示例#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);
                 }
             }
         }
     }
 }
示例#2
0
 public static function sharedSettings()
 {
     if (self::$_INSTANCE == NULL) {
         self::$_INSTANCE = self::alloc()->initWithContentsOfFile(RTString::stringWithString(dirname(dirname(__FILE__)) . "/Settings.plist"));
     }
     return self::$_INSTANCE;
 }
示例#3
0
 public function testMakeRangeWithRTObjectsAsArguments()
 {
     $location = RTString::stringWithString("100");
     $length = RTString::stringWithString("10");
     $range = RTMakeRange($location, $length);
     $this->assertSame($range->location, 100.0);
     $this->assertSame($range->length, 10.0);
 }
示例#4
0
 public function testInitWithContentsOfFile()
 {
     $file = RTString::stringWithString(dirname(__FILE__) . "/_files/sample.xml.plist");
     $dict = RTDictionary::alloc()->initWithContentsOfFile($file);
     $this->assertEquals(7, $dict->count());
     $this->assertSame(1965, $dict->objectForKey("Year Of Birth"));
     $this->assertSame(1087932223, $dict->objectForKey("Date Of Graduation"));
     $this->assertEquals("RTArray", $dict->objectForKey("Pets Names")->className());
     $this->assertEquals(0, $dict->objectForKey("Pets Names")->count());
     $this->assertEquals("PEKBpYGlmYFCPA==", base64_encode($dict->objectForKey("Picture")));
     $this->assertEquals("Springfield", $dict->objectForKey("City Of Birth"));
     $this->assertEquals("John Doe", $dict->objectForKey("Name"));
     $kidsNames = $dict->objectForKey("Kids Names");
     $this->assertEquals("RTArray", $kidsNames->className());
     $this->assertEquals(2, $kidsNames->count());
     $this->assertEquals("John", $kidsNames->objectAtIndex(0));
     $this->assertEquals("Kyra", $kidsNames->objectAtIndex(1));
 }
示例#5
0
 public function matchesPlistList($aFile)
 {
     if ($this->plistExtensionsAreEmpty() == YES) {
         return YES;
     }
     $fileName = RTString::stringWithString($aFile);
     for ($i = 0; $i < $this->plistExtensions()->count(); $i++) {
         $ext = $this->plistExtensions()->objectAtIndex($i);
         if (YES == $fileName->hasSuffix($ext)) {
             return YES;
         }
     }
     return NO;
 }
示例#6
0
 /**
 		A utility method that provides standardized filtering of incomming objects.
 		Basically, it makes sure that any object added to the array is an instance
 		of RTObject. An 'object' in this context literally means it passes the
 		is_object() function.
 		\param $anObject The object to add to the array
 		\param $anIndex The index at which the object should be inserted
 		\throws InvalidArgumentException if the object passes is_object() but is not
 		an instance of RTObject.
 */
 protected function _insertObject_atIndex($anObject, $anIndex)
 {
     if (is_object($anObject) && is_a($anObject, "RTObject") == NO) {
         throw new InvalidArgumentException("RTArray can only contain primitives and objects that inherit from " . "RTObject. Found object of class '" . get_class($anObject) . "'");
     }
     if (is_array($anObject)) {
         if (RTPHPArrayIsRTDictionary($anObject)) {
             $anObject = RTDictionary::dictionaryWithPHPArray($anObject);
         } else {
             $anObject = RTArray::arrayWithArray($anObject);
         }
     } else {
         if (is_string($anObject)) {
             $anObject = RTString::stringWithString($anObject);
         }
     }
     $this->_data[$anIndex] = $anObject;
 }
示例#7
0
 /**
 		Returns a new string in which all occurrences of a target string in the
 		receiver are replaced by another given string.
 		\param target
 		\param replacement
 		\returns RTString
 */
 public function stringByReplacingOccurrencesOfString_withString(RTString $target, RTString $replacement)
 {
     return RTString::stringWithString(str_replace($target->description(), $replacement->description(), $this->description()));
 }
示例#8
0
 /**
 		Returns the printable representation of this object.
 		\returns RTString
 */
 public function description()
 {
     return RTString::stringWithString($this->jsonValue());
 }
示例#9
0
 public function testSubstringWithRangeThrowsExceptionWithInvalidLength()
 {
     $string = RTString::stringWithString("This is a test");
     $range = RTMakeRange(0, $string->length() + 1);
     try {
         $anotherString = $string->substringWithRange($range);
     } catch (RTRangeException $e) {
         return;
     }
     $this->fail("Should have thrown exception when range's length is beyond the end of the string");
 }
示例#10
0
 /**
 		Provides a common set of logic filters for adding new items to the
 		dictionary. This prevents invalid items from being added, such as objects
 		that do not inherit from RTObject. The reason that object that do not
 		inherit from RTObject are forbidden its that there is no way to assure a
 		valid string representation can be derived from such objects. For example,
 		there is no programatic way to convert an instance of stdClass to a string.
 		Sure we would iterate over the properties and values of an object, but let's
 		say you have a custom class that only uses private properties. We could
 		alsos test for the ability of an object to be converted to a string, but by
 		enforcing this requirement, that's already done.
 */
 protected function _setObject_forKey($anObject, $aKey)
 {
     if (is_object($anObject) && is_a($anObject, "RTObject") == NO) {
         throw new InvalidArgumentException("Objects added to an RTDictionary must inherit from RTObject.");
     }
     if (is_null($aKey) == YES) {
         throw new InvalidArgumentException("Keys in an RTDictionary cannot be null");
     } else {
         if (is_object($aKey) && is_a($aKey, "RTObject")) {
             $aKey = $aKey->description();
         }
     }
     if (is_array($anObject)) {
         if (RTPHPArrayIsRTDictionary($anObject)) {
             $anObject = RTDictionary::dictionaryWithPHPArray($anObject);
         } else {
             $anObject = RTArray::arrayWithArray($anObject);
         }
     } else {
         if (is_string($anObject)) {
             $anObject = RTString::stringWithString($anObject);
         }
     }
     $this->_data[$aKey] = $anObject;
 }
示例#11
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());
 }
示例#12
0
 /**
 		Returns the extension found on the last component of the url or an empty
 		string if none can be found.
 		\returns RTString
 */
 public function pathExtension()
 {
     $file = RTString::stringWithString($this->pathComponents()->lastObject());
     return $file->componentsSeparatedByString(".")->lastObject();
 }