Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IncludeResponse #10

Open
oscarotero opened this issue Jan 28, 2017 · 1 comment
Open

IncludeResponse #10

oscarotero opened this issue Jan 28, 2017 · 1 comment

Comments

@oscarotero
Copy link
Member

This is something I did in psr7-middlewares. It's a middleware to include php files, usefull if you want to adapt old-style websites to the middleware approach. Let's say we have a website with the following files:

site/
    index.php
    about.php
    contact.php

Each page has it's own php file, so the urls are something like http://example.com/about.php, http://example.com/contact.php, etc. The middleware allow to use urls like http://example.com/about, include the php file, capture the output body and headers and return a response with that. It works as a wrapper for old websites.
I needed this in an old project and worked fine, the only problem I found was related with global variables, but was easy to solve.

@coisa
Copy link

coisa commented Jan 28, 2025

You can use the CallableHandler from middlewares/utils on these cases:

Ex.: new CallableHandler(fn() => include 'about.php');

You can also extend the CallableHandler. Ex.:

class PhpFile extends CallableHandler
{
    public function __construct(string $filename)
    {
        parent::__construct(fn() => include "{$filename}.php");
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants