convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
- <testsuites>
- <testsuite name="PHP Router">
- <directory>tests</directory>
- </testsuite>
- </testsuites>
-
- <filter>
- <whitelist>
- <directory>./</directory>
- <exclude>
- <directory>./tests/Fixtures</directory>
- <directory>./vendor</directory>
- </exclude>
- </whitelist>
- </filter>
-
- <logging>
- <log type="coverage-text" target="php://stdout" showUncoveredFiles="true"/>
- <log type="coverage-clover" target="logs/clover.xml"/>
- </logging>
-
+ <testsuites>
+ <testsuite name="PHP Router">
+ <directory>tests</directory>
+ </testsuite>
+ </testsuites>
+ <filter>
+ <whitelist>
+ <directory>./</directory>
+ <exclude>
+ <directory>./tests/Fixtures</directory>
+ <directory>./vendor</directory>
+ </exclude>
+ </whitelist>
+ </filter>
+ <logging>
+ <log type="coverage-text"
+ target="php://stdout"
+ showUncoveredFiles="true" />
+ <log type="coverage-clover"
+ target="logs/clover.xml" />
+ </logging>
+ <php>
+ <server name="REQUEST_TIME" value="0" />
+ </php>
</phpunit>
$this->name = isset($config['name']) ? $config['name'] : null;
$this->parameters = isset($config['parameters']) ? $config['parameters'] : array();
$action = explode('::', $this->config['_controller']);
+ $this->class = isset($action[0]) ? $action[0] : null;
$this->action = isset($action[1]) ? $action[1] : null;
}
return $this->config['_controller'];
}
- public function dispatch()
+ public function dispatch($instance = null)
{
- $action = explode('::', $this->config['_controller']);
- $instance = new $action[0]();
+ is_null($instance) and $instance = new $this->class();
if ($this->parametersByName) {
$this->parameters = array($this->parameters);
ob_start();
- if (empty($action[1]) || trim($action[1]) === '') {
+ if (empty($this->action) || trim($this->action) === '') {
// __invoke on a class
call_user_func_array($instance, $this->parameters);
} else {
- call_user_func_array(array($instance, $action[1]), $this->parameters);
+ call_user_func_array(array($instance, $this->action), $this->parameters);
}
$result = ob_get_clean();
--- /dev/null
+<?php
+
+namespace PHPRouter\Test\Fixtures;
+
+final class CustomController
+{
+ private $config;
+
+ public function __construct($config)
+ {
+ $this->config = $config;
+ }
+
+ public function index()
+ {
+ }
+}