[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * log4php is a PHP port of the log4j java logging package. 4 * 5 * <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p> 6 * <p>Design, strategies and part of the methods documentation are developed by log4j team 7 * (Ceki G�lc� as log4j project founder and 8 * {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p> 9 * 10 * <p>PHP port, extensions and modifications by VxR. All rights reserved.<br> 11 * For more information, please see {@link http://www.vxr.it/log4php/}.</p> 12 * 13 * <p>This software is published under the terms of the LGPL License 14 * a copy of which has been included with this distribution in the LICENSE file.</p> 15 * 16 * @package log4php 17 * @subpackage or 18 */ 19 20 /** 21 * @ignore 22 */ 23 if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); 24 25 /** 26 */ 27 require_once(LOG4PHP_DIR . '/or/LoggerDefaultRenderer.php'); 28 require_once (LOG4PHP_DIR . '/or/LoggerObjectRenderer.php'); 29 require_once (LOG4PHP_DIR . '/LoggerLog.php'); 30 31 /** 32 * Map class objects to an {@link LoggerObjectRenderer}. 33 * 34 * @author VxR <[email protected]> 35 * @version $Revision: 1.4 $ 36 * @package log4php 37 * @subpackage or 38 * @since 0.3 39 */ 40 class LoggerRendererMap { 41 42 /** 43 * @var array 44 */ 45 var $map; 46 47 /** 48 * @var LoggerDefaultRenderer 49 */ 50 var $defaultRenderer; 51 52 /** 53 * Constructor 54 */ 55 function LoggerRendererMap() 56 { 57 $this->map = array(); 58 $this->defaultRenderer = new LoggerDefaultRenderer(); 59 } 60 61 /** 62 * Add a renderer to a hierarchy passed as parameter. 63 * Note that hierarchy must implement getRendererMap() and setRenderer() methods. 64 * 65 * @param LoggerHierarchy &$repository a logger repository. 66 * @param string &$renderedClassName 67 * @param string &$renderingClassName 68 * @static 69 */ 70 function addRenderer(&$repository, $renderedClassName, $renderingClassName) 71 { 72 LoggerLog::debug("LoggerRendererMap::addRenderer() Rendering class: [{$renderingClassName}], Rendered class: [{$renderedClassName}]."); 73 $renderer = LoggerObjectRenderer::factory($renderingClassName); 74 if($renderer == null) { 75 LoggerLog::warn("LoggerRendererMap::addRenderer() Could not instantiate renderer [{$renderingClassName}]."); 76 return; 77 } else { 78 $repository->setRenderer($renderedClassName, $renderer); 79 } 80 } 81 82 83 /** 84 * Find the appropriate renderer for the class type of the 85 * <var>o</var> parameter. 86 * 87 * This is accomplished by calling the {@link getByObject()} 88 * method if <var>o</var> is object or using {@link LoggerDefaultRenderer}. 89 * Once a renderer is found, it is applied on the object <var>o</var> and 90 * the result is returned as a string. 91 * 92 * @param mixed $o 93 * @return string 94 */ 95 function findAndRender($o) 96 { 97 if($o == null) { 98 return null; 99 } else { 100 if (is_object($o)) { 101 $renderer = $this->getByObject($o); 102 if ($renderer !== null) { 103 return $renderer->doRender($o); 104 } else { 105 return null; 106 } 107 } else { 108 $renderer = $this->defaultRenderer; 109 return $renderer->doRender($o); 110 } 111 } 112 } 113 114 /** 115 * Syntactic sugar method that calls {@link PHP_MANUAL#get_class} with the 116 * class of the object parameter. 117 * 118 * @param mixed $o 119 * @return string 120 */ 121 function &getByObject($o) 122 { 123 return ($o == null) ? null : $this->getByClassName(get_class($o)); 124 } 125 126 127 /** 128 * Search the parents of <var>clazz</var> for a renderer. 129 * 130 * The renderer closest in the hierarchy will be returned. If no 131 * renderers could be found, then the default renderer is returned. 132 * 133 * @param string $class 134 * @return LoggerObjectRenderer 135 */ 136 function &getByClassName($class) 137 { 138 $r = null; 139 for($c = strtolower($class); !empty($c); $c = get_parent_class($c)) { 140 if (isset($this->map[$c])) { 141 return $this->map[$c]; 142 } 143 } 144 return $this->defaultRenderer; 145 } 146 147 /** 148 * @return LoggerDefaultRenderer 149 */ 150 function &getDefaultRenderer() 151 { 152 return $this->defaultRenderer; 153 } 154 155 156 function clear() 157 { 158 $this->map = array(); 159 } 160 161 /** 162 * Register a {@link LoggerObjectRenderer} for <var>clazz</var>. 163 * @param string $class 164 * @param LoggerObjectRenderer $or 165 */ 166 function put($class, $or) 167 { 168 $this->map[strtolower($class)] = $or; 169 } 170 171 /** 172 * @param string $class 173 * @return boolean 174 */ 175 function rendererExists($class) 176 { 177 $class = basename($class); 178 if (!class_exists($class)) { 179 @include_once(LOG4PHP_DIR ."/or/{$class}.php"); 180 } 181 return class_exists($class); 182 } 183 } 184 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |