我的作曲家自动加载文件不包含 类
My composer autoload file don't contain classes
我正在使用 Composer
和 coffeecode/datalayer
库创建一个 REST API
和 PHP
,但是当我尝试加载我的 class 时,我收到Class not found error 当我在终端输入 dump-autoload
时,我得到 Generated autoload files containing 0 classes
composer.json
{
"name": "bruno_monteiro/restapi_php",
"description": "Simple PHP REST API",
"type": "project",
"require": {
"coffeecode/datalayer": "1.1.*"
},
"license": "MIT",
"authors": [
{
"name": "Bruno Monteiro",
"email": ""
}
],
"minimum-stability": "stable",
"autoload": {
"psr-4": {
"Source\": "source/"
}
}
}
型号
namespace Source\Models;
final class Validations{
...
}
控制器(出现错误的地方)
namespace Source\Controllers;
require "../../vendor/autoload.php";
require "../Config.php";
use Source\Models\Validations;
switch($_SERVER["REQUEST_METHOD"]){
case "POST":
$data = json_decode(file_get_contents("php://input"), false);
if(!$data){
header("HTTP/1.1 400 Bad Request");
echo json_encode(array(
"response"=>"Nenhum dado informado"
));
exit;
}
$errors = array();
if(!Validations::validateString($data->first_name)){
array_push($errors, "Nome informado inválido");
}
...
目录结构
│ composer.json
│ composer.lock
│ Script.sql
│
├───source
│ │ Config.php
│ │
│ ├───Controllers
│ │ User.php
│ │
│ └───Models
│ User.php
│ Validations.php
│
└───vendor
│ autoload.php
│
├───coffeecode
│ └───datalayer
│ │ composer.json
│ │ CONTRIBUTING.md
│ │ LICENSE
│ │ README.md
│ │
│ ├───example
│ │ │ db_config.php
│ │ │ destroy_example.php
│ │ │ find_example.php
│ │ │ pdo_example.php
│ │ │ save_example.php
│ │ │
│ │ └───Models
│ │ Address.php
│ │ User.php
│ │
│ └───src
│ Connect.php
│ CrudTrait.php
│ DataLayer.php
│
└───composer
autoload_classmap.php
autoload_namespaces.php
autoload_psr4.php
autoload_real.php
autoload_static.php
ClassLoader.php
installed.json
LICENSE
我通过使用 -a
标志
在 dump-autoload
上加载 类 解决了我的问题
我正在使用 Composer
和 coffeecode/datalayer
库创建一个 REST API
和 PHP
,但是当我尝试加载我的 class 时,我收到Class not found error 当我在终端输入 dump-autoload
时,我得到 Generated autoload files containing 0 classes
composer.json
{
"name": "bruno_monteiro/restapi_php",
"description": "Simple PHP REST API",
"type": "project",
"require": {
"coffeecode/datalayer": "1.1.*"
},
"license": "MIT",
"authors": [
{
"name": "Bruno Monteiro",
"email": ""
}
],
"minimum-stability": "stable",
"autoload": {
"psr-4": {
"Source\": "source/"
}
}
}
型号
namespace Source\Models;
final class Validations{
...
}
控制器(出现错误的地方)
namespace Source\Controllers;
require "../../vendor/autoload.php";
require "../Config.php";
use Source\Models\Validations;
switch($_SERVER["REQUEST_METHOD"]){
case "POST":
$data = json_decode(file_get_contents("php://input"), false);
if(!$data){
header("HTTP/1.1 400 Bad Request");
echo json_encode(array(
"response"=>"Nenhum dado informado"
));
exit;
}
$errors = array();
if(!Validations::validateString($data->first_name)){
array_push($errors, "Nome informado inválido");
}
...
目录结构
│ composer.json
│ composer.lock
│ Script.sql
│
├───source
│ │ Config.php
│ │
│ ├───Controllers
│ │ User.php
│ │
│ └───Models
│ User.php
│ Validations.php
│
└───vendor
│ autoload.php
│
├───coffeecode
│ └───datalayer
│ │ composer.json
│ │ CONTRIBUTING.md
│ │ LICENSE
│ │ README.md
│ │
│ ├───example
│ │ │ db_config.php
│ │ │ destroy_example.php
│ │ │ find_example.php
│ │ │ pdo_example.php
│ │ │ save_example.php
│ │ │
│ │ └───Models
│ │ Address.php
│ │ User.php
│ │
│ └───src
│ Connect.php
│ CrudTrait.php
│ DataLayer.php
│
└───composer
autoload_classmap.php
autoload_namespaces.php
autoload_psr4.php
autoload_real.php
autoload_static.php
ClassLoader.php
installed.json
LICENSE
我通过使用 -a
标志
dump-autoload
上加载 类 解决了我的问题