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

Source for file AbstractDbApplication.php

Documentation is available at AbstractDbApplication.php

  1. <?php
  2. /**
  3.  * MediaSearch
  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$
  14.  * $Revision$
  15.  *
  16.  * @category    MediaSearch
  17.  * @package     Console_Application
  18.  * @copyright   Copyright (c) 2009 Sven Strittmatter
  19.  */
  20.  
  21. /**
  22.  * Console_Application_Abstract
  23.  *
  24.  * @see Console_Application_Abstract
  25.  */
  26. require_once('Console/Application/Abstract.php');
  27. /**
  28.  * Console_Exception
  29.  *
  30.  * @see Console_Exception
  31.  */
  32. require_once('Console/Exception.php');
  33. /**
  34.  * Zend_Application
  35.  *
  36.  * @see Zend_Application
  37.  */
  38. require_once('Zend/Application.php');
  39.  
  40. /**
  41.  * This basic console application provides the ability to bootstrap
  42.  * the Zend_Db resource. Derive this class to use the applications
  43.  * db resource (see application/configs/application.ini).
  44.  *
  45.  * @see Console_Application_Abstract
  46.  *
  47.  * @abstract
  48.  * @category   MediaSearch
  49.  * @package    Console_Application
  50.  * @uses       Console_Application_Abstract
  51.  * @uses       Console_Exception
  52.  * @uses       Zend_Application
  53.  * @copyright  Copyright (c) 2009 Sven Strittmatter
  54.  */
  55. abstract class AbstractDbApplication extends Console_Application_Abstract {
  56.     /**
  57.      * The database resource object.
  58.      *
  59.      * @access protected
  60.      * @var Zend_Application_Resource_Db 
  61.      */
  62.     protected $dbResource;
  63.     /**
  64.      * The datavase name the database resource is
  65.      * configured for.
  66.      *
  67.      * @access protected
  68.      * @var string 
  69.      */
  70.     protected $dbName;
  71.  
  72.     /**
  73.      * Bootstraps a Zend_Application bject with the config from
  74.      * APPLICATION_PATH . '/configs/application.ini'. Loads the
  75.      * database resource and database name.
  76.      *
  77.      * @access protected
  78.      */
  79.     protected function setUp({
  80.         $application      new Zend_Application(APPLICATION_ENV,
  81.                                 APPLICATION_PATH '/configs/application.ini');
  82.         $application->bootstrap();
  83.         $this->dbResource = $application->getBootstrap()->getPluginResource('db');
  84.         $options          $this->dbResource->getOptions();
  85.         $this->dbName     = $options['params']['dbname'];
  86.     }
  87.  
  88.     /**
  89.      * Resets the database resource object to null.
  90.      *
  91.      * @access protected
  92.      */
  93.     protected function tearDown({
  94.         $this->dbResource = null;
  95.     }
  96.  
  97.     /**
  98.      * If verbosity is given (by option -v) exception messages, errormessgaes
  99.      * or given variables are echoed to the stdout.
  100.      *
  101.      * @access protected
  102.      * @param mixed $errorData 
  103.      */
  104.     protected function onError($errorData{
  105.         parent::onError($errorData);
  106.  
  107.         if ($this->isVerbose()) {
  108.             if ($errorData instanceof Excpetion{
  109.                 $this->echoMsg($errorData->getMessage());
  110.             else if (is_string($errorData)) {
  111.                 $this->echoMsg($errorData);
  112.             else {
  113.                 $this->echoMsg(print_r($errorDatatrue));
  114.             }
  115.         }
  116.     }
  117.  
  118.     /**
  119.      * Aborts the script if ctrl + c is pressed.
  120.      *
  121.      * @access public
  122.      * @param int $signal 
  123.      */
  124.     public function signalInt($signal{
  125.         throw new Console_Exception('Script aborted by user!');
  126.     }
  127. }

Documentation generated on Mon, 17 Aug 2009 14:51:32 +0200 by phpDocumentor 1.4.2