radnan / rdn-database
Zend Framework 2 database adapter manager
Installs: 86
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/radnan/rdn-database
Requires
Requires (Dev)
- phpunit/phpunit: 3.*
This package is not auto-updated.
Last update: 2025-10-21 07:39:00 UTC
README
The RdnDatabase ZF2 module provides a service locator for database adapters.
How to install
-
Use
composerto require theradnan/rdn-databasepackage:$ composer require radnan/rdn-database:1.* -
Activate the module by including it in your
application.config.phpfile:<?php return array( 'modules' => array( 'RdnDatabase', // ... ), );
How to use
Simply configure your database adapters with the RdnDatabase\Adapter\AdapterManager service locator using the rdn_db_adapters configuration option. Adapters are instances of the Zend\Db\Adapter\Adapter class.
<?php return array( 'rdn_db_adapters' => array( 'invokables' => array(), 'factories' => array(), ), );
You can use the adapters key to dynamically create adapters using simple configuration:
<?php return array( 'rdn_db_adapters' => array( 'adapters' => array( 'default' => array( 'driver' => 'pdo_mysql', 'hostname' => null, 'port' => null, 'username' => null, 'password' => null, 'database' => null, ), ), ), );
The configuration options are used to create a Zend\Db\Adapter\Adapter object.
Controller Plugin
The module comes with the database() controller plugin that you can use to fetch database adapters from within a controller:
class FooController { public function indexAction() { /** @var \Zend\Db\Adapter\Adapter $adapter */ $adapter = $this->database('default'); } }
Factories
The module depends on the RdnFactory module and provides a database() plugin you can use when creating factory classes.
namespace App\Factory\Controller; use App\Controller; use RdnFactory\AbstractFactory; class Index extends AbstractFactory { protected function create() { $adapter = $this->database('default'); return new Controller\Index($adapter); } }