Skip to content

Commit 2618760

Browse files
committed
MAGETWO-21072: Entry point responsiveness
- added materialization strategy
1 parent 42eb908 commit 2618760

File tree

6 files changed

+126
-15
lines changed

6 files changed

+126
-15
lines changed

app/etc/di.xml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,12 +508,20 @@
508508
<type name="Magento\Framework\App\StaticResource">
509509
<arguments>
510510
<argument name="response" xsi:type="object" shared="false">Magento\Core\Model\File\Storage\Response</argument>
511-
<argument name="publisher" xsi:type="object">symlinkPublisher</argument>
511+
<argument name="publisher" xsi:type="object">developerPublisher</argument>
512512
</arguments>
513513
</type>
514-
<virtualType name="symlinkPublisher" type="Magento\Framework\App\View\Asset\Publisher">
514+
<virtualType name="developerPublisher" type="Magento\Framework\App\View\Asset\Publisher">
515515
<arguments>
516-
<argument name="publisher" xsi:type="object">Magento\Framework\App\View\Asset\Publisher\Symlink</argument>
516+
<argument name="materializationStrategyFactory" xsi:type="object">developerMaterialization</argument>
517+
</arguments>
518+
</virtualType>
519+
<virtualType name="developerMaterialization" type="Magento\Framework\App\View\Asset\MaterializationStrategy\Factory">
520+
<arguments>
521+
<argument name="strategiesList" xsi:type="array">
522+
<item name="view_preprocessed" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink</item>
523+
<item name="default" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Copy</item>
524+
</argument>
517525
</arguments>
518526
</virtualType>
519527
<virtualType name="fallbackResolverSimpleWithGroupedCache" type="Magento\Framework\View\Design\FileResolution\Fallback\Resolver\Simple">

lib/internal/Magento/Framework/App/View/Asset/Publisher/Copy.php renamed to lib/internal/Magento/Framework/App/View/Asset/MaterializationStrategy/Copy.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
namespace Magento\Framework\App\View\Asset\Publisher;
7+
namespace Magento\Framework\App\View\Asset\MaterializationStrategy;
88

99
use Magento\Framework\Filesystem\Directory\WriteInterface;
10+
use Magento\Framework\View\Asset;
1011

11-
class Copy implements PublisherInterface
12+
class Copy implements StrategyInterface
1213
{
1314
/**
1415
* Publish file
@@ -27,4 +28,15 @@ public function publishFile(
2728
) {
2829
return $rootDir->copyFile($sourcePath, $destinationPath, $targetDir);
2930
}
31+
32+
/**
33+
* Whether the strategy can be applied
34+
*
35+
* @param Asset\LocalInterface $asset
36+
* @return bool
37+
*/
38+
public function isSupported(Asset\LocalInterface $asset)
39+
{
40+
return true;
41+
}
3042
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\App\View\Asset\MaterializationStrategy;
8+
9+
use Magento\Framework\View\Asset;
10+
11+
class Factory
12+
{
13+
/**
14+
* Object Manager instance
15+
*
16+
* @var \Magento\Framework\ObjectManagerInterface
17+
*/
18+
protected $_objectManager;
19+
20+
/**
21+
* Strategies list
22+
*
23+
* @var array
24+
*/
25+
protected $strategiesList;
26+
27+
/**
28+
* Default strategy key
29+
*/
30+
const DEFAULT_STRATEGY = 'Magento\Framework\App\View\Asset\MaterializationStrategy\Copy';
31+
32+
/**
33+
* @param \Magento\Framework\ObjectManagerInterface $objectManager
34+
* @param StrategyInterface[] $strategiesList
35+
*/
36+
public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager, $strategiesList = [])
37+
{
38+
$this->_objectManager = $objectManager;
39+
$this->strategiesList = $strategiesList;
40+
}
41+
42+
/**
43+
* Create materialization strategy basing on asset
44+
*
45+
* @param Asset\LocalInterface $asset
46+
* @return StrategyInterface
47+
*
48+
* @throws \LogicException
49+
*/
50+
public function create(Asset\LocalInterface $asset)
51+
{
52+
if (empty($this->strategiesList)) {
53+
$this->strategiesList[] = $this->_objectManager->get(self::DEFAULT_STRATEGY);
54+
}
55+
56+
foreach ($this->strategiesList as $strategy) {
57+
if ($strategy->isSupported($asset)) {
58+
return $strategy;
59+
}
60+
}
61+
62+
throw new \LogicException(__('No materialization strategy is supported'));
63+
}
64+
}

