Please help me to find a way to add new php library to Magneto2. In Magetno1 I add it to lib folder and then I could use it in my custom modules... But in Magento2 I am trying to do the same but no go... Anybody already try to do that or?
1 Answer
the easiest way would be to install it via composer.
depends on the library. It has to have a composer.json with autoloading settings defined.
if the library has a valid composer.json you can install it with the following command in your magento2 root:
composer require vendor/name:version
with vendor/name = the name that is defined in the composer.json
-
Here is the trick lib doesn't have valid composer.json... But I can make it no problem... I thought that I can just copy it to lib/internal folder an do some magic in main composer.json file to do mapping like for Magento/Framework or something like that ... Thanks for the answer I will try to do that. Commented Feb 7, 2016 at 23:20
-
magento itself does only autoload its own framework from the lib/internal directory: github.com/magento/magento2/blob/develop/composer.json#L219. So the library has to take care of the autoloading itself and then, with a valid composer.json autoloading, can easily be installed in the vendor dir Commented Feb 7, 2016 at 23:26
-
Hey man, just want to say thank you... Lot of issues were here for this lib... using it on php7 don't work... And you were right about composer, just I needed to add custom autoloader. Now it works perfectly. Commented Feb 8, 2016 at 19:10
-
@DavidVerholen I have use Third party Libs (DOMPDF) and setup it like lib/internal and call to my helper but getting error to Source class *** generation does not exist . Means Libs file's internal class is not create into generation so getting error. Please let me know proper solution. Commented Aug 25, 2017 at 4:25
-
1For future readers.. In magento 2.2 adding library code to lib/internal doesn't work: github.com/magento/magento2/issues/10985 Commented Sep 28, 2017 at 17:06