Пример #1
0
 /**
  * Encode JSON response and immediately send
  *
  * @param  mixed   $data
  * @param  boolean|array $keepLayouts
  * NOTE:   if boolean, establish $keepLayouts to true|false
  *         if array, admit params for Zend_Json::encode as enableJsonExprFinder=>true|false
  *         if $keepLayouts and parmas for Zend_Json::encode are required
  *         then, the array can contains a 'keepLayout'=>true|false
  *         that will not be passed to Zend_Json::encode method but will be passed
  *         to Zend_View_Helper_Json
  * @param  bool $wrap
  * @return string|void
  */
 public function sendJson($data, $keepLayouts = false, $wrap = true)
 {
     if (!is_array($data)) {
         return parent::sendJson($data, $keepLayouts);
     }
     if (isset($data['success']) && !is_bool($data['success'])) {
         $data['success'] = (bool) $data['success'];
     }
     if ($wrap) {
         $messages = Axis::message()->getAll();
         //            if (isset(false === $data['success']) && $data['success']) {
         //                unset($messages['success']);
         //            }
         $data = array_merge(array('messages' => $messages), $data);
     }
     if ($this->_data) {
         $data = array_merge_recursive($this->_data, $data);
     }
     $data = $this->encodeJson($data, $keepLayouts);
     $response = $this->getResponse();
     $response->setBody($data);
     if (!$this->suppressExit) {
         Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
         //Axis_FirePhp
         $response->sendResponse();
         exit;
     }
     return $data;
 }
Пример #2
0
 public static function getChannel()
 {
     if (!self::$channel) {
         self::$channel = \Zend_Wildfire_Channel_HttpHeaders::getInstance();
     }
     return self::$channel;
 }
 public function testNoQueries()
 {
     $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
     $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
     Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
     // call plugin postDispatch to record profiler data
     $this->_plugin->dispatchLoopShutdown();
     $messages = $protocol->getMessages();
     $this->assertFalse($messages);
 }
Пример #4
0
 public static function start($config, $db)
 {
     self::$_config = $config;
     if (self::$_config['Zend_Db_Profiler_Firebug'] == false) {
         return;
     }
     $profiler = new Zend_Db_Profiler_Firebug('All DB Queries');
     $profiler->setEnabled(true);
     $db->setProfiler($profiler);
     $request = new Zend_Controller_Request_Http();
     self::$_response = new Zend_Controller_Response_Http();
     self::$_channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
     self::$_channel->setRequest($request);
     self::$_channel->setResponse(self::$_response);
     ob_start();
 }
Пример #5
0
 /**
  * send to Firebug
  *
  * @param $content
  */
 public function sendToFirebug($content)
 {
     $writer = new Zend_Log_Writer_Firebug();
     $logger = new Zend_Log($writer);
     $request = new Zend_Controller_Request_Http();
     $response = new Zend_Controller_Response_Http();
     $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
     $channel->setRequest($request);
     $channel->setResponse($response);
     // Start output buffering
     ob_start();
     $logger->log($content, Zend_Log::INFO);
     // Flush log data to browser
     $channel->flush();
     $response->sendHeaders();
 }
Пример #6
0
 public function test2PhpAction()
 {
     Zend_Registry::get('logger')->debug('Test Logging Message');
     $this->view->json('Sample Json Data');
     $this->getHelper('Json')->suppressExit = true;
     $this->getHelper('Json')->sendJson('Test JSON data');
     Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
     $this->getHelper('Json')->getResponse()->sendResponse();
     exit;
     /*
             Zend_Registry::get('logger')->debug('Test Logging Message');      
             $this->view->json('Sample Json Data');
     
             $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
             $viewRenderer->setNoRender(true);
     */
 }
Пример #7
0
 /**
  * Display profiling results and flush output buffer
  */
 public function display()
 {
     $firebugMessage = new Zend_Wildfire_Plugin_FirePhp_TableMessage($this->_renderCaption());
     $firebugMessage->setHeader(array_keys($this->_getColumns()));
     foreach ($this->_getTimers() as $timerId) {
         $row = array();
         foreach ($this->_getColumns() as $columnId) {
             $row[] = $this->_renderColumnValue($timerId, $columnId);
         }
         $firebugMessage->addRow($row);
     }
     Zend_Wildfire_Plugin_FirePhp::getInstance()->send($firebugMessage);
     // setup the wildfire channel
     $firebugChannel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
     $firebugChannel->setRequest($this->_request ? $this->_request : new Zend_Controller_Request_Http());
     $firebugChannel->setResponse($this->_response ? $this->_response : new Zend_Controller_Response_Http());
     // flush the wildfire headers into the response object
     $firebugChannel->flush();
     // send the response headers
     $firebugChannel->getResponse()->sendHeaders();
     ob_end_flush();
 }
