Completed
Pull Request — master (#331)
by Darren
20:21 queued 06:28
created
core/domain/entities/editor/EditorBlockCollection.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -20,55 +20,55 @@
 block discarded – undo
20 20
 class EditorBlockCollection extends Collection
21 21
 {
22 22
 
23
-    /**
24
-     * Collection constructor
25
-     *
26
-     * @throws InvalidInterfaceException
27
-     */
28
-    public function __construct()
29
-    {
30
-        parent::__construct('EventEspresso\core\domain\entities\editor\EditorBlockInterface');
31
-    }
23
+	/**
24
+	 * Collection constructor
25
+	 *
26
+	 * @throws InvalidInterfaceException
27
+	 */
28
+	public function __construct()
29
+	{
30
+		parent::__construct('EventEspresso\core\domain\entities\editor\EditorBlockInterface');
31
+	}
32 32
 
33 33
 
34
-    /**
35
-     * unRegisterBlock
36
-     * finds block in the Collection based on the identifier that was set using addObject()
37
-     * and calls unRegisterBlock() on it. Returns block if successful and false if block was not found.
38
-     * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards
39
-     *
40
-     * @param mixed $identifier
41
-     * @return boolean
42
-     */
43
-    public function unRegisterBlock($identifier)
44
-    {
45
-        $this->rewind();
46
-        while ($this->valid()) {
47
-            if ($identifier === $this->getInfo()) {
48
-                $object = $this->current();
49
-                $this->rewind();
50
-                return $object->unRegisterBlock();
51
-            }
52
-            $this->next();
53
-        }
54
-        return false;
55
-    }
34
+	/**
35
+	 * unRegisterBlock
36
+	 * finds block in the Collection based on the identifier that was set using addObject()
37
+	 * and calls unRegisterBlock() on it. Returns block if successful and false if block was not found.
38
+	 * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards
39
+	 *
40
+	 * @param mixed $identifier
41
+	 * @return boolean
42
+	 */
43
+	public function unRegisterBlock($identifier)
44
+	{
45
+		$this->rewind();
46
+		while ($this->valid()) {
47
+			if ($identifier === $this->getInfo()) {
48
+				$object = $this->current();
49
+				$this->rewind();
50
+				return $object->unRegisterBlock();
51
+			}
52
+			$this->next();
53
+		}
54
+		return false;
55
+	}
56 56
 
57 57
 
58
-    /**
59
-     * unRegisterAllBlocks
60
-     * calls unRegisterBlock() on all blocks in Collection.
61
-     * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards
62
-     *
63
-     * @return void
64
-     */
65
-    public function unRegisterAllBlocks()
66
-    {
67
-        $this->rewind();
68
-        while ($this->valid()) {
69
-            $this->current()->unRegisterBlock();
70
-            $this->next();
71
-        }
72
-        $this->rewind();
73
-    }
58
+	/**
59
+	 * unRegisterAllBlocks
60
+	 * calls unRegisterBlock() on all blocks in Collection.
61
+	 * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards
62
+	 *
63
+	 * @return void
64
+	 */
65
+	public function unRegisterAllBlocks()
66
+	{
67
+		$this->rewind();
68
+		while ($this->valid()) {
69
+			$this->current()->unRegisterBlock();
70
+			$this->next();
71
+		}
72
+		$this->rewind();
73
+	}
74 74
 }
Please login to merge, or discard this patch.
core/domain/entities/editor/EditorBlockInterface.php 1 patch
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -25,72 +25,72 @@
 block discarded – undo
25 25
 interface EditorBlockInterface
26 26
 {
27 27
 
28
-    /**
29
-     * Perform any early setup required by the block
30
-     * including setting the block type and supported post types
31
-     *
32
-     * @return void
33
-     */
34
-    public function initialize();
35
-
36
-
37
-    /**
38
-     * @return string
39
-     */
40
-    public function editorBlockType();
41
-
42
-
43
-    /**
44
-     * Registers the Editor Block with WP core;
45
-     * Returns the registered block type on success, or false on failure.
46
-     *
47
-     * @return WP_Block_Type|false
48
-     */
49
-    public function registerBlock();
50
-
51
-
52
-    /**
53
-     * Un-registers the Editor Block with WP core;
54
-     * Returns the registered block type on success, or false on failure.
55
-     *
56
-     * @return WP_Block_Type|false
57
-     */
58
-    public function unRegisterBlock();
59
-
60
-
61
-    /**
62
-     * returns true if the block type applies for the supplied post type
63
-     * and should be added to that post type's editor
64
-     *
65
-     * @param string $post_type
66
-     * @return boolean
67
-     */
68
-    public function appliesToPostType($post_type);
69
-
70
-
71
-    /**
72
-     * @return array
73
-     */
74
-    public function getEditorContainer();
75
-
76
-
77
-    /**
78
-     * @return  void
79
-     */
80
-    public function registerScripts();
81
-
82
-
83
-    /**
84
-     * @return void
85
-     */
86
-    public function registerStyles();
87
-
88
-
89
-    /**
90
-     * returns the rendered HTML for the block
91
-     *
92
-     * @param array $attributes
93
-     * @return string
94
-     */
95
-    public function renderBlock(array $attributes = array());
28
+	/**
29
+	 * Perform any early setup required by the block
30
+	 * including setting the block type and supported post types
31
+	 *
32
+	 * @return void
33
+	 */
34
+	public function initialize();
35
+
36
+
37
+	/**
38
+	 * @return string
39
+	 */
40
+	public function editorBlockType();
41
+
42
+
43
+	/**
44
+	 * Registers the Editor Block with WP core;
45
+	 * Returns the registered block type on success, or false on failure.
46
+	 *
47
+	 * @return WP_Block_Type|false
48
+	 */
49
+	public function registerBlock();
50
+
51
+
52
+	/**
53
+	 * Un-registers the Editor Block with WP core;
54
+	 * Returns the registered block type on success, or false on failure.
55
+	 *
56
+	 * @return WP_Block_Type|false
57
+	 */
58
+	public function unRegisterBlock();
59
+
60
+
61
+	/**
62
+	 * returns true if the block type applies for the supplied post type
63
+	 * and should be added to that post type's editor
64
+	 *
65
+	 * @param string $post_type
66
+	 * @return boolean
67
+	 */
68
+	public function appliesToPostType($post_type);
69
+
70
+
71
+	/**
72
+	 * @return array
73
+	 */
74
+	public function getEditorContainer();
75
+
76
+
77
+	/**
78
+	 * @return  void
79
+	 */
80
+	public function registerScripts();
81
+
82
+
83
+	/**
84
+	 * @return void
85
+	 */
86
+	public function registerStyles();
87
+
88
+
89
+	/**
90
+	 * returns the rendered HTML for the block
91
+	 *
92
+	 * @param array $attributes
93
+	 * @return string
94
+	 */
95
+	public function renderBlock(array $attributes = array());
96 96
 }
Please login to merge, or discard this patch.
core/domain/DomainInterface.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -16,61 +16,61 @@
 block discarded – undo
16 16
 interface DomainInterface extends InterminableInterface
17 17
 {
18 18
 
19
-    /**
20
-     * @return string
21
-     * @throws DomainException
22
-     */
23
-    public function pluginFile();
19
+	/**
20
+	 * @return string
21
+	 * @throws DomainException
22
+	 */
23
+	public function pluginFile();
24 24
 
25 25
 
26
-    /**
27
-     * @return string
28
-     * @throws DomainException
29
-     */
30
-    public function pluginBasename();
26
+	/**
27
+	 * @return string
28
+	 * @throws DomainException
29
+	 */
30
+	public function pluginBasename();
31 31
 
32 32
 
33
-    /**
34
-     * @return string
35
-     */
36
-    public function pluginPath();
33
+	/**
34
+	 * @return string
35
+	 */
36
+	public function pluginPath();
37 37
 
38 38
 
39
-    /**
40
-     * @return string
41
-     * @throws DomainException
42
-     */
43
-    public function pluginUrl();
39
+	/**
40
+	 * @return string
41
+	 * @throws DomainException
42
+	 */
43
+	public function pluginUrl();
44 44
 
45 45
 
46
-    /**
47
-     * @return string
48
-     * @throws DomainException
49
-     */
50
-    public function version();
46
+	/**
47
+	 * @return string
48
+	 * @throws DomainException
49
+	 */
50
+	public function version();
51 51
 
52 52
 
53
-    /**
54
-     * @return string
55
-     */
56
-    public function sourceAssetsPath();
53
+	/**
54
+	 * @return string
55
+	 */
56
+	public function sourceAssetsPath();
57 57
 
58 58
 
59
-    /**
60
-     * @return string
61
-     */
62
-    public function sourceAssetsUrl();
59
+	/**
60
+	 * @return string
61
+	 */
62
+	public function sourceAssetsUrl();
63 63
 
64 64
 
65
-    /**
66
-     * @return string
67
-     */
68
-    public function distributionAssetsPath();
65
+	/**
66
+	 * @return string
67
+	 */
68
+	public function distributionAssetsPath();
69 69
 
70 70
 
71
-    /**
72
-     * @return string
73
-     */
74
-    public function distributionAssetsUrl();
71
+	/**
72
+	 * @return string
73
+	 */
74
+	public function distributionAssetsUrl();
75 75
 
76 76
 }
Please login to merge, or discard this patch.
core/domain/DomainBase.php 2 patches
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -19,144 +19,144 @@
 block discarded – undo
19 19
 abstract class DomainBase implements DomainInterface
20 20
 {
21 21
 
22
-    /**
23
-     * Equivalent to `__FILE__` for main plugin file.
24
-     *
25
-     * @var FilePath
26
-     */
27
-    private $plugin_file;
22
+	/**
23
+	 * Equivalent to `__FILE__` for main plugin file.
24
+	 *
25
+	 * @var FilePath
26
+	 */
27
+	private $plugin_file;
28 28
 
29
-    /**
30
-     * String indicating version for plugin
31
-     *
32
-     * @var string
33
-     */
34
-    private $version;
35
-
36
-    /**
37
-     * @var string $plugin_basename
38
-     */
39
-    private $plugin_basename;
40
-
41
-    /**
42
-     * @var string $plugin_path
43
-     */
44
-    private $plugin_path;
45
-
46
-    /**
47
-     * @var string $plugin_url
48
-     */
49
-    private $plugin_url;
50
-
51
-
52
-
53
-    /**
54
-     * Initializes internal properties.
55
-     *
56
-     * @param FilePath $plugin_file
57
-     * @param Version  $version
58
-     */
59
-    public function __construct(FilePath $plugin_file, Version $version)
60
-    {
61
-        $this->plugin_file = $plugin_file;
62
-        $this->version = $version;
63
-        $this->plugin_basename = plugin_basename($this->pluginFile());
64
-        $this->plugin_path = plugin_dir_path($this->pluginFile());
65
-        $this->plugin_url = plugin_dir_url($this->pluginFile());
66
-    }
67
-
68
-
69
-    /**
70
-     * @return string
71
-     */
72
-    public function pluginFile()
73
-    {
74
-        return (string) $this->plugin_file;
75
-    }
76
-
77
-
78
-
79
-    /**
80
-     * @return string
81
-     */
82
-    public function pluginBasename()
83
-    {
84
-        return $this->plugin_basename;
85
-    }
86
-
87
-
88
-
89
-    /**
90
-     * @return string
91
-     */
92
-    public function pluginPath()
93
-    {
94
-        return $this->plugin_path;
95
-    }
96
-
97
-
98
-
99
-    /**
100
-     * @return string
101
-     */
102
-    public function pluginUrl()
103
-    {
104
-        return $this->plugin_url;
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * @return string
111
-     */
112
-    public function version()
113
-    {
114
-        return (string) $this->version;
115
-    }
116
-
117
-
118
-
119
-    /**
120
-     * @return Version
121
-     */
122
-    public function versionValueObject()
123
-    {
124
-        return $this->version;
125
-    }
126
-
127
-
128
-    /**
129
-     * @return string
130
-     */
131
-    public function sourceAssetsPath()
132
-    {
133
-        return $this->pluginPath() . 'assets/src/';
134
-    }
29
+	/**
30
+	 * String indicating version for plugin
31
+	 *
32
+	 * @var string
33
+	 */
34
+	private $version;
35
+
36
+	/**
37
+	 * @var string $plugin_basename
38
+	 */
39
+	private $plugin_basename;
40
+
41
+	/**
42
+	 * @var string $plugin_path
43
+	 */
44
+	private $plugin_path;
45
+
46
+	/**
47
+	 * @var string $plugin_url
48
+	 */
49
+	private $plugin_url;
50
+
51
+
52
+
53
+	/**
54
+	 * Initializes internal properties.
55
+	 *
56
+	 * @param FilePath $plugin_file
57
+	 * @param Version  $version
58
+	 */
59
+	public function __construct(FilePath $plugin_file, Version $version)
60
+	{
61
+		$this->plugin_file = $plugin_file;
62
+		$this->version = $version;
63
+		$this->plugin_basename = plugin_basename($this->pluginFile());
64
+		$this->plugin_path = plugin_dir_path($this->pluginFile());
65
+		$this->plugin_url = plugin_dir_url($this->pluginFile());
66
+	}
67
+
68
+
69
+	/**
70
+	 * @return string
71
+	 */
72
+	public function pluginFile()
73
+	{
74
+		return (string) $this->plugin_file;
75
+	}
76
+
77
+
78
+
79
+	/**
80
+	 * @return string
81
+	 */
82
+	public function pluginBasename()
83
+	{
84
+		return $this->plugin_basename;
85
+	}
86
+
87
+
88
+
89
+	/**
90
+	 * @return string
91
+	 */
92
+	public function pluginPath()
93
+	{
94
+		return $this->plugin_path;
95
+	}
96
+
97
+
98
+
99
+	/**
100
+	 * @return string
101
+	 */
102
+	public function pluginUrl()
103
+	{
104
+		return $this->plugin_url;
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * @return string
111
+	 */
112
+	public function version()
113
+	{
114
+		return (string) $this->version;
115
+	}
116
+
117
+
118
+
119
+	/**
120
+	 * @return Version
121
+	 */
122
+	public function versionValueObject()
123
+	{
124
+		return $this->version;
125
+	}
126
+
127
+
128
+	/**
129
+	 * @return string
130
+	 */
131
+	public function sourceAssetsPath()
132
+	{
133
+		return $this->pluginPath() . 'assets/src/';
134
+	}
135 135
 
136
-
137
-    /**
138
-     * @return string
139
-     */
140
-    public function sourceAssetsUrl()
141
-    {
142
-        return $this->pluginUrl() . 'assets/src/';
143
-    }
136
+
137
+	/**
138
+	 * @return string
139
+	 */
140
+	public function sourceAssetsUrl()
141
+	{
142
+		return $this->pluginUrl() . 'assets/src/';
143
+	}
144 144
 
145 145
 
146
-    /**
147
-     * @return string
148
-     */
149
-    public function distributionAssetsPath()
150
-    {
151
-        return $this->pluginPath() . 'assets/dist/';
152
-    }
153
-
154
-
155
-    /**
156
-     * @return string
157
-     */
158
-    public function distributionAssetsUrl()
159
-    {
160
-        return $this->pluginUrl() . 'assets/dist/';
161
-    }
146
+	/**
147
+	 * @return string
148
+	 */
149
+	public function distributionAssetsPath()
150
+	{
151
+		return $this->pluginPath() . 'assets/dist/';
152
+	}
153
+
154
+
155
+	/**
156
+	 * @return string
157
+	 */
158
+	public function distributionAssetsUrl()
159
+	{
160
+		return $this->pluginUrl() . 'assets/dist/';
161
+	}
162 162
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      */
131 131
     public function sourceAssetsPath()
132 132
     {
133
-        return $this->pluginPath() . 'assets/src/';
133
+        return $this->pluginPath().'assets/src/';
134 134
     }
135 135
 
136 136
 
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
      */
140 140
     public function sourceAssetsUrl()
141 141
     {
142
-        return $this->pluginUrl() . 'assets/src/';
142
+        return $this->pluginUrl().'assets/src/';
143 143
     }
144 144
 
145 145
 
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
      */
149 149
     public function distributionAssetsPath()
150 150
     {
151
-        return $this->pluginPath() . 'assets/dist/';
151
+        return $this->pluginPath().'assets/dist/';
152 152
     }
153 153
 
154 154
 
@@ -157,6 +157,6 @@  discard block
 block discarded – undo
157 157
      */
158 158
     public function distributionAssetsUrl()
159 159
     {
160
-        return $this->pluginUrl() . 'assets/dist/';
160
+        return $this->pluginUrl().'assets/dist/';
161 161
     }
162 162
 }
Please login to merge, or discard this patch.
core/services/editor/EditorBlockRegistrationManager.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
             foreach ($this->blocks as $block) {
144 144
                 // perform any setup required for the block
145 145
                 $block_type = $block->registerBlock();
146
-                if (! $block_type instanceof WP_Block_Type) {
146
+                if ( ! $block_type instanceof WP_Block_Type) {
147 147
                     throw new InvalidEntityException($block_type, 'WP_Block_Type');
148 148
                 }
149 149
                 add_action('enqueue_block_assets', array($block, 'registerStyles'));
@@ -178,9 +178,9 @@  discard block
 block discarded – undo
178 178
             $this->assets_registry->getAssetUrl(Registry::ASSET_NAMESPACE, 'core-blocks', Registry::ASSET_TYPE_JS),
179 179
             array(
180 180
                 'eejs-core',
181
-                'wp-blocks',    // Provides useful functions and components for extending the editor
182
-                'wp-i18n',      // Provides localization functions
183
-                'wp-element',   // Provides React.Component
181
+                'wp-blocks', // Provides useful functions and components for extending the editor
182
+                'wp-i18n', // Provides localization functions
183
+                'wp-element', // Provides React.Component
184 184
                 'wp-components' // Provides many prebuilt components and controls
185 185
             ),
186 186
             null,
Please login to merge, or discard this patch.
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -34,153 +34,153 @@
 block discarded – undo
34 34
 class EditorBlockRegistrationManager extends EditorBlockManager
35 35
 {
36 36
 
37
-    /**
38
-     *  Returns the name of a hookpoint to be used to call initialize()
39
-     *
40
-     * @return string
41
-     */
42
-    public function initHook()
43
-    {
44
-        return 'AHEE__EE_System__set_hooks_for_core';
45
-    }
46
-
47
-
48
-    /**
49
-     * Perform any early setup required for block editors to functions
50
-     *
51
-     * @return void
52
-     * @throws Exception
53
-     */
54
-    public function initialize()
55
-    {
56
-        $this->loadEditorBlocks();
57
-        add_action('AHEE__EE_System__initialize', array($this, 'registerEditorBlocks'));
58
-    }
59
-
60
-
61
-    /**
62
-     * @return CollectionInterface|EditorBlockInterface[]
63
-     * @throws ReflectionException
64
-     * @throws InvalidArgumentException
65
-     * @throws EE_Error
66
-     * @throws InvalidClassException
67
-     * @throws InvalidDataTypeException
68
-     * @throws InvalidEntityException
69
-     * @throws InvalidFilePathException
70
-     * @throws InvalidIdentifierException
71
-     * @throws InvalidInterfaceException
72
-     */
73
-    protected function populateEditorBlockCollection()
74
-    {
75
-        $loader = new CollectionLoader(
76
-            new CollectionDetails(
77
-                // collection name
78
-                'shortcodes',
79
-                // collection interface
80
-                'EventEspresso\core\domain\entities\editor\EditorBlockInterface',
81
-                // FQCNs for classes to add (all classes within each namespace will be loaded)
82
-                apply_filters(
83
-                    'FHEE__EventEspresso_core_services_editor_EditorBlockManager__populateEditorBlockCollection__collection_FQCNs',
84
-                    array()
85
-                    // array(
86
-                    //     'EventEspresso\core\domain\entities\editor\blocks\common',
87
-                    //     'EventEspresso\core\domain\entities\editor\blocks\editor',
88
-                    //     'EventEspresso\core\domain\entities\editor\blocks\shortcodes',
89
-                    //     'EventEspresso\core\domain\entities\editor\blocks\widgets',
90
-                    // )
91
-                ),
92
-                // filepaths to classes to add
93
-                array(),
94
-                // file mask to use if parsing folder for files to add
95
-                '',
96
-                // what to use as identifier for collection entities
97
-                // using CLASS NAME prevents duplicates (works like a singleton)
98
-                CollectionDetails::ID_CLASS_NAME
99
-            ),
100
-            $this->blocks
101
-        );
102
-        return $loader->getCollection();
103
-    }
104
-
105
-
106
-    /**
107
-     * populates the EditorBlockCollection and calls initialize() on all installed blocks
108
-     *
109
-     * @return void
110
-     * @throws Exception
111
-     */
112
-    public function loadEditorBlocks()
113
-    {
114
-        try {
115
-            $this->populateEditorBlockCollection();
116
-            // cycle thru block loaders and initialize each loader
117
-            foreach ($this->blocks as $block) {
118
-                $block->initialize();
119
-            }
120
-        } catch (Exception $exception) {
121
-            new ExceptionStackTraceDisplay($exception);
122
-        }
123
-    }
124
-
125
-
126
-    /**
127
-     * calls registerBlock() and load assets for all installed blocks
128
-     *
129
-     * @return void
130
-     * @throws Exception
131
-     */
132
-    public function registerEditorBlocks()
133
-    {
134
-        try {
135
-            // register primary assets
136
-            add_action('enqueue_block_assets', array($this, 'registerStyles'));
137
-            add_action('enqueue_block_assets', array($this, 'registerScripts'));
138
-            // cycle thru block loader folders
139
-            foreach ($this->blocks as $block) {
140
-                // perform any setup required for the block
141
-                $block_type = $block->registerBlock();
142
-                if (! $block_type instanceof WP_Block_Type) {
143
-                    throw new InvalidEntityException($block_type, 'WP_Block_Type');
144
-                }
145
-                add_action('enqueue_block_assets', array($block, 'registerStyles'));
146
-                add_action('enqueue_block_assets', array($block, 'registerScripts'));
147
-                do_action(
148
-                    'FHEE__EventEspresso_core_services_editor_EditorBlockManager__registerEditorBlocks__block_type_registered',
149
-                    $block,
150
-                    $block_type
151
-                );
152
-            }
153
-        } catch (Exception $exception) {
154
-            new ExceptionStackTraceDisplay($exception);
155
-        }
156
-    }
157
-
158
-
159
-    public function registerStyles()
160
-    {
161
-        // wp_register_style(
162
-        //     'ee-block-styles',
163
-        //     $this->domain->distributionAssetsUrl() . 'style.css',
164
-        //     array(),
165
-        //     filemtime($this->domain->distributionAssetsPath() . 'style.css')
166
-        // );
167
-    }
168
-
169
-
170
-    public function registerScripts()
171
-    {
172
-        wp_register_script(
173
-            'ee-core-blocks',
174
-            $this->assets_registry->getAssetUrl(Registry::ASSET_NAMESPACE, 'core-blocks', Registry::ASSET_TYPE_JS),
175
-            array(
176
-                'eejs-core',
177
-                'wp-blocks',    // Provides useful functions and components for extending the editor
178
-                'wp-i18n',      // Provides localization functions
179
-                'wp-element',   // Provides React.Component
180
-                'wp-components' // Provides many prebuilt components and controls
181
-            ),
182
-            null,
183
-            true
184
-        );
185
-    }
37
+	/**
38
+	 *  Returns the name of a hookpoint to be used to call initialize()
39
+	 *
40
+	 * @return string
41
+	 */
42
+	public function initHook()
43
+	{
44
+		return 'AHEE__EE_System__set_hooks_for_core';
45
+	}
46
+
47
+
48
+	/**
49
+	 * Perform any early setup required for block editors to functions
50
+	 *
51
+	 * @return void
52
+	 * @throws Exception
53
+	 */
54
+	public function initialize()
55
+	{
56
+		$this->loadEditorBlocks();
57
+		add_action('AHEE__EE_System__initialize', array($this, 'registerEditorBlocks'));
58
+	}
59
+
60
+
61
+	/**
62
+	 * @return CollectionInterface|EditorBlockInterface[]
63
+	 * @throws ReflectionException
64
+	 * @throws InvalidArgumentException
65
+	 * @throws EE_Error
66
+	 * @throws InvalidClassException
67
+	 * @throws InvalidDataTypeException
68
+	 * @throws InvalidEntityException
69
+	 * @throws InvalidFilePathException
70
+	 * @throws InvalidIdentifierException
71
+	 * @throws InvalidInterfaceException
72
+	 */
73
+	protected function populateEditorBlockCollection()
74
+	{
75
+		$loader = new CollectionLoader(
76
+			new CollectionDetails(
77
+				// collection name
78
+				'shortcodes',
79
+				// collection interface
80
+				'EventEspresso\core\domain\entities\editor\EditorBlockInterface',
81
+				// FQCNs for classes to add (all classes within each namespace will be loaded)
82
+				apply_filters(
83
+					'FHEE__EventEspresso_core_services_editor_EditorBlockManager__populateEditorBlockCollection__collection_FQCNs',
84
+					array()
85
+					// array(
86
+					//     'EventEspresso\core\domain\entities\editor\blocks\common',
87
+					//     'EventEspresso\core\domain\entities\editor\blocks\editor',
88
+					//     'EventEspresso\core\domain\entities\editor\blocks\shortcodes',
89
+					//     'EventEspresso\core\domain\entities\editor\blocks\widgets',
90
+					// )
91
+				),
92
+				// filepaths to classes to add
93
+				array(),
94
+				// file mask to use if parsing folder for files to add
95
+				'',
96
+				// what to use as identifier for collection entities
97
+				// using CLASS NAME prevents duplicates (works like a singleton)
98
+				CollectionDetails::ID_CLASS_NAME
99
+			),
100
+			$this->blocks
101
+		);
102
+		return $loader->getCollection();
103
+	}
104
+
105
+
106
+	/**
107
+	 * populates the EditorBlockCollection and calls initialize() on all installed blocks
108
+	 *
109
+	 * @return void
110
+	 * @throws Exception
111
+	 */
112
+	public function loadEditorBlocks()
113
+	{
114
+		try {
115
+			$this->populateEditorBlockCollection();
116
+			// cycle thru block loaders and initialize each loader
117
+			foreach ($this->blocks as $block) {
118
+				$block->initialize();
119
+			}
120
+		} catch (Exception $exception) {
121
+			new ExceptionStackTraceDisplay($exception);
122
+		}
123
+	}
124
+
125
+
126
+	/**
127
+	 * calls registerBlock() and load assets for all installed blocks
128
+	 *
129
+	 * @return void
130
+	 * @throws Exception
131
+	 */
132
+	public function registerEditorBlocks()
133
+	{
134
+		try {
135
+			// register primary assets
136
+			add_action('enqueue_block_assets', array($this, 'registerStyles'));
137
+			add_action('enqueue_block_assets', array($this, 'registerScripts'));
138
+			// cycle thru block loader folders
139
+			foreach ($this->blocks as $block) {
140
+				// perform any setup required for the block
141
+				$block_type = $block->registerBlock();
142
+				if (! $block_type instanceof WP_Block_Type) {
143
+					throw new InvalidEntityException($block_type, 'WP_Block_Type');
144
+				}
145
+				add_action('enqueue_block_assets', array($block, 'registerStyles'));
146
+				add_action('enqueue_block_assets', array($block, 'registerScripts'));
147
+				do_action(
148
+					'FHEE__EventEspresso_core_services_editor_EditorBlockManager__registerEditorBlocks__block_type_registered',
149
+					$block,
150
+					$block_type
151
+				);
152
+			}
153
+		} catch (Exception $exception) {
154
+			new ExceptionStackTraceDisplay($exception);
155
+		}
156
+	}
157
+
158
+
159
+	public function registerStyles()
160
+	{
161
+		// wp_register_style(
162
+		//     'ee-block-styles',
163
+		//     $this->domain->distributionAssetsUrl() . 'style.css',
164
+		//     array(),
165
+		//     filemtime($this->domain->distributionAssetsPath() . 'style.css')
166
+		// );
167
+	}
168
+
169
+
170
+	public function registerScripts()
171
+	{
172
+		wp_register_script(
173
+			'ee-core-blocks',
174
+			$this->assets_registry->getAssetUrl(Registry::ASSET_NAMESPACE, 'core-blocks', Registry::ASSET_TYPE_JS),
175
+			array(
176
+				'eejs-core',
177
+				'wp-blocks',    // Provides useful functions and components for extending the editor
178
+				'wp-i18n',      // Provides localization functions
179
+				'wp-element',   // Provides React.Component
180
+				'wp-components' // Provides many prebuilt components and controls
181
+			),
182
+			null,
183
+			true
184
+		);
185
+	}
186 186
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Line_Item.model.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -429,7 +429,7 @@
 block discarded – undo
429 429
      * If $expired is set to true, then only line items for expired sessions will be returned.
430 430
      * If $expired is set to false, then only line items for active sessions will be returned.
431 431
      *
432
-     * @param null $expired
432
+     * @param boolean $expired
433 433
      * @return EE_Base_Class[]|EE_Line_Item[]
434 434
      * @throws InvalidInterfaceException
435 435
      * @throws InvalidDataTypeException
Please login to merge, or discard this patch.
Indentation   +438 added lines, -438 removed lines patch added patch discarded remove patch
@@ -32,445 +32,445 @@
 block discarded – undo
32 32
 class EEM_Line_Item extends EEM_Base
33 33
 {
34 34
 
35
-    /**
36
-     * Tax sub-total is just the total of all the taxes, which should be children
37
-     * of this line item. There should only ever be one tax sub-total, and it should
38
-     * be a direct child of. Its quantity and LIN_unit_price = 1.
39
-     */
40
-    const type_tax_sub_total = 'tax-sub-total';
41
-
42
-    /**
43
-     * Tax line items indicate a tax applied to all the taxable line items.
44
-     * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal
45
-     * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1.
46
-     */
47
-    const type_tax = 'tax';
48
-
49
-    /**
50
-     * Indicating individual items purchased, or discounts or surcharges.
51
-     * The sum of all the regular line items  plus the tax items should equal
52
-     * the grand total.
53
-     * Possible children are sub-line-items and cancellations.
54
-     * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children
55
-     * LIN_totals. Its LIN_percent = 0.
56
-     * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1).
57
-     * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1.
58
-     */
59
-    const type_line_item = 'line-item';
60
-
61
-    /**
62
-     * Line item indicating all the factors that make a single line item.
63
-     * Sub-line items should have NO children line items.
64
-     * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's
65
-     * contribution towards the price of ONE of their parent items, and its LIN_total should be
66
-     *  = LIN_quantity * LIN_unit_price. Its LIN_percent = 0.
67
-     * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should
68
-     * = LIN_percent / 100 * sum of lower-priority sibling line items..
69
-     */
70
-    const type_sub_line_item = 'sub-item';
71
-
72
-    /**
73
-     * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal).
74
-     * Direct children should be event subtotals.
75
-     * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals.
76
-     *
77
-     */
78
-    const type_sub_total = 'sub-total';
79
-
80
-    /**
81
-     * Line item for the grand total of an order. Its direct children
82
-     * should be tax subtotals and (pre-tax) subtotals, and possibly a regular line item
83
-     * indicating a transaction-wide discount/surcharge. Should have a quantity of 1, a LIN_total and LIN_unit_price of
84
-     * the entire order's mount.
85
-     */
86
-    const type_total = 'total';
87
-
88
-    /**
89
-     * When a line item is cancelled, a sub-line-item of type 'cancellation'
90
-     * should be created, indicating the quantity that were cancelled
91
-     * (because a line item could have a quantity of 1, and its cancellation item
92
-     * could be for 3, indicating that originally 4 were purchased, but 3 have been
93
-     * cancelled, and only one remains).
94
-     * When items are refunded, a cancellation line item should be made, which points
95
-     * to teh payment model object which actually refunded the payment.
96
-     * Cancellations should NOT have any children line items; the should NOT affect
97
-     * any calculations, and are only meant as a record that cancellations have occurred.
98
-     * Their LIN_percent should be 0.
99
-     */
100
-    const type_cancellation = 'cancellation';
101
-
102
-    // private instance of the EEM_Line_Item object
103
-    protected static $_instance = null;
104
-
105
-
106
-    /**
107
-     *        private constructor to prevent direct creation
108
-     * @Constructor
109
-     * @access protected
110
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
111
-     * @return \EEM_Line_Item
112
-     */
113
-    protected function __construct($timezone)
114
-    {
115
-        $this->singular_item = __('Line Item', 'event_espresso');
116
-        $this->plural_item = __('Line Items', 'event_espresso');
117
-
118
-        $this->_tables = array(
119
-            'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID')
120
-        );
121
-        $line_items_can_be_for = apply_filters('FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket', 'Price', 'Event'));
122
-        $this->_fields = array(
123
-            'Line_Item' => array(
124
-                'LIN_ID' => new EE_Primary_Key_Int_Field('LIN_ID', __("ID", "event_espresso")),
125
-                'LIN_code' => new EE_Slug_Field('LIN_code', __("Code for index into Cart", "event_espresso"), true),
126
-                'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', __("Transaction ID", "event_espresso"), true, null, 'Transaction'),
127
-                'LIN_name' => new EE_Full_HTML_Field('LIN_name', __("Line Item Name", "event_espresso"), false, ''),
128
-                'LIN_desc' => new EE_Full_HTML_Field('LIN_desc', __("Line Item Description", "event_espresso"), true),
129
-                'LIN_unit_price' => new EE_Money_Field('LIN_unit_price', __("Unit Price", "event_espresso"), false, 0),
130
-                'LIN_percent' => new EE_Float_Field('LIN_percent', __("Percent", "event_espresso"), false, 0),
131
-                'LIN_is_taxable' => new EE_Boolean_Field('LIN_is_taxable', __("Taxable", "event_espresso"), false, false),
132
-                'LIN_order' => new EE_Integer_Field('LIN_order', __("Order of Application towards total of parent", "event_espresso"), false, 1),
133
-                'LIN_total' => new EE_Money_Field('LIN_total', __("Total (unit price x quantity)", "event_espresso"), false, 0),
134
-                'LIN_quantity' => new EE_Integer_Field('LIN_quantity', __("Quantity", "event_espresso"), true, 1),
135
-                'LIN_parent' => new EE_Integer_Field('LIN_parent', __("Parent ID (this item goes towards that Line Item's total)", "event_espresso"), true, null),
136
-                'LIN_type' => new EE_Enum_Text_Field('LIN_type', __("Type", "event_espresso"), false, 'line-item', array(
137
-                        self::type_line_item => __("Line Item", "event_espresso"),
138
-                        self::type_sub_line_item => __("Sub-Item", "event_espresso"),
139
-                        self::type_sub_total => __("Subtotal", "event_espresso"),
140
-                        self::type_tax_sub_total => __("Tax Subtotal", "event_espresso"),
141
-                        self::type_tax => __("Tax", "event_espresso"),
142
-                        self::type_total => __("Total", "event_espresso"),
143
-                        self::type_cancellation => __('Cancellation', 'event_espresso')
144
-                    )),
145
-                'OBJ_ID' => new EE_Foreign_Key_Int_Field('OBJ_ID', __('ID of Item purchased.', 'event_espresso'), true, null, $line_items_can_be_for),
146
-                'OBJ_type' => new EE_Any_Foreign_Model_Name_Field('OBJ_type', __("Model Name this Line Item is for", "event_espresso"), true, null, $line_items_can_be_for),
147
-                'LIN_timestamp' => new EE_Datetime_Field('LIN_timestamp', __('When the line item was created', 'event_espresso'), false, EE_Datetime_Field::now, $timezone),
148
-            )
149
-        );
150
-        $this->_model_relations = array(
151
-            'Transaction' => new EE_Belongs_To_Relation(),
152
-            'Ticket' => new EE_Belongs_To_Any_Relation(),
153
-            'Price' => new EE_Belongs_To_Any_Relation(),
154
-            'Event' => new EE_Belongs_To_Any_Relation()
155
-        );
156
-        $this->_model_chain_to_wp_user = 'Transaction.Registration.Event';
157
-        $this->_caps_slug = 'transactions';
158
-        parent::__construct($timezone);
159
-    }
160
-
161
-
162
-    /**
163
-     * Gets all the line items for this transaction of the given type
164
-     * @param string $line_item_type like one of EEM_Line_Item::type_*
165
-     * @param EE_Transaction|int $transaction
166
-     * @return EE_Line_Item[]
167
-     */
168
-    public function get_all_of_type_for_transaction($line_item_type, $transaction)
169
-    {
170
-        $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
171
-        return $this->get_all(array(array(
172
-            'LIN_type' => $line_item_type,
173
-            'TXN_ID' => $transaction
174
-        )));
175
-    }
176
-
177
-
178
-    /**
179
-     * Gets all line items unrelated to tickets that are normal line items
180
-     * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category)
181
-     * @param EE_Transaction|int $transaction
182
-     * @return EE_Line_Item[]
183
-     */
184
-    public function get_all_non_ticket_line_items_for_transaction($transaction)
185
-    {
186
-        $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
187
-        return $this->get_all(array(array(
188
-            'LIN_type' => self::type_line_item,
189
-            'TXN_ID' => $transaction,
190
-            'OR' => array(
191
-                'OBJ_type*notticket' => array('!=', 'Ticket'),
192
-                'OBJ_type*null' => array('IS_NULL'))
193
-        )));
194
-    }
195
-
196
-    /**
197
-     * Deletes line items with no transaction who have passed the transaction cutoff time.
198
-     * This needs to be very efficient
199
-     * because if there are spam bots afoot there will be LOTS of line items
200
-     * @return int count of how many deleted
201
-     */
202
-    public function delete_line_items_with_no_transaction()
203
-    {
204
-        /** @type WPDB $wpdb */
205
-        global $wpdb;
206
-        $time_to_leave_alone = apply_filters(
207
-            'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone',
208
-            WEEK_IN_SECONDS
209
-        );
210
-        $query = $wpdb->prepare(
211
-            'DELETE li
35
+	/**
36
+	 * Tax sub-total is just the total of all the taxes, which should be children
37
+	 * of this line item. There should only ever be one tax sub-total, and it should
38
+	 * be a direct child of. Its quantity and LIN_unit_price = 1.
39
+	 */
40
+	const type_tax_sub_total = 'tax-sub-total';
41
+
42
+	/**
43
+	 * Tax line items indicate a tax applied to all the taxable line items.
44
+	 * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal
45
+	 * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1.
46
+	 */
47
+	const type_tax = 'tax';
48
+
49
+	/**
50
+	 * Indicating individual items purchased, or discounts or surcharges.
51
+	 * The sum of all the regular line items  plus the tax items should equal
52
+	 * the grand total.
53
+	 * Possible children are sub-line-items and cancellations.
54
+	 * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children
55
+	 * LIN_totals. Its LIN_percent = 0.
56
+	 * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1).
57
+	 * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1.
58
+	 */
59
+	const type_line_item = 'line-item';
60
+
61
+	/**
62
+	 * Line item indicating all the factors that make a single line item.
63
+	 * Sub-line items should have NO children line items.
64
+	 * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's
65
+	 * contribution towards the price of ONE of their parent items, and its LIN_total should be
66
+	 *  = LIN_quantity * LIN_unit_price. Its LIN_percent = 0.
67
+	 * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should
68
+	 * = LIN_percent / 100 * sum of lower-priority sibling line items..
69
+	 */
70
+	const type_sub_line_item = 'sub-item';
71
+
72
+	/**
73
+	 * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal).
74
+	 * Direct children should be event subtotals.
75
+	 * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals.
76
+	 *
77
+	 */
78
+	const type_sub_total = 'sub-total';
79
+
80
+	/**
81
+	 * Line item for the grand total of an order. Its direct children
82
+	 * should be tax subtotals and (pre-tax) subtotals, and possibly a regular line item
83
+	 * indicating a transaction-wide discount/surcharge. Should have a quantity of 1, a LIN_total and LIN_unit_price of
84
+	 * the entire order's mount.
85
+	 */
86
+	const type_total = 'total';
87
+
88
+	/**
89
+	 * When a line item is cancelled, a sub-line-item of type 'cancellation'
90
+	 * should be created, indicating the quantity that were cancelled
91
+	 * (because a line item could have a quantity of 1, and its cancellation item
92
+	 * could be for 3, indicating that originally 4 were purchased, but 3 have been
93
+	 * cancelled, and only one remains).
94
+	 * When items are refunded, a cancellation line item should be made, which points
95
+	 * to teh payment model object which actually refunded the payment.
96
+	 * Cancellations should NOT have any children line items; the should NOT affect
97
+	 * any calculations, and are only meant as a record that cancellations have occurred.
98
+	 * Their LIN_percent should be 0.
99
+	 */
100
+	const type_cancellation = 'cancellation';
101
+
102
+	// private instance of the EEM_Line_Item object
103
+	protected static $_instance = null;
104
+
105
+
106
+	/**
107
+	 *        private constructor to prevent direct creation
108
+	 * @Constructor
109
+	 * @access protected
110
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
111
+	 * @return \EEM_Line_Item
112
+	 */
113
+	protected function __construct($timezone)
114
+	{
115
+		$this->singular_item = __('Line Item', 'event_espresso');
116
+		$this->plural_item = __('Line Items', 'event_espresso');
117
+
118
+		$this->_tables = array(
119
+			'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID')
120
+		);
121
+		$line_items_can_be_for = apply_filters('FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket', 'Price', 'Event'));
122
+		$this->_fields = array(
123
+			'Line_Item' => array(
124
+				'LIN_ID' => new EE_Primary_Key_Int_Field('LIN_ID', __("ID", "event_espresso")),
125
+				'LIN_code' => new EE_Slug_Field('LIN_code', __("Code for index into Cart", "event_espresso"), true),
126
+				'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', __("Transaction ID", "event_espresso"), true, null, 'Transaction'),
127
+				'LIN_name' => new EE_Full_HTML_Field('LIN_name', __("Line Item Name", "event_espresso"), false, ''),
128
+				'LIN_desc' => new EE_Full_HTML_Field('LIN_desc', __("Line Item Description", "event_espresso"), true),
129
+				'LIN_unit_price' => new EE_Money_Field('LIN_unit_price', __("Unit Price", "event_espresso"), false, 0),
130
+				'LIN_percent' => new EE_Float_Field('LIN_percent', __("Percent", "event_espresso"), false, 0),
131
+				'LIN_is_taxable' => new EE_Boolean_Field('LIN_is_taxable', __("Taxable", "event_espresso"), false, false),
132
+				'LIN_order' => new EE_Integer_Field('LIN_order', __("Order of Application towards total of parent", "event_espresso"), false, 1),
133
+				'LIN_total' => new EE_Money_Field('LIN_total', __("Total (unit price x quantity)", "event_espresso"), false, 0),
134
+				'LIN_quantity' => new EE_Integer_Field('LIN_quantity', __("Quantity", "event_espresso"), true, 1),
135
+				'LIN_parent' => new EE_Integer_Field('LIN_parent', __("Parent ID (this item goes towards that Line Item's total)", "event_espresso"), true, null),
136
+				'LIN_type' => new EE_Enum_Text_Field('LIN_type', __("Type", "event_espresso"), false, 'line-item', array(
137
+						self::type_line_item => __("Line Item", "event_espresso"),
138
+						self::type_sub_line_item => __("Sub-Item", "event_espresso"),
139
+						self::type_sub_total => __("Subtotal", "event_espresso"),
140
+						self::type_tax_sub_total => __("Tax Subtotal", "event_espresso"),
141
+						self::type_tax => __("Tax", "event_espresso"),
142
+						self::type_total => __("Total", "event_espresso"),
143
+						self::type_cancellation => __('Cancellation', 'event_espresso')
144
+					)),
145
+				'OBJ_ID' => new EE_Foreign_Key_Int_Field('OBJ_ID', __('ID of Item purchased.', 'event_espresso'), true, null, $line_items_can_be_for),
146
+				'OBJ_type' => new EE_Any_Foreign_Model_Name_Field('OBJ_type', __("Model Name this Line Item is for", "event_espresso"), true, null, $line_items_can_be_for),
147
+				'LIN_timestamp' => new EE_Datetime_Field('LIN_timestamp', __('When the line item was created', 'event_espresso'), false, EE_Datetime_Field::now, $timezone),
148
+			)
149
+		);
150
+		$this->_model_relations = array(
151
+			'Transaction' => new EE_Belongs_To_Relation(),
152
+			'Ticket' => new EE_Belongs_To_Any_Relation(),
153
+			'Price' => new EE_Belongs_To_Any_Relation(),
154
+			'Event' => new EE_Belongs_To_Any_Relation()
155
+		);
156
+		$this->_model_chain_to_wp_user = 'Transaction.Registration.Event';
157
+		$this->_caps_slug = 'transactions';
158
+		parent::__construct($timezone);
159
+	}
160
+
161
+
162
+	/**
163
+	 * Gets all the line items for this transaction of the given type
164
+	 * @param string $line_item_type like one of EEM_Line_Item::type_*
165
+	 * @param EE_Transaction|int $transaction
166
+	 * @return EE_Line_Item[]
167
+	 */
168
+	public function get_all_of_type_for_transaction($line_item_type, $transaction)
169
+	{
170
+		$transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
171
+		return $this->get_all(array(array(
172
+			'LIN_type' => $line_item_type,
173
+			'TXN_ID' => $transaction
174
+		)));
175
+	}
176
+
177
+
178
+	/**
179
+	 * Gets all line items unrelated to tickets that are normal line items
180
+	 * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category)
181
+	 * @param EE_Transaction|int $transaction
182
+	 * @return EE_Line_Item[]
183
+	 */
184
+	public function get_all_non_ticket_line_items_for_transaction($transaction)
185
+	{
186
+		$transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
187
+		return $this->get_all(array(array(
188
+			'LIN_type' => self::type_line_item,
189
+			'TXN_ID' => $transaction,
190
+			'OR' => array(
191
+				'OBJ_type*notticket' => array('!=', 'Ticket'),
192
+				'OBJ_type*null' => array('IS_NULL'))
193
+		)));
194
+	}
195
+
196
+	/**
197
+	 * Deletes line items with no transaction who have passed the transaction cutoff time.
198
+	 * This needs to be very efficient
199
+	 * because if there are spam bots afoot there will be LOTS of line items
200
+	 * @return int count of how many deleted
201
+	 */
202
+	public function delete_line_items_with_no_transaction()
203
+	{
204
+		/** @type WPDB $wpdb */
205
+		global $wpdb;
206
+		$time_to_leave_alone = apply_filters(
207
+			'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone',
208
+			WEEK_IN_SECONDS
209
+		);
210
+		$query = $wpdb->prepare(
211
+			'DELETE li
212 212
 				FROM ' . $this->table() . ' li
213 213
 				LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON li.TXN_ID = t.TXN_ID
214 214
 				WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s',
215
-            // use GMT time because that's what TXN_timestamps are in
216
-            date('Y-m-d H:i:s', time() - $time_to_leave_alone)
217
-        );
218
-        return $wpdb->query($query);
219
-    }
220
-
221
-
222
-    /**
223
-     * get_line_item_for_transaction_object
224
-     * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket
225
-     *
226
-     * @param int $TXN_ID
227
-     * @param \EE_Base_Class $object
228
-     * @return EE_Line_Item[]
229
-     */
230
-    public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object)
231
-    {
232
-        return $this->get_all(array(array(
233
-            'TXN_ID' => $TXN_ID,
234
-            'OBJ_type' => str_replace('EE_', '', get_class($object)),
235
-            'OBJ_ID' => $object->ID()
236
-        )));
237
-    }
238
-
239
-
240
-    /**
241
-     * get_object_line_items_for_transaction
242
-     * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs
243
-     *
244
-     * @param int $TXN_ID
245
-     * @param string $OBJ_type
246
-     * @param array $OBJ_IDs
247
-     * @return EE_Line_Item[]
248
-     */
249
-    public function get_object_line_items_for_transaction($TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array())
250
-    {
251
-        $query_params = array(
252
-            'OBJ_type' => $OBJ_type,
253
-            // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query
254
-            'OBJ_ID' => is_array($OBJ_IDs) && !isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs
255
-        );
256
-        if ($TXN_ID) {
257
-            $query_params['TXN_ID'] = $TXN_ID;
258
-        }
259
-        return $this->get_all(array($query_params));
260
-    }
261
-
262
-
263
-    /**
264
-     * get_all_ticket_line_items_for_transaction
265
-     *
266
-     * @param EE_Transaction $transaction
267
-     * @return EE_Line_Item[]
268
-     */
269
-    public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction)
270
-    {
271
-        return $this->get_all(array(
272
-            array(
273
-                'TXN_ID' => $transaction->ID(),
274
-                'OBJ_type' => 'Ticket',
275
-            )
276
-        ));
277
-    }
278
-
279
-
280
-    /**
281
-     * get_ticket_line_item_for_transaction
282
-     *
283
-     * @param int $TXN_ID
284
-     * @param int $TKT_ID
285
-     * @return \EE_Line_Item
286
-     */
287
-    public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID)
288
-    {
289
-        return $this->get_one(array(
290
-            array(
291
-                'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID),
292
-                'OBJ_ID' => $TKT_ID,
293
-                'OBJ_type' => 'Ticket',
294
-            )
295
-        ));
296
-    }
297
-
298
-
299
-    /**
300
-     * get_existing_promotion_line_item
301
-     * searches the cart for existing line items for the specified promotion
302
-     *
303
-     * @since   1.0.0
304
-     *
305
-     * @param EE_Line_Item $parent_line_item
306
-     * @param EE_Promotion $promotion
307
-     * @return EE_Line_Item
308
-     */
309
-    public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion)
310
-    {
311
-        return $this->get_one(array(
312
-            array(
313
-                'TXN_ID' => $parent_line_item->TXN_ID(),
314
-                'LIN_parent' => $parent_line_item->ID(),
315
-                'OBJ_type' => 'Promotion',
316
-                'OBJ_ID' => $promotion->ID()
317
-            )
318
-        ));
319
-    }
320
-
321
-
322
-    /**
323
-     * get_all_promotion_line_items
324
-     * searches the cart for any and all existing promotion line items
325
-     *
326
-     * @since   1.0.0
327
-     *
328
-     * @param EE_Line_Item $parent_line_item
329
-     * @return EE_Line_Item[]
330
-     */
331
-    public function get_all_promotion_line_items(EE_Line_Item $parent_line_item)
332
-    {
333
-        return $this->get_all(array(
334
-            array(
335
-                'TXN_ID' => $parent_line_item->TXN_ID(),
336
-                'LIN_parent' => $parent_line_item->ID(),
337
-                'OBJ_type' => 'Promotion'
338
-            )
339
-        ));
340
-    }
341
-
342
-    /**
343
-     * Gets the registration's corresponding line item.
344
-     * Note: basically does NOT support having multiple line items for a single ticket,
345
-     * which would happen if some of the registrations had a price modifier while others didn't.
346
-     * In order to support that, we'd probably need a LIN_ID on registrations or something.
347
-     * @param EE_Registration $registration
348
-     * @return EE_Line_ITem
349
-     */
350
-    public function get_line_item_for_registration(EE_Registration $registration)
351
-    {
352
-        return $this->get_one($this->line_item_for_registration_query_params($registration));
353
-    }
354
-
355
-    /**
356
-     * Gets the query params used to retrieve a specific line item for the given registration
357
-     * @param EE_Registration $registration
358
-     * @param array $original_query_params any extra query params you'd like to be merged with
359
-     * @return array like EEM_Base::get_all()'s $query_params
360
-     */
361
-    public function line_item_for_registration_query_params(EE_Registration $registration, $original_query_params = array())
362
-    {
363
-        return array_replace_recursive($original_query_params, array(
364
-            array(
365
-                'OBJ_ID' => $registration->ticket_ID(),
366
-                'OBJ_type' => 'Ticket',
367
-                'TXN_ID' => $registration->transaction_ID()
368
-            )
369
-        ));
370
-    }
371
-
372
-
373
-    /**
374
-     * @return EE_Base_Class[]|EE_Line_Item[]
375
-     * @throws InvalidInterfaceException
376
-     * @throws InvalidDataTypeException
377
-     * @throws EE_Error
378
-     * @throws InvalidArgumentException
379
-     */
380
-    public function get_total_line_items_with_no_transaction()
381
-    {
382
-        return $this->get_total_line_items_for_carts();
383
-    }
384
-
385
-
386
-    /**
387
-     * @return EE_Base_Class[]|EE_Line_Item[]
388
-     * @throws InvalidInterfaceException
389
-     * @throws InvalidDataTypeException
390
-     * @throws EE_Error
391
-     * @throws InvalidArgumentException
392
-     */
393
-    public function get_total_line_items_for_active_carts()
394
-    {
395
-        return $this->get_total_line_items_for_carts(false);
396
-    }
397
-
398
-
399
-    /**
400
-     * @return EE_Base_Class[]|EE_Line_Item[]
401
-     * @throws InvalidInterfaceException
402
-     * @throws InvalidDataTypeException
403
-     * @throws EE_Error
404
-     * @throws InvalidArgumentException
405
-     */
406
-    public function get_total_line_items_for_expired_carts()
407
-    {
408
-        return $this->get_total_line_items_for_carts(true);
409
-    }
410
-
411
-
412
-    /**
413
-     * Returns an array of grand total line items where the TXN_ID is 0.
414
-     * If $expired is set to true, then only line items for expired sessions will be returned.
415
-     * If $expired is set to false, then only line items for active sessions will be returned.
416
-     *
417
-     * @param null $expired
418
-     * @return EE_Base_Class[]|EE_Line_Item[]
419
-     * @throws InvalidInterfaceException
420
-     * @throws InvalidDataTypeException
421
-     * @throws EE_Error
422
-     * @throws InvalidArgumentException
423
-     * @throws InvalidDataTypeException
424
-     * @throws InvalidInterfaceException
425
-     */
426
-    private function get_total_line_items_for_carts($expired = null)
427
-    {
428
-        $where_params = array(
429
-            'TXN_ID' => 0,
430
-            'LIN_type' => 'total',
431
-        );
432
-        if ($expired !== null) {
433
-            /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
434
-            $session_lifespan = LoaderFactory::getLoader()->getShared(
435
-                'EventEspresso\core\domain\values\session\SessionLifespan'
436
-            );
437
-            $where_params['LIN_timestamp'] = array(
438
-                $expired ? '<=' : '>',
439
-                $session_lifespan->expiration(),
440
-            );
441
-        }
442
-        return $this->get_all(array($where_params));
443
-    }
444
-
445
-
446
-    /**
447
-     * Returns an array of ticket total line items where the TXN_ID is 0
448
-     * AND the timestamp is older than the session lifespan.
449
-     *
450
-     * @param int $timestamp
451
-     * @return EE_Base_Class[]|EE_Line_Item[]
452
-     * @throws EE_Error
453
-     * @throws InvalidArgumentException
454
-     * @throws InvalidDataTypeException
455
-     * @throws InvalidInterfaceException
456
-     */
457
-    public function getTicketLineItemsForExpiredCarts($timestamp = 0)
458
-    {
459
-        if (! absint($timestamp)) {
460
-            /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
461
-            $session_lifespan = LoaderFactory::getLoader()->getShared(
462
-                'EventEspresso\core\domain\values\session\SessionLifespan'
463
-            );
464
-            $timestamp = $session_lifespan->expiration();
465
-        }
466
-        return $this->get_all(
467
-            array(
468
-                array(
469
-                    'TXN_ID'        => 0,
470
-                    'OBJ_type'      => 'Ticket',
471
-                    'LIN_timestamp' => array('<=', $timestamp),
472
-                )
473
-            )
474
-        );
475
-    }
215
+			// use GMT time because that's what TXN_timestamps are in
216
+			date('Y-m-d H:i:s', time() - $time_to_leave_alone)
217
+		);
218
+		return $wpdb->query($query);
219
+	}
220
+
221
+
222
+	/**
223
+	 * get_line_item_for_transaction_object
224
+	 * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket
225
+	 *
226
+	 * @param int $TXN_ID
227
+	 * @param \EE_Base_Class $object
228
+	 * @return EE_Line_Item[]
229
+	 */
230
+	public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object)
231
+	{
232
+		return $this->get_all(array(array(
233
+			'TXN_ID' => $TXN_ID,
234
+			'OBJ_type' => str_replace('EE_', '', get_class($object)),
235
+			'OBJ_ID' => $object->ID()
236
+		)));
237
+	}
238
+
239
+
240
+	/**
241
+	 * get_object_line_items_for_transaction
242
+	 * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs
243
+	 *
244
+	 * @param int $TXN_ID
245
+	 * @param string $OBJ_type
246
+	 * @param array $OBJ_IDs
247
+	 * @return EE_Line_Item[]
248
+	 */
249
+	public function get_object_line_items_for_transaction($TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array())
250
+	{
251
+		$query_params = array(
252
+			'OBJ_type' => $OBJ_type,
253
+			// if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query
254
+			'OBJ_ID' => is_array($OBJ_IDs) && !isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs
255
+		);
256
+		if ($TXN_ID) {
257
+			$query_params['TXN_ID'] = $TXN_ID;
258
+		}
259
+		return $this->get_all(array($query_params));
260
+	}
261
+
262
+
263
+	/**
264
+	 * get_all_ticket_line_items_for_transaction
265
+	 *
266
+	 * @param EE_Transaction $transaction
267
+	 * @return EE_Line_Item[]
268
+	 */
269
+	public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction)
270
+	{
271
+		return $this->get_all(array(
272
+			array(
273
+				'TXN_ID' => $transaction->ID(),
274
+				'OBJ_type' => 'Ticket',
275
+			)
276
+		));
277
+	}
278
+
279
+
280
+	/**
281
+	 * get_ticket_line_item_for_transaction
282
+	 *
283
+	 * @param int $TXN_ID
284
+	 * @param int $TKT_ID
285
+	 * @return \EE_Line_Item
286
+	 */
287
+	public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID)
288
+	{
289
+		return $this->get_one(array(
290
+			array(
291
+				'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID),
292
+				'OBJ_ID' => $TKT_ID,
293
+				'OBJ_type' => 'Ticket',
294
+			)
295
+		));
296
+	}
297
+
298
+
299
+	/**
300
+	 * get_existing_promotion_line_item
301
+	 * searches the cart for existing line items for the specified promotion
302
+	 *
303
+	 * @since   1.0.0
304
+	 *
305
+	 * @param EE_Line_Item $parent_line_item
306
+	 * @param EE_Promotion $promotion
307
+	 * @return EE_Line_Item
308
+	 */
309
+	public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion)
310
+	{
311
+		return $this->get_one(array(
312
+			array(
313
+				'TXN_ID' => $parent_line_item->TXN_ID(),
314
+				'LIN_parent' => $parent_line_item->ID(),
315
+				'OBJ_type' => 'Promotion',
316
+				'OBJ_ID' => $promotion->ID()
317
+			)
318
+		));
319
+	}
320
+
321
+
322
+	/**
323
+	 * get_all_promotion_line_items
324
+	 * searches the cart for any and all existing promotion line items
325
+	 *
326
+	 * @since   1.0.0
327
+	 *
328
+	 * @param EE_Line_Item $parent_line_item
329
+	 * @return EE_Line_Item[]
330
+	 */
331
+	public function get_all_promotion_line_items(EE_Line_Item $parent_line_item)
332
+	{
333
+		return $this->get_all(array(
334
+			array(
335
+				'TXN_ID' => $parent_line_item->TXN_ID(),
336
+				'LIN_parent' => $parent_line_item->ID(),
337
+				'OBJ_type' => 'Promotion'
338
+			)
339
+		));
340
+	}
341
+
342
+	/**
343
+	 * Gets the registration's corresponding line item.
344
+	 * Note: basically does NOT support having multiple line items for a single ticket,
345
+	 * which would happen if some of the registrations had a price modifier while others didn't.
346
+	 * In order to support that, we'd probably need a LIN_ID on registrations or something.
347
+	 * @param EE_Registration $registration
348
+	 * @return EE_Line_ITem
349
+	 */
350
+	public function get_line_item_for_registration(EE_Registration $registration)
351
+	{
352
+		return $this->get_one($this->line_item_for_registration_query_params($registration));
353
+	}
354
+
355
+	/**
356
+	 * Gets the query params used to retrieve a specific line item for the given registration
357
+	 * @param EE_Registration $registration
358
+	 * @param array $original_query_params any extra query params you'd like to be merged with
359
+	 * @return array like EEM_Base::get_all()'s $query_params
360
+	 */
361
+	public function line_item_for_registration_query_params(EE_Registration $registration, $original_query_params = array())
362
+	{
363
+		return array_replace_recursive($original_query_params, array(
364
+			array(
365
+				'OBJ_ID' => $registration->ticket_ID(),
366
+				'OBJ_type' => 'Ticket',
367
+				'TXN_ID' => $registration->transaction_ID()
368
+			)
369
+		));
370
+	}
371
+
372
+
373
+	/**
374
+	 * @return EE_Base_Class[]|EE_Line_Item[]
375
+	 * @throws InvalidInterfaceException
376
+	 * @throws InvalidDataTypeException
377
+	 * @throws EE_Error
378
+	 * @throws InvalidArgumentException
379
+	 */
380
+	public function get_total_line_items_with_no_transaction()
381
+	{
382
+		return $this->get_total_line_items_for_carts();
383
+	}
384
+
385
+
386
+	/**
387
+	 * @return EE_Base_Class[]|EE_Line_Item[]
388
+	 * @throws InvalidInterfaceException
389
+	 * @throws InvalidDataTypeException
390
+	 * @throws EE_Error
391
+	 * @throws InvalidArgumentException
392
+	 */
393
+	public function get_total_line_items_for_active_carts()
394
+	{
395
+		return $this->get_total_line_items_for_carts(false);
396
+	}
397
+
398
+
399
+	/**
400
+	 * @return EE_Base_Class[]|EE_Line_Item[]
401
+	 * @throws InvalidInterfaceException
402
+	 * @throws InvalidDataTypeException
403
+	 * @throws EE_Error
404
+	 * @throws InvalidArgumentException
405
+	 */
406
+	public function get_total_line_items_for_expired_carts()
407
+	{
408
+		return $this->get_total_line_items_for_carts(true);
409
+	}
410
+
411
+
412
+	/**
413
+	 * Returns an array of grand total line items where the TXN_ID is 0.
414
+	 * If $expired is set to true, then only line items for expired sessions will be returned.
415
+	 * If $expired is set to false, then only line items for active sessions will be returned.
416
+	 *
417
+	 * @param null $expired
418
+	 * @return EE_Base_Class[]|EE_Line_Item[]
419
+	 * @throws InvalidInterfaceException
420
+	 * @throws InvalidDataTypeException
421
+	 * @throws EE_Error
422
+	 * @throws InvalidArgumentException
423
+	 * @throws InvalidDataTypeException
424
+	 * @throws InvalidInterfaceException
425
+	 */
426
+	private function get_total_line_items_for_carts($expired = null)
427
+	{
428
+		$where_params = array(
429
+			'TXN_ID' => 0,
430
+			'LIN_type' => 'total',
431
+		);
432
+		if ($expired !== null) {
433
+			/** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
434
+			$session_lifespan = LoaderFactory::getLoader()->getShared(
435
+				'EventEspresso\core\domain\values\session\SessionLifespan'
436
+			);
437
+			$where_params['LIN_timestamp'] = array(
438
+				$expired ? '<=' : '>',
439
+				$session_lifespan->expiration(),
440
+			);
441
+		}
442
+		return $this->get_all(array($where_params));
443
+	}
444
+
445
+
446
+	/**
447
+	 * Returns an array of ticket total line items where the TXN_ID is 0
448
+	 * AND the timestamp is older than the session lifespan.
449
+	 *
450
+	 * @param int $timestamp
451
+	 * @return EE_Base_Class[]|EE_Line_Item[]
452
+	 * @throws EE_Error
453
+	 * @throws InvalidArgumentException
454
+	 * @throws InvalidDataTypeException
455
+	 * @throws InvalidInterfaceException
456
+	 */
457
+	public function getTicketLineItemsForExpiredCarts($timestamp = 0)
458
+	{
459
+		if (! absint($timestamp)) {
460
+			/** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
461
+			$session_lifespan = LoaderFactory::getLoader()->getShared(
462
+				'EventEspresso\core\domain\values\session\SessionLifespan'
463
+			);
464
+			$timestamp = $session_lifespan->expiration();
465
+		}
466
+		return $this->get_all(
467
+			array(
468
+				array(
469
+					'TXN_ID'        => 0,
470
+					'OBJ_type'      => 'Ticket',
471
+					'LIN_timestamp' => array('<=', $timestamp),
472
+				)
473
+			)
474
+		);
475
+	}
476 476
 }
Please login to merge, or discard this patch.
core/domain/services/admin/ExitModal.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -19,94 +19,94 @@
 block discarded – undo
19 19
 class ExitModal
20 20
 {
21 21
 
22
-    /**
23
-     * @var Registry
24
-     */
25
-    private $assets_registry;
22
+	/**
23
+	 * @var Registry
24
+	 */
25
+	private $assets_registry;
26 26
 
27
-    /**
28
-     * ExitModal constructor.
29
-     *
30
-     * @param Registry $assets_registry
31
-     */
32
-    public function __construct(Registry $assets_registry)
33
-    {
34
-        $this->assets_registry = $assets_registry;
35
-        add_action('in_admin_footer', array($this, 'modalContainer'));
36
-        add_action('admin_enqueue_scripts', array($this, 'enqueues'));
37
-    }
27
+	/**
28
+	 * ExitModal constructor.
29
+	 *
30
+	 * @param Registry $assets_registry
31
+	 */
32
+	public function __construct(Registry $assets_registry)
33
+	{
34
+		$this->assets_registry = $assets_registry;
35
+		add_action('in_admin_footer', array($this, 'modalContainer'));
36
+		add_action('admin_enqueue_scripts', array($this, 'enqueues'));
37
+	}
38 38
 
39 39
 
40
-    /**
41
-     * Callback on in_admin_footer that is used to output the exit modal container.
42
-     */
43
-    public function modalContainer()
44
-    {
45
-        echo '<div id="ee-exit-survey-modal"></div>';
46
-    }
40
+	/**
41
+	 * Callback on in_admin_footer that is used to output the exit modal container.
42
+	 */
43
+	public function modalContainer()
44
+	{
45
+		echo '<div id="ee-exit-survey-modal"></div>';
46
+	}
47 47
 
48 48
 
49
-    /**
50
-     * Callback for `admin_enqueue_scripts` to take care of enqueueing scripts and styles specific to the modal.
51
-     *
52
-     * @throws InvalidArgumentException
53
-     */
54
-    public function enqueues()
55
-    {
56
-        $current_user = new WP_User(get_current_user_id());
57
-        $this->assets_registry->addData(
58
-            'exitModali18n',
59
-            array(
60
-                'introText' => htmlspecialchars(
61
-                    __(
62
-                        'Do you have a moment to share why you are deactivating Event Espresso?',
63
-                        'event_espresso'
64
-                    ),
65
-                    ENT_NOQUOTES
66
-                ),
67
-                'doSurveyButtonText' => htmlspecialchars(
68
-                    __(
69
-                        'Sure I\'ll help',
70
-                        'event_espresso'
71
-                    ),
72
-                    ENT_NOQUOTES
73
-                ),
74
-                'skipButtonText' => htmlspecialchars(
75
-                    __(
76
-                        'Skip',
77
-                        'event_espresso'
78
-                    ),
79
-                    ENT_NOQUOTES
80
-                )
81
-            )
82
-        );
83
-        $this->assets_registry->addData(
84
-            'exitModalInfo',
85
-            array(
86
-                'firstname' => htmlspecialchars($current_user->user_firstname),
87
-                'emailaddress' => htmlspecialchars($current_user->user_email),
88
-                'website' => htmlspecialchars(site_url()),
89
-                'isModalActive' => $this->isModalActive()
90
-            )
91
-        );
49
+	/**
50
+	 * Callback for `admin_enqueue_scripts` to take care of enqueueing scripts and styles specific to the modal.
51
+	 *
52
+	 * @throws InvalidArgumentException
53
+	 */
54
+	public function enqueues()
55
+	{
56
+		$current_user = new WP_User(get_current_user_id());
57
+		$this->assets_registry->addData(
58
+			'exitModali18n',
59
+			array(
60
+				'introText' => htmlspecialchars(
61
+					__(
62
+						'Do you have a moment to share why you are deactivating Event Espresso?',
63
+						'event_espresso'
64
+					),
65
+					ENT_NOQUOTES
66
+				),
67
+				'doSurveyButtonText' => htmlspecialchars(
68
+					__(
69
+						'Sure I\'ll help',
70
+						'event_espresso'
71
+					),
72
+					ENT_NOQUOTES
73
+				),
74
+				'skipButtonText' => htmlspecialchars(
75
+					__(
76
+						'Skip',
77
+						'event_espresso'
78
+					),
79
+					ENT_NOQUOTES
80
+				)
81
+			)
82
+		);
83
+		$this->assets_registry->addData(
84
+			'exitModalInfo',
85
+			array(
86
+				'firstname' => htmlspecialchars($current_user->user_firstname),
87
+				'emailaddress' => htmlspecialchars($current_user->user_email),
88
+				'website' => htmlspecialchars(site_url()),
89
+				'isModalActive' => $this->isModalActive()
90
+			)
91
+		);
92 92
 
93
-        wp_enqueue_script('ee-wp-plugins-page');
94
-        wp_enqueue_style('ee-wp-plugins-page');
95
-    }
93
+		wp_enqueue_script('ee-wp-plugins-page');
94
+		wp_enqueue_style('ee-wp-plugins-page');
95
+	}
96 96
 
97 97
 
98
-    /**
99
-     * Exposes a filter switch for turning off the enqueueing of the modal script.
100
-     * @return bool
101
-     */
102
-    private function isModalActive()
103
-    {
104
-        return filter_var(
105
-            apply_filters(
106
-                'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive',
107
-                true
108
-            ),
109
-            FILTER_VALIDATE_BOOLEAN
110
-        );
111
-    }
98
+	/**
99
+	 * Exposes a filter switch for turning off the enqueueing of the modal script.
100
+	 * @return bool
101
+	 */
102
+	private function isModalActive()
103
+	{
104
+		return filter_var(
105
+			apply_filters(
106
+				'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive',
107
+				true
108
+			),
109
+			FILTER_VALIDATE_BOOLEAN
110
+		);
111
+	}
112 112
 }
Please login to merge, or discard this patch.
core/services/assets/Registry.php 2 patches
Indentation   +694 added lines, -694 removed lines patch added patch discarded remove patch
@@ -27,705 +27,705 @@
 block discarded – undo
27 27
 class Registry
28 28
 {
29 29
 
30
-    const ASSET_TYPE_CSS = 'css';
31
-    const ASSET_TYPE_JS = 'js';
32
-    const ASSET_NAMESPACE = 'core';
33
-
34
-    /**
35
-     * @var EE_Template_Config $template_config
36
-     */
37
-    protected $template_config;
38
-
39
-    /**
40
-     * @var EE_Currency_Config $currency_config
41
-     */
42
-    protected $currency_config;
43
-
44
-    /**
45
-     * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
46
-     *
47
-     * @var array
48
-     */
49
-    protected $jsdata = array();
50
-
51
-
52
-    /**
53
-     * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
54
-     * page source.
55
-     * @var array
56
-     */
57
-    protected $script_handles_with_data = array();
58
-
59
-
60
-    /**
61
-     * @var DomainInterface
62
-     */
63
-    protected $domain;
64
-
65
-
66
-    /**
67
-     * @var I18nRegistry
68
-     */
69
-    private $i18n_registry;
70
-
71
-
72
-
73
-    /**
74
-     * Holds the manifest data obtained from registered manifest files.
75
-     * Manifests are maps of asset chunk name to actual built asset file names.
76
-     * Shape of this array is:
77
-     *
78
-     * array(
79
-     *  'some_namespace_slug' => array(
80
-     *      'some_chunk_name' => array(
81
-     *          'js' => 'filename.js'
82
-     *          'css' => 'filename.js'
83
-     *      ),
84
-     *      'url_base' => 'https://baseurl.com/to/assets
85
-     *  )
86
-     * )
87
-     *
88
-     * @var array
89
-     */
90
-    private $manifest_data = array();
91
-
92
-
93
-    /**
94
-     * Registry constructor.
95
-     * Hooking into WP actions for script registry.
96
-     *
97
-     * @param EE_Template_Config $template_config
98
-     * @param EE_Currency_Config $currency_config
99
-     * @param I18nRegistry       $i18n_registry
100
-     * @param DomainInterface    $domain
101
-     * @throws InvalidArgumentException
102
-     * @throws InvalidFilePathException
103
-     */
104
-    public function __construct(
105
-        EE_Template_Config $template_config,
106
-        EE_Currency_Config $currency_config,
107
-        I18nRegistry $i18n_registry,
108
-        DomainInterface $domain
109
-    ) {
110
-        $this->template_config = $template_config;
111
-        $this->currency_config = $currency_config;
112
-        $this->domain = $domain;
113
-        $this->i18n_registry = $i18n_registry;
114
-        $this->registerManifestFile(
115
-            self::ASSET_NAMESPACE,
116
-            $this->domain->distributionAssetsUrl(),
117
-            $this->domain->distributionAssetsPath() . 'build-manifest.json'
118
-        );
119
-        add_action('wp_enqueue_scripts', array($this, 'scripts'), 1);
120
-        add_action('admin_enqueue_scripts', array($this, 'scripts'), 1);
121
-        add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2);
122
-        add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2);
123
-        add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
124
-        add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
125
-    }
126
-
127
-
128
-    /**
129
-     * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
130
-     * translation handling.
131
-     *
132
-     * @return I18nRegistry
133
-     */
134
-    public function getI18nRegistry()
135
-    {
136
-        return $this->i18n_registry;
137
-    }
138
-
139
-    /**
140
-     * Callback for the WP script actions.
141
-     * Used to register globally accessible core scripts.
142
-     * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency.
143
-     *
144
-     */
145
-    public function scripts()
146
-    {
147
-        global $wp_version;
148
-        wp_register_script(
149
-            'ee-manifest',
150
-            $this->getJsUrl(self::ASSET_NAMESPACE, 'manifest'),
151
-            array(),
152
-            null,
153
-            true
154
-        );
155
-        wp_register_script(
156
-            'eejs-core',
157
-            $this->getJsUrl(self::ASSET_NAMESPACE, 'eejs'),
158
-            array('ee-manifest'),
159
-            null,
160
-            true
161
-        );
162
-        wp_register_script(
163
-            'ee-vendor-react',
164
-            $this->getJsUrl(self::ASSET_NAMESPACE, 'reactVendor'),
165
-            array('eejs-core'),
166
-            null,
167
-            true
168
-        );
169
-        //only run this if WordPress 4.4.0 > is in use.
170
-        if (version_compare($wp_version, '4.4.0', '>')) {
171
-            //js.api
172
-            wp_register_script(
173
-                'eejs-api',
174
-                EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
175
-                array('underscore', 'eejs-core'),
176
-                EVENT_ESPRESSO_VERSION,
177
-                true
178
-            );
179
-            $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest');
180
-            $this->jsdata['paths'] = array(
181
-                'rest_route' => rest_url('ee/v4.8.36/'),
182
-                'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName()
183
-            );
184
-        }
185
-        if (! is_admin()) {
186
-            $this->loadCoreCss();
187
-        }
188
-        $this->registerTranslationsForHandles(array('eejs-core'));
189
-        $this->loadCoreJs();
190
-        $this->loadJqueryValidate();
191
-        $this->loadAccountingJs();
192
-        $this->loadQtipJs();
193
-        $this->registerAdminAssets();
194
-    }
195
-
196
-
197
-
198
-    /**
199
-     * Call back for the script print in frontend and backend.
200
-     * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
201
-     *
202
-     * @since 4.9.31.rc.015
203
-     */
204
-    public function enqueueData()
205
-    {
206
-        $this->removeAlreadyRegisteredDataForScriptHandles();
207
-        wp_add_inline_script(
208
-            'eejs-core',
209
-            'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
210
-            'before'
211
-        );
212
-        wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
213
-        $this->localizeAccountingJs();
214
-        $this->addRegisteredScriptHandlesWithData('eejs-core');
215
-        $this->addRegisteredScriptHandlesWithData('espresso_core');
216
-    }
217
-
218
-
219
-
220
-    /**
221
-     * Used to add data to eejs.data object.
222
-     * Note:  Overriding existing data is not allowed.
223
-     * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
224
-     * If the data you add is something like this:
225
-     *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
226
-     * It will be exposed in the page source as:
227
-     *  eejs.data.my_plugin_data.foo == gar
228
-     *
229
-     * @param string       $key   Key used to access your data
230
-     * @param string|array $value Value to attach to key
231
-     * @throws InvalidArgumentException
232
-     */
233
-    public function addData($key, $value)
234
-    {
235
-        if ($this->verifyDataNotExisting($key)) {
236
-            $this->jsdata[$key] = $value;
237
-        }
238
-    }
239
-
240
-
241
-
242
-    /**
243
-     * Similar to addData except this allows for users to push values to an existing key where the values on key are
244
-     * elements in an array.
245
-     * When you use this method, the value you include will be appended to the end of an array on $key.
246
-     * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
247
-     * object like this, eejs.data.test = [ my_data,
248
-     * ]
249
-     * If there has already been a scalar value attached to the data object given key, then
250
-     * this will throw an exception.
251
-     *
252
-     * @param string       $key   Key to attach data to.
253
-     * @param string|array $value Value being registered.
254
-     * @throws InvalidArgumentException
255
-     */
256
-    public function pushData($key, $value)
257
-    {
258
-        if (isset($this->jsdata[$key])
259
-            && ! is_array($this->jsdata[$key])
260
-        ) {
261
-            throw new invalidArgumentException(
262
-                sprintf(
263
-                    __(
264
-                        'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
30
+	const ASSET_TYPE_CSS = 'css';
31
+	const ASSET_TYPE_JS = 'js';
32
+	const ASSET_NAMESPACE = 'core';
33
+
34
+	/**
35
+	 * @var EE_Template_Config $template_config
36
+	 */
37
+	protected $template_config;
38
+
39
+	/**
40
+	 * @var EE_Currency_Config $currency_config
41
+	 */
42
+	protected $currency_config;
43
+
44
+	/**
45
+	 * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
46
+	 *
47
+	 * @var array
48
+	 */
49
+	protected $jsdata = array();
50
+
51
+
52
+	/**
53
+	 * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
54
+	 * page source.
55
+	 * @var array
56
+	 */
57
+	protected $script_handles_with_data = array();
58
+
59
+
60
+	/**
61
+	 * @var DomainInterface
62
+	 */
63
+	protected $domain;
64
+
65
+
66
+	/**
67
+	 * @var I18nRegistry
68
+	 */
69
+	private $i18n_registry;
70
+
71
+
72
+
73
+	/**
74
+	 * Holds the manifest data obtained from registered manifest files.
75
+	 * Manifests are maps of asset chunk name to actual built asset file names.
76
+	 * Shape of this array is:
77
+	 *
78
+	 * array(
79
+	 *  'some_namespace_slug' => array(
80
+	 *      'some_chunk_name' => array(
81
+	 *          'js' => 'filename.js'
82
+	 *          'css' => 'filename.js'
83
+	 *      ),
84
+	 *      'url_base' => 'https://baseurl.com/to/assets
85
+	 *  )
86
+	 * )
87
+	 *
88
+	 * @var array
89
+	 */
90
+	private $manifest_data = array();
91
+
92
+
93
+	/**
94
+	 * Registry constructor.
95
+	 * Hooking into WP actions for script registry.
96
+	 *
97
+	 * @param EE_Template_Config $template_config
98
+	 * @param EE_Currency_Config $currency_config
99
+	 * @param I18nRegistry       $i18n_registry
100
+	 * @param DomainInterface    $domain
101
+	 * @throws InvalidArgumentException
102
+	 * @throws InvalidFilePathException
103
+	 */
104
+	public function __construct(
105
+		EE_Template_Config $template_config,
106
+		EE_Currency_Config $currency_config,
107
+		I18nRegistry $i18n_registry,
108
+		DomainInterface $domain
109
+	) {
110
+		$this->template_config = $template_config;
111
+		$this->currency_config = $currency_config;
112
+		$this->domain = $domain;
113
+		$this->i18n_registry = $i18n_registry;
114
+		$this->registerManifestFile(
115
+			self::ASSET_NAMESPACE,
116
+			$this->domain->distributionAssetsUrl(),
117
+			$this->domain->distributionAssetsPath() . 'build-manifest.json'
118
+		);
119
+		add_action('wp_enqueue_scripts', array($this, 'scripts'), 1);
120
+		add_action('admin_enqueue_scripts', array($this, 'scripts'), 1);
121
+		add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2);
122
+		add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2);
123
+		add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
124
+		add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
125
+	}
126
+
127
+
128
+	/**
129
+	 * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
130
+	 * translation handling.
131
+	 *
132
+	 * @return I18nRegistry
133
+	 */
134
+	public function getI18nRegistry()
135
+	{
136
+		return $this->i18n_registry;
137
+	}
138
+
139
+	/**
140
+	 * Callback for the WP script actions.
141
+	 * Used to register globally accessible core scripts.
142
+	 * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency.
143
+	 *
144
+	 */
145
+	public function scripts()
146
+	{
147
+		global $wp_version;
148
+		wp_register_script(
149
+			'ee-manifest',
150
+			$this->getJsUrl(self::ASSET_NAMESPACE, 'manifest'),
151
+			array(),
152
+			null,
153
+			true
154
+		);
155
+		wp_register_script(
156
+			'eejs-core',
157
+			$this->getJsUrl(self::ASSET_NAMESPACE, 'eejs'),
158
+			array('ee-manifest'),
159
+			null,
160
+			true
161
+		);
162
+		wp_register_script(
163
+			'ee-vendor-react',
164
+			$this->getJsUrl(self::ASSET_NAMESPACE, 'reactVendor'),
165
+			array('eejs-core'),
166
+			null,
167
+			true
168
+		);
169
+		//only run this if WordPress 4.4.0 > is in use.
170
+		if (version_compare($wp_version, '4.4.0', '>')) {
171
+			//js.api
172
+			wp_register_script(
173
+				'eejs-api',
174
+				EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
175
+				array('underscore', 'eejs-core'),
176
+				EVENT_ESPRESSO_VERSION,
177
+				true
178
+			);
179
+			$this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest');
180
+			$this->jsdata['paths'] = array(
181
+				'rest_route' => rest_url('ee/v4.8.36/'),
182
+				'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName()
183
+			);
184
+		}
185
+		if (! is_admin()) {
186
+			$this->loadCoreCss();
187
+		}
188
+		$this->registerTranslationsForHandles(array('eejs-core'));
189
+		$this->loadCoreJs();
190
+		$this->loadJqueryValidate();
191
+		$this->loadAccountingJs();
192
+		$this->loadQtipJs();
193
+		$this->registerAdminAssets();
194
+	}
195
+
196
+
197
+
198
+	/**
199
+	 * Call back for the script print in frontend and backend.
200
+	 * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
201
+	 *
202
+	 * @since 4.9.31.rc.015
203
+	 */
204
+	public function enqueueData()
205
+	{
206
+		$this->removeAlreadyRegisteredDataForScriptHandles();
207
+		wp_add_inline_script(
208
+			'eejs-core',
209
+			'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
210
+			'before'
211
+		);
212
+		wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
213
+		$this->localizeAccountingJs();
214
+		$this->addRegisteredScriptHandlesWithData('eejs-core');
215
+		$this->addRegisteredScriptHandlesWithData('espresso_core');
216
+	}
217
+
218
+
219
+
220
+	/**
221
+	 * Used to add data to eejs.data object.
222
+	 * Note:  Overriding existing data is not allowed.
223
+	 * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
224
+	 * If the data you add is something like this:
225
+	 *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
226
+	 * It will be exposed in the page source as:
227
+	 *  eejs.data.my_plugin_data.foo == gar
228
+	 *
229
+	 * @param string       $key   Key used to access your data
230
+	 * @param string|array $value Value to attach to key
231
+	 * @throws InvalidArgumentException
232
+	 */
233
+	public function addData($key, $value)
234
+	{
235
+		if ($this->verifyDataNotExisting($key)) {
236
+			$this->jsdata[$key] = $value;
237
+		}
238
+	}
239
+
240
+
241
+
242
+	/**
243
+	 * Similar to addData except this allows for users to push values to an existing key where the values on key are
244
+	 * elements in an array.
245
+	 * When you use this method, the value you include will be appended to the end of an array on $key.
246
+	 * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
247
+	 * object like this, eejs.data.test = [ my_data,
248
+	 * ]
249
+	 * If there has already been a scalar value attached to the data object given key, then
250
+	 * this will throw an exception.
251
+	 *
252
+	 * @param string       $key   Key to attach data to.
253
+	 * @param string|array $value Value being registered.
254
+	 * @throws InvalidArgumentException
255
+	 */
256
+	public function pushData($key, $value)
257
+	{
258
+		if (isset($this->jsdata[$key])
259
+			&& ! is_array($this->jsdata[$key])
260
+		) {
261
+			throw new invalidArgumentException(
262
+				sprintf(
263
+					__(
264
+						'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
265 265
                          push values to this data element when it is an array.',
266
-                        'event_espresso'
267
-                    ),
268
-                    $key,
269
-                    __METHOD__
270
-                )
271
-            );
272
-        }
273
-        $this->jsdata[$key][] = $value;
274
-    }
275
-
276
-
277
-
278
-    /**
279
-     * Used to set content used by javascript for a template.
280
-     * Note: Overrides of existing registered templates are not allowed.
281
-     *
282
-     * @param string $template_reference
283
-     * @param string $template_content
284
-     * @throws InvalidArgumentException
285
-     */
286
-    public function addTemplate($template_reference, $template_content)
287
-    {
288
-        if (! isset($this->jsdata['templates'])) {
289
-            $this->jsdata['templates'] = array();
290
-        }
291
-        //no overrides allowed.
292
-        if (isset($this->jsdata['templates'][$template_reference])) {
293
-            throw new invalidArgumentException(
294
-                sprintf(
295
-                    __(
296
-                        'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
297
-                        'event_espresso'
298
-                    ),
299
-                    $template_reference
300
-                )
301
-            );
302
-        }
303
-        $this->jsdata['templates'][$template_reference] = $template_content;
304
-    }
305
-
306
-
307
-
308
-    /**
309
-     * Retrieve the template content already registered for the given reference.
310
-     *
311
-     * @param string $template_reference
312
-     * @return string
313
-     */
314
-    public function getTemplate($template_reference)
315
-    {
316
-        return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference])
317
-            ? $this->jsdata['templates'][$template_reference]
318
-            : '';
319
-    }
320
-
321
-
322
-
323
-    /**
324
-     * Retrieve registered data.
325
-     *
326
-     * @param string $key Name of key to attach data to.
327
-     * @return mixed                If there is no for the given key, then false is returned.
328
-     */
329
-    public function getData($key)
330
-    {
331
-        return isset($this->jsdata[$key])
332
-            ? $this->jsdata[$key]
333
-            : false;
334
-    }
335
-
336
-
337
-    /**
338
-     * Get the actual asset path for asset manifests.
339
-     * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
340
-     * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
341
-     *                           asset file location.
342
-     * @param string $chunk_name
343
-     * @param string $asset_type
344
-     * @return string
345
-     * @since 4.9.59.p
346
-     */
347
-    public function getAssetUrl($namespace, $chunk_name, $asset_type)
348
-    {
349
-        $url = isset(
350
-            $this->manifest_data[$namespace][$chunk_name][$asset_type],
351
-            $this->manifest_data[$namespace]['url_base']
352
-        )
353
-            ? $this->manifest_data[$namespace]['url_base']
354
-              . $this->manifest_data[$namespace][$chunk_name][$asset_type]
355
-            : $chunk_name;
356
-        return apply_filters(
357
-            'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
358
-            $url,
359
-            $namespace,
360
-            $chunk_name,
361
-            $asset_type
362
-        );
363
-    }
364
-
365
-
366
-    /**
367
-     * Return the url to a js file for the given namespace and chunk name.
368
-     *
369
-     * @param string $namespace
370
-     * @param string $chunk_name
371
-     * @return string
372
-     */
373
-    public function getJsUrl($namespace, $chunk_name)
374
-    {
375
-        return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_JS);
376
-    }
377
-
378
-
379
-    /**
380
-     * Return the url to a css file for the given namespace and chunk name.
381
-     *
382
-     * @param string $namespace
383
-     * @param string $chunk_name
384
-     * @return string
385
-     */
386
-    public function getCssUrl($namespace, $chunk_name)
387
-    {
388
-        return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_CSS);
389
-    }
390
-
391
-
392
-    /**
393
-     * Used to register a js/css manifest file with the registered_manifest_files property.
394
-     *
395
-     * @param string $namespace     Provided to associate the manifest file with a specific namespace.
396
-     * @param string $url_base      The url base for the manifest file location.
397
-     * @param string $manifest_file The absolute path to the manifest file.
398
-     * @throws InvalidArgumentException
399
-     * @throws InvalidFilePathException
400
-     * @since 4.9.59.p
401
-     */
402
-    public function registerManifestFile($namespace, $url_base, $manifest_file)
403
-    {
404
-        if (isset($this->manifest_data[$namespace])) {
405
-            throw new InvalidArgumentException(
406
-                sprintf(
407
-                    esc_html__(
408
-                        'The namespace for this manifest file has already been registered, choose a namespace other than %s',
409
-                        'event_espresso'
410
-                    ),
411
-                    $namespace
412
-                )
413
-            );
414
-        }
415
-        if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
416
-            if (is_admin()) {
417
-                EE_Error::add_error(
418
-                    sprintf(
419
-                        esc_html__(
420
-                            'The url given for %1$s assets is invalid.  The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant',
421
-                            'event_espresso'
422
-                        ),
423
-                        'Event Espresso',
424
-                        $url_base,
425
-                        'plugins_url',
426
-                        'WP_PLUGIN_URL'
427
-                    ),
428
-                    __FILE__,
429
-                    __FUNCTION__,
430
-                    __LINE__
431
-                );
432
-            }
433
-            return;
434
-        }
435
-        $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file);
436
-        if (! isset($this->manifest_data[$namespace]['url_base'])) {
437
-            $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base);
438
-        }
439
-    }
440
-
441
-
442
-
443
-    /**
444
-     * Decodes json from the provided manifest file.
445
-     *
446
-     * @since 4.9.59.p
447
-     * @param string $manifest_file Path to manifest file.
448
-     * @return array
449
-     * @throws InvalidFilePathException
450
-     */
451
-    private function decodeManifestFile($manifest_file)
452
-    {
453
-        if (! file_exists($manifest_file)) {
454
-            throw new InvalidFilePathException($manifest_file);
455
-        }
456
-        return json_decode(file_get_contents($manifest_file), true);
457
-    }
458
-
459
-
460
-
461
-    /**
462
-     * Verifies whether the given data exists already on the jsdata array.
463
-     * Overriding data is not allowed.
464
-     *
465
-     * @param string $key Index for data.
466
-     * @return bool        If valid then return true.
467
-     * @throws InvalidArgumentException if data already exists.
468
-     */
469
-    protected function verifyDataNotExisting($key)
470
-    {
471
-        if (isset($this->jsdata[$key])) {
472
-            if (is_array($this->jsdata[$key])) {
473
-                throw new InvalidArgumentException(
474
-                    sprintf(
475
-                        __(
476
-                            'The value for %1$s already exists in the Registry::eejs object.
266
+						'event_espresso'
267
+					),
268
+					$key,
269
+					__METHOD__
270
+				)
271
+			);
272
+		}
273
+		$this->jsdata[$key][] = $value;
274
+	}
275
+
276
+
277
+
278
+	/**
279
+	 * Used to set content used by javascript for a template.
280
+	 * Note: Overrides of existing registered templates are not allowed.
281
+	 *
282
+	 * @param string $template_reference
283
+	 * @param string $template_content
284
+	 * @throws InvalidArgumentException
285
+	 */
286
+	public function addTemplate($template_reference, $template_content)
287
+	{
288
+		if (! isset($this->jsdata['templates'])) {
289
+			$this->jsdata['templates'] = array();
290
+		}
291
+		//no overrides allowed.
292
+		if (isset($this->jsdata['templates'][$template_reference])) {
293
+			throw new invalidArgumentException(
294
+				sprintf(
295
+					__(
296
+						'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
297
+						'event_espresso'
298
+					),
299
+					$template_reference
300
+				)
301
+			);
302
+		}
303
+		$this->jsdata['templates'][$template_reference] = $template_content;
304
+	}
305
+
306
+
307
+
308
+	/**
309
+	 * Retrieve the template content already registered for the given reference.
310
+	 *
311
+	 * @param string $template_reference
312
+	 * @return string
313
+	 */
314
+	public function getTemplate($template_reference)
315
+	{
316
+		return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference])
317
+			? $this->jsdata['templates'][$template_reference]
318
+			: '';
319
+	}
320
+
321
+
322
+
323
+	/**
324
+	 * Retrieve registered data.
325
+	 *
326
+	 * @param string $key Name of key to attach data to.
327
+	 * @return mixed                If there is no for the given key, then false is returned.
328
+	 */
329
+	public function getData($key)
330
+	{
331
+		return isset($this->jsdata[$key])
332
+			? $this->jsdata[$key]
333
+			: false;
334
+	}
335
+
336
+
337
+	/**
338
+	 * Get the actual asset path for asset manifests.
339
+	 * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
340
+	 * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
341
+	 *                           asset file location.
342
+	 * @param string $chunk_name
343
+	 * @param string $asset_type
344
+	 * @return string
345
+	 * @since 4.9.59.p
346
+	 */
347
+	public function getAssetUrl($namespace, $chunk_name, $asset_type)
348
+	{
349
+		$url = isset(
350
+			$this->manifest_data[$namespace][$chunk_name][$asset_type],
351
+			$this->manifest_data[$namespace]['url_base']
352
+		)
353
+			? $this->manifest_data[$namespace]['url_base']
354
+			  . $this->manifest_data[$namespace][$chunk_name][$asset_type]
355
+			: $chunk_name;
356
+		return apply_filters(
357
+			'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
358
+			$url,
359
+			$namespace,
360
+			$chunk_name,
361
+			$asset_type
362
+		);
363
+	}
364
+
365
+
366
+	/**
367
+	 * Return the url to a js file for the given namespace and chunk name.
368
+	 *
369
+	 * @param string $namespace
370
+	 * @param string $chunk_name
371
+	 * @return string
372
+	 */
373
+	public function getJsUrl($namespace, $chunk_name)
374
+	{
375
+		return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_JS);
376
+	}
377
+
378
+
379
+	/**
380
+	 * Return the url to a css file for the given namespace and chunk name.
381
+	 *
382
+	 * @param string $namespace
383
+	 * @param string $chunk_name
384
+	 * @return string
385
+	 */
386
+	public function getCssUrl($namespace, $chunk_name)
387
+	{
388
+		return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_CSS);
389
+	}
390
+
391
+
392
+	/**
393
+	 * Used to register a js/css manifest file with the registered_manifest_files property.
394
+	 *
395
+	 * @param string $namespace     Provided to associate the manifest file with a specific namespace.
396
+	 * @param string $url_base      The url base for the manifest file location.
397
+	 * @param string $manifest_file The absolute path to the manifest file.
398
+	 * @throws InvalidArgumentException
399
+	 * @throws InvalidFilePathException
400
+	 * @since 4.9.59.p
401
+	 */
402
+	public function registerManifestFile($namespace, $url_base, $manifest_file)
403
+	{
404
+		if (isset($this->manifest_data[$namespace])) {
405
+			throw new InvalidArgumentException(
406
+				sprintf(
407
+					esc_html__(
408
+						'The namespace for this manifest file has already been registered, choose a namespace other than %s',
409
+						'event_espresso'
410
+					),
411
+					$namespace
412
+				)
413
+			);
414
+		}
415
+		if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
416
+			if (is_admin()) {
417
+				EE_Error::add_error(
418
+					sprintf(
419
+						esc_html__(
420
+							'The url given for %1$s assets is invalid.  The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant',
421
+							'event_espresso'
422
+						),
423
+						'Event Espresso',
424
+						$url_base,
425
+						'plugins_url',
426
+						'WP_PLUGIN_URL'
427
+					),
428
+					__FILE__,
429
+					__FUNCTION__,
430
+					__LINE__
431
+				);
432
+			}
433
+			return;
434
+		}
435
+		$this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file);
436
+		if (! isset($this->manifest_data[$namespace]['url_base'])) {
437
+			$this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base);
438
+		}
439
+	}
440
+
441
+
442
+
443
+	/**
444
+	 * Decodes json from the provided manifest file.
445
+	 *
446
+	 * @since 4.9.59.p
447
+	 * @param string $manifest_file Path to manifest file.
448
+	 * @return array
449
+	 * @throws InvalidFilePathException
450
+	 */
451
+	private function decodeManifestFile($manifest_file)
452
+	{
453
+		if (! file_exists($manifest_file)) {
454
+			throw new InvalidFilePathException($manifest_file);
455
+		}
456
+		return json_decode(file_get_contents($manifest_file), true);
457
+	}
458
+
459
+
460
+
461
+	/**
462
+	 * Verifies whether the given data exists already on the jsdata array.
463
+	 * Overriding data is not allowed.
464
+	 *
465
+	 * @param string $key Index for data.
466
+	 * @return bool        If valid then return true.
467
+	 * @throws InvalidArgumentException if data already exists.
468
+	 */
469
+	protected function verifyDataNotExisting($key)
470
+	{
471
+		if (isset($this->jsdata[$key])) {
472
+			if (is_array($this->jsdata[$key])) {
473
+				throw new InvalidArgumentException(
474
+					sprintf(
475
+						__(
476
+							'The value for %1$s already exists in the Registry::eejs object.
477 477
                             Overrides are not allowed. Since the value of this data is an array, you may want to use the
478 478
                             %2$s method to push your value to the array.',
479
-                            'event_espresso'
480
-                        ),
481
-                        $key,
482
-                        'pushData()'
483
-                    )
484
-                );
485
-            }
486
-            throw new InvalidArgumentException(
487
-                sprintf(
488
-                    __(
489
-                        'The value for %1$s already exists in the Registry::eejs object. Overrides are not
479
+							'event_espresso'
480
+						),
481
+						$key,
482
+						'pushData()'
483
+					)
484
+				);
485
+			}
486
+			throw new InvalidArgumentException(
487
+				sprintf(
488
+					__(
489
+						'The value for %1$s already exists in the Registry::eejs object. Overrides are not
490 490
                         allowed.  Consider attaching your value to a different key',
491
-                        'event_espresso'
492
-                    ),
493
-                    $key
494
-                )
495
-            );
496
-        }
497
-        return true;
498
-    }
499
-
500
-
501
-
502
-    /**
503
-     * registers core default stylesheets
504
-     */
505
-    private function loadCoreCss()
506
-    {
507
-        if ($this->template_config->enable_default_style) {
508
-            $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
509
-                ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
510
-                : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css';
511
-            wp_register_style(
512
-                'espresso_default',
513
-                $default_stylesheet_path,
514
-                array('dashicons'),
515
-                EVENT_ESPRESSO_VERSION
516
-            );
517
-            //Load custom style sheet if available
518
-            if ($this->template_config->custom_style_sheet !== null) {
519
-                wp_register_style(
520
-                    'espresso_custom_css',
521
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
522
-                    array('espresso_default'),
523
-                    EVENT_ESPRESSO_VERSION
524
-                );
525
-            }
526
-        }
527
-    }
528
-
529
-
530
-
531
-    /**
532
-     * registers core default javascript
533
-     */
534
-    private function loadCoreJs()
535
-    {
536
-        // load core js
537
-        wp_register_script(
538
-            'espresso_core',
539
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
540
-            array('jquery'),
541
-            EVENT_ESPRESSO_VERSION,
542
-            true
543
-        );
544
-    }
545
-
546
-
547
-
548
-    /**
549
-     * registers jQuery Validate for form validation
550
-     */
551
-    private function loadJqueryValidate()
552
-    {
553
-        // register jQuery Validate and additional methods
554
-        wp_register_script(
555
-            'jquery-validate',
556
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
557
-            array('jquery'),
558
-            '1.15.0',
559
-            true
560
-        );
561
-        wp_register_script(
562
-            'jquery-validate-extra-methods',
563
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
564
-            array('jquery', 'jquery-validate'),
565
-            '1.15.0',
566
-            true
567
-        );
568
-    }
569
-
570
-
571
-
572
-    /**
573
-     * registers accounting.js for performing client-side calculations
574
-     */
575
-    private function loadAccountingJs()
576
-    {
577
-        //accounting.js library
578
-        // @link http://josscrowcroft.github.io/accounting.js/
579
-        wp_register_script(
580
-            'ee-accounting-core',
581
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
582
-            array('underscore'),
583
-            '0.3.2',
584
-            true
585
-        );
586
-        wp_register_script(
587
-            'ee-accounting',
588
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
589
-            array('ee-accounting-core'),
590
-            EVENT_ESPRESSO_VERSION,
591
-            true
592
-        );
593
-    }
594
-
595
-
596
-
597
-    /**
598
-     * registers accounting.js for performing client-side calculations
599
-     */
600
-    private function localizeAccountingJs()
601
-    {
602
-        wp_localize_script(
603
-            'ee-accounting',
604
-            'EE_ACCOUNTING_CFG',
605
-            array(
606
-                'currency' => array(
607
-                    'symbol'    => $this->currency_config->sign,
608
-                    'format'    => array(
609
-                        'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
610
-                        'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
611
-                        'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
612
-                    ),
613
-                    'decimal'   => $this->currency_config->dec_mrk,
614
-                    'thousand'  => $this->currency_config->thsnds,
615
-                    'precision' => $this->currency_config->dec_plc,
616
-                ),
617
-                'number'   => array(
618
-                    'precision' => $this->currency_config->dec_plc,
619
-                    'thousand'  => $this->currency_config->thsnds,
620
-                    'decimal'   => $this->currency_config->dec_mrk,
621
-                ),
622
-            )
623
-        );
624
-        $this->addRegisteredScriptHandlesWithData('ee-accounting');
625
-    }
626
-
627
-
628
-
629
-    /**
630
-     * registers assets for cleaning your ears
631
-     */
632
-    private function loadQtipJs()
633
-    {
634
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
635
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
636
-        if (apply_filters('FHEE_load_qtip', false)) {
637
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
638
-        }
639
-    }
640
-
641
-
642
-    /**
643
-     * This is used to set registered script handles that have data.
644
-     * @param string $script_handle
645
-     */
646
-    private function addRegisteredScriptHandlesWithData($script_handle)
647
-    {
648
-        $this->script_handles_with_data[$script_handle] = $script_handle;
649
-    }
650
-
651
-
652
-    /**i
491
+						'event_espresso'
492
+					),
493
+					$key
494
+				)
495
+			);
496
+		}
497
+		return true;
498
+	}
499
+
500
+
501
+
502
+	/**
503
+	 * registers core default stylesheets
504
+	 */
505
+	private function loadCoreCss()
506
+	{
507
+		if ($this->template_config->enable_default_style) {
508
+			$default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
509
+				? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
510
+				: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css';
511
+			wp_register_style(
512
+				'espresso_default',
513
+				$default_stylesheet_path,
514
+				array('dashicons'),
515
+				EVENT_ESPRESSO_VERSION
516
+			);
517
+			//Load custom style sheet if available
518
+			if ($this->template_config->custom_style_sheet !== null) {
519
+				wp_register_style(
520
+					'espresso_custom_css',
521
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
522
+					array('espresso_default'),
523
+					EVENT_ESPRESSO_VERSION
524
+				);
525
+			}
526
+		}
527
+	}
528
+
529
+
530
+
531
+	/**
532
+	 * registers core default javascript
533
+	 */
534
+	private function loadCoreJs()
535
+	{
536
+		// load core js
537
+		wp_register_script(
538
+			'espresso_core',
539
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
540
+			array('jquery'),
541
+			EVENT_ESPRESSO_VERSION,
542
+			true
543
+		);
544
+	}
545
+
546
+
547
+
548
+	/**
549
+	 * registers jQuery Validate for form validation
550
+	 */
551
+	private function loadJqueryValidate()
552
+	{
553
+		// register jQuery Validate and additional methods
554
+		wp_register_script(
555
+			'jquery-validate',
556
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
557
+			array('jquery'),
558
+			'1.15.0',
559
+			true
560
+		);
561
+		wp_register_script(
562
+			'jquery-validate-extra-methods',
563
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
564
+			array('jquery', 'jquery-validate'),
565
+			'1.15.0',
566
+			true
567
+		);
568
+	}
569
+
570
+
571
+
572
+	/**
573
+	 * registers accounting.js for performing client-side calculations
574
+	 */
575
+	private function loadAccountingJs()
576
+	{
577
+		//accounting.js library
578
+		// @link http://josscrowcroft.github.io/accounting.js/
579
+		wp_register_script(
580
+			'ee-accounting-core',
581
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
582
+			array('underscore'),
583
+			'0.3.2',
584
+			true
585
+		);
586
+		wp_register_script(
587
+			'ee-accounting',
588
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
589
+			array('ee-accounting-core'),
590
+			EVENT_ESPRESSO_VERSION,
591
+			true
592
+		);
593
+	}
594
+
595
+
596
+
597
+	/**
598
+	 * registers accounting.js for performing client-side calculations
599
+	 */
600
+	private function localizeAccountingJs()
601
+	{
602
+		wp_localize_script(
603
+			'ee-accounting',
604
+			'EE_ACCOUNTING_CFG',
605
+			array(
606
+				'currency' => array(
607
+					'symbol'    => $this->currency_config->sign,
608
+					'format'    => array(
609
+						'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
610
+						'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
611
+						'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
612
+					),
613
+					'decimal'   => $this->currency_config->dec_mrk,
614
+					'thousand'  => $this->currency_config->thsnds,
615
+					'precision' => $this->currency_config->dec_plc,
616
+				),
617
+				'number'   => array(
618
+					'precision' => $this->currency_config->dec_plc,
619
+					'thousand'  => $this->currency_config->thsnds,
620
+					'decimal'   => $this->currency_config->dec_mrk,
621
+				),
622
+			)
623
+		);
624
+		$this->addRegisteredScriptHandlesWithData('ee-accounting');
625
+	}
626
+
627
+
628
+
629
+	/**
630
+	 * registers assets for cleaning your ears
631
+	 */
632
+	private function loadQtipJs()
633
+	{
634
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
635
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
636
+		if (apply_filters('FHEE_load_qtip', false)) {
637
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
638
+		}
639
+	}
640
+
641
+
642
+	/**
643
+	 * This is used to set registered script handles that have data.
644
+	 * @param string $script_handle
645
+	 */
646
+	private function addRegisteredScriptHandlesWithData($script_handle)
647
+	{
648
+		$this->script_handles_with_data[$script_handle] = $script_handle;
649
+	}
650
+
651
+
652
+	/**i
653 653
      * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the
654 654
      * Dependency stored in WP_Scripts if its set.
655 655
      */
