flexible-shipping
/
vendor_prefixed
/
octolize
/
wp-octolize-docs-chat
/
src
/
Chat
Last commit date
views
2 weeks ago
AjaxChatSettings.php
2 weeks ago
Assets.php
2 weeks ago
ChatContainer.php
2 weeks ago
ChatSettings.php
2 weeks ago
ChatSettingsProvider.php
2 weeks ago
ConsentSettings.php
2 weeks ago
DocsChat.php
2 weeks ago
HookableChatObjects.php
2 weeks ago
DocsChat.php
51 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace FSVendor\Octolize\Docs\Chat; |
| 5 | |
| 6 | use FSVendor\WPDesk\PluginBuilder\Plugin\Hookable; |
| 7 | use FSVendor\WPDesk\ShowDecision\ShouldShowStrategy; |
| 8 | /** |
| 9 | * Coordinates the reusable docs chat integration. |
| 10 | */ |
| 11 | final class DocsChat implements Hookable |
| 12 | { |
| 13 | private string $plugin_slug; |
| 14 | private string $plugin_url; |
| 15 | private string $plugin_version; |
| 16 | private ShouldShowStrategy $show_strategy; |
| 17 | private ChatSettingsProvider $settings_provider; |
| 18 | public function __construct(string $plugin_slug, string $plugin_url, string $plugin_version, ShouldShowStrategy $show_strategy, ChatSettingsProvider $settings_provider) |
| 19 | { |
| 20 | $this->plugin_slug = $plugin_slug; |
| 21 | $this->plugin_url = $plugin_url; |
| 22 | $this->plugin_version = $plugin_version; |
| 23 | $this->show_strategy = $show_strategy; |
| 24 | $this->settings_provider = $settings_provider; |
| 25 | } |
| 26 | public function hooks(): void |
| 27 | { |
| 28 | add_action('admin_init', [$this, 'initialize_chat']); |
| 29 | } |
| 30 | /** |
| 31 | * @internal |
| 32 | */ |
| 33 | public function initialize_chat(): void |
| 34 | { |
| 35 | add_filter('octolize_docs_chat_settings_' . $this->plugin_slug, [$this, 'prepare_chat_settings'], 10, 2); |
| 36 | (new HookableChatObjects($this->plugin_slug, $this->plugin_url, $this->plugin_version, $this->show_strategy))->hooks(); |
| 37 | } |
| 38 | /** |
| 39 | * @internal |
| 40 | * |
| 41 | * @param array<string, mixed> $settings Current chat settings. |
| 42 | * @param array<string, mixed> $request_data Request data. |
| 43 | * |
| 44 | * @return array<string, mixed> |
| 45 | */ |
| 46 | public function prepare_chat_settings(array $settings, array $request_data): array |
| 47 | { |
| 48 | return $this->settings_provider->prepare_settings($settings, $request_data); |
| 49 | } |
| 50 | } |
| 51 |