L5.5 : How to auto discover package? - laravel

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

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.

Add command (console command) in a Prestashop module 1.7.6

I'm developing a prestashop module (v. 1.7.6) and I'd like to add some command available from console.
The problem is that when I configure services and try to run
bin/console mymodule:mycommand
system returns There are no commands defined in the "mymodule" namespace.
Here my services.yml
services:
mycommand_command:
class: Mymodule\MycommandCommand
tags:
- { name: 'console.command' }
Here my composer.json
{
"autoload": {
"psr-4": {
"Mymodule\\": "src/"
},
"classmap": [
"src/Command/"
]
},
"config": {
"preferred-install": "dist",
"prepend-autoloader": false
},
"type": "prestashop-module",
"author": "<???>",
"license": "<???>"
}
Any suggestions?
Thank you
Where have you create your Command class ? In src/Command/ ?
Update:
To myself:
When you Google this question next time - check:
Command defined in config/services.yml
The module is installed
Composer autoloder dumped
Old version:
Make sure you dumped autoloader in Composer and added protected static $defaultName = 'yourmodule:command'; to your command class and set the name any other way mentioned in Symfony docs.
I just faced the same issue a few days ago.
To anyone is looking for this:
Follow the step on this link: https://devdocs.prestashop.com/1.7/modules/concepts/commands/
Add composer.json IN THE ROOT OF YOUR MODULE with this code (and replace with your stuff..):
{
"autoload": {
"psr-4": {
"<YOUR-MODULE>\\": "src/"
},
"classmap": [
"src/Command/"
]
},
"config": {
"preferred-install": "dist",
"prepend-autoloader": false
},
"type": "prestashop-module",
"author": "<AUTHOR>",
"license": "<LICENSE>"
}
Connect via ssh, and cd into your module root
run composer dump-autoload -o --no-dev
Test your command by <ps-root>/bin/console your-module:command

Cannot make composer install work offline

I am trying to set up Composer to work without internet access. I have set up a server in the local network with a Satis configured repository with the following configuration file:
{
"name": "private/composer",
"homepage": "http://<some_ip>:9500",
"repositories": [
{"type": "composer", "url": "https://packagist.org"}
],
"require-dependencies": true,
"require": { ... },
"archive": {
"directory": "offline",
"format": "zip"
},
"config": {
"preferred-install": "dist"
}
}
After running
$ ./satis/bin/satis build ./satis.json ./mirror
Everything works, I get my ./satis/mirror/offline directory filled up with .zip files of the packages I am mirroring from packagist.org.
In my Composer, project, I added the following sections to the composer.json configuration:
{
"repositories": [{
"type": "composer",
"url": "http://<some_ip>:9500"
}],
"config": {
"secure-http": false
},
...
}
I tried to run composer install then and I get an error about Composer not begin able to access https://packagist.org/packages.json. Why is it trying to do that? How can I make this process work without internet access?
Thank you!
By default Composer does not disable access to packagist.org when you add custom repos. You can disable it with the following config:
{
"repositories": [
{
"packagist.org": false
}
]
}

laravel 5.5 package developing need to use composer require vendor_name/package_name

I developed a Laravel 5.5 package with package auto discovery and pushed it at git hub
https://github.com/adamibrahim/authconfirm
when i run
$ composer require "adamibrahim/authconfirm" : "v0.1.1"
I got an error
could not find package adamibrahim/authconfirm at any version for your min ...
do i need to register my repository somewhere so i can use composer require command ?
here is my package composer.json
{
"name": "adamibrahim/authconfirm",
"type": "library",
"description": ":Laravel 5.5 Auth modifications to confirm the auth email",
"keywords": [
"Laravel5.5",
"Auth",
],
"homepage": "https://github.com/adamibrahim/authconfirm",
"license": "MIT",
"authors": [
{
"name": ":Adam Ibrahim",
"email": ":adamibrahim1701#gmail.com",
"homepage": ":author_website",
"role": "Developer"
}
],
"require": {
"illuminate/support": "~5.1",
"php" : "~5.6|~7.0"
},
"require-dev": {
"phpunit/phpunit" : ">=5.4.3",
"squizlabs/php_codesniffer": "^2.3"
},
"autoload": {
"psr-4": {
"Adamibrahim\\Authconfirm\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Adamibrahim\\Authconfirm\\": "tests"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"config": {
"sort-packages": true
}
}
Well, it's not enough just to create Github repository to use it via composer. You should create account at https://packagist.org/ and add your package in there to make it available via composer require.
In addition you should setup Packagist integration on Github at:
https://github.com/adamibrahim/authconfirm/settings/installations
to make sure after changes in Github Packagist will see those changes.

Delegating to Local composer.json

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

Resources