dgifford/path

v0.3 2017-03-02 15:16 UTC

This package is auto-updated.

Last update: 2024-09-15 06:23:04 UTC


README

用于操作路径的类。

用法

该类可以非静态地使用

$path = new Path( '/path/to/a/file.ext' );

// Boolean check if the path exists
$path->exists();

// Boolean check if the path is writeable
$path->writeable();

// Get components of the path
$path->extension(); // returns 'ext'

// Get the path
$path->get(); // Returns '/path/to/a/file.ext'

// Change the path
$path->set('path/to/a/foo/../file.ext' );

// Resolve the path to a real path
$path->real()->get(); // Returns '/path/to/a/file.ext' or false if it doesn't exist

也可以静态地使用

// Boolean check if a path exists
Path::exists( '/path/to/a/file.ext' );

// Boolean check if a path is writeable
Path::writeable( '/path/to/a/file.ext' );

// Get components of the path
Path::extension( '/path/to/a/file.ext' ); // returns 'ext'

// Resolve a path to a real path
Path::real('path/to/a/foo/../file.ext' ); // Returns '/path/to/a/file.ext' or false if it doesn't exist

该类还可以接受多个参数

// Join strings to make a path
$path = new Path( '/path/', '/to/', '\a\', 'file.ext' );

$path->join()->get(); // Returns '/path/to/a/file.ext'

// Boolean check if any of the paths don't exist
$path->set( '/path/to/a/file.ext', 'foo bar', '/var/etc/' );

$path->exists(); // Returns false

// Boolean check if each of the paths exists
$path->exists( true ); // Returns [ true, false, true ]