add 'adding content' chapter
This commit is contained in:
parent
fed49011bd
commit
10aa69d6d4
20 changed files with 884 additions and 251 deletions
|
@ -1,7 +1,4 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Lubian\NoFramework\Repository;
|
||||
|
||||
|
@ -10,15 +7,17 @@ use Doctrine\ORM\EntityRepository;
|
|||
use Lubian\NoFramework\Exception\NotFound;
|
||||
use Lubian\NoFramework\Model\MarkdownPage;
|
||||
|
||||
use function random_int;
|
||||
use function usleep;
|
||||
|
||||
final class DoctrineMarkdownPageRepo implements MarkdownPageRepo
|
||||
{
|
||||
/**
|
||||
* @var EntityRepository<MarkdownPage>
|
||||
*/
|
||||
/** @var EntityRepository<MarkdownPage> */
|
||||
private EntityRepository $repo;
|
||||
|
||||
public function __construct(
|
||||
private EntityManagerInterface $entityManager
|
||||
){
|
||||
) {
|
||||
$this->repo = $this->entityManager->getRepository(MarkdownPage::class);
|
||||
}
|
||||
|
||||
|
@ -27,15 +26,15 @@ final class DoctrineMarkdownPageRepo implements MarkdownPageRepo
|
|||
*/
|
||||
public function all(): array
|
||||
{
|
||||
usleep(rand(500, 1500) * 1000);
|
||||
usleep(random_int(500, 1500) * 1000);
|
||||
return $this->repo->findAll();
|
||||
}
|
||||
|
||||
public function byId(int $id): MarkdownPage
|
||||
{
|
||||
usleep(rand(500, 1500) * 1000);
|
||||
usleep(random_int(500, 1500) * 1000);
|
||||
$page = $this->repo->findOneBy(['id' => $id]);
|
||||
if (!$page instanceof MarkdownPage){
|
||||
if (! $page instanceof MarkdownPage) {
|
||||
throw new NotFound;
|
||||
}
|
||||
return $page;
|
||||
|
@ -43,9 +42,9 @@ final class DoctrineMarkdownPageRepo implements MarkdownPageRepo
|
|||
|
||||
public function byTitle(string $title): MarkdownPage
|
||||
{
|
||||
usleep(rand(500, 1500) * 1000);
|
||||
usleep(random_int(500, 1500) * 1000);
|
||||
$page = $this->repo->findOneBy(['title' => $title]);
|
||||
if (!$page instanceof MarkdownPage){
|
||||
if (! $page instanceof MarkdownPage) {
|
||||
throw new NotFound;
|
||||
}
|
||||
return $page;
|
||||
|
@ -57,4 +56,4 @@ final class DoctrineMarkdownPageRepo implements MarkdownPageRepo
|
|||
$this->entityManager->flush();
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ use function count;
|
|||
use function file_get_contents;
|
||||
use function glob;
|
||||
use function is_array;
|
||||
use function random_int;
|
||||
use function str_replace;
|
||||
use function substr;
|
||||
use function usleep;
|
||||
|
@ -31,7 +32,7 @@ final class MarkdownPageFilesystem implements MarkdownPageRepo
|
|||
$fileNames = glob($this->dataPath . '*.md');
|
||||
assert(is_array($fileNames));
|
||||
return array_map(function (string $name): MarkdownPage {
|
||||
usleep(rand(200, 500) * 1000);
|
||||
usleep(random_int(200, 500) * 1000);
|
||||
$content = file_get_contents($name);
|
||||
$name = str_replace($this->dataPath, '', $name);
|
||||
$name = str_replace('.md', '', $name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue