Completed
Pull Request — master (#3)
by James
02:59
created
src/Contract/Axolotl/UsesWordPressPost.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -8,10 +8,10 @@
 block discarded – undo
8 8
  * @subpackage Contract\Axolotl
9 9
  */
10 10
 interface UsesWordPressPost {
11
-	/**
12
-	 * Returns the custom post type used by the Model.
13
-	 *
14
-	 * @return string
15
-	 */
16
-	public static function get_post_type();
11
+    /**
12
+     * Returns the custom post type used by the Model.
13
+     *
14
+     * @return string
15
+     */
16
+    public static function get_post_type();
17 17
 }
Please login to merge, or discard this patch.
src/Assets/Register.php 1 patch
Indentation   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -12,202 +12,202 @@
 block discarded – undo
12 12
  * @subpackage Register
13 13
  */
14 14
 class Register implements RegisterContract {
15
-	/**
16
-	 * Minification string for enqueued assets.
17
-	 *
18
-	 * @var string
19
-	 */
20
-	private $min = '';
21
-
22
-	/**
23
-	 * Url to the plugin directory.
24
-	 *
25
-	 * @var string
26
-	 */
27
-	protected $url;
28
-
29
-	/**
30
-	 * Script/plugin version.
31
-	 *
32
-	 * @var string
33
-	 */
34
-	protected $version;
35
-
36
-	/**
37
-	 * Array of script definition arrays.
38
-	 *
39
-	 * @var array
40
-	 */
41
-	private $scripts = array();
42
-
43
-	/**
44
-	 * Array of style definition arrays.
45
-	 *
46
-	 * @var array
47
-	 */
48
-	private $styles = array();
49
-
50
-	/**
51
-	 * Instantiates a new instance of the Register class.
52
-	 *
53
-	 * The URL param should be relative to the plugin directory. The URL
54
-	 * form should always end with a '/'. All asset location definitions
55
-	 * should not begin with a slash and should be relative to the plugin's
56
-	 * root directory. The URL provided by default from the Application
57
-	 * class is compatible.
58
-	 *
59
-	 * @param string $url
60
-	 * @param string $version
61
-	 */
62
-	public function __construct( $url, $version = null ) {
63
-		$this->url = $url;
64
-		$this->version = $version ? : null; // Empty string should remain null.
65
-	}
66
-
67
-	/**
68
-	 * {@inheritdoc}
69
-	 *
70
-	 * @param bool $debug
71
-	 */
72
-	public function set_debug( $debug ) {
73
-		if ( $debug ) {
74
-			$this->min = '.min';
75
-		} else {
76
-			$this->min = '';
77
-		}
78
-	}
79
-
80
-	/**
81
-	 * {@inheritdoc}
82
-	 *
83
-	 * @param array $script
84
-	 */
85
-	public function register_script( $script ) {
86
-		$this->scripts[] = $script;
87
-	}
88
-
89
-	/**
90
-	 * {@inheritdoc}
91
-	 *
92
-	 * @param array $style
93
-	 */
94
-	public function register_style( $style ) {
95
-		$this->styles[] = $style;
96
-	}
97
-
98
-	/**
99
-	 * {@inheritDoc}
100
-	 */
101
-	public function enqueue_web_scripts() {
102
-		foreach ( $this->scripts as $script ) {
103
-			if ( in_array( $script['type'], array( 'web', 'shared' ) ) ) {
104
-				$this->enqueue_script( $script );
105
-			}
106
-		}
107
-	}
108
-
109
-	/**
110
-	 * {@inheritDoc}
111
-	 */
112
-	public function enqueue_web_styles() {
113
-		foreach ( $this->styles as $style ) {
114
-			if ( in_array( $style['type'], array( 'web', 'shared' ) ) ) {
115
-				$this->enqueue_style( $style );
116
-			}
117
-		}
118
-	}
119
-
120
-	/**
121
-	 * {@inheritDoc}
122
-	 */
123
-	public function enqueue_admin_scripts() {
124
-		foreach ( $this->scripts as $script ) {
125
-			if ( in_array( $script['type'], array( 'admin', 'shared' ) ) ) {
126
-				$this->enqueue_script( $script );
127
-			}
128
-		}
129
-	}
130
-
131
-	/**
132
-	 * {@inheritDoc}
133
-	 */
134
-	public function enqueue_admin_styles() {
135
-		foreach ( $this->styles as $style ) {
136
-			if ( in_array( $style['type'], array( 'admin', 'shared' ) ) ) {
137
-				$this->enqueue_style( $style );
138
-			}
139
-		}
140
-	}
141
-
142
-	/**
143
-	 * {@inheritDoc}
144
-	 *
145
-	 * @return array[]
146
-	 */
147
-	public function action_hooks() {
148
-		return array(
149
-			array(
150
-				'hook'   => 'wp_enqueue_scripts',
151
-				'method' => 'enqueue_web_scripts',
152
-			),
153
-			array(
154
-				'hook'   => 'wp_enqueue_scripts',
155
-				'method' => 'enqueue_web_styles',
156
-			),
157
-			array(
158
-				'hook'   => 'admin_enqueue_scripts',
159
-				'method' => 'enqueue_admin_scripts',
160
-			),
161
-			array(
162
-				'hook'   => 'admin_enqueue_scripts',
163
-				'method' => 'enqueue_admin_styles',
164
-			),
165
-		);
166
-	}
167
-
168
-	/**
169
-	 * Enqueues an individual script if the style's condition is met.
170
-	 *
171
-	 * @param array $script
172
-	 */
173
-	protected function enqueue_script( $script ) {
174
-		if ( $script['condition']() ) {
175
-			wp_enqueue_script(
176
-				$script['handle'],
177
-				$this->url . $script['src'] . '.js',
178
-				isset( $script['deps'] ) ? $script['deps'] : array(),
179
-				$this->version,
180
-				isset( $script['footer'] ) ? $script['footer'] : false
181
-			);
182
-
183
-			if ( isset( $script['localize'] ) ) {
184
-				if ( is_callable( $script['localize'] ) ) { // @todo make all properties callables
185
-					$script['localize'] = call_user_func( $script['localize'] );
186
-				}
187
-
188
-				wp_localize_script(
189
-					$script['handle'],
190
-					$script['localize']['name'],
191
-					$script['localize']['data']
192
-				);
193
-			}
194
-		}
195
-	}
196
-
197
-	/**
198
-	 * Enqueues an individual stylesheet if the style's condition is met.
199
-	 *
200
-	 * @param array $style
201
-	 */
202
-	protected function enqueue_style( $style ) {
203
-		if ( $style['condition']() ) {
204
-			wp_enqueue_style(
205
-				$style['handle'],
206
-				$this->url . $style['src'] . '.css',
207
-				isset( $style['deps'] ) ? $style['deps'] : array(),
208
-				$this->version,
209
-				isset( $style['media'] ) ? $style['media'] : 'all'
210
-			);
211
-		}
212
-	}
15
+    /**
16
+     * Minification string for enqueued assets.
17
+     *
18
+     * @var string
19
+     */
20
+    private $min = '';
21
+
22
+    /**
23
+     * Url to the plugin directory.
24
+     *
25
+     * @var string
26
+     */
27
+    protected $url;
28
+
29
+    /**
30
+     * Script/plugin version.
31
+     *
32
+     * @var string
33
+     */
34
+    protected $version;
35
+
36
+    /**
37
+     * Array of script definition arrays.
38
+     *
39
+     * @var array
40
+     */
41
+    private $scripts = array();
42
+
43
+    /**
44
+     * Array of style definition arrays.
45
+     *
46
+     * @var array
47
+     */
48
+    private $styles = array();
49
+
50
+    /**
51
+     * Instantiates a new instance of the Register class.
52
+     *
53
+     * The URL param should be relative to the plugin directory. The URL
54
+     * form should always end with a '/'. All asset location definitions
55
+     * should not begin with a slash and should be relative to the plugin's
56
+     * root directory. The URL provided by default from the Application
57
+     * class is compatible.
58
+     *
59
+     * @param string $url
60
+     * @param string $version
61
+     */
62
+    public function __construct( $url, $version = null ) {
63
+        $this->url = $url;
64
+        $this->version = $version ? : null; // Empty string should remain null.
65
+    }
66
+
67
+    /**
68
+     * {@inheritdoc}
69
+     *
70
+     * @param bool $debug
71
+     */
72
+    public function set_debug( $debug ) {
73
+        if ( $debug ) {
74
+            $this->min = '.min';
75
+        } else {
76
+            $this->min = '';
77
+        }
78
+    }
79
+
80
+    /**
81
+     * {@inheritdoc}
82
+     *
83
+     * @param array $script
84
+     */
85
+    public function register_script( $script ) {
86
+        $this->scripts[] = $script;
87
+    }
88
+
89
+    /**
90
+     * {@inheritdoc}
91
+     *
92
+     * @param array $style
93
+     */
94
+    public function register_style( $style ) {
95
+        $this->styles[] = $style;
96
+    }
97
+
98
+    /**
99
+     * {@inheritDoc}
100
+     */
101
+    public function enqueue_web_scripts() {
102
+        foreach ( $this->scripts as $script ) {
103
+            if ( in_array( $script['type'], array( 'web', 'shared' ) ) ) {
104
+                $this->enqueue_script( $script );
105
+            }
106
+        }
107
+    }
108
+
109
+    /**
110
+     * {@inheritDoc}
111
+     */
112
+    public function enqueue_web_styles() {
113
+        foreach ( $this->styles as $style ) {
114
+            if ( in_array( $style['type'], array( 'web', 'shared' ) ) ) {
115
+                $this->enqueue_style( $style );
116
+            }
117
+        }
118
+    }
119
+
120
+    /**
121
+     * {@inheritDoc}
122
+     */
123
+    public function enqueue_admin_scripts() {
124
+        foreach ( $this->scripts as $script ) {
125
+            if ( in_array( $script['type'], array( 'admin', 'shared' ) ) ) {
126
+                $this->enqueue_script( $script );
127
+            }
128
+        }
129
+    }
130
+
131
+    /**
132
+     * {@inheritDoc}
133
+     */
134
+    public function enqueue_admin_styles() {
135
+        foreach ( $this->styles as $style ) {
136
+            if ( in_array( $style['type'], array( 'admin', 'shared' ) ) ) {
137
+                $this->enqueue_style( $style );
138
+            }
139
+        }
140
+    }
141
+
142
+    /**
143
+     * {@inheritDoc}
144
+     *
145
+     * @return array[]
146
+     */
147
+    public function action_hooks() {
148
+        return array(
149
+            array(
150
+                'hook'   => 'wp_enqueue_scripts',
151
+                'method' => 'enqueue_web_scripts',
152
+            ),
153
+            array(
154
+                'hook'   => 'wp_enqueue_scripts',
155
+                'method' => 'enqueue_web_styles',
156
+            ),
157
+            array(
158
+                'hook'   => 'admin_enqueue_scripts',
159
+                'method' => 'enqueue_admin_scripts',
160
+            ),
161
+            array(
162
+                'hook'   => 'admin_enqueue_scripts',
163
+                'method' => 'enqueue_admin_styles',
164
+            ),
165
+        );
166
+    }
167
+
168
+    /**
169
+     * Enqueues an individual script if the style's condition is met.
170
+     *
171
+     * @param array $script
172
+     */
173
+    protected function enqueue_script( $script ) {
174
+        if ( $script['condition']() ) {
175
+            wp_enqueue_script(
176
+                $script['handle'],
177
+                $this->url . $script['src'] . '.js',
178
+                isset( $script['deps'] ) ? $script['deps'] : array(),
179
+                $this->version,
180
+                isset( $script['footer'] ) ? $script['footer'] : false
181
+            );
182
+
183
+            if ( isset( $script['localize'] ) ) {
184
+                if ( is_callable( $script['localize'] ) ) { // @todo make all properties callables
185
+                    $script['localize'] = call_user_func( $script['localize'] );
186
+                }
187
+
188
+                wp_localize_script(
189
+                    $script['handle'],
190
+                    $script['localize']['name'],
191
+                    $script['localize']['data']
192
+                );
193
+            }
194
+        }
195
+    }
196
+
197
+    /**
198
+     * Enqueues an individual stylesheet if the style's condition is met.
199
+     *
200
+     * @param array $style
201
+     */
202
+    protected function enqueue_style( $style ) {
203
+        if ( $style['condition']() ) {
204
+            wp_enqueue_style(
205
+                $style['handle'],
206
+                $this->url . $style['src'] . '.css',
207
+                isset( $style['deps'] ) ? $style['deps'] : array(),
208
+                $this->version,
209
+                isset( $style['media'] ) ? $style['media'] : 'all'
210
+            );
211
+        }
212
+    }
213 213
 }
Please login to merge, or discard this patch.
src/Assets/ServiceProvider.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -11,40 +11,40 @@
 block discarded – undo
11 11
  * @subpackage Assets
12 12
  */
13 13
 class ServiceProvider implements ServiceProviderContract {
14
-	/**
15
-	 * Container to register with.
16
-	 *
17
-	 * @var Container
18
-	 */
19
-	protected $container;
14
+    /**
15
+     * Container to register with.
16
+     *
17
+     * @var Container
18
+     */
19
+    protected $container;
20 20
 
21
-	/**
22
-	 * {@inheritDoc}
23
-	 *
24
-	 * @param Container $container
25
-	 */
26
-	public function register( Container $container ) {
27
-		$this->container = $container;
21
+    /**
22
+     * {@inheritDoc}
23
+     *
24
+     * @param Container $container
25
+     */
26
+    public function register( Container $container ) {
27
+        $this->container = $container;
28 28
 
29
-		$container->define(
30
-			array( 'assets' => 'Intraxia\Jaxion\Contract\Assets\Register' ),
31
-			$register = new Register( $container->fetch( 'url' ), $container->fetch( 'version' ) )
32
-		);
29
+        $container->define(
30
+            array( 'assets' => 'Intraxia\Jaxion\Contract\Assets\Register' ),
31
+            $register = new Register( $container->fetch( 'url' ), $container->fetch( 'version' ) )
32
+        );
33 33
 
34
-		$this->add_assets( $register );
35
-	}
34
+        $this->add_assets( $register );
35
+    }
36 36
 
37
-	/**
38
-	 * Registers the assets on the generated Register.
39
-	 *
40
-	 * This is a no-op by default by can be overwritten by the implementing developer
41
-	 * to provide a single, clean location to register their assets.
42
-	 *
43
-	 * @param Register $register
44
-	 *
45
-	 * @codeCoverageIgnore
46
-	 */
47
-	protected function add_assets( Register $register ) {
48
-		// no-op
49
-	}
37
+    /**
38
+     * Registers the assets on the generated Register.
39
+     *
40
+     * This is a no-op by default by can be overwritten by the implementing developer
41
+     * to provide a single, clean location to register their assets.
42
+     *
43
+     * @param Register $register
44
+     *
45
+     * @codeCoverageIgnore
46
+     */
47
+    protected function add_assets( Register $register ) {
48
+        // no-op
49
+    }
50 50
 }
Please login to merge, or discard this patch.
src/Core/Loader.php 1 patch
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -15,109 +15,109 @@
 block discarded – undo
15 15
  * @subpackage Core
16 16
  */
17 17
 class Loader implements LoaderContract {
18
-	/**
19
-	 * Array of action hooks to attach.
20
-	 *
21
-	 * @var array[]
22
-	 */
23
-	protected $actions = array();
18
+    /**
19
+     * Array of action hooks to attach.
20
+     *
21
+     * @var array[]
22
+     */
23
+    protected $actions = array();
24 24
 
25
-	/**
26
-	 * Array of filter hooks to attach.
27
-	 *
28
-	 * @var array[]
29
-	 */
30
-	protected $filters = array();
25
+    /**
26
+     * Array of filter hooks to attach.
27
+     *
28
+     * @var array[]
29
+     */
30
+    protected $filters = array();
31 31
 
32
-	/**
33
-	 * {@inheritDoc}
34
-	 */
35
-	public function run() {
36
-		foreach ( $this->actions as $action ) {
37
-			add_action(
38
-				$action['hook'],
39
-				array( $action['service'], $action['method'] ),
40
-				$action['priority'],
41
-				$action['args']
42
-			);
43
-		}
32
+    /**
33
+     * {@inheritDoc}
34
+     */
35
+    public function run() {
36
+        foreach ( $this->actions as $action ) {
37
+            add_action(
38
+                $action['hook'],
39
+                array( $action['service'], $action['method'] ),
40
+                $action['priority'],
41
+                $action['args']
42
+            );
43
+        }
44 44
 
45
-		foreach ( $this->filters as $filter ) {
46
-			add_filter(
47
-				$filter['hook'],
48
-				array( $filter['service'], $filter['method'] ),
49
-				$filter['priority'],
50
-				$filter['args']
51
-			);
52
-		}
53
-	}
45
+        foreach ( $this->filters as $filter ) {
46
+            add_filter(
47
+                $filter['hook'],
48
+                array( $filter['service'], $filter['method'] ),
49
+                $filter['priority'],
50
+                $filter['args']
51
+            );
52
+        }
53
+    }
54 54
 
55
-	/**
56
-	 * {@inheritDoc}
57
-	 *
58
-	 * @param HasActions $service
59
-	 */
60
-	public function register_actions( HasActions $service ) {
61
-		foreach ( $service->action_hooks() as $action ) {
62
-			$this->actions = $this->add(
63
-				$this->actions,
64
-				$action['hook'],
65
-				$service,
66
-				$action['method'],
67
-				isset( $action['priority'] ) ? $action['priority'] : 10,
68
-				isset( $action['args'] ) ? $action['args'] : 1
69
-			);
70
-		}
71
-	}
55
+    /**
56
+     * {@inheritDoc}
57
+     *
58
+     * @param HasActions $service
59
+     */
60
+    public function register_actions( HasActions $service ) {
61
+        foreach ( $service->action_hooks() as $action ) {
62
+            $this->actions = $this->add(
63
+                $this->actions,
64
+                $action['hook'],
65
+                $service,
66
+                $action['method'],
67
+                isset( $action['priority'] ) ? $action['priority'] : 10,
68
+                isset( $action['args'] ) ? $action['args'] : 1
69
+            );
70
+        }
71
+    }
72 72
 
73
-	/**
74
-	 * {@inheritDoc}
75
-	 *
76
-	 * @param HasFilters $service
77
-	 */
78
-	public function register_filters( HasFilters $service ) {
79
-		foreach ( $service->filter_hooks() as $filter ) {
80
-			$this->filters = $this->add(
81
-				$this->filters,
82
-				$filter['hook'],
83
-				$service,
84
-				$filter['method'],
85
-				isset( $filter['priority'] ) ? $filter['priority'] : 10,
86
-				isset( $filter['args'] ) ? $filter['args'] : 1
87
-			);
88
-		}
89
-	}
73
+    /**
74
+     * {@inheritDoc}
75
+     *
76
+     * @param HasFilters $service
77
+     */
78
+    public function register_filters( HasFilters $service ) {
79
+        foreach ( $service->filter_hooks() as $filter ) {
80
+            $this->filters = $this->add(
81
+                $this->filters,
82
+                $filter['hook'],
83
+                $service,
84
+                $filter['method'],
85
+                isset( $filter['priority'] ) ? $filter['priority'] : 10,
86
+                isset( $filter['args'] ) ? $filter['args'] : 1
87
+            );
88
+        }
89
+    }
90 90
 
91
-	/**
92
-	 * {@inheritDoc}
93
-	 *
94
-	 * @param HasShortcode $service
95
-	 */
96
-	public function register_shortcode( HasShortcode $service ) {
97
-		add_shortcode( $service->shortcode_name(), array( $service, 'do_shortcode' ) );
98
-	}
91
+    /**
92
+     * {@inheritDoc}
93
+     *
94
+     * @param HasShortcode $service
95
+     */
96
+    public function register_shortcode( HasShortcode $service ) {
97
+        add_shortcode( $service->shortcode_name(), array( $service, 'do_shortcode' ) );
98
+    }
99 99
 
100
-	/**
101
-	 * Utility to register the actions and hooks into a single collection.
102
-	 *
103
-	 * @param array  $hooks
104
-	 * @param string $hook
105
-	 * @param object $service
106
-	 * @param string $method
107
-	 * @param int    $priority
108
-	 * @param int    $accepted_args
109
-	 *
110
-	 * @return array
111
-	 */
112
-	protected function add( $hooks, $hook, $service, $method, $priority, $accepted_args ) {
113
-		$hooks[] = array(
114
-			'hook'     => $hook,
115
-			'service'  => $service,
116
-			'method'   => $method,
117
-			'priority' => $priority,
118
-			'args'     => $accepted_args,
119
-		);
100
+    /**
101
+     * Utility to register the actions and hooks into a single collection.
102
+     *
103
+     * @param array  $hooks
104
+     * @param string $hook
105
+     * @param object $service
106
+     * @param string $method
107
+     * @param int    $priority
108
+     * @param int    $accepted_args
109
+     *
110
+     * @return array
111
+     */
112
+    protected function add( $hooks, $hook, $service, $method, $priority, $accepted_args ) {
113
+        $hooks[] = array(
114
+            'hook'     => $hook,
115
+            'service'  => $service,
116
+            'method'   => $method,
117
+            'priority' => $priority,
118
+            'args'     => $accepted_args,
119
+        );
120 120
 
121
-		return $hooks;
122
-	}
121
+        return $hooks;
122
+    }
123 123
 }
Please login to merge, or discard this patch.
src/Core/Container.php 1 patch
Indentation   +318 added lines, -318 removed lines patch added patch discarded remove patch
@@ -13,322 +13,322 @@
 block discarded – undo
13 13
  * @subpackage Core
14 14
  */
15 15
 class Container implements ContainerContract {
16
-	/**
17
-	 * ServiceProvider names to register with the container.
18
-	 *
19
-	 * Can be overwritten to include predefined providers.
20
-	 *
21
-	 * @var string[]
22
-	 */
23
-	protected $providers = array();
24
-
25
-	/**
26
-	 * Registered definitions.
27
-	 *
28
-	 * @var mixed[]
29
-	 */
30
-	private $definitions = array();
31
-
32
-	/**
33
-	 * Aliases to share between fetches.
34
-	 *
35
-	 * @var <string, true>[]
36
-	 */
37
-	private $shared = array();
38
-
39
-	/**
40
-	 * Aliases of all the registered services.
41
-	 *
42
-	 * @var <string, true>[]
43
-	 */
44
-	private $aliases = array();
45
-
46
-	/**
47
-	 * Array of classes registered on the container.
48
-	 *
49
-	 * @var <string, true>[]
50
-	 */
51
-	private $classes = array();
52
-
53
-	/**
54
-	 * Current position in the loop.
55
-	 *
56
-	 * @var int
57
-	 */
58
-	private $position;
59
-
60
-	/**
61
-	 * 0-indexed array of aliases for looping.
62
-	 *
63
-	 * @var string[]
64
-	 */
65
-	private $keys = array();
66
-
67
-	/**
68
-	 * Create a new container with the given providers.
69
-	 *
70
-	 * Providers can be instances or the class of the provider as a string.
71
-	 *
72
-	 * @param ServiceProvider[]|string[] $providers
73
-	 */
74
-	public function __construct( array $providers = array() ) {
75
-		// array_unique ensures we only register each provider once.
76
-		$providers = array_unique( array_merge( $this->providers, $providers ) );
77
-
78
-		foreach ( $providers as $provider ) {
79
-			if ( is_string( $provider ) && class_exists( $provider ) ) {
80
-				$provider = new $provider;
81
-			}
82
-
83
-			if ( $provider instanceof ServiceProvider ) {
84
-				$this->register( $provider );
85
-			}
86
-		}
87
-	}
88
-
89
-
90
-	/**
91
-	 * {@inheritdoc}
92
-	 *
93
-	 * @param string|array $alias
94
-	 * @param mixed        $definition
95
-	 *
96
-	 * @throws DefinedAliasException
97
-	 *
98
-	 * @return $this
99
-	 */
100
-	public function define( $alias, $definition ) {
101
-		if ( is_array( $alias ) ) {
102
-			$class = current( $alias );
103
-			$alias = key( $alias );
104
-		}
105
-
106
-		if ( isset( $this->aliases[ $alias ] ) ) {
107
-			throw new DefinedAliasException( $alias );
108
-		}
109
-
110
-		$this->aliases[ $alias ]     = true;
111
-		$this->definitions[ $alias ] = $definition;
112
-
113
-		// Closures are treated as factories unless
114
-		// defined via Container::share.
115
-		if ( ! $definition instanceof \Closure ) {
116
-			$this->shared[ $alias ] = true;
117
-		}
118
-
119
-		if ( isset( $class ) ) {
120
-			$this->classes[ $class ] = $alias;
121
-		}
122
-
123
-		return $this;
124
-	}
125
-
126
-	/**
127
-	 * {@inheritdoc}
128
-	 *
129
-	 * @param string|array $alias
130
-	 * @param mixed        $definition
131
-	 *
132
-	 * @throws DefinedAliasException
133
-	 *
134
-	 * @return $this
135
-	 */
136
-	public function share( $alias, $definition ) {
137
-		$this->define( $alias, $definition );
138
-
139
-		if ( is_array( $alias ) ) {
140
-			$alias = key( $alias );
141
-		}
142
-
143
-		$this->shared[ $alias ] = true;
144
-
145
-		return $this;
146
-	}
147
-
148
-	/**
149
-	 * {@inheritdoc}
150
-	 *
151
-	 * @param string $alias
152
-	 *
153
-	 * @throws UndefinedAliasException
154
-	 *
155
-	 * @return mixed
156
-	 */
157
-	public function fetch( $alias ) {
158
-		if ( isset( $this->classes[ $alias ] ) ) {
159
-			// If the alias is a class name,
160
-			// then retrieve its linked alias.
161
-			// This is only registered when
162
-			// registering using an array.
163
-			$alias = $this->classes[ $alias ];
164
-		}
165
-
166
-		if ( ! isset( $this->aliases[ $alias ] ) ) {
167
-			throw new UndefinedAliasException( $alias );
168
-		}
169
-
170
-		$value = $this->definitions[ $alias ];
171
-
172
-		// If the shared value is a closure,
173
-		// execute it and assign the result
174
-		// in place of the closure.
175
-		if ( $value instanceof \Closure ) {
176
-			$factory = $value;
177
-			$value   = $factory( $this );
178
-		}
179
-
180
-		// If the value is shared, save the shared value.
181
-		if ( isset( $this->shared[ $alias ] ) ) {
182
-			$this->definitions[ $alias ] = $value;
183
-		}
184
-
185
-		// Return the fetched value.
186
-		return $value;
187
-	}
188
-
189
-	/**
190
-	 * {@inheritdoc}
191
-	 *
192
-	 * @param  string $alias
193
-	 *
194
-	 * @return bool
195
-	 */
196
-	public function has( $alias ) {
197
-		return isset( $this->aliases[ $alias ] );
198
-	}
199
-
200
-	/**
201
-	 * {@inheritDoc}
202
-	 *
203
-	 * @param string $alias
204
-	 *
205
-	 * @return $this
206
-	 */
207
-	public function remove( $alias ) {
208
-		if ( isset( $this->aliases[ $alias ] ) ) {
209
-			/**
210
-			 * If there's no reference in the aliases array,
211
-			 * the service won't be found on fetching and
212
-			 * can be overwritten on setting.
213
-			 *
214
-			 * Pros: Quick setting/unsetting, faster
215
-			 * performance on those operations when doing
216
-			 * a lot of these.
217
-			 *
218
-			 * Cons: Objects and values set in the container
219
-			 * can't get garbage collected.
220
-			 *
221
-			 * If this is a problem, this may need to be revisited.
222
-			 */
223
-			unset( $this->aliases[ $alias ] );
224
-		}
225
-
226
-		return $this;
227
-	}
228
-
229
-	/**
230
-	 * {@inheritDoc}
231
-	 *
232
-	 * @param ServiceProvider $provider
233
-	 *
234
-	 * @return $this
235
-	 */
236
-	public function register( ServiceProvider $provider ) {
237
-		// @todo make sure provider is only registered once
238
-		$provider->register( $this );
239
-
240
-		return $this;
241
-	}
242
-
243
-	/**
244
-	 * Set a value into the container.
245
-	 *
246
-	 * @param  string $id
247
-	 * @param  mixed  $value
248
-	 *
249
-	 * @see    define
250
-	 */
251
-	public function offsetSet( $id, $value ) {
252
-		$this->define( $id, $value );
253
-	}
254
-
255
-	/**
256
-	 * Get an value from the container.
257
-	 *
258
-	 * @param  string $id
259
-	 *
260
-	 * @return object
261
-	 * @throws UndefinedAliasException
262
-	 *
263
-	 * @see    fetch
264
-	 */
265
-	public function offsetGet( $id ) {
266
-		return $this->fetch( $id );
267
-	}
268
-
269
-	/**
270
-	 * Checks if a key is set on the container.
271
-	 *
272
-	 * @param  string $id
273
-	 *
274
-	 * @return bool
275
-	 *
276
-	 * @see    has
277
-	 */
278
-	public function offsetExists( $id ) {
279
-		return $this->has( $id );
280
-	}
281
-
282
-	/**
283
-	 * Remove a key from the container.
284
-	 *
285
-	 * @param string $id
286
-	 *
287
-	 * @see   remove
288
-	 */
289
-	public function offsetUnset( $id ) {
290
-		$this->remove( $id );
291
-	}
292
-
293
-	/**
294
-	 * Sets the object properties to prepare for the loop.
295
-	 */
296
-	public function rewind() {
297
-		$this->position = 0;
298
-		$this->keys     = array_keys( $this->aliases );
299
-	}
300
-
301
-	/**
302
-	 * Retrieves the service object for the current step in the loop.
303
-	 *
304
-	 * @return object
305
-	 */
306
-	public function current() {
307
-		return $this->fetch( $this->keys[ $this->position ] );
308
-	}
309
-
310
-	/**
311
-	 * Retrieves the key for the current step in the loop.
312
-	 *
313
-	 * @return string
314
-	 */
315
-	public function key() {
316
-		return $this->keys[ $this->position ];
317
-	}
318
-
319
-	/**
320
-	 * Increments to the next step in the loop.
321
-	 */
322
-	public function next() {
323
-		$this->position ++;
324
-	}
325
-
326
-	/**
327
-	 * Checks if the next step in the loop in valid.
328
-	 *
329
-	 * @return bool
330
-	 */
331
-	public function valid() {
332
-		return isset( $this->keys[ $this->position ] );
333
-	}
16
+    /**
17
+     * ServiceProvider names to register with the container.
18
+     *
19
+     * Can be overwritten to include predefined providers.
20
+     *
21
+     * @var string[]
22
+     */
23
+    protected $providers = array();
24
+
25
+    /**
26
+     * Registered definitions.
27
+     *
28
+     * @var mixed[]
29
+     */
30
+    private $definitions = array();
31
+
32
+    /**
33
+     * Aliases to share between fetches.
34
+     *
35
+     * @var <string, true>[]
36
+     */
37
+    private $shared = array();
38
+
39
+    /**
40
+     * Aliases of all the registered services.
41
+     *
42
+     * @var <string, true>[]
43
+     */
44
+    private $aliases = array();
45
+
46
+    /**
47
+     * Array of classes registered on the container.
48
+     *
49
+     * @var <string, true>[]
50
+     */
51
+    private $classes = array();
52
+
53
+    /**
54
+     * Current position in the loop.
55
+     *
56
+     * @var int
57
+     */
58
+    private $position;
59
+
60
+    /**
61
+     * 0-indexed array of aliases for looping.
62
+     *
63
+     * @var string[]
64
+     */
65
+    private $keys = array();
66
+
67
+    /**
68
+     * Create a new container with the given providers.
69
+     *
70
+     * Providers can be instances or the class of the provider as a string.
71
+     *
72
+     * @param ServiceProvider[]|string[] $providers
73
+     */
74
+    public function __construct( array $providers = array() ) {
75
+        // array_unique ensures we only register each provider once.
76
+        $providers = array_unique( array_merge( $this->providers, $providers ) );
77
+
78
+        foreach ( $providers as $provider ) {
79
+            if ( is_string( $provider ) && class_exists( $provider ) ) {
80
+                $provider = new $provider;
81
+            }
82
+
83
+            if ( $provider instanceof ServiceProvider ) {
84
+                $this->register( $provider );
85
+            }
86
+        }
87
+    }
88
+
89
+
90
+    /**
91
+     * {@inheritdoc}
92
+     *
93
+     * @param string|array $alias
94
+     * @param mixed        $definition
95
+     *
96
+     * @throws DefinedAliasException
97
+     *
98
+     * @return $this
99
+     */
100
+    public function define( $alias, $definition ) {
101
+        if ( is_array( $alias ) ) {
102
+            $class = current( $alias );
103
+            $alias = key( $alias );
104
+        }
105
+
106
+        if ( isset( $this->aliases[ $alias ] ) ) {
107
+            throw new DefinedAliasException( $alias );
108
+        }
109
+
110
+        $this->aliases[ $alias ]     = true;
111
+        $this->definitions[ $alias ] = $definition;
112
+
113
+        // Closures are treated as factories unless
114
+        // defined via Container::share.
115
+        if ( ! $definition instanceof \Closure ) {
116
+            $this->shared[ $alias ] = true;
117
+        }
118
+
119
+        if ( isset( $class ) ) {
120
+            $this->classes[ $class ] = $alias;
121
+        }
122
+
123
+        return $this;
124
+    }
125
+
126
+    /**
127
+     * {@inheritdoc}
128
+     *
129
+     * @param string|array $alias
130
+     * @param mixed        $definition
131
+     *
132
+     * @throws DefinedAliasException
133
+     *
134
+     * @return $this
135
+     */
136
+    public function share( $alias, $definition ) {
137
+        $this->define( $alias, $definition );
138
+
139
+        if ( is_array( $alias ) ) {
140
+            $alias = key( $alias );
141
+        }
142
+
143
+        $this->shared[ $alias ] = true;
144
+
145
+        return $this;
146
+    }
147
+
148
+    /**
149
+     * {@inheritdoc}
150
+     *
151
+     * @param string $alias
152
+     *
153
+     * @throws UndefinedAliasException
154
+     *
155
+     * @return mixed
156
+     */
157
+    public function fetch( $alias ) {
158
+        if ( isset( $this->classes[ $alias ] ) ) {
159
+            // If the alias is a class name,
160
+            // then retrieve its linked alias.
161
+            // This is only registered when
162
+            // registering using an array.
163
+            $alias = $this->classes[ $alias ];
164
+        }
165
+
166
+        if ( ! isset( $this->aliases[ $alias ] ) ) {
167
+            throw new UndefinedAliasException( $alias );
168
+        }
169
+
170
+        $value = $this->definitions[ $alias ];
171
+
172
+        // If the shared value is a closure,
173
+        // execute it and assign the result
174
+        // in place of the closure.
175
+        if ( $value instanceof \Closure ) {
176
+            $factory = $value;
177
+            $value   = $factory( $this );
178
+        }
179
+
180
+        // If the value is shared, save the shared value.
181
+        if ( isset( $this->shared[ $alias ] ) ) {
182
+            $this->definitions[ $alias ] = $value;
183
+        }
184
+
185
+        // Return the fetched value.
186
+        return $value;
187
+    }
188
+
189
+    /**
190
+     * {@inheritdoc}
191
+     *
192
+     * @param  string $alias
193
+     *
194
+     * @return bool
195
+     */
196
+    public function has( $alias ) {
197
+        return isset( $this->aliases[ $alias ] );
198
+    }
199
+
200
+    /**
201
+     * {@inheritDoc}
202
+     *
203
+     * @param string $alias
204
+     *
205
+     * @return $this
206
+     */
207
+    public function remove( $alias ) {
208
+        if ( isset( $this->aliases[ $alias ] ) ) {
209
+            /**
210
+             * If there's no reference in the aliases array,
211
+             * the service won't be found on fetching and
212
+             * can be overwritten on setting.
213
+             *
214
+             * Pros: Quick setting/unsetting, faster
215
+             * performance on those operations when doing
216
+             * a lot of these.
217
+             *
218
+             * Cons: Objects and values set in the container
219
+             * can't get garbage collected.
220
+             *
221
+             * If this is a problem, this may need to be revisited.
222
+             */
223
+            unset( $this->aliases[ $alias ] );
224
+        }
225
+
226
+        return $this;
227
+    }
228
+
229
+    /**
230
+     * {@inheritDoc}
231
+     *
232
+     * @param ServiceProvider $provider
233
+     *
234
+     * @return $this
235
+     */
236
+    public function register( ServiceProvider $provider ) {
237
+        // @todo make sure provider is only registered once
238
+        $provider->register( $this );
239
+
240
+        return $this;
241
+    }
242
+
243
+    /**
244
+     * Set a value into the container.
245
+     *
246
+     * @param  string $id
247
+     * @param  mixed  $value
248
+     *
249
+     * @see    define
250
+     */
251
+    public function offsetSet( $id, $value ) {
252
+        $this->define( $id, $value );
253
+    }
254
+
255
+    /**
256
+     * Get an value from the container.
257
+     *
258
+     * @param  string $id
259
+     *
260
+     * @return object
261
+     * @throws UndefinedAliasException
262
+     *
263
+     * @see    fetch
264
+     */
265
+    public function offsetGet( $id ) {
266
+        return $this->fetch( $id );
267
+    }
268
+
269
+    /**
270
+     * Checks if a key is set on the container.
271
+     *
272
+     * @param  string $id
273
+     *
274
+     * @return bool
275
+     *
276
+     * @see    has
277
+     */
278
+    public function offsetExists( $id ) {
279
+        return $this->has( $id );
280
+    }
281
+
282
+    /**
283
+     * Remove a key from the container.
284
+     *
285
+     * @param string $id
286
+     *
287
+     * @see   remove
288
+     */
289
+    public function offsetUnset( $id ) {
290
+        $this->remove( $id );
291
+    }
292
+
293
+    /**
294
+     * Sets the object properties to prepare for the loop.
295
+     */
296
+    public function rewind() {
297
+        $this->position = 0;
298
+        $this->keys     = array_keys( $this->aliases );
299
+    }
300
+
301
+    /**
302
+     * Retrieves the service object for the current step in the loop.
303
+     *
304
+     * @return object
305
+     */
306
+    public function current() {
307
+        return $this->fetch( $this->keys[ $this->position ] );
308
+    }
309
+
310
+    /**
311
+     * Retrieves the key for the current step in the loop.
312
+     *
313
+     * @return string
314
+     */
315
+    public function key() {
316
+        return $this->keys[ $this->position ];
317
+    }
318
+
319
+    /**
320
+     * Increments to the next step in the loop.
321
+     */
322
+    public function next() {
323
+        $this->position ++;
324
+    }
325
+
326
+    /**
327
+     * Checks if the next step in the loop in valid.
328
+     *
329
+     * @return bool
330
+     */
331
+    public function valid() {
332
+        return isset( $this->keys[ $this->position ] );
333
+    }
334 334
 }
Please login to merge, or discard this patch.
src/Core/Application.php 1 patch
Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -13,146 +13,146 @@
 block discarded – undo
13 13
  * @package Intraxia\Jaxion
14 14
  */
15 15
 class Application extends Container implements ApplicationContract {
16
-	/**
17
-	 * Define plugin version on Application.
18
-	 */
19
-	const VERSION = '';
20
-
21
-	/**
22
-	 * Singleton instance of the Application object
23
-	 *
24
-	 * @var Application
25
-	 */
26
-	protected static $instance = null;
27
-
28
-	/**
29
-	 * Instantiates a new Application container.
30
-	 *
31
-	 * The Application constructor enforces the presence of of a single instance
32
-	 * of the Application. If an instance already exists, an Exception will be thrown.
33
-	 *
34
-	 * @param string $file
35
-	 * @param array  $providers
36
-	 *
37
-	 * @throws ApplicationAlreadyBootedException
38
-	 */
39
-	public function __construct( $file, array $providers = array() ) {
40
-		if ( null !== static::$instance ) {
41
-			throw new ApplicationAlreadyBootedException;
42
-		}
43
-
44
-		static::$instance = $this;
45
-
46
-		$this->register_constants( $file );
47
-		$this->register_core_services();
48
-		$this->load_i18n();
49
-
50
-		register_activation_hook( $file, array( $this, 'activate' ) );
51
-		register_deactivation_hook( $file, array( $this, 'deactivate' ) );
52
-
53
-		parent::__construct( $providers );
54
-	}
55
-
56
-	/**
57
-	 * {@inheritDoc}
58
-	 *
59
-	 * @throws UnexpectedValueException
60
-	 */
61
-	public function boot() {
62
-		$loader = $this->fetch( 'loader' );
63
-
64
-		if ( ! $loader instanceof LoaderContract ) {
65
-			throw new UnexpectedValueException;
66
-		}
67
-
68
-		foreach ( $this as $alias => $value ) {
69
-			if ( $value instanceof HasActions ) {
70
-				$loader->register_actions( $value );
71
-			}
72
-
73
-			if ( $value instanceof HasFilters ) {
74
-				$loader->register_filters( $value );
75
-			}
76
-
77
-			if ( $value instanceof HasShortcode ) {
78
-				$loader->register_shortcode( $value );
79
-			}
80
-		}
81
-
82
-		add_action( 'plugins_loaded', array( $loader, 'run' ) );
83
-	}
84
-
85
-	/**
86
-	 * {@inheritdoc}
87
-	 *
88
-	 * @codeCoverageIgnore
89
-	 */
90
-	public function activate() {
91
-		// no-op
92
-	}
93
-
94
-	/**
95
-	 * {@inheritdoc}
96
-	 *
97
-	 * @codeCoverageIgnore
98
-	 */
99
-	public function deactivate() {
100
-		// no-op
101
-	}
102
-
103
-	/**
104
-	 * {@inheritDoc}
105
-	 *
106
-	 * @return Application
107
-	 * @throws ApplicationNotBootedException
108
-	 */
109
-	public static function instance() {
110
-		if ( null === static::$instance ) {
111
-			throw new ApplicationNotBootedException;
112
-		}
113
-
114
-		return static::$instance;
115
-	}
116
-
117
-	/**
118
-	 * {@inheritDoc}
119
-	 */
120
-	public static function shutdown() {
121
-		if ( null !== static::$instance ) {
122
-			static::$instance = null;
123
-		}
124
-	}
125
-
126
-	/**
127
-	 * Sets the plugin's url, path, and basename.
128
-	 *
129
-	 * @param string $file
130
-	 */
131
-	private function register_constants( $file ) {
132
-		$this->share( 'url', plugin_dir_url( $file ) );
133
-		$this->share( 'path', plugin_dir_path( $file ) );
134
-		$this->share( 'basename', $basename = plugin_basename( $file ) );
135
-		$this->share( 'slug', dirname( $basename ) );
136
-		$this->share( 'version', static::VERSION );
137
-	}
138
-
139
-	/**
140
-	 * Registers the built-in services with the Application container.
141
-	 */
142
-	private function register_core_services() {
143
-		$this->share( array( 'loader' => 'Intraxia\Jaxion\Contract\Core\Loader' ), function ( $app ) {
144
-			return new Loader( $app );
145
-		} );
146
-	}
147
-
148
-	/**
149
-	 * Load's the plugin's translation files.
150
-	 */
151
-	private function load_i18n() {
152
-		load_plugin_textdomain(
153
-			$this->fetch( 'basename' ),
154
-			false,
155
-			basename( $this->fetch( 'path' ) ) . '/languages/'
156
-		);
157
-	}
16
+    /**
17
+     * Define plugin version on Application.
18
+     */
19
+    const VERSION = '';
20
+
21
+    /**
22
+     * Singleton instance of the Application object
23
+     *
24
+     * @var Application
25
+     */
26
+    protected static $instance = null;
27
+
28
+    /**
29
+     * Instantiates a new Application container.
30
+     *
31
+     * The Application constructor enforces the presence of of a single instance
32
+     * of the Application. If an instance already exists, an Exception will be thrown.
33
+     *
34
+     * @param string $file
35
+     * @param array  $providers
36
+     *
37
+     * @throws ApplicationAlreadyBootedException
38
+     */
39
+    public function __construct( $file, array $providers = array() ) {
40
+        if ( null !== static::$instance ) {
41
+            throw new ApplicationAlreadyBootedException;
42
+        }
43
+
44
+        static::$instance = $this;
45
+
46
+        $this->register_constants( $file );
47
+        $this->register_core_services();
48
+        $this->load_i18n();
49
+
50
+        register_activation_hook( $file, array( $this, 'activate' ) );
51
+        register_deactivation_hook( $file, array( $this, 'deactivate' ) );
52
+
53
+        parent::__construct( $providers );
54
+    }
55
+
56
+    /**
57
+     * {@inheritDoc}
58
+     *
59
+     * @throws UnexpectedValueException
60
+     */
61
+    public function boot() {
62
+        $loader = $this->fetch( 'loader' );
63
+
64
+        if ( ! $loader instanceof LoaderContract ) {
65
+            throw new UnexpectedValueException;
66
+        }
67
+
68
+        foreach ( $this as $alias => $value ) {
69
+            if ( $value instanceof HasActions ) {
70
+                $loader->register_actions( $value );
71
+            }
72
+
73
+            if ( $value instanceof HasFilters ) {
74
+                $loader->register_filters( $value );
75
+            }
76
+
77
+            if ( $value instanceof HasShortcode ) {
78
+                $loader->register_shortcode( $value );
79
+            }
80
+        }
81
+
82
+        add_action( 'plugins_loaded', array( $loader, 'run' ) );
83
+    }
84
+
85
+    /**
86
+     * {@inheritdoc}
87
+     *
88
+     * @codeCoverageIgnore
89
+     */
90
+    public function activate() {
91
+        // no-op
92
+    }
93
+
94
+    /**
95
+     * {@inheritdoc}
96
+     *
97
+     * @codeCoverageIgnore
98
+     */
99
+    public function deactivate() {
100
+        // no-op
101
+    }
102
+
103
+    /**
104
+     * {@inheritDoc}
105
+     *
106
+     * @return Application
107
+     * @throws ApplicationNotBootedException
108
+     */
109
+    public static function instance() {
110
+        if ( null === static::$instance ) {
111
+            throw new ApplicationNotBootedException;
112
+        }
113
+
114
+        return static::$instance;
115
+    }
116
+
117
+    /**
118
+     * {@inheritDoc}
119
+     */
120
+    public static function shutdown() {
121
+        if ( null !== static::$instance ) {
122
+            static::$instance = null;
123
+        }
124
+    }
125
+
126
+    /**
127
+     * Sets the plugin's url, path, and basename.
128
+     *
129
+     * @param string $file
130
+     */
131
+    private function register_constants( $file ) {
132
+        $this->share( 'url', plugin_dir_url( $file ) );
133
+        $this->share( 'path', plugin_dir_path( $file ) );
134
+        $this->share( 'basename', $basename = plugin_basename( $file ) );
135
+        $this->share( 'slug', dirname( $basename ) );
136
+        $this->share( 'version', static::VERSION );
137
+    }
138
+
139
+    /**
140
+     * Registers the built-in services with the Application container.
141
+     */
142
+    private function register_core_services() {
143
+        $this->share( array( 'loader' => 'Intraxia\Jaxion\Contract\Core\Loader' ), function ( $app ) {
144
+            return new Loader( $app );
145
+        } );
146
+    }
147
+
148
+    /**
149
+     * Load's the plugin's translation files.
150
+     */
151
+    private function load_i18n() {
152
+        load_plugin_textdomain(
153
+            $this->fetch( 'basename' ),
154
+            false,
155
+            basename( $this->fetch( 'path' ) ) . '/languages/'
156
+        );
157
+    }
158 158
 }
Please login to merge, or discard this patch.
src/Axolotl/Repository/AbstractRepository.php 1 patch
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -17,200 +17,200 @@
 block discarded – undo
17 17
  * @subpackage Axolotl\Repository
18 18
  */
19 19
 abstract class AbstractRepository {
20
-	/**
21
-	 * All models found by Repositories.
22
-	 *
23
-	 * @var array
24
-	 */
25
-	protected static $found = array();
26
-
27
-	/**
28
-	 * Reset the array of found model
29
-	 */
30
-	public static function free() {
31
-		self::$found = array();
32
-	}
33
-
34
-	/**
35
-	 * Retrieves the retrieved model by class and id.
36
-	 *
37
-	 * @param string $class
38
-	 * @param int    $id
39
-	 *
40
-	 * @return bool
41
-	 */
42
-	protected static function get_found( $class, $id ) {
43
-		if ( isset( self::$found[ $class ][ $id ] ) ) {
44
-			return self::$found[ $class ][ $id ];
45
-		}
46
-
47
-		return false;
48
-	}
49
-
50
-	/**
51
-	 * EntityManger service.
52
-	 *
53
-	 * @var EntityManager
54
-	 */
55
-	protected $database;
56
-
57
-	/**
58
-	 * Model class for this repository.
59
-	 *
60
-	 * @var string
61
-	 */
62
-	protected $class;
63
-
64
-	/**
65
-	 * EntityManager prefix.
66
-	 *
67
-	 * @var string
68
-	 */
69
-	protected $prefix;
70
-
71
-	/**
72
-	 * WP_Query instance.
73
-	 *
74
-	 * @var WP_Query
75
-	 */
76
-	protected $main;
77
-
78
-	/**
79
-	 * WordPress Database connection.
80
-	 *
81
-	 * @var wpdb
82
-	 */
83
-	protected $wpdb;
84
-
85
-	/**
86
-	 * AbstractRepository constructor.
87
-	 *
88
-	 * @param EntityManager $database
89
-	 * @param string        $class
90
-	 */
91
-	public function __construct( EntityManager $database, $class ) {
92
-		$this->database = $database;
93
-		$this->class    = $class;
94
-		$this->prefix   = $database->get_prefix();
95
-		$this->main     = $database->get_main_query();
96
-		$this->wpdb     = $database->get_wpdb();
97
-
98
-		if ( ! isset( self::$found[ $class ] ) ) {
99
-			self::$found[ $class ] = array();
100
-		}
101
-	}
102
-
103
-	/**
104
-	 * Get a single model of the repository class with the given ID.
105
-	 *
106
-	 * @param int $id ID of the model.
107
-	 *
108
-	 * @return Model|WP_Error
109
-	 */
110
-	abstract public function find( $id );
111
-
112
-	/**
113
-	 * Finds all the models of the repository class for the given params.
114
-	 *
115
-	 * @param array $params Params to constrain the find.
116
-	 *
117
-	 * @return Collection|WP_Error
118
-	 */
119
-	abstract public function find_by( array $params = array() );
120
-
121
-	/**
122
-	 * Create and saves a new model of the repository class
123
-	 * with the given data.
124
-	 *
125
-	 * @param array $data
126
-	 *
127
-	 * @return Model|WP_Error
128
-	 */
129
-	abstract public function create( array $data = array() );
130
-
131
-	/**
132
-	 * Updates a model with its latest data.
133
-	 *
134
-	 * @param Model $model
135
-	 *
136
-	 * @return Model|WP_Error
137
-	 */
138
-	abstract public function persist( Model $model );
139
-
140
-	/**
141
-	 * Delete the provided Model.
142
-	 *
143
-	 * @param Model $model
144
-	 * @param bool  $force
145
-	 *
146
-	 * @return Model|WP_Error
147
-	 */
148
-	abstract public function delete( Model $model, $force = false );
149
-
150
-	/**
151
-	 * Registers the found Model with the EntityManager.
152
-	 *
153
-	 * @param Model $model
154
-	 */
155
-	public function register_model( Model $model ) {
156
-		self::$found[ $this->class ][ $model->get_primary_id() ] = $model;
157
-	}
158
-
159
-	/**
160
-	 * Fills the provided Model with attributes from its custom table.
161
-	 *
162
-	 * @param Model|UsesCustomTable $model
163
-	 */
164
-	protected function fill_table_attrs_from_table( Model $model ) {
165
-		$sql[] = "SELECT * FROM {$this->make_table_name( $model )}";
166
-		$sql[] = "WHERE {$model->get_foreign_key()} = %d";
167
-
168
-		$sql = $this->wpdb->prepare(
169
-			implode( ' ', $sql ),
170
-			$model->get_primary_id()
171
-		);
172
-
173
-		$row = $this->wpdb->get_row( $sql, ARRAY_A );
174
-
175
-		$model->unguard();
176
-
177
-		foreach ( $row as $key => $value ) {
178
-			$model->set_attribute( $key, $value );
179
-		}
180
-
181
-		$model->reguard();
182
-	}
183
-
184
-	/**
185
-	 * Saves the Model's changed table attributes to its table.
186
-	 *
187
-	 * @param Model $model
188
-	 *
189
-	 * @throws LogicException
190
-	 */
191
-	protected function save_table_attributes_to_table( Model $model ) {
192
-		throw new LogicException;
193
-	}
194
-
195
-	/**
196
-	 * Deletes the Model's table attributes from its table.
197
-	 *
198
-	 * @param Model $model
199
-	 *
200
-	 * @throws LogicException
201
-	 */
202
-	protected function delete_table_attributes_from_table( Model $model ) {
203
-		throw new LogicException;
204
-	}
205
-
206
-	/**
207
-	 * Creates the table name string for the provided Model.
208
-	 *
209
-	 * @param UsesCustomTable $model
210
-	 *
211
-	 * @return string
212
-	 */
213
-	protected function make_table_name( UsesCustomTable $model ) {
214
-		return "{$this->wpdb->prefix}{$this->prefix}_{$model::get_table_name()}";
215
-	}
20
+    /**
21
+     * All models found by Repositories.
22
+     *
23
+     * @var array
24
+     */
25
+    protected static $found = array();
26
+
27
+    /**
28
+     * Reset the array of found model
29
+     */
30
+    public static function free() {
31
+        self::$found = array();
32
+    }
33
+
34
+    /**
35
+     * Retrieves the retrieved model by class and id.
36
+     *
37
+     * @param string $class
38
+     * @param int    $id
39
+     *
40
+     * @return bool
41
+     */
42
+    protected static function get_found( $class, $id ) {
43
+        if ( isset( self::$found[ $class ][ $id ] ) ) {
44
+            return self::$found[ $class ][ $id ];
45
+        }
46
+
47
+        return false;
48
+    }
49
+
50
+    /**
51
+     * EntityManger service.
52
+     *
53
+     * @var EntityManager
54
+     */
55
+    protected $database;
56
+
57
+    /**
58
+     * Model class for this repository.
59
+     *
60
+     * @var string
61
+     */
62
+    protected $class;
63
+
64
+    /**
65
+     * EntityManager prefix.
66
+     *
67
+     * @var string
68
+     */
69
+    protected $prefix;
70
+
71
+    /**
72
+     * WP_Query instance.
73
+     *
74
+     * @var WP_Query
75
+     */
76
+    protected $main;
77
+
78
+    /**
79
+     * WordPress Database connection.
80
+     *
81
+     * @var wpdb
82
+     */
83
+    protected $wpdb;
84
+
85
+    /**
86
+     * AbstractRepository constructor.
87
+     *
88
+     * @param EntityManager $database
89
+     * @param string        $class
90
+     */
91
+    public function __construct( EntityManager $database, $class ) {
92
+        $this->database = $database;
93
+        $this->class    = $class;
94
+        $this->prefix   = $database->get_prefix();
95
+        $this->main     = $database->get_main_query();
96
+        $this->wpdb     = $database->get_wpdb();
97
+
98
+        if ( ! isset( self::$found[ $class ] ) ) {
99
+            self::$found[ $class ] = array();
100
+        }
101
+    }
102
+
103
+    /**
104
+     * Get a single model of the repository class with the given ID.
105
+     *
106
+     * @param int $id ID of the model.
107
+     *
108
+     * @return Model|WP_Error
109
+     */
110
+    abstract public function find( $id );
111
+
112
+    /**
113
+     * Finds all the models of the repository class for the given params.
114
+     *
115
+     * @param array $params Params to constrain the find.
116
+     *
117
+     * @return Collection|WP_Error
118
+     */
119
+    abstract public function find_by( array $params = array() );
120
+
121
+    /**
122
+     * Create and saves a new model of the repository class
123
+     * with the given data.
124
+     *
125
+     * @param array $data
126
+     *
127
+     * @return Model|WP_Error
128
+     */
129
+    abstract public function create( array $data = array() );
130
+
131
+    /**
132
+     * Updates a model with its latest data.
133
+     *
134
+     * @param Model $model
135
+     *
136
+     * @return Model|WP_Error
137
+     */
138
+    abstract public function persist( Model $model );
139
+
140
+    /**
141
+     * Delete the provided Model.
142
+     *
143
+     * @param Model $model
144
+     * @param bool  $force
145
+     *
146
+     * @return Model|WP_Error
147
+     */
148
+    abstract public function delete( Model $model, $force = false );
149
+
150
+    /**
151
+     * Registers the found Model with the EntityManager.
152
+     *
153
+     * @param Model $model
154
+     */
155
+    public function register_model( Model $model ) {
156
+        self::$found[ $this->class ][ $model->get_primary_id() ] = $model;
157
+    }
158
+
159
+    /**
160
+     * Fills the provided Model with attributes from its custom table.
161
+     *
162
+     * @param Model|UsesCustomTable $model
163
+     */
164
+    protected function fill_table_attrs_from_table( Model $model ) {
165
+        $sql[] = "SELECT * FROM {$this->make_table_name( $model )}";
166
+        $sql[] = "WHERE {$model->get_foreign_key()} = %d";
167
+
168
+        $sql = $this->wpdb->prepare(
169
+            implode( ' ', $sql ),
170
+            $model->get_primary_id()
171
+        );
172
+
173
+        $row = $this->wpdb->get_row( $sql, ARRAY_A );
174
+
175
+        $model->unguard();
176
+
177
+        foreach ( $row as $key => $value ) {
178
+            $model->set_attribute( $key, $value );
179
+        }
180
+
181
+        $model->reguard();
182
+    }
183
+
184
+    /**
185
+     * Saves the Model's changed table attributes to its table.
186
+     *
187
+     * @param Model $model
188
+     *
189
+     * @throws LogicException
190
+     */
191
+    protected function save_table_attributes_to_table( Model $model ) {
192
+        throw new LogicException;
193
+    }
194
+
195
+    /**
196
+     * Deletes the Model's table attributes from its table.
197
+     *
198
+     * @param Model $model
199
+     *
200
+     * @throws LogicException
201
+     */
202
+    protected function delete_table_attributes_from_table( Model $model ) {
203
+        throw new LogicException;
204
+    }
205
+
206
+    /**
207
+     * Creates the table name string for the provided Model.
208
+     *
209
+     * @param UsesCustomTable $model
210
+     *
211
+     * @return string
212
+     */
213
+    protected function make_table_name( UsesCustomTable $model ) {
214
+        return "{$this->wpdb->prefix}{$this->prefix}_{$model::get_table_name()}";
215
+    }
216 216
 }
Please login to merge, or discard this patch.
src/Axolotl/Repository/WordPressTerm.php 1 patch
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -13,130 +13,130 @@
 block discarded – undo
13 13
  * @subpackage Axolotl\Repository
14 14
  */
15 15
 class WordPressTerm extends AbstractWordPress {
16
-	/**
17
-	 * {@inheritDoc}
18
-	 *
19
-	 * @param int $id
20
-	 *
21
-	 * @return WP_Term|false
22
-	 */
23
-	protected function get_wp_object_by_id( $id ) {
24
-		$class = $this->class;
25
-
26
-		$term = get_term( $id, $class::get_taxonomy() );
27
-
28
-		if ( is_wp_error( $term ) ) {
29
-			return false;
30
-		}
31
-
32
-		return $term;
33
-	}
34
-
35
-	/**
36
-	 * {@inheritDoc}
37
-	 *
38
-	 * @param array $params
39
-	 *
40
-	 * @return WP_Term[]
41
-	 */
42
-	protected function get_wp_objects_by_params( $params ) {
43
-		$class = $this->class;
44
-
45
-		return get_terms( $class::get_taxonomy(), $params );
46
-	}
47
-
48
-	/**
49
-	 * {@inheritDoc}
50
-	 *
51
-	 * @param Model $model
52
-	 */
53
-	protected function fill_table_attrs_from_meta( Model $model ) {
54
-		$model->unguard();
55
-
56
-		if ( $model instanceof UsesWordPressTerm ) {
57
-			foreach ( $model->get_table_keys() as $key ) {
58
-				$model->set_attribute(
59
-					$key,
60
-					get_term_meta(
61
-						$model->get_primary_id(),
62
-						$this->make_meta_key( $key ),
63
-						true
64
-					)
65
-				);
66
-			}
67
-		}
68
-
69
-		$model->reguard();
70
-	}
71
-
72
-	/**
73
-	 * {@inheritDoc}
74
-	 *
75
-	 * @param Model $model
76
-	 *
77
-	 * @return int|WP_Error
78
-	 */
79
-	protected function save_wp_object( Model $model ) {
80
-		$class = $this->class;
81
-		$object = $model->get_underlying_wp_object();
82
-
83
-		$term_id = $object->term_id;
84
-		unset( $object->term_id );
85
-
86
-		$result  = wp_update_term(
87
-			$term_id,
88
-			$class::get_taxonomy(),
89
-			(array) $object
90
-		);
91
-
92
-		if ( is_wp_error( $result ) ) {
93
-			return $result;
94
-		}
95
-
96
-		return $result['term_id'];
97
-	}
98
-
99
-	/**
100
-	 * {@inheritDoc}
101
-	 *
102
-	 * @param Model $model
103
-	 */
104
-	protected function save_table_attributes_to_meta( Model $model ) {
105
-		foreach ( $model->get_changed_table_attributes() as $attribute => $value ) {
106
-			update_term_meta(
107
-				$model->get_primary_id(),
108
-				$this->make_meta_key( $attribute ),
109
-				$value
110
-			);
111
-		}
112
-	}
113
-
114
-	/**
115
-	 * {@inheritDoc}
116
-	 *
117
-	 * @param Model $model
118
-	 * @param bool  $force
119
-	 */
120
-	protected function delete_wp_object( Model $model, $force = false ) {
121
-		$class = $this->class;
122
-
123
-		wp_delete_term(
124
-			$model->get_primary_id(),
125
-			$class::get_taxonomy()
126
-		);
127
-	}
128
-
129
-	/**
130
-	 * {@inheritDoc}
131
-	 *
132
-	 * @param Model $model
133
-	 */
134
-	protected function delete_table_attributes_from_meta( Model $model ) {
135
-		foreach ( $model->get_table_attributes() as $attribute ) {
136
-			delete_term_meta(
137
-				$model->get_primary_id(),
138
-				$this->make_meta_key( $attribute )
139
-			);
140
-		}
141
-	}
16
+    /**
17
+     * {@inheritDoc}
18
+     *
19
+     * @param int $id
20
+     *
21
+     * @return WP_Term|false
22
+     */
23
+    protected function get_wp_object_by_id( $id ) {
24
+        $class = $this->class;
25
+
26
+        $term = get_term( $id, $class::get_taxonomy() );
27
+
28
+        if ( is_wp_error( $term ) ) {
29
+            return false;
30
+        }
31
+
32
+        return $term;
33
+    }
34
+
35
+    /**
36
+     * {@inheritDoc}
37
+     *
38
+     * @param array $params
39
+     *
40
+     * @return WP_Term[]
41
+     */
42
+    protected function get_wp_objects_by_params( $params ) {
43
+        $class = $this->class;
44
+
45
+        return get_terms( $class::get_taxonomy(), $params );
46
+    }
47
+
48
+    /**
49
+     * {@inheritDoc}
50
+     *
51
+     * @param Model $model
52
+     */
53
+    protected function fill_table_attrs_from_meta( Model $model ) {
54
+        $model->unguard();
55
+
56
+        if ( $model instanceof UsesWordPressTerm ) {
57
+            foreach ( $model->get_table_keys() as $key ) {
58
+                $model->set_attribute(
59
+                    $key,
60
+                    get_term_meta(
61
+                        $model->get_primary_id(),
62
+                        $this->make_meta_key( $key ),
63
+                        true
64
+                    )
65
+                );
66
+            }
67
+        }
68
+
69
+        $model->reguard();
70
+    }
71
+
72
+    /**
73
+     * {@inheritDoc}
74
+     *
75
+     * @param Model $model
76
+     *
77
+     * @return int|WP_Error
78
+     */
79
+    protected function save_wp_object( Model $model ) {
80
+        $class = $this->class;
81
+        $object = $model->get_underlying_wp_object();
82
+
83
+        $term_id = $object->term_id;
84
+        unset( $object->term_id );
85
+
86
+        $result  = wp_update_term(
87
+            $term_id,
88
+            $class::get_taxonomy(),
89
+            (array) $object
90
+        );
91
+
92
+        if ( is_wp_error( $result ) ) {
93
+            return $result;
94
+        }
95
+
96
+        return $result['term_id'];
97
+    }
98
+
99
+    /**
100
+     * {@inheritDoc}
101
+     *
102
+     * @param Model $model
103
+     */
104
+    protected function save_table_attributes_to_meta( Model $model ) {
105
+        foreach ( $model->get_changed_table_attributes() as $attribute => $value ) {
106
+            update_term_meta(
107
+                $model->get_primary_id(),
108
+                $this->make_meta_key( $attribute ),
109
+                $value
110
+            );
111
+        }
112
+    }
113
+
114
+    /**
115
+     * {@inheritDoc}
116
+     *
117
+     * @param Model $model
118
+     * @param bool  $force
119
+     */
120
+    protected function delete_wp_object( Model $model, $force = false ) {
121
+        $class = $this->class;
122
+
123
+        wp_delete_term(
124
+            $model->get_primary_id(),
125
+            $class::get_taxonomy()
126
+        );
127
+    }
128
+
129
+    /**
130
+     * {@inheritDoc}
131
+     *
132
+     * @param Model $model
133
+     */
134
+    protected function delete_table_attributes_from_meta( Model $model ) {
135
+        foreach ( $model->get_table_attributes() as $attribute ) {
136
+            delete_term_meta(
137
+                $model->get_primary_id(),
138
+                $this->make_meta_key( $attribute )
139
+            );
140
+        }
141
+    }
142 142
 }
Please login to merge, or discard this patch.
src/Axolotl/Repository/WordPressPost.php 1 patch
Indentation   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -17,166 +17,166 @@
 block discarded – undo
17 17
  * @subpackage Axolotl\Repository
18 18
  */
19 19
 class WordPressPost extends AbstractWordPress {
20
-	/**
21
-	 * {@inheritDoc}
22
-	 *
23
-	 * @param int $id
24
-	 *
25
-	 * @return WP_Post|false
26
-	 */
27
-	protected function get_wp_object_by_id( $id ) {
28
-		$args = array_merge( $this->get_wp_query_args(), array(
29
-			'p' => (int) $id,
30
-		) );
31
-
32
-		$object = $this->main->query( $args );
33
-
34
-		if ( ! $object ) {
35
-			return false;
36
-		}
37
-
38
-		return $object[0];
39
-	}
40
-
41
-	/**
42
-	 * {@inheritDoc}
43
-	 *
44
-	 * @param array $params
45
-	 *
46
-	 * @return WP_Post[]
47
-	 */
48
-	protected function get_wp_objects_by_params( $params ) {
49
-		$args = array_merge(
50
-			$this->get_wp_query_args(),
51
-			$params
52
-		);
53
-
54
-		return $this->main->query( $args );
55
-	}
56
-
57
-	/**
58
-	 * {@inheritDoc}
59
-	 *
60
-	 * @param Model $model
61
-	 */
62
-	protected function fill_table_attrs_from_meta( Model $model ) {
63
-		$model->unguard();
64
-
65
-		if ( $model instanceof UsesWordPressPost ) {
66
-			foreach ( $model->get_table_keys() as $key ) {
67
-				$model->set_attribute(
68
-					$key,
69
-					get_post_meta(
70
-						$model->get_primary_id(),
71
-						$this->make_meta_key( $key ),
72
-						true
73
-					)
74
-				);
75
-			}
76
-		}
77
-
78
-		$model->reguard();
79
-	}
80
-
81
-	/**
82
-	 * Retrieves the default query args for the provided class.
83
-	 *
84
-	 * @return array
85
-	 */
86
-	protected function get_wp_query_args() {
87
-		$class = $this->class;
88
-
89
-		$args = array(
90
-			'post_type'   => $class::get_post_type(),
91
-		);
92
-
93
-		/**
94
-		 * Model object.
95
-		 *
96
-		 * @var Model $model
97
-		 */
98
-		$model = new $this->class;
99
-
100
-		foreach ( $model->get_related_keys() as $related_key ) {
101
-			/**
102
-			 * Relation object.
103
-			 *
104
-			 * @var Root $relation
105
-			 */
106
-			$relation = $model->{"related_{$related_key}"}();
107
-
108
-			if ( $relation instanceof HasMany &&
109
-			     $relation->get_relationship_type() === 'post_post' &&
110
-			     $relation->get_foreign_key() === 'post_parent'
111
-			) {
112
-				$args['post_parent'] = 0;
113
-			}
114
-
115
-			if ( $relation instanceof BelongsToOne &&
116
-			     $relation->get_relationship_type() === 'post_post' &&
117
-			     $relation->get_local_key() === 'post_parent'
118
-			) {
119
-				$args['post_parent__not_in'] = array( 0 );
120
-			}
121
-		}
122
-
123
-		return $args;
124
-	}
125
-
126
-	/**
127
-	 * {@inheritDoc}
128
-	 *
129
-	 * @param Model $model
130
-	 *
131
-	 * @return int|WP_Error
132
-	 */
133
-	protected function save_wp_object( Model $model ) {
134
-		$object = $model->get_underlying_wp_object();
135
-
136
-		return isset( $object->ID ) ?
137
-			wp_update_post( $object, true ) :
138
-			wp_insert_post( $object->to_array(), true );
139
-	}
140
-
141
-	/**
142
-	 * {@inheritDoc}
143
-	 *
144
-	 * @param Model $model
145
-	 */
146
-	protected function save_table_attributes_to_meta( Model $model ) {
147
-		foreach ( $model->get_changed_table_attributes() as $attribute => $value ) {
148
-			update_post_meta(
149
-				$model->get_primary_id(),
150
-				$this->make_meta_key( $attribute ),
151
-				$value
152
-			);
153
-		}
154
-	}
155
-
156
-	/**
157
-	 * {@inheritdoc}
158
-	 *
159
-	 * @param Model $model
160
-	 * @param bool  $force
161
-	 */
162
-	protected function delete_wp_object( Model $model, $force = false ) {
163
-		wp_delete_post(
164
-			$model->get_primary_id(),
165
-			$force
166
-		);
167
-	}
168
-
169
-	/**
170
-	 * {@inheritdoc}
171
-	 *
172
-	 * @param Model $model
173
-	 */
174
-	protected function delete_table_attributes_from_meta( Model $model ) {
175
-		foreach ( $model->get_table_keys() as $key ) {
176
-			delete_post_meta(
177
-				$model->get_primary_id(),
178
-				$key
179
-			);
180
-		}
181
-	}
20
+    /**
21
+     * {@inheritDoc}
22
+     *
23
+     * @param int $id
24
+     *
25
+     * @return WP_Post|false
26
+     */
27
+    protected function get_wp_object_by_id( $id ) {
28
+        $args = array_merge( $this->get_wp_query_args(), array(
29
+            'p' => (int) $id,
30
+        ) );
31
+
32
+        $object = $this->main->query( $args );
33
+
34
+        if ( ! $object ) {
35
+            return false;
36
+        }
37
+
38
+        return $object[0];
39
+    }
40
+
41
+    /**
42
+     * {@inheritDoc}
43
+     *
44
+     * @param array $params
45
+     *
46
+     * @return WP_Post[]
47
+     */
48
+    protected function get_wp_objects_by_params( $params ) {
49
+        $args = array_merge(
50
+            $this->get_wp_query_args(),
51
+            $params
52
+        );
53
+
54
+        return $this->main->query( $args );
55
+    }
56
+
57
+    /**
58
+     * {@inheritDoc}
59
+     *
60
+     * @param Model $model
61
+     */
62
+    protected function fill_table_attrs_from_meta( Model $model ) {
63
+        $model->unguard();
64
+
65
+        if ( $model instanceof UsesWordPressPost ) {
66
+            foreach ( $model->get_table_keys() as $key ) {
67
+                $model->set_attribute(
68
+                    $key,
69
+                    get_post_meta(
70
+                        $model->get_primary_id(),
71
+                        $this->make_meta_key( $key ),
72
+                        true
73
+                    )
74
+                );
75
+            }
76
+        }
77
+
78
+        $model->reguard();
79
+    }
80
+
81
+    /**
82
+     * Retrieves the default query args for the provided class.
83
+     *
84
+     * @return array
85
+     */
86
+    protected function get_wp_query_args() {
87
+        $class = $this->class;
88
+
89
+        $args = array(
90
+            'post_type'   => $class::get_post_type(),
91
+        );
92
+
93
+        /**
94
+         * Model object.
95
+         *
96
+         * @var Model $model
97
+         */
98
+        $model = new $this->class;
99
+
100
+        foreach ( $model->get_related_keys() as $related_key ) {
101
+            /**
102
+             * Relation object.
103
+             *
104
+             * @var Root $relation
105
+             */
106
+            $relation = $model->{"related_{$related_key}"}();
107
+
108
+            if ( $relation instanceof HasMany &&
109
+                 $relation->get_relationship_type() === 'post_post' &&
110
+                 $relation->get_foreign_key() === 'post_parent'
111
+            ) {
112
+                $args['post_parent'] = 0;
113
+            }
114
+
115
+            if ( $relation instanceof BelongsToOne &&
116
+                 $relation->get_relationship_type() === 'post_post' &&
117
+                 $relation->get_local_key() === 'post_parent'
118
+            ) {
119
+                $args['post_parent__not_in'] = array( 0 );
120
+            }
121
+        }
122
+
123
+        return $args;
124
+    }
125
+
126
+    /**
127
+     * {@inheritDoc}
128
+     *
129
+     * @param Model $model
130
+     *
131
+     * @return int|WP_Error
132
+     */
133
+    protected function save_wp_object( Model $model ) {
134
+        $object = $model->get_underlying_wp_object();
135
+
136
+        return isset( $object->ID ) ?
137
+            wp_update_post( $object, true ) :
138
+            wp_insert_post( $object->to_array(), true );
139
+    }
140
+
141
+    /**
142
+     * {@inheritDoc}
143
+     *
144
+     * @param Model $model
145
+     */
146
+    protected function save_table_attributes_to_meta( Model $model ) {
147
+        foreach ( $model->get_changed_table_attributes() as $attribute => $value ) {
148
+            update_post_meta(
149
+                $model->get_primary_id(),
150
+                $this->make_meta_key( $attribute ),
151
+                $value
152
+            );
153
+        }
154
+    }
155
+
156
+    /**
157
+     * {@inheritdoc}
158
+     *
159
+     * @param Model $model
160
+     * @param bool  $force
161
+     */
162
+    protected function delete_wp_object( Model $model, $force = false ) {
163
+        wp_delete_post(
164
+            $model->get_primary_id(),
165
+            $force
166
+        );
167
+    }
168
+
169
+    /**
170
+     * {@inheritdoc}
171
+     *
172
+     * @param Model $model
173
+     */
174
+    protected function delete_table_attributes_from_meta( Model $model ) {
175
+        foreach ( $model->get_table_keys() as $key ) {
176
+            delete_post_meta(
177
+                $model->get_primary_id(),
178
+                $key
179
+            );
180
+        }
181
+    }
182 182
 }
Please login to merge, or discard this patch.