douxiaochun4964 2015-05-31 11:13
浏览 94
已采纳

Predis Autoloader无法加载

I use composer to add external libraries to my project - including Predis.

For some reason Predis is not being generated probably and I always receive:

Class 'Predis\Autoloader' not found

So I dived into the composer loading files and find some weird things as follow:

This is my 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"
        }
    }
}

Now, I wanted to see how the generated namespace for Predis looks like so I checked the autoload_par4.php inside the composer folder and this is how it looks:

<?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'),
);

Now, if you'll notice you will see that the Predis namespace path is /predis/predis/PicoCore

(PicoCore is my application namespace) when it supposed to be

/predis/predis/src

When I manunally change it - it works fine, but the problem is that whenever I update the composer, it does it again..

Any ideas why or where does it take the path from and why does it add my project name?

By the way, I looked at the composer.json of predis and change it and now it looks as followed:

{
    "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"
        }
    }
}
  • 写回答

1条回答 默认 最新

  • dongqing220586 2015-05-31 12:22
    关注

    The problem was that I added the dependency of:

    "predis/predis": "1.1.*@dev"

    While I needed:

    "predis/predis": "1.0.1"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?