aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2021-06-21 01:55:47 +0200
committerThomas Lange <code@nerdmind.de>2021-06-21 01:55:47 +0200
commit466420be275aeb0af1abd34639e5a570db50313f (patch)
tree5ea8d1cbed872f7540848cdd41b53990f9cbc695 /core
parent8355f85e0a1e22f64248919a5759458ba897f0ee (diff)
downloadblog-466420be275aeb0af1abd34639e5a570db50313f.tar.gz
blog-466420be275aeb0af1abd34639e5a570db50313f.tar.xz
blog-466420be275aeb0af1abd34639e5a570db50313f.zip
Add method getEntityURL to Application class
This commit adds the method "getEntityURL" to the "Application" class. This method takes an instance of "Item" as parameter and then builds the absolute URL of the item from its attribute data.
Diffstat (limited to 'core')
-rw-r--r--core/namespace/Application.php20
1 files changed, 20 insertions, 0 deletions
diff --git a/core/namespace/Application.php b/core/namespace/Application.php
index 6a77865..4414665 100644
--- a/core/namespace/Application.php
+++ b/core/namespace/Application.php
@@ -140,6 +140,26 @@ class Application {
}
#===============================================================================
+ # Return absolute URL of a specifc entity
+ #===============================================================================
+ public function getEntityURL(Item $Entity) {
+ switch($class = get_class($Entity)) {
+ case 'Page\Item':
+ $attr = self::get('PAGE.SLUG_URLS') ? 'slug' : 'id';
+ return self::getPageURL($Entity->attr($attr).'/');
+ case 'Post\Item':
+ $attr = self::get('POST.SLUG_URLS') ? 'slug' : 'id';
+ return self::getPostURL($Entity->attr($attr).'/');
+ case 'User\Item':
+ $attr = self::get('USER.SLUG_URLS') ? 'slug' : 'id';
+ return self::getUserURL($Entity->attr($attr).'/');
+ default:
+ $error = 'Unknown URL handler for <code>%s</code> entities.';
+ throw new Exception(sprintf($error, $class));
+ }
+ }
+
+ #===============================================================================
# Exit application with a custom message and status code
#===============================================================================
public static function exit($message = '', $code = 503): void {