amdp3-metaforums/Application/Services/ServiceContainer.php
2019-11-19 02:18:37 +07:00

22 lines
606 B
PHP

<?php
namespace Application\Services;
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) {
$class = 'Application\\Services\\'.$service;
self::$services[$service] = new $class();
}
public static function __callStatic($name, $args) {
// Allow services to be referenced as ServiceContainer::Service()
return self::get($name);
}
}