Deployer.php 3.67 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\Deploy\Model;

use Magento\Deploy\Console\Command\DeployStaticOptionsInterface;
use Magento\Framework\View\Asset\PreProcessor\AlternativeSourceInterface;
use Magento\Framework\App\ObjectManagerFactory;
use Magento\Framework\App\View\Deployment\Version;
use Magento\Framework\App\Utility\Files;
use Magento\Framework\Translate\Js\Config as JsTranslationConfig;
use Symfony\Component\Console\Output\OutputInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Deploy\Model\DeployManagerFactory;

/**
 * A service for deploying Magento static view files for production mode
 *
 * @deprecated
 * @see Use DeployManager::deploy instead
 */
class Deployer
{
    /** @var OutputInterface */
    private $output;

    /**
     * @var JsTranslationConfig
     */
    protected $jsTranslationConfig;

    /**
     * @var array
     */
    private $options;

    /**
     * @var DeployManagerFactory
     */
    private $deployManagerFactory;

    /**
     * Constructor
     *
     * @param Files $filesUtil
     * @param OutputInterface $output
     * @param Version\StorageInterface $versionStorage
     * @param JsTranslationConfig $jsTranslationConfig
     * @param AlternativeSourceInterface[] $alternativeSources
     * @param DeployManagerFactory $deployManagerFactory
     * @param array $options
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function __construct(
        Files $filesUtil,
        OutputInterface $output,
        Version\StorageInterface $versionStorage,
        JsTranslationConfig $jsTranslationConfig,
        array $alternativeSources,
        DeployManagerFactory $deployManagerFactory = null,
        $options = []
    ) {
        $this->output = $output;
        $this->deployManagerFactory = $deployManagerFactory;
        if (is_array($options)) {
            $this->options = $options;
        } else {
            // backward compatibility support
            $this->options = [DeployStaticOptionsInterface::DRY_RUN => (bool)$options];
        }
    }

    /**
     * @return \Magento\Deploy\Model\DeployManagerFactory
     */
    private function getDeployManagerFactory()
    {
        if (null === $this->deployManagerFactory) {
            $this->deployManagerFactory = ObjectManager::getInstance()->get(DeployManagerFactory::class);
        }

        return $this->deployManagerFactory;
    }

    /**
     * Populate all static view files for specified root path and list of languages
     *
     * @param ObjectManagerFactory $omFactory
     * @param array $locales
     * @param array $deployableAreaThemeMap
     * @return int
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     * @deprecated
     */
    public function deploy(ObjectManagerFactory $omFactory, array $locales, array $deployableAreaThemeMap = [])
    {
        /** @var DeployManager $deployerManager */
        $deployerManager = $this->getDeployManagerFactory()->create(
            ['options' => $this->options, 'output' => $this->output]
        );

        foreach ($deployableAreaThemeMap as $area => $themes) {
            foreach ($locales as $locale) {
                foreach ($themes as $themePath) {
                    $deployerManager->addPack($area, $themePath, $locale);
                }
            }
        }
        return $deployerManager->deploy();
    }

    /**
     * Set application locale and load translation for area
     *
     * @param string $locale
     * @param string $area
     * @return void
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     * @deprecated
     */
    protected function emulateApplicationLocale($locale, $area)
    {
    }
}