656
-    private function removeAlreadyRegisteredDataForScriptHandles()
657
-    {
658
-        if (empty($this->script_handles_with_data)) {
659
-            return;
660
-        }
661
-        foreach ($this->script_handles_with_data as $script_handle) {
662
-            $this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
663
-        }
664
-    }
665
-
666
-
667
-    /**
668
-     * Removes any data dependency registered in WP_Scripts if its set.
669
-     * @param string $script_handle
670
-     */
671
-    private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
672
-    {
673
-        if (isset($this->script_handles_with_data[$script_handle])) {
674
-            global $wp_scripts;
675
-            $unset_handle = false;
676
-            if ($wp_scripts->get_data($script_handle, 'data')) {
677
-                unset($wp_scripts->registered[$script_handle]->extra['data']);
678
-                $unset_handle = true;
679
-            }
680
-            //deal with inline_scripts
681
-            if ($wp_scripts->get_data($script_handle, 'before')) {
682
-                unset($wp_scripts->registered[$script_handle]->extra['before']);
683
-                $unset_handle = true;
684
-            }
685
-            if ($wp_scripts->get_data($script_handle, 'after')) {
686
-                unset($wp_scripts->registered[$script_handle]->extra['after']);
687
-            }
688
-            if ($unset_handle) {
689
-                unset($this->script_handles_with_data[$script_handle]);
690
-            }
691
-        }
692
-    }
693
-
694
-
695
-    /**
696
-     * Registers assets that are used in the WordPress admin.
697
-     */
698
-    private function registerAdminAssets()
699
-    {
700
-        wp_register_script(
701
-            'ee-wp-plugins-page',
702
-            $this->getJsUrl(self::ASSET_NAMESPACE, 'wp-plugins-page'),
703
-            array(
704
-                'jquery',
705
-                'ee-vendor-react'
706
-            ),
707
-            null,
708
-            true
709
-        );
710
-        wp_register_style(
711
-            'ee-wp-plugins-page',
712
-            $this->getCssUrl(self::ASSET_NAMESPACE, 'wp-plugins-page'),
713
-            array(),
714
-            null
715
-        );
716
-        $this->registerTranslationsForHandles(array('ee-wp-plugins-page'));
717
-    }
718
-
719
-
720
-    /**
721
-     * All handles that are registered via the registry that might have translations have their translations registered
722
-     *
723
-     * @param array $handles_to_register
724
-     */
725
-    private function registerTranslationsForHandles(array $handles_to_register)
726
-    {
727
-        foreach($handles_to_register as $handle) {
728
-            $this->i18n_registry->registerScriptI18n($handle);
729
-        }
730
-    }
656
+	private function removeAlreadyRegisteredDataForScriptHandles()
657
+	{
658
+		if (empty($this->script_handles_with_data)) {
659
+			return;
660
+		}
661
+		foreach ($this->script_handles_with_data as $script_handle) {
662
+			$this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
663
+		}
664
+	}
665
+
666
+
667
+	/**
668
+	 * Removes any data dependency registered in WP_Scripts if its set.
669
+	 * @param string $script_handle
670
+	 */
671
+	private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
672
+	{
673
+		if (isset($this->script_handles_with_data[$script_handle])) {
674
+			global $wp_scripts;
675
+			$unset_handle = false;
676
+			if ($wp_scripts->get_data($script_handle, 'data')) {
677
+				unset($wp_scripts->registered[$script_handle]->extra['data']);
678
+				$unset_handle = true;
679
+			}
680
+			//deal with inline_scripts
681
+			if ($wp_scripts->get_data($script_handle, 'before')) {
682
+				unset($wp_scripts->registered[$script_handle]->extra['before']);
683
+				$unset_handle = true;
684
+			}
685
+			if ($wp_scripts->get_data($script_handle, 'after')) {
686
+				unset($wp_scripts->registered[$script_handle]->extra['after']);
687
+			}
688
+			if ($unset_handle) {
689
+				unset($this->script_handles_with_data[$script_handle]);
690
+			}
691
+		}
692
+	}
693
+
694
+
695
+	/**
696
+	 * Registers assets that are used in the WordPress admin.
697
+	 */
698
+	private function registerAdminAssets()
699
+	{
700
+		wp_register_script(
701
+			'ee-wp-plugins-page',
702
+			$this->getJsUrl(self::ASSET_NAMESPACE, 'wp-plugins-page'),
703
+			array(
704
+				'jquery',
705
+				'ee-vendor-react'
706
+			),
707
+			null,
708
+			true
709
+		);
710
+		wp_register_style(
711
+			'ee-wp-plugins-page',
712
+			$this->getCssUrl(self::ASSET_NAMESPACE, 'wp-plugins-page'),
713
+			array(),
714
+			null
715
+		);
716
+		$this->registerTranslationsForHandles(array('ee-wp-plugins-page'));
717
+	}
718
+
719
+
720
+	/**
721
+	 * All handles that are registered via the registry that might have translations have their translations registered
722
+	 *
723
+	 * @param array $handles_to_register
724
+	 */
725
+	private function registerTranslationsForHandles(array $handles_to_register)
726
+	{
727
+		foreach($handles_to_register as $handle) {
728
+			$this->i18n_registry->registerScriptI18n($handle);
729
+		}
730
+	}
731 731
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
         $this->registerManifestFile(
115 115
             self::ASSET_NAMESPACE,
116 116
             $this->domain->distributionAssetsUrl(),
117
-            $this->domain->distributionAssetsPath() . 'build-manifest.json'
117
+            $this->domain->distributionAssetsPath().'build-manifest.json'
118 118
         );
