400513398049815624d24050fd3687b05f915b33
[core.git] / inc / main / classes / factories / html / class_HtmlNewsFactory.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Factory\News;
4
5 // Import framework stuff
6 use CoreFramework\Factory\ObjectFactory;
7
8 /**
9  * A news factory for web pages
10  *
11  * @author              Roland Haeder <webmaster@shipsimu.org>
12  * @version             0.0.0
13  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
14  * @license             GNU GPL 3.0 or any newer version
15  * @link                http://www.shipsimu.org
16  *
17  * This program is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program. If not, see <http://www.gnu.org/licenses/>.
29  */
30 class HtmlNewsFactory extends BaseFactory {
31         /**
32          * Instance of a request class
33          */
34         private $requestInstance = NULL;
35
36         /**
37          * Protected constructor
38          *
39          * @return      void
40          */
41         protected function __construct () {
42                 // Call parent constructor
43                 parent::__construct(__CLASS__);
44         }
45
46         /**
47          * Singleton getter for a special factory instance depending on the given
48          * request
49          *
50          * @param       $requestInstance        An instance of a request class
51          * @return      $factoryInstance        An instance of a HtmlNewsFactory class
52          */
53         public static final function createFactoryByRequest (Requestable $requestInstance) {
54                 // Set default news reader class
55                 $configEntry = 'news_reader_class';
56
57                 // Get "page"
58                 $command = $requestInstance->getRequestElement('command');
59
60                 // Is 'command' used?
61                 if (!empty($command)) {
62                         // Then add it
63                         $configEntry = sprintf('news_reader_%s_class', $command);
64
65                         // Get 'action'
66                         $action = $requestInstance->getRequestElement('action');
67
68                         // Is it also there?
69                         if (!empty($action)) {
70                                 // Then use both for config entry
71                                 $configEntry = sprintf('news_reader_%s_%s_class', $command, $action);
72                         } // END - if
73                 } // END - if
74
75                 // Get the news reader class name from config
76                 $className = $requestInstance->getConfigInstance()->getConfigEntry($configEntry);
77
78                 // Once we have that name, try to load initialize it
79                 $newsInstance = ObjectFactory::createObjectByName($className, array($requestInstance));
80
81                 // Initialize the reader
82                 $newsInstance->initializeReader();
83
84                 // Return the prepared factory instance
85                 return $newsInstance;
86         }
87
88 }