32 private $packageFactory;
37 private $packages = [];
42 private $collected =
false;
56 $this->collector = $collector;
57 $themeCollection->clear()->resetConstraints();
58 $this->themes = $themeCollection->getItems();
59 $this->packageFactory = $packageFactory;
69 return isset($this->packages[
$path]) ? $this->packages[
$path] :
null;
78 return $this->packages;
88 $theme = $this->getThemeByFullPath($areaCode .
'/' . $themePath);
90 $theme->setThemePath($themePath);
102 $this->ensurePackagesForRequiredLocales(
$options);
106 foreach ($this->packages as
$path => $package) {
107 if ($this->checkPackageSkip($package,
$options)) {
108 $toSkip[
$path] = $package;
111 $toDeploy[
$path] = $package;
115 foreach ($toSkip as
$path => $package) {
116 if (!$this->isAncestorForDeployedPackages($package, $toDeploy)) {
117 unset($this->packages[
$path]);
121 return $this->packages;
131 private function isAncestorForDeployedPackages(
Package $excludedPackage, array $deployedPackages)
133 foreach ($deployedPackages as $deployedPackage) {
134 $parents = $deployedPackage->getParentPackages();
135 if (array_key_exists($excludedPackage->
getPath(), $parents)) {
146 private function getThemeByFullPath($fullPath)
148 foreach ($this->themes as
$theme) {
149 if (
$theme->getFullPath() === $fullPath) {
160 private function collect($recollect =
false)
162 if (!$this->collected || $recollect) {
163 $this->packages = $this->collector->collect();
164 $this->collected =
true;
174 private function ensurePackagesForRequiredLocales(array
$options)
176 $this->ensureRequiredLocales(
$options);
178 $resultPackages = $this->packages;
181 foreach ($this->themes as
$theme) {
182 $inheritedThemes =
$theme->getInheritedThemes();
183 foreach ($resultPackages as $package) {
187 foreach ($inheritedThemes as $inheritedTheme) {
188 if ($package->getTheme() === $inheritedTheme->getThemePath()
189 && $package->getArea() === $inheritedTheme->getArea()
191 $this->ensurePackage([
192 'area' => $package->getArea(),
193 'theme' =>
$theme->getThemePath(),
194 'locale' => $package->getLocale(),
209 private function ensureRequiredLocales(array
$options)
211 if (empty(
$options[Options::LANGUAGE]) ||
$options[Options::LANGUAGE][0] ===
'all') {
214 $forcedLocales =
$options[Options::LANGUAGE];
217 $resultPackages = $this->packages;
218 foreach ($resultPackages as $package) {
222 foreach ($forcedLocales as $locale) {
223 $this->ensurePackage([
224 'area' => $package->getArea(),
225 'theme' => $package->getTheme(),
239 private function checkPackageSkip(Package $package, array
$options)
241 return !$this->canDeployArea($package,
$options)
242 || !$this->canDeployTheme($package,
$options)
243 || !$this->canDeployLocale($package,
$options);
251 private function canDeployArea(Package $package, array
$options)
253 $area = $package->getArea();
255 if ($area ==
'install') {
261 $exclude = $this->getOption(Options::EXCLUDE_AREA,
$options);
262 $include = $this->getOption(Options::AREA,
$options);
263 return $this->isIncluded($area, $include, $exclude);
271 private function canDeployTheme(Package $package, array
$options)
273 $theme = $package->getTheme();
278 $exclude = $this->getOption(Options::EXCLUDE_THEME,
$options);
279 $include = $this->getOption(Options::THEME,
$options);
280 return $this->isIncluded(
$theme, $include, $exclude);
288 private function canDeployLocale(Package $package, array
$options)
290 $locale = $package->getLocale();
294 $exclude = $this->getOption(Options::EXCLUDE_LANGUAGE,
$options);
295 $include = $this->getOption(Options::LANGUAGE,
$options);
296 return $this->isIncluded($locale, $include, $exclude);
305 private function isIncluded(
$entity, array $includedEntities, array $excludedEntities)
308 if ($includedEntities[0] ===
'all' && $excludedEntities[0] ===
'none') {
310 }
elseif ($excludedEntities[0] !==
'none') {
312 }
elseif ($includedEntities[0] !==
'all') {
332 private function ensurePackage(array
$params)
334 $packagePath =
"{$params['area']}/{$params['theme']}/{$params['locale']}";
335 if (!isset($this->packages[$packagePath])) {
336 $this->packages[$packagePath] = $this->packageFactory->create(
$params);
__construct(Collector $collector, ListInterface $themeCollection, PackageFactory $packageFactory)
elseif(isset( $params[ 'redirect_parent']))
getPackagesForDeployment(array $options)
getThemeModel($areaCode, $themePath)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
if(!isset($_GET['name'])) $name