承接 bluepsyduck/common 相关项目开发

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

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

bluepsyduck/common

Composer 安装命令:

composer require bluepsyduck/common

包简介

Some classes commonly used in other projects.

README 文档

README

Latest Stable Version Total Downloads License Build Status codecov

This library contains some classes commonly used in other projects.

DataBuilder

The data builder is a class helping with building up an array with different values, ensuring that the values have the correct type. With all methods a default value can be specified which should be ignored and not added to the data array.

The data builder provides several methods for automatically casting the set values:

  • setBoolean(): Sets a boolean value.
  • setInteger(): Sets an integer number.
  • setFloat(): Sets a floating point number.
  • setString(): Sets a string value.
  • setDateTime(): Sets a date and time value in the specified format. If the passed value is not a DateTime instance, the value gets ignored automatically.
  • setArray(): Sets an array of value, optionally with a mapping method to e.g. cast each value.
Example
<?php
use BluePsyduck\Common\Data\DataBuilder;

$dataBuilder = new DataBuilder();

// Set some values
$dataBuilder->setInteger('foo', 42)
            ->setString('bar', 'baz');

// Set a variable value unless it is a specific one
$age1 = 21;
$age2 = -1;
$dataBuilder->setInteger('age1', $age1, -1)
            ->setInteger('age2', $age2, -1); // $age2 will get ignored.

// Set a date and time value
$date = new DateTime('2038-01-19 03:14:07');
$dataBuilder->setDateTime('creationTime', $date, 'Y-m-d'); // Will set '2038-01-17' as value.

// Set an array of strings
$dataBuilder->setArray('data', ['foo', 'bar', 42], 'strval'); // Casts all array values to a string.

DataContainer

The data container wraps around a deep array and is able to access and map the elements of the array without the need to check if any level key exists. All methods provide a default value to fall back to when a key is not defined.

The data container provides several methods to automatically map the data:

  • getBoolean(): Reads a boolean value.
  • getInteger(): Reads an integer number.
  • getFloat(): Reads a floating point number.
  • getString(): Reads a string value.
  • getDateTime(): Reads a date and time value. An integer value will be interpreted as Unix timestamp, a string value as date string.
  • getArray(): Reads an array value.
  • getObject(): Reads the value and returns a new DataContainer instance with that value.
  • getObjectArray(): Reads an array value and casts every item to a new instance of DataContainer.
Example
<?php
use BluePsyduck\Common\Data\DataContainer;

$data = [
    'foo' => 'bar',
    'first' => [
        'second' => 42
    ]
];
$dataContainer = new DataContainer($data);

// Accessing the first level
echo $dataContainer->getString('foo'); // 'bar'

// Accessing the second level
echo $dataContainer->getObject('first')->getInteger('second'); // 42
echo $dataContainer->getInteger(['first', 'second']); // 42

// Default values for undefined keys
echo $dataContainer->getFloat('missing', 13.37); // 13.37 

ReflectionTrait

This trait provides some methods to easily access non-public properties and invoke non-public methods of classes to be used in tests.

  • injectProperty(): Injects a value into the specified property.
  • extractProperty(): Extracts the value of the specified property.
  • invokeMethod(): Invokes the specified method and returns its result value.

bluepsyduck/common 适用场景与选型建议

bluepsyduck/common 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.01k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 02 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「common」 「BluePsyduck」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 bluepsyduck/common 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bluepsyduck/common 我们能提供哪些服务?
定制开发 / 二次开发

基于 bluepsyduck/common 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2018-02-16