Beispiel #1
0
 /**
  * Load a helper
  *
  * Injects the view object into the helper prior to returning it.
  * 
  * @param mixed $plugin 
  * @param array $options 
  * @return void
  */
 public function load($plugin, array $options = null)
 {
     $helper = parent::load($plugin, $options);
     if (null !== ($view = $this->getView())) {
         $helper->setView($view);
     }
     return $helper;
 }
Beispiel #2
0
 /**
  * Register plugin with broker
  *
  * Injects parser into plugin, if registered.
  * 
  * @param  string $name 
  * @param  mixed $plugin 
  * @return RendererBroker
  */
 public function register($name, $plugin)
 {
     parent::register($name, $plugin);
     if (null !== ($parser = $this->getParser())) {
         $plugin->setParser($parser);
     }
     return $this;
 }
Beispiel #3
0
 /**
  * Get plugin class that handles this resource
  *
  * @param resource $resource Resource type
  * @return object Resource class
  */
 public static function getResourceParser($resource)
 {
     if (self::$_resourceBroker) {
         $type = preg_replace("/[^A-Za-z0-9_]/", " ", get_resource_type($resource));
         $type = str_replace(" ", "", ucwords($type));
         return self::$_resourceBroker->load($type);
     }
     return false;
 }
Beispiel #4
0
 /**
  * Load a plugin
  *
  * Injects the controller object into the plugin prior to returning it, if 
  * available, and if the plugin supports it.
  *
  * @param  mixed $plugin
  * @param  array|null $options
  * @return mixed
  */
 public function load($plugin, array $options = null)
 {
     $helper = parent::load($plugin, $options);
     if (method_exists($helper, 'setController')) {
         if (null !== ($controller = $this->getController())) {
             $helper->setController($controller);
         }
     }
     return $helper;
 }
Beispiel #5
0
    /**
     * Create a route from array specifications.
     *
     * @param  mixed $specs
     * @return SimpleRouteStack
     */
    protected function routeFromArray($specs)
    {
        if (!is_array($specs) && !$specs instanceof ArrayAccess) {
            throw new Exception\InvalidArgumentException(sprintf(
                'Expected an array or ArrayAccess; received "%s"',
                (is_object($specs) ? get_class($specs) : gettype($specs))
            ));
        }
    
        if (!isset($specs['type'])) {
            throw new Exception\InvalidArgumentException('Missing "type" option');
        } elseif (!isset($specs['options'])) {
            throw new Exception\InvalidArgumentException('Missing "name" option');
        }
        
        $route = $this->pluginBroker->load($specs['type'], $specs['options']);

        return $route;
    }
Beispiel #6
0
    public function testAllowsConfigurationViaConstructor()
    {
        $validator = function($plugin) {
            return true;
        };
        $broker = new PluginBroker(array(
            'class_loader' => array(
                'class'   => 'Zend\Loader\PrefixPathLoader',
                'options' => array(
                    'ZendTest\UnusualNamespace' => __DIR__ . '/TestAsset',
                )
            ),
            '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());

        $broker = new PluginBroker(array(
            'class_loader' => 'ZendTest\Loader\TestAsset\CustomClassLoader',
        ));
        $loader = $broker->getClassLoader();
        $this->assertType('ZendTest\Loader\TestAsset\CustomClassLoader', $loader);
    }