Пример #1
0
 /**
 		Initializes a newly allocated dictionary using the contents found in the
 		file at the given URL.
 		\param $aURL
 		\returns RTDictionary
 		\note This method will return null if the file is malformed, or if the
 		top element is anything but a dictionary.
 */
 public function initWithContentsOfURL(RTURL $aURL)
 {
     $path = $aURL->description();
     return $this->initWithContentsOfFile($path);
 }
Пример #2
0
 /**
 		Initializes a newly allocated array with the contents of the file specified
 		by a given path. The contents of the file must be JSON.
 		\param $aPath
 		\returns RTArray
 */
 public function initWithContentsOfFile($aPath)
 {
     $this->init();
     $url = RTURL::URLWithString($aPath);
     if ($url->isFileURL() && (!is_file($aPath) || !is_readable($aPath))) {
         $this->_data = array();
         return $this;
     }
     $contents = @file_get_contents($aPath);
     if ($contents !== NO) {
         $data = json_decode($contents);
         if (is_array($data)) {
             $this->initWithArray(json_decode($contents));
         }
     }
     return $this;
 }
Пример #3
0
 public function testIsFileURL()
 {
     $url = RTURL::URLWithString("/tmp");
     $this->assertTrue($url->isFileURL());
 }