{"id":23872798,"url":"https://github.com/troublete/php-monty","last_synced_at":"2025-09-09T01:38:18.001Z","repository":{"id":57072965,"uuid":"98767064","full_name":"troublete/php-monty","owner":"troublete","description":"Sinatra-like framework, focused on fast response and reliability. 🐘","archived":false,"fork":false,"pushed_at":"2017-09-16T01:03:55.000Z","size":44,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-03T16:33:27.193Z","etag":null,"topics":["php","php-framework","php7"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/troublete.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}},"created_at":"2017-07-30T01:05:02.000Z","updated_at":"2022-02-12T14:24:51.000Z","dependencies_parsed_at":"2022-08-24T14:54:37.305Z","dependency_job_id":null,"html_url":"https://github.com/troublete/php-monty","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/troublete%2Fphp-monty","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/troublete%2Fphp-monty/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/troublete%2Fphp-monty/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/troublete%2Fphp-monty/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/troublete","download_url":"https://codeload.github.com/troublete/php-monty/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240229936,"owners_count":19768588,"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","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":["php","php-framework","php7"],"created_at":"2025-01-03T16:32:58.011Z","updated_at":"2025-02-22T19:50:32.341Z","avatar_url":"https://github.com/troublete.png","language":"PHP","readme":"# Monty\n\n### *Sinatra-like framework, focused on fast response and reliability.*\n\n[![Build Status](https://travis-ci.org/troublete/monty.svg?branch=master)](https://travis-ci.org/troublete/monty)\n\n## Example Setup\n\n```\n$ composer require troublete/monty\n```\n\n```php\n\u003c?php\nrequire_once 'path/to/vendor/autoload.php';\n\n$application = new \\Monty\\Application();\n\n$application-\u003eget(\n    '/request[/{someId}]',\n    function (\\Monty\\Request $req, \\Monty\\Response $res, $someId) {\n        \n        // do some awesome stuff\n        \n        return new \\Symfony\\Component\\HttpFoundation\\JsonResponse([]);\n    }\n);\n```\n\n## Routing\n\nThe route parsing is based on the [FastRoute](https://github.com/nikic/FastRoute) package created be @nikic, so for the\nmost part it should be possible to define routes as specified by FastRoute.\nRoute matching is done via **PCRE** with delimiter set to `@`, so be aware when setting user defined regex parameter matches with `@`.\nRoute definitions allow variable parts at the end of a definition marked with `[]`. Since this is possible the matching\nwill try multiple regular expressions in order of descendant complexity and will return on the first pattern match.\n\nValid routing\n```\n/search/{searchId} =\u003e routing with parameter\n/search/{searchId:\\d+} =\u003e routing with parameter with defined regex\n/search[/{searchId}] =\u003e routing with optional parameter\n/search/index[es] =\u003e routing with optional part\n```\n\nInvalid routing\n```\n/search/index[es]/{searchId} =\u003e optional chunk in the middle\n```\n\n## Request Handling\n\nHandling definitions will be processed in order of registration as soon as one matches with the received request it will\ndispatch, return and therefore close the process.  \n\nIn addition Monty is designed to be request and response centric, following the dogma that one request to an application\nwill be handled once so everything needed during the lifecycle is included (or should be appended) in the request or response\nobject. \n\nHandlers on a definition are an array of `callable`'s and will be executed synchronously in order on definition match. \nMiddlewares registered to run before or after are integrated in this \"call stack\".\n \nIf a response object is returned in a handler it is interpreted as the process response and can't be reset (but modified).\n\n## Application\n\nThe application is the main component of Monty. It will handle the registration of route handlers, middlewares and additional\nsetup of request and response. It generally contains four different use-cases. Accessing the request or response object\nof the current request process, registering route handlers and registering middlewares which will be executed during\nthe lifecycle.\n\nIn addition to the use-case methods it also contains an interface of alias methods to make the code your write a lot more\nunderstandable and sleek.\n\n### Methods\n\n#### $app-\u003ehandle($methods, $route, ...$handlers)\n\nThis method registers new request handlers for a specific route in regard to an collection of request methods on which\nshould be dispatched. \n\n##### Arguments\n\n| Argument | Type | Description |\n|---|---|---|\n| $methods | *string[]* | Collection of request methods in uppercase. |\n| $route | *string* | The route to which the handlers are registered. |\n| ...$handlers | *callable[]* | Collection of handlers which will be executed. |\n\n##### Example\n\n```php\n// ...\n$app-\u003ehandle(\n    ['GET'], \n    '/index', \n    function ($req, $res) { /*...*/ }, \n    function ($req, $res) { /*...*/ }, \n    function ($req, $res) { /*...*/ }\n    // ...\n);\n// ...\n```\n\n##### Aliases\n\n| Method | Description |\n|---|---|\n| **all($route, ...$handlers)** | Alias method which will react to all request methods |\n| **get($route, ...$handlers)** | Alias method which will react to **GET** requests |\n| **post($route, ...$handlers)** | Alias method which will react to **POST** requests |\n| **head($route, ...$handlers)** | Alias method which will react to **HEAD** requests |\n| **options($route, ...$handlers)** | Alias method which will react to **OPTIONS** requests |\n| **patch($route, ...$handlers)** | Alias method which will react to **PATCH** requests |\n| **put($route, ...$handlers)** | Alias method which will react to **PUT** requests |\n| **delete($route, ...$handlers)** | Alias method which will react to **DELETE** requests |\n\n#### $app-\u003emiddleware($placing, ...$handlers) : \\Monty\\Application\n\nThis method registers additional handlers which will be executed without regard to the requesting method.  \n\n##### Arguments\n\n| Argument | Type | Description |\n|---|---|---|\n| $placing | *integer* | The request lifecycle position (Application::PREPEND -- before, Application::APPEND -- after) when the handlers should be executed. |\n| ...$handlers | *callable[]* | Collection of handlers which will be executed. |\n\n##### Example\n\n```php\n// ...\n$app-\u003emiddleware(\n    \\Monty\\Application::PREPEND,\n    function ($req, $res) { /*...*/ },\n    function ($req, $res) { /*...*/ },\n    function ($req, $res) { /*...*/ }\n    // ...\n);\n// ...\n```\n\n##### Aliases\n\n| Method | Description |\n|---|---|\n| **before(...$handlers)** | Alias method which will add request handlers executed **before** the actual request handling |\n| **after(...$handlers)** |  Alias method which will add request handlers executed **after** the actual request handling |\n\n#### $app-\u003egetRequest() : \\Monty\\Request\n\nThis method retrieves the current request object.\n \n#### $app-\u003egetResponse() :  : \\Monty\\Response\n\nThis method retrieves the current response object.\n\n## Request\n\nThe request object is the center piece of the process. It contains the possibility to append properties and services necessary\nduring the request. With that handling the request object stays small and only necessary dependencies are registered when needed.\n\n### Methods\n\n#### $req-\u003eclientIp() : string\n\nMethod to retrieve the request IP.\n\n#### $req-\u003econtentType() : string\n\nMethod to retrieve the content-type header value requested.\n\n#### $req-\u003efiles() : \\Symfony\\Component\\HttpFoundation\\FileBag\n\nMethod to retrieve the $_FILES parameters.\n\n#### $req-\u003eget(...$parameters)\n\nThis method can be used to retrieve a property or service set to the request.\n \n##### Arguments\n\n| Argument | Type | Description |\n|---|---|---|\n| ...$parameters | *mixed* | Collection of parameters passed a long to the setter method. |\n \n##### Example\n \n```php\n// ...\n$request-\u003eget('logger', new SomeDefault());\n$request-\u003eget('property', 'some default value');\n// ...\n```\n\n#### $req-\u003egetRawRequest() : \\Symfony\\Component\\HttpFoundation\\Request\n\nMethod to retrieve the raw request embedded in the \\Monty\\Request object.\n\n#### $req-\u003ehttpHost() : string\n\nMethod to retrieve the http host including protocol.\n\n#### $req-\u003eisMethod($method) : boolean\n\nMethod to check if the request method is a specific value.\n\n##### Arguments\n\n| Argument | Type | Description |\n|---|---|---|\n| $method | *string* | Request method to check. |\n\n#### $req-\u003eisSecure() : boolean\n\nMethod to check if the request sent is secure (HTTPS/SSL).\n\n#### $req-\u003epath() : string\n\nMethod to retrieve the request path.\n\n#### $req-\u003epreviousReturn() : mixed\n\nMethod to retrieve the return value of the previous handler in the stack.\n\n#### $req-\u003equery() : \\Symfony\\Component\\HttpFoundation\\ParameterBag\n\nMethod to retrieve the $_GET parameters.\n\n#### $req-\u003erequestMethod() : string\n\nMethod to retrieve the request method.\n\n#### $req-\u003erequest() : \\Symfony\\Component\\HttpFoundation\\ParameterBag\n\nMethod to retrieve the $_POST parameters.\n\n#### $req-\u003erouteParameters() : \\Symfony\\Component\\HttpFoundation\\ParameterBag\n\nMethod to retrieve the route parameters values matches by the route handler instance.\n\n#### $req-\u003eset(...$parameters) : \\Monty\\Request\n\nThis method can be used to add a class instance or property to the request which can be accessed along the call stack. Usually\nthe method takes at least two parameters, first the id of the property/service as string and secondly a scalar or object value.\n\nArrays are not allowed to be set as request properties to avoid messy code and [resource bulking](https://twitter.com/nikita_ppv/status/847855830821109760).\n\n##### Arguments\n\n| Argument | Type | Description |\n|---|---|---|\n| ...$parameters | *mixed* | Collection of parameters passed a long to the setter method. |\n\n##### Example\n\n```php\n// ...\n$request-\u003eset('logger', new SomeLogger()); // valid\n$request-\u003eset('property', 'some value'); // valid\n\n$request-\u003eset('not_possible', []); // invalid\n// ...\n```\n\n#### $req-\u003esetPreviousReturn($value) : \\Monty\\Request\n\nMethod to set the previous handler return.\n\n##### Arguments\n\n| Argument | Type | Description |\n|---|---|---|\n| $value| *mixed* | Return value of the previous handler. |\n\n#### $req-\u003eupdateRouteParams($params) : \\Monty\\Request\n\nMethod to update the route parameters set to the request.\n\n##### Arguments\n\n| Argument | Type | Description |\n|---|---|---|\n| $params | *array* | Route parameters to be set. |\n\n## Response\n\nThe response object is generally assumed to resolve itself -- meaning that is should handle how the response defined\nshould be rendered in the application response. You can use simply the Symfony Http Component response object, or define\nown ones, which **need** to implement the \\Monty\\ResponseInterface.\n\n## Handler\n\nA handler is defined as a `callable` which is registered in a route handler definition or a middleware.\n\nHandler **can** be, simple lambda functions, closure objects, classes, ... practically anything that is possible to be\ninvoked. No limitations here.\n\n\n\u003chr /\u003e\n\n\n© 2017 Willi Eßer ","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftroublete%2Fphp-monty","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftroublete%2Fphp-monty","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftroublete%2Fphp-monty/lists"}