Normalizes the pointer format

@param mixed $pointer
@param array $context [optional]
@return array
@throws \axy\creator\errors\InvalidPointer
@throws \axy\creator\errors\Disabled
436731
public static function normalize($pointer, array $context = null)
    {
        if (is_object($pointer)) {
            return ['value' => $pointer];
        }
        if (is_string($pointer)) {
            return ['classname' => $pointer];
        }
        if ($pointer === null) {
            return [];
        }
        if ($pointer === false) {
            throw new Disabled('');
        }
        if (!is_array($pointer)) {
            throw new InvalidPointer('invalid pointer type');
        }
        if (!isset($pointer[0])) {
            return $pointer;
        }
        return self::normalizeNumeric($pointer, $context);
    }
743411
private function readRegionName($pointer) {
    if (false === $pointer) {
      // Deal with invalid IPs
      $regionName = self::INVALID_IP_ADDRESS;
    } elseif (0 === self::$columns[self::REGION_NAME][$this->type]) {
      // If the field is not suported, return accordingly
      $regionName = self::FIELD_NOT_SUPPORTED;
    } else {
      // Read the region name
      $regionName = $this->readString($pointer + self::$columns[self::REGION_NAME][$this->type]);
    }
    return $regionName;
  }
1208781
public function normalize($string, $format = null, array $context = array())
    {
        $mime = isset($context[static::CONTEXT_MIME]) ? $context[static::CONTEXT_MIME] : 'application/octet-stream';
        $charset = isset($context[static::CONTEXT_CHARSET]) ? $context[static::CONTEXT_CHARSET] : null;
        $gzip = isset($context[static::CONTEXT_GZIP]) ? $context[static::CONTEXT_GZIP] : null;
        $base64 = isset($context[static::CONTEXT_BASE64]) ? $context[static::CONTEXT_BASE64] : null;
        $base64 = ($base64 !== null) ? $base64 : strpos($mime, '/octet-stream') !== false;
        $urlencode = isset($context[static::CONTEXT_URLENCODE]) ? $context[static::CONTEXT_URLENCODE] : null;
        $urlencode = ($urlencode !== null) ? $urlencode : strpos($mime, 'text/') !== false;

        if ($gzip) {
            $string = gzencode($string);
            $mime = 'application/x-gzip';
        }
        if ($urlencode and !$base64) {
            $string = urlencode($string);
        }
        if ($base64 or !$urlencode) {
            $string = base64_encode($string);
        }

        $options = $mime;
        if ($charset and $mime) {
            $options .= ';charset='.$charset;
        }
        if ($base64) {
            $options .= ';base64';
        }

        return sprintf('data:%s,%s', $options, $string);
    }
81446
public function normalize($object, $format = null, array $context = [])
    {
        $normalized = [];
        foreach ($object->getDefinition()->getFields() as $field) {
            if (isset($object->{$key = $field->getName()})) {
                if ($field instanceof SerializerAwareInterface) {
                    $field->setSerializer($this->serializer);
                }

                $normalized[$key] = $field->normalize($object->{$key}, $format, $context);
            }
        }

        return $normalized;
    }
1347745
public function normalize($object, $format = null, array $context = [])
    {
        $return = [
            'property' => parent::normalize($object, $format, $context),
        ];

        return (object) $return;
    }
242868
public function normalize($object, $format = null, array $context = [])
    {
        if (isset($context['api_sub_level'])) {
            return $this->normalizeRawCollection($object, $format, $context);
        }

        try {
            $resourceClass = $this->resourceClassResolver->getResourceClass($object, $context['resource_class'] ?? null, true);
        } catch (InvalidArgumentException $e) {
            if (!isset($context['resource_class'])) {
                return $this->normalizeRawCollection($object, $format, $context);
            }

            throw $e;
        }
        $data = $this->addJsonLdContext($this->contextBuilder, $resourceClass, $context);
        $context = $this->initContext($resourceClass, $context);

        if (isset($context['operation_type']) && OperationType::SUBRESOURCE === $context['operation_type']) {
            $data['@id'] = $this->iriConverter->getSubresourceIriFromResourceClass($resourceClass, $context);
        } else {
            $data['@id'] = $this->iriConverter->getIriFromResourceClass($resourceClass);
        }

        $data['@type'] = 'hydra:Collection';

        $data['hydra:member'] = [];
        foreach ($object as $obj) {
            $data['hydra:member'][] = $this->normalizer->normalize($obj, $format, $context);
        }

        $paginated = null;
        if (
            \is_array($object) ||
            ($paginated = $object instanceof PaginatorInterface) ||
            $object instanceof \Countable && !$object instanceof PartialPaginatorInterface
        ) {
            $data['hydra:totalItems'] = $paginated ? $object->getTotalItems() : \count($object);
        }

        return $data;
    }
1261960
public function normalize($page, $format = null, array $context = [])
    {
        $data = parent::normalize($page, $format, $context);

        if ($this->contextHasGroup(['Default', 'Page'], $context)) {
            // Seo
            if (null !== $seo = $page->getSeo()) {
                $data['seo'] = $seo->getId();
            }
        } elseif ($this->contextHasGroup('Search', $context)) {
            // Seo
            if (null !== $seo = $page->getSeo()) {
                $data['seo'] = $this->normalizeObject($seo, $format, $context);
            }

            // TODO content.[locale]
        }

        return $data;
    }
