class 在 composer dump-autoload 之后找不到
class not found after composer dump-autoload
我的 compser autoload 有问题。
如果执行命令 "composer dump-autoload" 然后出现错误 Class not found 因为 autoload_static.php 已更改。
我有以下项目结构:
应用程序
-- public
------ index.php
-- 源码
------ WordToImage.php
-- 供应商
------ 作曲家
----------- (任何作曲家文件)
-------------- 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);
}
}
当我执行命令 "composer dump-autoload" 然后 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);
}
}
当我启动项目时,出现错误(Class 未找到)。请告诉我为什么这个字符串:
0 => __DIR__ . '/../..' . '/src/WordToImage.php'
'wti\src\WordToImage' => __DIR__ . '/../..' . '/src/WordToImage.php',
正在删除
两件事:
1. psr-4 自动加载器定义采用目录数组作为命名空间的值:
{
"autoload": {
"psr-4": {
"wti\": ["src/"]
}
}
}
- 正如@ndufreche 已经提到的:试试
use wti\WordToImage;
我的 compser autoload 有问题。
如果执行命令 "composer dump-autoload" 然后出现错误 Class not found 因为 autoload_static.php 已更改。
我有以下项目结构:
应用程序
-- public
------ index.php
-- 源码
------ WordToImage.php
-- 供应商
------ 作曲家
----------- (任何作曲家文件)
-------------- 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);
}
}
当我执行命令 "composer dump-autoload" 然后 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);
}
}
当我启动项目时,出现错误(Class 未找到)。请告诉我为什么这个字符串:
0 => __DIR__ . '/../..' . '/src/WordToImage.php'
'wti\src\WordToImage' => __DIR__ . '/../..' . '/src/WordToImage.php',
正在删除
两件事: 1. psr-4 自动加载器定义采用目录数组作为命名空间的值:
{
"autoload": {
"psr-4": {
"wti\": ["src/"]
}
}
}
- 正如@ndufreche 已经提到的:试试
use wti\WordToImage;