isAbstract()) { continue; } $classes[] = $reflection->getName(); } return $classes; } /** * Ensures the gateway names are unique for each gateway. * * @param array $gatewayClasses Fully-qualified Gateway class names * * @throws \Exception If there are two different Gateway classes with the same name * * @see \App\Library\Economy\Payment\GatewayInterface::getName() To see the names returned by the implementations */ public static function validateGatewayNames(array $gatewayClasses): void { $gatewaysValidated = []; foreach ($gatewayClasses as $gatewayClass) { $gatewayName = $gatewayClass::getName(); if (\array_key_exists($gatewayName, $gatewaysValidated)) { $exceptionMessage = sprintf( "Duplicate Gateway name '%s' from class %s, name is already in use by class %s", $gatewayName, $gatewayClass, $gatewaysValidated[$gatewayName] ); throw new \Exception($exceptionMessage); } $gatewaysValidated[$gatewayName] = $gatewayClass; } } /** * Stores the gateway names in disk. * * @param array $names The names returned by the gateways * * @see \App\Library\Economy\Payment\GatewayInterface::getName() To see the names returned by the implementations */ public static function compileGatewayNames(array $names): void { self::writeLockFile($names); } public function process(ContainerBuilder $container): void { $classesDir = join(DIRECTORY_SEPARATOR, [ $container->getParameter('kernel.project_dir'), 'src', ...\array_slice(explode('\\', self::getGatewaysNamespace()), 1), ]); $gatewayClasses = self::getGatewayClasses($classesDir); self::validateGatewayNames($gatewayClasses); $gatewayNames = $this->getGatewayNames($gatewayClasses); self::compileGatewayNames($gatewayNames); } }