fix api/v3 api_version

This commit is contained in:
aynsix
2019-12-06 14:24:03 +04:00
parent 2fd5b6cba2
commit f475a5c925
3 changed files with 13 additions and 7 deletions

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\Controller\Api;
use Alchemy\Phrasea\ControllerProvider\Api\V1;
use Alchemy\Phrasea\ControllerProvider\Api\V3;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -268,11 +269,13 @@ class Result
public function getVersion()
{
if (null === $this->version) {
if($this->request->attributes->get('api_version')){
if ($this->request->attributes->get('api_version')) {
$this->version = $this->request->attributes->get('api_version');
}elseif(mb_strpos($this->request->getPathInfo(), '/api/v1') !== FALSE){
} elseif (mb_strpos($this->request->getPathInfo(), '/api/v1') !== FALSE) {
$this->version = V1::VERSION;
}else{
} elseif (mb_strpos($this->request->getPathInfo(), '/api/v3') !== FALSE) {
$this->version = V3::VERSION;
} else {
$this->version = self::$defaultVersion;
}
}

View File

@@ -12,7 +12,7 @@ use Silex\ServiceProviderInterface;
class V3 extends Api implements ControllerProviderInterface, ServiceProviderInterface
{
const VERSION = '2.0.0';
const VERSION = '3.0.0';
public function register(Application $app)
{

View File

@@ -15,6 +15,7 @@ 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\ControllerProvider\Api\V3;
use Alchemy\Phrasea\Core\Configuration\PropertyAccess;
use Alchemy\Phrasea\Core\Event\ApiOAuth2EndEvent;
use Alchemy\Phrasea\Core\Event\ApiOAuth2StartEvent;
@@ -76,11 +77,13 @@ class OAuthListener
// Sets the Api Version
$CalledController = $request->attributes->get('_controller');
if(mb_strpos($CalledController, 'controller.api.v1') !== FALSE){
if (mb_strpos($CalledController, 'controller.api.v1') !== FALSE) {
$request->attributes->set('api_version', V1::VERSION);
}elseif(mb_strpos($CalledController, 'controller.api.v2') !== FALSE){
} elseif(mb_strpos($CalledController, 'controller.api.v2') !== FALSE) {
$request->attributes->set('api_version', V2::VERSION);
}else{
} elseif(mb_strpos($CalledController, 'controller.api.v3') !== FALSE) {
$request->attributes->set('api_version', V3::VERSION);
} else {
$request->attributes->set('api_version', $oAuth2Account->getApiVersion());
}