$path) { if (is_numeric($pkg)) { $pkg = $path; $path = null; } $result = $result and static::load($pkg, $path); } return $result; } if (static::loaded($package)) { return false; } // if no path is given, try to locate the package if ($path === null) { $paths = \Config::get('package_paths', array()); empty($paths) and $paths = array(PKGPATH); if ( ! empty($paths)) { foreach ($paths as $modpath) { if (is_dir($path = $modpath.strtolower($package).DS)) { break; } } } } if ( ! is_dir($path)) { throw new \PackageNotFoundException("Package '$package' could not be found at '".\Fuel::clean_path($path)."'"); } \Finder::instance()->add_path($path, 1); \Fuel::load($path.'bootstrap.php'); static::$packages[$package] = $path; return true; } /** * Unloads a package from the stack. * * @param string $package The package name * @return void */ public static function unload($package) { \Finder::instance()->remove_path(static::$packages[$package]); unset(static::$packages[$package]); } /** * Checks if the given package is loaded, if no package is given then * all loaded packages are returned. * * @param string|null $package The package name or null * @return bool|array Whether the package is loaded, or all packages */ public static function loaded($package = null) { if ($package === null) { return static::$packages; } return array_key_exists($package, static::$packages); } /** * Checks if the given package exists. * * @param string $package The package name * @return bool|string Path to the package found, or false if not found */ public static function exists($package) { if (array_key_exists($package, static::$packages)) { return static::$packages[$package]; } else { $paths = \Config::get('package_paths', array()); empty($paths) and $paths = array(PKGPATH); $package = strtolower($package); foreach ($paths as $path) { if (is_dir($path.$package)) { return $path.$package.DS; } } } return false; } }