Skip to content

Commit 67f29eb

Browse files
committed
Merge branch 'MAGETWO-35298' into develop
2 parents 8e30a58 + 95ddc08 commit 67f29eb

File tree

9 files changed

+340
-190
lines changed

9 files changed

+340
-190
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Developer\Model\Less\FileGenerator;
7+
8+
use Magento\Framework\Less\FileGenerator\RelatedGenerator;
9+
use Magento\Framework\View\Asset\LocalInterface;
10+
11+
/**
12+
* Class PublicationDecorator
13+
* Decorates generator of related assets and publishes them
14+
*
15+
* @package Magento\Developer\Model\Less\FileGenerator
16+
*/
17+
class PublicationDecorator extends RelatedGenerator
18+
{
19+
/**
20+
* @var \Magento\Framework\App\View\Asset\Publisher
21+
*/
22+
private $publisher;
23+
24+
/**
25+
* @param \Magento\Framework\Filesystem $filesystem
26+
* @param \Magento\Framework\View\Asset\Repository $assetRepo
27+
* @param \Magento\Framework\Less\File\Temporary $temporaryFile
28+
* @param \Magento\Framework\App\View\Asset\Publisher $publisher
29+
*/
30+
public function __construct(
31+
\Magento\Framework\Filesystem $filesystem,
32+
\Magento\Framework\View\Asset\Repository $assetRepo,
33+
\Magento\Framework\Less\File\Temporary $temporaryFile,
34+
\Magento\Framework\App\View\Asset\Publisher $publisher
35+
) {
36+
parent::__construct($filesystem, $assetRepo, $temporaryFile);
37+
$this->publisher = $publisher;
38+
}
39+
40+
/**
41+
* {inheritdoc}
42+
*/
43+
protected function generateRelatedFile($relatedFileId, LocalInterface $asset)
44+
{
45+
$relatedAsset = parent::generateRelatedFile($relatedFileId, $asset);
46+
$this->publisher->publish($relatedAsset);
47+
return $relatedAsset;
48+
}
49+
}

app/etc/di.xml

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -557,13 +557,6 @@
557557
<argument name="publisher" xsi:type="object">developerPublisher</argument>
558558
</arguments>
559559
</type>
560-
<type name="Magento\Framework\View\Asset\SourceFileGeneratorPool">
561-
<arguments>
562-
<argument name="fileGeneratorTypes" xsi:type="array">
563-
<item name="less" xsi:type="object">Magento\Framework\Less\FileGenerator</item>
564-
</argument>
565-
</arguments>
566-
</type>
567560
<virtualType name="developerPublisher" type="Magento\Framework\App\View\Asset\Publisher">
568561
<arguments>
569562
<argument name="materializationStrategyFactory" xsi:type="object">developerMaterialization</argument>
@@ -577,24 +570,23 @@
577570
</argument>
578571
</arguments>
579572
</virtualType>
580-
<virtualType name="lessFileGeneratorMaterialization" type="Magento\Framework\App\View\Asset\MaterializationStrategy\Factory">
573+
<type name="Magento\Framework\View\Asset\SourceFileGeneratorPool">
581574
<arguments>
582-
<argument name="strategiesList" xsi:type="array">
583-
<item name="view_preprocessed" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink</item>
584-
<item name="default" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Copy</item>
575+
<argument name="fileGeneratorTypes" xsi:type="array">
576+
<item name="less" xsi:type="object">fileassemblerFileGenerator</item>
585577
</argument>
586578
</arguments>
587-
</virtualType>
588-
<virtualType name="lessFileGeneratorPublisher" type="Magento\Framework\App\View\Asset\Publisher">
579+
</type>
580+
<virtualType name="fileassemblerFileGenerator" type="Magento\Framework\Less\FileGenerator">
589581
<arguments>
590-
<argument name="materializationStrategyFactory" xsi:type="object">lessFileGeneratorMaterialization</argument>
582+
<argument name="relatedGenerator" xsi:type="object">fileassemblerRelatedFilesGenerator</argument>
591583
</arguments>
592584
</virtualType>
593-
<type name="Magento\Framework\Less\FileGenerator">
585+
<virtualType name="fileassemblerRelatedFilesGenerator" type="Magento\Developer\Model\Less\FileGenerator\PublicationDecorator">
594586
<arguments>
595-
<argument name="publisher" xsi:type="object">lessFileGeneratorPublisher</argument>
587+
<argument name="publisher" xsi:type="object">developerPublisher</argument>
596588
</arguments>
597-
</type>
589+
</virtualType>
598590
<virtualType name="fallbackResolverSimpleWithGroupedCache" type="Magento\Framework\View\Design\FileResolution\Fallback\Resolver\Simple">
599591
<arguments>
600592
<argument name="cache" xsi:type="object">Magento\Framework\View\Design\FileResolution\Fallback\CacheData\Grouped</argument>

