namespaces and autoloading PHPMailer

178 views
Skip to first unread message

Boyd Pearson

unread,
Oct 13, 2017, 10:55:15 PM10/13/17
to Fat-Free Framework
this is probably my lack of experience with name spaces but ..

my autoloader looks in /lib for the libraries but

PHPMailer uses

namespace PHPMailer\PHPMailer;

which means i have to put it in a directory /lib/PHPMailer/PHPMailer/PHPMailer.php

 and the then call it with

$mail = new PHPMailer\PHPMailer\PHPMailer;

Which is a lot of extra "PHPMailer" strings and an empty directory to satisfy its names space

is there a way to have the file in /lib/PHPMailer/PHPMailer.php

and\or use

$mail = new PHPMailer;


Rayne

unread,
Oct 14, 2017, 5:27:02 AM10/14/17
to f3-fra...@googlegroups.com
If this is the official namespace there is no option to shorten it except from aliasing the namespace with the `use` statements (which even would require more characters):

use PHPMailer\PHPMailer\PHPMailer as Mailer;

$mail
= new Mailer;

F3's autoloader (AUTOLOAD) supports only "full qualified namespace to directory" mappings. The autoloader of Composer supports "shortened namespace to directory" mappings (Example). It could be possible that there are more autoloader libraries supporting this feature.

Boyd Pearson

unread,
Oct 15, 2017, 12:41:10 AM10/15/17
to Fat-Free Framework
thanks that's what i expected but its good to have a 2nd pair of eyes
Reply all
Reply to author
Forward
0 new messages