admin-views
1 week ago
bootstrap.php
1 week ago
error.php
1 week ago
extensions.php
1 week ago
modules.php
1 week ago
services.php
1 week ago
services.php
133 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace Syde\Vendor\Worldline; |
| 5 | |
| 6 | use Syde\Vendor\Worldline\Dhii\Package\Version\StringVersionFactoryInterface; |
| 7 | use Syde\Vendor\Worldline\Dhii\Services\Factories\Alias; |
| 8 | use Syde\Vendor\Worldline\Dhii\Services\Factories\Value; |
| 9 | use Syde\Vendor\Worldline\Dhii\Services\Factory; |
| 10 | use Syde\Vendor\Worldline\Dhii\Validation\ValidatorInterface; |
| 11 | use Syde\Vendor\Worldline\Dhii\Validator\CallbackValidator; |
| 12 | use Syde\Vendor\Worldline\Dhii\Validator\CompositeValidator; |
| 13 | use Syde\Vendor\Worldline\Dhii\Versions\StringVersionFactory; |
| 14 | use Syde\Vendor\Worldline\Inpsyde\Modularity\Package; |
| 15 | use Syde\Vendor\Worldline\Inpsyde\Modularity\Properties\PluginProperties; |
| 16 | use Syde\Vendor\Worldline\Inpsyde\Modularity\Properties\Properties; |
| 17 | use Syde\Vendor\Worldline\Inpsyde\WorldlineForWoocommerce\Admin\CancelAuthorizationUi; |
| 18 | use Syde\Vendor\Worldline\Inpsyde\WorldlineForWoocommerce\Core\PluginActionLink\PluginActionLink; |
| 19 | use Syde\Vendor\Worldline\Inpsyde\WorldlineForWoocommerce\Core\PluginActionLink\PluginActionLinkRegistry; |
| 20 | use Syde\Vendor\Worldline\Inpsyde\WorldlineForWoocommerce\Environment\WpEnvironmentFactory; |
| 21 | use Syde\Vendor\Worldline\Inpsyde\WorldlineForWoocommerce\Environment\WpEnvironmentFactoryInterface; |
| 22 | use Syde\Vendor\Worldline\Inpsyde\WorldlineForWoocommerce\Environment\WpEnvironmentInterface; |
| 23 | use Syde\Vendor\Worldline\Psr\Container\ContainerInterface; |
| 24 | use Syde\Vendor\Worldline\Psr\Http\Message\UriFactoryInterface; |
| 25 | use Syde\Vendor\Worldline\Psr\Http\Message\UriInterface; |
| 26 | use Syde\Vendor\Worldline\Inpsyde\WorldlineForWoocommerce\Admin\CaptureAuthorizationUi; |
| 27 | return static function (string $rootPath) : array { |
| 28 | $config = (require __DIR__ . '/../config.php'); |
| 29 | return ['assets.get_module_asset_url' => new Factory([Package::PROPERTIES], static function (PluginProperties $props) : callable { |
| 30 | return static function (string $moduleName, string $assetName) use($props) : string { |
| 31 | return $props->baseUrl() . "assets/{$moduleName}-{$assetName}"; |
| 32 | }; |
| 33 | }), 'assets.get_module_static_asset_url' => new Factory([Package::PROPERTIES], static function (PluginProperties $props) : callable { |
| 34 | return static function (string $packageName, string $assetName) use($props) : string { |
| 35 | return $props->baseUrl() . "modules/inpsyde/{$packageName}/assets/{$assetName}"; |
| 36 | }; |
| 37 | }), 'core.environment_validator' => static function (ContainerInterface $container) : ValidatorInterface { |
| 38 | /** @var ValidatorInterface $phpVersionValidator */ |
| 39 | $phpVersionValidator = $container->get('core.php_version_validator'); |
| 40 | /** @var ValidatorInterface $wpVersionValidator */ |
| 41 | $wpVersionValidator = $container->get('core.wp_version_validator'); |
| 42 | /** @var ValidatorInterface $wcVersionValidator */ |
| 43 | $wcVersionValidator = $container->get('core.wc_version_validator'); |
| 44 | /** @var ValidatorInterface $wcActiveValidator */ |
| 45 | $wcActiveValidator = $container->get('core.wc_active_validator'); |
| 46 | return new CompositeValidator([$phpVersionValidator, $wpVersionValidator, $wcVersionValidator, $wcActiveValidator]); |
| 47 | }, 'core.php_version_validator' => static function (ContainerInterface $container) : ValidatorInterface { |
| 48 | /** @var Properties $pluginProperties */ |
| 49 | $pluginProperties = $container->get('properties'); |
| 50 | return new CallbackValidator(static function (WpEnvironmentInterface $environment) use($pluginProperties) : ?string { |
| 51 | if (\version_compare($environment->phpVersion(), (string) $pluginProperties->requiresPhp(), '>=')) { |
| 52 | return null; |
| 53 | } |
| 54 | return \sprintf('Required PHP version is %1$s, but the current one is %2$s', (string) $pluginProperties->requiresPhp(), $environment->phpVersion()); |
| 55 | }); |
| 56 | }, 'core.wp_version_validator' => static function (ContainerInterface $container) : ValidatorInterface { |
| 57 | /** @var Properties $pluginProperties */ |
| 58 | $pluginProperties = $container->get('properties'); |
| 59 | return new CallbackValidator(static function (WpEnvironmentInterface $environment) use($pluginProperties) : ?string { |
| 60 | if (\version_compare($environment->wpVersion(), (string) $pluginProperties->requiresWp(), '>=')) { |
| 61 | return null; |
| 62 | } |
| 63 | return \sprintf('Required WordPress version is %1$s, but the current one is %2$s', (string) $pluginProperties->requiresWp(), $environment->wpVersion()); |
| 64 | }); |
| 65 | }, 'core.wc_version_validator' => static function (ContainerInterface $container) : ValidatorInterface { |
| 66 | /** @var Properties $pluginProperties */ |
| 67 | $pluginProperties = $container->get('properties'); |
| 68 | $requiredWcVersion = (string) $pluginProperties->get('WC requires at least'); |
| 69 | return new CallbackValidator(static function (WpEnvironmentInterface $environment) use($requiredWcVersion) : ?string { |
| 70 | if (empty($environment->wcVersion()) || \version_compare($environment->wcVersion(), $requiredWcVersion, '>=')) { |
| 71 | return null; |
| 72 | } |
| 73 | return \sprintf('Required WooCommerce version is %1$s, but the current one is %2$s', $requiredWcVersion, $environment->wcVersion()); |
| 74 | }); |
| 75 | }, 'core.wc_active_validator' => static function (ContainerInterface $container) : ValidatorInterface { |
| 76 | /** @var Properties $pluginProperties */ |
| 77 | $pluginProperties = $container->get('properties'); |
| 78 | $pluginName = $pluginProperties->name(); |
| 79 | return new CallbackValidator(static function (WpEnvironmentInterface $environment) use($pluginName) : ?string { |
| 80 | if ($environment->isWcActive()) { |
| 81 | return null; |
| 82 | } |
| 83 | return \sprintf('%1$s requires WooCommerce to be active.', $pluginName); |
| 84 | }); |
| 85 | }, 'core.wp_environment' => static function (ContainerInterface $container) : WpEnvironmentInterface { |
| 86 | /** @var WpEnvironmentFactoryInterface $environmentFactory */ |
| 87 | $environmentFactory = $container->get('core.wp_environment_factory'); |
| 88 | return $environmentFactory->createFromGlobals(); |
| 89 | }, 'core.wp_environment_factory' => static function (ContainerInterface $container) : WpEnvironmentFactoryInterface { |
| 90 | /** @var StringVersionFactoryInterface $versionFactory */ |
| 91 | $versionFactory = $container->get('core.string_version_factory'); |
| 92 | /** @var string $eventNameEnvironmentValidationFailed */ |
| 93 | $eventNameEnvironmentValidationFailed = $container->get('core.event_name_environment_validation_failed'); |
| 94 | return new WpEnvironmentFactory($versionFactory, $eventNameEnvironmentValidationFailed); |
| 95 | }, 'core.string_version_factory' => static function () : StringVersionFactoryInterface { |
| 96 | return new StringVersionFactory(); |
| 97 | }, 'core.event_name_environment_validation_failed' => static function () : string { |
| 98 | return 'wlop.environment_validation_failed'; |
| 99 | }, 'core.plugin.plugin_action_links.registry' => new Factory(['core.main_plugin_file', 'core.plugin.plugin_action_links', 'core.plugin.plugin_meta_links'], static function (string $mainFilePath, array $pluginActionLinks, array $pluginMetaLinks) : PluginActionLinkRegistry { |
| 100 | /** @var PluginActionLink[] $pluginActionLinks */ |
| 101 | return new PluginActionLinkRegistry(\plugin_basename($mainFilePath), $pluginActionLinks, $pluginMetaLinks); |
| 102 | }), 'core.main_plugin_file' => static function (ContainerInterface $container) : string { |
| 103 | /** @var PluginProperties $properties */ |
| 104 | $properties = $container->get(Package::PROPERTIES); |
| 105 | return \sprintf('%1$s/%2$s.php', $properties->basePath(), $properties->baseName()); |
| 106 | }, 'core.plugin.plugin_action_links' => new Factory(['core.http.settings_url'], static function (UriInterface $settingsUrl) : array { |
| 107 | return [new PluginActionLink('settings', \__('Settings', 'worldline-for-woocommerce'), $settingsUrl)]; |
| 108 | }), 'core.plugin.plugin_meta_links' => new Factory(['core.contact_us_url_builder'], static function (UriInterface $contactUsUrlBuilder) : array { |
| 109 | return [new PluginActionLink('contact_us', \__('Contact us', 'worldline-for-woocommerce'), $contactUsUrlBuilder, \true)]; |
| 110 | }), 'core.http.settings_url' => new Factory(['core.uri.factory'], static function (UriFactoryInterface $factory) : UriInterface { |
| 111 | return $factory->createUri(\sprintf('%s?%s', \admin_url('admin.php'), \http_build_query(['page' => 'wc-settings', 'tab' => 'checkout', 'section' => 'worldline-for-woocommerce']))); |
| 112 | }), 'core.contact_us_url' => new Value($config['CONTACT_URL']), 'core.documentation_url' => new Value($config['DOCUMENTATION_URL']), 'core.test_create_account_url' => new Value($config['TEST_CREATE_ACCOUNT_URL']), 'core.live_create_account_url' => new Value($config['LIVE_CREATE_ACCOUNT_URL']), 'core.test_view_account_url' => new Value($config['TEST_VIEW_ACCOUNT_URL']), 'core.live_view_account_url' => new Value($config['LIVE_VIEW_ACCOUNT_URL']), 'core.contact_us_url_builder' => new Factory(['core.uri.factory', 'core.contact_us_url'], static function (UriFactoryInterface $uriFactory, string $contactUsUrl) : UriInterface { |
| 113 | return $uriFactory->createUri($contactUsUrl); |
| 114 | }), 'core.uri.factory' => new Alias('uri.factory'), 'core.webhooks.namespace' => new Value('inpsyde/worldline-for-woocommerce'), 'core.webhooks.route' => new Value('/listener/notifications'), 'core.webhooks.notification_url' => new Factory(['webhooks.namespace', 'webhooks.rest_route', 'core.uri.factory'], static function (string $restNamespace, string $restRoute, UriFactoryInterface $uriFactory) : ?UriInterface { |
| 115 | $blogId = \get_current_blog_id(); |
| 116 | $path = $restNamespace . $restRoute; |
| 117 | try { |
| 118 | $restUrl = \get_rest_url($blogId, $path); |
| 119 | } catch (\Throwable $exception) { |
| 120 | return null; |
| 121 | } |
| 122 | return $uriFactory->createUri($restUrl); |
| 123 | }), 'inpsyde_logger.native_wc_logger' => static function () : \WC_Logger_Interface { |
| 124 | return \wc_get_logger(); |
| 125 | }, 'core.is_debug_logging_enabled' => new Alias('config.debug_logging'), 'core.is_logging_enabled' => new Factory(['core.is_debug_logging_enabled'], static function (bool $debugLogging) : bool { |
| 126 | return $debugLogging || \apply_filters('wlop.logging_enabled', \true); |
| 127 | }), 'core.admin.cancel_authorization_ui' => static function () : CancelAuthorizationUi { |
| 128 | return new CancelAuthorizationUi(); |
| 129 | }, 'core.admin.capture_authorization_ui' => static function () : CaptureAuthorizationUi { |
| 130 | return new CaptureAuthorizationUi(); |
| 131 | }]; |
| 132 | }; |
| 133 |