Skip to content
Advertisement

Use composer’s autoload to load OpenTBS plugin for tinybutstrong

I am using tinybutstrong and it’s opentbs plugin. Until now I did use an explicit require of the two source files for that but I want to switch to composer with autoloading. So I want to go from this

<?php
include 'tbs_class.php';
include 'tbs_plugin_opentbs.php';
$TBS = new clsTinyButStrong;
$TBS->Plugin(TBS_INSTALL,  OPENTBS_PLUGIN);

to this (or something similar)

<?php
include 'vendor/autoload.php';
$TBS = new clsTinyButStrong;
$TBS->Plugin(TBS_INSTALL,  OPENTBS_PLUGIN);

but that fails with the error TinyButStrong Error with plug-in 'OPENTBS_PLUGIN': no class named 'OPENTBS_PLUGIN' is found, and no function named 'tbspi_OPENTBS_PLUGIN_OnInstall' is found. So it seems composer can not load the relevant file just based on the constant’s name.

How can I get composer’s autoload to pick up the plugin file?

Advertisement

Answer

<?php
//load composer's autoloader
require 'vendor/autoload.php';

 //// Initialize the TBS instance
$TBS = new clsTinyButStrong; // new instance of TBS
$ok = class_exists('clsOpenTBS', true);
$TBS->Plugin(TBS_INSTALL,  OPENTBS_PLUGIN);// load the OpenTBS plugin
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement