ssa/doctrine

There is no license information available for the latest version (dev-master) of this package.

Add doctrine resolver for ssa framework.

dev-master 2015-04-30 15:31 UTC

This package is not auto-updated.

Last update: 2024-12-07 17:58:16 UTC


README

ssa/doctrine is an extension for ssa. This extension allow two convert id directly on your entity.

Working

Ssa in symfony add parameter resolvers. It can convert json oject into your doctrine entity. Example : Entity

Product :
  - id
  - name
  - price
  

Database

Id | Name | Price

1 | Foo | 10.0

ProductService.php

class ProductService {
    private $em;
    
    public function __construct(EntityManagerInterface $em) {
        $this->em = $em;
    }
    
    public function getProduct(Product $p) {
        return $p;
    }

    public function updateProduct(Product $p) {
        $this->em->persist($p);
        $this->em->flush();
        return $p;
    }
}

Javascript call :

productService.getProduct({id : 1}).done(function(data){
  // data.id = 1
  // data.name = "Foo"
  // data.price = 10.0
});

productService.updateProduct({name : 'Bar', price : 15}).done(function(data){
  // data.id = AutoGenerated value
  // data.name = 'Bar'
  // data.price = 15
});

productService.updateProduct({id : 1, price : 11.5}).done(function(data){
  // data.id = 1
  // data.name = 'Foo'
  // data.price = 11.5
});

Configuration

To add this extension to ssa :

  • add ssa/doctrine dependencies on your composer.json
  • add DoctrineObjectResolver on DefaultParameterResolver

Configuration.php

use ssa\runner\resolver\impl\DefaultParameterResolver;
use ssa\runner\resolver\DoctrineObjectResolver;

// add the doctrine resolver
// this resolver need know your entity manager
DefaultParameterResolver::createDefaultParameterResolver()
	->addObjectResolver(new DoctrineObjectResolver($entityManager));