Skip to content

Commit

Permalink
Page -> PageInterface, News deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
kapxapot committed Jun 21, 2020
1 parent df66eba commit 25ef7ac
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 133 deletions.
4 changes: 2 additions & 2 deletions src/Collections/PageCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Plasticode\Collections;

use Plasticode\Collections\Basic\DbModelCollection;
use Plasticode\Models\Page;
use Plasticode\Models\Interfaces\PageInterface;

class PageCollection extends DbModelCollection
{
protected string $class = Page::class;
protected string $class = PageInterface::class;
}
14 changes: 0 additions & 14 deletions src/Config/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@
use Plasticode\Repositories\Idiorm\Basic\RepositoryContext;
use Plasticode\Repositories\Idiorm\MenuItemRepository;
use Plasticode\Repositories\Idiorm\MenuRepository;
use Plasticode\Repositories\Idiorm\NewsRepository;
use Plasticode\Repositories\Idiorm\PageRepository;
use Plasticode\Repositories\Idiorm\RoleRepository;
use Plasticode\Repositories\Idiorm\TagRepository;
use Plasticode\Repositories\Idiorm\UserRepository;
Expand Down Expand Up @@ -250,18 +248,6 @@ function ($record) use ($c) {
)
);

$map['newsRepository'] = fn (CI $c) =>
new NewsRepository(
$c->repositoryContext,
$c->tagRepository
);

$map['pageRepository'] = fn (CI $c) =>
new PageRepository(
$c->repositoryContext,
$c->tagRepository
);

$map['roleRepository'] = fn (CI $c) =>
new RoleRepository(
$c->repositoryContext
Expand Down
9 changes: 9 additions & 0 deletions src/Models/Interfaces/PageInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Plasticode\Models\Interfaces;

interface PageInterface extends DbModelInterface
{
function isPublished() : bool;
function getSlug() : string;
}
23 changes: 0 additions & 23 deletions src/Models/News.php

This file was deleted.

26 changes: 0 additions & 26 deletions src/Models/Page.php

This file was deleted.

15 changes: 4 additions & 11 deletions src/Parsing/LinkMappers/PageLinkMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@
*/
class PageLinkMapper extends EntityLinkMapper
{
/** @var PageRepositoryInterface */
private $pageRepository;

/** @var TagRepositoryInterface */
private $tagRepository;

/** @var TagLinkMapper */
private $tagLinkMapper;
private PageRepositoryInterface $pageRepository;
private TagRepositoryInterface $tagRepository;
private TagLinkMapper $tagLinkMapper;

public function __construct(
PageRepositoryInterface $pageRepository,
Expand Down Expand Up @@ -53,9 +48,7 @@ protected function baseUrl() : string
/**
* Maps page chunks to a page link.
*
* @param SlugChunk $slugChunk
* @param string[] $otherChunks
* @return string|null
*/
public function mapSlug(SlugChunk $slugChunk, array $otherChunks) : ?string
{
Expand All @@ -68,7 +61,7 @@ public function mapSlug(SlugChunk $slugChunk, array $otherChunks) : ?string
$page = $this->pageRepository->getBySlug($slug);

if ($page && $page->isPublished()) {
return $this->renderPlaceholder($page->slug, $content);
return $this->renderPlaceholder($page->getSlug(), $content);
}
}

Expand Down
9 changes: 2 additions & 7 deletions src/Parsing/Parsers/DoubleBracketsParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
use Plasticode\Util\Arrays;

/**
* Parses double brackets tags such as [[about|About]] page or [[news:123|Some cool news]] news links.
* Parses double brackets tags such as [[about|About]] page
* or [[news:123|Some cool news]] news links.
*
* - Default mapper parses [[slug|Content]] links.
* - Tag mappers parse [[tag:id|Content]] links.
Expand Down Expand Up @@ -74,7 +75,6 @@ private function parseDoubleBracketsMatch(?string $match) : ?string
* Render no-tag link.
*
* @param string[] $chunks
* @return string|null
*/
private function renderDefault(array $chunks) : ?string
{
Expand All @@ -88,9 +88,7 @@ private function renderDefault(array $chunks) : ?string
/**
* Renders tag link.
*
* @param string $tag
* @param string[] $chunks
* @return string|null
*/
private function renderTag(string $tag, array $chunks) : ?string
{
Expand All @@ -106,9 +104,6 @@ private function renderTag(string $tag, array $chunks) : ?string

/**
* Renders %template% links using registered link renderers.
*
* @param ParsingContext $context
* @return ParsingContext
*/
public function renderLinks(ParsingContext $context) : ParsingContext
{
Expand Down
12 changes: 0 additions & 12 deletions src/Repositories/Idiorm/NewsRepository.php

This file was deleted.

20 changes: 0 additions & 20 deletions src/Repositories/Idiorm/PageRepository.php

This file was deleted.

7 changes: 0 additions & 7 deletions src/Repositories/Interfaces/NewsRepositoryInterface.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/Repositories/Interfaces/PageRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Plasticode\Repositories\Interfaces;

use Plasticode\Models\Page;
use Plasticode\Models\Interfaces\PageInterface;

interface PageRepositoryInterface
{
function getBySlug(?string $slug) : ?Page;
function getBySlug(?string $slug) : ?PageInterface;
}
23 changes: 23 additions & 0 deletions src/Testing/Dummies/PageDummy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Plasticode\Testing\Dummies;

use Plasticode\Models\DbModel;
use Plasticode\Models\Interfaces\PageInterface;
use Plasticode\Models\Traits\FullPublished;

/**
* @property integer $id
* @property string $slug
* @property string $title
* @property string|null $text
*/
class PageDummy extends DbModel implements PageInterface
{
use FullPublished;

public function getSlug() : string
{
return $this->slug;
}
}
12 changes: 7 additions & 5 deletions src/Testing/Mocks/Repositories/PageRepositoryMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Plasticode\Testing\Mocks\Repositories;

use Plasticode\Collections\PageCollection;
use Plasticode\Models\Page;
use Plasticode\Models\Interfaces\PageInterface;
use Plasticode\Repositories\Interfaces\PageRepositoryInterface;
use Plasticode\Testing\Seeders\Interfaces\ArraySeederInterface;

Expand All @@ -16,10 +16,12 @@ public function __construct(ArraySeederInterface $pageSeeder)
$this->pages = PageCollection::make($pageSeeder->seed());
}

public function getBySlug(?string $slug) : ?Page
public function getBySlug(?string $slug) : ?PageInterface
{
return $this->pages
->where('slug', $slug)
->first();
return $this
->pages
->first(
fn (PageInterface $p) => $p->getSlug() == $slug
);
}
}
8 changes: 4 additions & 4 deletions src/Testing/Seeders/PageSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

namespace Plasticode\Testing\Seeders;

use Plasticode\Models\Page;
use Plasticode\Testing\Dummies\PageDummy;
use Plasticode\Testing\Seeders\Interfaces\ArraySeederInterface;
use Plasticode\Util\Date;

class PageSeeder implements ArraySeederInterface
{
/**
* @return Page[]
* @return PageDummy[]
*/
public function seed() : array
{
return [
new Page(
new PageDummy(
[
'id' => 1,
'slug' => 'about-us',
Expand All @@ -24,7 +24,7 @@ public function seed() : array
'published_at' => Date::dbNow(),
]
),
new Page(
new PageDummy(
[
'id' => 2,
'slug' => 'illidan-stormrage',
Expand Down

0 comments on commit 25ef7ac

Please sign in to comment.