It works as a variable container with wrapping of return values for safe access without warnings (on missing properties).
コード例 #1
0
 /**
  * Get a value by path and wrap it into another context
  *
  * The whitelist for the given path is applied to the new context.
  *
  * @param string $path
  * @return Context The wrapped value
  */
 public function getAndWrap($path = null)
 {
     // There are some cases where the $path is a ProtectedContext, especially when doing s.th. like
     // foo()[myOffset]. In this case we need to unwrap it.
     if ($path instanceof ProtectedContext) {
         $path = $path->unwrap();
     }
     $context = parent::getAndWrap($path);
     if ($context instanceof ProtectedContext && isset($this->whitelist[$path]) && is_array($this->whitelist[$path])) {
         $context->whitelist = $this->whitelist[$path];
     }
     return $context;
 }
コード例 #2
0
 /**
  * @test
  * @dataProvider objectGetValues
  *
  * @param mixed $value
  * @param string $path
  * @param mixed $expectedGetValue
  */
 public function getValueByPathForObjectValues($value, $path, $expectedGetValue)
 {
     $context = new Context($value);
     $getValue = $context->get($path);
     $this->assertSame($getValue, $expectedGetValue);
 }