I'm kinda new to Autoload Composer, but hopefully I got the composer concept right: Basically you hand over some basic information (composer.json) and the composer then generates the classes which you have to include and then do the work you wanted. Right?
Well, after hours of trying to setup an Autoload Composer, that's my result:
Composer.json:
"name": "lordrazen/dpgenerator",
"description": "Page to generate Datapacks out of Rawfiles",
"type": "project",
"license": "GPL",
"authors": [
{
"name": "LordRazen",
"email": "[email protected]"
}
],
"minimum-stability": "dev",
"require": {},
"autoload": {
"psr-4": {"Inc\\": "inc/"}
}
}
Class "Test.php" inside the folder "Inc"
namespace Inc;
class Test {
}
Index.php
if (file_exists(dirname(__FILE__) . '/vendor/autoload.php')) {
require_once (dirname(__FILE__) . '/vendor/autoload.php');
}
$test = new Test();
I also went to the projects directory in the console and hit "composer update" command.
Well... it still doesnt work:
Fatal error: Uncaught Error: Class 'Test' not found in [...]/index.php:34 Stack trace: #0 {main} thrown in [...]/index.php on line 34
What's my mistake here?
Test.php
insideInc
or you define in autoloader the namespaceInc\` for the folder
inc`. Try to put it in uppercase. – GrenierJTest
in your project, without any namespace, or did you import that namespace in yourIndex.php
? – Nico Haase