Пример #8
0
 /**
  * Display profiling results and flush output buffer
  *
  * @param Stat $stat
  * @return void
  */
 public function display(Stat $stat)
 {
     $firebugMessage = new \Zend_Wildfire_Plugin_FirePhp_TableMessage($this->_renderCaption());
     $firebugMessage->setHeader(array_keys($this->_columns));
     foreach ($this->_getTimerIds($stat) as $timerId) {
         $row = array();
         foreach ($this->_columns as $column) {
             $row[] = $this->_renderColumnValue($stat->fetch($timerId, $column), $column);
         }
         $firebugMessage->addRow($row);
     }
     \Zend_Wildfire_Plugin_FirePhp::send($firebugMessage);
     // setup the wildfire channel
     $firebugChannel = \Zend_Wildfire_Channel_HttpHeaders::getInstance();
     $firebugChannel->setRequest($this->getRequest());
     $firebugChannel->setResponse($this->getResponse());
     // flush the wildfire headers into the response object
     $firebugChannel->flush();
     // send the response headers
     $firebugChannel->getResponse()->sendHeaders();
     ob_end_flush();
 }
Пример #9
0
function __exit()
{
    $front = Zend_Controller_Front::getInstance();
    $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
    //$channel->setRequest(new Zend_Controller_Request_Http());
    //$channel->setResponse(new Zend_Controller_Response_Http());
    $channel->getResponse();
    $channel->getRequest();
    $channel->flush();
    $channel->getResponse()->sendHeaders();
    //xdebug_get_code_coverage();
}
Пример #10
0
        $profiler->setEnabled(true);
        $db = Zend_Db::factory('PDO_SQLITE', array('dbname' => ':memory:'));
        $db->setProfiler($profiler);
        Zend_Registry::set('db', $db);
        $controller = Zend_Controller_Front::getInstance();
        $controller->setParam('useDefaultControllerAlways', true);
        $controller->setParam('noViewRenderer', true);
        $controller->setControllerDirectory(dirname(dirname(dirname(dirname(__FILE__)))) . '/application/controllers/Boot/Zend-Db-Profiler-Firebug');
        $controller->dispatch();
        print 'Test Doc Example with Controller';
        break;
    case 'WithoutController':
        $profiler = new Zend_Db_Profiler_Firebug('All DB Queries');
        $profiler->setEnabled(true);
        $db = Zend_Db::factory('PDO_SQLITE', array('dbname' => ':memory:'));
        $db->setProfiler($profiler);
        $request = new Zend_Controller_Request_Http();
        $response = new Zend_Controller_Response_Http();
        $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
        $channel->setRequest($request);
        $channel->setResponse($response);
        $db->getConnection()->exec('CREATE TABLE foo (
                                      id      INTEGNER NOT NULL,
                                      col1    VARCHAR(10) NOT NULL
                                    )');
        $db->insert('foo', array('id' => 1, 'col1' => 'original'));
        $channel->flush();
        $response->sendHeaders();
        print 'Test Doc Example without Controller';
        break;
}
Пример #11
0
 /**
  * @group ZF-10537
  */
 public function testFileLineOffsets()
 {
     $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
     $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
     $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
     $firephp->setOption('includeLineNumbers', true);
     $firephp->setOption('maxTraceDepth', 0);
     $lines = array();
     // NOTE: Do NOT separate the following pairs otherwise the line numbers will not match for the test
     // Message number: 1
     $lines[] = __LINE__ + 1;
     $this->_logger->log('Hello World', Zend_Log::INFO);
     // Message number: 2
     $this->_logger->addPriority('TRACE', 8);
     $this->_writer->setPriorityStyle(8, 'TRACE');
     $lines[] = __LINE__ + 1;
     $this->_logger->trace('Trace to here');
     // Message number: 3
     $this->_logger->addPriority('TABLE', 9);
     $this->_writer->setPriorityStyle(9, 'TABLE');
     $table = array('Summary line for the table', array(array('Column 1', 'Column 2'), array('Row 1 c 1', ' Row 1 c 2'), array('Row 2 c 1', ' Row 2 c 2')));
     $lines[] = __LINE__ + 1;
     $this->_logger->table($table);
     // Message number: 4
     $lines[] = __LINE__ + 1;
     $this->_logger->info('Hello World');
     $messages = $protocol->getMessages();
     $messages = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE][Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI];
     for ($i = 0; $i < sizeof($messages); $i++) {
         if (!preg_match_all('/FirebugTest\\.php","Line":' . $lines[$i] . '/', $messages[$i], $m)) {
             $this->fail("File and line does not match for message number: " . ($i + 1));
         }
     }
 }
