schnittstabil/get 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

schnittstabil/get

Composer 安装命令:

composer require schnittstabil/get

包简介

Get nested array values and object properties.

README 文档

README

SensioLabsInsight

Get nested array values and object properties.

Install

$ composer require schnittstabil/get

Usage

require __DIR__.'/vendor/autoload.php';

use Schnittstabil\Get;

echo 'Hello '.Get\value('name', $_REQUEST, 'John Doe');
echo 'Hello '.Get\valueOrFail('PHP_AUTH_USER', $_SERVER, 'User is not authenticated.');

echo 'user:     '.Get\env('DB_USER', 'root');
echo 'password: '.Get\envOrFail('DB_PASS', 'DB_PASS is not set');

API

Schnittstabil\Get\value

/**
 * Return array values and object properties.
 *
 * @param string|int|mixed[] $path    the path
 * @param object|array|null  $target  the target
 * @param mixed              $default default value if $path is not valid
 *
 * @return mixed the value determined by `$path` or otherwise `$default`
 *
 * @SuppressWarnings(PHPMD.StaticAccess)
 */
function value($path, $target, $default = null)
{/**/}
use Schnittstabil\Get;

$array = ['zero', 'one', 'two'];
$array['foo'] = new \stdClass();
$array['foo']->bar = true;
$array['un.usual'] = true;

Get\value(1,              $array);  //=> 'one'
Get\value('1',            $array);  //=> 'one'
Get\value('foo.bar',      $array);  //=> true
Get\value(['foo', 'bar'], $array);  //=> true
Get\value(['un.usual'],   $array);  //=> true

// $default
Get\value('un.usual', $array);      //=> null
Get\value(3,          $array);      //=> null
Get\value(3,          $array, 42);  //=> 42

Schnittstabil\Get\valueOrFail

Same as Schnittstabil\Get\value, but throws an OutOfBoundsException.

/**
 * Return array values and object properties.
 *
 * @param string|int|mixed[] $path    the path
 * @param object|array|null  $target  the target
 * @param mixed              $message exception message
 *
 * @throws \OutOfBoundsException if the `$path` does not determine a member of `$target`
 *
 * @return mixed the value determined by `$path`
 *
 * @SuppressWarnings(PHPMD.StaticAccess)
 */
function valueOrFail($path, $target, $message = null)
{/**/}
use Schnittstabil\Get;

Get\valueOrFail(3, $array);
//=> throws an OutOfBoundsException

Get\valueOrFail(3, $array, 'Error Message');
//=> throws a new OutOfBoundsException('Error Message')

Schnittstabil\Get\typed

/**
 * Converts a string value to a PHP typed value.
 *
 * @param mixed  $value
 * @return mixed
 */
function typed($value)
{/**/}
use Schnittstabil\Get;

Get\typed('42');
//=> int(42)

Get\typed('true');
Get\typed('yes');
Get\typed('on');
//=> bool(true)

Get\typed('false');
Get\typed('no');
Get\typed('off');
//=> bool(false)

/* escaping */
Get\typed('"true"');
Get\typed("'true'");
//=> string("true")

Schnittstabil\Get\env

/**
 * Gets the value of an environment variable.
 *
 * @param string $varname   the variable name
 * @param mixed  $default   default value if `$varname` is not valid
 * @param mixed  $typed     convert environment value to a PHP typed value
 * @param bool   $localOnly return only values of local environment variables
 *
 * @return mixed the environment value determined by `$varname` or otherwise `$default`
 */
function env($varname, $default = null, $typed = true, $localOnly = false)
{/**/}

Schnittstabil\Get\envOrFail

/**
 * Gets the value of an environment variable.
 *
 * @param string $varname   the variable name
 * @param mixed  $message   exception message
 * @param mixed  $typed     convert environment value to a PHP typed value
 * @param bool   $localOnly return only values of local environment variables
 *
 * @throws OutOfBoundsException if the `$varname` does not determine an environment value
 *
 * @return mixed the environment value determined by `$varname`
 */
function envOrFail($varname, $message = null, $typed = true, $localOnly = false)
{/**/}

License

MIT © Michael Mayer

schnittstabil/get 适用场景与选型建议

schnittstabil/get 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 113.32k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 11 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 113.32k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 17
  • 依赖项目数: 11
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-11-23