Show index.php syntax highlighted
<?php
/**
* Astrum Futura: Open Source Space Strategy Game
*
* LICENSE
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@astrumfutura.com so we can send you a copy immediately.
*
* @category Astrum
* @package Astrum
* @copyright Copyright (c) 2007 Pádraic Brady (http://blog.quantum-star.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @version $Id: index.php 91 2007-04-18 00:33:04Z santosj $
*/
/*
* Bootstrap for Astrum Futura and Zend Framework SVN
*/
error_reporting(E_ALL^E_NOTICE);
ini_set('display_errors', 1);
date_default_timezone_set('Europe/London');
/*
* For hosts that don't have mod_php SAPI, turn magic_quotes off. It is
* however, impossible to turn magic_quotes off during run time.
*/
set_magic_quotes_runtime(0);
/*
* Setup Autoloading (To be removed for development!)
*
* Autoload classes prior to first use based on
* the logic contained in __autoload function.
* Assumes files and classes follow the PEAR
* convention.
*/
function __autoload($class)
{
$path = str_replace('_', DIRECTORY_SEPARATOR, $class);
require $path . '.php';
}
/*
* The library_path.php file gets the constants for the library
* paths that can be separate from the Astrum Futura project.
*/
include './library_path.php';
/*
* Setup the include_path to the ZF library.
* We set the incubator first so the
* incubator classes are loaded in preference
* to core ZF classes where two versions exist.
*
* When 0.60 is released, the MVC classes in
* Incubator will move to the core library.
*/
/*
* In some SAPIs, '.;' is not set correctly. Caused some problems and none
* correct errors. I don't think it will hurt that much having it two or more times
* Actually, I know it won't hurt having it two or more times.
*/
set_include_path( '.'
. PATH_SEPARATOR . './library/zendframework/incubator'
. PATH_SEPARATOR . LIB_PATH_ZEND_FRAMEWORK
. PATH_SEPARATOR . LIB_PATH_SWIFT_MAILER
. PATH_SEPARATOR . LIB_PATH_ADODB_LITE
. PATH_SEPARATOR . './library/quantumstar'
. PATH_SEPARATOR . './library/astrumfutura'
. PATH_SEPARATOR . './application/tables'
. PATH_SEPARATOR . get_include_path()
);
/*
* On my platform, I need to set the BaseURL for ZF 0.20
* RewriteBase is assumed to be $_SERVER['PHP_SELF'] after
* removing the trailing "index.php" string.
*
* PHP_SELF can be user manipulated. Avoided using SCRIPT_NAME
* or SCRIPT_FILENAME because they may differ depending on SAPI
* being used.
*/
$base_url = substr($_SERVER['PHP_SELF'], 0, -9);
/*
* Create any objects needed for use in
* controllers. Can avoid using a static Registry
* with this method (cleaner).
*/
/*
* Create Registry
*/
require_once 'Astrum/Registry.php';
$registry = Astrum_Registry::getInstance();
/*
* Create View object
*/
require_once 'Astrum/View.php';
$view = new Astrum_View();
$view->setScriptPath('./views/en');
/* Set temporary theme and other variables */
$view->THEME = $base_url . 'themes/default';
$view->VERSION = '0.01preview';
$view->URLROOT = $base_url;
/* --------------------------------------- */
/*
* Create Session object
* Expire authentication flag after 5 minutes
*/
require_once 'Zend/Session.php';
Zend_Session::start();
$sessionDefaultNamespace = new Zend_Session_Namespace('astrumFuturaNamespace');
$sessionDefaultNamespace->setExpirationSeconds(300, 'authenticated');
Astrum_Registry::set('session', $sessionDefaultNamespace);
/*
* Create Cache object
*/
require_once 'Zend/Cache.php';
$frontendOptions = array(
'lifeTime' => 7200, // cache lifetime of 2 hours
'automaticSerialization' => true
);
$backendOptions = array(
'cacheDir' => './tmp/' // Directory where to put the cache files
);
// getting a Zend_Cache_Core object
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
/*
* Create DB Config object
*/
$db_config = new Zend_Config_Ini('./data/db.ini', 'local');
$registry['dbconfig'] = $db_config;
/*
* Get database connection and set on Registry. We currently use the ADOdb-Lite
* library ro abstract the database connection.
*/
require 'adodb.inc.php';
try
{
$options = array(
'driver'=>$db_config->driver,
'username'=>$db_config->username,
'password'=>$db_config->password,
'database'=>$db_config->database,
'host'=>$db_config->host
);
/*
* For the Installer, make sure the database
* exists before sending to index.php
*/
$db = Quantum_Db::factory($options);
$dao = Quantum_Db_Access::getInstance($db);
$registry['dbaccess'] = $dao;
}
catch(Quantum_Db_Exception $e)
{
echo $e->getCode, ': ', $e->getMessage(), "<br />\n";
}
/*
* Instantiate a RewriteRouter
*
* Disable default behaviour of allowing
* arbitrary parameters appended to URI
*/
try
{
$router = new Zend_Controller_Router_Rewrite();
/*
* This will throw Exception, catch and do nothing.
*/
$router->removeRoute('default');
}
catch(Zend_Controller_Router_Exception $e)
{
// Catching and doing nothing
//echo $e->getCode, ': ', $e->getMessage(), "<br />\n";
}
/*
* @todo Set applicable routes (move to new file when large enough)
*/
$routes = array();
$routes['astrum_default'] = new Zend_Controller_Router_Route(':controller/:action', array('controller' => 'index', 'action' => 'index'));
//$routes['astrum_static'] = new Zend_Controller_Router_StaticRoute(':controller', array('controller' => 'index', 'action' => 'index'));
$router->addRoutes($routes);
/*
* Require custom Zend_Controller_Action subclass.
*
* This subclass is specific to Astrum_Futura and sets up some new properties
* containing references to the most commonly used objects in our app. See the
* Zend_Controller_Front::setParam() method as used below.
*/
require_once('Astrum/Controller/Action.php');
/*
* Setup and run the Front Controller
*
* Set Controller Dir, add the RewriteRouter, set
* params to be passed to Controller, set a custom
* custom Base URL, dispatch the request and get
* the resulting Response object.
*/
$controller = Zend_Controller_Front::getInstance();
/*
* Create filters and pass to Controller
* This will disable the GET/POST superglobals
* and force access through the filter object
*/
if(isset($_POST) and !empty($_POST))
{
$controller->setParam('post', new Zend_Filter_Input($_POST));
}
if(isset($_GET) and !empty($_GET))
{
$controller->setParam('get', new Zend_Filter_Input($_GET));
}
/*
* Add other common objects to be
* passed to Controller.
*/
$controller ->setParam('view', $view)
->setParam('session', $sessionDefaultNamespace)
->setParam('registry', $registry)
->setParam('cache', $cache)
->setParam('dao', $dao);
$controller->returnResponse(true);
$response = $controller
->setControllerDirectory('./application/controllers')
->setRouter($router)
->setBaseUrl($base_url)
->dispatch();
/*
* By default Exceptions are not displayed.
* That won't do during development.
* Remove this in a live environment!
*/
$response->renderExceptions(true);
/*
* Echo the response (with headers) to client.
* Zend_Controller_Response_Http implements
* __toString().
*/
echo $response;
See more files for this project here