yiisoft/yii — Issue #397: yiiBase class_exists method
Author: droletm
Created: 2012-02-24 17:57:20+00:00
State: open

add a class exists method into yii to be able to check if a class is available or not. Cause actuall it's impossible to use the php class_exists function when the yiiBase enableIncludePath property is set to true.

A situation when you want to use this:
using a class factory that send you a default class if the requested one does not exists.

Here is the code that could be used to create the requested function.

/**
* Check if a class exists using the php include paths to find it.
*
* @param string $className The name of the class to find.
* NOTE: it's the file name, the name of the class will not be checked
*
* @static
* @access public
* @return boolean whether the class has been found.
*/
public static function class_exists($className)
{
foreach(self::$_includePaths as $path)
{
$classFile = $path . DIRECTORY_SEPARATOR . $className . '.php';
if (is_file($classFile))
{
return true;
}
}

return false;
}