sitroz/laravel-legacy-bridge
Composer 安装命令:
composer require sitroz/laravel-legacy-bridge
包简介
This package allows you to use all the familiar and powerful functionality of laravel as a library for an existing project
关键字:
README 文档
README
This package allows you to use all the familiar and powerful functionality of laravel as a library for an existing project.
Possibilities
-
Laravel Integration: Use the power of Laravel in any PHP project.
-
HTTP Request handling: With
LaraBridgeyou can handle HTTP requests the way Laravel does it, just include the initialization file. -
Including your dependency files: The package primarily aims to ensure that your function files are always loaded and accessible from anywhere: anywhere in Laravel and, of course, in your project code.
-
Does not interfere with standard Laravel behavior: use
public/index.phpandartisanas usual -
Simple disable error handling: Laravel error handler is very strong. If you are not sure that your project does not contain any warnings or errors, you can manage it.
-
Automatic installation: The package includes scripts for automatic registration
LaraBridgeServiceProviderand Laravel loading modifications. -
Automatic removal: You can run a script that will completely remove the package and will return all modified files to their original state.
-
Verifying and Rolling Back Changes: Installation and uninstallation scripts check whether the goes through each stage of installation and rolls back changes so that your project does not stop working.
Requirements
- Laravel: 5.4
- PHP: 5.6
Usage
Suppose your project is located in the /path1/path2/my-project directory. Follow these steps:
-
Install Laravel next to your project, for example in the
/path1/path2/laraveldirectory. The name of the folder containing Laravel does not matter. -
Install and configure the
laravel-legacy-bridgepackage using Composer in/path1/path2/laravel. -
Create a file
/path1/path2/my-project/bridgeExample.phpwith the following content:<?php include_once __DIR__ . '/../laravel/bootstrap/init.php'; dump('Hello world from Laravel!');
-
You can include
bootstrap/init.phpin any file.
To make this more elegant and maintainable, we recommend to define a LARAVEL_INIT constant equal to path/to/bootstrap/init.php and add it to the global PHP constants.
Then your bridgeExample.php will be like:
<?php include_once LARAVEL_INIT; dump('Hello world from Laravel!');
Installation
Here we suppose you have a laravel installation. If laravel is not installed, start from the topic before.
-
Install the package via composer
composer require sitroz/laravel-legacy-bridge -
Then run the register-script.php to register the LaraBridgeServiceProvider in the config app.php
php ./vendor/sitroz/laravel-legacy-bridge/register-script.phpor place service provider to your
app.providersconfigSitroz\LaraBridge\LaraBridgeServiceProvider::class,
-
Run the artisan command to embed the code into the standard files and push other files
php artisan laraBridge:install -
Open
config/laraBridge.phpfile and set your old boot files or other parameters as you wish -
Include
.../laravel/bootstrap/init.phpfile in any php file outside the Laravel folder You can also include your boot file in the LaraBridge configuration and includeinit.phpto your boot file, protection against recursive includes is configured here.
UNINSTALL
- Run artisan remove command and remove package in auto mode or follow the instructions if there is any issues.
php artisan laraBridge:remove - Remove
LaraBridgeServiceProvider::classfromapp.providersconfig - Remove package via composer
composer remove sitroz/laravel-legacy-bridge
Error Handling
By default, laravel handles exceptions and render an exception-page. But if you are not sure that your application is 100% stable and work without errors/warnings/etc. , then it is recommended to disable this behavior so that the application does not break by using laravel.
Important: you can disable error handling only for HTTP requests, CLI-scripts behaviour won't be changed.
For example:
include_once __DIR__ . '/laravel/bootstrap/init.php'; $a[0] = 'Hello'; $a[2] = 'World'; echo $a[0].$a[1].$a[2]; // By default, here your script will be stopped by laravel function smthImportant(){ echo 'doing our important stuff'; } smthImportant();
So the smthImportant won't be done.
Disabling
To solve it you can disable that by setting config parameter laraBridge.handling_exceptions.disabled to TRUE.
In this case you will see a warning and smthImportant be done.
Enable Parameter
However, if you want to use an ErrorHandler, you can choose the name and the secret in
laraBridge.handling_exceptions.enable_param config. Then you can enable handler for a single request you do.
Param usage: http://example.com/index.php?name=secret
To protect it from unauthorized use, you can control the configuration value from the ServiceProviders.
Using laravel router to handle your requests.
LaraBridge provides the ability to handle HTTP requests to any files through a laravel router if you set laraBridge.use_router to True.
How it works
When router is turned on, laravel will try to find matching route. In success case Router will handle request, send a response just after "include .../init.php" and will be finished.
Mismatch with registered routes not cause any errors/exceptions. The script will continue it's work properly as usual.
There is an extra option rewrite_path_info. When it sets to True the path from domain to filename will be added to router path.
The exception to this rule is the index.php file: the /index.php substring will be ignored.
Routing examples table
| URL to file with included init.php | Default Router Path | Router path with 'rewrite_path_info' option |
|---|---|---|
| example.com/index.php | / | / |
| example.com/index.php/p1/p2 | /p1/p2 | /p1/p2 |
| example.com/test.php | / | /test |
| example.com/test.php/p1/p2 | /p1/p2 | /test/p1/p2 |
| example.com/dir1/dir2/index.php | / | /dir1/dir2 |
| example.com/dir1/dir2/index.php/p1/p2 | /p1/p2 | /dir1/dir2/p1/p2 |
| example.com/dir1/dir2/page.php | / | /dir1/dir2/page |
| example.com/dir1/dir2/page.php/p1/p2 | /p1/p2 | /dir1/dir2/page/p1/p2 |
TODO
- Try to write PHPUnit test with full workflow including installation, tests and removing the package.
- Test with next laravel versions
Contribution to the project
Your contribution is welcome! Please send pull requests and create issues to improve this package.
License
This project is licensed under MIT terms. Details can be found in the LICENSE file.
sitroz/laravel-legacy-bridge 适用场景与选型建议
sitroz/laravel-legacy-bridge 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 12 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「error handling」 「laravel」 「integration」 「laravel 5」 「laravel 10」 「legacy-bridge」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sitroz/laravel-legacy-bridge 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sitroz/laravel-legacy-bridge 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sitroz/laravel-legacy-bridge 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provides form handler for Symfony form types
PHP Error Handler module that captures and displays all throwable errors in a given format, making debugging easier and more efficient
Common classes for handling files
Error and Exception override and observers.
Error handler based on Booboo with HTML and JSON support
Error Share App, for handle error page
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-23