This commit is contained in:
Lewis Dale 2024-09-17 21:52:08 +01:00
parent e6ad944f79
commit 657975324a
15 changed files with 190 additions and 23 deletions

View File

@ -2,9 +2,7 @@
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="Lewisdale\App\" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/masterminds/html5" />
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/lexer" />

View File

@ -2,7 +2,7 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/feacher.iml" filepath="$PROJECT_DIR$/.idea/feacher.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/baleen.iml" filepath="$PROJECT_DIR$/.idea/baleen.iml" />
</modules>
</component>
</project>
</project>

6
.idea/symfony2.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Symfony2PluginSettings">
<option name="pluginEnabled" value="true" />
</component>
</project>

View File

@ -8,6 +8,7 @@ use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
$dotenv = Dotenv\Dotenv::createImmutable([__DIR__, __DIR__ . "/.."]);
$dotenv->load();
require_once __DIR__ . '/../src/dependencies.php';
global $container;

View File

@ -1,5 +1,5 @@
{
"name": "lewisdale/app",
"name": "lewisdale/baleen",
"type": "project",
"require": {
"slim/slim": "^4.11",
@ -15,7 +15,7 @@
"ext-pdo": "*",
"ext-readline": "*",
"slim/csrf": "^1.3",
"ramsey/uuid-doctrine": "^2.0",
"ramsey/uuid-doctrine": "^2.1",
"ramsey/uuid": "^4.7",
"symfony/dom-crawler": "^6.3",
"symfony/css-selector": "^6.3",

29
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "b316cfe896d61acbd6be631afe77733f",
"content-hash": "c8354494b2a7c54a846acc27471f1b8a",
"packages": [
{
"name": "brick/math",
@ -2288,26 +2288,26 @@
},
{
"name": "ramsey/uuid-doctrine",
"version": "2.0.0",
"version": "2.1.0",
"source": {
"type": "git",
"url": "https://github.com/ramsey/uuid-doctrine.git",
"reference": "b002676be0e5e342d857c47f1b68e24de6841d08"
"reference": "491e1bfa4d9d81e52a60470fa92c871f7eef919e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ramsey/uuid-doctrine/zipball/b002676be0e5e342d857c47f1b68e24de6841d08",
"reference": "b002676be0e5e342d857c47f1b68e24de6841d08",
"url": "https://api.github.com/repos/ramsey/uuid-doctrine/zipball/491e1bfa4d9d81e52a60470fa92c871f7eef919e",
"reference": "491e1bfa4d9d81e52a60470fa92c871f7eef919e",
"shasum": ""
},
"require": {
"doctrine/dbal": "^2.8 || ^3.0",
"php": "^7.4 || ^8.0",
"doctrine/dbal": "^2.8 || ^3.0 || ^4.0",
"php": "^8.1",
"ramsey/uuid": "^3.9.7 || ^4.0"
},
"require-dev": {
"captainhook/plugin-composer": "^5.3",
"doctrine/orm": "^2.5",
"doctrine/orm": "^2.5 || ^3.0",
"ergebnis/composer-normalize": "^2.28.3",
"mockery/mockery": "^1.5",
"php-parallel-lint/php-console-highlighter": "^1.0",
@ -2317,12 +2317,9 @@
"phpstan/phpstan": "^1.9",
"phpstan/phpstan-mockery": "^1.1",
"phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "^9.5",
"psalm/plugin-mockery": "^1.1",
"psalm/plugin-phpunit": "^0.18.4",
"phpunit/phpunit": "^10.5",
"ramsey/coding-standard": "^2.0.3",
"ramsey/conventional-commits": "^1.3",
"vimeo/psalm": "^5.4"
"ramsey/conventional-commits": "^1.3"
},
"type": "library",
"extra": {
@ -2359,7 +2356,7 @@
],
"support": {
"issues": "https://github.com/ramsey/uuid-doctrine/issues",
"source": "https://github.com/ramsey/uuid-doctrine/tree/2.0.0"
"source": "https://github.com/ramsey/uuid-doctrine/tree/2.1.0"
},
"funding": [
{
@ -2371,7 +2368,7 @@
"type": "tidelift"
}
],
"time": "2022-12-20T23:38:28+00:00"
"time": "2024-05-27T00:00:21+00:00"
},
{
"name": "slim/csrf",
@ -5909,5 +5906,5 @@
"ext-readline": "*"
},
"platform-dev": [],
"plugin-api-version": "2.3.0"
"plugin-api-version": "2.6.0"
}

View File

@ -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');
}
}

27
src/Models/Data/Feed.php Normal file
View File

@ -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;
}

View File

@ -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;
}

View File

@ -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';
}

View File

@ -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';
}

View File

@ -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));
}
}

View File

@ -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));
}
}

View File

@ -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();

View File

@ -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);