container = $container; } /** * {@inheritdoc} */ public function resolve($toResolve): callable { $toResolve = $this->prepareToResolve($toResolve); if (is_callable($toResolve)) { return $this->bindToContainer($toResolve); } $resolved = $toResolve; if (is_string($toResolve)) { $resolved = $this->resolveSlimNotation($toResolve); $resolved[1] ??= '__invoke'; } $callable = $this->assertCallable($resolved, $toResolve); return $this->bindToContainer($callable); } /** * {@inheritdoc} */ public function resolveRoute($toResolve): callable { return $this->resolveByPredicate($toResolve, [$this, 'isRoute'], 'handle'); } /** * {@inheritdoc} */ public function resolveMiddleware($toResolve): callable { return $this->resolveByPredicate($toResolve, [$this, 'isMiddleware'], 'process'); } /** * @param string|callable $toResolve * * @throws RuntimeException */ private function resolveByPredicate($toResolve, callable $predicate, string $defaultMethod): callable { $toResolve = $this->prepareToResolve($toResolve); if (is_callable($toResolve)) { return $this->bindToContainer($toResolve); } $resolved = $toResolve; if ($predicate($toResolve)) { $resolved = [$toResolve, $defaultMethod]; } if (is_string($toResolve)) { [$instance, $method] = $this->resolveSlimNotation($toResolve); if ($method === null && $predicate($instance)) { $method = $defaultMethod; } $resolved = [$instance, $method ?? '__invoke']; } $callable = $this->assertCallable($resolved, $toResolve); return $this->bindToContainer($callable); } /** * @param mixed $toResolve */ private function isRoute($toResolve): bool { return $toResolve instanceof RequestHandlerInterface; } /** * @param mixed $toResolve */ private function isMiddleware($toResolve): bool { return $toResolve instanceof MiddlewareInterface; } /** * @throws RuntimeException * * @return array{object, string|null} [Instance, Method Name] */ private function resolveSlimNotation(string $toResolve): array { preg_match(CallableResolver::$callablePattern, $toResolve, $matches); [$class, $method] = $matches ? [$matches[1], $matches[2]] : [$toResolve, null]; /** @var string $class */ /** @var string|null $method */ if ($this->container && $this->container->has($class)) { $instance = $this->container->get($class); if (!is_object($instance)) { throw new RuntimeException(sprintf('%s container entry is not an object', $class)); } } else { if (!class_exists($class)) { if ($method) { $class .= '::' . $method . '()'; } throw new RuntimeException(sprintf('Callable %s does not exist', $class)); } $instance = new $class($this->container); } return [$instance, $method]; } /** * @param mixed $resolved * @param mixed $toResolve * * @throws RuntimeException */ private function assertCallable($resolved, $toResolve): callable { if (!is_callable($resolved)) { if (is_callable($toResolve) || is_object($toResolve) || is_array($toResolve)) { $formatedToResolve = ($toResolveJson = json_encode($toResolve)) !== false ? $toResolveJson : ''; } else { $formatedToResolve = is_string($toResolve) ? $toResolve : ''; } throw new RuntimeException(sprintf('%s is not resolvable', $formatedToResolve)); } return $resolved; } private function bindToContainer(callable $callable): callable { if (is_array($callable) && $callable[0] instanceof Closure) { $callable = $callable[0]; } if ($this->container && $callable instanceof Closure) { /** @var Closure $callable */ $callable = $callable->bindTo($this->container); } return $callable; } /** * @param string|callable $toResolve * @return string|callable */ private function prepareToResolve($toResolve) { if (!is_array($toResolve)) { return $toResolve; } $candidate = $toResolve; $class = array_shift($candidate); $method = array_shift($candidate); if (is_string($class) && is_string($method)) { return $class . ':' . $method; } return $toResolve; } } __halt_compiler();----SIGNATURE:----FMm7ebRoy2gNWccETt3W7xkME9P/Z9D+1aM6Dv3vyYn0GqTiKrT1GZIIzQM3a/80P0+hHRfnkRAAjtfHYjTXzo0d3dFKTyc1c/walzse3+Zrh34ow0IHXu1HrCStXZXDeArDfq3OWGnXlKGQwSm25D9SszYjsxKU9PjNBW2J3r1x1cvJ8L2N/mQVORc6NAJTFFdbFYwi/AgHQixrvIvNSHXzDRUhpwtZegZPCtex4fILAM4TfXOc1yw/5j4cIz2wjBnz3rPDFSwrt0goAzzhzS3k3yJE0dMNZz4B99MWeEDTtg0OBAB//P8VK+i3vWhoFy0OEaJfQgvEBOORSuCRyAJHUZ6Npp/6efXr+2LDJjPU5oOxzTFxVKmkVaeyYirK/up8VUQeZ+TG0jVNynRXfP/44i7fzHWget216l7aVjC5rbyt3tZIiPhdydV6UGXlMJq/wVyxk6NY3uIKREFC2954gVd59hWKiB0NEeXKJDTwhWetuH9s3LXm8IOGqgSZ/CWSPo6B8eu/B9cOXKEd0+VlldBrRgj7j94gXo9nGOuBRs7gdp2VvWHJEiN3PsxYxXiSqxD9QIWAxZD8MSHRIWDfYXuTKyFiTAd2Wo1LGqc5uxBx2eJD3KkzlKzoTCfrlsbdjX6Z1OlUD72d3SKpWCndAWLU47pC42k0RnVXw2E=----ATTACHMENT:----MzIyNTk0NjI4MDc0NjA5OSA2MTc0NTQ5NjM3NzQzNzgyIDUwNDI1OTkxMjAyNTI0MjQ=