Exemple #1
0
 /**
  * Create a new Action;
  *
  * @return Action
  * @author Matthias Bilger
  */
 public static function createAction(CFDictionary $action)
 {
     $actionname = $action->get('WFWorkflowActionIdentifier')->getValue();
     $actionname = str_replace('is.workflow.actions.', '', $actionname);
     $actionname = str_replace('.', ' ', $actionname);
     $actionname = ucwords($actionname);
     return new self($actionname, $action->get('WFWorkflowActionParameters'));
 }
 /**
  * Convert a DOMNode into a CFType.
  * @param DOMNode $node Node to import children of
  * @param CFDictionary|CFArray|CFPropertyList $parent
  * @return void
  */
 protected function import(DOMNode $node, $parent)
 {
     // abort if there are no children
     if (!$node->childNodes->length) {
         return;
     }
     foreach ($node->childNodes as $n) {
         // skip if we can't handle the element
         if (!isset(self::$types[$n->nodeName])) {
             continue;
         }
         $class = 'CFPropertyList\\' . self::$types[$n->nodeName];
         $key = null;
         // find previous <key> if possible
         $ps = $n->previousSibling;
         while ($ps && $ps->nodeName == '#text' && $ps->previousSibling) {
             $ps = $ps->previousSibling;
         }
         // read <key> if possible
         if ($ps && $ps->nodeName == 'key') {
             $key = $ps->firstChild->nodeValue;
         }
         switch ($n->nodeName) {
             case 'date':
                 $value = new $class(CFDate::dateValue($n->nodeValue));
                 break;
             case 'data':
                 $value = new $class($n->nodeValue, true);
                 break;
             case 'string':
                 $value = new $class($n->nodeValue);
                 break;
             case 'real':
             case 'integer':
                 $value = new $class($n->nodeName == 'real' ? floatval($n->nodeValue) : intval($n->nodeValue));
                 break;
             case 'true':
             case 'false':
                 $value = new $class($n->nodeName == 'true');
                 break;
             case 'array':
             case 'dict':
                 $value = new $class();
                 $this->import($n, $value);
                 if ($value instanceof CFDictionary) {
                     $hsh = $value->getValue();
                     if (isset($hsh['CF$UID']) && count($hsh) == 1) {
                         $value = new CFUid($hsh['CF$UID']->getValue());
                     }
                 }
                 break;
         }
         // Dictionaries need a key
         if ($parent instanceof CFDictionary) {
             $parent->add($key, $value);
         } else {
             $parent->add($value);
         }
     }
 }
 /**
  * Create CFType-structure by guessing the data-types.
  * {@link CFArray}, {@link CFDictionary}, {@link CFBoolean}, {@link CFNumber} and {@link CFString} can be created, {@link CFDate} and {@link CFData} cannot.
  * <br /><b>Note:</b>Distinguishing between {@link CFArray} and {@link CFDictionary} is done by examining the keys. 
  * Keys must be strictly incrementing integers to evaluate to a {@link CFArray}. 
  * Since PHP does not offer a function to test for associative arrays, 
  * this test causes the input array to be walked twice and thus work rather slow on large collections. 
  * If you work with large arrays and can live with all arrays evaluating to {@link CFDictionary}, 
  * feel free to set the appropriate flag.
  * <br /><b>Note:</b> If $value is an instance of CFType it is simply returned.
  * <br /><b>Note:</b> If $value is neither a CFType, array, numeric, boolean nor string, it is omitted.
  * @param mixed $value Value to convert to CFType
  * @param boolean $autoDictionary if true {@link CFArray}-detection is bypassed and arrays will be returned as {@link CFDictionary}.
  * @return CFType CFType based on guessed type
  * @uses isAssociativeArray() to check if an array only has numeric indexes
  */
 public function toCFType($value)
 {
     switch (true) {
         case $value instanceof CFType:
             return $value;
             break;
         case is_object($value):
             // DateTime should be CFDate
             if (class_exists('DateTime') && $value instanceof DateTime) {
                 return new CFDate($value->getTimestamp());
             }
             // convert possible objects to arrays, arrays will be arrays
             if ($this->objectToArrayMethod && is_callable(array($value, $this->objectToArrayMethod))) {
                 $value = call_user_func(array($value, $this->objectToArrayMethod));
             }
             if (!is_array($value)) {
                 if ($this->suppressExceptions) {
                     return $this->defaultValue();
                 }
                 throw new PListException('Could not determine CFType for object of type ' . get_class($value));
             }
             /* break; omitted */
         /* break; omitted */
         case $value instanceof Iterator:
         case is_array($value):
             // test if $value is simple or associative array
             if (!$this->autoDictionary) {
                 if (!$this->isAssociativeArray($value)) {
                     $t = new CFArray();
                     foreach ($value as $v) {
                         $t->add($this->toCFType($v));
                     }
                     return $t;
                 }
             }
             $t = new CFDictionary();
             foreach ($value as $k => $v) {
                 $t->add($k, $this->toCFType($v));
             }
             return $t;
             break;
         case is_bool($value):
             return new CFBoolean($value);
             break;
         case is_string($value):
             return new CFString($value);
             break;
         case is_null($value):
             return new CFString();
             break;
         case is_resource($value):
             if ($this->suppressExceptions) {
                 return $this->defaultValue();
             }
             throw new PListException('Could not determine CFType for resource of type ' . get_resource_type($value));
             break;
         case is_numeric($value):
             return new CFNumber($value);
             break;
         default:
             if ($this->suppressExceptions) {
                 return $this->defaultValue();
             }
             throw new PListException('Could not determine CFType for ' . gettype($value));
             break;
     }
 }
Exemple #4
0
 public function toXML(DOMDocument $doc, $nodeName = "")
 {
     $obj = new CFDictionary(array('CF$UID' => new CFNumber($this->value)));
     return $obj->toXml($doc);
 }