Skip to content

Commit 43cb9d5

Browse files
authored
Rebase + add polygon twig component
Rebase + add polygon twig component
2 parents f05883c + c3b1a3d commit 43cb9d5

File tree

75 files changed

+1163
-372
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1163
-372
lines changed

.github/workflows/test.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,14 @@ jobs:
8181
strategy:
8282
fail-fast: false
8383
matrix:
84-
php-version: ['8.1', '8.3']
84+
php-version: ['8.1', '8.3', '8.4']
8585
include:
8686
- php-version: '8.1'
8787
dependency-version: 'lowest'
8888
- php-version: '8.3'
8989
dependency-version: 'highest'
90+
- php-version: '8.4'
91+
dependency-version: 'highest'
9092
component: ${{ fromJson(needs.tests-php-components.outputs.components )}}
9193
exclude:
9294
- component: Map # does not support PHP 8.1
@@ -141,5 +143,5 @@ jobs:
141143
restore-keys: |
142144
${{ runner.os }}-yarn-
143145
- run: yarn --immutable
144-
- run: yarn playwright install
146+
- run: yarn playwright install
145147
- run: yarn test

src/Icons/doc/index.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ Now, all icons will have the ``fill`` attribute set to ``currentColor`` by defau
339339
Icon Aliases
340340
~~~~~~~~~~~~
341341

342+
.. versionadded:: 2.20
343+
344+
Icon Aliases feature was added in 2.20.
345+
342346
Aliases are custom names you can define to refer to any icon. They are useful for
343347
creating shortcuts to icons you frequently use in your templates:
344348

@@ -544,11 +548,11 @@ Full Configuration
544548
default_icon_attributes:
545549
# Default:
546550
fill: currentColor
547-
551+
548552
# Icon aliases (alias => icon name).
549553
aliases:
550554
# Exemple:
551-
dots: 'clarity:ellipsis-horizontal-line'
555+
dots: 'clarity:ellipsis-horizontal-line'
552556
553557
# Configuration for the "on demand" icons powered by Iconify.design.
554558
iconify:
@@ -559,7 +563,7 @@ Full Configuration
559563
560564
# The endpoint for the Iconify API.
561565
endpoint: 'https://api.iconify.design'
562-
566+
563567
# Whether to ignore errors when an icon is not found.
564568
ignore_not_found: false
565569

src/LiveComponent/tests/Fixtures/Serializer/Entity2Normalizer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@ public function __construct(private ManagerRegistry $doctrine)
2525
{
2626
}
2727

28-
public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed
28+
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed
2929
{
30-
[, $id] = \explode(':', $data);
30+
[, $id] = explode(':', $data);
3131

3232
return $this->doctrine->getRepository(Entity2::class)->find($id);
3333
}
3434

35-
public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool
35+
public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool
3636
{
3737
return Entity2::class === $type;
3838
}
3939

40-
public function normalize(mixed $object, string $format = null, array $context = []): float|array|\ArrayObject|bool|int|string|null
40+
public function normalize(mixed $object, ?string $format = null, array $context = []): float|array|\ArrayObject|bool|int|string|null
4141
{
4242
return 'entity2:'.$object->id;
4343
}
4444

45-
public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
45+
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
4646
{
4747
return $data instanceof Entity2;
4848
}

src/LiveComponent/tests/Fixtures/Serializer/MoneyNormalizer.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,27 @@
1717

1818
final class MoneyNormalizer implements NormalizerInterface, DenormalizerInterface
1919
{
20-
public function denormalize(mixed $data, string $type, string $format = null, array $context = []): Money
20+
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): Money
2121
{
22-
return new Money(...\explode('|', $data));
22+
return new Money(...explode('|', $data));
2323
}
2424

25-
public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool
25+
public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool
2626
{
2727
return Money::class === $type;
2828
}
2929

30-
public function normalize(mixed $object, string $format = null, array $context = []): float|array|\ArrayObject|bool|int|string|null
30+
public function normalize(mixed $object, ?string $format = null, array $context = []): float|array|\ArrayObject|bool|int|string|null
3131
{
32-
return \implode('|', [$object->amount, $object->currency]);
32+
return implode('|', [$object->amount, $object->currency]);
3333
}
3434

