0

When building a simple site with Silex and Symfony components, I receive the following error after installing the FormServiceProvider service:

ClassNotFoundException in XliffFileLoader.php line 54:

Attempted to load class "XmlUtils" from namespace "Symfony\Component\Config\Util". Did you forget a "use" statement for another namespace?

The template is here:

{% extends 'base.html.twig' %}

{% block body %}
    <h1>{{ page.title }}</h1>
    <p>By {{ page.author }}, published on {{ page.publishedAt|date('m/d/Y') }}</p>
    <pre>{{ page.content }}</pre>
    <hr/>
    {{ form_start(form) }}
    {{ form_body(form) }}
    {{ form_end(form) }}
{% endblock %}

I followed the install directions here:

https://silex.sensiolabs.org/doc/2.0/providers/form.html

I've read a number of other questions, most of which talk about a missing global namespace identifier (\DomDocument instead of DomDocument, which inherits the local namespace), or that php-xml is not installed, or that there's a missing configuration. Those are not the issues here, but here is one that covers two of those three:

Symfony app_dev.php install \DOMDomain error

And here are the configuration calls:

$this->app->register(new ServiceControllerServiceProvider());
$this->app->register(new LocaleServiceProvider());
$this->app->register(new TranslationServiceProvider(), [
    'locale_fallbacks' => ['en'],
    'translator.messages' => [],
    'translator.domains' => [],
]);
$this->app->register(new AssetServiceProvider());
$this->app->register(new TwigServiceProvider(), [
    'twig.path' => self::TEMPLATE_DIR
]);
$this->app->register(new FormServiceProvider());
$this->app->register(new MonologServiceProvider());
$this->app->register(new HttpFragmentServiceProvider());

The last two were the ones suggested as being the culprit based on configuration errors.

How is this error resolved in this situation?

1 Answer 1

2

The solution to this problem is hinted by looking at the file specified:

private function extract($resource, MessageCatalogue $catalogue, $domain)
{
    try {
        $dom = XmlUtils::loadFile($resource);
    } catch (\InvalidArgumentException $e) {
        throw new InvalidResourceException(sprintf('Unable to load "%s": %s', $resource, $e->getMessage()), $e->getCode(), $e);
    }

Line 54 is the fourth line starting with $dom. PhpStorm showed that the following two use statements were not referencing anything:

use Symfony\Component\Config\Util\XmlUtils;
use Symfony\Component\Config\Resource\FileResource;

Which led me to wonder where that came from, leading to the symfony/config component. I went back to the Silex FormServiceProvider documentation and remembered running this line:

composer require symfony/validator symfony/config

Note the second in the list. Either I forgot to type that or (as I recall) I did type it and it didn't install. Maybe it threw an error and I didn't catch it? I don't know. However, if you're getting this error in a project using Symfony components, check to make sure the Config Component is installed.

Sign up to request clarification or add additional context in comments.

1 Comment

just ran into the same problem. The symfony/config component is used by the symfony/translation, but is only require as "require-dev". I don't geht why it isnt a regular dependency, if it is used normaly..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.