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