35-
public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
35+
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
3636
{
3737
return $data instanceof Money;
3838
}
3939

40-
public function getSupportedTypes(string $format = null): array
40+
public function getSupportedTypes(?string $format = null): array
4141
{
4242
return [Money::class => true];
4343
}

src/Map/CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
## 2.20
44

5-
- Rename `render_map` Twig function `ux_map`
6-
- Deprecate `render_map` Twig function
7-
- Polygons added
5+
- Deprecate `render_map` Twig function (will be removed in 2.21). Use
6+
`ux_map` or the `<twig:ux:map />` Twig component instead.
7+
- Add `ux_map` Twig function (replaces `render_map` with a more flexible
8+
interface)
9+
- Add `<twig:ux:map />` Twig component
810

911
## 2.19
1012

src/Map/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"symfony/asset-mapper": "^6.4|^7.0",
4040
"symfony/framework-bundle": "^6.4|^7.0",
4141
"symfony/phpunit-bridge": "^6.4|^7.0",
42-
"symfony/twig-bundle": "^6.4|^7.0"
42+
"symfony/twig-bundle": "^6.4|^7.0",
43+
"symfony/ux-twig-component": "^2.18"
4344
},
4445
"extra": {
4546
"thanks": {

src/Map/config/services.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\UX\Map\Renderer\Renderer;
1616
use Symfony\UX\Map\Renderer\Renderers;
1717
use Symfony\UX\Map\Twig\MapExtension;
18+
use Symfony\UX\Map\Twig\MapRuntime;
1819

1920
/*
2021
* @author Hugo Alliaume <hugo@alliau.me>
@@ -26,7 +27,6 @@
2627
->args([
2728
abstract_arg('renderers configuration'),
2829
])
29-
->tag('twig.runtime')
3030

3131
->set('ux_map.renderer_factory.abstract', AbstractRendererFactory::class)
3232
->abstract()
@@ -41,5 +41,11 @@
4141

4242
->set('ux_map.twig_extension', MapExtension::class)
4343
->tag('twig.extension')
44+
45+
->set('ux_map.twig_runtime', MapRuntime::class)
46+
->args([
47+
service('ux_map.renderers'),
48+
])
49+
->tag('twig.runtime')
4450
;
4551
};

src/Map/config/twig_component.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.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+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Symfony\UX\Map\Twig\UXMapComponent;
15+
use Symfony\UX\Map\Twig\UXMapComponentListener;
16+
use Symfony\UX\TwigComponent\Event\PreCreateForRenderEvent;
17+
18+
return static function (ContainerConfigurator $container): void {
19+
$container->services()
20+
->set('.ux_map.twig_component_listener', UXMapComponentListener::class)
21+
->args([
22+
service('ux_map.twig_runtime'),
23+
])
24+
->tag('kernel.event_listener', [
25+
'event' => PreCreateForRenderEvent::class,
26+
'method' => 'onPreCreateForRender',
27+
])
28+
29+
->set('.ux_map.twig_component.map', UXMapComponent::class)
30+
->tag('twig.component', ['key' => 'UX:Map'])
31+
;
32+
};

src/Map/src/InfoWindow.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
final readonly class InfoWindow
2020
{
2121
/**
22-
* @param array<string, mixed> $extra Extra data, can be used by the developer to store additional information and use them later JavaScript side
22+
* @param array<string, mixed> $extra Extra data, can be used by the developer to store additional information and
23+
* use them later JavaScript side
2324
*/
2425
public function __construct(
2526
private ?string $headerContent = null,
@@ -31,6 +32,16 @@ public function __construct(
3132
) {
3233
}
3334

35+
/**
36+
* @return array{
37+
* headerContent: string|null,
38+
* content: string|null,
39+
* position: array{lat: float, lng: float}|null,
40+
* opened: bool,
41+
* autoClose: bool,
42+
* extra: object,
43+
* }
44+
*/
3445
public function toArray(): array
3546
{
3647
return [
@@ -42,4 +53,25 @@ public function toArray(): array
4253
'extra' => (object) $this->extra,
4354
];
4455
}
56+
57+
/**
58+
* @param array{
59+
* headerContent: string|null,
60+
* content: string|null,
61+
* position: array{lat: float, lng: float}|null,
62+
* opened: bool,
63+
* autoClose: bool,
64+
* extra: object,
65+
* } $data
66+
*
67+
* @internal
68+
*/
69+
public static function fromArray(array $data): self
70+
{
71+
if (isset($data['position'])) {
72+
$data['position'] = Point::fromArray($data['position']);
73+
}
74+
75+
return new self(...$data);
76+
}
4577
}

src/Map/src/Map.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,43 @@ public function toArray(): array
116116
'polygons' => array_map(static fn (Polygon $polygon) => $polygon->toArray(), $this->polygons),
117117
];
118118
}
119+
120+
/**
121+
* @param array{
122+
* center?: array{lat: float, lng: float},
123+
* zoom?: float,
124+
* markers?: list<array>,
125+
* polygons?: list<array>,
126+
* fitBoundsToMarkers?: bool,
127+
* options?: object,
128+
* } $map
129+
*
130+
* @internal
131+
*/
132+
public static function fromArray(array $map): self
133+
{
134+
$map['fitBoundsToMarkers'] = true;
135+
136+
if (isset($map['center'])) {
137+
$map['center'] = Point::fromArray($map['center']);
138+
}
139+
140+
if (isset($map['zoom']) || isset($map['center'])) {
141+
$map['fitBoundsToMarkers'] = false;
142+
}
143+
144+
$map['markers'] ??= [];
145+
if (!\is_array($map['markers'])) {
146+
throw new InvalidArgumentException('The "markers" parameter must be an array.');
147+
}
148+
$map['markers'] = array_map(Marker::fromArray(...), $map['markers']);
149+
150+
$map['polygons'] ??= [];
151+
if (!\is_array($map['polygons'])) {
152+
throw new InvalidArgumentException('The "polygons" parameter must be an array.');
153+
}
154+
$map['polygons'] = array_map(Polygon::fromArray(...), $map['polygons']);
155+
156+
return new self(...$map);
157+
}
119158
}

