Giter Site home page Giter Site logo

Comments (6)

franzliedke avatar franzliedke commented on August 29, 2024

A little bit of background: If it had this functionality, I would gladly use this library in Flarum in order to use PSR-15 middleware. We're currently using Zend's Stratigility, but their PSR-15-compatible version does not support PHP 7.0, which is - currently - still a requirement on our side.

from broker.

shadowhand avatar shadowhand commented on August 29, 2024

Would adding this functionality introduce new dependencies? I like the idea of it.

For whatever it's worth, the functionality is already possible by doing something like this:

$broker->when($this->matchesPath('/foo'), MyMiddleware::class);

Assuming that:

private function matchesPath(string $path): callable
{
    return static function (RequestInterface $request) use ($path): bool {
        return strpos($request->getUri()->getPath(), $path) === 0;
    };
}

from broker.

franzliedke avatar franzliedke commented on August 29, 2024

I would implement it without external dependencies.

Stratigility additionally strips out the path prefix from the request - which is very useful because the middleware does not need to know about the prefix. So just matchesPath is not enough.

@shadowhand Is that a "go ahead" then? 😀

from broker.

shadowhand avatar shadowhand commented on August 29, 2024

@franzliedke sure, I'd definitely consider a PR. Seems like it will be reasonable.

from broker.

franzliedke avatar franzliedke commented on August 29, 2024

Little status update:
I got path matching working. The only thing remaining is to change the request's URI object so that subsequent middleware does not have to know about the path prefix.

from broker.

shadowhand avatar shadowhand commented on August 29, 2024

Closing, see discussion on #7

from broker.

Related Issues (4)

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.