Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce new method isClient($identifier) in JApplicationCms class #8971

Merged
merged 5 commits into from
Oct 1, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions libraries/cms/application/cms.php
Original file line number Diff line number Diff line change
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()
{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently this is using only client_id, therefore I used it and also added support for client_name. Should I now finally drop support for client_id match in my new proposed method?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deprecated 4.0?

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 isset($match) && $match == $identifier;
}

/**
Expand Down
24 changes: 20 additions & 4 deletions libraries/legacy/application/application.php
Original file line number Diff line number Diff line change
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 isset($match) && $match == $identifier;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,22 @@ public function testIsSite()
$this->assertFalse($this->class->isSite());
}

/**
* Tests the JApplicationCms::isClient method.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function testIsClient()
{
$this->assertTrue($this->class->isClient('administrator'));
$this->assertTrue($this->class->isClient(1));

$this->assertFalse($this->class->isClient('site'));
$this->assertFalse($this->class->isClient(0));
}

/**
* Tests the JApplicationCms::render method.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,22 @@ public function testIsSite()
$this->assertFalse($this->class->isSite());
}

/**
* Tests the JApplicationCms::isClient method.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function testIsClient()
{
$this->assertFalse($this->class->isClient('administrator'));
$this->assertFalse($this->class->isClient(1));

$this->assertFalse($this->class->isClient('site'));
$this->assertFalse($this->class->isClient(0));
}

/**
* Tests the JApplicationCms::redirect method.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,22 @@ public function testIsSite()
$this->assertTrue($this->class->isSite());
}

/**
* Tests the JApplicationCms::isClient method.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function testIsClient()
{
$this->assertFalse($this->class->isClient('administrator'));
$this->assertFalse($this->class->isClient(1));

$this->assertTrue($this->class->isClient('site'));
$this->assertTrue($this->class->isClient(0));
}

/**
* Tests the JApplicationCms::render method.
*
Expand Down