Skip to content
Commits on Source (3)
......@@ -6,6 +6,9 @@ namespace Dbp\Relay\CoreBundle\Helpers;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* @deprecated Use Locale/Locale instead
*/
class Locale
{
public const LANGUAGE_OPTION = 'lang';
......
......@@ -13,8 +13,8 @@ class ApiConnection
{
public const API_URL_CONFIG_PARAMETER = 'api_url';
public const KEYCLOAK_SERVER_URL_CONFIG_PARAMETER = 'keycloak_server_url';
public const KEYCLOAK_REALM_CONFIG_PARAMETER = 'keycloak_realm';
public const OIDC_SERVER_URL_CONFIG_PARAMETER = 'oidc_server_url';
public const OIDC_REALM_CONFIG_PARAMETER = 'oidc_realm';
public const CLIENT_ID_CONFIG_PARAMETER = 'client_id';
public const CLIENT_SECRET_CONFIG_PARAMETER = 'client_secret';
......@@ -111,8 +111,8 @@ class ApiConnection
private function getAccessToken(): string
{
if ($this->accessToken === null) {
$idServerUrl = $this->config[self::KEYCLOAK_SERVER_URL_CONFIG_PARAMETER];
$idServerRealm = $this->config[self::KEYCLOAK_REALM_CONFIG_PARAMETER];
$idServerUrl = $this->config[self::OIDC_SERVER_URL_CONFIG_PARAMETER];
$idServerRealm = $this->config[self::OIDC_REALM_CONFIG_PARAMETER];
$clientId = $this->config[self::CLIENT_ID_CONFIG_PARAMETER];
$clientSecret = $this->config[self::CLIENT_SECRET_CONFIG_PARAMETER];
......
......@@ -74,7 +74,10 @@ class Locale
return $locale;
}
private static function setRequestLocaleFromQuery(Request $request, string $queryParam): void
/**
* Same as setCurrentRequestLocaleFromQuery(), but takes a request object.
*/
public static function setRequestLocaleFromQuery(Request $request, string $queryParam): void
{
if ($request->query->has($queryParam)) {
$lang = $request->query->get($queryParam);
......
......@@ -15,7 +15,7 @@ abstract class AbstractProxyDataEventSubscriber implements EventSubscriberInterf
public static function getSubscribedEvents(): array
{
return [
ProxyApi::PROXY_DATA_EVENT_NAME.static::NAMESPACE => 'onProxyDataEvent',
ProxyDataEvent::NAME.'.'.static::NAMESPACE => 'onProxyDataEvent',
];
}
......@@ -24,7 +24,7 @@ abstract class AbstractProxyDataEventSubscriber implements EventSubscriberInterf
*/
public function onProxyDataEvent(ProxyDataEvent $event): void
{
$event->setHandled();
$event->acknowledge();
$proxyData = $event->getProxyData();
$functionName = $proxyData->getFunctionName();
$arguments = $proxyData->getArguments();
......
......@@ -6,8 +6,6 @@ namespace Dbp\Relay\CoreBundle\ProxyApi;
class ProxyApi
{
public const PROXY_DATA_EVENT_NAME = '';
public const PROXY_DATA_RETURN_VALUE_KEY = 'data';
public const PROXY_DATA_ERRORS_KEY = 'errors';
}
......@@ -8,18 +8,18 @@ use Symfony\Contracts\EventDispatcher\Event;
class ProxyDataEvent extends Event
{
public const NAME = 'dbp.relay.proxy_bundle.proxy_data';
public const NAME = 'dbp.relay.core_bundle.proxy_data';
/** @var ProxyDataInterface */
private $proxyData;
/** @var bool */
private $wasHandled;
private $wasAcknowledged;
public function __construct(ProxyDataInterface $proxyData)
{
$this->proxyData = $proxyData;
$this->wasHandled = false;
$this->wasAcknowledged = false;
}
public function getProxyData(): ProxyDataInterface
......@@ -28,18 +28,18 @@ class ProxyDataEvent extends Event
}
/**
* Indicate, that the event was handled, e.g. there was an event subscriber for the requested proxy data namespace.
* Acknowledge the event, i.e. tell that there was an event subscriber responsible for the requested proxy data namespace.
*/
public function setHandled(): void
public function acknowledge(): void
{
$this->wasHandled = true;
$this->wasAcknowledged = true;
}
/**
* True, if the event was handled, e.g. there was an event subscriber for the requested proxy data namespace, false otherwise.
* True, if the event was acknowledged, e.g. there was an event subscriber responsible for the requested proxy data namespace, false otherwise.
*/
public function wasHandled(): bool
public function wasAcknowledged(): bool
{
return $this->wasHandled;
return $this->wasAcknowledged;
}
}
......@@ -22,11 +22,22 @@ class ProxyDataEventSubscriber extends AbstractProxyDataEventSubscriber
*/
private $provider;
/** @var bool */
private static $isCurrentlyActive = false;
public function __construct(AuthorizationDataProviderProvider $provider)
{
$this->provider = $provider;
}
/**
* Indicates, that the event subscriber is currently busy handling a proxy data event.
*/
public static function isCurrentlyActive(): bool
{
return self::$isCurrentlyActive;
}
protected function isFunctionDefined(string $functionName): bool
{
return
......@@ -46,18 +57,23 @@ class ProxyDataEventSubscriber extends AbstractProxyDataEventSubscriber
*/
protected function callFunction(string $functionName, array $arguments): ?array
{
$returnValue = null;
switch ($functionName) {
case self::GET_AVAILABLE_ATTRIBUTES_FUNCTION_NAME:
$returnValue = $this->getAvailableAttributes();
break;
case self::GET_USER_ATTRIBUTES_FUNCTION_NAME:
$returnValue = $this->getUserAttributes($arguments[self::USER_ID_PARAMETER_NAME]);
break;
try {
self::$isCurrentlyActive = true;
$returnValue = null;
switch ($functionName) {
case self::GET_AVAILABLE_ATTRIBUTES_FUNCTION_NAME:
$returnValue = $this->getAvailableAttributes();
break;
case self::GET_USER_ATTRIBUTES_FUNCTION_NAME:
$returnValue = $this->getUserAttributes($arguments[self::USER_ID_PARAMETER_NAME]);
break;
}
return $returnValue;
} finally {
self::$isCurrentlyActive = false;
}
return $returnValue;
}
private function getAvailableAttributes(): array
......
......@@ -101,6 +101,10 @@ services:
autowire: true
autoconfigure: true
Dbp\Relay\CoreBundle\ProxyApi\ProxyDataEventSubscriber:
autowire: true
autoconfigure: true
Dbp\Relay\CoreBundle\Locale\Locale:
autowire: true
autoconfigure: true
......@@ -39,4 +39,20 @@ class LocaleTest extends TestCase
$lang = $service->getCurrentPrimaryLanguage();
$this->assertSame('de', $lang);
}
public function testSetExplicit()
{
$stack = new RequestStack();
$params = new ParameterBag(['kernel.default_locale' => \Locale::acceptFromHttp('en')]);
$service = new Locale($stack, $params);
$request = new Request(['foo' => 'fr']);
$service->setRequestLocaleFromQuery($request, 'foo');
$stack->push($request);
$lang = $service->getCurrentPrimaryLanguage();
$this->assertSame('fr', $lang);
$stack->pop();
$lang = $service->getCurrentPrimaryLanguage();
$this->assertSame('en', $lang);
}
}