Overview

Namespaces

  • Minion
    • Service
    • Twig

Classes

  • Minion\Application
  • Minion\Console
  • Minion\Controller
  • Minion\Service\ServiceConfig
  • Minion\Service\ServiceProvider
  • Minion\Twig\AssetExtension
  • Minion\Twig\MiscExtension
  • Minion\Twig\TwigExtensionTagServiceProvider
  • Minion\Twig\UrlExtension
  • Minion\Utils

Interfaces

  • Minion\ControllerInterface
  • Minion\Service\ServiceConfigInterface
  • Minion\Service\ServiceProviderInterface
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Minion package.
  5:  * For the full copyright and license information, please view the LICENSE
  6:  * file that was distributed with this source code.
  7:  *
  8:  * @license MIT License
  9:  */
 10: 
 11: namespace Minion\Service;
 12: 
 13: use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
 14: use Symfony\Component\HttpFoundation\ParameterBag;
 15: 
 16: /**
 17:  * Class ServiceConfig.
 18:  *
 19:  * @package Minion
 20:  * @author Damian SzczerbiƄski <dszczer@gmail.com>
 21:  */
 22: class ServiceConfig implements ServiceConfigInterface
 23: {
 24:     /** @var string Service identifier */
 25:     protected $id;
 26:     /** @var string Service provider fully qualified class name */
 27:     protected $providerClass;
 28:     /** @var array Service related tags */
 29:     protected $tags;
 30:     /** @var ParameterBag Service options */
 31:     protected $options;
 32: 
 33:     /**
 34:      * {@inheritdoc}
 35:      */
 36:     public function __construct($id, array $parsed) {
 37:         $class = null;
 38:         $options = $tags = [];
 39:         if(isset($parsed['class']))
 40:             if(\is_string($parsed['class']))
 41:                 if(\class_exists($parsed['class']))
 42:                     $class = $parsed['class'];
 43:                 else throw new InvalidConfigurationException("Class '{$parsed['class']}' defined in '$id' not found");
 44:             else throw new InvalidConfigurationException("Class argument is not a string");
 45:         else throw new InvalidConfigurationException("Missing 'class' for '$id' service");
 46:         if(isset($parsed['options'])) {
 47:             if(\is_array($parsed['options']))
 48:                 $options = $parsed['options'];
 49:             else throw new InvalidConfigurationException("service options must be an array");
 50:         }
 51:         if(isset($parsed['tags'])) {
 52:             if(\is_array($parsed['tags']))
 53:                 $tags = $parsed['tags'];
 54:             else throw new InvalidConfigurationException("service tags must be an array");
 55:         }
 56: 
 57:         $this->id = $id;
 58:         $this->providerClass = $class;
 59:         $this->options = new ParameterBag($options);
 60:         $this->tags = $tags;
 61:     }
 62: 
 63:     /**
 64:      * {@inheritdoc}
 65:      */
 66:     public function getTags() {
 67:         return $this->tags;
 68:     }
 69: 
 70:     /**
 71:      * {@inheritdoc}
 72:      */
 73:     public function getId() {
 74:         return $this->id;
 75:     }
 76: 
 77:     /**
 78:      * {@inheritdoc}
 79:      */
 80:     public function getOption($name) {
 81:         if(!$this->options->has($name))
 82:             throw new \InvalidArgumentException("Option '$name' is not defined");
 83: 
 84:         return $this->options->get($name);
 85:     }
 86: 
 87:     /**
 88:      * {@inheritdoc}
 89:      */
 90:     public function getOptions() {
 91:         return $this->options->all();
 92:     }
 93: 
 94:     /**
 95:      * {@inheritdoc}
 96:      */
 97:     public function getProviderClass() {
 98:         return $this->providerClass;
 99:     }
100: }
API documentation generated by ApiGen