I created my first PHP library to host on GitHub.
https://github.com/TBETool/password-generator
on installing the library in my PHP Application using composer, the directory structure is like vendor
|- tbetool
|- php-password-generator
|- src
|- PasswordGenerator.php
|- README.md
|- composer.json
Content of composer.json is
{
"name": "tbetool/php-password-generator",
"type": "library",
"homepage": "http://thebornengineer.com",
],
"require": {
"php": ">=5.3.0"
}
}
content of PasswordGenerator.php
<?php
namespace TBETool;
/**
* Class PasswordGenerator
* @package TBETool
*/
class PasswordGenerator
{
// content goes here
}
and entry in my project's composer.json at /composer.json
"require": {
"php": ">=5.6",
.... other packages....
"tbetool/php-password-generator": "^1.2"
},
But when I use in my program.
<?php
use TBETool\PasswordGenerator;
class MyClass {
function myFun() {
$password = new PasswordGenerator();
}
}
But it gives error as
Class 'TBETool\PasswordGenerator' not found
Is there something error with setting up my library to be used using composer?
autoloadsection somewhere in yourcomposer.jsonfile. How do you load classes when using it locally?