Permalink
Browse files

Check that the content exists and is readable before including in the

book

fixes issue #8 - thanks @marijn for reporting
  • Loading branch information...
1 parent e0e977c commit e86aa18e3ec8869c3c4a6c04a4ab37e664aaf7aa @javiereguiluz committed Feb 18, 2012
Showing with 14 additions and 0 deletions.
  1. +14 −0 src/Easybook/Publishers/BasePublisher.php
@@ -59,6 +59,20 @@ public function loadContents()
// TODO: extensibility -> contents could be written in several formats simultaneously
// (e.g. Twig *and* Markdown)
$contentFile = $this->app['publishing.dir.contents'].'/'.$contentConfig['content'];
+
+ // check that content file exists and is readable
+ if (!is_readable($contentFile)) {
+ throw new \RuntimeException(sprintf(
+ "The '%s' content associated with '%s' element doesn't exist\n"
+ ."or is not readable.\n\n"
+ ."Check that '%s'\n"
+ ."file exists and check its permissions.",
+ $contentConfig['content'],
+ $item['config']['element'],
+ realpath($this->app['publishing.dir.contents']).'/'.$contentConfig['content']
+ ));
+ }
+
$item['original'] = file_get_contents($contentFile);
$item['config']['format'] = pathinfo($contentFile, PATHINFO_EXTENSION);
}

0 comments on commit e86aa18

Please sign in to comment.