Example #1
0
 function testToBufferFailure()
 {
     mkdir(T_CACHE_DIR . 'test');
     $path = new T_File_Path(T_CACHE_DIR . 'test', 'common', 'css');
     $file = new T_File_Unlocked($path, 'wb');
     $file->write('somecontent');
     $file->close();
     $view = new T_File_View(T_CACHE_DIR . 'test', 'common', 'css');
     $view->delete();
     try {
         $view->toBuffer();
         $this->fail();
     } catch (T_Exception_File $e) {
     }
 }
Example #2
0
 function testCanFilterGetContent()
 {
     mkdir(T_CACHE_DIR . 'test');
     $f = new T_Test_Filter_Suffix();
     $path = $this->getPathObject(T_CACHE_DIR . 'test', 'source', 'txt');
     touch($path->__toString());
     $file = new T_File_Unlocked($path, 'wb');
     $len = $file->write('content');
     $file->close();
     unset($file);
     $this->assertSame($path->getContent($f), $f->transform('content'));
 }
Example #3
0
 * Load files and convert to SQL.
 */
$ftotal = 0;
$fbatch = FILE_BATCH_SIZE === false ? '' : 0;
$sql = new T_File_Unlocked(new T_File_Path(T_ROOT_DIR . 'acl/_sql', 'wordlist' . $fbatch, 'sql'), 'wb');
foreach ($files as $f) {
    $words = array();
    $fp = fopen($f->__toString(), 'rb');
    while (!feof($fp)) {
        $w = trim(fgets($fp, 4096));
        if (mb_strlen($w) >= MIN_WORD_LENGTH && ctype_alnum($w)) {
            $words[] = "'{$w}'";
        }
        if (count($words) > WORD_BATCH_SIZE) {
            $sql->write('REPLACE INTO pwd_dictionary (word) VALUES (' . implode('),(', $words) . ');' . EOL);
            $ftotal += count($words);
            $words = array();
            // possibly need a new file at this point..
            if (FILE_BATCH_SIZE !== false && $ftotal > FILE_BATCH_SIZE) {
                $ftotal = 0;
                ++$fbatch;
                $sql->close();
                $sql = new T_File_Unlocked(new T_File_Path(T_ROOT_DIR . 'acl/_sql', 'wordlist' . $fbatch, 'sql'), 'wb');
            }
        }
    }
    if (count($words)) {
        $sql->write('REPLACE INTO pwd_dictionary (word) VALUES (' . implode('),(', $words) . ');' . EOL);
    }
}
$sql->close();
Example #4
0
 /**
  * "Swap" a write file on close.
  *
  * If the file has been opened in write mode, the file being written has
  * been opened and executed in a temporary location. When the file is
  * closed, the write needs to be committed (atomically) by renaming the
  * temporary file to its proper filename.
  */
 function close()
 {
     parent::close();
     // prevents code recursively calling this fn.
     if ($this->fswap !== false) {
         $this->rename($this->fswap);
         $this->fswap = false;
     }
 }