diff --git a/composer.json b/composer.json index 288bcf9f..59455a1b 100644 --- a/composer.json +++ b/composer.json @@ -18,9 +18,17 @@ "StellarWP\\Uplink\\Tests\\": "tests/_support/Helper/" } }, + "repositories": [ + { + "type": "vcs", + "url": "git@github.com:stellarwp/container-contract.git", + "no-api": true + } + ], "require": { + "php": "^7.0 | ^8.0", "lucatume/di52": "^3.0", - "php": "^7.0 | ^8.0" + "stellarwp/container-contract": "^1.0" }, "config": { "preferred-install": "dist", diff --git a/composer.lock b/composer.lock index 601e1674..3c03fb2d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e1695d51d5655314ba5f3db6fdf8e314", + "content-hash": "6329a39f0c4e91f4476b94ee1a3d60cd", "packages": [ { "name": "lucatume/di52", @@ -101,6 +101,48 @@ "source": "https://github.com/php-fig/container/tree/1.1.2" }, "time": "2021-11-05T16:50:12+00:00" + }, + { + "name": "stellarwp/container-contract", + "version": "1.0.3", + "source": { + "type": "git", + "url": "git@github.com:stellarwp/container-contract.git", + "reference": "65262f5b98538b56f0d20269b0deb55f5d366e3a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/stellarwp/container-contract/zipball/65262f5b98538b56f0d20269b0deb55f5d366e3a", + "reference": "65262f5b98538b56f0d20269b0deb55f5d366e3a", + "shasum": "" + }, + "require": { + "php": ">=7.4.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "StellarWP\\ContainerContract\\": "src/" + } + }, + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "StellarWP", + "homepage": "https://stellarwp.com" + } + ], + "description": "StellarWP Container Interface", + "homepage": "https://github.com/stellarwp/container-contract", + "keywords": [ + "container", + "container-interface", + "container-interop", + "psr-11" + ], + "time": "2022-09-23T02:59:52+00:00" } ], "packages-dev": [ @@ -6353,8 +6395,8 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "^5.6 | ^7.0 | ^8.0" + "php": "^7.0 | ^8.0" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.1.0" } diff --git a/src/Uplink/API/Client.php b/src/Uplink/API/Client.php index e88037ff..917fbdf1 100644 --- a/src/Uplink/API/Client.php +++ b/src/Uplink/API/Client.php @@ -2,6 +2,7 @@ namespace StellarWP\Uplink\API; +use StellarWP\Uplink\Config; use StellarWP\Uplink\Container; use StellarWP\Uplink\Resources\Resource; use StellarWP\Uplink\Site\Data; @@ -113,7 +114,7 @@ public function get_api_base_url(): string { * * @param string $base_url Base URL. */ - return apply_filters( 'stellar_uplink_api_get_base_url', static::$base_url ); + return apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'api_get_base_url', static::$base_url ); } /** @@ -159,7 +160,7 @@ protected function request( $method, $endpoint, $args ) { * @param string $endpoint Request method. * @param array $args Request data. */ - $request_args = apply_filters( 'stellar_uplink_api_request_args', $request_args, $endpoint, $args ); + $request_args = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'api_request_args', $request_args, $endpoint, $args ); $url = static::$base_url . static::$api_root . $endpoint; @@ -176,7 +177,7 @@ protected function request( $method, $endpoint, $args ) { * @param string $endpoint API endpoint. * @param array $args API arguments. */ - $result = apply_filters( 'stellar_uplink_api_response', $result, $endpoint, $args ); + $result = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'api_response', $result, $endpoint, $args ); return $result; } @@ -216,7 +217,7 @@ public function validate_license( Resource $resource, string $key = null, string * * @param array $args License validation arguments. */ - $args = apply_filters( 'stellar_uplink_client_validate_license_args', $args ); + $args = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'client_validate_license_args', $args ); $request_hash = $this->build_hash( $args ); $cache_key = 'stellar_uplink_validate_license_' . $request_hash; @@ -240,6 +241,6 @@ public function validate_license( Resource $resource, string $key = null, string * @param Validation_Response $results License validation results. * @param array $args License validation arguments. */ - return apply_filters( 'stellar_uplink_client_validate_license', $results, $args ); + return apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'client_validate_license', $results, $args ); } } diff --git a/src/Uplink/Admin/Field.php b/src/Uplink/Admin/Field.php index 100b33de..efd8d6b3 100644 --- a/src/Uplink/Admin/Field.php +++ b/src/Uplink/Admin/Field.php @@ -2,6 +2,7 @@ namespace StellarWP\Uplink\Admin; +use StellarWP\Uplink\Config; use StellarWP\Uplink\Container; use StellarWP\Uplink\Resources\Collection; @@ -99,7 +100,7 @@ public function field_html( array $args = [] ): void { $args['plugin'] ); - echo apply_filters( 'stellar_uplink_license_field_html_render', $field, $args ); + echo apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'license_field_html_render', $field, $args ); $this->get_description( $args ); } @@ -130,7 +131,7 @@ protected function get_content( array $context = [] ) { * @return string */ public function get_path(): string { - return apply_filters( 'stellar_uplink_field-template_path', dirname( __DIR__, 2 ) . $this->path, $this->path ); + return apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'field-template_path', dirname( __DIR__, 2 ) . $this->path, $this->path ); } /** diff --git a/src/Uplink/Admin/License_Field.php b/src/Uplink/Admin/License_Field.php index b291c7a5..260b3495 100644 --- a/src/Uplink/Admin/License_Field.php +++ b/src/Uplink/Admin/License_Field.php @@ -2,6 +2,7 @@ namespace StellarWP\Uplink\Admin; +use StellarWP\Uplink\Config; use StellarWP\Uplink\Container; use StellarWP\Uplink\Resources\Collection; use StellarWP\Uplink\Resources\Plugin; @@ -63,7 +64,7 @@ public function get_field_html( Plugin $plugin ): string { $html .= '
'; $html .= '
'; - return apply_filters( 'stellar_uplink_license_field_html', $html, $plugin->get_slug() ); + return apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'license_field_html', $html, $plugin->get_slug() ); } public function render(): void { @@ -75,12 +76,12 @@ public function render(): void { public function enqueue_assets(): void{ $handle = 'stellar-uplink-license-admin'; $path = preg_replace( '/.*\/vendor/', plugin_dir_url( $this->get_plugin()->get_path() ) . 'vendor', dirname( __DIR__, 2 ) ); - $js_src = apply_filters( 'stellar_uplink_admin_js_source', $path . '/resources/js/key-admin.js' ); + $js_src = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'admin_js_source', $path . '/resources/js/key-admin.js' ); wp_register_script( $handle, $js_src, [ 'jquery' ], '1.0.0', true ); wp_enqueue_script( $handle ); - $css_src = apply_filters( 'stellar_uplink_admin_css_source', $path . '/resources/css/main.css' ); + $css_src = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'admin_css_source', $path . '/resources/css/main.css' ); wp_enqueue_style( 'stellar-uplink-license-admin', $css_src ); } diff --git a/src/Uplink/Admin/Notice.php b/src/Uplink/Admin/Notice.php index b94292ef..485264dd 100644 --- a/src/Uplink/Admin/Notice.php +++ b/src/Uplink/Admin/Notice.php @@ -2,6 +2,7 @@ namespace StellarWP\Uplink\Admin; +use StellarWP\Uplink\Config; use StellarWP\Uplink\Messages\Expired_Key; use StellarWP\Uplink\Messages\Unlicensed; @@ -92,7 +93,7 @@ public function save_notices(): void { * @param array $current_notices * @param array $previously_saved_notices */ - do_action( 'stellar_uplink_notices_save_notices', $this->notices, $this->saved_notices ); + do_action( 'stellar_uplink_' . Config::get_hook_prefix(). 'notices_save_notices', $this->notices, $this->saved_notices ); } } diff --git a/src/Uplink/Admin/Plugins_Page.php b/src/Uplink/Admin/Plugins_Page.php index a64b7f5d..1ec417db 100644 --- a/src/Uplink/Admin/Plugins_Page.php +++ b/src/Uplink/Admin/Plugins_Page.php @@ -2,6 +2,7 @@ namespace StellarWP\Uplink\Admin; +use StellarWP\Uplink\Config; use StellarWP\Uplink\Container; use StellarWP\Uplink\Messages; use StellarWP\Uplink\Resources\Collection; @@ -125,7 +126,7 @@ public function display_plugin_messages( string $page ): void { 'message_row_html' => $message_row_html, ]; - add_filter( 'stellar_uplink_plugin_notices', [ $this, 'add_notice_to_plugin_notices' ] ); + add_filter( 'stellar_uplink_' . Config::get_hook_prefix(). 'plugin_notices', [ $this, 'add_notice_to_plugin_notices' ] ); } /** @@ -152,9 +153,9 @@ public function store_admin_notices( string $page ): void { if ( 'plugins.php' !== $page ) { return; } - $notices = apply_filters( 'stellar_uplink_plugin_notices', [] ); + $notices = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'plugin_notices', [] ); $path = preg_replace( '/.*\/vendor/', plugin_dir_url( $this->get_plugin()->get_path() ) . 'vendor', dirname( __DIR__, 2 ) ); - $js_src = apply_filters( 'stellar_uplink_admin_js_source', $path . '/resources/js/notices.js' ); + $js_src = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'admin_js_source', $path . '/resources/js/notices.js' ); $handle = 'stellar_uplink-notices'; wp_register_script( $handle, $js_src, [ 'jquery' ], '1.0.0', true ); diff --git a/src/Uplink/Admin/Provider.php b/src/Uplink/Admin/Provider.php index 46ac5412..3fef015c 100644 --- a/src/Uplink/Admin/Provider.php +++ b/src/Uplink/Admin/Provider.php @@ -2,7 +2,9 @@ namespace StellarWP\Uplink\Admin; -class Provider extends \tad_DI52_ServiceProvider { +use StellarWP\Uplink\Contracts\Abstract_Subscriber; + +class Provider extends Abstract_Subscriber { /** * Register the service provider. * @@ -20,20 +22,50 @@ public function register() { } public function register_hooks(): void { - add_filter( 'plugins_api', $this->container->callback( Plugins_Page::class, 'inject_info' ), 10, 3 ); + add_filter( 'plugins_api', function ( $result, $action, $args ) { + return $this->container->get( Plugins_Page::class)->inject_info( $result, $action, $args ); + }, 10, 3 ); if ( ( ! defined( 'TRIBE_DISABLE_PUE' ) || true !== TRIBE_DISABLE_PUE ) ) { - add_filter( 'pre_set_site_transient_update_plugins', $this->container->callback( Plugins_Page::class, 'check_for_updates' ) ); + add_filter( 'pre_set_site_transient_update_plugins', function ( $transient ) { + return $this->container->get( Plugins_Page::class )->check_for_updates( $transient ); + }, 10, 1 ); } - add_action( 'admin_init', $this->container->callback( License_Field::class, 'register_settings' ) ); - add_action( 'admin_enqueue_scripts', $this->container->callback( License_Field::class, 'enqueue_assets' ) ); - add_action( 'admin_notices', $this->container->callback( Notice::class, 'setup_notices' ) ); - add_action( 'wp_ajax_pue-validate-key-uplink' , $this->container->callback( Ajax::class, 'validate_license' ) ); - add_action( 'admin_enqueue_scripts', $this->container->callback( Plugins_Page::class, 'display_plugin_messages' ), 1 ); - add_action( 'admin_enqueue_scripts', $this->container->callback( Plugins_Page::class, 'store_admin_notices' ) ); - add_action( 'load-plugins.php', $this->container->callback( Plugins_Page::class, 'remove_default_inline_update_msg' ), 50 ); - - add_filter( 'upgrader_pre_download', $this->container->callback( Package_Handler::class, 'filter_upgrader_pre_download' ) , 5, 3 ); - add_filter( 'upgrader_source_selection', $this->container->callback( Update_Prevention::class, 'filter_upgrader_source_selection' ) , 15, 4 ); + + add_action( 'admin_init', function() { + $this->container->get( License_Field::class)->register_settings(); + }, 10, 0 ); + + add_action( 'admin_enqueue_scripts', function () { + $this->container->get( License_Field::class )->enqueue_assets(); + }, 10, 0 ); + + add_action( 'admin_notices', function () { + $this->container->get( Notice::class )->setup_notices(); + }, 10, 0 ); + + add_action( 'wp_ajax_pue-validate-key-uplink' , function () { + $this->container->get( Ajax::class)->validate_license(); + }, 10, 0 ); + + add_action( 'admin_enqueue_scripts', function ( $page ) { + $this->container->get( Plugins_Page::class)->display_plugin_messages( $page ); + }, 1, 1 ); + + add_action( 'admin_enqueue_scripts', function ( $page ) { + $this->container->get( Plugins_Page::class )->store_admin_notices( $page ); + }, 10, 0 ); + + add_action( 'load-plugins.php', function () { + $this->container->get( Plugins_Page::class )->remove_default_inline_update_msg(); + }, 50, 0 ); + + add_filter( 'upgrader_pre_download', function ( $reply, $package, $upgrader ) { + return $this->container->get( Package_Handler::class )->filter_upgrader_pre_download( $reply, $package, $upgrader ); + }, 5, 3 ); + + add_filter( 'upgrader_source_selection', function ( $source, $remote_source, $upgrader, $extras ) { + return $this->container->callback( Update_Prevention::class )->filter_upgrader_source_selection( $source, $remote_source, $upgrader, $extras ); + }, 15, 4 ); } } diff --git a/src/Uplink/Admin/Update_Prevention.php b/src/Uplink/Admin/Update_Prevention.php index ceeaff56..672948ec 100644 --- a/src/Uplink/Admin/Update_Prevention.php +++ b/src/Uplink/Admin/Update_Prevention.php @@ -2,6 +2,7 @@ namespace StellarWP\Uplink\Admin; +use StellarWP\Uplink\Config; use StellarWP\Uplink\Container; use StellarWP\Uplink\Resources\Collection; use StellarWP\Uplink\Resources\Plugin; @@ -63,7 +64,7 @@ public function filter_upgrader_source_selection( string $source, $remote_source } $incompatible_plugins = apply_filters( - 'stellar_uplink_update_prevention_incompatible_plugins', + 'stellar_uplink_' . Config::get_hook_prefix(). 'update_prevention_incompatible_plugins', [], $source, $remote_source @@ -88,7 +89,7 @@ public function filter_upgrader_source_selection( string $source, $remote_source * @param array $extra Extra arguments passed to hooked filters. */ $should_prevent_update = apply_filters( - 'stellar_uplink_should_prevent_update_without_license', + 'stellar_uplink_' . Config::get_hook_prefix(). 'should_prevent_update_without_license', true, $plugin, $incompatible_plugins, diff --git a/src/Uplink/Config.php b/src/Uplink/Config.php new file mode 100644 index 00000000..77a1f7d5 --- /dev/null +++ b/src/Uplink/Config.php @@ -0,0 +1,108 @@ +container = $container; + } + +} diff --git a/src/Uplink/Contracts/Subscriber_Interface.php b/src/Uplink/Contracts/Subscriber_Interface.php new file mode 100644 index 00000000..1eadf596 --- /dev/null +++ b/src/Uplink/Contracts/Subscriber_Interface.php @@ -0,0 +1,12 @@ +key ); + $key = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'license_get_key', $this->key ); return $key ?: ''; } diff --git a/src/Uplink/Resources/Resource.php b/src/Uplink/Resources/Resource.php index 9492ae43..45f44f8d 100644 --- a/src/Uplink/Resources/Resource.php +++ b/src/Uplink/Resources/Resource.php @@ -3,6 +3,7 @@ namespace StellarWP\Uplink\Resources; use StellarWP\Uplink\API; +use StellarWP\Uplink\Config; use StellarWP\Uplink\Container; use StellarWP\Uplink\Exceptions; use StellarWP\Uplink\Site\Data; @@ -262,7 +263,7 @@ public function get_slug() { * * @param string $slug Resource slug. */ - return apply_filters( 'stellar_uplink_resource_get_slug', $this->slug ); + return apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'resource_get_slug', $this->slug ); } /** @@ -310,7 +311,7 @@ public function get_version() { * * @param string $version Resource version. */ - return apply_filters( 'stellar_uplink_resource_get_version', $this->version ); + return apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'resource_get_version', $this->version ); } /** @@ -399,7 +400,7 @@ public static function register_resource( $resource_class, $slug, $name, $versio * * @param Resource $resource Resource instance. */ - $resource = apply_filters( 'stellar_uplink_resource_register_before_collection', $resource ); + $resource = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'resource_register_before_collection', $resource ); if ( ! empty( $collection[ $resource->get_slug() ] ) ) { throw new Exceptions\ResourceAlreadyRegisteredException( $resource->get_slug() ); @@ -414,7 +415,7 @@ public static function register_resource( $resource_class, $slug, $name, $versio * * @param Resource $resource Resource instance. */ - $resource = apply_filters( 'stellar_uplink_resource_register', $resource ); + $resource = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'resource_register', $resource ); return $resource; } diff --git a/src/Uplink/Site/Data.php b/src/Uplink/Site/Data.php index 8e1ee41a..2c1f42b6 100644 --- a/src/Uplink/Site/Data.php +++ b/src/Uplink/Site/Data.php @@ -2,6 +2,7 @@ namespace StellarWP\Uplink\Site; +use StellarWP\Uplink\Config; use StellarWP\Uplink\Container; class Data { @@ -89,7 +90,7 @@ public function get_db_version(): string { * * @param string $version DB version. */ - $version = apply_filters( 'stellar_uplink_get_db_version', $version ); + $version = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'get_db_version', $version ); return sanitize_text_field( $version ); } @@ -117,7 +118,7 @@ public function get_domain(): string { * * @param string $domain Domain. */ - $domain = apply_filters( 'stellar_uplink_get_domain', $domain ); + $domain = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'get_domain', $domain ); return sanitize_text_field( $domain ); } @@ -184,7 +185,7 @@ public function get_multisite_active_sites(): int { * * @param int $active_sites Number of active sites. */ - $active_sites = apply_filters( 'stellar_uplink_get_multisite_active_sites', $active_sites ); + $active_sites = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'get_multisite_active_sites', $active_sites ); return (int) $active_sites; } @@ -206,7 +207,7 @@ public function get_php_version(): string { * * @param string $version PHP version. */ - $version = apply_filters( 'stellar_uplink_get_php_version', $version ); + $version = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'get_php_version', $version ); return sanitize_text_field( $version ); } @@ -255,7 +256,7 @@ public function get_site_language(): string { * * @param string $locale Site language. */ - $locale = apply_filters( 'stellar_uplink_get_site_language', $locale ); + $locale = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'get_site_language', $locale ); return sanitize_text_field( $locale ); } @@ -277,7 +278,7 @@ public function get_stats(): array { * * @param boolean $use_full_stats Whether to send full stats */ - $use_full_stats = apply_filters( 'stellar_uplink_use_full_stats', false ); + $use_full_stats = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'use_full_stats', false ); if ( $use_full_stats ) { $stats = $this->build_full_stats( $stats ); @@ -292,7 +293,7 @@ public function get_stats(): array { * @param boolean $use_full_stats Whether to send full stats. * @param Data $checker Data object. */ - $stats = apply_filters( 'stellar_uplink_get_stats', $stats, $use_full_stats, $this ); + $stats = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'get_stats', $stats, $use_full_stats, $this ); return $stats; } @@ -327,7 +328,7 @@ public function get_theme_info(): array { * * @param array $info Theme info. */ - $info = apply_filters( 'stellar_uplink_get_theme_info', $info ); + $info = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'get_theme_info', $info ); return (array) $info; } @@ -381,7 +382,7 @@ public function get_timezone(): string { * * @param string $timezone Site timezone. */ - $timezone = apply_filters( 'stellar_uplink_get_timezone', $timezone ?: '' ); + $timezone = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'get_timezone', $timezone ?: '' ); return sanitize_text_field( $timezone ); } @@ -416,7 +417,7 @@ public function get_totals(): array { * * @param array $totals Site post totals. */ - $totals = apply_filters( 'stellar_uplink_get_totals', $totals ); + $totals = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'get_totals', $totals ); return (array) $totals; } @@ -438,7 +439,7 @@ public function get_user_language(): string { * * @param string $locale Site language. */ - $locale = apply_filters( 'stellar_uplink_get_user_language', $locale ); + $locale = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'get_user_language', $locale ); return sanitize_text_field( $locale ); } @@ -462,7 +463,7 @@ public function get_wp_version(): string { * * @param string $wp_version WordPress version. */ - $version = apply_filters( 'stellar_uplink_get_wp_version', $version ); + $version = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'get_wp_version', $version ); return sanitize_text_field( $version ); } @@ -484,7 +485,7 @@ public function is_debug_enabled(): bool { * * @param bool $debug_status Debug status. */ - $debug_status = apply_filters( 'stellar_uplink_is_debug_enabled', $debug_status ); + $debug_status = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'is_debug_enabled', $debug_status ); return (bool) $debug_status; } @@ -514,7 +515,7 @@ public function is_public(): bool { * * @param bool $is_public Is the site public? */ - $is_public = apply_filters( 'stellar_uplink_get_db_version', $is_public ); + $is_public = apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'get_db_version', $is_public ); return (bool) $is_public; } diff --git a/src/Uplink/Uplink.php b/src/Uplink/Uplink.php index e1eae8ab..01fe0264 100644 --- a/src/Uplink/Uplink.php +++ b/src/Uplink/Uplink.php @@ -2,14 +2,66 @@ namespace StellarWP\Uplink; -class Uplink extends \tad_DI52_ServiceProvider { +use StellarWP\ContainerContract\ContainerInterface; +use StellarWP\Uplink\Admin\Provider; + +class Uplink { + + /** + * The container that should be used for loading library resources. + * + * @since 1.0.0 + * + * @var ContainerInterface + */ + private ContainerInterface $container; + /** * Initializes the service provider. * * @since 1.0.0 */ - public static function init() : void { - Container::init()->register( static::class ); + public function init() : void { + if ( ! Config::has_container() ) { + throw new \RuntimeException( 'You must call StellarWP\Uplink\Config::set_container() before calling StellarWP\Telemetry::init().' ); + } + + $this->register(); + } + + /** + * The current instance of the library. + * + * @since 1.0.0 + * + * @var self + */ + private static self $instance; + + /** + * Returns the current instance or creates one to return. + * + * @since 1.0.0 + * + * @return self + */ + public static function instance() { + if ( ! isset( self::$instance ) ) { + self::$instance = new self(); + } + + return self::$instance; + } + + /** + * Gets the container. + * + * @since 1.0.0 + * + * @return ContainerInterface + */ + public function container() { + return $this->container; } /** @@ -18,12 +70,15 @@ public static function init() : void { * @since 1.0.0 */ public function register() { + $container = Config::get_container(); + $this->container = $container; + $this->container->singleton( static::class, $this ); $this->container->singleton( API\Client::class, API\Client::class ); $this->container->singleton( Resources\Collection::class, Resources\Collection::class ); $this->container->singleton( Site\Data::class, Site\Data::class ); - $this->container->register( Admin\Provider::class ); + (new Provider( $this->container ))->register(); $this->register_hooks(); } diff --git a/src/Uplink/Utils/Checks.php b/src/Uplink/Utils/Checks.php index 4d7c1263..963d9dee 100644 --- a/src/Uplink/Utils/Checks.php +++ b/src/Uplink/Utils/Checks.php @@ -2,6 +2,8 @@ namespace StellarWP\Uplink\Utils; +use StellarWP\Uplink\Config; + class Checks { /** * Determines if the provided value should be regarded as 'true'. @@ -23,7 +25,7 @@ public static function is_truthy( $var ) { * * @param array $truthy_strings */ - $truthy_strings = (array) apply_filters( 'stellar_uplink_is_truthy_strings', [ + $truthy_strings = (array) apply_filters( 'stellar_uplink_' . Config::get_hook_prefix(). 'is_truthy_strings', [ '1', 'enable', 'enabled', diff --git a/src/resources/views/fields/settings.php b/src/resources/views/fields/settings.php index 85a7cd69..3f702093 100644 --- a/src/resources/views/fields/settings.php +++ b/src/resources/views/fields/settings.php @@ -1,6 +1,7 @@