/**
 * Takes a hash and saves its contents to library/HTMLPurifier/ConfigSchema/
 */
function saveHash($hash)
{
    if ($hash === false) {
        return;
    }
    $dir = realpath(dirname(__FILE__) . '/../library/HTMLPurifier/ConfigSchema');
    $name = $hash['ID'] . '.txt';
    $file = $dir . '/' . $name;
    if (file_exists($file)) {
        trigger_error("File already exists; skipped {$name}");
        return;
    }
    $file = new FSTools_File($file);
    $file->open('w');
    $multiline = false;
    foreach ($hash as $key => $value) {
        $multiline = $multiline || strpos($value, "\n") !== false;
        if ($multiline) {
            $file->put("--{$key}--" . PHP_EOL);
            $file->put(str_replace("\n", PHP_EOL, $value) . PHP_EOL);
        } else {
            if ($key == 'ID') {
                $file->put("{$value}" . PHP_EOL);
            } else {
                $file->put("{$key}: {$value}" . PHP_EOL);
            }
        }
    }
    $file->close();
}
예제 #2
0
 public function testHandle()
 {
     $file = new FSTools_File('foo.txt');
     $this->assertFalse($file->exists());
     $file->open('w');
     $this->assertTrue($file->exists());
     $file->put('Foobar');
     $file->close();
     $file->open('r');
     $this->assertIdentical('F', $file->getChar());
     $this->assertFalse($file->eof());
     $this->assertIdentical('oo', $file->read(2));
     $this->assertIdentical('bar', $file->getLine());
     $this->assertTrue($file->eof());
 }