Use a Composer-based PHP plugin in Kirby

I’ve never used Composer, and I’m having a bit of trouble wrapping my head around what I need to do here.

I want to use a PHP package that’s only available as a Composer package (and I had a hard time figuring out if it’s even possible to extract it from the Composer wrappings, as I don’t know what I’m doing). So how would I go about getting this into my kirby site so I can take advantage of it?

The plugin in question is here, if that helps or makes a difference: https://github.com/joyent/php-manta

  1. Get the latest snapshot of the composer.phar or install it on your machine. If you get the phar, put it in the directory of your Kirby site and replace composer with php composer.phar in the following command.

  2. Run composer require joyent/php-manta in the directory of your Kirby site. Composer will create the composer.json and composer.lock files as well as a vendor directory where all source files are downloaded to.

  3. Add this below the first require in your index.php:

    require 'vendor'.DS.'autoload.php';
    
  4. Make sure to upload the vendor directory to your server when you deploy the site.

Now you can start using the package like this:

<?php

use Joyent\Manta\MantaClient;

// ...
$client = new MantaClient();
// ...

Excellent. Thanks. Hopefully I’ll have a chance to try this later today.

Where do I actually use that code? Directly in whatever template I need it (or snippet, etc.)?

That depends on what you are planning to do with code. If you want to create a plugin using that library, you would do the stuff within your plugins directory. You can also just build a wrapper for the package, so that you can easily use it anywhere in your project.

I think I’ll actually need to add it into my trigger that I already have running when an mp3 file is uploaded. I should be able to figure that out, I hope.