Example #1
0
 /**
  * Process logging data
  *
  * @param mixed $data    The data to process
  * @param bool  $display Whether to display the data to the user. Otherwise log it.
  * @param int   $level   The logging level for this data
  * @return void
  */
 protected function process($data, $display, $level)
 {
     // plugin can return false to stop the default logging method
     $params = array('level' => $level, 'msg' => $data, 'display' => $display, 'to_screen' => $display);
     if (!$this->hooks->trigger('debug', 'log', $params, true)) {
         return;
     }
     // Do not want to write to screen before page creation has started.
     // This is not fool-proof but probably fixes 95% of the cases when logging
     // results in data sent to the browser before the page is begun.
     if (!isset($GLOBALS['_ELGG']->pagesetupdone)) {
         $display = false;
     }
     // Do not want to write to JS or CSS pages
     if ($this->context->contains('js') || $this->context->contains('css')) {
         $display = false;
     }
     // don't display in simplecache requests
     $path = substr(current_page_url(), strlen(elgg_get_site_url()));
     if (preg_match('~^(cache|action)/~', $path)) {
         $display = false;
     }
     if ($display == true) {
         echo '<pre class="elgg-logger-data">';
         echo htmlspecialchars(print_r($data, true), ENT_QUOTES, 'UTF-8');
         echo '</pre>';
     }
     error_log(print_r($data, true));
 }
Example #2
0
 public function testContainsTellsYouIfAGivenContextIsInTheCurrentStack()
 {
     $context = new Context();
     $context->push('foo');
     $context->push('bar');
     $context->push('baz');
     $this->assertTrue($context->contains('foo'));
     $this->assertTrue($context->contains('bar'));
     $this->assertTrue($context->contains('baz'));
     $popped = $context->pop();
     $this->assertFalse($context->contains($popped));
     // TODO: remove once global state is fully deprecated (2.0)
     _elgg_services()->setValue('context', new Context());
     elgg_push_context('foo');
     elgg_push_context('bar');
     elgg_push_context('baz');
     $this->assertTrue(elgg_in_context('foo'));
     $this->assertTrue(elgg_in_context('bar'));
     $this->assertTrue(elgg_in_context('baz'));
     $popped = elgg_pop_context();
     $this->assertFalse(elgg_in_context($popped));
 }
Example #3
0
File: Logger.php Project: elgg/elgg
 /**
  * Process logging data
  *
  * @param mixed $data    The data to process
  * @param bool  $display Whether to display the data to the user. Otherwise log it.
  * @param int   $level   The logging level for this data
  * @return void
  */
 protected function process($data, $display, $level)
 {
     // plugin can return false to stop the default logging method
     $params = array('level' => $level, 'msg' => $data, 'display' => $display, 'to_screen' => $display);
     if (!$this->hooks->trigger('debug', 'log', $params, true)) {
         return;
     }
     // Do not want to write to JS or CSS pages
     if ($this->context->contains('js') || $this->context->contains('css')) {
         $display = false;
     }
     // don't display in simplecache requests
     $path = substr(current_page_url(), strlen(elgg_get_site_url()));
     if (preg_match('~^(cache|action|serve-file)/~', $path)) {
         $display = false;
     }
     if ($display == true) {
         echo '<pre class="elgg-logger-data">';
         echo htmlspecialchars(print_r($data, true), ENT_QUOTES, 'UTF-8');
         echo '</pre>';
     }
     error_log(print_r($data, true));
 }
Example #4
0
 /**
  * Recursive implementation of export
  *
  * @param  mixed $value The value to export
  * @param  integer $indentation The indentation level of the 2nd+ line
  * @param  SebastianBergmann\Exporter\Context $processed Contains all objects and arrays that have previously been rendered
  * @return string
  * @see    SebastianBergmann\Exporter\Exporter::export
  */
 protected function recursiveExport(&$value, $indentation, $processed = NULL)
 {
     if ($value === NULL) {
         return 'null';
     }
     if ($value === TRUE) {
         return 'true';
     }
     if ($value === FALSE) {
         return 'false';
     }
     if (is_float($value) && floatval(intval($value)) === $value) {
         return "{$value}.0";
     }
     if (is_resource($value)) {
         return sprintf('resource(%d) of type (%s)', $value, get_resource_type($value));
     }
     if (is_string($value)) {
         // Match for most non printable chars somewhat taking multibyte chars into account
         if (preg_match('/[^\\x09-\\x0d\\x20-\\xff]/', $value)) {
             return 'Binary String: 0x' . bin2hex($value);
         }
         return "'" . str_replace(array("\r\n", "\n\r", "\r"), array("\n", "\n", "\n"), $value) . "'";
     }
     $whitespace = str_repeat(' ', 4 * $indentation);
     if (!$processed) {
         $processed = new Context();
     }
     if (is_array($value)) {
         if (($key = $processed->contains($value)) !== FALSE) {
             return 'Array &' . $key;
         }
         $key = $processed->add($value);
         $values = '';
         if (count($value) > 0) {
             foreach ($value as $k => $v) {
                 $values .= sprintf('%s    %s => %s' . "\n", $whitespace, $this->recursiveExport($k, $indentation), $this->recursiveExport($value[$k], $indentation + 1, $processed));
             }
             $values = "\n" . $values . $whitespace;
         }
         return sprintf('Array &%s (%s)', $key, $values);
     }
     if (is_object($value)) {
         $class = get_class($value);
         if ($hash = $processed->contains($value)) {
             return sprintf('%s Object &%s', $class, $hash);
         }
         $hash = $processed->add($value);
         $values = '';
         $array = $this->toArray($value);
         if (count($array) > 0) {
             foreach ($array as $k => $v) {
                 $values .= sprintf('%s    %s => %s' . "\n", $whitespace, $this->recursiveExport($k, $indentation), $this->recursiveExport($v, $indentation + 1, $processed));
             }
             $values = "\n" . $values . $whitespace;
         }
         return sprintf('%s Object &%s (%s)', $class, $hash, $values);
     }
     return var_export($value, TRUE);
 }