{"id":15917508,"url":"https://github.com/takuya/php-relative-path","last_synced_at":"2026-03-05T00:03:37.429Z","repository":{"id":57064723,"uuid":"381054439","full_name":"takuya/php-relative-path","owner":"takuya","description":"calculate a relative path to path and create symlink relative","archived":false,"fork":false,"pushed_at":"2026-02-25T03:10:52.000Z","size":135,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-25T08:58:28.047Z","etag":null,"topics":["path","realpath","relative","relative-path","relative-to","symbloic-link","symlink"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/takuya.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-06-28T14:10:31.000Z","updated_at":"2026-02-25T03:10:55.000Z","dependencies_parsed_at":"2025-02-26T02:32:12.319Z","dependency_job_id":"d78e7575-a799-47b0-a978-c0cb6149dbae","html_url":"https://github.com/takuya/php-relative-path","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/takuya/php-relative-path","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takuya%2Fphp-relative-path","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takuya%2Fphp-relative-path/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takuya%2Fphp-relative-path/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takuya%2Fphp-relative-path/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/takuya","download_url":"https://codeload.github.com/takuya/php-relative-path/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takuya%2Fphp-relative-path/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30101697,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T23:59:36.199Z","status":"ssl_error","status_checked_at":"2026-03-04T23:56:48.556Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["path","realpath","relative","relative-path","relative-to","symbloic-link","symlink"],"created_at":"2024-10-06T18:11:08.058Z","updated_at":"2026-03-05T00:03:37.342Z","avatar_url":"https://github.com/takuya.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# php-relativePath\n\nCalculate a relative path to path \n\n[![phpunit](https://github.com/takuya/php-relative-path/actions/workflows/actions.yml/badge.svg)](https://github.com/takuya/php-relative-path/actions/workflows/actions.yml)\n[![composer](https://github.com/takuya/php-relative-path/actions/workflows/composer.yml/badge.svg)](https://github.com/takuya/php-relative-path/actions/workflows/composer.yml)\n\n\n## Get the Relative path.\n\nThis package make you get a relative path to a target.\n\n## Equivalent to GNU realpath (Directory to Dir)\n\nThis package intended to  same to GNU coreuitls `realpath --relative-to=DIR`.\n\n`realpath` option `--relative-to=DIR` is supposed to be Relative `DIR` to `DIR`.\n\nThis package is same to GNU realpath, to calc `DIR to DIR `, not `FILE to FILE`.\n\n\n## Installing from github.\n```\n\ncomposer config repositories.takuya/php-relative-path vcs https://github.com/takuya/php-relative-path\ncomposer config minimum-stability dev\ncomposer require takuya/php-relative-path\n```\n## Installing from packagist.\n```sh\ncomposer require takuya/php-relative-path\ncomposer install\n````\n## Usage example.\nThis package provides a function `relative_path()`  to your composer project. \n```php\n\u003c?php\n\nrequire_once 'vendor/autoload.php';\n$ret = relative_path('/etc/nginx/sites-available', '/etc/nginx/sites-enabled');\nvar_dump($ret);#=\u003e'../sites-available'\n```\n### example:02 file path \n```php\n\u003c?php\n\nrequire_once 'vendor/autoload.php';\n$from = '/etc/nginx/sites-available/example.com';\n$to   = '/etc/nginx/sites-enabled/example.com';\n$ret = relative_path( dirname($from),  dirname($to));\nvar_dump($ret.DIRECTORY_SEPARATOR.basename($from));#=\u003e'../sites-available/example.com'\n```\n\nNotice : `relative_path` expects DIR. \n\n## symlink( relative )\n\n`symlink_relative` function is available.\n\n```php\n\u003c?php\nrequire_once 'vendor/autoload.php';\n$real = '/etc/nginx/sites-available/example.com';\n$link  = '/etc/nginx/sites-enabled/example.com';\nsymlink_relative($link,$real);\n```\n\nRelative path is mainly used in symbolic link. so shortcut helper function is provided.\n\n## run tests \n```\ncomposer install\ncomposer dumpautoload\nrm tests/sample-data.json\n./vendor/bin/phpunit\n```\n\n## tests results sample.\n```text\nTest No.01 :        ./tests/Units relative-to ./tests              is Units\nTest No.02 :          tests/Units relative-to ./tests              is Units\nTest No.03 :        ./tests/Units relative-to tests                is Units\nTest No.04 :          tests/Units relative-to tests                is Units\nTest No.05 :              ./tests relative-to ./tests/Units        is ..\nTest No.06 :                tests relative-to ./tests/Units        is ..\nTest No.07 :              ./tests relative-to tests/Units          is ..\nTest No.08 :                tests relative-to tests/Units          is ..\nTest No.09 :        /usr/bin/bash relative-to /usr/local/bin       is ../../bin/bash\nTest No.10 :        /usr/bin/bash relative-to /usr/local/bin/      is ../../bin/bash\nTest No.11 :             /usr/bin relative-to /usr/local/bin/      is ../../bin\nTest No.12 :                /usr/ relative-to /usr/local/bin/      is ../..\nTest No.13 :                 /usr relative-to /usr/local/bin/      is ../..\nTest No.14 :                    / relative-to /usr/local/bin       is ../../..\nTest No.15 :         /usr/bin/php relative-to /usr/local/bin/      is ../../bin/php\nTest No.16 :        /usr/bin/bash relative-to /usr/local/bin/      is ../../bin/bash\n\n```\nYou will have doubts about `../../bin/bash` and `/../../php` .\n\nYou may shout loud complaint `This package is no use.` But that is bad, Result is correct, intended to be DIR.\n\n`/usr/bin/bash relative-to /usr/local/bin/  is ../../bin/bash` is correct. `DIR to DIR` relative path.\n\nIn precisely `/usr/bin/bash` is interpreted as DIR(`/usr/bin/bash/`), and relative path is `../../bin/bash/`.\n\nif you want to create relative symlink use helper function `symlink_relative`.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakuya%2Fphp-relative-path","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftakuya%2Fphp-relative-path","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakuya%2Fphp-relative-path/lists"}