Load namespaces with composer as psr-0 libraries

2.6k Views Asked by At

I am using Silex (and so, composer) for any web application project.

I would like to autoload 4 entities and forms:

  1. FSB\MyProject\Entity\Booking --> /src/FSB/MyProject/Entity/Booking.php
  2. FSB\MyProject\Form\BookingType --> /src/FSB/MyProject/Form/BookingType.php
  3. FSB\MyProject\Entity\Contact --> /src/FSB/MyProject/Entity/Contact.php
  4. FSB\MyProject\Form\ContactType --> /src/FSB/MyProject/Form/ContactType.php

The composer.json is defined with a psr-0 array:

{
    "require": {
        "silex/silex": "~1.0",
        [...]
    },
    "autoload": {
        "psr-0": {
            "FSB": "src/"
        }
    }
}

Then in my index.php file I just call :

use FSB\MyProject\Entity\Contact;
use FSB\MyProject\Form\ContactType;
use FSB\MyProject\Entity\Booking;
use FSB\MyProject\Form\BookingType;

$contact = new Contact();

Everything works fine in my dev-environment, MAMP, php 5.4

But it breaks on my production server, Apache2 on Ubuntu with PHP 5.4 too

"PHP Fatal error: Class 'FSB\MyProject\Entity\Contact' not found in /[...]/index.php"

I've tried many ways to load my entities like :

{
    "require": {
        "silex/silex": "~1.0",
        [...]
    },
    "autoload": {
        "psr-0": {
            "FSB/Palmeraie": "src/",
        }
    }
}

Or even:

{
    "require": {
        "silex/silex": "~1.0",
        [...]
    },
    "autoload": {
        "psr-0": {
            "FSB\\Palmeraie\\Entity": "src/",
            "FSB\\Palmeraie\\Form": "src/"
        }
    }
}

--> Several ways are working in my dev-environment ; none on my production environment...

Did I miss something ?

2

There are 2 best solutions below

5
On BEST ANSWER

Check your file/directory names for correct capitalization, file names on OS X are case insensitive opposed to those on Linux/Unix file systems.

0
On

Execute "composer update" and it will work again.