From 674feda4a02d437dd835e2069f96e3b1c8a42be5 Mon Sep 17 00:00:00 2001 From: Izhar Aazmi Date: Sat, 23 Jan 2016 17:28:28 +0530 Subject: [PATCH] Introduce new method isClient($identifier) in JApplicationCms class as a substitute for isSite and isAdmin methods. Hence, remove usage of descendant class reference in the JApplication (legacy) and JApplicationCms for better OO structure and support more extensibility. --- libraries/cms/application/cms.php | 22 ++++++++++++++++-- libraries/legacy/application/application.php | 24 ++++++++++++++++---- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/libraries/cms/application/cms.php b/libraries/cms/application/cms.php index ad46c24904b5..61d2a5de9536 100644 --- a/libraries/cms/application/cms.php +++ b/libraries/cms/application/cms.php @@ -669,10 +669,11 @@ protected function initialiseApp($options = array()) * @return boolean True if this application is administrator. * * @since 3.2 + * @deprecated Use isClient('administrator') or isClient(1) instead. */ public function isAdmin() { - return ($this->getClientId() === 1); + return $this->isClient('administrator'); } /** @@ -681,10 +682,27 @@ public function isAdmin() * @return boolean True if this application is site. * * @since 3.2 + * @deprecated Use isClient('site') or isClient(0) instead. */ public function isSite() { - return ($this->getClientId() === 0); + return $this->isClient('site'); + } + + /** + * Check the client interface by name or client id. + * + * @param string|int $identifier Numeric or string identifier for the application interface + * + * @return boolean True if this application is of the given type client interface. + * + * @since __DEPLOY_VERSION__ + */ + public function isClient($identifier) + { + $match = is_numeric($identifier) ? $this->getClientId() : $this->getName(); + + return $match == $identifier; } /** diff --git a/libraries/legacy/application/application.php b/libraries/legacy/application/application.php index 14940278a861..679aec7a6ab8 100644 --- a/libraries/legacy/application/application.php +++ b/libraries/legacy/application/application.php @@ -1123,11 +1123,11 @@ public function getClientId() * @return boolean True if this application is administrator. * * @since 11.1 - * @deprecated 4.0 + * @deprecated 4.0 Use isClient('administrator') or isClient(1) instead. */ public function isAdmin() { - return ($this->_clientId == 1); + return $this->isClient('administrator'); } /** @@ -1136,11 +1136,27 @@ public function isAdmin() * @return boolean True if this application is site. * * @since 11.1 - * @deprecated 4.0 + * @deprecated 4.0 Use isClient('site') or isClient(0) instead. */ public function isSite() { - return ($this->_clientId == 0); + return $this->isClient('site'); + } + + /** + * Check the client interface by name or client id. + * + * @param string|int $identifier Numeric or string identifier for the application interface + * + * @return boolean True if this application is of the given type client interface. + * + * @since __DEPLOY_VERSION__ + */ + public function isClient($identifier) + { + $match = is_numeric($identifier) ? $this->getClientId() : $this->getName(); + + return $match == $identifier; } /**