Autoload of Poser is not working

Asked

Viewed 531 times

1

Good night (or any shift in case you’re from the future).

Well, my problem is objective, but so far unsolved.

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

As the system has several classes I am using autoload from 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 in my Win was all ok. The problem occurs when I have prepared a server Ubuntu, apache, mysql, php7.2.

I installed Composer, downloaded the files from my site I ran "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, as it was working until I changed the platform.

Finally, I couldn’t find any answers that could help me, so thank you to whoever volunteers.

  • The class file Sistema seems to be sistema, which is wrong for Composer. The file must have the same class name.

1 answer

1


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

What does that mean? On Windows use Sistema\Sistema works with all uppercase files as in lowercase (libs/sistema/sistema.php, libs/sistema/Sistema.php, libs/Sistema/sistema.php, libs/SiStEmA/SiStEmA.php).

Already on Linux your use has to be exactly the same, use Sistema\Sistema will only upload the file libs/Sistema/Sistema.php

To resolve this, regardless of the system, adopt Camel case for everything:

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

Same idea in file and folder names.

  • I did what you said and everything worked perfectly. Thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.