Renamed Registry -> GenericRegistry to make it clear that this registry does
[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\Wrapper\DatabaseWrapperFactory;
9 use Org\Mxchange\CoreFramework\Factory\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
15 /**
16  * A local payment discovery class. This class looks in local database for
17  * registered payment types and like all the others it at least returns the
18  * money bank transfer type.
19  *
20  * @author              Roland Haeder <webmaster@shipsimu.org>
21  * @version             0.0.0
22  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
23  * @license             GNU GPL 3.0 or any newer version
24  * @link                http://www.shipsimu.org
25  *
26  * This program is free software: you can redistribute it and/or modify
27  * it under the terms of the GNU General Public License as published by
28  * the Free Software Foundation, either version 3 of the License, or
29  * (at your option) any later version.
30  *
31  * This program is distributed in the hope that it will be useful,
32  * but WITHOUT ANY WARRANTY; without even the implied warranty of
33  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
34  * GNU General Public License for more details.
35  *
36  * You should have received a copy of the GNU General Public License
37  * along with this program. If not, see <http://www.gnu.org/licenses/>.
38  */
39 class LocalPaymentDiscovery extends BaseDiscovery implements Discoverable, Registerable {
40         /**
41          * Protected constructor
42          *
43          * @return      void
44          */
45         protected function __construct () {
46                 // Call parent constructor
47                 parent::__construct(__CLASS__);
48         }
49
50         /**
51          * Create an instance of this class
52          *
53          * @param       $filterInstance         An instance of a filter
54          * @return      $discoveryInstance      An instance of this discovery class
55          */
56         public static final function createLocalPaymentDiscovery (Filterable $filterInstance) {
57                 // Get an instance of this class
58                 $discoveryInstance = new LocalPaymentDiscovery();
59
60                 // Set the action from filter
61                 $discoveryInstance->setActionName($filterInstance->getActionName());
62
63                 // Return the prepared instance
64                 return $discoveryInstance;
65         }
66
67         /**
68          * Discovers the request
69          *
70          * @param       $requestInstance        An instance of a Requestable class
71          * @return      void
72          */
73         public function discover (Requestable $requestInstance) {
74                 // Now get a search criteria and set app name and payment action as search critera
75                 $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
76                 $criteriaInstance->addCriteria('app_name', $requestInstance->getRequestElement('app'));
77                 $criteriaInstance->addCriteria('payment_action', $this->getActionName() . '_action');
78                 $criteriaInstance->setLimit(1);
79
80                 // Get a wrapper instance
81                 $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('payment_db_wrapper_class');
82
83                 // Get result back
84                 $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
85
86                 // Advanced to next entry and assert on it as it should always be there
87                 assert($resultInstance->valid());
88
89                 // Set the result instance
90                 $this->setResultInstance($resultInstance);
91         }
92
93         /**
94          * Adds the database result in a human-readable format to the helper class
95          *
96          * @param       $helperInstance         An instance of a helper class
97          * @return      void
98          * @todo        0% done
99          */
100         public function addResultsToHelper (HelpableTemplate $helperInstance) {
101                 // Undone part
102         }
103
104 }