Composer Autoload is not working

1

Good evening (or any shift if you are from the future).

Well, my problem is objective, but so far without a solution.

I developed an entire project on my windows PC using XAMPP.

As the system has several classes I'm using autoload of the composer as follows:

    "autoload": {
    "psr-4": {
            "persistencia\": "libs/persistencia/",
            "sistema\": "libs/sistema/"
    }
}

Folder structure:

libs
├── persistencia
│   ├── categoriaproduto.php
│   ├── cliente.php
│   ├── contrato.php
│   ├── funcionario.php
│   ├── itemcontrato.php
│   ├── mensageiro.php
│   ├── modelodados.php
│   ├── persistenciaexception.php
│   ├── persistencia.php
│   ├── produto.php
│   ├── relatorio.php
│   └── tipoacesso.php
└── sistema
    ├── logger.php
    ├── sistemaexception.php
    └── sistema.php

Running the system in XAMPP here on my Win was all ok. The problem occurs when I prepared a ubuntu server, apache, mysql, php7.2.

I installed the composer, downloaded the files from my site I ran the "composer install" and the result was:

  

Uncaught Error: Class 'System \ System' not found in   /var/www/html/api.php:18

The code in question is this:

<?php
require_once('vendor/autoload.php');

require_once('../config.php');

if(Config::REQUISITAR_LOGIN) // Se for nescesário estar logado para usar o sistema
   testarLogin(); //Impedindo acesso de usuários não logados
header('Content-Type: application/json');

if(Config::CORS) //Checando se deve ou não habilitar Cross Origin
   header("Access-Control-Allow-Origin: *");
if(!Config::EXIBIR_ERROS) {// Impedindo ou não a exibição de erros
   error_reporting(0);
   ini_set('display_errors', 0);
}

use sistema\Sistema;

try {
  $sistema = new Sistema; /*ESSA É A LINHA 18 QUE DEVIA FUNCIONAR*/
} catch(Exception $e) {

echo '{"status": "falha", "erro": "'.$e->getMessage().'"}';

exit(0); // A API não pode funcionar sem o sistema
}

The problem should not be in how I wrote the composer, because it was working until I changed the platform.

In the end, I did not find answers that could help me, so thanks to those who volunteer.

    
asked by anonymous 19.06.2018 / 02:17

1 answer

1

The problem is that the Windows file system is case incentive and Ubuntu is case sentitive .

What does this mean? In Windows use Sistema\Sistema it works with all uppercase and lowercase files ( libs/sistema/sistema.php , libs/sistema/Sistema.php , libs/Sistema/sistema.php , libs/SiStEmA/SiStEmA.php ).

In Linux, your use has to be exactly the same, use Sistema\Sistema will only load the file libs/Sistema/Sistema.php

To solve this, regardless of system, adopt camel case for everything:

"psr-4": {
        "Persistencia\": "libs/Persistencia/",
        "Sistema\": "libs/Sistema/"
}

The same idea in filenames and folders.

    
19.06.2018 / 03:50