/** 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); }
/** 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; }
public function testIsFileURL() { $url = RTURL::URLWithString("/tmp"); $this->assertTrue($url->isFileURL()); }