{"id":15024390,"url":"https://github.com/wizaplace/thephp6framework","last_synced_at":"2025-10-04T05:30:53.720Z","repository":{"id":88365017,"uuid":"72339072","full_name":"wizaplace/thephp6framework","owner":"wizaplace","description":"The one and only PHP 6 framework","archived":true,"fork":false,"pushed_at":"2019-10-01T07:29:59.000Z","size":17,"stargazers_count":25,"open_issues_count":0,"forks_count":1,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-01-23T03:32:49.738Z","etag":null,"topics":["framework","middleware","php","php-middleware","php6"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wizaplace.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-30T09:00:36.000Z","updated_at":"2024-09-29T08:28:58.000Z","dependencies_parsed_at":"2024-01-23T12:30:40.327Z","dependency_job_id":null,"html_url":"https://github.com/wizaplace/thephp6framework","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/wizaplace/thephp6framework","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wizaplace%2Fthephp6framework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wizaplace%2Fthephp6framework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wizaplace%2Fthephp6framework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wizaplace%2Fthephp6framework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wizaplace","download_url":"https://codeload.github.com/wizaplace/thephp6framework/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wizaplace%2Fthephp6framework/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278267419,"owners_count":25958852,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["framework","middleware","php","php-middleware","php6"],"created_at":"2024-09-24T20:00:15.043Z","updated_at":"2025-10-04T05:30:53.714Z","avatar_url":"https://github.com/wizaplace.png","language":"PHP","readme":"The one and only PHP 6 framework.\n\n## Why?\n\nBecause PHP 6 is the future, but not too much the future at the same time!\n\nOh and also this framework is a very simple introduction to **PHP middlewares**. It shows a very basic implementation of a framework based on middlewares without PSR-7 or even objects representing the request or the response.\n\n## Does it work on PHP 5\n\nNo.\n\n## Does it work on PHP 7\n\nNo.\n\n## Does it work on PHP 6?\n\nYES!\n\n## Demo\n\nA demo is included in this package ([`index.php`](index.php)), just run this command and visit [http://localhost:8000/index.php](http://localhost:8000/index.php)\n\n```\ndocker-compose up\n```\n\n## Deployment in production\n\nCompiling PHP 6 isn't easy, fortunately you can now deploy it straight to production thanks to this Docker image: [`wizaplace/php-6-apache`](https://github.com/wizaplace/docker-php-6-apache).\n\nHave a look at our [docker-compose.yml](docker-compose.yml) to see how we use it.\n\n## Introduction\n\nA traditional middleware looks like this:\n\n```php\nfunction (ServerRequestInterface $request, callable $next) {\n    // do something before the next middleware\n\n    $response = $next($request);\n\n    // do something after the next middleware\n\n    return $response;\n}\n```\n\nIn thephp6framework, in order to have maximum simplicity and maximum global state (:p) there are no objects to represent the request and the response.\n\nThe request is retrievable via the native PHP way:\n\n- global variables like `$_GET`, `$_POST`, `$_SERVER`, …\n- the raw input in the stream `php://input`\n\nThe response can be emitted via the native PHP way:\n\n- `echo '...'` to output the body ([`ob_start()`](http://php.net/manual/fr/function.ob-start.php) and similar functions to buffer the output)\n- [`header()`](http://php.net/manual/fr/function.header.php) to set headers\n\nBecause of that, a middleware looks like this:\n\n```php\nfunction ($next) {\n    // do something before the next middleware\n\n    $next();\n\n    // do something after the next middleware\n}\n```\n\n## Request pre-processor\n\nEven though the request is not an object, you can still write a middleware that will pre-process it (modify it) before invoking the next middleware:\n\n```php\nfunction security_middleware($next) {\n    // Secure the application BIG TIME by replicating PHP magic quotes\n    if (\\is_array($_GET)) {\n        foreach ($_GET as \u0026$value) {\n            $value = \\addslashes($value);\n        }\n    }\n    if (\\is_array($_POST)) {\n        foreach ($_POST as \u0026$value) {\n            $value = \\addslashes($value);\n        }\n    }\n\n    $next();\n}\n```\n\n## Response post-processor\n\nEven though the response is not an object, you can still write a middleware that will modify the response returned by the next middleware:\n\n```php\nfunction cloud_to_butt($next) {\n    // You could also use the framework's capture() function\n    \\ob_start();\n    $next();\n    $html = \\ob_get_contents();\n    \\ob_end_clean();\n\n    $html = \\str_replace('the cloud', 'my butt', $html);\n\n    echo $html;\n}\n```\n\n## Usage\n\n### Router\n\nTo build a simple application with different routes, you can use the `router()` function:\n\n```php\nrequire_once __DIR__ . '/theframework.php';\n\n$app = router(array(\n    '/' =\u003e function () {\n        echo 'The home page';\n    },\n    '/about' =\u003e function () {\n        echo 'The about page';\n    },\n));\n\n$app();\n```\n\n### Pipe\n\nYou can pipe middlewares one after another using the pipe:\n\n```php\n$app = pipe(array(\n    function ($next) {\n        echo 'Welcome ';\n        $next();\n    },\n    function () {\n        echo 'in the cloud!';\n    },\n));\n\n$app();\n```\n\n### Advanced architecture\n\nThe great thing about thephp6framework is that everything is a middleware:\n\n- the router is a middleware\n- the pipe is a middleware\n- controllers are middlewares too\n\nConsidering that, you can nest routers in pipes in controllers in pipes in routers…\n\nFor example, if you want to add middlewares before the router, simply use the pipe:\n\n```php\n$app = pipe(array(\n    'security_middleware',\n    router(array(\n        '/' =\u003e function () {\n            echo 'Hello world!';\n        },\n    )),\n));\n\n$app();\n```\n\n### The `capture()` function\n\nThe `capture()` function is a little helper from the framework around output buffering. Instead of this:\n\n```php\nob_start();\necho 'Hello world!';\n$output = ob_get_contents();\nob_end_clean();\n```\n\nYou can write this:\n\n```php\n$output = capture(function () {\n    echo 'Hello world!';\n});\n```\n\nThat means that if you want to capture the output of the next middleware, you can simply do this (because `$next` is a callable):\n\n```php\n$html = capture($next);\n```\n\n## TODO\n\n- [moar middlewares!](https://github.com/wizacha/thephp6framework/blob/master/theframework.php#L84)\n- allow placeholders in the router (regex with `preg_match()`?)\n- use Composer for file inclusion?\n\n## Learn more\n\nThis framework is meant as a very simple introduction to PHP middlewares. If you are interested to learn more you can read [this great article](https://mwop.net/blog/2015-01-08-on-http-middleware-and-psr-7.html) and have a look at [Zend Expressive](https://zendframework.github.io/zend-expressive/) or [Slim](http://www.slimframework.com/).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwizaplace%2Fthephp6framework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwizaplace%2Fthephp6framework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwizaplace%2Fthephp6framework/lists"}