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\Filterable;
10 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
11 use Org\Mxchange\CoreFramework\Loader\NoClassException;
12 use Org\Mxchange\CoreFramework\Registry\Registry;
13 use Org\Mxchange\CoreFramework\Request\Requestable;
14 use Org\Mxchange\CoreFramework\Response\Responseable;
17 * A filter for payment discovery. This class discovers the payment type and
18 * returns an object holding all available payment system for the requested
21 * @author Roland Haeder <webmaster@shipsimu.org>
23 <<<<<<< HEAD:framework/main/classes/filter/payment/class_PaymentDiscoveryFilter.php
24 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
26 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
27 >>>>>>> Some updates::inc/main/classes/filter/payment/class_PaymentDiscoveryFilter.php
28 * @license GNU GPL 3.0 or any newer version
29 * @link http://www.shipsimu.org
31 * This program is free software: you can redistribute it and/or modify
32 * it under the terms of the GNU General Public License as published by
33 * the Free Software Foundation, either version 3 of the License, or
34 * (at your option) any later version.
36 * This program is distributed in the hope that it will be useful,
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 * GNU General Public License for more details.
41 * You should have received a copy of the GNU General Public License
42 * along with this program. If not, see <http://www.gnu.org/licenses/>.
44 class PaymentDiscoveryFilter extends BaseFilter implements Filterable {
46 * Action name for payment discovery
48 private $actionName = '';
51 * Protected constructor
55 protected function __construct () {
56 // Call parent constructor
57 parent::__construct(__CLASS__);
61 * Creates an instance of this filter class
63 * @param $actionInstance A performable action
64 * @return $filterInstance An instance of this filter class
65 * @throws NullPointerException If the resolver is not set
67 public static final function createPaymentDiscoveryFilter (PerformableAction $actionInstance) {
69 $filterInstance = new PaymentDiscoveryFilter();
71 // Get resolver from action
72 $resolverInstance = $actionInstance->getResolverInstance();
74 // Is the resolver set?
75 if (is_null($resolverInstance)) {
76 // Throw an exception here
77 throw new NullPointerException($filterInstance, self::EXCEPTION_IS_NULL_POINTER);
80 // Get the action name from resolver
81 $actionName = $resolverInstance->getActionName();
83 // Store it away in this class
84 $filterInstance->setActionName($actionName);
86 // Return the instance
87 return $filterInstance;
91 * Protected setter for action name
93 * @param $actionName Action name to set
96 protected final function setActionName ($actionName) {
97 $this->actionName = (string) $actionName;
101 * Getter for action name
103 * @return $actionName Action name to set
105 public final function getActionName () {
106 return $this->actionName;
110 * Executes the filter with given request and response objects
112 * @param $requestInstance An instance of a class with an Requestable interface
113 * @param $responseInstance An instance of a class with an Responseable interface
116 * @throws FilterChainException If this filter fails to operate
118 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
119 // Try to get real discovery class
121 // Get an instance from the object factory
122 $discoveryInstance = ObjectFactory::createObjectByConfiguredName($this->getActionName() . '_payment_discovery', array($this));
124 // Call the discovery method
125 $discoveryInstance->discover($requestInstance);
127 // Remember this instance if all wents fine
128 Registry::getRegistry()->addInstance('payments', $discoveryInstance);
129 } catch (NoConfigEntryException $e) {
130 // Something bad happend
131 $requestInstance->requestIsValid(false);
133 // Add a message to the response
134 $responseInstance->addFatalMessage('payment_config_entry_error');
135 $responseInstance->addFatalMessagePlain($e->getMessage());
138 throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
139 } catch (NoClassException $e) {
140 // Something bad happend
141 $requestInstance->requestIsValid(false);
143 // Add a message to the response
144 $responseInstance->addFatalMessage('payment_class_error');
145 $responseInstance->addFatalMessagePlain($e->getMessage());
148 throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);