GithubHelp home page GithubHelp logo

Feature - Routes as Objects about klein.php HOT 4 CLOSED

klein avatar klein commented on July 27, 2024
Feature - Routes as Objects

from klein.php.

Comments (4)

unstoppablecarl avatar unstoppablecarl commented on July 27, 2024

That would be sexy. I don't know what the performance cost of __invoke() would be though

from klein.php.

Rican7 avatar Rican7 commented on July 27, 2024

I'm not incredibly concerned with the performance characteristics of __invoke(), only because most projects (insert made-up percentage statistic here) don't use the return value of the respond() method anyway, and even so would most likely not use it in performance-heavy tasks or in multiple places.

Besides, I think that the benefits of "classifying" the route callbacks outweigh the potential performance hit that correlates with a small percentage of developers actually using the respond() return value. 👅

I'm glad you like the idea, though. And yea, questioning performance is never a bad idea.

from klein.php.

Rican7 avatar Rican7 commented on July 27, 2024

Boom! So far this is coming along nicely in my branch: https://github.com/Rican7/klein.php/tree/feature/routes-as-objects

I have a new Route class and the Klein respond() method is now creating a new Route instance and then passing back the instance for chainable calling. :)

What I still need to work on:

  • Converting the $routes array into a class/data-structure of some kind
  • More Route class meta (like names and reverse routing?)
  • And a more generic add() method in the Klein class for simply adding Route object instances to the Klein routes data-structure without having to go through the respond() method. This allows:
    • Extendable Route classes by using dependency injection
    • Custom Route object definitions external of the respond() method

from klein.php.

Rican7 avatar Rican7 commented on July 27, 2024

Names and reverse routing will be in their own feature branch and PR.
For now, though, this is implemented and closed. :)

from klein.php.

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.