/**
  * Configures the view resolver.
  *
  * @param \Es\Modules\ModulesEvent $event The modules event
  *
  * @throws \UnexpectedValueException If configuration has invalid
  *                                   specification of view resolver
  */
 public function __invoke(ModulesEvent $event)
 {
     $modules = $this->getModules();
     $resolver = $this->getResolver();
     foreach ($modules as $name => $module) {
         $resolver->registerModulePath($name, $module->getModuleDir());
     }
     $config = $this->getConfig();
     if (!isset($config['view']['resolver'])) {
         return;
     }
     $map = (array) $config['view']['resolver'];
     foreach ($map as $key => $value) {
         if (is_array($value)) {
             foreach ($value as $template => $path) {
                 if (!is_string($path)) {
                     throw new UnexpectedValueException(sprintf('Invalid specification of view resolver for "%s" ' . 'provided; the path of template "%s" must be an ' . 'string, "%s" received.', $key, $template, is_object($path) ? get_class($path) : gettype($path)));
                 }
                 $template = Resolver::getFullTemplateName($key, $template);
                 $resolver->registerTemplatePath($template, $path);
             }
         } elseif (is_string($value)) {
             $resolver->registerTemplatePath($key, $value);
         } else {
             throw new UnexpectedValueException(sprintf('Invalid specification of view resolver provided; ' . '"%s" must be an string or an array, "%s" received.', $key, is_object($value) ? get_class($value) : gettype($value)));
         }
     }
 }
 public function testInvokeRegisterPathForFullTemplateName()
 {
     $viewConfig = ['resolver' => ['foo' => ['bar' => 'foo/bar.tpl']]];
     $config = new SystemConfig();
     $config['view'] = $viewConfig;
     $resolver = $this->getMock(Resolver::CLASS);
     $modules = new Modules();
     $listener = new ConfigureResolverListener();
     $listener->setResolver($resolver);
     $listener->setModules($modules);
     $listener->setConfig($config);
     $resolver->expects($this->once())->method('registerTemplatePath')->with($this->identicalTo(Resolver::getFullTemplateName('foo', 'bar')), $this->identicalTo('foo/bar.tpl'));
     $listener(new ModulesEvent());
 }
Exemple #3
0
 public function testResolverRaiseExceptionIfLastUsedModuleNotContainTemplate()
 {
     $resolver = new Resolver();
     $resolver->registerModulePath('Bar', $this->barDir);
     $this->assertSame($this->barIndex, $resolver->resolve('/index/index', 'Bar'));
     $this->setExpectedException(TemplateNotFoundException::CLASS);
     $resolver->resolve('foo/bar');
 }