Ejemplo n.º 1
0
 /**
  * @param string                    $baseUrl
  * @param array                     $definitions
  * @param array                     $listeners
  * @param HttpAdapterInterface|null $adapter
  * @param Router|null               $router
  * @return self
  */
 public static function createEndpoint($baseUrl, array $definitions, array $listeners = array(), HttpAdapterInterface $adapter = null, Router $router = null)
 {
     if (!$adapter) {
         $adapter = new GuzzleHttpAdapter(new Client());
     }
     if (!$router) {
         $router = new Router();
     }
     if (!count($listeners)) {
         $serializerAdapter = new SymfonySerializerAdapter(new Serializer([], [new JsonEncoder()]));
         $serializerAdapter->addContentType('application/json', 'json');
         $listeners[Endpoint::LISTENER_AFTER_RESPONSE] = new ContentTypeListenener($serializerAdapter);
         $listeners[Endpoint::LISTENER_AFTER_DATA] = new ReflectionHydratorListener();
     }
     $endpoint = new Endpoint($adapter, $router, $baseUrl);
     foreach ($listeners as $evt => $listener) {
         $endpoint->addListener($evt, $listener);
     }
     $driver = new AnnotationDriver();
     foreach ($definitions as $interfaceName) {
         $resources = $driver->createDefinitions($interfaceName);
         foreach ($resources as $resource) {
             $endpoint->addResourceDefinition($resource);
         }
     }
     return $endpoint;
 }
Ejemplo n.º 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $driver = new AnnotationDriver();
     $definitions = $driver->createDefinitions(GithubApi::class);
     $adapter = new GuzzleHttpAdapter(new Client());
     $endpoint = new Endpoint($adapter, new Router(), 'http://api.github.com');
     foreach ($definitions as $definition) {
         $endpoint->addResourceDefinition($definition);
     }
     $serializerAdapter = new SymfonySerializerAdapter(new Serializer([], [new JsonEncoder()]));
     $serializerAdapter->addContentType('application/json', 'json');
     $endpoint->addListener(Endpoint::LISTENER_AFTER_RESPONSE, new ContentTypeListenener($serializerAdapter));
     $endpoint->addListener(Endpoint::LISTENER_AFTER_DATA, new ReflectionHydratorListener());
     /** @var GithubApi $endpoint */
     $result = $endpoint->listRepos($input->getArgument('username'));
     var_dump($result);
 }
Ejemplo n.º 3
0
 /**
  * @test
  * @expectedException \Kix\Apiranha\Exception\InvalidResourceDefinitionException
  */
 public function it_throws_for_bad_parameter_property_paths()
 {
     $driver = new AnnotationDriver();
     $definitions = $driver->createDefinitions(BrokenResource::class);
 }