Skip to content

Commit 1d3a574

Browse files
janbarasekdg
andauthored
FileSystem: Add method makeWritable() (#244)
Co-authored-by: David Grudl <[email protected]>
1 parent c86d2ef commit 1d3a574

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/Utils/FileSystem.php

+21
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,27 @@ public static function write(string $file, string $content, ?int $mode = 0666):
148148
}
149149

150150

151+
/**
152+
* Fixes permissions to a specific file or directory. Directories can be fixed recursively.
153+
* @throws Nette\IOException on error occurred
154+
*/
155+
public static function makeWritable(string $path, int $dirMode = 0777, int $fileMode = 0666): void
156+
{
157+
if (is_file($path)) {
158+
if (!@chmod($path, $fileMode)) { // @ is escalated to exception
159+
throw new Nette\IOException("Unable to chmod file '$path' to mode " . decoct($fileMode) . '. ' . Helpers::getLastError());
160+
}
161+
} elseif (is_dir($path)) {
162+
foreach (new \FilesystemIterator($path) as $item) {
163+
static::makeWritable($item->getPathname(), $dirMode, $fileMode);
164+
}
165+
if (!@chmod($path, $dirMode)) { // @ is escalated to exception
166+
throw new Nette\IOException("Unable to chmod directory '$path' to mode " . decoct($dirMode) . '. ' . Helpers::getLastError());
167+
}
168+
}
169+
}
170+
171+
151172
/**
152173
* Determines if the path is absolute.
153174
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* Test: Nette\Utils\Reflection::getReturnType
5+
* @phpversion 7
6+
*/
7+
8+
require __DIR__ . '/../bootstrap.php';
9+
10+
class FunctionReflection
11+
{
12+
}
13+
14+
interface FunctionReflectionFactory
15+
{
16+
17+
public function create(
18+
\ReflectionFunction $reflection,
19+
array $phpDocParameterTypes
20+
): FunctionReflection|string;
21+
22+
}
23+
24+
dump(Nette\Utils\Reflection::getReturnType(new \ReflectionMethod(FunctionReflectionFactory::class, 'create')));

0 commit comments

Comments
 (0)