123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- <?php
- declare(strict_types=1);
- namespace Fgm\Drupal\Composer;
- use Composer\Package\PackageInterface;
- use Symfony\Component\Console\Input\InputArgument;
- use Symfony\Component\Console\Input\InputDefinition;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- class PhpMemcacheAdminConfigCommand extends BaseBuilderCommand {
-
- const BUILD_NAME = 'phpmemcacheadmin';
-
- const PACKAGE = 'elijaa/phpmemcacheadmin';
-
- const TARGET = 'Config/Memcache.php';
-
- protected $eventName;
-
- public function configure() {
- parent::configure();
- $this->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(
- <<<EOT
- The build:phpmemcacheadmin command uses the memcache section of the site parameters
- to build the vendor/elijaa/phpmemcacheamin/Config/Memcache.php file.
- EOT
- );
- }
-
- public function execute(InputInterface $input, OutputInterface $output): int {
- [
- $wrapper,
- $params,
- $msg,
- $err,
- ] = $this->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;
- }
-
- 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;
- }
-
- 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;
- }
- }
|