Simple implementation of Data Access Object pattern for Symfony 2 projects.

1.0.2 2013-02-17 13:04 UTC

This package is not auto-updated.

Last update: 2024-11-09 13:23:14 UTC


README

Simple implementation of Data Access Object pattern for symfony 2 projects.

  • Has unit tests: yes
  • Vendors: doctrine-common

Advantages

  • allows you to quickly switch between the ORM and ODM doctrine managers
  • promote clean and tested code. all of the business application logic should be in the services

Build Status

Installation

If you use a deps file, you could add:

 [dao]
     git=https://github.com/fightmaster/dao.git
 

Or if you want to clone the repos:

 git clone https://github.com/fightmaster/dao.git vendor/dao
 

If you use Composer, you could add:

{"require": {"fightmaster/dao": "1.x"}}

Add the namespace to your autoloader

<?php
 $loader->registerNamespaces(array(
     ............
     'Fightmaster'   => __DIR__.'/../vendor/dao/src',
     ...........
 ));

Examples

Example service layer

<?php
.....
Class ProductService extends Service
{
    public function __construct(ManagerInterface $manager)
    {
        $this->manager = $manager;
    }
    ....
    public function saveProduct(Product $product)
    {
        $prePersistEvent = new PrePersistEvent($product);
        $this->dispatcher->dispatch('product_pre_persist', $prePersistEvent);
        if (!$prePersistEvent->isAborted()) {
            $this->manager->save($product);
        }
        $postPersistEvent = new PostPersistEvent($product);
        $this->dispatcher->dispatch('product_post_persist', $postPersistEvent);
    }

    public function changeProductName(Product $product, $newName)
    {
        ....
        $product->setName($newName);
        $this->saveProduct($product);
    }
}