Parses fields query and validate against a resource

@param Resource $resource Resource

@return string[]

@throws RouterException If fields query parameter has invalid fields
175067
protected function parseFields(Resource $resource)
    {
        $fields = $resource->getFields();
        if (!is_array($fields)) {
            $this->sendError(static::ERROR_UNKNOWN_FIELDS, $fields);
        }
        return $fields;
    }
1138966
private function load($resource, string $type = null): array
    {
        if (null === $this->loader) {
            throw new \BadMethodCallException('Cannot import other routing resources: you must pass a LoaderInterface when constructing RouteCollectionBuilder.');
        }

        if ($this->loader->supports($resource, $type)) {
            $collections = $this->loader->load($resource, $type);

            return \is_array($collections) ? $collections : [$collections];
        }

        if (null === $resolver = $this->loader->getResolver()) {
            throw new LoaderLoadException($resource, null, null, null, $type);
        }

        if (false === $loader = $resolver->resolve($resource, $type)) {
            throw new LoaderLoadException($resource, null, null, null, $type);
        }

        $collections = $loader->load($resource, $type);

        return \is_array($collections) ? $collections : [$collections];
    }
1317859
protected function getAllowedMethods(string $resource)
    {
        $cached = $this->cache['allowed_methods'][$resource] ?? null;
        if ($cached !== null) {
            return $cached;
        }

        $resource_data = $this->resources[$resource] ?? null;
        if ($resource_data === null) {
            throw new \DomainException("Invalid resource '$resource'");
        }

        $allow = $this->implemented_methods;

        $methods = (array) ($resource_data['methods'] ?? null);
        if (!empty($methods)) {
            $allow = array_intersect(
                $allow,
                array_merge($methods, ['OPTIONS'])
            );
        }

        $this->cache['allowed_methods'][$resource] = $allow;
        return $allow;
    }
1317111
private function assertValidResource($resource)
    {
        $resource = (string) $resource;
        // All resources are basic ASCII, so we can ignore the fact that `strtolower` doesn't handle UTF-8 well.
        $resource = strtolower($resource);

        if (!in_array($resource, static::VALID_RESOURCES)) {
            throw new InvalidResourceException($resource);
        }

        return $resource;
    }
653613
private function getProperties(\SimpleXMLElement $resource): array
    {
        $properties = [];
        foreach ($resource->property as $property) {
            $properties[(string) $property['name']] = [
                'description' => $this->phpize($property, 'description', 'string'),
                'readable' => $this->phpize($property, 'readable', 'bool'),
                'writable' => $this->phpize($property, 'writable', 'bool'),
                'readableLink' => $this->phpize($property, 'readableLink', 'bool'),
                'writableLink' => $this->phpize($property, 'writableLink', 'bool'),
                'required' => $this->phpize($property, 'required', 'bool'),
                'identifier' => $this->phpize($property, 'identifier', 'bool'),
                'iri' => $this->phpize($property, 'iri', 'string'),
                'attributes' => $this->getAttributes($property, 'attribute'),
                'subresource' => $property->subresource ? [
                    'collection' => $this->phpize($property->subresource, 'collection', 'bool'),
                    'resourceClass' => $this->phpize($property->subresource, 'resourceClass', 'string'),
                    'maxDepth' => $this->phpize($property->subresource, 'maxDepth', 'integer'),
                ] : null,
            ];
        }

        return $properties;
    }
860772
protected function checkMissingFields(Resource $resource)
    {
        $missing = array_diff(
            $resource->model_class::getRequiredColumns(),
            array_keys($resource->data)
        );

        if (!empty($missing)) {
            $message = "Resource '$resource->name' requires the following "
                . "missing fields: '" . implode("', '", $missing) . "'";
            $this->sendError(static::ERROR_INVALID_PAYLOAD, $message);
        }
    }
1317466
private function prepareGetterParams($getter_params, $user, $resource)
    {
        if (empty($getter_params)) {
            return [];
        }
        $values = [];
        foreach ($getter_params as $getter_name=>$params) {
            foreach ($params as $param) {
                if ('@' !== $param[ 'param_name' ][ 0 ]) {
                    $values[$getter_name][] = $param[ 'param_value' ];
                } else {
                    $values[$getter_name][] = $this->attributeManager->retrieveAttribute($this->attributeManager->getAttribute($param[ 'param_value' ]), $user, $resource);
                }
            }
        }
        return $values;
    }
335518
public function normalize($data, Resource $resource)
    {
        $validator = new ExceptionValidator(new ArrayValidator([
            'requiredKeys'  => ['name'],
            'optionalKeys'  => ['property'],
            'allowExtra'    => false,
        ]));

        $validator->validate($data['value']);

        $definitions = [];
        if (isset($data['value']['property'])) {
            $definitions['properties'] = $this->normalizeProperties(
                $data['value']['property'],
                $resource
            );
        }

        return $this->createDefinition($data['value']['name'], $definitions);
    }
947966
public function parse($resource) {

        $result = array();
        $fieldcnt = mysqli_num_fields($resource);


        $fields_transform = array();

        for($i=0;$i<$fieldcnt;$i++) {
            $finfo = mysqli_fetch_field_direct($resource, $i);

            if(isset(self::$mysqli_type[$finfo->type])) {
                $fields_transform[$finfo->name] = self::$mysqli_to_php[self::$mysqli_type[$finfo->type]];
            }
        }

        while($row = mysqli_fetch_assoc($resource)) {
            foreach($fields_transform as $fieldname => $fieldtype) {
               settype($row[$fieldname], $fieldtype);
            }
            $result[] = $row;
        }
        return $result;
    }