Пример #12
0
 /**
  * getResponse
  *
  * <p>convert the $_response array to json and set the application mine type json</p>
  */
 public function getResponse()
 {
     if (Zend_Registry::get('config')->kebab->logging->enable && Zend_Registry::get('config')->kebab->logging->firebug->enable) {
         Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
     }
     //KBBTODO We should write an adapter for array, xml in future
     $jsonHelper = new Zend_Controller_Action_Helper_Json();
     $jsonHelper->direct($this->_response);
 }
Пример #13
0
 /**
  * @group ZF-6395
  */
 public function testNoQueriesAfterFiltering()
 {
     $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
     $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
     $profiler = $this->_profiler->setEnabled(true);
     $profiler->setFilterQueryType(Zend_Db_Profiler::INSERT | Zend_Db_Profiler::UPDATE);
     $this->_db->fetchAll('select * from foo');
     Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
     $messages = $protocol->getMessages();
     $this->assertFalse($messages);
 }
Пример #14
0
 protected static function _sendFatalResponse()
 {
     // Clean any previous output from buffer
     while (ob_get_level() > 0) {
         ob_end_clean();
     }
     // Send firephp headers
     if (APPLICATION_ENV == 'development') {
         try {
             $request = new Zend_Controller_Request_Http();
             $response = new Zend_Controller_Response_Http();
             $headers = Zend_Wildfire_Channel_HttpHeaders::getInstance();
             $headers->setResponse($response);
             $headers->setRequest($request);
             $headers->flush();
             $response->setBody(file_get_contents(APPLICATION_PATH . '/application/offline.html'));
             $response->sendHeaders();
             $response->sendResponse();
             die(1);
         } catch (Exception $e) {
             // Will fall through to stuff below
         }
     }
     // Send normal error message
     echo file_get_contents(APPLICATION_PATH . '/application/offline.html');
     die(1);
 }
Пример #15
0
 /**
  * @group ZF-5540
  */
 public function testMaxObjectArrayDepth()
 {
     $this->_setupWithoutFrontController();
     $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
     $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
     $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
     $firephp->setOption('maxObjectDepth', 2);
     $firephp->setOption('maxArrayDepth', 1);
     $obj = new Zend_Wildfire_WildfireTest_TestObject3();
     $obj->testArray = array('val1', array('val2', array('Hello World')));
     $obj->child = clone $obj;
     $obj->child->child = clone $obj;
     $firephp->send($obj);
     $table = array();
     $table[] = array('Col1', 'Col2');
     $table[] = array($obj, $obj);
     $firephp->send($table, 'Label', Zend_Wildfire_Plugin_FirePhp::TABLE);
     $messages = $protocol->getMessages();
     $message = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE][Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI][0];
     $this->assertEquals($message, '[{"Type":"LOG"},{"__className":"Zend_Wildfire_WildfireTest_TestObject3","public:name":"Name","public:value":"Value","undeclared:testArray":["val1","** Max Array Depth (1) **"],"undeclared:child":{"__className":"Zend_Wildfire_WildfireTest_TestObject3","public:name":"Name","public:value":"Value","undeclared:testArray":["val1","** Max Array Depth (1) **"],"undeclared:child":"** Max Object Depth (2) **"}}]');
     $message = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE][Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI][1];
     $this->assertEquals($message, '[{"Type":"TABLE","Label":"Label"},[["Col1","Col2"],[{"__className":"Zend_Wildfire_WildfireTest_TestObject3","public:name":"Name","public:value":"Value","undeclared:testArray":["val1","** Max Array Depth (1) **"],"undeclared:child":{"__className":"Zend_Wildfire_WildfireTest_TestObject3","public:name":"Name","public:value":"Value","undeclared:testArray":["val1","** Max Array Depth (1) **"],"undeclared:child":"** Max Object Depth (2) **"}},{"__className":"Zend_Wildfire_WildfireTest_TestObject3","public:name":"Name","public:value":"Value","undeclared:testArray":["val1","** Max Array Depth (1) **"],"undeclared:child":{"__className":"Zend_Wildfire_WildfireTest_TestObject3","public:name":"Name","public:value":"Value","undeclared:testArray":["val1","** Max Array Depth (1) **"],"undeclared:child":"** Max Object Depth (2) **"}}]]]');
 }
