API.php
60 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * API class |
| 5 | * |
| 6 | * @package Give |
| 7 | */ |
| 8 | |
| 9 | namespace Give\API; |
| 10 | |
| 11 | use Give\API\Endpoints\Reports as Reports; |
| 12 | |
| 13 | defined( 'ABSPATH' ) || exit; |
| 14 | |
| 15 | /** |
| 16 | * Manages API Endpoints |
| 17 | */ |
| 18 | class API { |
| 19 | |
| 20 | protected $endpoints = [ |
| 21 | Reports\PaymentStatuses::class, |
| 22 | Reports\PaymentMethods::class, |
| 23 | Reports\FormPerformance::class, |
| 24 | Reports\TopDonors::class, |
| 25 | Reports\RecentDonations::class, |
| 26 | Reports\Income::class, |
| 27 | Reports\IncomeBreakdown::class, |
| 28 | Reports\AverageDonation::class, |
| 29 | Reports\TotalDonors::class, |
| 30 | Reports\TotalIncome::class, |
| 31 | Reports\TotalRefunds::class, |
| 32 | ]; |
| 33 | |
| 34 | /** |
| 35 | * Initialize Reports and Pages, register hooks |
| 36 | */ |
| 37 | public function init() { |
| 38 | // To prevent conflict on we are loading autoload.php when need for now. In future we can loaded it globally. |
| 39 | require GIVE_PLUGIN_DIR . 'vendor/autoload.php'; |
| 40 | |
| 41 | // Load endpoints |
| 42 | $this->load_endpoints(); |
| 43 | |
| 44 | } |
| 45 | |
| 46 | public function __construct() { |
| 47 | // Do nothing |
| 48 | } |
| 49 | |
| 50 | public function load_endpoints() { |
| 51 | foreach ( $this->endpoints as $endpoint ) { |
| 52 | $class = new $endpoint(); |
| 53 | $class->init(); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | } |
| 58 | $api = new API(); |
| 59 | $api->init(); |
| 60 |