/** * Internal function called from @see load to generate a string representation of component method. */ protected function generateComponent(Dispenser_Element_Component $component) { $methods = $component->getMethods(); $arguments = $component->getArguments(); if ($component->isShared() === true) { $this->variables[] = "\tprivate \$" . $component->getId() . ";"; } $methodString = "\t/**\n" . "\t* @return " . $component->getClass() . "\n" . "\t*/ \n" . "\tpublic function get" . $component->getId() . "() { \n"; $instantiationTabs = "\t\t"; if ($component->isShared() === true) { $methodString .= ' if($this->' . $component->getId() . " == null) { \n"; $instantiationTabs = "\t\t\t"; } if ($component->hasFactory() === true) { $factory = $component->getFactory(); $methodString .= $instantiationTabs . '$instance = ' . $factory->getClass() . '::' . $factory->getMethod() . "("; } else { $methodString .= $instantiationTabs . '$instance = new ' . $component->getClass() . '('; } if (empty($arguments) === false) { $arguments = $this->getParsedArguments($arguments); $methodString .= implode(", ", $arguments); } $methodString .= ");\n"; $methods = $component->getMethods(); if (empty($methods) === false) { foreach ($methods as $method) { $methodString .= $instantiationTabs . '$instance->' . $method->getMethod() . '('; $arguments = $method->getArguments(); if (empty($arguments) === false) { $arguments = $this->getParsedArguments($arguments); $methodString .= implode(", ", $arguments); } $methodString .= "); \n"; } } if ($component->isShared() === true) { $methodString .= $instantiationTabs . '$this->' . $component->getId() . ' = $instance;' . "\n"; $methodString .= "\t\t} \n\n"; $methodString .= ' return $this->' . $component->getId() . ';' . "\n"; } else { $methodString .= ' return $instance;' . "\n"; } $methodString .= "\t}\n"; $this->methods[] = $methodString; }
/** * Internal function called from @see load to generate a array representation of component method. */ protected function generateComponent(Dispenser_Element_Component $component) { $componentArray = array(); $methods = $component->getMethods(); $arguments = $component->getArguments(); $componentArray[self::DISPENSER_CLASS] = $component->getClass(); if (empty($arguments) === false) { $componentArray[self::DISPENSER_ARGUMENTS] = $this->getParsedArguments($arguments); } $methods = $component->getMethods(); if (empty($methods) === false) { $componentArray[self::DISPENSER_METHODS] = array(); foreach ($methods as $method) { $arguments = $method->getArguments(); if (empty($arguments) === false) { $arguments = $this->getParsedArguments($arguments); } $componentArray[self::DISPENSER_METHODS][$method->getMethod()] = $arguments; } } if ($component->isShared() === true) { $componentArray[self::DISPENSER_SHARED] = "true"; } if ($component->hasFactory() === true) { $factory = $component->getFactory(); $componentArray[self::DISPENSER_FACTORY] = array(self::DISPENSER_CLASS => $factory->getClass(), self::DISPENSER_METHOD => $factory->getMethod()); } return $componentArray; }