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