Пример #16
0
 /**
  * @group ZF-4934
  */
 public function testAdvancedLogging()
 {
     Zend_Wildfire_Plugin_FirePhp::getInstance()->setOption('maxTraceDepth', 0);
     $message = 'This is a log message!';
     $label = 'Test Label';
     $table = array('Summary line for the table', array(array('Column 1', 'Column 2'), array('Row 1 c 1', ' Row 1 c 2'), array('Row 2 c 1', ' Row 2 c 2')));
     $this->_logger->addPriority('TRACE', 8);
     $this->_logger->addPriority('TABLE', 9);
     $this->_writer->setPriorityStyle(8, 'TRACE');
     $this->_writer->setPriorityStyle(9, 'TABLE');
     $this->_logger->trace($message);
     $this->_logger->table($table);
     try {
         throw new Exception('Test Exception');
     } catch (Exception $e) {
         $this->_logger->err($e);
     }
     try {
         Zend_Wildfire_Plugin_FirePhp::send($message, $label, 'UNKNOWN');
         $this->fail('Should not be able to log with undefined log style');
     } catch (Exception $e) {
         // success
     }
     $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
     $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
     $messages = array(Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE => array(Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI => array(1 => '[{"Type":"TABLE"},["Summary line for the table",[["Column 1","Column 2"],["Row 1 c 1"," Row 1 c 2"],["Row 2 c 1"," Row 2 c 2"]]]]')));
     $qued_messages = $protocol->getMessages();
     unset($qued_messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE][Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI][0]);
     unset($qued_messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE][Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI][2]);
     $this->assertEquals(serialize($qued_messages), serialize($messages));
 }
Пример #17
0
 public static function _toFirebug()
 {
     $timers = self::getTimers();
     $rows = array();
     $rows[] = array('Name', 'Time', 'Count', 'Real Mem', 'Emallac');
     foreach ($timers as $name => $timer) {
         $row = array();
         $row[] = $name;
         $row[] = number_format(self::fetch($name, 'sum'), 5);
         $row[] = number_format(self::fetch($name, 'count'));
         $row[] = number_format(self::fetch($name, 'realmem'));
         $row[] = number_format(self::fetch($name, 'emalloc'));
         $rows[] = $row;
     }
     $count = count($timers);
     $table = array("App Profiling ({$count} total)", $rows);
     Zend_Registry::get('log')->table($table);
     Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
 }
Пример #18
0
 /**
  * Setter method for the channel property. If no channel given
  * a new instance of the Zend_Wildfire_Channel_HttpHeaders will be used.
  *
  * @param Zend_Wildfire_Channel_HttpHeaders $channel
  */
 public function setFirebugChannel($channel = null)
 {
     if ($channel === null) {
         $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
     }
     $this->channel = $channel;
 }
Пример #19
0
 /**
  * Set the index of the plugin in the controller dispatch loop plugin stack
  *
  * @param integer $index The index of the plugin in the stack
  * @return integer The previous index.
  */
 public static function setControllerPluginStackIndex($index)
 {
     $previous = self::$_controllerPluginStackIndex;
     self::$_controllerPluginStackIndex = $index;
     return $previous;
 }
