3 namespace Drupal\Console\Composer\Plugin;
5 use Symfony\Component\Yaml\Yaml;
6 use Symfony\Component\Finder\Finder;
13 protected $configData = [];
18 protected $servicesData = [];
21 * ExtendExtensionManager constructor.
23 public function __construct()
29 * @param string $composerFile
33 public function isValidPackageType($composerFile)
35 if (!is_file($composerFile)) {
39 $composerContent = json_decode(file_get_contents($composerFile), true);
40 if (!$composerContent) {
44 if (!array_key_exists('type', $composerContent)) {
48 return $composerContent['type'] === 'drupal-console-library';
52 * @param string $configFile
54 public function addConfigFile($configFile)
56 $configData = $this->parseData($configFile);
57 if ($this->isValidConfigData($configData)) {
58 $this->configData = array_merge_recursive(
66 * @param string $servicesFile
68 public function addServicesFile($servicesFile)
74 $servicesData = $this->parseData($servicesFile);
75 if ($this->isValidServicesData($servicesData)) {
76 foreach ($servicesData['services'] as $key => $definition) {
77 if (!array_key_exists('tags', $definition)) {
80 $bootstrap = 'install';
81 foreach ($definition['tags'] as $tags) {
82 if (!array_key_exists('name', $tags)) {
86 if (array_search($tags['name'], $consoleTags) === false) {
90 if (array_key_exists('bootstrap', $tags)) {
91 $bootstrap = $tags['bootstrap'];
95 $this->servicesData[$bootstrap]['services'][$key] = $definition;
104 private function init()
106 $this->configData = [];
107 $this->servicesData = [];
112 * @return array|mixed
114 private function parseData($file)
116 if (!file_exists($file)) {
121 file_get_contents($file)
131 public function processProjectPackages($directory)
133 $finder = new Finder();
135 ->name('composer.json')
136 ->contains('drupal-console-library')
138 ->ignoreUnreadableDirs();
140 foreach ($finder as $file) {
141 $this->processComposerFile($file->getPathName());
146 * @param $composerFile
148 private function processComposerFile($composerFile)
150 $packageDirectory = dirname($composerFile);
152 $configFile = $packageDirectory.'/console.config.yml';
153 $this->addConfigFile($configFile);
155 $servicesFile = $packageDirectory.'/console.services.yml';
156 $this->addServicesFile($servicesFile);
160 * @param array $configData
164 private function isValidConfigData($configData)
170 if (!array_key_exists('application', $configData)) {
174 if (!array_key_exists('autowire', $configData['application'])) {
178 if (!array_key_exists('commands', $configData['application']['autowire'])) {
186 * @param array $servicesData
190 private function isValidServicesData($servicesData)
192 if (!$servicesData) {
196 if (!array_key_exists('services', $servicesData)) {
206 public function getConfigData()
208 return $this->configData;
214 public function getServicesData()
216 return $this->servicesData;