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
23 changes: 23 additions & 0 deletions bin/generate-feed
Comment thread
alexmerlin marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env php
<?php

declare(strict_types=1);

use Light\App\Service\FeedGenerator;

chdir(__DIR__ . '/../');

require 'vendor/autoload.php';

$container = require 'config/container.php';
$feedGenerator = $container->get(FeedGenerator::class);

$count = $feedGenerator->write();

printf(
"Done. %d article%s written to %s%s",
$count,
$count === 1 ? '' : 's',
$feedGenerator->getFeedFile(),
PHP_EOL
);
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"require": {
"php": "~8.5.0",
"ext-dom": "*",
"doctrine/data-fixtures": "^2.2",
"doctrine/doctrine-fixtures-bundle": "^4.3",
"dotkernel/dot-errorhandler": "^5.0.0",
Expand Down
3 changes: 3 additions & 0 deletions config/autoload/app.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

return [
'app' => $app,
'feed' => [
'path' => realpath(__DIR__ . '/../../public/feed.xml'),
],
Comment thread
OStefan2001 marked this conversation as resolved.
'twig' => [
'globals' => [
'app' => $app,
Expand Down
Empty file added public/feed.xml
Empty file.
6 changes: 6 additions & 0 deletions src/App/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
use Dot\Cache\Adapter\FilesystemAdapter;
use Light\App\DBAL\Types\UuidType;
use Light\App\Factory\EntityListenerResolverFactory;
use Light\App\Factory\FeedGeneratorFactory;
use Light\App\Factory\GetFeedViewHandlerFactory;
use Light\App\Factory\GetIndexViewHandlerFactory;
use Light\App\Handler\GetFeedViewHandler;
use Light\App\Handler\GetIndexViewHandler;
use Light\App\Resolver\EntityListenerResolver;
use Light\App\Service\FeedGenerator;
use Mezzio\Application;
use Roave\PsrContainerDoctrine\EntityManagerFactory;
use Symfony\Component\Cache\Adapter\AdapterInterface;
Expand Down Expand Up @@ -109,6 +113,8 @@ public function getDependencies(): array
'doctrine.entity_manager.orm_default' => EntityManagerFactory::class,
EntityListenerResolver::class => EntityListenerResolverFactory::class,
GetIndexViewHandler::class => GetIndexViewHandlerFactory::class,
GetFeedViewHandler::class => GetFeedViewHandlerFactory::class,
FeedGenerator::class => FeedGeneratorFactory::class,
],
'aliases' => [
EntityManager::class => 'doctrine.entity_manager.orm_default',
Expand Down
32 changes: 32 additions & 0 deletions src/App/src/Factory/FeedGeneratorFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Light\App\Factory;

use Light\App\Service\FeedGenerator;
use Light\Blog\Repository\PostRepository;
use Psr\Container\ContainerInterface;

use function assert;
use function rtrim;

class FeedGeneratorFactory
{
public function __invoke(ContainerInterface $container): FeedGenerator
{
$postRepository = $container->get(PostRepository::class);
assert($postRepository instanceof PostRepository);

$config = $container->get('config');

return new FeedGenerator(
$postRepository,
$config['feed']['path'],
rtrim($config['application']['url'] ?? '', '/') . '/',
$config['app']['meta']['title'] ?? '',
$config['app']['meta']['description'] ?? '',
$config['app']['meta']['image'] ?? '',
);
}
}
33 changes: 33 additions & 0 deletions src/App/src/Factory/GetFeedViewHandlerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Light\App\Factory;

use Light\App\Handler\GetFeedViewHandler;
use Light\App\Service\FeedGenerator;
use Light\Blog\Repository\CategoryRepository;
use Mezzio\Template\TemplateRendererInterface;
use Psr\Container\ContainerInterface;

use function assert;

class GetFeedViewHandlerFactory
{
/**
* @param class-string $requestedName
*/
public function __invoke(ContainerInterface $container, string $requestedName): GetFeedViewHandler
{
$template = $container->get(TemplateRendererInterface::class);
assert($template instanceof TemplateRendererInterface);

$categoryRepository = $container->get(CategoryRepository::class);
assert($categoryRepository instanceof CategoryRepository);

$feedGenerator = $container->get(FeedGenerator::class);
assert($feedGenerator instanceof FeedGenerator);

return new GetFeedViewHandler($template, $categoryRepository, $feedGenerator);
}
}
6 changes: 6 additions & 0 deletions src/App/src/Fixture/PostLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function load(ObjectManager $manager): void
: new DateTimeImmutable();

$excerpt = $articleData['excerpt'] ?? '';
$tlDr = $articleData['tl_dr'] ?? '';

$article = $repository->findOneBy(['slug' => $slug]);

Expand All @@ -87,6 +88,7 @@ public function load(ObjectManager $manager): void
$article->setCategory($category);
$article->setAuthor($author);
$article->setExcerpt($excerpt);
$article->setTldr($tlDr);

$manager->persist($article);
echo "CREATE: {$title}\n";
Expand Down Expand Up @@ -117,6 +119,10 @@ public function load(ObjectManager $manager): void
$article->setExcerpt($excerpt);
$changed = true;
}
if ($article->getTlDr() !== $tlDr) {
$article->setTldr($tlDr);
$changed = true;
}

echo $changed ? "UPDATE: {$title}\n" : "UNCHANGED: {$title}\n";
}
Expand Down
Loading