123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php namespace Laravel;
- class Module {
- /**
- * The active modules for the installation.
- *
- * This property is set in the Laravel bootstrap file, and the modules are defined
- * by the developer in the front controller.
- *
- * @var array
- */
- public static $modules = array();
- /**
- * All of the loaded module paths keyed by name.
- *
- * These are stored as the module paths are determined for convenient, fast access.
- *
- * @var array
- */
- private static $paths = array();
- /**
- * Parse a modularized identifier and return the module and key.
- *
- * Modular identifiers follow typically follow a {module}::{key} convention.
- * However, for convenience, the default module does not require a module qualifier.
- *
- * <code>
- * // Returns array('admin', 'test.example')
- * Module::parse('admin::test.example');
- *
- * // Returns array('application', 'test.example')
- * Module::parse('test.example');
- * </code>
- *
- * @param string $key
- * @return array
- */
- public static function parse($key)
- {
- $module = (strpos($key, '::') !== false) ? substr($key, 0, strpos($key, ':')) : DEFAULT_MODULE;
- $module = str_replace('.', '/', $module);
- if ($module !== DEFAULT_MODULE) $key = substr($key, strpos($key, ':') + 2);
- return array($module, $key);
- }
- /**
- * Get the path for a given module.
- *
- * Once the path has been determined, it will be cached by the class for quick access.
- *
- * @param string $module
- * @return string
- */
- public static function path($module)
- {
- if (array_key_exists($module, static::$paths)) return static::$paths[$module];
- if (array_key_exists($module, static::$modules))
- {
- return (static::$modules[$module] == DEFAULT_MODULE_PATH) ? static::$modules[$module] : MODULE_PATH.static::$modules[$module].'/';
- }
- elseif (in_array($module, static::$modules))
- {
- return static::$paths[$module] = MODULE_PATH.$module.'/';
- }
- }
- /**
- * Get an array of paths to all of the modules.
- *
- * @return array
- */
- public static function paths()
- {
- return array_map(function($module) { return Laravel\Module::path($module); }, static::$modules);
- }
- }
|