Alpha Framework alpha--controller
[ class tree: alpha--controller ] [ index: alpha--controller ] [ all elements ]

Source for file ViewLog.php

Documentation is available at ViewLog.php

  1. <?php
  2.  
  3. // include the config file
  4. if(!isset($config)) {
  5.     require_once '../util/AlphaConfig.inc';
  6.     $config AlphaConfig::getInstance();
  7. }
  8.  
  9. require_once $config->get('sysRoot').'alpha/util/Logger.inc';
  10. require_once $config->get('sysRoot').'alpha/controller/AlphaController.inc';
  11. require_once $config->get('sysRoot').'alpha/controller/AlphaControllerInterface.inc';
  12. require_once $config->get('sysRoot').'alpha/util/LogFile.inc';
  13. require_once $config->get('sysRoot').'alpha/exceptions/IllegalArguementException.inc';
  14. require_once $config->get('sysRoot').'alpha/view/AlphaView.inc';
  15.  
  16. /**
  17.  * 
  18.  * Controller used to display a log file, the path for which must be supplied in GET vars
  19.  * 
  20.  * @package alpha::controller
  21.  * @since 1.0
  22.  * @author John Collins <dev@alphaframework.org>
  23.  * @version $Id: ViewLog.php 1453 2011-12-04 15:12:54Z johnc $
  24.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  25.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  26.  *  All rights reserved.
  27.  * 
  28.  *  <pre>
  29.  *  Redistribution and use in source and binary forms, with or
  30.  *  without modification, are permitted provided that the
  31.  *  following conditions are met:
  32.  * 
  33.  *  * Redistributions of source code must retain the above
  34.  *    copyright notice, this list of conditions and the
  35.  *    following disclaimer.
  36.  *  * Redistributions in binary form must reproduce the above
  37.  *    copyright notice, this list of conditions and the
  38.  *    following disclaimer in the documentation and/or other
  39.  *    materials provided with the distribution.
  40.  *  * Neither the name of the Alpha Framework nor the names
  41.  *    of its contributors may be used to endorse or promote
  42.  *    products derived from this software without specific
  43.  *    prior written permission.
  44.  *   
  45.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  46.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  47.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  48.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  49.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  50.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  51.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  52.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  53.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  54.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  55.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  56.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  57.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  58.  *  </pre>
  59.  *  
  60.  */
  61. class ViewLog extends AlphaController implements AlphaControllerInterface{    
  62.     /**
  63.      * The path to the log that we are displaying
  64.      * 
  65.      * @var string 
  66.      * @since 1.0
  67.      */
  68.     private $logPath;
  69.     
  70.     /**
  71.      * Trace logger
  72.      * 
  73.      * @var Logger 
  74.      * @since 1.0
  75.      */
  76.     private static $logger null;
  77.     
  78.     /**
  79.      * The constructor
  80.      * 
  81.      * @since 1.0
  82.      */
  83.     public function __construct({
  84.         self::$logger new Logger('ViewLog');
  85.         self::$logger->debug('>>__construct()');
  86.         
  87.         // ensure that the super class constructor is called, indicating the rights group
  88.         parent::__construct('Admin');
  89.         
  90.         $this->setTitle('Displaying the requested log');
  91.         
  92.         self::$logger->debug('<<__construct');
  93.     }
  94.     
  95.     /**
  96.      * Handle GET requests
  97.      * 
  98.      * @param array $params 
  99.      * @since 1.0
  100.      * @throws ResourceNotFoundException
  101.      */
  102.     public function doGET($params{
  103.         self::$logger->debug('>>doGET($params=['.var_export($paramstrue).'])');
  104.         
  105.         
  106.         try{
  107.             echo AlphaView::displayPageHead($this);
  108.     
  109.             // load the business object (BO) definition
  110.             if (isset($params['logPath'])) {
  111.                 $logPath $params['logPath'];    
  112.             }else{
  113.                 throw new IllegalArguementException('No log file path available to view!');
  114.             }
  115.             
  116.             $this->logPath $logPath;
  117.             
  118.             $log new LogFile($this->logPath);
  119.             if(preg_match("/alpha.*/"basename($this->logPath)))
  120.                 $log->renderLog(array('Date/time','Level','Class','Message','Client','IP'));
  121.             if(preg_match("/search.*/"basename($this->logPath)))
  122.                 $log->renderLog(array('Search query','Search date','Client Application','Client IP'));
  123.             if(preg_match("/feeds.*/"basename($this->logPath)))
  124.                 $log->renderLog(array('Business object','Feed type','Request date','Client Application','Client IP'));
  125.             if(preg_match("/tasks.*/"basename($this->logPath)))
  126.                 $log->renderLog(array('Date/time','Level','Class','Message'));
  127.             
  128.             echo AlphaView::displayPageFoot($this);
  129.         }catch (IllegalArguementException $e{
  130.             self::$logger->error($e->getMessage());
  131.             throw new ResourceNotFoundException('File not found');
  132.         }
  133.         
  134.         self::$logger->debug('<<doGET');
  135.     }
  136.     
  137.     /**
  138.      * Handle POST requests
  139.      * 
  140.      * @param array $params 
  141.      * @since 1.0
  142.      */
  143.     public function doPOST($params{
  144.         self::$logger->debug('>>doPOST($params=['.var_export($paramstrue).'])');
  145.         
  146.         self::$logger->debug('<<doPOST');
  147.     }
  148. }
  149.  
  150. // now build the new controller if this file is called directly
  151. if ('ViewLog.php' == basename($_SERVER['PHP_SELF'])) {
  152.     $controller new ViewLog();
  153.     
  154.     if(!empty($_POST)) {            
  155.         $controller->doPOST($_POST);
  156.     }else{
  157.         $controller->doGET($_GET);
  158.     }
  159. }
  160.  
  161. ?>

Documentation generated on Tue, 13 Dec 2011 20:27:53 +0000 by phpDocumentor 1.4.3