[Vtigercrm-developers] Vtiger Class Loader?
Alan Lord
alanslists at gmail.com
Tue Jun 30 12:39:27 GMT 2015
On 30/06/15 13:29, Mariusz Krzaczkowski wrote:
> Default loader has a lot of possibilities, here is a description of how
> it works. Maybe this will help you answer your questions.
Thanks.
I did need a custom Autoloader because the library I wanted to use used
a completely different declarative syntax and a namespace:
So in my vtiger Model I have (after requiring my custom Autoloader):
> $this->phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
Which my Autoloader resolves to
> modules/MyCustomModule/resources/libphonenumber/PhoneNumberUtil.php
The Autoloader itself is fairly straightforward:
> <?php
>
> namespace libphonenumber;
>
> spl_autoload_register(function ($class) {
> if (substr($class, 0, strlen(__NAMESPACE__)) != __NAMESPACE__) {
> //Only autoload libraries from this package
> return;
> }
> $path = substr(str_replace('\\', '/', $class), 14);
> $path = 'modules/LSLiveFit/resources/libphonenumber' . $path . '.php';
> //echo "My path = $path";
> if (file_exists($path)) {
> require $path;
> }
> });
Thanks again for the input.
PS: Your documentation is looking great! :-)
Al
More information about the vtigercrm-developers
mailing list