0

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?

Lucas
  • 685
  • 4
  • 19
  • 2
    Before calling `$TBS->Plugin()` you can add `$ok = class_exists('clsOpenTBS', true);` This should invoke your custom autoloader. OpenTBS is currently version 1.10.0, but the next version will provide a clean solution for this problem. – Skrol29 Sep 02 '20 at 12:21
  • Yea I came up with a similar "hack": I just looked at the plugin code and am now creating a throw away instance of a class from the plugin code to force the loading of the script. I just put `new clsOpenTBS;` before the `$TBS->Plugin()` call. – Lucas Sep 02 '20 at 13:13

1 Answers1

3
<?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
waithira
  • 310
  • 1
  • 2
  • 12