summaryrefslogtreecommitdiff
path: root/services
diff options
context:
space:
mode:
Diffstat (limited to 'services')
-rw-r--r--services/servicefactory.php60
-rw-r--r--services/templateservice.php78
2 files changed, 69 insertions, 69 deletions
diff --git a/services/servicefactory.php b/services/servicefactory.php
index 7ff7f22..f4d6af7 100644
--- a/services/servicefactory.php
+++ b/services/servicefactory.php
@@ -1,35 +1,35 @@
<?php
-/* Build services */
+/* Connect to the database and build services */
class ServiceFactory {
- function ServiceFactory(&$db, $serviceoverrules = array()) {
- }
-
- function &getServiceInstance($name, $servicedir = NULL) {
- global $dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist, $dbtype;
- static $instances = array();
- static $db;
- if (!isset($db)) {
- require_once(dirname(__FILE__) .'/../includes/db/'. $dbtype .'.php');
- $db = new sql_db();
- $db->sql_connect($dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist);
- if(!$db->db_connect_id) {
- message_die(CRITICAL_ERROR, "Could not connect to the database", $db);
- }
- }
- if (!isset($instances[$name])) {
- if (isset($serviceoverrules[$name])) {
- $name = $serviceoverrules[$name];
- }
- if (!class_exists($name)) {
- if (!isset($servicedir)) {
- $servicedir = dirname(__FILE__) .'/';
- }
- require_once($servicedir . strtolower($name) . '.php');
- }
- $instances[$name] = call_user_func(array($name, 'getInstance'), $db);
- }
- return $instances[$name];
- }
+ function ServiceFactory(&$db, $serviceoverrules = array()) {
+ }
+
+ function &getServiceInstance($name, $servicedir = NULL) {
+ global $dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist, $dbtype;
+ static $instances = array();
+ static $db;
+ if (!isset($db)) {
+ require_once(dirname(__FILE__) .'/../includes/db/'. $dbtype .'.php');
+ $db = new sql_db();
+ $db->sql_connect($dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist);
+ if(!$db->db_connect_id) {
+ message_die(CRITICAL_ERROR, "Could not connect to the database", $db);
+ }
+ }
+ if (!isset($instances[$name])) {
+ if (isset($serviceoverrules[$name])) {
+ $name = $serviceoverrules[$name];
+ }
+ if (!class_exists($name)) {
+ if (!isset($servicedir)) {
+ $servicedir = dirname(__FILE__) .'/';
+ }
+ require_once($servicedir . strtolower($name) . '.php');
+ }
+ $instances[$name] = call_user_func(array($name, 'getInstance'), $db);
+ }
+ return $instances[$name];
+ }
}
?>
diff --git a/services/templateservice.php b/services/templateservice.php
index 191ab8d..05e494c 100644
--- a/services/templateservice.php
+++ b/services/templateservice.php
@@ -1,46 +1,46 @@
<?php
class TemplateService {
- var $basedir;
-
- function &getInstance() {
- static $instance;
- if (!isset($instance))
- $instance =& new TemplateService();
- return $instance;
- }
-
- function TemplateService() {
- $this->basedir = $GLOBALS['TEMPLATES_DIR'];
- }
-
- function loadTemplate($template, $vars = NULL) {
- if (substr($template, -4) != '.php')
- $template .= '.php';
- $tpl =& new Template($this->basedir .'/'. $template, $vars, $this);
- $tpl->parse();
- return $tpl;
- }
+ var $basedir;
+
+ function &getInstance() {
+ static $instance;
+ if (!isset($instance))
+ $instance =& new TemplateService();
+ return $instance;
+ }
+
+ function TemplateService() {
+ $this->basedir = $GLOBALS['TEMPLATES_DIR'];
+ }
+
+ function loadTemplate($template, $vars = NULL) {
+ if (substr($template, -4) != '.php')
+ $template .= '.php';
+ $tpl =& new Template($this->basedir .'/'. $template, $vars, $this);
+ $tpl->parse();
+ return $tpl;
+ }
}
class Template {
- var $vars = array();
- var $file = '';
- var $templateservice;
-
- function Template($file, $vars = NULL, &$templateservice) {
- $this->vars = $vars;
- $this->file = $file;
- $this->templateservice = $templateservice;
- }
-
- function parse() {
- if (isset($this->vars))
- extract($this->vars);
- include($this->file);
- }
-
- function includeTemplate($name) {
- return $this->templateservice->loadTemplate($name, $this->vars);
- }
+ var $vars = array();
+ var $file = '';
+ var $templateservice;
+
+ function Template($file, $vars = NULL, &$templateservice) {
+ $this->vars = $vars;
+ $this->file = $file;
+ $this->templateservice = $templateservice;
+ }
+
+ function parse() {
+ if (isset($this->vars))
+ extract($this->vars);
+ include($this->file);
+ }
+
+ function includeTemplate($name) {
+ return $this->templateservice->loadTemplate($name, $this->vars);
+ }
}
?> \ No newline at end of file