5 * Contains \Drupal\Console\Generator\ServiceGenerator.
8 namespace Drupal\Console\Generator;
10 use Drupal\Console\Core\Generator\Generator;
11 use Drupal\Console\Extension\Manager;
13 class ServiceGenerator extends Generator
18 protected $extensionManager;
21 * AuthenticationProviderGenerator constructor.
23 * @param Manager $extensionManager
25 public function __construct(
26 Manager $extensionManager
28 $this->extensionManager = $extensionManager;
34 * @param string $module Module name
35 * @param string $name Service name
36 * @param string $class Class name
37 * @param string $interface If TRUE an interface for this service is generated
38 * @param array $services List of services
39 * @param string $path_service Path of services
41 public function generate($module, $name, $class, $interface, $interface_name, $services, $path_service)
43 $interface = $interface ? ($interface_name ?: $class . 'Interface') : false;
48 'class_path' => sprintf('Drupal\%s\%s', $module, $class),
49 'interface' => $interface,
50 'services' => $services,
51 'path_service' => $path_service,
52 'file_exists' => file_exists($this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml'),
56 'module/services.yml.twig',
57 $this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml',
63 'module/src/service.php.twig',
64 $this->setDirectory($path_service, 'service.php.twig', $module, $class),
70 'module/src/service-interface.php.twig',
71 $this->setDirectory($path_service, 'interface.php.twig', $module, $interface),
77 protected function setDirectory($target, $template, $module, $class)
79 $default_path = '/modules/custom/' . $module . '/src/';
83 case 'service.php.twig':
84 $default_target = $this->extensionManager->getModule($module)->getPath() .'/src/'.$class.'.php';
85 $custom_target = $this->extensionManager->getModule($module)->getPath() .'/'.$target.'/'.$class.'.php';
87 $directory = (strcmp($target, $default_path) == 0) ? $default_target : $custom_target;
89 case 'interface.php.twig':
90 $default_target = $this->extensionManager->getModule($module)->getPath() .'/src/'.$class.'.php';
91 $custom_target = $this->extensionManager->getModule($module)->getPath() .'/'.$target.'/'.$class.'.php';
93 $directory = (strcmp($target, $default_path) == 0) ? $default_target : $custom_target;