Created
December 17, 2018 13:46
-
-
Save BerezhniyDmitro/c86bb8c7fb80efe44a43fae5182b2ea7 to your computer and use it in GitHub Desktop.
This file contains 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 | |
namespace Components\Core; | |
use Symfony\Component\DependencyInjection\ContainerBuilder; | |
use Symfony\Component\Config\FileLocator; | |
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; | |
class Container | |
{ | |
/** @var Container */ | |
private static $instance; | |
public $container; | |
/** | |
* Container constructor. | |
* @throws \Exception | |
*/ | |
private function __construct() | |
{ | |
$containerBuilder = new ContainerBuilder(); | |
$dirName = str_replace('core', 'config/yml', __DIR__); | |
$loader = new YamlFileLoader($containerBuilder, new FileLocator($dirName)); | |
$loader->load('config.yml', 'yml'); | |
$containerBuilder->compile(); | |
$this->container = $containerBuilder; | |
} | |
/** | |
* @return Container | |
* @throws \Exception | |
*/ | |
public static function instance() | |
{ | |
if (!self::$instance) { | |
self::$instance = new self(); | |
} | |
return self::$instance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment