+<?php
+/**
+ * A filter for payment discovery. This class discovers the payment type and
+ * returns an object holding all available payment system for the requested
+ * type.
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 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 <http://www.gnu.org/licenses/>.
+ */
+class PaymentDiscoveryFilter extends BaseFrameworkSystem implements Filterable {
+ /**
+ * Action name for payment discovery
+ */
+ private $actionName = "";
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Clean up a little
+ $this->removeNumberFormaters();
+ $this->removeSystemArray();
+ }
+
+ /**
+ * 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]
+?>