public function testSimpleObjectInXml()
 {
     $foo = new \StdClass();
     $foo->first = "First";
     $foo->second = "Second";
     $foo->third = array("1", "2");
     $this->config['session_data'] = array($foo);
     $notice = new Notice(new \Exception(), $this->config);
     $xml = $notice->asXml();
     $dom = new \DOMDocument();
     $dom->loadXML($xml);
     $valid = $dom->schemaValidate(dirname(__FILE__) . '/../../../../Resources/xsd/XSD.xml');
     $this->assertTrue($valid, 'Not Valid XSD');
 }
 protected function buildNoticeFor($exception, $options)
 {
     return Notice::forException($exception, $options)->asXml();
 }
Beispiel #3
0
 /**
  * Build the full XML document for the notice.
  *
  * @return string the XML
  */
 public function asXml()
 {
     $exception = $this->exception;
     $options = $this->options;
     $builder = new XmlBuilder();
     $self = $this;
     return $builder->tag('notice', '', array('version' => Errbit::API_VERSION), function (XmlBuilder $notice) use($exception, $options, $self) {
         $notice->tag('api-key', $options['api_key']);
         $notice->tag('notifier', '', array(), function (XmlBuilder $notifier) {
             $notifier->tag('name', Errbit::PROJECT_NAME);
             $notifier->tag('version', Errbit::VERSION);
             $notifier->tag('url', Errbit::PROJECT_URL);
         });
         $notice->tag('error', '', array(), function (XmlBuilder $error) use($exception, $self) {
             $class = Notice::className($exception);
             $error->tag('class', $self->filterTrace($class));
             $error->tag('message', $self->filterTrace(sprintf('%s: %s', $class, $exception->getMessage())));
             $error->tag('backtrace', '', array(), function (XmlBuilder $backtrace) use($exception, $self) {
                 $trace = $exception->getTrace();
                 $file1 = $exception->getFile();
                 $backtrace->tag('line', '', array('number' => $exception->getLine(), 'file' => !empty($file1) ? $self->filterTrace($file1) : '<unknown>', 'method' => "<unknown>"));
                 // if there is no trace we should add an empty element
                 if (empty($trace)) {
                     $backtrace->tag('line', '', array('number' => '', 'file' => '', 'method' => ''));
                 } else {
                     foreach ($trace as $frame) {
                         $backtrace->tag('line', '', array('number' => isset($frame['line']) ? $frame['line'] : 0, 'file' => isset($frame['file']) ? $self->filterTrace($frame['file']) : '<unknown>', 'method' => $self->filterTrace($self->formatMethod($frame))));
                     }
                 }
             });
         });
         if (!empty($options['url']) || !empty($options['controller']) || !empty($options['action']) || !empty($options['parameters']) || !empty($options['session_data']) || !empty($options['cgi_data'])) {
             $notice->tag('request', '', array(), function (XmlBuilder $request) use($options) {
                 $request->tag('url', !empty($options['url']) ? $options['url'] : '');
                 $request->tag('component', !empty($options['controller']) ? $options['controller'] : '');
                 $request->tag('action', !empty($options['action']) ? $options['action'] : '');
                 if (!empty($options['parameters'])) {
                     $request->tag('params', '', array(), function (XmlBuilder $params) use($options) {
                         Notice::xmlVarsFor($params, $options['parameters']);
                     });
                 }
                 if (!empty($options['session_data'])) {
                     $request->tag('session', '', array(), function (XmlBuilder $session) use($options) {
                         Notice::xmlVarsFor($session, $options['session_data']);
                     });
                 }
                 if (!empty($options['cgi_data'])) {
                     $request->tag('cgi-data', '', array(), function (XmlBuilder $cgiData) use($options) {
                         Notice::xmlVarsFor($cgiData, $options['cgi_data']);
                     });
                 }
             });
         }
         if (!empty($options['user'])) {
             $notice->tag('user-attributes', '', array(), function (XmlBuilder $user) use($options) {
                 Notice::xmlVarsFor($user, $options['user']);
             });
         }
         $notice->tag('server-environment', '', array(), function (XmlBuilder $env) use($options) {
             $env->tag('project-root', $options['project_root']);
             $env->tag('environment-name', $options['environment_name']);
             $env->tag('hostname', $options['hostname']);
         });
     })->asXml();
 }