Skip to content

Commit

Permalink
AliasExpander: setCacheDir() does not throw an exception
Browse files Browse the repository at this point in the history
  • Loading branch information
milo committed Jun 24, 2013
1 parent 3f2c9db commit b9ac4b3
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions AliasExpander.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,23 @@ class AliasExpander
* Sets cache dir.
* @param string path to cache directory
* @return self
* @throws \RuntimeException if cache dir is not writable
*/
public function setCacheDir($dir)
{
$dir = $dir . DIRECTORY_SEPARATOR . 'AliasExpander';
$valid = TRUE;
if (!is_dir($dir)) {
@mkdir($dir);
$err = error_get_last();
if (!is_dir($dir)) {
throw new \RuntimeException("Cannot create cache directory '$dir': $err[message]");
}
set_error_handler(function($severity, $message) use ($dir, &$valid) {
restore_error_handler();
return $valid = is_dir($dir);
});
mkdir($dir);
restore_error_handler();
}

if ($valid) {
$this->cacheDir = $dir;
}
$this->cacheDir = $dir;
return $this;
}

Expand Down

0 comments on commit b9ac4b3

Please sign in to comment.