0

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"
        }
    }
}
Asaf Nevo
  • 11,338
  • 23
  • 79
  • 154

1 Answers1

0

The problem was that I added the dependency of:

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

While I needed:

"predis/predis": "1.0.1"

Asaf Nevo
  • 11,338
  • 23
  • 79
  • 154