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