PHP 클래스 Prado\I18N\core\ChoiceFormat

ChoiceFormat converts between ranges of numeric values and string names for those ranges. A ChoiceFormat splits the real number line -Inf to +Inf into two or more contiguous ranges. Each range is mapped to a string. ChoiceFormat is generally used in a MessageFormat for displaying grammatically correct plurals such as "There are 2 files." $string = '[0] are no files |[1] is one file |(1,Inf] are {number} files'; $formatter = new MessageFormat(...); //init for a source $translated = $formatter->format($string); $choice = new ChoiceFormat(); echo $choice->format($translated, 0); //shows "are no files" The message/string choices are separated by the pipe "|" followed by a set notation of the form # [1,2] -- accepts values between 1 and 2, inclusive. # (1,2) -- accepts values between 1 and 2, excluding 1 and 2. # {1,2,3,4} -- only values defined in the set are accepted. # [-Inf,0) -- accepts value greater or equal to negative infinity and strictly less than 0 Any non-empty combinations of the delimiters of square and round brackets are acceptable. Since version 3.1.2 the following set notation is also possible. # {n: n % 10 > 1 && n % 10 < 5} -- matches numbers like 2, 3, 4, 22, 23, 24 Where set is defined by the expression after n:. In particular, the expression accepts the following mathematical/logical operators to form a set of logical conditions on the value given by n: # < -- less than. # <= -- less than equals. # > -- greater than. # >= -- greater than equals. # == -- of equal value. # % -- modulo, e.g., 1 % 10 equals 1, 11 % 10 equals 1. # - -- minus, negative. # + -- addition. # & -- conditional AND. # && -- condition AND with short circuit. # | -- conditional OR. # || -- conditional OR with short circuit. # ! -- negation. Additional round brackets can also be used to perform grouping.
파일 보기 프로젝트 열기: pradosoft/prado 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$inf float The value for positive infinity.
$parse string The pattern to parse the formatting string.
$validate string The pattern to validate a set notation

공개 메소드들

메소드 설명
__construct ( ) Constructor.
format ( $string, $number ) : string For the choice string, and a number, find and return the string that satisfied the set within the choices.
isValid ( $number, $set ) : boolean Determine if the given number belongs to a given set
parse ( $string ) : array Parse a choice string and get a list of sets and a list of strings corresponding to the sets.

보호된 메소드들

메소드 설명
isValidSetNotation ( $number, $set )

메소드 상세

__construct() 공개 메소드

Constructor.
public __construct ( )

format() 공개 메소드

For the choice string, and a number, find and return the string that satisfied the set within the choices.
public format ( $string, $number ) : string
리턴 string the choosen string.

isValid() 공개 메소드

Determine if the given number belongs to a given set
public isValid ( $number, $set ) : boolean
리턴 boolean true if number is in the set, false otherwise.

isValidSetNotation() 보호된 메소드

protected isValidSetNotation ( $number, $set )

parse() 공개 메소드

Parse a choice string and get a list of sets and a list of strings corresponding to the sets.
public parse ( $string ) : array
리턴 array array($sets, $strings)

프로퍼티 상세

$inf 보호되어 있는 프로퍼티

The value for positive infinity.
protected float $inf
리턴 float

$parse 보호되어 있는 프로퍼티

The pattern to parse the formatting string.
protected string $parse
리턴 string

$validate 보호되어 있는 프로퍼티

The pattern to validate a set notation
protected string $validate
리턴 string