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