PHP Class CRUDlex\TwigExtensions

显示文件 Open project: philiplb/crudlex Class Usage Examples

Public Methods

Method Description
formatDate ( string $value, boolean $isUTC ) : string Formats the given value to a date of the format 'Y-m-d'.
formatDateTime ( string $value, boolean $isUTC ) : string Formats the given value to a date of the format 'Y-m-d H:i'.
formatFloat ( float $float ) : double | string Formats a float to not display in scientific notation.
getLanguageName ( string $language ) : string Gets a language name in the given language.
registerTwigExtensions ( Pimple\Container $app ) Registers all extensions.

Protected Methods

Method Description
formatTime ( string $value, string $timezone, string $pattern ) : string Formats the given time value to a timestring defined by the $pattern parameter.

Method Details

formatDate() public method

Formats the given value to a date of the format 'Y-m-d'.
public formatDate ( string $value, boolean $isUTC ) : string
$value string the value, might be of the format 'Y-m-d H:i' or 'Y-m-d'
$isUTC boolean whether the given value is in UTC
return string the formatted result or an empty string on null value

formatDateTime() public method

Formats the given value to a date of the format 'Y-m-d H:i'.
public formatDateTime ( string $value, boolean $isUTC ) : string
$value string the value, might be of the format 'Y-m-d H:i'
$isUTC boolean whether the given value is in UTC
return string the formatted result or an empty string on null value

formatFloat() public method

Formats a float to not display in scientific notation.
public formatFloat ( float $float ) : double | string
$float float the float to format
return double | string the formated float

formatTime() protected method

If the value is false (like null), an empty string is returned. Else, the value is tried to be parsed as datetime via the given pattern. If that fails, it is tried to be parsed with the pattern 'Y-m-d H:i:s'. If that fails, the value is returned unchanged. Else, it is returned formatted with the given pattern. The effect is to shorten 'Y-m-d H:i:s' to 'Y-m-d' for example.
protected formatTime ( string $value, string $timezone, string $pattern ) : string
$value string the value to be formatted
$timezone string the timezone of the value
$pattern string the pattern with which the value is parsed and formatted
return string the formatted value

getLanguageName() public method

Gets a language name in the given language.
public getLanguageName ( string $language ) : string
$language string the language code of the desired language name
return string the language name in the given language or null if not available

registerTwigExtensions() public method

Registers all extensions.
public registerTwigExtensions ( Pimple\Container $app )
$app Pimple\Container the current application