box icon indicating copy to clipboard operation
box copied to clipboard

Compile is failing in a symfony project

Open Willdogx opened this issue 4 years ago • 3 comments
trafficstars

I am trying to compile a symfony cli application, I followed the https://github.com/box-project/box/blob/master/doc/symfony.md#symfony-support recommendations.

This is the output

In ComposerOrchestrator.php line 171:
                                  
  Could not dump the autoloader.  
                                  

In ComposerOrchestrator.php line 174:
                                                                                                                                                                            
  The command "'/usr/local/bin/composer' 'dump-autoload' '--classmap-authoritative' '--no-dev' '--ansi'" failed.                                                            
                                                                                                                                                                            
  Exit Code: 255(Unknown error)                                                                                                                                             
                                                                                                                                                                            
  Working directory: /tmp/box/Box92446                                                                                                                                      
                                                                                                                                                                            
  Output:                                                                                                                                                                   
  ================                                                                                                                                                          
  Generating optimized autoload files (authoritative)                                                                                                             
                                                                                                                                                                            
                                                                                                                                                                            
  Error Output:                                                                                                                                                             
  ================                                                                                                                                                          
  Executing script cache:clear [KO]                                                                                                                         
   [KO]                                                                                                                                                     
  Script cache:clear returned with error code 255                                                                                                           
  !!  PHP Fatal error:  Uncaught Error: Call to undefined function Symfony\Component\Config\ctype_alpha() in /tmp/box/Box92446/vendor/symfony/config/FileLocator.php:83     
  !!  Stack trace:                                                                                                                                                          
  !!  #0 /tmp/box/Box92446/vendor/symfony/config/FileLocator.php(42): Symfony\Component\Config\FileLocator->isAbsolutePath()                                                
  !!  #1 /tmp/box/Box92446/vendor/symfony/http-kernel/Config/FileLocator.php(44): Symfony\Component\Config\FileLocator->locate()                                            
  !!  #2 /tmp/box/Box92446/vendor/symfony/config/Loader/FileLoader.php(117): Symfony\Component\HttpKernel\Config\FileLocator->locate()                                      
  !!  #3 /tmp/box/Box92446/vendor/symfony/config/Loader/FileLoader.php(85): Symfony\Component\Config\Loader\FileLoader->glob()                                              
  !!  #4 /tmp/box/Box92446/vendor/symfony/dependency-injection/Loader/FileLoader.php(64): Symfony\Component\Config\Loader\FileLoader->import()                              
  !!  #5 /tmp/box/Box92446/vendor/symfony/dependency-injection/Loader/Configurator/ContainerConfigurator.php(61): Symfony\Component\DependencyInjection\Loader\FileLoader-  
  >import()                                                                                                                                                                 
  !!  #6 /tmp/box/Box92446/src/Kernel.php(19): Symfony\Component\Depen in /tmp/box/Box92446/vendor/symfony/config/FileLocator.php on line 83                                
  !!                                                                                                                                                                        
  Script @auto-scripts was called via post-autoload-dump                       

I have ran the composer dump-env prod command, and these are my scripts in composer

    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "cache:warmup": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts",
            "@composer bin all install --ansi"
        ],
        "post-update-cmd": [
            "@auto-scripts",
            "@composer bin all update --ansi"
        ],
        "post-autoload-dump": [
            "@auto-scripts"
        ],
        "cs-check": "php-cs-fixer fix --dry-run --no-interaction --diff -vvv",
        "cs-fix": "php-cs-fixer fix --dry-run --no-interaction --diff -vvv",
        "build": "box compile"
    },

Also I am using box in the project, and not globally, using the bamarni/composer-bin-plugin as the guide said. Do you know how I can fix this?

Willdogx avatar May 07 '21 09:05 Willdogx

Hi @Willdogx, would it be possible to have more details on which version of Symfony, Box & PHP-Scooper is used?

theofidry avatar May 10 '21 20:05 theofidry

Hello, I have the same problem with ctype_alpha() which appears to be undefined. I'm using PHP 8.0.11 with Symfony 5.3 on Debian 10 using WSL2.

I opened the file symfony/config/FileLocator.php, at line 83, the function didn't use a \ so I tried prefixing the function with it but the same error happened, without the namespace.

  !!  PHP Fatal error:  Uncaught Error: Call to undefined function ctype_alpha() in /tmp/box/Box95817/vendor/symfony/conf
  ig/FileLocator.php:83

I executed php -r "var_dump(function_exists('ctype_alpha'));" which gave me true so I don't understand how the function couldn't be found;

Tell me if you need anything else.

bruno-buiret avatar Oct 21 '21 17:10 bruno-buiret

Hello again, I tried some different tests today, in the same file symfony/config/FileLocator.php,

    /**
     * Returns whether the file path is an absolute path.
     */
    private function isAbsolutePath(string $file): bool
    {
        if(!function_exists('\\ctype_alpha')) {
            echo '--------- '.PHP_SAPI.' ('.PHP_VERSION.')'.PHP_EOL;
            var_dump(get_loaded_extensions());
            echo '---------'.PHP_EOL;
        }

        if ('/' === $file[0] || '\\' === $file[0]
            || (\strlen($file) > 3 && \ctype_alpha($file[0])
                && ':' === $file[1]
                && ('\\' === $file[2] || '/' === $file[2])
            )
            || null !== parse_url($file, \PHP_URL_SCHEME)
        ) {
            return true;
        }

        return false;
    }

It was the correct version (8.0.13) and SAPI (cli), but the ctype extension which is activated in my CLI version of PHP 8.0.13 wasn't enabled, only a few of them were available: Core, date, libxml, openssl, pcre, zlib, filter, hash, json, pcntl, Reflection, SPL, session, standard and sodium. I digged some more and tried the --no-restart option of compile which solved the problem, it appears the PHP restarting with a restricted set of settings doesn't allow for compilation.

Hope it can help, have a good evening.

bruno-buiret avatar Nov 22 '21 17:11 bruno-buiret

Reviewed this should not be fixed within 4.6.0 at the very least.

theofidry avatar Dec 14 '23 07:12 theofidry