定制 thangvanowo/simple-library 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

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 camelCase
  • toSnakeCase(string $string) - Convert string to snake_case
  • generateRandomString(int $length = 10, string $characters = '...') - Generate random string
  • isAssociativeArray(array $array) - Check if array is associative
  • sanitizeString(string $string) - Clean and sanitize string
  • formatFileSize(int $bytes, int $precision = 2) - Format file size

Validator Class

  • isValidEmail(string $email) - Validate email address
  • isValidUrl(string $url) - Validate URL
  • isValidPhone(string $phone) - Validate phone number
  • isAlphaNumeric(string $string) - Check if string is alphanumeric
  • isValidDate(string $date, string $format = 'Y-m-d') - Validate date format
  • checkPasswordStrength(string $password, int $minLength = 8) - Check password strength

Testing

Run the tests with:

composer test

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-08