| 1 |
<?php |
| 2 |
declare(strict_types=1); |
| 3 |
|
| 4 |
namespace Imagify\MCP; |
| 5 |
|
| 6 |
use Imagify\Abilities\GetAccount; |
| 7 |
use Imagify\Abilities\GetMediaStatus; |
| 8 |
use Imagify\Abilities\GetNextgenCoverage; |
| 9 |
use Imagify\Abilities\GetSettings; |
| 10 |
use Imagify\Abilities\GetStats; |
| 11 |
use Imagify\Abilities\OptimizeMedia; |
| 12 |
use Imagify\Abilities\UpdateSettings; |
| 13 |
use Imagify\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider; |
| 14 |
use Imagify\Stats\OptimizedMediaWithoutNextGen; |
| 15 |
|
| 16 |
/** |
| 17 |
* Service provider for the MCP (Model Context Protocol) module. |
| 18 |
* |
| 19 |
* Wires `ConfigSubscriber` and `AbilitiesSubscriber` into the DI container. |
| 20 |
* For the foundation `AbilitiesSubscriber` is registered with no ability |
| 21 |
* arguments. Downstream sub-issues extend the wiring via `addArguments()` |
| 22 |
* once concrete ability classes are added (see Downstream Wiring Contract |
| 23 |
* in spec #1108). |
| 24 |
* |
| 25 |
* @since 2.3.0 |
| 26 |
*/ |
| 27 |
class ServiceProvider extends AbstractServiceProvider { |
| 28 |
|
| 29 |
/** |
| 30 |
* Services provided by this provider. |
| 31 |
* |
| 32 |
* @var array<int, string> |
| 33 |
*/ |
| 34 |
protected $provides = [ |
| 35 |
ConfigSubscriber::class, |
| 36 |
AbilitiesSubscriber::class, |
| 37 |
GetAccount::class, |
| 38 |
GetMediaStatus::class, |
| 39 |
GetNextgenCoverage::class, |
| 40 |
GetSettings::class, |
| 41 |
GetStats::class, |
| 42 |
OptimizeMedia::class, |
| 43 |
UpdateSettings::class, |
| 44 |
]; |
| 45 |
|
| 46 |
/** |
| 47 |
* Subscribers provided by this provider. |
| 48 |
* |
| 49 |
* @var array<int, string> |
| 50 |
*/ |
| 51 |
public $subscribers = [ |
| 52 |
ConfigSubscriber::class, |
| 53 |
AbilitiesSubscriber::class, |
| 54 |
]; |
| 55 |
|
| 56 |
/** |
| 57 |
* Checks whether this provider provides a given service. |
| 58 |
* |
| 59 |
* @param string $id Service identifier. |
| 60 |
* @return bool |
| 61 |
*/ |
| 62 |
public function provides( string $id ): bool { |
| 63 |
return in_array( $id, $this->provides, true ); |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Registers the provided services into the container. |
| 68 |
* |
| 69 |
* @return void |
| 70 |
*/ |
| 71 |
public function register(): void { |
| 72 |
$this->getContainer()->addShared( ConfigSubscriber::class ); |
| 73 |
$this->getContainer()->addShared( GetAccount::class ); |
| 74 |
$this->getContainer()->addShared( GetMediaStatus::class ); |
| 75 |
$this->getContainer()->addShared( GetNextgenCoverage::class ) |
| 76 |
->addArgument( OptimizedMediaWithoutNextGen::class ); |
| 77 |
$this->getContainer()->addShared( GetSettings::class ); |
| 78 |
$this->getContainer()->addShared( GetStats::class ); |
| 79 |
$this->getContainer()->addShared( OptimizeMedia::class ); |
| 80 |
$this->getContainer()->addShared( UpdateSettings::class ); |
| 81 |
$this->getContainer()->addShared( AbilitiesSubscriber::class ) |
| 82 |
->addArguments( [ GetAccount::class, GetMediaStatus::class, GetNextgenCoverage::class, GetSettings::class, GetStats::class, OptimizeMedia::class, UpdateSettings::class ] ); |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Returns the list of subscriber class names. |
| 87 |
* |
| 88 |
* @return array<int, string> |
| 89 |
*/ |
| 90 |
public function get_subscribers(): array { |
| 91 |
return $this->subscribers; |
| 92 |
} |
| 93 |
} |
| 94 |
|