Models
[ class tree: Models ] [ index: Models ] [ all elements ]

Source for file Base.php

Documentation is available at Base.php

  1. <?php
  2. /**
  3.  * Base
  4.  * 
  5.  * Copyright (C) 2009  Mai (Me Artificial Intelligence)
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation, either version 3 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19.  * 
  20.  * @author Wouter Bulten (wouterbulten@mai-ai.org)
  21.  * @copyright Copyright (C) 2009  Mai (Me Artificial Intelligence)
  22.  * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
  23.  * @link http://www.launchpad.net/mai
  24.  * 
  25.  * @package Models
  26.  * @subpackage Other
  27.  * 
  28.  */
  29.  
  30. /**
  31.  * The Base class contains some basic functions for Mai.
  32.  * 
  33.  * @author Wouter Bulten (wouterbulten@mai-ai.org)
  34.  * @copyright Copyright (C) 2009  Mai (Me Artificial Intelligence)
  35.  * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
  36.  * @link http://www.launchpad.net/mai
  37.  * 
  38.  * @package Models
  39.  * @subpackage Other
  40.  * 
  41.  */
  42. class Base
  43. {
  44.     /**
  45.      * Contains the path of the log files.
  46.      * @var string 
  47.      */
  48.     static private $_logPath;
  49.     
  50.     /**
  51.      * Contains the name of the default log file.
  52.      * @var string 
  53.      */
  54.     static private $_logFilename;
  55.     
  56.     /**
  57.      * Contains the logger class
  58.      * @var object Zend_Log 
  59.      */
  60.     static private $_logger;
  61.     /**
  62.      * Private constructor to prevent creation of this class.
  63.      * @return void 
  64.      */
  65.     private function __construct(){}
  66.     
  67.     /**
  68.      * Stores a given message to the log.
  69.      * 
  70.      * Zend_Log::EMERG: Emergency: system is unusable
  71.      * Zend_Log::ALERT: Alert: action must be taken immediately
  72.      * Zend_Log::CRIT: Critical: critical condition
  73.      * Zend_Log::ERR: Error: error conditions
  74.      * Zend_Log::WARN: Warning: warning conditions
  75.      * Zend_Log::NOTICE: Notice: normal but significant condition
  76.      * Zend_Log::INFO: Informational: informational messages
  77.      * Zend_Log::DEBUG: Debug: debug messages
  78.      * 
  79.      * @param $message 
  80.      * @param $type Type of the message
  81.      * @return void 
  82.      */
  83. //    static public function log($message, $type = Zend_Log::INFO)
  84. //    {
  85. //        //Logger does not already excist, create
  86. //        if(empty(self::$_logger) || !(self::$_logger instanceof Zend_Log))
  87. //        {
  88. //            //Load log path
  89. //            if(empty(self::$_logPath))
  90. //            {
  91. //                self::$_logPath = Zend_Registry::get('config')->log->path;
  92. //            }
  93. //
  94. //            //Load default filename
  95. //            if(empty(self::$_logFilename))
  96. //            {
  97. //                self::$_logFilename = Zend_Registry::get('config')->log->name_default_file;
  98. //            }
  99. //
  100. //            //Start class
  101. //            self::$_logger = new Zend_Log(new Zend_Log_Writer_Stream(BASE_PATH .  self::$_logPath . '/' . self::$_logFilename));
  102. //        }
  103. //
  104. //        self::$_logger->log($message, $type);
  105. //    }
  106.  
  107.     /**
  108.      * Get the ip address of the current user.
  109.      * 
  110.      * @return string 
  111.      */
  112.     public static function getRealIp()
  113.     {
  114.         if(!empty($_SERVER['HTTP_CLIENT_IP']))
  115.         {
  116.               $ip $_SERVER['HTTP_CLIENT_IP'];
  117.         }
  118.         elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
  119.         {
  120.              $ip $_SERVER['HTTP_X_FORWARDED_FOR'];
  121.         }
  122.             else
  123.         {
  124.               $ip $_SERVER['REMOTE_ADDR'];
  125.            }
  126.            
  127.         return $ip;
  128.     }
  129. }

Documentation generated on Mon, 27 Jul 2009 19:54:28 +0200 by phpDocumentor 1.4.1