amdp3-metaforums/Application/Services/ServiceContainer.php

22 lines
606 B
PHP
Raw Permalink Normal View History

2019-11-17 19:22:25 +00:00
<?php
2019-11-18 13:33:45 +00:00
namespace Application\Services;
2019-11-17 19:22:25 +00:00
class ServiceContainer{
private static $services = [];
public static function get($service) {
if(!isset(self::$services[$service])) {
self::load($service);
}
return self::$services[$service];
}
public static function load($service) {
2019-11-18 13:33:45 +00:00
$class = 'Application\\Services\\'.$service;
2019-11-17 19:22:25 +00:00
self::$services[$service] = new $class();
}
public static function __callStatic($name, $args) {
// Allow services to be referenced as ServiceContainer::Service()
return self::get($name);
}
}