Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace MyCompany\Api\DependencyInjection;
- use Symfony\Component\DependencyInjection\ContainerBuilder;
- use Symfony\Component\DependencyInjection\Loader;
- use Symfony\Component\Config\FileLocator;
- use MyCompany\Api\Exception\ApiException;
- /**
- * Class MyCompanyApiConfig
- * @package MyCompany\Api\DependencyInjection
- */
- class MyCompanyApiConfig {
- /** @var MyCompanyApiConfig - Hold an instance of the class */
- private static $instance;
- private static $container;
- /**
- * The singleton method
- *
- * @return \MyCompany\Api\DependencyInjection\MyCompanyApiConfig
- */
- public static function getInstance() {
- if (!isset(self::$instance)) {
- self::$instance = new MyCompanyApiConfig();
- }
- return self::$instance;
- }
- /**
- * Handle dynamic, static calls to the object.
- *
- * @param string $method
- * @param array $args
- * @return mixed
- *
- * @throws ApiException
- */
- public static function __callStatic($method, $args) {
- $instance = static::getInstance();
- if (!$instance) {
- throw new ApiException('Unable to load the class instance.');
- }
- return $instance->$method(...$args);
- }
- /**
- * @param $varName
- * @return mixed
- * @throw \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
- */
- public static function get($varName) {
- return self::loadConfig()->getParameter($varName);
- }
- /**
- * @return \Symfony\Component\DependencyInjection\ContainerBuilder
- */
- public static function loadConfig() {
- if (empty(self::$container)) {
- self::$container = new ContainerBuilder();
- $loader = new Loader\YamlFileLoader(self::$container, new FileLocator(__DIR__.'/../Resources/config'));
- $loader->load('services.yml');
- $loader->load('config.yml');
- }
- return self::$container;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement