-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExploratorPlugin.php
More file actions
132 lines (118 loc) · 3.7 KB
/
Copy pathExploratorPlugin.php
File metadata and controls
132 lines (118 loc) · 3.7 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
declare(strict_types=1);
namespace Crustum\Explorator;
use Cake\Core\BasePlugin;
use Cake\Core\Configure;
use Cake\Core\ContainerInterface;
use Cake\Core\PluginApplicationInterface;
use Cake\Http\MiddlewareQueue;
use Crustum\Explorator\Engine\CollectionEngine;
use Crustum\Explorator\Engine\DatabaseEngine;
use Crustum\Explorator\Engine\NullEngine;
use Crustum\PluginManifest\Manifest\ManifestInterface;
use Crustum\PluginManifest\Manifest\ManifestTrait;
use Override;
/**
* CakePHP Explorator plugin — driver-based search for Tables and Entities.
*
* @uses \Crustum\PluginManifest\Manifest\ManifestTrait
*/
class ExploratorPlugin extends BasePlugin implements ManifestInterface
{
use ManifestTrait;
/**
* Plugin name.
*
* @var string|null
*/
protected ?string $name = 'Explorator';
/**
* @var bool
*/
protected bool $bootstrapEnabled = true;
/**
* @var bool
*/
protected bool $consoleEnabled = true;
/**
* @var bool
*/
protected bool $middlewareEnabled = false;
/**
* @var bool
*/
protected bool $routesEnabled = false;
/**
* Load Explorator configuration.
*
* @param \Cake\Core\PluginApplicationInterface $app Application instance
* @return void
*/
#[Override]
public function bootstrap(PluginApplicationInterface $app): void
{
parent::bootstrap($app);
if (!Configure::check('Explorator')) {
if (file_exists(CONFIG . 'explorator.php')) {
Configure::load('explorator', 'default');
} elseif (file_exists($this->getConfigPath() . 'explorator.php')) {
Configure::load('Crustum/Explorator.explorator', 'default', false);
}
}
}
/**
* Register Explorator engine manager and local engines.
*
* @param \Cake\Core\ContainerInterface $container Application container
* @return void
*/
public function services(ContainerInterface $container): void
{
$container->addShared(EngineManager::class, fn(): EngineManager => new EngineManager());
$container->addShared(
SearchableIndexer::class,
fn(): SearchableIndexer => new SearchableIndexer($container->get(EngineManager::class)),
);
$container->addShared(NullEngine::class, fn(): NullEngine => new NullEngine());
$container->addShared(
CollectionEngine::class,
fn(): CollectionEngine => new CollectionEngine(),
);
$container->addShared(
DatabaseEngine::class,
fn(): DatabaseEngine => new DatabaseEngine(),
);
}
/**
* No HTTP middleware in Explorator v1 scaffold.
*
* @param \Cake\Http\MiddlewareQueue $middlewareQueue Middleware queue
* @return \Cake\Http\MiddlewareQueue
*/
#[Override]
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
{
return $middlewareQueue;
}
/**
* Get the manifest for the plugin.
*
* @return array<int, array<string, mixed>>
*/
public static function manifest(): array
{
$pluginPath = dirname(__DIR__);
return array_merge(
static::manifestConfig(
$pluginPath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'explorator.php',
CONFIG . 'explorator.php',
false,
),
static::manifestBootstrapAppend(
"if (file_exists(CONFIG . 'explorator.php')) {\n Configure::load('explorator', 'default');\n}",
'// Explorator Plugin Configuration',
),
static::manifestStarRepo('Crustum/explorator'),
);
}
}