Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields
Package Class Reference

Public Member Functions

 __construct (PackagePool $packagePool, FileNameResolver $fileNameResolver, $area, $theme, $locale, $isVirtual=false, array $preProcessors=[], array $postProcessors=[])
 
 getArea ()
 
 getParent ()
 
 getTheme ()
 
 getLocale ()
 
 getPath ()
 
 isVirtual ()
 
 getParam ($name)
 
 setParam ($name, $value)
 
 getThemeModel ()
 
 getFile ($fileId)
 
 addFile (PackageFile $file)
 
 addFileToMap (PackageFile $file)
 
 getFiles ()
 
 deleteFile ($fileId)
 
 setParent ($parent)
 
 getMap ()
 
 getState ()
 
 setState ($state)
 
 getInheritanceLevel ()
 
 getResultMap ()
 
 getParentMap ()
 
 getParentFiles ($type=null)
 
 getParentPackages ()
 
 getPreProcessors ()
 
 getPostProcessors ()
 

Data Fields

const STATE_PROGRESS = 0
 
const STATE_COMPLETED = 1
 
const BASE_AREA = 'base'
 
const BASE_THEME = 'Magento/base'
 
const BASE_LOCALE = 'default'
 

Detailed Description

Deployment Package

Definition at line 15 of file Package.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( PackagePool  $packagePool,
FileNameResolver  $fileNameResolver,
  $area,
  $theme,
  $locale,
  $isVirtual = false,
array  $preProcessors = [],
array  $postProcessors = [] 
)
Parameters
PackagePool$packagePool
FileNameResolver$fileNameResolver
string$area
string$theme
string$locale
bool$isVirtual
ProcessorInterface[]$preProcessors
ProcessorInterface[]$postProcessors

Definition at line 132 of file Package.php.

141  {
142  $this->packagePool = $packagePool;
143  $this->fileNameResolver = $fileNameResolver;
144  $this->area = $area;
145  $this->theme = $theme;
146  $this->locale = $locale;
147  $this->isVirtual = $isVirtual;
148  $this->preProcessors = $preProcessors;
149  $this->postProcessors = $postProcessors;
150  }

Member Function Documentation

◆ addFile()

addFile ( PackageFile  $file)

Add file to package

Parameters
PackageFile$file
Returns
string

Definition at line 253 of file Package.php.

254  {
255  if (!$file->getLocale()) {
256  $file->setLocale($this->getLocale());
257  }
258  $this->files[$file->getFileId()] = $file;
259 
260  $deployedFilePath = $this->getPath() . '/'
261  . ($file->getModule() ? ($file->getModule() . '/') : '')
262  . $file->getDeployedFileName();
263  $file->setDeployedFilePath($deployedFilePath);
264 
265  return $file->getFileId();
266  }

◆ addFileToMap()

addFileToMap ( PackageFile  $file)

Add file to the package map

Parameters
PackageFile$file
Returns
void

Definition at line 274 of file Package.php.

275  {
276  $fileId = $file->getDeployedFileId();
277  $this->map[$fileId] = [
278  'area' => $this->getArea(),
279  'theme' => $this->getTheme(),
280  'locale' => $this->getLocale()
281  ];
282  }

◆ deleteFile()

deleteFile (   $fileId)

Delete file from package by file id

Parameters
string$fileId
Returns
void

Definition at line 321 of file Package.php.

322  {
323  unset($this->files[$fileId]);
324  }

◆ getArea()

getArea ( )
Returns
string

Definition at line 155 of file Package.php.

156  {
157  return $this->area;
158  }

◆ getFile()

getFile (   $fileId)

Retrieve file by file id

Parameters
string$fileId
Returns
bool|PackageFile

Definition at line 242 of file Package.php.

243  {
244  return isset($this->files[$fileId]) ? $this->files[$fileId] : false;
245  }

◆ getFiles()

getFiles ( )

Retrieve all files

Returns
PackageFile[]

Definition at line 289 of file Package.php.

290  {
291  return $this->files;
292  }

◆ getInheritanceLevel()

getInheritanceLevel ( )
Returns
int

Definition at line 391 of file Package.php.

392  {
393  $level = 0;
394  $theme = $this->getThemeModel();
395  if ($theme) {
396  ++$level;
397  while ($theme = $theme->getParentTheme()) {
398  ++$level;
399  }
400  }
401  return $level;
402  }

◆ getLocale()

getLocale ( )
Returns
string

Definition at line 179 of file Package.php.

180  {
181  return $this->locale;
182  }

◆ getMap()

getMap ( )

Retrieve map

Returns
array

Definition at line 365 of file Package.php.

366  {
367  return $this->map;
368  }

◆ getParam()

getParam (   $name)
Parameters
string$name
Returns
mixed|null

Definition at line 210 of file Package.php.

