GithubHelp home page GithubHelp logo

folded-php / routing Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 80 KB

Routing functions for your PHP web app.

Home Page: https://packagist.org/packages/folded/routing

License: MIT License

PHP 98.94% Dockerfile 1.06%
php routing

routing's People

Contributors

khalyomede avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

routing's Issues

Add issues templates for both bugs and enhancements

Description

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.

Expected behavior

Enhancements issue template

For an enhancements, the following sections (using level 2 title, ##) should be shown:

  • Description
  • Proposal
  • Workaround solutions
  • Notes

The text hints, using italic, should be shown below each of these titles (without the double quotes):

  • Description: "Give some context and motivation for the proposed solution."
  • Proposal: "The detail proposition. Can include code."
  • Worarkound solutions: "Mention every existing workaround you know that will solve the issue apart from the proposed solution."
  • Notes: "Add everything that relates the proposal, like future induced issues, related issues, ..."

Bug issue template

For a bug, the following sections (using level 2 title, ##) should be shown:

  • Description
  • Steps to reproduce the issue
  • Expected behavior
  • Workaround solutions
  • Notes

The text hints, using italic, should be show below each of these titles (without the double quotes):

  • Description: "Any information that can give more understanding about how you came to this issue."
  • Steps to reproduce the issue: "Detail precisely how we can reproduce the issue from a blank new project (if possible)."
  • Expected behavior: "Describe what the output or the behavior should be instead of the issue you have."
  • Workaround solutions: "Mention every existing workaround you know that will solve the issue."
  • Notes: "Add everything that relates the proposal, like related issues, ..."

Alternatives solutions

To write by hand the issue layout.

To be able to redirect the user to a route by its name or URL

Description

I need to use a hand made code to redirect to a certain URL. I would like to leverage route name to do this.

Expected behavior

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));

Actual behavior

No way to simply redirect to a name route or URL.

Alternatives solutions

I am using the native function header("Location: /login"); for the moment.

Notes

To be able to add parameters when using redirectToRoute

Description

Currently it is impossible to redirect to a route with parameters.

Expected behavior

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"

Actual behavior

No parameters allowed when using this method.

Alternatives solutions

Using redirectToUrl() and manually injecting the parameters in the string.

To be able to provide query strings to redirectToRoute and getRouteUrl

Description

We should be able to add custom query strings when it is needed.

Proposal

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]);

Worarkound solutions

To manually add query strings.

Notes

None.

Set the URL when throwing a MethodNotAllowedException

Description

Starting from folded/exception:0.4, MethodNotAllowedException allows to set the URL.

Proposal

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();
}

Worarkound solutions

Getting the current URL using either $_SERVER["REQUEST_URI"] or any other frameworks that provides a Request object.

Notes

Upgrade to folded/exception 0.4.0

Description

This package use an old version of folded/exception.

Proposal

Upgrading to folded/exception:0.4.*

Worarkound solutions

Notes

Bug when currentRouteIs fails when query strings are in the route

Description

When there is query strings, currentRouteIs() is not able to return the correct value.

Reproduce the issue

  1. Go to page "/?page=2"
  2. You have a route registered with name "home.index" and url "/"
  3. Calling currentRouteIs("home.index") will return false, where it should return true

Expected behavior

To ignore query strings.

To be able to check if multiples routes match the current URL

Description

I currently have to use multiple times currentRouteIs() for highlighting a dropdown menu.

Expected behavior

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
}

Alternatives solutions

To chain calls:

if (currentRouteIs("home.index") || currentRouteIs("popular.index")) {
  // ...
}

Add a cache mecanism

Description

Since this library relies on nikic/fast-route, we can leverage the cache feature.

Expected behavior

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");

Actual behavior

No way to enable/disable route cache, nor a way to set the route cache file.

Notes

Missing namespace in function_exists call

Description

When the code loads functions, it should detect the existance of the function under the namespace instead of just the name of the function

Expected behavior

The call of function_exists() use the full qualified namespace.

namespace Folded;

if (!function_exists("Folded\theFunction")) {
  // load the function now
}

Actual behavior

Functions declared twice enters in collision.

Alternatives solutions

None.

Mark classes Route, Router and RequestMethod as final

Description

Theses classes are not meant to be extended. Mark them as final.

Proposal

  • The Route class is marked as final
  • The Router class is marked as final
  • The RequestMethod class is marked as final

Worarkound solutions

None.

Notes

None.

Methods to know if the current route or URL is a given route or URL

Description

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.

Expected behavior

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 /";
}

Alternatives solutions

Matching $_SERVER["REQUEST_URI] against a string.

Add missing comment for method Router::replaceRouteParameters

Description

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.

Expected behavior

To have a phpdoc comment on method replaceRouteParameters of the file src\Router.php.

Alternatives solutions

None.

To be able to get a route URL by its name

Description

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.

Expected behavior

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) "/"

Actual behavior

No method to get an URL from the route name.

Alternatives solutions

Duplicating the URLs in the routes registration file and the view.

Notes

Upgrade to folded/exception 0.3

Description

The package folded/exception has been released on version 0.3.

Expected behavior

This package uses folded/exception 0.3.

Actual behavior

This package uses folded/exception 0.2.

Alternatives solutions

None.

Notes

Add static analysis in the test command

Description

Static analysis helps catching bugs earlier.

Proposal

  • Using phpstan/phpstan and run the command after the test command: pest --coverage && phpstan analyse src
  • Use the level 8 for a maximum of consistency
  • Use a phpstan.neon configuration file

Worarkound solutions

None.

Notes

None.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.