Jump to content

Manual:ContextSource.php

From mediawiki.org

ContextSource is an abstract class that holds request-dependent objects containers.

It implements IContextSource.

Public methods

  • getContext()
  • setContext()
  • etc.

Extended by

Notes

From a ContextSource class you can use setContext() to set the context your class is in. For example a constructor that requires a context can be written like so:

class SomeClass extends ContextSource {
  public function __constructor( IContextSource $context ) {
    $this->setContext( $context );
  }
}

Because we cannot use traits[1] yet if you need to make your class extend from another class you will have to implements IContextSource and implement the helper boilerplate directly in the class.

Again if you can't extend ContextSource you'll have to write the helper boilerplate into your class directly. As we unfortunately cannot use traits[1] to allow something like this:

class SomeClass extends SomeOtherClass implements IContextSource {
  use TContextSource;
  public function __constructor( IContextSource $context ) {
    $this->setContext( $context );
  }
}
  1. 1.0 1.1 Traits have appeared with PHP 5.4 and allow to reduce limitations of PHP single inheritance by allowing you to declare methods (abstract too) with their access modifier (public, private, protected) you can use in several classes.