Skip to content

Commit

Permalink
Added namespace for service
Browse files Browse the repository at this point in the history
  • Loading branch information
taiwen committed Apr 28, 2011
1 parent 433115f commit f69ed09
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
10 changes: 6 additions & 4 deletions XoopsEngine/lib/Kernel/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
class Service
{
protected static $services = array();
protected static $engine;

public function __construct()
public function __construct($engineName = 'xoops')
{
static::$engine = ucfirst($engineName);
}

public function load($name, $options = array())
Expand All @@ -33,10 +35,10 @@ public function load($name, $options = array())
if (!isset(static::$services[$key])) {
static::$services[$key] = false;
// Loads custom service
$class = "Engine\\" . ucfirst(\XOOPS::config("identifier")) . "\\Service\\" . ucfirst($key);
$class = "Engine\\" . static::$engine . "\\Service\\" . ucfirst($name);
if (!class_exists($class)) {
// If custom service not defined, loads kernel service
$class = "Kernel\\Service\\" . ucfirst($key);
$class = "Kernel\\Service\\" . ucfirst($name);
if (!class_exists($class)) {
trigger_error("Service class \"{$class}\" was not loaded.", E_USER_ERROR);
return static::$services[$key];
Expand All @@ -45,7 +47,7 @@ public function load($name, $options = array())

static::$services[$key] = new $class($options);
if (!(static::$services[$key] instanceof Service\ServiceAbstract)) {
throw new \Exception("Invalid service instantiation '{$key}'!");
throw new \Exception("Invalid service instantiation '{$name}'!");
}
if ($log = $this->getService('logger')) {
$log->info("Service '{$name}' is loaded", "service");
Expand Down
2 changes: 1 addition & 1 deletion XoopsEngine/lib/Kernel/Service/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function getLogs()

public function shutdown()
{
if (!$this->enabled() || !sef::getLogger()) {
if (!$this->enabled() || !$this->getLogger()) {
return;
}

Expand Down
5 changes: 4 additions & 1 deletion XoopsEngine/lib/Xoops.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ public static function service($name = null, $options = array())
{
// Singleton
if (!isset(self::$service)) {
self::$service = new Kernel\Service();
// self::$engine -- Engine\Xoops\Engine
$engineNameSegs = explode('\\', get_class(self::$engine));
$engineName = $engineNameSegs[1];
self::$service = new Kernel\Service($engineName);
}
// Return service handler
if (null === $name) {
Expand Down

0 comments on commit f69ed09

Please sign in to comment.