Skip to content

Commit

Permalink
add FailedWriteException
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Dec 26, 2016
1 parent c71fd6f commit 623d741
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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'));
}

/**
Expand Down Expand Up @@ -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");
}
}

/**
Expand Down
20 changes: 20 additions & 0 deletions src/FailedWriteException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Composer plugin for config assembling
*
* @link https://github.com/hiqdev/composer-config-plugin
* @package composer-config-plugin
* @license BSD-3-Clause
* @copyright Copyright (c) 2016, HiQDev (http://hiqdev.com/)
*/

namespace hiqdev\composer\config;

/**
* Failed write file exception.
*
* @author Andrii Vasyliev <sol@hiqdev.com>
*/
class FailedWriteException extends \Exception
{
}

0 comments on commit 623d741

Please sign in to comment.