Optimized language routing

This commit is contained in:
Kevin Frantz 2019-01-05 18:39:32 +01:00
parent 36f8e597f7
commit edc8a941af
3 changed files with 19 additions and 12 deletions

View File

@ -2,9 +2,11 @@
namespace App\Controller\API;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
/**
* @author kevinfrantz
*/
abstract class AbstractAPIController implements APIControllerInterface
abstract class AbstractAPIController extends Controller implements APIControllerInterface
{
}

View File

@ -13,7 +13,7 @@ use App\Controller\API\AbstractAPIController;
class SourceApiController extends AbstractAPIController
{
/**
* @Route("/api/{_locale}/source/{identifier}.{_format}",
* @Route("/{_locale}/api/source/{identifier}.{_format}",
* defaults={"_format"="json"} ,
* methods={"GET"}
* )
@ -26,7 +26,7 @@ class SourceApiController extends AbstractAPIController
}
/**
* @Route("/api/{_locale}/source/.{_format}",
* @Route("/{_locale}/api/source.{_format}",
* defaults={"_format"="json"} ,
* methods={"POST"}
* )
@ -39,7 +39,7 @@ class SourceApiController extends AbstractAPIController
}
/**
* @Route("/api/{_locale}/source/{identifier}.{_format}",
* @Route("/{_locale}/api/source/{identifier}.{_format}",
* defaults={"_format"="json"} ,
* methods={"PUT"}
* )
@ -52,7 +52,7 @@ class SourceApiController extends AbstractAPIController
}
/**
* @Route("/api/{_locale}/sources/.{_format}",
* @Route("/{_locale}/api/sources/.{_format}",
* defaults={"_format"="json"} ,
* methods={"GET"}
* )
@ -65,7 +65,7 @@ class SourceApiController extends AbstractAPIController
}
/**
* @Route("/api/{_locale}/source/{identifier}.{_format}",
* @Route("/{_locale}/api/source/{identifier}.{_format}",
* defaults={"_format"="json"} ,
* methods={"DELETE"}
* )

View File

@ -42,11 +42,17 @@ class ApiUrlReachableIntegrationTest extends KernelTestCase
$this->language("$route/asdfg", $method);
}
/**
* @todo Implement routing without i18l part!
*
* @param string $entity
* @param string $method
*/
private function language(string $entity, string $method): void
{
$this->type('api/'.$entity, $method);
foreach (LanguageType::getChoices() as $key => $value) {
$this->type("api/$key/$entity", $method);
//$this->type('api/'.$entity, $method);
foreach (LanguageType::getChoices() as $language => $value) {
$this->type("$language/api/$entity", $method);
}
}
@ -62,10 +68,9 @@ class ApiUrlReachableIntegrationTest extends KernelTestCase
{
$request = new Request([], [], [], [], [], [
'REQUEST_URI' => $url,
'REQUEST_METHOD' => $method,
]);
$request->setMethod(Request::METHOD_GET);
$request->setMethod($method);
$response = static::$kernel->handle($request);
$this->assertNotEquals(404, $response->getStatusCode(), "Route $url sends an 404 response!");
$this->assertNotEquals(404, $response->getStatusCode(), "Route $url with Method $method sends an 404 response!");
}
}