import v1.1.0_beta1 | 2009-08-21

This commit is contained in:
2019-07-17 22:16:19 +02:00
parent 2c1152f0d3
commit 8dee6b1a10
2306 changed files with 251360 additions and 23428 deletions

View File

@ -22,9 +22,6 @@
/** Zend_Wildfire_Channel_Interface */
require_once 'Zend/Wildfire/Channel/Interface.php';
/** Zend_Wildfire_Exception */
require_once 'Zend/Wildfire/Exception.php';
/** Zend_Controller_Request_Abstract */
require_once('Zend/Controller/Request/Abstract.php');
@ -42,7 +39,7 @@ require_once 'Zend/Controller/Front.php';
/**
* Implements communication via HTTP request and response headers for Wildfire Protocols.
*
*
* @category Zend
* @package Zend_Wildfire
* @subpackage Channel
@ -56,25 +53,25 @@ class Zend_Wildfire_Channel_HttpHeaders extends Zend_Controller_Plugin_Abstract
* @var string
*/
protected static $_headerPrefix = 'X-WF-';
/**
* Singleton instance
* @var Zend_Wildfire_Channel_HttpHeaders
*/
protected static $_instance = null;
/**
* The index of the plugin in the controller dispatch loop plugin stack
* @var integer
*/
protected static $_controllerPluginStackIndex = 999;
/**
* The protocol instances for this channel
* @var array
*/
protected $_protocols = null;
/**
* Initialize singleton instance.
*
@ -84,41 +81,50 @@ class Zend_Wildfire_Channel_HttpHeaders extends Zend_Controller_Plugin_Abstract
*/
public static function init($class = null)
{
if (self::$_instance!==null) {
if (self::$_instance !== null) {
require_once 'Zend/Wildfire/Exception.php';
throw new Zend_Wildfire_Exception('Singleton instance of Zend_Wildfire_Channel_HttpHeaders already exists!');
}
if ($class!==null) {
if ($class !== null) {
if (!is_string($class)) {
require_once 'Zend/Wildfire/Exception.php';
throw new Zend_Wildfire_Exception('Third argument is not a class string');
}
Zend_Loader::loadClass($class);
if (!class_exists($class)) {
require_once 'Zend/Loader.php';
Zend_Loader::loadClass($class);
}
self::$_instance = new $class();
if (!self::$_instance instanceof Zend_Wildfire_Channel_HttpHeaders) {
self::$_instance = null;
require_once 'Zend/Wildfire/Exception.php';
throw new Zend_Wildfire_Exception('Invalid class to third argument. Must be subclass of Zend_Wildfire_Channel_HttpHeaders.');
}
} else {
self::$_instance = new self();
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Get or create singleton instance
*
*
* @param $skipCreate boolean True if an instance should not be created
* @return Zend_Wildfire_Channel_HttpHeaders
*/
public static function getInstance($skipCreate=false)
{
{
if (self::$_instance===null && $skipCreate!==true) {
return self::init();
return self::init();
}
return self::$_instance;
}
/**
* Destroys the singleton instance
*
@ -130,10 +136,10 @@ class Zend_Wildfire_Channel_HttpHeaders extends Zend_Controller_Plugin_Abstract
{
self::$_instance = null;
}
/**
* Get the instance of a give protocol for this channel
*
*
* @param string $uri The URI for the protocol
* @return object Returns the protocol instance for the diven URI
*/
@ -142,15 +148,15 @@ class Zend_Wildfire_Channel_HttpHeaders extends Zend_Controller_Plugin_Abstract
if (!isset($this->_protocols[$uri])) {
$this->_protocols[$uri] = $this->_initProtocol($uri);
}
$this->_registerControllerPlugin();
return $this->_protocols[$uri];
}
/**
* Initialize a new protocol
*
*
* @param string $uri The URI for the protocol to be initialized
* @return object Returns the new initialized protocol instance
* @throws Zend_Wildfire_Exception
@ -161,10 +167,11 @@ class Zend_Wildfire_Channel_HttpHeaders extends Zend_Controller_Plugin_Abstract
case Zend_Wildfire_Protocol_JsonStream::PROTOCOL_URI;
return new Zend_Wildfire_Protocol_JsonStream();
}
require_once 'Zend/Wildfire/Exception.php';
throw new Zend_Wildfire_Exception('Tyring to initialize unknown protocol for URI "'.$uri.'".');
}
/**
* Flush all data from all protocols and send all data to response headers.
*
@ -190,10 +197,10 @@ class Zend_Wildfire_Channel_HttpHeaders extends Zend_Controller_Plugin_Abstract
}
return true;
}
/**
* 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.
*/
@ -206,7 +213,7 @@ class Zend_Wildfire_Channel_HttpHeaders extends Zend_Controller_Plugin_Abstract
/**
* Register this object as a controller plugin.
*
*
* @return void
*/
protected function _registerControllerPlugin()
@ -214,21 +221,54 @@ class Zend_Wildfire_Channel_HttpHeaders extends Zend_Controller_Plugin_Abstract
$controller = Zend_Controller_Front::getInstance();
if (!$controller->hasPlugin(get_class($this))) {
$controller->registerPlugin($this, self::$_controllerPluginStackIndex);
}
}
}
/*
* Zend_Wildfire_Channel_Interface
* Zend_Wildfire_Channel_Interface
*/
/**
* Determine if channel is ready.
*
* The channel is ready as long as the request and response objects are initialized,
* can send headers and the FirePHP header exists in the User-Agent.
*
* If the header does not exist in the User-Agent, no appropriate client
* is making this request and the messages should not be sent.
*
* A timing issue arises when messages are logged before the request/response
* objects are initialized. In this case we do not yet know if the client
* will be able to accept the messages. If we consequently indicate that
* the channel is not ready, these messages will be dropped which is in
* most cases not the intended behaviour. The intent is to send them at the
* end of the request when the request/response objects will be available
* for sure.
*
* If the request/response objects are not yet initialized we assume if messages are
* logged, the client will be able to receive them. As soon as the request/response
* objects are availoable and a message is logged this assumption is challenged.
* If the client cannot accept the messages any further messages are dropped
* and messages sent prior are kept but discarded when the channel is finally
* flushed at the end of the request.
*
* When the channel is flushed the $forceCheckRequest option is used to force
* a check of the request/response objects. This is the last verification to ensure
* messages are only sent when the client can accept them.
*
* @param boolean $forceCheckRequest OPTIONAL Set to TRUE if the request must be checked
* @return boolean Returns TRUE if channel is ready.
*/
public function isReady()
public function isReady($forceCheckRequest=false)
{
if (!$forceCheckRequest
&& !$this->_request
&& !$this->_response) {
return true;
}
return ($this->getResponse()->canSendHeaders() &&
preg_match_all('/\s?FirePHP\/([\.|\d]*)\s?/si',
$this->getRequest()->getHeader('User-Agent'),$m));
@ -236,7 +276,7 @@ class Zend_Wildfire_Channel_HttpHeaders extends Zend_Controller_Plugin_Abstract
/*
* Zend_Controller_Plugin_Abstract
* Zend_Controller_Plugin_Abstract
*/
/**
@ -248,10 +288,10 @@ class Zend_Wildfire_Channel_HttpHeaders extends Zend_Controller_Plugin_Abstract
{
$this->flush();
}
/**
* Get the request object
*
*
* @return Zend_Controller_Request_Abstract
* @throws Zend_Wildfire_Exception
*/
@ -262,6 +302,7 @@ class Zend_Wildfire_Channel_HttpHeaders extends Zend_Controller_Plugin_Abstract
$this->setRequest($controller->getRequest());
}
if (!$this->_request) {
require_once 'Zend/Wildfire/Exception.php';
throw new Zend_Wildfire_Exception('Request objects not initialized.');
}
return $this->_request;
@ -269,7 +310,7 @@ class Zend_Wildfire_Channel_HttpHeaders extends Zend_Controller_Plugin_Abstract
/**
* Get the response object
*
*
* @return Zend_Controller_Response_Abstract
* @throws Zend_Wildfire_Exception
*/
@ -282,6 +323,7 @@ class Zend_Wildfire_Channel_HttpHeaders extends Zend_Controller_Plugin_Abstract
}
}
if (!$this->_response) {
require_once 'Zend/Wildfire/Exception.php';
throw new Zend_Wildfire_Exception('Response objects not initialized.');
}
return $this->_response;