Skip to content

04b PathValidator

tei187 edited this page Aug 23, 2024 · 1 revision

Description

tei187\QrImage2Svg\Utilities\PathValidator::class

This class uses static methods in order to validate directory and file paths.


Configuring validation

Root directory

If both your input and output folders are to be limited to a specific root directory, you can use the ::setRootDirectory() method, which accepts the string argument representing a proper existing directory path or null if you want to turn the root directoring validation.

use tei187\QrImage2Svg\Utilities\PathValidator;

PathValidator::setRootDirectory('some/root/path'); // setting root directory validation
PathValidator::setRootDirectory(null); // removing root directory validation

Relative paths

If you want to allow relative paths being used within the validator (turned off by default), you will have to use the ::setAllowedRelativePath() method, accepting a boolean argument. Turning it on will remove any relative paths traversal strings from input and output dir arguments.

PathValidator::setAllowedRelativePath(true); // relative paths allowed
PathValidator::setAllowedRelativePath(false); // relative paths NOT allowed

Maximal path length

It is possible to set the maximal path length by using the ::setMaxPathLength() method, accepting an integer argument. By default it uses the PHP_MAXPATHLEN environmental constans.


Temporary directory

Certain processors may require a temporary directory to store temporary process files. This directory can be set manually by using ::setTempDirectory() accepting a string argument. By default, the value corresponds with sys_get_temp_dir().


Paths caching

PathValidator uses an internal caching array, usefull when you are working on many files in bulk. It can be turned off and on by using the ::setRealpathCaching(), passing a boolean argument.