mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Use Composer modules and convert modules to PSR-4
PSR-4 is much more robust and predictable. But to do this, a source root dir must be specified for every module. This could be done in the root file, but this is not very modular. Instead, now every module declares its own source root by using the amazing Composer Merge Plugin. This approach allows each module to also declare its own dependencies. Together, these changes allow modules to be easily extractable to separate pacakges when the need arises, and in general improves modularity significantly.
This commit is contained in:
parent
45db097bd8
commit
d4c8282518
157 changed files with 168 additions and 8 deletions
60
modules/ppcp-onboarding/src/Environment.php
Normal file
60
modules/ppcp-onboarding/src/Environment.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
/**
|
||||
* Used to detect the current environment.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Onboarding
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Onboarding;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Class Environment
|
||||
*/
|
||||
class Environment {
|
||||
|
||||
|
||||
const PRODUCTION = 'production';
|
||||
const SANDBOX = 'sandbox';
|
||||
|
||||
/**
|
||||
* The Settings.
|
||||
*
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
private $settings;
|
||||
|
||||
/**
|
||||
* Environment constructor.
|
||||
*
|
||||
* @param ContainerInterface $settings The Settings.
|
||||
*/
|
||||
public function __construct( ContainerInterface $settings ) {
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current environment.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function current_environment(): string {
|
||||
return (
|
||||
$this->settings->has( 'sandbox_on' ) && $this->settings->get( 'sandbox_on' )
|
||||
) ? self::SANDBOX : self::PRODUCTION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect whether the current environment equals $environment
|
||||
*
|
||||
* @param string $environment The value to check against.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function current_environment_is( string $environment ): bool {
|
||||
return $this->current_environment() === $environment;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue