Stuff
This commit is contained in:
1 parent
e6ad944f79
commit
657975324a
15 files changed
+190
-23
No files matched your search
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace Lewisdale\App\Controllers;
|
||||
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
use Lewisdale\App\Models\Repositories\FeedRepository;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Slim\Views\Twig;
|
||||
|
||||
class FeedController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly Twig $view,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly FeedRepository $feedRepository
|
||||
) {}
|
||||
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response)
|
||||
{
|
||||
$this->logger->info("FeedController::get() called");
|
||||
$feeds = $this->feedRepository->findBy([], ['title' => 'ASC']);
|
||||
return $this->view->render($response, 'index.twig.html', ['feeds' => $feeds]);
|
||||
}
|
||||
|
||||
public function create(ServerRequestInterface $request, ResponseInterface $response)
|
||||
{
|
||||
$this->logger->info("FeedController::create() called");
|
||||
$body = $request->getParsedBody();
|
||||
|
||||
return $this->view->render($response, 'create.twig.html');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace Lewisdale\App\Models\Data;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Ramsey\Uuid\Doctrine\UuidGenerator;
|
||||
use Ramsey\Uuid\UuidInterface;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: 'feeds')]
|
||||
#[ORM\HasLifecycleCallbacks]
|
||||
class Feed
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(type: "uuid", unique: true)]
|
||||
#[ORM\GeneratedValue(strategy: "CUSTOM")]
|
||||
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
|
||||
public UuidInterface $id;
|
||||
|
||||
#[ORM\Column(type: 'string')]
|
||||
public string $url;
|
||||
|
||||
#[ORM\Column(type: 'string')]
|
||||
public string $title;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace Lewisdale\App\Models\Data;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Ramsey\Uuid\Doctrine\UuidGenerator;
|
||||
use Ramsey\Uuid\UuidInterface;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: 'feed_filters')]
|
||||
#[ORM\HasLifecycleCallbacks]
|
||||
class FeedFilter
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(type: "uuid", unique: true)]
|
||||
#[ORM\GeneratedValue(strategy: "CUSTOM")]
|
||||
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
|
||||
public UuidInterface $id;
|
||||
|
||||
public function getId(): UuidInterface
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
#[ORM\Column(type: 'string', enumType: FilterTarget::class)]
|
||||
public FilterTarget $target;
|
||||
|
||||
#[ORM\Column(type: 'string', enumType: FilterType::class)]
|
||||
public FilterType $filter;
|
||||
|
||||
#[ORM\Column(type: 'string')]
|
||||
public string $value;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: Feed::class)]
|
||||
#[ORM\JoinColumn(name: 'feed_id', referencedColumnName: 'id')]
|
||||
public Feed $feed;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Lewisdale\App\Models\Data;
|
||||
|
||||
enum FilterTarget: string
|
||||
{
|
||||
case TITLE = 'title';
|
||||
case DESCRIPTION = 'description';
|
||||
case LINK = 'link';
|
||||
case AUTHOR = 'author';
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Lewisdale\App\Models\Data;
|
||||
|
||||
enum FilterType: string
|
||||
{
|
||||
case INCLUDE = 'include';
|
||||
case EXCLUDE = 'exclude';
|
||||
case REGEX = 'regex';
|
||||
case EXACT = 'exact';
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace Lewisdale\App\Models\Repositories;
|
||||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Lewisdale\App\Models\Data\FeedFilter;
|
||||
|
||||
/** @extends EntityRepository<FeedFilter> */
|
||||
class FeedFilterRepository extends EntityRepository
|
||||
{
|
||||
public function __construct(EntityManager $em)
|
||||
{
|
||||
parent::__construct($em, $em->getClassMetadata(FeedFilter::class));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace Lewisdale\App\Models\Repositories;
|
||||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Lewisdale\App\Models\Data\Feed;
|
||||
|
||||
/** @extends EntityRepository<Feed> */
|
||||
class FeedRepository extends EntityRepository
|
||||
{
|
||||
public function __construct(EntityManager $em)
|
||||
{
|
||||
parent::__construct($em, $em->getClassMetadata(Feed::class));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use Lewisdale\App\Controllers\FeedController;
|
||||
use Lewisdale\App\Controllers\SampleController;
|
||||
use Slim\Views\TwigMiddleware;
|
||||
|
||||
@@ -18,6 +19,8 @@ $app->add('csrf');
|
||||
|
||||
$app->get("/", [SampleController::class, 'get']);
|
||||
|
||||
$app->get('/feed', [FeedController::class, 'get']);
|
||||
|
||||
$app->addErrorMiddleware(true, true, true);
|
||||
|
||||
$app->run();
|
||||
@@ -48,7 +48,7 @@ $container->set(EntityManager::class, static function() {
|
||||
|
||||
$connection = DriverManager::getConnection([
|
||||
'driver' => 'pdo_sqlite',
|
||||
'path' => __DIR__ . '/../' . $_ENV["SQLITE_DB_NAME"],
|
||||
'path' => __DIR__ . '/../' . getenv("SQLITE_DB_NAME"),
|
||||
], $config);
|
||||
|
||||
return new EntityManager($connection, $config);
|
||||
|
||||
Reference in new issue
Block a user