0

I'm trying to split up a long file into smaller chunks, so I created an src folder, and am trying to reference it from the main Extension.php file (which loads and works fine, by the way).

So, I add the src folder to the psr-4 autoloading array:

"psr-4": {
        "Bolt\\Extension\\AndyJessop\\SurveyMonkey\\": [
            "",
            "src/"
        ]
    }

I create the Test.php file inside src:

<?php

namespace Bolt\Extension\AndyJessop\SurveyMonkey;

class Test
{
    public function test() {
        return 'success';
    }
}

In the Extension.php file (which is under the same namespace), I have this function that is called:

use Bolt\Extension\AndyJessop\SurveyMonkey\Test;

public function testing(){
    return Test::test();
}

But I get the following error:

Error: Class 'Bolt\Extension\AndyJessop\SurveyMonkey\Test' not found
File: extensions/local/andyjessop/surveymonkey/Extension.php
babbaggeii
  • 7,577
  • 20
  • 64
  • 118

1 Answers1

2

First, either run composer update or composer dump-autoload to generate the autoload system.

Next, make sure that you include (require_once is preferable) the autoload at the top of your entrypoint(s):

require_once __DIR__ . '/path/to/vendor/autoload.php';

N.B.: if you have PHP 5.3 or lower, replace __DIR__ with dirname(__FILE__).

T0xicCode
  • 4,583
  • 2
  • 37
  • 50