Reputation: 3167
I created a package for Laravel 4 that worked properly when used in development in workbench but when I install it with Composer it keeps returning me the error Class 'Myvendor\Mypackage\MypackageServiceProvider' not found
.
There is a particularity with my package which is that the name of my classes sources are different from the name of my package. Usually they are the same.
vendor/
Houle/
laravel-dynamite/
src/
Fhoule/
Dynamite/
DynamiteServiceProvider.php
I know that it can work because Laravel work's this way too.
vendor/
laravel/
framework/
src/
Illuminate/
And the property PSR-0 of my package composer.json seems to be properly configured:
"name": "Houle/laravel-dynamite",
...
"require": {
"php": ">=5.3.0",
"illuminate/support": "4.0.x"
},
"autoload": {
"classmap": [
"src/migrations",
"src/controllers",
"src/models"
],
"psr-0": {
"Fhoule\\Dynamite": "src/"
}
},
...
How I created my package:
Changed composer.json configuration to install my package (from private repository)
"name": "laravel/laravel",
...
"require": {
"laravel/framework": "4.0.*",
"Houle/laravel-dynamite": "2.0.1"
},
"repositories": [{
"type": "package",
"package": {
"name": "Houle/laravel-dynamite",
"version": "2.0.1",
"source": {
"url": "[email protected]:Houle/laravel-dynamite.git",
"type": "git",
"reference": "v2.0.1"
}
}
}],
...
Added my package Service Provider to app/config/app.php:
'providers' => array(
'Fhoule\Dynamite\DynamiteServiceProvider',
)
That's where my application return the error Class 'Fhoule\Dynamite\DynamiteServiceProvider' not found
.
What could be my issue?
Upvotes: 1
Views: 3298
Reputation: 3167
I found my problem, it hadn't nothing to do with the way I named my vendor, package and classes.
It was that in my composer.json
(root of the project), I set my repository type to package
but like the Composer documentation states the type package is for packages that don't support Composer. That's why Composer wasn't updating my autoload_classmap.php
file.
So if you want to use a private repository (like at Bitbucket or GitHub) you need to set the type of the repository to git
:
{
"name": "laravel/laravel",
...
"require": {
"laravel/framework": "4.0.*",
"houle/laravel-dynamite": "dev-master"
},
"repositories": [{
"type": "git",
"url": "[email protected]:Houle/laravel-dynamite.git"
}],
...
}
Hope it helps someone.
Upvotes: 9
Reputation: 12293
The composer.json
in your package (Package found in BitBucket) needs to specify the PSR-0
Autoloading component, rather than the composer.json
file in your top-level Laravel project.
Can you show us the composer.json file for your repo in the private repository?
Upvotes: 0