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, this is free software
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 BaseFrameworkSystem 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__);
42 $this->removeNumberFormaters();
43 $this->removeSystemArray();
47 * Creates an instance of this filter class
49 * @param $actionInstance A performable action
50 * @return $filterInstance An instance of this filter class
51 * @throws NullPointerException If the resolver is not set
53 public final static function createPaymentDiscoveryFilter (PerformableAction $actionInstance) {
55 $filterInstance = new PaymentDiscoveryFilter();
57 // Get resolver from action
58 $resolverInstance = $actionInstance->getResolverInstance();
60 // Is the resolver set?
61 if (is_null($resolverInstance)) {
62 // Throw an exception here
63 throw new NullPointerException($filterInstance, self::EXCEPTION_IS_NULL_POINTER);
66 // Get the action name from resolver
67 $actionName = $resolverInstance->getActionName();
69 // Store it away in this class
70 $filterInstance->setActionName($actionName);
72 // Return the instance
73 return $filterInstance;
77 * Protected setter for action name
79 * @param $actionName Action name to set
82 protected final function setActionName ($actionName) {
83 $this->actionName = (string) $actionName;
87 * Getter for action name
89 * @return $actionName Action name to set
91 public final function getActionName () {
92 return $this->actionName;
96 * Executes the filter with given request and response objects
98 * @param $requestInstance An instance of a class with an Requestable interface
99 * @param $responseInstance An instance of a class with an Responseable interface
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 (FrameworkException $e) {
115 // Something bad happend
116 $requestInstance->requestIsValid(false);
118 // Add a message to the response
119 $responseInstance->addFatalMessage('payment_error');
120 $responseInstance->addFatalMessagePlain($e->getMessage());