protected function getImplementation($type) { if (!isset($this->implementations)) { $this->implementations['Array'] = array('itemGetter' => array('return array_key_exists($key, $this->%collection%) ? $this->%collection%[$key] : NULL;'), 'itemAdder' => array('$this->%collection%[] = $%item%;', 'return $this;'), 'itemChecker' => array('return in_array($%item%, $this->%collection%);'), 'itemRemover' => array('if (($key = array_search($%item%, $this->%collection%, %strict%)) !== FALSE) {', ' array_splice($this->%collection%, $key, 1);', '}', 'return $this;')); $this->implementations['Collection'] = array('itemGetter' => array('return $this->%collection%->containsKey($key, $this->%collection%) ? $this->%collection%->get($key) : NULL;'), 'itemAdder' => array('$this->%collection%->add($%item%);', 'return $this;'), 'itemChecker' => array('return $this->%collection%->contains($%item%);'), 'itemRemover' => array('if ($this->contains($%item%)) {', ' $this->removeElement($%item%);', '}', 'return $this;')); } $vars = $this->codeVars; $code = array_map(function ($line) use($vars) { return \Psc\TPL\TPL::miniTemplate($line, $vars); }, $this->implementations[$this->collectionType->getName()][$type]); return $code; }
public function getName() { return $this->type->getName(); }