container = new ExtendedContainer(); // Allow the container to be used as a dependency. $this->container->addShared( static::class, $this ); // Add shared services. $this->load_providers(); // Allow delegating unresolved queries to classes from `includes`. $this->container->delegate( $legacy_container ?? new LegacyContainer() ); // Allow delegating unresolved queries to the WooCommerce container. $this->container->delegate( $woo_container ?? new WooContainer() ); } /** * Retrieves an instance of a given class. * * @template ID * @param class-string $id The ID of the class to retrieve. * @return ID * @throws ContainerException In case the ID could not be resolved or instantiated. */ public function get( $id ) { try { return $this->container->get( $id ); } catch ( \Throwable $e ) { throw new ContainerException( $e->getMessage(), $e->getCode(), $e ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped } } /** * Checks if a class is available. * * @param string $id The ID of the class to check. * @return bool */ public function has( $id ) { return $this->container->has( $id ); } /** * Loads all available providers into the container. */ private function load_providers() { $this->container->addServiceProvider( new GenericServiceProvider() ); $this->container->addServiceProvider( new PaymentsServiceProvider() ); $this->container->addServiceProvider( new ProxiesServiceProvider() ); } }