diff --git a/app/etc/di.xml b/app/etc/di.xml index bf9ea5ae6a650e7260af9caee61849005c2e747f..b7f30cf450bafc55fc50f731c23838a2de92f81d 100755 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -127,7 +127,6 @@ <preference for="Magento\Framework\Module\ResourceInterface" type="Magento\Framework\Module\Resource" /> <preference for="Magento\Framework\Pricing\Amount\AmountInterface" type="Magento\Framework\Pricing\Amount\Base" /> <preference for="Magento\Framework\Api\SearchResultsInterface" type="Magento\Framework\Api\SearchResults" /> - <preference for="Magento\Framework\Api\AttributeInterface" type="Magento\Framework\Api\AttributeValue" /> <preference for="Magento\Framework\Model\Resource\Db\TransactionManagerInterface" type="Magento\Framework\Model\Resource\Db\TransactionManager" /> <type name="Magento\Framework\Model\Resource\Db\TransactionManager" shared="false" /> <type name="Magento\Framework\Logger\Handler\Base"> diff --git a/dev/tests/integration/framework/Magento/TestFramework/ObjectManager/EnvironmentFactory.php b/dev/tests/integration/framework/Magento/TestFramework/App/EnvironmentFactory.php similarity index 50% rename from dev/tests/integration/framework/Magento/TestFramework/ObjectManager/EnvironmentFactory.php rename to dev/tests/integration/framework/Magento/TestFramework/App/EnvironmentFactory.php index 6d364820023193ad93e11f55fcb2b24bf1750f07..29dc3b2609604f82b25ecc4c7f85115a4babcc84 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/ObjectManager/EnvironmentFactory.php +++ b/dev/tests/integration/framework/Magento/TestFramework/App/EnvironmentFactory.php @@ -4,11 +4,11 @@ * See COPYING.txt for license details. */ -namespace Magento\TestFramework\ObjectManager; +namespace Magento\TestFramework\App; -use Magento\TestFramework\ObjectManager\Environment\Developer; +use Magento\TestFramework\App\ObjectManager\Environment\Developer; -class EnvironmentFactory extends \Magento\Framework\ObjectManager\EnvironmentFactory +class EnvironmentFactory extends \Magento\Framework\App\EnvironmentFactory { public function createEnvironment() { diff --git a/dev/tests/integration/framework/Magento/TestFramework/ObjectManager/Environment/Developer.php b/dev/tests/integration/framework/Magento/TestFramework/App/ObjectManager/Environment/Developer.php similarity index 74% rename from dev/tests/integration/framework/Magento/TestFramework/ObjectManager/Environment/Developer.php rename to dev/tests/integration/framework/Magento/TestFramework/App/ObjectManager/Environment/Developer.php index cc8e8b1d2d5f4c841cdf335ba951ee64763e677a..049382450835e7e0f3e50aa5458644da0ea6fd19 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/ObjectManager/Environment/Developer.php +++ b/dev/tests/integration/framework/Magento/TestFramework/App/ObjectManager/Environment/Developer.php @@ -3,9 +3,9 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\TestFramework\ObjectManager\Environment; +namespace Magento\TestFramework\App\ObjectManager\Environment; -class Developer extends \Magento\Framework\ObjectManager\Environment\Developer +class Developer extends \Magento\Framework\App\ObjectManager\Environment\Developer { public function getDiConfig() { diff --git a/dev/tests/integration/framework/Magento/TestFramework/ObjectManagerFactory.php b/dev/tests/integration/framework/Magento/TestFramework/ObjectManagerFactory.php index e977d5de3dd64a1c76b8e569349c1be634e8fa18..8cebbc8f76dfcfe7677bb0c52a03950f3bdf9cac 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/ObjectManagerFactory.php +++ b/dev/tests/integration/framework/Magento/TestFramework/ObjectManagerFactory.php @@ -32,7 +32,7 @@ class ObjectManagerFactory extends \Magento\Framework\App\ObjectManagerFactory /** * @var string */ - protected $envFactoryClassName = 'Magento\TestFramework\ObjectManager\EnvironmentFactory'; + protected $envFactoryClassName = 'Magento\TestFramework\App\EnvironmentFactory'; /** * @var array @@ -57,6 +57,12 @@ class ObjectManagerFactory extends \Magento\Framework\App\ObjectManagerFactory $deploymentConfig = $this->createDeploymentConfig($directoryList, $arguments); $this->factory->setArguments($arguments); $objectManager->addSharedInstance($deploymentConfig, 'Magento\Framework\App\DeploymentConfig'); + $objectManager->addSharedInstance( + $objectManager->get( + 'Magento\Framework\App\ObjectManager\ConfigLoader' + ), + 'Magento\Framework\ObjectManager\ConfigLoaderInterface' + ); $objectManager->get('Magento\Framework\Interception\PluginListInterface')->reset(); $objectManager->configure( $objectManager->get('Magento\Framework\App\ObjectManager\ConfigLoader')->load('global') diff --git a/dev/tests/integration/testsuite/Magento/Framework/Code/_expected/SourceClassWithNamespaceInterceptor.php.sample b/dev/tests/integration/testsuite/Magento/Framework/Code/_expected/SourceClassWithNamespaceInterceptor.php.sample index 8d47ba0724780304b14e9f85bbe1c1cd1d04094a..7b78299861058c1440a803cdb63a28f939d2a418 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Code/_expected/SourceClassWithNamespaceInterceptor.php.sample +++ b/dev/tests/integration/testsuite/Magento/Framework/Code/_expected/SourceClassWithNamespaceInterceptor.php.sample @@ -35,15 +35,23 @@ class Interceptor extends \Magento\Framework\Code\GeneratorTest\SourceClassWithN */ protected $subjectType = null; - public function __construct(\Magento\Framework\ObjectManagerInterface $pluginLocator, \Magento\Framework\Interception\PluginListInterface $pluginList, \Magento\Framework\Interception\ChainInterface $chain, $param1 = '', $param2 = '\\', $param3 = '\'') + public function __construct($param1 = '', $param2 = '\\', $param3 = '\'') { - $this->pluginLocator = $pluginLocator; - $this->pluginList = $pluginList; - $this->chain = $chain; - $this->subjectType = get_parent_class($this); + $this->___init(); parent::__construct($param1, $param2, $param3); } + public function ___init() + { + $this->pluginLocator = \Magento\Framework\App\ObjectManager::getInstance(); + $this->pluginList = $this->pluginLocator->get('Magento\Framework\Interception\PluginListInterface'); + $this->chain = $this->pluginLocator->get('Magento\Framework\Interception\ChainInterface'); + $this->subjectType = get_parent_class($this); + if (method_exists($this->subjectType, '___init')) { + parent::___init(); + } + } + public function ___callParent($method, array $arguments) { return call_user_func_array(array('parent', $method), $arguments); @@ -60,13 +68,7 @@ class Interceptor extends \Magento\Framework\Code\GeneratorTest\SourceClassWithN public function __wakeup() { - $this->pluginLocator = \Magento\Framework\App\ObjectManager::getInstance(); - $this->pluginList = $this->pluginLocator->get('Magento\Framework\Interception\PluginListInterface'); - $this->chain = $this->pluginLocator->get('Magento\Framework\Interception\ChainInterface'); - $this->subjectType = get_parent_class($this); - if (method_exists(get_parent_class($this), '__wakeup')) { - parent::__wakeup(); - } + $this->___init(); } protected function ___callPlugins($method, array $arguments, array $pluginInfo) diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/AbstractPlugin.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/AbstractPlugin.php index 64cad39d9c989dd7fe5da54bfb1a4ead28dc1636..217d35cbc485c5c2e6110f3bf5900a5091b108ba 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Interception/AbstractPlugin.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/AbstractPlugin.php @@ -11,7 +11,6 @@ namespace Magento\Framework\Interception; */ abstract class AbstractPlugin extends \PHPUnit_Framework_TestCase { - /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -22,6 +21,26 @@ abstract class AbstractPlugin extends \PHPUnit_Framework_TestCase */ protected $_objectManager; + /** + * @var \Magento\Framework\ObjectManagerInterface + */ + private $applicationObjectManager; + + public function setUp() + { + if (!$this->_objectManager) { + return; + } + + $this->applicationObjectManager = \Magento\Framework\App\ObjectManager::getInstance(); + \Magento\Framework\App\ObjectManager::setInstance($this->_objectManager); + } + + public function tearDown() + { + \Magento\Framework\App\ObjectManager::setInstance($this->applicationObjectManager); + } + public function setUpInterceptionConfig($pluginConfig) { $config = new \Magento\Framework\Interception\ObjectManager\Config\Developer(); @@ -68,6 +87,7 @@ abstract class AbstractPlugin extends \PHPUnit_Framework_TestCase $sharedInstances ); $factory->setObjectManager($this->_objectManager); + $config->setInterceptionConfig($interceptionConfig); $config->extend( [ diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/GeneralTest.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/GeneralTest.php index dfeb14900296ee264a47089b051c53cb0a82ee63..16b16935904b9c8299aefaf25115b2d17933228a 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Interception/GeneralTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/GeneralTest.php @@ -35,6 +35,8 @@ class GeneralTest extends AbstractPlugin ], ] ); + + parent::setUp(); } public function testMethodCanBePluginized() diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/TwoPluginTest.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/TwoPluginTest.php index a4cbcd18f1103952d43884c3c34c11f0278e9e4d..58a27e0d9365d703a7bb1bce2f87b7221cac6d80 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Interception/TwoPluginTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/TwoPluginTest.php @@ -27,6 +27,8 @@ class TwoPluginTest extends AbstractPlugin ] ] ); + + parent::setUp(); } public function testPluginBeforeWins() diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/ClassesTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/ClassesTest.php index 102e4097cdf517e61870170264460613687b144f..2cbd11a348fe259e0591cc86f395914b63fbc1ed 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/ClassesTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/ClassesTest.php @@ -534,9 +534,16 @@ class ClassesTest extends \PHPUnit_Framework_TestCase $errors = []; foreach ($files->getFiles([BP . '/dev/tests/{integration,unit}'], '*') as $file) { $code = file_get_contents($file); - if (preg_match('/@covers(DefaultClass)?\s+([\w\\\\]+)(::([\w\\\\]+))?/', $code, $matches)) { - if ($this->isNonexistentEntityCovered($matches)) { - $errors[] = $file . ': ' . $matches[0]; + if (preg_match_all( + '/@covers(DefaultClass)?\s+([\w\\\\]+)(::([\w\\\\]+))?/', + $code, + $matchesAll, + PREG_SET_ORDER + )) { + foreach ($matchesAll as $matches) { + if ($this->isNonexistentEntityCovered($matches)) { + $errors[] = $file . ': ' . $matches[0]; + } } } } diff --git a/dev/tests/unit/testsuite/Magento/Framework/App/FactoryStub.php b/dev/tests/unit/testsuite/Magento/Framework/App/FactoryStub.php index aabc55192386fcddf523a7c9b3fc14b914ff2600..41e77424f1ac82bd23c192a676052e597e8146ab 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/App/FactoryStub.php +++ b/dev/tests/unit/testsuite/Magento/Framework/App/FactoryStub.php @@ -5,6 +5,8 @@ */ namespace Magento\Framework\App; +use Magento\Framework\ObjectManagerInterface; + /** * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ @@ -34,4 +36,17 @@ class FactoryStub implements \Magento\Framework\ObjectManager\FactoryInterface { throw new \BadMethodCallException(__METHOD__); } + + /** + * Set object manager + * + * @param ObjectManagerInterface $objectManager + * + * @return void + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function setObjectManager(ObjectManagerInterface $objectManager) + { + + } } diff --git a/dev/tests/unit/testsuite/Magento/Framework/ObjectManager/Environment/CompiledTest.php b/dev/tests/unit/testsuite/Magento/Framework/App/ObjectManager/Environment/CompiledTest.php similarity index 54% rename from dev/tests/unit/testsuite/Magento/Framework/ObjectManager/Environment/CompiledTest.php rename to dev/tests/unit/testsuite/Magento/Framework/App/ObjectManager/Environment/CompiledTest.php index 0ed7917404e9265e56c290bf5eeb11a462ab9f6f..618c51fddfe612635b52721fbc4a6482a35a5373 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/ObjectManager/Environment/CompiledTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/App/ObjectManager/Environment/CompiledTest.php @@ -3,26 +3,19 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\ObjectManager\Environment; - -require 'CompiledTesting.php'; +namespace Magento\Framework\App\ObjectManager\Environment; class CompiledTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Framework\ObjectManager\Environment\Compiled + * @var \Magento\Framework\App\ObjectManager\Environment\Compiled */ protected $_compiled; protected function setUp() { - $envFactoryMock = $this->getMock('Magento\Framework\ObjectManager\EnvironmentFactory', [], [], '', false); - $this->_compiled = new \Magento\Framework\ObjectManager\Environment\CompiledTesting($envFactoryMock); - } - - public function testGetFilePath() - { - $this->assertContains('/var/di/global.ser', $this->_compiled->getFilePath()); + $envFactoryMock = $this->getMock('Magento\Framework\App\EnvironmentFactory', [], [], '', false); + $this->_compiled = new \Magento\Framework\App\ObjectManager\Environment\CompiledTesting($envFactoryMock); } public function testGetMode() diff --git a/dev/tests/unit/testsuite/Magento/Framework/ObjectManager/Environment/CompiledTesting.php b/dev/tests/unit/testsuite/Magento/Framework/App/ObjectManager/Environment/CompiledTesting.php similarity index 88% rename from dev/tests/unit/testsuite/Magento/Framework/ObjectManager/Environment/CompiledTesting.php rename to dev/tests/unit/testsuite/Magento/Framework/App/ObjectManager/Environment/CompiledTesting.php index 88daaa0c6795b32fcf75e9ada76bf9f35a1c3730..0a2fc3de5c056ec84bcfac6c488754950b2d502a 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/ObjectManager/Environment/CompiledTesting.php +++ b/dev/tests/unit/testsuite/Magento/Framework/App/ObjectManager/Environment/CompiledTesting.php @@ -4,7 +4,7 @@ * See COPYING.txt for license details. */ -namespace Magento\Framework\ObjectManager\Environment; +namespace Magento\Framework\App\ObjectManager\Environment; require 'ConfigTesting.php'; diff --git a/dev/tests/unit/testsuite/Magento/Framework/ObjectManager/Environment/ConfigTesting.php b/dev/tests/unit/testsuite/Magento/Framework/App/ObjectManager/Environment/ConfigTesting.php similarity index 98% rename from dev/tests/unit/testsuite/Magento/Framework/ObjectManager/Environment/ConfigTesting.php rename to dev/tests/unit/testsuite/Magento/Framework/App/ObjectManager/Environment/ConfigTesting.php index 328f9da0474bf8760297acfd47d5b7c5ecde9340..4eb2e737cd6e31fb72f33a7fb8e9e067ce7ec325 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/ObjectManager/Environment/ConfigTesting.php +++ b/dev/tests/unit/testsuite/Magento/Framework/App/ObjectManager/Environment/ConfigTesting.php @@ -3,7 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\ObjectManager\Environment; +namespace Magento\Framework\App\ObjectManager\Environment; use Magento\Framework\Interception\ObjectManager\ConfigInterface; use Magento\Framework\ObjectManager\ConfigCacheInterface; diff --git a/dev/tests/unit/testsuite/Magento/Framework/ObjectManager/Environment/DeveloperTest.php b/dev/tests/unit/testsuite/Magento/Framework/App/ObjectManager/Environment/DeveloperTest.php similarity index 60% rename from dev/tests/unit/testsuite/Magento/Framework/ObjectManager/Environment/DeveloperTest.php rename to dev/tests/unit/testsuite/Magento/Framework/App/ObjectManager/Environment/DeveloperTest.php index 240bd3a69786c685509558a32b29ecfc338a5797..55dba66fe2bb08e605f7fbc33d2d07e5d08cceb1 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/ObjectManager/Environment/DeveloperTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/App/ObjectManager/Environment/DeveloperTest.php @@ -3,19 +3,19 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\ObjectManager\Environment; +namespace Magento\Framework\App\ObjectManager\Environment; class DeveloperTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Framework\ObjectManager\Environment\Developer + * @var \Magento\Framework\App\ObjectManager\Environment\Developer */ protected $_developer; protected function setUp() { - $envFactoryMock = $this->getMock('Magento\Framework\ObjectManager\EnvironmentFactory', [], [], '', false); - $this->_developer = new \Magento\Framework\ObjectManager\Environment\Developer($envFactoryMock); + $envFactoryMock = $this->getMock('Magento\Framework\App\EnvironmentFactory', [], [], '', false); + $this->_developer = new \Magento\Framework\App\ObjectManager\Environment\Developer($envFactoryMock); } public function testGetMode() diff --git a/dev/tests/unit/testsuite/Magento/Tools/Di/App/CompilerTest.php b/dev/tests/unit/testsuite/Magento/Tools/Di/App/CompilerTest.php index be07af2814105307ce24135669429471d324ed67..4160b0f927c09f6a5ee1d58f9d147c526cf1831f 100644 --- a/dev/tests/unit/testsuite/Magento/Tools/Di/App/CompilerTest.php +++ b/dev/tests/unit/testsuite/Magento/Tools/Di/App/CompilerTest.php @@ -10,7 +10,7 @@ class CompilerTest extends \PHPUnit_Framework_TestCase /** * @var Compiler */ - private $model; + private $application; /** * @var \Magento\Framework\ObjectManagerInterface | \PHPUnit_Framework_MockObject_MockObject @@ -40,7 +40,7 @@ class CompilerTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->setMethods([]) ->getMock(); - $this->model = new Compiler( + $this->application = new Compiler( $this->taskManagerMock, $this->objectManagerMock, $this->responseMock @@ -64,7 +64,7 @@ class CompilerTest extends \PHPUnit_Framework_TestCase ->method('setCode') ->with(\Magento\Framework\App\Console\Response::SUCCESS); - $this->assertInstanceOf('\Magento\Framework\App\Console\Response', $this->model->launch()); + $this->assertInstanceOf('\Magento\Framework\App\Console\Response', $this->application->launch()); } public function testLaunchException() @@ -89,7 +89,7 @@ class CompilerTest extends \PHPUnit_Framework_TestCase ->method('setCode') ->with(\Magento\Framework\App\Console\Response::ERROR); - $this->assertInstanceOf('\Magento\Framework\App\Console\Response', $this->model->launch()); + $this->assertInstanceOf('\Magento\Framework\App\Console\Response', $this->application->launch()); } /** @@ -110,14 +110,25 @@ class CompilerTest extends \PHPUnit_Framework_TestCase 'Magento\Tools\Di\Compiler\Config\ModificationChain' => [ 'arguments' => [ 'modificationsList' => [ - 'PreferencesResolving' => - ['instance' => 'Magento\Tools\Di\Compiler\Config\Chain\PreferencesResolving'], 'BackslashTrim' => ['instance' => 'Magento\Tools\Di\Compiler\Config\Chain\BackslashTrim'], + 'PreferencesResolving' => + ['instance' => 'Magento\Tools\Di\Compiler\Config\Chain\PreferencesResolving'], + 'InterceptorSubstitution' => + ['instance' => 'Magento\Tools\Di\Compiler\Config\Chain\InterceptorSubstitution'], + 'InterceptionPreferencesResolving' => + ['instance' => 'Magento\Tools\Di\Compiler\Config\Chain\PreferencesResolving'], 'ArgumentsSerialization' => ['instance' => 'Magento\Tools\Di\Compiler\Config\Chain\ArgumentsSerialization'], ] ] + ], + 'Magento\Tools\Di\Code\Generator\PluginList' => [ + 'arguments' => [ + 'cache' => [ + 'instance' => 'Magento\Framework\App\Interception\Cache\CompiledConfig' + ] + ] ] ]; } @@ -134,11 +145,14 @@ class CompilerTest extends \PHPUnit_Framework_TestCase 'path' => BP . '/' . 'app/code', 'filePatterns' => ['di' => '/\/etc\/([a-zA-Z_]*\/di|di)\.xml$/'] ], - Task\OperationFactory::AREA => [ + Task\OperationFactory::APPLICATION_CODE_GENERATOR => [ BP . '/' . 'app/code', BP . '/' . 'lib/internal/Magento/Framework', BP . '/' . 'var/generation' ], Task\OperationFactory::INTERCEPTION => BP . '/var/generation', + Task\OperationFactory::AREA_CONFIG_GENERATOR => [ + BP . '/' . 'app/code', BP . '/' . 'lib/internal/Magento/Framework', BP . '/' . 'var/generation' + ], Task\OperationFactory::INTERCEPTION_CACHE => [ BP . '/' . 'app/code', BP . '/' . 'lib/internal/Magento/Framework', BP . '/' . 'var/generation' ] diff --git a/dev/tests/unit/testsuite/Magento/Tools/Di/App/Task/InterceptionCacheTest.php b/dev/tests/unit/testsuite/Magento/Tools/Di/App/Task/InterceptionCacheTest.php new file mode 100644 index 0000000000000000000000000000000000000000..7a99c3d19f932513cb574c4be1592efaf59fd118 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Tools/Di/App/Task/InterceptionCacheTest.php @@ -0,0 +1,82 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Tools\Di\App\Task; + +use Magento\Tools\Di\App\Task\Operation\Interception; +use Magento\Tools\Di\App\Task\Operation\InterceptionCache; + +class InterceptionCacheTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Interception\Config\Config + */ + private $configMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Tools\Di\Code\Reader\InstancesNamesList\Interceptions + */ + private $interceptionsListMock; + + public function setUp() + { + $this->configMock = $this->getMockBuilder('Magento\Framework\Interception\Config\Config') + ->setMethods([]) + ->disableOriginalConstructor() + ->getMock(); + $this->interceptionsListMock = $this->getMockBuilder( + 'Magento\Tools\Di\Code\Reader\InstancesNamesList\Interceptions' + ) + ->setMethods([]) + ->disableOriginalConstructor() + ->getMock(); + } + + public function testDoOperationEmptyData() + { + $data = []; + + $operation = new InterceptionCache($this->configMock, $this->interceptionsListMock, $data); + $this->configMock->expects($this->never()) + ->method('initialize'); + + $this->assertNull($operation->doOperation()); + } + + public function testDoOperationInitializeWithDefinitions() + { + $definitions = [ + 'Library\Class', + 'Application\Class', + 'VarGeneration\Class', + 'AppGeneration\Class' + ]; + + $data = [ + 'lib', + 'app', + 'generation', + 'appgeneration' + ]; + + $this->interceptionsListMock->expects($this->any()) + ->method('getList') + ->willReturnMap( + [ + ['lib', ['Library\Class']], + ['app', ['Application\Class']], + ['generation', ['VarGeneration\Class']], + ['appgeneration', ['AppGeneration\Class']] + ] + ); + + $operation = new InterceptionCache($this->configMock, $this->interceptionsListMock, $data); + $this->configMock->expects($this->once()) + ->method('initialize') + ->with($definitions); + + $this->assertNull($operation->doOperation()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Tools/Di/App/Task/OperationFactoryTest.php b/dev/tests/unit/testsuite/Magento/Tools/Di/App/Task/OperationFactoryTest.php index 359adca36a68a1d9bf117662bf270058d4822926..450f3c187a58179721e069173e395e66832628f7 100644 --- a/dev/tests/unit/testsuite/Magento/Tools/Di/App/Task/OperationFactoryTest.php +++ b/dev/tests/unit/testsuite/Magento/Tools/Di/App/Task/OperationFactoryTest.php @@ -65,7 +65,7 @@ class OperationFactoryTest extends \PHPUnit_Framework_TestCase public function aliasesDataProvider() { return [ - [OperationFactory::AREA, [], 'Magento\Tools\Di\App\Task\Operation\Area'], + [OperationFactory::AREA_CONFIG_GENERATOR, [], 'Magento\Tools\Di\App\Task\Operation\Area'], [OperationFactory::INTERCEPTION, null, 'Magento\Tools\Di\App\Task\Operation\Interception'], [OperationFactory::INTERCEPTION_CACHE, 1, 'Magento\Tools\Di\App\Task\Operation\InterceptionCache'], ]; diff --git a/dev/tests/unit/testsuite/Magento/Tools/Di/Code/Generator/InterceptionConfigurationBuilderTest.php b/dev/tests/unit/testsuite/Magento/Tools/Di/Code/Generator/InterceptionConfigurationBuilderTest.php index 43ada6efbcdf42d37d238186dba8825e3e177098..c7b69e58ed1d29de0b596dd8dce2c9e4970a4a99 100644 --- a/dev/tests/unit/testsuite/Magento/Tools/Di/Code/Generator/InterceptionConfigurationBuilderTest.php +++ b/dev/tests/unit/testsuite/Magento/Tools/Di/Code/Generator/InterceptionConfigurationBuilderTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Tools\Di\Code\Generator; +use Magento\Framework\App\Interception\Cache\CompiledConfig; + class InterceptionConfigurationBuilderTest extends \PHPUnit_Framework_TestCase { /** @@ -26,6 +28,11 @@ class InterceptionConfigurationBuilderTest extends \PHPUnit_Framework_TestCase */ protected $typeReader; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $cacheManager; + protected function setUp() { $this->interceptionConfig = $this->getMock( @@ -42,11 +49,20 @@ class InterceptionConfigurationBuilderTest extends \PHPUnit_Framework_TestCase '', false ); + $this->cacheManager = $this->getMock( + 'Magento\Framework\App\Cache\Manager', + [], + [], + '', + false + ); + $this->typeReader = $this->getMock('Magento\Tools\Di\Code\Reader\Type', ['isConcrete'], [], '', false); $this->model = new \Magento\Tools\Di\Code\Generator\InterceptionConfigurationBuilder( $this->interceptionConfig, $this->pluginList, - $this->typeReader + $this->typeReader, + $this->cacheManager ); } @@ -66,6 +82,9 @@ class InterceptionConfigurationBuilderTest extends \PHPUnit_Framework_TestCase ['Class1', true], ['instance', true], ]); + $this->cacheManager->expects($this->once()) + ->method('setEnabled') + ->with([CompiledConfig::TYPE_IDENTIFIER], true); $this->pluginList->expects($this->once()) ->method('setInterceptedClasses') ->with($definedClasses); diff --git a/dev/tests/unit/testsuite/Magento/Tools/Di/Compiler/Config/Chain/InterceptorSubstitutionTest.php b/dev/tests/unit/testsuite/Magento/Tools/Di/Compiler/Config/Chain/InterceptorSubstitutionTest.php new file mode 100644 index 0000000000000000000000000000000000000000..af2179d4b59ceb1739a97c0fa0a76f4700c50e4b --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Tools/Di/Compiler/Config/Chain/InterceptorSubstitutionTest.php @@ -0,0 +1,108 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Tools\Di\Compiler\Config\Chain; + +class InterceptorSubstitutionTest extends \PHPUnit_Framework_TestCase +{ + public function testModifyArgumentsDoNotExist() + { + $inputConfig = [ + 'data' => [] + ]; + $modifier = new InterceptorSubstitution(); + $this->assertSame($inputConfig, $modifier->modify($inputConfig)); + } + + public function testModifyArguments() + { + $modifier = new InterceptorSubstitution(); + $this->assertEquals($this->getOutputConfig(), $modifier->modify($this->getInputConfig())); + } + + + /** + * Input config + * + * @return array + */ + private function getInputConfig() + { + return [ + 'arguments' => [ + 'Class' => [ + 'argument_type' => ['_i_' => 'Class\Dependency'], + 'argument_not_shared' => ['_ins_' => 'Class\Dependency'], + 'array_configured' => [ + 'argument_type' => ['_i_' => 'Class\Dependency'], + 'argument_not_shared' => ['_ins_' => 'Class\Dependency'], + 'array' => [ + 'argument_type' => ['_i_' => 'Class\Dependency'], + 'argument_not_shared' => ['_ins_' => 'Class\DependencyIntercepted'], + ] + ] + ], + 'virtualType' => [ + 'argument_type' => ['_i_' => 'Class\DependencyIntercepted'], + 'argument_not_shared' => ['_ins_' => 'Class\Dependency'], + 'array_configured' => ['banana'] + ], + 'Class\Interceptor' => [ + 'argument_type' => ['_i_' => 'Class\Dependency'], + 'argument_not_shared' => ['_ins_' => 'Class\Dependency'], + 'array_configured' => [] + ], + + 'Class\DependencyIntercepted\Interceptor' => [], + 'Class\DependencyIntercepted' => [] + ], + 'preferences' => [ + 'ClassInterface' => 'Class', + ], + 'instanceTypes' => [ + 'virtualType' => 'Class' + ] + ]; + } + + /** + * Output config + * + * @return array + */ + private function getOutputConfig() + { + return [ + 'arguments' => [ + 'Class\Interceptor' => [ + 'argument_type' => ['_i_' => 'Class\Dependency'], + 'argument_not_shared' => ['_ins_' => 'Class\Dependency'], + 'array_configured' => [ + 'argument_type' => ['_i_' => 'Class\Dependency'], + 'argument_not_shared' => ['_ins_' => 'Class\Dependency'], + 'array' => [ + 'argument_type' => ['_i_' => 'Class\Dependency'], + 'argument_not_shared' => ['_ins_' => 'Class\DependencyIntercepted'], + ] + ] + ], + 'virtualType' => [ + 'argument_type' => ['_i_' => 'Class\DependencyIntercepted'], + 'argument_not_shared' => ['_ins_' => 'Class\Dependency'], + 'array_configured' => ['banana'] + ], + 'Class\DependencyIntercepted\Interceptor' => [] + ], + 'preferences' => [ + 'ClassInterface' => 'Class\Interceptor', + 'Class' => 'Class\Interceptor', + 'Class\DependencyIntercepted' => 'Class\DependencyIntercepted\Interceptor' + ], + 'instanceTypes' => [ + 'virtualType' => 'Class\Interceptor', + ] + ]; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Tools/Di/Compiler/Config/Chain/PreferencesResolvingTest.php b/dev/tests/unit/testsuite/Magento/Tools/Di/Compiler/Config/Chain/PreferencesResolvingTest.php index 773809d3902beacd33efa9981afd5eea67fa510e..3718cbd1a2c39bf422595bb4524e920b149b25e8 100644 --- a/dev/tests/unit/testsuite/Magento/Tools/Di/Compiler/Config/Chain/PreferencesResolvingTest.php +++ b/dev/tests/unit/testsuite/Magento/Tools/Di/Compiler/Config/Chain/PreferencesResolvingTest.php @@ -127,7 +127,7 @@ class PreferencesResolvingTest extends \PHPUnit_Framework_TestCase '_ins_' => 'Type\Dependency\Configured', ], 'type_dependency_shared_configured' => [ - '_i_' => 'Type\Dependency\Shared\Configured', + '_i_' => 'Type\Dependency\Shared\ConfiguredPreference', ], 'global_argument' => [ '_a_' => 'global_argument_configured', @@ -144,12 +144,12 @@ class PreferencesResolvingTest extends \PHPUnit_Framework_TestCase '_vac_' => [ 'array_value' => 'value', 'array_configured_instance' => [ - '_i_' => 'Type\Dependency\Shared\Configured', + '_i_' => 'Type\Dependency\Shared\ConfiguredPreference', ], 'array_configured_array' => [ 'array_array_value' => 'value', 'array_array_configured_instance' => [ - '_ins_' => 'Type\Dependency\Shared\Configured', + '_ins_' => 'Type\Dependency\Shared\ConfiguredPreference', ], ], 'array_global_argument' => [ @@ -174,7 +174,8 @@ class PreferencesResolvingTest extends \PHPUnit_Framework_TestCase 'Type\DependencyInterface' => 'Type\Dependency', 'Type\Dependency\SharedInterface' => 'Type\Dependency\Shared', 'Type\Dependency\ConfiguredInterface' => 'Type\Dependency\Configured', - 'Type\Dependency\Shared\ConfiguredInterface' => 'Type\Dependency\Shared\Configured', + 'Type\Dependency\Shared\ConfiguredInterface' => 'Type\Dependency\Shared\ConfiguredPreference', + 'Type\Dependency\Shared\Configured' => 'Type\Dependency\Shared\ConfiguredPreference', ]; } } diff --git a/dev/tools/Magento/Tools/Di/App/Compiler.php b/dev/tools/Magento/Tools/Di/App/Compiler.php index 1c266051fdc1874ef564a30ca59562136ce97ce3..f8f65ad42b476f12144ed943559637d0206ff045 100644 --- a/dev/tools/Magento/Tools/Di/App/Compiler.php +++ b/dev/tools/Magento/Tools/Di/App/Compiler.php @@ -66,14 +66,25 @@ class Compiler implements \Magento\Framework\AppInterface 'Magento\Tools\Di\Compiler\Config\ModificationChain' => [ 'arguments' => [ 'modificationsList' => [ - 'PreferencesResolving' => - ['instance' => 'Magento\Tools\Di\Compiler\Config\Chain\PreferencesResolving'], 'BackslashTrim' => ['instance' => 'Magento\Tools\Di\Compiler\Config\Chain\BackslashTrim'], + 'PreferencesResolving' => + ['instance' => 'Magento\Tools\Di\Compiler\Config\Chain\PreferencesResolving'], + 'InterceptorSubstitution' => + ['instance' => 'Magento\Tools\Di\Compiler\Config\Chain\InterceptorSubstitution'], + 'InterceptionPreferencesResolving' => + ['instance' => 'Magento\Tools\Di\Compiler\Config\Chain\PreferencesResolving'], 'ArgumentsSerialization' => ['instance' => 'Magento\Tools\Di\Compiler\Config\Chain\ArgumentsSerialization'], ] ] + ], + 'Magento\Tools\Di\Code\Generator\PluginList' => [ + 'arguments' => [ + 'cache' => [ + 'instance' => 'Magento\Framework\App\Interception\Cache\CompiledConfig' + ] + ] ] ] ); @@ -83,11 +94,14 @@ class Compiler implements \Magento\Framework\AppInterface 'path' => BP . '/' . 'app/code', 'filePatterns' => ['di' => '/\/etc\/([a-zA-Z_]*\/di|di)\.xml$/'] ], - Task\OperationFactory::AREA => [ - BP . '/' . 'app/code', BP . '/' . 'lib/internal/Magento/Framework', BP . '/' . 'var/generation' + Task\OperationFactory::APPLICATION_CODE_GENERATOR => [ + BP . '/' . 'app/code', BP . '/' . 'lib/internal/Magento/Framework', BP . '/' . 'var/generation' ], Task\OperationFactory::INTERCEPTION => BP . '/var/generation', + Task\OperationFactory::AREA_CONFIG_GENERATOR => [ + BP . '/' . 'app/code', BP . '/' . 'lib/internal/Magento/Framework', BP . '/' . 'var/generation' + ], Task\OperationFactory::INTERCEPTION_CACHE => [ BP . '/' . 'app/code', BP . '/' . 'lib/internal/Magento/Framework', BP . '/' . 'var/generation' ] diff --git a/dev/tools/Magento/Tools/Di/App/Task/Operation/ApplicationCodeGenerator.php b/dev/tools/Magento/Tools/Di/App/Task/Operation/ApplicationCodeGenerator.php new file mode 100644 index 0000000000000000000000000000000000000000..21b24e52c91a028629b5e2973b642836e9469e13 --- /dev/null +++ b/dev/tools/Magento/Tools/Di/App/Task/Operation/ApplicationCodeGenerator.php @@ -0,0 +1,48 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Tools\Di\App\Task\Operation; + +use Magento\Tools\Di\App\Task\OperationInterface; +use Magento\Tools\Di\Code\Reader\ClassesScanner; + +class ApplicationCodeGenerator implements OperationInterface +{ + /** + * @var array + */ + private $data = []; + + /** + * @var ClassesScanner + */ + private $classesScanner; + + /** + * @param ClassesScanner $classesScanner + * @param array $data + */ + public function __construct( + ClassesScanner $classesScanner, + $data = [] + ) { + $this->data = $data; + $this->classesScanner = $classesScanner; + } + + /** + * {@inheritdoc} + */ + public function doOperation() + { + if (empty($this->data)) { + return; + } + + foreach ($this->data as $path) { + $this->classesScanner->getList($path); + } + } +} diff --git a/dev/tools/Magento/Tools/Di/App/Task/Operation/Area.php b/dev/tools/Magento/Tools/Di/App/Task/Operation/Area.php index 3639bd996da8a0cfe29bdc65551b41f9594ebd76..2cda2f6edcd41ea4b2c7f2f0bdc381296aae160f 100644 --- a/dev/tools/Magento/Tools/Di/App/Task/Operation/Area.php +++ b/dev/tools/Magento/Tools/Di/App/Task/Operation/Area.php @@ -7,7 +7,6 @@ namespace Magento\Tools\Di\App\Task\Operation; use Magento\Tools\Di\App\Task\OperationInterface; use Magento\Framework\App; -use Magento\Tools\Di\Code\Reader\ClassesScanner; use Magento\Tools\Di\Compiler\Config; use Magento\Tools\Di\Definition\Collection as DefinitionsCollection; diff --git a/dev/tools/Magento/Tools/Di/App/Task/Operation/InterceptionCache.php b/dev/tools/Magento/Tools/Di/App/Task/Operation/InterceptionCache.php index 1a42794f21ce620eb7ccd965b659a7ca2dd79200..3a060fdeb8e6c7c3453bf9142158794214b8ddfe 100644 --- a/dev/tools/Magento/Tools/Di/App/Task/Operation/InterceptionCache.php +++ b/dev/tools/Magento/Tools/Di/App/Task/Operation/InterceptionCache.php @@ -25,21 +25,18 @@ class InterceptionCache implements OperationInterface private $interceptionsInstancesNamesList; /** - * @param \Magento\Framework\Interception\Config\Config $configInterface - * @param \Magento\Tools\Di\Code\Reader\ClassesScanner $classesScanner + * @param \Magento\Framework\Interception\Config\Config $configInterface * @param \Magento\Tools\Di\Code\Reader\InstancesNamesList\Interceptions $interceptionsInstancesNamesList - * @param array $data + * @param array $data */ public function __construct( \Magento\Framework\Interception\Config\Config $configInterface, - \Magento\Tools\Di\Code\Reader\ClassesScanner $classesScanner, \Magento\Tools\Di\Code\Reader\InstancesNamesList\Interceptions $interceptionsInstancesNamesList, array $data = [] ) { - $this->data = $data; $this->configInterface = $configInterface; - $this->classesScanner = $classesScanner; $this->interceptionsInstancesNamesList = $interceptionsInstancesNamesList; + $this->data = $data; } /** @@ -55,9 +52,7 @@ class InterceptionCache implements OperationInterface $definitions = []; foreach ($this->data as $path) { - if (is_readable($path)) { - array_merge($definitions, $this->interceptionsInstancesNamesList->getList($path)); - } + $definitions = array_merge($definitions, $this->interceptionsInstancesNamesList->getList($path)); } $this->configInterface->initialize($definitions); diff --git a/dev/tools/Magento/Tools/Di/App/Task/OperationFactory.php b/dev/tools/Magento/Tools/Di/App/Task/OperationFactory.php index f66328ea80e6c9a17e26711a39bdcc1526ced6ff..94fc7702689755f8e9d7477df0cf72eba40739e3 100644 --- a/dev/tools/Magento/Tools/Di/App/Task/OperationFactory.php +++ b/dev/tools/Magento/Tools/Di/App/Task/OperationFactory.php @@ -15,7 +15,7 @@ class OperationFactory /** * Area */ - const AREA = 'area'; + const AREA_CONFIG_GENERATOR = 'area'; /** * Interception @@ -32,13 +32,19 @@ class OperationFactory */ const REPOSITORY_GENERATOR = 'repository_generator'; + /** + * Application code generator + */ + const APPLICATION_CODE_GENERATOR = 'application_code_generator'; + /** * Operations definitions * * @var array */ private $operationsDefinitions = [ - self::AREA => 'Magento\Tools\Di\App\Task\Operation\Area', + self::AREA_CONFIG_GENERATOR => 'Magento\Tools\Di\App\Task\Operation\Area', + self::APPLICATION_CODE_GENERATOR => 'Magento\Tools\Di\App\Task\Operation\ApplicationCodeGenerator', self::INTERCEPTION => 'Magento\Tools\Di\App\Task\Operation\Interception', self::INTERCEPTION_CACHE => 'Magento\Tools\Di\App\Task\Operation\InterceptionCache', self::REPOSITORY_GENERATOR => 'Magento\Tools\Di\App\Task\Operation\RepositoryGenerator' diff --git a/dev/tools/Magento/Tools/Di/Code/Generator/InterceptionConfigurationBuilder.php b/dev/tools/Magento/Tools/Di/Code/Generator/InterceptionConfigurationBuilder.php index 5739bab9ca37e9caa74a4ed863a933984298418c..550fee79364ff7eb7a6585616cb3147fd33db706 100644 --- a/dev/tools/Magento/Tools/Di/Code/Generator/InterceptionConfigurationBuilder.php +++ b/dev/tools/Magento/Tools/Di/Code/Generator/InterceptionConfigurationBuilder.php @@ -8,6 +8,8 @@ namespace Magento\Tools\Di\Code\Generator; use Magento\Framework\App\Area; +use Magento\Framework\App\Cache\Manager; +use Magento\Framework\App\Interception\Cache\CompiledConfig; use Magento\Framework\Interception\Config\Config as InterceptionConfig; use Magento\Tools\Di\Code\Reader\Type; @@ -35,16 +37,27 @@ class InterceptionConfigurationBuilder */ private $typeReader; + /** + * @var Manager + */ + private $cacheManager; + /** * @param InterceptionConfig $interceptionConfig * @param PluginList $pluginList * @param Type $typeReader + * @param Manager $cacheManager */ - public function __construct(InterceptionConfig $interceptionConfig, PluginList $pluginList, Type $typeReader) - { + public function __construct( + InterceptionConfig $interceptionConfig, + PluginList $pluginList, + Type $typeReader, + Manager $cacheManager + ) { $this->interceptionConfig = $interceptionConfig; $this->pluginList = $pluginList; $this->typeReader = $typeReader; + $this->cacheManager = $cacheManager; } /** @@ -102,6 +115,7 @@ class InterceptionConfigurationBuilder */ private function getPluginsList($interceptedInstances) { + $this->cacheManager->setEnabled([CompiledConfig::TYPE_IDENTIFIER], true); $this->pluginList->setInterceptedClasses($interceptedInstances); $inheritedConfig = []; diff --git a/dev/tools/Magento/Tools/Di/Code/Generator/PluginList.php b/dev/tools/Magento/Tools/Di/Code/Generator/PluginList.php index 6d328fbeb668865f4748f090080296e012f1208f..d59f9525b1340f04c5a815fbeddc392900faf765 100644 --- a/dev/tools/Magento/Tools/Di/Code/Generator/PluginList.php +++ b/dev/tools/Magento/Tools/Di/Code/Generator/PluginList.php @@ -11,6 +11,11 @@ use Magento\Framework\Interception; class PluginList extends Interception\PluginList\PluginList { + /** + * @var array + */ + private $interceptedClasses; + /** * Returns plugins config * diff --git a/dev/tools/Magento/Tools/Di/Code/Reader/InstancesNamesList/Area.php b/dev/tools/Magento/Tools/Di/Code/Reader/InstancesNamesList/Area.php index 1fae763a1eed26b18214efc41010accac1df9a9a..7143d136e12ec07b02bba3b8378f66841cbcbe8f 100644 --- a/dev/tools/Magento/Tools/Di/Code/Reader/InstancesNamesList/Area.php +++ b/dev/tools/Magento/Tools/Di/Code/Reader/InstancesNamesList/Area.php @@ -5,6 +5,10 @@ */ namespace Magento\Tools\Di\Code\Reader\InstancesNamesList; +use Magento\Tools\Di\Code\Reader\ClassesScanner; +use Magento\Tools\Di\Code\Reader\ClassReaderDecorator; +use Magento\Framework\Filesystem\FilesystemException; + /** * Class Area * @@ -13,22 +17,22 @@ namespace Magento\Tools\Di\Code\Reader\InstancesNamesList; class Area implements \Magento\Tools\Di\Code\Reader\InstancesNamesListInterface { /** - * @var \Magento\Tools\Di\Code\Reader\ClassReaderDecorator + * @var ClassReaderDecorator */ private $classReaderDecorator; /** - * @var \Magento\Tools\Di\Code\Reader\ClassesScanner + * @var ClassesScanner */ private $classesScanner; /** - * @param \Magento\Tools\Di\Code\Reader\ClassesScanner $classesScanner - * @param \Magento\Tools\Di\Code\Reader\ClassReaderDecorator $classReaderDecorator + * @param ClassesScanner $classesScanner + * @param ClassReaderDecorator $classReaderDecorator */ public function __construct( - \Magento\Tools\Di\Code\Reader\ClassesScanner $classesScanner, - \Magento\Tools\Di\Code\Reader\ClassReaderDecorator $classReaderDecorator + ClassesScanner $classesScanner, + ClassReaderDecorator $classReaderDecorator ) { $this->classReaderDecorator = $classReaderDecorator; $this->classesScanner = $classesScanner; @@ -40,7 +44,7 @@ class Area implements \Magento\Tools\Di\Code\Reader\InstancesNamesListInterface * @param string $path path to dir with files * * @return array - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws FilesystemException */ public function getList($path) { diff --git a/dev/tools/Magento/Tools/Di/Compiler/Config/Chain/InterceptorSubstitution.php b/dev/tools/Magento/Tools/Di/Compiler/Config/Chain/InterceptorSubstitution.php new file mode 100644 index 0000000000000000000000000000000000000000..26e6464858f590aa6b7ec639c495f213c7ffff89 --- /dev/null +++ b/dev/tools/Magento/Tools/Di/Compiler/Config/Chain/InterceptorSubstitution.php @@ -0,0 +1,86 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Tools\Di\Compiler\Config\Chain; + +use Magento\Tools\Di\Compiler\Config\ModificationInterface; + +class InterceptorSubstitution implements ModificationInterface +{ + /** + * Modifies input config + * + * @param array $config + * @return array + */ + public function modify(array $config) + { + $configKeys = [ + 'arguments', + 'preferences', + 'instanceTypes' + ]; + if ($configKeys != array_keys($config)) { + return $config; + } + + $interceptors = $this->getInterceptorsList($config['arguments']); + + $config['arguments'] = array_diff_key($config['arguments'], array_flip($interceptors)); + + foreach ($interceptors as $originalName => $interceptor) { + if (isset($config['arguments'][$originalName])) { + $config['arguments'][$interceptor] = $config['arguments'][$originalName]; + unset($config['arguments'][$originalName]); + } + } + + $config['preferences'] = $this->resolvePreferences($config['preferences'], $interceptors); + + $config['preferences'] = array_merge($config['preferences'], $interceptors); + $config['instanceTypes'] = $this->resolvePreferences($config['instanceTypes'], $interceptors); + + + + return $config; + } + + /** + * Returns list of intercepted types and their interceptors + * + * @param array $arguments + * @return array + */ + private function getInterceptorsList(array $arguments) + { + $interceptors = []; + + foreach (array_keys($arguments) as $instanceName) { + if (substr($instanceName, -12) === '\Interceptor') { + $originalName = substr($instanceName, 0, strlen($instanceName) - 12); + $interceptors[$originalName] = $instanceName; + } + } + + return $interceptors; + } + + /** + * Resolves config preferences + * + * @param array $preferences + * @param array $interceptors + * @return array + */ + private function resolvePreferences(array $preferences, array $interceptors) + { + foreach ($preferences as &$preference) { + if (isset($interceptors[$preference])) { + $preference = $interceptors[$preference]; + } + } + return $preferences; + } +} diff --git a/lib/internal/Magento/Framework/Api/Builder.php b/lib/internal/Magento/Framework/Api/Builder.php index 8096e4722c257993b248cbdba9f83febfe458754..9b7338a54e2788624477f5131966860e36b4b845 100644 --- a/lib/internal/Magento/Framework/Api/Builder.php +++ b/lib/internal/Magento/Framework/Api/Builder.php @@ -265,7 +265,7 @@ class Builder implements BuilderInterface } elseif (is_subclass_of($dataType, '\Magento\Framework\Model\AbstractExtensibleModel')) { return self::TYPE_DATA_MODEL; } - + $dataType = ltrim($dataType, '\\'); $sourceClassPreference = $this->objectManagerConfig->getPreference($dataType); if (empty($sourceClassPreference)) { throw new \LogicException( diff --git a/lib/internal/Magento/Framework/App/Area.php b/lib/internal/Magento/Framework/App/Area.php index cbb8d5a5901a72a18bc9138710ed2d21749b9172..4131b995009d93fd0d22eacf69f65d1664519f23 100644 --- a/lib/internal/Magento/Framework/App/Area.php +++ b/lib/internal/Magento/Framework/App/Area.php @@ -6,6 +6,8 @@ namespace Magento\Framework\App; +use Magento\Framework\ObjectManager\ConfigLoaderInterface; + /** * Application area model */ @@ -58,7 +60,7 @@ class Area implements \Magento\Framework\App\AreaInterface protected $_objectManager; /** - * @var \Magento\Framework\App\ObjectManager\ConfigLoader + * @var ConfigLoaderInterface */ protected $_diConfigLoader; @@ -89,7 +91,7 @@ class Area implements \Magento\Framework\App\AreaInterface * @param \Magento\Framework\Event\ManagerInterface $eventManager * @param \Magento\Framework\TranslateInterface $translator * @param \Magento\Framework\ObjectManagerInterface $objectManager - * @param \Magento\Framework\App\ObjectManager\ConfigLoader $diConfigLoader + * @param ConfigLoaderInterface $diConfigLoader * @param \Magento\Framework\App\DesignInterface $design * @param \Magento\Framework\App\ScopeResolverInterface $scopeResolver * @param \Magento\Framework\View\DesignExceptions $designExceptions @@ -100,7 +102,7 @@ class Area implements \Magento\Framework\App\AreaInterface \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\TranslateInterface $translator, \Magento\Framework\ObjectManagerInterface $objectManager, - \Magento\Framework\App\ObjectManager\ConfigLoader $diConfigLoader, + ConfigLoaderInterface $diConfigLoader, \Magento\Framework\App\DesignInterface $design, \Magento\Framework\App\ScopeResolverInterface $scopeResolver, \Magento\Framework\View\DesignExceptions $designExceptions, diff --git a/lib/internal/Magento/Framework/ObjectManager/EnvironmentFactory.php b/lib/internal/Magento/Framework/App/EnvironmentFactory.php similarity index 78% rename from lib/internal/Magento/Framework/ObjectManager/EnvironmentFactory.php rename to lib/internal/Magento/Framework/App/EnvironmentFactory.php index 3d26f4239b6ad7123ae2ebebb9e8b79d179147ba..0624b0c29ec276dadf820d740c49e1902b08aa9e 100644 --- a/lib/internal/Magento/Framework/ObjectManager/EnvironmentFactory.php +++ b/lib/internal/Magento/Framework/App/EnvironmentFactory.php @@ -3,10 +3,13 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\ObjectManager; +namespace Magento\Framework\App; -use Magento\Framework\ObjectManager\Environment\Compiled; -use Magento\Framework\ObjectManager\Environment\Developer; +use Magento\Framework\App\ObjectManager\Environment\Compiled; +use Magento\Framework\App\ObjectManager\Environment\Developer; +use Magento\Framework\App\ObjectManager\ConfigLoader; +use Magento\Framework\ObjectManager\RelationsInterface; +use Magento\Framework\ObjectManager\DefinitionInterface; class EnvironmentFactory { @@ -55,7 +58,7 @@ class EnvironmentFactory */ private function getMode() { - if (file_exists(Compiled::getFilePath())) { + if (file_exists(ConfigLoader\Compiled::getFilePath(Area::AREA_GLOBAL))) { return Compiled::MODE; } diff --git a/lib/internal/Magento/Framework/ObjectManager/EnvironmentInterface.php b/lib/internal/Magento/Framework/App/EnvironmentInterface.php similarity index 55% rename from lib/internal/Magento/Framework/ObjectManager/EnvironmentInterface.php rename to lib/internal/Magento/Framework/App/EnvironmentInterface.php index 494981fef3a1570ae628bbb3e2662fc8e7109875..32247a659d859c8c76b92fc4a542ab9f69057887 100644 --- a/lib/internal/Magento/Framework/ObjectManager/EnvironmentInterface.php +++ b/lib/internal/Magento/Framework/App/EnvironmentInterface.php @@ -4,7 +4,11 @@ * See COPYING.txt for license details. */ -namespace Magento\Framework\ObjectManager; +namespace Magento\Framework\App; + +use Magento\Framework\ObjectManager\FactoryInterface; +use Magento\Framework\Interception\ObjectManager\ConfigInterface; +use Magento\Framework\ObjectManager\ConfigLoaderInterface; /** * Interface for ObjectManager Environment @@ -21,7 +25,7 @@ interface EnvironmentInterface /** * Return config object * - * @return \Magento\Framework\Interception\ObjectManager\ConfigInterface + * @return ConfigInterface */ public function getDiConfig(); @@ -29,14 +33,21 @@ interface EnvironmentInterface * Return factory object * * @param array $arguments - * @return Factory\AbstractFactory + * @return FactoryInterface */ public function getObjectManagerFactory($arguments); /** * Return ConfigLoader object * - * @return \Magento\Framework\App\ObjectManager\ConfigLoader | null + * @return ConfigLoaderInterface */ public function getObjectManagerConfigLoader(); + + /** + * @param ConfigInterface $diConfig + * @param array &$sharedInstances + * @return void + */ + public function configureObjectManager(ConfigInterface $diConfig, &$sharedInstances); } diff --git a/lib/internal/Magento/Framework/App/Http.php b/lib/internal/Magento/Framework/App/Http.php index 5bc869596bf7885edcd75647846bde9e87f0f6a5..54a71efa0c038bf015b91fa505fc73dd37cad368 100644 --- a/lib/internal/Magento/Framework/App/Http.php +++ b/lib/internal/Magento/Framework/App/Http.php @@ -8,7 +8,7 @@ namespace Magento\Framework\App; use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Framework\App\ObjectManager\ConfigLoader; +use Magento\Framework\ObjectManager\ConfigLoaderInterface; use Magento\Framework\App\Request\Http as RequestHttp; use Magento\Framework\App\Response\Http as ResponseHttp; use Magento\Framework\App\Response\HttpInterface; @@ -42,7 +42,7 @@ class Http implements \Magento\Framework\AppInterface protected $_request; /** - * @var ConfigLoader + * @var ConfigLoaderInterface */ protected $_configLoader; @@ -72,7 +72,7 @@ class Http implements \Magento\Framework\AppInterface * @param AreaList $areaList * @param RequestHttp $request * @param ResponseHttp $response - * @param ConfigLoader $configLoader + * @param ConfigLoaderInterface $configLoader * @param State $state * @param Filesystem $filesystem, * @param \Magento\Framework\Registry $registry @@ -83,7 +83,7 @@ class Http implements \Magento\Framework\AppInterface AreaList $areaList, RequestHttp $request, ResponseHttp $response, - ConfigLoader $configLoader, + ConfigLoaderInterface $configLoader, State $state, Filesystem $filesystem, \Magento\Framework\Registry $registry diff --git a/lib/internal/Magento/Framework/App/Interception/Cache/CompiledConfig.php b/lib/internal/Magento/Framework/App/Interception/Cache/CompiledConfig.php new file mode 100644 index 0000000000000000000000000000000000000000..b9121520679630219aa9af10a9343cb0945facb1 --- /dev/null +++ b/lib/internal/Magento/Framework/App/Interception/Cache/CompiledConfig.php @@ -0,0 +1,31 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\App\Interception\Cache; + +use Magento\Framework\Cache\Frontend\Decorator\TagScope; +use Magento\Framework\Config\CacheInterface; +use Magento\Framework\App\Cache\Type\FrontendPool; + +class CompiledConfig extends TagScope implements CacheInterface +{ + /** + * Cache type code unique among all cache types + */ + const TYPE_IDENTIFIER = 'compiled_config'; + + /** + * Cache tag used to distinguish the cache type from all other cache + */ + const CACHE_TAG = 'COMPILED_CONFIG'; + + /** + * @param FrontendPool $cacheFrontendPool + */ + public function __construct(FrontendPool $cacheFrontendPool) + { + parent::__construct($cacheFrontendPool->get(self::TYPE_IDENTIFIER), self::CACHE_TAG); + } +} diff --git a/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader.php b/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader.php index a013a6aa4126c7f32d753a01fe4007cc6401c80c..cdedbbcc9c608c87abfe3f2f9fa4fcfd324dc619 100644 --- a/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader.php +++ b/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader.php @@ -7,7 +7,9 @@ */ namespace Magento\Framework\App\ObjectManager; -class ConfigLoader +use Magento\Framework\ObjectManager\ConfigLoaderInterface; + +class ConfigLoader implements ConfigLoaderInterface { /** * Config reader @@ -56,10 +58,7 @@ class ConfigLoader } /** - * Load modules DI configuration - * - * @param string $area - * @return array + * {inheritdoc} */ public function load($area) { diff --git a/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php b/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php index a29062ab9b57507a7529d03460d92587f78c306e..b3375d770045231e1f1fc3f4f68a300785b2b3db 100644 --- a/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php +++ b/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php @@ -6,38 +6,37 @@ */ namespace Magento\Framework\App\ObjectManager\ConfigLoader; -use Magento\Framework\App\Area; +use Magento\Framework\ObjectManager\ConfigLoaderInterface; -class Compiled extends \Magento\Framework\App\ObjectManager\ConfigLoader +class Compiled implements ConfigLoaderInterface { /** * Global config * * @var array */ - private $globalConfig = []; + private $configCache = []; /** - * Compiled construct - * - * @param array $globalConfig + * {inheritdoc} */ - public function __construct(array $globalConfig = []) + public function load($area) { - $this->globalConfig = $globalConfig; + if (isset($this->configCache[$area])) { + return $this->configCache[$area]; + } + $this->configCache[$area] = \unserialize(\file_get_contents(self::getFilePath($area))); + return $this->configCache[$area]; } /** - * Load modules DI configuration + * Returns path to cached configuration * * @param string $area - * @return array|mixed + * @return string */ - public function load($area) + public static function getFilePath($area) { - if ($area == Area::AREA_GLOBAL) { - return $this->globalConfig; - } - return \unserialize(\file_get_contents(BP . '/var/di/' . $area . '.ser')); + return BP . '/var/di/' . $area . '.ser'; } } diff --git a/lib/internal/Magento/Framework/ObjectManager/Environment/AbstractEnvironment.php b/lib/internal/Magento/Framework/App/ObjectManager/Environment/AbstractEnvironment.php similarity index 84% rename from lib/internal/Magento/Framework/ObjectManager/Environment/AbstractEnvironment.php rename to lib/internal/Magento/Framework/App/ObjectManager/Environment/AbstractEnvironment.php index ef821a36ac18de5b6110531faeb8f673d551cb80..bc03b05a1cfebf8164ae5a125f3c16498820e6fb 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Environment/AbstractEnvironment.php +++ b/lib/internal/Magento/Framework/App/ObjectManager/Environment/AbstractEnvironment.php @@ -4,17 +4,19 @@ * See COPYING.txt for license details. */ -namespace Magento\Framework\ObjectManager\Environment; +namespace Magento\Framework\App\ObjectManager\Environment; -use Magento\Framework\ObjectManager\EnvironmentFactory; -use Magento\Framework\ObjectManager\EnvironmentInterface; +use Magento\Framework\App\EnvironmentFactory; +use Magento\Framework\Interception\ObjectManager\ConfigInterface; +use Magento\Framework\App\EnvironmentInterface; use Magento\Framework\ObjectManager\Profiler\FactoryDecorator; use Magento\Framework\ObjectManager\FactoryInterface; +use Magento\Framework\ObjectManager\Profiler\Log; abstract class AbstractEnvironment implements EnvironmentInterface { /** - * @var \Magento\Framework\Interception\ObjectManager\ConfigInterface + * @var ConfigInterface */ protected $config; @@ -50,7 +52,7 @@ abstract class AbstractEnvironment implements EnvironmentInterface * Returns object manager factory * * @param array $arguments - * @return \Magento\Framework\ObjectManager\Factory\AbstractFactory + * @return FactoryInterface */ public function getObjectManagerFactory($arguments) { @@ -83,7 +85,7 @@ abstract class AbstractEnvironment implements EnvironmentInterface if (isset($arguments['MAGE_PROFILER']) && $arguments['MAGE_PROFILER'] == 2) { $this->factory = new FactoryDecorator( $this->factory, - \Magento\Framework\ObjectManager\Profiler\Log::getInstance() + Log::getInstance() ); } } diff --git a/lib/internal/Magento/Framework/App/ObjectManager/Environment/Compiled.php b/lib/internal/Magento/Framework/App/ObjectManager/Environment/Compiled.php new file mode 100644 index 0000000000000000000000000000000000000000..6718dc4d11830d54741acc73a1788d8482933b70 --- /dev/null +++ b/lib/internal/Magento/Framework/App/ObjectManager/Environment/Compiled.php @@ -0,0 +1,119 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Framework\App\ObjectManager\Environment; + +use Magento\Framework\App\EnvironmentInterface; +use Magento\Framework\App\Interception\Cache\CompiledConfig; +use Magento\Framework\ObjectManager\FactoryInterface; +use Magento\Framework\App\Area; +use Magento\Framework\Interception\ObjectManager\ConfigInterface; +use Magento\Framework\App\ObjectManager; + +class Compiled extends AbstractEnvironment implements EnvironmentInterface +{ + /**#@+ + * Mode name + */ + const MODE = 'compiled'; + + protected $mode = self::MODE; + /**#@- */ + + /** + * @var string + */ + protected $configPreference = 'Magento\Framework\ObjectManager\Factory\Compiled'; + + /** + * @var \Magento\Framework\App\ObjectManager\ConfigLoader\Compiled + */ + private $configLoader; + + /** + * Creates factory + * + * @param array $arguments + * @param string $factoryClass + * + * @return FactoryInterface + */ + protected function createFactory($arguments, $factoryClass) + { + return new $factoryClass( + $this->getDiConfig(), + $arguments['shared_instances'], + $arguments + ); + } + + /** + * Returns initialized compiled config + * + * @return \Magento\Framework\Interception\ObjectManager\ConfigInterface + */ + public function getDiConfig() + { + if (!$this->config) { + $this->config = new \Magento\Framework\Interception\ObjectManager\Config\Compiled( + $this->getConfigData() + ); + } + + return $this->config; + } + + /** + * Returns config data as array + * + * @return array + */ + protected function getConfigData() + { + $this->getObjectManagerConfigLoader()->load(Area::AREA_GLOBAL); + } + + /** + * Returns new instance of compiled config loader + * + * @return \Magento\Framework\App\ObjectManager\ConfigLoader\Compiled + */ + public function getObjectManagerConfigLoader() + { + if ($this->configLoader) { + return $this->configLoader; + } + + $this->configLoader = new \Magento\Framework\App\ObjectManager\ConfigLoader\Compiled(); + return $this->configLoader; + } + + /** + * {inheritdoc} + */ + public function configureObjectManager(ConfigInterface $diConfig, &$sharedInstances) + { + $objectManager = ObjectManager::getInstance(); + + $objectManager->configure( + $objectManager + ->get('Magento\Framework\ObjectManager\ConfigLoaderInterface') + ->load(Area::AREA_GLOBAL) + ); + $objectManager->get('Magento\Framework\Config\ScopeInterface') + ->setCurrentScope('global'); + $diConfig->setInterceptionConfig( + $objectManager->get('Magento\Framework\Interception\Config\Config') + ); + $sharedInstances['Magento\Framework\Interception\PluginList\PluginList'] = $objectManager->create( + 'Magento\Framework\Interception\PluginListInterface', + ['cache' => $objectManager->get('Magento\Framework\App\Interception\Cache\CompiledConfig')] + ); + $objectManager + ->get('Magento\Framework\App\Cache\Manager') + ->setEnabled([CompiledConfig::TYPE_IDENTIFIER], true); + } +} diff --git a/lib/internal/Magento/Framework/App/ObjectManager/Environment/Developer.php b/lib/internal/Magento/Framework/App/ObjectManager/Environment/Developer.php new file mode 100644 index 0000000000000000000000000000000000000000..09d25c7de4d1b35698df97ba085f2483aa0be8bd --- /dev/null +++ b/lib/internal/Magento/Framework/App/ObjectManager/Environment/Developer.php @@ -0,0 +1,84 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Framework\App\ObjectManager\Environment; + +use Magento\Framework\App\EnvironmentInterface; +use Magento\Framework\Interception\ObjectManager\ConfigInterface; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\App\Area; + +class Developer extends AbstractEnvironment implements EnvironmentInterface +{ + /**#@+ + * Mode name + */ + const MODE = 'developer'; + protected $mode = self::MODE; + /**#@- */ + + /** + * @var ConfigInterface + */ + protected $config; + + /** + * @var string + */ + protected $configPreference = 'Magento\Framework\ObjectManager\Factory\Dynamic\Developer'; + + /** + * Returns initialized di config entity + * + * @return ConfigInterface + */ + public function getDiConfig() + { + if (!$this->config) { + $this->config = new \Magento\Framework\Interception\ObjectManager\Config\Developer( + $this->envFactory->getRelations(), + $this->envFactory->getDefinitions() + ); + } + + return $this->config; + } + + /** + * As developer environment does not have config loader, we return null + * + * @return null + */ + public function getObjectManagerConfigLoader() + { + return null; + } + + /** + * {inheritdoc} + */ + public function configureObjectManager(ConfigInterface $diConfig, &$sharedInstances) + { + $objectManager = ObjectManager::getInstance(); + $sharedInstances['Magento\Framework\ObjectManager\ConfigLoaderInterface'] = $objectManager + ->get('Magento\Framework\App\ObjectManager\ConfigLoader'); + + $diConfig->setCache( + $objectManager->get('Magento\Framework\App\ObjectManager\ConfigCache') + ); + + $objectManager->configure( + $objectManager + ->get('Magento\Framework\App\ObjectManager\ConfigLoader') + ->load(Area::AREA_GLOBAL) + ); + $objectManager->get('Magento\Framework\Config\ScopeInterface') + ->setCurrentScope('global'); + $diConfig->setInterceptionConfig( + $objectManager->get('Magento\Framework\Interception\Config\Config') + ); + } +} diff --git a/lib/internal/Magento/Framework/App/ObjectManagerFactory.php b/lib/internal/Magento/Framework/App/ObjectManagerFactory.php index 8c777c869e82417a90e684ed24db56a204feac2e..cc66aee4075bfc6361b06ff8ff424665809e845c 100644 --- a/lib/internal/Magento/Framework/App/ObjectManagerFactory.php +++ b/lib/internal/Magento/Framework/App/ObjectManagerFactory.php @@ -8,12 +8,12 @@ namespace Magento\Framework\App; use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Framework\Code\Generator\FileResolver; use Magento\Framework\Filesystem\DriverPool; +use Magento\Framework\Interception\ObjectManager\ConfigInterface; use Magento\Framework\ObjectManager\Definition\Compiled\Serialized; -use Magento\Framework\ObjectManager\Environment; -use Magento\Framework\ObjectManager\EnvironmentFactory; -use Magento\Framework\ObjectManager\EnvironmentInterface; +use Magento\Framework\App\ObjectManager\Environment; +use Magento\Framework\App\EnvironmentFactory; +use Magento\Framework\App\EnvironmentInterface; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -50,7 +50,7 @@ class ObjectManagerFactory * * @var string */ - protected $envFactoryClassName = 'Magento\Framework\ObjectManager\EnvironmentFactory'; + protected $envFactoryClassName = 'Magento\Framework\App\EnvironmentFactory'; /** * Filesystem directory list @@ -107,12 +107,12 @@ class ObjectManagerFactory $definitions = $definitionFactory->createClassDefinition($deploymentConfig->get('definitions')); $relations = $definitionFactory->createRelations(); - /** @var \Magento\Framework\ObjectManager\EnvironmentFactory $enFactory */ + /** @var EnvironmentFactory $enFactory */ $enFactory = new $this->envFactoryClassName($relations, $definitions); /** @var EnvironmentInterface $env */ $env = $enFactory->createEnvironment(); - /** @var \Magento\Framework\Interception\ObjectManager\ConfigInterface $diConfig */ + /** @var ConfigInterface $diConfig */ $diConfig = $env->getDiConfig(); $appMode = isset($arguments[State::PARAM_MODE]) ? $arguments[State::PARAM_MODE] : State::MODE_DEFAULT; @@ -152,7 +152,7 @@ class ObjectManagerFactory 'Magento\Framework\ObjectManager\DefinitionInterface' => $definitions, 'Magento\Framework\Stdlib\BooleanUtils' => $booleanUtils, 'Magento\Framework\ObjectManager\Config\Mapper\Dom' => $argumentMapper, - 'Magento\Framework\App\ObjectManager\ConfigLoader' => $env->getObjectManagerConfigLoader(), + 'Magento\Framework\ObjectManager\ConfigLoaderInterface' => $env->getObjectManagerConfigLoader(), $this->_configClassName => $diConfig, ]; $arguments['shared_instances'] = &$sharedInstances; @@ -164,18 +164,8 @@ class ObjectManagerFactory $this->factory->setObjectManager($objectManager); ObjectManager::setInstance($objectManager); - $diConfig->setCache( - $objectManager->get('Magento\Framework\App\ObjectManager\ConfigCache') - ); + $env->configureObjectManager($diConfig, $sharedInstances); - $objectManager->configure( - $objectManager->get('Magento\Framework\App\ObjectManager\ConfigLoader')->load('global') - ); - $objectManager->get('Magento\Framework\Config\ScopeInterface') - ->setCurrentScope('global'); - $diConfig->setInterceptionConfig( - $objectManager->get('Magento\Framework\Interception\Config\Config') - ); return $objectManager; } diff --git a/lib/internal/Magento/Framework/App/StaticResource.php b/lib/internal/Magento/Framework/App/StaticResource.php index 45fe01dac839dc28c47816a70c27a085eb53fd86..28600a42bd7ca3348330a385688632cdba5e3b9f 100644 --- a/lib/internal/Magento/Framework/App/StaticResource.php +++ b/lib/internal/Magento/Framework/App/StaticResource.php @@ -5,7 +5,7 @@ */ namespace Magento\Framework\App; -use Magento\Framework\App; +use Magento\Framework\ObjectManager\ConfigLoaderInterface; /** * Entry point for retrieving static resources like JS, CSS, images by requested public path @@ -50,9 +50,10 @@ class StaticResource implements \Magento\Framework\AppInterface private $objectManager; /** - * @var ObjectManager\ConfigLoader + * @var ConfigLoaderInterface */ private $configLoader; + /** * @var \Magento\Framework\View\Asset\MinifyService */ @@ -66,7 +67,7 @@ class StaticResource implements \Magento\Framework\AppInterface * @param \Magento\Framework\View\Asset\Repository $assetRepo * @param \Magento\Framework\Module\ModuleList $moduleList * @param \Magento\Framework\ObjectManagerInterface $objectManager - * @param ObjectManager\ConfigLoader $configLoader + * @param ConfigLoaderInterface $configLoader * @param \Magento\Framework\View\Asset\MinifyService $minifyService */ public function __construct( @@ -77,7 +78,7 @@ class StaticResource implements \Magento\Framework\AppInterface \Magento\Framework\View\Asset\Repository $assetRepo, \Magento\Framework\Module\ModuleList $moduleList, \Magento\Framework\ObjectManagerInterface $objectManager, - ObjectManager\ConfigLoader $configLoader, + ConfigLoaderInterface $configLoader, \Magento\Framework\View\Asset\MinifyService $minifyService ) { $this->state = $state; @@ -120,7 +121,7 @@ class StaticResource implements \Magento\Framework\AppInterface /** * {@inheritdoc} */ - public function catchException(App\Bootstrap $bootstrap, \Exception $exception) + public function catchException(Bootstrap $bootstrap, \Exception $exception) { $this->response->setHttpResponseCode(404); $this->response->setHeader('Content-Type', 'text/plain'); diff --git a/lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php b/lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php index f0cb7cd637c48d9331fad0f8d0f4e6a890eb3389..43e9e4d47ac6a26b2b1f150b25b544962d9d8f43 100644 --- a/lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php +++ b/lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php @@ -94,18 +94,8 @@ class Interceptor extends \Magento\Framework\Code\Generator\EntityAbstract return [ 'name' => '__construct', - 'parameters' => array_merge( - [ - ['name' => 'pluginLocator', 'type' => '\Magento\Framework\ObjectManagerInterface'], - ['name' => 'pluginList', 'type' => '\Magento\Framework\Interception\PluginListInterface'], - ['name' => 'chain', 'type' => '\Magento\Framework\Interception\ChainInterface'], - ], - $parameters - ), - 'body' => "\$this->pluginLocator = \$pluginLocator;\n" . - "\$this->pluginList = \$pluginList;\n" . - "\$this->chain = \$chain;\n" . - "\$this->subjectType = get_parent_class(\$this);\n" . + 'parameters' => $parameters, + 'body' => "\$this->___init();\n" . (count( $parameters ) ? "parent::__construct({$this->_getParameterList( @@ -123,6 +113,17 @@ class Interceptor extends \Magento\Framework\Code\Generator\EntityAbstract { $methods = [$this->_getDefaultConstructorDefinition()]; + $methods[] = [ + 'name' => '___init', + 'body' => "\$this->pluginLocator = \\Magento\\Framework\\App\\ObjectManager::getInstance();\n" . + "\$this->pluginList = \$this->pluginLocator->get('Magento\\Framework\\Interception\\PluginListInterface');\n" . + "\$this->chain = \$this->pluginLocator->get('Magento\\Framework\\Interception\\ChainInterface');\n" . + "\$this->subjectType = get_parent_class(\$this);\n" . + "if (method_exists(\$this->subjectType, '___init')) {\n" . + " parent::___init();\n" . + "}\n", + ]; + $methods[] = [ 'name' => '___callParent', 'parameters' => [ @@ -143,13 +144,7 @@ class Interceptor extends \Magento\Framework\Code\Generator\EntityAbstract $methods[] = [ 'name' => '__wakeup', - 'body' => "\$this->pluginLocator = \\Magento\\Framework\\App\\ObjectManager::getInstance();\n" . - "\$this->pluginList = \$this->pluginLocator->get('Magento\\Framework\\Interception\\PluginListInterface');\n" . - "\$this->chain = \$this->pluginLocator->get('Magento\\Framework\\Interception\\ChainInterface');\n" . - "\$this->subjectType = get_parent_class(\$this);\n" . - "if (method_exists(get_parent_class(\$this), '__wakeup')) {\n" . - " parent::__wakeup();\n" . - "}\n", + 'body' => "\$this->___init();\n", ]; $methods[] = [ diff --git a/lib/internal/Magento/Framework/Interception/ObjectManager/Config/Compiled.php b/lib/internal/Magento/Framework/Interception/ObjectManager/Config/Compiled.php index ff4034dd43745903d26c098abcd3a16f0767837f..8c291a6b590398b84c8eb9a731129fb79129b5ce 100644 --- a/lib/internal/Magento/Framework/Interception/ObjectManager/Config/Compiled.php +++ b/lib/internal/Magento/Framework/Interception/ObjectManager/Config/Compiled.php @@ -27,21 +27,6 @@ class Compiled extends \Magento\Framework\ObjectManager\Config\Compiled implemen $this->interceptionConfig = $interceptionConfig; } - /** - * Retrieve instance type with interception processing - * - * @param string $instanceName - * @return string - */ - public function getInstanceType($instanceName) - { - $type = parent::getInstanceType($instanceName); - if ($this->interceptionConfig && $this->interceptionConfig->hasPlugins($instanceName)) { - return $type . '\\Interceptor'; - } - return $type; - } - /** * Retrieve instance type without interception processing * diff --git a/lib/internal/Magento/Framework/ObjectManager/ConfigLoaderInterface.php b/lib/internal/Magento/Framework/ObjectManager/ConfigLoaderInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..6b4d9ca39ce4b3aec839e916d27996b26c690a9b --- /dev/null +++ b/lib/internal/Magento/Framework/ObjectManager/ConfigLoaderInterface.php @@ -0,0 +1,17 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\ObjectManager; + +interface ConfigLoaderInterface +{ + /** + * Load modules DI configuration + * + * @param string $area + * @return array + */ + public function load($area); +} diff --git a/lib/internal/Magento/Framework/ObjectManager/Environment/Compiled.php b/lib/internal/Magento/Framework/ObjectManager/Environment/Compiled.php deleted file mode 100644 index 00478b6e3692e8f7e9dc7f72660d7a8c305a0948..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/ObjectManager/Environment/Compiled.php +++ /dev/null @@ -1,110 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\Framework\ObjectManager\Environment; - -use Magento\Framework\ObjectManager\EnvironmentInterface; -use Magento\Framework\ObjectManager\FactoryInterface; - -class Compiled extends AbstractEnvironment implements EnvironmentInterface -{ - /** - * File name with compiled data - */ - const FILE_NAME = 'global.ser'; - - /** - * Relative path to file with compiled data - */ - const RELATIVE_FILE_PATH = '/var/di/'; - - /**#@+ - * Mode name - */ - const MODE = 'compiled'; - - protected $mode = self::MODE; - /**#@- */ - - /** - * Global config - * - * @var array - */ - private $globalConfig = []; - - /** - * @var string - */ - protected $configPreference = 'Magento\Framework\ObjectManager\Factory\Compiled'; - - /** - * Creates factory - * - * @param array $arguments - * @param string $factoryClass - * - * @return FactoryInterface - */ - protected function createFactory($arguments, $factoryClass) - { - return new $factoryClass( - $this->getDiConfig(), - $arguments['shared_instances'], - $arguments - ); - } - - /** - * Returns initialized compiled config - * - * @return \Magento\Framework\Interception\ObjectManager\ConfigInterface - */ - public function getDiConfig() - { - if (!$this->config) { - $this->config = new \Magento\Framework\Interception\ObjectManager\Config\Compiled( - $this->getConfigData() - ); - } - - return $this->config; - } - - /** - * Returns config data as array - * - * @return array - */ - protected function getConfigData() - { - if (empty($this->globalConfig)) { - $this->globalConfig = \unserialize(\file_get_contents(self::getFilePath())); - } - - return $this->globalConfig; - } - - /** - * Returns file path - * - * @return string - */ - public static function getFilePath() - { - return BP . self::RELATIVE_FILE_PATH . self::FILE_NAME; - } - - /** - * Returns new instance of compiled config loader - * - * @return \Magento\Framework\App\ObjectManager\ConfigLoader\Compiled - */ - public function getObjectManagerConfigLoader() - { - return new \Magento\Framework\App\ObjectManager\ConfigLoader\Compiled($this->getConfigData()); - } -} diff --git a/lib/internal/Magento/Framework/ObjectManager/Environment/Developer.php b/lib/internal/Magento/Framework/ObjectManager/Environment/Developer.php deleted file mode 100644 index 10d94dee725ba662ae45057127ca57a00bb5f08c..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/ObjectManager/Environment/Developer.php +++ /dev/null @@ -1,56 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\Framework\ObjectManager\Environment; - -use Magento\Framework\ObjectManager\EnvironmentInterface; - -class Developer extends AbstractEnvironment implements EnvironmentInterface -{ - /**#@+ - * Mode name - */ - const MODE = 'developer'; - protected $mode = self::MODE; - /**#@- */ - - /** - * @var \Magento\Framework\Interception\ObjectManager\ConfigInterface - */ - protected $config; - - /** - * @var string - */ - protected $configPreference = 'Magento\Framework\ObjectManager\Factory\Dynamic\Developer'; - - /** - * Returns initialized di config entity - * - * @return \Magento\Framework\Interception\ObjectManager\ConfigInterface - */ - public function getDiConfig() - { - if (!$this->config) { - $this->config = new \Magento\Framework\Interception\ObjectManager\Config\Developer( - $this->envFactory->getRelations(), - $this->envFactory->getDefinitions() - ); - } - - return $this->config; - } - - /** - * As developer environment does not have config loader, we return null - * - * @return null - */ - public function getObjectManagerConfigLoader() - { - return null; - } -} diff --git a/lib/internal/Magento/Framework/ObjectManager/Factory/AbstractFactory.php b/lib/internal/Magento/Framework/ObjectManager/Factory/AbstractFactory.php index 29f758fef5a5b83eba6b83bee7b6866473ffc41b..2caf976b30ca135a601fb44cbc4d347ef522be66 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Factory/AbstractFactory.php +++ b/lib/internal/Magento/Framework/ObjectManager/Factory/AbstractFactory.php @@ -5,12 +5,14 @@ */ namespace Magento\Framework\ObjectManager\Factory; +use Magento\Framework\ObjectManagerInterface; + abstract class AbstractFactory implements \Magento\Framework\ObjectManager\FactoryInterface { /** * Object manager * - * @var \Magento\Framework\ObjectManagerInterface + * @var ObjectManagerInterface */ protected $objectManager; @@ -37,13 +39,13 @@ abstract class AbstractFactory implements \Magento\Framework\ObjectManager\Facto /** * @param \Magento\Framework\ObjectManager\ConfigInterface $config - * @param \Magento\Framework\ObjectManagerInterface $objectManager + * @param ObjectManagerInterface $objectManager * @param \Magento\Framework\ObjectManager\DefinitionInterface $definitions * @param array $globalArguments */ public function __construct( \Magento\Framework\ObjectManager\ConfigInterface $config, - \Magento\Framework\ObjectManagerInterface $objectManager = null, + ObjectManagerInterface $objectManager = null, \Magento\Framework\ObjectManager\DefinitionInterface $definitions = null, $globalArguments = [] ) { @@ -56,11 +58,11 @@ abstract class AbstractFactory implements \Magento\Framework\ObjectManager\Facto /** * Set object manager * - * @param \Magento\Framework\ObjectManagerInterface $objectManager + * @param ObjectManagerInterface $objectManager * * @return void */ - public function setObjectManager(\Magento\Framework\ObjectManagerInterface $objectManager) + public function setObjectManager(ObjectManagerInterface $objectManager) { $this->objectManager = $objectManager; } diff --git a/lib/internal/Magento/Framework/ObjectManager/Factory/Compiled.php b/lib/internal/Magento/Framework/ObjectManager/Factory/Compiled.php index b2f6517e5dfba7c6ac3110f832b5348904409332..94043e232763b899c5a5db8dd2aa6380644a584e 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Factory/Compiled.php +++ b/lib/internal/Magento/Framework/ObjectManager/Factory/Compiled.php @@ -53,10 +53,9 @@ class Compiled extends AbstractFactory */ public function create($requestedType, array $arguments = []) { - /** @TODO get rid of ltrim() usage and place it to client code */ $args = $this->config->getArguments($requestedType); $type = $this->config->getInstanceType($requestedType); - if ($args === null) { + if (!$args) { return new $type(); } @@ -84,13 +83,6 @@ class Compiled extends AbstractFactory } $args = array_values($args); - if (substr($type, -12) == '\Interceptor') { - $args = array_merge([ - $this->objectManager, - $this->get($this->config->getPreference('Magento\Framework\Interception\PluginListInterface')), - $this->get($this->config->getPreference('Magento\Framework\Interception\ChainInterface')), - ], $args); - } return $this->createObject($type, $args); } diff --git a/lib/internal/Magento/Framework/ObjectManager/FactoryInterface.php b/lib/internal/Magento/Framework/ObjectManager/FactoryInterface.php index 071885dd9111f5094c245d5a7c2787fb3ef28255..66af7d55f8868001b7941a8c2a1ba14ddf6f4967 100644 --- a/lib/internal/Magento/Framework/ObjectManager/FactoryInterface.php +++ b/lib/internal/Magento/Framework/ObjectManager/FactoryInterface.php @@ -5,6 +5,8 @@ */ namespace Magento\Framework\ObjectManager; +use Magento\Framework\ObjectManagerInterface; + interface FactoryInterface { /** @@ -17,4 +19,13 @@ interface FactoryInterface * @throws \BadMethodCallException */ public function create($requestedType, array $arguments = []); + + /** + * Set object manager + * + * @param ObjectManagerInterface $objectManager + * + * @return void + */ + public function setObjectManager(ObjectManagerInterface $objectManager); }