21 public function item($type,$id){
22 \Rsi\Record::add($this->_entities,$type,[]);
23 if($id && array_key_exists($id,$this->_entities[$type]))
return $this->_entities[$type][$id];
24 $this->
component(
'log')->debug(
"Creating entity $type:$id",__FILE__,__LINE__);
25 $reflect = new \ReflectionClass($this->classNames[$type] ?? $this->defaultNamespace .
'\\' . ucfirst($type));
26 $params = func_get_args();
28 return $this->_entities[$type][$id] = $reflect->newInstanceArgs($params);
36 public function has($type,$id){
37 return array_key_exists($type,$this->_entities) && array_key_exists($id,$this->_entities[$type]);
44 public function flush($type = null,$id = null){
45 $this->
component(
'log')->debug(__CLASS__ .
"::flush($type" . ($id ?
",$id" :
'') .
')',__FILE__,__LINE__);
46 if($id) unset($this->_entities[$type][$id]);
47 elseif($type) unset($this->_entities[$type]);
48 else $this->_entities = [];
51 public function __call($func_name,$params){
52 return call_user_func_array([$this,
'item'],array_merge([$func_name],$params));
56 return $this->
item($type,$id);
$defaultNamespace
Namespace to look for an item class (ucfirst(id)) when not found in classNames.
item($type, $id)
Retrieve an entity, or create a new if nonexistence.
flush($type=null, $id=null)
Flush entities.
Entity manager component.
__call($func_name, $params)
has($type, $id)
Check if an entity already exists.
$classNames
Classnames for item types (key = type, value = class name).
component($name)
Get a component (local or default).