I'm struggling to work out how to correctly build and autoload my first composer package. I understand that if I follow the PSR-0 naming convention, autoloading should "just work". I am trying to set up with:
- vendor: Programster
- package name: CoreLibs
I have managed to debug a project that includes the package to the point where I am outputting the search path by putting a print in the findFileWithExtension()
function of the ClassLoader.php
file
/home/stuart/Desktop/test-project/vendor/Programster/CoreLibs/Programster/Programster/CoreLibs/Core.php
I know that the file is actually located at:
/home/stuart/Desktop/test-project/vendor/Programster/CoreLibs/Core.php
My Package's composer.json file:
{
"name": "Programster/CoreLibs",
"type": "library",
"description": "Core libraries for PHP 5.3+",
"keywords": ["core","library"],
"homepage": "http://svn.yadda-yadda.com/php/core-libs",
"license": "none",
"authors": [
{
"name": "xxxx",
"email": "my.email@email.com",
"homepage": "http://mywebsite.com/",
"role": "Developer"
}
],
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-0": {
"Programster": "Programster"
}
}
}
The following is a tiny script in a project that includes the package to test if is working:
<?php
require_once(__DIR__ . '/../vendor/autoload.php');
$loader = new \Composer\Autoload\ClassLoader();
$loader->register();
use \Programster\CoreLibs as programster;
programster\Core::println("hello world");
The project's composer.json file to include the package:
{
"repositories": [ { "type": "composer", "url": "http://satis.mydomain.com/" } ],
"require": {
"Programster/CoreLibs": "dev-trunk"
}
}
Is my package's config wrong, or do I really need to create Programster/CoreLibs/ subdirectories within the CoreLibs repository source code?