承接 wikimedia/assert 相关项目开发

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

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

wikimedia/assert

最新稳定版本:v0.5.1

Composer 安装命令:

composer require wikimedia/assert

包简介

Provides runtime assertions

README 文档

README

This package provides an alternative to PHP's assert() that allows for an simple and reliable way to check preconditions and postconditions in PHP code. It was proposed as a MediaWiki RFC, but is completely generic and can be used by any PHP program or library. It is published under the MIT license, see the COPYING file.

Usage

The Assert class provides several static methods for checking various kinds of assertions. The most common kind is to check the type of a parameter, typically in a constructor or a setter method:

function setFoo( $foo ) {
    Assert::parameterType( 'integer', $foo, 'foo' );
    Assert::parameter( $foo > 0, 'foo', 'must be greater than 0' );
}

function __construct( $bar, array $bazz ) {
    Assert::parameterType( 'Me\MyApp\SomeClass', $bar );
    Assert::parameterElementType( 'int', $bazz );
}

Checking parameters, or other assertions such as pre- or postconditions, is not recommended for performance critical regions of the code, since evaluating expressions and calling the assertion functions costs time.

Rationale

The background of this proposal is the recurring discussions about whether PHP's assert() can and should be used in MediaWiki code. Two relevant threads:

The outcome appears to be that

  • assertions are generally a good way to improve code quality
  • but PHP's ''assert()'' is broken by design

Following a suggestion by Tim Starling, this package provides an alternative to PHP's built in assert().

统计信息

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

GitHub 信息

  • Stars: 9
  • Watchers: 20
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-07-29