diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index d5f211b..ea83cad 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -51,14 +51,14 @@ protected function addPaths(ArrayNodeDefinition $node) ->arrayNode('paths') ->addDefaultsIfNotSet() ->children() - ->scalarNode('workspace_directory')->defaultValue('%kernel.root_dir%/supervisor/%kernel.environment%/')->end() - ->scalarNode('configuration_file')->defaultValue('%kernel.root_dir%/supervisor/%kernel.environment%/supervisord.conf')->end() - ->scalarNode('pid_file')->defaultValue('%kernel.root_dir%/supervisor/%kernel.environment%/supervisor.pid')->end() - ->scalarNode('sock_file')->defaultValue('%kernel.root_dir%/supervisor/%kernel.environment%/supervisor.sock')->end() - ->scalarNode('log_file')->defaultValue('%kernel.root_dir%/supervisor/%kernel.environment%/supervisord.log')->end() - ->scalarNode('worker_configuration_directory')->defaultValue('%kernel.root_dir%/supervisor/%kernel.environment%/worker/')->end() - ->scalarNode('worker_output_log_file')->defaultValue('%kernel.root_dir%/supervisor/%kernel.environment%/logs/stdout.log')->end() - ->scalarNode('worker_error_log_file')->defaultValue('%kernel.root_dir%/supervisor/%kernel.environment%/logs/stderr.log')->end() + ->scalarNode('workspace_directory')->defaultValue('%phobetor_rabbitmq_supervisor.project_dir%/supervisor/%kernel.environment%/')->end() + ->scalarNode('configuration_file')->defaultValue('%phobetor_rabbitmq_supervisor.project_dir%/supervisor/%kernel.environment%/supervisord.conf')->end() + ->scalarNode('pid_file')->defaultValue('%phobetor_rabbitmq_supervisor.project_dir%/supervisor/%kernel.environment%/supervisor.pid')->end() + ->scalarNode('sock_file')->defaultValue('%phobetor_rabbitmq_supervisor.project_dir%/supervisor/%kernel.environment%/supervisor.sock')->end() + ->scalarNode('log_file')->defaultValue('%phobetor_rabbitmq_supervisor.project_dir%/supervisor/%kernel.environment%/supervisord.log')->end() + ->scalarNode('worker_configuration_directory')->defaultValue('%phobetor_rabbitmq_supervisor.project_dir%/supervisor/%kernel.environment%/worker/')->end() + ->scalarNode('worker_output_log_file')->defaultValue('%phobetor_rabbitmq_supervisor.project_dir%/supervisor/%kernel.environment%/logs/stdout.log')->end() + ->scalarNode('worker_error_log_file')->defaultValue('%phobetor_rabbitmq_supervisor.project_dir%/supervisor/%kernel.environment%/logs/stderr.log')->end() ->scalarNode('php_executable')->defaultValue('php')->end() ->end() ->end() diff --git a/DependencyInjection/RabbitMqSupervisorExtension.php b/DependencyInjection/RabbitMqSupervisorExtension.php index 88b5fb2..1d93243 100644 --- a/DependencyInjection/RabbitMqSupervisorExtension.php +++ b/DependencyInjection/RabbitMqSupervisorExtension.php @@ -19,6 +19,12 @@ class RabbitMqSupervisorExtension extends Extension implements PrependExtensionI */ public function load(array $configs, ContainerBuilder $container) { + if ($container->hasParameter('kernel.root_dir')) { + $container->setParameter('phobetor_rabbitmq_supervisor.project_dir', '%kernel.root_dir%/..'); + } else { + $container->setParameter('phobetor_rabbitmq_supervisor.project_dir', '%kernel.project_dir%'); + } + $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); diff --git a/README.md b/README.md index f6dab7f..32d96fa 100644 --- a/README.md +++ b/README.md @@ -72,10 +72,8 @@ supervisor/ ├── queue3.conf └── queue4.conf ``` -In symfony 2 and 3 this will be placed inside your `app/` directory. -Caution with symfony 4: to not have this inside of your `src/` directory you need to set the paths to suit your needs. -E. g. to use the standard structure inside of the `var/` directory, use this: +If you want to use the standard structure inside of the `var/` directory, change the configuration like this: ```yml rabbit_mq_supervisor: paths: diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 1374d6b..e7ad7ce 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -16,7 +16,7 @@ services: - "%phobetor_rabbitmq_supervisor.rpc_servers%" - "%phobetor_rabbitmq_supervisor.config%" - "%phobetor_rabbitmq_supervisor.sock_file_permissions%" - - "%kernel.root_dir%" + - "%phobetor_rabbitmq_supervisor.project_dir%" - "%kernel.environment%" phobetor_rabbitmq_supervisor.supervisor_service: diff --git a/Services/RabbitMqSupervisor.php b/Services/RabbitMqSupervisor.php index 636a038..3a10ac4 100644 --- a/Services/RabbitMqSupervisor.php +++ b/Services/RabbitMqSupervisor.php @@ -52,7 +52,7 @@ class RabbitMqSupervisor /** * @var string */ - private $rootDir; + private $projectDir; /** * @var string @@ -76,10 +76,10 @@ class RabbitMqSupervisor * @param array $rpcServers * @param array $config * @param $sockFilePermissions - * @param string $kernelRootDir + * @param string $projectDir * @param string $environment */ - public function __construct(Supervisor $supervisor, array $paths, array $commands, $consumers, $multipleConsumers, $batchConsumers, $rpcServers, $config, $sockFilePermissions, $kernelRootDir, $environment) + public function __construct(Supervisor $supervisor, array $paths, array $commands, $consumers, $multipleConsumers, $batchConsumers, $rpcServers, $config, $sockFilePermissions, $projectDir, $environment) { $this->supervisor = $supervisor; $this->paths = $paths; @@ -90,7 +90,7 @@ public function __construct(Supervisor $supervisor, array $paths, array $command $this->rpcServers = $rpcServers; $this->config = $config; $this->sockFilePermissions = $sockFilePermissions; - $this->rootDir = dirname($kernelRootDir); + $this->projectDir = $projectDir; $this->environment = $environment; } @@ -328,7 +328,7 @@ private function generateWorkerConfigurations($names, $baseCommand) // try different possible console paths (realpath() will throw away the not existing ones) $consolePaths = []; foreach (['bin', 'app'] as $consoleDirectory) { - $consolePath = sprintf('%s/%s/console', $this->rootDir, $consoleDirectory); + $consolePath = sprintf('%s/%s/console', $this->projectDir, $consoleDirectory); if (!empty(realpath($consolePath))) { $consolePaths[] = $consolePath; } @@ -336,7 +336,7 @@ private function generateWorkerConfigurations($names, $baseCommand) // fall back to standard console path if none of the paths was valid if (empty($consolePaths)) { - $consolePaths[] = sprintf('%s/%s/console', $this->rootDir, 'bin'); + $consolePaths[] = sprintf('%s/%s/console', $this->projectDir, 'bin'); } $executablePath = $consolePaths[0];