Calling any package from the vendor
directory structure within any CakePHP controller works, as the composer
set up everything correctly. For example this MCVE from https://github.com/giggsey/libphonenumber-for-php#quick-examples
$swissNumberStr = "044 668 18 00"; $phoneUtil = libphonenumberPhoneNumberUtil::getInstance(); try { $swissNumberProto = $phoneUtil->parse($swissNumberStr, "CH"); var_dump($swissNumberProto); } catch (libphonenumberNumberParseException $e) { var_dump($e); }
When I run the equal code directly in webroot/sample.php
so it fails :
Got error ‘PHP message: PHP Fatal error: Uncaught Error: Class ‘libphonenumberPhoneNumberUtil’ not found in …sample.php
My question:
What do I have to do outside the CakePHP world so I can use the packages in the vendor
directory structure?
Advertisement
Answer
I was now looking around and I saw in the vendor
directory the file autoload.php
and I gave it a try.
The solution is:
Outside the CakePHP world I have only to include this autoload.php
:
include( __DIR__ . '/../vendor/autoload.php');
Then all packages in the vendor
directory became available.