PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.9.6
GiveWP – Donation Plugin and Fundraising Platform v2.9.6
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / TestData / ServiceProvider.php

ServiceProvider.php in GiveWP – Donation Plugin and Fundraising Platform 2.9.6, at src/TestData/ServiceProvider.php

84 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\TestData;
4
5 use WP_CLI;
6 use InvalidArgumentException;
7 use Faker\Factory as FakerFactory;
8 use Faker\Generator as FakerGenerator;
9 use Give\TestData\Commands\DonorSeedCommand;
10 use Give\TestData\Commands\DonationSeedCommand;
11 use Give\TestData\Commands\DonationStatusCommand;
12 use Give\TestData\Commands\FormSeedCommand;
13 use Give\TestData\Commands\PageSeedCommand;
14 use Give\ServiceProviders\ServiceProvider as GiveServiceProvider;
15
16 /**
17 * Class ServiceProvider
18 * @package Give\TestData
19 */
20 class ServiceProvider implements GiveServiceProvider {
21 /**
22 * @inheritDoc
23 */
24 public function register() {
25 // Instead of passing around an instance, bind a singleton to the container.
26 give()->singleton(
27 FakerGenerator::class,
28 function () {
29 return FakerFactory::create();
30 }
31 );
32 }
33
34 /**
35 * @inheritDoc
36 */
37 public function boot() {
38 // Add CLI commands
39 if ( defined( 'WP_CLI' ) && WP_CLI ) {
40
41 $this->addCommands();
42
43 try {
44 $this->loadAddonsServiceProviders();
45 } catch ( InvalidArgumentException $e ) {
46 exit( $e->getMessage() );
47 }
48 }
49 }
50
51 /**
52 * Load addons service providers for TestData
53 */
54 private function loadAddonsServiceProviders() {
55 $providers = [];
56
57 // Load Test Data add-ons Service Providers as they are not handled by Give
58 foreach ( Addons::getActiveAddons() as $addon ) {
59 if ( ! is_subclass_of( $addon['serviceProvider'], GiveServiceProvider::class ) ) {
60 throw new InvalidArgumentException( "{$addon['serviceProvider']} class must implement the ServiceProvider interface" );
61 }
62
63 $addonServiceProvider = new $addon['serviceProvider']();
64 $addonServiceProvider->register();
65 $providers[] = $addonServiceProvider;
66 }
67
68 foreach ( $providers as $addonServiceProvider ) {
69 $addonServiceProvider->boot();
70 }
71 }
72
73 /**
74 * Add CLI comands
75 */
76 private function addCommands() {
77 WP_CLI::add_command( 'give test-donors', give()->make( DonorSeedCommand::class ) );
78 WP_CLI::add_command( 'give test-donations', give()->make( DonationSeedCommand::class ) );
79 WP_CLI::add_command( 'give test-donation-statuses', give()->make( DonationStatusCommand::class ) );
80 WP_CLI::add_command( 'give test-demonstration-page', give()->make( PageSeedCommand::class ) );
81 WP_CLI::add_command( 'give test-donation-form', give()->make( FormSeedCommand::class ) );
82 }
83 }
84