Created
August 19, 2011 12:31
-
-
Save wodor/1156701 to your computer and use it in GitHub Desktop.
ServiceContainerFactory
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 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