Skip to content

Commit 27e35bd

Browse files
committed
Add action option
1 parent 7076ad2 commit 27e35bd

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

src/class-elda.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Elda {
2727
* @var array
2828
*/
2929
protected $options = [
30+
'action' => 'plugins_loaded',
3031
'domain' => '',
3132
'files' => [],
3233
'instance' => '',
@@ -74,12 +75,21 @@ public static function boot( $base_path, array $options = [] ) {
7475
$instance = new static( $base_path, $options );
7576

7677
// @codeCoverageIgnoreStart
77-
add_action( 'plugins_loaded', function () use ( $instance, $name ) {
78+
add_action( $instance->get_action(), function () use ( $instance, $name ) {
7879
return static::$instances[$name] = $instance->load_files()->get_instance();
7980
} );
8081
// @codeCoverageIgnoreEnd
8182
}
8283

84+
/**
85+
* Get action.
86+
*
87+
* @return string
88+
*/
89+
public function get_action() {
90+
return $this->options->action;
91+
}
92+
8393
/**
8494
* Get instance.
8595
*
@@ -239,6 +249,10 @@ protected function set_options( array $options ) {
239249

240250
$this->set_namespace();
241251

252+
if ( ! is_string( $this->options->action ) ) {
253+
throw new InvalidArgumentException( 'Invalid argument. `action` must be string.' );
254+
}
255+
242256
if ( ! is_string( $this->options->domain ) ) {
243257
throw new InvalidArgumentException( 'Invalid argument. `domain` must be string.' );
244258
}

tests/class-elda-test.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ public function test_base_path_exception() {
133133
public function test_options_exceptions() {
134134
try {
135135
Elda::boot( __DIR__, [
136-
'instance' => false
136+
'action' => false
137137
] );
138138
} catch ( \InvalidArgumentException $e ) {
139-
$this->assertEquals( 'Invalid argument. `instance` must be string.', $e->getMessage() );
139+
$this->assertEquals( 'Invalid argument. `action` must be string.', $e->getMessage() );
140140
}
141141

142142
try {
@@ -147,6 +147,14 @@ public function test_options_exceptions() {
147147
$this->assertEquals( 'Invalid argument. `domain` must be string.', $e->getMessage() );
148148
}
149149

150+
try {
151+
Elda::boot( __DIR__, [
152+
'instance' => false
153+
] );
154+
} catch ( \InvalidArgumentException $e ) {
155+
$this->assertEquals( 'Invalid argument. `instance` must be string.', $e->getMessage() );
156+
}
157+
150158
try {
151159
Elda::boot( __DIR__, [
152160
'lang_dir' => false

0 commit comments

Comments
 (0)