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); } } } } }
/** Removes from the dictionary entries specified by elements in a given array. \param $anArray */ public function removeObjectsForKeys($anArray) { if (is_array($anArray)) { $anArray = RTArray::arrayWithArray($anArray); } for ($i = 0; $i < $anArray->count(); $i++) { $this->removeObjectForKey($anArray->objectAtIndex($i)); } }
public function testRemoveObjectsWithPHPArrayOfKeys() { $dict = $this->dictionary; $keys = $dict->allKeys(); $keysToRemove = RTArray::arrayWithObjects($keys->firstObject(), $keys->lastObject()); $dict->removeObjectsForKeys($keysToRemove->phpArray()); $this->assertNull($dict->objectForKey($keysToRemove->firstObject())); $this->assertNull($dict->objectForKey($keysToRemove->lastObject())); }
/** Returns a new array containing the receiving array's elements that fall within the limits specified by a given range. \param $aRange \returns RTArray */ public function subarrayWithRange(RTRange $aRange) { $array = array(); for ($i = $aRange->location; $i <= $aRange->location + $aRange->length; $i++) { $array[] = $this->objectAtIndex($i); } return RTArray::arrayWithArray($array); }
/** Basically this is PHP's explode() function. \returns RTArray */ public function componentsSeparatedByString($aString) { return RTArray::arrayWithArray(explode($aString, $this->_string)); }
/** Removes from the receiving array the objects in another given array. \param $anArray */ public function removeObjectsInArray($anArray) { if (is_array($anArray) == YES) { $anArray = RTArray::arrayWithArray($anArray); } if (is_a($anArray, "RTArray") == YES) { for ($i = 0; $i < $anArray->count(); $i++) { $this->removeObject($anArray->objectAtIndex($i)); } } else { throw new InvalidArgumentException("RTMutableArray::removeObjectsInArray expects an array"); } }
public function testRemoveObjectsInArrayWithRTArray() { $mArray = RTMutableArray::anArray(); $mArray->addObjectsFromArray(array("42", 42, TRUE, FALSE)); $mArray->removeObjectsInArray(RTArray::arrayWithObjects("42", TRUE)); $this->assertEquals(2, $mArray->count()); $this->assertSame(42, $mArray->objectAtIndex(0)); $this->assertEquals(FALSE, $mArray->objectAtIndex(1)); }
public function testComponentsSeparatedByString() { $raw = RTArray::arrayWithObjects("this", "is", "a", "csv", "string"); $str = RTString::stringWithString($raw->componentsJoinedByString(",")); $components = $str->componentsSeparatedByString(","); $this->assertEquals(5, $components->count()); for ($i = 0; $i < $components->count(); $i++) { $this->assertEquals($raw->objectAtIndex($i), $components->objectAtIndex($i)); } }
/** Returns a new array containing the dictionary's values. \returns RTArray */ public function allValues() { return RTArray::arrayWithArray(array_values($this->_data)); }
public function testInitWithPHPArray() { $array = array("one" => "42", "two" => 42, "three" => YES, "four" => RTArray::arrayWithObjects("42", 42, YES, NO)); $dict = RTDictionary::alloc()->initWithPHPArray($array); $this->assertEquals(4, $dict->count()); $rtArray = RTArray::arrayWithObject($array); $dict = RTDictionary::alloc()->initWithPHPArray($rtArray); $this->assertEquals(1, $dict->count()); }
public function testIteratorImplementation() { $array = RTArray::arrayWithArray(array("test", "one", "two", "three", "mic check")); foreach ($array as $key => $val) { $this->assertEquals($val, $array->objectAtIndex($key)); } }
/** Returns the components of the URLs path as an array. \returns RTArray */ public function pathComponents() { $path = RTString::stringWithString($this->path()); $components = RTMutableArray::arrayWithArray($path->componentsSeparatedByString("/")); if ($components->count() > 0) { $components->removeObjectAtIndex(0); } return RTArray::arrayWithArray($components); }