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