public function appending()
 {
     with($stream = new FileOutputStream($this->file, true));
     $stream->write('!');
     $this->file->close();
     $this->assertEquals('Created by FileOutputStreamTest!', FileUtil::getContents($this->file));
 }
예제 #2
0
 public function fetchWsdl()
 {
     if (0 == strncmp('https://', $this->uri, 8) || 0 == strncmp('http://', $this->uri, 7)) {
         return HttpUtil::get(new HttpConnection(new URL($this->uri)));
     } else {
         return FileUtil::getContents(new File($this->uri));
     }
 }
 /**
  * Retrieve contents of errordocument
  *
  * @return  string content
  */
 public function getContent()
 {
     try {
         $contents = FileUtil::getContents(new File($this->filename));
     } catch (Exception $e) {
         $this->message .= $e->toString();
         $contents = '<xp:value-of select="reason"/>';
     }
     return str_replace('<xp:value-of select="reason"/>', $this->message, $contents);
 }
예제 #4
0
 public function get_contents_read_returns_less_than_size()
 {
     $data = 'Test';
     $f = newinstance('io.Stream', array(), '{
     public function read($size= 4096) { return parent::read(min(1, $size)); }
   }');
     $f->open(STREAM_MODE_WRITE);
     $f->write($data);
     $f->close();
     $this->assertEquals($data, FileUtil::getContents($f));
 }
 /**
  * Fetch data
  *
  * @param   string name
  * @return  string data
  */
 protected function fetch($name)
 {
     return FileUtil::getContents(new File($this->path, $name));
 }
예제 #6
0
 /**
  * Add a file
  *
  * @param   string id the id under which this entry will be located
  * @param   io.File file
  */
 public function addFile($id, $file)
 {
     $bytes = FileUtil::getContents($file);
     $this->_index[$id] = array(strlen($bytes), -1, $bytes);
 }
예제 #7
0
 /**
  * Construct an XML tree from a file.
  *
  * <code>
  *   $tree= Tree::fromFile(new File('foo.xml'));
  * </code>
  *
  * @param   io.File file
  * @param   string c default __CLASS__ class name
  * @return  xml.Tree
  * @throws  xml.XMLFormatException in case of a parser error
  * @throws  io.IOException in case reading the file fails
  */
 public static function fromFile($file, $c = __CLASS__)
 {
     $parser = new XMLParser();
     $tree = new $c();
     $parser->setCallback($tree);
     $parser->parse(FileUtil::getContents($file));
     // Fetch actual encoding from parser
     $tree->setEncoding($parser->getEncoding());
     delete($parser);
     return $tree;
 }
예제 #8
0
 public function testGetContents()
 {
     // With both methods:
     $this->assertTrue((bool) FileUtil::getContents('http://google.com'));
     FileUtil::$alwaysCurl = true;
     $this->assertTrue((bool) FileUtil::getContents('http://google.com'));
     FileUtil::$alwaysCurl = false;
 }
예제 #9
0
 public function get_contents()
 {
     $f = new File(Streams::readableFd(new MemoryInputStream('Test')));
     $this->assertEquals('Test', FileUtil::getContents($f));
 }
