Skip to content

Commit

Permalink
Added separate routes for topics and examples to a landing page (#960)
Browse files Browse the repository at this point in the history
  • Loading branch information
owsiakl authored Feb 4, 2024
1 parent c874055 commit 75559d1
Show file tree
Hide file tree
Showing 62 changed files with 1,962 additions and 110 deletions.
3 changes: 2 additions & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
__DIR__ . '/src/adapter/**/tests',
__DIR__ . '/src/lib/**/src',
__DIR__ . '/src/lib/**/tests',
__DIR__ . '/src/web/**/src',
__DIR__ . '/web/**/src',
__DIR__ . '/web/**/tests',
__DIR__ . '/examples',
]);

Expand Down
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@
"@test:mutation"
],
"test": [
"tools/phpunit/vendor/bin/phpunit"
"tools/phpunit/vendor/bin/phpunit",
"@test:web"
],
"test:docs": [
"docker run -t --rm -v $PWD:/app norberttech/md-link-linter --exclude=vendor ."
Expand All @@ -208,6 +209,7 @@
"tools/infection/vendor/bin/infection -j2"
],
"test:monorepo": "tools/monorepo/vendor/bin/monorepo-builder validate",
"test:web": "composer test --working-dir=web/landing",
"static:analyze": [
"@static:analyze:cs-fixer",
"@static:analyze:psalm",
Expand Down Expand Up @@ -247,7 +249,8 @@
"composer install --working-dir=./tools/phpbench",
"composer install --working-dir=./tools/phpstan",
"composer install --working-dir=./tools/psalm",
"composer install --working-dir=./tools/phpunit"
"composer install --working-dir=./tools/phpunit",
"composer install --working-dir=./web/landing/tools/phpunit"
],
"tools:update": [
"composer update --working-dir=./tools/blackfire",
Expand All @@ -258,7 +261,8 @@
"composer update --working-dir=./tools/phpbench",
"composer update --working-dir=./tools/phpstan",
"composer update --working-dir=./tools/psalm",
"composer update --working-dir=./tools/phpunit"
"composer update --working-dir=./tools/phpunit",
"composer update --working-dir=./web/landing/tools/phpunit"
]
},
"extra": {
Expand Down
Empty file removed src/web/landing/build/.gitkeep
Empty file.
23 changes: 0 additions & 23 deletions src/web/landing/src/Flow/Website/Controller/DefaultController.php

This file was deleted.

40 changes: 0 additions & 40 deletions src/web/landing/templates/main/example.txt.twig

This file was deleted.

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.
8 changes: 8 additions & 0 deletions src/web/landing/composer.json → web/landing/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@
"Flow\\Website\\": "src/Flow/Website/"
}
},
"autoload-dev": {
"psr-4": {
"Flow\\Website\\": "tests/Flow/Website/"
}
},
"config": {
"allow-plugins": {
"php-http/discovery": false,
"symfony/runtime": true
}
},
"scripts": {
"test": [
"tools/phpunit/vendor/bin/phpunit"
],
"assets:clear": "rm -rf public/assets",
"assets:build": [
"@assets:clear",
Expand Down
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.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters:
examples_path: '../../../examples'

services:
_defaults:
Expand All @@ -17,3 +18,7 @@ services:
Flow\Website\Factory\Github\ContributorsRequestFactory:
arguments:
$githubToken: '%env(GITHUB_TOKEN)%'

Flow\Website\Service\Examples:
arguments:
$examplesPath: '%examples_path%'
File renamed without changes.
22 changes: 22 additions & 0 deletions web/landing/phpunit.xml
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 web/landing/src/Flow/Website/Controller/DefaultController.php
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.
61 changes: 61 additions & 0 deletions web/landing/src/Flow/Website/Service/Examples.php
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.
Loading

0 comments on commit 75559d1

Please sign in to comment.