我已经在app
目录下的Laravel中添加了我的课程。今天,当我添加一个具有目录结构的API客户端时,我无法在Laravel PSR-4默认结构中识别出类。
我的API客户端目录结构是:
app -- MySubdirectory -- Partners +
|- Partner1
|- Partner2 +
|- Includes -- (other subdirectories)
|- Version -- (other subdirectories)
|- ApiClient.php
现在,我已经创建了一个位于应用程序下方的模型MyModel。
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class MyModel extends Model
{
/**
*/
protected $api;
/**
* Returns MyModel API Client connected to the API.
*/
public function __construct()
{
parent::__construct();
// ApiClient is not recognized thought PhpStorm do recognized.
$this->api = \ApiClient::factory(PROTOCOL_JSON, VERSION_DEFAULT);
$credentials = json_decode(OtherModel::where('name', 'some_name')->configuration);
$this->api->setConnectId($credentials['connect_id']);
$this->api->setSecretKey($credentials['secret_key']);
}
}
好吧,当我在线编写MyModel
时$this->api = \ApiClient::factory(PROTOCOL_JSON, VERSION_DEFAULT);
PhpStorm建议上课,显然是认识到自动加载的课程。
但是当我运行脚本时,我收到错误:
FatalThrowableError in MyModel.php line 20:
Class 'ApiClient' not found
好吧,也许composer autoload
可能存在一些问题 - 甚至到目前为止我已创建的其他课程都由PHP
自动识别。
因此,我运行了composer dump-autoload -o
并验证了autoload_classmap.php
文件,并且app
目录下的所有其他子目录/类都被识别,减去MySubdirectory
以及下面的其他子目录和类{ {1}}。
我的composer.json文件有基本的自动加载部分:
MySubdirectory
那么,为什么运行"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
无法捕获composer dump-autoload
以及其他子目录和类?
为什么PhpStorm会抓住MySubdirectory
?