Beispiel #1
0
 /**
  * Populates this template from an XML source.
  *
  * @param DocBlox_Transformer $transformer The transformer which is parent.
  * @param string              $xml         The XML definition for this template.
  *
  * @return void
  */
 public function populate(DocBlox_Transformer $transformer, $xml)
 {
     $xml = new SimpleXMLElement($xml);
     $this->author = $xml->author;
     $this->version = $xml->version;
     $this->copyright = $xml->copyright;
     foreach ($xml->transformations->transformation as $transformation) {
         $transformation_obj = new DocBlox_Transformer_Transformation($transformer, (string) $transformation['query'], (string) $transformation['writer'], (string) $transformation['source'], (string) $transformation['artifact']);
         if (isset($transformation['parameters']) && count($transformation['parameters'])) {
             $transformation_obj->setParameters($transformation['parameters']);
         }
         $this->transformations[] = $transformation_obj;
     }
 }
Beispiel #2
0
 /**
  * Adds the given transformation to the transformer for execution.
  *
  * It is also allowed to pass an array notation for the transformation; then this method will create
  * a transformation object out of it.
  *
  * The structure for this array must be:
  * array(
  *   'query'        => <query>,
  *   'writer'       => <writer>,
  *   'source'       => <source>,
  *   'artifact'     => <artifact>,
  *   'parameters'   => array(<parameters>),
  *   'dependencies' => array(<dependencies>)
  * )
  *
  * @param Transformation|array $transformation
  *
  * @return void
  */
 public function addTransformation($transformation)
 {
     if (is_array($transformation)) {
         // check if all required items are present
         if (!key_exists('query', $transformation) || !key_exists('writer', $transformation) || !key_exists('source', $transformation) || !key_exists('artifact', $transformation)) {
             throw new InvalidArgumentException('Transformation array is missing elements, received: ' . var_export($transformation, true));
         }
         $transformation_obj = new DocBlox_Transformer_Transformation($this, $transformation['query'], $transformation['writer'], $transformation['source'], $transformation['artifact']);
         if (isset($transformation['parameters']) && is_array($transformation['parameters'])) {
             $transformation_obj->setParameters($transformation['parameters']);
         }
         $transformation = $transformation_obj;
     }
     // if it is still not an object; fail
     if (!is_object($transformation)) {
         throw new InvalidArgumentException('Only transformations of type (or descended from) DocBlox_Transformer_Transformation can be used in the ' . 'transformation process; received: ' . gettype($transformation));
     }
     // if the object is not a DocBlox_Transformer_Transformation; we cannot use it
     if (!$transformation instanceof DocBlox_Transformer_Transformation) {
         throw new InvalidArgumentException('Only transformations of type (or descended from) DocBlox_Transformer_Transformation can be used in the ' . 'transformation process; received: ' . get_class($transformation));
     }
     $this->transformations[] = $transformation;
 }
 public static function createFromArray(DocBlox_Transformer $transformer, array $transformation)
 {
     // check if all required items are present
     if (!key_exists('query', $transformation) || !key_exists('writer', $transformation) || !key_exists('source', $transformation) || !key_exists('artifact', $transformation)) {
         throw new InvalidArgumentException('Transformation array is missing elements, received: ' . var_export($transformation, true));
     }
     $transformation_obj = new DocBlox_Transformer_Transformation($transformer, $transformation['query'], $transformation['writer'], $transformation['source'], $transformation['artifact']);
     if (isset($transformation['parameters']) && is_array($transformation['parameters'])) {
         $transformation_obj->setParameters($transformation['parameters']);
     }
     return $transformation_obj;
 }