Skip to content

Instantly share code, notes, and snippets.

@DavidHernandez
Last active October 7, 2015 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidHernandez/b1ce9634a6857f23acf5 to your computer and use it in GitHub Desktop.
Save DavidHernandez/b1ce9634a6857f23acf5 to your computer and use it in GitHub Desktop.
20 lines service container
<?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