3 namespace CoreFramework\Filter\Discovery\Payment;
5 // Import framework stuff
6 use CoreFramework\Factory\ObjectFactory;
7 use CoreFramework\Generic\NullPointerException;
8 use CoreFramework\Registry\Generic\Registry;
11 * A filter for payment discovery. This class discovers the payment type and
12 * returns an object holding all available payment system for the requested
15 * @author Roland Haeder <webmaster@shipsimu.org>
17 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
18 * @license GNU GPL 3.0 or any newer version
19 * @link http://www.shipsimu.org
21 * This program is free software: you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation, either version 3 of the License, or
24 * (at your option) any later version.
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this program. If not, see <http://www.gnu.org/licenses/>.
34 class PaymentDiscoveryFilter extends BaseFilter implements Filterable {
36 * Action name for payment discovery
38 private $actionName = '';
41 * Protected constructor
45 protected function __construct () {
46 // Call parent constructor
47 parent::__construct(__CLASS__);
51 * Creates an instance of this filter class
53 * @param $actionInstance A performable action
54 * @return $filterInstance An instance of this filter class
55 * @throws NullPointerException If the resolver is not set
57 public static final function createPaymentDiscoveryFilter (PerformableAction $actionInstance) {
59 $filterInstance = new PaymentDiscoveryFilter();
61 // Get resolver from action
62 $resolverInstance = $actionInstance->getResolverInstance();
64 // Is the resolver set?
65 if (is_null($resolverInstance)) {
66 // Throw an exception here
67 throw new NullPointerException($filterInstance, self::EXCEPTION_IS_NULL_POINTER);
70 // Get the action name from resolver
71 $actionName = $resolverInstance->getActionName();
73 // Store it away in this class
74 $filterInstance->setActionName($actionName);
76 // Return the instance
77 return $filterInstance;
81 * Protected setter for action name
83 * @param $actionName Action name to set
86 protected final function setActionName ($actionName) {
87 $this->actionName = (string) $actionName;
91 * Getter for action name
93 * @return $actionName Action name to set
95 public final function getActionName () {
96 return $this->actionName;
100 * Executes the filter with given request and response objects
102 * @param $requestInstance An instance of a class with an Requestable interface
103 * @param $responseInstance An instance of a class with an Responseable interface
106 * @throws FilterChainException If this filter fails to operate
108 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
109 // Try to get real discovery class
111 // Get an instance from the object factory
112 $discoveryInstance = ObjectFactory::createObjectByConfiguredName($this->getActionName() . '_payment_discovery', array($this));
114 // Call the discovery method
115 $discoveryInstance->discover($requestInstance);
117 // Remember this instance if all wents fine
118 Registry::getRegistry()->addInstance('payments', $discoveryInstance);
119 } catch (NoConfigEntryException $e) {
120 // Something bad happend
121 $requestInstance->requestIsValid(FALSE);
123 // Add a message to the response
124 $responseInstance->addFatalMessage('payment_config_entry_error');
125 $responseInstance->addFatalMessagePlain($e->getMessage());
128 throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
129 } catch (NoClassException $e) {
130 // Something bad happend
131 $requestInstance->requestIsValid(FALSE);
133 // Add a message to the response
134 $responseInstance->addFatalMessage('payment_class_error');
135 $responseInstance->addFatalMessagePlain($e->getMessage());
138 throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);