承接 athwari/laravel-method-overrider 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

athwari/laravel-method-overrider

最新稳定版本:v0.1.1-alpha

Composer 安装命令:

composer require athwari/laravel-method-overrider

包简介

Runtime method interception and overriding for Laravel

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Runtime method interception and overriding for Laravel applications.

This package allows you to override instance and static methods on a class at runtime by generating a proxy class that delegates to an implementation closure.

Installation

Install the package with Composer:

composer require athwari/laravel-method-overrider

Laravel package auto-discovery is supported, so the service provider and facade are registered automatically.

Configuration

Publish the configuration file:

php artisan vendor:publish --tag=method-overrider-config

The published config file is located at config/method-overrider.php.

Default configuration

return [
    'ignore_final_methods' => true,
];
  • ignore_final_methods: when true, final methods are skipped during override generation instead of throwing an exception.

Usage

Use the MethodOverrider facade to override methods on a target class.

Override a method

use Athwari\MethodOverrider\Facades\MethodOverrider;

class TestService
{
    public function greet(string $name): string
    {
        return "Hello {$name}";
    }
}

$service = MethodOverrider::override(
    TestService::class,
    'greet',
    function ($original, $name) {
        return strtoupper($original($name));
    }
);

echo $service->greet('Taylor'); // HELLO TAYLOR

Override multiple methods

$service = MethodOverrider::override(
    TestService::class,
    ['greet', 'nullable'],
    [
        function ($original, $name) {
            return strtoupper($original($name));
        },
        function ($original, $name) {
            return $original($name);
        },
    ]
);

Supported method signatures

The package supports:

  • nullable and union parameter types
  • variadic parameters
  • reference parameters
  • static methods
  • return types

Final methods are skipped when ignore_final_methods is enabled.

Exceptions

The package throws exceptions for invalid usage:

  • Athwari\MethodOverrider\Exceptions\ClassNotFoundException
  • Athwari\MethodOverrider\Exceptions\MethodNotFoundException
  • Athwari\MethodOverrider\Exceptions\InvalidImplementationException

Testing

Run the test suite with Pest:

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The package is open-source software licensed under the MIT License. Please see License File for more information.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固