safronik / helpers
不同的助手,例如:IP、数组、数据、反射
0.1.2
2024-07-27 09:04 UTC
Requires
- php: >=8.2
- safronik/globals: ^0.1.0
This package is not auto-updated.
Last update: 2024-09-21 09:35:46 UTC
README
一个PHP库,以不同方式简化开发者的生活
关于
帮助操作如下事物
- 数组
- 缓冲区
- 数据
- 目录
- DNS
- HTTP
- IP
- 页面
- 反射
- 字符串
- 周围环境
- 时间
- 版本
安装
首选的安装方法是使用Composer。运行以下命令安装软件包并将其添加到项目的composer.json
中
composer require safronik/helpers
或者直接下载文件或克隆仓库(在这种情况下,您需要处理自动加载器)
使用方法
HelperArray
HelperArray::insert( $array_passed by_link, $insert_position, $insert_value); // Modifies the array $array. Paste $insert on $position
HelperData
$array_from_json = HelperData::unpackIfJSON( $json_data ); $token = HelperData::createToken(); // Generates UUID
HelperIP
get([ip_types: array|string[] = [...]], [v4_only: bool = true]): array|mixed|null getDecimal([ip: null|string = null]): int isPrivateNetwork(ip: string, [ip_type: string = 'v4']): bool isIPInMask(ip: string, cidr: array|string, [ip_type: string = 'v4'], [xtet_count: int = 0]): bool convertLongMaskToNumber(long_mask: int): int validate(ip: string): bool|string cidrValidate(cidr: string): bool normalizeIPv6(ip: string): string reduceIPv6(ip: string): string resolveIP(ip): string
HelperReflection
// Scan directory and its subdirectories. Could filter the set by different parameters HelperReflection::getClassesFromDirectory( directory: string, // Directory path namespace: string, // Directory namespace [exclusions: string[] = [...]], // Exclusions. Full strict comparison [filter: string = ''], // Positive filter (only string contains will be present in the result set) [recursive: bool = false], // Scan subdirectories [skip_infrastructure: bool = true], // Skip classes starts with '_' (underscore symbol) [filter_callback: callable|null = null] // Any callback you want to filter the result set. Other methods of self could be passed as a callback filter ): array // Filter everything except final classes from the given set HelperReflection::filterFinalClasses(classes): array // Filter everything except interfaces from the given set HelperReflection::getInterfacesFromDirectory(classes): array // Check if the given class use specific trait HelperReflection::isClassUseTrait(classname: string, trait: string): bool // Gets class traits HelperReflection::getClassTraits(classname: string): array // Filter everything except classes which are implement specific interface from the given set HelperReflection::filterClassesByInterface(classes: array, interface: string): array // // Check if the given class implements specific interface HelperReflection::isClassHasInterface(class: object|string, interface: string): bool
BufferHelper.php
getCSVMap(&csv: string): array parseCSV(&scv_string: string): array parseNSV(nsv_string: string): string[] convertCSVToArray(&csv: string, [map: array = [...]]): array convertCSVLineToArray(&csv: string, [map: array = [...]], [stripslashes: bool = false]): array cleanUpCSV(&buffer: array): array popCSVLine(&csv: string): string
DirHelper.php
isExist(path): bool isEmpty(path): bool create(path): void
DNSHelper.php
resolveHost(host: string): string
HTTPHelper.php
http__request(url: string, [data: array = [...]], [presets: array|null|string = null], [opts: array = [...]]): array|string[]|bool|int|string http__request__get_content(url: string): array|string[]|bool|int|mixed|string http__request__get_response_code(url: string): array|string[]|bool|int|mixed|string http__get_data_from_remote_gz(url: string): array|false|mixed|string get_data_from_local_gz(path: string): array|string[]|mixed|string http__download_remote_file(url, tmp_folder): array|string[]|bool|int|string http__download_remote_file__multi(urls: array, [write_to: string = '']): array|string[]
PageHelper.php
hasError(string_page): bool
StringHelper.php
removeNonUTF8(data: array|object|string): array|object|string toUTF8(data: array|object|string, [data_codepage: null|string = null]): array|object|string fromUTF8(obj: array|object|string, [data_codepage: null|string = null]): mixed
SurroundingHelper.php
isWindows(): bool
isExtensionLoaded(extension_name): bool
TimeHelper.php
getIntervalStart(interval: int): int
VersionHelper.php
isCorrectSemanticVersion(version: string): bool standardizeVersion(version): string compare(version1: string, version2: string): int