getStrategyNameForRenderer() public method

public getStrategyNameForRenderer ( $rendererName, $default = null )
Example #1
0
 /**
  * Get strategy to setup assets for given $renderer.
  *
  * @param \Zend\View\Renderer\RendererInterface $renderer
  * @throws Exception\DomainException
  * @throws Exception\InvalidArgumentException
  * @return \AsseticBundle\View\StrategyInterface|null
  */
 public function getStrategyForRenderer(Renderer $renderer)
 {
     if (!$this->hasStrategyForRenderer($renderer)) {
         return null;
     }
     $rendererName = $this->getRendererName($renderer);
     if (!isset($this->strategy[$rendererName])) {
         $strategyClass = $this->configuration->getStrategyNameForRenderer($rendererName);
         if (!class_exists($strategyClass, true)) {
             throw new Exception\InvalidArgumentException(sprintf('strategy class "%s" dosen\'t exists', $strategyClass));
         }
         $instance = new $strategyClass();
         if (!$instance instanceof StrategyInterface) {
             throw new Exception\DomainException(sprintf('strategy class "%s" is not instanceof "AsseticBundle\\View\\StrategyInterface"', $strategyClass));
         }
         $this->strategy[$rendererName] = $instance;
     }
     /** @var $strategy \AsseticBundle\View\StrategyInterface */
     $strategy = $this->strategy[$rendererName];
     $strategy->setBaseUrl($this->configuration->getBaseUrl());
     $strategy->setBasePath($this->configuration->getBasePath());
     $strategy->setDebug($this->configuration->isDebug());
     $strategy->setCombine($this->configuration->isCombine());
     $strategy->setRenderer($renderer);
     return $strategy;
 }
 public function testGetStrategyNameForRenderer()
 {
     $strategyName = 'some-module';
     $result = $this->object->getStrategyNameForRenderer($strategyName);
     $this->assertNull($result);
     $expected = '123';
     $result = $this->object->getStrategyNameForRenderer($strategyName, $expected);
     $this->assertEquals($expected, $result);
     $expected = array('name' => 'value');
     $data = array($strategyName => $expected);
     $this->object->setRendererToStrategy($data);
     $result = $this->object->getStrategyNameForRenderer($strategyName);
     $this->assertEquals($expected, $result);
 }