1
|
|
|
<?php namespace Intraxia\Jaxion\Core; |
2
|
|
|
|
3
|
|
|
use Intraxia\Jaxion\Contract\Core\Application as ApplicationContract; |
4
|
|
|
use Intraxia\Jaxion\Contract\Core\HasActions; |
5
|
|
|
use Intraxia\Jaxion\Contract\Core\HasFilters; |
6
|
|
|
use Intraxia\Jaxion\Contract\Core\HasShortcode; |
7
|
|
|
use Intraxia\Jaxion\Contract\Core\Loader as LoaderContract; |
8
|
|
|
use UnexpectedValueException; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class Application |
12
|
|
|
* |
13
|
|
|
* @package Intraxia\Jaxion |
14
|
|
|
*/ |
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
|
27 |
|
public function __construct( $file, array $providers = array() ) { |
40
|
27 |
|
if ( null !== static::$instance ) { |
41
|
3 |
|
throw new ApplicationAlreadyBootedException; |
42
|
|
|
} |
43
|
|
|
|
44
|
27 |
|
static::$instance = $this; |
45
|
|
|
|
46
|
27 |
|
$this->register_constants( $file ); |
47
|
27 |
|
$this->register_core_services(); |
48
|
|
|
|
49
|
27 |
|
register_activation_hook( $file, array( $this, 'activate' ) ); |
50
|
27 |
|
register_deactivation_hook( $file, array( $this, 'deactivate' ) ); |
51
|
|
|
|
52
|
27 |
|
parent::__construct( $providers ); |
53
|
27 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritDoc} |
57
|
|
|
* |
58
|
|
|
* @throws UnexpectedValueException |
59
|
|
|
*/ |
60
|
12 |
|
public function boot() { |
61
|
12 |
|
$loader = $this->fetch( 'loader' ); |
62
|
|
|
|
63
|
12 |
|
if ( ! $loader instanceof LoaderContract ) { |
64
|
3 |
|
throw new UnexpectedValueException; |
65
|
|
|
} |
66
|
|
|
|
67
|
9 |
|
foreach ( $this as $alias => $value ) { |
68
|
9 |
|
if ( $value instanceof HasActions ) { |
69
|
9 |
|
$loader->register_actions( $value ); |
70
|
9 |
|
} |
71
|
|
|
|
72
|
9 |
|
if ( $value instanceof HasFilters ) { |
73
|
3 |
|
$loader->register_filters( $value ); |
74
|
3 |
|
} |
75
|
|
|
|
76
|
9 |
|
if ( $value instanceof HasShortcode ) { |
77
|
3 |
|
$loader->register_shortcode( $value ); |
78
|
3 |
|
} |
79
|
9 |
|
} |
80
|
|
|
|
81
|
9 |
|
add_action( 'plugins_loaded', array( $loader, 'run' ) ); |
82
|
9 |
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc} |
86
|
|
|
* |
87
|
|
|
* @codeCoverageIgnore |
88
|
|
|
*/ |
89
|
|
|
public function activate() { |
90
|
|
|
// no-op |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* {@inheritdoc} |
95
|
|
|
* |
96
|
|
|
* @codeCoverageIgnore |
97
|
|
|
*/ |
98
|
|
|
public function deactivate() { |
99
|
|
|
// no-op |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* {@inheritDoc} |
104
|
|
|
* |
105
|
|
|
* @return Application |
106
|
|
|
* @throws ApplicationNotBootedException |
107
|
|
|
*/ |
108
|
9 |
|
public static function instance() { |
109
|
9 |
|
if ( null === static::$instance ) { |
110
|
6 |
|
throw new ApplicationNotBootedException; |
111
|
|
|
} |
112
|
|
|
|
113
|
3 |
|
return static::$instance; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* {@inheritDoc} |
118
|
|
|
*/ |
119
|
30 |
|
public static function shutdown() { |
120
|
30 |
|
if ( null !== static::$instance ) { |
121
|
27 |
|
static::$instance = null; |
122
|
27 |
|
} |
123
|
30 |
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Sets the plugin's url, path, and basename. |
127
|
|
|
* |
128
|
|
|
* @param string $file |
129
|
|
|
*/ |
130
|
27 |
|
private function register_constants( $file ) { |
131
|
27 |
|
$this->share( 'url', plugin_dir_url( $file ) ); |
132
|
27 |
|
$this->share( 'path', plugin_dir_path( $file ) ); |
133
|
27 |
|
$this->share( 'basename', $basename = plugin_basename( $file ) ); |
134
|
27 |
|
$this->share( 'slug', dirname( $basename ) ); |
135
|
27 |
|
$this->share( 'version', static::VERSION ); |
136
|
27 |
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Registers the built-in services with the Application container. |
140
|
|
|
*/ |
141
|
27 |
|
private function register_core_services() { |
142
|
|
|
$this->share( array( 'loader' => 'Intraxia\Jaxion\Contract\Core\Loader' ), function ( $app ) { |
143
|
3 |
|
return new Loader( $app ); |
|
|
|
|
144
|
27 |
|
} ); |
145
|
27 |
|
$this->share( array( 'i18n' => 'Intaxia\Jaxion\Contract\Core\I18n' ), function ( $app ) { |
146
|
9 |
|
return new I18n( $app->fetch( 'basename' ), $app->fetch( 'path' ) ); |
147
|
27 |
|
} ); |
148
|
27 |
|
} |
149
|
|
|
} |
150
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.