linuscash/with-global-state 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

linuscash/with-global-state

Composer 安装命令:

composer require linuscash/with-global-state

包简介

a simple way to make global state clear in order to bring it back under control

README 文档

README

withGlobalState is a simple utility that will wrap any function in order to make its global state requirements clear.

motivation

Working on an application recently I found that large chunks of it shared global state. I wanted to focus my efforts untangling modules that shared state but didn't want to go all big bang on it and run down the rabbit hole. Thus this little function was born. I used it to get a grip on each modules global state while I refactored it out without interfering with the other modules.

example

function greetMe (String $moniker): String
{
    return "Hello {$moniker} my name is {$GLOBALS['name']}";
}

greetMe('stranger'); // ??

$linusGreetMe = withGlobalState('greetMe', ['name' => 'Linus']);
$linusGreetMe('stranger'); // "Hello stranger my name is Linus"

The above is a contrived example but it does demonstrate the functions purpose. We can see a poorly implemented function that depends on global state instantly become more readable, manageable and testable.

Essentially we can write tests against this legacy code. Once we have a handle on it, we can refactor it down to something more meanful and maintainable without treading on the toes of other modules.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-08-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固