0

Is there a way I can include files same folder automatically?

I see lot of code in application I am working on that has this kind of code. Specific example is swift mailer (if anyone is aware of that). But this can also be used as general example:

 Folder: vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport

 |
 --- File MailInvoker.php
                 |
                 --- interface Swift_Transport_MailInvoker
 |
 --- File SimpleMailInvoker.php
                 |
                 --- class Swift_Transport_SimpleMailInvoker implements Swift_Transport_MailInvoker

I am unable to figure out without any specific include statements or without any mention in any of autoload files, how class can use interface.

Thanks in advance for help!

  • 1
    Is this in a framework project? With that folder structure, I assume it's probably using the composer autoloader. – Don't Panic Nov 13 '17 at 16:33

2 Answers2

0

You can load classes automatic. See http://php.net/manual/en/language.oop5.autoload.php for the offical documentation.

Basically you create a function to load classes and register it with spl_autoload_register('autoloader_function_name'); That function will be executed when the class isn't already included.

You can find the swift autoloader in the file swiftmailer/lib/classes/Swift.php as public static function autoload($class)

Here, on stackoverflow, there are a many examples too: Best Way To Autoload Classes In PHP

C. D. Miksche
  • 88
  • 1
  • 7
0

Composer is the best tool to autoload files, all modern frameworks use composer. To autoload a folder files you should inialize autoloading system and then follow some standards in file naming. You can read this tutorial for more information about composer

T. AKROUT
  • 1,719
  • 8
  • 18