1tomany/get-safely
Composer 安装命令:
composer require 1tomany/get-safely
包简介
A simple library to safely get scalar types from values of unknown origin or type
README 文档
README
This simple library exposes several PHP functions that assist with static analysis by ensuring values of unknown or mixed types are a scalar type.
Installation
composer require 1tomany/get-safely
Functions
get_string(): string
This function returns the $value argument if it is a string or implements the \Stringable interface, otherwise it returns the value of the $default argument. If the $default argument is of type callable, the $value is passed to it and the result of the callable is returned. An exception is thrown if the callable does not return a string.
Arguments
mixed $valuestring|callable $default = ''
get_string_loose(): string
This function is identical to get_string() except the $value argument is first cast to a string if it is a scalar value (boolean, int, float, or string in PHP).
Arguments
mixed $valuestring|callable $default = ''
Examples
<?php use function OneToMany\Getters\get_string; use function OneToMany\Getters\get_string_loose; // // get_string() Examples // // string(0) "" get_string(null); // string(3) "Vic" get_string('Vic'); // string(4) "nope" get_string(null, 'nope'); // string(8) "callable" get_string(null, fn ($v) => 'callable'); // string(3) "Vic" get_string(new class('Vic') implements \Stringable { function __construct(public readonly string $name) { } public function __toString(): string { return $this->name; } }, 'Neil'); // // get_string_loose() Examples // // string(0) "" get_string_loose(null); // string(1) "1" get_string_loose(true); // string(0) "" get_string_loose(false); // string(2) "10" get_string_loose(10); // string(4) "3.14" get_string_loose(3.14); // string(3) "Vic" get_string_loose([], 'Vic');
Credits
License
The MIT License
1tomany/get-safely 适用场景与选型建议
1tomany/get-safely 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「types」 「data types」 「type safety」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 1tomany/get-safely 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 1tomany/get-safely 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 1tomany/get-safely 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
A bundle providing fields for image upload with jquery upload and image cropping with jcrop for symfony2
A simple Symfony bundle that adds boolean form field type.
Data type classes for PHP
Easily switch between entry types in entries section
A PHP Abstract Enum Class
统计信息
- 总下载量: 20
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-10