Add frontpage explaining the project and providing links
This commit is contained in:
parent
0d0866be1e
commit
c634827af7
8 changed files with 167 additions and 6 deletions
|
@ -2,12 +2,14 @@
|
|||
|
||||
use DanielSiepmann\FediverseFeedWrappers\RequestHandler;
|
||||
use DanielSiepmann\FediverseFeedWrappers\WrapperRegistry;
|
||||
use DanielSiepmann\FediverseFeedWrappers\Wrapper\Frontpage;
|
||||
use DanielSiepmann\FediverseFeedWrappers\Wrapper\GitHubTypo3;
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
(new RequestHandler(
|
||||
new WrapperRegistry([
|
||||
'' => Frontpage::class,
|
||||
'GitHubTypo3' => GitHubTypo3::class,
|
||||
])
|
||||
))->handleRequest();
|
||||
|
|
|
@ -38,8 +38,8 @@ class RequestHandler
|
|||
*/
|
||||
public function handleRequest(): void
|
||||
{
|
||||
$content = $this->wrapperRegistry->get($_GET['feed'] ?? '')->handle();
|
||||
header('content-type: application/xml;charset=utf-8');
|
||||
echo $content;
|
||||
$wrapper = $this->wrapperRegistry->get($_GET['feed'] ?? '');
|
||||
header('content-type: ' . $wrapper->contentType() . ';charset=utf-8');
|
||||
echo $wrapper->content();
|
||||
}
|
||||
}
|
||||
|
|
40
src/Wrapper/Frontpage.php
Normal file
40
src/Wrapper/Frontpage.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DanielSiepmann\FediverseFeedWrappers\Wrapper;
|
||||
|
||||
use DanielSiepmann\FediverseFeedWrappers\WrapperInterface;
|
||||
|
||||
class Frontpage implements WrapperInterface
|
||||
{
|
||||
public function contentType(): string
|
||||
{
|
||||
return 'text/html';
|
||||
}
|
||||
|
||||
public function content(): string
|
||||
{
|
||||
$content = '
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Fediverse Wrapper by Daniel Siepmann</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Fediverse Wrapper by Daniel Siepmann</h1>
|
||||
<p>This is a small project that allows to wrap other sources to be used by the Fediverse.</p>
|
||||
<p>I use it myself in order to mirror the wrapped feeds from my friendi.ca instance.</p>
|
||||
<p>A list of the TYPO3 mirror accounts is available at: <a href="https://daniel-siepmann.de/typo3-fediverse-news-accounts.html">https://daniel-siepmann.de/typo3-fediverse-news-accounts.html</a>.</p>
|
||||
<p>The repository of the source code is available here: <a href="https://git.daniel-siepmann.de/danielsiepmann/fediverse-feed-wrappers">https://git.daniel-siepmann.de/danielsiepmann/fediverse-feed-wrappers</a>.</p>
|
||||
</body>
|
||||
</html>
|
||||
';
|
||||
|
||||
$content = str_replace(' ', '', $content);
|
||||
$content = trim($content);
|
||||
|
||||
return $content . PHP_EOL;
|
||||
}
|
||||
}
|
|
@ -36,13 +36,18 @@ class GitHubTypo3 implements WrapperInterface
|
|||
$this->url = $url;
|
||||
}
|
||||
|
||||
public function contentType(): string
|
||||
{
|
||||
return 'application/xml';
|
||||
}
|
||||
|
||||
/**
|
||||
* We don't want the full commit messag within each feed item.
|
||||
*
|
||||
* Instead we are only interested in first row.
|
||||
* Interested people can head over to the actual URL for full info.
|
||||
*/
|
||||
public function handle(): string
|
||||
public function content(): string
|
||||
{
|
||||
$content = new DOMDocument();
|
||||
$content->loadXML(file_get_contents($this->url));
|
||||
|
|
|
@ -25,5 +25,6 @@ namespace DanielSiepmann\FediverseFeedWrappers;
|
|||
|
||||
interface WrapperInterface
|
||||
{
|
||||
public function handle(): string;
|
||||
public function contentType(): string;
|
||||
public function content(): string;
|
||||
}
|
||||
|
|
14
tests/Unit/Wrapper/Assertions/Frontpage.html
Normal file
14
tests/Unit/Wrapper/Assertions/Frontpage.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Fediverse Wrapper by Daniel Siepmann</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Fediverse Wrapper by Daniel Siepmann</h1>
|
||||
<p>This is a small project that allows to wrap other sources to be used by the Fediverse.</p>
|
||||
<p>I use it myself in order to mirror the wrapped feeds from my friendi.ca instance.</p>
|
||||
<p>A list of the TYPO3 mirror accounts is available at: <a href="https://daniel-siepmann.de/typo3-fediverse-news-accounts.html">https://daniel-siepmann.de/typo3-fediverse-news-accounts.html</a>.</p>
|
||||
<p>The repository of the source code is available here: <a href="https://git.daniel-siepmann.de/danielsiepmann/fediverse-feed-wrappers">https://git.daniel-siepmann.de/danielsiepmann/fediverse-feed-wrappers</a>.</p>
|
||||
</body>
|
||||
</html>
|
86
tests/Unit/Wrapper/FrontpageTest.php
Normal file
86
tests/Unit/Wrapper/FrontpageTest.php
Normal file
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Copyright (C) 2023 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
namespace DanielSiepmann\FediverseFeedWrappers\Tests\Unit\Wrapper;
|
||||
|
||||
use DanielSiepmann\FediverseFeedWrappers\WrapperInterface;
|
||||
use DanielSiepmann\FediverseFeedWrappers\Wrapper\Frontpage;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \DanielSiepmann\FediverseFeedWrappers\Wrapper\Frontpage
|
||||
*/
|
||||
class FrontpageTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function canBeCreated(): void
|
||||
{
|
||||
$subject = new Frontpage();
|
||||
|
||||
self::assertInstanceOf(
|
||||
Frontpage::class,
|
||||
$subject
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function isInstanceOfWrapperInterface(): void
|
||||
{
|
||||
$subject = new Frontpage();
|
||||
|
||||
self::assertInstanceOf(
|
||||
WrapperInterface::class,
|
||||
$subject
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function returnsContentType(): void
|
||||
{
|
||||
$subject = new Frontpage();
|
||||
|
||||
self::assertSame(
|
||||
'text/html',
|
||||
$subject->contentType()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function returnsContent(): void
|
||||
{
|
||||
$subject = new Frontpage();
|
||||
|
||||
self::assertStringEqualsFile(
|
||||
__DIR__ . '/Assertions/Frontpage.html',
|
||||
$subject->content()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -58,6 +58,19 @@ class GitHubTypo3Test extends TestCase
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function returnsContentType(): void
|
||||
{
|
||||
$subject = new GitHubTypo3();
|
||||
|
||||
self::assertSame(
|
||||
'application/xml',
|
||||
$subject->contentType()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
|
@ -69,7 +82,7 @@ class GitHubTypo3Test extends TestCase
|
|||
|
||||
self::assertStringEqualsFile(
|
||||
__DIR__ . '/Assertions/GitHubTypo3.atom',
|
||||
$subject->handle()
|
||||
$subject->content()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue