Beispiel #1
0
 /**
  * Class constructor.
  *
  * @param string $path The file path.
  * @param string $mode The open mode. See the documentation for fopen() for available modes.
  *
  * @throws FileSystemException If the file cannot be open.
  */
 public function __construct($path, $mode)
 {
     $this->errorHandler = new ErrorCatcher(function (\ErrorException $e) {
         if ($this->throw) {
             throw FileSystemException::wrap($e);
         }
     });
     $this->throw = true;
     $this->errorHandler->swallow(E_WARNING, function () use($path, $mode) {
         $this->handle = fopen($path, $mode);
     });
 }
Beispiel #2
0
 /**
  * @param integer  $severity The severity of the errors to catch.
  * @param boolean  $throw    Whether to throw exceptions or silently ignore errors.
  * @param callable $function The function to call.
  *
  * @return mixed The return value of the called function.
  *
  * @throws FileSystemException If an error is caught and $throw is true.
  */
 private function swallow($severity, $throw, callable $function)
 {
     if (Path::$errorHandler === null) {
         Path::$errorHandler = new ErrorCatcher(function (\ErrorException $e) {
             if (Path::$throw) {
                 throw FileSystemException::wrap($e);
             }
         });
     }
     Path::$throw = $throw;
     return Path::$errorHandler->swallow($severity, $function);
 }
Beispiel #3
0
 /**
  * Returns the current working directory.
  *
  * @return string
  *
  * @throws FileSystemException If an error occurs.
  */
 public function getWorkingDirectory()
 {
     $path = getcwd();
     if ($path === false) {
         throw FileSystemException::cannotGetWorkingDirectory();
     }
     return $path;
 }