{"id":17472368,"url":"https://github.com/jackiedo/path-helper","last_synced_at":"2025-07-12T05:04:57.195Z","repository":{"id":56995423,"uuid":"466402187","full_name":"JackieDo/Path-Helper","owner":"JackieDo","description":"Helper class for working with local paths in PHP","archived":false,"fork":false,"pushed_at":"2022-03-17T06:25:12.000Z","size":23,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-06T12:42:30.106Z","etag":null,"topics":["helper","helpers","library","path","paths","php"],"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/JackieDo.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":"2022-03-05T09:02:40.000Z","updated_at":"2025-01-17T05:29:56.000Z","dependencies_parsed_at":"2022-08-21T13:20:29.470Z","dependency_job_id":null,"html_url":"https://github.com/JackieDo/Path-Helper","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/JackieDo/Path-Helper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JackieDo%2FPath-Helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JackieDo%2FPath-Helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JackieDo%2FPath-Helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JackieDo%2FPath-Helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JackieDo","download_url":"https://codeload.github.com/JackieDo/Path-Helper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JackieDo%2FPath-Helper/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264940385,"owners_count":23686243,"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":["helper","helpers","library","path","paths","php"],"created_at":"2024-10-18T17:08:53.971Z","updated_at":"2025-07-12T05:04:57.169Z","avatar_url":"https://github.com/JackieDo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Path Helper\n\n[![Latest Stable Version](https://poser.pugx.org/jackiedo/path-helper/v)](//packagist.org/packages/jackiedo/path-helper)\n[![Total Downloads](https://poser.pugx.org/jackiedo/path-helper/downloads)](//packagist.org/packages/jackiedo/path-helper)\n[![Latest Unstable Version](https://poser.pugx.org/jackiedo/path-helper/v/unstable)](//packagist.org/packages/jackiedo/path-helper)\n[![License](https://poser.pugx.org/jackiedo/path-helper/license)](//packagist.org/packages/jackiedo/path-helper)\n\nHelper class for working with local paths in PHP.\n\n# Compatibility\nThis package requires PHP 5.4.0 or later.\n\n# Overview\nLook at one of the following topics to learn more about Path Helper\n\n- [Path Helper](#path-helper)\n- [Compatibility](#compatibility)\n- [Overview](#overview)\n  - [Installation](#installation)\n  - [Usage](#usage)\n    - [Using static method](#using-static-method)\n    - [Using method of instance](#using-method-of-instance)\n    - [Using built-in function](#using-built-in-function)\n  - [Available methods](#available-methods)\n    - [Normalize the directory separators of the path](#normalize-the-directory-separators-of-the-path)\n    - [Restyle the path](#restyle-the-path)\n      - [Restyle to Unix style](#restyle-to-unix-style)\n      - [Restyle to Windows style](#restyle-to-windows-style)\n      - [Restyle belong to current OS](#restyle-belong-to-current-os)\n    - [Create the absolute path](#create-the-absolute-path)\n    - [Create the relative path](#create-the-relative-path)\n    - [Check the form of the path](#check-the-form-of-the-path)\n      - [Check the absolute form](#check-the-absolute-form)\n      - [Check the relative form](#check-the-relative-form)\n    - [Check the mutual wrapping of paths](#check-the-mutual-wrapping-of-paths)\n      - [Check if the path is ancestor of another](#check-if-the-path-is-ancestor-of-another)\n      - [Check if the path is descendant of another](#check-if-the-path-is-descendant-of-another)\n  - [Available functions](#available-functions)\n- [License](#license)\n\n## Installation\n[Download a latest package](https://github.com/JackieDo/Path-Helper/releases/latest) or use [Composer](http://getcomposer.org/):\n\n```shell\n$ composer require jackiedo/path-helper\n```\n\n## Usage\n\nAfter requiring composer autoloader, you can use the package in the following ways:\n\n### Using static method\n\n``` php\nuse Jackiedo\\PathHelper\\Path;\n\n// ...\n\n$return = Path::doSomething();\n```\n\n### Using method of instance\n\n```php\nuse Jackiedo\\PathHelper\\Path;\n\n// ...\n\n$helper = new Path;\n$return = $helper-\u003edoSomething();\n```\n\n### Using built-in function\n\nSee [here](#available-functions) for more details.\n\n## Available methods\n\n### Normalize the directory separators of the path\nFormats the directory separators of a given path with a specific string.\n\n**Syntax:**\n\n```php\n/**\n * Formats the directory separators of a given path with a specific string.\n *\n * @param string $path      the path want to normalize\n * @param string $separator the directory separator want to use\n *\n * @return string\n */\npublic static function normalize($path, $separator = DIRECTORY_SEPARATOR);\n```\n\n**Example:**\n\n```php\n$return1 = Path::normalize('path\\\\to/specific/file/or\\\\directory');\n// The result returned will depend on the operating system\n//     On Windows -\u003e path\\to\\specific\\file\\or\\directory\n//     On Unix    -\u003e path/to/specific/file/or/directory\n\n$return2 = Path::normalize('path\\\\to/specific/file/or\\\\directory', '/');\n// path/to/specific/file/or/directory\n\n$return3 = Path::normalize('path\\\\to/specific/file/or\\\\directory', ' \u003e ');\n// path \u003e to \u003e specific \u003e file \u003e or \u003e directory\n```\n\n### Restyle the path\n\n#### Restyle to Unix style\nAlternative to `normalize($path, '/')` method.\n\n**Syntax:**\n\n```php\n/**\n * Normalize directory separators of a given path according to Unix OS style.\n *\n * @param string $path the path want to normalize\n *\n * @return string\n */\npublic static function unixStyle($path);\n```\n\n**Example:**\n\n```php\n$return = Path::unixStyle('path\\\\to/specific/file/or\\\\directory');\n// path/to/specific/file/or/directory\n```\n\n#### Restyle to Windows style\nAlternative to `normalize($path, '\\\\')` method.\n\n**Syntax:**\n\n```php\n/**\n * Normalize directory separators of a given path according to Windows OS style.\n *\n * @param string $path the path want to normalize\n *\n * @return string\n */\npublic static function winStyle($path);\n```\n\n**Example:**\n\n```php\n$return = Path::winStyle('path\\\\to/specific/file/or\\\\directory');\n// path\\to\\specific\\file\\or\\directory\n```\n\n#### Restyle belong to current OS\nAlternative to `normalize($path, DIRECTORY_SEPARATOR)` method.\n\n**Syntax:**\n\n```php\n/**\n * Normalize directory separators of a given path according to the current OS style.\n *\n * @param string $path the path want to normalize\n *\n * @return string\n */\npublic static function osStyle($path);\n```\n\n**Example:**\n\n```php\n$return = Path::osStyle('path\\\\to/specific/file/or\\\\directory');\n// The result returned will depend on the operating system\n//     On Windows -\u003e path\\to\\specific\\file\\or\\directory\n//     On Unix    -\u003e path/to/specific/file/or/directory\n```\n\n### Create the absolute path\nCreate the absolute path from a given path.\n\n**Syntax:**\n\n```php\n/**\n * Return absolute path from a given path.\n *\n * This method is an alternative to `realpath()` function for non-existent paths.\n *\n * @param string $path      the path want to format\n * @param string $separator the directory separator want to use in the result\n *\n * @return string\n */\npublic static function absolute($path, $separator = DIRECTORY_SEPARATOR);\n```\n\n**Example:**\n\n```php\n$return = Path::absolute('./this\\\\is/../sample/path');\n// The result returned will depend on the operating system and current working directory\n// You will probably get the following result: /home/www/public_html/this/sample/path\n```\n\n**Note:**\n\nThis method looks like PHP's `realpath()` function at first glance, but it actually works in a different way.\n\n\u003e The `realpath()` function returns the absolute path to the `existing` directory or file, while this method `does not check` for actual existence.\n\n### Create the relative path\nCreate the relative path from a given file or directory to another location.\n\n**Syntax:**\n\n```php\n/**\n * Return relative path from a given file or directory to another location.\n *\n * @param string $from      the path of departure file or directory\n * @param string $to        the path of destination file or directory\n * @param string $separator the directory separator want to use in the result\n *\n * @return string\n */\npublic static function relative($from, $to, $separator = DIRECTORY_SEPARATOR);\n```\n\n**Example:**\n\n```php\n$return = Path::absolute('./this\\\\is/../sample/path', '/home/www/another/directory');\n// The result returned will depend on the operating system and current working directory\n// You will probably get the following result: ../../../../another/directory\n```\n\n### Check the form of the path\n\n#### Check the absolute form\n\n**Syntax:**\n\n```php\n/**\n * Check if a given path is an absolute path.\n *\n * @param string $path the path want to check\n *\n * @return bool\n */\npublic static function isAbsolute($path);\n```\n\n**Example:**\n\n```php\n$return = Path::isAbsolute('/home/www/public_html');      // true\n$return = Path::isAbsolute('sample/../path');             // false\n$return = Path::isAbsolute('D:\\\\home\\\\www\\\\public_html'); // true\n$return = Path::isAbsolute('sample\\\\..\\\\path');           // false\n```\n\n#### Check the relative form\n\n**Syntax:**\n\n```php\n/**\n * Check if a given path is a relative path.\n *\n * @param string $path the path want to check\n *\n * @return bool\n */\npublic static function isRelative($path);\n```\n\n**Example:**\n\n```php\n$return = Path::isRelative('/home/www/public_html');      // false\n$return = Path::isRelative('sample/../path');             // true\n$return = Path::isRelative('D:\\\\home\\\\www\\\\public_html'); // false\n$return = Path::isRelative('sample\\\\..\\\\path');           // true\n```\n\n### Check the mutual wrapping of paths\n\n#### Check if the path is ancestor of another\n\n**Syntax:**\n\n```php\n/**\n * Check if a given path is ancestor of the another path.\n *\n * Return true if the input path is ancestor of the comparison\n *\n * @param string $path       the path want to check\n * @param string $comparison the target path used for comparison\n *\n * @return bool\n */\npublic static function isAncestor($path, $comparison);\n```\n\n**Example:**\n\n```php\n$return = Path::isAncestor('/home/www', '/home/www/public/assets/css/../images/sample.png');     // true\n$return = Path::isAncestor('/home/www', '/another_home/public/assets/css/../images/sample.png'); // false\n```\n\n#### Check if the path is descendant of another\n\n**Syntax:**\n\n```php\n/**\n * Check if a given path is descendant of the another path.\n *\n * Return true if the input path is descendant of the comparison\n *\n * @param string $path       the path want to check\n * @param string $comparison the target path used for comparison\n *\n * @return bool\n */\npublic static function isDescendant($path, $comparison);\n```\n\n**Example:**\n\n```php\n$return = Path::isDescendant('/home/www/public/assets/css/../images/sample.png', '/home/www');     // true\n$return = Path::isDescendant('/another_home/public/assets/css/../images/sample.png', '/home/www'); // false\n```\n\n## Available functions\nThis package contains several built-in `functions` to alternative using the `methods` of the `Path` class. However, the use of these functions is `not recommended`, because they may conflict with the functions of other packages.\n\n| Function               | Class method           |\n| ---------------------- | ---------------------- |\n| *absolute_path()*      | *Path::absolute()*     |\n| *relative_path()*      | *Path::relative()*     |\n| *winstyle_path()*      | *Path::winStyle()*     |\n| *unixstyle_path()*     | *Path::unixStyle()*    |\n| *osstyle_path()*       | *Path::osStyle()*      |\n| *normalize_path()*     | *Path::normalize()*    |\n| *is_absolute_path()*   | *Path::isAbsolute()*   |\n| *is_relative_path()*   | *Path::isRelative()*   |\n| *is_descendant_path()* | *Path::isDescendant()* |\n| *is_ancestor_path()*   | *Path::isAncestor()*   |\n\n# License\n[MIT](https://github.com/JackieDo/Path-Helper/blob/master/LICENSE) © Jackie Do\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackiedo%2Fpath-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjackiedo%2Fpath-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackiedo%2Fpath-helper/lists"}