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