我在Windows上使用composer,当我执行composer install
或composer update
时,它正在成功加载我在composer.json文件中使用的2个包。
{
"require": {
"bcosca/fatfree": "dev-master",
"respect/validation": "^1.1"
}
}
我的index.php中的第一行是
require_once __DIR__ . '\vendor\autoload.php';
这似乎没有加载任何东西,例如,与这两个包中未定义的类相关的许多错误。我进一步调查了一下,发现我的autoload_namespaces.php
如下:
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);
数组完全是空的,这是怎么回事?我希望能看到这2个套餐&#39;这里的要求......
感谢您的帮助!
从包本身添加composer.json: F3:
{
"name": "bcosca/fatfree",
"description": "A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!",
"homepage": "http://fatfreeframework.com/",
"license": "GPL-3.0",
"require": {
"php": ">=5.3.6"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/bcosca/fatfree"
}
],
"autoload": {
"files": ["lib/base.php"]
}
}
验证
{
"name": "respect/validation",
"description": "The most awesome validation engine ever created for PHP",
"keywords": ["respect", "validation", "validator"],
"type": "library",
"homepage": "http://respect.github.io/Validation/",
"license": "BSD Style",
"authors": [
{
"name": "Respect/Validation Contributors",
"homepage": "https://github.com/Respect/Validation/graphs/contributors"
}
],
"require": {
"php": ">=5.4",
"symfony/polyfill-mbstring": "^1.2"
},
"require-dev": {
"egulias/email-validator": "~1.2",
"malkusch/bav": "~1.0",
"mikey179/vfsStream": "^1.5",
"phpunit/phpunit": "~4.0",
"symfony/validator": "~2.6.9",
"zendframework/zend-validator": "~2.3"
},
"suggest": {
"ext-bcmath": "Arbitrary Precision Mathematics",
"ext-mbstring": "Multibyte String Functions",
"egulias/email-validator": "Strict (RFC compliant) email validation",
"malkusch/bav": "German bank account validation",
"symfony/validator": "Use Symfony validator through Respect\\Validation",
"zendframework/zend-validator": "Use Zend Framework validator through Respect\\Validation",
"fabpot/php-cs-fixer": "Fix PSR2 and other coding style issues"
},
"autoload": {
"psr-4": {
"Respect\\Validation\\": "library/"
}
},
"autoload-dev": {
"psr-4": {
"Respect\\Validation\\": "tests/library/"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
}
},
"scripts": {
"test": "./vendor/bin/phpunit"
}
}
在加载Validator之后,这个Symfony组件附带了它:
{
"name": "symfony/polyfill-mbstring",
"type": "library",
"description": "Symfony polyfill for the Mbstring extension",
"keywords": ["polyfill", "shim", "compatibility", "portable", "mbstring"],
"homepage": "https://symfony.com",
"license": "MIT",
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"require": {
"php": ">=5.3.3"
},
"autoload": {
"psr-4": { "Symfony\\Polyfill\\Mbstring\\": "" },
"files": [ "bootstrap.php" ]
},
"suggest": {
"ext-mbstring": "For best performance"
},
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.3-dev"
}
}
}
答案 0 :(得分:4)
数组完全是空的,这是怎么回事?我希望能看到这2个套餐&#39;这里的要求......
Composer支持多种类加载方法。一个重要的实现PSR4
规范。 Symfony
和Respect
正在使用PSR4
。您可以查看他们的composer.json
文件或生成的vendor/composer/autoload_psr4.php
文件来验证它。
Fat-Free Framework允许Composer 自动加载其lib/base.php
文件。这一点很重要,因为包括base.php
两次会抛出PHP Fatal error: Cannot declare class Cache, because the name is already in use
。解决方案是让Composer完成工作并取而代之的是$f3 = Base::instance()
。
<强>建议强>
删除vendor
文件夹并使用Composer
进行全新安装
验证代码中是否缺少(或导入)类名称空间,例如\Respect\Validation\Validator
代替Validator
答案 1 :(得分:0)