Skip to content

Instantly share code, notes, and snippets.

@Ocramius
Last active December 17, 2015 19:49
Show Gist options
  • Save Ocramius/5663159 to your computer and use it in GitHub Desktop.
Save Ocramius/5663159 to your computer and use it in GitHub Desktop.
ZfrRest example configuration
<?php
namespace My\CMS\Entity\Product;
use Doctrine\ORM\Mapping as ORM;
use ZfrRest\Resource\Metadata\Annotation as REST;
/**
* @author Marco Pivetta <marco.pivetta@com2-gmbh.de>
*
* @ORM\Entity()
* @ORM\Table(name="my_cms_product_category")
* @REST\Resource(controller="My\CMS\Controller\REST\DefaultController")
* @REST\Collection(controller="My\CMS\Controller\REST\DefaultCollectionController")
*/
class Category
{
/**
* @var int|null
*
* @ORM\Id()
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer", name="id")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(type="string", name="name", nullable=false)
*/
protected $name = '';
}
<?php
return array(
'controllers' => array(
'invokables' => array(
'My\\CMS\\Controller\\REST\\DefaultController'
=> 'My\\CMS\\Controller\\REST\\DefaultController',
'My\\CMS\\Controller\\REST\\DefaultCollectionController'
=> 'My\\CMS\\Controller\\REST\\DefaultCollectionController',
),
),
// entity mappings
'doctrine' => array(
'driver' => array(
'My\CMS' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(
__DIR__ . '/../src/My/CMS/Entity',
),
),
'orm_default' => array(
'drivers' => array(
'My\CMS' => 'My\CMS',
),
),
),
),
'service_manager' => array(
'factories' => array(
'My\CMS\Repository\ProductCategoryRepository' => function ($sl) {
return $sl->get('Doctrine\ORM\EntityManager')->getRepository('My\CMS\Entity\Product\Category');
},
'My\CMS\Repository\ProductRepository' => function ($sl) {
return $sl->get('Doctrine\ORM\EntityManager')->getRepository('My\CMS\Entity\Product');
},
),
),
'zfr_rest' => array(
'object_manager' => 'doctrine.entitymanager.orm_default',
'resource_metadata' => array(
'drivers' => array(
'annotation_driver' => array(
'class' => 'ZfrRest\Resource\Metadata\Driver\AnnotationDriver'
)
)
)
),
// routing configuration (TBD, still incomplete)
'router' => array(
'routes' => array(
'my_product_category' => array(
'type' => 'ResourceGraphRoute',
'options' => array(
'route' => '/my/product-category',
'resource' => 'My\CMS\Repository\ProductCategoryRepository',
),
),
'my_product' => array(
'type' => 'ResourceGraphRoute',
'options' => array(
'route' => '/my/product',
'resource' => 'My\CMS\Repository\ProductRepository',
),
),
),
),
);
<?php
namespace My\CMS\Entity;
use Comcom\CMS\Upload\Entity\File;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use My\CMS\Entity\Product\Category;
use ZfrRest\Resource\Metadata\Annotation as REST;
/**
* @author Marco Pivetta <marco.pivetta@com2-gmbh.de>
*
* @ORM\Entity()
* @ORM\Table(name="my_cms_product")
* @REST\Resource(controller="My\CMS\Controller\REST\DefaultController")
* @REST\Collection(controller="My\CMS\Controller\REST\DefaultCollectionController")
*/
class Product
{
/**
* @var int|null
*
* @ORM\Id()
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer", name="id")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(type="string", name="name", nullable=false)
*/
protected $name = '';
/**
* @var string
*
* @ORM\ManyToOne(targetEntity="My\CMS\Entity\Product\Category")
*/
protected $category;
/**
* @var \My\CMS\Entity\Product\Type|null
*
* @ORM\ManyToOne(targetEntity="My\CMS\Entity\Product\Category")
* @ORM\JoinColumn(name="type_id", referencedColumnName="id", nullable=true)
* @REST\Association
*/
protected $category;
/**
* @return int|null
*/
public function getId()
{
return $this->id;
}
public function setCategory($category)
{
$this->category = $category;
}
public function getCategory()
{
return $this->category;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment