Skip to content

Commit

Permalink
FileSystem: Add method makeWritable() (#244)
Browse files Browse the repository at this point in the history
Co-authored-by: David Grudl <[email protected]>
  • Loading branch information
janbarasek and dg authored Aug 16, 2021
1 parent c86d2ef commit 1d3a574
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Utils/FileSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,27 @@ public static function write(string $file, string $content, ?int $mode = 0666):
}


/**
* Fixes permissions to a specific file or directory. Directories can be fixed recursively.
* @throws Nette\IOException on error occurred
*/
public static function makeWritable(string $path, int $dirMode = 0777, int $fileMode = 0666): void
{
if (is_file($path)) {
if (!@chmod($path, $fileMode)) { // @ is escalated to exception
throw new Nette\IOException("Unable to chmod file '$path' to mode " . decoct($fileMode) . '. ' . Helpers::getLastError());
}
} elseif (is_dir($path)) {
foreach (new \FilesystemIterator($path) as $item) {
static::makeWritable($item->getPathname(), $dirMode, $fileMode);
}
if (!@chmod($path, $dirMode)) { // @ is escalated to exception
throw new Nette\IOException("Unable to chmod directory '$path' to mode " . decoct($dirMode) . '. ' . Helpers::getLastError());
}
}
}


/**
* Determines if the path is absolute.
*/
Expand Down
24 changes: 24 additions & 0 deletions tests/Utils/Reflection.getReturnType.x.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* Test: Nette\Utils\Reflection::getReturnType
* @phpversion 7
*/

require __DIR__ . '/../bootstrap.php';

class FunctionReflection
{
}

interface FunctionReflectionFactory
{

public function create(
\ReflectionFunction $reflection,
array $phpDocParameterTypes
): FunctionReflection|string;

}

dump(Nette\Utils\Reflection::getReturnType(new \ReflectionMethod(FunctionReflectionFactory::class, 'create')));

0 comments on commit 1d3a574

Please sign in to comment.