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

Public Member Functions

 __construct (ComponentRegistrarInterface $componentRegistrar)
 
 getDir ($moduleName, $type='')
 

Data Fields

const MODULE_ETC_DIR = 'etc'
 
const MODULE_I18N_DIR = 'i18n'
 
const MODULE_VIEW_DIR = 'view'
 
const MODULE_CONTROLLER_DIR = 'Controller'
 
const MODULE_SETUP_DIR = 'Setup'
 

Detailed Description

Definition at line 13 of file Dir.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ComponentRegistrarInterface  $componentRegistrar)
Parameters
ComponentRegistrarInterface$componentRegistrar

Definition at line 31 of file Dir.php.

32  {
33  $this->componentRegistrar = $componentRegistrar;
34  }

Member Function Documentation

◆ getDir()

getDir (   $moduleName,
  $type = '' 
)

Retrieve full path to a directory of certain type within a module

Parameters
string$moduleNameFully-qualified module name
string$typeType of module's directory to retrieve
Returns
string
Exceptions

Definition at line 44 of file Dir.php.

45  {
46  $path = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName);
47 
48  // An empty $type means it's getting the directory of the module itself.
49  if (empty($type) && !isset($path)) {
50  // Note: do not throw \LogicException, as it would break backwards-compatibility.
51  throw new \InvalidArgumentException("Module '$moduleName' is not correctly registered.");
52  }
53 
54  if ($type) {
55  if (!in_array($type, [
56  self::MODULE_ETC_DIR,
57  self::MODULE_I18N_DIR,
58  self::MODULE_VIEW_DIR,
59  self::MODULE_CONTROLLER_DIR,
60  self::MODULE_SETUP_DIR
61  ])) {
62  throw new \InvalidArgumentException("Directory type '{$type}' is not recognized.");
63  }
64  $path .= '/' . $type;
65  }
66 
67  return $path;
68  }
$type
Definition: item.phtml:13

Field Documentation

◆ MODULE_CONTROLLER_DIR

const MODULE_CONTROLLER_DIR = 'Controller'

Definition at line 21 of file Dir.php.

◆ MODULE_ETC_DIR

const MODULE_ETC_DIR = 'etc'

#+ Directories within modules

Definition at line 18 of file Dir.php.

◆ MODULE_I18N_DIR

const MODULE_I18N_DIR = 'i18n'

Definition at line 19 of file Dir.php.

◆ MODULE_SETUP_DIR

const MODULE_SETUP_DIR = 'Setup'

Definition at line 22 of file Dir.php.

◆ MODULE_VIEW_DIR

const MODULE_VIEW_DIR = 'view'

Definition at line 20 of file Dir.php.


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