我是名称空间的新手,正在进行测试,但是当我运行app.php时,出现下一个错误:
严重错误:找不到“ ProtocoloWT \ models \ status”类 C:\ xampp \ htdocs \ wt.uptkd \ protocoloWt \ app.php
。
app.php
use Neomerx\JsonApi\Encoder\Encoder;
use Neomerx\JsonApi\Encoder\EncoderOptions;
use ProtocoloWT\models\status;
require '../vendor/autoload.php';
$status = status::instance(http_response_code(204));
$encoder = Encoder::instance([
'\status' => '\statusEsquema',
], new EncoderOptions(JSON_PRETTY_PRINT, 'http://example.com/api/v1'));
echo $encoder->encodeData($status);
status.php
namespace ProtocoloWT\models;
class status
{
public static function instance ($status)
{
$estado = new status();
$estado->status = $status;
return $estado;
}
}
composer.json
{
"name": "neomerx/json-api",
"description": "Framework agnostic JSON API (jsonapi.org) implementation",
"keywords": [
"jsonapi.org",
"json-api",
"jsonapi",
"neomerx",
"json",
"api"
],
"homepage": "https://github.com/neomerx/json-api",
"support": {
"issues": "https://github.com/neomerx/json-api/issues"
},
"license": "Apache-2.0",
"authors": [
{
"name": "neomerx",
"email": "info@neomerx.com"
}
],
"require": {
"php": ">=5.5.0",
"psr/http-message": "^1.0",
"psr/log": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^4.6 || ^5.0 || ^6.0",
"mockery/mockery": "~0.9.4",
"scrutinizer/ocular": "^1.3",
"squizlabs/php_codesniffer": "^2.5",
"monolog/monolog": "^1.18",
"phpmd/phpmd": "^2.6"
},
"minimum-stability": "stable",
"autoload": {
"psr-4": {
"Neomerx\\JsonApi\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Neomerx\\Tests\\JsonApi\\": "tests/",
"Neomerx\\Samples\\JsonApi\\": "sample/"
}
},
"scripts": {
"test": ["@test-unit", "@test-cs", "@test-md"],
"test-unit": "./vendor/phpunit/phpunit/phpunit --coverage-text",
"test-unit-with-coverage": "phpdbg -qrr ./vendor/bin/phpunit --coverage-text",
"test-cs": "./vendor/bin/phpcs -p -s --standard=PSR2 ./src ./tests",
"test-md": "./vendor/bin/phpmd ./src text codesize,controversial,cleancode,design,unusedcode,naming",
"perf-php": "docker-compose run --rm cli_php php /app/sample/sample.php -t=10000",
"perf-hhvm": "docker-compose run --rm cli_hhvm hhvm /app/sample/sample.php -t=10000"
}
}
app.php文件位于名为protocoloWT/
的目录中,status.php位于protocoloWT/models
中。
我使用composer安装了一个框架,并且可以使用这些名称空间(Neomerx \ JsonApi),但是由于出现该错误,因此无法在文件中创建自己的名称空间。可能是什么问题?
PS:对不起,我的英语,我已经尽力解释了一下