mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR Added Zend_Log thirdparty dependency (merge from r84322)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@92549 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
32c44b071d
commit
29f375a679
222
thirdparty/Zend/Log.php
vendored
Normal file
222
thirdparty/Zend/Log.php
vendored
Normal file
@ -0,0 +1,222 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
class Zend_Log
|
||||
{
|
||||
const EMERG = 0; // Emergency: system is unusable
|
||||
const ALERT = 1; // Alert: action must be taken immediately
|
||||
const CRIT = 2; // Critical: critical conditions
|
||||
const ERR = 3; // Error: error conditions
|
||||
const WARN = 4; // Warning: warning conditions
|
||||
const NOTICE = 5; // Notice: normal but significant condition
|
||||
const INFO = 6; // Informational: informational messages
|
||||
const DEBUG = 7; // Debug: debug messages
|
||||
|
||||
/**
|
||||
* @var array of priorities where the keys are the
|
||||
* priority numbers and the values are the priority names
|
||||
*/
|
||||
protected $_priorities = array();
|
||||
|
||||
/**
|
||||
* @var array of Zend_Log_Writer_Abstract
|
||||
*/
|
||||
protected $_writers = array();
|
||||
|
||||
/**
|
||||
* @var array of Zend_Log_Filter_Interface
|
||||
*/
|
||||
protected $_filters = array();
|
||||
|
||||
/**
|
||||
* @var array of extra log event
|
||||
*/
|
||||
protected $_extras = array();
|
||||
|
||||
/**
|
||||
* Class constructor. Create a new logger
|
||||
*
|
||||
* @param Zend_Log_Writer_Abstract|null $writer default writer
|
||||
*/
|
||||
public function __construct(Zend_Log_Writer_Abstract $writer = null)
|
||||
{
|
||||
$r = new ReflectionClass($this);
|
||||
$this->_priorities = array_flip($r->getConstants());
|
||||
|
||||
if ($writer !== null) {
|
||||
$this->addWriter($writer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class destructor. Shutdown log writers
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
foreach($this->_writers as $writer) {
|
||||
$writer->shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undefined method handler allows a shortcut:
|
||||
* $log->priorityName('message')
|
||||
* instead of
|
||||
* $log->log('message', Zend_Log::PRIORITY_NAME)
|
||||
*
|
||||
* @param string $method priority name
|
||||
* @param string $params message to log
|
||||
* @return void
|
||||
* @throws Zend_Log_Exception
|
||||
*/
|
||||
public function __call($method, $params)
|
||||
{
|
||||
$priority = strtoupper($method);
|
||||
if (($priority = array_search($priority, $this->_priorities)) !== false) {
|
||||
$this->log(array_shift($params), $priority);
|
||||
} else {
|
||||
/** @see Zend_Log_Exception */
|
||||
require_once 'Zend/Log/Exception.php';
|
||||
throw new Zend_Log_Exception('Bad log priority');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message at a priority
|
||||
*
|
||||
* @param string $message Message to log
|
||||
* @param integer $priority Priority of message
|
||||
* @return void
|
||||
* @throws Zend_Log_Exception
|
||||
*/
|
||||
public function log($message, $priority)
|
||||
{
|
||||
// sanity checks
|
||||
if (empty($this->_writers)) {
|
||||
/** @see Zend_Log_Exception */
|
||||
require_once 'Zend/Log/Exception.php';
|
||||
throw new Zend_Log_Exception('No writers were added');
|
||||
}
|
||||
|
||||
if (! isset($this->_priorities[$priority])) {
|
||||
/** @see Zend_Log_Exception */
|
||||
require_once 'Zend/Log/Exception.php';
|
||||
throw new Zend_Log_Exception('Bad log priority');
|
||||
}
|
||||
|
||||
// pack into event required by filters and writers
|
||||
$event = array_merge(array('timestamp' => date('c'),
|
||||
'message' => $message,
|
||||
'priority' => $priority,
|
||||
'priorityName' => $this->_priorities[$priority]),
|
||||
$this->_extras);
|
||||
|
||||
// abort if rejected by the global filters
|
||||
foreach ($this->_filters as $filter) {
|
||||
if (! $filter->accept($event)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// send to each writer
|
||||
foreach ($this->_writers as $writer) {
|
||||
$writer->write($event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a custom priority
|
||||
*
|
||||
* @param string $name Name of priority
|
||||
* @param integer $priority Numeric priority
|
||||
* @throws Zend_Log_InvalidArgumentException
|
||||
*/
|
||||
public function addPriority($name, $priority)
|
||||
{
|
||||
// Priority names must be uppercase for predictability.
|
||||
$name = strtoupper($name);
|
||||
|
||||
if (isset($this->_priorities[$priority])
|
||||
|| array_search($name, $this->_priorities)) {
|
||||
/** @see Zend_Log_Exception */
|
||||
require_once 'Zend/Log/Exception.php';
|
||||
throw new Zend_Log_Exception('Existing priorities cannot be overwritten');
|
||||
}
|
||||
|
||||
$this->_priorities[$priority] = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a filter that will be applied before all log writers.
|
||||
* Before a message will be received by any of the writers, it
|
||||
* must be accepted by all filters added with this method.
|
||||
*
|
||||
* @param int|Zend_Log_Filter_Interface $filter
|
||||
* @return void
|
||||
*/
|
||||
public function addFilter($filter)
|
||||
{
|
||||
if (is_integer($filter)) {
|
||||
/** @see Zend_Log_Filter_Priority */
|
||||
require_once 'Zend/Log/Filter/Priority.php';
|
||||
$filter = new Zend_Log_Filter_Priority($filter);
|
||||
} elseif(!is_object($filter) || ! $filter instanceof Zend_Log_Filter_Interface) {
|
||||
/** @see Zend_Log_Exception */
|
||||
require_once 'Zend/Log/Exception.php';
|
||||
throw new Zend_Log_Exception('Invalid filter provided');
|
||||
}
|
||||
|
||||
$this->_filters[] = $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a writer. A writer is responsible for taking a log
|
||||
* message and writing it out to storage.
|
||||
*
|
||||
* @param Zend_Log_Writer_Abstract $writer
|
||||
* @return void
|
||||
*/
|
||||
public function addWriter(Zend_Log_Writer_Abstract $writer)
|
||||
{
|
||||
$this->_writers[] = $writer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an extra item to pass to the log writers.
|
||||
*
|
||||
* @param $name Name of the field
|
||||
* @param $value Value of the field
|
||||
* @return void
|
||||
*/
|
||||
public function setEventItem($name, $value) {
|
||||
$this->_extras = array_merge($this->_extras, array($name => $value));
|
||||
}
|
||||
|
||||
}
|
8
thirdparty/Zend/Log/.piston.yml
vendored
Normal file
8
thirdparty/Zend/Log/.piston.yml
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
---
|
||||
format: 1
|
||||
handler:
|
||||
piston:remote-revision: 17966
|
||||
piston:uuid: 44c647ce-9c0f-0410-b52a-842ac1e357ba
|
||||
lock: false
|
||||
repository_url: http://framework.zend.com/svn/framework/standard/tags/release-1.8.1/library/Zend/Log
|
||||
repository_class: Piston::Svn::Repository
|
33
thirdparty/Zend/Log/Exception.php
vendored
Normal file
33
thirdparty/Zend/Log/Exception.php
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
*/
|
||||
|
||||
/** Zend_Exception */
|
||||
require_once 'Zend/Exception.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
*/
|
||||
class Zend_Log_Exception extends Zend_Exception
|
||||
{}
|
41
thirdparty/Zend/Log/Filter/Interface.php
vendored
Normal file
41
thirdparty/Zend/Log/Filter/Interface.php
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Filter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Interface.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Filter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Interface.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
*/
|
||||
interface Zend_Log_Filter_Interface
|
||||
{
|
||||
/**
|
||||
* Returns TRUE to accept the message, FALSE to block it.
|
||||
*
|
||||
* @param array $event event data
|
||||
* @return boolean accepted?
|
||||
*/
|
||||
public function accept($event);
|
||||
|
||||
}
|
67
thirdparty/Zend/Log/Filter/Message.php
vendored
Normal file
67
thirdparty/Zend/Log/Filter/Message.php
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Filter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Message.php 14132 2009-02-21 20:23:00Z shahar $
|
||||
*/
|
||||
|
||||
/** Zend_Log_Filter_Interface */
|
||||
require_once 'Zend/Log/Filter/Interface.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Filter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Message.php 14132 2009-02-21 20:23:00Z shahar $
|
||||
*/
|
||||
class Zend_Log_Filter_Message implements Zend_Log_Filter_Interface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_regexp;
|
||||
|
||||
/**
|
||||
* Filter out any log messages not matching $regexp.
|
||||
*
|
||||
* @param string $regexp Regular expression to test the log message
|
||||
* @throws Zend_Log_Exception
|
||||
*/
|
||||
public function __construct($regexp)
|
||||
{
|
||||
if (@preg_match($regexp, '') === false) {
|
||||
require_once 'Zend/Log/Exception.php';
|
||||
throw new Zend_Log_Exception("Invalid regular expression '$regexp'");
|
||||
}
|
||||
$this->_regexp = $regexp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE to accept the message, FALSE to block it.
|
||||
*
|
||||
* @param array $event event data
|
||||
* @return boolean accepted?
|
||||
*/
|
||||
public function accept($event)
|
||||
{
|
||||
return preg_match($this->_regexp, $event['message']) > 0;
|
||||
}
|
||||
|
||||
}
|
76
thirdparty/Zend/Log/Filter/Priority.php
vendored
Normal file
76
thirdparty/Zend/Log/Filter/Priority.php
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Filter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Priority.php 14132 2009-02-21 20:23:00Z shahar $
|
||||
*/
|
||||
|
||||
/** Zend_Log_Filter_Interface */
|
||||
require_once 'Zend/Log/Filter/Interface.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Filter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Priority.php 14132 2009-02-21 20:23:00Z shahar $
|
||||
*/
|
||||
class Zend_Log_Filter_Priority implements Zend_Log_Filter_Interface
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $_priority;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_operator;
|
||||
|
||||
/**
|
||||
* Filter logging by $priority. By default, it will accept any log
|
||||
* event whose priority value is less than or equal to $priority.
|
||||
*
|
||||
* @param integer $priority Priority
|
||||
* @param string $operator Comparison operator
|
||||
* @throws Zend_Log_Exception
|
||||
*/
|
||||
public function __construct($priority, $operator = '<=')
|
||||
{
|
||||
if (! is_integer($priority)) {
|
||||
require_once 'Zend/Log/Exception.php';
|
||||
throw new Zend_Log_Exception('Priority must be an integer');
|
||||
}
|
||||
|
||||
$this->_priority = $priority;
|
||||
$this->_operator = $operator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE to accept the message, FALSE to block it.
|
||||
*
|
||||
* @param array $event event data
|
||||
* @return boolean accepted?
|
||||
*/
|
||||
public function accept($event)
|
||||
{
|
||||
return version_compare($event['priority'], $this->_priority, $this->_operator);
|
||||
}
|
||||
|
||||
}
|
66
thirdparty/Zend/Log/Filter/Suppress.php
vendored
Normal file
66
thirdparty/Zend/Log/Filter/Suppress.php
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Filter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Suppress.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
*/
|
||||
|
||||
/** Zend_Log_Filter_Interface */
|
||||
require_once 'Zend/Log/Filter/Interface.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Filter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Suppress.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
*/
|
||||
class Zend_Log_Filter_Suppress implements Zend_Log_Filter_Interface
|
||||
{
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_accept = true;
|
||||
|
||||
/**
|
||||
* This is a simple boolean filter.
|
||||
*
|
||||
* Call suppress(true) to suppress all log events.
|
||||
* Call suppress(false) to accept all log events.
|
||||
*
|
||||
* @param boolean $suppress Should all log events be suppressed?
|
||||
* @return void
|
||||
*/
|
||||
public function suppress($suppress)
|
||||
{
|
||||
$this->_accept = (! $suppress);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE to accept the message, FALSE to block it.
|
||||
*
|
||||
* @param array $event event data
|
||||
* @return boolean accepted?
|
||||
*/
|
||||
public function accept($event)
|
||||
{
|
||||
return $this->_accept;
|
||||
}
|
||||
|
||||
}
|
49
thirdparty/Zend/Log/Formatter/Firebug.php
vendored
Normal file
49
thirdparty/Zend/Log/Formatter/Firebug.php
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Formatter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_Log_Formatter_Interface */
|
||||
require_once 'Zend/Log/Formatter/Interface.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Formatter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Log_Formatter_Firebug implements Zend_Log_Formatter_Interface
|
||||
{
|
||||
/**
|
||||
* This method formats the event for the firebug writer.
|
||||
*
|
||||
* The default is to just send the message parameter, but through
|
||||
* extension of this class and calling the
|
||||
* {@see Zend_Log_Writer_Firebug::setFormatter()} method you can
|
||||
* pass as much of the event data as you are interested in.
|
||||
*
|
||||
* @param array $event event data
|
||||
* @return mixed event message
|
||||
*/
|
||||
public function format($event)
|
||||
{
|
||||
return $event['message'];
|
||||
}
|
||||
}
|
41
thirdparty/Zend/Log/Formatter/Interface.php
vendored
Normal file
41
thirdparty/Zend/Log/Formatter/Interface.php
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Formatter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Interface.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Formatter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Interface.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
*/
|
||||
interface Zend_Log_Formatter_Interface
|
||||
{
|
||||
/**
|
||||
* Formats data into a single line to be written by the writer.
|
||||
*
|
||||
* @param array $event event data
|
||||
* @return string formatted line to write to the log
|
||||
*/
|
||||
public function format($event);
|
||||
|
||||
}
|
85
thirdparty/Zend/Log/Formatter/Simple.php
vendored
Normal file
85
thirdparty/Zend/Log/Formatter/Simple.php
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Formatter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Simple.php 13208 2008-12-13 22:33:12Z thomas $
|
||||
*/
|
||||
|
||||
/** Zend_Log_Formatter_Interface */
|
||||
require_once 'Zend/Log/Formatter/Interface.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Formatter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Simple.php 13208 2008-12-13 22:33:12Z thomas $
|
||||
*/
|
||||
class Zend_Log_Formatter_Simple implements Zend_Log_Formatter_Interface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_format;
|
||||
|
||||
const DEFAULT_FORMAT = '%timestamp% %priorityName% (%priority%): %message%';
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param null|string $format Format specifier for log messages
|
||||
* @throws Zend_Log_Exception
|
||||
*/
|
||||
public function __construct($format = null)
|
||||
{
|
||||
if ($format === null) {
|
||||
$format = self::DEFAULT_FORMAT . PHP_EOL;
|
||||
}
|
||||
|
||||
if (! is_string($format)) {
|
||||
require_once 'Zend/Log/Exception.php';
|
||||
throw new Zend_Log_Exception('Format must be a string');
|
||||
}
|
||||
|
||||
$this->_format = $format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats data into a single line to be written by the writer.
|
||||
*
|
||||
* @param array $event event data
|
||||
* @return string formatted line to write to the log
|
||||
*/
|
||||
public function format($event)
|
||||
{
|
||||
$output = $this->_format;
|
||||
foreach ($event as $name => $value) {
|
||||
|
||||
if ((is_object($value) && !method_exists($value,'__toString'))
|
||||
|| is_array($value)) {
|
||||
|
||||
$value = gettype($value);
|
||||
}
|
||||
|
||||
$output = str_replace("%$name%", $value, $output);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
90
thirdparty/Zend/Log/Formatter/Xml.php
vendored
Normal file
90
thirdparty/Zend/Log/Formatter/Xml.php
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Formatter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Xml.php 12363 2008-11-07 10:45:22Z beberlei $
|
||||
*/
|
||||
|
||||
/** Zend_Log_Formatter_Interface */
|
||||
require_once 'Zend/Log/Formatter/Interface.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Formatter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Xml.php 12363 2008-11-07 10:45:22Z beberlei $
|
||||
*/
|
||||
class Zend_Log_Formatter_Xml implements Zend_Log_Formatter_Interface
|
||||
{
|
||||
/**
|
||||
* @var Relates XML elements to log data field keys.
|
||||
*/
|
||||
protected $_rootElement;
|
||||
|
||||
/**
|
||||
* @var Relates XML elements to log data field keys.
|
||||
*/
|
||||
protected $_elementMap;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param array $elementMap
|
||||
*/
|
||||
public function __construct($rootElement = 'logEntry', $elementMap = null)
|
||||
{
|
||||
$this->_rootElement = $rootElement;
|
||||
$this->_elementMap = $elementMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats data into a single line to be written by the writer.
|
||||
*
|
||||
* @param array $event event data
|
||||
* @return string formatted line to write to the log
|
||||
*/
|
||||
public function format($event)
|
||||
{
|
||||
if ($this->_elementMap === null) {
|
||||
$dataToInsert = $event;
|
||||
} else {
|
||||
$dataToInsert = array();
|
||||
foreach ($this->_elementMap as $elementName => $fieldKey) {
|
||||
$dataToInsert[$elementName] = $event[$fieldKey];
|
||||
}
|
||||
}
|
||||
|
||||
$dom = new DOMDocument();
|
||||
$elt = $dom->appendChild(new DOMElement($this->_rootElement));
|
||||
|
||||
foreach ($dataToInsert as $key => $value) {
|
||||
if($key == "message") {
|
||||
$value = htmlspecialchars($value);
|
||||
}
|
||||
$elt->appendChild(new DOMElement($key, $value));
|
||||
}
|
||||
|
||||
$xml = $dom->saveXML();
|
||||
$xml = preg_replace('/<\?xml version="1.0"( encoding="[^\"]*")?\?>\n/u', '', $xml);
|
||||
|
||||
return $xml . PHP_EOL;
|
||||
}
|
||||
|
||||
}
|
107
thirdparty/Zend/Log/Writer/Abstract.php
vendored
Normal file
107
thirdparty/Zend/Log/Writer/Abstract.php
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Writer
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Abstract.php 13621 2009-01-14 01:53:04Z cadorn $
|
||||
*/
|
||||
|
||||
/** Zend_Log_Filter_Priority */
|
||||
require_once 'Zend/Log/Filter/Priority.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Writer
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Abstract.php 13621 2009-01-14 01:53:04Z cadorn $
|
||||
*/
|
||||
abstract class Zend_Log_Writer_Abstract
|
||||
{
|
||||
/**
|
||||
* @var array of Zend_Log_Filter_Interface
|
||||
*/
|
||||
protected $_filters = array();
|
||||
|
||||
/**
|
||||
* Formats the log message before writing.
|
||||
* @var Zend_Log_Formatter_Interface
|
||||
*/
|
||||
protected $_formatter;
|
||||
|
||||
/**
|
||||
* Add a filter specific to this writer.
|
||||
*
|
||||
* @param Zend_Log_Filter_Interface $filter
|
||||
* @return void
|
||||
*/
|
||||
public function addFilter($filter)
|
||||
{
|
||||
if (is_integer($filter)) {
|
||||
$filter = new Zend_Log_Filter_Priority($filter);
|
||||
}
|
||||
|
||||
$this->_filters[] = $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message to this writer.
|
||||
*
|
||||
* @param array $event log data event
|
||||
* @return void
|
||||
*/
|
||||
public function write($event)
|
||||
{
|
||||
foreach ($this->_filters as $filter) {
|
||||
if (! $filter->accept($event)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// exception occurs on error
|
||||
$this->_write($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new formatter for this writer
|
||||
*
|
||||
* @param Zend_Log_Formatter_Interface $formatter
|
||||
* @return void
|
||||
*/
|
||||
public function setFormatter($formatter)
|
||||
{
|
||||
$this->_formatter = $formatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform shutdown activites such as closing open resources
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function shutdown()
|
||||
{}
|
||||
|
||||
/**
|
||||
* Write a message to the log.
|
||||
*
|
||||
* @param array $event log data event
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function _write($event);
|
||||
|
||||
}
|
113
thirdparty/Zend/Log/Writer/Db.php
vendored
Normal file
113
thirdparty/Zend/Log/Writer/Db.php
vendored
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Writer
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Db.php 14336 2009-03-16 21:12:38Z wil $
|
||||
*/
|
||||
|
||||
/** Zend_Log_Writer_Abstract */
|
||||
require_once 'Zend/Log/Writer/Abstract.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Writer
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Db.php 14336 2009-03-16 21:12:38Z wil $
|
||||
*/
|
||||
class Zend_Log_Writer_Db extends Zend_Log_Writer_Abstract
|
||||
{
|
||||
/**
|
||||
* Database adapter instance
|
||||
* @var Zend_Db_Adapter
|
||||
*/
|
||||
private $_db;
|
||||
|
||||
/**
|
||||
* Name of the log table in the database
|
||||
* @var string
|
||||
*/
|
||||
private $_table;
|
||||
|
||||
/**
|
||||
* Relates database columns names to log data field keys.
|
||||
*
|
||||
* @var null|array
|
||||
*/
|
||||
private $_columnMap;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param Zend_Db_Adapter $db Database adapter instance
|
||||
* @param string $table Log table in database
|
||||
* @param array $columnMap
|
||||
*/
|
||||
public function __construct($db, $table, $columnMap = null)
|
||||
{
|
||||
$this->_db = $db;
|
||||
$this->_table = $table;
|
||||
$this->_columnMap = $columnMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatting is not possible on this writer
|
||||
*/
|
||||
public function setFormatter($formatter)
|
||||
{
|
||||
require_once 'Zend/Log/Exception.php';
|
||||
throw new Zend_Log_Exception(get_class() . ' does not support formatting');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove reference to database adapter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function shutdown()
|
||||
{
|
||||
$this->_db = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a message to the log.
|
||||
*
|
||||
* @param array $event event data
|
||||
* @return void
|
||||
*/
|
||||
protected function _write($event)
|
||||
{
|
||||
if ($this->_db === null) {
|
||||
require_once 'Zend/Log/Exception.php';
|
||||
throw new Zend_Log_Exception('Database adapter is null');
|
||||
}
|
||||
|
||||
if ($this->_columnMap === null) {
|
||||
$dataToInsert = $event;
|
||||
} else {
|
||||
$dataToInsert = array();
|
||||
foreach ($this->_columnMap as $columnName => $fieldKey) {
|
||||
$dataToInsert[$columnName] = $event[$fieldKey];
|
||||
}
|
||||
}
|
||||
|
||||
$this->_db->insert($this->_table, $dataToInsert);
|
||||
}
|
||||
|
||||
}
|
187
thirdparty/Zend/Log/Writer/Firebug.php
vendored
Normal file
187
thirdparty/Zend/Log/Writer/Firebug.php
vendored
Normal file
@ -0,0 +1,187 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Writer
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_Log */
|
||||
require_once 'Zend/Log.php';
|
||||
|
||||
/** Zend_Log_Writer_Abstract */
|
||||
require_once 'Zend/Log/Writer/Abstract.php';
|
||||
|
||||
/** Zend_Log_Formatter_Firebug */
|
||||
require_once 'Zend/Log/Formatter/Firebug.php';
|
||||
|
||||
/** Zend_Wildfire_Plugin_FirePhp */
|
||||
require_once 'Zend/Wildfire/Plugin/FirePhp.php';
|
||||
|
||||
/**
|
||||
* Writes log messages to the Firebug Console via FirePHP.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Writer
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Log_Writer_Firebug extends Zend_Log_Writer_Abstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Maps logging priorities to logging display styles
|
||||
* @var array
|
||||
*/
|
||||
protected $_priorityStyles = array(Zend_Log::EMERG => Zend_Wildfire_Plugin_FirePhp::ERROR,
|
||||
Zend_Log::ALERT => Zend_Wildfire_Plugin_FirePhp::ERROR,
|
||||
Zend_Log::CRIT => Zend_Wildfire_Plugin_FirePhp::ERROR,
|
||||
Zend_Log::ERR => Zend_Wildfire_Plugin_FirePhp::ERROR,
|
||||
Zend_Log::WARN => Zend_Wildfire_Plugin_FirePhp::WARN,
|
||||
Zend_Log::NOTICE => Zend_Wildfire_Plugin_FirePhp::INFO,
|
||||
Zend_Log::INFO => Zend_Wildfire_Plugin_FirePhp::INFO,
|
||||
Zend_Log::DEBUG => Zend_Wildfire_Plugin_FirePhp::LOG);
|
||||
|
||||
/**
|
||||
* The default logging style for un-mapped priorities
|
||||
* @var string
|
||||
*/
|
||||
protected $_defaultPriorityStyle = Zend_Wildfire_Plugin_FirePhp::LOG;
|
||||
|
||||
/**
|
||||
* Flag indicating whether the log writer is enabled
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_enabled = true;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if (php_sapi_name()=='cli') {
|
||||
$this->setEnabled(false);
|
||||
}
|
||||
|
||||
$this->_formatter = new Zend_Log_Formatter_Firebug();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable the log writer.
|
||||
*
|
||||
* @param boolean $enabled Set to TRUE to enable the log writer
|
||||
* @return boolean The previous value.
|
||||
*/
|
||||
public function setEnabled($enabled)
|
||||
{
|
||||
$previous = $this->_enabled;
|
||||
$this->_enabled = $enabled;
|
||||
return $previous;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the log writer is enabled.
|
||||
*
|
||||
* @return boolean Returns TRUE if the log writer is enabled.
|
||||
*/
|
||||
public function getEnabled()
|
||||
{
|
||||
return $this->_enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default display style for user-defined priorities
|
||||
*
|
||||
* @param string $style The default log display style
|
||||
* @return string Returns previous default log display style
|
||||
*/
|
||||
public function setDefaultPriorityStyle($style)
|
||||
{
|
||||
$previous = $this->_defaultPriorityStyle;
|
||||
$this->_defaultPriorityStyle = $style;
|
||||
return $previous;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default display style for user-defined priorities
|
||||
*
|
||||
* @return string Returns the default log display style
|
||||
*/
|
||||
public function getDefaultPriorityStyle()
|
||||
{
|
||||
return $this->_defaultPriorityStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a display style for a logging priority
|
||||
*
|
||||
* @param int $priority The logging priority
|
||||
* @param string $style The logging display style
|
||||
* @return string|boolean The previous logging display style if defined or TRUE otherwise
|
||||
*/
|
||||
public function setPriorityStyle($priority, $style)
|
||||
{
|
||||
$previous = true;
|
||||
if (array_key_exists($priority,$this->_priorityStyles)) {
|
||||
$previous = $this->_priorityStyles[$priority];
|
||||
}
|
||||
$this->_priorityStyles[$priority] = $style;
|
||||
return $previous;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a display style for a logging priority
|
||||
*
|
||||
* @param int $priority The logging priority
|
||||
* @return string|boolean The logging display style if defined or FALSE otherwise
|
||||
*/
|
||||
public function getPriorityStyle($priority)
|
||||
{
|
||||
if (array_key_exists($priority,$this->_priorityStyles)) {
|
||||
return $this->_priorityStyles[$priority];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message to the Firebug Console.
|
||||
*
|
||||
* @param array $event The event data
|
||||
* @return void
|
||||
*/
|
||||
protected function _write($event)
|
||||
{
|
||||
if (!$this->getEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (array_key_exists($event['priority'],$this->_priorityStyles)) {
|
||||
$type = $this->_priorityStyles[$event['priority']];
|
||||
} else {
|
||||
$type = $this->_defaultPriorityStyle;
|
||||
}
|
||||
|
||||
$message = $this->_formatter->format($event);
|
||||
|
||||
$label = isset($event['firebugLabel'])?$event['firebugLabel']:null;
|
||||
|
||||
Zend_Wildfire_Plugin_FirePhp::getInstance()->send($message,
|
||||
$label,
|
||||
$type,
|
||||
array('traceOffset'=>6));
|
||||
}
|
||||
}
|
278
thirdparty/Zend/Log/Writer/Mail.php
vendored
Normal file
278
thirdparty/Zend/Log/Writer/Mail.php
vendored
Normal file
@ -0,0 +1,278 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Writer
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Mail.php 13626 2009-01-14 18:24:57Z matthew $
|
||||
*/
|
||||
|
||||
/** Zend_Log_Writer_Abstract */
|
||||
require_once 'Zend/Log/Writer/Abstract.php';
|
||||
|
||||
/** Zend_Log_Exception */
|
||||
require_once 'Zend/Log/Exception.php';
|
||||
|
||||
/** Zend_Log_Formatter_Simple*/
|
||||
require_once 'Zend/Log/Formatter/Simple.php';
|
||||
|
||||
/**
|
||||
* Class used for writing log messages to email via Zend_Mail.
|
||||
*
|
||||
* Allows for emailing log messages at and above a certain level via a
|
||||
* Zend_Mail object. Note that this class only sends the email upon
|
||||
* completion, so any log entries accumulated are sent in a single email.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Writer
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Mail.php 13626 2009-01-14 18:24:57Z matthew $
|
||||
*/
|
||||
class Zend_Log_Writer_Mail extends Zend_Log_Writer_Abstract
|
||||
{
|
||||
/**
|
||||
* Array of formatted events to include in message body.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_eventsToMail = array();
|
||||
|
||||
/**
|
||||
* Array of formatted lines for use in an HTML email body; these events
|
||||
* are formatted with an optional formatter if the caller is using
|
||||
* Zend_Layout.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_layoutEventsToMail = array();
|
||||
|
||||
/**
|
||||
* Zend_Mail instance to use
|
||||
*
|
||||
* @var Zend_Mail
|
||||
*/
|
||||
protected $_mail;
|
||||
|
||||
/**
|
||||
* Zend_Layout instance to use; optional.
|
||||
*
|
||||
* @var Zend_Layout
|
||||
*/
|
||||
protected $_layout;
|
||||
|
||||
/**
|
||||
* Optional formatter for use when rendering with Zend_Layout.
|
||||
*
|
||||
* @var Zend_Log_Formatter_Interface
|
||||
*/
|
||||
protected $_layoutFormatter;
|
||||
|
||||
/**
|
||||
* Array keeping track of the number of entries per priority level.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_numEntriesPerPriority = array();
|
||||
|
||||
/**
|
||||
* Subject prepend text.
|
||||
*
|
||||
* Can only be used of the Zend_Mail object has not already had its
|
||||
* subject line set. Using this will cause the subject to have the entry
|
||||
* counts per-priority level appended to it.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $_subjectPrependText;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* Constructs the mail writer; requires a Zend_Mail instance, and takes an
|
||||
* optional Zend_Layout instance. If Zend_Layout is being used,
|
||||
* $this->_layout->events will be set for use in the layout template.
|
||||
*
|
||||
* @param Zend_Mail $mail Mail instance
|
||||
* @param Zend_Layout $layout Layout instance; optional
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Zend_Mail $mail, Zend_Layout $layout = null)
|
||||
{
|
||||
$this->_mail = $mail;
|
||||
$this->_layout = $layout;
|
||||
$this->_formatter = new Zend_Log_Formatter_Simple();
|
||||
}
|
||||
|
||||
/**
|
||||
* Places event line into array of lines to be used as message body.
|
||||
*
|
||||
* Handles the formatting of both plaintext entries, as well as those
|
||||
* rendered with Zend_Layout.
|
||||
*
|
||||
* @param array $event Event data
|
||||
* @return void
|
||||
*/
|
||||
protected function _write($event)
|
||||
{
|
||||
// Track the number of entries per priority level.
|
||||
if (!isset($this->_numEntriesPerPriority[$event['priorityName']])) {
|
||||
$this->_numEntriesPerPriority[$event['priorityName']] = 1;
|
||||
} else {
|
||||
$this->_numEntriesPerPriority[$event['priorityName']]++;
|
||||
}
|
||||
|
||||
$formattedEvent = $this->_formatter->format($event);
|
||||
|
||||
// All plaintext events are to use the standard formatter.
|
||||
$this->_eventsToMail[] = $formattedEvent;
|
||||
|
||||
// If we have a Zend_Layout instance, use a specific formatter for the
|
||||
// layout if one exists. Otherwise, just use the event with its
|
||||
// default format.
|
||||
if ($this->_layout) {
|
||||
if ($this->_layoutFormatter) {
|
||||
$this->_layoutEventsToMail[] =
|
||||
$this->_layoutFormatter->format($event);
|
||||
} else {
|
||||
$this->_layoutEventsToMail[] = $formattedEvent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets instance of Zend_Log_Formatter_Instance used for formatting a
|
||||
* message using Zend_Layout, if applicable.
|
||||
*
|
||||
* @return Zend_Log_Formatter_Interface|null The formatter, or null.
|
||||
*/
|
||||
public function getLayoutFormatter()
|
||||
{
|
||||
return $this->_layoutFormatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a specific formatter for use with Zend_Layout events.
|
||||
*
|
||||
* Allows use of a second formatter on lines that will be rendered with
|
||||
* Zend_Layout. In the event that Zend_Layout is not being used, this
|
||||
* formatter cannot be set, so an exception will be thrown.
|
||||
*
|
||||
* @param Zend_Log_Formatter_Interface $formatter
|
||||
* @return Zend_Log_Writer_Mail
|
||||
* @throws Zend_Log_Exception
|
||||
*/
|
||||
public function setLayoutFormatter(Zend_Log_Formatter_Interface $formatter)
|
||||
{
|
||||
if (!$this->_layout) {
|
||||
throw new Zend_Log_Exception(
|
||||
'cannot set formatter for layout; ' .
|
||||
'a Zend_Layout instance is not in use');
|
||||
}
|
||||
|
||||
$this->_layoutFormatter = $formatter;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows caller to have the mail subject dynamically set to contain the
|
||||
* entry counts per-priority level.
|
||||
*
|
||||
* Sets the text for use in the subject, with entry counts per-priority
|
||||
* level appended to the end. Since a Zend_Mail subject can only be set
|
||||
* once, this method cannot be used if the Zend_Mail object already has a
|
||||
* subject set.
|
||||
*
|
||||
* @param string $subject Subject prepend text.
|
||||
* @return Zend_Log_Writer_Mail
|
||||
*/
|
||||
public function setSubjectPrependText($subject)
|
||||
{
|
||||
if ($this->_mail->getSubject()) {
|
||||
throw new Zend_Log_Exception(
|
||||
'subject already set on mail; ' .
|
||||
'cannot set subject prepend text');
|
||||
}
|
||||
|
||||
$this->_subjectPrependText = (string) $subject;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends mail to recipient(s) if log entries are present. Note that both
|
||||
* plaintext and HTML portions of email are handled here.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function shutdown()
|
||||
{
|
||||
// If there are events to mail, use them as message body. Otherwise,
|
||||
// there is no mail to be sent.
|
||||
if (empty($this->_eventsToMail)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->_subjectPrependText !== null) {
|
||||
// Tack on the summary of entries per-priority to the subject
|
||||
// line and set it on the Zend_Mail object.
|
||||
$numEntries = $this->_getFormattedNumEntriesPerPriority();
|
||||
$this->_mail->setSubject(
|
||||
"{$this->_subjectPrependText} ({$numEntries})");
|
||||
}
|
||||
|
||||
|
||||
// Always provide events to mail as plaintext.
|
||||
$this->_mail->setBodyText(implode('', $this->_eventsToMail));
|
||||
|
||||
// If a Zend_Layout instance is being used, set its "events"
|
||||
// value to the lines formatted for use with the layout.
|
||||
if ($this->_layout) {
|
||||
// Set the required "messages" value for the layout. Here we
|
||||
// are assuming that the layout is for use with HTML.
|
||||
$this->_layout->events =
|
||||
implode('', $this->_layoutEventsToMail);
|
||||
$this->_mail->setBodyHtml($this->_layout->render());
|
||||
}
|
||||
|
||||
// Finally, send the mail, but re-throw any exceptions at the
|
||||
// proper level of abstraction.
|
||||
try {
|
||||
$this->_mail->send();
|
||||
} catch (Exception $e) {
|
||||
throw new Zend_Log_Exception(
|
||||
$e->getMessage(),
|
||||
$e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a string of number of entries per-priority level that occurred, or
|
||||
* an emptry string if none occurred.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getFormattedNumEntriesPerPriority()
|
||||
{
|
||||
$strings = array();
|
||||
|
||||
foreach ($this->_numEntriesPerPriority as $priority => $numEntries) {
|
||||
$strings[] = "{$priority}={$numEntries}";
|
||||
}
|
||||
|
||||
return implode(', ', $strings);
|
||||
}
|
||||
}
|
66
thirdparty/Zend/Log/Writer/Mock.php
vendored
Normal file
66
thirdparty/Zend/Log/Writer/Mock.php
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Writer
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Null.php 3980 2007-03-15 21:38:38Z mike $
|
||||
*/
|
||||
|
||||
/** Zend_Log_Writer_Abstract */
|
||||
require_once 'Zend/Log/Writer/Abstract.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Writer
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Null.php 3980 2007-03-15 21:38:38Z mike $
|
||||
*/
|
||||
class Zend_Log_Writer_Mock extends Zend_Log_Writer_Abstract
|
||||
{
|
||||
/**
|
||||
* array of log events
|
||||
*/
|
||||
public $events = array();
|
||||
|
||||
/**
|
||||
* shutdown called?
|
||||
*/
|
||||
public $shutdown = false;
|
||||
|
||||
/**
|
||||
* Write a message to the log.
|
||||
*
|
||||
* @param array $event event data
|
||||
* @return void
|
||||
*/
|
||||
public function _write($event)
|
||||
{
|
||||
$this->events[] = $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Record shutdown
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function shutdown()
|
||||
{
|
||||
$this->shutdown = true;
|
||||
}
|
||||
}
|
46
thirdparty/Zend/Log/Writer/Null.php
vendored
Normal file
46
thirdparty/Zend/Log/Writer/Null.php
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Writer
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Null.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
*/
|
||||
|
||||
/** Zend_Log_Writer_Abstract */
|
||||
require_once 'Zend/Log/Writer/Abstract.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Writer
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Null.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
*/
|
||||
class Zend_Log_Writer_Null extends Zend_Log_Writer_Abstract
|
||||
{
|
||||
/**
|
||||
* Write a message to the log.
|
||||
*
|
||||
* @param array $event event data
|
||||
* @return void
|
||||
*/
|
||||
protected function _write($event)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
104
thirdparty/Zend/Log/Writer/Stream.php
vendored
Normal file
104
thirdparty/Zend/Log/Writer/Stream.php
vendored
Normal file
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Writer
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Stream.php 14131 2009-02-21 20:13:38Z shahar $
|
||||
*/
|
||||
|
||||
/** Zend_Log_Writer_Abstract */
|
||||
require_once 'Zend/Log/Writer/Abstract.php';
|
||||
|
||||
/** Zend_Log_Formatter_Simple */
|
||||
require_once 'Zend/Log/Formatter/Simple.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Log
|
||||
* @subpackage Writer
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Stream.php 14131 2009-02-21 20:13:38Z shahar $
|
||||
*/
|
||||
class Zend_Log_Writer_Stream extends Zend_Log_Writer_Abstract
|
||||
{
|
||||
/**
|
||||
* Holds the PHP stream to log to.
|
||||
* @var null|stream
|
||||
*/
|
||||
protected $_stream = null;
|
||||
|
||||
/**
|
||||
* Class Constructor
|
||||
*
|
||||
* @param streamOrUrl Stream or URL to open as a stream
|
||||
* @param mode Mode, only applicable if a URL is given
|
||||
*/
|
||||
public function __construct($streamOrUrl, $mode = 'a')
|
||||
{
|
||||
if (is_resource($streamOrUrl)) {
|
||||
if (get_resource_type($streamOrUrl) != 'stream') {
|
||||
require_once 'Zend/Log/Exception.php';
|
||||
throw new Zend_Log_Exception('Resource is not a stream');
|
||||
}
|
||||
|
||||
if ($mode != 'a') {
|
||||
require_once 'Zend/Log/Exception.php';
|
||||
throw new Zend_Log_Exception('Mode cannot be changed on existing streams');
|
||||
}
|
||||
|
||||
$this->_stream = $streamOrUrl;
|
||||
} else {
|
||||
if (! $this->_stream = @fopen($streamOrUrl, $mode, false)) {
|
||||
require_once 'Zend/Log/Exception.php';
|
||||
$msg = "\"$streamOrUrl\" cannot be opened with mode \"$mode\"";
|
||||
throw new Zend_Log_Exception($msg);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_formatter = new Zend_Log_Formatter_Simple();
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the stream resource.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function shutdown()
|
||||
{
|
||||
if (is_resource($this->_stream)) {
|
||||
fclose($this->_stream);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a message to the log.
|
||||
*
|
||||
* @param array $event event data
|
||||
* @return void
|
||||
*/
|
||||
protected function _write($event)
|
||||
{
|
||||
$line = $this->_formatter->format($event);
|
||||
|
||||
if (false === @fwrite($this->_stream, $line)) {
|
||||
require_once 'Zend/Log/Exception.php';
|
||||
throw new Zend_Log_Exception("Unable to write to stream");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user