Exemplo n.º 1
0
 /**
  * Remove an extension from a class.
  * Keep in mind that this won't revert any datamodel additions
  * of the extension at runtime, unless its used before the
  * schema building kicks in (in your _config.php).
  * Doesn't remove the extension from any {@link Object}
  * instances which are already created, but will have an
  * effect on new extensions.
  * Clears any previously created singletons through {@link singleton()}
  * to avoid side-effects from stale extension information.
  * 
  * @todo Add support for removing extensions with parameters
  *
  * @param string $class
  * @param string $extension Classname of an {@link Extension} subclass, without parameters
  */
 public static function remove_extension($class, $extension)
 {
     // unload statics now for DataObject classes
     if (ClassInfo::is_subclass_of($class, 'DataObject')) {
         if (!preg_match('/^([^(]*)/', $extension, $matches)) {
             user_error("Bad extension '{$extension}'", E_USER_WARNING);
         } else {
             $extensionClass = $matches[1];
             DataObjectDecorator::unload_extra_statics($class, $extensionClass);
         }
     }
     if (self::has_extension($class, $extension)) {
         self::set_static($class, 'extensions', array_diff(self::uninherited_static($class, 'extensions'), array($extension)));
     }
     // unset singletons to avoid side-effects
     global $_SINGLETONS;
     $_SINGLETONS = array();
     // unset some caches
     self::$cached_statics[$class]['extensions'] = null;
     $subclasses = ClassInfo::subclassesFor($class);
     $subclasses[] = $class;
     if ($subclasses) {
         foreach ($subclasses as $subclass) {
             unset(self::$classes_constructed[$subclass]);
             unset(self::$extra_methods[$subclass]);
         }
     }
 }