Пример #20
0
 /**
  * Call this in controller (before any output) to dispatch Ajax requests.
  *
  * @param string $id ID to recognize the request from multiple tables ajax request will be ignored if FALSE
  *
  * @return void
  */
 public function setAjax($id = '')
 {
     $this->setId($id);
     // apply additional configuration
     $this->runConfigCallbacks();
     // track that this function was called
     $this->_ajaxFuncCalled = true;
     // if request is Ajax we should only return data
     if (false !== $id && $this->isAjaxRequest() && isset($_GET['q']) && $id === $_GET['q']) {
         // prepare data
         parent::deploy();
         // set data in JSON format
         $response = Zend_Controller_Front::getInstance()->getResponse();
         if (!self::$debug) {
             $response->setHeader('Content-Type', 'application/json');
         }
         $response->setBody($this->renderPartData());
         // send logged messages to FirePHP
         Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
         // send the response now and end request processing
         $response->sendResponse();
         exit;
     }
 }
Пример #21
0
 public function testHttpHeadersChannelSubclass()
 {
     $firephp = Zend_Wildfire_Channel_HttpHeaders::init('Zend_Wildfire_WildfireTest_HttpHeadersChannel');
     $this->assertEquals(get_class($firephp), 'Zend_Wildfire_WildfireTest_HttpHeadersChannel');
     Zend_Wildfire_Channel_HttpHeaders::destroyInstance();
     try {
         Zend_Wildfire_Channel_HttpHeaders::init('Zend_Wildfire_WildfireTest_Request');
         $this->fail('Should not be able to initialize');
     } catch (Exception $e) {
         // success
     }
     $this->assertNull(Zend_Wildfire_Channel_HttpHeaders::getInstance(true));
     try {
         Zend_Wildfire_Channel_HttpHeaders::init(array());
         $this->fail('Should not be able to initialize');
     } catch (Exception $e) {
         // success
     }
     $this->assertNull(Zend_Wildfire_Channel_HttpHeaders::getInstance(true));
 }
 public static function run()
 {
     self::setRequest();
     $response = new Zend_Controller_Response_Http();
     $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
     $channel->setRequest(self::$_request);
     $channel->setResponse($response);
     // Start output buffering
     ob_start();
     try {
         self::prepare();
         Lms_Debug::debug('Request URI: ' . $_SERVER['REQUEST_URI']);
         try {
             self::$_frontController->dispatch(self::$_request);
         } catch (Exception $e) {
             Lms_Debug::crit($e->getMessage());
             Lms_Debug::crit($e->getTraceAsString());
         }
         self::close();
     } catch (Exception $e) {
         Lms_Debug::crit($e->getMessage());
         Lms_Debug::crit($e->getTraceAsString());
     }
     // Flush log data to browser
     $channel->flush();
     $response->sendHeaders();
 }
Пример #23
0
 /**
  * Shutdown function to execute at the end of the request. This function
  * is called automatically so there is no need to call it explicitly.
  */
 public static function shutdown()
 {
     $error = error_get_last();
     if ($error !== null && $error['type'] == E_ERROR) {
         $e = new ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']);
         self::showException($e);
     }
     if (self::$logger) {
         self::$throwExceptionsOnError = false;
         $queryCount = Curry_Propel::getQueryCount();
         $generationTime = self::getExecutionTime();
         self::log("Generation time: " . round($generationTime, 3) . "s", Zend_Log::NOTICE);
         self::log("Peak memory usage: " . Curry_Util::humanReadableBytes(memory_get_peak_usage()), Zend_Log::NOTICE);
         self::log("SQL query count: " . ($queryCount !== null ? $queryCount : 'n/a'), Zend_Log::NOTICE);
         if (self::$writer instanceof Zend_Log_Writer_Firebug && !headers_sent()) {
             // Flush log data to browser
             $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
             $response = $channel->getResponse();
             $channel->flush();
             //$response->sendHeaders();
             // send headers manually so http status (3xx) doesn't get overridden
             foreach ($response->getRawHeaders() as $header) {
                 header($header);
             }
             foreach ($response->getHeaders() as $header) {
                 header($header['name'] . ': ' . $header['value'], $header['replace']);
             }
         }
     }
 }
Пример #24
0
 /**
  * Constructor
  * @return void
  */
 protected function __construct()
 {
     $this->_channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
     $this->_channel->getProtocol(self::PROTOCOL_URI)->registerPlugin($this);
 }
Пример #25
0
 public function testNoQueries()
 {
     $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
     $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
     $this->_profiler->setEnabled(true);
     Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
     $messages = $protocol->getMessages();
     $this->assertFalse($messages);
 }