Coder Social home page Coder Social logo

Comments (17)

kevinsmith avatar kevinsmith commented on June 23, 2024 1

@maiorano84 I ended up going with a different routing solution, but Iā€™m sure it would make a good reference for someone if you wanted to post it.

from route.

philipobenito avatar philipobenito commented on June 23, 2024

This is something I'd be interested in adding, it needs more discussion around the format of the configuration array though as there is the possibility of adding named routes in the future but it's not something currently implemented.

Also we have to take per route configuration in to account for strategies.

Your example has the knowledge of modules/sections which I also like but again would need discussion around planned future features. I plan to release a roadmap at some point soon so would you be happy to pick this back up with me once I've finalised that?

from route.

NigelGreenway avatar NigelGreenway commented on June 23, 2024

Yeah, I would be more than happy.

In terms of the named routes part, is it more that I am assuming that everyone would be using named routes? If that is the case, what is the cost of having 2 methods?

$router->addNamedRoutesFromConfig($routes);
// --or--
$router->addRoutesFromConfig($routes);

from route.

philipobenito avatar philipobenito commented on June 23, 2024

It will definitely be an optional thing, having several conversations about the benefits of named routes before any decision is made as I don't personally see how I would use them in my own projects that would benefit me over what I'm doing now. I'd love ALL input I can get on that and any code examples of how it would ideally work for people if you have any input?

from route.

NigelGreenway avatar NigelGreenway commented on June 23, 2024

So, last night I was thinking and I have come up with an idea on how it could be done...

This takes named routes into consideration

Instead of having two functions, we could have a function takes three parameters:

  • array $routes | default: []
  • boolean $namesRoutes | default: false
  • StrategyInterface $strategy | default: null

It is a very quick and dirty implementation of my idea but serves its basic purpose

example

I am implementing this into my own micro framework for learning purposes and would be good for me for the following:

The reason for a route config for me would be the ability to separate have them in one file along with separating them into several configs (as per the example). It also allows for developers to go to one place on a project.

The reason for named parameters would be the ability to create a url parser (similar to the path() functionality in twig) for a php, mustache or twig template allowing me to edit routes easily by changing the parameter requirements or doing a search and replace across the project. I can search for every instance of route article_by_category_and_year, if this rendered as /articles/{{ article.category }}/{{ article.year }} then I can use the route name to search on.

from route.

patrickheeney avatar patrickheeney commented on June 23, 2024

šŸ‘ Couldn't you fit all options into an array:

$routes = [
    [
        'pattern' => '/demo/{name}',
        'controller' => 'Demo\Controller\DemoController::index',
        'method' => 'GET',
        'name' => ''demo_page',
        'strategy' => 'FQNS\CustomStrategy'
    ],
];

from route.

philipobenito avatar philipobenito commented on June 23, 2024

@patrickheeney yes, this is planned in the near future for v2.

from route.

patrickheeney avatar patrickheeney commented on June 23, 2024

@philipobenito Sounds good. Was just adding my feedback from your suggestion:

I'd love ALL input I can get on that and any code examples of how it would ideally work for people if you have any input?

from route.

philipobenito avatar philipobenito commented on June 23, 2024

Yes, mentioned on the other thread, apologies if I ever appear to be curt, it's generally just jumping on and and addressing issues and discussions in the middle of something else so I get straight to my point, don't want that to discourage you from contributing with discussion and suggestions.

from route.

sagikazarmark avatar sagikazarmark commented on June 23, 2024

šŸ‘

from route.

philipobenito avatar philipobenito commented on June 23, 2024

@NigelGreenway I'm building a Service Provider to go with version 2.0.0 that will allow use of config. Are you happy with that as a resolution to this?

from route.

NigelGreenway avatar NigelGreenway commented on June 23, 2024

Hi @philipobenito,

Sorry, had my email app closed.

A service provider would be great, cheers.

I would then be able to create the config as I see fit and then create a service provider to manage it?

If you need any help with anything like testing, let me know. Will be glad to help where I can.

from route.

philipobenito avatar philipobenito commented on June 23, 2024

@NigelGreenway yup, taking a new tact with config and handling it with bootable service providers in v2 of container, that way there's no real defined structure and anybody can build their own service provider to handle it in a different way if they feel they want to/need to. i.e. migrations from frameworks etc.

So if you're happy with that I'll close this and consider it resolved by that.

from route.

NigelGreenway avatar NigelGreenway commented on June 23, 2024

@philipobenito Yeah, more than happy. Cheers

šŸ‘

from route.

kevinsmith avatar kevinsmith commented on June 23, 2024

To my knowledge, this concept didn't get fleshed out, and at least as of v4 it's not possible to reference an external routes.php file. Mind providing a little insight into the trouble implementing this concept? I'm curious about whether it might be possible in the future.

from route.

maiorano84 avatar maiorano84 commented on June 23, 2024

@kevinsmith I know I'm responding over a year later, but I just found this discussion.

I have an implementation I'm actually currently putting together using Container and a YAML file. Seems to work pretty well so far, but I haven't built out any unit tests yet. Is this something you're still interested in? If so, I can work on decoupling this from my personal implementation and getting a quick Composer package up.

from route.

ParadiseStudios avatar ParadiseStudios commented on June 23, 2024

I am currently working on a yaml configuration parser as well, so it is a feature at least a couple of us are looking for.

from route.

Related Issues (20)

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.