added a method to create Route instance#1906
Conversation
…nherit from Slim\Route to add other methods: ex: getIsSecured()
|
@vicolachips44 , I also was looking for a way to set my own implementation of But, @codeguy , @silentworks is this ok for merge? It would be much better to use this approach as a Slim official release, so we would not break compatibility in near future official releases, please! |
|
Why not just override |
|
@akrabat , thanks for your question! See the piece of code below. IMHO, it push us to change to much core code just to insert a new function to the inherited class. I am concerned about overriding map:
That is why I agree with this merge request. Seems reasonable. Correct me if I'm wrong. class RouteB extends \Slim\Route{
public function allow($roles){
//my new function
}
}
class RouterB extends \Slim\Router {
/**
*
* {@inheritDoc}
* @see \Slim\Router::map()
*/
public function map($methods, $pattern, $handler)
{
if (!is_string($pattern)) {
throw new InvalidArgumentException('Route pattern must be a string');
}
// Prepend parent group pattern(s)
if ($this->routeGroups) {
$pattern = $this->processGroups() . $pattern;
}
// According to RFC methods are defined in uppercase (See RFC 7231)
$methods = array_map("strtoupper", $methods);
/* ******************************************************
* Is this approach ok just to instantiate RouteB instead of Slim\Route ?????
*******************************************************
*/
$route = new RouteB ($methods, $pattern, $handler, $this->routeGroups, $this->routeCounter);
$this->routes[$route->getIdentifier()] = $route;
$this->routeCounter++;
return $route;
}
}
$container['router'] = new RouterB(); |
You'll still have to do this. |
but the point is: All we need is just to tell If |
By doing so one can