Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleaning up the JMediawiki::__get() method

  • Loading branch information...
commit 85a869287d85a0cce64ef2adbd915fb975f0a414 1 parent 71f3311
@dongilbert dongilbert authored
Showing with 18 additions and 63 deletions.
  1. +18 −63 libraries/joomla/mediawiki/mediawiki.php
View
81 libraries/joomla/mediawiki/mediawiki.php
@@ -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));
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.