Example #1
0
 /**
  * Load a resource
  * 
  * @param  mixed $plugin 
  * @param  array $options 
  * @return Zend\Application\Resource
  */
 public function load($plugin, array $options = null)
 {
     $resource = parent::load($plugin, $options);
     if (null !== ($bootstrap = $this->getBootstrap())) {
         $resource->setBootstrap($bootstrap);
     }
     return $resource;
 }
Example #2
0
    /**
     * Load and return a plugin instance
     *
     * If the plugin was previously loaded, returns that instance.
     *
     * If no options were passed, and we have no specification, load normally.
     *
     * If no options were passed, and we have a specification, use the
     * specification to load an instance.
     *
     * Otherwise, simply try and load the plugin.
     *
     * @param  string $plugin
     * @param  array|null $options
     * @return object
     * @throws Exception if plugin not found
     */
    public function load($plugin, array $options = null)
    {
        $pluginName = strtolower($plugin);
        if (isset($this->plugins[$pluginName])) {
            // If we've loaded it already, just return it
            return $this->plugins[$pluginName];
        }

        $instance = parent::load($plugin, $options);

        if (null !== $this->actionController) {
            $instance->setActionController($this->actionController);
            $instance->init();
        }

        return $instance;
    }
 public function testAllowsConfigurationViaConstructor()
 {
     $validator = function ($plugin) {
         return true;
     };
     $broker = new PluginSpecBroker(array('class_loader' => array('class' => 'Zend\\Loader\\PrefixPathLoader', 'options' => array('ZendTest\\UnusualNamespace' => __DIR__ . '/TestAsset')), 'specs' => array('ClassMappedClass' => array(array('foo' => 'bar'))), 'plugins' => array('test' => $this), 'validator' => $validator));
     $loader = $broker->getClassLoader();
     $this->assertType('Zend\\Loader\\PrefixPathLoader', $loader);
     $this->assertEquals('ZendTest\\UnusualNamespace\\ClassMappedClass', $loader->load('ClassMappedClass'));
     $this->assertTrue($broker->isLoaded('test'));
     $this->assertSame($validator, $broker->getValidator());
     $plugin = $broker->load('ClassMappedClass');
     $this->assertType('ZendTest\\UnusualNamespace\\ClassMappedClass', $plugin);
     $this->assertEquals(array('foo' => 'bar'), $plugin->options);
     $broker = new PluginSpecBroker(array('class_loader' => 'ZendTest\\Loader\\TestAsset\\CustomClassLoader'));
     $loader = $broker->getClassLoader();
     $this->assertType('ZendTest\\Loader\\TestAsset\\CustomClassLoader', $loader);
 }
Example #4
0
    /**
     * Register a helper
     *
     * Proxies to parent functionality, and then registers helper with 
     * HelperPriorityStack.
     *
     * Additionally, if the plugin implements a "setBroker()" method, it will
     * inject itself into the helper.
     * 
     * @param  string $name 
     * @param  mixed $plugin 
     * @return HelperBroker
     */
    public function register($name, $plugin)
    {
        parent::register($name, $plugin);

        $stack   = $this->getStack();
        $stack[] = $plugin;

        if (method_exists($plugin, 'setBroker')) {
            $plugin->setBroker($this);
        }

        if (null !== $controller = $this->getActionController()) {
            $plugin->setActionController($controller);
        }

        return $this;
    }