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