2017 © Pedro Peláez
 

symfony-bundle model-manager-bundle

HCLabs Model Manager Bundle

image

hclabs/model-manager-bundle

HCLabs Model Manager Bundle

  • Wednesday, February 18, 2015
  • by hclabs
  • Repository
  • 2 Watchers
  • 2 Stars
  • 158 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

HCLabs Model Manager

Build Status, (*1)

A simple model manager., (*2)


Usage:

Add to your composer.json file:, (*3)

"require": {
    // ...

    "hclabs/model-manager-bundle": "dev-master"
}

Service Definitions:, (*4)

# src/Acme/AcmeDemoBundle/Resources/config/services.yml

parameters:
    acme.demo_entity.class:     "Acme\\DemoBundle\\Entity\\TestEntity"
    hclabs.model_manager.class: "HCLabs\\ModelManagerBundle\\Model\\ModelManager"

    acme.demo_controller.class: "Acme\\DemoBundle\\Controller\\DemoController"

services:
    acme.demo_model_manager:
        class: "%hclabs.model_manager.class%"
        tags:
            - { name: hclabs.model_manager, entity: "%acme.demo_entity.class%" }

    acme.demo_controller:
        class: "%acme.demo_controller%"
        calls:
            - [setTestModelManager, ["@acme.demo_model_manager"]]

Example Entity:, (*5)

<?php
// src/Acme/AcmeDemoBundle/Entity/TestEntity

class TestEntity
{
    /**
     * @var string
     */
    private $name;

    /**
     * @var bool
     */
    private $enabled;

    /**
     * Set name
     *
     * @param string $name
     */
    public function setName($name)
    {
        $this->name = $name;
    }

    /**
     * Set enabled
     *
     * @param bool $enabled
     */
    public function setEnabled($enabled)
    {
        $this->enabled = $enabled;
    }

    // ... getters
}

Example Controller:, (*6)

<?php
// src/Acme/AcmeDemoBundle/Controller/DemoController.php

use HCLabs\ModelManagerBundle\Model\Contract\ModelManagerInterface;

class DemoController
{
    protected $manager;

    public function indexAction()
    {
        /** @var string[] $criteria */
        $criteria = ['name' => 'test'];

        try {
            $entity = $this->manager->findOrFail($criteria);
        }
        catch(EntityNotFoundException $e) {
            $entity = $this->manager->create($criteria);
        }

        $entity->setEnabled(1);

        $this->manager->persist($entity)->flush();

        // some other stuff....

    }

    public function setTestModelManager(ModelManagerInterface $modelManager)
    {
        $this->manager = $modelManager;
    }
}

New:

The admin pool:, (*7)

You can make use of the admin pool to get a manager for any managed entity. E.g.:, (*8)

<?php
// src/Acme/AcmeDemoBundle/Controller/DemoController.php

use Symfony\Component\HttpFoundation\Request;
use HCLabs\ModelManagerBundle\Pool\ModelManagerPool;

class DemoController
{
    protected $pool;

    protected $formFactory;

    protected $twig;

    public function updateUserAction(Request $request)
    {
        $form = $this->formFactory->create('my_form_type');
        $form->handleRequest($request);

        if ($form->isValid()) {
            $user = $form->getData();

            $manager = $this->pool->getManager($user);

            $manager->persist($user)->flush();

            return $this->twig->render(
                'AcmeDemoBundle:Demo:update-success.html.twig',
                ['user' => $user]
            );
        }

        return $this->twig->render(
            'AcmeDemoBundle:Demo:edit.html.twig',
            ['form' => $form]
        );
    }

    public function setModelManagerPool(ModelManagerPool $pool)
    {
        $this->pool = $pool;
    }

    // Other service setters ...
}

The Versions

18/02 2015

dev-master

9999999-dev https://github.com/jrdnhannah/ModelManager

HCLabs Model Manager Bundle

  Sources   Download

MIT

The Requires

 

model entity manager model manager

11/05 2014

1.0.0-RC2

1.0.0.0-RC2 https://github.com/jrdnhannah/ModelManager

HCLabs Model Manager Bundle

  Sources   Download

MIT

The Requires

 

model entity manager model manager

11/05 2014

1.0.0-RC1

1.0.0.0-RC1 https://github.com/jrdnhannah/ModelManager

HCLabs Model Manager Bundle

  Sources   Download

MIT

The Requires

 

model entity manager model manager