Commit 87df068e by Qiang Xue

DI WIP

parent 8e11ad03
......@@ -55,7 +55,7 @@ $object = Yii::createObject([
'class' => 'MyClass',
'property1' => 'abc',
'property2' => 'cde',
], $param1, $param2);
], [$param1, $param2]);
```
......
......@@ -105,13 +105,11 @@ For each component you can specify class-wide defaults. For example, if you want
widgets without specifying the class for every widget usage, you can do the following:
```php
\Yii::$objectConfig = [
'yii\widgets\LinkPager' => [
'options' => [
'class' => 'pagination',
],
],
];
\Yii::$container->set('yii\widgets\LinkPager', [
'options' => [
'class' => 'pagination',
],
]);
```
The code above should be executed once before `LinkPager` widget is used. It can be done in `index.php`, the application
......
......@@ -71,7 +71,7 @@ $object = Yii::createObject([
'class' => 'MyClass',
'property1' => 'abc',
'property2' => 'cde',
], $param1, $param2);
], [$param1, $param2]);
```
More on configuration can be found in the [Basic concepts section](basics.md).
......
......@@ -200,10 +200,9 @@ class Mailer extends BaseMailer
}
}
unset($config['constructArgs']);
array_unshift($args, $className);
$object = call_user_func_array(['Yii', 'createObject'], $args);
$object = Yii::createObject($className, $args);
} else {
$object = new $className;
$object = Yii::createObject($className);
}
if (!empty($config)) {
foreach ($config as $name => $value) {
......
......@@ -10,6 +10,7 @@ use yii\base\InvalidConfigException;
use yii\base\InvalidParamException;
use yii\base\UnknownClassException;
use yii\log\Logger;
use yii\di\Container;
/**
* Gets the application start timestamp.
......@@ -76,26 +77,13 @@ class BaseYii
*/
public static $aliases = ['@yii' => __DIR__];
/**
* @var array initial property values that will be applied to objects newly created via [[createObject]].
* The array keys are class names without leading backslashes "\", and the array values are the corresponding
* name-value pairs for initializing the created class instances. For example,
*
* ~~~
* [
* 'Bar' => [
* 'prop1' => 'value1',
* 'prop2' => 'value2',
* ],
* 'mycompany\foo\Car' => [
* 'prop1' => 'value1',
* 'prop2' => 'value2',
* ],
* ]
* ~~~
*
* @var Container the dependency injection (DI) container used by [[createObject()]].
* You may use [[Container::set()]] to set up the needed dependencies of classes and
* their initial property values.
* @see createObject()
* @see Container
*/
public static $objectConfig = [];
public static $container;
/**
......@@ -304,11 +292,13 @@ class BaseYii
/**
* Creates a new object using the given configuration.
*
* The configuration can be either a string or an array.
* If a string, it is treated as the *object class*; if an array,
* it must contain a `class` element specifying the *object class*, and
* the rest of the name-value pairs in the array will be used to initialize
* the corresponding object properties.
* The following kinds of configuration are supported:
*
* - a string: representing the class name of the object to be created
* - a configuration array: the array must contain a `class` element which is treated as the object class,
* and the rest of the name-value pairs will be used to initialize the corresponding object properties
* - a PHP callable: either an anonymous function or an array representing a class method (`[$class or $object, $method]`).
* The callable should return a new instance of the object being created.
*
* Below are some usage examples:
*
......@@ -318,60 +308,44 @@ class BaseYii
* 'class' => 'app\components\GoogleMap',
* 'apiKey' => 'xyz',
* ]);
* $object = \Yii::createObject([
* return new \yii\base\Object;
* ]);
* ~~~
*
* Note that the last usage is mainly useful to create an object based on some dynamic configuration
* specified as a property of a component.
*
* This method can be used to create any object as long as the object's constructor is
* defined like the following:
*
* ~~~
* public function __construct(..., $config = []) {
* public function __construct(..., $config = [])
* {
* }
* ~~~
*
* The method will pass the given configuration as the last parameter of the constructor,
* and any additional parameters to this method will be passed as the rest of the constructor parameters.
*
* @param string|array $config the configuration. It can be either a string representing the class name
* or an array representing the object configuration.
* @return mixed the created object
* @param string|array|callable $config the configuration for creating the object.
* @return mixed the created object
* @throws InvalidConfigException if the configuration is invalid.
*/
public static function createObject($config)
public static function createObject($type, array $params = [])
{
static $reflections = [];
if (is_string($config)) {
$class = $config;
$config = [];
} elseif (isset($config['class'])) {
$class = $config['class'];
unset($config['class']);
} else {
if (is_string($type)) {
return static::$container->get($type, $params);
} elseif (is_array($type) && isset($type['class'])) {
$class = $type['class'];
unset($type['class']);
return static::$container->get($class, $params, $type);
} elseif (is_callable($type, true)) {
return call_user_func($type, $params, static::$container);
} elseif (is_array($type)) {
throw new InvalidConfigException('Object configuration must be an array containing a "class" element.');
}
$class = ltrim($class, '\\');
if (isset(static::$objectConfig[$class])) {
$config = array_merge(static::$objectConfig[$class], $config);
}
if (func_num_args() > 1) {
/** @var \ReflectionClass $reflection */
if (isset($reflections[$class])) {
$reflection = $reflections[$class];
} else {
$reflection = $reflections[$class] = new \ReflectionClass($class);
}
$args = func_get_args();
array_shift($args); // remove $config
if (!empty($config)) {
$args[] = $config;
}
return $reflection->newInstanceArgs($args);
} else {
return empty($config) ? new $class : new $class($config);
throw new InvalidConfigException("Unsupported configuration type: " . gettype($type));
}
}
......
......@@ -24,3 +24,4 @@ class Yii extends \yii\BaseYii
spl_autoload_register(['Yii', 'autoload'], true, true);
Yii::$classMap = include(__DIR__ . '/classes.php');
Yii::$container = new yii\di\Container;
......@@ -192,7 +192,7 @@ class Controller extends Component implements ViewContextInterface
$actionMap = $this->actions();
if (isset($actionMap[$id])) {
return Yii::createObject($actionMap[$id], $id, $this);
return Yii::createObject($actionMap[$id], [$id, $this]);
} elseif (preg_match('/^[a-z0-9\\-_]+$/', $id) && strpos($id, '--') === false && trim($id, '-') === $id) {
$methodName = 'action' . str_replace(' ', '', ucwords(implode(' ', explode('-', $id))));
if (method_exists($this, $methodName)) {
......
......@@ -8,8 +8,7 @@
namespace yii\base;
use Yii;
use yii\di\ContainerInterface;
use yii\di\ContainerTrait;
use yii\di\ServiceLocator;
/**
* Module is the base class for module and application classes.
......@@ -37,10 +36,8 @@ use yii\di\ContainerTrait;
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class Module extends Component implements ContainerInterface
class Module extends ServiceLocator
{
use ContainerTrait;
/**
* @var array custom module parameters (name => value).
*/
......@@ -349,7 +346,7 @@ class Module extends Component implements ContainerInterface
$this->_modules[$id]['class'] = 'yii\base\Module';
}
return $this->_modules[$id] = Yii::createObject($this->_modules[$id], $id, $this);
return $this->_modules[$id] = Yii::createObject($this->_modules[$id], [$id, $this]);
}
}
......@@ -522,7 +519,7 @@ class Module extends Component implements ContainerInterface
return $module->createController($route);
}
if (isset($this->controllerMap[$id])) {
$controller = Yii::createObject($this->controllerMap[$id], $id, $this);
$controller = Yii::createObject($this->controllerMap[$id], [$id, $this]);
return [$controller, $route];
}
......
......@@ -7,23 +7,34 @@
namespace yii\di;
use ReflectionClass;
use yii\base\Component;
use yii\base\InvalidConfigException;
/**
* Container implements a service locator as well as a dependency injection container.
* Container implements a dependency injection (DI) container.
*
* By calling [[set()]] or [[setComponents()]], you can register with the container the components
* that may be later instantiated or accessed via [[get()]].
* A DI container is an object that knows how to instantiate and configure objects and all their dependent objects.
* For more information about DI, please refer to [Martin Fowler's article](http://martinfowler.com/articles/injection.html).
*
* Container mainly implements setter injection. It does not provide automatic constructor injection
* for performance reason. If you want to support constructor injection, you may override [[buildComponent()]].
* Container supports constructor injection as well as property injection.
*
* Below is an example how a container can be used:
* To use Container, you first need to set up the class dependencies by calling [[set()]].
* You then call [[get()]] to create a new class object. Container will automatically instantiate
* dependent objects, inject them into the object being created, configure and finally return the newly created object.
*
* By default, [[\Yii::$container]] refers to a Container instance which is used by [[\Yii::createObject()]]
* to create new object instances. You may use this method to replace the `new` operator
* when creating a new object, which gives you the benefit of automatic dependency resolution and default
* property configuration.
*
* Below is an example of using Container:
*
* ```php
* namespace app\models;
*
* use yii\base\Object;
* use yii\db\Connection;
* use yii\di\Container;
* use yii\di\Instance;
*
......@@ -36,9 +47,10 @@ use yii\base\Component;
* {
* public $db;
*
* public function init()
* public function __construct(Connection $db, $config = [])
* {
* $this->db = Instance::ensure($this->db, 'yii\db\Connection');
* $this->db = $db;
* parent::__construct($config);
* }
*
* public function findUser()
......@@ -50,72 +62,375 @@ use yii\base\Component;
* {
* public $finder;
*
* public function init()
* public function __construct(UserFinderInterface $finder, $config = [])
* {
* $this->finder = Instance::ensure($this->finder, 'app\models\UserFinderInterface');
* $this->finder = $finder;
* parent::__construct($config);
* }
* }
*
* $container = new Container;
* $container->components = [
* 'db' => [
* 'class' => 'yii\db\Connection',
* 'dsn' => '...',
* ],
* 'userFinder' => [
* 'class' => 'app\models\UserFinder',
* 'db' => Instance::of('db', $container),
* ],
* 'userLister' => [
* 'finder' => Instance::of('userFinder', $container),
* ],
* ];
*
* // uses both constructor injection (for UserLister)
* // and setter injection (for UserFinder, via Instance::of('db'))
* $container->set('yii\db\Connection', [
* 'dsn' => '...',
* ]);
* $container->set('app\models\UserFinderInterface', [
* 'class' => 'app\models\UserFinder',
* ]);
* $container->set('userLister', 'app\models\UserLister');
*
* $lister = $container->get('userLister');
*
* // which is equivalent to:
*
* $db = new \yii\db\Connection(['dsn' => '...']);
* $finder = new UserFinder(['db' => $db]);
* $lister = new UserLister(['finder' => $finder);
* $finder = new UserFinder($db);
* $lister = new UserLister($finder);
* ```
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class Container extends Component implements ContainerInterface
class Container extends Component
{
use ContainerTrait;
/**
* @var array singleton objects indexed by their types
*/
private $_singletons = [];
/**
* @var array object definitions indexed by their types
*/
private $_definitions = [];
/**
* @var array constructor parameters indexed by object types
*/
private $_params = [];
/**
* @var array cached ReflectionClass objects indexed by class/interface names
*/
private $_reflections = [];
/**
* @var array cached dependencies indexed by class/interface names. Each class name
* is associated with a list of constructor parameter types or default values.
*/
private $_dependencies = [];
/**
* Getter magic method.
* This method is overridden to support accessing components like reading properties.
* @param string $name component or property name
* @return mixed the named property value
* Returns an instance of the requested class.
*
* You may provide constructor parameters (`$params`) and object configurations (`$config`)
* that will be used during the creation of the instance.
*
* Note that if the class is declared to be singleton by calling [[setSingleton()]],
* the same instance of the class will be returned each time this method is called.
* In this case, the constructor parameters and object configurations will be used
* only if the class is instantiated the first time.
*
* @param string $class the class name or an alias name (e.g. `foo`) that was previously registered via [[set()]]
* or [[setSingleton()]].
* @param array $params a list of constructor parameter values. The parameters should be provided in the order
* they appear in the constructor declaration. If you want to skip some parameters, you should index the remaining
* ones with the integers that represent their positions in the constructor parameter list.
* @param array $config a list of name-value pairs that will be used to initialize the object properties.
* @return object an instance of the requested class.
* @throws InvalidConfigException if the class cannot be recognized or correspond to an invalid definition
*/
public function __get($name)
public function get($class, $params = [], $config = [])
{
if ($this->has($name)) {
return $this->get($name);
if (isset($this->_singletons[$class])) {
// singleton
return $this->_singletons[$class];
} elseif (!isset($this->_definitions[$class])) {
return $this->build($class, $params, $config);
}
$definition = $this->_definitions[$class];
if (is_callable($definition, true)) {
$params = $this->resolveDependencies($this->mergeParams($class, $params));
$object = call_user_func($definition, $params, $config, $this);
} elseif (is_array($definition)) {
$concrete = $definition['class'];
unset($definition['class']);
$config = array_merge($definition, $config);
$params = $this->mergeParams($class, $params);
if ($concrete === $class) {
$object = $this->build($class, $params, $config);
} else {
$object = $this->get($concrete, $params, $config);
}
} elseif (is_object($definition)) {
return $this->_singletons[$class] = $definition;
} else {
return parent::__get($name);
throw new InvalidConfigException("Unexpected object definition type: " . gettype($definition));
}
if (array_key_exists($class, $this->_singletons)) {
// singleton
$this->_singletons[$class] = $object;
}
return $object;
}
/**
* Checks if a property value is null.
* This method overrides the parent implementation by checking if the named component is loaded.
* @param string $name the property name or the event name
* @return boolean whether the property value is null
* Registers a class definition with this container.
*
* For example,
*
* ```php
* // register a class name as is. This can be skipped.
* $container->set('yii\db\Connection');
*
* // register an interface
* // When a class depends on the interface, the corresponding class
* // will be instantiated as the dependent object
* $container->set('yii\mail\MailInterface', 'yii\swiftmailer\Mailer');
*
* // register an alias name. You can use $container->get('foo')
* // to create an instance of Connection
* $container->set('foo', 'yii\db\Connection');
*
* // register a class with configuration. The configuration
* // will be applied when the class is instantiated by get()
* $container->set('yii\db\Connection', [
* 'dsn' => 'mysql:host=127.0.0.1;dbname=demo',
* 'username' => 'root',
* 'password' => '',
* 'charset' => 'utf8',
* ]);
*
* // register an alias name with class configuration
* // In this case, a "class" element is required to specify the class
* $container->set('db', [
* 'class' => 'yii\db\Connection',
* 'dsn' => 'mysql:host=127.0.0.1;dbname=demo',
* 'username' => 'root',
* 'password' => '',
* 'charset' => 'utf8',
* ]);
*
* // register a PHP callable
* // The callable will be executed when $container->get('db') is called
* $container->set('db', function ($params, $config, $container) {
* return new \yii\db\Connection($config);
* });
* ```
*
* If a class definition with the same name already exists, it will be overwritten with the new one.
* You may use [[has()]] to check if a class definition already exists.
*
* @param string $class class name, interface name or alias name
* @param mixed $definition the definition associated with `$class`. It can be one of the followings:
*
* - a PHP callable: The callable will be executed when [[get()]] is invoked. The signature of the callable
* should be `function ($params, $config, $container)`, where `$params` stands for the list of constructor
* parameters, `$config` the object configuration, and `$container` the container object. The return value
* of the callable will be returned by [[get()]] as the object instance requested.
* - a configuration array: the array contains name-value pairs that will be used to initialize the property
* values of the newly created object when [[get()]] is called. The `class` element stands for the
* the class of the object to be created. If `class` is not specified, `$class` will be used as the class name.
* - a string: a class name, an interface name or an alias name.
* @param array $params the list of constructor parameters. The parameters will be passed to the class
* constructor when [[get()]] is called.
* @return static the container itself
*/
public function __isset($name)
public function set($class, $definition = [], array $params = [])
{
if ($this->has($name)) {
return $this->get($name, [], false) !== null;
$this->_definitions[$class] = $this->normalizeDefinition($class, $definition);
$this->_params[$class] = $params;
unset($this->_singletons[$class]);
return $this;
}
/**
* Registers a class definition with this container and marks the class as a singleton class.
*
* This method is similar to [[set()]] except that classes registered via this method will only have one
* instance. Each time [[get()]] is called, the same instance of the specified class will be returned.
*
* @param string $class class name, interface name or alias name
* @param mixed $definition the definition associated with `$class`. See [[set()]] for more details.
* @param array $params the list of constructor parameters. The parameters will be passed to the class
* constructor when [[get()]] is called.
* @return static the container itself
* @see set()
*/
public function setSingleton($class, $definition = [], array $params = [])
{
$this->_definitions[$class] = $this->normalizeDefinition($class, $definition);;
$this->_params[$class] = $params;
$this->_singletons[$class] = null;
return $this;
}
/**
* Returns a value indicating whether the container has the definition of the specified name.
* @param string $class class name, interface name or alias name
* @return boolean whether the container has the definition of the specified name..
* @see set()
*/
public function has($class)
{
return isset($this->_singletons[$class]);
}
/**
* Returns a value indicating whether the given name corresponds to a registered singleton.
* @param string $class class name, interface name or alias name
* @param boolean $checkInstance whether to check if the singleton has been instantiated.
* @return boolean whether the given name corresponds to a registered singleton. If `$checkInstance` is true,
* the method should return a value indicating whether the singleton has been instantiated.
*/
public function hasSingleton($class, $checkInstance = false)
{
return $checkInstance ? isset($this->_singletons[$class]) : array_key_exists($class, $this->_singletons);
}
/**
* Removes the definition for the specified name.
* @param string $class class name, interface name or alias name
*/
public function clear($class)
{
unset($this->_definitions[$class], $this->_singletons[$class]);
}
protected function normalizeDefinition($class, $definition)
{
if (empty($definition)) {
return ['class' => $class];
} elseif (is_string($definition)) {
return ['class' => $definition];
} elseif (is_callable($definition, true) || is_object($definition)) {
return $definition;
} elseif (is_array($definition)) {
if (!isset($definition['class'])) {
$definition['class'] = $class;
}
return $definition;
} else {
throw new InvalidConfigException("Unsupported definition type for \"$class\": " . gettype($definition));
}
}
/**
* Returns the list of the object definitions or the loaded shared objects.
* @return array the list of the object definitions or the loaded shared objects (type or ID => definition or instance).
*/
public function getDefinitions()
{
return $this->_definitions;
}
/**
* Creates an instance of the specified class.
* This method will resolve dependencies of the specified class, instantiate them, and inject
* them into the new instance of the specified class.
* @param string $class the class name
* @param array $params constructor parameters
* @param array $config configurations to be applied to the new instance
* @return object the newly created instance of the specified class
*/
protected function build($class, $params, $config)
{
/** @var ReflectionClass $reflection */
list ($reflection, $dependencies) = $this->getDependencies($class);
foreach ($params as $index => $param) {
$dependencies[$index] = $param;
}
$dependencies = $this->resolveDependencies($dependencies, $reflection);
if (!empty($config) && !empty($dependencies) && is_a($class, 'yii\base\Object', true)) {
// set $config as the last parameter (existing one will be overwritten)
$dependencies[count($dependencies) - 1] = $config;
return $reflection->newInstanceArgs($dependencies);
} else {
$object = $reflection->newInstanceArgs($dependencies);
foreach ($config as $name => $value) {
$object->$name = $value;
}
return $object;
}
}
/**
* Merges the user-specified constructor parameters with the ones registered via [[set()]].
* @param string $class class name, interface name or alias name
* @param array $params the constructor parameters
* @return array the merged parameters
*/
protected function mergeParams($class, $params)
{
if (empty($this->_params[$class])) {
return $params;
} elseif (empty($params)) {
return $this->_params[$class];
} else {
return parent::__isset($name);
$ps = $this->_params[$class];
foreach ($params as $index => $value) {
$ps[$index] = $value;
}
return $ps;
}
}
/**
* Returns the dependencies of the specified class.
* @param string $class class name, interface name or alias name
* @return array the dependencies of the specified class.
*/
protected function getDependencies($class)
{
if (isset($this->_reflections[$class])) {
return [$this->_reflections[$class], $this->_dependencies[$class]];
}
$dependencies = [];
$reflection = new ReflectionClass($class);
$constructor = $reflection->getConstructor();
if ($constructor !== null) {
foreach ($constructor->getParameters() as $param) {
if ($param->isDefaultValueAvailable()) {
$dependencies[] = $param->getDefaultValue();
} else {
$c = $param->getClass();
$dependencies[] = Instance::of($c === null ? null : $c->getName());
}
}
}
$this->_reflections[$class] = $reflection;
$this->_dependencies[$class] = $dependencies;
return [$reflection, $dependencies];
}
/**
* Resolves dependencies by replacing them with the actual object instances.
* @param array $dependencies the dependencies
* @param ReflectionClass $reflection the class reflection associated with the dependencies
* @return array the resolved dependencies
* @throws InvalidConfigException if a dependency cannot be resolved or if a dependency cannot be fulfilled.
*/
protected function resolveDependencies($dependencies, $reflection = null)
{
foreach ($dependencies as $index => $dependency) {
if ($dependency instanceof Instance) {
if ($dependency->id !== null) {
$dependencies[$index] = $this->get($dependency->id);
} elseif ($reflection !== null) {
$name = $reflection->getConstructor()->getParameters()[$index]->getName();
$class = $reflection->getName();
throw new InvalidConfigException("Missing required parameter \"$name\" when instantiating \"$class\".");
}
}
}
return $dependencies;
}
}
......@@ -8,7 +8,7 @@
namespace yii\di;
/**
* ContainerInterface specifies the interface that a dependency injection container should implement.
* ContainerInterface specifies the interface that should be implemented by a dependency inversion (DI) container.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
......@@ -16,92 +16,20 @@ namespace yii\di;
interface ContainerInterface
{
/**
* Returns the list of the component definitions or the loaded shared component instances.
* @param boolean $returnDefinitions whether to return component definitions or the loaded shared component instances.
* @return array the list of the component definitions or the loaded shared component instances (type or ID => definition or instance).
* Returns a value indicating whether the container has the definition for the specified object type.
* @param string $type the object type. Depending on the implementation, this could be a class name, an interface name or an alias.
* @return boolean whether the container has the definition for the specified object.
*/
public function getComponents($returnDefinitions = true);
public function has($type);
/**
* Registers a set of component definitions in this container.
* Returns an instance of the specified object type.
*
* This is the bulk version of [[set()]]. The parameter should be an array
* whose keys are component types or IDs and values the corresponding component definitions.
* If the container is unable to get an instance of the object type, an exception will be thrown.
* To avoid exception, you may use [[has()]] to check if the container has the definition for
* the specified object type.
*
* For more details on how to specify component types/IDs and definitions, please
* refer to [[set()]].
*
* If a component definition with the same type/ID already exists, it will be overwritten.
*
* @param array $components component definitions or instances
*/
public function setComponents($components);
/**
* Returns a value indicating whether the container has the specified component definition or has instantiated the shared component.
* This method may return different results depending on the value of `$checkInstance`.
*
* - If `$checkInstance` is false (default), the method will return a value indicating whether the container has the specified
* component definition.
* - If `$checkInstance` is true, the method will return a value indicating whether the container has
* instantiated the specified shared component.
*
* @param string $typeOrID component type (a fully qualified namespaced class/interface name, e.g. `yii\db\Connection`) or ID (e.g. `db`).
* @param boolean $checkInstance whether the method should check if the component is shared and instantiated.
* @return boolean whether the container has the component definition of the specified type or ID
* @see set()
*/
public function has($typeOrID, $checkInstance = false);
/**
* Returns an instance of a component with the specified type or ID.
*
* If a component is registered as a shared component via [[set()]], this method will return
* the same component instance each time it is called.
* If a component is not shared, this method will create a new instance every time.
*
* @param string $typeOrID component type (a fully qualified namespaced class/interface name, e.g. `yii\db\Connection`) or ID (e.g. `db`).
* @param boolean $throwException whether to throw an exception if `$typeOrID` is not registered with the container before.
* @return object the component of the specified type or ID
* @throws \yii\base\InvalidConfigException if `$typeOrID` refers to a nonexistent component ID
* or if there is cyclic dependency detected
* @see has()
* @see set()
*/
public function get($typeOrID, $throwException = true);
/**
* Registers a component definition with this container.
*
* If a component definition with the same type/ID already exists, it will be overwritten.
*
* @param string $typeOrID component type or ID. This can be in one of the following three formats:
*
* - a fully qualified namespaced class/interface name: e.g. `yii\db\Connection`.
* This declares a shared component. Only a single instance of this class will be created and injected
* into different objects who depend on this class. If this is an interface name, the class name will
* be obtained from `$definition`.
* - a fully qualified namespaced class/interface name prefixed with an asterisk `*`: e.g. `*yii\db\Connection`.
* This declares a non-shared component. That is, if each time the container is injecting a dependency
* of this class, a new instance of this class will be created and used. If this is an interface name,
* the class name will be obtained from `$definition`.
* - an ID: e.g. `db`. This declares a shared component with an ID. The class name should
* be declared in `$definition`. When [[get()]] is called, the same component instance will be returned.
*
* @param mixed $definition the component definition to be registered with this container.
* It can be one of the followings:
*
* - a PHP callable: either an anonymous function or an array representing a class method (e.g. `['Foo', 'bar']`).
* The callable will be called by [[get()]] to return an object associated with the specified component type.
* The signature of the function should be: `function ($container)`, where `$container` is this container.
* - an object: When [[get()]] is called, this object will be returned. No new object will be created.
* This essentially makes the component a shared one, regardless how it is specified in `$typeOrID`.
* - a configuration array: the array contains name-value pairs that will be used to initialize the property
* values of the newly created object when [[get()]] is called. The `class` element stands for the
* the class of the object to be created. If `class` is not specified, `$typeOrID` will be used as the class name.
* - a string: either a class name or a component ID that is registered with this container.
*
* If the parameter is null, the component definition will be removed from the container.
* @param string $type the object type. Depending on the implementation, this could be a class name, an interface name or an alias.
*/
public function set($typeOrID, $definition);
public function get($type);
}
......@@ -55,10 +55,6 @@ use yii\base\InvalidConfigException;
class Instance
{
/**
* @var ContainerInterface the container
*/
public $container;
/**
* @var string the component ID
*/
public $id;
......@@ -66,23 +62,20 @@ class Instance
/**
* Constructor.
* @param string $id the component ID
* @param ContainerInterface $container the container. If null, the application instance will be used.
*/
protected function __construct($id, ContainerInterface $container = null)
protected function __construct($id)
{
$this->id = $id;
$this->container = $container;
}
/**
* Creates a new Instance object.
* @param string $id the component ID
* @param ContainerInterface $container the container. If null, the application instance will be used.
* @return Instance the new Instance object.
*/
public static function of($id, ContainerInterface $container = null)
public static function of($id)
{
return new static($id, $container);
return new static($id);
}
/**
......@@ -111,48 +104,45 @@ class Instance
* @return object
* @throws \yii\base\InvalidConfigException
*/
public static function ensure($value, $type, $container = null)
public static function ensure($value, $type = null, $container = null)
{
if (empty($value)) {
throw new InvalidConfigException('The required component is not specified.');
}
if ($value instanceof $type) {
return $value;
} elseif (is_string($value)) {
$value = new static($value, $container);
} elseif (empty($value)) {
throw new InvalidConfigException('The required component is not specified.');
}
if (is_string($value)) {
$value = new static($value);
}
if ($value instanceof self) {
$component = $value->get();
if ($component instanceof $type) {
$component = $value->get($container);
if ($component instanceof $type || $type === null) {
return $component;
} else {
$container = $value->container ? : Yii::$app;
if ($component === null) {
throw new InvalidConfigException('"' . $value->id . '" is not a valid component ID of ' . get_class($container));
} else {
throw new InvalidConfigException('"' . $value->id . '" refers to a ' . get_class($component) . " component. $type is expected.");
}
throw new InvalidConfigException('"' . $value->id . '" refers to a ' . get_class($component) . " component. $type is expected.");
}
} else {
$valueType = is_object($value) ? get_class($value) : gettype($value);
throw new InvalidConfigException("Invalid data type: $valueType. $type is expected.");
}
$valueType = is_object($value) ? get_class($value) : gettype($value);
throw new InvalidConfigException("Invalid data type: $valueType. $type is expected.");
}
/**
* Returns the actual component referenced by this Instance object.
* @return object the actual component referenced by this Instance object.
* @throws InvalidConfigException there is no container available
*/
public function get()
public function get($container = null)
{
/** @var ContainerInterface $container */
$container = $this->container ? : Yii::$app;
if ($container !== null) {
if ($container) {
return $container->get($this->id);
}
if (Yii::$app && Yii::$app->has($this->id)) {
return Yii::$app->get($this->id);
} else {
throw new InvalidConfigException("Unable to locate a container for component \"{$this->id}\".");
return Yii::$container->get($this->id);
}
}
}
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\di;
use Yii;
use Closure;
use yii\base\Component;
use yii\base\InvalidConfigException;
/**
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class ServiceLocator extends Component
{
/**
* @var array shared component instances indexed by their IDs
*/
private $_components = [];
/**
* @var array component definitions indexed by their IDs
*/
private $_definitions = [];
/**
* Returns a value indicating whether the locator has the specified component definition or has instantiated the component.
* This method may return different results depending on the value of `$checkInstance`.
*
* - If `$checkInstance` is false (default), the method will return a value indicating whether the locator has the specified
* component definition.
* - If `$checkInstance` is true, the method will return a value indicating whether the locator has
* instantiated the specified component.
*
* @param string $id component ID (e.g. `db`).
* @param boolean $checkInstance whether the method should check if the component is shared and instantiated.
* @return boolean whether the locator has the specified component definition or has instantiated the component.
* @see set()
*/
public function has($id, $checkInstance = false)
{
return $checkInstance ? isset($this->_components[$id]) : isset($this->_definitions[$id]);
}
/**
* Returns the component instance with the specified ID.
*
* @param string $id component ID (e.g. `db`).
* @param boolean $throwException whether to throw an exception if `$id` is not registered with the locator before.
* @return object|null the component of the specified ID. If `$throwException` is false and `$id`
* is not registered before, null will be returned.
* @throws InvalidConfigException if `$id` refers to a nonexistent component ID
* @see has()
* @see set()
*/
public function get($id, $throwException = true)
{
if (isset($this->_components[$id])) {
return $this->_components[$id];
}
if (isset($this->_definitions[$id])) {
$definition = $this->_definitions[$id];
if (is_object($definition) && !$definition instanceof Closure) {
return $this->_components[$id] = $definition;
} else {
return $this->_components[$id] = Yii::createObject($definition);
}
} elseif ($throwException) {
throw new InvalidConfigException("Unknown component ID: $id");
} else {
return null;
}
}
/**
* Registers a component definition with this locator.
*
* For example,
*
* ```php
* // via configuration array
* $locator->set('db', [
* 'class' => 'yii\db\Connection',
* 'dsn' => '...',
* ]);
*
* // via anonymous function
* $locator->set('db', function ($locator) {
* return new \yii\db\Connection;
* });
* ```
*
* If a component definition with the same ID already exists, it will be overwritten.
*
* If `$definition` is null, the previously registered component definition will be removed.
*
* @param string $id component ID (e.g. `db`).
* @param mixed $definition the component definition to be registered with this locator.
* It can be one of the followings:
*
* - a PHP callable: either an anonymous function or an array representing a class method (e.g. `['Foo', 'bar']`).
* The callable will be called by [[get()]] to return an object associated with the specified component ID.
* The signature of the function should be: `function ($locator)`, where `$locator` is this locator.
* - an object: When [[get()]] is called, this object will be returned.
* - a configuration array or a class name: the array contains name-value pairs that will be used to
* initialize the property values of the newly created object when [[get()]] is called.
* The `class` element stands for the the class of the object to be created.
*
* @throws InvalidConfigException if the definition is an invalid configuration array
*/
public function set($id, $definition)
{
if ($definition === null) {
unset($this->_components[$id], $this->_definitions[$id]);
return;
}
if (is_object($definition) || is_callable($definition, true)) {
// an object, a class name, or a PHP callable
$this->_definitions[$id] = $definition;
} elseif (is_array($definition)) {
// a configuration array
if (isset($definition['class'])) {
$this->_definitions[$id] = $definition;
} else {
throw new InvalidConfigException("The configuration for the \"$id\" component must contain a \"class\" element.");
}
} else {
throw new InvalidConfigException("Unexpected configuration type for the \"$id\" component: " . gettype($definition));
}
}
/**
* Returns the list of the component definitions or the loaded component instances.
* @param boolean $returnDefinitions whether to return component definitions or the loaded component instances.
* @return array the list of the component definitions or the loaded component instances (ID => definition or instance).
*/
public function getComponents($returnDefinitions = true)
{
return $returnDefinitions ? $this->_definitions : $this->_components;
}
/**
* Registers a set of component definitions in this locator.
*
* This is the bulk version of [[set()]]. The parameter should be an array
* whose keys are component IDs and values the corresponding component definitions.
*
* For more details on how to specify component IDs and definitions, please refer to [[set()]].
*
* If a component definition with the same ID already exists, it will be overwritten.
*
* The following is an example for registering two component definitions:
*
* ~~~
* [
* 'db' => [
* 'class' => 'yii\db\Connection',
* 'dsn' => 'sqlite:path/to/file.db',
* ],
* 'cache' => [
* 'class' => 'yii\caching\DbCache',
* 'db' => 'db',
* ],
* ]
* ~~~
*
* @param array $components component definitions or instances
*/
public function setComponents($components)
{
foreach ($components as $id => $component) {
$this->set($id, $component);
}
}
}
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\di;
use Yii;
use Closure;
use yii\base\InvalidConfigException;
/**
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
trait ServiceLocatorTrait
{
/**
* @var array shared component instances indexed by their IDs
*/
private $_components = [];
/**
* @var array component definitions indexed by their IDs
*/
private $_definitions = [];
/**
* Returns a value indicating whether the locator has the specified component definition or has instantiated the component.
* This method may return different results depending on the value of `$checkInstance`.
*
* - If `$checkInstance` is false (default), the method will return a value indicating whether the locator has the specified
* component definition.
* - If `$checkInstance` is true, the method will return a value indicating whether the locator has
* instantiated the specified component.
*
* @param string $id component ID (e.g. `db`).
* @param boolean $checkInstance whether the method should check if the component is shared and instantiated.
* @return boolean whether the locator has the specified component definition or has instantiated the component.
* @see set()
*/
public function has($id, $checkInstance = false)
{
return $checkInstance ? isset($this->_components[$id]) : isset($this->_definitions[$id]);
}
/**
* Returns the component instance with the specified ID.
*
* @param string $id component ID (e.g. `db`).
* @param boolean $throwException whether to throw an exception if `$id` is not registered with the locator before.
* @return object|null the component of the specified ID. If `$throwException` is false and `$id`
* is not registered before, null will be returned.
* @throws InvalidConfigException if `$id` refers to a nonexistent component ID
* @see has()
* @see set()
*/
public function get($id, $throwException = true)
{
if (isset($this->_components[$id])) {
return $this->_components[$id];
}
if (isset($this->_definitions[$id])) {
$definition = $this->_definitions[$id];
if (is_object($definition) && !$definition instanceof Closure) {
return $this->_components[$id] = $definition;
} else {
return $this->_components[$id] = Yii::createObject($definition);
}
} elseif ($throwException) {
throw new InvalidConfigException("Unknown component ID: $id");
} else {
return null;
}
}
/**
* Registers a component definition with this locator.
*
* For example,
*
* ```php
* // via configuration array
* $locator->set('db', [
* 'class' => 'yii\db\Connection',
* 'dsn' => '...',
* ]);
*
* // via anonymous function
* $locator->set('db', function ($locator) {
* return new \yii\db\Connection;
* });
* ```
*
* If a component definition with the same ID already exists, it will be overwritten.
*
* If `$definition` is null, the previously registered component definition will be removed.
*
* @param string $id component ID (e.g. `db`).
* @param mixed $definition the component definition to be registered with this locator.
* It can be one of the followings:
*
* - a PHP callable: either an anonymous function or an array representing a class method (e.g. `['Foo', 'bar']`).
* The callable will be called by [[get()]] to return an object associated with the specified component ID.
* The signature of the function should be: `function ($locator)`, where `$locator` is this locator.
* - an object: When [[get()]] is called, this object will be returned.
* - a configuration array or a class name: the array contains name-value pairs that will be used to
* initialize the property values of the newly created object when [[get()]] is called.
* The `class` element stands for the the class of the object to be created.
*
* @throws InvalidConfigException if the definition is an invalid configuration array
*/
public function set($id, $definition)
{
if ($definition === null) {
unset($this->_components[$id], $this->_definitions[$id]);
return;
}
if (is_object($definition) || is_callable($definition, true)) {
// an object, a class name, or a PHP callable
$this->_definitions[$id] = $definition;
} elseif (is_array($definition)) {
// a configuration array
if (isset($definition['class'])) {
$this->_definitions[$id] = $definition;
} else {
throw new InvalidConfigException("The configuration for the \"$id\" component must contain a \"class\" element.");
}
} else {
throw new InvalidConfigException("Unexpected configuration type for the \"$id\" component: " . gettype($definition));
}
}
/**
* Returns the list of the component definitions or the loaded component instances.
* @param boolean $returnDefinitions whether to return component definitions or the loaded component instances.
* @return array the list of the component definitions or the loaded component instances (ID => definition or instance).
*/
public function getComponents($returnDefinitions = true)
{
return $returnDefinitions ? $this->_definitions : $this->_components;
}
/**
* Registers a set of component definitions in this locator.
*
* This is the bulk version of [[set()]]. The parameter should be an array
* whose keys are component IDs and values the corresponding component definitions.
*
* For more details on how to specify component IDs and definitions, please refer to [[set()]].
*
* If a component definition with the same ID already exists, it will be overwritten.
*
* The following is an example for registering two component definitions:
*
* ~~~
* [
* 'db' => [
* 'class' => 'yii\db\Connection',
* 'dsn' => 'sqlite:path/to/file.db',
* ],
* 'cache' => [
* 'class' => 'yii\caching\DbCache',
* 'db' => 'db',
* ],
* ]
* ~~~
*
* @param array $components component definitions or instances
*/
public function setComponents($components)
{
foreach ($components as $id => $component) {
$this->set($id, $component);
}
}
}
......@@ -7,24 +7,13 @@
namespace yiiunit\framework\di;
use yii\base\Object;
use yii\di\Container;
use yii\di\Instance;
use yiiunit\framework\di\stubs\Bar;
use yiiunit\framework\di\stubs\Foo;
use yiiunit\framework\di\stubs\Qux;
use yiiunit\TestCase;
class Creator
{
public static function create($type, $container)
{
return new $type;
}
}
class TestClass extends Object
{
public $prop1 = 1;
public $prop2;
}
/**
* @author Qiang Xue <qiang.xue@gmail.com>
......@@ -34,118 +23,62 @@ class ContainerTest extends TestCase
{
public function testDefault()
{
// without configuring anything
$container = new Container;
$className = TestClass::className();
$object = $container->get($className);
$this->assertEquals(1, $object->prop1);
$this->assertTrue($object instanceof $className);
// check non-shared
$object2 = $container->get($className);
$this->assertTrue($object2 instanceof $className);
$this->assertTrue($object !== $object2);
}
public function testCallable()
{
// anonymous function
$container = new Container;
$className = TestClass::className();
$container->set($className, function ($type) {
return new $type([
'prop1' => 100,
'prop2' => 200,
]);
});
$object = $container->get($className);
$this->assertTrue($object instanceof $className);
$this->assertEquals(100, $object->prop1);
$this->assertEquals(200, $object->prop2);
// static method
$container = new Container;
$className = TestClass::className();
$container->set($className, [__NAMESPACE__ . "\\Creator", 'create']);
$object = $container->get($className);
$this->assertTrue($object instanceof $className);
$this->assertEquals(1, $object->prop1);
$this->assertNull($object->prop2);
}
public function testObject()
{
$object = new TestClass;
$className = TestClass::className();
$container = new Container;
$container->set($className, $object);
$this->assertTrue($container->get($className) === $object);
}
$namespace = __NAMESPACE__ . '\stubs';
$QuxInterface = "$namespace\\QuxInterface";
$Foo = Foo::className();
$Bar = Bar::className();
$Qux = Qux::className();
public function testString()
{
$object = new TestClass;
$className = TestClass::className();
// automatic wiring
$container = new Container;
$container->set('test', $object);
$container->set($className, 'test');
$this->assertTrue($container->get($className) === $object);
}
$container->set($QuxInterface, $Qux);
$foo = $container->get($Foo);
$this->assertTrue($foo instanceof $Foo);
$this->assertTrue($foo->bar instanceof $Bar);
$this->assertTrue($foo->bar->qux instanceof $Qux);
public function testShared()
{
// with configuration: shared
// full wiring
$container = new Container;
$className = TestClass::className();
$container->set($className, [
'prop1' => 10,
'prop2' => 20,
]);
$object = $container->get($className);
$this->assertEquals(10, $object->prop1);
$this->assertEquals(20, $object->prop2);
$this->assertTrue($object instanceof $className);
// check shared
$object2 = $container->get($className);
$this->assertTrue($object2 instanceof $className);
$this->assertTrue($object === $object2);
}
$container->set($QuxInterface, $Qux);
$container->set($Bar);
$container->set($Qux);
$container->set($Foo);
$foo = $container->get($Foo);
$this->assertTrue($foo instanceof $Foo);
$this->assertTrue($foo->bar instanceof $Bar);
$this->assertTrue($foo->bar->qux instanceof $Qux);
public function testNonShared()
{
// with configuration: non-shared
// wiring by closure
$container = new Container;
$className = TestClass::className();
$container->set('*' . $className, [
'prop1' => 10,
'prop2' => 20,
]);
$object = $container->get($className);
$this->assertEquals(10, $object->prop1);
$this->assertEquals(20, $object->prop2);
$this->assertTrue($object instanceof $className);
// check non-shared
$object2 = $container->get($className);
$this->assertTrue($object2 instanceof $className);
$this->assertTrue($object !== $object2);
$container->set('foo', function () {
$qux = new Qux;
$bar = new Bar($qux);
return new Foo($bar);
});
$foo = $container->get('foo');
$this->assertTrue($foo instanceof $Foo);
$this->assertTrue($foo->bar instanceof $Bar);
$this->assertTrue($foo->bar->qux instanceof $Qux);
// shared as non-shared
$object = new TestClass;
$className = TestClass::className();
// wiring by closure which uses container
$container = new Container;
$container->set('*' . $className, $object);
$this->assertTrue($container->get($className) === $object);
}
$container->set($QuxInterface, $Qux);
$container->set('foo', function ($params, $config, Container $c) {
return $c->get(Foo::className());
});
$foo = $container->get('foo');
$this->assertTrue($foo instanceof $Foo);
$this->assertTrue($foo->bar instanceof $Bar);
$this->assertTrue($foo->bar->qux instanceof $Qux);
public function testRegisterByID()
{
$className = TestClass::className();
// predefined constructor parameters
$container = new Container;
$container->set('test', [
'class' => $className,
'prop1' => 100,
]);
$object = $container->get('test');
$this->assertTrue($object instanceof TestClass);
$this->assertEquals(100, $object->prop1);
$container->set('foo', $Foo, [Instance::of('bar')]);
$container->set('bar', $Bar, [Instance::of('qux')]);
$container->set('qux', $Qux);
$foo = $container->get('foo');
$this->assertTrue($foo instanceof $Foo);
$this->assertTrue($foo->bar instanceof $Bar);
$this->assertTrue($foo->bar->qux instanceof $Qux);
}
}
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yiiunit\framework\di;
use yii\base\Object;
use yii\di\Container;
use yiiunit\TestCase;
class Creator
{
public static function create($type, $container)
{
return new $type;
}
}
class TestClass extends Object
{
public $prop1 = 1;
public $prop2;
}
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class ServiceLocatorTest extends TestCase
{
public function testDefault()
{
// without configuring anything
$container = new Container;
$className = TestClass::className();
$object = $container->get($className);
$this->assertEquals(1, $object->prop1);
$this->assertTrue($object instanceof $className);
// check non-shared
$object2 = $container->get($className);
$this->assertTrue($object2 instanceof $className);
$this->assertTrue($object !== $object2);
}
public function testCallable()
{
// anonymous function
$container = new Container;
$className = TestClass::className();
$container->set($className, function ($type) {
return new $type([
'prop1' => 100,
'prop2' => 200,
]);
});
$object = $container->get($className);
$this->assertTrue($object instanceof $className);
$this->assertEquals(100, $object->prop1);
$this->assertEquals(200, $object->prop2);
// static method
$container = new Container;
$className = TestClass::className();
$container->set($className, [__NAMESPACE__ . "\\Creator", 'create']);
$object = $container->get($className);
$this->assertTrue($object instanceof $className);
$this->assertEquals(1, $object->prop1);
$this->assertNull($object->prop2);
}
public function testObject()
{
$object = new TestClass;
$className = TestClass::className();
$container = new Container;
$container->set($className, $object);
$this->assertTrue($container->get($className) === $object);
}
public function testString()
{
$object = new TestClass;
$className = TestClass::className();
$container = new Container;
$container->set('test', $object);
$container->set($className, 'test');
$this->assertTrue($container->get($className) === $object);
}
public function testShared()
{
// with configuration: shared
$container = new Container;
$className = TestClass::className();
$container->set($className, [
'prop1' => 10,
'prop2' => 20,
]);
$object = $container->get($className);
$this->assertEquals(10, $object->prop1);
$this->assertEquals(20, $object->prop2);
$this->assertTrue($object instanceof $className);
// check shared
$object2 = $container->get($className);
$this->assertTrue($object2 instanceof $className);
$this->assertTrue($object === $object2);
}
public function testNonShared()
{
// with configuration: non-shared
$container = new Container;
$className = TestClass::className();
$container->set('*' . $className, [
'prop1' => 10,
'prop2' => 20,
]);
$object = $container->get($className);
$this->assertEquals(10, $object->prop1);
$this->assertEquals(20, $object->prop2);
$this->assertTrue($object instanceof $className);
// check non-shared
$object2 = $container->get($className);
$this->assertTrue($object2 instanceof $className);
$this->assertTrue($object !== $object2);
// shared as non-shared
$object = new TestClass;
$className = TestClass::className();
$container = new Container;
$container->set('*' . $className, $object);
$this->assertTrue($container->get($className) === $object);
}
public function testRegisterByID()
{
$className = TestClass::className();
$container = new Container;
$container->set('test', [
'class' => $className,
'prop1' => 100,
]);
$object = $container->get('test');
$this->assertTrue($object instanceof TestClass);
$this->assertEquals(100, $object->prop1);
}
}
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yiiunit\framework\di\stubs;
use yii\base\Object;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class Bar extends Object
{
public $qux;
public function __construct(QuxInterface $qux, $config = [])
{
$this->qux = $qux;
parent::__construct($config);
}
}
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yiiunit\framework\di\stubs;
use yii\base\Object;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class Foo extends Object
{
public $bar;
public function __construct(Bar $bar, $config = [])
{
$this->bar = $bar;
parent::__construct($config);
}
}
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yiiunit\framework\di\stubs;
use yii\base\Object;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class Qux extends Object implements QuxInterface
{
public $a;
public function __construct($a = 1, $config = [])
{
$this->a = $a;
parent::__construct($config);
}
public function quxMethod()
{
}
}
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yiiunit\framework\di\stubs;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
interface QuxInterface
{
function quxMethod();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment