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