rest-proxy.php

Simple proxy for RESTful APIs
git clone git://git.finwo.net/app/rest-proxy.php
Log | Files | Refs | README

ParameterBag.php (1595B)


      1 <?php
      2 
      3 namespace Finwo\Framework;
      4 
      5 use Finwo\PropertyAccessor\PropertyAccessor;
      6 use Invoker\ParameterResolver\ParameterResolver;
      7 
      8 class ParameterBag implements ParameterResolver
      9 {
     10     /**
     11      * Parameters
     12      * Contain the actual stuff
     13      *
     14      * @var array
     15      */
     16     protected $parameters = array();
     17 
     18     /**
     19      * @var PropertyAccessor
     20      */
     21     protected $accessor;
     22 
     23     /**
     24      * @return PropertyAccessor
     25      */
     26     protected function getAccessor()
     27     {
     28         if ( !($this->accessor instanceof PropertyAccessor) ) {
     29             $this->accessor = new PropertyAccessor();
     30         }
     31         return $this->accessor;
     32     }
     33 
     34     /**
     35      * ParameterBag constructor.
     36      * @param array $data
     37      */
     38     public function __construct($data = array())
     39     {
     40         // Insert data if provided
     41         if (is_array($data)) {
     42             foreach ($data as $key => $value) {
     43                 $this->set($key, $value);
     44             }
     45         }
     46     }
     47 
     48     public function toArray()
     49     {
     50         return $this->parameters;
     51     }
     52 
     53     public function getParameters(
     54         \ReflectionFunctionAbstract $reflection,
     55         array $providedParameters,
     56         array $resolvedParameters
     57     )
     58     {
     59         var_dump($reflection, $providedParameters, $resolvedParameters);
     60         die();
     61     }
     62 
     63     public function set($key, $value)
     64     {
     65         $acc = $this->getAccessor();
     66         $acc->set($this->parameters, $key, $value, '.');
     67         return $this;
     68     }
     69 
     70     public function get($key)
     71     {
     72         $acc = $this->getAccessor();
     73         return $acc->get($this->parameters, $key, '.');
     74     }
     75 }