Skip to content

Commit

Permalink
Merge branch '4.4' into 5.4
Browse files Browse the repository at this point in the history
* 4.4:
  [Form] Fix same choice loader with different choice values
  [Filesystem] Safeguard (sym)link calls
  • Loading branch information
xabbuh committed May 20, 2022
2 parents 3a44421 + 815412e commit 36a017f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ private function isReadable(string $filename): bool
*/
public function symlink(string $originDir, string $targetDir, bool $copyOnWindows = false)
{
self::assertFunctionExists('symlink');

if ('\\' === \DIRECTORY_SEPARATOR) {
$originDir = strtr($originDir, '/', '\\');
$targetDir = strtr($targetDir, '/', '\\');
Expand Down Expand Up @@ -364,6 +366,8 @@ public function symlink(string $originDir, string $targetDir, bool $copyOnWindow
*/
public function hardlink(string $originFile, $targetFiles)
{
self::assertFunctionExists('link');

if (!$this->exists($originFile)) {
throw new FileNotFoundException(null, 0, null, $originFile);
}
Expand Down Expand Up @@ -730,13 +734,22 @@ private function getSchemeAndHierarchy(string $filename): array
return 2 === \count($components) ? [$components[0], $components[1]] : [null, $components[0]];
}

private static function assertFunctionExists(string $func): void
{
if (!\function_exists($func)) {
throw new IOException(sprintf('Unable to perform filesystem operation because the "%s()" function has been disabled.', $func));
}
}

/**
* @param mixed ...$args
*
* @return mixed
*/
private static function box(callable $func, ...$args)
private static function box(string $func, ...$args)
{
self::assertFunctionExists($func);

self::$lastError = null;
set_error_handler(__CLASS__.'::handleError');
try {
Expand Down

0 comments on commit 36a017f

Please sign in to comment.