From 623d74188d398bf76b34f4bc8b56bdb4f40212d5 Mon Sep 17 00:00:00 2001 From: Andrii Vasyliev Date: Mon, 26 Dec 2016 14:02:05 +0000 Subject: [PATCH] add FailedWriteException --- src/Builder.php | 10 ++++++---- src/FailedWriteException.php | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 src/FailedWriteException.php diff --git a/src/Builder.php b/src/Builder.php index 4206cd5..35fb1bb 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -81,7 +81,7 @@ public function saveFiles() $this->writeConfig('__addition', $this->addition); } - public static function rebuild($outputDir) + public static function rebuild($outputDir = null) { $builder = new self([], $outputDir); $builder->loadFiles(); @@ -123,7 +123,7 @@ public function buildConfigs($files = null) } $this->buildConfig($name, $configs); } - file_put_contents($this->getOutputPath('__rebuild'), file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '__rebuild.php')); + static::putFile($this->getOutputPath('__rebuild'), file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '__rebuild.php')); } /** @@ -186,10 +186,12 @@ public static function writeFile($path, array $data) */ protected static function putFile($path, $content) { - if (file_exists($path) && $content = file_get_contents($path)) { + if (file_exists($path) && $content === file_get_contents($path)) { return; } - file_put_contents($path, $content); + if (file_put_contents($path, $content) === FALSE) { + throw new FailedWriteException("Failed write file $path"); + } } /** diff --git a/src/FailedWriteException.php b/src/FailedWriteException.php new file mode 100644 index 0000000..e0738bd --- /dev/null +++ b/src/FailedWriteException.php @@ -0,0 +1,20 @@ + + */ +class FailedWriteException extends \Exception +{ +}