示例#1
0
文件: Common.php 项目: brick/brick
 /**
  * Executes the given function and throws an exception if an error has occurred.
  *
  * @param \Closure $function The function to execute.
  *
  * @return mixed The value returned by the function.
  *
  * @throws JsonException If an error occurs.
  */
 protected function execute(\Closure $function)
 {
     $result = $this->errorHandler->swallow(E_ALL, $function);
     if (json_last_error() !== JSON_ERROR_NONE) {
         throw new JsonException(json_last_error_msg(), json_last_error());
     }
     return $result;
 }
示例#2
0
文件: File.php 项目: brick/brick
 /**
  * Forces the write of all buffered output to the file.
  *
  * @return void
  *
  * @throws FileSystemException If an error occurs.
  */
 public function flush()
 {
     $this->throw = true;
     $this->errorHandler->swallow(E_WARNING, function () {
         fflush($this->handle);
     });
 }
示例#3
0
 /**
  * Changes the current working directory.
  *
  * The current working directory is used to resolve relative paths.
  *
  * @param string $path The path to the new working directory.
  *
  * @return void
  *
  * @throws FileSystemException If the path is not a directory, or an error occurs.
  */
 public function changeWorkingDirectory($path)
 {
     $this->throw = true;
     $this->errorCatcher->swallow(E_WARNING, function () use($path) {
         chdir($path);
     });
 }
示例#4
0
文件: Path.php 项目: e-ruiz/brick
 /**
  * @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);
 }