syntatis / utils
PHP 的便捷函数
v1.5.1
2024-08-03 14:58 UTC
Requires
- php: >=7.4
- doctrine/inflector: ^2.0
- jawira/case-converter: ^3.5
- psr/http-message: ^1.0
- symfony/deprecation-contracts: ^2.5
Requires (Dev)
- composer/installers: ^2.3
- dealerdirect/phpcodesniffer-composer-installer: ^1.0
- league/uri: ^6.7
- phpcompatibility/php-compatibility: ^9.3
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^1.11
- phpstan/phpstan-deprecation-rules: ^1.2
- phpstan/phpstan-phpunit: ^1.4
- phpstan/phpstan-strict-rules: ^1.6
- phpunit/phpunit: ^9.6
- squizlabs/php_codesniffer: ^3.10
- symfony/var-dumper: >=5.4.40
- syntatis/coding-standard: ^1.4
README
syntatis/utils
包提供各种实用函数,以简化 PHP 中的常见任务,包括验证、大小写转换和词形变化。
安装
您可以通过 Composer 安装此包
composer require syntatis/utils
用法
验证器
此包包括多个用于验证值的函数,例如检查值是否为电子邮件、URL 或是否为空。
示例
use function Syntatis\Utils\Val; // Check if a value is blank or empty Val::isBlank(''); // true Val::isBlank(' '); // true Val::isBlank('foo '); // false // Check if a value is a valid email address Val::isEmail('example@example.com'); // true Val::isEmail('invalid-email'); // false
字符串
此包包括多个处理字符串的函数,例如将字符串转换为驼峰式、使单词变为复数或检查字符串是否以特定子串开头。
示例
use function Syntatis\Utils\Str; // Convert a string to camel case Str::toCamelCase('foo_bar'); // fooBar // Pluralize a word Str::toPlural('apple'); // apples // Check if a string starts with a specific substring Str::startsWith('Hello, World!', 'Hello'); // true