|
|
@@ -1,13 +1,20 @@
|
|
|
<?php
|
|
|
-namespace App\Service\Utils;
|
|
|
+declare(strict_types=1);
|
|
|
+
|
|
|
+namespace App\Service\Security;
|
|
|
|
|
|
use App\Entity\Organization\Organization;
|
|
|
+use App\Service\Utils\Reflection;
|
|
|
+use App\Test\Service\Security\ModuleTest;
|
|
|
use Doctrine\Common\Cache\ApcuCache;
|
|
|
use Symfony\Component\Config\FileLocator;
|
|
|
-use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
|
|
use Symfony\Component\Yaml\Yaml;
|
|
|
|
|
|
+/**
|
|
|
+ * Class Module : classe gérant la récupération de l'ensemble des modules possédées par une organisation
|
|
|
+ * @package App\Service\Security
|
|
|
+ */
|
|
|
class Module
|
|
|
{
|
|
|
const OPENTALENT_CONFIG = __DIR__.'/../../../config/opentalent';
|
|
|
@@ -18,55 +25,18 @@ class Module
|
|
|
/** @var array */
|
|
|
private $moduleByConditionsConfig;
|
|
|
|
|
|
- /** @var ContainerInterface */
|
|
|
- private $container;
|
|
|
+ /** @var Reflection */
|
|
|
+ private $reflection;
|
|
|
|
|
|
- public function __construct(ContainerInterface $container)
|
|
|
+ public function __construct(Reflection $reflection)
|
|
|
{
|
|
|
- $this->container = $container;
|
|
|
+ $this->reflection = $reflection;
|
|
|
$this->moduleConfig = $this->getModuleConfig();
|
|
|
$this->moduleByConditionsConfig = $this->getModuleByConditionsConfig();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Parse and return the products.yaml content
|
|
|
- * @return array
|
|
|
- */
|
|
|
- private function getModuleConfig(): array{
|
|
|
- $configDirectories = [self::OPENTALENT_CONFIG];
|
|
|
- $fileLocator = new FileLocator($configDirectories);
|
|
|
- $yamlConfig = $fileLocator->locate('products.yaml', null, false)[0];
|
|
|
- return Yaml::parseFile($yamlConfig);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Parse and return the modulesbyconditions.yaml content
|
|
|
- * @return array
|
|
|
- */
|
|
|
- private function getModuleByConditionsConfig(): array{
|
|
|
- $configDirectories = [self::OPENTALENT_CONFIG];
|
|
|
- $fileLocator = new FileLocator($configDirectories);
|
|
|
- $yamlConfig = $fileLocator->locate('modulesbyconditions.yaml', null, false)[0];
|
|
|
- return Yaml::parseFile($yamlConfig);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Get the module who enabled the access to the resource
|
|
|
- * @param string $resource
|
|
|
- * @return int|null|string
|
|
|
- */
|
|
|
- public function getModuleByResourceName(string $resource): ?string {
|
|
|
- $modules = $this->moduleConfig['opentalent']['modules'];
|
|
|
- foreach ($modules as $module => $data) {
|
|
|
- if ($data['entities'] && in_array($resource, $data['entities'], true)) {
|
|
|
- return $module;
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Get all the modules for one organization
|
|
|
+ * Récupère tous les modules de l'oganisation
|
|
|
* @param Organization $organization
|
|
|
* @return array
|
|
|
*/
|
|
|
@@ -93,9 +63,10 @@ class Module
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Get the module inside the organization's settings
|
|
|
+ * Récupère les modules disponibles dans les settings de l'organisation (Sms, Pes, etc)
|
|
|
* @param Organization $organization
|
|
|
* @return array
|
|
|
+ * @see ModuleTest::testGetModuleBySettings()
|
|
|
*/
|
|
|
public function getModuleBySettings(Organization $organization): array{
|
|
|
$moduleByOptions = [];
|
|
|
@@ -110,20 +81,22 @@ class Module
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Get the modules by conditions, thanks to the modulebyconditions.yaml file
|
|
|
+ * Récupère les modules par conditions, grace au fichier modulebyconditions.yaml
|
|
|
* @param Organization $organization
|
|
|
* @return array
|
|
|
+ * @see ModuleTest::testGetModulesByConditions()
|
|
|
*/
|
|
|
public function getModulesByConditions(Organization $organization): array {
|
|
|
$modulesByConditions = [];
|
|
|
-
|
|
|
+ return $modulesByConditions;
|
|
|
$modules = $this->moduleByConditionsConfig['opentalent']['modulesbyconditions'];
|
|
|
foreach ($modules as $moduleName => $module) {
|
|
|
try{
|
|
|
- $function = $this->container->get($module["conditions"]["service"]["name"]);
|
|
|
- $reflection = new \ReflectionClass(get_class($function));
|
|
|
- $method = $reflection->getMethod($module["conditions"]["service"]["function"]);
|
|
|
- $response = $method->invokeArgs($function, array($organization));
|
|
|
+ $response = $this->reflection->dynamicInvokeWithArgsServiceMethod(
|
|
|
+ $module["conditions"]["service"]["name"],
|
|
|
+ $module["conditions"]["service"]["function"],
|
|
|
+ array($organization)
|
|
|
+ );
|
|
|
if($response) {
|
|
|
$modulesByConditions[] = $moduleName;
|
|
|
}
|
|
|
@@ -134,9 +107,10 @@ class Module
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Get product configuration thanks to the products.yaml file
|
|
|
+ * Récupère les modules disponibles par produit grace au fichier products.yaml
|
|
|
* @param string $product
|
|
|
* @return array|null
|
|
|
+ * @see ModuleTest::testGetModulesByProductConfiguration()
|
|
|
*/
|
|
|
public function getModulesByProductConfiguration(string $product): ?array {
|
|
|
$product = str_replace('-', '_', $product);
|
|
|
@@ -154,4 +128,41 @@ class Module
|
|
|
|
|
|
return $modules;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Parse et retourne le contenu du fichier products.yaml
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ private function getModuleConfig(): array{
|
|
|
+ $configDirectories = [self::OPENTALENT_CONFIG];
|
|
|
+ $fileLocator = new FileLocator($configDirectories);
|
|
|
+ $yamlConfig = $fileLocator->locate('products.yaml', null, false)[0];
|
|
|
+ return Yaml::parseFile($yamlConfig);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Parse et retourne le contenu du fichier modulesbyconditions.yaml
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ private function getModuleByConditionsConfig(): array{
|
|
|
+ $configDirectories = [self::OPENTALENT_CONFIG];
|
|
|
+ $fileLocator = new FileLocator($configDirectories);
|
|
|
+ $yamlConfig = $fileLocator->locate('modulesbyconditions.yaml', null, false)[0];
|
|
|
+ return Yaml::parseFile($yamlConfig);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retourne le module possédant la resource passée en paramètre
|
|
|
+ * @param string $resource
|
|
|
+ * @return int|null|string
|
|
|
+ */
|
|
|
+ public function getModuleByResourceName(string $resource): ?string {
|
|
|
+ $modules = $this->moduleConfig['opentalent']['modules'];
|
|
|
+ foreach ($modules as $module => $data) {
|
|
|
+ if ($data['entities'] && in_array($resource, $data['entities'], true)) {
|
|
|
+ return $module;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|