2017 © Pedro Peláez
 

library crud-bundle

image

vox/crud-bundle

  • Thursday, July 26, 2018
  • by jhonatanTeixeira
  • Repository
  • 1 Watchers
  • 0 Stars
  • 74 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Crud Bundle

Configure Routes:

vox_crud:
    routes:
        firstStep:
            type: Presentation\Form\FirstStepType                   # the symfony form type to use
            class: Domain\Model\ProccessData                        # the object to be persisted, usualy a entity
            contextObject: Vox\CrudBundle\Form\CrudFormEvent        # a context object for the events to be dispatched
            strategy: Infrastructure\CrudStrategy\FirstStepStrategy # the persistence strategy class, must implement the strategy interface
            operations: ['get', 'put']                              # operations
            formTemplate: 'first-step/form.html.twig'               # form twig template

        secondStep:
            type: Presentation\Form\FirstStepType
            class: Domain\Model\ProccessData
            contextObject: Vox\CrudBundle\Form\CrudFormEvent
            strategy: Infrastructure\CrudStrategy\FirstStepStrategy
            operations: ['get', 'put']
            formTemplate: 'first-step/form.html.twig'

Custom Persistence Strategy

Register this class using the strategy option on your route configuration, (*1)

namespace Infrastructure\CrudStrategy;

use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Vox\CrudBundle\Crud\Strategy\CrudPostFlushableInterface;
use Vox\CrudBundle\Crud\Strategy\CrudStrategyInterface;

class FirstStepStrategy implements CrudStrategyInterface, CrudPostFlushableInterface
{

    public function persistDataObject(FormInterface $form)
    {
        //persist data using your database mechanism
    }

    public function createDataObjectForPost(Request $request)
    {
        //create the data object for the form when its a post route
    }

    public function createDataObjectForPut(Request $request)
    {
        //create the data object for the form when its a put route
    }

    public function createDataObjectForGet(Request $request)
    {
        //create the data object for the form when its a get route
    }

    public function postFlush($object)
    {
        //do something after the flushing of doctrine or your database mechanism
    }
}

Events

This bundle exposes some events to help manipulate the forms, (*2)

The Versions