584968
private function getFieldsByFieldNormalizationMappings(
        NormalizerContextInterface $context,
        array $normalizationFieldMappings,
        string $path,
        $object
    ): array {
        $data = [];
        foreach ($normalizationFieldMappings as $normalizationFieldMapping) {
            if (!$this->isWithinGroup($context, $normalizationFieldMapping)) {
                continue;
            }

            $fieldNormalizer = $normalizationFieldMapping->getFieldNormalizer();

            $name = $normalizationFieldMapping->getName();

            $subPath = $this->getSubPathByName($path, $name);

            $this->logger->info('serialize: path {path}', ['path' => $subPath]);

            $data[$name] = $fieldNormalizer->normalizeField($subPath, $object, $context, $this);
        }

        return $data;
    }
958837
public function normalize($object, $format = null, array $context = [])
    {
        if (!$object instanceof \DateTimeInterface) {
            throw new InvalidArgumentException('The object must implement the "\DateTimeInterface".');
        }

        $dateTimeFormat = $context[self::FORMAT_KEY] ?? $this->defaultContext[self::FORMAT_KEY];
        $timezone = $this->getTimezone($context);

        if (null !== $timezone) {
            $object = clone $object;
            $object = $object->setTimezone($timezone);
        }

        return $object->format($dateTimeFormat);
    }
462313
public function normalizeField(
        string $path,
        $object,
        NormalizerContextInterface $context,
        NormalizerInterface $normalizer = null
    ) {
        if (null === $relatedObject = $this->accessor->getValue($object)) {
            return null;
        }

        return $this->identifierAccessor->getValue($relatedObject);
    }
820324
public function denormalize($string, $class, $format = null, array $context = array())
    {
        if (!preg_match(static::FULL_REGEX, $string, $matches)) {
            throw new \InvalidArgumentException('The provided "data:" URI is not valid.');
        }

        $mime = !empty($matches[static::CONTEXT_MIME]) ? $matches[static::CONTEXT_MIME] : 'application/octet-stream';
        $charset = !empty($matches[static::CONTEXT_CHARSET]) ? $matches[static::CONTEXT_CHARSET] : null;
        $gzip = strpos($mime, 'gzip') !== false;
        $base64 = !empty($matches[static::CONTEXT_BASE64]) ? $matches[static::CONTEXT_BASE64] : null;
        $urldecode = strpos($mime, 'text/') !== false;

        $string = $matches[static::CONTEXT_DATA];

        if ($base64) {
            $string = base64_decode($string);
        }
        if ($gzip) {
            $string = gzdecode($string);
        }
        if ($urldecode or !$base64) {
            $string = urldecode($string);
        }

        return $string;
    }
487663
public function denormalize($data, $class, $format = null, array $context = [])
    {
        // Handle -1 in expiresAt property of AppCredential.
        if ($data < 0) {
            return null;
        }
        $context[$this->normalizer::FORMAT_KEY] = 'U';
        $context[$this->normalizer::TIMEZONE_KEY] = new \DateTimeZone('UTC');

        return $this->normalizer->denormalize(intval($data / 1000), $class, $format, $context);
    }
69696
public function normalize($object, $format = null, array $context = array())
    {
        if (!$object instanceof \DateTimeInterface) {
            throw new InvalidArgumentException('The object must implement the "\DateTimeInterface".');
        }

        $format = isset($context[static::CONTEXT_FORMAT]) ? $context[self::CONTEXT_FORMAT] : $this->format;

        return $object->format($format);
    }
1087393
private function readIddAndAreaCodes($pointer) {
    if (false === $pointer) {
      // Deal with invalid IPs
      $iddCode  = self::INVALID_IP_ADDRESS;
      $areaCode = self::INVALID_IP_ADDRESS;
    } elseif (0 === self::$columns[self::IDD_CODE][$this->type]) {
      // If the field is not suported, return accordingly
      $iddCode  = self::FIELD_NOT_SUPPORTED;
      $areaCode = self::FIELD_NOT_SUPPORTED;
    } else {
      // Read IDD and area codes
      $iddCode  = $this->readString($pointer + self::$columns[self::IDD_CODE][$this->type]);
      $areaCode = $this->readString($pointer + self::$columns[self::AREA_CODE][$this->type]);
    }
    return [$iddCode, $areaCode];
  }
380444
public function normalize($object, $format = null, array $context = []): array
    {
        $normalized = [
            'page' => $object->getPage(),
            'limit' => $object->getLimit(),
            'total' => $object->getTotal(),
            'items' => [],
        ];

        foreach ($object as $item) {
            $normalized['items'][] = $this->normalizer->normalize($item, $format, $context);
        }

        return $normalized;
    }
1033839
public static function validate($result, array $context)
    {
        if (!empty($context['parent'])) {
            if (!($result instanceof $context['parent'])) {
                throw new InvalidPointer('Object must be an instance of '.$context['parent']);
            }
        }
        if (!empty($context['validator'])) {
            if (!Callback::call($context['validator'], [$result])) {
                throw new InvalidPointer('Object is not valid');
            }
        }
        return true;
    }
208735
public function normalize($object, $format = null, array $context = [])
    {
        if (!$object instanceof ResourceCollection) {
            throw new \InvalidArgumentException(sprintf(
                'The normalizer support only "%s" but "%s" given.',
                ResourceCollection::class,
                is_object($object) ? get_class($object) : gettype($object)
            ));
        }

        $data = [];
        $links = [];

        if (count($object->getRelations())) {
            $links = array_merge($links, $this->normalizer->normalize($object->getRelations(), $format, $context));
        }

        if (count($object->getActions())) {
            $links = array_merge($links, $this->normalizer->normalize($object->getActions(), $format, $context));
        }

        foreach ($object as $resource) {
            $data[] = $this->normalizer->normalize($resource, $format, $context);
        }

        if (count($links)) {
            return [
                '_links' => $links,
                '_embedded' => [
                    'items' => $data,
                ],
            ];
        }

        return $data;
    }