119 119
         add_action('wp_enqueue_scripts', array($this, 'scripts'), 1);
120 120
         add_action('admin_enqueue_scripts', array($this, 'scripts'), 1);
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
             //js.api
172 172
             wp_register_script(
173 173
                 'eejs-api',
174
-                EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
174
+                EE_LIBRARIES_URL.'rest_api/assets/js/eejs-api.min.js',
175 175
                 array('underscore', 'eejs-core'),
176 176
                 EVENT_ESPRESSO_VERSION,
177 177
                 true
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
                 'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName()
183 183
             );
184 184
         }
185
-        if (! is_admin()) {
185
+        if ( ! is_admin()) {
186 186
             $this->loadCoreCss();
187 187
         }
188 188
         $this->registerTranslationsForHandles(array('eejs-core'));
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
         $this->removeAlreadyRegisteredDataForScriptHandles();
207 207
         wp_add_inline_script(
208 208
             'eejs-core',
209
-            'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
209
+            'var eejsdata='.wp_json_encode(array('data' => $this->jsdata)),
210 210
             'before'
211 211
         );
212 212
         wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
      */
286 286
     public function addTemplate($template_reference, $template_content)
287 287
     {
288
-        if (! isset($this->jsdata['templates'])) {
288
+        if ( ! isset($this->jsdata['templates'])) {
289 289
             $this->jsdata['templates'] = array();
290 290
         }
291 291
         //no overrides allowed.
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
             return;
434 434
         }
435 435
         $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file);
436
-        if (! isset($this->manifest_data[$namespace]['url_base'])) {
436
+        if ( ! isset($this->manifest_data[$namespace]['url_base'])) {
437 437
             $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base);
438 438
         }
439 439
     }
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
      */
451 451
     private function decodeManifestFile($manifest_file)
452 452
     {
453
-        if (! file_exists($manifest_file)) {
453
+        if ( ! file_exists($manifest_file)) {
454 454
             throw new InvalidFilePathException($manifest_file);
455 455
         }
456 456
         return json_decode(file_get_contents($manifest_file), true);
@@ -505,9 +505,9 @@  discard block
 block discarded – undo
505 505
     private function loadCoreCss()
506 506
     {
507 507
         if ($this->template_config->enable_default_style) {
508
-            $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
508
+            $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css')
509 509
                 ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
510
-                : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css';
510
+                : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css';
511 511
             wp_register_style(
512 512
                 'espresso_default',
513 513
                 $default_stylesheet_path,
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
             if ($this->template_config->custom_style_sheet !== null) {
519 519
                 wp_register_style(
520 520
                     'espresso_custom_css',
521
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
521
+                    EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet,
522 522
                     array('espresso_default'),
523 523
                     EVENT_ESPRESSO_VERSION
524 524
                 );
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
         // load core js
537 537
         wp_register_script(
538 538
             'espresso_core',
539
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
539
+            EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
540 540
             array('jquery'),
541 541
             EVENT_ESPRESSO_VERSION,
542 542
             true
@@ -553,14 +553,14 @@  discard block
 block discarded – undo
553 553
         // register jQuery Validate and additional methods
554 554
         wp_register_script(
555 555
             'jquery-validate',
556
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
556
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js',
557 557
             array('jquery'),
558 558
             '1.15.0',
559 559
             true
560 560
         );
561 561
         wp_register_script(
562 562
             'jquery-validate-extra-methods',
563
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
563
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js',
564 564
             array('jquery', 'jquery-validate'),
565 565
             '1.15.0',
566 566
             true
@@ -578,14 +578,14 @@  discard block
 block discarded – undo
578 578
         // @link http://josscrowcroft.github.io/accounting.js/
579 579
         wp_register_script(
580 580
             'ee-accounting-core',
581
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
581
+            EE_THIRD_PARTY_URL.'accounting/accounting.js',
582 582
             array('underscore'),
583 583
             '0.3.2',
584 584
             true
585 585
         );
586 586
         wp_register_script(
587 587
             'ee-accounting',
588
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
588
+            EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js',
589 589
             array('ee-accounting-core'),
590 590
             EVENT_ESPRESSO_VERSION,
591 591
             true
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
      */
725 725
     private function registerTranslationsForHandles(array $handles_to_register)
726 726
     {
727
-        foreach($handles_to_register as $handle) {
727
+        foreach ($handles_to_register as $handle) {
728 728
             $this->i18n_registry->registerScriptI18n($handle);
729 729
         }
730 730
     }
Please login to merge, or discard this patch.
core/services/collections/CollectionLoader.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -163,7 +163,7 @@
 block discarded – undo
163 163
 
164 164
     /**
165 165
      * @param        $entity
166
-     * @param  mixed $identifier
166
+     * @param  string $identifier
167 167
      * @return string
168 168
      * @throws InvalidEntityException
169 169
      */
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
         LocatorInterface $file_locator = null
85 85
     ) {
86 86
         $this->collection_details = $collection_details;
87
-        if (! $collection instanceof CollectionInterface) {
87
+        if ( ! $collection instanceof CollectionInterface) {
88 88
             $collection = new Collection($this->collection_details->getCollectionInterface());
89 89
         }
90 90
         $this->collection = $collection;
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
      */
112 112
     protected function loadAllFromFilepaths()
113 113
     {
114
-        if (! $this->file_locator instanceof FileLocator) {
114
+        if ( ! $this->file_locator instanceof FileLocator) {
115 115
             $this->file_locator = new FileLocator();
116 116
         }
117 117
         $this->file_locator->setFileMask($this->collection_details->getFileMask());
@@ -143,10 +143,10 @@  discard block
 block discarded – undo
143 143
      */
144 144
     protected function loadClassFromFilepath($filepath)
145 145
     {
146
-        if (! is_string($filepath)) {
146
+        if ( ! is_string($filepath)) {
147 147
             throw new InvalidDataTypeException('$filepath', $filepath, 'string');
148 148
         }
149
-        if (! is_readable($filepath)) {
149
+        if ( ! is_readable($filepath)) {
150 150
             throw new InvalidFilePathException($filepath);
151 151
         }
152 152
         require_once $filepath;
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
         $file_name = basename($filepath);
155 155
         // now remove any file extensions
156 156
         $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name);
157
-        if (! class_exists($class_name)) {
157
+        if ( ! class_exists($class_name)) {
158 158
             throw new InvalidClassException($class_name);
159 159
         }
160 160
         return $this->addEntityToCollection(new $class_name(), $file_name);
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
             // objects added to the collection based on entity callback, so the entity itself decides
225 225
             case CollectionDetails::ID_CALLBACK_METHOD:
226 226
                 $identifier_callback = $this->collection_details->identifierCallback();
227
-                if (! method_exists($entity, $identifier_callback)) {
227
+                if ( ! method_exists($entity, $identifier_callback)) {
228 228
                     throw new InvalidEntityException(
229 229
                         $entity,
230 230
                         $this->collection_details->getCollectionInterface(),
@@ -288,10 +288,10 @@  discard block
 block discarded – undo
288 288
      */
289 289
     protected function loadClassFromFQCN($FQCN)
290 290
     {
291
-        if (! is_string($FQCN)) {
291
+        if ( ! is_string($FQCN)) {
292 292
             throw new InvalidDataTypeException('$FQCN', $FQCN, 'string');
293 293
         }
294
-        if (! class_exists($FQCN)) {
294
+        if ( ! class_exists($FQCN)) {
295 295
             throw new InvalidClassException($FQCN);
296 296
         }
297 297
         return $this->addEntityToCollection(
Please login to merge, or discard this patch.
Indentation   +249 added lines, -249 removed lines patch added patch discarded remove patch
@@ -27,276 +27,276 @@
 block discarded – undo
27 27
 class CollectionLoader
28 28
 {
29 29
 
30
-    /**
31
-     * possible return value when adding entities to a collection.
32
-     * denotes that the entity was NOT ADDED to the collection
33
-     */
34
-    const ENTITY_NOT_ADDED = 'entity-not-added-to-collection';
30
+	/**
31
+	 * possible return value when adding entities to a collection.
32
+	 * denotes that the entity was NOT ADDED to the collection
33
+	 */
34
+	const ENTITY_NOT_ADDED = 'entity-not-added-to-collection';
35 35
 
36
-    /**
37
-     * possible return value when adding entities to a collection.
38
-     * denotes that the entity was SUCCESSFULLY ADDED to the collection
39
-     */
40
-    const ENTITY_ADDED = 'entity-added-to-collection';
36
+	/**
37
+	 * possible return value when adding entities to a collection.
38
+	 * denotes that the entity was SUCCESSFULLY ADDED to the collection
39
+	 */
40
+	const ENTITY_ADDED = 'entity-added-to-collection';
41 41
 
42
-    /**
43
-     * possible return value when adding entities to a collection.
44
-     * denotes that the entity was ALREADY ADDED to the collection,
45
-     * and therefore could not be added again.
46
-     */
47
-    const ENTITY_EXISTS = 'entity-already-in-collection';
42
+	/**
43
+	 * possible return value when adding entities to a collection.
44
+	 * denotes that the entity was ALREADY ADDED to the collection,
45
+	 * and therefore could not be added again.
46
+	 */
47
+	const ENTITY_EXISTS = 'entity-already-in-collection';
48 48
 
49 49
 
50
-    /**
51
-     * @var CollectionDetailsInterface $collection_details
52
-     */
53
-    protected $collection_details;
50
+	/**
51
+	 * @var CollectionDetailsInterface $collection_details
52
+	 */
53
+	protected $collection_details;
54 54
 
55
-    /**
56
-     * @var CollectionInterface $collection
57
-     */
58
-    protected $collection;
55
+	/**
56
+	 * @var CollectionInterface $collection
57
+	 */
58
+	protected $collection;
59 59
 
60
-    /**
61
-     * @var FileLocator $file_locator
62
-     */
63
-    protected $file_locator;
60
+	/**
61
+	 * @var FileLocator $file_locator
62
+	 */
63
+	protected $file_locator;
64 64
 
65 65
 
66
-    /**
67
-     * CollectionLoader constructor.
68
-     *
69
-     * @param CollectionDetailsInterface $collection_details
70
-     * @param CollectionInterface        $collection
71
-     * @param LocatorInterface           $file_locator
72
-     * @throws ReflectionException
73
-     * @throws InvalidArgumentException
74
-     * @throws EE_Error
75
-     * @throws InvalidInterfaceException
76
-     * @throws InvalidClassException
77
-     * @throws InvalidDataTypeException
78
-     * @throws InvalidFilePathException
79
-     * @throws InvalidEntityException
80
-     */
81
-    public function __construct(
82
-        CollectionDetailsInterface $collection_details,
83
-        CollectionInterface $collection = null,
84
-        LocatorInterface $file_locator = null
85
-    ) {
86
-        $this->collection_details = $collection_details;
87
-        if (! $collection instanceof CollectionInterface) {
88
-            $collection = new Collection($this->collection_details->getCollectionInterface());
89
-        }
90
-        $this->collection = $collection;
91
-        $this->file_locator = $file_locator;
92
-        $this->loadAllFromFilepaths();
93
-        $this->loadFromFQCNs();
94
-    }
66
+	/**
67
+	 * CollectionLoader constructor.
68
+	 *
69
+	 * @param CollectionDetailsInterface $collection_details
70
+	 * @param CollectionInterface        $collection
71
+	 * @param LocatorInterface           $file_locator
72
+	 * @throws ReflectionException
73
+	 * @throws InvalidArgumentException
74
+	 * @throws EE_Error
75
+	 * @throws InvalidInterfaceException
76
+	 * @throws InvalidClassException
77
+	 * @throws InvalidDataTypeException
78
+	 * @throws InvalidFilePathException
79
+	 * @throws InvalidEntityException
80
+	 */
81
+	public function __construct(
82
+		CollectionDetailsInterface $collection_details,
83
+		CollectionInterface $collection = null,
84
+		LocatorInterface $file_locator = null
85
+	) {
86
+		$this->collection_details = $collection_details;
87
+		if (! $collection instanceof CollectionInterface) {
88
+			$collection = new Collection($this->collection_details->getCollectionInterface());
89
+		}
90
+		$this->collection = $collection;
91
+		$this->file_locator = $file_locator;
92
+		$this->loadAllFromFilepaths();
93
+		$this->loadFromFQCNs();
94
+	}
95 95
 
96 96
 
97
-    /**
98
-     * @return CollectionInterface
99
-     */
100
-    public function getCollection()
101
-    {
102
-        return $this->collection;
103
-    }
97
+	/**
98
+	 * @return CollectionInterface
99
+	 */
100
+	public function getCollection()
101
+	{
102
+		return $this->collection;
103
+	}
104 104
 
105 105
 
106
-    /**
107
-     * @throws InvalidClassException
108
-     * @throws InvalidFilePathException
109
-     * @throws InvalidDataTypeException
110
-     * @throws InvalidEntityException
111
-     */
112
-    protected function loadAllFromFilepaths()
113
-    {
114
-        if (! $this->file_locator instanceof FileLocator) {
115
-            $this->file_locator = new FileLocator();
116
-        }
117
-        $this->file_locator->setFileMask($this->collection_details->getFileMask());
118
-        // find all of the files that match the file mask in the specified folder
119
-        $this->file_locator->locate($this->collection_details->getCollectionPaths());
120
-        // filter the results
121
-        $filepaths = (array) apply_filters(
122
-            'FHEE__CollectionLoader__loadAllFromFilepath__filepaths',
123
-            $this->file_locator->getFilePaths(),
124
-            $this->collection_details->collectionName(),
125
-            $this->collection_details
126
-        );
127
-        if (empty($filepaths)) {
128
-            return;
129
-        }
130
-        foreach ($filepaths as $filepath) {
131
-            $this->loadClassFromFilepath($filepath);
132
-        }
133
-    }
106
+	/**
107
+	 * @throws InvalidClassException
108
+	 * @throws InvalidFilePathException
109
+	 * @throws InvalidDataTypeException
110
+	 * @throws InvalidEntityException
111
+	 */
112
+	protected function loadAllFromFilepaths()
113
+	{
114
+		if (! $this->file_locator instanceof FileLocator) {
115
+			$this->file_locator = new FileLocator();
116
+		}
117
+		$this->file_locator->setFileMask($this->collection_details->getFileMask());
118
+		// find all of the files that match the file mask in the specified folder
119
+		$this->file_locator->locate($this->collection_details->getCollectionPaths());
120
+		// filter the results
121
+		$filepaths = (array) apply_filters(
122
+			'FHEE__CollectionLoader__loadAllFromFilepath__filepaths',
123
+			$this->file_locator->getFilePaths(),
124
+			$this->collection_details->collectionName(),
125
+			$this->collection_details
126
+		);
127
+		if (empty($filepaths)) {
128
+			return;
129
+		}
130
+		foreach ($filepaths as $filepath) {
131
+			$this->loadClassFromFilepath($filepath);
132
+		}
133
+	}
134 134
 
135 135
 
136
-    /**
137
-     * @param  string $filepath
138
-     * @return string
139
-     * @throws InvalidEntityException
140
-     * @throws InvalidDataTypeException
141
-     * @throws InvalidFilePathException
142
-     * @throws InvalidClassException
143
-     */
144
-    protected function loadClassFromFilepath($filepath)
145
-    {
146
-        if (! is_string($filepath)) {
147
-            throw new InvalidDataTypeException('$filepath', $filepath, 'string');
148
-        }
149
-        if (! is_readable($filepath)) {
150
-            throw new InvalidFilePathException($filepath);
151
-        }
152
-        require_once $filepath;
153
-        // extract filename from path
154
-        $file_name = basename($filepath);
155
-        // now remove any file extensions
156
-        $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name);
157
-        if (! class_exists($class_name)) {
158
-            throw new InvalidClassException($class_name);
159
-        }
160
-        return $this->addEntityToCollection(new $class_name(), $file_name);
161
-    }
136
+	/**
137
+	 * @param  string $filepath
138
+	 * @return string
139
+	 * @throws InvalidEntityException
140
+	 * @throws InvalidDataTypeException
141
+	 * @throws InvalidFilePathException
142
+	 * @throws InvalidClassException
143
+	 */
144
+	protected function loadClassFromFilepath($filepath)
145
+	{
146
+		if (! is_string($filepath)) {
147
+			throw new InvalidDataTypeException('$filepath', $filepath, 'string');
148
+		}
149
+		if (! is_readable($filepath)) {
150
+			throw new InvalidFilePathException($filepath);
151
+		}
152
+		require_once $filepath;
153
+		// extract filename from path
154
+		$file_name = basename($filepath);
155
+		// now remove any file extensions
156
+		$class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name);
157
+		if (! class_exists($class_name)) {
158
+			throw new InvalidClassException($class_name);
159
+		}
160
+		return $this->addEntityToCollection(new $class_name(), $file_name);
161
+	}
162 162
 
163 163
 
164
-    /**
165
-     * @param        $entity
166
-     * @param  mixed $identifier
167
-     * @return string
168
-     * @throws InvalidEntityException
169
-     */
170
-    protected function addEntityToCollection($entity, $identifier)
171
-    {
172
-        do_action(
173
-            'FHEE__CollectionLoader__addEntityToCollection__entity',
174
-            $entity,
175
-            $this->collection_details->collectionName(),
176
-            $this->collection_details
177
-        );
178
-        $identifier = $this->setIdentifier($entity, $identifier);
179
-        if ($this->collection->has($identifier)) {
180
-            do_action(
181
-                'FHEE__CollectionLoader__addEntityToCollection__entity_already_added',
182
-                $this,
183
-                $this->collection_details->collectionName(),
184
-                $this->collection_details
185
-            );
186
-            return CollectionLoader::ENTITY_EXISTS;
187
-        }
188
-        if ($this->collection->add($entity, $identifier)) {
189
-            do_action(
190
-                'FHEE__CollectionLoader__addEntityToCollection__entity_added',
191
-                $this,
192
-                $this->collection_details->collectionName(),
193
-                $this->collection_details
194
-            );
195
-            return CollectionLoader::ENTITY_ADDED;
196
-        }
197
-        do_action(
198
-            'FHEE__CollectionLoader__addEntityToCollection__entity_not_added',
199
-            $this,
200
-            $this->collection_details->collectionName(),
201
-            $this->collection_details
202
-        );
203
-        return CollectionLoader::ENTITY_NOT_ADDED;
204
-    }
164
+	/**
165
+	 * @param        $entity
166
+	 * @param  mixed $identifier
167
+	 * @return string
168
+	 * @throws InvalidEntityException
169
+	 */
170
+	protected function addEntityToCollection($entity, $identifier)
171
+	{
172
+		do_action(
173
+			'FHEE__CollectionLoader__addEntityToCollection__entity',
174
+			$entity,
175
+			$this->collection_details->collectionName(),
176
+			$this->collection_details
177
+		);
178
+		$identifier = $this->setIdentifier($entity, $identifier);
179
+		if ($this->collection->has($identifier)) {
180
+			do_action(
181
+				'FHEE__CollectionLoader__addEntityToCollection__entity_already_added',
182
+				$this,
183
+				$this->collection_details->collectionName(),
184
+				$this->collection_details
185
+			);
186
+			return CollectionLoader::ENTITY_EXISTS;
187
+		}
188
+		if ($this->collection->add($entity, $identifier)) {
189
+			do_action(
190
+				'FHEE__CollectionLoader__addEntityToCollection__entity_added',
191
+				$this,
192
+				$this->collection_details->collectionName(),
193
+				$this->collection_details
194
+			);
195
+			return CollectionLoader::ENTITY_ADDED;
196
+		}
197
+		do_action(
198
+			'FHEE__CollectionLoader__addEntityToCollection__entity_not_added',
199
+			$this,
200
+			$this->collection_details->collectionName(),
201
+			$this->collection_details
202
+		);
203
+		return CollectionLoader::ENTITY_NOT_ADDED;
204
+	}
205 205
 
206 206
 
207
-    /**
208
-     * @param        $entity
209
-     * @param  mixed $identifier
210
-     * @return string
211
-     * @throws InvalidEntityException
212
-     */
213
-    protected function setIdentifier($entity, $identifier)
214
-    {
215
-        switch ($this->collection_details->identifierType()) {
216
-            // every unique object gets added to the collection, but not duplicates of the exact same object
217
-            case CollectionDetails::ID_OBJECT_HASH:
218
-                $identifier = spl_object_hash($entity);
219
-                break;
220
-            // only one entity per class can be added to collection, like a singleton
221
-            case CollectionDetails::ID_CLASS_NAME:
222
-                $identifier = get_class($entity);
223
-                break;
224
-            // objects added to the collection based on entity callback, so the entity itself decides
225
-            case CollectionDetails::ID_CALLBACK_METHOD:
226
-                $identifier_callback = $this->collection_details->identifierCallback();
227
-                if (! method_exists($entity, $identifier_callback)) {
228
-                    throw new InvalidEntityException(
229
-                        $entity,
230
-                        $this->collection_details->getCollectionInterface(),
231
-                        sprintf(
232
-                            __(
233
-                                'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance
207
+	/**
208
+	 * @param        $entity
209
+	 * @param  mixed $identifier
210
+	 * @return string
211
+	 * @throws InvalidEntityException
212
+	 */
213
+	protected function setIdentifier($entity, $identifier)
214
+	{
215
+		switch ($this->collection_details->identifierType()) {
216
+			// every unique object gets added to the collection, but not duplicates of the exact same object
217
+			case CollectionDetails::ID_OBJECT_HASH:
218
+				$identifier = spl_object_hash($entity);
219
+				break;
220
+			// only one entity per class can be added to collection, like a singleton
221
+			case CollectionDetails::ID_CLASS_NAME:
222
+				$identifier = get_class($entity);
223
+				break;
224
+			// objects added to the collection based on entity callback, so the entity itself decides
225
+			case CollectionDetails::ID_CALLBACK_METHOD:
226
+				$identifier_callback = $this->collection_details->identifierCallback();
227
+				if (! method_exists($entity, $identifier_callback)) {
228
+					throw new InvalidEntityException(
229
+						$entity,
230
+						$this->collection_details->getCollectionInterface(),
231
+						sprintf(
232
+							__(
233
+								'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance
234 234
                                 of "%2$s", but does not contain this method.',
235
-                                'event_espresso'
236
-                            ),
237
-                            $identifier_callback,
238
-                            get_class($entity)
239
-                        )
240
-                    );
241
-                }
242
-                $identifier = $entity->{$identifier_callback}();
243
-                break;
244
-        }
245
-        return apply_filters(
246
-            'FHEE__CollectionLoader__addEntityToCollection__identifier',
247
-            $identifier,
248
-            $this->collection_details->collectionName(),
249
-            $this->collection_details
250
-        );
251
-    }
235
+								'event_espresso'
236
+							),
237
+							$identifier_callback,
238
+							get_class($entity)
239
+						)
240
+					);
241
+				}
242
+				$identifier = $entity->{$identifier_callback}();
243
+				break;
244
+		}
245
+		return apply_filters(
246
+			'FHEE__CollectionLoader__addEntityToCollection__identifier',
247
+			$identifier,
248
+			$this->collection_details->collectionName(),
249
+			$this->collection_details
250
+		);
251
+	}
252 252
 
253 253
 
254
-    /**
255
-     * @throws ReflectionException
256
-     * @throws InvalidArgumentException
257
-     * @throws InvalidInterfaceException
258
-     * @throws EE_Error
259
-     * @throws InvalidClassException
260
-     * @throws InvalidDataTypeException
261
-     * @throws InvalidEntityException
262
-     */
263
-    protected function loadFromFQCNs()
264
-    {
265
-        $FQCNs = $this->collection_details->getCollectionFQCNs();
266
-        $FQCNs = (array) apply_filters(
267
-            'FHEE__CollectionLoader__loadAllFromFQCNs__FQCNs',
268
-            $FQCNs,
269
-            $this->collection_details->collectionName(),
270
-            $this->collection_details
271
-        );
272
-        foreach ($FQCNs as $FQCN) {
273
-            $this->loadClassFromFQCN($FQCN);
274
-        }
275
-    }
254
+	/**
255
+	 * @throws ReflectionException
256
+	 * @throws InvalidArgumentException
257
+	 * @throws InvalidInterfaceException
258
+	 * @throws EE_Error
259
+	 * @throws InvalidClassException
260
+	 * @throws InvalidDataTypeException
261
+	 * @throws InvalidEntityException
262
+	 */
263
+	protected function loadFromFQCNs()
264
+	{
265
+		$FQCNs = $this->collection_details->getCollectionFQCNs();
266
+		$FQCNs = (array) apply_filters(
267
+			'FHEE__CollectionLoader__loadAllFromFQCNs__FQCNs',
268
+			$FQCNs,
269
+			$this->collection_details->collectionName(),
270
+			$this->collection_details
271
+		);
272
+		foreach ($FQCNs as $FQCN) {
273
+			$this->loadClassFromFQCN($FQCN);
274
+		}
275
+	}
276 276
 
277 277
 
278
-    /**
279
-     * @param  string $FQCN Fully Qualified Class Name
280
-     * @return string
281
-     * @throws InvalidArgumentException
282
-     * @throws InvalidInterfaceException
283
-     * @throws ReflectionException
284
-     * @throws EE_Error
285
-     * @throws InvalidEntityException
286
-     * @throws InvalidDataTypeException
287
-     * @throws InvalidClassException
288
-     */
289
-    protected function loadClassFromFQCN($FQCN)
290
-    {
291
-        if (! is_string($FQCN)) {
292
-            throw new InvalidDataTypeException('$FQCN', $FQCN, 'string');
293
-        }
294
-        if (! class_exists($FQCN)) {
295
-            throw new InvalidClassException($FQCN);
296
-        }
297
-        return $this->addEntityToCollection(
298
-            EE_Registry::instance()->create($FQCN),
299
-            $FQCN
300
-        );
301
-    }
278
+	/**
279
+	 * @param  string $FQCN Fully Qualified Class Name
280
+	 * @return string
281
+	 * @throws InvalidArgumentException
282
+	 * @throws InvalidInterfaceException
283
+	 * @throws ReflectionException
284
+	 * @throws EE_Error
285
+	 * @throws InvalidEntityException
286
+	 * @throws InvalidDataTypeException
287
+	 * @throws InvalidClassException
288
+	 */
289
+	protected function loadClassFromFQCN($FQCN)
290
+	{
291
+		if (! is_string($FQCN)) {
292
+			throw new InvalidDataTypeException('$FQCN', $FQCN, 'string');
293
+		}
294
+		if (! class_exists($FQCN)) {
295
+			throw new InvalidClassException($FQCN);
296
+		}
297
+		return $this->addEntityToCollection(
298
+			EE_Registry::instance()->create($FQCN),
299
+			$FQCN
300
+		);
301
+	}
302 302
 }
Please login to merge, or discard this patch.