{"id":13395592,"url":"https://github.com/mtymek/blast-base-url","last_synced_at":"2026-01-11T16:51:18.845Z","repository":{"id":51252463,"uuid":"48326847","full_name":"mtymek/blast-base-url","owner":"mtymek","description":"PSR-7 middleware and helpers for working with base URL.","archived":false,"fork":false,"pushed_at":"2023-11-29T22:14:16.000Z","size":28,"stargazers_count":10,"open_issues_count":3,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-12T20:37:40.160Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mtymek.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-12-20T15:42:11.000Z","updated_at":"2021-04-06T18:02:55.000Z","dependencies_parsed_at":"2024-01-15T22:01:44.567Z","dependency_job_id":null,"html_url":"https://github.com/mtymek/blast-base-url","commit_stats":{"total_commits":32,"total_committers":3,"mean_commits":"10.666666666666666","dds":0.1875,"last_synced_commit":"3d28633fa329fa7de9051b1419ec8c11908d2753"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtymek%2Fblast-base-url","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtymek%2Fblast-base-url/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtymek%2Fblast-base-url/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtymek%2Fblast-base-url/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mtymek","download_url":"https://codeload.github.com/mtymek/blast-base-url/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243493027,"owners_count":20299584,"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-07-30T18:00:25.142Z","updated_at":"2026-01-11T16:51:18.839Z","avatar_url":"https://github.com/mtymek.png","language":"PHP","funding_links":[],"categories":["Middleware"],"sub_categories":[],"readme":"Blast\\BaseUrl\n=============\n\n[![Build Status](https://travis-ci.org/mtymek/blast-base-url.svg?branch=master)](https://travis-ci.org/mtymek/blast-base-url)\n  \nThis package detects base URL of web application. It is useful when you need your app\nto be served from subdirectory (like `http://localhost/my-project/public`). This can\nbe useful sometimes, especially in development environment.\n\nView helpers for working with assets are also provided in the package.\n\nDetection logic is based on [`zend-http`](https://github.com/zendframework/zend-http) \npackage.\n\nInstallation\n------------\n\nInstallation is supported using Composer:\n```\n$ composer require mtymek/blast-base-url\n```\n\nIf `Zend Component Installer` is present, it will automatically update application configuration.\n\nUsage\n-----\n\nFor simplicity, following instructions are targeting applications based on \n[Zend Expressive Skeleton](https://github.com/zendframework/zend-expressive-skeleton),\nassuming that `Zend\\ServiceManager` was selected as DI container.\n  \n`Blast\\BaseUrl` is based on PSR-7, so it will work well with other frameworks/dispatchers\nlike Slim3 or Relay, just that wiring process will look different.\n\n### Base URL Middleware\n\nAdd `BaseUrlMiddleware` to your pipeline, just before routing middleware (`config/pipeline.php` file):\n\n```php\n// ...\n$app-\u003epipe(\\Blast\\BaseUrl\\BaseUrlMiddleware::class);\n\n// ...\n$app-\u003epipe(RouteMiddleware::class);\n```\n\n`BaseUrlMiddleware` will alter path from request URI, stripping base url. It means that\neven if you access your project from `http:/localhost/~user/project/public/index.php/foo/bar`,\nnext middleware in the pipe will see the path as `/foo/bar`.\n\nAdditionally, two attributes will be added to ServerRequest, holding base URL and base path:\n\n```php\necho $request-\u003egetAttribute(BaseUrlMiddleware::BASE_URL);   \n// outputs: /some/subdirectory/index.php\n\necho $request-\u003egetAttribute(BaseUrlMiddleware::BASE_PATH);\n// outputs: /some/subdirectory/\n```\n\n### Generating URLs\n\n`BaseUrlMiddleware` is able to automatically configure `UrlHelper`, so that all URLs generated \nby this helper will have appropriate prefix. This will be done automatically if `UrlHelper`\nis available in service container.\n\n### Accessing assets - base path\n\nAnother feature provided by this package is base path helper. It can be used to generate URLS\nfor your asset files that work correctly under subdirectory. \n\nIf `BasePathHelper` is available, `BaseUrlMiddleware` will automatically configure it during\nexecution. \n\n#### Zend View\n\nYou will be able to use following syntax inside `zend-view` templates:\n\n```html\n\u003clink rel=\"stylesheet\" href=\"\u003c?= $this-\u003ebasePath('/css/style.css') ?\u003e\" /\u003e\n```\n\nDepending on your application directory, it will produce something similar to:\n\n```html\n\u003clink rel=\"stylesheet\" href=\"/public_html/my-project/public/css/style.css\" /\u003e\n```\n\n#### Twig\n\nYou will be able to use following syntax inside `twig` templates:\n\n```html\n\u003clink rel=\"stylesheet\" href=\"{{ basePath('/css/style.css') }}\" /\u003e\n```\n\nDepending on your application directory, it will produce something similar to:\n\n```html\n\u003clink rel=\"stylesheet\" href=\"/public_html/my-project/public/css/style.css\" /\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtymek%2Fblast-base-url","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmtymek%2Fblast-base-url","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtymek%2Fblast-base-url/lists"}