Skip to content

Instantly share code, notes, and snippets.

@alwinmark
Created December 23, 2013 16:06
Show Gist options
  • Save alwinmark/8099632 to your computer and use it in GitHub Desktop.
Save alwinmark/8099632 to your computer and use it in GitHub Desktop.
Possible abstract Application class for the Lousson Project
<?php
namespace Lousson\Application;
use Lousson\Config\AnyConfig;
use Lousson\Config\Builtin\BuiltinConfig;
use Lousson\Config\AnyConfigLoader;
use Lousson\Config\Builtin\BuiltinConfigLoader;
require 'PEAR/Config.php';
abstract class AbstractApplication implements AnyConfig {
private static $instance;
protected $config = null;
protected static $ds = array();
public function __construct(AnyConfig $config) {
$this->config = $config;
}
public function addDatasource($name, Datasource $ds) {
$this->ds[$name] = $ds;
}
abstract public function initDatasources();
public static function getInstance(AnyConfigLoader $configLoader = null) {
if ($this->instance == null) {
if ($configLoader == null) {
$configLoader = new BuiltinConfigLoader();
}
$config = $configLoader->loadConfig(self::getConfigFile());
$clazz = __CLASS__;
self::$instance = new $clazz($config);
}
return self::$instance;
}
private static function getConfigFile() {
$base = "";
return $base . $_SERVER['Stage'] ."php.inc";
}
public function getOption($name, $fallback = null) {
$this->config->getOption($name, $fallback);
}
public function hasOption($name) {
$this->config->hasOption($name);
}
public function getDataSource($name) {
$this->ds[$name];
}
/**
* returns the PEAR constant cfg_dir which can be configured
* when pear gets installed or with: pear config-set cfg_dir [Path]
*
* @return String Path of the default config dir where all the config
* files of installed packages are lying.
*/
public static function getDefaultConfigDir()
{
return PEAR_CONFIG_DEFAULT_CFG_DIR;
}
/**
* returns the PEAR constant data_dir which can be configured
* when pear gets installed or with: pear config-set data_dir [Path]
*
* @return String Path of the default data dir where all the local
* databases and static files of installed packages are lying.
*/
public static function getDefaultDataDir()
{
return PEAR_CONFIG_DEFAULT_DATA_DIR;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment