Example #1
0
 /**
  * Initialize Consumerr WITHOUT enabling its error handlers. Usefull when error handling is done elsewhere.
  *
  * @param Configuration|string|array $configuration optionally set configuration @see setConfiguration
  * @return bool
  */
 public static function initialize($configuration = NULL)
 {
     if ($configuration) {
         self::setConfiguration($configuration);
     }
     if (!self::$configuration instanceof Configuration) {
         throw new InvalidConfigurationException("Consumerr is not properly configured.");
     }
     if (self::$enabled) {
         self::log("Multiple calls to initialize - ignore");
         return FALSE;
     }
     if (self::$configuration->isClientDisabled()) {
         self::log('Client IP is disabled by current configuration.');
         return FALSE;
         //nothing to do here
     }
     self::$enabled = TRUE;
     self::getTime();
     if (!self::isConsole()) {
         self::getAccess()->setUrl((isset($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off') ? 'https://' : 'http://') . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '')) . $_SERVER['REQUEST_URI']);
         if (isset($_SERVER['SERVER_NAME'])) {
             self::getAccess()->setServerName($_SERVER['SERVER_NAME']);
         }
         if (isset($_SERVER['REMOTE_ADDR'])) {
             self::getAccess()->setRemoteAddr($_SERVER['REMOTE_ADDR']);
         }
         if (isset($_SERVER['SCRIPT_NAME'])) {
             self::getAccess()->setName($_SERVER['SCRIPT_NAME']);
         }
         if (isset($_SERVER['HTTP_USER_AGENT'])) {
             self::getAccess()->setUserAgent($_SERVER['HTTP_USER_AGENT']);
         }
     } else {
         self::getAccess()->setName(self::getCliArguments());
         self::getAccess()->setBackgroundJob(TRUE);
     }
     self::registerSenderShutdownHandler();
     return TRUE;
 }