<?php
function dump($debug) {
    switch (APPLICATION_ENV) {
        case 'production':
        case 'homolog':
            break;
        default:
            echo "<pre>";
            print_r($debug);
            echo "</pre>";
            die;
            break;
    }
}

try{
    date_default_timezone_set('America/Sao_Paulo');

    set_include_path(implode(
    PATH_SEPARATOR,
    array(realpath(dirname(__FILE__) . '/../library'),
    get_include_path())
    ));

    // Define path to application directory
    defined('APPLICATION') || define('APPLICATION', realpath(dirname(__FILE__)));
    defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
    defined('DDL_PATH') || define('DDL_PATH', realpath(dirname(__FILE__) . '/../DDL'));
    defined('LIBRARY') || define('LIBRARY', realpath(dirname(__FILE__) . '/../library'));

    define('RESOURCES', APPLICATION.'/resources');
    define('RESOURCES_JS', RESOURCES.'/javascript');
    define('RESOURCES_CSS', RESOURCES.'/css');

    // Define application environment
    defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

    /** Zend_Application */
    require_once 'Zend/Application.php';
    
    // Create application, bootstrap, and run
    $application = new Zend_Application(
            APPLICATION_ENV,
            APPLICATION_PATH . '/config/application.ini'
    );
    
    $application->bootstrap();
    $application->run();

} catch (\Exception $e){
    $message = '<div style="width:100%;text-align:center;vertical-align: middle;font-size: 20px">
            <h1>
            <u>Prezado desenvolvedor</u>
            </h1>
            <br>
            <br>
            <b>MESSAGE</b>
            </div>
            ';
    switch ($e->getCode()){
        case 7:
            print_r(str_ireplace("MESSAGE", "A base de dados configurada no application.ini nao existe, altere para uma base existente", $message));
            break;

        default:
            die($e->getMessage());
    }
}