diff options
author | Thomas Lange <code@nerdmind.de> | 2021-06-21 01:55:47 +0200 |
---|---|---|
committer | Thomas Lange <code@nerdmind.de> | 2021-06-21 01:55:47 +0200 |
commit | 466420be275aeb0af1abd34639e5a570db50313f (patch) | |
tree | 5ea8d1cbed872f7540848cdd41b53990f9cbc695 /core | |
parent | 8355f85e0a1e22f64248919a5759458ba897f0ee (diff) | |
download | blog-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.php | 20 |
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 { |