Esempio n. 1
1
 protected function _globDir($aDir, RTArray &$results)
 {
     if (!is_dir($aDir)) {
         return;
     }
     $contents = scandir($aDir);
     $validator = FileNameValidator::alloc()->init();
     $fullPathToNode = "";
     foreach ($contents as $node) {
         $fullPathToNode = $aDir->stringByAppendingPathComponent(RTString::stringWithString($node));
         // If the node represents a directory but does not start with a "."
         // character...
         if (is_dir($fullPathToNode) && strpos($node, ".") !== 0) {
             $arr = RTMutableArray::anArray();
             $this->_globDir($fullPathToNode, $arr);
             $results->addObject(RTDictionary::dictionaryWithObject_forKey($arr, $node));
         } else {
             if ($validator->isValidFileName($node) == YES) {
                 try {
                     // See if we can parse the plist file
                     $dict = RTDictionary::dictionaryWithContentsOfFile(RTString::stringWithString($fullPathToNode));
                     // $node is a valid plist
                     if ($dict->count() !== 0) {
                         $results->addObject($node);
                     }
                 } catch (Exception $e) {
                     // $node is not a valid plist
                     $results->addObject("(PARSE_ERROR) " . $node);
                 }
             }
         }
     }
 }
Esempio n. 2
0
 public function testDescriptionWithNestedDictionary()
 {
     $aDict = RTDictionary::dictionaryWithObject_forKey("42", "one");
     $objects = array(42, $aDict);
     $keys = array("one", "two");
     $dict = RTDictionary::dictionaryWithObjects_andKeys($objects, $keys);
     $this->assertEquals('{"one":42,"two":{"one":"42"}}', $dict->description());
 }
Esempio n. 3
0
 public function testDescriptionWithComplexDataStructures()
 {
     $nativeArray = array(array("negative number" => -1, "zero" => 0, "positive number" => 1, "PHP string" => "a native string", "RTString" => RTString::stringWithString("an RTString instance"), "RTDictionary" => RTDictionary::dictionaryWithObject_forKey(YES, "aBool"), "aBoolean YES" => YES, "aBoolean NO" => NO, "null" => null, "Empty RTArray", RTArray::anArray()), RTString::stringWithString("Another RTString"), 42, null);
     $array = RTArray::arrayWithArray($nativeArray);
     $this->assertSame('[{"negative number":-1,"zero":0,"positive number":1,' . '"PHP string":"a native string","RTString":"an RTString instance",' . '"RTDictionary":{"aBool":true},"aBoolean YES":true,"aBoolean NO":false,' . '"null":,"0":"Empty RTArray","1":[]},"Another RTString",42,]', $array->description());
 }