GithubHelp home page GithubHelp logo

breeze.server.php's Introduction

Project Status: ๐Ÿšจ Unmaintained ๐Ÿšจ

This project is no longer maintained. We will not be accepting pull requests, addressing issues, nor making future releases.

breeze.server.php

Featured in Official BreezeJS docs

This project is a PHP library that facilitates building Breeze JS compatible backends using Doctrine

Features:

a well documented, feature rich and popular Object Relational Mapper for PHP which supports several database systems

Why use Doctrine? (extracted from doctrine website)

  • Around since 2006 with very stable, high-quality codebase.
  • Extremely flexible and powerful object-mapping and query features.
  • Support for both high-level and low-level database programming for all your use-cases.
  • Large Community and integrations with many different frameworks (Symfony, Zend Framework, CodeIgniter, FLOW3, Lithium and more

Currently this library supports Doctrine ORM only. Future versions should support Doctrine MongoDB ODM too.

Some of the Doctrine Types are converted into Breeze Data Types

Built in Doctrine types with their breeze equivalent types

  • string - String - SQL VARCHAR to a PHP string.
  • integer - Int32 - SQL INT to a PHP integer.
  • smallint - Int32 - SMALLINT to a PHP integer.
  • bigint - Int32 - BIGINT to a PHP string.
  • boolean - Boolean - SQL boolean to a PHP boolean.
  • decimal - Decimal - SQL DECIMAL to a PHP double.
  • date - DateTime - SQL DATETIME to a PHP DateTime object.
  • time - DateTime - SQL TIME to a PHP DateTime object.
  • datetime - DateTime - SQL DATETIME/TIMESTAMP to a PHP DateTime object.
  • float - Double - SQL Float (Double Precision) to a PHP double. IMPORTANT: Works only with locale settings that use decimal points as separator.
  • Other data types fall back to String

a powerful serialization library for PHP. Provides more control over your serialized results. e.g: if you want to exclude a property from returned results, you may use the @Exclude annotation. Read the documentation to find out more.

(Optional, if you want to support validation) a powerful validation service for PHP with out of box support for Doctrine.

Please note that, by using the Symfony components, it does not necessarily mean you have to use the full stack symfony framework, since they are decoupled and standalone components.

Some of the Validation Constraints are converted to equivalent breeze validators.

Built in Validation Constraints with their Breeze equivalent validators

Example/Demo

Installation

The library uses composer, the package manager for PHP.

add these lines to your composer.json and run composer update

    "require": {
        "adrotec/breeze.server.php": "dev-master"
    }

Please note that symfony/validator - 2.6+ is required by "adrotec/breeze.server.php" since the library relies on ConstraintViolation::getConstraint() method which is not (yet) available in the older versions.

Usage

The library provides a basic framework to easily bootstrap the API. You may use either Application or StandaloneApplication class.

Using the Application class

/* @var $entityManager instanceof \Doctrine\ORM\EntityManager */
/* @var $serializer instanceof \JMS\Serializer\SerializerInterface */
/* @var $validator instanceof \Symfony\Component\Validator\Validator\ValidatorInterface */

$app = new Adrotec\BreezeJs\Framework\Application(
  $entityManager,
  $serializer,
  $validator
);

$app->addResources(array(
    'Employees' => 'EmpDirectory\Model\Employee',
    'Departments' => 'EmpDirectory\Model\Department',
    'Jobs' => 'EmpDirectory\Model\Job',
));

/* @var $request instanceof \Symfony\Component\HttpFoundation\Request */

$response = $app->handle($request);

Using the StandaloneApplication class

$loader = require 'vendor/autoload.php';

$app = new Adrotec\BreezeJs\Framework\StandaloneApplication();

$app->setConnection(array(
    'driver' => 'pdo_mysql',
    'host' => 'localhost',
    'dbname' => 'employees',
    'user' => 'root',
    'password' => ''
));

// configuring doctrine, serializer and validator
// using xml mappings
$app->addMapping(array(
    'namespace' => 'EmpDirectory\Model',
    'type' => 'xml',
    'extension' => '.orm.xml', // default ".dcm.xml"
    'doctrine' => __DIR__ . '/src/EmpDirectory/config/doctrine', // doctrine directory
    'serializer' => __DIR__ . '/src/EmpDirectory/config/serializer', // [optional] serializer metadata directory
    'validation' => __DIR__ . '/src/EmpDirectory/config/validation.xml', // [optional] validation file
));

// limiting the api to certain classes
$app->addResources(array(
    // Resource name => Class name
    'Employees' => 'EmpDirectory\Model\Employee',
    'Jobs' => 'EmpDirectory\Model\Job',
    'Departments' => 'EmpDirectory\Model\Department',
));

$app->build();

$app->run();

With Symfony 2

There's a bundle for that!

breeze.server.php's People

Contributors

safrazik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

breeze.server.php's Issues

[feature] Custom Services And non-mapped properties

This library has been working out pretty great sitting in a laravel 5 project. Just a couple improvements could make it exceed endlessly... It'd be cool if you could create service endpoints that return arrays of objects (think Lookups). The example in the demo is OK but highly ineffceient for a large lookup set .. (talking 10+ queries) which could be exacted in one lookup service..

Also I notice if you put a property on the doctrine class but don't specify a doctrine @column tag it still sends the data down in the metadata.. I personally think this or perhaps something more clever could be useful for sending unmaped properties . Since per the breeze docs you can't get tracking on unmaped properties unless they come down from the server side...

isPartOfKey not being set correcting for keys in Embeddable properties

I have my keys stored in a UUID value object. When this is generating the metadata, the isPartOfKey flag is not being properly set for the classes.

Example:

/**
 * @Entity
 * @HasLifecycleCallbacks()
 **/
class Expense extends Base
{
    /**
     * @Embedded(class="Objects\UUID", columnPrefix=false)
     * @var UUID
     **/
    protected $id;
   ....
}
/**
 * @Embeddable
 */
class UUID
{
    /**
     * @Id
     * @Column(type="string")
     */
    private $id;

   ...
}

The generated Metadata looks like this:

{
"metadataVersion":"1.0.5",
"structuralTypes":[{
   "shortName":"Expense",
   "autoGeneratedKeyType":"None",
   "defaultResourceName":"Expenses",
   "dataProperties":[
      {"name":"id","dataType":"String"}
      ...
   ]
}

It appears that Embeddables aren't being evaluated correctly.

MetadataBuilder doesn't support simple array data properties

I'm working on a project which uses BreezeJS and the breeze.server.php bundle to generate the Breeze metadata from Doctrine mappings which is really awesome, but now I'm running into a use case where I need to have a simple array data property, in fact a simple array of strings.

In BreezeJS this is supported via an extra property in the metadata for a certain DataProperty ('isScalar = false" => http://stackoverflow.com/questions/22055013/breeze-js-metadata-by-hand-for-an-array-type) but I can't get this property added via the breeze.php.library as there is no "isScalar" property in the DataProperty class of the library.

Do you think this property could be added to the DataProperty class?

Assitance with install of Emploee Directory

Forgive me if this is the worng place to post this -

I am having trouble installing the PHP Employee Directory which is located here:
http://emp-directory.herokuapp.com/

In the directions it says : run composer update from server/standalone directory.

How is that accoplished exactly? I tried to run it from the url but I get a 404. Am I supposed to do this at a command line? I'm installing into a WAMP environment.

Thanks for any help

composer - no matching packages

Upon executing composer update, the following error shows up:

Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for symfony/validator dev-master -> satisfiable by symfony/validator[dev-master].
- symfony/validator dev-master requires symfony/translation ~2.8|~3.0 -> no matching package found.
Problem 2
- Installation request for adrotec/breeze.server.php dev-master -> satisfiable by adrotec/breeze.server.php[dev-master].
- adrotec/breeze.server.php dev-master requires jms/serializer ~1.0 -> no matching package found.

Perhaps your package should depend on stable releases instead of dev-master? I changed "dev-master" to "@dev" and it temporarily fixes the problem, for the lack of any better/quicker solution, if that can be called so.

It's acutally an issue with the demo: https://github.com/adrotec/breeze.server.php.demo

Cool

Sounds like a very very good start. I am willing to help, I need the same thing to save in a mysql db. Could you kindly provide a bit more information ?.

A index.php that will contain the JS used to load the schema and run the save and the SQL to create the DB background would be just perfect to help me to go forward.

Thx for your much appreciated efforts here

Authorization

Is there a way to do authorization with this as well? I see that there is data validation, but I don't see any authorization. It seems like the Breeze way is to do 'Save Interception'. Is that supported?

Triggering Events?

I'm considering using this for an upcoming project, but there's one last thing I'm not seeing how to do using this library and breeze that I'm hopeful someone can shed some light on. I need a way to be able to trigger an event in php from breeze. I'm all set with using the events on the back-end, I just don't see a way to get them to run from the front-end.

Probably the best example I can give is a tournament. Once all of the matches for a round are done I'd show the user a button to progress to the next round, which would send a request to the server to do all the work of figuring out the matches and then respond with the next round.

Ideally on the front-end I could have a progress method on the tournament entity, and calling that would trigger a Symfony event somehow.

Any ideas on how something like this can be accomplished?

Child entity types define the inherited navigation properties again

e.g:

namespace Test\Model;

class Address {
}

class Person {
  protected $firstName; // string
  protected $address; // instance of Address
}

class Employee extends Person {
}

the metadata generated is

{
  "structuralTypes": [
    {
      "shortName": "Person",
      "namespace": "Test.Model",
      "dataProperties": [
        {
          "name": "firstName",
          "dataType": "String"
        }
      ],
      "navigationProperties": [
        {
          "name": "address",
          "entityTypeName": "Address:#Test.Model",
          "isScalar": true
        }
      ]
    },
    {
      "shortName": "Employee",
      "baseTypeName": "Person:#Test.Model",
      "namespace": "Test.Model",
      "dataProperties": [ ],
      "navigationProperties": [
        {
          "name": "address",
          "entityTypeName": "Address:#Test.Model",
          "isScalar": true
        }
      ]
    }
  ]
}

while navigation property address is inherited from Person entity, Employee entity should not define it again. This is already working with dataProperties

No Tests

No (unit) tests are available yet

Compatibility with PHP 7

This is not to breeze.server.php but to your fork of odataphpprod (that fork not has Issues tab).

I get next error when try run code on the PHP 7
Fatal error: Cannot use ODataProducer\Providers\Metadata\Type\String as String because 'String' is a special class name in vendor\adrotec\odataphpprod\library\ODataProducer\Providers\Metadata\ResourceType.php on line 47
Can this will be fixed?

Many TO Many

Should probably be documented that many to many doesn't work

Add support for automatic handling of bidirectional associations

As mentioned in the Doctrine documentation, it is required to update both sides of a bidirectional association:

// Many-To-One / One-To-Many Bidirectional
$newComment = new Comment();
$user->getAuthoredComments()->add($newComment);
$newComment->setAuthor($user);

Currently the breeze.server.php library has support for assigning from the owning side only.

$newComment = new Comment();
$newComment->setAuthor($user);

While this is not a problem in a usual scenario, it can be very useful when lifecycle callbacks are involved.

Status of Build?

I stumbled across this project when searching for "breeze php," and it seems to be exactly what I was looking for. However, I'm wondering what the status of the code is? I don't see any test cases, and the project as a whole seems to have come out of the blue. Is it being used in production somewhere?

The readme mentions that the project supports a subset of OData queries. Does this affect the use of Breeze? On the whole does this implement an OData producer library for PHP? I had come across https://github.com/balihoo/POData, but that seemed to have issues / was lacking documentation. It looks like this may include some code from there.

Serialization of entities after SaveChanges includes associations

In the serialized json response after SaveChanges, only the entities that were sent to the server, should be returned with the updated values. At the moment, the serialized entities also include the associations.

It becomes problematic when one to many associations are available. A big payload can break things. Could be a side effect of this feature #6 Add support for automatic handling of bidirectional associations

Hint: Introduce serialization contexts for SaveChanges, Metadata and Query Results

Is it possible to include navigation property IDs in projection query?

From @slawojstanislawski on September 5, 2015 11:54

Here's a link from a project built with MongoDb, angular and breezeJs:
https://github.com/johnpapa/ng-demos/blob/master/cc-bmean/src/client/app/data/repositories/repository.session.js#L65

On line 65 in the code, as part of a projection selection there are navigation properties' IDs included. So one can first download all the track, timeSlot and room entities (say, as part of some lookup query, as was provided as an example for a PHP app here: #12 (comment)), and then ask for such a projection, and since the navigation properites' entities are in the cache, one can make use of, say, session.timeSlot.name, or session.track.title, things like that, and the navigation properties are retrieved from cache appropriately for a given session (after casting the query result to session entity with toType() method).

In my sandbox model (based on EmpDirectory sample app) User entity has ManyToOne association with Job entity and a ManyToOne association with Department entity, and when I do:
breeze.EntityQuery.from('Users').toType("User")
with no projection, I get properties like jobId and departmentId in the results. When I try to use projection:
breeze.EntityQuery.from('Users').select('id, firstName, lastName, jobId').toType("User")
I get 500 server response:
Invalid select expression "X.lastName" (500 Internal Server Error)

There's clearly something I'm missing but I've been unable to pinpoint exactly what it is.

Copied from original issue: adrotec/AdrotecWebApiBundle#2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.