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