aboutsummaryrefslogtreecommitdiffstats
path: root/core/namespace
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2021-07-22 14:00:12 +0200
committerThomas Lange <code@nerdmind.de>2021-07-22 14:00:12 +0200
commit59392e460020447720089976b83139ad59d275fe (patch)
tree25cc766f352d9ae6319d22d43388db563d6ba404 /core/namespace
parent912a19ef8c58b87ac075d21cee0425f7715b4f94 (diff)
downloadblog-59392e460020447720089976b83139ad59d275fe.tar.gz
blog-59392e460020447720089976b83139ad59d275fe.tar.xz
blog-59392e460020447720089976b83139ad59d275fe.zip
Rename: Append "Repository" to repository classes
Rename the repository classes and append the name with "Repository" to prevent naming confusions with the entity classes.
Diffstat (limited to 'core/namespace')
-rw-r--r--core/namespace/Application.php4
-rw-r--r--core/namespace/ORM/Repositories/CategoryRepository.php (renamed from core/namespace/ORM/Repositories/Category.php)10
-rw-r--r--core/namespace/ORM/Repositories/PageRepository.php (renamed from core/namespace/ORM/Repositories/Page.php)3
-rw-r--r--core/namespace/ORM/Repositories/PostRepository.php (renamed from core/namespace/ORM/Repositories/Post.php)4
-rw-r--r--core/namespace/ORM/Repositories/UserRepository.php (renamed from core/namespace/ORM/Repositories/User.php)12
5 files changed, 15 insertions, 18 deletions
diff --git a/core/namespace/Application.php b/core/namespace/Application.php
index 140baac..93361dd 100644
--- a/core/namespace/Application.php
+++ b/core/namespace/Application.php
@@ -102,10 +102,10 @@ class Application {
#===============================================================================
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());
+ $className = sprintf('ORM\Repositories\%sRepository', $entity);
+ $Repository = new $className(self::getDatabase());
self::$repositories[$identifier] = $Repository;
}
diff --git a/core/namespace/ORM/Repositories/Category.php b/core/namespace/ORM/Repositories/CategoryRepository.php
index df32f69..b62485a 100644
--- a/core/namespace/ORM/Repositories/Category.php
+++ b/core/namespace/ORM/Repositories/CategoryRepository.php
@@ -2,18 +2,18 @@
namespace ORM\Repositories;
use ORM\Repository;
use ORM\EntityInterface;
-use ORM\Entities\Category as CategoryEntity;
+use ORM\Entities\Category;
-class Category extends Repository {
+class CategoryRepository extends Repository {
public static function getTableName(): string { return 'category'; }
public static function getClassName(): string { return 'ORM\Entities\Category'; }
#===============================================================================
# Get number of *posts* assigned to $Category
#===============================================================================
- public function getNumberOfPosts(CategoryEntity $Category): int {
+ public function getNumberOfPosts(Category $Category): int {
$query = 'SELECT COUNT(id) FROM %s WHERE category = ?';
- $query = sprintf($query, Post::getTableName());
+ $query = sprintf($query, PostRepository::getTableName());
$Statement = $this->Database->prepare($query);
$Statement->execute([$Category->getID()]);
@@ -75,7 +75,7 @@ class Category extends Repository {
#===============================================================================
# Get number of children categories assigned to $Category
#===============================================================================
- public function getNumberOfChildren(CategoryEntity $Category): int {
+ public function getNumberOfChildren(Category $Category): int {
$query = 'WITH RECURSIVE tree AS (
SELECT * FROM %s WHERE id = ? UNION
SELECT c.* FROM %s c, tree WHERE tree.id = c.parent
diff --git a/core/namespace/ORM/Repositories/Page.php b/core/namespace/ORM/Repositories/PageRepository.php
index 714605e..8c7c94b 100644
--- a/core/namespace/ORM/Repositories/Page.php
+++ b/core/namespace/ORM/Repositories/PageRepository.php
@@ -1,9 +1,8 @@
<?php
namespace ORM\Repositories;
use ORM\Repository;
-use ORM\Entities\User;
-class Page extends Repository {
+class PageRepository extends Repository {
public static function getTableName(): string { return 'page'; }
public static function getClassName(): string { return 'ORM\Entities\Page'; }
}
diff --git a/core/namespace/ORM/Repositories/Post.php b/core/namespace/ORM/Repositories/PostRepository.php
index 7f672e5..400d596 100644
--- a/core/namespace/ORM/Repositories/Post.php
+++ b/core/namespace/ORM/Repositories/PostRepository.php
@@ -1,10 +1,8 @@
<?php
namespace ORM\Repositories;
use ORM\Repository;
-use ORM\Entities\User;
-use ORM\Entities\Category;
-class Post extends Repository {
+class PostRepository extends Repository {
public static function getTableName(): string { return 'post'; }
public static function getClassName(): string { return 'ORM\Entities\Post'; }
}
diff --git a/core/namespace/ORM/Repositories/User.php b/core/namespace/ORM/Repositories/UserRepository.php
index ce3ff2c..a0e58c6 100644
--- a/core/namespace/ORM/Repositories/User.php
+++ b/core/namespace/ORM/Repositories/UserRepository.php
@@ -1,18 +1,18 @@
<?php
namespace ORM\Repositories;
use ORM\Repository;
-use ORM\Entities\User as UserEntity;
+use ORM\Entities\User;
-class User extends Repository {
+class UserRepository extends Repository {
public static function getTableName(): string { return 'user'; }
public static function getClassName(): string { return 'ORM\Entities\User'; }
#===============================================================================
# Get number of *pages* assigned to $User
#===============================================================================
- public function getNumberOfPages(UserEntity $User): int {
+ public function getNumberOfPages(User $User): int {
$query = 'SELECT COUNT(id) FROM %s WHERE user = ?';
- $query = sprintf($query, Page::getTableName());
+ $query = sprintf($query, PageRepository::getTableName());
$Statement = $this->Database->prepare($query);
$Statement->execute([$User->getID()]);
@@ -23,9 +23,9 @@ class User extends Repository {
#===============================================================================
# Get number of *posts* assigned to $User
#===============================================================================
- public function getNumberOfPosts(UserEntity $User): int {
+ public function getNumberOfPosts(User $User): int {
$query = 'SELECT COUNT(id) FROM %s WHERE user = ?';
- $query = sprintf($query, Post::getTableName());
+ $query = sprintf($query, PostRepository::getTableName());
$Statement = $this->Database->prepare($query);
$Statement->execute([$User->getID()]);