From 7afd0daf3f2cbd4f0fa6201cc01579f050b03e75 Mon Sep 17 00:00:00 2001 From: Matan Bareket Date: Mon, 21 Jan 2019 08:40:43 -0500 Subject: [PATCH] WEB: Use OO for objects --- include/Objects/Article.php | 8 +------ include/Objects/BasicObject.php | 19 +++++++++++++++++ include/Objects/CSection.php | 20 ++---------------- include/Objects/CompatGame.php | 8 +------ include/Objects/DSection.php | 19 ++--------------- include/Objects/Document.php | 16 +------------- include/Objects/File.php | 8 +------ include/Objects/GameDemo.php | 8 +------ include/Objects/MenuItem.php | 8 +------ include/Objects/Person.php | 21 +++---------------- include/Objects/Section.php | 37 +++++++++++++++++++++++++++++++++ include/Objects/WebLink.php | 17 +-------------- 12 files changed, 70 insertions(+), 119 deletions(-) create mode 100644 include/Objects/Section.php diff --git a/include/Objects/Article.php b/include/Objects/Article.php index 9aef3276..beeec142 100644 --- a/include/Objects/Article.php +++ b/include/Objects/Article.php @@ -14,18 +14,12 @@ class Article extends BasicObject /* Article object constructor. */ public function __construct($data) { - $this->name = $data['name']; + parent::__construct($data); $this->url = $data['url']; $this->language = $data['language']; $this->posted = $data['posted']; } - /* Get the name. */ - public function getName() - { - return $this->name; - } - /* Get the URL. */ public function getURL() { diff --git a/include/Objects/BasicObject.php b/include/Objects/BasicObject.php index e207226a..b5e40774 100644 --- a/include/Objects/BasicObject.php +++ b/include/Objects/BasicObject.php @@ -8,6 +8,25 @@ namespace ScummVM\Objects; abstract class BasicObject { protected $name; + protected $description; + + public function __construct($data) + { + $this->description = $data['description']; + $this->name = $data['name']; + } + + /* Get the name. */ + public function getName() + { + return $this->name; + } + + public function getDescription() + { + return $this->description; + } + /** * If the input array doesn't contain the numerical key 0, wrap it inside * an array. This functions operates on the data directly. diff --git a/include/Objects/CSection.php b/include/Objects/CSection.php index 59203f8f..7e7f666b 100644 --- a/include/Objects/CSection.php +++ b/include/Objects/CSection.php @@ -5,19 +5,15 @@ namespace ScummVM\Objects; * The Section class represens a section (or a subsection) on the credits page * on the website. */ -class CSection extends BasicObject +class CSection extends Section { - private $title; private $groups; - private $subsections; private $paragraphs; - private $anchor; /* CSection object constructor. */ public function __construct($data) { - $this->title = $data['title']; - $this->anchor = $data['anchor']; + parent::__construct($data); $this->groups = array(); $this->subsections = array(); $this->paragraphs = array(); @@ -53,18 +49,6 @@ class CSection extends BasicObject } } - /* Get the title. */ - public function getTitle() - { - return $this->title; - } - - /* Get the anchor. */ - public function getAnchor() - { - return $this->anchor; - } - /* Get the optional list of groups. */ public function getGroups() { diff --git a/include/Objects/CompatGame.php b/include/Objects/CompatGame.php index 71fd0bd7..1b251ccf 100644 --- a/include/Objects/CompatGame.php +++ b/include/Objects/CompatGame.php @@ -14,7 +14,7 @@ class CompatGame extends BasicObject /* Project object constructor. */ public function __construct($data) { - $this->name = $data['name']; + parent::__construct($data); $this->target = $data['target']; // In old compat pages we used 'percent' instead of 'support_level'. // we still want to support those thus we check whether the old tag @@ -27,12 +27,6 @@ class CompatGame extends BasicObject $this->notes = $data['notes']; } - /* Get the name. */ - public function getName() - { - return $this->name; - } - /* Get the target name. */ public function getTarget() { diff --git a/include/Objects/DSection.php b/include/Objects/DSection.php index 1d16072f..5780dfa1 100644 --- a/include/Objects/DSection.php +++ b/include/Objects/DSection.php @@ -4,19 +4,15 @@ namespace ScummVM\Objects; /** * The DSection object represents a section on the downloads page. */ -class DSection extends BasicObject +class DSection extends Section { - private $title; - private $anchor; private $baseurl; private $baseturl; - private $subsections; /* DSection object constructor. */ public function __construct($data) { - $this->title = $data['title']; - $this->anchor = $data['anchor']; + parent::__construct($data); $this->baseurl = $data['baseurl']; $this->baseturl = $data['baseturl']; $this->subsections = array(); @@ -27,17 +23,6 @@ class DSection extends BasicObject } } - /* Get the title. */ - public function getTitle() - { - return $this->title; - } - - /* Get the anchor name. */ - public function getAnchor() - { - return $this->anchor; - } /* Get the base URL. */ public function getBaseURL() diff --git a/include/Objects/Document.php b/include/Objects/Document.php index 37db5022..eda85038 100644 --- a/include/Objects/Document.php +++ b/include/Objects/Document.php @@ -7,20 +7,12 @@ namespace ScummVM\Objects; class Document extends BasicObject { private $url; - private $description; /* Document object constructor. */ public function __construct($data) { - $this->name = $data['name']; + parent::__construct($data); $this->url = $data['url']; - $this->description = $data['description']; - } - - /* Get the name. */ - public function getName() - { - return $this->name; } /* Get the URL. */ @@ -28,10 +20,4 @@ class Document extends BasicObject { return $this->url; } - - /* Get the description. */ - public function getDescription() - { - return $this->description; - } } diff --git a/include/Objects/File.php b/include/Objects/File.php index 6b91c70a..f68197ee 100644 --- a/include/Objects/File.php +++ b/include/Objects/File.php @@ -15,8 +15,8 @@ class File extends BasicObject public function __construct($data, $baseurl = null, $baseturl = null) { + parent::__construct($data); $this->category_icon = $data['category_icon']; - $this->name = $data['name']; $this->extra_info = $data['extra_info']; $this->type = strtolower($data['type']); $this->user_agent = isset($data["user_agent"]) ? $data["user_agent"] : ""; @@ -109,12 +109,6 @@ class File extends BasicObject return $this->_url; } - /* Get the name. */ - public function getName() - { - return $this->name; - } - /* Get the type. */ public function getType() { diff --git a/include/Objects/GameDemo.php b/include/Objects/GameDemo.php index 443b636a..53eb8bf9 100644 --- a/include/Objects/GameDemo.php +++ b/include/Objects/GameDemo.php @@ -14,18 +14,12 @@ class GameDemo extends BasicObject /* GameDemo object constructor. */ public function __construct($data) { - $this->name = $data['name']; + parent::__construct($data); $this->url = $data['url']; $this->target = $data['target']; $this->category = isset($data['category']) ? $data['category'] : $data['target']; } - /* Get the name of the demo. */ - public function getName() - { - return $this->name; - } - /* Get the download URL for the demo. */ public function getURL() { diff --git a/include/Objects/MenuItem.php b/include/Objects/MenuItem.php index 098c4a7e..03e66ad5 100644 --- a/include/Objects/MenuItem.php +++ b/include/Objects/MenuItem.php @@ -13,7 +13,7 @@ class MenuItem extends BasicObject /* Menu object constructor. */ public function __construct($data) { - $this->name = $data['name']; + parent::__construct($data); $this->class = $data['class']; $this->entries = array(); foreach ($data['link'] as $key => $value) { @@ -21,12 +21,6 @@ class MenuItem extends BasicObject } } - /* Get the name. */ - public function getName() - { - return $this->name; - } - /* Get the CSS class. */ public function getClass() { diff --git a/include/Objects/Person.php b/include/Objects/Person.php index 0a6e22df..c35a5781 100644 --- a/include/Objects/Person.php +++ b/include/Objects/Person.php @@ -7,22 +7,13 @@ namespace ScummVM\Objects; */ class Person extends BasicObject { - private $alias; - private $description; /* Person object constructor. */ - public function __construct($args) + public function __construct($data) { - $this->name = $args['name']; - $this->alias = $args['alias']; - $this->description = $args['description']; - } - - /* Get the name. */ - public function getName() - { - return $this->name; + parent::__construct($data); + $this->alias = $data['alias']; } /* Get the alias. */ @@ -30,10 +21,4 @@ class Person extends BasicObject { return $this->alias; } - - /* Get the description. */ - public function getDescription() - { - return $this->description; - } } diff --git a/include/Objects/Section.php b/include/Objects/Section.php new file mode 100644 index 00000000..e475859b --- /dev/null +++ b/include/Objects/Section.php @@ -0,0 +1,37 @@ +title = $data['title']; + $this->anchor = $data['anchor']; + } + + /* Get the title. */ + public function getTitle() + { + return $this->title; + } + + /* Get the anchor. */ + public function getAnchor() + { + return $this->anchor; + } + + /* Get the optional list of subsections. */ + public function getSubSections() + { + return $this->subsections; + } +} diff --git a/include/Objects/WebLink.php b/include/Objects/WebLink.php index 900e04f8..f44d2834 100644 --- a/include/Objects/WebLink.php +++ b/include/Objects/WebLink.php @@ -6,22 +6,13 @@ namespace ScummVM\Objects; */ class WebLink extends BasicObject { - private $url; - private $description; /* WebLink object constructor. */ public function __construct($data) { - $this->name = $data['name']; + parent::__construct($data); $this->url = $data['url']; - $this->description = $data['description']; - } - - /* Get the name of the link. */ - public function getName() - { - return $this->name; } /* Get the URL of the link. */ @@ -30,12 +21,6 @@ class WebLink extends BasicObject return $this->url; } - /* Get the description of the link. */ - public function getDescription() - { - return $this->description; - } - /* Get the user-agent. */ public function getUserAgent() {