在composer dump-autoload之后找不到类

时间:2017-03-30 21:27:26

标签: php composer-php autoload

我有compser autoload的问题。
如果执行命令" composer dump-autoload"然后出现错误未找到类,因为 autoload_static.php 已更改。

我有以下项目结构:

app
- 公众
------ index.php
- src
------ WordToImage.php
- 供应商
------作曲家 ------------ (任何作曲家档案)
------------ autoload_static.php
- composer.json

index.php

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

composer.json

<?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);
    }
}

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',
        ),
    );

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

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

当我执行命令&#34; composer dump-autoload&#34;然后 autoload_static.php 被更改为

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

当我启动项目时,会出现错误(未找到类)。请告诉我为什么这个字符串:

{{1}}

是删除

1 个答案:

答案 0 :(得分:0)

两件事: 1. psr-4自动加载器定义采用一组目录作为命名空间的值:

{
    "autoload": {
        "psr-4": {
            "wti\\": ["src/"]
        }
    }
}
  1. 正如@ndufreche已经提到过:尝试use wti\WordToImage;