Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Autoloader from Development to Production fails

Hi everybody, my team has just discovered that Autoloader works in different ways on different OS. Specifically we are developing locally on Mac OSX and Windows machines using MAMP and XAMPP.

At first I've started developing on Mac OSX without problems, later we have discovered that on Windows the Autoloader needs lowercase filenames so we have renamed every file and directory and it worked like a charm.

Now we have released the first version on our CentOS 7.1 beta server and we have sadly discovered that Autoloader is looking for CamelCase filenames.

I've found other people talking about this problem but seems that there is no cross-OS solution, if we rename each file and directory Windows developers won't be able to work locally using XAMPP.

We are thinking about extending Autoloader class forcing lowercase discovery as follows:

use Phalcon\Loader;

class YPJLoader extends Loader {
    public function autoLoad($className) { parent::autoLoad(strtolower($className)); }
}

We have tried this but doesn't works, Autoloader can't find Class. Strange fact, if we use strtoupper it works under Windows. Anyone knows why? Any advice?

One more thing: I'm beginning to think that we should move from MAMP/XAMPP/LAMP to Vagrant and leave behind this problem, any advice? Pro & Cons?

Thank you in advance, any help would be appreciated

Carlo

Maybe this is a little bit out of topic, but I also found some strange issues regarding camelCase, lowercase in relation's alias. Maybe this is caused by zephir internal strtolower or strtoupper?

https://github.com/phalcon/cphalcon/issues/10886
https://github.com/phalcon/cphalcon/issues/10800

I hope @Phalcon found the solution

OSX and Windows have case insensitive filesystems, meanwhile linux does not. So if a single character does have a different case it will make the autoloader not able to load it.



454

Thank you for the answer so, what is the best practice for developing on local machine and then release on linux server?



454
Accepted
answer

Thank you everybody, we have managed to solve the problem extending Loader class as I've said in original post, we have made a mistake integrating the workaround but now it works!

For everyone with the same problem, this is the class:

<?php
use Phalcon\Loader;

class InsensitiveLoader extends Loader {
      public function autoload($className) { parent::autoLoad(strtolower($className)); }
}

And you can use it in bootstrap file or module.php in place of Phalcon\Loader:

$loader = new InsensitiveLoader();

$loader->registerDirs( array(
    __DIR__ . '/tools/',
    __DIR__ . '/components/'
) );
$loader->registerNamespaces( array(
    'Core\Tools'      => __DIR__ . '/tools/',
    'Core\Components' => __DIR__ . '/components/'
) );

$loader->register();