private $class;
/**
- * @param $resource
- * @param array $config
+ * @param string $pathInfo
+ * @param array $config
*/
- public function __construct($resource, array $config)
+ public function __construct($pathInfo, array $config)
{
- $this->url = $resource;
+ $this->url = $pathInfo;
$this->config = $config;
$this->methods = isset($config['methods']) ? (array)$config['methods'] : array();
$this->target = isset($config['target']) ? $config['target'] : null;
}
try {
- $classRexl->getMethod($method);
+ $methRexl = $classRexl->getMethod($method);
} catch (\ReflectionException $ex) {
return null;
}
+ // use only public methods
+ // to avoid calling inherited protected methods
+ if(!$methRexl->isPublic()) {
+ return null;
+ }
+
return $this->config['_controller'];
}
private $routeUsing__invoke;
private $routeWithParameters;
private $routeInvalid;
+ private $routeWithPrivateMethod;
protected function setUp()
{
)
);
+ $this->routeWithPrivateMethod = new Route(
+ '/home/:user/:id',
+ array(
+ '_controller' => '\PHPRouter\Test\Fixtures\SomeController::privateMethod',
+ 'methods' => array(
+ 'GET',
+ ),
+ )
+ );
+
$this->routeWithParameters = new Route(
'/page/:page_id/:page_size',
array(
$this->assertNull($this->routeInvalid->getValidController());
}
+ public function testGetValidController_privateMethod()
+ {
+ $this->assertNull($this->routeWithPrivateMethod->getValidController());
+ }
+
public function testSetGetParameters()
{
$param = array("page_id" => 123);
$rexl->setAccessible(true);
$provider = array(
+ array(true, true, "1"),
+ array(true, false, ""),
array(true, 1, "1"),
array(true, 0, "0"),
array(true, 1.23, "1.23"),
array(true, new PrintableDate(), "to string"),
array(false, null),
array(false, array()),
+ array(false, date_create()),
);
foreach ($provider as $case) {