From 85a869287d85a0cce64ef2adbd915fb975f0a414 Mon Sep 17 00:00:00 2001 From: Don Gilbert Date: Sun, 17 Mar 2013 13:07:29 -0500 Subject: [PATCH] Cleaning up the JMediawiki::__get() method --- libraries/joomla/mediawiki/mediawiki.php | 81 ++++++------------------ 1 file changed, 18 insertions(+), 63 deletions(-) diff --git a/libraries/joomla/mediawiki/mediawiki.php b/libraries/joomla/mediawiki/mediawiki.php index 803996b109..a918a58ea9 100644 --- a/libraries/joomla/mediawiki/mediawiki.php +++ b/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)); } /**