From c7ecca60adac8bbcd16796ba7573c90847f4566e Mon Sep 17 00:00:00 2001 From: Andrew Roslik Date: Tue, 30 Aug 2016 15:45:38 +0300 Subject: [PATCH] Implemented #116: Rename "commithook files:allow-default" to "commithook files allow-default" - Added catching php error exceptions. Pushed to using dirname() func. --- .../PreCommit/Console/Helper/Config/WriterHelper.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/lib/PreCommit/Console/Helper/Config/WriterHelper.php b/src/lib/PreCommit/Console/Helper/Config/WriterHelper.php index 58038cf..b960f4a 100644 --- a/src/lib/PreCommit/Console/Helper/Config/WriterHelper.php +++ b/src/lib/PreCommit/Console/Helper/Config/WriterHelper.php @@ -53,10 +53,16 @@ public function write($config, $file) */ public function writeContent($file, $content) { - $dir = pathinfo($file, PATHINFO_DIRNAME); - if (!is_dir($dir) && !mkdir($dir, 770, true)) { - throw new Exception('Cannot create directory \''.$dir.'\'.'); + $dir = dirname($file); + + try { + if (!is_dir($dir) && !mkdir($dir, 770, true)) { + throw new Exception("Cannot create directory '$dir' (file: $file)."); + } + } catch (\Exception $e) { + throw new Exception("Cannot create directory '$dir' (file: $file)."); } + if (!file_put_contents($file, $content)) { throw new Exception("Cannot write file '$file'."); }