I have a very simple class in an external file, and I’m trying to use the class in my composer (the following is very simplified). The file defining the class /app/View/Classes/test.php:
<?php
class test {
...
function data {
return "My data";
}
}
In the composer,
<?php
namespace App\View\Composer;
require_once(get_template_directory() . '/app/View/Classes/test.php');
use Roots\Acorn\View\Composer;
class Events extends Composer {
public function with() {
return [
'test' => $this->get_test(),
];
}
public function get_test(){
return class_exists ('test');
}
In the associated blade, {{$test}} return true, so the class exists. However, in the composer function, if I try to instantiate the class with $test = new test(); I get a server error. How can I use a class defined in an external file within a Composer?