|null */ private ?array $instances = null; /** * Constructor. * * @param Container $container Plugin container. */ public function __construct( Container $container ) { $this->container = $container; } /** * Resolve every tool. * * Instances are memoised, though the container caches resolutions anyway. * * @return array Tool instances in registration order. */ public function all(): array { if ( null === $this->instances ) { $instances = array(); foreach ( self::TOOLS as $tool_class ) { $instances[] = $this->container->get( $tool_class ); } $this->instances = $instances; } return $this->instances; } /** * The TOOL_ID of every tool. * * Reads the constant off each class name, so this does not instantiate anything — * create_server() only needs the IDs. * * @return string[] Tool IDs in registration order. */ public function tool_ids(): array { $ids = array(); foreach ( self::TOOLS as $tool_class ) { $ids[] = $tool_class::TOOL_ID; } return $ids; } }