Code Monkey home page Code Monkey logo

Comments (8)

bramus avatar bramus commented on July 29, 2024 1

With #38 being merged and closed this feature is now on master. Feel free to test. If found OK I'll tag this release as 1.2 :-)

from router.

JBlond avatar JBlond commented on July 29, 2024

Your second example the closure is the best option. But instead of using an anonymous function you could use an existing function aka callback function.
Global is not what you want to use.

from router.

ovflowd avatar ovflowd commented on July 29, 2024

What you're aiming, it's exactly what Laravel does.

I will think on a solution and provide a Pull Request for it.

@bramus what you think about it?

from router.

xergio avatar xergio commented on July 29, 2024

mmm... @JBlond how do you suggest me to use an existing function?

When I need to pass, for example, the controller, the method, $tpl and $id (if the route is something like /test/(\d+) ), I can't see anything but an anonymous function...

from router.

JBlond avatar JBlond commented on July 29, 2024

@xergio Somethings like this.

function myCallBackFunction(){
    //do fanzy things
}
$router->get('/', myCallBackFunction());

See http://php.net/manual/de/language.types.callable.php

from router.

ovflowd avatar ovflowd commented on July 29, 2024

In terms of code readability and simplicity I won't recommend @JBlond's method.

In case of using Class@Method, you are strictly following the MVC pattern. In the same case, Class@Method would be a callable. "a callable".

Need advice to @JBlond that actually Callable's are a type of entities on php. In the case of myCallbackFunction() and Method@Class, they aren't really callables.

What the Router does it's check the existence of the callability of them, and if they really exists.

Actually on the Class@Method, you need provide a full namespace.

I may do a commit creating the ability of adding namespaces on the environment, and also passing variables to the methods like on Laravel.

Example.:

$router->get('/my/route/with/{some}/{data}', 'MyClass@Method');

And something like that for namespace:

$router->add('/App/Controllers');

from router.

JBlond avatar JBlond commented on July 29, 2024

@Sant0ro I commented #37 (comment) at using closure is the best option.
Well using native call_user_func would work.

from router.

ovflowd avatar ovflowd commented on July 29, 2024

Yes using Callables would be the best option.

from router.

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.