phpconsolecomposer-phpsymfony-2.8

Problem with AppKernel.php in project symfony 2.8 after upgrade php from 5.6 to 7.4


Last days I try to upgrade my project step by step. I have Symfony 2.8, composer 2. Lately I found rector/rector package for upgrading, but there was conflicts when I try to install it. Next I try to install rector/rector-prefixed. It also gives many problems with installation, but after research I've update my php version to 7.4 and it goes good. I've made composer update and install, but in the meantime new error shows up. With AppKernel. Before there was everything good and the app works fine. Now I've got message in the browser: Composer detected issues in your platform: "Your Composer dependencies require a PHP version ">= 7.4.0". "

And in the console after every command (for example: php app/console list) now I'm getting this message:

#!/usr/bin/env php
PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "TixiCoreDomainBundle" from namespace "Tixi\CoreDomainBundle".
Did you forget a "use" statement for "Tixi\CoreDomainBundle\TixiCoreDomainBundle"? in C:\Users\Developer\PhpstormProjects\sfitixi\app\AppKernel.php:32
Stack trace:
#0 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php(427): AppKernel->registerBundles()
#1 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php(128): Symfony\Component\HttpKernel\Kernel->initializeBundles()
#2 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php(62): Symfony\Component\HttpKernel\Kernel->boot()
#3 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Component\Console\Application.php(117): Symfony\Bundle\FrameworkBundle\Console\Application->doRun(Object(Symfony\Compone in C:\Users\Developer\Phpstor
mProjects\sfitixi\app\AppKernel.php on line 32

Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "TixiCoreDomainBundle" from namespace "Tixi\CoreDomainBundle".
Did you forget a "use" statement for "Tixi\CoreDomainBundle\TixiCoreDomainBundle"? in C:\Users\Developer\PhpstormProjects\sfitixi\app\AppKernel.php:32
Stack trace:
#0 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php(427): AppKernel->registerBundles()
#1 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php(128): Symfony\Component\HttpKernel\Kernel->initializeBundles()
#2 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php(62): Symfony\Component\HttpKernel\Kernel->boot()
#3 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Component\Console\Application.php(117): Symfony\Bundle\FrameworkBundle\Console\Application->doRun(Object(Symfony\Compone in C:\Users\Developer\Phpstor
mProjects\sfitixi\app\AppKernel.php on line 32

This is what I have in AppKernel.php:

public function registerBundles(): array
    {
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),

            new Tixi\CoreDomainBundle\TixiCoreDomainBundle(),
            new Tixi\ApiBundle\TixiApiBundle(),
            new Tixi\SecurityBundle\TixiSecurityBundle(),
            new Tixi\App\AppBundle\TixiAppBundle(),
            new FOS\RestBundle\FOSRestBundle(),
            new FOS\OAuthServerBundle\FOSOAuthServerBundle(),
            new JMS\SerializerBundle\JMSSerializerBundle(),
            new APY\BreadcrumbTrailBundle\APYBreadcrumbTrailBundle(),
            new Knp\Bundle\SnappyBundle\KnpSnappyBundle(),
            new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
        );

        if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }

        return $bundles;
    }

I've tried to write use statements but it didn't change anything. My composer.json:

{
  "name": "symfony/framework-standard-edition",
  "license": "MIT",
  "type": "project",
  "description": "The \"Symfony Standard Edition\" distribution",
  "autoload": {
    "psr-4": {
      "Tixi\\": "src/"
    },
    "classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
  },
  "autoload-dev": {
    "files": [ "vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php" ]
  },
  "require": {
    "php": "~7.4",
    "ext-json": "*",
    "apy/breadcrumbtrail-bundle": "1.3.*",
    "composer/ca-bundle": "~1.2.7",
    "doctrine/doctrine-bundle": "~1.4",
    "doctrine/doctrine-migrations-bundle": "1.3.*",
    "doctrine/orm": "^2.4.8",
    "egulias/email-validator": "~1.2",
    "friendsofsymfony/oauth-server-bundle": "1.5.*",
    "friendsofsymfony/rest-bundle": "1.7.*",
    "incenteev/composer-parameter-handler": "~2.0",
    "jms/serializer-bundle": "1.5.*",
    "knplabs/knp-snappy-bundle": "1.5.*",
    "mediaburst/clockworksms": "2.0.*",
    "sensio/distribution-bundle": "~4.0",
    "sensio/framework-extra-bundle": "^3.0.2",
    "symfony/monolog-bundle": "^3.0.2",
    "symfony/swiftmailer-bundle": "~2.3,>=2.3.10",
    "symfony/symfony": "2.8.*",
    "twig/extensions": "1.5.*",
    "twig/twig": "^1.0||^2.0"
  },
  "require-dev": {
    "rector/rector-prefixed": "^0.9.31",
    "sensio/generator-bundle": "~3.0",
    "symfony/phpunit-bridge": "~2.7"
  },
  "scripts": {
    "symfony-scripts": [
      "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
      "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
      "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
      "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
      "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
      "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
    ],
    "post-install-cmd": [
      "@symfony-scripts"
    ],
    "post-update-cmd": [
      "@symfony-scripts"
    ]
  },
  "config": {
    "bin-dir": "bin",
    "platform": {
      "php": "7.4"
    },
    "sort-packages": true,
    "discard-changes": true
  },
  "extra": {
    "symfony-app-dir": "app",
    "symfony-web-dir": "web",
    "symfony-assets-install": "relative",
    "incenteev-parameters": {
      "file": "app/config/parameters.yml"
    },
    "branch-alias": {
      "dev-master": "2.8-dev"
    }
  }
}

