예제 #1
0
파일: Parser.php 프로젝트: uqiauto/fusio
 /**
  * Parses and resolves the json schema source and returns the object
  * presentation of the schema
  *
  * @param string $source
  */
 public function parse($source)
 {
     $resolver = new RefResolver();
     if ($this->connection !== null) {
         $resolver->addResolver('schema', new Resolver($this->connection));
     }
     $parser = new JsonSchema(null, $resolver);
     $schema = $parser->parse($source);
     if (!$schema->getDefinition() instanceof Property\ComplexType) {
         throw new RuntimeException('Schema must be an object');
     }
     return serialize($schema);
 }
예제 #2
0
 public function onKernelResponse(FilterResponseEvent $event)
 {
     $controller = $event->getRequest()->attributes->get('_controller');
     if (empty($controller)) {
         return;
     }
     if (strpos($controller, '::') !== false) {
         $controller = explode('::', $controller, 2);
         $class = new \ReflectionClass($controller[0]);
         $method = $class->getMethod($controller[1]);
         $annotation = $this->reader->getMethodAnnotation($method, 'PSX\\PSXBundle\\Configuration\\Outgoing');
         $response = $event->getResponse();
         $writer = $this->getWriter($event->getRequest());
         if ($response instanceof DataResponse) {
             if ($annotation instanceof Outgoing) {
                 $file = $this->rootDir . '/' . $annotation->getFile();
                 $data = $this->assimilator->assimilate(JsonSchema::fromFile($file), $response->getData());
                 $response->headers->set('Content-Type', $writer->getContentType());
                 $response->setContent($writer->write($data));
             } else {
                 $data = $this->normalizeData($response->getData());
                 $response->headers->set('Content-Type', $writer->getContentType());
                 $response->setContent($writer->write($data));
             }
         } else {
             throw new RuntimeException('Can only transform responses of PSX\\PSXBundle\\DataResponse');
         }
     }
 }
예제 #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $schema = Parser\JsonSchema::fromFile($input->getArgument('file'));
     switch ($input->getArgument('format')) {
         case 'serialize':
             $output->write(serialize($schema));
             break;
         case 'php':
         default:
             $output->write(var_export($schema, true));
             break;
     }
 }
예제 #4
0
 public function onKernelController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     if (!is_array($controller)) {
         return;
     }
     $object = new \ReflectionObject($controller[0]);
     $method = $object->getMethod($controller[1]);
     $annotation = $this->reader->getMethodAnnotation($method, 'PSX\\PSXBundle\\Configuration\\Incoming');
     if ($annotation instanceof Incoming) {
         $file = $this->rootDir . '/' . $annotation->getFile();
         $request = $event->getRequest();
         $message = new Message($request->server->getHeaders(), $request->getContent());
         $data = $this->importer->import(JsonSchema::fromFile($file), $message);
         $request->attributes->set(Context::REQUEST_BODY, $data);
     }
 }
예제 #5
0
 /**
  * @expectedException \RuntimeException
  */
 public function testParseInvalidSchemaRef()
 {
     JsonSchema::fromFile(__DIR__ . '/unknown_protocol_ref_schema.json');
 }
예제 #6
0
파일: Raml.php 프로젝트: seytar/psx
 protected function parseSchema($schema)
 {
     if (is_string($schema)) {
         if (substr($schema, 0, 8) == '!include') {
             $file = trim(substr($schema, 8));
             if (!is_file($file)) {
                 $file = $this->basePath . '/' . $file;
             }
             return JsonSchema::fromFile($file);
         } else {
             $parser = new JsonSchema($this->basePath);
             return $parser->parse($schema);
         }
     } else {
         throw new RuntimeException('Schema definition must be a string');
     }
 }