<?php
/**
* Created by PhpStorm.
* User: Islam
* Date: 27/11/2016
* Time: 11:41 م
*/
namespace Rawafed\CommonsBundle\Service;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\KernelInterface;
class ContentApiAccessRestriction
{
private $kernel;
public function __construct(KernelInterface $kernel)
{
$this->kernel = $kernel;
}
public function onKernelRequest(GetResponseEvent $event)
{
if(!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
if(strpos($request->getUri(), '/api/')) {
if(!in_array('ContentApiBundle', array_keys($this->kernel->getBundles()))) {
throw new NotFoundHttpException('Not found');
}
}
}
}