jced-artem/legacy-adapter
Composer 安装命令:
composer require jced-artem/legacy-adapter
包简介
Flyweight-adapter for using legacy code in modern frameworks with lazy refactor.
README 文档
README
Flyweight-adapter for using legacy code in modern frameworks with lazy refactor.
Install
composer require jced-artem/legacy-adapter
Example
<?php
// legacy_lib.php
include("settings.inc.php");
require("functions.php");
require_once("database.connection.php");
define('SOME_CONST', 'value');
$var1 = funcName(CONST_2);
function get_Var2A($param1, $param2) {
return functionFromAnotherInclude($param2, $param1);
}
class myClass
{
var $data = '';
function getData() {
global $var1;
// do somethig
return get_Var2A($var1, SOME_CONST);
}
}
include_once("specialCode.php");
function needThis() {
$obj = new myClass();
return unknownFunctionFromInclude() + $obj->getData();
}
$var2 = needThis();
printr('{"param":' . $var2 . '; "var": ' . $var1 . '}');
You can use this legacy file anywhere simply:
class MyLib extends LegacyAbstractAdapter
{
/**
* Configure flyweight
*/
protected function configure()
{
$this
->setLegacyFile('legacy_lib.php')
->setLegacyPath('/path/to/includes')
;
}
}
$myLib = new MyLib();
// global vars
$var1 = $myLib->var1;
$var2 = $myLib->var2;
// set value
$myLib->var1 = 'some new value';
// get global functions
$res1 = $myLib->get_Var2A($param1, $param2);
$res2 = $myLib->needThis();
// get printr result
$content = $myLib->getFlyweight()->getContent();
or
class MyLib extends LegacyAbstractAdapter
{
/**
* Configure flyweight
*/
protected function configure()
{
$this
->setLegacyFile('legacy_lib.php')
->setLegacyPath('/path/to/includes')
;
}
// override
public function needThis()
{
return 'dummy value';
}
// decorate
public function get_Var2A($param1, $param2)
{
return '<font>' . $this->getFlyweight()->call('get_Var2A', [$param1, $param2]); . '</font>';
}
// and more
}
Methods available in flyweight
getContent() - get echo/print/etc after include file
get($name) - get variable from file
hasVariable($name) - check if variable exists
set($name, $value) - set variable value
hasFunction($name) - check if function exists
call($name, array $parameters = []) - call function
hasClassDeclared($className) - check if class exists
innerClassGetConstant($className, $constantName) - get constsnt from class
innerClassGetInstance($className) - get instance of class which was declared in file
innerClassCallStatic($className, $methodName, array $parameters = []) - call static function of class declared in file
getFunctionNamesList() - list of all function
getVariableNamesList() - list of all variables
getClassNamesList() - list of all classes
Weakness
- Singleton-like. You can't create 2 objects because you can't include file 2 times;
- Global functions and classes are still global;
- Performance can be 2 times lower then native usage include();
jced-artem/legacy-adapter 适用场景与选型建议
jced-artem/legacy-adapter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 9, 最近一次更新时间为 2016 年 12 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「adapter」 「wrapper」 「require」 「legacy」 「include」 「refactoring」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jced-artem/legacy-adapter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jced-artem/legacy-adapter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jced-artem/legacy-adapter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Adapter designed to add Framework Agnosticism for Caching within PHP Packages.
flysystem cache Adapter
Virtual Filesystem Storage Adapter for Laravel
LinkedIn API PHP SDK with OAuth 2.0 & CSRF support. Can be used for social sign in or sharing on LinkedIn. Examples. Documentation.
This Composer plugin adds "require-ext" command which makes using of private repositories and packages smoother.
A simple interface for composite Flysystem adapters
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-12-01