Comments (15)
Trying to debug this myself locally, in RouteCollection on line 72 I change:
if ($handler instanceof Closure ||
(is_object($handler) && is_callable($handler))
) {
to
if ($handler instanceof Closure ||
(is_object($handler) || is_callable($handler))
) {
Fixes the first error, then you get a new set of errors which I didn't get that far with:
Warning: array_key_exists(): The first argument should be either a string or an integer in /var/www/source/vendor/league/container/src/Container.php on line 189
Warning: array_key_exists(): The first argument should be either a string or an integer in /var/www/source/vendor/league/container/src/Container.php on line 194
Warning: Illegal offset type in /var/www/source/vendor/league/container/src/Container.php on line 208
Fatal error: Function name must be a string in /var/www/source/vendor/league/container/src/Container.php on line 210
from route.
Will have a look at this tomorrow morning and ensure all callables are
accepted
On 7 Sep 2015 22:23, "G4MR" [email protected] wrote:
Trying to debug this myself locally, in RouteCollection on line 72 I
change:if ($handler instanceof Closure ||
(is_object($handler) && is_callable($handler))
) {to
if ($handler instanceof Closure ||
(is_object($handler) || is_callable($handler))
) {Fixes the first error, then you get a new set of errors which I didn't get
that far with:Warning: array_key_exists(): The first argument should be either a string or an integer in /var/www/source/vendor/league/container/src/Container.php on line 189
Warning: array_key_exists(): The first argument should be either a string or an integer in /var/www/source/vendor/league/container/src/Container.php on line 194
Warning: Illegal offset type in /var/www/source/vendor/league/container/src/Container.php on line 208
Fatal error: Function name must be a string in /var/www/source/vendor/league/container/src/Container.php on line 210
—
Reply to this email directly or view it on GitHub
#61 (comment).
from route.
I figured out what's wrong or a solution to my issue:
RouteCollection on line 72 I change:
if ($handler instanceof Closure ||
(is_object($handler) && is_callable($handler))
) {
to
if ($handler instanceof Closure ||
(is_object($handler) || is_callable($handler))
) {
And in Strategy/AbstractStrategy.php on line 27 if I changed line 27 from:
$this->getContainer()->get($controller[0]),
to
$controller[0],
Everything works as expected. Both [$test, 'index'] and 'test::index', now I'm assuming this line creates a new object for the controller class and then attempts to call it normally so you don't have to forcefully call static on the class method. I guess a simple solution would be to check if $controller[0] is already an object?
$controller = [
is_object($controller[0]) ? $controller[0] : $this->getContainer()->get($controller[0]),
$controller[1]
];
from route.
It's not actually a static call but a pointer so that the class can be
resolved via the container, your solution looks to be correct but I need to
be sure it fits all scenarios so I'll put together some test cases tomorrow
and get all of them passing.
On 7 Sep 2015 22:44, "G4MR" [email protected] wrote:
I figured out what's wrong or a solution to my issue:
RouteCollection on line 72 I change:
if ($handler instanceof Closure ||
(is_object($handler) && is_callable($handler))
) {to
if ($handler instanceof Closure ||
(is_object($handler) || is_callable($handler))
) {And in Strategy/AbstractStrategy.php on line 27 if I changed line 27 from:
$this->getContainer()->get($controller[0]),
to
$controller[0],
Everything works as expected. Both [$test, 'index'] and 'test::index', now
I'm assuming this line creates a new object for the controller and then
attempts to call it normally so you don't have to forcefully call static on
the class method. I guess a simple solution would be to check if
$controller[0] is already an object?$controller = [
is_object($controller[0]) ? $controller[0] : $this->getContainer()->get($controller[0]),
$controller[1]
];—
Reply to this email directly or view it on GitHub
#61 (comment).
from route.
Sounds good.
from route.
Should be fixed by 6029f14
from route.
Did you forget to update AbstractStrategy.php on Line 27 because I'm still getting:
Warning: array_key_exists(): The first argument should be either a string or an integer in /var/www/source/vendor/league/container/src/Container.php on line 189
Warning: array_key_exists(): The first argument should be either a string or an integer in /var/www/source/vendor/league/container/src/Container.php on line 194
Warning: Illegal offset type in /var/www/source/vendor/league/container/src/Container.php on line 208
Fatal error: Function name must be a string in /var/www/source/vendor/league/container/src/Container.php on line 210
I played with my solution above checking $controller[0] to see if it was an object already seemed to work locally.
Just to post code with the issue again:
<?php
/**
* ----------------------------
* Composer Autoloader
* ----------------------------
*/
require_once dirname(__DIR__) . '/source/vendor/autoload.php';
use League\Route;
use League\Container;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class Test {
public function index(Request $request, Response $response) {
return new Response("Webpage2", Response::HTTP_OK);
}
}
$testing = new Test();
$router = new Route\RouteCollection();
$router->addRoute('GET', '/', function(Request $request, Response $resp) {
$resp->setContent("Testing");
return $resp;
});
//$router->addRoute('GET', '/test', 'test::index');
$router->addRoute('GET', '/test', [$testing, 'index']);
$dispatcher = $router->getDispatcher();
$request = Request::createFromGlobals();
$response = $dispatcher->dispatch($request->getMethod(), $request->getPathInfo());
$response->send();
from route.
Yep, apologies, I rushed that, will add the check asap
from route.
alright
from route.
I noticed you've written another version under the develop branch, when is that expected to drop because it has some features that I've wanted like get,post,etc... to shorten the length of the addRoute method (now map in develop)
from route.
@G4MR expect a tag over the weekend, however, those convenience methods are already there in version 1
from route.
those convenience methods are already there in version 1
I must have overlooked them, my mistake.
from route.
tag/1.2.3
from route.
thanks :)
from route.
Hello, I use the magic method __invoke to use the instance of the class to group routes
<?php
use League\Route\RouteGroup;
abstract class Router
{
abstract protected function routes(RouteGroup $group);
public function __invoke(RouteGroup $group)
{
$this->routes($group);
}
}
class UserRoutes extends Router
{
protected function routes(RouteGroup $group)
{
$group->post("/users", "UserController::index");
}
}
$router = new League\Route\Router;
$request = new Request; // Psr\Http\Message\ServerRequestInterface
// Using UserRoutes
$router->group("/api", new UserRoutes());
$response = $router->dispatch($request);
from route.
Related Issues (20)
- Feature request: custom attributes for route and route group accessible within a middleware HOT 6
- Catch Exception Best Way HOT 3
- Feature request: map with array of methods HOT 1
- Feature request: make $request available in getOptionsCallable HOT 2
- I cannot make post requests HOT 5
- Url resolve fails with 2 numeric parameter HOT 3
- Add an option to get the target route from the middleware HOT 2
- Why isn't the middleware stack executed for unmatched routes? HOT 2
- psr/simple-cache version constraints HOT 2
- Allow for empty route paths to be treat as the base route path HOT 2
- Nested groups are required HOT 1
- Feature request: Treat Route `$handler` that implements RequestHandlerInterface as callable
- Root exception class (and possibly, its children) not compatible with PHP7+
- Request matcher? guess if ServerRequest can be handled
- Dispatcher: handle and find HOT 1
- Feature: Extra map() options
- Method to get declared routes?
- How can I assign controller to errors http ? HOT 1
- Cannot Change Cache Key
- Is this package still actively maintained? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from route.