Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ComponentRegistrar.php
Go to the documentation of this file.
1 <?php
7 
17 {
21  const MODULE = 'module';
22  const LIBRARY = 'library';
23  const THEME = 'theme';
24  const LANGUAGE = 'language';
25  const SETUP = 'setup';
29  private static $paths = [
30  self::MODULE => [],
31  self::LIBRARY => [],
32  self::LANGUAGE => [],
33  self::THEME => [],
34  self::SETUP => []
35  ];
36 
46  public static function register($type, $componentName, $path)
47  {
48  self::validateType($type);
49  if (isset(self::$paths[$type][$componentName])) {
50  throw new \LogicException(
51  ucfirst($type) . ' \'' . $componentName . '\' from \'' . $path . '\' '
52  . 'has been already defined in \'' . self::$paths[$type][$componentName] . '\'.'
53  );
54  } else {
55  self::$paths[$type][$componentName] = str_replace('\\', '/', $path);
56  }
57  }
58 
62  public function getPaths($type)
63  {
64  self::validateType($type);
65  return self::$paths[$type];
66  }
67 
71  public function getPath($type, $componentName)
72  {
73  self::validateType($type);
74  return self::$paths[$type][$componentName] ?? null;
75  }
76 
84  private static function validateType($type)
85  {
86  if (!isset(self::$paths[$type])) {
87  throw new \LogicException('\'' . $type . '\' is not a valid component type');
88  }
89  }
90 }
$type
Definition: item.phtml:13
$paths
Definition: _bootstrap.php:83