# LogLevel.class.php

Go to the documentation of this file.

    00001 <?php
    00002 /***************************************************************************
    00003  *   Copyright (C) 2007 by Ivan Y. Khvostishkov                            *
    00004  *                                                                         *
    00005  *   This program is free software; you can redistribute it and/or modify  *
    00006  *   it under the terms of the GNU Lesser General Public License as        *
    00007  *   published by the Free Software Foundation; either version 3 of the    *
    00008  *   License, or (at your option) any later version.                       *
    00009  *                                                                         *
    00010  ***************************************************************************/
    00011
    00015     final class LogLevel extends Enumeration
    00016     {
    00017         const SEVERE    = 1; // highest value
    00018         const WARNING   = 2;
    00019         const INFO      = 3;
    00020         const CONFIG    = 4;
    00021         const FINE      = 5;
    00022         const FINER     = 6;
    00023         const FINEST    = 7; // lowest value
    00024
    00025         protected $names = array(
    00026             self::SEVERE    => 'severe',
    00027             self::WARNING   => 'warning',
    00028             self::INFO      => 'info',
    00029             self::CONFIG    => 'config',
    00030             self::FINE      => 'fine',
    00031             self::FINER     => 'finer',
    00032             self::FINEST    => 'finest'
    00033         );
    00034
    00038         public function setId($id)
    00039         {
    00040             Assert::isNull($this->id, 'i am immutable one!');
    00041
    00042             return parent::setId($id);
    00043         }
    00044
    00048         public static function severe()
    00049         {
    00050             return self::getInstance(self::SEVERE);
    00051         }
    00052
    00056         public static function warning()
    00057         {
    00058             return self::getInstance(self::WARNING);
    00059         }
    00060
    00064         public static function info()
    00065         {
    00066             return self::getInstance(self::INFO);
    00067         }
    00068
    00072         public static function config()
    00073         {
    00074             return self::getInstance(self::CONFIG);
    00075         }
    00076
    00080         public static function fine()
    00081         {
    00082             return self::getInstance(self::FINE);
    00083         }
    00084
    00088         public static function finer()
    00089         {
    00090             return self::getInstance(self::FINER);
    00091         }
    00092
    00096         public static function finest()
    00097         {
    00098             return self::getInstance(self::FINEST);
    00099         }
    00100
    00104         private static function getInstance($id)
    00105         {
    00106             static $instances = array();
    00107
    00108             if (!isset($instances[$id]))
    00109                 $instances[$id] = new self($id);
    00110
    00111             return $instances[$id];
    00112         }
    00113     }
    00114 ?>