Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script Merging #32

Merged
merged 15 commits into from
Oct 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Cli/ServiceContainer/CliExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace Meteor\Cli\ServiceContainer;

use Meteor\ServiceContainer\ExtensionBase;
use Meteor\ServiceContainer\ExtensionInterface;
use Meteor\ServiceContainer\ExtensionManager;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class CliExtension implements ExtensionInterface
class CliExtension extends ExtensionBase implements ExtensionInterface
{
const PARAMETER_COMMAND_SERVICE_IDS = 'cli.command.service_ids';
const SERVICE_APPLICATION = 'cli.application';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace Meteor\Configuration\ServiceContainer;

use Meteor\ServiceContainer\ExtensionBase;
use Meteor\ServiceContainer\ExtensionInterface;
use Meteor\ServiceContainer\ExtensionManager;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

class ConfigurationExtension implements ExtensionInterface
class ConfigurationExtension extends ExtensionBase implements ExtensionInterface
{
// NB: Set in Application
const SERVICE_LOADER = 'configuration.loader';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace Meteor\EventDispatcher\ServiceContainer;

use Meteor\ServiceContainer\ExtensionBase;
use Meteor\ServiceContainer\ExtensionInterface;
use Meteor\ServiceContainer\ExtensionManager;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class EventDispatcherExtension implements ExtensionInterface
class EventDispatcherExtension extends ExtensionBase implements ExtensionInterface
{
const SERVICE_EVENT_DISPATCHER = 'events.event_dispatcher';
const TAG_SUBSCRIBER = 'events.subscriber';
Expand Down
3 changes: 2 additions & 1 deletion src/Filesystem/ServiceContainer/FilesystemExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace Meteor\Filesystem\ServiceContainer;

use Meteor\IO\ServiceContainer\IOExtension;
use Meteor\ServiceContainer\ExtensionBase;
use Meteor\ServiceContainer\ExtensionInterface;
use Meteor\ServiceContainer\ExtensionManager;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class FilesystemExtension implements ExtensionInterface
class FilesystemExtension extends ExtensionBase implements ExtensionInterface
{
const SERVICE_FILESYSTEM = 'filesystem';
const SERVICE_FINDER_FACTORY = 'filesyste.finder.factory';
Expand Down
3 changes: 2 additions & 1 deletion src/IO/ServiceContainer/IOExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

use Meteor\Cli\ServiceContainer\CliExtension;
use Meteor\Logger\ServiceContainer\LoggerExtension;
use Meteor\ServiceContainer\ExtensionBase;
use Meteor\ServiceContainer\ExtensionInterface;
use Meteor\ServiceContainer\ExtensionManager;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class IOExtension implements ExtensionInterface
class IOExtension extends ExtensionBase implements ExtensionInterface
{
const SERVICE_IO = 'io';

Expand Down
3 changes: 2 additions & 1 deletion src/Logger/ServiceContainer/LoggerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace Meteor\Logger\ServiceContainer;

use Meteor\ServiceContainer\ExtensionBase;
use Meteor\ServiceContainer\ExtensionInterface;
use Meteor\ServiceContainer\ExtensionManager;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

class LoggerExtension implements ExtensionInterface
class LoggerExtension extends ExtensionBase implements ExtensionInterface
{
const SERVICE_LOGGER = 'logger';

Expand Down
3 changes: 2 additions & 1 deletion src/Migrations/ServiceContainer/MigrationsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
use Meteor\Logger\ServiceContainer\LoggerExtension;
use Meteor\Migrations\MigrationsConstants;
use Meteor\Platform\ServiceContainer\PlatformExtension;
use Meteor\ServiceContainer\ExtensionBase;
use Meteor\ServiceContainer\ExtensionInterface;
use Meteor\ServiceContainer\ExtensionManager;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class MigrationsExtension implements ExtensionInterface
class MigrationsExtension extends ExtensionBase implements ExtensionInterface
{
const SERVICE_CONFIGURATION_FACTORY = 'migrations.configuration.factory';
const SERVICE_CONNECTION_CONFIGURATION_LOADER = 'migrations.connection.configuration.loader';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
namespace Meteor\Package\Provider\Dummy\ServiceContainer;

use Meteor\Package\ServiceContainer\PackageExtension;
use Meteor\ServiceContainer\ExtensionBase;
use Meteor\ServiceContainer\ExtensionInterface;
use Meteor\ServiceContainer\ExtensionManager;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

class DummyPackageProviderExtension implements ExtensionInterface
class DummyPackageProviderExtension extends ExtensionBase implements ExtensionInterface
{
const PROVIDER_NAME = 'dummy';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
use Meteor\IO\ServiceContainer\IOExtension;
use Meteor\Package\ServiceContainer\PackageExtension;
use Meteor\Process\ServiceContainer\ProcessExtension;
use Meteor\ServiceContainer\ExtensionBase;
use Meteor\ServiceContainer\ExtensionInterface;
use Meteor\ServiceContainer\ExtensionManager;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class GoogleDrivePackageProviderExtension implements ExtensionInterface
class GoogleDrivePackageProviderExtension extends ExtensionBase implements ExtensionInterface
{
const PROVIDER_NAME = 'gdrive';
const PARAMETER_BINARY = 'gdrive_package_provider.binary';
Expand Down
3 changes: 2 additions & 1 deletion src/Package/ServiceContainer/PackageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Meteor\Configuration\ServiceContainer\ConfigurationExtension;
use Meteor\Filesystem\ServiceContainer\FilesystemExtension;
use Meteor\IO\ServiceContainer\IOExtension;
use Meteor\ServiceContainer\ExtensionBase;
use Meteor\ServiceContainer\ExtensionInterface;
use Meteor\ServiceContainer\ExtensionManager;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
Expand All @@ -16,7 +17,7 @@
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class PackageExtension implements ExtensionInterface
class PackageExtension extends ExtensionBase implements ExtensionInterface
{
const PARAMETER_PROVIDER = 'package.provider';
const SERVICE_COMBINED_PACKAGE_DEPENDENCY_CHECKER = 'package.combined.package_dependency_checker';
Expand Down
3 changes: 2 additions & 1 deletion src/Patch/ServiceContainer/PatchExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
use Meteor\Platform\ServiceContainer\PlatformExtension;
use Meteor\Scripts\ScriptEventProviderInterface;
use Meteor\Scripts\ServiceContainer\ScriptsExtension;
use Meteor\ServiceContainer\ExtensionBase;
use Meteor\ServiceContainer\ExtensionInterface;
use Meteor\ServiceContainer\ExtensionManager;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class PatchExtension implements ExtensionInterface, ScriptEventProviderInterface
class PatchExtension extends ExtensionBase implements ExtensionInterface, ScriptEventProviderInterface
{
const PARAMETER_STRATEGY = 'patch.strategy';
const SERVICE_BACKUP_FINDER = 'patch.backup.finder';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
namespace Meteor\Patch\Strategy\Dummy\ServiceContainer;

use Meteor\Patch\ServiceContainer\PatchExtension;
use Meteor\ServiceContainer\ExtensionBase;
use Meteor\ServiceContainer\ExtensionInterface;
use Meteor\ServiceContainer\ExtensionManager;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

class DummyPatchStrategyExtension implements ExtensionInterface
class DummyPatchStrategyExtension extends ExtensionBase implements ExtensionInterface
{
const STRATEGY_NAME = 'dummy';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
namespace Meteor\Patch\Strategy\Overwrite\ServiceContainer;

use Meteor\Patch\ServiceContainer\PatchExtension;
use Meteor\ServiceContainer\ExtensionBase;
use Meteor\ServiceContainer\ExtensionInterface;
use Meteor\ServiceContainer\ExtensionManager;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

class OverwritePatchStrategyExtension implements ExtensionInterface
class OverwritePatchStrategyExtension extends ExtensionBase implements ExtensionInterface
{
const STRATEGY_NAME = 'overwrite';

Expand Down
3 changes: 2 additions & 1 deletion src/Permissions/ServiceContainer/PermissionsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
use Meteor\Cli\ServiceContainer\CliExtension;
use Meteor\IO\ServiceContainer\IOExtension;
use Meteor\Platform\ServiceContainer\PlatformExtension;
use Meteor\ServiceContainer\ExtensionBase;
use Meteor\ServiceContainer\ExtensionInterface;
use Meteor\ServiceContainer\ExtensionManager;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class PermissionsExtension implements ExtensionInterface
class PermissionsExtension extends ExtensionBase implements ExtensionInterface
{
const SERVICE_COMMAND_RESET_PERMISSIONS = 'permissions.cli.command.reset_permissions';
const SERVICE_PERMISSION_LOADER = 'permissions.permission_loader';
Expand Down
3 changes: 2 additions & 1 deletion src/Platform/ServiceContainer/PlatformExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

use Meteor\Filesystem\ServiceContainer\FilesystemExtension;
use Meteor\Process\ServiceContainer\ProcessExtension;
use Meteor\ServiceContainer\ExtensionBase;
use Meteor\ServiceContainer\ExtensionInterface;
use Meteor\ServiceContainer\ExtensionManager;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class PlatformExtension implements ExtensionInterface
class PlatformExtension extends ExtensionBase implements ExtensionInterface
{
const SERVICE_PLATFORM = 'platform';
const SERVICE_PLATFORM_UNIX = 'platform.unix';
Expand Down
3 changes: 2 additions & 1 deletion src/Process/ServiceContainer/ProcessExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace Meteor\Process\ServiceContainer;

use Meteor\IO\ServiceContainer\IOExtension;
use Meteor\ServiceContainer\ExtensionBase;
use Meteor\ServiceContainer\ExtensionInterface;
use Meteor\ServiceContainer\ExtensionManager;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class ProcessExtension implements ExtensionInterface
class ProcessExtension extends ExtensionBase implements ExtensionInterface
{
const SERVICE_PROCESS_RUNNER = 'process.runner';

Expand Down
43 changes: 29 additions & 14 deletions src/Scripts/ScriptRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,50 @@ public function setWorkingDir($workingDir)
}

/**
* Process each script type.
*
* @param string $scriptName
* @return boolean
*/
public function run($scriptName)
{
if (!isset($this->scripts[$scriptName])) {
return false;
}
$result = false;

foreach ($this->scripts as $scripts) {
if (!isset($scripts[$scriptName])) {
continue;
}

$result = true;
foreach ($this->scripts[$scriptName] as $script) {
$result = $this->runScript($scriptName, $script);
$result = $this->runScripts($scriptName, $scripts);
}

return $result;
}

private function runScript($scriptName, $script)
/**
* Cycle through each of the script declarations and run the, or
* parse the script if it's a function alias.
*
* @param $scriptName
* @param $scripts
* @return bool
*/
private function runScripts($scriptName, $scripts)
{
if (strpos($script, '@') === 0) {
$script = substr($script, 1);
if ($scriptName === $script) {
throw new RuntimeException(sprintf('Infinite recursion detected in script "%s"', $scriptName));
foreach ($scripts[$scriptName] as $script) {
if (strpos($script, '@') === 0) {
$script = substr($script, 1);
if ($scriptName === $script) {
throw new RuntimeException(sprintf('Infinite recursion detected in script "%s"', $scriptName));
}

return $this->runScripts($script, $scripts);
}

return $this->run($script);
$this->processRunner->run($script, $this->getWorkingDir());
}

$this->processRunner->run($script, $this->getWorkingDir());

return true;
}

}
25 changes: 23 additions & 2 deletions src/Scripts/ServiceContainer/ScriptsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
use Meteor\IO\ServiceContainer\IOExtension;
use Meteor\Process\ServiceContainer\ProcessExtension;
use Meteor\Scripts\ScriptEventProviderInterface;
use Meteor\ServiceContainer\ExtensionInterface;
use Meteor\ServiceContainer\ExtensionBase;
use Meteor\ServiceContainer\ExtensionManager;
use Meteor\ServiceContainer\ExtensionInterface;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class ScriptsExtension implements ExtensionInterface
class ScriptsExtension extends ExtensionBase implements ExtensionInterface
{
const PARAMETER_SCRIPTS = 'scripts';
const SERVICE_COMMAND_RUN = 'scripts.cli.command.run';
Expand Down Expand Up @@ -50,6 +51,26 @@ public function initialize(ExtensionManager $extensionManager)
}
}

/**
* {@inheritdoc}
*/
public function configParse(array $config)
{
$extensionConfig = array();
$extensionConfig[] = parent::configParse($config);

if (isset($config['combined'])) {
$extensionConfigKey = $this->getConfigKey();
foreach ($config['combined'] as $combinedConfig) {
if (isset($combinedConfig[$extensionConfigKey])) {
$extensionConfig[] = $combinedConfig[$extensionConfigKey];
}
}
}

return $extensionConfig;
}

/**
* {@inheritdoc}
*/
Expand Down
12 changes: 5 additions & 7 deletions src/ServiceContainer/ContainerLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,11 @@ private function initializeExtensions(ContainerBuilder $container, array $config
private function loadExtensions(ContainerBuilder $container, array $config)
{
foreach ($this->extensionManager->getExtensions() as $extension) {
$extensionConfig = array();
if (isset($config[$extension->getConfigKey()])) {
$extensionConfig = $config[$extension->getConfigKey()];
unset($config[$extension->getConfigKey()]);
}

$this->loadExtension($container, $extension, $extensionConfig);
$this->loadExtension(
$container,
$extension,
$extension->configParse($config)
);
}
}

Expand Down
Loading