Delegating to Local composer.json - laravel

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

Related

How to install github package in laravel 7

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.

Install unstable fork

I maintain a project that uses an abandoned library with a bug that affects me. I'd like to install a fork that includes the bugfix. I can't find the way.
Relevant settings were this:
{
"type": "project",
"license": "proprietary",
"minimum-stability": "stable",
"require": {
"php": "5.3 - 5.6",
"nuovo/spreadsheet-reader": "^0.5.11"
},
"config": {
"preferred-install": {
"*": "dist"
},
"vendor-dir": "Vendor/"
}
}
I've tried too many things to share but my latest iteration is:
{
"type": "project",
"license": "proprietary",
"minimum-stability": "dev",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/virtua-network/spreadsheet-reader"
}
],
"require": {
"php": "5.3 - 5.6",
"nuovo/spreadsheet-reader": "dev-master"
},
"config": {
"preferred-install": {
"*": "dist"
},
"vendor-dir": "Vendor/"
}
}
The package shows up in composer outdated:
PS D:\src> composer outdated
nuovo/spreadsheet-reader 0.5.11 dev-master f6bd49d Spreadsheet reader library for Excel, OpenOffice and structured text files
… but won't update:
PS D:\src> composer update nuovo/spreadsheet-reader
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating autoload files
Also, f6bd49d hash is not latest fork revision but latest original package.
How can I install the fork with Composer?
You're using incorrect package name - in your fork package is named as virtua-network/spreadsheet-reader, but you're requesting nuovo/spreadsheet-reader. So your fork is not considered as a nuovo/spreadsheet-reader package, but as a virtua-network/spreadsheet-reader, so original package from Packagist is used. You should either revert name change in composer.json of your fork and leave it as nuovo/spreadsheet-reader, or use new name in require of composer.json in your app:
"virtua-network/spreadsheet-reader": "dev-master"

How to add helpers in own laravel packages? (Call to undefined function)

In my composer.json I have written:
"autoload": {
"psr-4": {
"Pmochine\\MyOwnPackage\\": "src/"
},
"files": [
"src/helpers.php"
]
},
But somehow even after composer dump-autoload the functions are not loaded. I get "Call to undefined function". To create the package I used a package generator. Maybe it has something to do that it creates a symlink in the vendor folder?
Inside helpers I have written
<?php
if (! function_exists('myowntest')) {
function myowntest()
{
return 'test';
}
}
In the package service provider, try adding this:
// if 'src/helpers.php' does not work, try with 'helpers.php'
if (file_exists($file = app_path('src/helpers.php'))) {
require $file;
}
What you are doing is best practise and should work. I took the composer.json from barryvdh/laravel-debugbar as an example. https://github.com/barryvdh/laravel-debugbar/blob/master/composer.json
{
"name": "barryvdh/laravel-debugbar",
"description": "PHP Debugbar integration for Laravel",
"keywords": ["laravel", "debugbar", "profiler", "debug", "webprofiler"],
"license": "MIT",
"authors": [
{
"name": "Barry vd. Heuvel",
"email": "barryvdh#gmail.com"
}
],
"require": {
"php": ">=5.5.9",
"illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*",
"symfony/finder": "~2.7|~3.0",
"maximebf/debugbar": "~1.13.0"
},
"autoload": {
"psr-4": {
"Barryvdh\\Debugbar\\": "src/"
},
"files": [
"src/helpers.php"
]
}
}
My guess is that you are not requiring your own package the correct way in the main composer.json?
Just need to call in your main project
composer update you/your-package
Source
The only thing that has worked for me is to run composer remove <vendor>/<package> and require it back again. The files section was ignored otherwise.
This seems to happen while developing locally the package and making changes on the composer.json file.

L5.5 : How to auto discover package?

I want to create package and I following this tutorial https://devdojo.com/blog/tutorials/how-to-create-a-laravel-package
I want to use auto discover the new feature of L5.5, how step-3 should be? (what I need to write on laravel's composer.json)
Laravel’s custom package’s providers will be auto-discovered only if the package present in vendor folder, So for that we need to make our package installable via composer itself.
So we need to make our custom package should be installable via composer, for that set your applications composer file with minimum-stability as dev is must and we have to configure custom packages path.
"minimum-stability" : "dev",
"repositories": [
{
"type": "path",
"url": "./packages/suresh/calc/"
}
]
once you done that your package can be installed using composer require <vendor/package>, then it will configure auto discover as per your packages settings. Get the sample configurations for your package,
{
"name": "suresh/calc",
"description": "This demo for auto discover providers in laravel with custom package",
"authors": [
{
"name": "Suresh Veluamy",
"email": "sureshamk#gmail.com"
}
],
"minimum-stability": "stable",
"require": {},
"autoload": {
"psr-4": {
"Suresh\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Suresh\\Calc\\CalcServiceProvider"
]
}
}
}
For more information, i wrote a post, check it out here

packagist laravel package -composer Could not find package

I have created package using Laravel.
The composer.json file for my package will look like this
{
"name": "lakshmajim/testview",
"description": "hi",
"keywords": [
"package"
],
"homepage": "https://github.com/lakshmajim/testview",
"license": "MIT",
"authors": [
{
"name": "lakshmajim",
"email": "lakshmaji9#gmail.com"
}
],
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-4": {
"lakshmajim\\testview\\": "src/"
}
},
"minimum-stability": "dev"
}
then I have pulled to github
then I have linked it to Packagist
when I am running this composer require lakshmajim/testview
it is showing following error message
[InvalidArgumentException]
Could not find package lakshmajim/testview at any version for your minimum-stability (stable). Check the package spelling or your minimum-s
tability
QUESTION:
Why I am getting that error message ,when I'm trying to install using composer?
How can I successfully run composer require lakshmajim/testview
it's a release issue
you must run
composer require lakshmajim/testview dev-master
you don't have a release yet.

Resources