定制 labrodev/php-mixed-converter 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

labrodev/php-mixed-converter

最新稳定版本:v1.0.0

Composer 安装命令:

composer require labrodev/php-mixed-converter

包简介

PHP utility class that provides methods to convert mixed values to strings, ints or floats

README 文档

README

PhpMixedConvert is PHP utility class that provides methods to convert mixed values to strings, ints or floats.

Sometimes there is necessity in a code to ensure that our variable is string, int or float, especially strict types declaration is enabled in the class. On other hand, there is sometimes cases when the exact type is unknown. For example, it happens often in Laravel and probably could happen in any other project/code structure.

So this utility class has 3 static methods to just convert variable with mixed type to certain type depends on context.

P.S. We surely could detect such cases when to convert from mixed to exact type due static analysis (for example, wtih PHPStan).

Installation

To install the package, run the following command in your Laravel project:

composer require labrodev/php-mixed-converter

Requirements

  • PHP 8.1 or higher

Configuration

After installing the package, no additional configuration is needed to start using utility.

Usage

To use the utility, use Utility class in your class and just call existed static methods from it:

<?php

namespace YourNamespace;

use Labrodev\PhpMixedConverter\MixedConverter;

class YourClass extends Model
{
   
    // somewhere in your code

    // convert mixed to string
    $value = MixedConverter::toString($value);

    // convert mixed to float
    $value = MixedConverter::toFloat($value);

    // convert mixed to int
    $value = MixedConverter::toInt($value);

}

Testing

To run the tests included with the package, execute the following command:

composer test

Security

If you discover any security-related issues, please email admin@labrodev.com instead of using the issue tracker.

Credits

Labro Dev

License

The MIT License (MIT). Please see License File for more information.

Read more

Read more about our web development experince on our Substack page - Labrodev.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固