3 namespace Org\Mxchange\CoreFramework\Filter\Discovery\Payment;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Action\PerformableAction;
7 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
8 use Org\Mxchange\CoreFramework\Filter\BaseFilter;
9 use Org\Mxchange\CoreFramework\Filter\Chain\FilterChainException;
10 use Org\Mxchange\CoreFramework\Filter\Filterable;
11 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
12 use Org\Mxchange\CoreFramework\Loader\NoClassException;
13 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
14 use Org\Mxchange\CoreFramework\Request\Requestable;
15 use Org\Mxchange\CoreFramework\Response\Responseable;
18 * A filter for payment discovery. This class discovers the payment type and
19 * returns an object holding all available payment system for the requested
22 * @author Roland Haeder <webmaster@shipsimu.org>
24 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
25 * @license GNU GPL 3.0 or any newer version
26 * @link http://www.shipsimu.org
28 * This program is free software: you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation, either version 3 of the License, or
31 * (at your option) any later version.
33 * This program is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details.
38 * You should have received a copy of the GNU General Public License
39 * along with this program. If not, see <http://www.gnu.org/licenses/>.
41 class PaymentDiscoveryFilter extends BaseFilter implements Filterable {
43 * Action name for payment discovery
45 private $actionName = '';
48 * Protected constructor
52 protected function __construct () {
53 // Call parent constructor
54 parent::__construct(__CLASS__);
58 * Creates an instance of this filter class
60 * @param $actionInstance A performable action
61 * @return $filterInstance An instance of this filter class
62 * @throws NullPointerException If the resolver is not set
64 public static final function createPaymentDiscoveryFilter (PerformableAction $actionInstance) {
66 $filterInstance = new PaymentDiscoveryFilter();
68 // Get resolver from action
69 $resolverInstance = $actionInstance->getResolverInstance();
71 // Is the resolver set?
72 if (is_null($resolverInstance)) {
73 // Throw an exception here
74 throw new NullPointerException($filterInstance, self::EXCEPTION_IS_NULL_POINTER);
77 // Get the action name from resolver
78 $actionName = $resolverInstance->getActionName();
80 // Store it away in this class
81 $filterInstance->setActionName($actionName);
83 // Return the instance
84 return $filterInstance;
88 * Protected setter for action name
90 * @param $actionName Action name to set
93 protected final function setActionName ($actionName) {
94 $this->actionName = (string) $actionName;
98 * Getter for action name
100 * @return $actionName Action name to set
102 public final function getActionName () {
103 return $this->actionName;
107 * Executes the filter with given request and response objects
109 * @param $requestInstance An instance of a class with an Requestable interface
110 * @param $responseInstance An instance of a class with an Responseable interface
113 * @throws FilterChainException If this filter fails to operate
115 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
116 // Try to get real discovery class
118 // Get an instance from the object factory
119 $discoveryInstance = ObjectFactory::createObjectByConfiguredName($this->getActionName() . '_payment_discovery', array($this));
121 // Call the discovery method
122 $discoveryInstance->discover($requestInstance);
124 // Remember this instance if all wents fine
125 GenericRegistry::getRegistry()->addInstance('payments', $discoveryInstance);
126 } catch (NoConfigEntryException $e) {
127 // Something bad happend
128 $requestInstance->requestIsValid(false);
130 // Add a message to the response
131 $responseInstance->addFatalMessage('payment_config_entry_error');
132 $responseInstance->addFatalMessagePlain($e->getMessage());
135 throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
136 } catch (NoClassException $e) {
137 // Something bad happend
138 $requestInstance->requestIsValid(false);
140 // Add a message to the response
141 $responseInstance->addFatalMessage('payment_class_error');
142 $responseInstance->addFatalMessagePlain($e->getMessage());
145 throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);