Skip to content

Instantly share code, notes, and snippets.

@ThaDafinser
Created July 24, 2014 12:28
Show Gist options
  • Save ThaDafinser/71504f514ae615fbb4c7 to your computer and use it in GitHub Desktop.
Save ThaDafinser/71504f514ae615fbb4c7 to your computer and use it in GitHub Desktop.
<?php
return array(
'service_manager' => array(
'factories' => array(
'DatagridManager' => 'LispBase\Mvc\Service\DatagridManagerFactory'
)
)
);
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace LispBase\ZfcDatagrid;
use Zend\ServiceManager\AbstractPluginManager;
/**
* Plugin manager implementation for form elements.
*
* Enforces that elements retrieved are instances of ElementInterface.
*/
class DatagridManager extends AbstractPluginManager
{
/**
* Don't share form elements by default
*
* @var bool
*/
protected $shareByDefault = false;
public function validatePlugin($plugin)
{
}
/**
* Retrieve a service from the manager by name
*
* Allows passing an array of options to use when creating the instance.
* createFromInvokable() will use these and pass them to the instance
* constructor if not null and a non-empty array.
*
* @param string $name
* @param string|array $options
* @param bool $usePeeringServiceManagers
* @return object
*/
public function get($name, $options = array(), $usePeeringServiceManagers = true)
{
$instance = new $name();
$instance->setServiceLocator($this->getServiceLocator());
return $instance;
}
}
<?php
namespace LispBase\Mvc\Service;
use Zend\Mvc\Service\AbstractPluginManagerFactory;
use Zend\Form\FormElementManager;
use Zend\ServiceManager\ServiceLocatorInterface;
class DatagridManagerFactory extends AbstractPluginManagerFactory
{
const PLUGIN_MANAGER_CLASS = 'LispBase\ZfcDatagrid\DatagridManager';
/**
* Create and return the MVC controller plugin manager
*
* @param ServiceLocatorInterface $serviceLocator
* @return FormElementManager
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$plugins = parent::createService($serviceLocator);
$plugins->addPeeringServiceManager($serviceLocator);
$plugins->setRetrieveFromPeeringManagerFirst(true);
return $plugins;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment