public static function add_extension($classOrExtension, $extension = null)
    {
        if ($extension) {
            $class = $classOrExtension;
        } else {
            $class = get_called_class();
            $extension = $classOrExtension;
        }

        if (!preg_match('/^([^(]*)/', $extension, $matches)) {
            return false;
        }
        $extensionClass = $matches[1];
        if (!class_exists($extensionClass)) {
            user_error(
                sprintf('Object::add_extension() - Can\'t find extension class for "%s"', $extensionClass),
                E_USER_ERROR
            );
        }

        if (!is_subclass_of($extensionClass, 'SilverStripe\\Core\\Extension')) {
            user_error(
                sprintf('Object::add_extension() - Extension "%s" is not a subclass of Extension', $extensionClass),
                E_USER_ERROR
            );
        }

        // unset some caches
        $subclasses = ClassInfo::subclassesFor($class);
        $subclasses[] = $class;

        if ($subclasses) {
            foreach ($subclasses as $subclass) {
                unset(self::$extra_methods[$subclass]);
            }
        }

        Config::modify()
            ->merge($class, 'extensions', array(
                $extension
            ));

        Injector::inst()->unregisterNamedObject($class);
        return true;
    }