Skip to content

Instantly share code, notes, and snippets.

@BerezhniyDmitro
Created December 17, 2018 13:46
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 BerezhniyDmitro/c86bb8c7fb80efe44a43fae5182b2ea7 to your computer and use it in GitHub Desktop.
Save BerezhniyDmitro/c86bb8c7fb80efe44a43fae5182b2ea7 to your computer and use it in GitHub Desktop.
<?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