Reputation: 307
I need to install custom packages from github url using composer. My Laravel 5.2 based project is clean and fresh install.
The github project I need is: https://github.com/cmcdonaldca/ohShopify.php
I am still new to Laravel and composer and need help with clear steps as much as possible.
Any help?
Upvotes: 8
Views: 12746
Reputation: 2156
I could not get answer to this question anywhere, and it is no wonder. You have sort know a little about how composer works under the hood so to speak because you have to be explicit in telling composer what you want it to do. I would therefore suggest reading the documentation here well.
Next, if you have other packages already installed, look at the vendor/composer/installed.json file. This will give you an idea of what composer is looking for when it adds a namespace to the classmap.
I am developing a laravel package, I wanted to import a repo without using packagist, and I got stuck on this for while. I eventually got it work and this is what I have.
"repositories": [
{
"type": "package",
"package": {
"name": "example/package",
"version": "0.1.0",
"dist": {
"url": "https://github.org/name/package/src/master",
"type": "git"
},
"source": {
"url": "https://github.org/name/package",
"type": "git",
"reference": "master"
},
"autoload": {
"psr-4": {
"Example\\Package\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Example\\Package\\ExamplePackageProvider"
]
}
}
}
}
],
"require": {
"exmaple\package": "0.1.0"
}
Run composer install
Check /vendor/composer/installed.json and it should show...
{
"name": "exmaple\package",
"version": "0.1.0",
"version_normalized": "0.1.0.0",
"source": {
"type": "git",
"url": "https://github.org/name/package/src/master",
"reference": "master"
},
"dist": {
"type": "git",
"url": "https://github.org/name/package"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Example\\Package\\ExamplePackageProvider"
]
}
},
"installation-source": "source",
"autoload": {
"psr-4": {
"Example\\Package\\": "src/"
}
},
"install-path": "../exmaple/package"
}
Then check vendor/autoload_classmap.php and you should see the namespaces.
Now if you commit and push on your package repo and want update the package in your test repo you need to change the version.
...
"package": {
"name": "example/package",
"version": "0.2.0",
"dist":
...
Then run composer update example/package
Upvotes: 0
Reputation: 51
An improvement to the answer above.
Add repositories in composer.json
"repositories": [
{
"url": "https://github.com/notmaintained/shopify.php",
"type": "git"
}
],
Add the package name in require with the branch name after the dev:
"sandeepshetty/shopify.php" : "dev-master"
The package name is sometimes mistaken with the username/repo name. Always open the composer.json file to get the actual packcage name. I spent great deal of time looking around.
Upvotes: 5
Reputation: 8130
I am going to use this repo to explain the steps. The reasons is because the repo you includes do not have composer.json
which I don't think possible to install using composer in that case
Add repositories in composer.json
"repositories": [
{
"url": "https://github.com/notmaintained/shopify.php",
"type": "git"
}
],
Add the package name in require with the branch name after the dev
:
"sandeepshetty/shopify.php" : "dev-master"
EDIT:
Just tested this. There are some error since it was unmaintained package but you should get the idea of installing composer package using git.
Upvotes: 11
Reputation: 317
Composer uses packages from the repository https://packagist.org/. You can't really just use github packages directly from github.
You have 2 options here.
Use a package available on https://packagist.org/ to integrate with the shopify API. I've had a look on packagist and found rocket-code/shopify and phpish/shopify. To add them to your laravel project, in the folder that contains the composer.json file use the following command:
composer require rocket-code/shopify
You could create your own packagist package using the git repository. so you'll clone the repo and then create your own packagist account. So sign up, get a packagist account, upload the file and then require it in your laravel project.
I suggest that you use an existing composer package, as it takes away the responsibility of managing your own package.
Upvotes: 0