aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2021-06-25 22:13:59 +0200
committerThomas Lange <code@nerdmind.de>2021-06-25 22:13:59 +0200
commita86bdc6b5bab78b4026f44161413f4e482df42e4 (patch)
tree76ffd745780671371272e97b3eeac85e154e236e
parent366d0de19c012821ef587d5fdb9557c339b43303 (diff)
downloadblog-a86bdc6b5bab78b4026f44161413f4e482df42e4.tar.gz
blog-a86bdc6b5bab78b4026f44161413f4e482df42e4.tar.xz
blog-a86bdc6b5bab78b4026f44161413f4e482df42e4.zip
Reorganize namespaces
-rw-r--r--admin/page/insert.php2
-rw-r--r--admin/post/insert.php2
-rw-r--r--admin/user/insert.php2
-rw-r--r--core/application.php6
-rw-r--r--core/functions.php18
-rw-r--r--core/namespace/Application.php14
-rw-r--r--core/namespace/ORM/Entities/Page.php (renamed from core/namespace/Page/Entity.php)5
-rw-r--r--core/namespace/ORM/Entities/Post.php (renamed from core/namespace/Post/Entity.php)5
-rw-r--r--core/namespace/ORM/Entities/User.php (renamed from core/namespace/User/Entity.php)5
-rw-r--r--core/namespace/ORM/Entity.php (renamed from core/namespace/Entity.php)2
-rw-r--r--core/namespace/ORM/EntityInterface.php (renamed from core/namespace/EntityInterface.php)2
-rw-r--r--core/namespace/ORM/Repositories/Page.php (renamed from core/namespace/Page/Repository.php)10
-rw-r--r--core/namespace/ORM/Repositories/Post.php (renamed from core/namespace/Post/Repository.php)10
-rw-r--r--core/namespace/ORM/Repositories/User.php8
-rw-r--r--core/namespace/ORM/Repository.php (renamed from core/namespace/Repository.php)3
-rw-r--r--core/namespace/User/Repository.php7
16 files changed, 60 insertions, 41 deletions
diff --git a/admin/page/insert.php b/admin/page/insert.php
index 6acfcfb..8ec69ea 100644
--- a/admin/page/insert.php
+++ b/admin/page/insert.php
@@ -19,7 +19,7 @@ $UserRepository = Application::getRepository('User');
#===============================================================================
# Instantiate new Page entity
#===============================================================================
-$Page = new Page\Entity;
+$Page = new ORM\Entities\Page;
#===============================================================================
# Check for insert request
diff --git a/admin/post/insert.php b/admin/post/insert.php
index c640a39..72f40b6 100644
--- a/admin/post/insert.php
+++ b/admin/post/insert.php
@@ -19,7 +19,7 @@ $UserRepository = Application::getRepository('User');
#===============================================================================
# Instantiate new Post entity
#===============================================================================
-$Post = new Post\Entity;
+$Post = new ORM\Entities\Post;
#===============================================================================
# Check for insert request
diff --git a/admin/user/insert.php b/admin/user/insert.php
index 96fcb84..67b62fa 100644
--- a/admin/user/insert.php
+++ b/admin/user/insert.php
@@ -18,7 +18,7 @@ $UserRepository = Application::getRepository('User');
#===============================================================================
# Instantiate new User entity
#===============================================================================
-$User = new User\Entity;
+$User = new ORM\Entities\User;
#===============================================================================
# Check for insert request
diff --git a/core/application.php b/core/application.php
index ecb7947..80952fd 100644
--- a/core/application.php
+++ b/core/application.php
@@ -159,9 +159,9 @@ if(Application::get('CORE.SEND_304') === TRUE AND !defined('ADMINISTRATION')) {
#===========================================================================
$execute = '(SELECT time_update FROM %s ORDER BY time_update DESC LIMIT 1) AS %s';
- $pageTable = Page\Repository::getTableName();
- $postTable = Post\Repository::getTableName();
- $userTable = User\Repository::getTableName();
+ $pageTable = ORM\Repositories\Page::getTableName();
+ $postTable = ORM\Repositories\Post::getTableName();
+ $userTable = ORM\Repositories\User::getTableName();
$pageSQL = sprintf($execute, $pageTable, $pageTable);
$postSQL = sprintf($execute, $postTable, $postTable);
diff --git a/core/functions.php b/core/functions.php
index 55744f1..dadaab8 100644
--- a/core/functions.php
+++ b/core/functions.php
@@ -1,7 +1,9 @@
<?php
-use Page\Entity as Page;
-use Post\Entity as Post;
-use User\Entity as User;
+use ORM\Entities\Page;
+use ORM\Entities\Post;
+use ORM\Entities\User;
+use ORM\EntityInterface;
+
use Template\Template as Template;
use Template\Factory as TemplateFactory;
@@ -114,10 +116,10 @@ function generateItemTemplateData(EntityInterface $Entity): array {
#===============================================================================
function generatePseudoGUID(EntityInterface $Entity) {
switch(get_class($Entity)) {
- case "Page\Entity":
+ case "ORM\Entities\Page":
$attr = Application::get('PAGE.FEED_GUID');
break;
- case "Post\Entity":
+ case "ORM\Entities\Post":
$attr = Application::get('POST.FEED_GUID');
break;
default:
@@ -164,13 +166,13 @@ function parseContentTags(string $text): string {
#===============================================================================
function parseEntityContent(EntityInterface $Entity): string {
switch($class = get_class($Entity)) {
- case 'Page\Entity':
+ case 'ORM\Entities\Page':
$prefix = 'PAGE';
break;
- case 'Post\Entity':
+ case 'ORM\Entities\Post':
$prefix = 'POST';
break;
- case 'User\Entity':
+ case 'ORM\Entities\User':
$prefix = 'USER';
break;
default:
diff --git a/core/namespace/Application.php b/core/namespace/Application.php
index 0d6d30e..2329253 100644
--- a/core/namespace/Application.php
+++ b/core/namespace/Application.php
@@ -1,4 +1,6 @@
<?php
+use ORM\EntityInterface;
+
class Application {
#===============================================================================
@@ -97,9 +99,9 @@ class Application {
#===============================================================================
# Return singleton repository instance
#===============================================================================
- public static function getRepository(string $namespace): Repository {
- $identifier = strtolower($namespace);
- $repository = "$namespace\Repository";
+ public static function getRepository(string $entity): ORM\Repository {
+ $identifier = strtolower($entity);
+ $repository = "ORM\Repositories\\$entity";
if(!isset(self::$repositories[$identifier])) {
$Repository = new $repository(self::getDatabase());
@@ -186,13 +188,13 @@ class Application {
#===============================================================================
public static function getEntityURL(EntityInterface $Entity) {
switch($class = get_class($Entity)) {
- case 'Page\Entity':
+ case 'ORM\Entities\Page':
$attr = self::get('PAGE.SLUG_URLS') ? 'slug' : 'id';
return self::getPageURL($Entity->get($attr).'/');
- case 'Post\Entity':
+ case 'ORM\Entities\Post':
$attr = self::get('POST.SLUG_URLS') ? 'slug' : 'id';
return self::getPostURL($Entity->get($attr).'/');
- case 'User\Entity':
+ case 'ORM\Entities\User':
$attr = self::get('USER.SLUG_URLS') ? 'slug' : 'id';
return self::getUserURL($Entity->get($attr).'/');
default:
diff --git a/core/namespace/Page/Entity.php b/core/namespace/ORM/Entities/Page.php
index 6ca5979..94e5ff5 100644
--- a/core/namespace/Page/Entity.php
+++ b/core/namespace/ORM/Entities/Page.php
@@ -1,7 +1,8 @@
<?php
-namespace Page;
+namespace ORM\Entities;
+use ORM\Entity;
-class Entity extends \Entity {
+class Page extends Entity {
protected $id = FALSE;
protected $user = FALSE;
protected $slug = FALSE;
diff --git a/core/namespace/Post/Entity.php b/core/namespace/ORM/Entities/Post.php
index 399f5bb..e6bff36 100644
--- a/core/namespace/Post/Entity.php
+++ b/core/namespace/ORM/Entities/Post.php
@@ -1,7 +1,8 @@
<?php
-namespace Post;
+namespace ORM\Entities;
+use ORM\Entity;
-class Entity extends \Entity {
+class Post extends Entity {
protected $id = FALSE;
protected $user = FALSE;
protected $slug = FALSE;
diff --git a/core/namespace/User/Entity.php b/core/namespace/ORM/Entities/User.php
index fdfaf9e..f0c9a1f 100644
--- a/core/namespace/User/Entity.php
+++ b/core/namespace/ORM/Entities/User.php
@@ -1,7 +1,8 @@
<?php
-namespace User;
+namespace ORM\Entities;
+use ORM\Entity;
-class Entity extends \Entity {
+class User extends Entity {
protected $id = FALSE;
protected $slug = FALSE;
protected $username = FALSE;
diff --git a/core/namespace/Entity.php b/core/namespace/ORM/Entity.php
index 4bedd37..9cc7755 100644
--- a/core/namespace/Entity.php
+++ b/core/namespace/ORM/Entity.php
@@ -1,4 +1,6 @@
<?php
+namespace ORM;
+
abstract class Entity implements EntityInterface {
protected $id;
protected $time_insert;
diff --git a/core/namespace/EntityInterface.php b/core/namespace/ORM/EntityInterface.php
index 8eaa089..68c9588 100644
--- a/core/namespace/EntityInterface.php
+++ b/core/namespace/ORM/EntityInterface.php
@@ -1,4 +1,6 @@
<?php
+namespace ORM;
+
interface EntityInterface {
public function get(string $attribute);
public function set(string $attribute, $value);
diff --git a/core/namespace/Page/Repository.php b/core/namespace/ORM/Repositories/Page.php
index b76ef85..595b420 100644
--- a/core/namespace/Page/Repository.php
+++ b/core/namespace/ORM/Repositories/Page.php
@@ -1,11 +1,13 @@
<?php
-namespace Page;
+namespace ORM\Repositories;
+use ORM\Repository;
+use ORM\Entities\User;
-class Repository extends \Repository {
+class Page extends Repository {
public static function getTableName(): string { return 'page'; }
- public static function getClassName(): string { return 'Page\Entity'; }
+ public static function getClassName(): string { return 'ORM\Entities\Page'; }
- public function getCountByUser(\User\Entity $User): int {
+ public function getCountByUser(User $User): int {
$query = 'SELECT COUNT(id) FROM %s WHERE user = ?';
$query = sprintf($query, static::getTableName());
diff --git a/core/namespace/Post/Repository.php b/core/namespace/ORM/Repositories/Post.php
index 5a3d834..8eac12f 100644
--- a/core/namespace/Post/Repository.php
+++ b/core/namespace/ORM/Repositories/Post.php
@@ -1,11 +1,13 @@
<?php
-namespace Post;
+namespace ORM\Repositories;
+use ORM\Repository;
+use ORM\Entities\User;
-class Repository extends \Repository {
+class Post extends Repository {
public static function getTableName(): string { return 'post'; }
- public static function getClassName(): string { return 'Post\Entity'; }
+ public static function getClassName(): string { return 'ORM\Entities\Post'; }
- public function getCountByUser(\User\Entity $User): int {
+ public function getCountByUser(User $User): int {
$query = 'SELECT COUNT(id) FROM %s WHERE user = ?';
$query = sprintf($query, static::getTableName());
diff --git a/core/namespace/ORM/Repositories/User.php b/core/namespace/ORM/Repositories/User.php
new file mode 100644
index 0000000..629d9c1
--- /dev/null
+++ b/core/namespace/ORM/Repositories/User.php
@@ -0,0 +1,8 @@
+<?php
+namespace ORM\Repositories;
+use ORM\Repository;
+
+class User extends Repository {
+ public static function getTableName(): string { return 'user'; }
+ public static function getClassName(): string { return 'ORM\Entities\User'; }
+}
diff --git a/core/namespace/Repository.php b/core/namespace/ORM/Repository.php
index e2b42a7..507605c 100644
--- a/core/namespace/Repository.php
+++ b/core/namespace/ORM/Repository.php
@@ -1,4 +1,7 @@
<?php
+namespace ORM;
+use Database;
+
abstract class Repository {
protected $Database;
protected $entities = [];
diff --git a/core/namespace/User/Repository.php b/core/namespace/User/Repository.php
deleted file mode 100644
index 59205b3..0000000
--- a/core/namespace/User/Repository.php
+++ /dev/null
@@ -1,7 +0,0 @@
-<?php
-namespace User;
-
-class Repository extends \Repository {
- public static function getTableName(): string { return 'user'; }
- public static function getClassName(): string { return 'User\Entity'; }
-}