当前位置: 首页>>代码示例>>PHP>>正文


PHP Yii::_includePaths方法代码示例

本文整理汇总了PHP中Yii::_includePaths方法的典型用法代码示例。如果您正苦于以下问题:PHP Yii::_includePaths方法的具体用法?PHP Yii::_includePaths怎么用?PHP Yii::_includePaths使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Yii的用法示例。


在下文中一共展示了Yii::_includePaths方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: import

 /**
  * Imports a class or a directory.
  * Overrides {@link YiiBase::import()} to check in /custom for all imported classes
  *
  * @param string $alias path alias to be imported
  * @param boolean $forceInclude whether to include the class file immediately. If false, the class file
  * will be included only when the class is being used. This parameter is used only when
  * the path alias refers to a class.
  * @return string the class name or the directory that this alias refers to
  * @throws CException if the alias is invalid
  */
 public static function import($alias, $forceInclude = false)
 {
     if (isset(self::$_imports[$alias])) {
         // previously imported
         return self::$_imports[$alias];
     }
     if (class_exists($alias, false) || interface_exists($alias, false)) {
         return self::$_imports[$alias] = $alias;
     }
     if (($pos = strrpos($alias, '\\')) !== false) {
         $namespace = str_replace('\\', '.', ltrim(substr($alias, 0, $pos), '\\'));
         if (($path = self::getPathOfAlias($namespace)) !== false) {
             $classFile = $path . DIRECTORY_SEPARATOR . substr($alias, $pos + 1) . '.php';
             if ($forceInclude) {
                 if (is_file($classFile)) {
                     require self::getCustomPath($classFile);
                 } else {
                     throw new CException(Yii::t('yii', 'Alias "{alias}" is invalid. Make sure it points to an existing PHP file.', array('{alias}' => $alias)));
                 }
                 self::$_imports[$alias] = $alias;
             } else {
                 self::$classMap[$alias] = $classFile;
             }
             return $alias;
         } else {
             throw new CException(Yii::t('yii', 'Alias "{alias}" is invalid. Make sure it points to an existing directory.', array('{alias}' => $namespace)));
         }
     }
     if (($pos = strrpos($alias, '.')) === false) {
         if ($forceInclude && self::x2_autoload($alias)) {
             self::$_imports[$alias] = $alias;
         }
         return $alias;
     }
     $className = (string) substr($alias, $pos + 1);
     $isClass = $className !== '*';
     if ($isClass && (class_exists($className, false) || interface_exists($className, false))) {
         return self::$_imports[$alias] = $className;
     }
     if (($path = self::getPathOfAlias($alias)) !== false) {
         if ($isClass) {
             if ($forceInclude) {
                 if (is_file($path . '.php')) {
                     require self::getCustomPath($path . '.php');
                 } else {
                     throw new CException(Yii::t('yii', 'Alias "{alias}" is invalid. Make sure it points to an existing PHP file.', array('{alias}' => $alias)));
                 }
                 self::$_imports[$alias] = $className;
             } else {
                 self::$classMap[$className] = $path . '.php';
             }
             return $className;
         } else {
             if (self::$_includePaths === null) {
                 self::$_includePaths = array_unique(explode(PATH_SEPARATOR, get_include_path()));
                 if (($pos = array_search('.', self::$_includePaths, true)) !== false) {
                     unset(self::$_includePaths[$pos]);
                 }
             }
             array_unshift(self::$_includePaths, $path);
             if (self::$enableIncludePath && set_include_path('.' . PATH_SEPARATOR . implode(PATH_SEPARATOR, self::$_includePaths)) === false) {
                 self::$enableIncludePath = false;
             }
             return self::$_imports[$alias] = $path;
         }
     } else {
         throw new CException(Yii::t('yii', 'Alias "{alias}" is invalid. Make sure it points to an existing directory or file.', array('{alias}' => $alias)));
     }
 }
开发者ID:keyeMyria,项目名称:CRM,代码行数:80,代码来源:yii.php


注:本文中的Yii::_includePaths方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。