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

Source for file Stat.php

Documentation is available at Stat.php

  1. <?php
  2. /**
  3.  * Mai_Stat
  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.  * @category Mai
  26.  * @package Stat
  27.  * 
  28.  */
  29.  
  30. /**
  31.  * Mai_Stat is a statistics manager of 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.  * @category Mai
  39.  * @package Stat
  40.  * 
  41.  */
  42.  
  43. class Mai_Stat
  44. {
  45.     /**
  46.      * @var Mai_Stat Singleton instance
  47.      */
  48.     protected static $_instance;
  49.     
  50.     /**
  51.      * @var integer The start time.
  52.      */
  53.     protected static $_timeStart;
  54.  
  55.     /**
  56.      *
  57.      * @var integer The end time.
  58.      */
  59.     protected static $_timeEnd;
  60.  
  61.     /**
  62.      * @var integer Status of Mai_Stat
  63.      */
  64.     protected static $_status self::WAITING_FOR_START;
  65.  
  66.     /**
  67.      * Constants for the status of Mai_Stat
  68.      */
  69.     const WAITING_FOR_START 0;
  70.     const STARTED 1;
  71.     const ENDED 2;
  72.  
  73.     /**
  74.      * Private constructor to prevent creation of this object.
  75.      * @return void 
  76.      */
  77.     private function __construct(){}
  78.     
  79.     /**
  80.      * Retrieve singleton instance
  81.      * 
  82.      * @return Mai_Stat 
  83.      */
  84.     public static function getInstance()
  85.     {            
  86.         if(!Mai::isInit())
  87.         {
  88.             trigger_error('Mai has not been setup yet. Please use Mai::init().'E_USER_ERROR);
  89.         }
  90.         
  91.         if (null === self::$_instance{
  92.             self::$_instance new self();
  93.         }
  94.         return self::$_instance;
  95.     }
  96.     
  97.     /**
  98.      * Start the statistics.
  99.      * @return void 
  100.      */
  101.     public static function start()
  102.     {
  103.         self::$_status self::STARTED;
  104.         
  105.         //Get time in seconds
  106.         self::$_timeStart microtime(true);
  107.     }
  108.     
  109.     /**
  110.      * Exit the statistics.
  111.      * @return void 
  112.      */
  113.     public static function end()
  114.     {
  115.         self::$_status self::ENDED;
  116.  
  117.         //Get time in seconds
  118.         self::$_timeEnd microtime(true);
  119.     }
  120.  
  121.     public function executionTime()
  122.     {
  123.         if(self::$_status == self::ENDED)
  124.         {
  125.             return self::$_timeEnd self::$_timeStart;
  126.         }
  127.         else
  128.         {
  129.             trigger_error("Mai_Stat not ended yet."E_USER_NOTICE);
  130.         }
  131.     }
  132.     
  133.     /**
  134.      * Cloning of a singleton class is not allowed.
  135.      * @return void 
  136.      */
  137.     final public function __clone()
  138.     {
  139.         trigger_error('Clone is not allowed.'E_USER_ERROR);
  140.     }
  141.  
  142.     /**
  143.      * Function to prevent deserializing
  144.      * @return void 
  145.      */
  146.     public function __wakeup()
  147.     {
  148.         trigger_error('Deserializing is not allowed.'E_USER_ERROR);
  149.     }
  150. }

Documentation generated on Mon, 27 Jul 2009 19:55:13 +0200 by phpDocumentor 1.4.1