mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
Merge pull request #2664 from aynsix/PHRAS-1993-API-answer-version
PHRAS-1993 API / API answer / the age of token define API version in answer
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\Controller\Api;
|
namespace Alchemy\Phrasea\Controller\Api;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\ControllerProvider\Api\V1;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
@@ -267,7 +268,13 @@ class Result
|
|||||||
public function getVersion()
|
public function getVersion()
|
||||||
{
|
{
|
||||||
if (null === $this->version) {
|
if (null === $this->version) {
|
||||||
$this->version = $this->request->attributes->get('api_version') ?: self::$defaultVersion;
|
if($this->request->attributes->get('api_version')){
|
||||||
|
$this->version = $this->request->attributes->get('api_version');
|
||||||
|
}elseif(mb_strpos($this->request->getPathInfo(), '/api/v1') !== FALSE){
|
||||||
|
$this->version = V1::VERSION;
|
||||||
|
}else{
|
||||||
|
$this->version = self::$defaultVersion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->version;
|
return $this->version;
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ use Alchemy\Phrasea\Application;
|
|||||||
use Alchemy\Phrasea\Authentication\Authenticator;
|
use Alchemy\Phrasea\Authentication\Authenticator;
|
||||||
use Alchemy\Phrasea\Authentication\Context;
|
use Alchemy\Phrasea\Authentication\Context;
|
||||||
use Alchemy\Phrasea\Controller\Api\Result;
|
use Alchemy\Phrasea\Controller\Api\Result;
|
||||||
|
use Alchemy\Phrasea\ControllerProvider\Api\V1;
|
||||||
|
use Alchemy\Phrasea\ControllerProvider\Api\V2;
|
||||||
use Alchemy\Phrasea\Core\Configuration\PropertyAccess;
|
use Alchemy\Phrasea\Core\Configuration\PropertyAccess;
|
||||||
use Alchemy\Phrasea\Core\Event\ApiOAuth2EndEvent;
|
use Alchemy\Phrasea\Core\Event\ApiOAuth2EndEvent;
|
||||||
use Alchemy\Phrasea\Core\Event\ApiOAuth2StartEvent;
|
use Alchemy\Phrasea\Core\Event\ApiOAuth2StartEvent;
|
||||||
@@ -72,7 +74,16 @@ class OAuthListener
|
|||||||
|
|
||||||
$oAuth2Account = $token->getAccount();
|
$oAuth2Account = $token->getAccount();
|
||||||
// Sets the Api Version
|
// Sets the Api Version
|
||||||
$request->attributes->set('api_version', $oAuth2Account->getApiVersion());
|
|
||||||
|
$CalledController = $request->attributes->get('_controller');
|
||||||
|
if(mb_strpos($CalledController, 'controller.api.v1') !== FALSE){
|
||||||
|
$request->attributes->set('api_version', V1::VERSION);
|
||||||
|
}elseif(mb_strpos($CalledController, 'controller.api.v2') !== FALSE){
|
||||||
|
$request->attributes->set('api_version', V2::VERSION);
|
||||||
|
}else{
|
||||||
|
$request->attributes->set('api_version', $oAuth2Account->getApiVersion());
|
||||||
|
}
|
||||||
|
|
||||||
$oAuth2App = $oAuth2Account->getApplication();
|
$oAuth2App = $oAuth2Account->getApplication();
|
||||||
|
|
||||||
/** @var PropertyAccess $conf */
|
/** @var PropertyAccess $conf */
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use Alchemy\Phrasea\Application;
|
|||||||
use Alchemy\Phrasea\Authentication\Context;
|
use Alchemy\Phrasea\Authentication\Context;
|
||||||
use Alchemy\Phrasea\Border\File;
|
use Alchemy\Phrasea\Border\File;
|
||||||
use Alchemy\Phrasea\Controller\Api\V1Controller;
|
use Alchemy\Phrasea\Controller\Api\V1Controller;
|
||||||
|
use Alchemy\Phrasea\ControllerProvider\Api\V1;
|
||||||
use Alchemy\Phrasea\ControllerProvider\Api\V2;
|
use Alchemy\Phrasea\ControllerProvider\Api\V2;
|
||||||
use Alchemy\Phrasea\Core\Configuration\PropertyAccess;
|
use Alchemy\Phrasea\Core\Configuration\PropertyAccess;
|
||||||
use Alchemy\Phrasea\Core\PhraseaEvents;
|
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||||
@@ -459,6 +460,10 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
|
|||||||
|
|
||||||
protected function evaluateMeta($content, $version = null)
|
protected function evaluateMeta($content, $version = null)
|
||||||
{
|
{
|
||||||
|
if(mb_strpos($content['meta']['request'], '/api/v1') !== FALSE){
|
||||||
|
$version = V1::VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
$this->assertTrue(is_array($content), 'La reponse est un objet');
|
$this->assertTrue(is_array($content), 'La reponse est un objet');
|
||||||
$this->assertArrayHasKey('meta', $content);
|
$this->assertArrayHasKey('meta', $content);
|
||||||
$this->assertArrayHasKey('response', $content);
|
$this->assertArrayHasKey('response', $content);
|
||||||
|
|||||||
Reference in New Issue
Block a user