* @version 0.0.0 * @copyright Copyright (c) 2007 - 2009 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ class PaymentDiscoveryFilter extends BaseFilter implements Filterable { /** * Action name for payment discovery */ private $actionName = ""; /** * Protected constructor * * @return void */ protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); } /** * Creates an instance of this filter class * * @param $actionInstance A performable action * @return $filterInstance An instance of this filter class * @throws NullPointerException If the resolver is not set */ public final static function createPaymentDiscoveryFilter (PerformableAction $actionInstance) { // Get a new instance $filterInstance = new PaymentDiscoveryFilter(); // Get resolver from action $resolverInstance = $actionInstance->getResolverInstance(); // Is the resolver set? if (is_null($resolverInstance)) { // Throw an exception here throw new NullPointerException($filterInstance, self::EXCEPTION_IS_NULL_POINTER); } // END - if // Get the action name from resolver $actionName = $resolverInstance->getActionName(); // Store it away in this class $filterInstance->setActionName($actionName); // Return the instance return $filterInstance; } /** * Protected setter for action name * * @param $actionName Action name to set * @return void */ protected final function setActionName ($actionName) { $this->actionName = (string) $actionName; } /** * Getter for action name * * @return $actionName Action name to set */ public final function getActionName () { return $this->actionName; } /** * Executes the filter with given request and response objects * * @param $requestInstance An instance of a class with an Requestable interface * @param $responseInstance An instance of a class with an Responseable interface * @return void * @todo 0% done */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Try to get real discovery class try { // Get an instance from the object factory $discoveryInstance = ObjectFactory::createObjectByConfiguredName($this->getActionName().'_payment_discovery', array($this)); // Call the discovery method $discoveryInstance->discover($requestInstance); // Remember this instance if all wents fine Registry::getRegistry()->addInstance('payments', $discoveryInstance); } catch (ConfigEntryNotFoundException $e) { // Something bad happend $requestInstance->requestIsValid(false); // Add a message to the response $responseInstance->addFatalMessage('payment_config_entry_error'); $responseInstance->addFatalMessagePlain($e->getMessage()); // Abort here return false; } catch (ClassNotFoundException $e) { // Something bad happend $requestInstance->requestIsValid(false); // Add a message to the response $responseInstance->addFatalMessage('payment_class_error'); $responseInstance->addFatalMessagePlain($e->getMessage()); // Abort here return false; } } } // [EOF] ?>