Error: Class "Symfony\Component\Filesystem\Filesystem" not found

Created on 30 January 2023, almost 2 years ago
Updated 5 February 2023, almost 2 years ago

Problem/Motivation

When running the security review on my relatively new (started at Drupal 9.4.7) site, it fails, with this from the watchdog log:

Error: Class "Symfony\Component\Filesystem\Filesystem" not found in Drupal\security_review\Checks\PrivateFiles->run() (line 38 of /modules/contrib/security_review/src/Checks/PrivateFiles.php)

Steps to reproduce

Proposed resolution

Require the symfony/filesystem component when requiring the module with Composer, if that is the correct required component for the PrivateFiles.php check.

If the check should be using the Drupal core version, not the Symfony version that is stated, then I would think that last use line of PrivateFiles.php needs updating to:

use Drupal\Core\Component\Filesystem\Filesystem;

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom natts London

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @natts
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Can you check your file permissions on vendor folder? Symfony\Component\Filesystem has been around from what I can tell in Drupal core for some time.

  • πŸ‡¬πŸ‡§United Kingdom natts London

    It wasn't a permissions issue on the root vendor directory.

    A version of the Filesystem class is indeed in core, but the PrivateFiles.php check in this module wants to use the Symfony version:

    <?php
    
    namespace Drupal\security_review\Checks;
    
    use Drupal\Core\Link;
    use Drupal\Core\StreamWrapper\PrivateStream;
    use Drupal\security_review\Check;
    use Drupal\security_review\CheckResult;
    use Symfony\Component\Filesystem\Filesystem;
    
    /**
     * Checks whether the private files' directory is under the web root.
     */
    class PrivateFiles extends Check {
    ...
    

    So as a workaround, I had to require the component in Composer ('composer require symfony/filesystem') to get that specific version of the class into my codebase.

    If the check should be using the Drupal core version, not the Symfony version that is stated, then I would think that last use line of PrivateFiles.php needs updating to:

    use Drupal/Core/Component/Filesystem/Filesystem;

  • πŸ‡¬πŸ‡§United Kingdom natts London
  • @smustgrave opened merge request.
  • Status changed to Needs review almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    This work for you?

  • πŸ‡¬πŸ‡§United Kingdom natts London

    I wasn't the author of the Private Files check, so I don't know which is the correct version of the Filesystem class to be used by it.

  • Status changed to Fixed almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    This should ensure symfony is installed.

  • Automatically closed - issue fixed for 2 weeks with no activity.

  • πŸ‡©πŸ‡ͺGermany richardmetzger

    Just installed this module and ran across the reported error.

    composer require symfony/filesystem

    solved it for me.

Production build 0.71.5 2024