autoloading nested classes with composer

805 views Asked by At

I have created a very basic validator class.

My base code is in a my src/ folder, which gets autoloader with

"kevdotbadger\\Validator\\": "src/"

this works fine, so that when I instantiate a new "kevdotbadger\Validator\ Validator is gives me src/Validator.php

My Validator.php class then loads a bunch of sub-classes in my src/Rules directory. These are magically loaded by using the __call, so ->between() should look for src/Rules/between.php. However, for some reason it won't usual load despite it being setup in my composer.json file.

My whole codebase is available at https://github.com/kevdotbadger/validator/

Have I setup my namespace correctly? I think the problem might be with php version 5.3, however I need to use version 5.3.

Thanks.

1

There are 1 answers

0
Tzook Bar Noy On BEST ANSWER

Well you need to keep the guidelines of psr-4 as you are using it to autoload.

  • change the folder name "rules" to "Rules"
  • Uppercase all your file names of classes like:

     between.php  -->  Between.php
    

that should do the job