
| Current Path : /var/www/html/vendor/chi-teck/drupal-code-generator/src/Command/Service/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/vendor/chi-teck/drupal-code-generator/src/Command/Service/CacheContext.php |
<?php declare(strict_types=1);
namespace DrupalCodeGenerator\Command\Service;
use DrupalCodeGenerator\Application;
use DrupalCodeGenerator\Command\ModuleGenerator;
/**
* Implements service:cache-context command.
*/
final class CacheContext extends ModuleGenerator {
protected string $name = 'service:cache-context';
protected string $description = 'Generates a cache context service';
protected string $alias = 'cache-context';
protected string $templatePath = Application::TEMPLATE_PATH . '/service/cache-context';
/**
* {@inheritdoc}
*/
protected function generate(array &$vars): void {
$this->collectDefault($vars);
$vars['context_id'] = $this->ask('Context ID', 'example');
$vars['class'] = $this->ask('Class', '{context_id|camelize}CacheContext');
$base_class_choices = [
'-',
'RequestStackCacheContextBase',
'UserCacheContextBase',
];
$vars['base_class'] = $this->io->choice('Base class', $base_class_choices);
if ($vars['base_class'] == '-') {
$vars['base_class'] = FALSE;
}
$vars['calculated'] = $this->confirm('Make the context calculated?', FALSE);
$vars['context_label'] = '{context_id|m2h}';
$vars['interface'] = $vars['calculated'] ?
'CalculatedCacheContextInterface' : 'CacheContextInterface';
$this->addFile('src/Cache/Context/{class}.php', 'cache-context');
$this->addServicesFile()->template('services');
}
}