50 if (array_key_exists(
$name, $this->cache)) {
51 return $this->cache[
$name];
53 if (!isset($this->factories[
$name])) {
56 $value = $this->
build($this->factories[$name][
'callable'], $name);
60 if (!empty($this->factories[$name]) && $this->factories[$name][
'shared']) {
75 if (is_callable($factory)) {
76 return call_user_func($factory, $this);
78 $msg =
"Factory for '$name' was uncallable";
79 if (is_string($factory)) {
80 $msg .=
": '$factory'";
81 } elseif (is_array($factory)) {
82 if (is_string($factory[0])) {
83 $msg .=
": '{$factory[0]}::{$factory[1]}'";
85 $msg .=
": " . get_class($factory[0]) .
"->{$factory[1]}";
100 $this->
remove(
$name);
115 if (!is_callable($callable,
true)) {
116 throw new InvalidArgumentException(
'$factory must appear callable');
118 $this->
remove(
$name);
119 $this->factories[
$name] = array(
120 'callable' => $callable,
136 $classname_pattern = version_compare(PHP_VERSION,
'5.3',
'<') ? self::CLASS_NAME_PATTERN_52 : self::CLASS_NAME_PATTERN_53;
137 if (!is_string($class_name) || !preg_match($classname_pattern, $class_name)) {
138 throw new InvalidArgumentException(
'Class names must be valid PHP class names');
140 $func = create_function(
'',
"return new $class_name();");
151 unset($this->cache[
$name]);
152 unset($this->factories[$name]);
163 return isset($this->factories[
$name]) || array_key_exists($name, $this->cache);
const CLASS_NAME_PATTERN_53
setFactory($name, $callable, $shared=true)
Set a factory to generate a value when the container is read.
has($name)
Does the container have this value.
if($guid==elgg_get_logged_in_user_guid()) $name
setClassName($name, $class_name, $shared=true)
Set a factory based on instantiating a class with no arguments.
__get($name)
Fetch a value.
const CLASS_NAME_PATTERN_52
build($factory, $name)
Build a value.
setValue($name, $value)
Set a value to be returned without modification.