Beispiel #1
0
 protected function onShutdown()
 {
     // TODO: Allow client to switch this off
     $files = get_included_files();
     // exclude our own files
     $excluding = false;
     for ($i = 0; $i < count($files); $i++) {
         // TODO: Make this more reliable
         if (preg_match("/\\/FirePHP\\//", $files[$i]) || preg_match("/\\/FirePHPCore\\//", $files[$i]) || preg_match("/\\/Insight\\//", $files[$i]) || preg_match("/\\/Wildfire\\//", $files[$i]) || preg_match("/\\/Zend\\//", $files[$i])) {
             // potentially exclude
             $exclude = false;
             // start excluding when
             if (preg_match("/\\/FirePHP\\/Init.php\$/", $files[$i])) {
                 $excluding = true;
             } else {
                 // stop excluding after
                 if (preg_match("/\\/Wildfire\\/Protocol\\/Component.php\$/", $files[$i]) || -preg_match("/\\/Insight\\/Encoder\\/Default.php\$/", $files[$i]) || preg_match("/\\/Zend\\/Reflection\\/Class.php\$/", $files[$i]) || preg_match("/\\/Zend\\/Reflection\\/Property.php\$/", $files[$i]) || preg_match("/\\/Zend\\/Reflection\\/Method.php\$/", $files[$i]) || preg_match("/\\/Zend\\/Reflection\\/Docblock.php\$/", $files[$i]) || preg_match("/\\/Zend\\/Reflection\\/Docblock\\/Tag.php\$/", $files[$i]) || preg_match("/\\/Zend\\/Loader.php\$/", $files[$i]) || preg_match("/\\/Zend\\/Reflection\\/Parameter.php\$/", $files[$i])) {
                     $excluding = false;
                     $exclude = true;
                 } else {
                     // always exclude
                     if (preg_match("/\\/FirePHP\\//", $files[$i]) || preg_match("/\\/FirePHPCore\\//", $files[$i]) || preg_match("/\\/Insight\\//", $files[$i]) || preg_match("/\\/Wildfire\\//", $files[$i])) {
                         $exclude = true;
                     }
                 }
             }
             if ($excluding || $exclude) {
                 array_splice($files, $i, 1);
                 $i--;
             }
         }
     }
     Insight_Helper::to('request')->files()->loaded($files);
 }
Beispiel #2
0
 protected function onShutdown()
 {
     if (!$this->usedFilters || !$this->request->isClientPresent()) {
         return;
     }
     $this->request->storeInCache('filters', $this->usedFilters);
     Insight_Helper::to('selective')->getMessage()->meta(array("encoder" => "JSON"))->send(array("filters" => $this->usedFilters));
 }
Beispiel #3
0
 protected function onShutdown()
 {
     if (!$this->info) {
         return;
     }
     if (!$this->request->isClientPresent()) {
         return;
     }
     // only send info to client if it has changed
     $packageInfo = $this->request->getFromClientCache('package-info', false);
     if ($packageInfo == serialize($this->info)) {
         return;
     }
     $this->request->storeInClientCache('package-info', serialize($this->info), false);
     Insight_Helper::to('package')->getMessage()->meta(array("encoder" => "JSON", "target" => "info"))->send($this->info);
 }
