aboutsummaryrefslogtreecommitdiffstats
path: root/core/namespace
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 /core/namespace
parent366d0de19c012821ef587d5fdb9557c339b43303 (diff)
downloadblog-a86bdc6b5bab78b4026f44161413f4e482df42e4.tar.gz
blog-a86bdc6b5bab78b4026f44161413f4e482df42e4.tar.xz
blog-a86bdc6b5bab78b4026f44161413f4e482df42e4.zip
Reorganize namespaces
Diffstat (limited to 'core/namespace')
-rw-r--r--core/namespace/Application.php14
-rw-r--r--core/namespace/ORM/Entities/Page.php (renamed from core/namespace/Post/Entity.php)5
-rw-r--r--core/namespace/ORM/Entities/Post.php (renamed from core/namespace/Page/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
11 files changed, 44 insertions, 27 deletions
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/Post/Entity.php b/core/namespace/ORM/Entities/Page.php
index 399f5bb..94e5ff5 100644
--- a/core/namespace/Post/Entity.php
+++ b/core/namespace/ORM/Entities/Page.php
@@ -1,7 +1,8 @@
<?php
-namespace Post;
+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/Page/Entity.php b/core/namespace/ORM/Entities/Post.php
index 6ca5979..e6bff36 100644
--- a/core/namespace/Page/Entity.php
+++ b/core/namespace/ORM/Entities/Post.php
@@ -1,7 +1,8 @@
<?php
-namespace Page;
+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'; }
-}