1. Go to this page and download the library: Download lastdragon-ru/path library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lastdragon-ru / path example snippets
declare(strict_types = 1);
namespace LastDragon_ru\Path\Docs\Examples;
use LastDragon_ru\LaraASP\Dev\App\Example;
use LastDragon_ru\Path\DirectoryPath;
use LastDragon_ru\Path\FilePath;
$baseDirectory = new DirectoryPath('/path/to/directory');
$baseFile = new FilePath('/path/to/directory/file.md');
$file = new FilePath('../file.txt');
Example::dump((string) $baseDirectory->resolve($file));
Example::dump((string) $baseFile->resolve($file));
Example::dump((string) $baseFile->file('../../file.md'));
declare(strict_types = 1);
namespace LastDragon_ru\Path\Docs\Examples;
use LastDragon_ru\LaraASP\Dev\App\Example;
use LastDragon_ru\Path\DirectoryPath;
use LastDragon_ru\Path\FilePath;
$base = new DirectoryPath('\\path\\.\\to\\directory');
$file = new FilePath('../path/../to/../file.txt');
$win = new FilePath('c:/path/../to/../file.txt');
Example::dump((string) $base->resolve($file));
Example::dump((string) $win->normalized());
declare(strict_types = 1);
namespace LastDragon_ru\Path\Docs\Examples;
use LastDragon_ru\LaraASP\Dev\App\Example;
use LastDragon_ru\Path\DirectoryPath;
use LastDragon_ru\Path\FilePath;
$home = new DirectoryPath('~/path');
$file = new FilePath('file.txt');
Example::dump($home->type);
Example::dump((string) $home->resolve($file));
Example::dump((string) $home->file('../../../file.md')); // !
declare(strict_types = 1);
namespace LastDragon_ru\Path\Docs\Examples;
use LastDragon_ru\LaraASP\Dev\App\Example;
use LastDragon_ru\Path\DirectoryPath;
use LastDragon_ru\Path\FilePath;
$base = new DirectoryPath('C:/path');
Example::dump(
(string) $base->resolve(new FilePath('C:file.txt')),
);
Example::dump(
(string) $base->resolve(new FilePath('D:file.txt')),
);
declare(strict_types = 1);
namespace LastDragon_ru\Path\Docs\Examples;
use LastDragon_ru\LaraASP\Dev\App\Example;
use LastDragon_ru\Path\DirectoryPath;
use LastDragon_ru\Path\FilePath;
$base = new DirectoryPath('//server/share/directory');
$file = new FilePath('../../../../../file.txt');
Example::dump((string) $base->resolve($file));
declare(strict_types = 1);
namespace LastDragon_ru\Path\Docs\Examples;
use LastDragon_ru\LaraASP\Dev\App\Example;
use LastDragon_ru\Path\DirectoryPath;
use LastDragon_ru\Path\FilePath;
$base = new DirectoryPath('~/path/to/directory');
Example::dump((string) $base->relative(new FilePath('~/file.txt')));
Example::dump($base->relative(new FilePath('/file.txt'))); // `null`, because type differ
plain
"C:/file.txt"
plain
"D:/file.txt"
plain
"//server/share/file.txt"
plain
"../../../file.txt"
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.