3 namespace CoreFramework\Filter\Discovery\Payment;
5 // Import framework stuff
6 use CoreFramework\Registry\Generic\Registry;
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
13 * @author Roland Haeder <webmaster@shipsimu.org>
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
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.
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.
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/>.
32 class PaymentDiscoveryFilter extends BaseFilter implements Filterable {
34 * Action name for payment discovery
36 private $actionName = '';
39 * Protected constructor
43 protected function __construct () {
44 // Call parent constructor
45 parent::__construct(__CLASS__);
49 * Creates an instance of this filter class
51 * @param $actionInstance A performable action
52 * @return $filterInstance An instance of this filter class
53 * @throws NullPointerException If the resolver is not set
55 public static final function createPaymentDiscoveryFilter (PerformableAction $actionInstance) {
57 $filterInstance = new PaymentDiscoveryFilter();
59 // Get resolver from action
60 $resolverInstance = $actionInstance->getResolverInstance();
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);
68 // Get the action name from resolver
69 $actionName = $resolverInstance->getActionName();
71 // Store it away in this class
72 $filterInstance->setActionName($actionName);
74 // Return the instance
75 return $filterInstance;
79 * Protected setter for action name
81 * @param $actionName Action name to set
84 protected final function setActionName ($actionName) {
85 $this->actionName = (string) $actionName;
89 * Getter for action name
91 * @return $actionName Action name to set
93 public final function getActionName () {
94 return $this->actionName;
98 * Executes the filter with given request and response objects
100 * @param $requestInstance An instance of a class with an Requestable interface
101 * @param $responseInstance An instance of a class with an Responseable interface
104 * @throws FilterChainException If this filter fails to operate
106 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
107 // Try to get real discovery class
109 // Get an instance from the object factory
110 $discoveryInstance = ObjectFactory::createObjectByConfiguredName($this->getActionName() . '_payment_discovery', array($this));
112 // Call the discovery method
113 $discoveryInstance->discover($requestInstance);
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);
121 // Add a message to the response
122 $responseInstance->addFatalMessage('payment_config_entry_error');
123 $responseInstance->addFatalMessagePlain($e->getMessage());
126 throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
127 } catch (NoClassException $e) {
128 // Something bad happend
129 $requestInstance->requestIsValid(FALSE);
131 // Add a message to the response
132 $responseInstance->addFatalMessage('payment_class_error');
133 $responseInstance->addFatalMessagePlain($e->getMessage());
136 throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);