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
bootstrap.php
59 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace Syde\Vendor\Worldline; |
| 5 | |
| 6 | use Syde\Vendor\Worldline\Inpsyde\Modularity\Module\Module; |
| 7 | use Syde\Vendor\Worldline\Inpsyde\Modularity\Package; |
| 8 | use Syde\Vendor\Worldline\Inpsyde\WorldlineForWoocommerce\Core\WorldlineProperties; |
| 9 | return static function (string $mainPluginFile, callable $onError, Module ...$modules) : Package { |
| 10 | $autoload = \dirname($mainPluginFile) . '/vendor/autoload.php'; |
| 11 | /** Older Woocommerce versions don't set version plugin headers. |
| 12 | * Here we set a version header "WC requires at least", so we are able |
| 13 | * to read the version from plugin properties when needed. |
| 14 | */ |
| 15 | \add_filter('extra_plugin_headers', static function (array $headers) { |
| 16 | $wcVersionHeader = 'WC requires at least'; |
| 17 | if (!\in_array($wcVersionHeader, $headers, \true)) { |
| 18 | $headers[] = $wcVersionHeader; |
| 19 | } |
| 20 | return $headers; |
| 21 | }, 999); |
| 22 | if (\is_readable($autoload)) { |
| 23 | /** |
| 24 | * @psalm-suppress UnresolvableInclude |
| 25 | */ |
| 26 | include_once $autoload; |
| 27 | } |
| 28 | $properties = WorldlineProperties::new($mainPluginFile); |
| 29 | $package = Package::new($properties); |
| 30 | \add_action($package->hookName(Package::ACTION_FAILED_BOOT), $onError); |
| 31 | /** |
| 32 | * @psalm-suppress MissingClosureParamType |
| 33 | * |
| 34 | * WP 6.7.0 changed the way textdomains are loaded. |
| 35 | * Calling load_plugin_textdomain too early now produces a notice. |
| 36 | * However, the just-in-time-loading early only checks wp-content/languages by default. |
| 37 | * So we currently do not have a safe way to expose our plugin path, |
| 38 | * resulting in potentially missing translations. |
| 39 | * We're keeping both paths, hoping there are going to be amendments for this in future releases |
| 40 | * |
| 41 | * First, we force our plugin languages path into the textdomain loading system. |
| 42 | */ |
| 43 | \add_filter('lang_dir_for_domain', static function ($dir, $domain) { |
| 44 | if ($domain !== 'worldline-for-woocommerce') { |
| 45 | return $dir; |
| 46 | } |
| 47 | return \WP_PLUGIN_DIR . '/worldline-for-woocommerce/languages/'; |
| 48 | }, 10, 3); |
| 49 | /** |
| 50 | * Now we expose our custom path safely. |
| 51 | */ |
| 52 | \add_action('init', static fn() => \load_plugin_textdomain('worldline-for-woocommerce')); |
| 53 | foreach ($modules as $module) { |
| 54 | $package->addModule($module); |
| 55 | } |
| 56 | $package->boot(); |
| 57 | return $package; |
| 58 | }; |
| 59 |