Skip to content

Commit

Permalink
deprecate(documentator): `LastDragon_ru\LaraASP\Documentator\Utils\Pa…
Browse files Browse the repository at this point in the history
…th` (please use `LastDragon_ru\LaraASP\Core\Utils\Path` instead). (#146)
  • Loading branch information
LastDragon-ru authored Mar 23, 2024
1 parent 3e30a97 commit d2c7592
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 56 deletions.
1 change: 1 addition & 0 deletions packages/core/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"illuminate/console": "^10.34.0",
"illuminate/container": "^10.34.0",
"illuminate/contracts": "^10.34.0",
"symfony/filesystem": "^6.3.0",
"symfony/polyfill-php83": "^1.28"
},
"require-dev": {
Expand Down
49 changes: 49 additions & 0 deletions packages/core/src/Utils/Path.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php declare(strict_types = 1);

namespace LastDragon_ru\LaraASP\Core\Utils;

use Symfony\Component\Filesystem\Path as SymfonyPath;

use function dirname;
use function is_file;

class Path {
public static function getPath(string $root, string $path): string {
$path = static::isRelative($path)
? static::join(static::getDirname($root), $path)
: $path;
$path = static::normalize($path);

return $path;
}

public static function getRelativePath(string $root, string $path): string {
$path = static::isRelative($path)
? static::join(static::getDirname($root), $path)
: $path;
$path = SymfonyPath::makeRelative($path, $root);
$path = static::normalize($path);

return $path;
}

public static function getDirname(string $path): string {
return static::normalize(is_file($path) ? dirname($path) : $path);
}

public static function isRelative(string $path): bool {
return SymfonyPath::isRelative(static::normalize($path));
}

public static function isAbsolute(string $path): bool {
return SymfonyPath::isAbsolute(static::normalize($path));
}

public static function normalize(string $path): string {
return SymfonyPath::canonicalize($path);
}

public static function join(string ...$paths): string {
return SymfonyPath::join(...$paths);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php declare(strict_types = 1);

namespace LastDragon_ru\LaraASP\Documentator\Utils;
namespace LastDragon_ru\LaraASP\Core\Utils;

use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase;
use LastDragon_ru\LaraASP\Core\Testing\Package\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;

use function dirname;
Expand Down
2 changes: 1 addition & 1 deletion packages/documentator/src/Commands/Commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use LastDragon_ru\LaraASP\Core\Utils\Cast;
use LastDragon_ru\LaraASP\Core\Utils\Path;
use LastDragon_ru\LaraASP\Documentator\Package;
use LastDragon_ru\LaraASP\Documentator\PackageViewer;
use LastDragon_ru\LaraASP\Documentator\Utils\ArtisanSerializer;
use LastDragon_ru\LaraASP\Documentator\Utils\Path;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Filesystem\Filesystem;
Expand Down
2 changes: 1 addition & 1 deletion packages/documentator/src/Commands/CommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\ServiceProvider;
use LastDragon_ru\LaraASP\Core\Utils\Path;
use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase;
use LastDragon_ru\LaraASP\Documentator\Utils\Path;
use Override;
use PHPUnit\Framework\Attributes\CoversClass;
use Symfony\Component\Console\Attribute\AsCommand;
Expand Down
2 changes: 1 addition & 1 deletion packages/documentator/src/Commands/Requirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
use Exception;
use Illuminate\Console\Command;
use LastDragon_ru\LaraASP\Core\Utils\Cast;
use LastDragon_ru\LaraASP\Core\Utils\Path;
use LastDragon_ru\LaraASP\Documentator\Metadata\Metadata;
use LastDragon_ru\LaraASP\Documentator\Metadata\Storage;
use LastDragon_ru\LaraASP\Documentator\Package;
use LastDragon_ru\LaraASP\Documentator\PackageViewer;
use LastDragon_ru\LaraASP\Documentator\Utils\Git;
use LastDragon_ru\LaraASP\Documentator\Utils\Path;
use LastDragon_ru\LaraASP\Documentator\Utils\Version;
use LastDragon_ru\LaraASP\Serializer\Contracts\Serializer;
use Symfony\Component\Console\Attribute\AsCommand;
Expand Down
2 changes: 1 addition & 1 deletion packages/documentator/src/Metadata/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace LastDragon_ru\LaraASP\Documentator\Metadata;

use LastDragon_ru\LaraASP\Documentator\Utils\Path;
use LastDragon_ru\LaraASP\Core\Utils\Path;
use LastDragon_ru\LaraASP\Documentator\Utils\Version;
use LastDragon_ru\LaraASP\Serializer\Contracts\Serializer;
use Symfony\Component\Serializer\Context\Encoder\JsonEncoderContextBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace LastDragon_ru\LaraASP\Documentator\Preprocessor\Instructions\IncludeDocBlock;

use Exception;
use LastDragon_ru\LaraASP\Core\Utils\Path;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Contracts\ParameterizableInstruction;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Exceptions\TargetIsNotFile;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Exceptions\TargetIsNotValidPhpFile;
use LastDragon_ru\LaraASP\Documentator\Utils\Path;
use LastDragon_ru\LaraASP\Serializer\Contracts\Serializable;
use Override;
use PhpParser\NameContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace LastDragon_ru\LaraASP\Documentator\Preprocessor\Instructions\IncludeDocumentList;

use LastDragon_ru\LaraASP\Core\Utils\Path;
use LastDragon_ru\LaraASP\Documentator\PackageViewer;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Contracts\ParameterizableInstruction;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Exceptions\DocumentTitleIsMissing;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Exceptions\TargetIsNotDirectory;
use LastDragon_ru\LaraASP\Documentator\Utils\Markdown;
use LastDragon_ru\LaraASP\Documentator\Utils\Path;
use LastDragon_ru\LaraASP\Serializer\Contracts\Serializable;
use Override;
use Symfony\Component\Finder\Finder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
use Exception;
use Illuminate\Container\Container;
use Illuminate\Process\Factory;
use LastDragon_ru\LaraASP\Core\Utils\Path;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Contracts\ProcessableInstruction;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Exceptions\TargetExecFailed;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Exceptions\TargetIsNotFile;
use LastDragon_ru\LaraASP\Documentator\Utils\Path;
use Override;

use function dirname;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace LastDragon_ru\LaraASP\Documentator\Preprocessor\Instructions\IncludeFile;

use LastDragon_ru\LaraASP\Core\Utils\Path;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Contracts\ProcessableInstruction;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Exceptions\TargetIsNotFile;
use LastDragon_ru\LaraASP\Documentator\Utils\Path;
use Override;

use function dirname;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
namespace LastDragon_ru\LaraASP\Documentator\Preprocessor\Instructions\IncludePackageList;

use Exception;
use LastDragon_ru\LaraASP\Core\Utils\Path;
use LastDragon_ru\LaraASP\Documentator\PackageViewer;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Contracts\ParameterizableInstruction;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Exceptions\DocumentTitleIsMissing;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Exceptions\PackageComposerJsonIsMissing;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Exceptions\PackageReadmeIsMissing;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Exceptions\TargetIsNotDirectory;
use LastDragon_ru\LaraASP\Documentator\Utils\Markdown;
use LastDragon_ru\LaraASP\Documentator\Utils\Path;
use LastDragon_ru\LaraASP\Serializer\Contracts\Serializable;
use Override;
use Symfony\Component\Finder\Finder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace LastDragon_ru\LaraASP\Documentator\Preprocessor\Instructions\IncludeTemplate;

use LastDragon_ru\LaraASP\Core\Utils\Path;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Contracts\ParameterizableInstruction;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Exceptions\TargetIsNotFile;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Exceptions\TemplateDataMissed;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Exceptions\TemplateVariablesMissed;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Exceptions\TemplateVariablesUnused;
use LastDragon_ru\LaraASP\Documentator\Utils\Path;
use LastDragon_ru\LaraASP\Serializer\Contracts\Serializable;
use Override;

Expand Down
2 changes: 1 addition & 1 deletion packages/documentator/src/Preprocessor/Preprocessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Exception;
use Illuminate\Container\Container;
use LastDragon_ru\LaraASP\Core\Utils\Path;
use LastDragon_ru\LaraASP\Documentator\Commands\Preprocess;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Contracts\Instruction;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Contracts\ParameterizableInstruction;
Expand All @@ -16,7 +17,6 @@
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Instructions\IncludeFile\Instruction as IncludeFile;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Instructions\IncludePackageList\Instruction as IncludePackageList;
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Instructions\IncludeTemplate\Instruction as IncludeTemplate;
use LastDragon_ru\LaraASP\Documentator\Utils\Path;
use LastDragon_ru\LaraASP\Serializer\Contracts\Serializer;

use function array_column;
Expand Down
49 changes: 6 additions & 43 deletions packages/documentator/src/Utils/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,11 @@

namespace LastDragon_ru\LaraASP\Documentator\Utils;

use Symfony\Component\Filesystem\Path as SymfonyPath;
use LastDragon_ru\LaraASP\Core\Utils\Path as CorePath;

use function dirname;
use function is_file;

class Path {
public static function getPath(string $root, string $path): string {
$path = static::isRelative($path)
? static::join(static::getDirname($root), $path)
: $path;
$path = static::normalize($path);

return $path;
}

public static function getRelativePath(string $root, string $path): string {
$path = static::isRelative($path)
? static::join(static::getDirname($root), $path)
: $path;
$path = SymfonyPath::makeRelative($path, $root);
$path = static::normalize($path);

return $path;
}

public static function getDirname(string $path): string {
return static::normalize(is_file($path) ? dirname($path) : $path);
}

public static function isRelative(string $path): bool {
return SymfonyPath::isRelative(static::normalize($path));
}

public static function isAbsolute(string $path): bool {
return SymfonyPath::isAbsolute(static::normalize($path));
}

public static function normalize(string $path): string {
return SymfonyPath::canonicalize($path);
}

public static function join(string ...$paths): string {
return SymfonyPath::join(...$paths);
}
/**
* @deprecated ${version} Use {@see CorePath} instead.
*/
class Path extends CorePath {
// empty
}

0 comments on commit d2c7592

Please sign in to comment.