Download the PHP package axy/syspaths without Composer
On this page you can find all versions of the php package axy/syspaths. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package syspaths
Short Description Specifying paths within the system
License MIT
Homepage https://github.com/axypro/syspaths
Informations about the package syspaths
axy\syspaths
Specifying paths within the system.
- The library does not require any dependencies (except composer packages).
- Tested on PHP 5.4+, PHP 7, HHVM (on Linux), PHP 5.5 (on Windows).
- Install:
composer require axy/syspaths
. - License: MIT.
Documentation
The library allows to store of the directories structure within a certain system. Inside an application for example.
Define paths in one place makes it easy to change the structure.
API
The library provides a single class axy\syspaths\Paths
.
The constructor:
The only required arguments is $root
- the root directory of the system.
$patterns
$patterns
specifies a list of sub-paths.
It can be specified via the constructor (as in the example above).
Or by overriding:
Now available autocomplete in IDE.
Or you can define the property $patterns
and also specify the argument of the constructor.
In this case these two list recursively merged.
For example, define a system class and redefine some paths for tests.
Access to paths
Via magic methods.
Patterns
If a path pattern begins with a colon then it is a link to the other path. Such links are processed recursively (circular references are not tracked):
If a path pattern begins with /
then it is an absolute path:
Other patterns is relative to the root.
www
is equivalent to :root:/www
.
Nested paths
An array defines a nested object Paths.
For Paths-objects defined __toString()
:
The nested array must contains the field root
.
It may be link: 'root' => ':htdocs:/templates'
.
The nested array may contains the field __classname
for the class of the nested path.
By defaults it is axy\syspaths\Paths
.
Now we have the full auto-complete: $app->paths->templates->profile
.
Links can consist of several components:
Creating paths
Or via the method create
(or __invoke
):
If specified the second argument $real
executed realpath()
for the result.
If the path is not exists then returned NULL
.
Exceptions
In the namespace axy\syspaths\errors
.
RequirePatterns
-$patterns
not defined nor in the property, nor in the constructor.PatternNotFound
- where access via__get
or in a link form other pattern.InvalidPattern
- not closed link, a nested array is not containsroot
,__classname
in not exists and etc.