|
|
@ -154,7 +154,7 @@ class YiiBase |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($alias[0] !== '@') { // a simple class name |
|
|
|
if ($alias[0] !== '@') { // a simple class name |
|
|
|
if ($forceInclude && self::autoload($alias)) { |
|
|
|
if ($forceInclude && static::autoload($alias)) { |
|
|
|
self::$_imported[$alias] = $alias; |
|
|
|
self::$_imported[$alias] = $alias; |
|
|
|
} |
|
|
|
} |
|
|
|
return $alias; |
|
|
|
return $alias; |
|
|
@ -167,7 +167,7 @@ class YiiBase |
|
|
|
return self::$_imported[$alias] = $className; |
|
|
|
return self::$_imported[$alias] = $className; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (($path = self::getAlias(dirname($alias))) === false) { |
|
|
|
if (($path = static::getAlias(dirname($alias))) === false) { |
|
|
|
throw new \yii\base\Exception('Invalid path alias: ' . $alias); |
|
|
|
throw new \yii\base\Exception('Invalid path alias: ' . $alias); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -240,7 +240,7 @@ class YiiBase |
|
|
|
elseif ($path[0] !== '@') { |
|
|
|
elseif ($path[0] !== '@') { |
|
|
|
self::$aliases[$alias] = rtrim($path, '\\/'); |
|
|
|
self::$aliases[$alias] = rtrim($path, '\\/'); |
|
|
|
} |
|
|
|
} |
|
|
|
elseif (($p = self::getAlias($path)) !== false) { |
|
|
|
elseif (($p = static::getAlias($path)) !== false) { |
|
|
|
self::$aliases[$alias] = $p; |
|
|
|
self::$aliases[$alias] = $p; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
@ -277,7 +277,7 @@ class YiiBase |
|
|
|
if (strpos($className, '\\') !== false) { |
|
|
|
if (strpos($className, '\\') !== false) { |
|
|
|
// convert namespace to path alias, e.g. yii\base\Component to @yii/base/Component |
|
|
|
// convert namespace to path alias, e.g. yii\base\Component to @yii/base/Component |
|
|
|
$alias = '@' . str_replace('\\', '/', ltrim($className, '\\')); |
|
|
|
$alias = '@' . str_replace('\\', '/', ltrim($className, '\\')); |
|
|
|
if (($path = self::getAlias($alias)) !== false) { |
|
|
|
if (($path = static::getAlias($alias)) !== false) { |
|
|
|
include($path . '.php'); |
|
|
|
include($path . '.php'); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
@ -288,7 +288,7 @@ class YiiBase |
|
|
|
if (($pos = strpos($className, '_')) !== false) { |
|
|
|
if (($pos = strpos($className, '_')) !== false) { |
|
|
|
// convert class name to path alias, e.g. PHPUnit_Framework_TestCase to @PHPUnit/Framework/TestCase |
|
|
|
// convert class name to path alias, e.g. PHPUnit_Framework_TestCase to @PHPUnit/Framework/TestCase |
|
|
|
$alias = '@' . str_replace('_', '/', $className); |
|
|
|
$alias = '@' . str_replace('_', '/', $className); |
|
|
|
if (($path = self::getAlias($alias)) !== false) { |
|
|
|
if (($path = static::getAlias($alias)) !== false) { |
|
|
|
include($path . '.php'); |
|
|
|
include($path . '.php'); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
@ -307,15 +307,16 @@ class YiiBase |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates an object and initializes its properties based on the given configuration. |
|
|
|
* Creates a new component instance using the given configuration. |
|
|
|
* |
|
|
|
* |
|
|
|
* The specified configuration can be either a string or an array. |
|
|
|
* The specified configuration can be either a string or an array. |
|
|
|
* If the former, the string is treated as the object type which can |
|
|
|
* If the former, the string is treated as the object type; if the latter, |
|
|
|
* be either a class name or [[getAlias|path alias]]. |
|
|
|
* the array must contain a `class` element specifying the object type, and |
|
|
|
* If the latter, the array must contain a `class` element which refers |
|
|
|
* the rest of the name-value pairs in the array will be used to initialize |
|
|
|
* to a class name or [[getAlias|path alias]]. The rest of the name-value |
|
|
|
* the corresponding object properties. |
|
|
|
* pairs in the array will be used to initialize the corresponding object properties. |
|
|
|
* |
|
|
|
* For example, |
|
|
|
* The object type can be either a class name or [[getAlias|path alias]] of |
|
|
|
|
|
|
|
* the class. For example, |
|
|
|
* |
|
|
|
* |
|
|
|
* ~~~ |
|
|
|
* ~~~ |
|
|
|
* $component = Yii::createComponent('@app/components/GoogleMap'); |
|
|
|
* $component = Yii::createComponent('@app/components/GoogleMap'); |
|
|
@ -330,63 +331,65 @@ class YiiBase |
|
|
|
* passed to the constructor of the object being created. |
|
|
|
* passed to the constructor of the object being created. |
|
|
|
* |
|
|
|
* |
|
|
|
* If a component class implements the [[\yii\base\Initable]] interface, |
|
|
|
* If a component class implements the [[\yii\base\Initable]] interface, |
|
|
|
* its [[\yii\base\Initable::init|init]] method will be invoked after |
|
|
|
* its [[\yii\base\Initable::preinit|preinit]] and [[\yii\base\Initable::init|init]] |
|
|
|
* its properties have been initialized. |
|
|
|
* methods will be invoked BEFORE and AFTER the component properties are initialized, |
|
|
|
|
|
|
|
* respectively. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param mixed $config the configuration. It can be either a string or an array. |
|
|
|
* @param mixed $config the configuration. It can be either a string or an array. |
|
|
|
* @return mixed the created object |
|
|
|
* @return mixed the created object |
|
|
|
* @throws \yii\base\Exception if the configuration does not have a 'class' element. |
|
|
|
* @throws \yii\base\Exception if the configuration is invalid. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static function createComponent($config) |
|
|
|
public static function createComponent($config) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (is_string($config)) { |
|
|
|
if (is_string($config)) { |
|
|
|
$type = $config; |
|
|
|
$class = $config; |
|
|
|
$config = array(); |
|
|
|
$config = array(); |
|
|
|
} |
|
|
|
} |
|
|
|
elseif (isset($config['class'])) { |
|
|
|
elseif (isset($config['class'])) { |
|
|
|
$type = $config['class']; |
|
|
|
$class = $config['class']; |
|
|
|
unset($config['class']); |
|
|
|
unset($config['class']); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
throw new \yii\base\Exception('Object configuration must be an array containing a "class" element.'); |
|
|
|
throw new \yii\base\Exception('Object configuration must be an array containing a "class" element.'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!class_exists($type, false)) { |
|
|
|
if (!class_exists($class, false)) { |
|
|
|
$type = Yii::import($type, true); |
|
|
|
$class = static::import($class, true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (($n = func_num_args()) > 1) { |
|
|
|
if (($n = func_num_args()) > 1) { |
|
|
|
$args = func_get_args(); |
|
|
|
$args = func_get_args(); |
|
|
|
if ($n === 2) { |
|
|
|
if ($n === 2) { |
|
|
|
$object = new $type($args[1]); |
|
|
|
$object = new $class($args[1]); |
|
|
|
} |
|
|
|
} |
|
|
|
elseif ($n === 3) { |
|
|
|
elseif ($n === 3) { |
|
|
|
$object = new $type($args[1], $args[2]); |
|
|
|
$object = new $class($args[1], $args[2]); |
|
|
|
} |
|
|
|
} |
|
|
|
elseif ($n === 4) { |
|
|
|
elseif ($n === 4) { |
|
|
|
$object = new $type($args[1], $args[2], $args[3]); |
|
|
|
$object = new $class($args[1], $args[2], $args[3]); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
unset($args[0]); |
|
|
|
unset($args[0]); |
|
|
|
$class = new ReflectionClass($type); |
|
|
|
$r = new ReflectionClass($class); |
|
|
|
$object = $class->newInstanceArgs($args); |
|
|
|
$object = $r->newInstanceArgs($args); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
$object = new $type; |
|
|
|
$object = new $class; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($object instanceof \yii\base\Component) { |
|
|
|
if ($object instanceof Initable) { |
|
|
|
$object->preinit(); |
|
|
|
$object->preinit(); |
|
|
|
} |
|
|
|
foreach ($config as $name => $value) { |
|
|
|
|
|
|
|
$object->$name = $value; |
|
|
|
foreach ($config as $key => $value) { |
|
|
|
} |
|
|
|
$object->$key = $value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($object instanceof \yii\base\Initable) { |
|
|
|
|
|
|
|
$object->init(); |
|
|
|
$object->init(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
foreach ($config as $name => $value) { |
|
|
|
|
|
|
|
$object->$name = $value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $object; |
|
|
|
return $object; |
|
|
|
} |
|
|
|
} |
|
|
@ -401,7 +404,7 @@ class YiiBase |
|
|
|
public static function trace($msg, $category = 'application') |
|
|
|
public static function trace($msg, $category = 'application') |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (YII_DEBUG) { |
|
|
|
if (YII_DEBUG) { |
|
|
|
self::log($msg, CLogger::LEVEL_TRACE, $category); |
|
|
|
static::log($msg, CLogger::LEVEL_TRACE, $category); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -459,7 +462,7 @@ class YiiBase |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static function beginProfile($token, $category = 'application') |
|
|
|
public static function beginProfile($token, $category = 'application') |
|
|
|
{ |
|
|
|
{ |
|
|
|
self::log('begin:' . $token, CLogger::LEVEL_PROFILE, $category); |
|
|
|
static::log('begin:' . $token, CLogger::LEVEL_PROFILE, $category); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -471,7 +474,7 @@ class YiiBase |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static function endProfile($token, $category = 'application') |
|
|
|
public static function endProfile($token, $category = 'application') |
|
|
|
{ |
|
|
|
{ |
|
|
|
self::log('end:' . $token, CLogger::LEVEL_PROFILE, $category); |
|
|
|
static::log('end:' . $token, CLogger::LEVEL_PROFILE, $category); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|