Neos\Eel\Context::get PHP Method

get() public method

This basically acts as a safe access to non-existing properties, unified array and property access (using getters) and access to the current value (empty path). If a property or key did not exist this method will return NULL.
public get ( string | integer | Context $path ) : mixed
$path string | integer | Context The path as string or Context value, will be unwrapped for convenience
return mixed The value
    public function get($path)
    {
        if ($path instanceof Context) {
            $path = $path->unwrap();
        }
        if ($path === null) {
            return null;
        } elseif (is_string($path) || is_integer($path)) {
            if (is_array($this->value)) {
                return array_key_exists($path, $this->value) ? $this->value[$path] : null;
            } elseif (is_object($this->value)) {
                try {
                    return ObjectAccess::getProperty($this->value, $path);
                } catch (PropertyNotAccessibleException $exception) {
                    return null;
                }
            }
        } else {
            throw new EvaluationException('Path is not of type string or integer, got ' . gettype($path), 1344418464);
        }
    }

Usage Example

 /**
  * @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);
 }