2017 © Pedro Peláez
 

library rdn-factory

Zend Framework 2 module to help create factory classes

image

radnan/rdn-factory

Zend Framework 2 module to help create factory classes

  • Friday, November 14, 2014
  • by radnan
  • Repository
  • 1 Watchers
  • 2 Stars
  • 15,952 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 4 % Grown

The README.md

RdnFactory

The RdnFactory ZF2 module makes it really easy to create factory classes., (*1)

How to install

  1. Use composer to require the radnan/rdn-factory package:, (*2)

    $ composer require radnan/rdn-factory:1.*
    
  2. Activate the module by including it in your application.config.php file:, (*3)

    <?php
    
    return array(
       'modules' => array(
           'RdnFactory',
           // ...
       ),
    );
    

How to use

The module provides an RdnFactory\AbstractFactory class that you should extend when creating your factory classes. Implement the protected create() method to create your service., (*4)

namespace FooModule\Factory\Controller;

use FooModule\Controller;
use RdnFactory\AbstractFactory;

class Bar extends AbstractFactory
{
    protected function create()
    {
        // Create and return your service
        return new Controller\Bar;
    }
}

This abstract factory has access to a repository of plugins, similar to a controller. Simply call the plugin as if you were calling a method:, (*5)

namespace FooModule\Factory\Controller;

use FooModule\Controller;
use RdnFactory\AbstractFactory;

class Bar extends AbstractFactory
{
    protected function create()
    {
        $config = $this->config('foo', 'bar');
        $modules = $this->service('ModuleManager');

        return new Controller\Bar($config, $modules);
    }
}

config(...$key)

Get configuration by key. You can pass multiple keys to traverse nested configuration items., (*6)

// grab the 'display_exceptions' item inside the 'view_manager' array
$config = $this->config('view_manager', 'display_exceptions');

controller($name)

Get the controller with the given name., (*7)

$controller = $this->controller('FooModule:BarController');

form($name)

Get a form/fieldset/element with the given name., (*8)

$collection = $this->form('Collection');

$form = $this->form('FooModule:BarForm');

params($name)

Get a route parameter value., (*9)

$id = $this->params('bar-id');

service($name)

Get a service from the top-level service locator (service manager)., (*10)

$app = $this->service('Application');

$view = $this->service('ViewRenderer');

$uploads = $this->service('RdnUpload\Container');

url($route = null, $params = array(), $options = array(), $reuseMatchedParams = false)

This is just a proxy to the url()->fromRoute() controller plugin. Useful for generating URLs from within a factory., (*11)

$apiUrl = $this->url('foo/api/search/user');

The Versions

14/11 2014

dev-master

9999999-dev

Zend Framework 2 module to help create factory classes

  Sources   Download

MIT

The Requires

 

by Avatar radnan

plugins zf2 zend factory

14/11 2014

v1.0.2

1.0.2.0

Zend Framework 2 module to help create factory classes

  Sources   Download

MIT

The Requires

 

by Avatar radnan

plugins zf2 zend factory

13/11 2014

v1.0.1

1.0.1.0

Zend Framework 2 module to help create factory classes

  Sources   Download

MIT

The Requires

 

by Avatar radnan

plugins zf2 zend factory

26/12 2013

v1.0.0

1.0.0.0

Zend Framework 2 module to help create factory classes

  Sources   Download

MIT

The Requires

 

by Avatar radnan

plugins zf2 zend factory