Add catalyst api bundle and test controller #164
This commit is contained in:
parent
df534dfe91
commit
2b9499861b
10 changed files with 931 additions and 396 deletions
7
catalyst/api-bundle/Controller/APIController.php
Normal file
7
catalyst/api-bundle/Controller/APIController.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Catalyst\APIBundle\Controller;
|
||||
|
||||
interface APIController
|
||||
{
|
||||
}
|
||||
69
catalyst/api-bundle/EventSubscriber/TokenSubscriber.php
Normal file
69
catalyst/api-bundle/EventSubscriber/TokenSubscriber.php
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace Catalyst\APIBundle\EventSubscriber;
|
||||
|
||||
use Catalyst\APIBundle\Controller\APIController;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
class TokenSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
const HEADER_API_KEY = 'X-Catalyst-API-Key';
|
||||
const HEADER_SIGNATURE = 'X-Catalyst-Signature';
|
||||
|
||||
const MODE_HEADER = 'header';
|
||||
const MODE_QUERY_STRING = 'query';
|
||||
|
||||
protected $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this-> em = $em;
|
||||
}
|
||||
|
||||
public function onKernelController(FilterControllerEvent $event)
|
||||
{
|
||||
$controller = $event->getController();
|
||||
|
||||
// not a controller class? (docs said to handle)
|
||||
if (!is_array($controller))
|
||||
return;
|
||||
|
||||
|
||||
// not an api controller
|
||||
if (!($controller[0] instanceof APIController))
|
||||
return;
|
||||
|
||||
// TODO: check if we have a mode setup
|
||||
|
||||
// TODO: if no mode specified default to header
|
||||
|
||||
$req = $event->getRequest();
|
||||
|
||||
// api key header
|
||||
$api_key = $req->headers->get(self::HEADER_API_KEY);
|
||||
if ($api_key == null)
|
||||
throw new AccessDeniedHttpException('No api key sent.');
|
||||
|
||||
// TODO: check valid api key
|
||||
|
||||
// signature header
|
||||
$sig = $req->header->get(self::HEADER_SIGNATURE);
|
||||
if ($sig == null)
|
||||
throw new AccessDeniedHttpException('No signature sent.');
|
||||
|
||||
// TODO: check valid signature
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
KernelEvents::CONTROLLER => 'onKernelController',
|
||||
];
|
||||
}
|
||||
}
|
||||
9
catalyst/api-bundle/Library/Response.php
Normal file
9
catalyst/api-bundle/Library/Response.php
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Catalyst\APIBundle\Library;
|
||||
|
||||
class Response
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -38,7 +38,8 @@
|
|||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "src/",
|
||||
"Catalyst\\": "catalyst-libs/"
|
||||
"Catalyst\\": "catalyst-libs/",
|
||||
"Catalyst\\APIBundle\\": "catalyst/api-bundle/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
|
|
|
|||
1185
composer.lock
generated
1185
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -27,6 +27,10 @@ security:
|
|||
pattern: ^\/rapi\/
|
||||
security: false
|
||||
|
||||
warranty_api:
|
||||
pattern: ^\/capi\/
|
||||
security: false
|
||||
|
||||
main:
|
||||
form_login:
|
||||
login_path: login
|
||||
|
|
|
|||
6
config/routes/api_test.yaml
Normal file
6
config/routes/api_test.yaml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# api test
|
||||
|
||||
api_test_test:
|
||||
path: /capi/test
|
||||
controller: App\Controller\APITestController::test
|
||||
|
||||
|
|
@ -75,3 +75,9 @@ services:
|
|||
arguments:
|
||||
$ip_address: "%env(APNS_REDIS_IP_ADDRESS)%"
|
||||
$port: "%env(APNS_REDIS_PORT)%"
|
||||
|
||||
Catalyst\APIBundle\EventSubscriber\TokenSubscriber:
|
||||
arguments:
|
||||
$em: "@doctrine.orm.entity_manager"
|
||||
tags: ['kernel.event_subscriber']
|
||||
|
||||
|
|
|
|||
23
src/Controller/APITestController.php
Normal file
23
src/Controller/APITestController.php
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Ramcar\BaseController;
|
||||
use App\Entity\VehicleManufacturer;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
||||
use App\Menu\Generator as MenuGenerator;
|
||||
use App\Access\Generator as ACLGenerator;
|
||||
|
||||
use Catalyst\APIBundle\Controller\APIController;
|
||||
|
||||
class APITestController extends BaseController implements APIController
|
||||
{
|
||||
public function test()
|
||||
{
|
||||
}
|
||||
}
|
||||
15
symfony.lock
15
symfony.lock
|
|
@ -56,6 +56,9 @@
|
|||
"ref": "c1431086fec31f17fbcfe6d6d7e92059458facc1"
|
||||
}
|
||||
},
|
||||
"doctrine/event-manager": {
|
||||
"version": "v1.0.0"
|
||||
},
|
||||
"doctrine/inflector": {
|
||||
"version": "v1.2.0"
|
||||
},
|
||||
|
|
@ -71,6 +74,12 @@
|
|||
"doctrine/orm": {
|
||||
"version": "v2.6.0"
|
||||
},
|
||||
"doctrine/persistence": {
|
||||
"version": "v1.0.1"
|
||||
},
|
||||
"doctrine/reflection": {
|
||||
"version": "v1.0.0"
|
||||
},
|
||||
"guzzlehttp/guzzle": {
|
||||
"version": "6.3.0"
|
||||
},
|
||||
|
|
@ -83,6 +92,9 @@
|
|||
"jdorn/sql-formatter": {
|
||||
"version": "v1.2.17"
|
||||
},
|
||||
"nikic/php-parser": {
|
||||
"version": "v4.1.0"
|
||||
},
|
||||
"ocramius/package-versions": {
|
||||
"version": "1.2.0"
|
||||
},
|
||||
|
|
@ -197,6 +209,9 @@
|
|||
"symfony/orm-pack": {
|
||||
"version": "v1.0.5"
|
||||
},
|
||||
"symfony/polyfill-ctype": {
|
||||
"version": "v1.9.0"
|
||||
},
|
||||
"symfony/polyfill-mbstring": {
|
||||
"version": "v1.6.0"
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue