Skip to content

Commit

Permalink
Merge pull request #182 from magento-mpi/develop
Browse files Browse the repository at this point in the history
[MPI] - bug fix
  • Loading branch information
vpelipenko committed Mar 20, 2015
2 parents 3c74e6b + 18444d3 commit ad5e6b2
Show file tree
Hide file tree
Showing 9 changed files with 361 additions and 192 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Developer\Model\Less\FileGenerator;

use Magento\Framework\Less\FileGenerator\RelatedGenerator;
use Magento\Framework\View\Asset\LocalInterface;

/**
* Class PublicationDecorator
* Decorates generator of related assets and publishes them
*
* @package Magento\Developer\Model\Less\FileGenerator
*/
class PublicationDecorator extends RelatedGenerator
{
/**
* @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\File\Temporary $temporaryFile
* @param \Magento\Framework\App\View\Asset\Publisher $publisher
*/
public function __construct(
\Magento\Framework\Filesystem $filesystem,
\Magento\Framework\View\Asset\Repository $assetRepo,
\Magento\Framework\Less\File\Temporary $temporaryFile,
\Magento\Framework\App\View\Asset\Publisher $publisher
) {
parent::__construct($filesystem, $assetRepo, $temporaryFile);
$this->publisher = $publisher;
}

/**
* {inheritdoc}
*/
protected function generateRelatedFile($relatedFileId, LocalInterface $asset)
{
$relatedAsset = parent::generateRelatedFile($relatedFileId, $asset);
$this->publisher->publish($relatedAsset);
return $relatedAsset;
}
}
26 changes: 9 additions & 17 deletions app/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,6 @@
<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>
Expand All @@ -577,24 +570,23 @@
</argument>
</arguments>
</virtualType>
<virtualType name="lessFileGeneratorMaterialization" type="Magento\Framework\App\View\Asset\MaterializationStrategy\Factory">
<type name="Magento\Framework\View\Asset\SourceFileGeneratorPool">
<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 name="fileGeneratorTypes" xsi:type="array">
<item name="less" xsi:type="object">fileassemblerFileGenerator</item>
</argument>
</arguments>
</virtualType>
<virtualType name="lessFileGeneratorPublisher" type="Magento\Framework\App\View\Asset\Publisher">
</type>
<virtualType name="fileassemblerFileGenerator" type="Magento\Framework\Less\FileGenerator">
<arguments>
<argument name="materializationStrategyFactory" xsi:type="object">lessFileGeneratorMaterialization</argument>
<argument name="relatedGenerator" xsi:type="object">fileassemblerRelatedFilesGenerator</argument>
</arguments>
</virtualType>
<type name="Magento\Framework\Less\FileGenerator">
<virtualType name="fileassemblerRelatedFilesGenerator" type="Magento\Developer\Model\Less\FileGenerator\PublicationDecorator">
<arguments>
<argument name="publisher" xsi:type="object">lessFileGeneratorPublisher</argument>
<argument name="publisher" xsi:type="object">developerPublisher</argument>
</arguments>
</type>
</virtualType>
<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>
Expand Down
26 changes: 21 additions & 5 deletions dev/tools/Magento/Tools/Webdev/App/FileAssembler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\Framework\App;
use Magento\Framework\App\State;
use Magento\Framework\AppInterface;
use Magento\Framework\Filesystem;
use Magento\Tools\Webdev\CliParams;
use Magento\Tools\View\Deployer\Log;
use Magento\Framework\View\Asset\Source;
Expand All @@ -18,6 +19,7 @@
use Magento\Framework\App\ObjectManager\ConfigLoader;
use Magento\Framework\View\Asset\SourceFileGeneratorPool;
use Magento\Framework\View\Asset\PreProcessor\ChainFactoryInterface;
use Magento\Framework\App\Filesystem\DirectoryList;

/**
* Class FileAssembler
Expand Down Expand Up @@ -60,7 +62,7 @@ class FileAssembler implements AppInterface
/**
* @var \Magento\Framework\Less\FileGenerator
*/
private $sourceFileGeneratorPoll;
private $sourceFileGeneratorPool;

