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:
Created the package with Artisan.
Maked it work properly in workbench directory
Pushed to private Bitbucket repo
Installed new instance of Laravel
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": "git#bitbucket.org: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?
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": "git#bitbucket.org:Houle/laravel-dynamite.git"
}],
...
}
Hope it helps someone.
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?
Related
I am new in laravel 7. i want ask how to install github package into my laravel project.
(https://github.com/lomotech/jajahan) this package i want to install to my laravel but not instruction in this package.
If a package is missing a composer.json, you can add the following to your project's composer.json:
"repositories": [
{
"type": "package",
"package": {
"name": "lomotech/jajahan",
"version": "v2.2018.01",
"source": {
"url": "https://github.com/lomotech/jajahan",
"type": "git",
"reference": "master"
}
}
}
],
"require": {
"lomotech/jajahan": "*"
},
"autoload": {
"psr-4": {
"Lomotech\\Jajahan\\": "vendor/lomotech/jajahan/"
}
},
The autoload entry allows composer to generate the vendor classmaps so you can use the package in your code by:
use Lomotech\Jajahan\SomeClassFile;
Finally, run composer install/update.
When i use "composer require x/y" command inside my custom package all done. Getting all dependencies perfectly.
But when i try to add to laravel project from bitbucket repository, only install my package without all dependencies.
I set my private repository to laravel composer.json file
"repositories": {
"hooks": {
"type":"package",
"package": {
"name": "x/y",
"version":"1.0.2",
"source": {
"url": "https://{username}#bitbucket.org/x/y.git",
"type": "git",
"reference": "master"
}
}
}
}
My custom repository composer.json
{
"name": "x/y",
"description": "Base Api System",
"license": "MIT",
"require": {
"php": "^7.2",
"tcg/voyager": "^1.1",
"predis/predis": "1.1",
"monarobase/country-list": "^2.0"
},
"require-dev": {
},
"autoload": {
"psr-4": {
"X\\Y\\": "src/"
}
},
"minimum-stability": "dev",
"extra": {
"laravel": {
"providers": [
"X\\Y\\XYServiceProvider"
]
}
}
}
Composer require output
Using version ^1.0 for x/y
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Installing x/y (1.0.2): Cloning master from cache
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> #php artisan package:discover
Discovered Package: fideloper/proxy
Discovered Package: laravel/tinker
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
You're using package type incorrectly. This type is for non-composer packages. Composer will not even look at composer.json file in such dependency, since it assumes that this file does not exist. All relevant information about package should be in package definition in repositories setting in composer.json of main (root) application.
But in your case you have repository with complete composer package (with correct composer.json file), so you should vcs or git type:
"repositories": [
{
"type":"git",
"url": "https://{username}#bitbucket.org/x/y.git"
}
]
I've been a bit confused how Composer loads dependencies of a private repository project. I have found this link but I am not sure if this comment is referring to nested repositories or simply any dependency of a repository. To clarify my situation:
I have a private git repository that I am attempting to add as a dependency for a project.
The private git repository is also a composer project, which contains a composer.json which requires publicly available packages.
I have the following code in my composer.json for the project.
"repositories": [
{
"type": "package",
"package": {
"name": "{vendor}/{package-name}",
"version": "{arbitrary-version}",
"type": "package",
"source": {
"url": "git#github.com:{github-username}/{github-repository}.git",
"type": "git",
}
}
}
]
"require": {
"{vendor}/{package-name}": "^0.0.1"
}
So if I were to do composer update on the project after these changes it will successfully download my package from the private repository, but it does not trigger a check/update on the composer.json of the private repository - so no vendor folder is created and critical dependencies are not installed. The private repository composer.json is below:
{
"name": "{vendor}/{package-name}",
"description": "{removed}",
"type": "library",
"require": {
"illuminate/database": "^5.6",
"chumper/zipper": "1.0.x",
"symfony/debug": "^4.0",
"vlucas/phpdotenv": "^2.4"
},
}
So my question is, is what I want to do achievable with a private repository via composer and if so does anybody know where I am going wrong?
package type is for non-composer dependencies. If you use this type, Composer will not even look for composer.json file inside of defined package source, you need to include all required information about package inside of the package declaration in your project composer.json:
"repositories": [
{
"type": "package",
"package": {
"name": "{vendor}/{package-name}",
"description": "{removed}",
"type": "library",
"require": {
"illuminate/database": "^5.6",
"chumper/zipper": "1.0.x",
"symfony/debug": "^4.0",
"vlucas/phpdotenv": "^2.4"
},
"version": "{arbitrary-version}",
"source": {
"url": "git#github.com:{github-username}/{github-repository}.git",
"type": "git",
}
}
}
]
But in your case (you have a package with proper composer.json) you should use vcs type:
"repositories": [
{
"type": "git",
"url": "git#github.com:{github-username}/{github-repository}.git"
}
]
With my clean Laravel 5.3 installation, I can run composer install to install the dependent packages.
Now, I've an internal package with its own composer.json, like below:
{
"name": "bar/foo",
"description": "A package for handling foo",
"licence": "MIT",
"authors": [
{
"name": "A. Foo",
"email": "a#foo.bar"
}],
"minimum-stability": "dev",
"require": {},
"autoload": {
"psr-4": {
"Foo\\Bar\\": "packages/foo/Bar/src"
}
}
}
So I prefer to autoload from the package itself, instead of autoloading from the main composer.json.
My questions:
Running composer dumpa from packages/foo/Bar doesn't take effect for autoloading. After Generating autoload files, Laravel doesn't know namespace Foo\Bar
Is there a way to run composer dumpa for all recursive composer.jsons?
You need to add the following section to your global composer.json
"repositories": [
{
"type": "path",
"url": "packages/*/*"
}
]
You also need to add the packages to the require object in composer.json
I've successfully set up Satis on my own server and am able to pull in packages from it.
However, dependencies that are required in those private packages are constantly being cloned at their bleeding edge version instead of the specified version constraint. I think that Satis is creating a local mirror of the latest dev-version. However I do not want to have a local mirror, I just need them to install directly from Packagist.
So how do I need to setup the project / package / Satis to have the dependencies in those private packages installed from Packagist?
Thanks.
This is my Satis build file:
{
"name": "Package Server",
"homepage": "http://packages.URL",
"repositories": [
{
"type": "vcs",
"url": "git#bitbucket.org:USERNAME/REPO.git",
"options": {
"ssh2": {
"username": "USERNAME",
"pubkey_file": "PUBFILE",
"privkey_file": "PRIVATEFILE"
}
}
}
],
"require-all": true
}
And this is the composer.json file of the project requiring the private package (package has no tagged releases):
{
"name": "Test Project",
"description": "",
"require": {
"php": ">=5.4.0",
"USERNAME/REPO": "*"
},
"repositories": [
{
"type": "composer",
"url": "http://packages.URL"
}
],
"minimum-stability": "dev"
}
And this is the private package's composer.json:
{
"name": "USERNAME/RPO",
"description": "",
"require": {
"php": ">=5.4.0",
"illuminate/support": "5.0.*",
"vinkla/hashids": "~1.0"
},
"minimum-stability": "dev"
}
In your Satis config you defined "require-all": true.
This is default and selects all versions of all packages in the repository you defined.
You could try to remove "require-all": true in favor of a require section.
This means that Satis will only contain these specific packages and their versions, like so:
"require": {
"company/packageA": "*",
"company/packageB": "1.2.3",
"company/packageC": "2.0.0"
}
It's package cherry picking on Satis
So if I understand correctly I need to add the private packages that are available in the specified private repository in the require key and their own dependencies will then install from Packagist?
Add require-dependencies - this tells Satis to mirror not only the packages specified in the "require" section, but also all their dependencies.
See https://getcomposer.org/doc/articles/handling-private-packages-with-satis.md#resolving-dependencies
Is it possible to have multiple packages resided in one defined repository or does every single package need their own repository url entry in Satis?
I think it's not possible to have multiple packages in one "type": "vcs" repository.
With "type": "composer" and a cloned packagist you can store multiple repos.
Think of http://drupal-composer.org with http://packagist.drupal-composer.org/.
{
"repositories": [
{ "type": "vcs", "url": "https://github.com/somewhere/packageA" },
{ "type": "composer", "url": "https://packagist.org" }
],
"require": {
"package/packageA": "somewhere-dev",
"phpunit/phpunit": "*"
},
"require-dependencies": true
}