| 1 |
<?php |
| 2 |
|
| 3 |
// @phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- This namespace should reflect the namespace of the original class. |
| 4 |
namespace Yoast\WP\SEO\Editors\Framework\Integrations; |
| 5 |
|
| 6 |
use Yoast\WP\SEO\Editors\Domain\Integrations\Integration_Data_Provider_Interface; |
| 7 |
use Yoast\WP\SEO\Helpers\Options_Helper; |
| 8 |
use Yoast\WP\SEO\Helpers\Wincher_Helper; |
| 9 |
|
| 10 |
/** |
| 11 |
* Describes if the Wincher integration is enabled. |
| 12 |
*/ |
| 13 |
class Wincher implements Integration_Data_Provider_Interface { |
| 14 |
|
| 15 |
/** |
| 16 |
* The Wincher helper. |
| 17 |
* |
| 18 |
* @var Wincher_Helper |
| 19 |
*/ |
| 20 |
private $wincher_helper; |
| 21 |
|
| 22 |
/** |
| 23 |
* The options helper. |
| 24 |
* |
| 25 |
* @var Options_Helper |
| 26 |
*/ |
| 27 |
private $options_helper; |
| 28 |
|
| 29 |
/** |
| 30 |
* The constructor. |
| 31 |
* |
| 32 |
* @param Wincher_Helper $wincher_helper The Wincher helper. |
| 33 |
* @param Options_Helper $options_helper The options helper. |
| 34 |
*/ |
| 35 |
public function __construct( Wincher_Helper $wincher_helper, Options_Helper $options_helper ) { |
| 36 |
$this->wincher_helper = $wincher_helper; |
| 37 |
$this->options_helper = $options_helper; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* If the integration is activated. |
| 42 |
* |
| 43 |
* @return bool If the integration is activated. |
| 44 |
*/ |
| 45 |
public function is_enabled(): bool { |
| 46 |
return $this->wincher_helper->is_active(); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Return this object represented by a key value array. |
| 51 |
* |
| 52 |
* @return array<string, bool> Returns the name and if the feature is enabled. |
| 53 |
*/ |
| 54 |
public function to_array(): array { |
| 55 |
return [ |
| 56 |
'active' => $this->is_enabled(), |
| 57 |
'loginStatus' => $this->is_enabled() && $this->wincher_helper->login_status(), |
| 58 |
'websiteId' => $this->options_helper->get( 'wincher_website_id', '' ), |
| 59 |
'autoAddKeyphrases' => $this->options_helper->get( 'wincher_automatically_add_keyphrases', false ), |
| 60 |
]; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Returns this object represented by a key value structure that is compliant with the script data array. |
| 65 |
* |
| 66 |
* @return array<string, bool> Returns the legacy key and if the feature is enabled. |
| 67 |
*/ |
| 68 |
public function to_legacy_array(): array { |
| 69 |
return [ |
| 70 |
'wincherIntegrationActive' => $this->is_enabled(), |
| 71 |
'wincherLoginStatus' => $this->is_enabled() && $this->wincher_helper->login_status(), |
| 72 |
'wincherWebsiteId' => $this->options_helper->get( 'wincher_website_id', '' ), |
| 73 |
'wincherAutoAddKeyphrases' => $this->options_helper->get( 'wincher_automatically_add_keyphrases', false ), |
| 74 |
]; |
| 75 |
} |
| 76 |
} |
| 77 |
|