• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 9710673650

25 Jun 2024 02:01PM UTC coverage: 61.693% (-0.9%) from 62.637%
9710673650

push

github

web-flow
feat(laravel): laravel component (#5882)

* feat(laravel): laravel component

* try to skip laravel

* feat(jsonapi): component

* feat(laravel): json api support (needs review)

* work on relations

* relations (needs toMany) + skolem + IRI to resource

* links handler

* ulid

* validation

* slug post

* remove deprecations

* move classes

* fix tests

* fix tests metadata

* phpstan

* missing class

* fix laravel tests

* fix stan

33 of 77 new or added lines in 20 files covered. (42.86%)

140 existing lines in 15 files now uncovered.

10787 of 17485 relevant lines covered (61.69%)

59.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.0
/src/JsonApi/Util/IriHelper.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\JsonApi\Util;
15

16
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
17
use ApiPlatform\Metadata\UrlGeneratorInterface;
18
use ApiPlatform\State\Util\RequestParser;
19

20
/**
21
 * Parses and creates IRIs.
22
 *
23
 * @author Kévin Dunglas <dunglas@gmail.com>
24
 *
25
 * @internal
26
 */
27
final class IriHelper
28
{
29
    private function __construct()
30
    {
NEW
31
    }
×
32

33
    /**
34
     * Parses and standardizes the request IRI.
35
     *
36
     * @throws InvalidArgumentException
37
     */
38
    public static function parseIri(string $iri, string $pageParameterName): array
39
    {
40
        $parts = parse_url($iri);
20✔
41
        if (false === $parts) {
20✔
NEW
42
            throw new InvalidArgumentException(sprintf('The request URI "%s" is malformed.', $iri));
×
43
        }
44

45
        $parameters = [];
20✔
46
        if (isset($parts['query'])) {
20✔
NEW
47
            $parameters = RequestParser::parseRequestParams($parts['query']);
×
48

49
            // Remove existing page parameter
NEW
50
            unset($parameters[$pageParameterName]);
×
51
        }
52

53
        return ['parts' => $parts, 'parameters' => $parameters];
20✔
54
    }
55

56
    /**
57
     * Gets a collection IRI for the given parameters.
58
     */
59
    public static function createIri(array $parts, array $parameters, ?string $pageParameterName = null, ?float $page = null, $urlGenerationStrategy = UrlGeneratorInterface::ABS_PATH): string
60
    {
61
        if (null !== $page && null !== $pageParameterName) {
20✔
NEW
62
            $parameters[$pageParameterName] = $page;
×
63
        }
64

65
        $query = http_build_query($parameters, '', '&', \PHP_QUERY_RFC3986);
20✔
66
        $parts['query'] = preg_replace('/%5B\d+%5D/', '%5B%5D', $query);
20✔
67

68
        $url = '';
20✔
69
        if ((UrlGeneratorInterface::ABS_URL === $urlGenerationStrategy || UrlGeneratorInterface::NET_PATH === $urlGenerationStrategy) && isset($parts['host'])) {
20✔
NEW
70
            if (isset($parts['scheme'])) {
×
NEW
71
                $scheme = $parts['scheme'];
×
NEW
72
            } elseif (isset($parts['port']) && 443 === $parts['port']) {
×
NEW
73
                $scheme = 'https';
×
74
            } else {
NEW
75
                $scheme = 'http';
×
76
            }
NEW
77
            $url .= UrlGeneratorInterface::NET_PATH === $urlGenerationStrategy ? '//' : "$scheme://";
×
78

NEW
79
            if (isset($parts['user'])) {
×
NEW
80
                $url .= $parts['user'];
×
81

NEW
82
                if (isset($parts['pass'])) {
×
NEW
83
                    $url .= ':'.$parts['pass'];
×
84
                }
85

NEW
86
                $url .= '@';
×
87
            }
88

NEW
89
            $url .= $parts['host'];
×
90

NEW
91
            if (isset($parts['port'])) {
×
NEW
92
                $url .= ':'.$parts['port'];
×
93
            }
94
        }
95

96
        $url .= $parts['path'];
20✔
97

98
        if ('' !== $parts['query']) {
20✔
NEW
99
            $url .= '?'.$parts['query'];
×
100
        }
101

102
        if (isset($parts['fragment'])) {
20✔
NEW
103
            $url .= '#'.$parts['fragment'];
×
104
        }
105

106
        return $url;
20✔
107
    }
108
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc