Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions resources/docs/composer-based-sets.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ return RectorConfig::configure()
* and run those

If you upgrade to Doctrine 4, Twig 4, or Symfony 10 later, Rector will pick up sets for you.


59 changes: 59 additions & 0 deletions resources/views/llm/llms-txt.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
@php
/** @var \App\Entity\Post[] $posts */
/** @var array<string, \App\Documentation\DocumentationMenuItem[]> $documentationMenuItemsBySection */
@endphp


# Rector

We help successful and growing companies to get the most out of the code they already have.

Reduce maintenance cost, make feature delivery cheaper
and turn legacy code into sustainable code.


## How does Rector Improve your Business?

Rector is a PHP tool that you can run on any PHP project to get an instant upgrade or automated refactoring.

It helps you with:

* PHP and framework upgrades,
* in-house framework migrations,
* improving your code quality to deliver features faster than competition

In the hands of an expert, Rector massively reduces your work-time.
Where project upgrade PHP 8.0 to 8.4 would take 3 months, Rector is done in 3 days.

You can learn it yourself from documentation, or to save time and start upgrading today, hire our upgrade team.

=========================================

# Documentation

@foreach ($documentationMenuItemsBySection as $section => $documentationMenuItems)
@foreach ($documentationMenuItems as $documentationMenuItem)
@continue ($documentationMenuItem->getSlug() === null)

## {{ $section }}: {{ $documentationMenuItem->getLabel() }}

{!! $documentationMenuItem->getMarkdownContents() !!}

-----------------------------------------

@endforeach
@endforeach

=========================================

# Blog posts

@foreach ($posts as $post)
## {{ $post->getTitle() }}

Perex: {!! $post->getPerex() !!}

{!! $post->getContents() !!}

-----------------------------------------
@endforeach
3 changes: 3 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use App\Controller\Llm\LlmsTxtController;
use App\Controller\Stats\FindRuleStatsController;
use App\Ast\Controller\AstController;
use App\Ast\Controller\AstDetailController;
Expand All @@ -25,6 +26,8 @@

Route::get('/', HomepageController::class);

Route::get('llms.txt', LlmsTxtController::class);

// old pages redirect
Route::redirect('/documentation/rules-overview', '/find-rule');
Route::redirect('step-by-step', '/hire-team');
Expand Down
6 changes: 5 additions & 1 deletion src/Controller/DocumentationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Contracts\View\View;
use Illuminate\Routing\Controller;
use Nette\Utils\FileSystem;
use Webmozart\Assert\Assert;

final class DocumentationController extends Controller
{
Expand All @@ -18,7 +19,10 @@ public function __construct(

public function __invoke(string $section = 'introduction'): View
{
$markdownContents = FileSystem::read(__DIR__ . '/../../resources/docs/' . $section . '.md');
$documentationFile = __DIR__ . '/../../resources/docs/' . $section . '.md';
Assert::fileExists($documentationFile);

$markdownContents = FileSystem::read($documentationFile);

return \view('docs/section', [
'section_title' => $this->documentationMenuFactory->createSectionTitle($section),
Expand Down
27 changes: 27 additions & 0 deletions src/Controller/Llm/LlmsTxtController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace App\Controller\Llm;

use App\Documentation\DocumentationMenuFactory;
use App\Repository\PostRepository;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;

final class LlmsTxtController extends Controller
{
public function __construct(
private readonly PostRepository $postRepository,
private readonly DocumentationMenuFactory $documentationMenuFactory,
) {
}

public function __invoke(): Response
{
return response()->view('llm/llms-txt', [
'posts' => $this->postRepository->fetchAll(),
'documentationMenuItemsBySection' => $this->documentationMenuFactory->create(),
])->header('Content-Type', 'text/plain');
}
}
3 changes: 1 addition & 2 deletions src/Documentation/DocumentationMenuFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
final readonly class DocumentationMenuFactory
{
public function __construct(
private DocumentationMenuItemFactory $documentationMenuItemFactory
private DocumentationMenuItemFactory $documentationMenuItemFactory,
) {
}

Expand Down Expand Up @@ -68,7 +68,6 @@ public function create(): array
'writing-tests-for-custom-rule',
'Writing Tests For Custom Rule'
),
$this->documentationMenuItemFactory->createSection('rules-overview', 'Rules Overview'),
$this->documentationMenuItemFactory->createSection('creating-a-node-visitor', 'Creating Node Visitor'),
$this->documentationMenuItemFactory->createSection('how-to-run-on-php-53', 'Run on PHP 5.3'),
$this->documentationMenuItemFactory->createSection(
Expand Down
24 changes: 24 additions & 0 deletions src/Documentation/DocumentationMenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@

namespace App\Documentation;

use Nette\Utils\FileSystem;
use Webmozart\Assert\Assert;

final readonly class DocumentationMenuItem
{
/**
* @param non-empty-string|null $slug
*/
public function __construct(
private string $href,
private string $label,
private ?string $slug,
private bool $isNew = false,
) {
}
Expand All @@ -27,4 +34,21 @@ public function isNew(): bool
{
return $this->isNew;
}

/**
* @return non-empty-string|null
*/
public function getSlug(): ?string
{
return $this->slug;
}

public function getMarkdownContents(): string
{
Assert::notNull($this->slug);
$documentationFilePath = __DIR__ . '/../../resources/docs/' . $this->slug . '.md';

Assert::fileExists($documentationFilePath);
return FileSystem::read($documentationFilePath);
}
}
12 changes: 9 additions & 3 deletions src/Documentation/DocumentationMenuItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,23 @@ public function __construct(
) {
}

/**
* @param non-empty-string $slugOrUrl
*/
public function createSection(string $slugOrUrl, string $name, bool $isNew = false): DocumentationMenuItem
{
if (str_starts_with($slugOrUrl, 'https://')) {
if (str_starts_with($slugOrUrl, 'https://') || str_starts_with($slugOrUrl, 'http://')) {
$url = $slugOrUrl;
$slug = null;
} else {
$url = $this->urlGenerator->action(DocumentationController::class, [
'section' => $slugOrUrl,
]);

$slug = $slugOrUrl;
}

return new DocumentationMenuItem($url, $name, $isNew);
return new DocumentationMenuItem($url, $name, $slug, $isNew);
}

/**
Expand All @@ -35,6 +41,6 @@ public function createInternalLink(string $controllerClass, string $label): Docu
{
$href = $this->urlGenerator->action($controllerClass);

return new DocumentationMenuItem($href, $label);
return new DocumentationMenuItem($href, $label, null);
}
}
8 changes: 8 additions & 0 deletions src/Repository/PostRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ public function fetchLast(int $count): array
return array_slice($this->posts, 0, $count);
}

/**
* @return Post[]
*/
public function fetchAll(): array
{
return $this->posts;
}

private function createPosts(): void
{
$posts = [];
Expand Down
2 changes: 1 addition & 1 deletion tests/Documentation/DocumentationMenuFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function setUp(): void
->willReturn('/index.html');

$this->documentationMenuFactory = new DocumentationMenuFactory(
new DocumentationMenuItemFactory($urlGenerator)
new DocumentationMenuItemFactory($urlGenerator),
);
}

Expand Down