Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function read($id, $key, &$lockContext)
 {
     $path = new Path($this->getPath($id, $key));
     if (!$path->exists()) {
         return null;
     }
     $file = $this->openFile($id, $key);
     $file->lock($lockContext);
     $data = $file->read();
     if ($lockContext) {
         // Keep the file locked and store the file object.
         $lockContext = $file;
     } else {
         // Unlock immediately and discard the file object.
         $file->unlock();
     }
     return $data;
 }
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);
 }