コード例 #1
0
ファイル: Array.php プロジェクト: simensan/dispenser
 /**
  * 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;
 }
コード例 #2
0
ファイル: Native.php プロジェクト: simensan/dispenser
 /**
  * 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;
 }
コード例 #3
0
ファイル: ComponentTest.php プロジェクト: simensan/dispenser
 /**
  * @depends testSetShared
  */
 public function testIsShared($component)
 {
     $this->component->setShared(false);
     $this->assertFalse($this->component->isShared());
     $this->assertTrue($component->isShared());
 }
コード例 #4
0
ファイル: Xml.php プロジェクト: simensan/dispenser
 /**
  * Parses a xml component node.
  *
  * @param  SimpleXMLElement $componentNode
  */
 protected function parseComponent($componentNode)
 {
     if (isset($componentNode[self::DISPENSER_ID]) === false) {
         throw new Dispenser_Exception("Id must be set in component definition.");
     }
     if (isset($componentNode[self::DISPENSER_CLASS]) === false) {
         throw new Dispenser_Exception("Class must be set in component definition.");
     }
     $id = (string) $componentNode[self::DISPENSER_ID];
     $component = new Dispenser_Element_Component($id);
     $component->setClass((string) $componentNode[self::DISPENSER_CLASS]);
     if (isset($componentNode[self::DISPENSER_SHARED])) {
         $component->setShared((string) $componentNode[self::DISPENSER_SHARED]);
     }
     if (isset($componentNode->factory) === true) {
         $component->setFactory($this->parseFactory($componentNode->factory));
     }
     if (isset($componentNode->arguments) === true) {
         $component->addArguments($this->parseArguments($componentNode->arguments));
     }
     if (isset($componentNode->methods) === true) {
         $component->addMethods($this->parseMethods($componentNode->methods));
     }
     $this->components[$id] = $component;
 }
コード例 #5
0
ファイル: Array.php プロジェクト: simensan/dispenser
 /**
  * Parses passed array.  
  *
  */
 protected function parse()
 {
     if (is_array($this->array) === false) {
         throw new Dispenser_Exception("Passed argument is not an array.");
     }
     foreach ($this->array as $id => $componentItem) {
         if (is_array($componentItem) === false) {
             throw new Dispenser_Exception("Passed array is malformed, component definition is not an array.");
         }
         if (isset($componentItem[self::DISPENSER_CLASS]) === false) {
             throw new Dispenser_Exception("Class must be set in component definition.");
         }
         $component = new Dispenser_Element_Component($id);
         $component->setClass($componentItem[self::DISPENSER_CLASS]);
         unset($componentItem[self::DISPENSER_CLASS]);
         if (isset($componentItem[self::DISPENSER_SHARED])) {
             $component->setShared($componentItem[self::DISPENSER_SHARED]);
             unset($componentItem[self::DISPENSER_SHARED]);
         }
         if (isset($componentItem[self::DISPENSER_FACTORY])) {
             $component->setFactory($this->parseFactory($componentItem[self::DISPENSER_FACTORY]));
             unset($componentItem[self::DISPENSER_FACTORY]);
         }
         if (isset($componentItem[self::DISPENSER_METHODS])) {
             $component->addMethods($this->parseMethods($componentItem[self::DISPENSER_METHODS]));
             unset($componentItem[self::DISPENSER_METHODS]);
         }
         if (isset($componentItem[self::DISPENSER_ARGUMENTS])) {
             $component->addArguments($this->parseArguments($componentItem[self::DISPENSER_ARGUMENTS]));
             unset($componentItem[self::DISPENSER_ARGUMENTS]);
         }
         if (empty($componentItem) === false) {
             $unknownKeys = array();
             foreach ($componentItem as $key => $value) {
                 $unknownKeys[] = $key;
             }
             throw new Dispenser_Exception("Unknown keys: (" . implode(", ", $unknownKeys) . ")");
         }
         $this->components[$id] = $component;
     }
 }