Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cLog
  • cLogWriter
  • cLogWriterFile
  • cModuleLog
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the abstract log writer class.
  4:  *
  5:  * @package    Core
  6:  * @subpackage Log
  7:  * @version    SVN Revision $Rev:$
  8:  *
  9:  * @author     Dominik Ziegler
 10:  * @copyright  four for business AG <www.4fb.de>
 11:  * @license    http://www.contenido.org/license/LIZENZ.txt
 12:  * @link       http://www.4fb.de
 13:  * @link       http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * This class contains the main functionalities for the logging writer in CONTENIDO.
 20:  *
 21:  * @package    Core
 22:  * @subpackage Log
 23:  */
 24: abstract class cLogWriter {
 25:     /**
 26:      * @var array Contains all options of the current writer instance.
 27:      */
 28:     protected $_options = array();
 29: 
 30:     /**
 31:      * Constructor of the writer instance.
 32:      * @param    array    $options    Array with options for the writer instance (optional)
 33:      */
 34:     public function __construct($options = array()) {
 35:         $this->setOptions($options);
 36: 
 37:         // Set all default options if they were not set already
 38:         $this->setOption('default_priority', cLog::INFO, false);
 39:         $this->setOption('line_ending', PHP_EOL, false);
 40:     }
 41: 
 42:     /**
 43:      * Factory method for a new writer instance.
 44:      *
 45:      * @param string $writerName Name of the writer
 46:      * @param array $writerOptions Options array for the writer instance
 47:      * @throws cInvalidArgumentException if the writer class with the given name
 48:      *         does not exist or is not an instance of clogWriter
 49:      * @return cLogWriter Log writer instance
 50:      */
 51:     public static function factory($writerName, array $writerOptions) {
 52:         $logWriterClassName = 'cLogWriter' . ucfirst($writerName);
 53:         if (!class_exists($logWriterClassName)) {
 54:             throw new cInvalidArgumentException('Unknown writer class: ' . $writerName);
 55:         }
 56: 
 57:         $writer = new $logWriterClassName($writerOptions);
 58:         if (($writer instanceof cLogWriter) == false) {
 59:             throw new cInvalidArgumentException('Provided class is not an instance of cLogWriter');
 60:         }
 61: 
 62:         return $writer;
 63:     }
 64: 
 65:     /**
 66:      * Sets the whole options array.
 67:      *
 68:      * @param    array    $options    Array with options
 69:      */
 70:     public function setOptions(array $options) {
 71:         $this->_options = $options;
 72:     }
 73: 
 74:     /**
 75:      * Returns an array with all options.
 76:      * @return    array    Array with all options
 77:      */
 78:     public function getOptions() {
 79:         return $this->_options;
 80:     }
 81: 
 82:     /**
 83:      * Sets a option. If option was set previously, it must be forced to overwrite the value.
 84:      *
 85:      * @param    string    $option    Name of the option
 86:      * @param    mixed    $value    Value of the option
 87:      * @param    boolean    $force    Flag to force setting the option value (optional, default: false)
 88:      */
 89:     public function setOption($option, $value, $force = false) {
 90:         if ($force == false && isset($this->_options[$option]) == true) {
 91:             return;
 92:         }
 93: 
 94:         $this->_options[$option] = $value;
 95:     }
 96: 
 97:     /**
 98:      * Returns the value of an option entry.
 99:      *
100:      * @param    string    $option    Name of the option
101:      *
102:      * @return    mixed    Value of the option entry
103:      */
104:     public function getOption($option) {
105:         return $this->_options[$option];
106:     }
107: 
108:     /**
109:      * Removes an option entry.
110:      *
111:      * @param    string    $option    Name of the option
112:      */
113:     public function removeOption($option) {
114:         unset($this->_options[$option]);
115:     }
116: 
117:     /**
118:      * Abstract function for the write process.
119:      * This method must be implemented in the specific writer.
120:      *
121:      * @param    string    $message    Message to write
122:      * @param    int        $priority    Priority of the log entry
123:      *
124:      * @return    boolean    State of the write process
125:      */
126:     abstract function write($message, $priority);
127: }
CMS CONTENIDO 4.9.3 API documentation generated by ApiGen 2.8.0