protected function generatePlistFromData()
 {
     $plist = new CFPropertyList();
     $plist->add($array = new CFArray());
     while ($entry = $this->getData()->next()) {
         $array->add($this->formatEntryAsPlist($entry));
     }
     return $plist;
 }
Пример #2
0
 public function testWriteString()
 {
     $plist = new CFPropertyList();
     $dict = new CFDictionary();
     $names = new CFDictionary();
     $names->add('given-name', new CFString('John'));
     $names->add('surname', new CFString('Dow'));
     $dict->add('names', $names);
     $pets = new CFArray();
     $pets->add(new CFString('Jonny'));
     $pets->add(new CFString('Bello'));
     $dict->add('pets', $pets);
     $dict->add('age', new CFNumber(28));
     $dict->add('birth-date', new CFDate(412035803));
     $plist->add($dict);
     $content = $plist->toXML();
     $plist->parse($content);
 }
Пример #3
0
function generateManifest($manifest_path, $parent, $catalog)
{
    $plist = new CFPropertyList();
    $plist->add($dict = new CFDictionary());
    if ($catalog != '') {
        // Add manifest to production catalog by default
        $dict->add('catalogs', $array = new CFArray());
        $array->add(new CFString($catalog));
    }
    // Add parent manifest to included_manifests to achieve waterfall effect
    $dict->add('included_manifests', $array = new CFArray());
    $array->add(new CFString($parent));
    $tmp = explode('/', $manifest_path);
    $manifest = end($tmp);
    logToFile("Generating manifest '{$manifest}'...");
    // Save the newly created plist
    $plist->saveXML($manifest_path);
}
 /**
  * Convert array to binary format and add it to the object table
  * @param CFArray $val The array to convert
  * @return integer The position in the object table
  */
 public function arrayToBinary($val)
 {
     $saved_object_count = $this->writtenObjectCount++;
     $bdata = self::typeBytes("a", count($val->getValue()));
     // a is 1010, type indicator for arrays
     foreach ($val as $v) {
         $bval = $v->toBinary($this);
         $bdata .= self::packItWithSize($this->objectRefSize, $bval);
     }
     $this->objectTable[$saved_object_count] = $bdata;
     return $saved_object_count;
 }
Пример #5
0
$identifier = $_GET["identifier"];
$hostname = $_GET["hostname"];
// Split the manifest path up to determine directory structure
$directories = explode("/", $identifier, -1);
$total = count($directories);
$n = 0;
$identifier_path = "";
while ($n < $total) {
    $identifier_path .= $directories[$n] . '/';
    $n++;
}
// Check if manifest already exists for this machine
if (file_exists('../manifests/' . $identifier_path . '/clients/' . $hostname)) {
    echo "Computer manifest already exists.";
} else {
    echo "Computer manifest does not exist. Will create.";
    if (!is_dir('../manifests/' . $identifier_path . 'clients/')) {
        mkdir('../manifests/' . $identifier_path . 'clients/', 0755, true);
    }
    // Create the new manifest plist
    $plist = new CFPropertyList();
    $plist->add($dict = new CFDictionary());
    // Add manifest to production catalog by default
    $dict->add('catalogs', $array = new CFArray());
    $array->add(new CFString('production'));
    // Add parent manifest to included_manifests to achieve waterfall effect
    $dict->add('included_manifests', $array = new CFArray());
    $array->add(new CFString($identifier));
    // Save the newly created plist
    $plist->saveXML('../manifests/' . $identifier_path . 'clients/' . $hostname);
}
Пример #6
0
 /**
  * Create CFType-structure from 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
  */
 public static function guess($value, $autoDictionary = false)
 {
     switch (true) {
         case $value instanceof CFType:
             return $value;
             break;
         case is_array($value):
             // test if $value is simple or associative array
             if (!$autoDictionary) {
                 $numericKeys = true;
                 $previousKey = null;
                 foreach ($value as $key => $v) {
                     if (!is_numeric($key) || $previousKey !== null && $previousKey != $key - 1) {
                         $numericKeys = false;
                         break;
                     }
                     $previousKey = $key;
                 }
                 if ($numericKeys) {
                     $t = new CFArray();
                     foreach ($value as $v) {
                         $t->add(self::guess($v, $autoDictionary));
                     }
                     return $t;
                 }
             }
             $t = new CFDictionary();
             foreach ($value as $k => $v) {
                 $t->add($k, self::guess($v, $autoDictionary));
             }
             return $t;
             break;
         case is_numeric($value):
             return new CFNumber($value);
             break;
         case is_bool($value):
             return new CFBoolean($value);
             break;
         case is_string($value):
             return new CFString($value);
             break;
     }
 }
Пример #7
0
 /**
  * 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_numeric($value):
             return new CFNumber($value);
             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;
         default:
             if ($this->suppressExceptions) {
                 return $this->defaultValue();
             }
             throw new PListException('Could not determine CFType for ' . gettype($value));
             break;
     }
 }
Пример #8
0
 /**
  * Get first (and only) child, or complete collection.
  * @param string $cftype if set to true returned value will be CFArray instead of an array in case of a collection
  * @return CFType|array CFType or list of CFTypes known to the PropertyList
  * @uses $value for retrieving CFTypes
  */
 public function getValue($cftype = false)
 {
     if (count($this->value) === 1) {
         $t = array_values($this->value);
         return $t[0];
     }
     if ($cftype) {
         $t = new CFArray();
         foreach ($this->value as $value) {
             if ($value instanceof CFType) {
                 $t->add($value);
             }
         }
         return $t;
     }
     return $this->value;
 }
Пример #9
0
<?php

require_once 'cfpropertylist-1.1.2/CFPropertyList.php';
// Get the varibles passed by the enroll script
$hostname = $_GET["hostname"];
$identifier1 = $_GET["identifier1"];
// Check if manifest already exists for this machine
if (file_exists('../manifests/' . $hostname)) {
    echo "Computer manifest already exists.";
} else {
    echo "Computer manifest does not exist. Will create.";
    // Create the new manifest plist
    $plist = new CFPropertyList();
    $plist->add($dict = new CFDictionary());
    // Add manifest to release catalog by default
    $dict->add('catalogs', $array = new CFArray());
    $array->add(new CFString('release'));
    // Add manifests
    $dict->add('included_manifests', $array = new CFArray());
    $array->add(new CFString('__Core'));
    if ($identifier1 != "") {
        $array->add(new CFString($identifier1));
    }
    // Save the newly created plist
    $plist->saveXML('../manifests/' . $hostname);
}
Пример #10
0
 protected function readBinaryArray($length)
 {
     $ary = new CFArray();
     if ($length != 0) {
         if (strlen($buff = substr($this->content, $this->pos, $length * $this->objectRefSize)) != $length * $this->objectRefSize) {
             throw IOException::readError("");
         }
         $this->pos += $length * $this->objectRefSize;
         $objects = unpack($this->objectRefSize == 1 ? "C*" : "n*", $buff);
         for ($i = 0; $i < $length; ++$i) {
             $object = $this->readBinaryObjectAt($objects[$i + 1] + 1, $this->objectRefSize);
             $ary->add($object);
         }
     }
     return $ary;
 }
Пример #11
0
$plist = new CFPropertyList();
/*
 * Manuall Create the sample.xml.plist 
 */
// the Root element of the PList is a Dictionary
$plist->add($dict = new CFDictionary());
// <key>Year Of Birth</key><integer>1965</integer>
$dict->add('Year Of Birth', new CFNumber(1965));
// <key>Date Of Graduation</key><date>2004-06-22T19:23:43Z</date>
$dict->add('Date Of Graduation', new CFDate(gmmktime(19, 23, 43, 06, 22, 2004)));
// <key>Pets Names</key><array/>
$dict->add('Pets Names', new CFArray());
// <key>Picture</key><data>PEKBpYGlmYFCPA==</data>
// to keep it simple we insert an already base64-encoded string
$dict->add('Picture', new CFData('PEKBpYGlmYFCPA==', true));
// <key>City Of Birth</key><string>Springfield</string>
$dict->add('City Of Birth', new CFString('Springfield'));
// <key>Name</key><string>John Doe</string>
$dict->add('Name', new CFString('John Doe'));
// <key>Kids Names</key><array><string>John</string><string>Kyra</string></array>
$dict->add('Kids Names', $array = new CFArray());
$array->add(new CFString('John'));
$array->add(new CFString('Kyra'));
/*
 * Save PList as XML
 */
$plist->saveXML(__DIR__ . '/example-create-01.xml.plist');
/*
 * Save PList as Binary
 */
$plist->saveBinary(__DIR__ . '/example-create-01.binary.plist');
 /**
  * Get first (and only) child, or complete collection.
  * @param string $cftype if set to true returned value will be CFArray instead of an array in case of a collection
  * @return CFType|array CFType or list of CFTypes known to the PropertyList
  * @uses $value for retrieving CFTypes
  */
 public function getValue($cftype = false)
 {
     if (count($this->value) === 1) {
         return $this->value[0];
     }
     if ($cftype) {
         $t = new CFArray();
         foreach ($this->value as $value) {
             $t->add($value);
         }
         return $t;
     }
     return $this->value;
 }
Пример #13
0
 /**
  * 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 $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_numeric($value):
             return new CFNumber($value);
             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_object($value):
             if ($this->suppressExceptions) {
                 return $this->defaultValue();
             }
             throw new PListException('Could not determine CFType for object of type ' . get_class($value));
             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;
         default:
             if ($this->suppressExceptions) {
                 return $this->defaultValue();
             }
             throw new PListException('Could not determine CFType for ' . gettype($value));
             break;
     }
 }