phpgt/input
Composer 安装命令:
composer require phpgt/input
包简介
Encapsulated user input.
README 文档
README
By default, PHP stores all user input in global arrays ($_GET, $_POST, and $_FILES) available for reading and modification in any code, including third party libraries.
This library wraps user input in objects that promote encapsulation, allowing functions to be passed only the user input they require, rather than having unmitigated read/write access to everything.
Type-safe functions allow more predictable functionality, such as $input->getFileUpload("photo"), $input->getDateTime("date-of-birth"), and $input->getMultipleString("pizza-topping").
Example usage
<form method="post"> <h1>User Profile</h1> <label> <span>Your name</span> <input name="name" placeholder="e.g. Eugene Kaspersky" required /> </label> <label> <span>Age</span> <input type="number" name="age" /> </label> <label> <span>Interests</span> <select name="interest[]" multiple> <option>Mathematics</option> <option>Cryptography</option> <option>Information Security</option> <option>Cyberwarfare</option> </select> </label> <label> <span>Photo</span> <input name="photo" type="file" /> </label> <button name="do" value="save">Save profile</button> </form>
<?php $profile->update( $profileId, // Use type-safe getters to help write maintainable code. $input->getString("name"), $input->getInt("age"), ); // Handle multiple values with type safety. foreach($input->getMultipleString("interest") as $interest) { $profile->addInterest($interest); } // Handle file uploads with a FileUpload object. $photoUpload = $input->getFile("photo"); if($photoUpload instanceof FailedFileUpload) { // Handle a failed upload here. } $photoUpload->moveTo("data/upload/$profileId.jpg");
Features at a glance
- Type-safe getters, implementing the TypeSafeGetter interface.
- Typed
multiplegetters, for working with checkboxes, multi-select elements or multiple file uploads. - "do" callback functions - hook up callbacks to button presses (implemented automatically in WebEngine applications).
- "when" triggers - execute callbacks when certain user input is present.
FileUploadInputDataclass for easy file uploads, including functions such asmoveTo(),getOriginalName(), etc.- Coming soon: working with huge files by streaming them to PHP, efficiently managing memory in the process.
Proudly sponsored by
phpgt/input 适用场景与选型建议
phpgt/input 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19.21k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2017 年 11 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 phpgt/input 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 phpgt/input 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 19.21k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-11-28