getPropertyValue() public static method

public static getPropertyValue ( $data, $path )
Example #1
0
 protected function doResolve(FieldInterface $field, AstFieldInterface $ast, $parentValue = null)
 {
     /** @var AstQuery|AstField $ast */
     $arguments = $this->parseArgumentsValues($field, $ast);
     $astFields = $ast instanceof AstQuery ? $ast->getFields() : [];
     $resolveInfo = $this->createResolveInfo($field, $astFields);
     $this->assertClientHasFieldAccess($resolveInfo);
     if ($field instanceof Field) {
         if ($resolveFunc = $field->getConfig()->getResolveFunction()) {
             if ($this->isServiceReference($resolveFunc)) {
                 $service = substr($resolveFunc[0], 1);
                 $method = $resolveFunc[1];
                 if (!$this->executionContext->getContainer()->has($service)) {
                     throw new ResolveException(sprintf('Resolve service "%s" not found for field "%s"', $service, $field->getName()));
                 }
                 $serviceInstance = $this->executionContext->getContainer()->get($service);
                 if (!method_exists($serviceInstance, $method)) {
                     throw new ResolveException(sprintf('Resolve method "%s" not found in "%s" service for field "%s"', $method, $service, $field->getName()));
                 }
                 return $serviceInstance->{$method}($parentValue, $arguments, $resolveInfo);
             }
             return $resolveFunc($parentValue, $arguments, $resolveInfo);
         } else {
             return TypeService::getPropertyValue($parentValue, $field->getName());
         }
     } else {
         //instance of AbstractContainerAwareField
         if (in_array('Symfony\\Component\\DependencyInjection\\ContainerAwareInterface', class_implements($field))) {
             /** @var $field ContainerAwareInterface */
             $field->setContainer($this->executionContext->getContainer()->getSymfonyContainer());
         }
         return $field->resolve($parentValue, $arguments, $resolveInfo);
     }
 }
 public function resolve($value, array $args, ResolveInfo $info)
 {
     if ($resolveFunction = $this->getConfig()->getResolveFunction()) {
         return $resolveFunction($value, $args, $info);
     } else {
         if (is_array($value) && array_key_exists($this->getName(), $value)) {
             return $value[$this->getName()];
         } elseif (is_object($value)) {
             return TypeService::getPropertyValue($value, $this->getName());
         } elseif ($this->getType()->getNamedType()->getKind() == TypeMap::KIND_SCALAR) {
             return null;
         } else {
             throw new \Exception(sprintf('Property "%s" not found in resolve result', $this->getName()));
         }
     }
 }
Example #3
0
 public function testGetPropertyValue()
 {
     $arrayData = (new TestObjectType())->getData();
     $this->assertEquals('John', TypeService::getPropertyValue($arrayData, 'name'));
     $this->assertEquals('John', TypeService::getPropertyValue((object) $arrayData, 'name'));
 }