承接 dechamp/shorty 相关项目开发

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

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

dechamp/shorty

最新稳定版本:1.3.8

Composer 安装命令:

composer require dechamp/shorty

包简介

Just a few tools to help avoid annoying things such as long logic where it should be simple.

README 文档

README

pipeline status coverage report

The goal of this library is to provide easy helpers to shorten repetitive task that are used day in and day out.

Guidelines

  • Do not create something that you can get from another supported library.
  • K.I.S.S. (Keep it simple stupid), don't make large helpers.
  • Keep them as static methods for simplicity

Helps shorten typical logic that can become excessive, such as getting a value from an deep array or returning null.

Methods

grabOrNull((array|object) $haystack, (string) $needle)

Used when dealing with arrays or object, when getting values. check recursively for key, return value or null if key not found

  • $haystack - (array|object) it will do the same, for array or object
  • $needle - (string) search recursively by seperating the keys with /, exp a/b/c

example usage

use

Shorty::grabOrNull($deepArray, "a/b/c/d");

instead of...

isset($deepArray['a']['b']['c']['d']) ? $deepArray['a']['b']['c']['d'] : null;

grabOr((array|object) $haystack, (string) $needle, (mixed) $default)

Used when dealing with arrays or object, when getting values. check recursively for key, return value or your default if key not found

  • $haystack - (array|object) it will do the same, for array or object
  • $needle - (string) search recursively by seperating the keys with /, exp a/b/c
  • $default - (mixed) anything you wish to return by default

example usage

use

Shorty::grabOr($deepArray, "a/b/c/d", "tacos");

instead of...

isset($deepArray['a']['b']['c']['d']) ? $deepArray['a']['b']['c']['d'] : "tacos";

grabOrThrow((array|object) $haystack, (string) $needle, Exception $exception)

Used when dealing with arrays or object, when getting values. check recursively for key, return value or throw your exception.

  • $haystack - (array|object) it will do the same, for array or object
  • $needle - (string) search recursively by seperating the keys with /, exp a/b/c
  • $exception - Exception instance

example usage

use

try {
    $val = Shorty::grabOrThrow($deepArray, "a/b/c/d", new Exception('No tacos'));
} ...

instead of...

try {
    if (! isset($deepArray['a']['b']['c']['d'])) {
        throw new Exception('No Tacos');
    }

    $val = $deepArray['a']['b']['c']['d'];
} ...

guard() this is now deprecated, use https://packagist.org/packages/webmozart/assert instead

Testing

You can use the included Dockerfile for running phpunit.

Setup

1 docker build -t shorty . 2 docker run -it -v $PWD:/var/www/html shorty /bin/bash 3 phpunit and phpunit --coverage-text

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-05-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固