Skip to content

Commit 349c773

Browse files
committed
Prepare demos for map
1 parent 4e846f8 commit 349c773

File tree

6 files changed

+141
-138
lines changed

6 files changed

+141
-138
lines changed

ux.symfony.com/src/Controller/Demo/LiveComponentDemoController.php renamed to ux.symfony.com/src/Controller/Demo/LiveDemoController.php

Lines changed: 12 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,14 @@
2424
use Symfony\Component\Routing\Attribute\Route;
2525

2626
#[Route('/demos/live-component')]
27-
class LiveComponentDemoController extends AbstractController
27+
class LiveDemoController extends AbstractController
2828
{
2929
#[Route('/', name: 'app_demo_live_component')]
3030
public function __invoke(): Response
3131
{
3232
return $this->redirectToRoute('app_demos');
3333
}
3434

35-
#[Route('/auto-validating-form', name: 'app_demo_live_component_auto_validating_form')]
36-
public function demoAutoValidatingForm(LiveDemoRepository $liveDemoRepository): Response
37-
{
38-
return $this->render('demos/live_component/auto_validating_form.html.twig', [
39-
'demo' => $liveDemoRepository->find('auto-validating-form'),
40-
]);
41-
}
42-
4335
#[Route('/form-collection-type/{id}', name: 'app_demo_live_component_form_collection_type', defaults: ['id' => null])]
4436
public function demoFormCollectionType(LiveDemoRepository $liveDemoRepository, Request $request, TodoListRepository $todoListRepository, ?TodoList $todoList = null): Response
4537
{
@@ -66,14 +58,6 @@ public function demoFormCollectionType(LiveDemoRepository $liveDemoRepository, R
6658
]);
6759
}
6860

69-
#[Route('/dependent-form-fields', name: 'app_demo_live_component_dependent_form_fields')]
70-
public function demoDependentFormFields(LiveDemoRepository $liveDemoRepository): Response
71-
{
72-
return $this->render('demos/live_component/dependent_form_fields.html.twig', [
73-
'demo' => $liveDemoRepository->find('dependent-form-fields'),
74-
]);
75-
}
76-
7761
#[Route('/voting', name: 'app_demo_live_component_voting')]
7862
public function demoVoting(LiveDemoRepository $liveDemoRepository, FoodRepository $foodRepository): Response
7963
{
@@ -97,14 +81,6 @@ public function inlineEdit(LiveDemoRepository $liveDemoRepository, FoodRepositor
9781
]);
9882
}
9983

100-
#[Route('/chartjs', name: 'app_demo_live_component_chartjs')]
101-
public function chartJs(LiveDemoRepository $liveDemoRepository): Response
102-
{
103-
return $this->render('demos/live_component/chartjs.html.twig', parameters: [
104-
'demo' => $liveDemoRepository->find('chartjs'),
105-
]);
106-
}
107-
10884
#[Route('/invoice/{id}', name: 'app_demo_live_component_invoice', defaults: ['id' => null])]
10985
public function invoice(LiveDemoRepository $liveDemoRepository, ?Invoice $invoice = null): Response
11086
{
@@ -116,35 +92,20 @@ public function invoice(LiveDemoRepository $liveDemoRepository, ?Invoice $invoic
11692
]);
11793
}
11894

95+
#[Route('/{demo}', name: 'app_demo_live_component_demo')]
96+
#[Route('/auto-validating-form', name: 'app_demo_live_component_auto_validating_form')]
97+
#[Route('/chartjs', name: 'app_demo_live_component_chartjs')]
98+
#[Route('/dependent-form-fields', name: 'app_demo_live_component_dependent_form_fields')]
11999
#[Route('/infinite-scroll', name: 'app_demo_live_component_infinite_scroll')]
120-
public function infiniteScroll(LiveDemoRepository $liveDemoRepository): Response
121-
{
122-
return $this->render('demos/live_component/infinite_scroll.html.twig', parameters: [
123-
'demo' => $liveDemoRepository->find('infinite-scroll'),
124-
]);
125-
}
126-
127100
#[Route('/infinite-scroll-2', name: 'app_demo_live_component_infinite_scroll_2')]
128-
public function infiniteScroll2(LiveDemoRepository $liveDemoRepository): Response
129-
{
130-
return $this->render('demos/live_component/infinite_scroll_2.html.twig', parameters: [
131-
'demo' => $liveDemoRepository->find('infinite-scroll-2'),
132-
]);
133-
}
134-
135101
#[Route('/product-form', name: 'app_demo_live_component_product_form')]
136-
public function productForm(LiveDemoRepository $liveDemoRepository): Response
137-
{
138-
return $this->render('demos/live_component/product_form.html.twig', parameters: [
139-
'demo' => $liveDemoRepository->find('product-form'),
140-
]);
141-
}
142-
143102
#[Route('/upload', name: 'app_demo_live_component_upload')]
144-
public function uploadFiles(LiveDemoRepository $liveDemoRepository): Response
145-
{
146-
return $this->render('demos/live_component/upload.html.twig', parameters: [
147-
'demo' => $liveDemoRepository->find('upload'),
148-
]);
103+
public function demo(
104+
LiveDemoRepository $liveDemoRepository,
105+
string $demo,
106+
): Response {
107+
$demo = $liveDemoRepository->find($demo);
108+
109+
return $this->render($demo->getTemplate(), ['demo' => $demo]);
149110
}
150111
}

ux.symfony.com/src/Controller/Demo/LiveMemoryController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
class LiveMemoryController extends AbstractController
2222
{
2323
#[Route('/', name: 'app_demo_live_memory')]
24+
#[Route('/', name: 'app_demo_live_component_live_memory')]
2425
public function __invoke(LiveDemoRepository $liveDemoRepository): Response
2526
{
2627
return $this->render('demos/live_memory/index.html.twig', [
@@ -33,6 +34,7 @@ public function __invoke(LiveDemoRepository $liveDemoRepository): Response
3334
* from the session. This can be useful when you want to start over.
3435
*/
3536
#[Route('/reset', name: 'app_demo_live_memory_reset', env: 'dev')]
37+
#[Route('/reset', name: 'app_demo_live_component_live_memory_reset', env: 'dev')]
3638
public function reset(GameStorageInterface $gameStorage): Response
3739
{
3840
$gameStorage->saveGame(null);

ux.symfony.com/src/Model/Demo.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 App\Model;
13+
14+
class Demo
15+
{
16+
public function __construct(
17+
private string $identifier,
18+
private string $name,
19+
private string $description,
20+
private Person|string $author,
21+
private \DateTimeImmutable|string $publishedAt,
22+
private array $tags,
23+
) {
24+
}
25+
26+
public function getIdentifier(): string
27+
{
28+
return $this->identifier;
29+
}
30+
31+
public function getName(): string
32+
{
33+
return $this->name;
34+
}
35+
36+
public function getDescription(): string
37+
{
38+
return $this->description;
39+
}
40+
41+
/**
42+
* @return list<string>
43+
*/
44+
public function getTags(): array
45+
{
46+
return $this->tags;
47+
}
48+
49+
public function getAuthor(): Person|string
50+
{
51+
return $this->author;
52+
}
53+
54+
public function getPublishedAt(): \DateTimeImmutable|string
55+
{
56+
return $this->publishedAt;
57+
}
58+
}

ux.symfony.com/src/Model/LiveDemo.php

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,37 @@
1111

1212
namespace App\Model;
1313

14-
class LiveDemo
14+
final class LiveDemo extends Demo
1515
{
1616
public function __construct(
17-
private string $identifier,
18-
private string $name,
19-
private string $description,
20-
private string $route,
17+
string $identifier,
18+
string $name,
19+
string $description,
20+
string $author,
21+
string $publishedAt,
22+
array $tags,
2123
private string $longDescription,
22-
/**
23-
* @var string[]
24-
*/
25-
private array $tags = [],
2624
) {
25+
parent::__construct($identifier, $name, $description, $author, $publishedAt, $tags);
2726
}
2827

29-
public function getIdentifier(): string
28+
public function getRoute(): string
3029
{
31-
return $this->identifier;
30+
return 'app_demo_live_component_'.str_replace('-', '_', parent::getIdentifier());
3231
}
3332

34-
public function getName(): string
33+
public function getScreenshotFilename(?string $format = null): string
3534
{
36-
return $this->name;
35+
return 'images/live_demo/'.parent::getIdentifier().($format ? ('-'.$format) : '').'.png';
3736
}
3837

39-
public function getDescription(): string
38+
public function getTemplate(): string
4039
{
41-
return $this->description;
40+
return \sprintf('demos/live_component/%s.html.twig', str_replace('-', '_', parent::getIdentifier()));
4241
}
4342

4443
public function getLongDescription(): string
4544
{
4645
return $this->longDescription;
4746
}
48-
49-
public function getRoute(): string
50-
{
51-
return $this->route;
52-
}
53-
54-
public function getTags(): array
55-
{
56-
return $this->tags;
57-
}
58-
59-
public function getScreenshotFilename(?string $format = null): string
60-
{
61-
return 'images/live_demo/'.$this->identifier.($format ? ('-'.$format) : '').'.png';
62-
}
6347
}

0 commit comments

Comments
 (0)