コード例 #1
0
ファイル: Styling.php プロジェクト: erebot/styling
 /**
  * Parses a template into a DOM.
  *
  * \param string $source
  *      Template to parse.
  *
  * \retval Erebot::DOM
  *      DOM object constructed
  *      from the template.
  *
  * \throw ::InvalidArgumentException
  *      The template was malformed
  *      or invalid.
  */
 protected static function parseTemplate($source)
 {
     $source = '<msg xmlns="http://www.erebot.net/xmlns/erebot/styling">' . $source . '</msg>';
     $schema = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'styling.rng';
     $dom = new \Erebot\DOM();
     $dom->substituteEntities = true;
     $dom->resolveExternals = false;
     $dom->recover = true;
     $ue = libxml_use_internal_errors(true);
     $dom->loadXML($source);
     $valid = $dom->relaxNGValidate($schema);
     $errors = $dom->getErrors();
     libxml_use_internal_errors($ue);
     if (!$valid || count($errors)) {
         // Some unpredicted error occurred,
         // show some (hopefully) useful information.
         if (class_exists('\\Plop')) {
             $logger = \Plop::getInstance();
             $logger->error(print_r($errors, true));
         }
         throw new \InvalidArgumentException('Error while validating the message');
     }
     return $dom;
 }
コード例 #2
0
ファイル: TestCase.php プロジェクト: erebot/testenv
 public function run(PHPUnit_Framework_TestResult $result = NULL)
 {
     $this->setExpectedLogsFromAnnotations();
     $this->logStream = NULL;
     if (class_exists('Plop', TRUE)) {
         $logging = Plop::getInstance();
         $this->logStream = fopen('php://temp', 'a+');
         $handlers = new Plop_HandlersCollection();
         $handler = new Plop_Handler_Stream($this->logStream);
         $handler->setFormatter(new Plop_Formatter('%(levelname)s:%(message)s'));
         $handlers[] = $handler;
         $logging->getLogger()->setHandlers($handlers);
     }
     return parent::run($result);
 }