folded-php / routing Goto Github PK
View Code? Open in Web Editor NEWRouting functions for your PHP web app.
Home Page: https://packagist.org/packages/folded/routing
License: MIT License
Routing functions for your PHP web app.
Home Page: https://packagist.org/packages/folded/routing
License: MIT License
There is no templates for bugs and enhancements, which can reduce the chances someone will want to describe his issue or can make difficult to format and clarify an issue without proper templates.
For an enhancements, the following sections (using level 2 title, ##
) should be shown:
The text hints, using italic, should be shown below each of these titles (without the double quotes):
For a bug, the following sections (using level 2 title, ##
) should be shown:
The text hints, using italic, should be show below each of these titles (without the double quotes):
To write by hand the issue layout.
I need to use a hand made code to redirect to a certain URL. I would like to leverage route name to do this.
To be able to redirect the user by route name:
use function Folded\redirectToRoute();
redirectToRoute("account.create"); // route is "/account/create"
redirectToRoute("user.post.show", ["user" => 42, "post" => 12]); // route is "/user/42/post/12
Or by simple URL:
use function Folded\redirectToUrl;
use function Folded\getHistory; // folded/history
redirectToUrl("/login");
redirectToUrl(getHistory(-1));
No way to simply redirect to a name route or URL.
I am using the native function header("Location: /login");
for the moment.
Currently it is impossible to redirect to a route with parameters.
To be able to add parameters to the redirectToRoute to get the correct url like following:
redirectToUrl("user.show", ["user" => 12]); // string(8) "/user/12"
No parameters allowed when using this method.
Using redirectToUrl()
and manually injecting the parameters in the string.
We should be able to add custom query strings when it is needed.
To be able to provide query strings to getRouteUrl()
:
use function Folded\getRouteUrl;
echo getRouteUrl("home.index", [], ["page" => 2, "view" => "list"]); // empty second parameter, because no placeholder route to replace
To be able to provide query strings to redirectToRoute()
:
use function Folded\redirectToRoute;
return redirectToRoute("home.index", [], ["source" => "email", "page" => 42]);
To manually add query strings.
None.
Starting from folded/exception:0.4, MethodNotAllowedException
allows to set the URL.
To be able to catch the MethodNotAllowedException
and get the URL not allowed:
use function Folded\matchRequestedUrl;
try {
matchRequestedUrl();
} catch (MethodNotAllowed $exception) {
echo $exception->getUrl();
}
Getting the current URL using either $_SERVER["REQUEST_URI"]
or any other frameworks that provides a Request object.
This package use an old version of folded/exception.
Upgrading to folded/exception:0.4.*
When there is query strings, currentRouteIs()
is not able to return the correct value.
currentRouteIs("home.index")
will return false, where it should return trueTo ignore query strings.
I currently have to use multiple times currentRouteIs()
for highlighting a dropdown menu.
To be able to specify multiples routes.
use function Folded\currentRouteIs;
if (currentRouteIs(["home.index", "popular.index"])) {
// This is either the home page or the popular posts page
} else {
// This is another page
}
To chain calls:
if (currentRouteIs("home.index") || currentRouteIs("popular.index")) {
// ...
}
Since this library relies on nikic/fast-route, we can leverage the cache feature.
To be able to specify wether to enable caching route or not.
use Folded\enableRouteCache;
use Folded\disableRouteCache;
enableRouteCache();
disableRouteCache();
It should be disabled by default.
And being able to specify in which file to store the cache.
setRouteCacheFilePath(__DIR__ . "/cache/routes/routes.php");
No way to enable/disable route cache, nor a way to set the route cache file.
When the code loads functions, it should detect the existance of the function under the namespace instead of just the name of the function
The call of function_exists()
use the full qualified namespace.
namespace Folded;
if (!function_exists("Folded\theFunction")) {
// load the function now
}
Functions declared twice enters in collision.
None.
Theses classes are not meant to be extended. Mark them as final.
None.
None.
There is currently no easy way to determine if the current URL matches a route name or an URL. It makes knowing if a menu should be activated difficult to setup for example.
To be able to know if a route name matches an URL:
use Folded\currentRouteIs;
if (currentRouteIs("home.index")) {
echo "URL is /";
else {
echo "URL is not /";
}
Or to be able to know if the current URL is a given URL:
use Folded\currentUrlIs;
if (currentUrlIs("/")) {
echo "URL is /";
} else {
echo "URL is not /";
}
Matching $_SERVER["REQUEST_URI]
against a string.
The method Router::replaceRouteParameters()
is not documented, and could reduce the chance it could be used because it has not clear description and parameter description.
To have a phpdoc comment on method replaceRouteParameters
of the file src\Router.php
.
None.
Currently we duplicate the route URL both in the addGetRoute()
method and in the view. A system associating a route with its name to be able to get the URL by the route name instead.
To be able to register an optional name for the route:
use function Folded\addGetRoute;
addGetRoute("/", function() {}, "home.index");
To be able to get an URL by the route name:
use function getRouteUrl;
echo getRouteUrl("home.index"); // string (1) "/"
No method to get an URL from the route name.
Duplicating the URLs in the routes registration file and the view.
The package folded/exception has been released on version 0.3.
This package uses folded/exception 0.3.
This package uses folded/exception 0.2.
None.
Static analysis helps catching bugs earlier.
pest --coverage && phpstan analyse src
phpstan.neon
configuration fileNone.
None.
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.