Skip to content
This repository has been archived by the owner on Nov 26, 2017. It is now read-only.

Commit

Permalink
Cleaning up the JMediawiki::__get() method
Browse files Browse the repository at this point in the history
  • Loading branch information
dongilbert committed Mar 17, 2013
1 parent 71f3311 commit 85a8692
Showing 1 changed file with 18 additions and 63 deletions.
81 changes: 18 additions & 63 deletions libraries/joomla/mediawiki/mediawiki.php
Expand Up @@ -102,78 +102,33 @@ public function __construct(JRegistry $options = null, JMediawikiHttp $client =
* @return JMediaWikiObject MediaWiki API object (users, reviews, etc).
*
* @since 12.3
* @throws InvalidArgumentException
*/
public function __get($name)
{
if ($name == 'sites')
$name = strtolower($name);
$class = 'JMediawiki' . ucfirst($name);
$accessible = array(
'categories',
'images',
'links',
'pages',
'search',
'sites',
'users'
);

if (class_exists($class) && in_array($name, $accessible))
{
if ($this->sites == null)
if (!isset($this->$name))
{
$this->sites = new JMediawikiSites($this->options, $this->client);
}
return $this->sites;
}

if ($name == 'pages')
{
if ($this->pages == null)
{
$this->pages = new JMediawikiPages($this->options, $this->client);
}

return $this->pages;
}

if ($name == 'users')
{
if ($this->users == null)
{
$this->users = new JMediawikiUsers($this->options, $this->client);
}

return $this->users;
}

if ($name == 'links')
{
if ($this->links == null)
{
$this->links = new JMediawikiLinks($this->options, $this->client);
}

return $this->links;
}

if ($name == 'categories')
{
if ($this->categories == null)
{
$this->categories = new JMediawikiCategories($this->options, $this->client);
}

return $this->categories;
}

if ($name == 'images')
{
if ($this->images == null)
{
$this->images = new JMediawikiImages($this->options, $this->client);
}

return $this->images;
}

if ($name == 'search')
{
if ($this->search == null)
{
$this->search = new JMediawikiSearch($this->options, $this->client);
$this->$name = new $class($this->options, $this->client);
}

return $this->search;
return $this->$name;
}

throw new InvalidArgumentException(sprintf('Property %s is not accessible.', $name));
}

/**
Expand Down

0 comments on commit 85a8692

Please sign in to comment.