Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 /**
  * 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;
     }
 }