/**
* @var \Magento\Framework\View\Asset\Source
Expand All @@ -77,6 +79,11 @@ class FileAssembler implements AppInterface
*/
private $chainFactory;

/**
* @var Filesystem
*/
private $filesystem;

/**
* @param ObjectManagerInterface $objectManager
* @param Response $response
Expand All @@ -88,6 +95,7 @@ class FileAssembler implements AppInterface
* @param \Magento\Framework\View\Asset\SourceFileGeneratorPool $sourceFileGeneratorPoll
* @param \Magento\Tools\View\Deployer\Log $logger
* @param ChainFactoryInterface $chainFactory
* @param Filesystem $filesystem
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
Expand All @@ -101,18 +109,20 @@ public function __construct(
Source $assetSource,
SourceFileGeneratorPool $sourceFileGeneratorPoll,
Log $logger,
ChainFactoryInterface $chainFactory
ChainFactoryInterface $chainFactory,
Filesystem $filesystem
) {
$this->response = $response;
$this->params = $params;
$this->state = $state;
$this->objectManager = $objectManager;
$this->configLoader = $configLoader;
$this->assetRepo = $assetRepo;
$this->sourceFileGeneratorPoll = $sourceFileGeneratorPoll;
$this->sourceFileGeneratorPool = $sourceFileGeneratorPoll;
$this->assetSource = $assetSource;
$this->logger = $logger;
$this->chainFactory = $chainFactory;
$this->filesystem = $filesystem;
}

/**
Expand All @@ -125,7 +135,7 @@ 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());
$sourceFileGenerator = $this->sourceFileGeneratorPool->create($this->params->getExt());

foreach ($this->params->getFiles() as $file) {
$file .= '.' . $this->params->getExt();
Expand All @@ -152,7 +162,13 @@ public function launch()
]
);

$sourceFileGenerator->generateFileTree($chain);
$processedCoreFile = $sourceFileGenerator->generateFileTree($chain);

$targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
$rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
$source = $rootDir->getRelativePath($processedCoreFile);
$destination = $asset->getPath();
$rootDir->copyFile($source, $destination, $targetDir);

$this->logger->logMessage("Done");
}
Expand Down
6 changes: 3 additions & 3 deletions dev/tools/Magento/Tools/Webdev/file_assembler.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@
$logger = new Log($params->getVerbose());

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

$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication(
'Magento\Tools\WebDev\App\FileAssembler',
'Magento\Tools\Webdev\App\FileAssembler',
['params' => $params, 'logger' => $logger]
);
$bootstrap->run($app);
26 changes: 26 additions & 0 deletions lib/internal/Magento/Framework/Less/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\Less;

use Magento\Framework\App\Filesystem\DirectoryList;

class Config
{
/**
* Temporary directory prefix
*/
const TMP_LESS_DIR = 'less';

/**
* Returns relative path to less materialization directory
*
* @return string
*/
public function getLessMaterializationRelativePath()
{
return DirectoryList::TMP_MATERIALIZATION_DIR . '/' . self::TMP_LESS_DIR;
}
}
52 changes: 52 additions & 0 deletions lib/internal/Magento/Framework/Less/File/Temporary.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\Less\File;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;
use Magento\Framework\Less\Config;

class Temporary
{
/**
* @var Config
*/
private $config;

/**
* @var Filesystem\Directory\WriteInterface
*/
private $tmpDirectory;

/**
* @param Filesystem $filesystem
* @param Config $config
*/
public function __construct(
Filesystem $filesystem,
Config $config
) {
$this->tmpDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
$this->config = $config;
}

/**
* Write down contents to a temporary file and return its absolute path
*
* @param string $relativePath
* @param string $contents
* @return string
*/
public function createFile($relativePath, $contents)
{
$filePath = $this->config->getLessMaterializationRelativePath() . '/' . $relativePath;

if (!$this->tmpDirectory->isExist($filePath)) {
$this->tmpDirectory->writeFile($filePath, $contents);
}
return $this->tmpDirectory->getAbsolutePath($filePath);
}
}
Loading

0 comments on commit ad5e6b2

Please sign in to comment.