Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
FileResolver Class Reference
Inheritance diagram for FileResolver:
FileResolverInterface DesignResolverInterface FileResolverInterface

Public Member Functions

 __construct (DirReader $moduleReader, FileIteratorFactory $iteratorFactory, DesignInterface $designInterface, DirectoryList $directoryList, Filesystem $filesystem, ResolverInterface $resolver)
 
 get ($filename, $scope)
 
 getParents ($filename, $scope)
 

Protected Attributes

 $moduleReader
 
 $iteratorFactory
 
 $currentTheme
 
 $area
 
 $rootDirectory
 
 $resolver
 

Detailed Description

Class FileResolver @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 22 of file FileResolver.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( DirReader  $moduleReader,
FileIteratorFactory  $iteratorFactory,
DesignInterface  $designInterface,
DirectoryList  $directoryList,
Filesystem  $filesystem,
ResolverInterface  $resolver 
)
Parameters
DirReader$moduleReader
FileIteratorFactory$iteratorFactory
DesignInterface$designInterface
DirectoryList$directoryList
Deprecated:
Parameters
Filesystem$filesystem
ResolverInterface$resolver

Definition at line 70 of file FileResolver.php.

77  {
78  $this->directoryList = $directoryList;
79  $this->iteratorFactory = $iteratorFactory;
80  $this->moduleReader = $moduleReader;
81  $this->currentTheme = $designInterface->getDesignTheme();
82  $this->area = $designInterface->getArea();
83  $this->rootDirectory = $filesystem->getDirectoryRead(DirectoryList::ROOT);
84  $this->resolver = $resolver;
85  }
$filesystem

Member Function Documentation

◆ get()

get (   $filename,
  $scope 
)

{Retrieve the list of configuration files with given name that relate to specified scope

Parameters
string$filename
string$scope
Returns
array
}

Implements FileResolverInterface.

Definition at line 90 of file FileResolver.php.

91  {
92  switch ($scope) {
93  case 'global':
94  $iterator = $this->moduleReader->getConfigurationFiles($filename)->toArray();
95  $themeConfigFile = $this->currentTheme->getCustomization()->getCustomViewConfigPath();
96  if ($themeConfigFile
97  && $this->rootDirectory->isExist($this->rootDirectory->getRelativePath($themeConfigFile))
98  ) {
99  $iterator[$this->rootDirectory->getRelativePath($themeConfigFile)] =
100  $this->rootDirectory->readFile(
101  $this->rootDirectory->getRelativePath(
102  $themeConfigFile
103  )
104  );
105  } else {
106  $designPath = $this->resolver->resolve(
108  'etc/view.xml',
109  $this->area,
110  $this->currentTheme
111  );
112  if (file_exists($designPath)) {
113  try {
114  $designDom = new \DOMDocument();
115  $designDom->load($designPath);
116  $iterator[$designPath] = $designDom->saveXML();
117  } catch (\Exception $e) {
118  throw new \Magento\Framework\Exception\LocalizedException(
119  new \Magento\Framework\Phrase('Could not read config file')
120  );
121  }
122  }
123  }
124  break;
125  default:
126  $iterator = $this->iteratorFactory->create([]);
127  break;
128  }
129  return $iterator;
130  }

◆ getParents()

getParents (   $filename,
  $scope 
)

{Retrieve parent configs

Parameters
string$filename
string$scope
Returns
array
Since
100.1.0
}

Implements DesignResolverInterface.

Definition at line 135 of file FileResolver.php.

136  {
137  switch ($scope) {
138  case 'global':
139  $iterator = $this->moduleReader->getConfigurationFiles($filename)->toArray();
140  $designPath = $this->resolver->resolve(
142  'etc/view.xml',
143  $this->area,
144  $this->currentTheme
145  );
146 
147  if (file_exists($designPath)) {
148  try {
149  $iterator = $this->getParentConfigs($this->currentTheme, []);
150  } catch (\Exception $e) {
151  throw new \Magento\Framework\Exception\LocalizedException(
152  new \Magento\Framework\Phrase('Could not read config file')
153  );
154  }
155  }
156  break;
157  default:
158  $iterator = $this->iteratorFactory->create([]);
159  break;
160  }
161 
162  return $iterator;
163  }

Field Documentation

◆ $area

$area
protected

Definition at line 44 of file FileResolver.php.

◆ $currentTheme

$currentTheme
protected

Definition at line 39 of file FileResolver.php.

◆ $iteratorFactory

$iteratorFactory
protected

Definition at line 34 of file FileResolver.php.

◆ $moduleReader

$moduleReader
protected

Definition at line 29 of file FileResolver.php.

◆ $resolver

$resolver
protected

Definition at line 54 of file FileResolver.php.

◆ $rootDirectory

$rootDirectory
protected

Definition at line 49 of file FileResolver.php.


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