PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Zend/Log/Writer/Abstract.php

https://bitbucket.org/sunil_nextbits/magento2
PHP | 137 lines | 46 code | 14 blank | 77 comment | 5 complexity | 63dbb11e0009e868f6833b1bde830d98 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Log
  17. * @subpackage Writer
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: Abstract.php 22567 2010-07-16 03:32:31Z ramon $
  21. */
  22. /** Zend_Log_Filter_Priority */
  23. #require_once 'Zend/Log/Filter/Priority.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Log
  27. * @subpackage Writer
  28. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @version $Id: Abstract.php 22567 2010-07-16 03:32:31Z ramon $
  31. */
  32. abstract class Zend_Log_Writer_Abstract implements Zend_Log_FactoryInterface
  33. {
  34. /**
  35. * @var array of Zend_Log_Filter_Interface
  36. */
  37. protected $_filters = array();
  38. /**
  39. * Formats the log message before writing.
  40. * @var Zend_Log_Formatter_Interface
  41. */
  42. protected $_formatter;
  43. /**
  44. * Add a filter specific to this writer.
  45. *
  46. * @param Zend_Log_Filter_Interface $filter
  47. * @return void
  48. */
  49. public function addFilter($filter)
  50. {
  51. if (is_integer($filter)) {
  52. $filter = new Zend_Log_Filter_Priority($filter);
  53. }
  54. if (!$filter instanceof Zend_Log_Filter_Interface) {
  55. /** @see Zend_Log_Exception */
  56. #require_once 'Zend/Log/Exception.php';
  57. throw new Zend_Log_Exception('Invalid filter provided');
  58. }
  59. $this->_filters[] = $filter;
  60. return $this;
  61. }
  62. /**
  63. * Log a message to this writer.
  64. *
  65. * @param array $event log data event
  66. * @return void
  67. */
  68. public function write($event)
  69. {
  70. foreach ($this->_filters as $filter) {
  71. if (! $filter->accept($event)) {
  72. return;
  73. }
  74. }
  75. // exception occurs on error
  76. $this->_write($event);
  77. }
  78. /**
  79. * Set a new formatter for this writer
  80. *
  81. * @param Zend_Log_Formatter_Interface $formatter
  82. * @return void
  83. */
  84. public function setFormatter(Zend_Log_Formatter_Interface $formatter)
  85. {
  86. $this->_formatter = $formatter;
  87. return $this;
  88. }
  89. /**
  90. * Perform shutdown activites such as closing open resources
  91. *
  92. * @return void
  93. */
  94. public function shutdown()
  95. {}
  96. /**
  97. * Write a message to the log.
  98. *
  99. * @param array $event log data event
  100. * @return void
  101. */
  102. abstract protected function _write($event);
  103. /**
  104. * Validate and optionally convert the config to array
  105. *
  106. * @param array|Zend_Config $config Zend_Config or Array
  107. * @return array
  108. * @throws Zend_Log_Exception
  109. */
  110. static protected function _parseConfig($config)
  111. {
  112. if ($config instanceof Zend_Config) {
  113. $config = $config->toArray();
  114. }
  115. if (!is_array($config)) {
  116. #require_once 'Zend/Log/Exception.php';
  117. throw new Zend_Log_Exception(
  118. 'Configuration must be an array or instance of Zend_Config'
  119. );
  120. }
  121. return $config;
  122. }
  123. }