src/Map/src/Marker.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\UX\Map;
1313

14+
use Symfony\UX\Map\Exception\InvalidArgumentException;
15+
1416
/**
1517
* Represents a marker on a map.
1618
*
@@ -19,7 +21,8 @@
1921
final readonly class Marker
2022
{
2123
/**
22-
* @param array<string, mixed> $extra Extra data, can be used by the developer to store additional information and use them later JavaScript side
24+
* @param array<string, mixed> $extra Extra data, can be used by the developer to store additional information and
25+
* use them later JavaScript side
2326
*/
2427
public function __construct(
2528
private Point $position,
@@ -29,6 +32,14 @@ public function __construct(
2932
) {
3033
}
3134

35+
/**
36+
* @return array{
37+
* position: array{lat: float, lng: float},
38+
* title: string|null,
39+
* infoWindow: array<string, mixed>|null,
40+
* extra: object,
41+
* }
42+
*/
3243
public function toArray(): array
3344
{
3445
return [
@@ -38,4 +49,28 @@ public function toArray(): array
3849
'extra' => (object) $this->extra,
3950
];
4051
}
52+
53+
/**
54+
* @param array{
55+
* position: array{lat: float, lng: float},
56+
* title: string|null,
57+
* infoWindow: array<string, mixed>|null,
58+
* extra: object,
59+
* } $marker
60+
*
61+
* @internal
62+
*/
63+
public static function fromArray(array $marker): self
64+
{
65+
if (!isset($marker['position'])) {
66+
throw new InvalidArgumentException('The "position" parameter is required.');
67+
}
68+
$marker['position'] = Point::fromArray($marker['position']);
69+
70+
if (isset($marker['infoWindow'])) {
71+
$marker['infoWindow'] = InfoWindow::fromArray($marker['infoWindow']);
72+
}
73+
74+
return new self(...$marker);
75+
}
4176
}

src/Map/src/Point.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,16 @@ public function toArray(): array
4343
'lng' => $this->longitude,
4444
];
4545
}
46+
47+
/**
48+
* @param array{lat: float, lng: float}|array{0: float, 1: float} $point
49+
*/
50+
public static function fromArray(array $point): self
51+
{
52+
if (isset($point['lat'], $point['lng'])) {
53+
return new self($point['lat'], $point['lng']);
54+
}
55+
56+
return new self(...$point);
57+
}
4658
}

0 commit comments

Comments
 (0)