Skip to content

Instantly share code, notes, and snippets.

@wodor
Created August 19, 2011 12:31
Show Gist options
  • Select an option

  • Save wodor/1156701 to your computer and use it in GitHub Desktop.

Select an option

Save wodor/1156701 to your computer and use it in GitHub Desktop.
ServiceContainerFactory
<?php
class ServiceContainerFactory {
private static $instances = array();
private static $coreSiteId = null;
/**
* Site id po raz pierwszy użyty implikuje późniejszy domyślny siteId
* @param int $siteId
* @return Symfony\Component\DependencyInjection\ContainerBuilder
*/
public static function getInstance($siteId = null) {
if(self::$coreSiteId == null && $siteId == null) {
throw new Exception("Container has no site id");
}
elseif(self::$coreSiteId == null ) {
self::$coreSiteId = $siteId;
}
elseif($siteId == null) {
$siteId = self::$coreSiteId;
}
if(empty($instances[$siteId])) {
$ContainerBuilder = new \Symfony\Component\DependencyInjection\ContainerBuilder();
$ContainerBuilderLoader = new \Symfony\Component\DependencyInjection\Loader\XmlFileLoader($ContainerBuilder,new \Symfony\Component\Config\FileLocator(__DIR__.'/../../conf/serviceContainer/'));
$ContainerBuilderLoader->load('container.xml');
$ContainerBuilderLoader->load('container.cc.'.$siteId.'.xml');
$instances[$siteId] = $ContainerBuilder;
}
return $instances[$siteId];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment