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

Source for file Application.php

Documentation is available at Application.php

  1. <?php
  2. /**
  3.  * Console Library
  4.  *
  5.  * LICENSE
  6.  *
  7.  * "THE BEER-WARE LICENSE" (Revision 42):
  8.  * "Sven Strittmatter" <ausserirdisch@sven-space.de> wrote this file.
  9.  * As long as you retain this notice you can do whatever you want with
  10.  * this stuff. If we meet some day, and you think this stuff is worth it,
  11.  * you can buy me a beer in return.
  12.  *
  13.  * $Author: sxs $
  14.  * $Revision: 161 $
  15.  * 
  16.  * @category    Console
  17.  * @package     Console_Application
  18.  * @copyright   Copyright (c) 2009 Sven Strittmatter
  19.  */
  20.  
  21. /**
  22.  * Console_Loader.
  23.  *
  24.  * @see Console_Loader
  25.  */
  26. require_once('Console/Loader.php');
  27. /**
  28.  * Console_Exception.
  29.  *
  30.  * @see Console_Exception
  31.  */
  32. require_once('Console/Exception.php');
  33.  
  34. /**
  35.  * Class for running a Console_Application_Abstract-Script.
  36.  *
  37.  * @final
  38.  * @category   Console
  39.  * @package    Console_Application
  40.  * @uses       Console_Loader
  41.  * @uses       Console_Exception
  42.  * @copyright  Copyright (c) 2009 Sven Strittmatter
  43.  */
  44. final class Console_Application {
  45.     /**
  46.      * Loads a class named ${applicationName}Application in the direcotry
  47.      * ${directory} and executes it.
  48.      *
  49.      * @static
  50.      * @access public
  51.      * @param string $applicationName 
  52.      * @param string $direcotry Optional;
  53.      * @param int $maxExecutionTime Optional;
  54.      * @param string $memoryLimit Optional;
  55.      * @return Console_Application_Interface 
  56.      * @throws Console_Exception If file is not readable
  57.      */
  58.     public static function execute($applicationName$direcotry '.'$maxExecutionTime 60$memoryLimit '128M'{
  59.         $className  $applicationName 'Application';
  60.  
  61.         if (!class_exists($classNamefalse)) {
  62.             $fileName $direcotry DIRECTORY_SEPARATOR $className '.php';
  63.             
  64.             if (Console_Loader::isReadable($fileName)) {
  65.                 require_once($fileName);
  66.             else {
  67.                 throw new Console_Exception('Cant require console file: ' $fileName);
  68.             }
  69.         }
  70.  
  71.         $scriptName  strtolower($applicationName'.sh';
  72.         $application new $className($scriptName$maxExecutionTime$memoryLimit);
  73.  
  74.         if (!$application instanceof Console_Application_Interface{
  75.             throw new Console_Exception($className ' must implement the interface Console_Application_Interface!');
  76.         }
  77.  
  78.         $application->execute();
  79.  
  80.         return $application;
  81.     }
  82. }

Documentation generated on Mon, 17 Aug 2009 15:52:25 +0200 by phpDocumentor 1.4.2