Skip to content

PathsReducer

Mistralys edited this page Apr 29, 2021 · 1 revision

The paths reducer tool accepts a list of absolute paths, and attempts to reduce them to the closest common relative path.

use AppUtils;

$reducer = FileHelper::createPathsReducer();
$reducer->addPath('/path/to/subfolder/and/file.txt');
$reducer->addPath('/path/to/subfolder/name');
$reducer->addPath('/path/to/subfolder/or/further/name.pdf');

$result = $reducer->reduce();

This will return the following reduced paths:

and/file.txt
name
or/further/name.pdf

NOTE: The tool uses realpath to resolve paths with ... in them, so symlinks will make it fail to reduce if the target file is not on the same drive.

New here?

Have a look at the overview for a list of all helper classes available in the package.

Table of contents

Find the current page in the collapsible "Pages" list above, and expand the page, to view a table of contents.

Clone this wiki locally