This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I just download a library: PHPCrawl. I am wondering what is the right way to import the library in OctoberCMS framework. Anyone can help me?
Thanks.
If you can install phpcrawl with composer (looks like you can: https://packagist.org/packages/cuab/phpcrawl) , do it with composer.json (see how https://github.com/Shahiem/CKeditor-plugin did it).
When you import a package with composer.json, remember to add vendor to your .gitignore. The build bot on the marketplace will automatically composer install
when you release updates and for non marketplace plugins, the vendor dir doesn't need to be in your git repo anyway :)
Last updated
Thanks, Flynsarmy, but one question, is there a solution for running composer install
automatically, after deploying, if my plugin is not marketplace-plugin?
Last updated
Here is my solution:
#!/bin/bash
# these are actions that need to be done after boot, not after build. This is because we don't have DB access in build
# because env vars aren't available yet.
APPDIR="/app"
#run composer and log to syslog.
cd /app
COMPOSER_HOME="/root" composer install --no-dev --prefer-dist --optimize-autoloader --no-interaction
## run composer in each plugin directory
# http://stackoverflow.com/questions/3769137/use-git-log-command-in-another-folder
# http://briancoyner.github.io/blog/2013/06/05/git-sparse-checkout/
# note: https://github.com/dokku-alt/dokku-alt/issues/74
for d in $APPDIR/plugins/*/*/ ; do
if [ -f "${d}composer.json" ]; then
echo "--------------------------------------"
echo "Running composer for $d"
echo "--------------------------------------"
cd $d
COMPOSER_HOME="/root" composer install --no-dev --prefer-dist --optimize-autoloader --no-interaction
fi
done
Just iterates through the folders and runs composer install
Thanks! It's very simple and powerful solution. Also possible to run this code like a git-hook, I think.
My sites are deployed with docker (dokku-alt: https://github.com/dokku-alt/dokku-alt) so I have that script run when the site/server is built, it works very well. That is why I have the COMPOSER_HOME env var in there. You might not need that.
Hey If I have 3party library payment library How should I import it? Should I put it into vendor folder? or simly make include(file)?
Thanks
@AlexeiKo, you have to import this library by adding library name and version to your plugin composer.json. Check the readme file of this library. If this library do not provide composer installation, you can just include library in the plugin file, but it's not modern way.
1-9 of 9