本文整理汇总了PHP中Autoloader::namespace_path方法的典型用法代码示例。如果您正苦于以下问题:PHP Autoloader::namespace_path方法的具体用法?PHP Autoloader::namespace_path怎么用?PHP Autoloader::namespace_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Autoloader
的用法示例。
在下文中一共展示了Autoloader::namespace_path方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* Formats the output and saved it to disc.
*
* @param string $identifier filename
* @param $contents $contents language array to save
* @return bool \File::update result
*/
public function save($identifier, $contents)
{
// store the current filename
$file = $this->file;
// save it
$return = parent::save($identifier, $contents);
// existing file? saved? and do we need to flush the opcode cache?
if ($file == $this->file and $return and static::$flush_needed) {
if ($this->file[0] !== '/' and (!isset($this->file[1]) or $this->file[1] !== ':')) {
// locate the file
if ($pos = strripos($identifier, '::')) {
// get the namespace path
if ($file = \Autoloader::namespace_path('\\' . ucfirst(substr($identifier, 0, $pos)))) {
// strip the namespace from the filename
$identifier = substr($identifier, $pos + 2);
// strip the classes directory as we need the module root
$file = substr($file, 0, -8) . 'lang' . DS . $identifier;
} else {
// invalid namespace requested
return false;
}
} else {
$file = \Finder::search('lang', $identifier);
}
}
// make sure we have a fallback
$file or $file = APPPATH . 'lang' . DS . $identifier;
// flush the opcode caches that are active
static::$uses_opcache and opcache_invalidate($file, true);
static::$uses_apc and apc_compile_file($file);
}
return $return;
}
示例2: save
public static function save($file, $config)
{
if (!is_array($config)) {
if (!isset(static::$items[$config])) {
return false;
}
$config = static::$items[$config];
}
$content = <<<CONF
<?php
/**
* Fuel is a fast, lightweight, community driven PHP5 framework.
*
* @package\t\tFuel
* @version\t\t1.0
* @author\t\tFuel Development Team
* @license\t\tMIT License
* @copyright\t2011 Fuel Development Team
* @link\t\thttp://fuelphp.com
*/
CONF;
$content .= 'return ' . str_replace(' ', "\t", var_export($config, true)) . ';';
if (!($path = \Fuel::find_file('config', $file, '.php'))) {
if ($pos = strripos($file, '::')) {
// get the namespace path
if ($path = \Autoloader::namespace_path('\\' . ucfirst(substr($file, 0, $pos)))) {
// strip the namespace from the filename
$file = substr($file, $pos + 2);
// strip the classes directory as we need the module root
// and construct the filename
$path = substr($path, 0, -8) . 'config' . DS . $file . '.php';
} else {
// invalid namespace requested
return false;
}
}
}
$content .= <<<CONF
CONF;
// make sure we have a fallback
$path or $path = APPPATH . 'config' . DS . $file . '.php';
$path = pathinfo($path);
return File::update($path['dirname'], $path['basename'], $content);
}
示例3: save
/**
* Formats the output and saved it to disc.
*
* @param $contents $contents config array to save
* @return bool \File::update result
*/
public function save($contents)
{
// get the formatted output
$output = $this->export_format($contents);
if (!$output) {
return false;
}
if (!($path = \Finder::search('config', $this->file, $this->ext))) {
if ($pos = strripos($this->file, '::')) {
// get the namespace path
if ($path = \Autoloader::namespace_path('\\' . ucfirst(substr($this->file, 0, $pos)))) {
// strip the namespace from the filename
$this->file = substr($this->file, $pos + 2);
// strip the classes directory as we need the module root
$path = substr($path, 0, -8) . 'config' . DS . $this->file . $this->ext;
} else {
// invalid namespace requested
return false;
}
}
}
// absolute path requested?
if ($this->file[0] === '/' or isset($this->file[1]) and $this->file[1] === ':') {
$path = $this->file;
}
// make sure we have a fallback
$path or $path = APPPATH . 'config' . DS . $this->file . $this->ext;
$path = pathinfo($path);
if (!is_dir($path['dirname'])) {
mkdir($path['dirname'], 0777, true);
}
$return = \File::update($path['dirname'], $path['basename'], $output);
if ($return) {
try {
\Config::load('file', true);
chmod($path['dirname'] . DS . $path['basename'], \Config::get('file.chmod.files', 0666));
} catch (\PhpErrorException $e) {
// if we get something else then a chmod error, bail out
if (substr($e->getMessage(), 0, 8) !== 'chmod():') {
throw new $e();
}
}
}
return $return;
}
示例4: config
public static function config($args)
{
$file = strtolower(array_shift($args));
if (empty($file)) {
throw new Exception('No config filename has been provided.');
}
$config = array();
// load the config
if ($paths = \Finder::search('config', $file, '.php', true)) {
// Reverse the file list so that we load the core configs first and
// the app can override anything.
$paths = array_reverse($paths);
foreach ($paths as $path) {
$config = \Fuel::load($path) + $config;
}
}
unset($path);
// We always pass in fields to a config, so lets sort them out here.
foreach ($args as $conf) {
// Each paramater for a config is seperated by the : character
$parts = explode(":", $conf);
// We must have the 'name:value' if nothing else!
if (count($parts) >= 2) {
$config[$parts[0]] = $parts[1];
}
}
$overwrite = (\Cli::option('o') or \Cli::option('overwrite'));
// strip whitespace and add tab
$export = str_replace(array(' ', 'array ('), array("\t", 'array('), var_export($config, true));
$content = '<?php' . PHP_EOL . PHP_EOL . 'return ' . $export . ';';
$content .= <<<CONF
/* End of file {$file}.php */
CONF;
$module = \Cli::option('module', \Cli::option('m'));
// add support for `php oil g config module::file arg1:value1`
if (strpos($file, '::') !== false) {
list($module, $file) = explode('::', $file);
}
// get the namespace path (if available)
if (!empty($module) and $path = \Autoloader::namespace_path('\\' . ucfirst($module))) {
// strip the classes directory as we need the module root
// and construct the filename
$path = substr($path, 0, -8) . 'config' . DS . $file . '.php';
$path_name = "\\" . ucfirst($module) . '::';
} elseif (!empty($module)) {
throw new Exception("{$module} need to be loaded first, please use config always_load.modules.");
} else {
$path = APPPATH . 'config' . DS . $file . '.php';
$path_name = 'APPPATH/';
}
if (!$overwrite and is_file($path)) {
throw new Exception("{$path_name}/config/{$file}.php already exist, please use --overwrite option to force update");
}
$path = pathinfo($path);
try {
\File::update($path['dirname'], $path['basename'], $content);
\Cli::write("Created config: {$path_name}config/{$file}.php", 'green');
} catch (\InvalidPathException $e) {
throw new Exception("Invalid basepath, cannot update at " . $path_name . "config" . DS . "{$file}.php");
} catch (\FileAccessException $e) {
throw new Exception($path_name . "config" . DS . $file . ".php could not be written.");
}
}
示例5: locate
/**
* Locates a given file in the search paths.
*
* @param string $dir Directory to look in
* @param string $file File to find
* @param string $ext File extension
* @param bool $multiple Whether to find multiple files
* @param bool $cache Whether to cache this path or not
* @return mixed Path, or paths, or false
*/
public function locate($dir, $file, $ext = '.php', $multiple = false, $cache = true)
{
$found = $multiple ? array() : false;
// absolute path requested?
if ($file[0] === '/' or substr($file, 1, 2) === ':\\') {
if (!is_file($file)) {
// at this point, found would be either empty array or false
return $found;
}
return $multiple ? array($file) : $file;
}
$cache_id = $multiple ? 'M.' : 'S.';
$paths = array();
// If a filename contains a :: then it is trying to be found in a namespace.
// This is sometimes used to load a view from a non-loaded module.
if ($pos = strripos($file, '::')) {
// get the namespace path
if ($path = \Autoloader::namespace_path('\\' . ucfirst(substr($file, 0, $pos)))) {
$cache_id .= substr($file, 0, $pos);
// and strip the classes directory as we need the module root
$paths = array(substr($path, 0, -8));
// strip the namespace from the filename
$file = substr($file, $pos + 2);
}
} else {
$paths = $this->paths;
// get extra information of the active request
if (class_exists('Request', false) and $request = \Request::active()) {
$request->module and $cache_id .= $request->module;
$paths = array_merge($request->get_paths(), $paths);
}
}
// Merge in the flash paths then reset the flash paths
$paths = array_merge($this->flash_paths, $paths);
$this->clear_flash();
$file = $this->prep_path($dir) . $file . $ext;
$cache_id .= $file;
if ($cache and $cached_path = $this->from_cache($cache_id)) {
return $cached_path;
}
foreach ($paths as $dir) {
$file_path = $dir . $file;
if (is_file($file_path)) {
if (!$multiple) {
$found = $file_path;
break;
}
$found[] = $file_path;
}
}
if (!empty($found) and $cache) {
$this->add_to_cache($cache_id, $found);
}
return $found;
}
示例6: add_module
/**
* 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;
}
示例7: save
/**
* Formats the output and saved it to disc.
*
* @param string $identifier filename
* @param $contents $contents config array to save
* @return bool \File::update result
*/
public function save($identifier, $contents)
{
// get the formatted output
$output = $this->export_format($contents);
if (!$output) {
return false;
}
if (!($path = \Finder::search('config', $identifier))) {
if ($pos = strripos($identifier, '::')) {
// get the namespace path
if ($path = \Autoloader::namespace_path('\\' . ucfirst(substr($identifier, 0, $pos)))) {
// strip the namespace from the filename
$identifier = substr($identifier, $pos + 2);
// strip the classes directory as we need the module root
$path = substr($path, 0, -8) . 'config' . DS . $identifier;
} else {
// invalid namespace requested
return false;
}
}
}
// absolute path requested?
if ($identifier[0] === '/' or isset($identifier[1]) and $identifier[1] === ':') {
$path = $identifier;
}
// make sure we have a fallback
$path or $path = APPPATH . 'config' . DS . $identifier;
$path = pathinfo($path);
if (!is_dir($path['dirname'])) {
mkdir($path['dirname'], 0777, true);
}
return \File::update($path['dirname'], $path['basename'], $output);
}
示例8: add_module
/**
* 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;
}
示例9: save
/**
* Save a config array to disc.
*
* @param string $file desired file name
* @param string|array $config master config array key or config array
* @return bool false when config is empty or invalid else \File::update result
*/
public static function save($file, $config)
{
if (!is_array($config)) {
if (!isset(static::$items[$config])) {
return false;
}
$config = static::$items[$config];
}
$content = <<<CONF
<?php
CONF;
$content .= 'return ' . str_replace(array(' ', 'array (', '\'' . APPPATH, '\'' . DOCROOT, '\'' . COREPATH, '\'' . PKGPATH), array("\t", 'array(', 'APPPATH.\'', 'DOCROOT.\'', 'COREPATH.\'', 'PKGPATH.\''), var_export($config, true)) . ";\n";
if (!($path = \Finder::search('config', $file, '.php'))) {
if ($pos = strripos($file, '::')) {
// get the namespace path
if ($path = \Autoloader::namespace_path('\\' . ucfirst(substr($file, 0, $pos)))) {
// strip the namespace from the filename
$file = substr($file, $pos + 2);
// strip the classes directory as we need the module root
// and construct the filename
$path = substr($path, 0, -8) . 'config' . DS . $file . '.php';
} else {
// invalid namespace requested
return false;
}
}
}
// absolute path requested?
if ($file[0] === '/' or isset($file[1]) and $file[1] === ':') {
$path = $file;
}
// make sure we have a fallback
$path or $path = APPPATH . 'config' . DS . $file . '.php';
$path = pathinfo($path);
if (!is_dir($path['dirname'])) {
mkdir($path['dirname'], 0777, true);
}
return \File::update($path['dirname'], $path['basename'], $content);
}
示例10: add_module
/**
* 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;
}
示例11: add_module
/**
* 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;
}