2017 © Pedro Peláez
 

symfony-bundle objectmanagerbundle

Bundle provides structured model handling

image

swoopster/objectmanagerbundle

Bundle provides structured model handling

  • Tuesday, December 16, 2014
  • by malte
  • Repository
  • 2 Watchers
  • 0 Stars
  • 18 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:, (*1)

$ composer require swoopster/objectmanagerbundle "~0.2"

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation., (*2)

Step 2: Enable the Bundle

Then, enable the bundle by adding the following line in the app/AppKernel.php file of your project:, (*3)

<?php
// app/AppKernel.php

class AppKernel extends Kernel
{
    public function registerBundles()
    {

        $bundles = array(
            new Swoopster\ObjectManagerBundle\SwoopsterObjectManagerBundle()
        );

    }

}

Step 3: Configure Bundle

Define coniguration parameters to customize bundle for your own needs. You need to define which bundles should be managed by the ObjectManager. Currently this bundle supports only the xml-mapping-format., (*4)

swoopster_object_manager:
    model_dir: Model #default
    mapping_format: xml #default
    bundles:
        - {namespace: Swoopster\TestBundle}

Usage

Define Mappings

Define your mapping definitions inside BundleFolder/Resources/config/doctrine/model. Currently only xml mappings supported!, (*5)

Use Manager

To get the manager use $container->get('id') or use the factory. To use the factory the manager service has to be tagged with the following tag:, (*6)

<tag name="swoopster.object_manager"/>

Now you can get an Manager by using the $conatainer->get('swoopster.object_manager.manager_factory')->getManager($instanceOfManagedObject), (*7)

Standard Manager

To use a manager for an object without customization, define a service like below, (*8)

<services>
    <service id="swoopster_test.model.test_object_manager" parent="swoopster.object_manager.doctrine_manager">
        <argument>Swoopster\TestBundle\Model\TestModel</argument>
    </service>
</services>

Customizable Manager

To extend the standardmanager define a manager class which extends from Swoopster\ObjectManagerBundle\Doctrine\DoctrineManager and register this class as a service. see example below, (*9)

<services>
    <service id="swoopster_test.model.test_object_manager" class="Swoopster\TestBundle\Model\TestObjectManager" parent="swoopster.object_manager.doctrine_manager">
        <argument>Swoopster\TestBundle\Model\TestModel</argument>
    </service>
</services>

Manager Functions

Create

Get a new instance of managed modelclass, (*10)

$manager->create()

Save

save or update an instance of managed modelclass. Second argument defines if orm should persist object immediately or later, default is true (immediately)., (*11)

$manager->save($object, $flush)

Delete

delete an existing instance of managed modelclass, (*12)

$manager->delete($object, $flush)

Find

the manager supports a predefined set of methods to find objects in database. you can find supported functions in Swoopster\ObjectManagerBundle\Model\ManagerInterface, (*13)

$manager->find*()

Lifecycle Events

To use the lifecycle events you need to comply with the following requirments, (*14)

  1. the model to be managed must implement Swoopster\ObjectManagerBundle\Model\EventDrivenModelInterface
  2. the manager belonging to this model must implement Swoopster\ObjectManagerBundle\Model\ManagerEventInterface
  3. manager must be registered in the factory

Supported Events

All events are expecting an instance of the managed model as argument, (*15)

  • prePersist
  • postPersit
  • preUpdate
  • postUpdate
  • preRemove
  • postRemove
  • postLoad

License

This bundle is under the MIT license. See the complete license in the bundle:, (*16)

Resources/meta/LICENSE

The Versions