3 * A filter for payment discovery. This class discovers the payment type and
4 * returns an object holding all available payment system for the requested
7 * @author Roland Haeder <webmaster@ship-simu.org>
9 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team
10 * @license GNU GPL 3.0 or any newer version
11 * @link http://www.ship-simu.org
13 * This program is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 class PaymentDiscoveryFilter extends BaseFilter implements Filterable {
28 * Action name for payment discovery
30 private $actionName = '';
33 * Protected constructor
37 protected function __construct () {
38 // Call parent constructor
39 parent::__construct(__CLASS__);
43 * Creates an instance of this filter class
45 * @param $actionInstance A performable action
46 * @return $filterInstance An instance of this filter class
47 * @throws NullPointerException If the resolver is not set
49 public static final function createPaymentDiscoveryFilter (PerformableAction $actionInstance) {
51 $filterInstance = new PaymentDiscoveryFilter();
53 // Get resolver from action
54 $resolverInstance = $actionInstance->getResolverInstance();
56 // Is the resolver set?
57 if (is_null($resolverInstance)) {
58 // Throw an exception here
59 throw new NullPointerException($filterInstance, self::EXCEPTION_IS_NULL_POINTER);
62 // Get the action name from resolver
63 $actionName = $resolverInstance->getActionName();
65 // Store it away in this class
66 $filterInstance->setActionName($actionName);
68 // Return the instance
69 return $filterInstance;
73 * Protected setter for action name
75 * @param $actionName Action name to set
78 protected final function setActionName ($actionName) {
79 $this->actionName = (string) $actionName;
83 * Getter for action name
85 * @return $actionName Action name to set
87 public final function getActionName () {
88 return $this->actionName;
92 * Executes the filter with given request and response objects
94 * @param $requestInstance An instance of a class with an Requestable interface
95 * @param $responseInstance An instance of a class with an Responseable interface
98 * @throws FilterChainException If this filter fails to operate
100 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
101 // Try to get real discovery class
103 // Get an instance from the object factory
104 $discoveryInstance = ObjectFactory::createObjectByConfiguredName($this->getActionName().'_payment_discovery', array($this));
106 // Call the discovery method
107 $discoveryInstance->discover($requestInstance);
109 // Remember this instance if all wents fine
110 Registry::getRegistry()->addInstance('payments', $discoveryInstance);
111 } catch (NoConfigEntryException $e) {
112 // Something bad happend
113 $requestInstance->requestIsValid(false);
115 // Add a message to the response
116 $responseInstance->addFatalMessage('payment_config_entry_error');
117 $responseInstance->addFatalMessagePlain($e->getMessage());
120 throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
121 } catch (NoClassException $e) {
122 // Something bad happend
123 $requestInstance->requestIsValid(false);
125 // Add a message to the response
126 $responseInstance->addFatalMessage('payment_class_error');
127 $responseInstance->addFatalMessagePlain($e->getMessage());
130 throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);