gpt4 book ai didi

php - Composer 没有加载我自己的 psr-0 文件

转载 作者:可可西里 更新时间:2023-11-01 12:57:46 25 4
gpt4 key购买 nike

我似乎无法让 Composer 使用 psr-0 自动加载机制处理我自己的类/文件。任何人都可以阐明为什么以下内容不起作用吗?

我在错误日志中得到以下输出:

PHP Fatal error: Class 'TestdirTest1' not found in /home/webroot/bitlama/index.php on line 5

如果我取消对显式 require 语句 (index.php:2) 的注释,它确实有效。

如果有人想知道 - 是的,我已经以以下形式运行 composer install:'php ../composer.phar install'。

这是我的目录结构:

├── composer.json
├── index.php
├── testspacedir
│   └── Testdir
│   └── test1.php
└── vendor
├── autoload.php
└── composer
├── autoload_classmap.php
├── autoload_namespaces.php
├── autoload_real.php
└── ClassLoader.php

Composer .json:

{
"autoload": {
"psr-0": { "Testdir\\": "testspacedir/"}
}
}

test1.php:

<?php

namespace Testdir;

class Test1 {

public function __construct()
{
echo "Woohoo Test1";
}

}

索引.php:

<?php
require 'vendor/autoload.php';
//require 'testspacedir/Testdir/test1.php';

$test1 = new Testdir\Test1();

供应商/autoload.php:

<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer' . '/autoload_real.php';

return ComposerAutoloaderInit7b4760e0f7ca9d6454dd2f098c374ba4::getLoader();

最佳答案

我的类文件被命名为 test1.php 而不是 Test1.php 所需的 PSR-0 命名约定。

关于php - Composer 没有加载我自己的 psr-0 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20446768/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com