-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin.php
More file actions
69 lines (61 loc) · 2.41 KB
/
Plugin.php
File metadata and controls
69 lines (61 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace GoodWP\Altinator;
use GoodWP\Altinator\Modules\Modules_Service_Provider;
use GoodWP\Altinator\Vendor\GoodWP\Common\DI\Container;
use GoodWP\Altinator\Vendor\GoodWP\Common\Plugin\Plugin as Base_Plugin;
/**
* {@inheritDoc}
*/
class Plugin extends Base_Plugin {
public const VERSION = '1.0.0';
public const SLUG = 'altinator';
public readonly string $path;
public readonly string $relative_path;
public readonly string $file;
protected array $service_providers = [
Plugin_Service_Provider::class,
Modules_Service_Provider::class,
];
public function __construct( string $plugin_file ) {
assert( ! empty( static::VERSION ), 'VERSION constant in Plugin class must be defined' );
assert( ! empty( static::SLUG ), 'SLUG constant in Plugin class must be defined' );
// TODO: this is a workaround for symlinking.
$full_path = wp_normalize_path( WP_PLUGIN_DIR ) . DIRECTORY_SEPARATOR . plugin_basename( $plugin_file );
$this->file = $full_path;
$this->path = dirname( $full_path );
// $this->path = dirname( $plugin_file );
$this->relative_path = str_replace( wp_normalize_path( WP_CONTENT_DIR ), '', $this->path );
}
/**
* {@inheritDoc}
*/
public function init_container( ?Container $base_container = null ): Container {
$container = parent::init_container( $base_container );
/**
* Allows adding your services or service providers to the container or changing bindings
* after all core service providers and services were registered.
*
* @param Container $container The container instance after it's initialized/registered.
*/
do_action( 'altinator/init_container', $container );
return $container;
}
/**
* {@inheritDoc}
*/
public function boot(): void {
parent::boot();
/**
* Allows booting your own service providers/services after the plugin and all its services were booted.
*
* @param self $plugin The plugin instance booting.
*/
do_action( 'altinator/boot', $this );
}
public function get_relative_path( string $relative_path = '' ): string {
if ( ! empty( $relative_path ) ) {
return $this->relative_path . DIRECTORY_SEPARATOR . $relative_path;
}
return $this->relative_path;
}
}