[英]PSR-4 not autoloading class files?
Index: <?php require '../application/bootstrap.php'; ?>
索引: <?php require '../application/bootstrap.php'; ?>
<?php require '../application/bootstrap.php'; ?>
Bootstrap: 引导程序:
<?php
define("START", microtime(true));
define("ROOT", realpath(__DIR__.'/../'));
include '../vendor/autoload.php';
include ROOT . '/application/Library/Application.php';
App\Application::getClass('test')->test();
Composer.JSON: Composer.JSON:
"autoload": {
"psr-4": {
"App\\": "application/"
}
}
The problem is with this line: 问题在于此行:
include ROOT . '/application/Library/Application.php';
I shouldn't have to include it, PSR-4 should do it for me. 我不必包括它,PSR-4应该为我做。 Here is my Application class. 这是我的Application类。
<?php
namespace App;
class Application
{
public static function getClass($library){} // removed body for minimal example
}
?>
Here is my file structure: https://i.imgur.com/Gr1aaZG.png , Vendor folder is hidden in my IDE as I configured it like that in my VSCode settings, although it is there. 这是我的文件结构: https ://i.imgur.com/Gr1aaZG.png,虽然我在VSCode设置中进行了配置,但Vendor文件夹在我的IDE中是隐藏的,尽管它已经存在。
Your PSR-4 namespace says ROOT of App
namespace is at folder application/
, but your file is at path /application/Library/Application.php
. 您的PSR-4命名空间表示App
命名空间的ROOT位于文件夹application/
,但文件位于路径/application/Library/Application.php
。 With this config you either move Application.php
to /application/Application.php
or you set namespace of your application class to App\\Library
; 使用此配置,您可以将Application.php
移至/application/Application.php
或者将应用程序类的名称空间设置为App\\Library
;
That should solve your problem. 那应该解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.