5e22439f8dde0ceabce7b5f37c502b13512b3a90
[shipsimu.git] / inc / classes / main / filter / payment / class_PaymentDiscoveryFilter.php
1 <?php
2 /**
3  * A filter for payment discovery. This class discovers the payment type and
4  * returns an object holding all available payment system for the requested
5  * type.
6  *
7  * @author              Roland Haeder <webmaster@ship-simu.org>
8  * @version             0.0.0
9  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, this is free software
10  * @license             GNU GPL 3.0 or any newer version
11  * @link                http://www.ship-simu.org
12  *
13  * This program is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation, either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <http://www.gnu.org/licenses/>.
25  */
26 class PaymentDiscoveryFilter extends BaseFrameworkSystem implements Filterable {
27         /**
28          * Action name for payment discovery
29          */
30         private $actionName = "";
31
32         /**
33          * Protected constructor
34          *
35          * @return      void
36          */
37         protected function __construct () {
38                 // Call parent constructor
39                 parent::__construct(__CLASS__);
40
41                 // Clean up a little
42                 $this->removeNumberFormaters();
43                 $this->removeSystemArray();
44         }
45
46         /**
47          * Creates an instance of this filter class
48          *
49          * @param       $actionInstance         A performable action
50          * @return      $filterInstance         An instance of this filter class
51          * @throws      NullPointerException    If the resolver is not set
52          */
53         public final static function createPaymentDiscoveryFilter (PerformableAction $actionInstance) {
54                 // Get a new instance
55                 $filterInstance = new PaymentDiscoveryFilter();
56
57                 // Get resolver from action
58                 $resolverInstance = $actionInstance->getResolverInstance();
59
60                 // Is the resolver set?
61                 if (is_null($resolverInstance)) {
62                         // Throw an exception here
63                         throw new NullPointerException($filterInstance, self::EXCEPTION_IS_NULL_POINTER);
64                 } // END - if
65
66                 // Get the action name from resolver
67                 $actionName = $resolverInstance->getActionName();
68
69                 // Store it away in this class
70                 $filterInstance->setActionName($actionName);
71
72                 // Return the instance
73                 return $filterInstance;
74         }
75
76         /**
77          * Protected setter for action name
78          *
79          * @param       $actionName             Action name to set
80          * @return      void
81          */
82         protected final function setActionName ($actionName) {
83                 $this->actionName = (string) $actionName;
84         }
85
86         /**
87          * Getter for action name
88          *
89          * @return      $actionName             Action name to set
90          */
91         public final function getActionName () {
92                 return $this->actionName;
93         }
94
95         /**
96          * Executes the filter with given request and response objects
97          *
98          * @param       $requestInstance        An instance of a class with an Requestable interface
99          * @param       $responseInstance       An instance of a class with an Responseable interface
100          * @return      void
101          * @todo        0% done
102          */
103         public function execute (Requestable $requestInstance, Responseable $responseInstance) {
104                 // Try to get real discovery class
105                 try {
106                         // Get an instance from the object factory
107                         $discoveryInstance = ObjectFactory::createObjectByConfiguredName($this->getActionName().'_payment_discovery', array($this));
108
109                         // Call the discovery method
110                         $discoveryInstance->discover($requestInstance);
111
112                         // Remember this instance if all wents fine
113                         Registry::getRegistry()->addInstance('payments', $discoveryInstance);
114                 } catch (FrameworkException $e) {
115                         // Something bad happend
116                         $requestInstance->requestIsValid(false);
117
118                         // Add a message to the response
119                         $responseInstance->addFatalMessage('payment_error');
120                         $responseInstance->addFatalMessagePlain($e->getMessage());
121
122                         // Abort here
123                         return false;
124                 }
125         }
126 }
127
128 // [EOF]
129 ?>