mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 09:53:15 +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;
|
||||
|
||||
use Alchemy\Phrasea\ControllerProvider\Api\V1;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
@@ -267,7 +268,13 @@ class Result
|
||||
public function getVersion()
|
||||
{
|
||||
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;
|
||||
|
@@ -13,6 +13,8 @@ use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Authentication\Authenticator;
|
||||
use Alchemy\Phrasea\Authentication\Context;
|
||||
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\Event\ApiOAuth2EndEvent;
|
||||
use Alchemy\Phrasea\Core\Event\ApiOAuth2StartEvent;
|
||||
@@ -72,7 +74,16 @@ class OAuthListener
|
||||
|
||||
$oAuth2Account = $token->getAccount();
|
||||
// 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();
|
||||
|
||||
/** @var PropertyAccess $conf */
|
||||
|
Reference in New Issue
Block a user