2017 © Pedro Peláez
 

symfony-bundle generator-bundle

Generator auxiliary codes: REST from Doctrine

image

softfly/generator-bundle

Generator auxiliary codes: REST from Doctrine

  • Sunday, February 14, 2016
  • by softfly
  • Repository
  • 1 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Softfly Generator for Symfony

Install

composer require softfly/generator-bundle, (*1)

Functionalities

  1. Doctrine to REST, (*2)

    Generate REST on FOSRestBundle based on Doctrine entity., (*3)

    1. Method get all entities
    • Generate mapping entitly to response object.
    • Generate recursive mappings for relation entity.
    • Protection for "A circular reference"

Example

namespace AppBundle\Controller\Rest\Properties;

use FOS\RestBundle\Controller\Annotations\RouteResource;
use FOS\RestBundle\Controller\FOSRestController;

class PropertyRest extends FOSRestController
{
    public function getPropertiesAction()
    {
        $data = array();
        /* @var $propertiesRepo \Doctrine\ORM\EntityRepository */
        $propertiesRepo = $this->getDoctrine()->getRepository('\\AppBundle\\Entity\\Properties\\Property');
        $properties = $propertiesRepo->findAll();
        /* @var $property \AppBundle\Entity\Properties\Property*/
        foreach ($properties as $property) {
            $row = array();
            $row['id'] = $property->getId();
            $row['name'] = $property->getName();
            $row['slug'] = $property->getSlug();
            $row['location'] = $property->getLocation();
            $row['short_description'] = $property->getShortDescription();
            $row['long_description'] = $property->getLongDescription();
            /* @var $price \AppBundle\Entity\Offers\Price*/
            foreach ($property->getPrices() as $price) {
                $row1 = array();
                $row1['id'] = $price->getId();
                $row1['price'] = $price->getPrice();
                $row['price'][] = $row1;
                /* @var $timeUnit \AppBundle\Entity\Offers\TimeUnit*/
                $timeUnit = $price->getTimeUnit();
                if ($timeUnit) {
                    $row2 = array();
                    $row2['id'] = $timeUnit->getId();
                    $row2['noun'] = $timeUnit->getNoun();
                    $row2['adverb'] = $timeUnit->getAdverb();
                    $row['timeUnit'] = $row2;
                }
            }
            $data[] = $row;
        }
        $view = $this->view($data, 200);
        return $this->handleView($view);
    }
}

The Versions

14/02 2016

dev-master

9999999-dev https://github.com/softfly/GeneratorBundle

Generator auxiliary codes: REST from Doctrine

  Sources   Download

MIT

The Requires

 

rest generator doctrine