211  {
212  return isset($this->params[$name]) ? $this->params[$name] : null;
213  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getParent()

getParent ( )
Returns
Package

Definition at line 163 of file Package.php.

164  {
165  return $this->parent;
166  }

◆ getParentFiles()

getParentFiles (   $type = null)

Retrieve parent files

Parameters
string | null$type
Returns
PackageFile[]

Definition at line 436 of file Package.php.

437  {
438  $files = [];
439  foreach ($this->getParentPackages() as $parentPackage) {
440  if ($type === null) {
441  $files = array_merge($files, $parentPackage->getFiles());
442  } else {
443  $files = array_merge($files, $parentPackage->getFilesByType($type));
444  }
445  }
446  return $files;
447  }
$type
Definition: item.phtml:13

◆ getParentMap()

getParentMap ( )

Retrieve parent map

Returns
array

Definition at line 421 of file Package.php.

422  {
423  $map = [];
424  foreach ($this->getParentPackages() as $parentPackage) {
425  $map = array_merge($map, $parentPackage->getMap());
426  }
427  return $map;
428  }

◆ getParentPackages()

getParentPackages ( )

Retrieve parent packages list

Returns
Package[]

Definition at line 454 of file Package.php.

455  {
456  if ($this->parentPackages === null) {
457  $this->parentPackages = [];
458  $parentPaths = [];
459  $this->collectParentPaths(
460  $this,
461  $this->getArea(),
462  $this->getTheme(),
463  $this->getLocale(),
464  $parentPaths,
465  $this->getThemeModel()
466  );
467 
468  // collect packages in reverse order to have closer ancestor goes later
469  foreach (array_reverse($parentPaths) as $path) {
470  if ($package = $this->packagePool->getPackage($path)) {
471  $this->parentPackages[$path] = $package;
472  }
473  }
474  }
475 
476  return $this->parentPackages;
477  }

◆ getPath()

getPath ( )

Retrieve package path

Returns
string

Definition at line 189 of file Package.php.

190  {
191  return $this->getArea() . '/' . $this->getTheme() . '/' . $this->getLocale();
192  }

◆ getPostProcessors()

getPostProcessors ( )
Returns
Processor\ProcessorInterface[]

Definition at line 490 of file Package.php.

491  {
492  return $this->postProcessors;
493  }

◆ getPreProcessors()

getPreProcessors ( )
Returns
Processor\ProcessorInterface[]

Definition at line 482 of file Package.php.

483  {
484  return $this->preProcessors;
485  }

◆ getResultMap()

getResultMap ( )

Retrieve inherited package map

Returns
array

Definition at line 409 of file Package.php.

410  {
411  $map = $this->getMap();
412  $parentMap = $this->getParentMap();
413  return array_merge($parentMap, $map);
414  }

◆ getState()

getState ( )
Returns
int

Definition at line 373 of file Package.php.

374  {
375  return $this->state;
376  }

◆ getTheme()

getTheme ( )
Returns
string

Definition at line 171 of file Package.php.

172  {
173  return $this->theme;
174  }

◆ getThemeModel()

getThemeModel ( )

Retrieve theme model

Returns
ThemeInterface|null

Definition at line 231 of file Package.php.

232  {
233  return $this->packagePool->getThemeModel($this->getArea(), $this->getTheme());
234  }

◆ isVirtual()

isVirtual ( )

Is package virtual and can not be referenced directly

Package considered as "virtual" when not all of the scope identifiers defined (area, theme, locale)

Returns
string

Definition at line 201 of file Package.php.

202  {
203  return $this->isVirtual;
204  }

◆ setParam()

setParam (   $name,
  $value 
)
Parameters
string$name
mixed$value
Returns
bool

Definition at line 220 of file Package.php.

221  {
222  $this->params[$name] = $value;
223  return true;
224  }
$value
Definition: gender.phtml:16
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setParent()

setParent (   $parent)
Parameters
Package$parent
Returns
bool

Definition at line 354 of file Package.php.

355  {
356  $this->parent = $parent;
357  return true;
358  }

◆ setState()

setState (   $state)
Parameters
int$state
Returns
bool

Definition at line 382 of file Package.php.

383  {
384  $this->state = $state;
385  return true;
386  }

Field Documentation

◆ BASE_AREA

const BASE_AREA = 'base'

Base area code

Definition at line 100 of file Package.php.

◆ BASE_LOCALE

const BASE_LOCALE = 'default'

Base locale code

Definition at line 110 of file Package.php.

◆ BASE_THEME

const BASE_THEME = 'Magento/base'

Base theme code

Definition at line 105 of file Package.php.

◆ STATE_COMPLETED

const STATE_COMPLETED = 1

Deployment state identifier for "completed" state

Definition at line 95 of file Package.php.

◆ STATE_PROGRESS

const STATE_PROGRESS = 0

Deployment state identifier for "in progress" state

Definition at line 90 of file Package.php.


The documentation for this class was generated from the following file: