コード例 #1
1
ファイル: AbstractModel.php プロジェクト: nbalonso/MunkiFace
 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 function testSetDictionary()
 {
     $dict = RTDictionary::dictionaryWithObjects_andKeys(array("once there was a story"), array("one"));
     $this->assertFalse($this->dictionary->isEqualToDictionary($dict));
     $this->dictionary->setDictionary($dict);
     $this->assertTrue($this->dictionary->isEqualToDictionary($dict));
 }
コード例 #3
0
ファイル: ReadAction.php プロジェクト: nbalonso/MunkiFace
 public function read()
 {
     if ($this->targetIsDirectory()) {
         throw new Exception("Class 'Read' cannot parse a directory '" . $this->fullPathToTarget() . "'", MFInvalidTargetForActionError);
     }
     try {
         $dict = RTDictionary::dictionaryWithContentsOfFile($this->fullPathToTarget());
         if ($dict->allKeys()->count() == 0) {
             throw new Exception("Invalid plist specified in '" . $this->fullPathToTarget() . "'", MFParseError);
         }
         return $dict;
     } catch (Exception $e) {
         throw new Exception("Unable to parse plist at '" . $this->fullPathToTarget() . "'", MFParseError);
     }
 }
コード例 #4
0
ファイル: SetAction.php プロジェクト: nbalonso/MunkiFace
 public function set()
 {
     // Check the request method. If it isn't POST or PUT, return a 400.
     if ($_SERVER['REQUEST_METHOD'] != "POST" && $_SERVER['REQUEST_METHOD'] != "PUT") {
         header("HTTP/1.0 400 Bad Request");
         throw new Exception("Requests to modify files must be sent either via PUT or POST", MFBadRequestTypeError);
         exit;
     }
     if ($this->targetIsDirectory()) {
         throw new Exception("Class 'SetAction' cannot treat directories as files '" . $this->fullPathToTarget() . "'", MFInvalidTargetForActionError);
     }
     $parentDir = $this->fullPathToTarget()->stringByDeletingLastPathComponent();
     if (!is_dir($parentDir)) {
         $components = $parentDir->pathComponents();
         $tmpPath = "";
         for ($i = 0; $i < $components->count(); $i++) {
             $component = $components->objectAtIndex($i);
             if ($component == "/") {
                 continue;
             }
             $tmpPath .= "/" . $components->objectAtIndex($i);
             if (!is_dir($tmpPath)) {
                 if (@mkdir($tmpPath) === NO) {
                     throw new Exception("Insufficient permissions to mkdir '" . $tmpPath . "'", MFPermissionsError);
                 }
             }
         }
     }
     $json = json_decode(HTTPRequest::sharedRequest()->objectForKey("set")->description(), YES);
     $dict = RTDictionary::dictionaryWithPHPArray($json);
     try {
         $dict->writeToFile($this->fullPathToTarget());
         return YES;
     } catch (Exception $e) {
         throw new Exception("Insufficient permissions to write to file '" . $this->fullPathToTarget() . "'", MFPermissionsError);
     }
 }
コード例 #5
0
ファイル: RTURL.php プロジェクト: nbalonso/MunkiFace
 public function initWithString($aString)
 {
     if (is_object($aString) && get_class($aString) != "RTString") {
         $aString = RTString::stringWithString(strval($aString));
     }
     parent::init();
     $this->_url = $aString;
     $parsedUrl = parse_url($aString);
     // @codeCoverageIgnoreStart
     if ($parsedUrl === NO) {
         throw new InvalidArgumentException("Unable to parse url '" . $aString . "'");
     }
     // @codeCoverageIgnoreEnd
     $this->_setDefaultValue_forKey_onArray("file", "scheme", $parsedUrl);
     $this->_setDefaultValue_forKey_onArray(null, "host", $parsedUrl);
     $this->_setDefaultValue_forKey_onArray(null, "port", $parsedUrl);
     $this->_setDefaultValue_forKey_onArray(null, "user", $parsedUrl);
     $this->_setDefaultValue_forKey_onArray(null, "pass", $parsedUrl);
     $this->_setDefaultValue_forKey_onArray("/", "path", $parsedUrl);
     $this->_setDefaultValue_forKey_onArray(null, "query", $parsedUrl);
     $this->_setDefaultValue_forKey_onArray(null, "fragment", $parsedUrl);
     $this->_parsedUrl = RTDictionary::dictionaryWithPHPArray($parsedUrl);
     return $this;
 }
コード例 #6
0
ファイル: RTArray.php プロジェクト: nbalonso/MunkiFace
 /**
 		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
ファイル: RTDictionary.php プロジェクト: nbalonso/MunkiFace
 /**
 		Returns YES if the receiving dictionary and aDict have the same number of
 		entries and for a given key, the corresponding objecs are also the same.
 		\param $aDict
 		\returns BOOL
 */
 public function isEqualToDictionary(RTDictionary $aDict)
 {
     return $this->count() == $aDict->count() && $this->allKeys()->isEqualToArray($aDict->allKeys()) && $this->allValues()->isEqualToArray($aDict->allValues());
 }
コード例 #8
0
 public function testIteratorImplementation()
 {
     $dict = RTDictionary::alloc()->initWithPHPArray(array("one" => "42", "two" => 42, "three" => YES, "four" => "blah"));
     foreach ($dict as $key => $val) {
         $this->assertSame($val, $dict->objectForKey($key));
     }
 }
コード例 #9
0
ファイル: RTArrayTest.php プロジェクト: nbalonso/MunkiFace
 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());
 }
コード例 #10
0
 /**
 		Sets the contents of the receiving dictionary to the entries in a given
 		dictionary.
 		\param $aDictionary
 */
 public function setDictionary(RTDictionary $aDictionary)
 {
     $this->_data = $aDictionary->phpArray();
 }