true; } foreach ($this->delegates as $delegate) { if ($delegate->has($id)) { return true; } } return false; } public function inflector(string $type, ?callable $callback = null): InflectorInterface { return $this->inflectors->add($type, $callback); } public function delegate(ContainerInterface $container): self { $this->delegates[] = $container; if ($container instanceof ContainerAwareInterface) { $container->setContainer($this); } return $this; } protected function resolve($id, bool $new = false) { if ($this->definitions->has($id)) { $resolved = (true === $new) ? $this->definitions->resolveNew($id) : $this->definitions->resolve($id); return $this->inflectors->inflect($resolved); } if ($this->definitions->hasTag($id)) { $arrayOf = (true === $new) ? $this->definitions->resolveTaggedNew($id) : $this->definitions->resolveTagged($id); array_walk($arrayOf, function (&$resolved) { $resolved = $this->inflectors->inflect($resolved); }); return $arrayOf; } if ($this->providers->provides($id)) { $this->providers->register($id); if (!$this->definitions->has($id) && !$this->definitions->hasTag($id)) { // translators: %s is the alias of the service that was not found. throw new ContainerException(sprintf(esc_html__('Service provider lied about providing (%s) service', 'backwpup'), esc_html($id))); } return $this->resolve($id, $new); } foreach ($this->delegates as $delegate) { if ($delegate->has($id)) { $resolved = $delegate->get($id); return $this->inflectors->inflect($resolved); } } // translators: %s is the alias of the definition that cannot be resolved. throw new NotFoundException(sprintf(esc_html__('Alias (%s) is not being managed by the container or delegates', 'backwpup'), esc_html($id))); } }