承接 simivar/reverse-print-r 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

simivar/reverse-print-r

Composer 安装命令:

composer require simivar/reverse-print-r

包简介

Library to reverse print_r output to PHP objects, arrays and scalar values.

README 文档

README

This library provides six different handlers for reversing output of PHP's print_r function back to original variables. If there's no handler available for a type it's returned as string.

Assumptions

  • all values should be type-casted, not returned as string
  • empty string ("") is treated as null (see NullHandler)
  • integers are treated as integers (no boolean support)
  • multi-level array MUST be supported with type-casting
  • public, protected and private properties of Objects MUST be supported with type-casting

Known issues

  • no support for Object Inheritance

Installation

Package is available via Composer.

composer require simivar/reverse-print-r

Usage

<?php

$print_r_output = print_r([
    'string' => 'some text',
    'integer' => 1,
    'float' => 2.3,
    'subArray' => [
        'Hello World.',
    ],
], true);

$reverser = new \ReversePrintR\ReversePrintR($print_r_output);
echo $reverser->reverse()['float']; 
// outputs "2.3"

Changing behavior of Handlers

All handlers are defined as final, but thanks to Dependency Injection it's easy to change the behavior of library and it's type-casting. Let's say you want to keep all the empty strings "" as string, not null. All you have to do is create your own HandlerRunner without NullHandler.

<?php

$print_r_output = print_r([
    'string' => '',
    'null' => null,
], true);

$handlerRunner = new \ReversePrintR\HandlerRunner(
    new \ReversePrintR\Handler\FloatHandler(),
    new \ReversePrintR\Handler\IntegerHandler(),
    new \ReversePrintR\Handler\ArrayHandler(),
    new \ReversePrintR\Handler\ObjectHandler()
);

$reverser = new \ReversePrintR\ReversePrintR($print_r_output, $handlerRunner);
var_dump($reverser->reverse()['null']); 
// outputs ""

Own Handlers

The same way to removed NullHandler you can add your own handlers. All you have to do is make sure that it implements \ReversePrintR\Handler\HandlerInterface and you are good to go.

Versioning

Library is following Semver. All minor and patch updates are backwards compatible.

License

Please see the license file for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固