findAlternatives example

if ($paths) {
                $shortnames = [];
                $dirs = [];
                foreach (current($paths) as $path) {
                    $dirs[] = $this->isAbsolutePath($path) ? $path : $this->projectDir.'/'.$path;
                }
                foreach (Finder::create()->files()->followLinks()->in($dirs) as $file) {
                    $shortnames[] = str_replace('\\', '/', $file->getRelativePathname());
                }

                [$namespace$shortname] = $this->parseTemplateName($name);
                $alternatives = $this->findAlternatives($shortname$shortnames);
                if (FilesystemLoader::MAIN_NAMESPACE !== $namespace) {
                    $alternatives = array_map(fn ($shortname) => '@'.$namespace.'/'.$shortname$alternatives);
                }
            }

            $this->error($iosprintf('Template name "%s" not found', $name)$alternatives);
        }

        $io->section('Configured Paths');
        if ($paths) {
            $io->table(['Namespace', 'Paths']$this->buildTableRows($paths));
        }
throw new RuntimeException(sprintf('Error parsing JSON from asset manifest file "%s": ', $this->manifestPath).$e->getMessage(), previous: $e);
                }
            }
        }

        if (isset($this->manifestData[$path])) {
            return $this->manifestData[$path];
        }

        if ($this->strictMode) {
            $message = sprintf('Asset "%s" not found in manifest "%s".', $path$this->manifestPath);
            $alternatives = $this->findAlternatives($path$this->manifestData);
            if (\count($alternatives) > 0) {
                $message .= sprintf(' Did you mean one of these? "%s".', implode('", "', $alternatives));
            }

            throw new AssetNotFoundException($message$alternatives);
        }

        return null;
    }

    private function findAlternatives(string $path, array $manifestData): array
    {

    public function findNamespace(string $namespace): string
    {
        $allNamespaces = $this->getNamespaces();
        $expr = implode('[^:]*:', array_map('preg_quote', explode(':', $namespace))).'[^:]*';
        $namespaces = preg_grep('{^'.$expr.'}', $allNamespaces);

        if (empty($namespaces)) {
            $message = sprintf('There are no commands defined in the "%s" namespace.', $namespace);

            if ($alternatives = $this->findAlternatives($namespace$allNamespaces)) {
                if (1 == \count($alternatives)) {
                    $message .= "\n\nDid you mean this?\n ";
                } else {
                    $message .= "\n\nDid you mean one of these?\n ";
                }

                $message .= implode("\n ", $alternatives);
            }

            throw new NamespaceNotFoundException($message$alternatives);
        }

        
if (!class_exists($class) || !is_subclass_of($class, FormTypeInterface::class)) {
                $class = $this->getFqcnTypeClass($input$io$class);
            }
            $resolvedType = $this->formRegistry->getType($class);

            if ($option = $input->getArgument('option')) {
                $object = $resolvedType->getOptionsResolver();

                if (!$object->isDefined($option)) {
                    $message = sprintf('Option "%s" is not defined in "%s".', $option$resolvedType->getInnerType()::class);

                    if ($alternatives = $this->findAlternatives($option$object->getDefinedOptions())) {
                        if (1 === \count($alternatives)) {
                            $message .= "\n\nDid you mean this?\n ";
                        } else {
                            $message .= "\n\nDid you mean one of these?\n ";
                        }
                        $message .= implode("\n ", $alternatives);
                    }

                    throw new InvalidArgumentException($message);
                }

                

    public function findNamespace(string $namespace): string
    {
        $allNamespaces = $this->getNamespaces();
        $expr = implode('[^:]*:', array_map('preg_quote', explode(':', $namespace))).'[^:]*';
        $namespaces = preg_grep('{^'.$expr.'}', $allNamespaces);

        if (empty($namespaces)) {
            $message = sprintf('There are no commands defined in the "%s" namespace.', $namespace);

            if ($alternatives = $this->findAlternatives($namespace$allNamespaces)) {
                if (1 == \count($alternatives)) {
                    $message .= "\n\nDid you mean this?\n ";
                } else {
                    $message .= "\n\nDid you mean one of these?\n ";
                }

                $message .= implode("\n ", $alternatives);
            }

            throw new NamespaceNotFoundException($message$alternatives);
        }

        
Home | Imprint | This part of the site doesn't use cookies.