We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

[SOLVED] registerNamespaces lacks recursive autoloading in Centos (case in/sensitive)

In backend/Modue.php in OSX using php 5.6.23 I have registered a namepace:

        $loader->registerNamespaces([
                'Multiple\\Backend\\Forms' => SITE_ROOT . 'apps/backend/forms'
         ]);

In the backend controller I can:

    $form = new \Multiple\Backend\Forms\Admin\Member();
    $form = new \Multiple\Backend\Forms\Settings\Members();

However in Centos php 5.6.24 the classes cannot be found and I have to declare the follwoing to reach the forms:

        $loader->registerNamespaces([
                'Multiple\\Backend\\Forms' => SITE_ROOT . 'apps/backend/forms',
                'Multiple\\Backend\\Forms\\Admin' => SITE_ROOT . 'apps/backend/forms/news',
                'Multiple\\Backend\\Forms\\Settings' => SITE_ROOT . 'apps/backend/forms/forum'
        ]);

Can anyone comment on what is happening here? Both phalcon versions are 3.0.0 and were built in their respective environments.

What is the exact file name of the form behind \Multiple\Backend\Forms\Admin\Member? Member.php?



47.7k
edited Sep '16

Same file name yes.

so in Member.php

namespace Multiple\Backend\Forms\Admin;

class Member extends \Phalcon\Forms\Form
{
...
}

In my osx environment I do not have to explicitly declare 'Multiple\Backend\Forms\Admin' namespace. 'Multiple\Backend\Forms' suffices in osx.

What is the exact file name of the form behind \Multiple\Backend\Forms\Admin\Member? Member.php?



189
Accepted
answer

Because of OSX is'nt case sensitive but centos is. change apps/backend/forms/admin to apps/backend/forms/Admin

@bestirani2 that's not true, both GNU/Linux and OSX are case sensitive systems. Only M$ Windows is case insensitive.



47.7k

Hi @bestirani2 and @stamster,

Sorry for my delay.

I have tested this in CentOS Linux release 7.2.1511 (Core).

When I capitalize the folder name to match a namespace then autoloading automatically recurses from the root namespace.

I have asserted that Phalcon in Centos is case sensitive when recursing from root namespaces.

Is this a bug in Phalcons autoloader?

No, it's not a bug, but a 'feature'. Since native PHP spl_autoload_register() sux big time with it's total lack of any flexibility for file names / namespaces naming options, this was the only possible approach in order to provide some sort of flexibility. So if you named your namespace baychae you need to create directory structure with exactly the same name (lowercased). If you have usedBaychae, it needs to follow that Camel case as well on the filesystem etc.

One more time: both Linux and OSX are case sensitive systems.

osx is dependent on drive format. https://www.quora.com/Why-does-OS-X-choose-to-have-a-case-insensitive-file-system-instead-of-a-case-sensitive-one You must use same folder and namespace, if you want it works on all os.



47.7k

Then what is the mechanism in place where case insensitive recursive autoloading is occurring in osx and not in centos?

This is the behaviour I am observing.

One more time: both Linux and OSX are case sensitive systems.



47.7k

I just checked in Disk Utility in osx.

It appears in the file system info for my Untitled 1 Volume as:

Is case-sensitive                   No

This is my own fault for choosing the case insenstive version of HFS+ when formatting the disk.

osx is dependent on drive format. https://www.quora.com/Why-does-OS-X-choose-to-have-a-case-insensitive-file-system-instead-of-a-case-sensitive-one You must use same folder and namespace, if you want it works on all os.

That's a supprise! Mac has configurable filesystem :S @bestirani2 good to know that.

To conclude: one more reason NOT to develop on Windows || OSX :)



47.7k

https://en.wikipedia.org/wiki/HFS_Plus

Additionally, the core of the filesystem uses case-insensitive Unicode strings, which led Linus Torvalds to state "HFS+ is probably the worst file-system ever."

That's a supprise! Mac has configurable filesystem :S @bestirani2 good to know that.

To conclude: one more reason NOT to develop on Windows || OSX :)

I just have checked on our office iMac mini. diskutil info /

I don't see 'sensitive' flag anywhere, type is hfs.



47.7k

I am using disk utility in osx 10.11.6.

How about when you enter this in console:

diskutil info /

You should get an entry similar to this :

   File System Personality:  Journaled HFS+
   Type (Bundle):            hfs
   Name (User Visible):      Mac OS Extended (Journaled)

If mine was case sensitive it should be something like:

   File System Personality:  Case-sensitive Journaled HFS
   Type (Bundle):            hfs
   Name (User Visible):      Mac OS Extended (Case-sensitive, Journaled)

I just have checked on our office iMac mini. diskutil info /

I don't see 'sensitive' flag anywhere, type is hfs.

edited Sep '16

Yes, that's the command I ran, see my previous post. There's no mention of sensitive.

And it's really easy to test, I just created file and tried to access it with CAPITALS. And guess what - it is case insensitive after all! But I just don't see it in the output of diskutil info. Crazy shit.



47.7k
edited Sep '16

lol! That made my day! (Crazy shit)

What version of osx ?

Actually don't answer. You've answered.

Yes, that's the command I ran, see my previous post. There's no mention of sensitive.

And it's really easy to test, I just created file and tried to access it with CAPITALS. And guess what - it is case insensitive after all! But I just don't see it in the output of diskutil info. Crazy shit.

Device Identifier:        disk1
   Device Node:              /dev/disk1
   Part of Whole:            disk1
   Device / Media Name:      Macintosh HD

   Volume Name:              Macintosh HD

   Mounted:                  Yes
   Mount Point:              /

   File System Personality:  Journaled HFS+
   Type (Bundle):            hfs
   Name (User Visible):      Mac OS Extended (Journaled)
   Journal:                  Journal size 81920 KB at offset 0x1b215000
   Owners:                   Enabled

   Content (IOContent):      Apple_HFS
   OS Can Be Installed:      Yes
   Recovery Disk:            disk0s3
   Media Type:               Generic
   Protocol:                 SATA
   SMART Status:             Not Supported
   Volume UUID:              xxxxxxxxxxxxxxxxxxxxxxxxxxx
   Disk / Partition UUID:    xxxxxxxxxxxxxxxxxxxxxxxxxxx

   Total Size:               999.0 GB (998982549504 Bytes) (exactly 1951137792 512-Byte-Units)
   Volume Free Space:        897.0 GB (896963489792 Bytes) (exactly 1751881816 512-Byte-Units)
   Device Block Size:        512 Bytes
   Allocation Block Size:    4096 Bytes

   Read-Only Media:          No
   Read-Only Volume:         No
   Ejectable:                No

   Whole:                    Yes
   Internal:                 Yes
   Solid State:              No
   OS 9 Drivers:             No
   Low Level Format:         Not supported

   This disk is a Core Storage Logical Volume (LV).  Core Storage Information:
   LV UUID:                  xxxxxxxxxxxxxxxxxxxxxxxxxxx
   LVF UUID:                 xxxxxxxxxxxxxxxxxxxxxxxxxxx
   LVG UUID:                 xxxxxxxxxxxxxxxxxxxxxxxxxxx
   Fusion Drive:             No
   Encrypted:                No