0
votes

I have a problem with compser autoload.
If execute command "composer dump-autoload" then emerges error Class not found because autoload_static.php changed.

I have following structure of project:

app
-- public
------ index.php
-- src
------ WordToImage.php
-- vendor
------ composer
------------ (any composer files)
------------ autoload_static.php
-- composer.json

index.php

 require_once __DIR__ . '/../vendor/autoload.php';
 use wti\src\WordToImage;

 $loader = new WordToImage();
 $loader->saveImages();

composer.json

{
    "autoload": {
        "psr-4": {
            "wti\\" : "src/"
        }
    }
} 

autoload_static.php

<?php

// autoload_static.php @generated by Composer

namespace Composer\Autoload;

class ComposerStaticInit416f5acb57c46a86bf05d897e056b40d
{
    public static $prefixLengthsPsr4 = array (
        'w' => 
        array (
            'wti\\' => 4,
        ),
    );

    public static $prefixDirsPsr4 = array (
        'wti\\' => 
        array (
            0 => __DIR__ . '/../..' . '/src/WordToImage.php',
        ),
    );

    public static $classMap = array (
        'wti\\src\\WordToImage' => __DIR__ . '/../..' . '/src/WordToImage.php',
    );

    public static function getInitializer(ClassLoader $loader)
    {
        return \Closure::bind(function () use ($loader) {
            $loader->prefixLengthsPsr4 = ComposerStaticInit416f5acb57c46a86bf05d897e056b40d::$prefixLengthsPsr4;
            $loader->prefixDirsPsr4 = ComposerStaticInit416f5acb57c46a86bf05d897e056b40d::$prefixDirsPsr4;
            $loader->classMap = ComposerStaticInit416f5acb57c46a86bf05d897e056b40d::$classMap;

        }, null, ClassLoader::class);
    }
}

When I execute command "composer dump-autoload" then autoload_static.php is changed

<?php

// autoload_static.php @generated by Composer

namespace Composer\Autoload;

class ComposerStaticInit416f5acb57c46a86bf05d897e056b40d
{
    public static $prefixLengthsPsr4 = array (
        'w' => 
        array (
            'wti\\' => 4,
        ),
    );

    public static $prefixDirsPsr4 = array (
        'wti\\' => 
        array (
            0 => __DIR__ . '/../..' . '/src',
        ),
    );

    public static function getInitializer(ClassLoader $loader)
    {
        return \Closure::bind(function () use ($loader) {
            $loader->prefixLengthsPsr4 = ComposerStaticInit416f5acb57c46a86bf05d897e056b40d::$prefixLengthsPsr4;
            $loader->prefixDirsPsr4 = ComposerStaticInit416f5acb57c46a86bf05d897e056b40d::$prefixDirsPsr4;

        }, null, ClassLoader::class);
    }
}

And when I starting the project, an error emerges (Class not found). Please tell me why this strings:

0 => __DIR__ . '/../..' . '/src/WordToImage.php'
'wti\\src\\WordToImage' => __DIR__ . '/../..' . '/src/WordToImage.php', 

are delete

1
try use wti\WordToImage; wti refer to the src folder, then if your is in src/WordToImage.php then the namespace is wti\WordToImagendufreche

1 Answers

1
votes

Two things: 1. The psr-4 autoloader definition takes an array of directories as the value for the namespace:

{
    "autoload": {
        "psr-4": {
            "wti\\": ["src/"]
        }
    }
}
  1. As @ndufreche already mentioned: Try use wti\WordToImage;