Composer plugin: how to add a custom autoloader? - composer-php

I have a custom autoloader that does a lot of behind-the-stage magic handling of class loading (https://github.com/exteon/chaining-class-resolver).
I want to distribute modules that rely on this loader as composer packages, for which I've already written a custom composer install plugin.
Is there a way I can tap into composer's autoloading sequence i.e. on post-autoload-dump to append my autoloader?
I have an obvious solution in building another autoload.php script that require()s vendor/autoload.php and using that to bootstrap the application; however:
extending the composer autoloader seems more elegant
I was pondering whether there will be a future need that the said custom autoloaded modules expose some composer paraphernalia, like composer commands (https://getcomposer.org/doc/articles/plugins.md#command-provider). This would not work with the obvious solution as composer will not call upon the custom bootstrap to load the classes.
So, is there a more elegant way to tap into the composer autoloader itself? i.e. include a custom autoloader that would be loaded with vendor/autoload.php ?

Related

php artisan make:controller is not defined

I am using Laravel Framework 6.20.44, which I can tell from php artisan -V
It comes part of OctoberCMS, which I just updated.
I'm jealous because the documentation for Laravel 6.x, and some many other resources, show that php artisan come with a make command, derived into so many subcommands.
I would like to enjoy a command like php artisan make:controller API/TopicController --api.
I can't, because my version of artisan returns:
Command "make:controller" is not defined.
Did you mean one of these?
create:controller
make:migration
It looks like I have an older version of artisan, heavily coupled to October.
I say coupled because I can spot commands such as october: when I list available artisan commands.
No luck with create:controller either, as --api is not implemented in my version...
My question: how do I update artisan so that I have access to the make command, according to the doco?
October CMS is developed in Laravel and it's not framework. It is CMS.
So, being CMS it has to maintain its directory structure with predefined paths. CMS is driven by plugins and themes. So you can only add/modify plugins or theme files.
So now if you try to add a controller where do it will add? it cants add to its system files OR in app/controllers/. To prevent this the authors of CMS have removed/overrideLaravel native commands to avoid creating the unexpected directory structure or files in core folders.
So basically you need to follow CMS rules and its command to maintain the directory structure and file structure of CMS. It's important otherwise CMS will not work.
php artisan create:controller <Author>:<PluginName> <ControllerName>
this is the exact definition: Create the controller in this plugin by this name. So it can work with CMS core logic.
Check some tutorials to understand how October CMS works:
How to install OctoberCMS
themes
How to edit OctoberCMS
themes
How to install OctoberCMS
plugins
Essential Plugins for
OctoberCMS
If any doubts please comment.

Laravel's ui:auth command generating incompatible Controllers

I have a Laravel installation on v7.29.3 (our server won't support v8 yet)
I am having an issue with the ui:auth command. It is generating Controllers that reference classes in the Illuminate namespace that don't exist.
For example, the Auth\VerificationController class it gives me, uses Illuminate\Foundation\Auth\VerifiesEmails but I can't see a corresponding file in the /vendor/laravel/src/Illuminate/Foundation/Auth directory.
What's more, when I search for "VerifiesEmails" in the Laravel API doc for v7.x there is no such file. This file does exist however when I search for it in v6.x
So my guess is that I've got a mismatch somewhere and I'm getting v6 controllers for a v7 installation.
However, composer is showing that I have laravel/ui 2.5 which is supposed to be for Laravel 7.
I've tried deleting my composer.lock and vendor directories and reinstalling from composer in the hope that would clear up the issue, but no dice.
Any ideas what could be going on?
Those classes aren't in vendor/laravel/framework/src/.... They are not part of the framework. They come from the laravel/ui package, vendor/laravel/ui/auth-backend/....

Laravel Aws\Kinesis\KinesisClient not found

I would like to use Aws\Kinesis\KinesisClient on my Laravel project but unfortunately, when I install package using
composer require aws/aws-sdk-php
and try to use
use Aws\Kinesis\KinesisClient;
I got
Symfony\Component\Debug\Exception\FatalThrowableError: Class 'Aws\Kinesis\KinesisClient not found.
Please guide me how to use KinesisClient on laravel project.
Regards.
The documentation says that; you need to include vendor/autoload.php before using it.
<?php
// Require the Composer autoloader.
require 'vendor/autoload.php';
use Aws\S3\S3Client;
If you don't want to require on every class you use, then maybe you may check this repository to load with service provider. (more laravel way)
This is a simple Laravel service provider for making it easy to include the official AWS SDK for PHP in your Laravel and Lumen applications.

How can I require composer autoloader in the laravel?

I want to install guzzle https://github.com/guzzle/guzzle
I read the reference, but I'm confused this section :
From that tutorial, asking for require composer autoloader. So seems needed to add require 'vendor/autoload.php';
Where I add the script?
I using laravel 5.6
You don't have to do anything if you are going to install guzzle in Laravel.
The example above is for core php actually. Laravel will automatically do it for you.
Just run composer require guzzlehttp/guzzle in your terminal. (of course in the directory where your laravel project actually is.)
And add use GuzzleHttp\Client; at the top of the file you will be calling guzzle from.

Does laravel has any gems to extend or modify functionality?

Does laravel has gems like as ruby on rails have? Like, for signup flow ruby on rails has "devise" gem. Does laravel has anything like that?
There is no built-in package manager for Laravel but you can use reference like: https://packalyst.com . Here you can find all available packages for Laravel. All of them can be installed with Composer - php package manager. There is detail description how to install every pack in Packalyst.
If you want to have auth in Laravel you have two options. To do it manually, or to use the built-in module for authentication. You can run
php artisan make:auth
in the main project directory. This will add the required views and routes in the Laravel file structure in order to use the auth. Better to run this command on fresh installation. See this for detailed step by step authentication with Laravel 5: https://laravel.com/docs/5.5/authentication#authentication-quickstart

Resources