vendor/pimcore/php-templating-engine-bundle/src/Pimcore/Templating/Model/ViewModel.php line 17

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under following license:
  6.  * - Pimcore Commercial License (PCL)
  7.  *
  8.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  9.  *  @license    http://www.pimcore.org/license     PCL
  10.  */
  11. namespace Pimcore\Templating\Model;
  12. use Symfony\Component\HttpFoundation\ParameterBag;
  13. class ViewModel implements ViewModelInterface
  14. {
  15.     /**
  16.      * @var ParameterBag
  17.      */
  18.     protected $parameters;
  19.     /**
  20.      * @param array $parameters
  21.      */
  22.     public function __construct(array $parameters = [])
  23.     {
  24.         $this->initialize($parameters);
  25.     }
  26.     /**
  27.      * @param array $parameters
  28.      *
  29.      * @return $this
  30.      */
  31.     public function initialize(array $parameters = [])
  32.     {
  33.         $this->parameters = new ParameterBag($parameters);
  34.         return $this;
  35.     }
  36.     /**
  37.      * @return ParameterBag
  38.      */
  39.     public function getParameters()
  40.     {
  41.         return $this->parameters;
  42.     }
  43.     /**
  44.      * @return array
  45.      */
  46.     public function getAllParameters()
  47.     {
  48.         return $this->parameters->all();
  49.     }
  50.     /**
  51.      * @inheritDoc
  52.      */
  53.     public function get($key$default null)
  54.     {
  55.         return $this->getParameters()->get($key$default);
  56.     }
  57.     /**
  58.      * @inheritDoc
  59.      */
  60.     public function has($key)
  61.     {
  62.         return $this->parameters->has($key);
  63.     }
  64.     /**
  65.      * @param string $name
  66.      *
  67.      * @return mixed
  68.      */
  69.     public function __get($name)
  70.     {
  71.         return $this->parameters->get($namenull);
  72.     }
  73.     /**
  74.      * @param string $name
  75.      * @param mixed $value
  76.      */
  77.     public function __set($name$value)
  78.     {
  79.         $this->parameters->set($name$value);
  80.     }
  81.     /**
  82.      * @param string $name
  83.      *
  84.      * @return bool
  85.      */
  86.     public function __isset($name)
  87.     {
  88.         return $this->parameters->has($name);
  89.     }
  90.     /**
  91.      * @return \ArrayIterator
  92.      */
  93.     public function getIterator()
  94.     {
  95.         return $this->parameters->getIterator();
  96.     }
  97.     /**
  98.      * @return int
  99.      */
  100.     public function count()
  101.     {
  102.         return $this->parameters->count();
  103.     }
  104.     /**
  105.      * @param mixed $offset
  106.      *
  107.      * @return bool
  108.      */
  109.     public function offsetExists($offset)
  110.     {
  111.         return $this->parameters->has($offset);
  112.     }
  113.     /**
  114.      * @param mixed $offset
  115.      *
  116.      * @return mixed
  117.      */
  118.     public function offsetGet($offset)
  119.     {
  120.         return $this->parameters->get($offset);
  121.     }
  122.     /**
  123.      * @param mixed $offset
  124.      * @param mixed $value
  125.      */
  126.     public function offsetSet($offset$value)
  127.     {
  128.         $this->parameters->set($offset$value);
  129.     }
  130.     /**
  131.      * @param mixed $offset
  132.      */
  133.     public function offsetUnset($offset)
  134.     {
  135.         $this->parameters->remove($offset);
  136.     }
  137.     /**
  138.      * @inheritDoc
  139.      */
  140.     public function jsonSerialize()
  141.     {
  142.         return $this->parameters->all();
  143.     }
  144. }