FOF30\Factory\MagicSwitchFactory::dispatcher PHP Метод

dispatcher() публичный Метод

Creates a new Dispatcher
public dispatcher ( array $config = [] ) : Dispatcher
$config array The configuration values for the Dispatcher object
Результат FOF30\Dispatcher\Dispatcher
    public function dispatcher(array $config = array())
    {
        $dispatcherClass = $this->container->getNamespacePrefix($this->getSection()) . 'Dispatcher\\Dispatcher';
        try {
            return $this->createDispatcher($dispatcherClass, $config);
        } catch (DispatcherNotFound $e) {
            // Not found. Let's go on.
        }
        $dispatcherClass = $this->container->getNamespacePrefix('inverse') . 'Dispatcher\\Dispatcher';
        try {
            return $this->createDispatcher($dispatcherClass, $config);
        } catch (DispatcherNotFound $e) {
            // Not found. Return the magically created Dispatcher
            $magic = new DispatcherFactory($this->container);
            // Let's pass the section override (if any)
            $magic->setSection($this->getSection());
            return $magic->make($config);
        }
    }

Usage Example

Пример #1
0
 /**
  * @group           MagicSwitchFactory
  * @covers          FOF30\Factory\MagicSwitchFactory::dispatcher
  * @dataProvider    MagicSwitchFactoryDataprovider::getTestDispatcher
  */
 public function testDispatcher($test, $check)
 {
     $msg = 'MagicSwitchFactory::dispatcher %s - Case: ' . $check['case'];
     $container = new TestContainer(array('componentName' => $test['component'], 'backEndPath' => $test['backend_path']));
     $platform = $container->platform;
     $platform::$isAdmin = $test['backend'];
     // Required so we force FOF to read the fof.xml file
     $dummy = $container->appConfig;
     $factory = new MagicSwitchFactory($container);
     $result = $factory->dispatcher();
     $this->assertEquals($check['result'], get_class($result), sprintf($msg, 'Returned the wrong result'));
 }