auraphp / aura.router Goto Github PK
View Code? Open in Web Editor NEWA web router implementation for PHP.
Home Page: http://auraphp.com/packages/3.x/Router/
License: MIT License
A web router implementation for PHP.
Home Page: http://auraphp.com/packages/3.x/Router/
License: MIT License
Can we delete the action only branch for it is merged to develop-2 ?
How does one set up language routes with Aura.Router? I want to match /en/blog/read/1
and /blog/read/1
with the same route but it seems I would need to set up 2 routes: one that is with the language prefix, the other without
$router->add('read', '/blog/read/{id}');
$router->add('lang_read', '/{lang}/blog/read/{id}');
Or there is another option?
It would be nice if it was possible to use something other than a regex to validate individual route parameters. Ideally, this would take the form of a callable that is passed the value and returns true or false. For example, I'm using the Composer Semver package elsewhere in a project, and am using version numbers as part of the URL. Ideally I'd just be able to wire up the two.
Hi,
Could I just check, other than PHP 5.4's new 'quick array' brackets ($array = [];) is there any other code in use that isn't php 5.3 compatible? I've been scouring through the source on github but cant see anything else other than the array brackets that would prevent php 5.3 compatibility.
Possible bug
When there is
$map->add(null, '/{:controller}/{:action}/{:id}');
Or
$map->add('named_route', '/{:controller}/{:action}/{:id}');
in-front of the route
$map->add('read', '/blog/read/{:id}{:format}', [
'params' => [
'id' => '(\d+)',
'format' => '(\.json|\.html)?',
],
'values' => [
'controller' => 'blog',
'action' => 'read',
'format' => '.html',
]
]);
And when a request for a get http://localhost:8000/blog/read/1.json
format not recognized
Array ( [controller] => blog [action] => read [id] => 1.json )
But when
$map->add(null, '/{:controller}/{:action}/{:id}');
Or
$map->add('named_route', '/{:controller}/{:action}/{:id}');
is below the route
$map->add('read', '/blog/read/{:id}{:format}', [
'params' => [
'id' => '(\d+)',
'format' => '(\.json|\.html)?',
],
'values' => [
'controller' => 'blog',
'action' => 'read',
'format' => '.html',
]
]);
It works
Array ( [controller] => blog [action] => read [format] => .json [id] => 1 )
I want to use the Generator
in a view script.
It seems like I want to be able to do it like this, I guess?
// view.php
echo $this->a(
$this->url()->generate('route', $params),
'click here'
);
// or possibly even:
echo $this->a(
$this->url('route', $params),
'click here'
);
I did it like this the other day, and it seemed a little awkward.
I set up my DI to grab the Aura\Html helper locator, and set the url
key to a
lazyGetCall
on the router, and then wrapped that in a function...
<?php
class Config extends ContainerConfig
{
public function modify(Container $di)
{
$helpers = $di->get('aura/html:helpers');
$url = $di->lazyGetCall('radar/adr:router', 'getGenerator');
$helpers->set(
'url',
function () use ($url) {
return $url;
}
);
}
}
...That seems pretty weird though.
If Generator
had this:
//...
public function __invoke($name = null, $data = [])
{
if (null == $name) {
return $this;
}
return $this->generate($name, $data);
}
I wouldn't need to wrap it in a function to use with the helpers, and I could
just call $this->url(...)
, instead of
$this->url()->generate(...)
, but if needed, could also
$this->url()->generateRaw(...)
However, again... it doesnt seem quite right to me to add the __invoke
method
like that in the Generator
.
Maybe I should just be adding it into the view and not mess with the helpers?
eg:
<?php
class Config extends ContainerConfig
{
public function modify(Container $di)
{
$view = $di->get('aura/view:view');
$generator = $di->get('radar/adr:router')->getGenerator();
$view->addData(['urlHelper' => $generator]);
}
}
// in view:
echo $this->a(
$this->urlHelper->generate('route', $params),
'click here'
);
Are other people doing this?
Thoughts? Recommendations? Best Practices?
Hi,
Are wildcard routes supported? ie /post/* where * could be 1 to n params.
Great router!
Hi @auraphp/code-team ,
I have been thinking a lot on how not to use phpunit.sh for there can be people who use Windows.
I love to change the current way of using phpunit.sh to test containers with require-dev
in composer.
We can add aura/di
into require-dev and users can install the packages with --no-dev
for production.
And now if you are going to test or write a PR .
composer install --dev
phpunit -c tests/unit
phpunit -c tests/container
This seems to be nice. Also we could promote the use of --no-dev
.
Thank you.
Right now, if I define a route that does not explicitly contain a trailing slash, and then I use one, it won't match.
E.g. route defined is /home, but I go to example.com/home/, I get a 404.
It's extra useful for things like format/output as used in the README example. Once you can set that a route should be cut
, it will continue trying to find a route that matches but without the cut part. An example:
$router->add(
'output',
'{format}',
->cut()
->addTokens(array(
'format' => '(\.[^/]+)?',
));
$router->add(
'blog.read',
'/blog/{id}',
->addTokens(array(
'id' => '\d+',
));
that would make blog.read
match in any of the cases:
/blog/12.json
/blog/12.html
/blog/12.xml
This applies to this library and probably all the others.
It would be very helpful to people unfamiliar with aura to have a new section before the "Basic Usage" section called "Getting Started: aura.router as a Stand-Alone Library".
This should include step by step instructions required to follow to install and use the library. For example, it can look something like this:
Ideally, there would also be a similar section called "Getting Started: aura.router with the aura framework"
Also note that a short description of dependency injection, with a link or two perhaps, near the top of each library README, would also be helpful, IMO.
Hello.
I'm a bit confused about 'handler' method and property names in Route
class (3.x).
Test route:
$map->route('test.route', '/', function($request, $response) {
return $response;
});
When the route matched and $route->handler
filled with callable,
Closure Object
(
[parameter] => Array
(
[$request] =>
[$response] =>
)
)
it is confusing when you try to call it directly via $route->handler($request, $response)
because Route::handler()
exists and gets called, instead of Closure Object. So we have to put $route->handler
contents into variable and call it then or use call_user_func($route->handler, $myParam)
to run that callable.
Should either $route->handler
or $route->handler()
be renamed to avoid it? Or this is expected behavior?
Consider a route like the below
$router->add('archieve', '/archieve/{year}/{month}/{day}')
->addTokens([
'year' => '[^/]+',
'month' => '[^/]+',
'day' => '[^/]+'
]);
When you try to generate route as
echo "<a href=\"" . $router->generate('archieve') . "\">Archieve</a>";
echo "<a href=\"" . $router->generate('archieve', ['year' => 2013]) . "\">Archieve</a>";
It generates something like /archieve///
and /archieve/2013//
. We should remove the /
if the route has no more values after that.
I think
$map = require '/path/to/aura.router/instance.php';
Should be
$map = require '/path/to/aura.router/scripts/instance.php';
As the route class uses property overloading and a __get() magic method, it should implement also an __isset() megic method.
public function __isset($key)
{
return isset($this->$key);
}
Currently I don't know whether we can make an option like make use of different controller for different sub domain.
$router->add('blog.browse', '/blog')
->addValues(array(
'action' => 'BlogBrowseAction',
))
->addDomain('*.hello.com');
$router->add('m.blog.browse', '/blog')
->addValues(array(
'action' => 'BlogMobileBrowseAction',
))
->addDomain('m.hello.com');
We can do in 2.x with adding a callable, but may be the controller and params may not be able to change
->setIsMatchCallable(function(array $server, \ArrayObject $matches) {
if ($server['HTTP_HOST'] == 'http://example.com') {
return false;
}
})
Thank you
Right now route matcher matches routes in FIFO order.
For some reasons you might want the matcher to match in FILO order.
I propose to add a way for the matcher to know how he should process. At a first sight, it would be very easy to implement just by reversing this loop:
Line 117 in 57a8066
That could look like:
$routerContainer->getMatcher()->setReverseMatchOrder(true);
What's your opinion?
I know this sounds silly....but
I cannot make the router to recognize urls when the index.php is inside a subdirectory.
I added the RewriteBase rule but still the router works only if I prepend the subdirectory in rooute definitions.
/path/to/project/web/subdir/index.php
// web/ is the public web folder, the docroot
$dispatcher->setObject('hello',//doesn't work
$dispatcher->setObject('subdir/hello',// works...
what am i missing?
The latest update in this commit: 0bcdaa1 breaks php 5.3 compatibility. Was this intentional or an oversight as the blogpost announcing the update states "you should be able to update-in-place without any problems" which wont be the case for anyone on 5.3.
I know 5.4 or above is desirable, but is it really worth killing off 5.3 over a handful of shorthand arrays? There's surely no need for that is there?
In the advanced section
method -- The $server['REQUEST_METHOD'] must match one of these values.
secure -- When true the $server['HTTPS']
,
I feel its $_SERVER , but as I am confused whether you was trying to represent the variable in signature function over
is_match -- A custom callback or closure with the signature function(array $server, \ArrayObject $matches)
Sample code I tried is not working , confusion over the format
in documentation . See first example no dot for format , second one has dot for the format . I feel we don't need the dot to be passed . Do you feel so ? Then why ? Normally we say html , atom like so , not .html , .xml etc .
<?php
$package_dir = dirname( __DIR__ ) . '/auraphp/system/package';
$loader = require_once $package_dir . '/Aura.Autoload/scripts/instance.php';
$loader->add('Aura\Router', $package_dir . '/Aura.Router/src/' );
$loader->register();
use Aura\Router\Map;
use Aura\Router\RouteFactory;
$map = new Map(new RouteFactory);
/*
$map->add('home', '/');
$map->add(null, '/{:controller}/{:action}/{:id}');
$map->add('read', '/blog/read/{:id}{:format}', [
'params' => [
'id' => '(\d+)',
'format' => '(\..+)?',
],
'values' => [
'controller' => 'blog',
'action' => 'read',
'format' => '.html',
]
]);
*/
$map->add('read', '/blog/read/{:id}{:format}', [
'params' => [
'id' => '(\d+)',
'format' => '(\..+)?',
],
'values' => [
'controller' => 'blog',
'action' => 'read',
'id' => 1,
'format' => '.html',
],
'secure' => false,
'method' => ['GET'],
'routable' => true,
'is_match' => function(array $server, \ArrayObject $matches) {
// disallow matching if referred from example.com
if ($server['HTTP_REFERER'] == 'http://example.com') {
return false;
}
// add the referer from $server to the match values
$matches['referer'] = $server['HTTP_REFERER'];
return true;
},
'generate' => function(\Aura\Router\Route $route, array $data) {
$data['foo'] = 'bar';
return $data;
}
]);
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$route = $map->match($path, $_SERVER);
if (! $route) {
// no route object was returned
echo "No application route was found for that URI path.";
exit;
}
echo " Controller : " . $route->values['controller'];
echo " Action : " . $route->values['action'];
echo " Format : " . $route->values['format'];
I have started the server with
$ php -s localhost:8000
from the default directory . I guess, the error is throwing by Apache and not by Router itself .
Hi, I'm trying out version 3.
It's possible to specify matching constraints on routes for hosts/subdomains. But I can't find the possibility to then generate these routes? For example I want to generate a url with a specific subdomain. But you only get the path.
Is it possible to add this feature?
Instead of allowing a single host, it could be handy to match more than one e.g. when multiple domains are used.
public function match($path, array $server = null) {
...
// Then a call to $route->isMatch($path, $server);
}
So, either remove the null or use $_SERVER if null?
I can make a change if you think it's warranted.
J.
Eg : When using a route which have a language it will be good to have a default language set in the router than adding it on each route.
$router->setDefaultParams(array('lang' => 'en', 'format' => '.html'))
so we don't need to add the default format, change the language on all routes. The idea is when a route add is called internally we can add to addValues
what do you think ?
Hey guys, I have optional parameters set in a URL as follows:
$routes = [
[
"name" => "API",
"path" => "/api/{version}/{class}{/id,function,third}/"
]
];
$newRoute = $this->router->add($route["name"], $route["path"]);
if(isset($route["tokens"]))
$newRoute->addTokens($route["tokens"]);
if(isset($route["values"]))
$newRoute->addValues($route["values"]);
and I have the controller matching it printing it out like this:
if(isset($this->route->params["id"]))
echo "id = " . $this->route->params["id"] . "<br><br>";
if(isset($this->route->params["function"]))
echo "function = " . $this->route->params["function"] . "<br><br>";
if(isset($this->route->params["third"]));
echo "third = " . $this->route->params["third"] . "<br><br>";
exit;
So that if you have a URL like /api/1/class/id/function/third/, it'll print out like:
id = id
function = function
third = third
however, if I only specify a single parameter (i.e. /api/1/class/id/), it will still print like this:
id = id
third =
So it always sets third, regardless of whether or not it's been specified.
Anybody know why? Is it my syntax that's causing the issue?
The Matcher current matches against the value of $request->getUri()->getPath();
.
Is this preferable to using $request->getRequestTarget()
?
I was wondering if you'd accept a pull request to implement functionality that would mean the Router class (Aura\Router\Router) would remember whether or not it had attempted to match a route yet, and if so, which route it matched. I have a need for this functionality in something I'm developing, and it would make my life easier if the Aura.Router module did this by itself.
In the README.md file, the syntax for long-form routes is described as
$map->add('read', array(
'path' => '/blog/read/{:id}{:format}',
'params' => array(
'id' => '(\d+)',
'format' => '(\..+)?',
),
[...]
));
while according to the current actual code, the path should just be the second parameter, as in
$map->add('read', '/blog/read/{:id}{:format}', array(
'params' => array(
'id' => '(\d+)',
'format' => '(\..+)?',
),
[...]
));
This is in both 'Mapping A Route' and 'Long-Form Route Specification'.
When working on the screencast for Aura.Router I happened to get into an issue ( probably a bug, didn't get time to checkout ) .
I made a route setRoutable(false)
, but was still showing in the getDebug()
. May be I missed something.
Code tried
require dirname(__DIR__) . '/Aura.Router/autoload.php';
use Aura\Router\RouterFactory;
class SomeController
{
public function indexAction()
{
echo "Hello Contact";
}
}
$router_factory = new RouterFactory();
$router = $router_factory->newInstance();
$router->add('home', '/')
->setValues([
'controller' => function () use ($router) {
echo "Hello World! <br />";
// echo "<a href=\"{$router->generate('contact', [])}\">Contact</a>";
echo "<a href=\"{$router->generate('archieve', [])}\">Archieve</a>";
echo "<a href=\"{$router->generate('archieve', ['year' => 2014])}\">Archieve 2014</a>";
echo "<a href=\"{$router->generate('archieve', ['year' => 2014, 'month' => '04'])}\">Archieve 2014 - 04 </a>";
echo "<a href=\"{$router->generate('archieve', ['year' => 2014, 'month' => '04', 'day' => '25'])}\">Archieve 2014-04-25</a>";
},
]);
$router->add('contact', '/contact')
->setValues([
'controller' => 'SomeController',
'action' => 'indexAction'
])
->setRoutable(false);
$router->add('archieve', '/archieve{/year,month,day}')
->addTokens([
'year' => '\d{4}',
'month' => '\d{2}',
'day' => '\d{2}',
])
->setValues(['controller' => function () {
echo "Archieve ";
}]);
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$route = $router->match($path, $_SERVER);
if ($route) {
$controller = $route->params['controller'];
if ($controller instanceof Closure) {
$controller();
} else {
$obj = new $controller;
$action = $route->params['action'];
$obj->{$action}();
}
} else {
$routes = $router->getDebug();
foreach ($routes as $route) {
echo $route->name . "<br />";
}
echo "No application route found!";
}
When we add a REST route
$router->attachResource('blog', '/blog');
array(5) { ["controller"]=> string(4) "blog" ["action"]=> string(4) "read" ["id"]=> string(1) "1" ["format"]=> NULL ["REQUEST_METHOD"]=> string(3) "GET" }
http://localhost:8000/blog/add pointing to same route with action read
.
array(5) { ["controller"]=> string(4) "blog" ["action"]=> string(4) "read" ["id"]=> string(3) "add" ["format"]=> NULL ["REQUEST_METHOD"]=> string(3) "GET" }
I assume the id
should be made as \d
Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'Aura\Router\RouteCollection' does not have a method 'generateRaw' in /var/www/github.com/harikt/aurav2bookcode/vendor/aura/router/src/Router.php on line 97
Hello.
Seems like ServerRequestInterface
is not needed here: https://github.com/auraphp/Aura.Router/blob/3.x/src/Route.php#L11
Thanks
From the http://blog.alejandrocelaya.com/2015/09/12/my-first-approach-to-zend-expressive/
I needed routes to support optional params at the beginning of the path (the language). Neither Aura.Router or FastRoute do it, so I had to stick with ZF2's router .
Use case was <lang>/blog
. If no lang the default should take en
without /en/blog
but route from /blog
.
Is it possible to create urls without urlencode ?
Eg : in aura/asset-bundle when we pass the file path as /css/something.css
all will be converted to %2Fcss%2Fsomething.css . That means even when we have the real path with some sort of file moved, the css may not get loaded.
Any idea to fix for routes like that ?
List of typos seen , so we don't want to add more commits ;) .
1 ) Currently in https://github.com/auraphp/Aura.Router#matching-a-route
becuase
Next major commits can resolve this or before next Beta :) .
If anything like that is found add in comments section .
The whole code I have is
<?php
$package_dir = dirname( __DIR__ ) . '/auraphp/system/package';
$loader = require_once $package_dir . '/Aura.Autoload/scripts/instance.php';
$loader->add('Aura\Router\\', $package_dir . '/Aura.Router/src/' );
$loader->register();
use Aura\Router\Map;
use Aura\Router\RouteFactory;
$map = new Map(new RouteFactory);
$map->add('home', '/');
$map->add(null, '/{:controller}/{:action}/{:id}');
$map->add('read', '/blog/read/{:id}{:format}', [
'params' => [
'id' => '(\d+)',
'format' => '(\.json|\.html)?',
],
'values' => [
'controller' => 'blog',
'action' => 'read',
'format' => '.html',
]
]);
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
//echo $path . '<pre>' . print_r( $map->getRoutes() , true );
$route = $map->match($path, $_SERVER);
if (! $route) {
// no route object was returned
echo "No application route was found for that URI path.";
exit;
}
echo " Controller : " . $route->values['controller'];
echo " Action : " . $route->values['action'];
echo " Format : " . $route->values['format'];
Started server via php -S localhost:8000
http://localhost:8000/blog/read/1
Controller : blog Action : read Notice: Undefined index: format in /media/Linux/auracomponentstest/index.php on line 38 Format :
Yes the format is not there , so the error , but
http://localhost:8000/blog/read/1.html
http://localhost:8000/blog/read/1.json
all throwing
`Not Found
The requested resource /blog/read/1.html was not found on this server.`
The example suggests to use the key 'controller' with a value of anonymous function/closure, but later when Route.generate is called, it loops through all the values and calls urlencode on each, throwing a php warning as the anonymous function/closure is not a string (Warning: urlencode() expects parameter 1 to be string). Don't know if you wish to add to the code or update the microframework docs to resolve this.
I've recently tried this out and a working setup can be found here:
https://github.com/Tuxion/DoctrineRest/tree/develop
Summary of what to change.
/test/unit/
the /test
folder is the place to define phpunit.xml
, bootstrap.php
, etc.phpunit.xml
file should have two directories for tests, both the container and unit tests.bootstrap.php
file should take into account the new relative paths..travis.yml
file should point to the new locations.Howdy.
At the moment, on my dev box, a full URL could look something like the following:
http://10.10.10.10/example/www/public/index.php/blog/49
This means, that at present I have to do the following, otherwise I get a 404:
$map->get('Example\Misc\Demo','/example/www/public/index.php/blog/{id}');
What would be cool is if I could say
$map->urlprefix('/example/www/public/index.php'); $map->get('Example\Misc\Demo','/blog/{id}');
Similarly, if I set an alias on my server of '/bob' pointing to '/example/www/public/index.php', it would be equally cool to be able to do:
$map->urlprefix('/example/www/public/index.php'); $map->urlalias('/bob'); $map->get('Example\Misc\Demo','/blog/{id}');
In the documentation code snippets, your variable assignment is not always clear, for example:
Then call the match() method to match a PSR-7 ServerRequestInterface instance to a mapped Route.
match($request); ?>
Great, but where does $request come from ?
It would be nice if you could show a basic "real-world" type example from start to finish. Would be easier to get a feel for how things work rather than a bunch of text interspersed with code snippets and its left to the reader to figure out how what goes where/how/when.
https://github.com/auraphp/Aura.Router/blob/3.x/docs/getting-started.md
Having a hard time getting this code to work. Would have helped if it specifically mentioned needing \Zend\Diactoros\ServerRequest and a link to download it.
$request = \Zend\Diactoros\ServerRequestFactory::fromGlobals();
$route = $matcher->match($request);
I'm presently stuck at
$callable = $route->handler;
$response = $callable($request);
Error: Warning: Missing argument 2 for {closure}(), called in ... ... on line 15.
The error refers to:
$map->get('blog.read', '/blog/{id}', function ($request, $response) {
$id = (int) $request->getAttribute('id');
$response->body()->write("You asked for blog entry {$id}.");
return $response;
});
Apparently $response = $callable($request);
should have a 2nd parameter but I'm not sure what and the example code does not have a 2nd parameter.
Please see my code at: https://github.com/thinsoldier/aura-router-test
I'm pasting the code exactly from your "Getting Started" and trying to get its basic functionality working.
Also, and this might just be my machine or web server, but at times this example code takes 11 seconds to run.
Hi there!
I've been using Aura's router a tiny bit (still at noob level to be honest) and the first thing I did was write something that allows me to configure the routes using an array. Example (from here):
$routes = [
'home' => [
'pattern' => '/',
'controller' => HomeController::class,
],
'project' => [
'pattern' => '/project/{user}/{repository}',
'controller' => ProjectController::class,
],
];
// Then later on:
$router = (new RouterFactory())->newInstance();
foreach ($routes as $routeName => $route) {
$router->add($routeName, $route['pattern'])
->addValues(['controller' => $route['controller']]);
}
This is of course very basic, but I was wondering if you have ever considered and discussed something like that. I guess that wouldn't fit everybody's usage, but for my usage, that's the only way I would use a router as soon as I get more than 2 routes.
I keep seeing requests in the #auraphp IRC channel for help with Aura.Router, especially with release 3. Mostly people are confused about how to actually use it, because many competing products do so much more. What's really needed is an example of usage from a DOCROOT/index.php point of view in the documentation someplace.
On the README.MD on the example regarding Attaching Route Groups the code should be
$name_prefix = 'blog';
$path_prefix = '/blog';
$router->attach($name_prefix, $path_prefix, function ($router) {
$router->add('browse', '{format}')
->addTokens(array(
'format' => '(\.json|\.atom|\.html)?'
))
->addValues(array(
'format' => '.html',
));
$router->add('read', '/{id}{format}')
->addTokens(array(
'id' => '\d+',
'format' => '(\.json|\.atom|\.html)?'
))
->addValues(array(
'format' => '.html',
));
$router->add('edit', '/{id}/edit{format}')
->addTokens(array(
'id' => '\d+',
'format' => '(\.json|\.atom|\.html)?'
))
->setValues(array(
'format' => '.html',
));
});
Turning on HTTPS shouldn't cause routes not marked secure to be not found. Serving a route that does not require HTTPS over HTTPS improves the security of that route.
When playing with creating routes like
$router->add('post.list', '/post')
->setValues(array(
'controller' => 'post',
'action' => 'actionList'
));
$router->add('post.add', '/post/add')
->setValues(array(
'controller' => 'post',
'action' => 'actionAdd'
))
->addServer(array(
'REQUEST_METHOD' => 'POST|GET'
));
$router->add('post.edit', '/post/edit/{id}')
->setValues(array(
'controller' => 'post',
'action' => 'actionEdit'
))
->addTokens(array(
'id' => '\d+'
))
->addServer(array(
'REQUEST_METHOD' => 'POST|GET'
));
$router->add('post.list', '/post/delete/{id}')
->setValues(array(
'controller' => 'post',
'action' => 'actionDelete'
))
->addTokens(array(
'id' => '\d+'
))
->addServer(array(
'REQUEST_METHOD' => 'POST'
));
the route /post
getting not routed. Mentioning no route.
Hi,
I got an email asking about version 3.x of router.
How do I define the $request variable?
I did pointed to https://github.com/zendframework/zend-diactoros
I will look into how I can fix it when I get sometime.
Thank you.
While building a RESTful API using router's attachResource()
function I found myself adding a special case for the OPTIONS method as it's not supported by default. It looks something like this:
$router->attachResource('user', '/user');
$router->add('user.options', '/user')
->addServer(['REQUEST_METHOD' => 'OPTIONS'])
->addValues(['controller' => 'user', 'action' => 'options']);
Then in the controller it's simply:
public function options() {
$this->response->content->set('*');
}
As you can see, I give a response telling the client all methods are allowed. but the reason I had to add this is because for example: Backbone.js by default will first check this method before making any other REST operations with it's models. you can "hack" you way around it in Backbone. but it does not look pretty and actually, why not adding OPTIONS as it's essential part of RESTful services.
I would be glad taking this task on myself, what do you think? does this sound reasonable or am missing something?
Hello.
Will be great to have the ability to load route definitions from an array, like so:
$routes = [
'route' => [
'__arguments' => ['test.route', '/{controller}{/action,id}', function($request, $response, $next) {
return $next($request, $response);
}],
'tokens' => [
'__arguments' => [
[
'id' => '\d{2,}'
]
]
]
]
];
$routerContainer = \Aura\Router\RouterContainer('/', $routes);
This will lead to easier configuration within the DI container, IMO.
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.