Skip to content

Commit

Permalink
Introduce new method isClient($identifier) in JApplicationCms class a…
Browse files Browse the repository at this point in the history
…s 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.
  • Loading branch information
izharaazmi committed Jan 23, 2016
1 parent d29c547 commit 674feda
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
22 changes: 20 additions & 2 deletions libraries/cms/application/cms.php
Expand Up @@ -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');
}

/**
Expand All @@ -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;
}

/**
Expand Down
24 changes: 20 additions & 4 deletions libraries/legacy/application/application.php
Expand Up @@ -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');
}

/**
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit 674feda

Please sign in to comment.