parseFile() public method

Parses a file that contains a single string-hash.
public parseFile ( string $file ) : array
$file string
return array
コード例 #1
0
 public function testHtmlt()
 {
     $parser = new HTMLPurifier_StringHashParser();
     $hash = $parser->parseFile($this->path);
     // assume parser normalizes to "\n"
     if (isset($hash['SKIPIF'])) {
         if (eval($hash['SKIPIF'])) {
             return;
         }
     }
     $this->config->set('Output.Newline', "\n");
     if (isset($hash['INI'])) {
         // there should be a more efficient way than writing another
         // ini file every time... probably means building a parser for
         // ini (check out the yaml implementation we saw somewhere else)
         $ini_file = $this->path . '.ini';
         file_put_contents($ini_file, $hash['INI']);
         $this->config->loadIni($ini_file);
     }
     $expect = isset($hash['EXPECT']) ? $hash['EXPECT'] : $hash['HTML'];
     $this->assertPurification(rtrim($hash['HTML']), rtrim($expect));
     if (isset($hash['INI'])) {
         unlink($ini_file);
     }
 }
コード例 #2
0
 public static function buildFromDirectory($dir = null)
 {
     $parser = new HTMLPurifier_StringHashParser();
     $builder = new HTMLPurifier_ConfigSchema_InterchangeBuilder();
     $interchange = new HTMLPurifier_ConfigSchema_Interchange();
     if (!$dir) {
         $dir = HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema/';
     }
     $info = parse_ini_file($dir . 'info.ini');
     $interchange->name = $info['name'];
     $files = array();
     $dh = opendir($dir);
     while (false !== ($file = readdir($dh))) {
         if (!$file || $file[0] == '.' || strrchr($file, '.') !== '.txt') {
             continue;
         }
         $files[] = $file;
     }
     closedir($dh);
     sort($files);
     foreach ($files as $file) {
         $builder->build($interchange, new HTMLPurifier_StringHash($parser->parseFile($dir . $file)));
     }
     return $interchange;
 }
コード例 #3
0
 public function buildFile($interchange, $file)
 {
     $parser = new HTMLPurifier_StringHashParser();
     $this->build($interchange, new HTMLPurifier_StringHash($parser->parseFile($file)));
 }