From fc61377fd877e7812b964ecc2caf77a71665b9aa Mon Sep 17 00:00:00 2001 From: Rostislav Wolny Date: Tue, 4 Dec 2018 14:48:11 +0100 Subject: [PATCH] Move container dump from application code to Robofile and to generated dir [PREMIUM-99] --- RoboFile.php | 21 ++++++++++++++++----- build.sh | 1 + composer.json | 4 +++- generated/.gitignore | 2 ++ lib/DI/ContainerFactory.php | 13 ------------- 5 files changed, 22 insertions(+), 19 deletions(-) create mode 100644 generated/.gitignore diff --git a/RoboFile.php b/RoboFile.php index a6897fd30b..917e9c1584 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -283,9 +283,6 @@ class RoboFile extends \Robo\Tasks { } function containerDump() { - $this->say('Deleting DI Container'); - $this->_exec('rm -f ./lib/DI/CachedContainer.php'); - $this->say('Generating DI container cache'); $this->loadEnv(); define('ABSPATH', getenv('WP_ROOT') . '/'); if (!file_exists(ABSPATH . 'wp-config.php')) { @@ -293,8 +290,22 @@ class RoboFile extends \Robo\Tasks { exit(1); } require_once __DIR__ . '/vendor/autoload.php'; - $container_factory = new \MailPoet\DI\ContainerFactory(); - $container_factory->dumpContainer(); + $configurator = new \MailPoet\DI\ContainerConfigurator(); + $dump_file = __DIR__ . '/generated/' . $configurator->getDumpClassname() . '.php'; + $this->say('Deleting DI Container'); + $this->_exec("rm -f $dump_file"); + $this->say('Generating DI container cache'); + $container_factory = new \MailPoet\DI\ContainerFactory($configurator); + $container = $container_factory->getConfiguredContainer(); + $container->compile(); + $dumper = new \MailPoetVendor\Symfony\Component\DependencyInjection\Dumper\PhpDumper($container); + file_put_contents( + $dump_file, + $dumper->dump([ + 'class' => $configurator->getDumpClassname(), + 'namespace' => $configurator->getDumpNamespace() + ]) + ); } function qa() { diff --git a/build.sh b/build.sh index 336662e4aa..7b32641c65 100755 --- a/build.sh +++ b/build.sh @@ -42,6 +42,7 @@ echo '[BUILD] Fetching prefixed production libraries' echo '[BUILD] Copying release folders' cp -Rf lang $plugin_name cp -RfL assets $plugin_name +cp -Rf generated $plugin_name cp -Rf lib $plugin_name cp -Rf vendor $plugin_name cp -Rf vendor-prefixed $plugin_name diff --git a/composer.json b/composer.json index 2a51d1641d..701ad65f25 100644 --- a/composer.json +++ b/composer.json @@ -48,7 +48,9 @@ ], "psr-4": { "MailPoet\\": "lib/", - "Sudzy\\": "lib/Util/Sudzy" + "MailPoetVendor\\": "vendor-prefixed/", + "Sudzy\\": "lib/Util/Sudzy", + "MailPoetGenerated\\": "generated/" } }, "scripts": { diff --git a/generated/.gitignore b/generated/.gitignore new file mode 100644 index 0000000000..d6b7ef32c8 --- /dev/null +++ b/generated/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/lib/DI/ContainerFactory.php b/lib/DI/ContainerFactory.php index b6fc8abb8c..b25b9e9aad 100644 --- a/lib/DI/ContainerFactory.php +++ b/lib/DI/ContainerFactory.php @@ -3,7 +3,6 @@ namespace MailPoet\DI; use MailPoetVendor\Symfony\Component\DependencyInjection\ContainerBuilder; -use MailPoetVendor\Symfony\Component\DependencyInjection\Dumper\PhpDumper; class ContainerFactory { @@ -36,16 +35,4 @@ class ContainerFactory { function getConfiguredContainer() { return $this->configurator->configure(new ContainerBuilder()); } - - function dumpContainer() { - $container = $this->createContainer(); - $container->compile(); - $dumper = new PhpDumper($container); - file_put_contents( - __DIR__ . '/' . $this->dump_file, - $dumper->dump([ - 'class' => $this->dump_class - ]) - ); - } }