mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 00:55:28 +00:00
refactor to separated entities, init abstractions
This commit is contained in:
parent
08c9fe76e5
commit
90acc3ac2d
47 changed files with 1927 additions and 2069 deletions
|
|
@ -1,45 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Model;
|
||||
|
||||
class Config
|
||||
{
|
||||
public function __construct(
|
||||
?string $filename = null
|
||||
) {
|
||||
if (empty($filename))
|
||||
{
|
||||
$filename = __DIR__ .
|
||||
DIRECTORY_SEPARATOR . '..' .
|
||||
DIRECTORY_SEPARATOR . '..' .
|
||||
DIRECTORY_SEPARATOR . 'config.json';
|
||||
}
|
||||
|
||||
if (!file_exists($filename))
|
||||
{
|
||||
throw new \Exception; // @TODO
|
||||
}
|
||||
|
||||
if (!is_readable($filename))
|
||||
{
|
||||
throw new \Exception; // @TODO
|
||||
}
|
||||
|
||||
if (!$data = file_get_contents($filename))
|
||||
{
|
||||
throw new \Exception; // @TODO
|
||||
}
|
||||
|
||||
if (!$config = @json_decode($data))
|
||||
{
|
||||
throw new \Exception; // @TODO
|
||||
}
|
||||
|
||||
foreach ($config as $key => $value)
|
||||
{
|
||||
$this->{$key} = $value; // @TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -64,8 +64,8 @@ class Database
|
|||
return (int) $this->_database->lastInsertId();
|
||||
}
|
||||
|
||||
public function getHistory(
|
||||
string $search = '',
|
||||
public function findHistory(
|
||||
string $value = '',
|
||||
int $start = 0,
|
||||
int $limit = 1000
|
||||
): array
|
||||
|
|
@ -73,7 +73,7 @@ class Database
|
|||
$query = $this->_database->prepare(
|
||||
sprintf(
|
||||
'SELECT * FROM `history`
|
||||
WHERE `url` LIKE :search OR `title` LIKE :search
|
||||
WHERE `url` LIKE :value OR `title` LIKE :value
|
||||
ORDER BY `id` DESC
|
||||
LIMIT %d,%d',
|
||||
$start,
|
||||
|
|
@ -83,9 +83,9 @@ class Database
|
|||
|
||||
$query->execute(
|
||||
[
|
||||
':search' => sprintf(
|
||||
':value' => sprintf(
|
||||
'%%%s%%',
|
||||
$search
|
||||
$value
|
||||
)
|
||||
]
|
||||
);
|
||||
|
|
@ -122,4 +122,35 @@ class Database
|
|||
|
||||
return $query->rowCount();
|
||||
}
|
||||
|
||||
public function refreshHistory(
|
||||
string $url,
|
||||
?string $title = null
|
||||
): void
|
||||
{
|
||||
// Find same records match URL
|
||||
$query = $this->_database->prepare(
|
||||
'SELECT * FROM `history` WHERE `url` LIKE :url'
|
||||
);
|
||||
|
||||
$query->execute(
|
||||
[
|
||||
':url' => $url
|
||||
]
|
||||
);
|
||||
|
||||
// Drop previous records
|
||||
foreach ($query->fetchAll() as $record)
|
||||
{
|
||||
$this->deleteHistory(
|
||||
$record->id
|
||||
);
|
||||
}
|
||||
|
||||
// Add new record
|
||||
$this->addHistory(
|
||||
$url,
|
||||
$title
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Model;
|
||||
|
||||
class File
|
||||
{
|
||||
public static function getTheme(string $name): string
|
||||
{
|
||||
$filename = __DIR__ .
|
||||
DIRECTORY_SEPARATOR . '..' .
|
||||
DIRECTORY_SEPARATOR . 'Theme' .
|
||||
DIRECTORY_SEPARATOR . $name . '.css';
|
||||
|
||||
if (file_exists($filename) && is_readable($filename))
|
||||
{
|
||||
$result = file_get_contents(
|
||||
$filename
|
||||
);
|
||||
}
|
||||
|
||||
if (empty($result))
|
||||
{
|
||||
throw new \Exception(); // @TODO
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Model;
|
||||
|
||||
class Memory
|
||||
{
|
||||
private array $_memory = [];
|
||||
|
||||
public function __construct()
|
||||
{}
|
||||
|
||||
public function set(string $key, mixed $value): void
|
||||
{
|
||||
$this->_memory[$key] = $value;
|
||||
}
|
||||
|
||||
public function get(string $key): mixed
|
||||
{
|
||||
if (isset($this->_memory[$key]))
|
||||
{
|
||||
return $this->_memory[$key];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function flush(): void
|
||||
{
|
||||
$this->_memory = [];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Model;
|
||||
|
||||
class Page
|
||||
{
|
||||
public static function get(string $name): ?string
|
||||
{
|
||||
$name = ucfirst(
|
||||
mb_strtolower(
|
||||
$name
|
||||
)
|
||||
);
|
||||
|
||||
$filename = __DIR__ .
|
||||
DIRECTORY_SEPARATOR . '..' .
|
||||
DIRECTORY_SEPARATOR . 'Page' .
|
||||
DIRECTORY_SEPARATOR . $name . '.gmi';
|
||||
|
||||
if (file_exists($filename) && is_readable($filename))
|
||||
{
|
||||
return file_get_contents(
|
||||
$filename
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue