-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added separate routes for topics and examples to a landing page (#960)
- Loading branch information
Showing
62 changed files
with
1,962 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Empty file.
23 changes: 0 additions & 23 deletions
23
src/web/landing/src/Flow/Website/Controller/DefaultController.php
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="tools/phpunit/vendor/phpunit/phpunit/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
cacheResultFile="./var/phpunit/phpunit.cache" | ||
displayDetailsOnTestsThatTriggerWarnings="true" | ||
displayDetailsOnTestsThatTriggerErrors="true" | ||
executionOrder="random" | ||
> | ||
<testsuites> | ||
<testsuite name="integration"> | ||
<directory>tests/Flow/Website/**/Tests/Integration</directory> | ||
</testsuite> | ||
</testsuites> | ||
<source> | ||
<include> | ||
<directory suffix=".php">src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
File renamed without changes.
75 changes: 75 additions & 0 deletions
75
web/landing/src/Flow/Website/Controller/DefaultController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Flow\Website\Controller; | ||
|
||
use Flow\Website\Service\Examples; | ||
use Flow\Website\Service\Github; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
|
||
final class DefaultController extends AbstractController | ||
{ | ||
public function __construct( | ||
private readonly Github $github, | ||
private readonly Examples $examples, | ||
) { | ||
} | ||
|
||
#[Route('/{topic}/{example}', name: 'example')] | ||
public function example(string $topic, string $example) : Response | ||
{ | ||
$topics = $this->examples->topics(); | ||
$currentTopic = $topic; | ||
|
||
$examples = $this->examples->examples($currentTopic); | ||
$currentExample = $example; | ||
|
||
return $this->render('main/index.html.twig', [ | ||
'contributors' => $this->github->contributors(), | ||
'topics' => $topics, | ||
'examples' => $examples, | ||
'currentTopic' => $topic, | ||
'currentExample' => $example, | ||
'code' => $this->examples->code($currentTopic, $currentExample), | ||
]); | ||
} | ||
|
||
#[Route('/', name: 'main')] | ||
public function main() : Response | ||
{ | ||
$topics = $this->examples->topics(); | ||
$currentTopic = \current($topics); | ||
|
||
$examples = $this->examples->examples($currentTopic); | ||
$currentExample = \current($examples); | ||
|
||
return $this->render('main/index.html.twig', [ | ||
'contributors' => $this->github->contributors(), | ||
'topics' => $topics, | ||
'examples' => $examples, | ||
'currentTopic' => $currentTopic, | ||
'currentExample' => $currentExample, | ||
'code' => $this->examples->code($currentTopic, $currentExample), | ||
]); | ||
} | ||
|
||
#[Route('/{topic}', name: 'topic')] | ||
public function topic(string $topic) : Response | ||
{ | ||
$topics = $this->examples->topics(); | ||
$currentTopic = $topic; | ||
|
||
$examples = $this->examples->examples($currentTopic); | ||
$currentExample = \current($examples); | ||
|
||
return $this->render('main/index.html.twig', [ | ||
'contributors' => $this->github->contributors(), | ||
'topics' => $topics, | ||
'examples' => $examples, | ||
'currentTopic' => $currentTopic, | ||
'currentExample' => $currentExample, | ||
'code' => $this->examples->code($currentTopic, $currentExample), | ||
]); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Flow\Website\Service; | ||
|
||
final class Examples | ||
{ | ||
public function __construct(private readonly string $examplesPath) | ||
{ | ||
} | ||
|
||
public function code(string $topic, string $example) : string | ||
{ | ||
$path = \sprintf('%s/topics/%s/%s/code.php', \realpath($this->examplesPath), $topic, $example); | ||
|
||
if (false === \file_exists($path)) { | ||
throw new \RuntimeException(\sprintf('Code example doesn\'t exists, it should be located in path: "%s".', $path)); | ||
} | ||
|
||
return \file_get_contents($path); | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function examples(string $topic) : array | ||
{ | ||
$path = \sprintf('%s/topics/%s', \realpath($this->examplesPath), $topic); | ||
|
||
if (false === \file_exists($path)) { | ||
throw new \RuntimeException(\sprintf('Topic "%s" doesn\'t exists, it should be located in path: "%s".', $topic, $path)); | ||
} | ||
|
||
$examples = \array_diff(\scandir($path), ['..', '.']); | ||
|
||
if (0 === \count($examples)) { | ||
throw new \RuntimeException(\sprintf('Topic "%s" doesn\'t have any example, there should be at least one example in path "%s".', $topic, $path)); | ||
} | ||
|
||
return $examples; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function topics() : array | ||
{ | ||
$path = \sprintf('%s/topics', \realpath($this->examplesPath)); | ||
|
||
if (false === \file_exists($path)) { | ||
throw new \RuntimeException(\sprintf('Topics root directory doesn\'t exists, it should be located in path: "%s".', $path)); | ||
} | ||
|
||
$topics = \array_diff(\scandir($path), ['..', '.']); | ||
|
||
if (0 === \count($topics)) { | ||
throw new \RuntimeException(\sprintf('Topics root directory doesn\'t have any topic, there should be at least one topic in path "%s".', $path)); | ||
} | ||
|
||
return $topics; | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.