Continued:
[core.git] / framework / main / classes / discovery / payment / class_LocalPaymentDiscovery.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Discovery\Payment;
4
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;
15
16 /**
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.
20  *
21  * @author              Roland Haeder <webmaster@shipsimu.org>
22  * @version             0.0.0
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
26  *
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.
31  *
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.
36  *
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/>.
39  */
40 class LocalPaymentDiscovery extends BaseDiscovery implements Discoverable, Registerable {
41         // Load traits
42         use SearchableResultTrait;
43
44         /**
45          * Protected constructor
46          *
47          * @return      void
48          */
49         private function __construct () {
50                 // Call parent constructor
51                 parent::__construct(__CLASS__);
52         }
53
54         /**
55          * Create an instance of this class
56          *
57          * @param       $filterInstance         An instance of a filter
58          * @return      $discoveryInstance      An instance of this discovery class
59          */
60         public static final function createLocalPaymentDiscovery (Filterable $filterInstance) {
61                 // Get an instance of this class
62                 $discoveryInstance = new LocalPaymentDiscovery();
63
64                 // Set the action from filter
65                 $discoveryInstance->setActionName($filterInstance->getActionName());
66
67                 // Return the prepared instance
68                 return $discoveryInstance;
69         }
70
71         /**
72          * Discovers the request
73          *
74          * @param       $requestInstance        An instance of a Requestable class
75          * @return      void
76          */
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);
83
84                 // Get a frontend instance
85                 $frontendInstance = DatabaseFrontendFactory::createFrontendByConfiguredName('payment_db_frontend_class');
86
87                 // Get result back
88                 $resultInstance = $frontendInstance->doSelectByCriteria($criteriaInstance);
89
90                 // Advanced to next entry and assert on it as it should always be there
91                 assert($resultInstance->valid());
92
93                 // Set the result instance
94                 $this->setResultInstance($resultInstance);
95         }
96
97         /**
98          * Adds the database result in a human-readable format to the helper class
99          *
100          * @param       $helperInstance         An instance of a helper class
101          * @return      void
102          * @todo        0% done
103          */
104         public function addResultsToHelper (HelpableTemplate $helperInstance) {
105                 // Undone part
106         }
107
108 }