eventName = $this->getName(); $this ->setName('build:phpmemcacheadmin') ->setDescription('Build the PhpMemcacheAdmin configuration.') ->setDefinition( new InputDefinition([ new InputArgument(static::ARG_FILE, InputArgument::OPTIONAL, '', static::BUILD_NAME), ]) ) ->setHelp( <<prepare($input, $output, static::BUILD_NAME); if ($err != 0) { $output->writeln($msg); return $err; } $context = $this->buildConfig($wrapper, $params); $target = $this->getTarget(); echo "Generating $target\n"; [$msg, $error] = $this->render($wrapper, $context, $target); if ($error) { $output->writeln(sprintf("Failed rendering doc configuration: %s", $msg)); return 5; } return 0; } /** * Render the config from params.local.yml and the template. * * @param \Twig_TemplateWrapper $template * The template used to format the parameters. * @param array $params * The parameters loaded from the local params file. * * @return array * An array made of the relevant parameters. */ protected function buildConfig(\Twig_TemplateWrapper $template, array $params) { $params[static::BUILD_NAME]['basic']['file_path'] = realpath($params[static::BUILD_NAME]['basic']['file_path']); $variables = array_merge( $params[static::BUILD_NAME]['basic'], $params[static::BUILD_NAME]['advanced'], [ 'servers' => $params['memcache']['servers'], ], ['local_params_path' => realpath($this->getSettingsPath() . "/params.local.yml")] ); return $variables; } /** * Get the actual path where the configuration file needs to be generated. * * @return string * The path. */ protected function getTarget(): string { $composer = $this->getComposer(); $packages = $composer ->getRepositoryManager() ->getLocalRepository() ->getPackages(); $package = current(array_filter($packages, function (PackageInterface $package) { return $package->getName() === static::PACKAGE; })); $targetBase = $composer ->getInstallationManager() ->getInstallPath($package); $target = "{$targetBase}/" . static::TARGET; return $target; } }