/**
  * Read file contents or return null if file has timed out
  *
  * @return mixed
  */
 public function read()
 {
     if ($this->isTimedOut()) {
         return null;
     }
     return parent::read();
 }
Exemple #2
0
 /**
  * 解析cvs文件
  *
  * @param
  *
  */
 public function csv($start, $end = null, $bundle = null, $type = 'access')
 {
     if (!$end) {
         $end = time();
     }
     if ($bundle) {
         $bundles = (array) $bundle;
     }
     $bundles[] = '#';
     $file = Storage::getStorageFile($type, date('Ymd', $start));
     $storage = new FileStorage($file, 'rb');
     while ($v = $storage->read()) {
         $this->parse($v, $start, $end, $bundles);
     }
     return $this->results;
 }
Exemple #3
0
 function setDataFile($to)
 {
     $this->dataFile = $to;
     if (file_exists($to)) {
         $fs = new FileStorage($to, FS_READ);
         $fs->read();
         foreach ($fs->contents as $line) {
             $data = explode('::', $line, 2);
             if ($data[1]) {
                 foreach (array_keys($this->qset->questions) as $k) {
                     $field = $this->qset->getQuestionAttribute($k, 'FIELD');
                     if ($data[0] == $field) {
                         if (!is_array($this->responses[$k])) {
                             $this->responses[$k] = array();
                         }
                         array_push($this->responses[$k], $data[1]);
                         $this->satisfied[$k] = true;
                     }
                 }
             }
         }
     }
 }
Exemple #4
0
 /**
 	remove a name from the known users list.
 	@access public
 	**/
 function unreg()
 {
     $user = $this->getArg(1);
     if ($user) {
         $fs = new FileStorage(REG_USERS_FILE);
         $fs->read();
         $new = array();
         foreach ($fs->contents as $nick) {
             if ($nick != $user) {
                 $new[] = $nick;
             } else {
                 $found = true;
                 $this->pm($nick . " removed.");
             }
         }
         if (!$found) {
             $this->pm($nick . " wasnt in the list.");
         } else {
             $fs = new FileStorage(REG_USERS_FILE, FS_WRITE);
             $fs->write($new);
         }
     }
 }
 /**
 Reads the storage file to get bug items
 @access private
 @return void
 */
 function read()
 {
     $this->bugs = array();
     $fs = new FileStorage($this->bugfile, FS_READ);
     $fs->read();
     $bugs = $this->decode(current($fs->contents));
     if (is_array($bugs)) {
         foreach ($bugs as $b) {
             $this->bugs[] = get_object_vars($b);
         }
     }
 }
Exemple #6
0
}
// test loop
echo "Testing...\n";
Debug::timer();
$hits = array('ok' => 0, 'notfound' => 0, 'error' => 0, 'cantwrite' => 0, 'cantdelete' => 0);
for ($counter = 0; $counter < 1000; $counter++) {
    // write
    $ok = $storage->write(rand(0, COUNT_FILES), randomStr(), array());
    if ($ok === FALSE) {
        $hits['cantwrite']++;
    }
    // remove
    //$ok = $storage->remove(rand(0, COUNT_FILES));
    //if (!$ok) $hits['cantdelete']++;
    // read
    $res = $storage->read(rand(0, COUNT_FILES));
    // compare
    if ($res === NULL) {
        $hits['notfound']++;
    } elseif (checkStr($res)) {
        $hits['ok']++;
    } else {
        $hits['error']++;
    }
}
$time = Debug::timer();
echo "Results:\n";
Debug::dump($hits);
// expected results are:
//    [ok] => 1000       // should be 1000. If unlink() is used, sum [ok] + [notfound] should be 1000
//    [notfound] => 0    // means "file not found", should be 0 if delete() is not used
Exemple #7
0
 /**
 @access private
 @param string nick
 */
 function registered($u)
 {
     $fs = new FileStorage(REG_USERS_FILE);
     $fs->read();
     return in_array($u, $fs->contents);
 }
 function pmLink($handle)
 {
     $fs = new FileStorage($this->storage);
     $fs->read();
     foreach ($fs->contents as $line) {
         $x = explode('::', $line, 2);
         if ($x[0] == $handle) {
             $link = $x[1];
             // var replace
             foreach (range(1, 9) as $i) {
                 $link = str_replace("\${$i}", $this->getArg($i), $link);
             }
             $this->pm($link);
             return;
         }
     }
 }