예제 #10
0
 /**
  * In which the updater downloads a new version of itself.
  * 
  * @param type $updaterCheck New version of the update utility
  * @return array
  */
 public function updateUpdater($updaterCheck)
 {
     if (version_compare($this->configVars['updaterVersion'], $updaterCheck) >= 0) {
         return array();
     }
     $updaterFiles = $this->updaterFiles;
     // Retrieve the update package contents' files' digests:
     $md5sums_content = FileUtil::getContents($this->updateServer . '/' . $this->getUpdateDataRoute($this->configVars['updaterVersion']) . '/contents.md5');
     // If there's an error on the server end the response will be a JSON
     $tryJson = json_decode($md5sums_content, 1);
     if (!(bool) $md5sums_content) {
         $admin = CActiveRecord::model('Admin')->findByPk(1);
         if ($this->scenario === 'upgrade' && isset($admin) && empty($admin->unique_key)) {
             $updaterSettingsLink = CHtml::link(Yii::t('admin', 'Updater Settings page'), array('admin/updaterSettings'));
             throw new CException(Yii::t('admin', 'You must first set a product key on the ' . $updaterSettingsLink));
         } else {
             throw new CException(Yii::t('admin', 'Unknown update server error.'), self::ERR_UPSERVER);
         }
     } else {
         if (is_array($tryJson)) {
             // License key error
             if (isset($tryJson['errors'])) {
                 throw new CException($tryJson['errors']);
             } else {
                 throw new CException(Yii::t('admin', 'Unknown update server error.') . ' ' . $md5sums_content);
             }
         }
     }
     preg_match_all(':^(?<md5sum>[a-f0-9]{32})\\s+source/protected/(?<filename>\\S.*)$:m', $md5sums_content, $md5s);
     $md5sums = array();
     for ($i = 0; $i < count($md5s[0]); $i++) {
         $md5sums[$md5s['md5sum'][$i]] = $md5s['filename'][$i];
     }
     // These are the files that need to be downloaded -- only those which have changed:
     $updaterFiles = array_intersect($md5sums, $updaterFiles);
     // Try to retrieve the files:
     $failed2Retrieve = array();
     foreach ($updaterFiles as $md5 => $file) {
         $pass = 0;
         $tries = 0;
         $downloadedFile = FileUtil::relpath(implode(DIRECTORY_SEPARATOR, array($this->webRoot, self::TMP_DIR, 'protected', FileUtil::rpath($file))), $this->thisPath . DIRECTORY_SEPARATOR);
         while (!$pass && $tries < 2) {
             $remoteFile = $this->updateServer . '/' . $this->sourceFileRoute . "/protected/{$file}";
             try {
                 $this->downloadSourceFile("protected/{$file}");
             } catch (Exception $e) {
                 break;
             }
             // Only call it done if it's intact and ready for use:
             $pass = md5_file($downloadedFile) == $md5;
             $tries++;
         }
         if (!$pass) {
             $failed2Retrieve[] = "protected/{$file}";
         }
     }
     $failedDownload = (bool) count($failed2Retrieve);
     // Copy the files into the live install
     if (!$failedDownload && (bool) count($updaterFiles)) {
         $this->applyFiles(self::TMP_DIR);
         // Remove the temporary directory:
         FileUtil::rrmdir($this->webRoot . DIRECTORY_SEPARATOR . self::TMP_DIR);
     } else {
         $errorResponse = json_decode($md5sums_content, 1);
         if (isset($errorResponse['errors'])) {
             throw new CException($errorResponse['errors']);
         }
     }
     // Write the new updater version into the configuration; else
     // the app will get stuck in a redirect loop
     if (!$failedDownload) {
         $this->regenerateConfig(Null, $updaterCheck, Null);
     }
     return $failed2Retrieve;
 }
