3 namespace Org\Mxchange\CoreFramework\Discovery\Payment;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Discovery\BaseDiscovery;
7 use Org\Mxchange\CoreFramework\Discovery\Discoverable;
8 use Org\Mxchange\CoreFramework\Factory\Database\Frontend\DatabaseFrontendFactory;
9 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
10 use Org\Mxchange\CoreFramework\Filter\Filterable;
11 use Org\Mxchange\CoreFramework\Helper\Template\HelpableTemplate;
12 use Org\Mxchange\CoreFramework\Registry\Registerable;
13 use Org\Mxchange\CoreFramework\Request\Requestable;
14 use Org\Mxchange\CoreFramework\Traits\Result\Search\SearchableResultTrait;
17 * A local payment discovery class. This class looks in local database for
18 * registered payment types and like all the others it at least returns the
19 * money bank transfer type.
21 * @author Roland Haeder <webmaster@shipsimu.org>
23 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
24 * @license GNU GPL 3.0 or any newer version
25 * @link http://www.shipsimu.org
27 * This program is free software: you can redistribute it and/or modify
28 * it under the terms of the GNU General Public License as published by
29 * the Free Software Foundation, either version 3 of the License, or
30 * (at your option) any later version.
32 * This program is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
37 * You should have received a copy of the GNU General Public License
38 * along with this program. If not, see <http://www.gnu.org/licenses/>.
40 class LocalPaymentDiscovery extends BaseDiscovery implements Discoverable, Registerable {
42 use SearchableResultTrait;
45 * Protected constructor
49 private function __construct () {
50 // Call parent constructor
51 parent::__construct(__CLASS__);
55 * Create an instance of this class
57 * @param $filterInstance An instance of a filter
58 * @return $discoveryInstance An instance of this discovery class
60 public static final function createLocalPaymentDiscovery (Filterable $filterInstance) {
61 // Get an instance of this class
62 $discoveryInstance = new LocalPaymentDiscovery();
64 // Set the action from filter
65 $discoveryInstance->setActionName($filterInstance->getActionName());
67 // Return the prepared instance
68 return $discoveryInstance;
72 * Discovers the request
74 * @param $requestInstance An instance of a Requestable class
77 public function discover (Requestable $requestInstance) {
78 // Now get a search criteria and set app name and payment action as search critera
79 $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
80 $criteriaInstance->addCriteria('app_name', $requestInstance->getRequestElement('app'));
81 $criteriaInstance->addCriteria('payment_action', $this->getActionName() . '_action');
82 $criteriaInstance->setLimit(1);
84 // Get a frontend instance
85 $frontendInstance = DatabaseFrontendFactory::createFrontendByConfiguredName('payment_db_frontend_class');
88 $resultInstance = $frontendInstance->doSelectByCriteria($criteriaInstance);
90 // Advanced to next entry and assert on it as it should always be there
91 assert($resultInstance->valid());
93 // Set the result instance
94 $this->setResultInstance($resultInstance);
98 * Adds the database result in a human-readable format to the helper class
100 * @param $helperInstance An instance of a helper class
104 public function addResultsToHelper (HelpableTemplate $helperInstance) {