Add backwards compatibility for has_extension

This commit is contained in:
Craig Lyons 2013-10-11 10:18:00 -04:00
parent 829b45af67
commit 27b139bc75

View File

@ -470,12 +470,21 @@ abstract class Object {
} }
/** /**
* Return TRUE if a class has a specified extension * Return TRUE if a class has a specified extension.
* * This supports backwards-compatible format (static Object::has_extension($requiredExtension)) and new format ($object->has_extension($class, $requiredExtension))
* @param string $requiredExtension the class name of the extension to check for. * @param string $classOrExtension if 1 argument supplied, the class name of the extension to check for; if 2 supplied, the class name to test
* @param string $requiredExtension used only if 2 arguments supplied
*/ */
public static function has_extension($requiredExtension) { public static function has_extension($classOrExtension, $requiredExtension = null) {
$class = get_called_class(); //BC support
if(func_num_args() > 1){
$class = $classOrExtension;
$requiredExtension = $requiredExtension;
}
else {
$class = get_called_class();
$requiredExtension = $classOrExtension;
}
$requiredExtension = strtolower($requiredExtension); $requiredExtension = strtolower($requiredExtension);
$extensions = Config::inst()->get($class, 'extensions'); $extensions = Config::inst()->get($class, 'extensions');