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

Public Member Functions

 __construct (Filesystem $filesystem, BundleInterfaceFactory $bundleFactory, BundleConfig $bundleConfig, Files $files)
 
 deploy ($area, $theme, $locale)
 

Data Fields

const BUNDLE_JS_DIR = 'js/bundle'
 
const ASSET_TYPE_JS = 'js'
 
const ASSET_TYPE_HTML = 'html'
 

Static Public Attributes

static $availableTypes
 

Detailed Description

Deploy bundled static files service

Read all static files from deployed packages and generate bundles. Bundle Factory can be configured to use bundle format different from RequireJS used out of the box

Definition at line 23 of file Bundle.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Filesystem  $filesystem,
BundleInterfaceFactory  $bundleFactory,
BundleConfig  $bundleConfig,
Files  $files 
)

Bundle constructor

Parameters
Filesystem$filesystem
BundleInterfaceFactory$bundleFactory
BundleConfig$bundleConfig
Files$files

Definition at line 87 of file Bundle.php.

92  {
93  $this->pubStaticDir = $filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
94  $this->bundleFactory = $bundleFactory;
95  $this->bundleConfig = $bundleConfig;
96  $this->utilityFiles = $files;
97  }
$filesystem
foreach($appDirs as $dir) $files

Member Function Documentation

◆ deploy()

deploy (   $area,
  $theme,
  $locale 
)

Deploy bundles for the given area, theme and locale

Parameters
string$area
string$theme
string$locale
Returns
void

Definition at line 107 of file Bundle.php.

108  {
109  $bundle = $this->bundleFactory->create([
110  'area' => $area,
111  'theme' => $theme,
112  'locale' => $locale
113  ]);
114 
115  // delete all previously created bundle files
116  $bundle->clear();
117  $files = [];
118  $mapFilePath = $area . '/' . $theme . '/' . $locale . '/' . RepositoryMap::RESULT_MAP_NAME;
119  if ($this->pubStaticDir->isFile($mapFilePath)) {
120  // map file is available in compact mode, so no need to scan filesystem one more time
121  $resultMap = $this->pubStaticDir->readFile($mapFilePath);
122  if ($resultMap) {
123  $files = json_decode($resultMap, true);
124  }
125  } else {
126  $packageDir = $this->pubStaticDir->getAbsolutePath($area . '/' . $theme . '/' . $locale);
127  $files = $this->utilityFiles->getFiles([$packageDir], '*.*');
128  }
129 
130  foreach ($files as $filePath => $sourcePath) {
131  if (is_array($sourcePath)) {
132  $filePath = str_replace(Repository::FILE_ID_SEPARATOR, '/', $filePath);
133  $sourcePath = $sourcePath['area']
134  . '/' . $sourcePath['theme']
135  . '/' . $sourcePath['locale']
136  . '/' . $filePath;
137  } else {
138  $sourcePath = str_replace('\\', '/', $sourcePath);
139  $sourcePath = $this->pubStaticDir->getRelativePath($sourcePath);
140  $filePath = substr($sourcePath, strlen($area . '/' . $theme . '/' . $locale) + 1);
141  }
142 
143  $contentType = pathinfo($filePath, PATHINFO_EXTENSION);
144  if (!in_array($contentType, self::$availableTypes)) {
145  continue;
146  }
147 
148  if ($this->hasMinVersion($filePath) || $this->isExcluded($filePath, $area, $theme)) {
149  continue;
150  }
151 
152  $bundle->addFile($filePath, $sourcePath, $contentType);
153  }
154  $bundle->flush();
155  }
$theme
foreach($appDirs as $dir) $files

Field Documentation

◆ $availableTypes

$availableTypes
static
Initial value:

Definition at line 74 of file Bundle.php.

◆ ASSET_TYPE_HTML

const ASSET_TYPE_HTML = 'html'

Matched file extension name for template files

Definition at line 38 of file Bundle.php.

◆ ASSET_TYPE_JS

const ASSET_TYPE_JS = 'js'

Matched file extension name for JavaScript files

Definition at line 33 of file Bundle.php.

◆ BUNDLE_JS_DIR

const BUNDLE_JS_DIR = 'js/bundle'

Path to package subdirectory where bundle files are located

Definition at line 28 of file Bundle.php.


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