thangvanowo/simple-library
Composer 安装命令:
composer require thangvanowo/simple-library
包简介
A simple PHP library for common utilities
README 文档
README
A simple PHP library providing common utility and validation functions.
Installation
You can install this library via Composer:
composer require thangvanowo/simple-library
Requirements
- PHP >= 7.4
Usage
Utility Class
The Utility class provides common string and array manipulation functions:
<?php require_once 'vendor/autoload.php'; use SimpleLibrary\Utility; // Convert to camelCase echo Utility::toCamelCase('hello_world'); // Output: helloWorld // Convert to snake_case echo Utility::toSnakeCase('HelloWorld'); // Output: hello_world // Generate random string echo Utility::generateRandomString(16); // Output: Random 16-character string // Check if array is associative $array = ['name' => 'John', 'age' => 30]; var_dump(Utility::isAssociativeArray($array)); // Output: true // Sanitize string echo Utility::sanitizeString('<p>Hello World</p>'); // Output: Hello World // Format file size echo Utility::formatFileSize(1024); // Output: 1.00 KB
Validator Class
The Validator class provides validation functions:
<?php use SimpleLibrary\Validator; // Validate email var_dump(Validator::isValidEmail('test@example.com')); // Output: true // Validate URL var_dump(Validator::isValidUrl('https://example.com')); // Output: true // Validate phone number var_dump(Validator::isValidPhone('+1234567890')); // Output: true // Check if string is alphanumeric var_dump(Validator::isAlphaNumeric('abc123')); // Output: true // Validate date format var_dump(Validator::isValidDate('2024-01-15', 'Y-m-d')); // Output: true // Check password strength $result = Validator::checkPasswordStrength('MyPassword123!'); echo $result['strength']; // Output: Strong
Available Methods
Utility Class
toCamelCase(string $string, string $separator = '_')- Convert string to camelCasetoSnakeCase(string $string)- Convert string to snake_casegenerateRandomString(int $length = 10, string $characters = '...')- Generate random stringisAssociativeArray(array $array)- Check if array is associativesanitizeString(string $string)- Clean and sanitize stringformatFileSize(int $bytes, int $precision = 2)- Format file size
Validator Class
isValidEmail(string $email)- Validate email addressisValidUrl(string $url)- Validate URLisValidPhone(string $phone)- Validate phone numberisAlphaNumeric(string $string)- Check if string is alphanumericisValidDate(string $date, string $format = 'Y-m-d')- Validate date formatcheckPasswordStrength(string $password, int $minLength = 8)- Check password strength
Testing
Run the tests with:
composer test
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
- Thang - thang@example.com
Changelog
1.0.0 - 2026-01-08
- Initial release
- Added Utility class with string and array manipulation methods
- Added Validator class with validation methods
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-08