mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-09 21:48:41 +00:00
Improve robustness
This commit is contained in:
parent
bc77b62685
commit
ff91b98a44
|
|
@ -74,24 +74,28 @@ final class File extends FileAbstract implements LocalContainerInterface, FileIn
|
||||||
{
|
{
|
||||||
$exists = \file_exists($path);
|
$exists = \file_exists($path);
|
||||||
|
|
||||||
if ((ContentPutMode::hasFlag($mode, ContentPutMode::APPEND) && $exists)
|
try {
|
||||||
|| (ContentPutMode::hasFlag($mode, ContentPutMode::PREPEND) && $exists)
|
if (($exists && ContentPutMode::hasFlag($mode, ContentPutMode::APPEND))
|
||||||
|| (ContentPutMode::hasFlag($mode, ContentPutMode::REPLACE) && $exists)
|
|| ($exists && ContentPutMode::hasFlag($mode, ContentPutMode::PREPEND))
|
||||||
|| (!$exists && ContentPutMode::hasFlag($mode, ContentPutMode::CREATE))
|
|| ($exists && ContentPutMode::hasFlag($mode, ContentPutMode::REPLACE))
|
||||||
) {
|
|| (!$exists && ContentPutMode::hasFlag($mode, ContentPutMode::CREATE))
|
||||||
if (ContentPutMode::hasFlag($mode, ContentPutMode::APPEND) && $exists) {
|
) {
|
||||||
\file_put_contents($path, \file_get_contents($path) . $content);
|
if ($exists && ContentPutMode::hasFlag($mode, ContentPutMode::APPEND)) {
|
||||||
} elseif (ContentPutMode::hasFlag($mode, ContentPutMode::PREPEND) && $exists) {
|
\file_put_contents($path, \file_get_contents($path) . $content);
|
||||||
\file_put_contents($path, $content . \file_get_contents($path));
|
} elseif ($exists && ContentPutMode::hasFlag($mode, ContentPutMode::PREPEND)) {
|
||||||
} else {
|
\file_put_contents($path, $content . \file_get_contents($path));
|
||||||
if (!Directory::exists(\dirname($path))) {
|
} else {
|
||||||
Directory::create(\dirname($path), 0755, true);
|
if (!Directory::exists(\dirname($path))) {
|
||||||
|
Directory::create(\dirname($path), 0755, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
\file_put_contents($path, $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
\file_put_contents($path, $content);
|
return true;
|
||||||
}
|
}
|
||||||
|
} catch (\Throwable $e) {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -251,7 +255,7 @@ final class File extends FileAbstract implements LocalContainerInterface, FileIn
|
||||||
public static function size(string $path, bool $recursive = true) : int
|
public static function size(string $path, bool $recursive = true) : int
|
||||||
{
|
{
|
||||||
if (!\file_exists($path)) {
|
if (!\file_exists($path)) {
|
||||||
throw new PathException($path);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int) \filesize($path);
|
return (int) \filesize($path);
|
||||||
|
|
|
||||||
|
|
@ -116,9 +116,7 @@ class FileTest extends \PHPUnit\Framework\TestCase
|
||||||
|
|
||||||
public function testInvalidSizePath() : void
|
public function testInvalidSizePath() : void
|
||||||
{
|
{
|
||||||
self::expectException(\phpOMS\System\File\PathException::class);
|
self::assertEquals(0, File::size(__DIR__ . '/invalid.txt'));
|
||||||
|
|
||||||
File::size(__DIR__ . '/invalid.txt');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInvalidPermissionPath() : void
|
public function testInvalidPermissionPath() : void
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user