Psr7Middlewares\Middleware\JsonValidator::fromFile PHP Method

fromFile() public static method

public static fromFile ( SplFileObject $file ) : static | callable
$file SplFileObject
return static | callable
    public static function fromFile(\SplFileObject $file)
    {
        $schema = (object) ['$ref' => $file->getPathname()];
        return new static($schema);
    }

Usage Example

 /**
  * Execute the middleware.
  *
  * @param ServerRequestInterface $request
  * @param ResponseInterface      $response
  * @param callable               $next
  *
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     $schema = $this->getSchema($request);
     if ($schema instanceof \SplFileObject) {
         $validator = JsonValidator::fromFile($schema);
         return $validator($request, $response, $next);
     }
     return $next($request, $response);
 }