示例#1
0
 /**
  * Loads the given module.  If a path is not given, then 'module_paths' is used.
  * It also accepts an array of modules as the first parameter.
  *
  * @param   string|array  $package  The module name or array of modules.
  * @param   string|null   $path     The path to the module
  * @return  bool  True on success
  * @throws  ModuleNotFoundException
  */
 public static function load($module, $path = null)
 {
     if (is_array($module)) {
         $result = true;
         foreach ($module as $mod => $path) {
             if (is_numeric($mod)) {
                 $mod = $path;
                 $path = null;
             }
             $result = $result and static::load($mod, $path);
         }
         return $result;
     }
     if (static::loaded($module)) {
         return;
     }
     // if no path is given, try to locate the module
     if ($path === null) {
         $paths = \Config::get('module_paths', array());
         if (!empty($paths)) {
             foreach ($paths as $modpath) {
                 if (is_dir($path = $modpath . strtolower($module) . DS)) {
                     break;
                 }
             }
         }
     } else {
         // make sure it's terminated properly
         $path = rtrim($path, DS) . DS;
     }
     // make sure the path exists
     if (!is_dir($path)) {
         throw new \ModuleNotFoundException("Module '{$module}' could not be found at '" . \Fuel::clean_path($path) . "'");
     }
     // determine the module namespace
     $ns = '\\' . ucfirst($module);
     // add the namespace to the autoloader
     \Autoloader::add_namespaces(array($ns => $path . 'classes' . DS), true);
     static::$modules[$module] = $path;
     return true;
 }
示例#2
0
 /**
  * Add module
  *
  * Registers a given module as a class prefix and returns the path to the
  * module. Won't register twice, will just return the path on a second call.
  *
  * @param	string	module name (lowercase prefix without underscore)
  * @param	bool	whether it is an loaded package
  */
 public static function add_module($name, $loaded = false)
 {
     if (!($path = Autoloader::namespace_path('\\' . ucfirst($name)))) {
         $paths = \Config::get('module_paths', array());
         if (empty($paths)) {
             return false;
         }
         foreach ($paths as $modpath) {
             if (is_dir($mod_check_path = $modpath . strtolower($name) . DS)) {
                 $path = $mod_check_path;
                 $ns = '\\' . ucfirst($name);
                 Autoloader::add_namespaces(array($ns => $path . 'classes' . DS), true);
                 break;
             }
         }
     } else {
         // strip the classes directory, we need the module root
         $path = substr($path, 0, -8);
     }
     if ($loaded) {
         // add the module path
         static::add_path($path);
         // get the path for this modules namespace
         if ($path = Autoloader::namespace_path('\\' . ucfirst($name))) {
             // add the namespace path too
             static::add_path($path);
         }
     }
     return $path;
 }
示例#3
0
文件: fuel.php 项目: phabos/fuel-core
 /**
  * Add module
  *
  * Registers a given module as a class prefix and returns the path to the
  * module. Won't register twice, will just return the path on a second call.
  *
  * @param   string  module name (lowercase prefix without underscore)
  * @return  string  the path that was loaded
  */
 public static function add_module($name)
 {
     if (!($path = \Autoloader::namespace_path('\\' . ucfirst($name)))) {
         $paths = \Config::get('module_paths', array());
         if (!empty($paths)) {
             foreach ($paths as $modpath) {
                 if (is_dir($mod_check_path = $modpath . strtolower($name) . DS)) {
                     $path = $mod_check_path;
                     $ns = '\\' . ucfirst($name);
                     \Autoloader::add_namespaces(array($ns => $path . 'classes' . DS), true);
                     break;
                 }
             }
         }
         // throw an exception if a non-existent module has been added
         if (!isset($ns)) {
             throw new \FuelException('Trying to add a non-existent module "' . $name . '"');
         }
     } else {
         // strip the classes directory, we need the module root
         $path = substr($path, 0, -8);
     }
     return $path;
 }
示例#4
0
<?php

