I am trying to use composer to autoload my classes in a wordpress plugin.
I wish for my models and controllers to reside within the GD namespace, however I would like to put my models and controllers into their own directories.
I am facing the error message: Fatal error: Class 'GD\ShortcodeController' not found in /.. .../src/GD/App.php on line 10
directory/file structure
plugins
gd
cache
// location for twig template cache
public
// location for plugin assets
src
controllers
ShortcodeController.php
models
App.php
templates
test.html
vendor
// location for application dependencies installed via composer
composer
autoload_namespaces.php
composer.json
{
"require": {
"twig/twig": "1.*"
},
"autoload": {
"psr-0": {
"GD": ["src/", "src/GD/", "src/GD/controllers/", "src/GD/models/"]
}
}
}
vendor/composer/autoload_namespaces.php
return array(
'Twig_' => array($vendorDir . '/twig/twig/lib'),
'GD' => array($baseDir . '/src', $baseDir . '/src/GD', $baseDir . '/src/GD/controllers', $baseDir . '/src/GD/models'),
);
GD/src/App.php
class App
{
private $plugin_dir;
private $twig;
public function init()
{
$shortcodes = new ShortcodeController;
add_shortcode( 'gd', [ $shortcodes , 'gd'] );
}
}
GD/src/controllers/ShortcodeController.php
<?php namespace GD;
class ShortcodeController
{
// STUFF IN HERE
}
Should i be using autoload classmap instead of psr-0? How does composer deal with namespaced classes when using classmap?