Exemple #1
0
 /**
  * Build the full XML document for the notice.
  *
  * @return [String]
  *   the XML
  */
 public function asXml()
 {
     $exception = $this->_exception;
     $options = $this->_options;
     $builder = new Errbit_XmlBuilder();
     $self = $this;
     return $builder->tag('notice', array('version' => Errbit::API_VERSION), function ($notice) use($exception, $options, $self) {
         $notice->tag('api-key', $options['api_key']);
         $notice->tag('notifier', function ($notifier) {
             $notifier->tag('name', Errbit::PROJECT_NAME);
             $notifier->tag('version', Errbit::VERSION);
             $notifier->tag('url', Errbit::PROJECT_URL);
         });
         $notice->tag('error', function ($error) use($exception, $self) {
             $klass = Errbit_Notice::className($exception);
             $error->tag('class', $self->filterTrace($klass));
             $error->tag('message', $self->filterTrace(sprintf('%s: %s', $klass, $exception->getMessage())));
             $error->tag('backtrace', function ($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(Errbit_Notice::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', function ($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', function ($params) use($options) {
                         Errbit_Notice::xmlVarsFor($params, $options['parameters']);
                     });
                 }
                 if (!empty($options['session_data'])) {
                     $request->tag('session', function ($session) use($options) {
                         Errbit_Notice::xmlVarsFor($session, $options['session_data']);
                     });
                 }
                 if (!empty($options['cgi_data'])) {
                     $request->tag('cgi-data', function ($cgiData) use($options) {
                         Errbit_Notice::xmlVarsFor($cgiData, $options['cgi_data']);
                     });
                 }
             });
         }
         $notice->tag('server-environment', function ($env) use($options) {
             $env->tag('project-root', $options['project_root']);
             $env->tag('environment-name', $options['environment_name']);
             $env->tag('hostname', $options['hostname']);
         });
     })->asXml();
 }
Exemple #2
0
 private function _buildNoticeFor($exception, $options)
 {
     return Errbit_Notice::forException($exception, $options)->asXml();
 }