/var/www/html_uk/wp-content/plugins/automatewoo/includes/Tools/ToolsService.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php

namespace AutomateWoo\Tools;

use 
AutomateWoo\Guest_Eraser;
use 
AutomateWoo\Options;
use 
AutomateWoo\OptionsStore;
use 
AutomateWoo\Tool_Abstract;
use 
AutomateWoo\Tool_Optin_Importer;
use 
AutomateWoo\Tool_Optout_Importer;
use 
AutomateWoo\Tool_Reset_Workflow_Records;

/**
 * Tools service class.
 *
 * @since 5.2.0
 */
class ToolsService {

    
/**
     * @var Tool_Abstract[] $tools
     */
    
protected $tools;

    
/**
     * @var OptionsStore
     */
    
protected $options_store;

    
/**
     * @param OptionsStore $options_store
     */
    
public function __constructOptionsStore $options_store ) {
        
$this->options_store $options_store;
    }

    
/**
     * Get all tools.
     *
     * @return Tool_Abstract[]
     */
    
public function get_tools() {
        if ( isset( 
$this->tools ) ) {
            return 
$this->tools;
        }

        
$class_names = [];

        
$class_names[] = $this->options_store->get_optin_enabled() ? Tool_Optin_Importer::class : Tool_Optout_Importer::class;
        
$class_names[] = Guest_Eraser::class;
        
$class_names[] = Tool_Reset_Workflow_Records::class;

        
$class_names apply_filters'automatewoo/tools'$class_names );

        foreach ( 
$class_names as $tool_class ) {
            
/** @var Tool_Abstract $class */
            
$class                           = new $tool_class();
            
$this->tools$class->get_id() ] = $class;
        }

        return 
$this->tools;
    }

    
/**
     * Get a single tool.
     *
     * @param string $id
     *
     * @return Tool_Abstract|false
     */
    
public function get_toolstring $id ) {
        
$tools $this->get_tools();

        if ( isset( 
$tools$id ] ) ) {
            return 
$tools$id ];
        }

        return 
false;
    }
}