amdp3-metaforums/backend/Mitsumine/Services/ServiceContainer.php

22 lines
602 B
PHP
Raw Normal View History

2019-11-17 19:22:25 +00:00
<?php
namespace Mitsumine\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 = 'Mitsumine\\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);
}
}