我使用composer将外部库添加到我的项目中 - 包括Predis。
出于某种原因,可能并没有生成Predis,我总是收到:
Class 'Predis\Autoloader' not found
所以我潜入了作曲家加载文件并找到一些奇怪的东西如下:
这是我的composer.json:
{
"require": {
"facebook/php-sdk": "@stable",
"everyman/neo4jphp": "dev-master",
"predis/predis": "1.1.*@dev",
"aws/aws-sdk-php": "2.*"
},
"autoload": {
"psr-0": {
"PicoCore\\": "",
"PicoCore\\Authentication\\" : "PicoCore/authentication",
"PicoCore\\Aws\\" : "PicoCore/aws",
"PicoCore\\Cache\\" : "PicoCore/cache",
"PicoCore\\Database\\" : "PicoCore/database",
"PicoCore\\Facebook\\" : "PicoCore/facebook",
"PicoCore\\Objects\\" : "PicoCore/objects",
"PicoCore\\Rest\\" : "PicoCore/rest",
"PicoCore\\Configuration\\" : "PicoCore/configuration",
"PicoCore\\Configuration\\Api\\" : "PicoCore/configuration/api",
"PicoCore\\Scripts\\" : "PicoCore/scripts",
"PicoCore\\Times" : "PicoCore/times"
}
}
}
现在,我想知道为Predis生成的命名空间是怎么样的,所以我检查了composer文件夹里面的autoload_par4.php,这就是它的样子:
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Symfony\\Component\\EventDispatcher\\' => array($vendorDir . '/symfony/event-dispatcher'),
'Predis\\' => array($vendorDir . '/predis/predis/PicoCore'),
);
现在,如果您注意到您将看到Predis名称空间路径为/predis/predis/PicoCore
(PicoCore是我的应用程序命名空间)
/predis/predis/src
当我无动于衷地改变它 - 它工作正常,但问题是每当我更新作曲家时,它都会再次发生..
任何想法为什么或从哪里开始路径?为什么它会添加我的项目名称?
顺便说一句,我查看了predis的composer.json并更改了它,现在看起来如下:
{
"name": "predis/predis",
"type": "library",
"description": "Flexible and feature-complete PHP client library for Redis",
"keywords": ["nosql", "redis", "predis"],
"homepage": "http://github.com/nrk/predis",
"license": "MIT",
"support": {
"issues": "https://github.com/nrk/predis/issues"
},
"authors": [
{
"name": "Daniele Alessandri",
"email": "suppakilla@gmail.com",
"homepage": "http://clorophilla.net"
}
],
"require": {
"php": ">=5.3.9"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"suggest": {
"ext-phpiredis": "Allows faster serialization and deserialization of the Redis protocol",
"ext-curl": "Allows access to Webdis when paired with phpiredis"
},
"autoload": {
"psr-4": {"Predis\\": "src/"}
},
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
}
}
}
答案 0 :(得分:0)
问题是我添加了依赖:
&#34; predis / predis&#34;:&#34; 1.1。* @ dev&#34;
我需要的时候:
&#34; predis / predis&#34;:&#34; 1.0.1&#34;