示例#1
0
 /**
  * @param string $filename
  * @param FileReport $report
  * @return bool|string
  */
 private function getSchemaValidationSource($filename, $report)
 {
     if (preg_match('/^(http|https|ftp):/i', $filename) === 0) {
         if (file_exists($filename) === false) {
             $filename = $report->getFile()->getPath() . '/' . $filename;
         }
         if (!is_readable($filename)) {
             $report->reportProblem('unable to validate, schema file is not readable: ' . $filename);
             return false;
         }
     }
     if (isset($this->cache[$filename])) {
         return $this->cache[$filename];
     }
     $validationSource = @file_get_contents($filename);
     if ($validationSource === false) {
         $report->reportProblem('unable to load schema file from: ' . $filename);
         return false;
     }
     if (empty($validationSource)) {
         $report->reportProblem(sprintf('xsd validation file is empty ("%s").', $filename));
         return false;
     }
     return $this->cache[$filename] = $validationSource;
 }
示例#2
0
 /**
  * @inheritdoc
  */
 public function validateFile(FileReport $report)
 {
     $realPath = $report->getFile()->getRealPath();
     if (is_file($realPath) === false) {
         $report->reportProblem('file not found: ' . $realPath);
         return false;
     }
     if (is_readable($realPath) === false) {
         $report->reportProblem('file not readable: ' . $realPath);
         return false;
     }
     libxml_clear_errors();
     $domDoc = new \DOMDocument();
     $domDoc->load($realPath, LIBXML_NOERROR | LIBXML_NOWARNING | LIBXML_PEDANTIC);
     $errors = libxml_get_errors();
     foreach ($this->formatter->formatErrors($errors) as $problem) {
         $report->reportProblem($problem);
     }
     return !$report->hasProblems();
 }