|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace App\Http\Controllers; |
| 6 | + |
| 7 | +use CmsIg\Seal\Adapter\AdapterInterface; |
| 8 | +use CmsIg\Seal\EngineInterface; |
| 9 | +use CmsIg\Seal\Integration\Laravel\Facade\Engine as EngineFacade; |
| 10 | +use CmsIg\Seal\Integration\Laravel\Facade\EngineRegistry as EngineRegistryFacade; |
| 11 | +use Symfony\Component\HttpFoundation\Response; |
| 12 | + |
| 13 | +class SearchController extends Controller |
| 14 | +{ |
| 15 | + private readonly EngineInterface $algoliaEngine; |
| 16 | + private readonly EngineInterface $meilisearchEngine; |
| 17 | + private readonly EngineInterface $elasticsearchEngine; |
| 18 | + private readonly EngineInterface $loupeEngine; |
| 19 | + private readonly EngineInterface $memoryEngine; |
| 20 | + private readonly EngineInterface $opensearchEngine; |
| 21 | + private readonly EngineInterface $solrEngine; |
| 22 | + private readonly EngineInterface $redisearchEngine; |
| 23 | + private readonly EngineInterface $typesenseEngine; |
| 24 | + private readonly EngineInterface $multiEngine; |
| 25 | + private readonly EngineInterface $readWriteEngine; |
| 26 | + |
| 27 | + public function __construct() |
| 28 | + { |
| 29 | + $this->algoliaEngine = EngineRegistryFacade::getEngine('algolia'); |
| 30 | + $this->meilisearchEngine = EngineRegistryFacade::getEngine('meilisearch'); |
| 31 | + $this->elasticsearchEngine = EngineRegistryFacade::getEngine('elasticsearch'); |
| 32 | + $this->loupeEngine = EngineRegistryFacade::getEngine('loupe'); |
| 33 | + $this->memoryEngine = EngineRegistryFacade::getEngine('memory'); |
| 34 | + $this->opensearchEngine = EngineRegistryFacade::getEngine('opensearch'); |
| 35 | + $this->solrEngine = EngineRegistryFacade::getEngine('solr'); |
| 36 | + $this->redisearchEngine = EngineRegistryFacade::getEngine('redisearch'); |
| 37 | + $this->typesenseEngine = EngineRegistryFacade::getEngine('typesense'); |
| 38 | + $this->multiEngine = EngineRegistryFacade::getEngine('multi'); |
| 39 | + $this->readWriteEngine = EngineRegistryFacade::getEngine('read-write'); |
| 40 | + } |
| 41 | + |
| 42 | + public function home(): string |
| 43 | + { |
| 44 | + $engineNames = \implode(', ', \array_keys([...EngineRegistryFacade::getEngines()])); |
| 45 | + |
| 46 | + $engineFacadeClass = EngineFacade::class; |
| 47 | + $engineRegistryFacadeClass = EngineRegistryFacade::class; |
| 48 | + $engineFacadeTargetClass = EngineFacade::getFacadeRoot()::class; // @phpstan-ignore-line |
| 49 | + $engineRegistryFacadeTargetClass = EngineRegistryFacade::getFacadeRoot()::class; // @phpstan-ignore-line |
| 50 | + |
| 51 | + return |
| 52 | + <<<HTML |
| 53 | + <!doctype html> |
| 54 | + <html> |
| 55 | + <head> |
| 56 | + <title>Search Engines</title> |
| 57 | + </head> |
| 58 | + <body> |
| 59 | + <h1>Adapters</h1> |
| 60 | + <ul> |
| 61 | + <li><a href="/algolia">Algolia</a></li> |
| 62 | + <li><a href="/elasticsearch">Elasticsearch</a></li> |
| 63 | + <li><a href="/loupe">Loupe</a></li> |
| 64 | + <li><a href="/meilisearch">Meilisearch</a></li> |
| 65 | + <li><a href="/memory">Memory</a></li> |
| 66 | + <li><a href="/opensearch">Opensearch</a></li> |
| 67 | + <li><a href="/redisearch">RediSearch</a></li> |
| 68 | + <li><a href="/solr">Solr</a></li> |
| 69 | + <li><a href="/typesense">Typesense</a></li> |
| 70 | + <li>....</li> |
| 71 | + <li><a href="/multi">Multi</a></li> |
| 72 | + <li><a href="/read-write">Read-Write</a></li> |
| 73 | + </ul> |
| 74 | +
|
| 75 | + <div> |
| 76 | + <strong>Registered Engines</strong>: $engineNames |
| 77 | + </div> |
| 78 | +
|
| 79 | + <div> |
| 80 | + <h2>Facade Engines</h2> |
| 81 | +
|
| 82 | + <ul> |
| 83 | + <li><strong>$engineFacadeClass</strong>: $engineFacadeTargetClass</li> |
| 84 | + <li><strong>$engineRegistryFacadeClass</strong>: $engineRegistryFacadeTargetClass</li> |
| 85 | + </ul> |
| 86 | + </div> |
| 87 | + </body> |
| 88 | + </html> |
| 89 | + HTML; |
| 90 | + } |
| 91 | + |
| 92 | + public function algolia(): Response |
| 93 | + { |
| 94 | + $class = $this->getAdapterClass($this->algoliaEngine); |
| 95 | + |
| 96 | + return new Response( |
| 97 | + <<<HTML |
| 98 | + <!doctype html> |
| 99 | + <html> |
| 100 | + <head> |
| 101 | + <title>Algolia</title> |
| 102 | + </head> |
| 103 | + <body> |
| 104 | + <h1>$class</h1> |
| 105 | + </body> |
| 106 | + </html> |
| 107 | +HTML |
| 108 | + ); |
| 109 | + } |
| 110 | + |
| 111 | + public function meilisearch(): Response |
| 112 | + { |
| 113 | + $class = $this->getAdapterClass($this->meilisearchEngine); |
| 114 | + |
| 115 | + return new Response( |
| 116 | + <<<HTML |
| 117 | + <!doctype html> |
| 118 | + <html> |
| 119 | + <head> |
| 120 | + <title>Meilisearch</title> |
| 121 | + </head> |
| 122 | + <body> |
| 123 | + <h1>$class</h1> |
| 124 | + </body> |
| 125 | + </html> |
| 126 | +HTML |
| 127 | + ); |
| 128 | + } |
| 129 | + |
| 130 | + public function elasticsearch(): Response |
| 131 | + { |
| 132 | + $class = $this->getAdapterClass($this->elasticsearchEngine); |
| 133 | + |
| 134 | + return new Response( |
| 135 | + <<<HTML |
| 136 | + <!doctype html> |
| 137 | + <html> |
| 138 | + <head> |
| 139 | + <title>Elasticsearch</title> |
| 140 | + </head> |
| 141 | + <body> |
| 142 | + <h1>$class</h1> |
| 143 | + </body> |
| 144 | + </html> |
| 145 | +HTML |
| 146 | + ); |
| 147 | + } |
| 148 | + |
| 149 | + public function loupe(): Response |
| 150 | + { |
| 151 | + $class = $this->getAdapterClass($this->loupeEngine); |
| 152 | + |
| 153 | + return new Response( |
| 154 | + <<<HTML |
| 155 | + <!doctype html> |
| 156 | + <html> |
| 157 | + <head> |
| 158 | + <title>Loupe</title> |
| 159 | + </head> |
| 160 | + <body> |
| 161 | + <h1>$class</h1> |
| 162 | + </body> |
| 163 | + </html> |
| 164 | +HTML |
| 165 | + ); |
| 166 | + } |
| 167 | + |
| 168 | + public function memory(): Response |
| 169 | + { |
| 170 | + $class = $this->getAdapterClass($this->memoryEngine); |
| 171 | + |
| 172 | + return new Response( |
| 173 | + <<<HTML |
| 174 | + <!doctype html> |
| 175 | + <html> |
| 176 | + <head> |
| 177 | + <title>Memory</title> |
| 178 | + </head> |
| 179 | + <body> |
| 180 | + <h1>$class</h1> |
| 181 | + </body> |
| 182 | + </html> |
| 183 | +HTML |
| 184 | + ); |
| 185 | + } |
| 186 | + |
| 187 | + public function opensearch(): Response |
| 188 | + { |
| 189 | + $class = $this->getAdapterClass($this->opensearchEngine); |
| 190 | + |
| 191 | + return new Response( |
| 192 | + <<<HTML |
| 193 | + <!doctype html> |
| 194 | + <html> |
| 195 | + <head> |
| 196 | + <title>Opensearch</title> |
| 197 | + </head> |
| 198 | + <body> |
| 199 | + <h1>$class</h1> |
| 200 | + </body> |
| 201 | + </html> |
| 202 | +HTML |
| 203 | + ); |
| 204 | + } |
| 205 | + |
| 206 | + public function solr(): Response |
| 207 | + { |
| 208 | + $class = $this->getAdapterClass($this->solrEngine); |
| 209 | + |
| 210 | + return new Response( |
| 211 | + <<<HTML |
| 212 | + <!doctype html> |
| 213 | + <html> |
| 214 | + <head> |
| 215 | + <title>Solr</title> |
| 216 | + </head> |
| 217 | + <body> |
| 218 | + <h1>$class</h1> |
| 219 | + </body> |
| 220 | + </html> |
| 221 | +HTML |
| 222 | + ); |
| 223 | + } |
| 224 | + |
| 225 | + public function redisearch(): Response |
| 226 | + { |
| 227 | + $class = $this->getAdapterClass($this->redisearchEngine); |
| 228 | + |
| 229 | + return new Response( |
| 230 | + <<<HTML |
| 231 | + <!doctype html> |
| 232 | + <html> |
| 233 | + <head> |
| 234 | + <title>RediSearch</title> |
| 235 | + </head> |
| 236 | + <body> |
| 237 | + <h1>$class</h1> |
| 238 | + </body> |
| 239 | + </html> |
| 240 | +HTML |
| 241 | + ); |
| 242 | + } |
| 243 | + |
| 244 | + public function typesense(): Response |
| 245 | + { |
| 246 | + $class = $this->getAdapterClass($this->typesenseEngine); |
| 247 | + |
| 248 | + return new Response( |
| 249 | + <<<HTML |
| 250 | + <!doctype html> |
| 251 | + <html> |
| 252 | + <head> |
| 253 | + <title>Typesense</title> |
| 254 | + </head> |
| 255 | + <body> |
| 256 | + <h1>$class</h1> |
| 257 | + </body> |
| 258 | + </html> |
| 259 | +HTML |
| 260 | + ); |
| 261 | + } |
| 262 | + |
| 263 | + public function multi(): Response |
| 264 | + { |
| 265 | + $class = $this->getAdapterClass($this->multiEngine); |
| 266 | + |
| 267 | + return new Response( |
| 268 | + <<<HTML |
| 269 | + <!doctype html> |
| 270 | + <html> |
| 271 | + <head> |
| 272 | + <title>Multi</title> |
| 273 | + </head> |
| 274 | + <body> |
| 275 | + <h1>$class</h1> |
| 276 | + </body> |
| 277 | + </html> |
| 278 | +HTML |
| 279 | + ); |
| 280 | + } |
| 281 | + |
| 282 | + public function readWrite(): Response |
| 283 | + { |
| 284 | + $class = $this->getAdapterClass($this->readWriteEngine); |
| 285 | + |
| 286 | + return new Response( |
| 287 | + <<<HTML |
| 288 | + <!doctype html> |
| 289 | + <html> |
| 290 | + <head> |
| 291 | + <title>Read-Write</title> |
| 292 | + </head> |
| 293 | + <body> |
| 294 | + <h1>$class</h1> |
| 295 | + </body> |
| 296 | + </html> |
| 297 | +HTML |
| 298 | + ); |
| 299 | + } |
| 300 | + |
| 301 | + private function getAdapterClass(EngineInterface $engine): string |
| 302 | + { |
| 303 | + $reflection = new \ReflectionClass($engine); |
| 304 | + $propertyReflection = $reflection->getProperty('adapter'); |
| 305 | + $propertyReflection->setAccessible(true); |
| 306 | + |
| 307 | + /** @var AdapterInterface $object */ |
| 308 | + $object = $propertyReflection->getValue($engine); |
| 309 | + |
| 310 | + return $object::class; |
| 311 | + } |
| 312 | +} |
0 commit comments