// Bootstrap the framework DO NOT edit this
require COREPATH . 'bootstrap.php';
Autoloader::add_namespaces(array());
Autoloader::add_classes(array('DbModel\\DataTrain' => APPPATH . 'classes/model/msgboardDB.php'));
// Register the autoloader
Autoloader::register();
/**
 * Your environment.  Can be set to any of the following:
 *
 * Fuel::DEVELOPMENT
 * Fuel::TEST
 * Fuel::STAGING
 * Fuel::PRODUCTION
 */
Fuel::$env = isset($_SERVER['FUEL_ENV']) ? $_SERVER['FUEL_ENV'] : Fuel::DEVELOPMENT;
// Initialize the framework with the config file.
Fuel::init('config.php');
示例#5
0
文件: fuel.php 项目: novius/core
	/**
	 * Add module
	 *
	 * Registers a given module as a class prefix and returns the path to the
	 * module. Won't register twice, will just return the path on a second call.
	 *
	 * @param   string  module name (lowercase prefix without underscore)
	 * @return  string  the path that was loaded
	 */
	public static function add_module($name)
	{
		if ( ! $path = \Autoloader::namespace_path('\\'.ucfirst($name)))
		{
			$paths = \Config::get('module_paths', array());

			if (empty($paths))
			{
				return false;
			}

			foreach ($paths as $modpath)
			{
				if (is_dir($mod_check_path = $modpath.strtolower($name).DS))
				{
					$path = $mod_check_path;
					$ns = '\\'.ucfirst($name);
					\Autoloader::add_namespaces(array(
						$ns					=> $path.'classes'.DS,
					), true);
					break;
				}
			}
		}
		else
		{
			// strip the classes directory, we need the module root
			$path = substr($path,0, -8);
		}

		return $path;
	}
示例#6
0
文件: fuel.php 项目: ralf57/fuel
	/**
	 * Add module
	 *
	 * Registers a given module as a class prefix and returns the path to the
	 * module. Won't register twice, will just return the path on a second call.
	 *
	 * @param	string	module name (lowercase prefix without underscore)
	 * @param	bool	whether it is an active package
	 */
	public static function add_module($name, $active = false)
	{
		$paths = \Config::get('module_paths', array());

		if (empty($paths))
		{
			return false;
		}

		$path = Autoloader::namespace_path('\\'.ucfirst($name));

		if ( ! $path)
		{
			foreach ($paths as $path)
			{
				if (is_dir($mod_check_path = $path.strtolower($name).DS))
				{
					$path = $mod_check_path;
					$ns = '\\'.ucfirst($name);
					Autoloader::add_namespaces(array(
						$ns					=> $path.'classes'.DS,
						$ns.'\\Model'		=> $path.'classes'.DS.'model'.DS,
						$ns.'\\Controller'	=> $path.'classes'.DS.'controller'.DS,
					), true);
					Autoloader::add_namespace_aliases(array(
						$ns.'\\Controller'	=> 'Fuel\\App',
						$ns.'\\Model'		=> 'Fuel\\App',
						$ns					=> 'Fuel\\App',
					), true);
					break;
				}
			}
		}

		// not found
		if ( ! $path)
		{
			return false;
		}

		// add the module path
		static::add_path($path);

		// get the path for this modules namespace
		$path = Autoloader::namespace_path('\\'.ucfirst($name));

		// Active modules get their path prefixed and routes loaded
		if ($active)
		{
			static::add_path($path, true);

			// We want active modules to be able to have their own routes, so we reload routes.
			\Route::load_routes(true);
			return $path;
		}

		static::add_path($path);
		return $path;
	}
示例#7
0
<?php

\Autoloader::add_namespaces(array('Erp' => __DIR__ . DS . 'classes' . DS), true);
$menu = \Menu_Admin::instance('indigo');
$menu->add(array(array('name' => gettext('ERP'), 'icon' => 'glyphicon glyphicon-file', 'sort' => 15, 'children' => array(array('name' => gettext('Products'), 'url' => \Uri::admin(false) . 'erp/stock/product'), array('name' => gettext('Manufacturers'), 'url' => \Uri::admin(false) . 'erp/stock/manufacturer')))));