Coder Social home page Coder Social logo

breeze.server.php's Introduction

breeze.server.php

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

Features:

Doctrine

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

JMS Serializer

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.

Symfony Validator Component

(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",
        "symfony/validator": "dev-master"
    },
    "minimum-stability": "dev"

Please note that "symfony/validator": "dev-master" is required by "adrotec/breeze.server.php" since the library relies on ConstraintViolation::getConstraint() method which is not (yet) available in the older versions. You may have to add "minimum-stability": "dev" to your composer.json

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

Watchers

 avatar  avatar

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.