{"id":19311138,"url":"https://github.com/boxuk/boxuk-routing","last_synced_at":"2025-06-30T01:32:33.688Z","repository":{"id":138957683,"uuid":"1571519","full_name":"boxuk/boxuk-routing","owner":"boxuk","description":"Routing library for PHP front controller based applications","archived":false,"fork":false,"pushed_at":"2014-07-18T10:52:00.000Z","size":253,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":50,"default_branch":"master","last_synced_at":"2025-02-24T03:43:22.000Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/boxuk.png","metadata":{"files":{"readme":"README.markdown","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":"2011-04-05T10:22:01.000Z","updated_at":"2014-07-18T10:50:05.000Z","dependencies_parsed_at":"2023-03-13T10:52:26.832Z","dependency_job_id":null,"html_url":"https://github.com/boxuk/boxuk-routing","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/boxuk/boxuk-routing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boxuk%2Fboxuk-routing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boxuk%2Fboxuk-routing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boxuk%2Fboxuk-routing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boxuk%2Fboxuk-routing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/boxuk","download_url":"https://codeload.github.com/boxuk/boxuk-routing/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boxuk%2Fboxuk-routing/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262693278,"owners_count":23349708,"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":[],"created_at":"2024-11-10T00:27:54.956Z","updated_at":"2025-06-30T01:32:33.643Z","avatar_url":"https://github.com/boxuk.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Box UK Routing\n\nThis library provides an easy way to add highly configurable routing support to your Front Controller based application.  It comes with an input router to pass control to your application classes, and an output filter that transforms HTML to use these routes automatically.  All of this is then configured through one easy to read routing file.\n\n## Requirements\n\n* PHP 5.3\n\n## The Routing File\n\nThe routing file is designed to be as easy to read as possible, and simply maps URLs on the left side, to the controller to handle them on the right.  Here's a simple example...\n\n\u003cpre\u003e\n/user/:num = user:show( id )\n\u003c/pre\u003e\n\nThe format for route definitions is as follows:\n\n\u003cpre\u003e\nMETHOD URL = CONTROLLER:ACTION( PARAMS )\n\u003c/pre\u003e\n\nThe method allows you to limit certain routes to certain HTTP request methods.  If the action is not specified then it defaults to _'index'_.\n\n### URLs\n\nThe left hand side specifies the URL for the route.  You specify your dynamic parameters with a colon (eg. :num), by default these are...\n\n* :num\n* :word\n* :file\n* :any\n\n#### Additional Types\n\nYou can specify additional types using regular expressions.\n\n\u003cpre\u003e\n:num = ID\\d\\d\\w+\n\u003c/pre\u003e\n\n### Controller Blocks\n\nAs a shorthand (and a neat way of keeping related specs together) you can use controller blocks to eliminate the need to specify the controller in your routes.\n\n\u003cpre\u003e\n[foo]\n/this/:word = show( name )\n/some/:num = ( id )\n[*]\n\u003c/pre\u003e\n\nThe above example shows two routes defined for a controller called 'foo'.  As you can see it's no longer required to specify *foo* for each route. The controller block is then ended with a star (indicating any controller can now be used in routes)\n\n### Base Paths\n\nYou can also specify a base path for a controller block which means all routes have that as their prefix.  This is useful when all of a controllers routes have the same prefix, for example:\n\n\u003cpre\u003e\n[admin:/private/admin]\n/:word = ( action )\n/ = ()\n[*]\n\u003c/pre\u003e\n\nThis would then send URLs like /private/admin/home to the _admin_ controller, with the action _home_.\n\n## Default Values\n\nYou can also have parameters with default, or static, values.\n\n\u003cpre\u003e\n/foo = bar( id:1 )\n\u003c/pre\u003e\n\nThis route will always pass a parameter called _id_ of value _1_.\n\n## The Helper\n\nYou are free to instantiate and set up all the objects manually if you want, but the easiest way to do it is through the helper class provided (BoxUK\\\\Routing) by supplying a configuration object.  This is used in all the examples.\n\n## The Router\n\nThe router forms the input part of the system.  You instantiate the router using the configured helper, then pass it the requested URL along with a request object to populate with the data extracted from the matched route.\n\n```php\n\u003c?php\n$req = new BoxUK\\Routing\\Input\\StandardRequest();\n$url = '/some/url';\n\n$config = new BoxUK\\Routing\\Config;\n$config-\u003esetRoutesFile( '/path/to/routes.txt' );\n\n$routing = new BoxUK\\Routing( $config );\n\n$router = $routing-\u003egetRouter();\n$router-\u003eprocess( $req, $url )\n```\n\nWhen the process method has completed the request object will contain the information from the route (eg. controller = 'foo')\n\nThe example above uses a default request object provided with this library, but you will most likely want to provide your own if you already have a request object abstraction in your application (just implement BoxUK\\\\Routing\\\\Input\\\\Request)\n\n## The Filter\n\nThe output filter allows us to transform our output using the routing information provided in our routes file.  This is done dynamically so the URLs in your output should be the raw versions pointing to your front controller script.\n\n```php\n\u003c?php\n$html = '\u003ca href=\"server.php?controller=cars\u0026action=show\u0026brand=ford\"\u003eShow Ford\u003c/a\u003e';\n\n$filter = $routing-\u003egetFilter();\n$filter-\u003eprocess( $html );\n```\n\nGiven the route _/cars/:word = cars:show( brand )_, the *$html* variable will be transformed to...\n\n```html\n\u003ca href=\"/cars/ford\"\u003eShow Ford\u003c/a\u003e\n```\n\nThis provides a flexible, unobtrusive way to handle generating your clean URLs.\n\n### Forms\n\nForms actions can also be transformed by using hidden input fields to specify your routing parameters.\n\n```html\n\u003cform action=\"server.php\"\u003e\n    \u003cinput type=\"hidden\" name=\"controller\" value=\"cars\" /\u003e\n    \u003cinput type=\"hidden\" name=\"action\" value=\"show\" /\u003e\n    etc...\n\u003c/form\u003e\n```\n\n## The Rewriter\n\nInternally, the output filter uses a rewriting object to transform raw URLs into clean URLs.  We can fetch this from the helper or instantiate it ourselves to use it alone.  This will be handy if you would just like to rewrite URLs individually (when redirecting the user for example).\n\n## Unit Tests\n\nThe library is fully unit tested.  To run these tests just use phing or phpunit...\n\n\u003cpre\u003e\nphing test\n# or\nphpunit tests/php\n\u003c/pre\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboxuk%2Fboxuk-routing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboxuk%2Fboxuk-routing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboxuk%2Fboxuk-routing/lists"}