Anyone have idea how to fix this?

EDIT (11.03.2021)

Yes, the class exist. The problem is with every 4 class with namespace begin with Tixi. This class are empty and they extends Bundle class from Symfony. They are like this:

<?php

namespace Tixi\ApiBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
 * Class TixiApiBundle
 * @package Tixi\ApiBundle
 */
class TixiApiBundle extends Bundle
{
}

And the place of this classes pass with they namespace.Folders structure

EDIT: 18.03

After changing the namespace in composer.json for auto load I have another error, this time with running scripts from composer.json. This is the error message:

> post-install-cmd: @symfony-scripts
> symfony-scripts: Incenteev\ParameterHandler\ScriptHandler::buildParameters
Updating the "app/config/parameters.yml" file
> symfony-scripts: Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> symfony-scripts: Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache

#!/usr/bin/env php

  [Symfony\Component\Debug\Exception\ContextErrorException]
  Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?

Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event terminated with an exception

  [RuntimeException]
  An error occurred when executing the ""cache:clear --no-warmup"" command:

  #!/usr/bin/env php

    [Symfony\Component\Debug\Exception\ContextErrorException]
    Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?
  .
Exception trace:
 () at C:\Users\Developer\PhpstormProjects\sfitixi\vendor\sensio\distribution-bundle\Sensio\Bundle\DistributionBundle\Composer\ScriptHandler.php:326
 Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::executeCommand() at C:\Users\Developer\PhpstormProjects\sfitixi\vendor\sensio\distribution-bundle\Sensio\Bundle\DistributionBundle\Composer\ScriptHandler.php:138
 Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:341
 Composer\EventDispatcher\EventDispatcher->executeEventPhpScript() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:220
 Composer\EventDispatcher\EventDispatcher->doDispatch() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:87
 Composer\EventDispatcher\EventDispatcher->dispatch() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:200
 Composer\EventDispatcher\EventDispatcher->doDispatch() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:102
 Composer\EventDispatcher\EventDispatcher->dispatchScript() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Installer.php:341
 Composer\Installer->run() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Command/InstallCommand.php:136
 Composer\Command\InstallCommand->execute() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Command/Command.php:245
 Symfony\Component\Console\Command\Command->run() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Application.php:835
 Symfony\Component\Console\Application->doRunCommand() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Application.php:185
 Symfony\Component\Console\Application->doRun() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Console/Application.php:310
 Composer\Console\Application->doRun() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Application.php:117
 Symfony\Component\Console\Application->run() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Console/Application.php:122
 Composer\Console\Application->run() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/bin/composer:63
 require() at C:\ProgramData\ComposerSetup\bin\composer.phar:24


Solution

  • The autoloader is not configured properly:

      "autoload": {
        "psr-4": {
          "Tixi\\": "src/"
        },
        "classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
      },
    

    This tells the autoloader to search for all classes in the Tixi namespace in src. According to this, the class Tixi\CoreDomainBundle\TixiCoreDomainBundle should be located at src/CoreDomainBundle/TixiCoreDomainBundle.php, but it is located at src/Tixi/CoreDomainBundle/TixiCoreDomainBundle.php.

    Either move everything from the Tixi subfolder one level up, or adjust your classloader settings - changing it to src/Tixi/ could help