protected function validate() { $file = $this->rootPath; if (!is_dir($file) || !is_readable($file)) { throw new Exception('Program root path "' . $file . '" does not exist or is not readable.'); } // Ensure program is declared in a directory we have access to if (!Insight_Helper::getInstance()->getServer()->canServeFile($file)) { throw new Exception('Program "' . $file . '" cannot be access remotely. You need to configure acces with ["implements"]["cadorn.org/insight/@meta/config/0"]["paths"].'); } $descriptorFile = $file . '/package.json'; if (!is_file($descriptorFile) || !is_readable($descriptorFile)) { throw new Exception('Package descriptor for program not accessbile: ' . $descriptorFile); } $this->descriptor = $descriptor = json_decode(file_get_contents($descriptorFile), true); if (!json_decode(file_get_contents($descriptorFile))) { throw new Exception('Package descriptor for program not valid JSON: ' . $descriptorFile); } if (!isset($descriptor['mappings'])) { throw new Exception('Package descriptor must declare "mappings": ' . $descriptorFile); } if (!isset($descriptor['implements'])) { throw new Exception('Package descriptor must declare "implements": ' . $descriptorFile); } if (!isset($descriptor['implements']['cadorn.org/insight/@meta/plugin/0'])) { throw new Exception('Package descriptor must declare "implements" -> "cadorn.org/insight/@meta/plugin/0": ' . $descriptorFile); } if (!isset($descriptor['implements']['cadorn.org/insight/@meta/plugin/0']['options'])) { throw new Exception('Package descriptor must declare "implements" -> "cadorn.org/insight/@meta/plugin/0" -> "options": ' . $descriptorFile); } if (!isset($descriptor['implements']['cadorn.org/insight/@meta/plugin/0']['options']['label'])) { throw new Exception('Package descriptor must declare "implements" -> "cadorn.org/insight/@meta/plugin/0" -> "options" -> "label": ' . $descriptorFile); } if (!isset($descriptor['implements']['cadorn.org/insight/@meta/plugin/0']['main'])) { $descriptor['implements']['cadorn.org/insight/@meta/plugin/0']['main'] = 'main'; } return $file; }
protected function loadProgram($class, $file = null) { if (!class_exists($class, false)) { if (!$file) { // assuming $class is accessible via autoloader new $class(); } else { if (!is_file($file) || !is_readable($file)) { throw new Exception('File not accessible: ' . $file); } if (!(require_once $file)) { throw new Exception('Error while requiring file: ' . $file); } if (!class_exists($class, false)) { throw new Exception('Class "' . $class . '" not declared in file: ' . $file); } } } $reflectionClass = new ReflectionClass($class); // Ensure class is declared in a directory we have access to if (!Insight_Helper::getInstance()->getServer()->canServeFile($reflectionClass->getFileName())) { throw new Exception('Class "' . $class . '" in file "' . $reflectionClass->getFileName() . ' cannot be access remotely. You need to configure acces with ["implements"]["cadorn.org/insight/@meta/config/0"]["paths"].'); } $program = new $class(); if (!is_a($program, 'Insight_Program_JavaScript')) { throw new Exception('Class "' . $class . '" in file "' . $reflectionClass->getFileName() . '" does not inherit from Insight_Program_JavaScript'); } return $program; }
// Print all headers to be sent $html = array(); $html[] = '<div class="box">'; $html[] = '<div class="header">'; $html[] = 'headers_list()'; $html[] = '</div>'; $html[] = '<div id="response-headers-body" class="body">'; foreach (headers_list() as $header) { $html[] = $header . '<br/>'; } $html[] = '</div>'; $html[] = '</div>'; echo implode("\n", $html); // Print payload to be fetched by client if applicable if (class_exists('Insight_Helper', false)) { $insight = Insight_Helper::getInstance(); if ($insight->getEnabled()) { $html = array(); $html[] = '<div class="box">'; $html[] = '<div class="header">'; $html[] = 'Payload'; $html[] = '</div>'; $html[] = '<div id="payload-body" class="body">'; $transport = $insight->getChannel()->getTransport(); $contents = $transport->getData($transport->getLastKey()); $contents = str_replace("\n", '<br/>', $contents); $html[] = $contents; $html[] = '</div>'; $html[] = '</div>'; echo implode("\n", $html); }
function Insight_Helper__shutdown() { $insight = Insight_Helper::getInstance(); // only send headers if this was not a transport request if (class_exists('Insight_Server', false) && Insight_Util::getRequestHeader('x-insight') == "transport") { return; } // if disabled do not flush headers if (!$insight->getEnabled()) { return; } // call shutdown for all APIs $apis = $insight->getApis(); if ($apis) { foreach ($apis as $name => $obj) { if (method_exists($obj, '_shutdown')) { $obj->_shutdown(); } } } Insight_Helper::debug('Flushing headers'); $insight->getDispatcher()->getChannel()->flush(false, true); if ($insight->hasListenersFor('payload')) { $transport = $insight->getChannel()->getTransport(); $contents = $transport->getData($transport->getLastKey()); foreach ($insight->getListenersFor('payload') as $listener) { $listener->onPayload($insight->getRequest, $contents); } } // if not authorized we now destroy the cached data as it is no longer needed // for later catching if ($insight->getAuthorized() !== true) { $transport = $insight->getChannel()->getTransport(); $file = $transport->getPath($transport->getLastKey()); unlink($file); } }
<?php // NOTE: You must have FirePHP Companion installed (http://www.christophdorn.com/Tools/) // See FirePHP Companion or Firebug Console for result (depending on $_GET['target']) define('INSIGHT_CONFIG_PATH', dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'package.json'); // force-enable FirePHP define('FIREPHP_ACTIVATED', true); require_once 'FirePHP/Init.php'; $console = FirePHP::to('page')->console(); if (isset($_GET['target'])) { // set by the drop-down in the reference $console = FirePHP::to($_GET['target'])->console(); if ($_GET['target'] == 'request') { FirePHP::to('controller')->triggerInspect(); } } // register a listener class PayloadListener { public function onPayload($request, $payload) { echo $payload; } } Insight_Helper::getInstance()->registerListener('payload', new PayloadListener()); // send a test message $console->log('Hello World');
protected static function _logUpgradeClientMessage() { if (self::$upgradeClientMessageLogged) { return; } // x-insight: activate request header is sent and FirePHP Extension detected, but not wildfire/insight client $info = Insight_Helper::getInstance()->getClientInfo(); if ($info['client'] == 'firephp' && Insight_Util::getRequestHeader('x-insight') == 'activate') { self::$upgradeClientMessageLogged = true; $firephp = self::getInstance(); $enabled = $firephp->getEnabled(); $firephp->setEnabled(true); $firephp->info('Your client only supports some features of the FirePHP library being used on the server. See http://upgrade.firephp.org/ for information on how to upgrade your client.'); $firephp->setEnabled($enabled); } }
<?php // NOTE: You must have FirePHP Companion installed (http://www.christophdorn.com/Tools/) // See Firebug Console for result define('INSIGHT_CONFIG_PATH', dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'package.json'); require_once 'FirePHP/Init.php'; $payload = array(); $payload[] = 'x-wf-protocol-1: http://registry.pinf.org/cadorn.org/wildfire/@meta/protocol/component/0.1.0'; $payload[] = 'x-wf-1-index: 3'; $payload[] = 'x-wf-1-1-receiver: http://registry.pinf.org/cadorn.org/insight/@meta/receiver/insight/package/0'; $payload[] = 'x-wf-1-1-1-sender: http://registry.pinf.org/cadorn.org/github/firephp-libs/programs/standalone/examples/TestRunner/?lib=cadorn.org/github/firephp-libs/packages/insight@' . FirePHP::VERSION; $payload[] = 'x-wf-1-1-1-1: 350|{"target":"info"}|{"links":{"quick":{"Homepage":"http:\\/\\/github.com\\/cadorn\\/firephp-libs\\/tree\\/master\\/programs\\/standalone\\/examples\\/","Bugs":"http:\\/\\/github.com\\/cadorn\\/firephp-libs\\/issues","Discuss":"http:\\/\\/groups.google.com\\/group\\/firephp-dev","Follow":"http:\\/\\/twitter.com\\/firephplib"}},"description":"FirePHP Examples: Test Runner"}|'; $payload[] = 'x-wf-1-2-receiver: http://registry.pinf.org/cadorn.org/insight/@meta/receiver/insight/controller/0'; $payload[] = 'x-wf-1-2-1-sender: http://registry.pinf.org/cadorn.org/github/firephp-libs/programs/standalone/examples/TestRunner/?lib=cadorn.org/github/firephp-libs/packages/insight@' . FirePHP::VERSION; $payload[] = 'x-wf-1-2-1-2: 125||{"serverUrl":"http:\\/\\/reference.developercompanion.com\\/Tools\\/FirePHPCompanion\\/Run\\/Examples\\/TestRunner\\/_insight_.php"}|'; $payload[] = 'x-wf-1-3-receiver: http://registry.pinf.org/cadorn.org/insight/@meta/receiver/console/page/0'; $payload[] = 'x-wf-1-3-1-sender: http://registry.pinf.org/cadorn.org/github/firephp-libs/programs/standalone/examples/TestRunner/?lib=cadorn.org/github/firephp-libs/packages/insight@' . FirePHP::VERSION; $payload[] = 'x-wf-1-3-1-3: 386|{"context":"page","target":"console","priority":"log","file":"\\/Users\\/cadorn\\/pinf\\/workspaces\\/github.com\\/cadorn\\/firephp-libs\\/programs\\/standalone\\/examples\\/TestRunner\\/insight-devcomp\\/snippets\\/PayloadListener.php","line":33,"lang.id":"registry.pinf.org\\/cadorn.org\\/github\\/renderers\\/packages\\/php\\/master"}|{"origin":{"type":"text","text":"Hello World","lang.type":"string"}}|'; Insight_Helper::getInstance()->relayPayload(implode("\n", $payload));