Example #1
0
 /**
  * Filters a supplied `array` of `$params`, searching for `$keys` and
  * replacing each occurance with `[FILTERED]`.
  *
  * @param   array  $keys
  * @param   array  $params Parameters to filter.
  * @return  array  Filtered parameters.
  */
 public static function params(array $keys = array(), $params = array())
 {
     if (empty($keys) or empty($params)) {
         return $params;
     }
     foreach ($params as $param => &$value) {
         if (Arr::is_array($value)) {
             $value = self::params($keys, $value);
         } elseif (!is_integer($param) and in_array($param, $keys)) {
             $value = '[FILTERED]';
         }
     }
     return $params;
 }
Example #2
0
 /**
  * Creates a predefined environment using the default environment
  *
  * Extending classes that have their own setUp() should call
  * parent::setUp()
  */
 public function setUp()
 {
     $this->_helpers = new Helpers();
     if (!isset($this->_environment_default['\\Honeybadger\\Honeybadger::$config'])) {
         $api_key = Arr::get($_SERVER, 'HONEYBADGER_API_KEY');
         $config = new Config(Arr::merge(array('project_root' => realpath(__DIR__ . '/../..'), 'framework' => 'PHPUnit', 'environment_name' => 'testing', 'api_key' => empty($api_key) ? NULL : $api_key), $this->_default_config));
         $this->_environment_default['\\Honeybadger\\Honeybadger::$config'] = $config;
     }
     if (!isset($this->_environment_default['\\Honeybadger\\Honeybadger::$sender'])) {
         $this->_environment_default['\\Honeybadger\\Honeybadger::$sender'] = new Sender();
     }
     if (!isset($this->_environment_default['\\Honeybadger\\Honeybadger::$logger'])) {
         $this->_environment_default['\\Honeybadger\\Honeybadger::$logger'] = new Logger\Test();
     }
     $this->setEnvironment($this->_environment_default);
 }
Example #3
0
 /**
  * Returns an array of all configurable options merged with `$config`.
  *
  * @param   array  $config  Options to merge with configuration
  * @return  array  The merged configuration.
  */
 public function merge(array $config = array())
 {
     return Arr::merge($this->as_array(), $config);
 }
 private static function build_notice_for($exception, array $options = array())
 {
     if ($exception instanceof \Exception) {
         $options['exception'] = self::unwrap_exception($exception);
     } elseif (Arr::is_array($exception)) {
         $options = Arr::merge($options, $exception);
     }
     return Notice::factory($options);
 }
Example #5
0
 public function __construct(array $args = array())
 {
     // Store self to allow access in callbacks.
     self::$current = $this;
     $this->args = $args;
     $this->cgi_data = Environment::factory(Arr::get($args, 'cgi_data'));
     $this->project_root = Arr::get($args, 'project_root');
     $this->url = Arr::get($args, 'url', $this->cgi_data['url']);
     $this->environment_name = Arr::get($args, 'environment_name');
     $this->notifier_name = Arr::get($args, 'notifier_name');
     $this->notifier_version = Arr::get($args, 'notifier_version');
     $this->notifier_url = Arr::get($args, 'notifier_url');
     $this->ignore = Arr::get($args, 'ignore', array());
     $this->ignore_by_filters = Arr::get($args, 'ignore_by_filters', array());
     $this->backtrace_filters = Arr::get($args, 'backtrace_filters', array());
     $this->params_filters = Arr::get($args, 'params_filters', array());
     if (isset($args['parameters'])) {
         $this->params = $args['parameters'];
     } elseif (isset($args['params'])) {
         $this->params = $args['params'];
     }
     if (isset($args['component'])) {
         $this->component = $args['component'];
     } elseif (isset($args['controller'])) {
         $this->component = $args['controller'];
     } elseif (isset($this->params['controller'])) {
         $this->component = $this->params['controller'];
     }
     if (isset($args['action'])) {
         $this->action = $args['action'];
     } elseif (isset($this->params['action'])) {
         $this->action = $this->params['action'];
     }
     $this->exception = Arr::get($args, 'exception');
     if ($this->exception instanceof \Exception) {
         $backtrace = $this->exception->getTrace();
         if (empty($backtrace)) {
             $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
         }
         $this->error_class = get_class($this->exception);
         $this->error_message = HoneybadgerError::text($this->exception);
     } else {
         if (isset($args['backtrace']) and is_array($args['backtrace'])) {
             $backtrace = $args['backtrace'];
         } else {
             $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
         }
         $this->error_class = Arr::get($args, 'error_class');
         $this->error_message = Arr::get($args, 'error_message', 'Notification');
     }
     $this->backtrace = Backtrace::parse($backtrace, array('filters' => $this->backtrace_filters));
     $this->hostname = gethostname();
     $this->source_extract_radius = Arr::get($args, 'source_extract_radius', 2);
     $this->source_extract = $this->extract_source_from_backtrace();
     $this->send_request_session = Arr::get($args, 'send_request_session', TRUE);
     $this->find_session_data();
     $this->clean_params();
     $this->set_context();
 }
Example #6
0
 /**
  * Unfortunately, PHP has no separation between the shell and
  * request environments. This means sensitive data such as database
  * information (it's common practice to set these when using services like
  * Heroku and Pagoda Box) must be filtered out.
  *
  * The following steps are taken to alleviate this issue:
  *
  * * Only allow the
  *   [predefined variables](http://php.net/manual/en/reserved.variables.server.php)
  *   in `$_SERVER`.
  *
  * * Allow variables prefixed with `HTTP_` (HTTP headers).
  *
  * @return  array  The filtered PHP request environment.
  */
 private function sanitized_php_environment()
 {
     $env = Arr::overwrite($this->allowed_php_environment_keys, $_SERVER);
     foreach ($_SERVER as $key => $value) {
         if (strpos($key, 'HTTP_') === 0) {
             $env[$key] = $value;
         }
     }
     if (!empty($_COOKIE)) {
         // Add cookies
         $env['rack.request.cookie_hash'] = $_COOKIE;
     }
     return array_filter($env);
 }
Example #7
0
 /**
  * Combines the request and route parameters into one array for
  * Honeybadger notices.
  *
  * @param   Slim\Http\Request  $request
  * @return  array  The combined request and route parameters.
  */
 private function combined_params($request)
 {
     $router = $this->app->router();
     // Find the matching route for the request, to extract parameters for
     // routes such as: `/books/:id`.
     $router->getMatchedRoutes($request->getMethod(), $request->getPathInfo());
     if ($route = $router->getCurrentRoute()) {
         $params = $route->getParams();
     } else {
         $params = array();
     }
     // Merge the route and request parameters into one array.
     return Arr::merge($request->params(), $params);
 }
Example #8
0
 /**
  *
  * @test
  * @dataProvider provider_flatten
  */
 public function test_flatten($source, $expected)
 {
     $this->assertSame($expected, Arr::flatten($source));
 }