Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
86.49% |
32 / 37 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
1 | <?php |
2 | /** |
3 | * The plugin bootstrap file |
4 | * |
5 | * This file is read by WordPress to generate the plugin information in the plugin |
6 | * admin area. This file also includes all of the dependencies used by the plugin, |
7 | * registers the activation and deactivation functions, and defines a function |
8 | * that starts the plugin. |
9 | * |
10 | * @link http://example.com |
11 | * @since 1.0.0 |
12 | * @package BH_WC_Address_Validation |
13 | * |
14 | * @wordpress-plugin |
15 | * Plugin Name: Address Validation |
16 | * Plugin URI: http://github.com/BrianHenryIE/bh-wc-address-validation/ |
17 | * Description: Uses USPS API to verify and correct shipping addresses. |
18 | * Version: 1.4.1 |
19 | * Author: BrianHenryIE |
20 | * Author URI: https://BrianHenry.ie |
21 | * License: GPL-2.0+ |
22 | * License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
23 | * Text Domain: bh-wc-address-validation |
24 | * Domain Path: /languages |
25 | */ |
26 | |
27 | |
28 | namespace BrianHenryIE\WC_Address_Validation; |
29 | |
30 | use BrianHenryIE\WC_Address_Validation\API\Address_Validator_Interface; |
31 | use BrianHenryIE\WC_Address_Validation\API\API; |
32 | use BrianHenryIE\WC_Address_Validation\API\Settings; |
33 | use BrianHenryIE\WC_Address_Validation\API\Validators\EasyPost_Address_Validator; |
34 | use BrianHenryIE\WC_Address_Validation\API\Validators\Null_Validator; |
35 | use BrianHenryIE\WC_Address_Validation\API\Validators\USPS_Address_Validator; |
36 | use BrianHenryIE\WC_Address_Validation\lucatume\DI52\Container; |
37 | use BrianHenryIE\WC_Address_Validation\Psr\Container\ContainerInterface; |
38 | use BrianHenryIE\WC_Address_Validation\WP_Includes\Activator; |
39 | use BrianHenryIE\WC_Address_Validation\WP_Includes\Deactivator; |
40 | use BrianHenryIE\WC_Address_Validation\WP_Logger\Logger; |
41 | use BrianHenryIE\WC_Address_Validation\WP_Logger\Logger_Settings_Interface; |
42 | use Psr\Log\LoggerInterface; |
43 | |
44 | // If this file is called directly, abort. |
45 | if ( ! defined( 'WPINC' ) ) { |
46 | throw new \Exception( 'WordPress not loaded.' ); |
47 | } |
48 | |
49 | require_once plugin_dir_path( __FILE__ ) . 'autoload.php'; |
50 | |
51 | /** |
52 | * Currently plugin version. |
53 | * Start at version 1.0.0 and use SemVer - https://semver.org |
54 | * Rename this for your plugin and update it as you release new versions. |
55 | */ |
56 | define( 'BH_WC_ADDRESS_VALIDATION_VERSION', '1.4.1' ); |
57 | |
58 | /** |
59 | * The code that runs during plugin activation, deactivation. |
60 | */ |
61 | register_activation_hook( __FILE__, array( Activator::class, 'activate' ) ); |
62 | register_deactivation_hook( __FILE__, array( Deactivator::class, 'deactivate' ) ); |
63 | |
64 | |
65 | // Create container. |
66 | $container = new Container(); |
67 | |
68 | $container->singleton( |
69 | ContainerInterface::class, |
70 | static function () use( $container ) { |
71 | return $container; |
72 | } |
73 | ); |
74 | |
75 | // Define ambiguous (interface) binds. |
76 | $container->bind( API_Interface::class, API::class ); |
77 | $container->bind( Settings_Interface::class, Settings::class ); |
78 | $container->bind( Logger_Settings_Interface::class, Settings::class ); |
79 | // Define more complex bind. |
80 | $container->singleton( |
81 | LoggerInterface::class, |
82 | static function ( Container $container ) { |
83 | return Logger::instance( $container->get( Logger_Settings_Interface::class ) ); |
84 | } |
85 | ); |
86 | |
87 | $settings = $container->get( Settings_Interface::class ); |
88 | |
89 | // Address_Validator_Interface |
90 | if ( ! empty( $settings->get_easypost_api_key() ) ) { |
91 | $container->bind( Address_Validator_Interface::class, EasyPost_Address_Validator::class ); |
92 | } elseif ( ! empty( $settings->get_usps_username() ) ) { |
93 | $container->bind( Address_Validator_Interface::class, USPS_Address_Validator::class ); |
94 | } else { |
95 | $container->bind( Address_Validator_Interface::class, Null_Validator::class ); |
96 | } |
97 | |
98 | |
99 | // Instantiate the main plugin class which itself uses the container to instantiate (::get()) |
100 | // classes and adds the actions and filters. |
101 | $app = $container->get( BH_WC_Address_Validation::class ); |
102 | |
103 | $GLOBALS['bh_wc_address_validation'] = $container->get( API_Interface::class ); |
104 | |
105 | add_action( |
106 | 'init', |
107 | function () use ( $container ) { |
108 | $upgrader = $container->get( Upgrader::class ); |
109 | $upgrader->do_upgrade(); |
110 | } |
111 | ); |