diff --git a/.gitignore b/.gitignore index 657c315552ed4e9a89623814ed54e2d81903f062..1e6c8cdcecef6cdad04fdea14e744b760cb2816e 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ atlassian* /lib/internal/flex/varien/.project /lib/internal/flex/varien/.settings /node_modules +/.grunt /pub/media/*.* !/pub/media/.htaccess diff --git a/app/code/Magento/Config/Controller/Adminhtml/System/Config/Save.php b/app/code/Magento/Config/Controller/Adminhtml/System/Config/Save.php index 25ed5c9ce6100b7c38fe1a466cdb316966581f37..8cc81e08d40092507e5abdada866ff6ccf175a94 100644 --- a/app/code/Magento/Config/Controller/Adminhtml/System/Config/Save.php +++ b/app/code/Magento/Config/Controller/Adminhtml/System/Config/Save.php @@ -72,12 +72,12 @@ class Save extends AbstractConfig $groups = $this->getRequest()->getPost('groups'); $files = $this->getRequest()->getFiles('groups'); - if (isset($files['name']) && is_array($files['name'])) { + if ($files && is_array($files)) { /** * Carefully merge $_FILES and $_POST information * None of '+=' or 'array_merge_recursive' can do this correct */ - foreach ($files['name'] as $groupName => $group) { + foreach ($files as $groupName => $group) { $data = $this->_processNestedGroups($group); if (!empty($data)) { if (!empty($groups[$groupName])) { diff --git a/app/code/Magento/Config/Test/Unit/Controller/Adminhtml/System/Config/_files/files_array.php b/app/code/Magento/Config/Test/Unit/Controller/Adminhtml/System/Config/_files/files_array.php index 906904addc27d35a5a278ec27d5d853afc8e378d..a721e3c93f6ee2c9bb7e571fe6cd33c80e3267e2 100644 --- a/app/code/Magento/Config/Test/Unit/Controller/Adminhtml/System/Config/_files/files_array.php +++ b/app/code/Magento/Config/Test/Unit/Controller/Adminhtml/System/Config/_files/files_array.php @@ -5,35 +5,33 @@ */ return [ - 'name' => [ - 'group.1' => [ - 'fields' => ['f1.1' => ['value' => 'f1.1.val'], 'f1.2' => ['value' => 'f1.2.val']], + 'group.1' => [ + 'fields' => ['f1.1' => ['value' => 'f1.1.val'], 'f1.2' => ['value' => 'f1.2.val']], + ], + 'group.2' => [ + 'fields' => [ + 'f2.1' => ['value' => 'f2.1.val'], + 'f2.2' => ['value' => 'f2.2.val'], + 'f2.3' => ['value' => ''], ], - 'group.2' => [ - 'fields' => [ - 'f2.1' => ['value' => 'f2.1.val'], - 'f2.2' => ['value' => 'f2.2.val'], - 'f2.3' => ['value' => ''], - ], - 'groups' => [ - 'group.2.1' => [ - 'fields' => [ - 'f2.1.1' => ['value' => 'f2.1.1.val'], - 'f2.1.2' => ['value' => 'f2.1.2.val'], - 'f2.1.3' => ['value' => ''], - ], - 'groups' => [ - 'group.2.1.1' => [ - 'fields' => [ - 'f2.1.1.1' => ['value' => 'f2.1.1.1.val'], - 'f2.1.1.2' => ['value' => 'f2.1.1.2.val'], - 'f2.1.1.3' => ['value' => ''], - ], + 'groups' => [ + 'group.2.1' => [ + 'fields' => [ + 'f2.1.1' => ['value' => 'f2.1.1.val'], + 'f2.1.2' => ['value' => 'f2.1.2.val'], + 'f2.1.3' => ['value' => ''], + ], + 'groups' => [ + 'group.2.1.1' => [ + 'fields' => [ + 'f2.1.1.1' => ['value' => 'f2.1.1.1.val'], + 'f2.1.1.2' => ['value' => 'f2.1.1.2.val'], + 'f2.1.1.3' => ['value' => ''], ], ], ], ], ], - 'group.3' => 'some.data', - ] + ], + 'group.3' => 'some.data', ]; diff --git a/app/code/Magento/Developer/Model/Config/Source/WorkflowType.php b/app/code/Magento/Developer/Model/Config/Source/WorkflowType.php new file mode 100644 index 0000000000000000000000000000000000000000..02b778c561f514a5f20c6a81dd91a57f7f4a9faf --- /dev/null +++ b/app/code/Magento/Developer/Model/Config/Source/WorkflowType.php @@ -0,0 +1,45 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Developer\Model\Config\Source; + +use Magento\Framework\App\State; +use Magento\Framework\Option\ArrayInterface; + +/** + * Class WorkflowType + * + * @package Magento\Developer\Model\Config\Source + */ +class WorkflowType implements ArrayInterface +{ + /** + * Constant for + */ + const CONFIG_NAME_PATH = 'dev/front_end_development_workflow/type'; + + /** + * Constant for server side compilation workflow + */ + const SERVER_SIDE_COMPILATION = 'server_side_compilation'; + + /** + * Constant for client side compilation workflow + */ + const CLIENT_SIDE_COMPILATION = 'client_side_compilation'; + + /** + * Return list of Workflow types + * + * @return array Format: array(array('value' => '<value>', 'label' => '<label>'), ...) + */ + public function toOptionArray() + { + return [ + ['value' => self::CLIENT_SIDE_COMPILATION, 'label' => __('Client side less compilation')], + ['value' => self::SERVER_SIDE_COMPILATION, 'label' => __('Server side less compilation')] + ]; + } +} diff --git a/app/code/Magento/Developer/Model/View/Asset/PreProcessor/DeveloperChain.php b/app/code/Magento/Developer/Model/View/Asset/PreProcessor/DeveloperChain.php new file mode 100644 index 0000000000000000000000000000000000000000..9703008ff7dafd06debf523eeb0c02b2896ee563 --- /dev/null +++ b/app/code/Magento/Developer/Model/View/Asset/PreProcessor/DeveloperChain.php @@ -0,0 +1,34 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Developer\Model\View\Asset\PreProcessor; + +use Magento\Framework\View\Asset\PreProcessor\Chain; +use Magento\Framework\View\Asset\LocalInterface; + +class DeveloperChain extends Chain +{ + /** + * @param LocalInterface $asset + * @param string $origContent + * @param string $origContentType + * @param null $origAssetPath + */ + public function __construct( + LocalInterface $asset, + $origContent, + $origContentType, + $origAssetPath = null + ) { + parent::__construct( + $asset, + $origContent, + $origContentType + ); + + $this->targetContentType = $this->origContentType; + $this->targetAssetPath = $origAssetPath; + } +} diff --git a/app/code/Magento/Developer/Model/View/Asset/PreProcessor/DeveloperChainFactory.php b/app/code/Magento/Developer/Model/View/Asset/PreProcessor/DeveloperChainFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..dff0dc015aa087f818829cbb4bebc41450a2c67d --- /dev/null +++ b/app/code/Magento/Developer/Model/View/Asset/PreProcessor/DeveloperChainFactory.php @@ -0,0 +1,61 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Developer\Model\View\Asset\PreProcessor; + +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\View\Asset\PreProcessor\ChainFactory; +use Magento\Framework\View\Asset\PreProcessor\ChainFactoryInterface; +use Magento\Framework\ObjectManagerInterface; +use Magento\Developer\Model\Config\Source\WorkflowType; + +class DeveloperChainFactory implements ChainFactoryInterface +{ + /** + * Object manager + * + * @var ObjectManagerInterface + */ + private $_objectManager; + + /** + * @var ChainFactory + */ + private $chainFactory; + + /** + * @var ScopeConfigInterface + */ + private $scopeConfig; + + /** + * @param ObjectManagerInterface $objectManager + * @param ChainFactory $chainFactory + * @param ScopeConfigInterface $scopeConfig + */ + public function __construct( + ObjectManagerInterface $objectManager, + ChainFactory $chainFactory, + ScopeConfigInterface $scopeConfig + ) { + $this->_objectManager = $objectManager; + $this->chainFactory = $chainFactory; + $this->scopeConfig = $scopeConfig; + } + + /** + * {inheritdoc} + */ + public function create(array $arguments = []) + { + if (WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH)) { + return $this->_objectManager->create( + 'Magento\Developer\Model\View\Asset\PreProcessor\DeveloperChain', + $arguments + ); + } + return $this->chainFactory->create($arguments); + } +} diff --git a/app/code/Magento/Developer/Model/View/Page/Config/ClientSideLessCompilation/Renderer.php b/app/code/Magento/Developer/Model/View/Page/Config/ClientSideLessCompilation/Renderer.php new file mode 100644 index 0000000000000000000000000000000000000000..59e3441a782e30214138e7bcc872c02e737961f3 --- /dev/null +++ b/app/code/Magento/Developer/Model/View/Page/Config/ClientSideLessCompilation/Renderer.php @@ -0,0 +1,134 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Developer\Model\View\Page\Config\ClientSideLessCompilation; + +use Magento\Framework\View\Page\Config; + +/** + * Page config Renderer model + */ +class Renderer extends Config\Renderer +{ + /** + * @var \Magento\Framework\View\Asset\Repository + */ + private $assetRepo; + + /** + * @param Config $pageConfig + * @param \Magento\Framework\View\Asset\MinifyService $assetMinifyService + * @param \Magento\Framework\View\Asset\MergeService $assetMergeService + * @param \Magento\Framework\UrlInterface $urlBuilder + * @param \Magento\Framework\Escaper $escaper + * @param \Magento\Framework\Stdlib\String $string + * @param \Psr\Log\LoggerInterface $logger + * @param \Magento\Framework\View\Asset\Repository $assetRepo + */ + public function __construct( + Config $pageConfig, + \Magento\Framework\View\Asset\MinifyService $assetMinifyService, + \Magento\Framework\View\Asset\MergeService $assetMergeService, + \Magento\Framework\UrlInterface $urlBuilder, + \Magento\Framework\Escaper $escaper, + \Magento\Framework\Stdlib\String $string, + \Psr\Log\LoggerInterface $logger, + \Magento\Framework\View\Asset\Repository $assetRepo + ) { + $this->assetRepo = $assetRepo; + + parent::__construct( + $pageConfig, + $assetMinifyService, + $assetMergeService, + $urlBuilder, + $escaper, + $string, + $logger + ); + } + + /** + * @param string $contentType + * @param string $attributes + * @return string + */ + protected function addDefaultAttributes($contentType, $attributes) + { + $taggedAttributes = parent::addDefaultAttributes($contentType, $attributes); + + if ($taggedAttributes !== $attributes) { + return $taggedAttributes; + } + + switch ($contentType) { + case 'less': + $taggedAttributes = ' rel="stylesheet/less" type="text/css" ' . ($attributes ?: ' media="all"'); + break; + + } + return $taggedAttributes; + } + + /** + * Returns rendered HTML for all Assets (CSS before) + * + * @param array $resultGroups + * + * @return string + */ + public function renderAssets($resultGroups = []) + { + return parent::renderAssets($this->renderLessJsScripts($resultGroups)); + } + + /** + * Injecting less.js compiler + * + * @param array $resultGroups + * + * @return mixed + */ + private function renderLessJsScripts($resultGroups) + { + // less js have to be injected before any *.js in developer mode + $lessJsConfigAsset = $this->assetRepo->createAsset('less/config.less.js'); + $resultGroups['js'] .= sprintf('<script src="%s"></script>' . "\n", $lessJsConfigAsset->getUrl()); + $lessJsAsset = $this->assetRepo->createAsset('less/less.min.js'); + $resultGroups['js'] .= sprintf('<script src="%s"></script>' . "\n", $lessJsAsset->getUrl()); + + return $resultGroups; + } + + /** + * Render HTML tags referencing corresponding URLs + * + * @param string $template + * @param array $assets + * @return string + */ + protected function renderAssetHtml($template, $assets) + { + $result = ''; + try { + foreach ($assets as $asset) { + /** @var $asset \Magento\Framework\View\Asset\File */ + if ($asset instanceof \Magento\Framework\View\Asset\File + && $asset->getSourceUrl() != $asset->getUrl() + ) { + $attributes = $this->addDefaultAttributes('less', []); + $groupTemplate = $this->getAssetTemplate($asset->getContentType(), $attributes); + $result .= sprintf($groupTemplate, $asset->getSourceUrl()); + } else { + $result .= sprintf($template, $asset->getUrl()); + } + } + } catch (\Magento\Framework\Exception $e) { + $this->logger->critical($e); + $result .= sprintf($template, $this->urlBuilder->getUrl('', ['_direct' => 'core/index/notFound'])); + } + return $result; + } +} diff --git a/app/code/Magento/Developer/Model/View/Page/Config/RendererFactory.php b/app/code/Magento/Developer/Model/View/Page/Config/RendererFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..bba4643f4e745d57fa643d1db11a70363f609051 --- /dev/null +++ b/app/code/Magento/Developer/Model/View/Page/Config/RendererFactory.php @@ -0,0 +1,70 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Developer\Model\View\Page\Config; + +use Magento\Developer\Model\Config\Source\WorkflowType; +use Magento\Store\Model\ScopeInterface; + +/** + * Factory class for \Magento\Framework\View\Page\Config\RendererInterface + * + * todo work with interfaces instead of abstractions + */ +class RendererFactory extends \Magento\Framework\View\Page\Config\RendererFactory +{ + /** + * Object Manager instance + * + * @var \Magento\Framework\ObjectManagerInterface + */ + protected $objectManager; + + /** + * @var \Magento\Framework\App\Config\ScopeConfigInterface + */ + protected $scopeConfig; + + /** + * Renderer Types + * + * @var array + */ + private $rendererTypes; + + /** + * Factory constructor + * + * @param \Magento\Framework\ObjectManagerInterface $objectManager + * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + * @param array $rendererTypes + */ + public function __construct( + \Magento\Framework\ObjectManagerInterface $objectManager, + \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, + array $rendererTypes = [] + ) { + $this->objectManager = $objectManager; + $this->scopeConfig = $scopeConfig; + $this->rendererTypes = $rendererTypes; + } + + /** + * Create class instance + * + * @param array $data + * + * @return \Magento\Framework\View\Page\Config\RendererInterface + */ + public function create(array $data = []) + { + $renderer = $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH, ScopeInterface::SCOPE_STORE); + + return $this->objectManager->create( + $this->rendererTypes[$renderer], + $data + ); + } +} diff --git a/app/code/Magento/Developer/Test/Unit/Model/Config/Source/WorkflowTypeTest.php b/app/code/Magento/Developer/Test/Unit/Model/Config/Source/WorkflowTypeTest.php new file mode 100644 index 0000000000000000000000000000000000000000..185d1f84c4cc9e349357f21346ceb1623f0359b0 --- /dev/null +++ b/app/code/Magento/Developer/Test/Unit/Model/Config/Source/WorkflowTypeTest.php @@ -0,0 +1,45 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Developer\Test\Unit\Model\Config\Source; + +use Magento\Developer\Model\Config\Source\WorkflowType; + +/** + * Class WorkflowTypeTest + * + * @package Magento\Backend\Model\Config\Source\Dev + */ +class WorkflowTypeTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var WorkflowType + */ + protected $model; + + protected function setUp() + { + $this->model = new WorkflowType(); + } + + public function testToOptionArray() + { + $this->assertInstanceOf('\Magento\Framework\Option\ArrayInterface', $this->model); + $this->assertCount(2, $this->model->toOptionArray()); + $option = current($this->model->toOptionArray()); + + /** @var \Magento\Framework\Phrase $label */ + $label = $option['label']; + $this->assertInstanceOf('\Magento\Framework\Phrase', $label); + } + + public function testOptionStructure() + { + foreach ($this->model->toOptionArray() as $option) { + $this->assertArrayHasKey('value', $option); + $this->assertArrayHasKey('label', $option); + } + } +} diff --git a/app/code/Magento/Developer/etc/adminhtml/system.xml b/app/code/Magento/Developer/etc/adminhtml/system.xml new file mode 100644 index 0000000000000000000000000000000000000000..25de378ba8882c53c205fc19a967002a71c113f7 --- /dev/null +++ b/app/code/Magento/Developer/etc/adminhtml/system.xml @@ -0,0 +1,20 @@ +<?xml version="1.0"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */--> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd"> + <system> + <section id="dev" translate="label"> + <group id="front_end_development_workflow" translate="label" type="text" sortOrder="8" showInDefault="1" showInWebsite="1" showInStore="1"> + <label>Front-end development workflow</label> + <field id="type" translate="label comment" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1"> + <label>Workflow type</label> + <comment>Not available in production mode</comment> + <source_model>Magento\Developer\Model\Config\Source\WorkflowType</source_model> + </field> + </group> + </section> + </system> +</config> diff --git a/app/code/Magento/Developer/etc/config.xml b/app/code/Magento/Developer/etc/config.xml index e89e173e832768926551bac312375247c148205b..21e898035fb4b6c828aac28a65584eb13af0acd8 100644 --- a/app/code/Magento/Developer/etc/config.xml +++ b/app/code/Magento/Developer/etc/config.xml @@ -11,6 +11,9 @@ <restrict> <allow_ips /> </restrict> + <front_end_development_workflow> + <type>server_side_compilation</type> + </front_end_development_workflow> </dev> </default> </config> diff --git a/app/code/Magento/Developer/etc/di.xml b/app/code/Magento/Developer/etc/di.xml index 9378ecf189c073549f908c2a06f526b3220716b4..d923b3d55553d83da4bd4d54defdd00bf2baf8d6 100644 --- a/app/code/Magento/Developer/etc/di.xml +++ b/app/code/Magento/Developer/etc/di.xml @@ -6,7 +6,21 @@ */ --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd"> + <preference for="Magento\Framework\View\Asset\PreProcessor\ChainFactoryInterface" type="Magento\Developer\Model\View\Asset\PreProcessor\DeveloperChainFactory"/> <type name="Magento\Framework\View\TemplateEngineFactory"> <plugin name="debug_hints" type="Magento\Developer\Model\TemplateEngine\Plugin\DebugHints" sortOrder="10"/> </type> + <type name="Magento\Framework\View\Result\Page"> + <arguments> + <argument name="pageConfigRendererFactory" xsi:type="object">Magento\Developer\Model\View\Page\Config\RendererFactory</argument> + </arguments> + </type> + <type name="Magento\Developer\Model\View\Page\Config\RendererFactory"> + <arguments> + <argument name="rendererTypes" xsi:type="array"> + <item name="client_side_compilation" xsi:type="string">Magento\Developer\Model\View\Page\Config\ClientSideLessCompilation\Renderer</item> + <item name="server_side_compilation" xsi:type="string">Magento\Framework\View\Page\Config\Renderer</item> + </argument> + </arguments> + </type> </config> diff --git a/app/etc/di.xml b/app/etc/di.xml index fe752e71c22539f98bb5247288575f86ee683aad..a3da2e85a1954b11a9415d002266b285fad6b676 100755 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -557,6 +557,13 @@ <argument name="publisher" xsi:type="object">developerPublisher</argument> </arguments> </type> + <type name="Magento\Framework\View\Asset\SourceFileGeneratorPool"> + <arguments> + <argument name="fileGeneratorTypes" xsi:type="array"> + <item name="less" xsi:type="object">Magento\Framework\Less\FileGenerator</item> + </argument> + </arguments> + </type> <virtualType name="developerPublisher" type="Magento\Framework\App\View\Asset\Publisher"> <arguments> <argument name="materializationStrategyFactory" xsi:type="object">developerMaterialization</argument> @@ -570,6 +577,24 @@ </argument> </arguments> </virtualType> + <virtualType name="lessFileGeneratorMaterialization" type="Magento\Framework\App\View\Asset\MaterializationStrategy\Factory"> + <arguments> + <argument name="strategiesList" xsi:type="array"> + <item name="view_preprocessed" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink</item> + <item name="default" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Copy</item> + </argument> + </arguments> + </virtualType> + <virtualType name="lessFileGeneratorPublisher" type="Magento\Framework\App\View\Asset\Publisher"> + <arguments> + <argument name="materializationStrategyFactory" xsi:type="object">lessFileGeneratorMaterialization</argument> + </arguments> + </virtualType> + <type name="Magento\Framework\Less\FileGenerator"> + <arguments> + <argument name="publisher" xsi:type="object">lessFileGeneratorPublisher</argument> + </arguments> + </type> <virtualType name="fallbackResolverSimpleWithGroupedCache" type="Magento\Framework\View\Design\FileResolution\Fallback\Resolver\Simple"> <arguments> <argument name="cache" xsi:type="object">Magento\Framework\View\Design\FileResolution\Fallback\CacheData\Grouped</argument> 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/framework/Magento/Sniffs/Annotations/Helper.php b/dev/tests/static/framework/Magento/Sniffs/Annotations/Helper.php index e2fb6987724b6f2de342839679c2fafe2c728a8e..90d6f10db76f1bfe066680eba5cd281d23bd3424 100644 --- a/dev/tests/static/framework/Magento/Sniffs/Annotations/Helper.php +++ b/dev/tests/static/framework/Magento/Sniffs/Annotations/Helper.php @@ -502,6 +502,7 @@ class Helper // Skip all phtml files $shouldFilter = true; } + return $shouldFilter; } 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/dev/tools/Magento/Tools/Di/Test/Unit/App/CompilerTest.php b/dev/tools/Magento/Tools/Di/Test/Unit/App/CompilerTest.php index d59fd2941863129e9ef7c387a3c3a123c0e19a48..aad0c51d60fca2fb55b4aa74cb1d6c3721f67fec 100644 --- a/dev/tools/Magento/Tools/Di/Test/Unit/App/CompilerTest.php +++ b/dev/tools/Magento/Tools/Di/Test/Unit/App/CompilerTest.php @@ -5,15 +5,16 @@ */ namespace Magento\Tools\Di\Test\Unit\App; -use \Magento\Tools\Di\App\Compiler; -use \Magento\Tools\Di\App\Task; +use Magento\Framework\App\Console\Response; +use Magento\Tools\Di\App\Compiler; +use Magento\Tools\Di\App\Task; class CompilerTest extends \PHPUnit_Framework_TestCase { /** * @var Compiler */ - private $model; + private $application; /** * @var \Magento\Framework\ObjectManagerInterface | \PHPUnit_Framework_MockObject_MockObject @@ -26,7 +27,7 @@ class CompilerTest extends \PHPUnit_Framework_TestCase private $taskManagerMock; /** - * @var \Magento\Framework\App\Console\Response | \PHPUnit_Framework_MockObject_MockObject + * @var Response | \PHPUnit_Framework_MockObject_MockObject */ private $responseMock; @@ -43,7 +44,7 @@ class CompilerTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->setMethods([]) ->getMock(); - $this->model = new Compiler( + $this->application = new Compiler( $this->taskManagerMock, $this->objectManagerMock, $this->responseMock @@ -65,9 +66,9 @@ class CompilerTest extends \PHPUnit_Framework_TestCase $this->taskManagerMock->expects($this->at($index))->method('process'); $this->responseMock->expects($this->once()) ->method('setCode') - ->with(\Magento\Framework\App\Console\Response::SUCCESS); + ->with(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() @@ -90,9 +91,9 @@ class CompilerTest extends \PHPUnit_Framework_TestCase $this->taskManagerMock->expects($this->never())->method('process'); $this->responseMock->expects($this->once()) ->method('setCode') - ->with(\Magento\Framework\App\Console\Response::ERROR); + ->with(Response::ERROR); - $this->assertInstanceOf('\Magento\Framework\App\Console\Response', $this->model->launch()); + $this->assertInstanceOf('\Magento\Framework\App\Console\Response', $this->application->launch()); } /** @@ -113,14 +114,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' + ] + ] ] ]; } @@ -137,11 +149,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/tools/Magento/Tools/Di/Test/Unit/App/Task/InterceptionCacheTest.php b/dev/tools/Magento/Tools/Di/Test/Unit/App/Task/InterceptionCacheTest.php new file mode 100644 index 0000000000000000000000000000000000000000..dadc312493474a79ce5b7523a23b00d8329dfab9 --- /dev/null +++ b/dev/tools/Magento/Tools/Di/Test/Unit/App/Task/InterceptionCacheTest.php @@ -0,0 +1,81 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Tools\Di\Test\Unit\App\Task; + +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/tools/Magento/Tools/Di/Test/Unit/App/Task/OperationFactoryTest.php b/dev/tools/Magento/Tools/Di/Test/Unit/App/Task/OperationFactoryTest.php index 14baf5d549c5f95e237d645014b37bcb73c98306..0e9645a97822480eb1a9168f57b66257964a1793 100644 --- a/dev/tools/Magento/Tools/Di/Test/Unit/App/Task/OperationFactoryTest.php +++ b/dev/tools/Magento/Tools/Di/Test/Unit/App/Task/OperationFactoryTest.php @@ -8,8 +8,8 @@ namespace Magento\Tools\Di\Test\Unit\App\Task; -use \Magento\Tools\Di\App\Task\OperationFactory; -use \Magento\Tools\Di\App\Task\OperationException; +use Magento\Tools\Di\App\Task\OperationFactory; +use Magento\Tools\Di\App\Task\OperationException; class OperationFactoryTest extends \PHPUnit_Framework_TestCase { @@ -68,7 +68,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/tools/Magento/Tools/Di/Test/Unit/Code/Generator/InterceptionConfigurationBuilderTest.php b/dev/tools/Magento/Tools/Di/Test/Unit/Code/Generator/InterceptionConfigurationBuilderTest.php index 02ecb922feef15fcdf8f3cbc7b8f9e96f67f3e1f..a8196935b92ad31806eb12602d83b48e92bbfae0 100644 --- a/dev/tools/Magento/Tools/Di/Test/Unit/Code/Generator/InterceptionConfigurationBuilderTest.php +++ b/dev/tools/Magento/Tools/Di/Test/Unit/Code/Generator/InterceptionConfigurationBuilderTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Tools\Di\Test\Unit\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/tools/Magento/Tools/Di/Test/Unit/Compiler/Config/Chain/InterceptorSubstitutionTest.php b/dev/tools/Magento/Tools/Di/Test/Unit/Compiler/Config/Chain/InterceptorSubstitutionTest.php new file mode 100644 index 0000000000000000000000000000000000000000..d30437d6eef1b258edec843676aade8171fadd37 --- /dev/null +++ b/dev/tools/Magento/Tools/Di/Test/Unit/Compiler/Config/Chain/InterceptorSubstitutionTest.php @@ -0,0 +1,110 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Tools\Di\Test\Unit\Compiler\Config\Chain; + +use Magento\Tools\Di\Compiler\Config\Chain\InterceptorSubstitution; + +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/tools/Magento/Tools/Di/Test/Unit/Compiler/Config/Chain/PreferencesResolvingTest.php b/dev/tools/Magento/Tools/Di/Test/Unit/Compiler/Config/Chain/PreferencesResolvingTest.php index 5d1ddbdbef53dca96749e81ad4c021dd46d20f28..c4cdc2f672ec4e70a88709061589df6f0c457abc 100644 --- a/dev/tools/Magento/Tools/Di/Test/Unit/Compiler/Config/Chain/PreferencesResolvingTest.php +++ b/dev/tools/Magento/Tools/Di/Test/Unit/Compiler/Config/Chain/PreferencesResolvingTest.php @@ -6,7 +6,7 @@ namespace Magento\Tools\Di\Test\Unit\Compiler\Config\Chain; -use \Magento\Tools\Di\Compiler\Config\Chain\PreferencesResolving; +use Magento\Tools\Di\Compiler\Config\Chain\PreferencesResolving; class PreferencesResolvingTest extends \PHPUnit_Framework_TestCase { @@ -129,7 +129,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', @@ -146,12 +146,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' => [ @@ -176,7 +176,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/Webdev/App/FileAssembler.php b/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php new file mode 100644 index 0000000000000000000000000000000000000000..fb8529dd7596966ce189816f5276a222fb7bd4fa --- /dev/null +++ b/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php @@ -0,0 +1,182 @@ +<?php +/** + * + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Tools\Webdev\App; + +use Magento\Framework\App; +use Magento\Framework\App\State; +use Magento\Framework\AppInterface; +use Magento\Tools\Webdev\CliParams; +use Magento\Tools\View\Deployer\Log; +use Magento\Framework\View\Asset\Source; +use Magento\Framework\App\Console\Response; +use Magento\Framework\View\Asset\Repository; +use Magento\Framework\ObjectManagerInterface; +use Magento\Framework\App\ObjectManager\ConfigLoader; +use Magento\Framework\View\Asset\SourceFileGeneratorPool; +use Magento\Framework\View\Asset\PreProcessor\ChainFactoryInterface; + +/** + * Class FileAssembler + * + * @package Magento\Tools\Di\App + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ +class FileAssembler implements AppInterface +{ + /** + * @var ObjectManagerInterface + */ + private $objectManager; + + /** + * @var Response + */ + private $response; + + /** + * @var CliParams + */ + private $params; + + /** + * @var Repository + */ + private $assetRepo; + + /** + * @var ConfigLoader + */ + private $configLoader; + + /** + * @var State + */ + private $state; + + /** + * @var \Magento\Framework\Less\FileGenerator + */ + private $sourceFileGeneratorPoll; + + /** + * @var \Magento\Framework\View\Asset\Source + */ + private $assetSource; + + /** + * @var \Magento\Tools\View\Deployer\Log + */ + private $logger; + + /** + * @var ChainFactoryInterface + */ + private $chainFactory; + + /** + * @param ObjectManagerInterface $objectManager + * @param Response $response + * @param CliParams $params + * @param Repository $assetRepo + * @param ConfigLoader $configLoader + * @param State $state + * @param Source $assetSource + * @param \Magento\Framework\View\Asset\SourceFileGeneratorPool $sourceFileGeneratorPoll + * @param \Magento\Tools\View\Deployer\Log $logger + * @param ChainFactoryInterface $chainFactory + * + * @SuppressWarnings(PHPMD.ExcessiveParameterList) + */ + public function __construct( + ObjectManagerInterface $objectManager, + Response $response, + CliParams $params, + Repository $assetRepo, + ConfigLoader $configLoader, + State $state, + Source $assetSource, + SourceFileGeneratorPool $sourceFileGeneratorPoll, + Log $logger, + ChainFactoryInterface $chainFactory + ) { + $this->response = $response; + $this->params = $params; + $this->state = $state; + $this->objectManager = $objectManager; + $this->configLoader = $configLoader; + $this->assetRepo = $assetRepo; + $this->sourceFileGeneratorPoll = $sourceFileGeneratorPoll; + $this->assetSource = $assetSource; + $this->logger = $logger; + $this->chainFactory = $chainFactory; + } + + /** + * Launch application + * + * @return \Magento\Framework\App\ResponseInterface + */ + public function launch() + { + $this->state->setAreaCode($this->params->getArea()); + $this->objectManager->configure($this->configLoader->load($this->params->getArea())); + + $sourceFileGenerator = $this->sourceFileGeneratorPoll->create($this->params->getExt()); + + foreach ($this->params->getFiles() as $file) { + $file .= '.' . $this->params->getExt(); + + $this->logger->logMessage("Gathering {$file} sources."); + + $asset = $this->assetRepo->createAsset( + $file, + [ + 'area' => $this->params->getArea(), + 'theme' => $this->params->getTheme(), + 'locale' => $this->params->getLocale(), + ] + ); + + $sourceFile = $this->assetSource->findSource($asset); + $content = \file_get_contents($sourceFile); + + $chain = $this->chainFactory->create( + [ + 'asset' => $asset, + 'origContent' => $content, + 'origContentType' => $asset->getContentType() + ] + ); + + $sourceFileGenerator->generateFileTree($chain); + + $this->logger->logMessage("Done"); + } + + $this->response->setCode(Response::SUCCESS); + + return $this->response; + } + + /** + * Ability to handle exceptions that may have occurred during bootstrap and launch + * + * Return values: + * - true: exception has been handled, no additional action is needed + * - false: exception has not been handled - pass the control to Bootstrap + * + * @param App\Bootstrap $bootstrap + * @param \Exception $exception + * @return bool + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function catchException(App\Bootstrap $bootstrap, \Exception $exception) + { + return false; + } +} diff --git a/dev/tools/Magento/Tools/Webdev/CliParams.php b/dev/tools/Magento/Tools/Webdev/CliParams.php new file mode 100644 index 0000000000000000000000000000000000000000..b06560868d8a84796ef9cb4bdddcaba518cf33f7 --- /dev/null +++ b/dev/tools/Magento/Tools/Webdev/CliParams.php @@ -0,0 +1,192 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Tools\Webdev; + +use Magento\Tools\View\Deployer\Log; + +/** + * Class CliParams + * + * @package Magento\Tools\Webdev + */ +class CliParams +{ + /** + * AREA_DOC + */ + const AREA_DOC = 'doc'; + + /** + * AREA_FRONTEND + */ + const AREA_FRONTEND = 'frontend'; + + /** + * AREA_ADMIN + */ + const AREA_ADMIN = 'adminhtml'; + + /** + * @var string + */ + private $locale = 'en_US'; + + /** + * @var string + */ + private $area = self::AREA_FRONTEND; + + /** + * @var string + */ + private $theme = 'Magento/blank'; + + /** + * @var array + */ + private $files = ['css/styles-m']; + + /** + * @var string + */ + private $ext; + + /** + * @var int + */ + private $verbose = Log::ERROR; + + /** + * @param \Zend_Console_Getopt $opt + * @SuppressWarnings(PHPMD.NPathComplexity) + * @throws \Zend_Console_Getopt_Exception + */ + public function __construct(\Zend_Console_Getopt $opt) + { + $this->locale = $opt->getOption('locale')? :$this->locale; + + if (!$opt->getOption('ext')) { + throw new \Zend_Console_Getopt_Exception('Provide "ext" parameter!'); + } + + $this->ext = $opt->getOption('ext'); + + if (!preg_match('/^[a-z]{2}_[A-Z]{2}$/', $this->locale)) { + throw new \Zend_Console_Getopt_Exception('Invalid locale format'); + } + + $this->area = $opt->getOption('area')? :$this->area; + $this->theme = $opt->getOption('theme')? :$this->theme; + + if ($opt->getOption('files')) { + $this->files = explode(',', $opt->getOption('files')); + } + + if ($opt->getOption('verbose')) { + $this->verbose = Log::ERROR | Log::DEBUG; + } + } + + /** + * @return string + */ + public function getLocale() + { + return $this->locale; + } + + /** + * @param string $locale + * + * @throws \Zend_Console_Getopt_Exception + * + * @return void + */ + public function setLocale($locale) + { + $this->locale = $locale; + } + + /** + * @return string + */ + public function getArea() + { + return $this->area; + } + + /** + * @param string $area + * + * @return void + */ + public function setArea($area) + { + $this->area = $area; + } + + /** + * @return string + */ + public function getTheme() + { + return $this->theme; + } + + /** + * @param string $theme + * + * @return void + */ + public function setTheme($theme) + { + $this->theme = $theme; + } + + /** + * @return array + */ + public function getFiles() + { + return $this->files; + } + + /** + * @param array $files + * + * @return void + */ + public function setFiles($files) + { + $this->files = $files; + } + + /** + * @return int + */ + public function getVerbose() + { + return $this->verbose; + } + + /** + * @param int $verbose + * + * @return void + */ + public function setVerbose($verbose) + { + $this->verbose = $verbose; + } + + /** + * @return string + */ + public function getExt() + { + return $this->ext; + } +} diff --git a/dev/tools/Magento/Tools/Webdev/file_assembler.php b/dev/tools/Magento/Tools/Webdev/file_assembler.php new file mode 100644 index 0000000000000000000000000000000000000000..72ec5b0458fdf12637221079aca0457872a60bb4 --- /dev/null +++ b/dev/tools/Magento/Tools/Webdev/file_assembler.php @@ -0,0 +1,49 @@ +<?php +/** + * + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +use Magento\Tools\Webdev\CliParams; +use Magento\Tools\View\Deployer\Log; + +require __DIR__ . '/../../../bootstrap.php'; + +try { + $opt = new \Zend_Console_Getopt( + [ + 'locale=s' => 'locale, default: en_US', + 'area=s' => 'area, one of (frontend|adminhtml|doc), default: frontend', + 'theme=s' => 'theme in format Vendor/theme, default: Magento/blank', + 'files=s' => 'files to pre-process (accept more than one file type as comma-separate values),' + . ' default: css/styles-m', + 'ext=s' => 'dynamic stylesheet language: less|sass', + 'verbose|v' => 'provide extra output', + 'help|h' => 'show help', + ] + ); + + $opt->parse(); + + if ($opt->getOption('help')) { + echo $opt->getUsageMessage(); + exit(0); + } + + $params = new CliParams($opt); + $logger = new Log($params->getVerbose()); + +} catch (\Zend_Console_Getopt_Exception $e) { + echo $e->getUsageMessage(); + echo 'Please, use quotes(") for wrapping strings.' . "\n"; + exit(1); +} + +$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER); +/** @var \Magento\Framework\App\Http $app */ +$app = $bootstrap->createApplication( + 'Magento\Tools\WebDev\App\FileAssembler', + ['params' => $params, 'logger' => $logger] +); +$bootstrap->run($app); diff --git a/dev/tools/grunt/configs/clean.json b/dev/tools/grunt/configs/clean.js similarity index 67% rename from dev/tools/grunt/configs/clean.json rename to dev/tools/grunt/configs/clean.js index aedc81f1da6af7689e93b80fd28e92ceb4e753f6..7ac0a11703c34aaf5b2d4d350dfd290b35dd5e5c 100644 --- a/dev/tools/grunt/configs/clean.json +++ b/dev/tools/grunt/configs/clean.js @@ -1,4 +1,34 @@ -{ +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +'use strict'; + +var themes = require('./themes'), + _ = require('underscore'); + +var themeOptions = {}; + +_.each(themes, function(theme, name) { + themeOptions[name] = { + "force": true, + "files": [ + { + "force": true, + "dot": true, + "src": [ + "<%= path.tmp %>/cache/**/*", + "<%= combo.autopath(\""+name+"\", \"pub\") %>**/*", + "<%= combo.autopath(\""+name+"\", \"tmpLess\") %>**/*", + "<%= combo.autopath(\""+name+"\", \"tmpSource\") %>**/*" + ] + } + ] + }; +}); + +var cleanOptions = { "var": { "force": true, "files": [ @@ -75,50 +105,8 @@ ] } ] - }, - "blank": { - "force": true, - "files": [ - { - "force": true, - "dot": true, - "src": [ - "<%= path.tmp %>/cache/**/*", - "<%= combo.autopath(\"blank\", \"pub\") %>**/*", - "<%= combo.autopath(\"blank\", \"tmpLess\") %>**/*", - "<%= combo.autopath(\"blank\", \"tmpSource\") %>**/*" - ] - } - ] - }, - "backend": { - "force": true, - "files": [ - { - "force": true, - "dot": true, - "src": [ - "<%= path.tmp %>/cache/**/*", - "<%= combo.autopath(\"backend\", \"pub\") %>**/*", - "<%= combo.autopath(\"backend\", \"tmpLess\") %>**/*", - "<%= combo.autopath(\"backend\", \"tmpSource\") %>**/*" - ] - } - ] - }, - "luma": { - "force": true, - "files": [ - { - "force": true, - "dot": true, - "src": [ - "<%= path.tmp %>/cache/**/*", - "<%= combo.autopath(\"luma\", \"pub\") %>**/*", - "<%= combo.autopath(\"luma\", \"tmpLess\") %>**/*", - "<%= combo.autopath(\"luma\", \"tmpSource\") %>**/*" - ] - } - ] } -} \ No newline at end of file +}; + +module.exports = _.extend(cleanOptions, themeOptions); + diff --git a/dev/tools/grunt/configs/combo.js b/dev/tools/grunt/configs/combo.js index 42fc64ef691e6ed6dc608c22ab1ce9fc5d470d8b..185d8ef931311af1e071786b9cf6521a42ebe51e 100644 --- a/dev/tools/grunt/configs/combo.js +++ b/dev/tools/grunt/configs/combo.js @@ -5,7 +5,7 @@ 'use strict'; -var theme = require('./theme'), +var theme = require('./themes'), path = require('./path'); /** @@ -16,11 +16,12 @@ module.exports = { var cmdPlus = /^win/.test(process.platform) ? ' & ' : ' && ', command = 'grunt --force clean:' + themeName + cmdPlus; - command = command + 'php -f dev/tools/Magento/Tools/Webdev/less.php --' + + command = command + 'php -f dev/tools/Magento/Tools/Webdev/file_assembler.php --' + ' --locale=' + theme[themeName].locale + ' --area=' + theme[themeName].area + ' --theme=' + theme[themeName].name + - ' --files=' + theme[themeName].files.join(','); + ' --files=' + theme[themeName].files.join(',') + + ' --ext=' + theme[themeName].dsl; return command; }, diff --git a/dev/tools/grunt/configs/exec.js b/dev/tools/grunt/configs/exec.js index cebeb4ae5d09eb2cf80d2c065cc87b44514f6e8f..7d7b910865a41b95725c06017217c9d256a940cb 100644 --- a/dev/tools/grunt/configs/exec.js +++ b/dev/tools/grunt/configs/exec.js @@ -6,39 +6,33 @@ 'use strict'; var combo = require('./combo'), - theme = require('./theme'); + themes = require('./themes'), + _ = require('underscore'); -/** - * Execution into cmd - */ -module.exports = { - blank: { - cmd: function () { - return combo.collector('blank'); - } - }, - luma: { - cmd: function () { - return combo.collector('luma'); - } - }, - backend: { - cmd: function () { - return combo.collector('backend'); - } - }, - all: { +var themeOptions = {}; + +_.each(themes, function(theme, name) { + themeOptions[name] = { + cmd: combo.collector.bind(combo, name) + }; +}); + +var execOptions = { + all : { cmd: function () { - var command = '', - cmdPlus = /^win/.test(process.platform) ? ' & ' : ' && ', - themes = Object.keys(theme), - i = 0; + var cmdPlus = (/^win/.test(process.platform) == true) ? ' & ' : ' && ', + command; - for (i; i < themes.length; i++) { - command += combo.collector(themes[i]) + cmdPlus; - } + command = _.map(themes, function(theme, name) { + return combo.collector(name); + }).join(cmdPlus); return 'echo ' + command; } } }; + +/** + * Execution into cmd + */ +module.exports = _.extend(themeOptions, execOptions); diff --git a/dev/tools/grunt/configs/less.js b/dev/tools/grunt/configs/less.js index c6ab91e52865c2d63b0b81756ef8f622eb4cf475..6f3e6186c214c15fc3d8405fb9c76cad9fbb6b06 100644 --- a/dev/tools/grunt/configs/less.js +++ b/dev/tools/grunt/configs/less.js @@ -5,12 +5,19 @@ 'use strict'; -var combo = require('./combo'); +var combo = require('./combo'), + themes = require('./themes'), + _ = require('underscore'); -/** - * Compiles Less to CSS and generates necessary files if requested. - */ -module.exports = { +var themeOptions = {}; + +_.each(themes, function(theme, name) { + themeOptions[name] = { + files: combo.lessFiles(name) + }; +}); + +var lessOptions = { options: { sourceMap: true, strictImports: false, @@ -43,3 +50,8 @@ module.exports = { } } }; + +/** + * Compiles Less to CSS and generates necessary files if requested. + */ +module.exports = _.extend(themeOptions, lessOptions); diff --git a/dev/tools/grunt/configs/theme.js b/dev/tools/grunt/configs/themes.js similarity index 66% rename from dev/tools/grunt/configs/theme.js rename to dev/tools/grunt/configs/themes.js index b01f58d499464036ca4dba94c358a224bd9dd334..3d9729b9d09451cd766e9d4a12ad7afadc47bcfd 100644 --- a/dev/tools/grunt/configs/theme.js +++ b/dev/tools/grunt/configs/themes.js @@ -7,6 +7,16 @@ /** * Define Themes + * + * area: area, one of (frontend|adminhtml|doc), + * name: theme name in format Vendor/theme-name, + * locale: locale, + * files: [ + * 'css/styles-m', + * 'css/styles-l' + * ], + * dsl: dynamic stylesheet language (less|sass) + * */ module.exports = { blank: { @@ -16,7 +26,8 @@ module.exports = { files: [ 'css/styles-m', 'css/styles-l' - ] + ], + dsl: 'less' }, luma: { area: 'frontend', @@ -25,7 +36,8 @@ module.exports = { files: [ 'css/styles-m', 'css/styles-l' - ] + ], + dsl: 'less' }, backend: { area: 'adminhtml', @@ -34,7 +46,10 @@ module.exports = { files: [ 'css/styles-old', 'css/styles', + 'css/pages', + 'css/admin', 'css/styles-migration' - ] + ], + dsl: 'less' } }; diff --git a/dev/tools/grunt/configs/watch.js b/dev/tools/grunt/configs/watch.js new file mode 100644 index 0000000000000000000000000000000000000000..786f5ab270bd02f61d2887beaa348028ab3ed059 --- /dev/null +++ b/dev/tools/grunt/configs/watch.js @@ -0,0 +1,30 @@ +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +'use strict'; + +var combo = require('./combo'), + themes = require('./themes'), + _ = require('underscore'); + +var themeOptions = {}; + +_.each(themes, function(theme, name) { + themeOptions[name] = { + "files": [ + "<%= combo.autopath(\""+name+"\",\"pub\") %>/**/*.less" + ], + "tasks": "less:" + name + }; +}); + +var watchOptions = { + "setup": { + "files": "<%= path.less.setup %>/**/*.less", + "tasks": "less:setup" + } +}; + +module.exports = _.extend(themeOptions, watchOptions); \ No newline at end of file diff --git a/dev/tools/grunt/configs/watch.json b/dev/tools/grunt/configs/watch.json deleted file mode 100644 index 39792f545ae4368c2950618e1ae4a3a355caa3bf..0000000000000000000000000000000000000000 --- a/dev/tools/grunt/configs/watch.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "blank": { - "files": [ - "<%= combo.autopath(\"blank\",\"pub\") %>/**/*.less" - ], - "tasks": "less:blank" - }, - "luma": { - "files": [ - "<%= combo.autopath(\"luma\",\"pub\") %>/**/*.less" - ], - "tasks": "less:luma" - }, - "setup": { - "files": "<%= path.less.setup %>/**/*.less", - "tasks": "less:setup" - }, - "backendCompile": { - "files": [ - "<%= combo.autopath(\"backend\",\"pub\") %>/**/*.less" - ], - "tasks": "less:backend" - }, - "backendReplace": { - "files": [ - "<%= combo.autopath(\"backend\",\"pub\") %>/css/styles.css" - ], - "tasks": [ - "replace:example", - "less:override" - ] - } -} 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 ddb68b8583ac41420e46d57f04302efd43797d4c..61ed3b457a27cde46c8df905ce20fec41e70f145 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; @@ -165,18 +165,8 @@ class ObjectManagerFactory ObjectManager::setInstance($objectManager); $definitionFactory->getCodeGenerator()->setObjectManager($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 a4df94fc2eafdf67458801a82ac574f721a7f3c9..bad6ddc7a796b96eb801b83c59434b114665096c 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; @@ -122,7 +123,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/ObjectManager/Test/Unit/Environment/CompiledTest.php b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/CompiledTest.php similarity index 51% rename from lib/internal/Magento/Framework/ObjectManager/Test/Unit/Environment/CompiledTest.php rename to lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/CompiledTest.php index 43791391dae64f706783d054fc1522e530a024f9..fbd182148fa698d5a9861bbac3e1fad08fd6990a 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Environment/CompiledTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/CompiledTest.php @@ -3,28 +3,21 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\ObjectManager\Test\Unit\Environment; +namespace Magento\Framework\App\Test\Unit\ObjectManager\Environment; -use \Magento\Framework\ObjectManager\Environment\Compiled; - -require 'CompiledTesting.php'; +use Magento\Framework\App\ObjectManager\Environment\Compiled; class CompiledTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Framework\ObjectManager\Environment\Compiled + * @var Compiled */ protected $_compiled; protected function setUp() { - $envFactoryMock = $this->getMock('Magento\Framework\ObjectManager\EnvironmentFactory', [], [], '', false); - $this->_compiled = new \Magento\Framework\ObjectManager\Test\Unit\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 CompiledTesting($envFactoryMock); } public function testGetMode() diff --git a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Environment/CompiledTesting.php b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/CompiledTesting.php similarity index 73% rename from lib/internal/Magento/Framework/ObjectManager/Test/Unit/Environment/CompiledTesting.php rename to lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/CompiledTesting.php index 82d199ebf3f190edd68c9925a30bf844ff2af7c7..4c9471b23c40610b3b168cf7c97f0fdfb781c3aa 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Environment/CompiledTesting.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/CompiledTesting.php @@ -4,11 +4,9 @@ * See COPYING.txt for license details. */ -namespace Magento\Framework\ObjectManager\Test\Unit\Environment; +namespace Magento\Framework\App\Test\Unit\ObjectManager\Environment; -use Magento\Framework\ObjectManager\Environment\Compiled; - -require 'ConfigTesting.php'; +use Magento\Framework\App\ObjectManager\Environment\Compiled; class CompiledTesting extends Compiled { diff --git a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Environment/ConfigTesting.php b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/ConfigTesting.php similarity index 97% rename from lib/internal/Magento/Framework/ObjectManager/Test/Unit/Environment/ConfigTesting.php rename to lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/ConfigTesting.php index 8ba5771121bc562b487361483e4a7f803d7c4697..abe2a86ec9b629c33af95ab76eb12992d061841b 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Environment/ConfigTesting.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/ConfigTesting.php @@ -3,7 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\ObjectManager\Test\Unit\Environment; +namespace Magento\Framework\App\Test\Unit\ObjectManager\Environment; use Magento\Framework\Interception\ObjectManager\ConfigInterface; use Magento\Framework\ObjectManager\ConfigCacheInterface; diff --git a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Environment/DeveloperTest.php b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/DeveloperTest.php similarity index 55% rename from lib/internal/Magento/Framework/ObjectManager/Test/Unit/Environment/DeveloperTest.php rename to lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/DeveloperTest.php index 1813ee33cf7cfee42b90b6e78da6571486a7fb8d..c86318181a2c06c7068a82b39b44905774bbd2a3 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Environment/DeveloperTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/DeveloperTest.php @@ -3,21 +3,21 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\ObjectManager\Test\Unit\Environment; +namespace Magento\Framework\App\Test\Unit\ObjectManager\Environment; -use \Magento\Framework\ObjectManager\Environment\Developer; +use Magento\Framework\App\ObjectManager\Environment\Developer; class DeveloperTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Framework\ObjectManager\Environment\Developer + * @var 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 Developer($envFactoryMock); } public function testGetMode() diff --git a/lib/internal/Magento/Framework/App/Test/Unit/FactoryStub.php b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/FactoryStub.php similarity index 73% rename from lib/internal/Magento/Framework/App/Test/Unit/FactoryStub.php rename to lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/FactoryStub.php index bc5d81c1b07354ec108fe8f2def950e07c3ab365..8f5bda81538ca62dc2e4974da54c450d6e0f7ea6 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/FactoryStub.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/FactoryStub.php @@ -3,7 +3,9 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\App\Test\Unit; +namespace Magento\Framework\App\Test\Unit\ObjectManager; + +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/lib/internal/Magento/Framework/App/Test/Unit/ObjectManagerFactoryTest.php b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManagerFactoryTest.php index 243f95be8544483bf940e33d740f9e6cf2a514d6..cf75953d4e19b00374317c73c5001089858a1b0f 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/ObjectManagerFactoryTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManagerFactoryTest.php @@ -41,7 +41,7 @@ class ObjectManagerFactoryTest extends \PHPUnit_Framework_TestCase /** * @expectedException \BadMethodCallException - * @expectedExceptionMessage Magento\Framework\App\Test\Unit\FactoryStub::__construct + * @expectedExceptionMessage Magento\Framework\App\Test\Unit\ObjectManager\FactoryStub::__construct */ public function testCreateObjectManagerFactoryCouldBeOverridden() { diff --git a/lib/internal/Magento/Framework/App/Test/Unit/_files/app/etc/di.xml b/lib/internal/Magento/Framework/App/Test/Unit/_files/app/etc/di.xml index 4da988c58c28c8e9a1a9a2237d6401866a637108..77c37c59d030ad76e782509acbef89a2cd2a1ab3 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/_files/app/etc/di.xml +++ b/lib/internal/Magento/Framework/App/Test/Unit/_files/app/etc/di.xml @@ -6,5 +6,5 @@ */ --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd"> - <preference for="Magento\Framework\ObjectManager\Factory\Dynamic\Developer" type="Magento\Framework\App\Test\Unit\FactoryStub" /> + <preference for="Magento\Framework\ObjectManager\Factory\Dynamic\Developer" type="Magento\Framework\App\Test\Unit\ObjectManager\FactoryStub" /> </config> diff --git a/lib/internal/Magento/Framework/Css/PreProcessor/Less.php b/lib/internal/Magento/Framework/Css/PreProcessor/Less.php index 71e2c71e629428af3f06b7d1e546fc1c14c55fc2..723a39f56d60369797010924857d2cc7ef560cad 100644 --- a/lib/internal/Magento/Framework/Css/PreProcessor/Less.php +++ b/lib/internal/Magento/Framework/Css/PreProcessor/Less.php @@ -38,7 +38,7 @@ class Less implements PreProcessorInterface public function process(\Magento\Framework\View\Asset\PreProcessor\Chain $chain) { $chain->setContentType('less'); - $tmpLessFile = $this->fileGenerator->generateLessFileTree($chain); + $tmpLessFile = $this->fileGenerator->generateFileTree($chain); $cssContent = $this->adapter->process($tmpLessFile); $cssTrimmedContent = trim($cssContent); if (!empty($cssTrimmedContent)) { diff --git a/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/LessTest.php b/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/LessTest.php index 5979ea6f1d26ee23a4f734e9a66ec4885e7b0b8f..a889a4320f3639f891c117e5cfba26d6cc122d76 100644 --- a/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/LessTest.php +++ b/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/LessTest.php @@ -42,7 +42,7 @@ class LessTest extends \PHPUnit_Framework_TestCase $expectedContent = 'updated content'; $tmpFile = 'tmp/file.ext'; $this->fileGenerator->expects($this->once()) - ->method('generateLessFileTree') + ->method('generateFileTree') ->with($this->chain) ->will($this->returnValue($tmpFile)); $this->adapter->expects($this->once()) diff --git a/lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php b/lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php index 2458a3cbd7518252b1d5671a5ec379445b87f0c1..d50721d4e52a1df5db315c72ab853b20dec58472 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/Less/FileGenerator.php b/lib/internal/Magento/Framework/Less/FileGenerator.php index a72f6dea6cb70ce2e6ce8a4aeda486af14d9a6de..f45d462e7eaaeeff23b95633c658bf40d526f650 100644 --- a/lib/internal/Magento/Framework/Less/FileGenerator.php +++ b/lib/internal/Magento/Framework/Less/FileGenerator.php @@ -8,9 +8,10 @@ namespace Magento\Framework\Less; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\View\Asset\LocalInterface; -use Magento\Framework\View\Asset\Source; +use Magento\Framework\View\Asset\PreProcessor\Chain; +use Magento\Framework\View\Asset\SourceFileGeneratorInterface; -class FileGenerator +class FileGenerator implements SourceFileGeneratorInterface { /** * Temporary directory prefix @@ -42,6 +43,11 @@ class FileGenerator */ private $assetRepo; + /** + * @var \Magento\Framework\View\Asset\Source + */ + private $assetSource; + /** * @var \Magento\Framework\Less\PreProcessor\Instruction\MagentoImport */ @@ -52,35 +58,48 @@ class FileGenerator */ private $importProcessor; + /** + * @var \Magento\Framework\App\View\Asset\Publisher + */ + private $publisher; + /** * @param \Magento\Framework\Filesystem $filesystem * @param \Magento\Framework\View\Asset\Repository $assetRepo * @param \Magento\Framework\Less\PreProcessor\Instruction\MagentoImport $magentoImportProcessor * @param \Magento\Framework\Less\PreProcessor\Instruction\Import $importProcessor + * @param \Magento\Framework\View\Asset\Source $assetSource + * @param \Magento\Framework\App\View\Asset\Publisher $publisher */ public function __construct( \Magento\Framework\Filesystem $filesystem, \Magento\Framework\View\Asset\Repository $assetRepo, \Magento\Framework\Less\PreProcessor\Instruction\MagentoImport $magentoImportProcessor, - \Magento\Framework\Less\PreProcessor\Instruction\Import $importProcessor + \Magento\Framework\Less\PreProcessor\Instruction\Import $importProcessor, + \Magento\Framework\View\Asset\Source $assetSource, + \Magento\Framework\App\View\Asset\Publisher $publisher ) { $this->tmpDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); + $this->pubDirectory = $filesystem->getDirectoryWrite(DirectoryList::PUB); $this->lessDirectory = DirectoryList::TMP_MATERIALIZATION_DIR . '/' . self::TMP_LESS_DIR; $this->assetRepo = $assetRepo; + $this->assetSource = $assetSource; + $this->magentoImportProcessor = $magentoImportProcessor; $this->importProcessor = $importProcessor; + $this->publisher = $publisher; } /** * Create a tree of self-sustainable files and return the topmost LESS file, ready for passing to 3rd party library * - * @param \Magento\Framework\View\Asset\PreProcessor\Chain $chain + * @param Chain $chain * @return string Absolute path of generated LESS file */ - public function generateLessFileTree(\Magento\Framework\View\Asset\PreProcessor\Chain $chain) + public function generateFileTree(Chain $chain) { /** - * @bug This logic is duplicated at \Magento\Framework\View\Asset\PreProcessor\Pool::getPreProcessors() + * @bug This logic is duplicated at \Magento\Framework\View\Asset\PreProcessor\Pool * If you need to extend or modify behavior of LESS preprocessing, you must account for both places */ @@ -98,6 +117,9 @@ class FileGenerator $this->generateRelatedFiles(); $lessRelativePath = preg_replace('#\.css$#', '.less', $chain->getAsset()->getPath()); $tmpFilePath = $this->createFile($lessRelativePath, $chain->getContent()); + + $this->createFileMain($lessRelativePath, $chain->getContent()); + $this->tmpDirectory->delete($lockFilePath); return $tmpFilePath; } @@ -148,7 +170,11 @@ class FileGenerator protected function generateRelatedFile($relatedFileId, LocalInterface $asset) { $relatedAsset = $this->assetRepo->createRelated($relatedFileId, $asset); + $relatedAsset->getFilePath(); + $this->createFile($relatedAsset->getPath(), $relatedAsset->getContent()); + $relatedAsset->getSourceFile(); + $this->publisher->publish($relatedAsset); } /** @@ -158,7 +184,7 @@ class FileGenerator * @param string $contents * @return string */ - protected function createFile($relativePath, $contents) + private function createFile($relativePath, $contents) { $filePath = $this->lessDirectory . '/' . $relativePath; @@ -167,4 +193,18 @@ class FileGenerator } return $this->tmpDirectory->getAbsolutePath($filePath); } + + /** + * @param string $relativePath + * @param string $contents + * + * @return void + */ + private function createFileMain($relativePath, $contents) + { + $filePath = '/static/' . $relativePath; + $contents .= '@urls-resolved: true;' . PHP_EOL . PHP_EOL; + $this->pubDirectory->writeFile($filePath, $contents); + return; + } } diff --git a/lib/internal/Magento/Framework/Less/Test/Unit/FileGeneratorTest.php b/lib/internal/Magento/Framework/Less/Test/Unit/FileGeneratorTest.php index 8a965e0cb951a02d5cb638274fdc183e757a9edb..60293981b8f761c070b06930b9461640e90b450b 100644 --- a/lib/internal/Magento/Framework/Less/Test/Unit/FileGeneratorTest.php +++ b/lib/internal/Magento/Framework/Less/Test/Unit/FileGeneratorTest.php @@ -8,8 +8,6 @@ namespace Magento\Framework\Less\Test\Unit; -use Magento\Framework\App\Filesystem\DirectoryList; - class FileGeneratorTest extends \PHPUnit_Framework_TestCase { /** @@ -42,6 +40,11 @@ class FileGeneratorTest extends \PHPUnit_Framework_TestCase */ private $object; + /** + * @var \Magento\Framework\App\View\Asset\Publisher|\PHPUnit_Framework_MockObject_MockObject + */ + private $publisher; + protected function setUp() { $this->tmpDirectory = $this->getMockForAbstractClass('\Magento\Framework\Filesystem\Directory\WriteInterface'); @@ -55,9 +58,9 @@ class FileGeneratorTest extends \PHPUnit_Framework_TestCase return "content of '$file'"; })); $filesystem = $this->getMock('\Magento\Framework\Filesystem', [], [], '', false); - $filesystem->expects($this->once()) + $filesystem->expects($this->exactly(2)) ->method('getDirectoryWrite') - ->with(DirectoryList::VAR_DIR) + //->with(DirectoryList::VAR_DIR) ->will($this->returnValue($this->tmpDirectory)); $this->assetRepo = $this->getMock('\Magento\Framework\View\Asset\Repository', [], [], '', false); $this->magentoImport = $this->getMock( @@ -66,8 +69,15 @@ class FileGeneratorTest extends \PHPUnit_Framework_TestCase $this->import = $this->getMock( '\Magento\Framework\Less\PreProcessor\Instruction\Import', [], [], '', false ); + + $assetSource = $this->getMock( + 'Magento\Framework\View\Asset\Source', [], [], '', false + ); + + $this->publisher = $this->getMock('Magento\Framework\App\View\Asset\Publisher', [], [], '', false); + $this->object = new \Magento\Framework\Less\FileGenerator( - $filesystem, $this->assetRepo, $this->magentoImport, $this->import + $filesystem, $this->assetRepo, $this->magentoImport, $this->import, $assetSource, $this->publisher ); } @@ -142,7 +152,7 @@ class FileGeneratorTest extends \PHPUnit_Framework_TestCase ->method('getAbsolutePath') ->will($this->returnValueMap($pathsMap)); - $actual = $this->object->generateLessFileTree($chain); + $actual = $this->object->generateFileTree($chain); $this->assertSame($expectedPath, $actual); } } 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 b7a5a962ddb1550b23f240b1fd251ecf4a7812fe..1d458237ab6f04c51d0195c82b346f7dc23eaf88 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Factory/Compiled.php +++ b/lib/internal/Magento/Framework/ObjectManager/Factory/Compiled.php @@ -53,11 +53,10 @@ 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(); } @@ -85,13 +84,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); } diff --git a/lib/internal/Magento/Framework/Test/Unit/View/Asset/SourceTest.php b/lib/internal/Magento/Framework/Test/Unit/View/Asset/SourceTest.php deleted file mode 100644 index b1d22dca5d9a9692a2c8fed68235edee03e965f7..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Test/Unit/View/Asset/SourceTest.php +++ /dev/null @@ -1,285 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -// @codingStandardsIgnoreFile - -namespace Magento\Framework\Test\Unit\View\Asset; - -use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Framework\Filesystem\DriverPool; -use Magento\Framework\View\Asset\Source; - -/** - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) - */ -class SourceTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject - */ - private $filesystem; - - /** - * @var \Magento\Framework\Filesystem\Directory\ReadInterface|\PHPUnit_Framework_MockObject_MockObject - */ - private $rootDirRead; - - /** - * @var \Magento\Framework\Filesystem\Directory\WriteInterface|\PHPUnit_Framework_MockObject_MockObject - */ - private $varDir; - - /** - * @var \Magento\Framework\Filesystem\Directory\WriteInterface|\PHPUnit_Framework_MockObject_MockObject - */ - private $staticDirRead; - - /** - * @var \Magento\Framework\View\Asset\PreProcessor\Cache|\PHPUnit_Framework_MockObject_MockObject - */ - private $cache; - - /** - * @var \Magento\Framework\View\Asset\PreProcessor\Pool|\PHPUnit_Framework_MockObject_MockObject - */ - private $preProcessorPool; - - /** - * @var \Magento\Framework\View\Design\FileResolution\Fallback\StaticFile|\PHPUnit_Framework_MockObject_MockObject - */ - private $viewFileResolution; - - /** - * @var \Magento\Framework\View\Design\ThemeInterface|\PHPUnit_Framework_MockObject_MockObject - */ - private $theme; - - /** - * @var Source - */ - private $object; - - protected function setUp() - { - $this->cache = $this->getMock( - 'Magento\Framework\View\Asset\PreProcessor\Cache', [], [], '', false - ); - $this->preProcessorPool = $this->getMock( - 'Magento\Framework\View\Asset\PreProcessor\Pool', [], [], '', false - ); - $this->viewFileResolution = $this->getMock( - 'Magento\Framework\View\Design\FileResolution\Fallback\StaticFile', [], [], '', false - ); - $this->theme = $this->getMockForAbstractClass('Magento\Framework\View\Design\ThemeInterface'); - - $themeList = $this->getMockForAbstractClass('Magento\Framework\View\Design\Theme\ListInterface'); - $themeList->expects($this->any()) - ->method('getThemeByFullPath') - ->with('frontend/magento_theme') - ->will($this->returnValue($this->theme)); - - $this->initFilesystem(); - - $this->object = new Source( - $this->cache, - $this->filesystem, - $this->preProcessorPool, - $this->viewFileResolution, - $themeList - ); - } - - public function testGetFileCached() - { - $root = '/root/some/file.ext'; - $expected = '/var/some/file.ext'; - $filePath = 'some/file.ext'; - $this->viewFileResolution->expects($this->once()) - ->method('getFile') - ->with('frontend', $this->theme, 'en_US', $filePath, 'Magento_Module') - ->will($this->returnValue($root)); - $this->rootDirRead->expects($this->once()) - ->method('getRelativePath') - ->with($root) - ->will($this->returnValue($filePath)); - $this->cache->expects($this->once()) - ->method('load') - ->with("some/file.ext:{$filePath}") - ->will($this->returnValue(serialize([DirectoryList::VAR_DIR, $filePath]))); - - $this->varDir->expects($this->once())->method('getAbsolutePath') - ->with($filePath) - ->will($this->returnValue($expected)); - $this->assertSame($expected, $this->object->getFile($this->getAsset())); - } - - /** - * @param string $origFile - * @param string $origPath - * @param string $origContentType - * @param string $origContent - * @param string $isMaterialization - * @dataProvider getFileDataProvider - */ - public function testGetFile($origFile, $origPath, $origContent, $isMaterialization) - { - $filePath = 'some/file.ext'; - $cacheValue = "{$origPath}:{$filePath}"; - $this->viewFileResolution->expects($this->once()) - ->method('getFile') - ->with('frontend', $this->theme, 'en_US', $filePath, 'Magento_Module') - ->will($this->returnValue($origFile)); - $this->rootDirRead->expects($this->once()) - ->method('getRelativePath') - ->with($origFile) - ->will($this->returnValue($origPath)); - $this->cache->expects($this->once()) - ->method('load') - ->will($this->returnValue(false)); - $this->rootDirRead->expects($this->once()) - ->method('readFile') - ->with($origPath) - ->will($this->returnValue($origContent)); - $this->preProcessorPool->expects($this->once()) - ->method('process') - ->will($this->returnCallback([$this, 'chainTestCallback'])); - if ($isMaterialization) { - $this->varDir->expects($this->once()) - ->method('writeFile') - ->with('view_preprocessed/source/some/file.ext', 'processed'); - $this->cache->expects($this->once()) - ->method('save') - ->with( - serialize([DirectoryList::VAR_DIR, 'view_preprocessed/source/some/file.ext']), - $cacheValue - ); - $this->varDir->expects($this->once()) - ->method('getAbsolutePath') - ->with('view_preprocessed/source/some/file.ext')->will($this->returnValue('result')); - } else { - $this->varDir->expects($this->never())->method('writeFile'); - $this->cache->expects($this->once()) - ->method('save') - ->with(serialize([DirectoryList::ROOT, 'source/some/file.ext']), $cacheValue); - $this->rootDirRead->expects($this->once()) - ->method('getAbsolutePath') - ->with('source/some/file.ext') - ->will($this->returnValue('result')); - } - $this->assertSame('result', $this->object->getFile($this->getAsset())); - } - - /** - * @param string $path - * @param string $expected - * @dataProvider getContentTypeDataProvider - */ - public function testGetContentType($path, $expected) - { - $this->assertEquals($expected, $this->object->getContentType($path)); - } - - /** - * @return array - */ - public function getContentTypeDataProvider() - { - return [ - ['', ''], - ['path/file', ''], - ['path/file.ext', 'ext'], - ]; - } - - /** - * A callback for affecting preprocessor chain in the test - * - * @param \Magento\Framework\View\Asset\PreProcessor\Chain $chain - */ - public function chainTestCallback(\Magento\Framework\View\Asset\PreProcessor\Chain $chain) - { - $chain->setContentType('ext'); - $chain->setContent('processed'); - } - - /** - * @return array - */ - public function getFileDataProvider() - { - return [ - ['/root/some/file.ext', 'source/some/file.ext', 'processed', false], - ['/root/some/file.ext', 'source/some/file.ext', 'not_processed', true], - ['/root/some/file.ext2', 'source/some/file.ext2', 'processed', true], - ['/root/some/file.ext2', 'source/some/file.ext2', 'not_processed', true], - ]; - } - - protected function initFilesystem() - { - $this->filesystem = $this->getMock('Magento\Framework\Filesystem', [], [], '', false); - $this->rootDirRead = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\ReadInterface'); - $this->staticDirRead = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\ReadInterface'); - $this->varDir = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface'); - - $readDirMap = [ - [DirectoryList::ROOT, DriverPool::FILE, $this->rootDirRead], - [DirectoryList::STATIC_VIEW, DriverPool::FILE, $this->staticDirRead], - [DirectoryList::VAR_DIR, DriverPool::FILE, $this->varDir], - ]; - - $this->filesystem->expects($this->any()) - ->method('getDirectoryRead') - ->will($this->returnValueMap($readDirMap)); - $this->filesystem->expects($this->any()) - ->method('getDirectoryWrite') - ->with(DirectoryList::VAR_DIR) - ->will($this->returnValue($this->varDir)); - } - - /** - * Create an asset mock - * - * @param bool $isFallback - * @return \Magento\Framework\View\Asset\File|\PHPUnit_Framework_MockObject_MockObject - */ - protected function getAsset($isFallback = true) - { - if ($isFallback) { - $context = new \Magento\Framework\View\Asset\File\FallbackContext( - 'http://example.com/static/', - 'frontend', - 'magento_theme', - 'en_US' - ); - } else { - $context = new \Magento\Framework\View\Asset\File\Context( - 'http://example.com/static/', - DirectoryList::STATIC_VIEW, - '' - ); - } - - $asset = $this->getMock('Magento\Framework\View\Asset\File', [], [], '', false); - $asset->expects($this->any()) - ->method('getContext') - ->will($this->returnValue($context)); - $asset->expects($this->any()) - ->method('getFilePath') - ->will($this->returnValue('some/file.ext')); - $asset->expects($this->any()) - ->method('getPath') - ->will($this->returnValue('some/file.ext')); - $asset->expects($this->any()) - ->method('getModule') - ->will($this->returnValue('Magento_Module')); - $asset->expects($this->any()) - ->method('getContentType') - ->will($this->returnValue('ext')); - - return $asset; - } -} diff --git a/lib/internal/Magento/Framework/View/Asset/PreProcessor/Chain.php b/lib/internal/Magento/Framework/View/Asset/PreProcessor/Chain.php index f8b971338cac1101009402d132014f4198a1f559..cf7a30b161a7b27986eba272d084eafb418732eb 100644 --- a/lib/internal/Magento/Framework/View/Asset/PreProcessor/Chain.php +++ b/lib/internal/Magento/Framework/View/Asset/PreProcessor/Chain.php @@ -6,6 +6,8 @@ namespace Magento\Framework\View\Asset\PreProcessor; +use Magento\Framework\View\Asset\LocalInterface; + /** * An object that's passed to preprocessors to carry current and original information for processing * Encapsulates complexity of all necessary context and parameters @@ -13,7 +15,7 @@ namespace Magento\Framework\View\Asset\PreProcessor; class Chain { /** - * @var \Magento\Framework\View\Asset\LocalInterface + * @var LocalInterface */ private $asset; @@ -25,7 +27,7 @@ class Chain /** * @var string */ - private $origContentType; + protected $origContentType; /** * @var string @@ -40,51 +42,36 @@ class Chain /** * @var string */ - private $targetContentType; - - /** - * @var string - */ - private $appMode; + protected $targetContentType; /** * @var null|string */ - private $targetAssetPath; + protected $targetAssetPath; /** - * @param \Magento\Framework\View\Asset\LocalInterface $asset + * @param LocalInterface $asset * @param string $origContent * @param string $origContentType - * @param null $origAssetPath - * @param string $appMode */ public function __construct( - \Magento\Framework\View\Asset\LocalInterface $asset, + LocalInterface $asset, $origContent, - $origContentType, - $origAssetPath = null, - $appMode = \Magento\Framework\App\State::MODE_DEFAULT + $origContentType ) { $this->asset = $asset; $this->origContent = $origContent; $this->content = $origContent; $this->origContentType = $origContentType; $this->contentType = $origContentType; - $this->appMode = $appMode; $this->targetContentType = $asset->getContentType(); $this->targetAssetPath = $asset->getPath(); - - if ($appMode == \Magento\Framework\App\State::MODE_DEVELOPER) { - $this->targetContentType = $this->origContentType; - $this->targetAssetPath = $origAssetPath; - } } /** * Get asset object * - * @return \Magento\Framework\View\Asset\LocalInterface + * @return LocalInterface */ public function getAsset() { diff --git a/lib/internal/Magento/Framework/View/Asset/PreProcessor/ChainFactory.php b/lib/internal/Magento/Framework/View/Asset/PreProcessor/ChainFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..e817380eff140e92907eb8ffdc453495e0158d86 --- /dev/null +++ b/lib/internal/Magento/Framework/View/Asset/PreProcessor/ChainFactory.php @@ -0,0 +1,43 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Asset\PreProcessor; + +use Magento\Framework\ObjectManagerInterface; + +class ChainFactory implements ChainFactoryInterface +{ + /** + * Object manager + * + * @var ObjectManagerInterface + */ + private $_objectManager; + + /** + * @param ObjectManagerInterface $objectManager + */ + public function __construct( + ObjectManagerInterface $objectManager + ) { + $this->_objectManager = $objectManager; + } + + /** + * {inheritdoc} + */ + public function create(array $arguments = []) + { + $arguments = array_intersect_key( + $arguments, + [ + 'asset' => 'asset', + 'origContent' => 'origContent', + 'origContentType' => 'origContentType' + ] + ); + return $this->_objectManager->create('Magento\Framework\View\Asset\PreProcessor\Chain', $arguments); + } +} diff --git a/lib/internal/Magento/Framework/View/Asset/PreProcessor/ChainFactoryInterface.php b/lib/internal/Magento/Framework/View/Asset/PreProcessor/ChainFactoryInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..737fced8777ff1df8cdccccb91d3c37f789035bb --- /dev/null +++ b/lib/internal/Magento/Framework/View/Asset/PreProcessor/ChainFactoryInterface.php @@ -0,0 +1,17 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Asset\PreProcessor; + +interface ChainFactoryInterface +{ + /** + * Creates chain of pre-processors + * + * @param array $arguments + * @return Chain + */ + public function create(array $arguments = []); +} diff --git a/lib/internal/Magento/Framework/View/Asset/Source.php b/lib/internal/Magento/Framework/View/Asset/Source.php index 2518c6973eaf06b14584ed0d435a0dea5ade18b9..29d7d4a6af02c803a18b8a27fdf0e2279b22e1d8 100644 --- a/lib/internal/Magento/Framework/View/Asset/Source.php +++ b/lib/internal/Magento/Framework/View/Asset/Source.php @@ -7,6 +7,7 @@ namespace Magento\Framework\View\Asset; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\View\Asset\PreProcessor\ChainFactoryInterface; use Magento\Framework\View\Design\FileResolution\Fallback\Resolver\Simple; /** @@ -52,9 +53,9 @@ class Source private $themeList; /** - * @var string + * @var ChainFactoryInterface */ - private $appMode; + private $chainFactory; /** * @param PreProcessor\Cache $cache @@ -62,7 +63,7 @@ class Source * @param PreProcessor\Pool $preProcessorPool * @param \Magento\Framework\View\Design\FileResolution\Fallback\StaticFile $fallback * @param \Magento\Framework\View\Design\Theme\ListInterface $themeList - * @param string $appMode + * @param ChainFactoryInterface $chainFactory */ public function __construct( PreProcessor\Cache $cache, @@ -70,7 +71,7 @@ class Source PreProcessor\Pool $preProcessorPool, \Magento\Framework\View\Design\FileResolution\Fallback\StaticFile $fallback, \Magento\Framework\View\Design\Theme\ListInterface $themeList, - $appMode = \Magento\Framework\App\State::MODE_DEFAULT + ChainFactoryInterface $chainFactory ) { $this->cache = $cache; $this->filesystem = $filesystem; @@ -79,7 +80,7 @@ class Source $this->preProcessorPool = $preProcessorPool; $this->fallback = $fallback; $this->themeList = $themeList; - $this->appMode = $appMode; + $this->chainFactory = $chainFactory; } /** @@ -136,13 +137,16 @@ class Source if ($cached) { return unserialize($cached); } - $chain = new \Magento\Framework\View\Asset\PreProcessor\Chain( - $asset, - $path ? $this->rootDir->readFile($path) : "", - $this->getContentType($path), - $path, - $this->appMode + + $chain = $this->chainFactory->create( + [ + 'asset' => $asset, + 'origContent' => $this->rootDir->readFile($path), + 'origContentType' => $this->getContentType($path), + 'origAssetPath' => $path + ] ); + $this->preProcessorPool->process($chain); $chain->assertValid(); if ($chain->isChanged()) { @@ -155,6 +159,15 @@ class Source return $result; } + /** + * @param LocalInterface $asset + * @return bool|string + */ + public function findSource(LocalInterface $asset) + { + return $this->findSourceFile($asset); + } + /** * Infer a content type from the specified path * diff --git a/lib/internal/Magento/Framework/View/Asset/SourceFileGeneratorInterface.php b/lib/internal/Magento/Framework/View/Asset/SourceFileGeneratorInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..ff36547d20cb3f7b19d0ac1a9a1a8d71cdb31993 --- /dev/null +++ b/lib/internal/Magento/Framework/View/Asset/SourceFileGeneratorInterface.php @@ -0,0 +1,23 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Asset; + +use Magento\Framework\View\Asset\PreProcessor\Chain; + +/** + * Interface SourceFileGenerator + * + * @package Magento\Framework\View\Asset + */ +interface SourceFileGeneratorInterface +{ + /** + * @param Chain $chain + * + * @return mixed + */ + public function generateFileTree(Chain $chain); +} diff --git a/lib/internal/Magento/Framework/View/Asset/SourceFileGeneratorPool.php b/lib/internal/Magento/Framework/View/Asset/SourceFileGeneratorPool.php new file mode 100644 index 0000000000000000000000000000000000000000..5dcf15f79b2d7ed6f5fe53d10250391ecd80f505 --- /dev/null +++ b/lib/internal/Magento/Framework/View/Asset/SourceFileGeneratorPool.php @@ -0,0 +1,48 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Framework\View\Asset; + +/** + * Class SourceFileGeneratorFactory + * + * @package Magento\Framework\View\Asset + */ +class SourceFileGeneratorPool +{ + /** + * Renderer Types + * + * @var array + */ + private $fileGeneratorTypes; + + /** + * Factory constructor + * + * @param SourceFileGeneratorInterface[] $fileGeneratorTypes + */ + public function __construct(array $fileGeneratorTypes = []) + { + $this->fileGeneratorTypes = $fileGeneratorTypes; + } + + /** + * Create class instance + * + * @param string $generatorType + * + * @return SourceFileGeneratorInterface + */ + public function create($generatorType) + { + if (!$this->fileGeneratorTypes[$generatorType]) { + throw new \LogicException('Wrong file generator type!'); + } + + return $this->fileGeneratorTypes[$generatorType]; + } +} diff --git a/lib/internal/Magento/Framework/View/Model/PageLayout/Config/BuilderInterface.php b/lib/internal/Magento/Framework/View/Model/PageLayout/Config/BuilderInterface.php index 107bd1f278605435c2e1e3f238a09dc291e61b83..bcbba380767115452038f76526e8ebbedf7f65b3 100644 --- a/lib/internal/Magento/Framework/View/Model/PageLayout/Config/BuilderInterface.php +++ b/lib/internal/Magento/Framework/View/Model/PageLayout/Config/BuilderInterface.php @@ -5,8 +5,6 @@ */ namespace Magento\Framework\View\Model\PageLayout\Config; -use Magento\Framework\View\LayoutInterface; - /** * Interface BuilderInterface */ diff --git a/lib/internal/Magento/Framework/View/Page/Config/Renderer.php b/lib/internal/Magento/Framework/View/Page/Config/Renderer.php index 0e05ac3da9c246d5fff6c9ced0f83e3275ded24f..ebfd7944a88aa054f316917dbd1da419ffdfde71 100644 --- a/lib/internal/Magento/Framework/View/Page/Config/Renderer.php +++ b/lib/internal/Magento/Framework/View/Page/Config/Renderer.php @@ -3,7 +3,6 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Framework\View\Page\Config; use Magento\Framework\View\Asset\GroupedCollection; @@ -14,7 +13,7 @@ use Magento\Framework\View\Page\Config; * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Renderer +class Renderer implements RendererInterface { /** * @var array @@ -56,16 +55,6 @@ class Renderer */ protected $urlBuilder; - /** - * @var string - */ - private $appMode; - - /** - * @var \Magento\Framework\View\Asset\Repository - */ - private $assetRepo; - /** * @param \Magento\Framework\View\Page\Config $pageConfig * @param \Magento\Framework\View\Asset\MinifyService $assetMinifyService @@ -74,8 +63,6 @@ class Renderer * @param \Magento\Framework\Escaper $escaper * @param \Magento\Framework\Stdlib\String $string * @param \Psr\Log\LoggerInterface $logger - * @param \Magento\Framework\View\Asset\Repository $assetRepo - * @param string $appMode */ public function __construct( Config $pageConfig, @@ -84,9 +71,7 @@ class Renderer \Magento\Framework\UrlInterface $urlBuilder, \Magento\Framework\Escaper $escaper, \Magento\Framework\Stdlib\String $string, - \Psr\Log\LoggerInterface $logger, - \Magento\Framework\View\Asset\Repository $assetRepo, - $appMode = \Magento\Framework\App\State::MODE_DEFAULT + \Psr\Log\LoggerInterface $logger ) { $this->pageConfig = $pageConfig; $this->assetMinifyService = $assetMinifyService; @@ -95,8 +80,6 @@ class Renderer $this->escaper = $escaper; $this->string = $string; $this->logger = $logger; - $this->assetRepo = $assetRepo; - $this->appMode = $appMode; } /** @@ -121,7 +104,7 @@ class Renderer $result .= $this->renderMetadata(); $result .= $this->renderTitle(); $this->prepareFavicon(); - $result .= $this->renderAssets(); + $result .= $this->renderAssets($this->getAvailableResultGroups()); $result .= $this->pageConfig->getIncludes(); return $result; } @@ -232,13 +215,12 @@ class Renderer /** * Returns rendered HTML for all Assets (CSS before) * + * @param array $resultGroups + * * @return string */ - public function renderAssets() + public function renderAssets($resultGroups = []) { - $resultGroups = array_fill_keys($this->assetTypeOrder, ''); - // less js have to be injected before any *.js in developer mode - $resultGroups = $this->renderLessJsScripts($resultGroups); /** @var $group \Magento\Framework\View\Asset\PropertyGroup */ foreach ($this->pageConfig->getAssetCollection()->getGroups() as $group) { $type = $group->getProperty(GroupedCollection::PROPERTY_CONTENT_TYPE); @@ -328,10 +310,6 @@ class Renderer case 'css': $attributes = ' rel="stylesheet" type="text/css" ' . ($attributes ?: ' media="all"'); break; - - case 'less': - $attributes = ' rel="stylesheet/less" type="text/css" ' . ($attributes ?: ' media="all"'); - break; } return $attributes; } @@ -381,22 +359,9 @@ class Renderer { $result = ''; try { + /** @var $asset \Magento\Framework\View\Asset\AssetInterface */ foreach ($assets as $asset) { - /** @var $asset \Magento\Framework\View\Asset\File */ - // todo will be fixed in MAGETWO-33631 - if ($this->appMode == \Magento\Framework\App\State::MODE_DEVELOPER) { - if ($asset instanceof \Magento\Framework\View\Asset\File && - $asset->getSourceUrl() != $asset->getUrl() - ) { - $attributes = $this->addDefaultAttributes('less', []); - $groupTemplate = $this->getAssetTemplate('less', $attributes); - $result .= sprintf($groupTemplate, $asset->getUrl()); - } else { - $result .= sprintf($template, $asset->getUrl()); - } - } else { - $result .= sprintf($template, $asset->getUrl()); - } + $result .= sprintf($template, $asset->getUrl()); } } catch (\Magento\Framework\Exception $e) { $this->logger->critical($e); @@ -406,22 +371,10 @@ class Renderer } /** - * Injecting less.js compiler - * - * @param array $resultGroups - * - * @return mixed + * @return array */ - private function renderLessJsScripts($resultGroups) + public function getAvailableResultGroups() { - if (\Magento\Framework\App\State::MODE_DEVELOPER == $this->appMode) { - // less js have to be injected before any *.js in developer mode - $lessJsConfigAsset = $this->assetRepo->createAsset('less/config.less.js'); - $resultGroups['js'] .= sprintf('<script src="%s"></script>' . "\n", $lessJsConfigAsset->getUrl()) ; - $lessJsAsset = $this->assetRepo->createAsset('less/less.min.js'); - $resultGroups['js'] .= sprintf('<script src="%s"></script>' . "\n", $lessJsAsset->getUrl()) ; - } - - return $resultGroups; + return array_fill_keys($this->assetTypeOrder, ''); } } diff --git a/lib/internal/Magento/Framework/View/Page/Config/RendererInterface.php b/lib/internal/Magento/Framework/View/Page/Config/RendererInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..2cc1a147a0ef67ff3bdfcf80a3aa2ef0ee0bf449 --- /dev/null +++ b/lib/internal/Magento/Framework/View/Page/Config/RendererInterface.php @@ -0,0 +1,61 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Framework\View\Page\Config; + +/** + * Interface RendererInterface + * + * @package Magento\Framework\View\Page\Config + */ +interface RendererInterface +{ + /** + * Render Element Attributes + * + * @param string $elementType + * + * @return string + */ + public function renderElementAttributes($elementType); + + /** + * Render Head Content + * + * @return string + */ + public function renderHeadContent(); + + /** + * Render Title + * + * @return string + */ + public function renderTitle(); + + /** + * Render Metadata + * + * @return string + */ + public function renderMetadata(); + + /** + * Prepare Favicon + * + * @return void + */ + public function prepareFavicon(); + + /** + * Returns rendered HTML for all Assets (CSS before) + * + * @param array $resultGroups + * + * @return string + */ + public function renderAssets($resultGroups = []); +} diff --git a/lib/internal/Magento/Framework/View/Result/Page.php b/lib/internal/Magento/Framework/View/Result/Page.php index 8a78993d0b7ccf77daf6d667066d71785ad32c3c..e2f12e786c4421c20f67263c67fca8e4c1c3c2d5 100644 --- a/lib/internal/Magento/Framework/View/Result/Page.php +++ b/lib/internal/Magento/Framework/View/Result/Page.php @@ -37,7 +37,7 @@ class Page extends Layout protected $pageConfig; /** - * @var \Magento\Framework\View\Page\Config\Renderer + * @var \Magento\Framework\View\Page\Config\RendererInterface */ protected $pageConfigRenderer; diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/ChainTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/ChainTest.php index e9456819279929fddb5631e2269cc889988c0cb3..e0c4e8b4d7003c5a88e7d6194e8117574be2bc9c 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/ChainTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/ChainTest.php @@ -6,7 +6,7 @@ namespace Magento\Framework\View\Test\Unit\Asset\PreProcessor; -use \Magento\Framework\View\Asset\PreProcessor\Chain; +use Magento\Framework\View\Asset\PreProcessor\Chain; /** * Class ChainTest @@ -90,46 +90,4 @@ class ChainTest extends \PHPUnit_Framework_TestCase ['anotherContent', 'anotherType', true], ]; } - - public function testChainTargetAssetPathNonDevMode() - { - $assetPath = 'assetPath'; - $origPath = 'origPath'; - - $this->asset = $this->getMockForAbstractClass('\Magento\Framework\View\Asset\LocalInterface'); - $this->asset->expects($this->once()) - ->method('getContentType') - ->will($this->returnValue('assetType')); - $this->asset->expects($this->once()) - ->method('getPath') - ->will($this->returnValue($assetPath)); - $this->object = new Chain($this->asset, 'origContent', 'origType', $origPath); - - $this->assertSame($this->object->getTargetAssetPath(), $assetPath); - $this->assertNotSame($this->object->getTargetAssetPath(), $origPath); - } - - public function testChainTargetAssetPathDevMode() - { - $assetPath = 'assetPath'; - $origPath = 'origPath'; - - $this->asset = $this->getMockForAbstractClass('\Magento\Framework\View\Asset\LocalInterface'); - $this->asset->expects($this->once()) - ->method('getContentType') - ->will($this->returnValue('assetType')); - $this->asset->expects($this->once()) - ->method('getPath') - ->will($this->returnValue($assetPath)); - $this->object = new Chain( - $this->asset, - 'origContent', - 'origType', - $origPath, - \Magento\Framework\App\State::MODE_DEVELOPER - ); - - $this->assertSame($this->object->getTargetAssetPath(), $origPath); - $this->assertNotSame($this->object->getTargetAssetPath(), $assetPath); - } } diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/ModuleNotationTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/ModuleNotationTest.php deleted file mode 100644 index 51930bbd3853ea62171a7c76a8765897ef78e951..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/ModuleNotationTest.php +++ /dev/null @@ -1,55 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -// @codingStandardsIgnoreFile - -namespace Magento\Framework\View\Test\Unit\Asset\PreProcessor; - -use \Magento\Framework\View\Asset\PreProcessor\ModuleNotation; - -class ModuleNotationTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var \Magento\Framework\View\Asset\PreProcessor\ModuleNotation - */ - protected $moduleNotation; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $cssResolverMock; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $assetMock; - - protected function setUp() - { - $this->assetMock = $this->getMock('Magento\Framework\View\Asset\File', [], [], '', false); - $this->cssResolverMock = $this->getMock('Magento\Framework\View\Url\CssResolver', [], [], '', false); - $notationResolver = $this->getMock( - '\Magento\Framework\View\Asset\ModuleNotation\Resolver', [], [], '', false - ); - $this->moduleNotation = new ModuleNotation( - $this->cssResolverMock, $notationResolver - ); - } - - public function testProcess() - { - $content = 'ol.favicon {background: url(Magento_Theme::favicon.ico)}'; - $chain = new \Magento\Framework\View\Asset\PreProcessor\Chain($this->assetMock, $content, 'css'); - $replacedContent = 'Foo_Bar/images/logo.gif'; - $this->cssResolverMock->expects($this->once()) - ->method('replaceRelativeUrls') - ->with($content, $this->isInstanceOf('Closure')) - ->will($this->returnValue($replacedContent)); - $this->assertSame($content, $chain->getContent()); - $this->moduleNotation->process($chain); - $this->assertSame($replacedContent, $chain->getContent()); - } -} diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Asset/SourceTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Asset/SourceTest.php index 026fbf85e677e1977a0ce9e51b23664c9f848b21..4db38ebb9c55a2e78dd179a4e8ff94d25b3c1620 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Asset/SourceTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Asset/SourceTest.php @@ -8,9 +8,11 @@ namespace Magento\Framework\View\Test\Unit\Asset; -use \Magento\Framework\View\Asset\Source; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem\DriverPool; +use Magento\Framework\View\Asset\PreProcessor\ChainFactoryInterface; +use Magento\Framework\View\Asset\PreProcessor\Chain; +use Magento\Framework\View\Asset\Source; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -62,6 +64,16 @@ class SourceTest extends \PHPUnit_Framework_TestCase */ private $object; + /** + * @var ChainFactoryInterface | \PHPUnit_Framework_MockObject_MockObject + */ + private $chainFactory; + + /** + * @var Chain | \PHPUnit_Framework_MockObject_MockObject + */ + private $chain; + protected function setUp() { $this->cache = $this->getMock( @@ -74,6 +86,17 @@ class SourceTest extends \PHPUnit_Framework_TestCase 'Magento\Framework\View\Design\FileResolution\Fallback\StaticFile', [], [], '', false ); $this->theme = $this->getMockForAbstractClass('Magento\Framework\View\Design\ThemeInterface'); + /** @var \Magento\Framework\App\Config\ScopeConfigInterface $config */ + + $this->chainFactory = $this->getMockBuilder('Magento\Framework\View\Asset\PreProcessor\ChainFactoryInterface') + ->getMock(); + $this->chain = $this->getMockBuilder('Magento\Framework\View\Asset\PreProcessor\Chain') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $this->chainFactory->expects($this->any()) + ->method('create') + ->willReturn($this->chain); $themeList = $this->getMockForAbstractClass('Magento\Framework\View\Design\Theme\ListInterface'); $themeList->expects($this->any()) @@ -88,7 +111,8 @@ class SourceTest extends \PHPUnit_Framework_TestCase $this->filesystem, $this->preProcessorPool, $this->viewFileResolution, - $themeList + $themeList, + $this->chainFactory ); } @@ -117,11 +141,11 @@ class SourceTest extends \PHPUnit_Framework_TestCase } /** - * @param string $origFile - * @param string $origPath - * @param string $origContentType - * @param string $origContent - * @param string $isMaterialization + * @param $origFile + * @param $origPath + * @param $origContent + * @param $isMaterialization + * * @dataProvider getFileDataProvider */ public function testGetFile($origFile, $origPath, $origContent, $isMaterialization) @@ -145,8 +169,20 @@ class SourceTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue($origContent)); $this->preProcessorPool->expects($this->once()) ->method('process') - ->will($this->returnCallback([$this, 'chainTestCallback'])); + ->with($this->chain); if ($isMaterialization) { + $this->chain + ->expects($this->once()) + ->method('isChanged') + ->willReturn(true); + $this->chain + ->expects($this->once()) + ->method('getContent') + ->willReturn('processed'); + $this->chain + ->expects($this->once()) + ->method('getTargetAssetPath') + ->willReturn($filePath); $this->varDir->expects($this->once()) ->method('writeFile') ->with('view_preprocessed/source/some/file.ext', 'processed'); @@ -197,9 +233,9 @@ class SourceTest extends \PHPUnit_Framework_TestCase /** * A callback for affecting preprocessor chain in the test * - * @param \Magento\Framework\View\Asset\PreProcessor\Chain $chain + * @param Chain $chain */ - public function chainTestCallback(\Magento\Framework\View\Asset\PreProcessor\Chain $chain) + public function chainTestCallback(Chain $chain) { $chain->setContentType('ext'); $chain->setContent('processed'); diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Page/Config/RendererTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Page/Config/RendererTest.php index 8447dc9b6c3e922e7e0bfe228357002e8fdc360a..e407988f77df31cddaa18ff21d82c26401b4f078 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Page/Config/RendererTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Page/Config/RendererTest.php @@ -6,10 +6,10 @@ namespace Magento\Framework\View\Test\Unit\Page\Config; -use \Magento\Framework\View\Page\Config\Renderer; -use \Magento\Framework\View\Page\Config\Generator; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Framework\View\Asset\GroupedCollection; -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; +use Magento\Framework\View\Page\Config\Renderer; +use Magento\Framework\View\Page\Config\Generator; /** * Test for page config renderer model @@ -73,7 +73,9 @@ class RendererTest extends \PHPUnit_Framework_TestCase */ protected $titleMock; - /** @var ObjectManagerHelper */ + /** + * @var ObjectManager + */ protected $objectManagerHelper; protected function setUp() @@ -119,7 +121,7 @@ class RendererTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $this->objectManagerHelper = new ObjectManagerHelper($this); + $this->objectManagerHelper = new ObjectManager($this); $this->renderer = $this->objectManagerHelper->getObject( 'Magento\Framework\View\Page\Config\Renderer', [ @@ -333,7 +335,10 @@ class RendererTest extends \PHPUnit_Framework_TestCase ->with('', ['_direct' => 'core/index/notFound']) ->willReturn($assetNoRoutUrl); - $this->assertEquals($expectedResult, $this->renderer->renderAssets()); + $this->assertEquals( + $expectedResult, + $this->renderer->renderAssets($this->renderer->getAvailableResultGroups()) + ); } /**