protected function addStrategies(Detector $detector, array $strategies, ServiceLocatorInterface $serviceLocator)
 {
     $plugins = $serviceLocator->get('SlmLocale\\Strategy\\StrategyPluginManager');
     foreach ($strategies as $strategy) {
         if (is_string($strategy)) {
             $class = $plugins->get($strategy);
             $detector->addStrategy($class);
         } elseif (is_array($strategy)) {
             $name = $strategy['name'];
             $class = $plugins->get($name);
             if (array_key_exists('options', $strategy) && method_exists($class, 'setOptions')) {
                 $class->setOptions($strategy['options']);
             }
             $priority = 1;
             if (array_key_exists('priority', $strategy)) {
                 $priority = $strategy['priority'];
             }
             $detector->addStrategy($class, $priority);
         } else {
             throw new Exception\StrategyConfigurationException('Strategy configuration must be a string or an array');
         }
     }
 }
Beispiel #2
0
 public function testStrategyAttachesToEventManager()
 {
     $detector = new Detector();
     $strategy = $this->createMock('SlmLocale\\Strategy\\StrategyInterface');
     $events = $this->createMock('Zend\\EventManager\\EventManager', array('attachAggregate'));
     $events->expects($this->once())->method('attachAggregate')->with($strategy);
     $detector->setEventManager($events);
     $detector->addStrategy($strategy);
 }