Youshido\GraphQL\Type\TypeService::getPropertyValue PHP Method

getPropertyValue() public static method

public static getPropertyValue ( $data, $path )
    public static function getPropertyValue($data, $path)
    {
        if (is_object($data)) {
            $getter = $path;
            if (substr($path, 0, 2) != 'is') {
                $getter = 'get' . self::classify($path);
            }
            return is_callable([$data, $getter]) ? $data->{$getter}() : (isset($data->{$path}) ? $data->{$path} : null);
        } elseif (is_array($data)) {
            return array_key_exists($path, $data) ? $data[$path] : null;
        }
        return null;
    }

Usage Example

Esempio n. 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);
     }
 }
All Usage Examples Of Youshido\GraphQL\Type\TypeService::getPropertyValue