Skip to content

Commit

Permalink
Merge pull request #1 from hechoendrupal/add-boostrap-attribute
Browse files Browse the repository at this point in the history
Read service tag attribute bootstrap.
  • Loading branch information
jmolivas authored Feb 14, 2017
2 parents fe98b54 + d949218 commit f1d3f76
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
20 changes: 18 additions & 2 deletions src/Extender.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function processPackages(PackageEvent $event)

$configFile = $directory . '/extend.console.config.yml';
$servicesFile = $directory . '/extend.console.services.yml';
$servicesUnistallFile = $directory . '/extend.console.uninstall.services.yml';

if (file_exists($configFile)) {
unlink($configFile);
Expand All @@ -78,6 +79,11 @@ public function processPackages(PackageEvent $event)
$this->io->write('<info>Removing services cache file:</info>' . $servicesFile);
}

if (file_exists($servicesUnistallFile)) {
unlink($servicesUnistallFile);
$this->io->write('<info>Removing services cache file:</info>' . $servicesUnistallFile);
}

if ($configData = $extenderManager->getConfigData()) {
file_put_contents(
$configFile,
Expand All @@ -86,12 +92,22 @@ public function processPackages(PackageEvent $event)
$this->io->write('<info>Creating config cache file:</info>' . $configFile);
}

if ($servicesData = $extenderManager->getServicesData()) {
$servicesData = $extenderManager->getServicesData();
if ($servicesData && array_key_exists('install', $servicesData)) {
file_put_contents(
$servicesFile,
Yaml::dump($servicesData, 4, 2)
Yaml::dump($servicesData['install'], 4, 2)
);
$this->io->write('<info>Creating services cache file: </info>' . $servicesFile);
}

$servicesData = $extenderManager->getServicesData();
if ($servicesData && array_key_exists('uninstall', $servicesData)) {
file_put_contents(
$servicesUnistallFile,
Yaml::dump($servicesData['uninstall'], 4, 2)
);
$this->io->write('<info>Creating services cache file: </info>' . $servicesUnistallFile);
}
}
}
26 changes: 22 additions & 4 deletions src/ExtenderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,28 @@ public function addServicesFile($servicesFile)
{
$servicesData = $this->parseData($servicesFile);
if ($this->isValidServicesData($servicesData)) {
$this->servicesData = array_merge_recursive(
$servicesData,
$this->servicesData
);
foreach ($servicesData['services'] as $key => $definition) {
if (!array_key_exists('tags', $definition)) {
continue;
}
$bootstrap = 'install';
foreach ($definition['tags'] as $tags) {
if (!array_key_exists('name', $tags)) {
continue;
}

if (array_key_exists('bootstrap', $tags)) {
$bootstrap = $tags['bootstrap'];
}
}

$packageService[$bootstrap]['services'][$key] = $definition;

$this->servicesData = array_merge_recursive(
$packageService,
$this->servicesData
);
}
}
}

Expand Down

0 comments on commit f1d3f76

Please sign in to comment.