예제 #11
0
 /**
  * Create a new checksum from a file object
  *
  * @param   io.File file
  * @return  security.checksum.CRC16
  */
 public static function fromFile($file)
 {
     return CRC16::fromString(FileUtil::getContents($file));
 }
 /**
  * Load an image
  *
  * @param   peer.URL source
  * @return  string[2] data and contenttype
  */
 public function load($source)
 {
     return array(FileUtil::getContents(new File($source->getURL())), MimeType::getByFilename($source->getURL()));
 }
 /**
  * Reload Bot configuration
  *
  */
 public function reloadConfiguration()
 {
     $this->config->reset();
     $this->lists = array();
     // Set base directory for lists relative to that of the config file's
     $base = dirname($this->config->getFilename()) . DIRECTORY_SEPARATOR;
     // Read word/message lists
     foreach ($this->config->readSection('lists') as $identifier => $file) {
         $this->lists[$identifier] = array();
         $f = new File($base . $file);
         try {
             if ($f->open(FILE_MODE_READ)) {
                 while (($line = $f->readLine()) && !$f->eof()) {
                     $this->lists[$identifier][] = $line;
                 }
             }
             $f->close();
         } catch (IOException $e) {
             $e->printStackTrace();
             return FALSE;
         }
     }
     // Read karma recognition phrases
     $f = new File($base . $this->config->readString('karma', 'recognition'));
     try {
         if ($f->open(FILE_MODE_READ)) {
             while (!$f->eof()) {
                 $line = $f->readLine();
                 if (empty($line) || strspn($line, ';#')) {
                     continue;
                 }
                 list($pattern, $channel, $direct) = explode(':', $line);
                 $this->recognition[$pattern] = array((int) $channel, (int) $direct);
             }
         }
         $f->close();
     } catch (IOException $e) {
         $e->printStackTrace();
         return FALSE;
     }
     // If no karma is set and the karma storage exists, load it
     if (0 == sizeof($this->karma)) {
         try {
             $f = new File($base . 'karma.list');
             if ($f->exists()) {
                 $karma = unserialize(FileUtil::getContents($f));
                 if ($karma) {
                     $this->karma = $karma;
                 }
             }
         } catch (IOException $e) {
             // Karma loading failed - log, but ignore...
             $this->cat && $this->cat->error($e);
         }
     }
 }
 public function loadingNonexistantFile()
 {
     $this->assertEquals('Foobar', trim(FileUtil::getContents(new File('res://one/Dummy.txt'))));
 }
예제 #15
0
 /**
  * Create a new checksum from a file object
  *
  * @param   io.File file
  * @param   string key default NULL
  * @return  security.checksum.HMAC_MD5
  */
 public static function fromFile($file, $key = NULL)
 {
     return new HMAC_MD5(HMAC_MD5::hash(FileUtil::getContents($file), $key));
 }
예제 #16
0
 /**
  * Entry point
  *
  * @param   text.doclet.RootDoc root
  * @return  var
  */
 public function start(RootDoc $root)
 {
     $this->processor = new MarkupBuilder();
     // Option: API (will be used in title, default: none)
     $this->api = $this->option('api');
     // Option: Gen (will be used in footer)
     $this->gen = $this->option('gen');
     // Option: CSS to embed (filename, default: none)
     if ($css = $this->option('css')) {
         $this->css = FileUtil::getContents(new File($css));
     }
     // Option: Output folder (default: Current directory, created if non-existant)
     $target = new Folder($this->option('output', '.'));
     $target->exists() || $target->create();
     // Compute hierarchy
     Console::write('[');
     $this->hierarchy = array();
     $seen = array();
     while ($this->classes->hasNext()) {
         $class = $this->classes->next();
         if (isset($seen[$class->qualifiedName()])) {
             continue;
         }
         $seen[$class->qualifiedName()] = TRUE;
         $key = $class->containingPackage()->name();
         if (!isset($this->hierarchy[$key])) {
             $sub = new Folder($target, strtr($key, '.', DIRECTORY_SEPARATOR));
             $sub->exists() || $sub->create();
             $this->hierarchy[$key] = array('target' => $sub, 'doc' => $class->containingPackage(), 'contents' => array(INTERFACE_CLASS => array(), ORDINARY_CLASS => array(), ENUM_CLASS => array(), EXCEPTION_CLASS => array(), ERROR_CLASS => array()));
         }
         Console::write('.');
         $this->hierarchy[$key]['contents'][$class->classType()][] = $class;
     }
     // Generate HTML files
     Console::write('>');
     $this->writeOverview($this->hierarchy, $target)->close();
     Console::writeLine($target, ']');
 }
예제 #17
0
 /**
  * Add a file to the Blog
  *
  * @param   &io.File file
  * @return  array url of the file
  */
 public function newMediaObject($file)
 {
     return $this->invoke('metaWeblog.newMediaObject', $this->blogid, $this->username, $this->password, array('name' => $file->getFileName(), 'type' => MimeType::getByFilename($file->getFileName()), 'bits' => Base64::encode(FileUtil::getContents($file))));
 }
예제 #18
0
 public function writePngBC()
 {
     $s = new Stream();
     $this->image->saveTo(new PngStreamWriter(ref($s)));
     $this->assertNotEmpty(FileUtil::getContents($s));
 }