dev/tools/Magento/Tools/Webdev/App/FileAssembler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class FileAssembler implements AppInterface
6060
/**
6161
* @var \Magento\Framework\Less\FileGenerator
6262
*/
63-
private $sourceFileGeneratorPoll;
63+
private $sourceFileGeneratorPool;
6464

6565
/**
6666
* @var \Magento\Framework\View\Asset\Source
@@ -109,7 +109,7 @@ public function __construct(
109109
$this->objectManager = $objectManager;
110110
$this->configLoader = $configLoader;
111111
$this->assetRepo = $assetRepo;
112-
$this->sourceFileGeneratorPoll = $sourceFileGeneratorPoll;
112+
$this->sourceFileGeneratorPool = $sourceFileGeneratorPoll;
113113
$this->assetSource = $assetSource;
114114
$this->logger = $logger;
115115
$this->chainFactory = $chainFactory;
@@ -125,7 +125,7 @@ public function launch()
125125
$this->state->setAreaCode($this->params->getArea());
126126
$this->objectManager->configure($this->configLoader->load($this->params->getArea()));
127127

128-
$sourceFileGenerator = $this->sourceFileGeneratorPoll->create($this->params->getExt());
128+
$sourceFileGenerator = $this->sourceFileGeneratorPool->create($this->params->getExt());
129129

130130
foreach ($this->params->getFiles() as $file) {
131131
$file .= '.' . $this->params->getExt();

dev/tools/Magento/Tools/Webdev/file_assembler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@
3535
$logger = new Log($params->getVerbose());
3636

3737
} catch (\Zend_Console_Getopt_Exception $e) {
38-
echo $e->getUsageMessage();
39-
echo 'Please, use quotes(") for wrapping strings.' . "\n";
38+
echo $e->getMessage() . PHP_EOL;
39+
echo 'Please, use quotes(") for wrapping strings.' . PHP_EOL;
4040
exit(1);
4141
}
4242

4343
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
4444
/** @var \Magento\Framework\App\Http $app */
4545
$app = $bootstrap->createApplication(
46-
'Magento\Tools\WebDev\App\FileAssembler',
46+
'Magento\Tools\Webdev\App\FileAssembler',
4747
['params' => $params, 'logger' => $logger]
4848
);
4949
$bootstrap->run($app);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Less;
7+
8+
use Magento\Framework\App\Filesystem\DirectoryList;
9+
10+
class Config
11+
{
12+
/**
13+
* Temporary directory prefix
14+
*/
15+
const TMP_LESS_DIR = 'less';
16+
17+
/**
18+
* Returns relative path to less materialization directory
19+
*
20+
* @return string
21+
*/
22+
public function getLessMaterializationRelativePath()
23+
{
24+
return DirectoryList::TMP_MATERIALIZATION_DIR . '/' . self::TMP_LESS_DIR;
25+
}
26+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Less\File;
7+
8+
use Magento\Framework\App\Filesystem\DirectoryList;
9+
use Magento\Framework\Filesystem;
10+
use Magento\Framework\Less\Config;
11+
12+
class Temporary
13+
{
14+
/**
15+
* @var Config
16+
*/
17+
private $config;
18+
19+
/**
20+
* @var Filesystem\Directory\WriteInterface
21+
*/
22+
private $tmpDirectory;
23+
24+
/**
25+
* @param Filesystem $filesystem
26+
* @param Config $config
27+
*/
28+
public function __construct(
29+
Filesystem $filesystem,
30+
Config $config
31+
) {
32+
$this->tmpDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
33+
$this->config = $config;
34+
}
35+
36+
/**
37+
* Write down contents to a temporary file and return its absolute path
38+
*
39+
* @param string $relativePath
40+
* @param string $contents
41+
* @return string
42+
*/
43+
public function createFile($relativePath, $contents)
44+
{
45+
$filePath = $this->config->getLessMaterializationRelativePath() . '/' . $relativePath;
46+
47+
if (!$this->tmpDirectory->isExist($filePath)) {
48+
$this->tmpDirectory->writeFile($filePath, $contents);
49+
}
50+
return $this->tmpDirectory->getAbsolutePath($filePath);
51+
}
52+
}

0 commit comments

Comments
 (0)