807036
public function validate(Config\Interfaces\ItemRouter $RouteItem, Interfaces\Request $Request)
    {
        $method = $RouteItem->getMethod();
        if ($method !== null && strcasecmp($method, $Request->getMethod()) !== 0) {
            throw new Exception\RequestValidator('Invalid request method: "%s", expected: "%s" for url: "%s"', [$Request->getMethod(), $method, $RouteItem->getName()]);
        }

        $this->errors = null;

        $parsed_query_parameters = $this->validateQuery($RouteItem, $Request->getPath(), $Request->getQueryCollection()->toArray());
        $this->validateRoute(
            $RouteItem->getName(),
            (array) $RouteItem->getQueryRegex(),
            $parsed_query_parameters,
            true //so 404 can be thrown
        );

        $parsed_get_parameters = $this->validateGet($RouteItem, $Request->getGetCollection()->toArray());
        $this->validateRoute(
            $RouteItem->getName(),
            (array) $RouteItem->getGetRegex(),
            $parsed_get_parameters,
            false
        );

        $parsed_post_parameters = $this->validatePost($RouteItem, $Request->getPostCollection()->toArray());
        $this->validateRoute(
            $RouteItem->getName(),
            (array) $RouteItem->getPostRegex(),
            $parsed_post_parameters,
            false
        );

        return [$parsed_query_parameters, $parsed_get_parameters, $parsed_post_parameters];
    }
1549
public function indexFields(Resource $resource): array
    {
        return $this->resourceFields($resource)->map(function (Field $field) {
            if (!$field->computed()) {
                return $field->attribute;
            }

            return $field->name;
        })->unique()->all();
    }
835928
public function getResourceMetadata($resource)
    {
        if (is_object($resource)) {
            $className = get_class($resource);
        } else {
            $className = $resource;
        }
        if (!isset($this->resources[$className])) {
            throw new \Exception('Resource class "'.$className.'" not found');
        }
        return $this->resources[$className];
    }
1201145
protected function getIdentifierRepresentationFromResource(ResourceInterface $resource): array
    {
        return $resource->hasIdentifierMeta() === false ? [
            DocumentInterface::KEYWORD_TYPE => $resource->getType(),
            DocumentInterface::KEYWORD_ID   => $resource->getId(),
        ] : [
            DocumentInterface::KEYWORD_TYPE => $resource->getType(),
            DocumentInterface::KEYWORD_ID   => $resource->getId(),
            DocumentInterface::KEYWORD_META => $resource->getIdentifierMeta(),
        ];
    }
1262431
private function match(string $url, Route $route) : array
    {
        $regexp = $this->routeRegexp($route);

        if (preg_match_all('`^' . $regexp . '$`', $url, $matches, PREG_SET_ORDER)) {
            // remove all numeric matches
            $matches = array_diff_key($matches[0], range(0, count($matches[0])));

            // control query string
            if ($route->getUserInputs()) {
                foreach ($route->getUserInputs() as $querystring) {
                    $method = self::request()->getMethod() == 'POST' ? 'getPostOrQuery' : 'getQuery';
                    $value = self::request()->$method($querystring->getName(), $querystring->getType());

                    if (is_null($value) && $querystring->isMandatory()) {
                        return [false, null, $regexp];
                    }

                    if (!is_null($value)) {
                        $matches[$querystring->getName()] = $value;
                    }
                }
            }

            // control conditions
            if ($route->getConditions()) {
                foreach ($route->getConditions() as $condition) {
                    if (!$condition($matches)) {
                        return [false, null, $regexp];
                    }
                }
            }

            return [true, $matches, $regexp];
        }

        return [false, null, $regexp];
    }
1067340
public static function parseIri(string $iri, string $pageParameterName): array
    {
        $parts = parse_url($iri);
        if (false === $parts) {
            throw new InvalidArgumentException(sprintf('The request URI "%s" is malformed.', $iri));
        }

        $parameters = [];
        if (isset($parts['query'])) {
            $parameters = RequestParser::parseRequestParams($parts['query']);

            // Remove existing page parameter
            unset($parameters[$pageParameterName]);
        }

        return ['parts' => $parts, 'parameters' => $parameters];
    }
662212
public function normalize($data, Resource $resource)
    {
        if (isset($data['value']['map'])) {
            $options = isset($data['value']['map']['options']) ? $data['value']['map']['options'] : [];
            $data['value']['map'] = $this->normalizer->normalize(
                [
                    'key'   => $data['value']['map']['validator'],
                    'value' => $options,
                ],
                $resource
            );
        }

        return $this->createDefinition($data['value']);
    }
196204
protected function matchesResource(Resource $resource = null)
    {
        // If the resource is null we should only return true if the current resource is also null.
        if ($resource === null) {
            return $this->getResource() === null || (
                $this->getResourceType() === null && $this->getResourceId() === null
            );
        }

        // If the permission's resource id is null then all resources with a specific ID are accepted.
        if ($this->getResourceId() === null) {
            return $this->getResourceType() === $resource->getResourceType();
        }

        // Otherwise make sure that we're matching a specific resource.
        return (
            $this->getResourceType() === $resource->getResourceType() &&
            $this->getResourceId() === $resource->getResourceId()
        );
    }