Last active
October 7, 2015 09:27
20 lines service container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Class ServiceContainer { | |
public $services; | |
private $container; | |
public static function get($service) { | |
$container = ServiceContainer::getContainer(); | |
return $container->services[$service]; | |
} | |
public static function set($service, $object) { | |
$container = ServiceContainer::getContainer(); | |
$container->services[$service] = $object; | |
} | |
private static function getContainer() { | |
static $container = NULL; | |
if (is_null($container)) { | |
$container = new ServiceContainer(); | |
} | |
return $container; | |
} | |
private function __construct() { | |
$this->services = array(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment