Skip to content

Commit

Permalink
fix: use project_dir if available (Symfony 3+)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanpoulain committed Apr 14, 2022
1 parent 403658f commit 682cf28
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
16 changes: 8 additions & 8 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions DependencyInjection/RabbitMqSupervisorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions Services/RabbitMqSupervisor.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class RabbitMqSupervisor
/**
* @var string
*/
private $rootDir;
private $projectDir;

/**
* @var string
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -328,15 +328,15 @@ 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;
}
}

// 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];
Expand Down

0 comments on commit 682cf28

Please sign in to comment.