This package is abandoned and no longer maintained. No replacement package was suggested.

Vegas CMF DAO

v2.0.0-beta 2016-06-03 14:27 UTC

This package is not auto-updated.

Last update: 2022-08-11 23:44:02 UTC


README

Build Status Coverage Status Latest Stable Version Total Downloads

DAO library adapts the Data Access Object pattern to your application.

Installation

Set \Vegas\Db\Dao\Manager class as a service by adding following snippet into your services directory:

use Phalcon\DiInterface;
use Vegas\DI\ServiceProviderInterface;

/**
 * Class DaoServiceProvider
 */
class DaoServiceProvider implements ServiceProviderInterface
{
    const SERVICE_NAME = 'dao';

    /**
     * {@inheritdoc}
     */
    public function register(DiInterface $di)
    {
        $di->set(self::SERVICE_NAME, function() use ($di) {
            $dao = new \Vegas\Db\Dao\Manager;
            return $dao->setDI($di);
        }, true);
    }

    public function getDependencies()
    {
        return [];
    }
}

Example usage:

Inside injection-aware class:

$modelName = '\Foo\Models\Bar';
$model = new $modelName;

$daoManager = $this->getDI()->get('dao');

/** @var \Foo\Models\Dao\Bar $dao */
$dao = $daoManager->get($modelName);
// or
$dao = $daoManager->get($model);

/** @var \Foo\Models\Bar $result */
$result = $dao->findById('example_id');

/** @var \Foo\Models\Bar[] $results */
$results = $dao->findAll();

For the full list of available methods please examine \Vegas\Db\Dao\DefaultDao class.

By default, DAO classes for specific collections/models should be placed under additional Dao suffix and should have the same name. e.x. for \Foo\Models\Bar collection a \Foo\Models\Dao\Bar class should be created. Currently there are no additional requirements for the class implementation.