Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composer is not loading my own psr-0 files

I can't seem to get composer to work with my own classes/files using the psr-0 autoload mechanism. Can anyone please shed some light as to why the below isn't working?

I'm getting the following output in my error log:

PHP Fatal error: Class 'TestdirTest1' not found in /home/webroot/bitlama/index.php on line 5

It does work If I uncomment the explicit require statement (index.php:2).

And if anybody is wondering - yes I have run composer install in the form of: 'php ../composer.phar install'.

This is my directory structure:

├── composer.json
├── index.php
├── testspacedir
│   └── Testdir
│       └── test1.php
└── vendor
    ├── autoload.php
    └── composer
        ├── autoload_classmap.php
        ├── autoload_namespaces.php
        ├── autoload_real.php
        └── ClassLoader.php

composer.json:

{
    "autoload": {
        "psr-0": { "Testdir\\": "testspacedir/"}
    }
}

test1.php:

<?php

namespace Testdir;

class Test1 {

    public function __construct()
    {
        echo "Woohoo Test1";
    }

}

index.php:

<?php
require 'vendor/autoload.php';
//require 'testspacedir/Testdir/test1.php';

$test1 = new Testdir\Test1();

vendor/autoload.php:

<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer' . '/autoload_real.php';

return ComposerAutoloaderInit7b4760e0f7ca9d6454dd2f098c374ba4::getLoader();
like image 826
Chris Stryczynski Avatar asked Dec 07 '13 21:12

Chris Stryczynski


1 Answers

My class file was named as test1.php instead of the required PSR-0 naming convention of Test1.php.

like image 76
Chris Stryczynski Avatar answered Sep 30 '22 09:09

Chris Stryczynski