Extend the Laravel\Lumen\Exceptions\Handler.php inside package - laravel

I've got several Lumen services that have the same code inside the render() function within the App\Exceptions\Handler.php class. I want to move this code to a separate package that all of the services can include. I was able to get this working by making the package Handler.php file extend the Laravel\Lumen\Exceptions\Handler.php class, basically inserting my class between the default framework file and the Handler that users edit.
Change:
class Handler extends Laravel\Lumen\Exceptions\Handler {...}
To:
My class
use Laravel\Lumen\Exceptions\Handler;
class MyHandler extends Handler {...}
Framework class
use ServiceHelpers\Exceptions\MyHandler;
class Handler extends MyHandler {...}
However I ran into the problem where Laravel\Lumen\Exceptions\Handler doesn't exist when unit testing my file within the package. I've requires several illuminate/... packages in my composer file but it looks like the file I'm trying to extend is in the Laravel or Lumen framework and I'd have to require the laravel/lumen package which I don't think is appropriate.
I'm currently have the following required:
"illuminate/support": "^5.5",
"illuminate/http": "^5.5",
"illuminate/validation": "^5.5",
The error I'm getting is:
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'Laravel\Lumen\Exceptions\Handler' not found

Well, technically, your package depends on laravel/lumen-framework being installed, since it is extending a class from that package. Because of this, having laravel/lumen-framework as a dependency for your package is appropriate; your package depends on it being installed.

Related

Grails 3.2 with Intellij cannot extend plugin class

I have a base plugin class that cannot be resolved. It is like this:
package my.project
class NotificationController extends my.notification.plugin.NotificationController {...}
Upon building, the error I receive is
Error:(11, 1) Groovyc: unable to resolve class my.notification.plugin.NotificationController
Same thing for the Notification service.
Is this an Intellij thing or a Grails/Gradle thing? And is there a cure?
The answer is - you can't extend the controller because of the special processing grails applies to a controller. If one must do this, the base plugin should partition the controller "guts" into a regular class. Then, both the plugin and the main app can extend the regular class. Of course this is not quite the same as extending the plugin controller, but it seems to be as close as one can get. And this assumes one has control of the plugin class code...

Overriding module class in prestashop 1.7.6

I'm trying to override a class from a module I installed. The class is located in the modules folder in MyModule/lib/MyClass.php
So what i did is create a copy of that class in override/modules/MyModule/lib/MyClass.php and it's declared like this:
class MyClassOverride extends MyClass {
// custom code
}
I also deleted the class_index.php file.
And my changes are not applied so i really don't know what I am missing here. Is it even possible to do that ? I heard that in previous versions of prestashop you couldn't override a module class...
Anyone has an idea ?
I have the same problem.
It seems that it's possible to override a php class for a module if the class is in MyModule/MyClass.php, but it doesn't work if the class is in MyModule/lib/MyClass.php...

`.jsconfig` but for php paths in vscode

I have a laravel project and frequently uses Facade with a usage of something like
\MyCustomFacade::renewalDate()
which point to a class /src/Classes/MyCustomFacade#renewalDate.
The goal is that VScode definition of the facade usage will point to the correct file class path.
try this package
its index all your facade model controller routes view you create and auto import your class by typing your facade

Create controller with already included classes laravel

I am working with Laravel framework and I want to include my common classes in the controller file while I am creating controller from php artisan. For now it creates controller like
<?php namespace ReaPro\Http\Controllers\Home;
use ReaPro\Http\Requests;
use ReaPro\Http\Controllers\Controller;
class HomeController extends Controller {}
I want to include my common classes like
<?php namespace ReaPro\Http\Controllers\Home;
use ReaPro\Http\Requests;
use ReaPro\Http\Controllers\Controller;
use ReaPro\Model\Page;
use ReaPro\Helpers\Common;
class HomeController extends Controller {}
So how can I pre include my
use ReaPro\Model\Page;
use ReaPro\Helpers\Common;
Classes somewhere so that these may come with each controller by default when I create controller with php artisan ?
The Laravel GeneratorCommand class is quite easy to extend for your own needs. Here is the ControllerMakeCommand which extends GeneratorCommand. The most important part is in the getStub() method, from here you can see that it returns either controller.stub or controller.plain.stub depending on the options. These stubs are here.
In short:
Create your own command for generating controllers
Extend Illuminate\Console\GeneratorCommand
Implement your own command in the same way as Illuminate\Routing\Console\ControllerMakeCommand
Create your own stubs

How to integrate in Laravel 5 a Package from Packagist?

I'm working with laravel 5 and trying to integrate the following package:
exacttarget/fuel-sdk-php
I executed on my project:
composer require exacttarget/fuel-sdk-php
So I had on my vendor dir exacttarget provider.
First thing I've noticed this particular package doesn't use namespaces, so it still calls require directives but not "use \path\namespace"
Is it a right approach? I haven't seen many packages yet but among my past experience doesn't look to me the right approach to write a package...
After this I edit condif/app.php to use ET_Client class.
'providers' => [
...
'ET_Client',
...
],
Once I did this, I got an error: looks like Laravel frmwk tries to instantiate the class, that needs some parameters to work, even if I'm not yet using it (istantiating). It this a normal behavior from Laravel?
Am I missing something ?
The providers array is for registering service provider classes. Unless ET_Client extends Laravel’s base ServiceProvider class, it’s not going to work.
Instead, just add the use statements to your PHP classes as and when you need to use the class:
<?php
namespace App\Http\Controllers;
use ET_Client;
class SomeController extends Controller
{
public function someAction()
{
// Instantiate client class
$client = new ET_Client;
// Now do something with it...
}
}

Resources