But I have absolutely no idea how I can add existing libraries to my new plugin as I only have very little experience with PHP and even less with things like composer.
Use composer, and autoload the libraries (example). Then, in the events which you do the parsing, employ the libraries (example). Composer is just a library-manager, which generates a composer.json, and populates a vendor-folder.
I copied the whole folder of the library manually into /vendor in my plugin and added the line
require DIR . ‘/vendor/autoload.php’;
at the top of my plugins PHP file (event-calendar.php).
When I reload any site now, I get the following error:
**Fatal error** : require(): Failed opening required 'xxx/user/plugins/event-calendar/vendor/autoload.php' (include_path='.:/usr/local/php72/share/php72') in **/xxx/user/plugins/event-calendar/event-calendar.php** on line **4**
I tried to, but to be honest I have no idea how to do that correctly. I’m coming from programming in C and Python and therefore I have no idea how to use the composer.
Could you help me with the correct command line command? If I type
composer
in the command line it shows me
bash: composer: command not found
Shall I use the composer.phar in /bin or must it be installed by my hosting company? How do I tell it which package it shall install and where it shall be installed.
Since we have Composer available in Grav, in /bin as you note, you can use it from there. Say you’re on the terminal, and in your plugin’s folder (eg. cd /user/grav/user/plugins/pluginname).
You can write php /user/grav/bin/composer.phar require om/icalparser to install it to this folder. That will add it to composer.json, and the contents of the library to /user/grav/user/plugins/pluginname/vendor.
In most environments, you want it installed globally like PHP, but if the host makes that difficult just using composer.phar is sufficient.
Thank you very much! That helped me and now the library was installed and seems to work as expected. I’ll proceed now and come back if I have another issue.
Hi myscha,
I’m currently thinking about doing the same as you described here:
writing a Plugin to display Events from ics File(s) .
so, short question: is your Plugin finished/working ?
and, if so, available e.g. on GitHub ?