lib/internal/Magento/Framework/App/View/Asset/Publisher/PublisherInterface.php renamed to lib/internal/Magento/Framework/App/View/Asset/MaterializationStrategy/StrategyInterface.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
namespace Magento\Framework\App\View\Asset\Publisher;
7+
namespace Magento\Framework\App\View\Asset\MaterializationStrategy;
88

99
use Magento\Framework\Filesystem\Directory\WriteInterface;
10+
use Magento\Framework\View\Asset;
1011

11-
interface PublisherInterface
12+
interface StrategyInterface
1213
{
1314
/**
1415
* Publish file
@@ -25,4 +26,12 @@ public function publishFile(
2526
$sourcePath,
2627
$destinationPath
2728
);
29+
30+
/**
31+
* Whether the strategy can be applied
32+
*
33+
* @param Asset\LocalInterface $asset
34+
* @return bool
35+
*/
36+
public function isSupported(Asset\LocalInterface $asset);
2837
}

lib/internal/Magento/Framework/App/View/Asset/Publisher/Symlink.php renamed to lib/internal/Magento/Framework/App/View/Asset/MaterializationStrategy/Symlink.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
namespace Magento\Framework\App\View\Asset\Publisher;
7+
namespace Magento\Framework\App\View\Asset\MaterializationStrategy;
88

99
use Magento\Framework\Filesystem\Directory\WriteInterface;
10+
use Magento\Framework\View\Asset;
1011

11-
class Symlink implements PublisherInterface
12+
class Symlink implements StrategyInterface
1213
{
1314
/**
1415
* Publish file
@@ -27,4 +28,20 @@ public function publishFile(
2728
) {
2829
return $rootDir->createSymlink($sourcePath, $destinationPath, $targetDir);
2930
}
31+
32+
/**
33+
* Whether the strategy can be applied
34+
*
35+
* @param Asset\LocalInterface $asset
36+
* @return bool
37+
*/
38+
public function isSupported(Asset\LocalInterface $asset)
39+
{
40+
$sourceParts = explode('/', $asset->getSourceFile());
41+
if (in_array(Asset\Source::TMP_MATERIALIZATION_DIR, $sourceParts)) {
42+
return false;
43+
}
44+
45+
return true;
46+
}
3047
}

lib/internal/Magento/Framework/App/View/Asset/Publisher.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ class Publisher
2020
protected $filesystem;
2121

2222
/**
23-
* @var Publisher\PublisherInterface
23+
* @var MaterializationStrategy\Factory
2424
*/
25-
private $publisher;
25+
private $materializationStrategyFactory;
2626

2727
/**
2828
* @param \Magento\Framework\Filesystem $filesystem
29-
* @param Publisher\PublisherInterface $publisher
29+
* @param MaterializationStrategy\Factory $materializationStrategyFactory
3030
*/
3131
public function __construct(
3232
\Magento\Framework\Filesystem $filesystem,
33-
Publisher\PublisherInterface $publisher
33+
MaterializationStrategy\Factory $materializationStrategyFactory
3434
) {
3535
$this->filesystem = $filesystem;
36-
$this->publisher = $publisher;
36+
$this->materializationStrategyFactory = $materializationStrategyFactory;
3737
}
3838

3939
/**
@@ -61,6 +61,7 @@ private function publishAsset(Asset\LocalInterface $asset)
6161
$rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
6262
$source = $rootDir->getRelativePath($asset->getSourceFile());
6363
$destination = $asset->getPath();
64-
return $this->publisher->publishFile($rootDir, $targetDir, $source, $destination);
64+
$strategy = $this->materializationStrategyFactory->create($asset);
65+
return $strategy->publishFile($rootDir, $targetDir, $source, $destination);
6566
}
6667
}

0 commit comments

Comments
 (0)