Skip to content
PHP Ecosystem
Explore

PathValidator

API reference › Scaffold › Security › PathValidator

final classPHPForge\Scaffold\Security\PathValidator
Sourcesrc/Security/PathValidator.php

Rejects source and destination paths that are absolute, contain .. segments, escape their root through a symlink, or address the reserved scaffold-lock.json.

MethodDescriptionDefined by
hasTraversal() staticReturns whether $path contains a .. segment, splitting on forward slashes and backslashes.PathValidator
isAbsolute() staticReturns whether $path starts with a directory separator or a Windows drive letter.PathValidator
validateDestination()Validates that a destination path does not escape the project root.PathValidator
validateSource()Validates that a source path does not escape the provider root.PathValidator
public static function hasTraversal(string $path): bool

Returns whether $path contains a .. segment, splitting on forward slashes and backslashes.

Parameters

ParameterTypeDescription
$pathstringPath to check.

Returns

bool: true when a segment is .., false otherwise.

public static function isAbsolute(string $path): bool

Returns whether $path starts with a directory separator or a Windows drive letter.

Parameters

ParameterTypeDescription
$pathstringPath to check.

Returns

bool: true when the path is absolute or drive-qualified, false otherwise.

public function validateDestination(string $destination, string $projectRoot): string

Validates that a destination path does not escape the project root.

Parameters

ParameterTypeDescription
$destinationstringRelative destination path declared in the manifest.
$projectRootstringAbsolute path to the project root directory.

Returns

string: Canonical absolute path of the project root.

Throws

  • RuntimeException: when the project root does not exist, or the destination is absolute, contains .., escapes the root through a symlink, or is reserved.
public function validateSource(string $source, string $providerRoot): string

Validates that a source path does not escape the provider root.

Parameters

ParameterTypeDescription
$sourcestringRelative source path declared in the manifest.
$providerRootstringAbsolute path to the provider root inside vendor.

Returns

string: Canonical absolute path of the provider root.

Throws

  • RuntimeException: when the provider root does not exist, or the source is absolute, contains .. or escapes the root through a symlink.