Beispiel #4
0
 public static function init($configPath, $additionalConfig, $options = array())
 {
     if (self::$instance) {
         throw new Exception("Insight_Helper already initialized!");
     }
     try {
         // ensure min php version
         if (version_compare(phpversion(), '5.1') == -1) {
             throw new Exception('PHP version 5.1+ required. Your version: ' . phpversion());
         }
         // environment cleanup
         unset($GLOBALS['INSIGHT_AUTOLOAD']);
         unset($GLOBALS['INSIGHT_ADDITIONAL_CONFIG']);
         unset($GLOBALS['INSIGHT_FORCE_ENABLE']);
         $config = new Insight_Config();
         if (is_array($configPath)) {
             $config->loadFromArray($configPath, $additionalConfig);
         } else {
             $config->loadFromFile($configPath, $additionalConfig);
         }
         self::$instance = new self();
         self::$instance->setConfig($config);
         self::$instance->authorized = self::$instance->isClientAuthorized();
         self::$instance->forceEnabled = isset($options['forceEnable']) && $options['forceEnable'] === true ? true : false;
         if (self::$instance->authorized || self::$instance->forceEnabled) {
             // set a dummy channel if not authorized
             // this will prevent all data from being sent while keeping all channel logic and listeners working
             if (self::$instance->authorized !== true) {
                 self::$instance->channel = new Wildfire_Channel_Memory();
             }
             // ensure cache path works
             $cachePath = $config->getCachePath();
             if (!file_exists($cachePath)) {
                 $baseCachePath = $config->getCachePath(true);
                 if (!is_writable($baseCachePath)) {
                     throw new Exception('Error creating cache path. Insufficient permissions. Directory not writable: ' . $baseCachePath);
                 }
                 if (!mkdir($cachePath, 0775, true)) {
                     throw new Exception('Error creating cache path at: ' . $cachePath);
                 }
             }
             if (!is_dir($cachePath)) {
                 throw new Exception('Cache path not a directory: ' . $cachePath);
             }
             if (!is_writable($cachePath)) {
                 throw new Exception('Cache path not writable: ' . $cachePath);
             }
             // enable output buffering to disable flush() calls in code
             if (php_sapi_name() != 'cli') {
                 ob_start();
             }
             // always enable insight for now
             self::$instance->setEnabled(true);
             // flush on shutdown
             register_shutdown_function('Insight_Helper__shutdown');
             // set transport
             // NOTE: If running as CLI we don't need to keep data in file
             $transport = false;
             if (php_sapi_name() != 'cli') {
                 $transport = new Insight_Transport();
                 $transport->setConfig($config);
                 self::$instance->getChannel()->setTransport($transport);
             }
             // initialize server
             self::$instance->server = new Insight_Server();
             self::$instance->server->setHelper(self::$instance);
             self::$instance->server->setConfig($config);
             // NOTE: This may stop script execution if a transport data request is detected
             if ($transport) {
                 $transport->setServer(self::$instance->server);
                 if ($transport->listen() === true) {
                     self::$swallowDebugMessages = true;
                     exit;
                 }
             }
             // NOTE: This may stop script execution if a server request is detected
             if (self::$instance->server->listen() === true) {
                 self::$swallowDebugMessages = true;
                 exit;
             }
             // initialize request object
             self::$instance->request = new Insight_Request();
             self::$instance->request->setConfig($config);
             if ($clientInfo = self::$instance->getClientInfo()) {
                 self::$instance->request->setClientKey(implode(':', $clientInfo['authkeys']));
             }
             self::$instance->request->initAppRequest($_SERVER);
             // send package info
             // TODO: Figure out a way to not send this all the time
             //       Could be done via static data structures with checksums where the client announces which
             //       data structures it has by sending the checksum in the request headers
             if ($packageInfo = $config->getPackageInfo()) {
                 self::to('package')->setInfo($packageInfo);
             }
             //                self::to('controller')->setServerUrl(self::$instance->server->getUrl());
             // init some plugins so their shutdown callback will be called
             self::to('request')->files();
             // setup error and assertion tracking
             self::plugin('assertion')->onAssertionError(FirePHP::to('page')->console('Assertions'));
             self::plugin('error')->onError(FirePHP::to('page')->console('Errors'));
             self::plugin('error')->onException(FirePHP::to('page')->console('Errors'));
             // Look for x-insight trigger
             $insight = false;
             if (isset($_GET['x-insight'])) {
                 $insight = $_GET['x-insight'];
             }
             if (isset($_POST['x-insight'])) {
                 $insight = $_POST['x-insight'];
             }
             if ($insight == 'inspect' || Insight_Util::getRequestHeader('x-insight') == 'inspect') {
                 Insight_Helper::to('controller')->triggerInspect();
             }
         }
     } catch (Exception $e) {
         // disable sending of data
         if (isset(self::$instance)) {
             self::$instance->setEnabled(false);
         }
         header("HTTP/1.0 500 Internal Server Error");
         header("Status: 500 Internal Server Error");
         if (isset(self::$instance->authorized) && self::$instance->authorized) {
             header('x-insight-status: ERROR');
             header('x-insight-status-msg: ' . $e->getMessage());
         }
         if (!Insight_Helper::debug('Initialization Error: ' . $e->getMessage())) {
             throw $e;
         }
     }
     return self::$instance;
 }