Download the PHP package websitesql/utilities without Composer
On this page you can find all versions of the php package websitesql/utilities. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download websitesql/utilities
More information about websitesql/utilities
Files in websitesql/utilities
Package utilities
Short Description A lightweight set of utilities from Website SQL.
License MIT
Homepage https://www.websitesql.com
Informations about the package utilities
WebsiteSQL Utilities
A comprehensive collection of utility factory classes for common web development tasks.
Table of Contents
- WebsiteSQL Utilities
- Table of Contents
- Installation
- Usage
- Basic Setup
- UUID Generation
- String Manipulation
- DateTime Handling
- Pagination
- Security
- File Operations
- Validation
- API Reference
- UuidFactory
- StringFactory
- DateTimeFactory
- PaginationFactory
- SecurityFactory
- FileFactory
- ValidationFactory
- Contributing
- License
Installation
You can install the package via composer:
Usage
Basic Setup
The Utilities class serves as an entry point to access all other specialized factory classes. It provides static methods that instantiate and return factory objects for different domains.
UUID Generation
Generate and manipulate UUIDs of different versions:
String Manipulation
Perform various string operations with a fluent interface:
DateTime Handling
Manipulate dates and times with ease:
Pagination
Handle pagination and searching in arrays:
Security
Handle security-related operations:
File Operations
Work with files efficiently:
Validation
Validate user input:
API Reference
UuidFactory
| Method | Description |
|---|---|
generate(string $version = '4'): UuidFactory |
Generates a UUID of the specified version |
toString(): string |
Returns the UUID as a string |
fromString(string $uuid): UuidFactory |
Creates a UUID object from a string |
getVersion(): int |
Returns the UUID version |
StringFactory
| Method | Description |
|---|---|
random(int $length = 10, string $charset = 'alphanumeric'): StringFactory |
Generates a random string |
slugify(): StringFactory |
Converts a string to a URL-friendly slug |
encrypt(string $key, string $method = 'aes-256-cbc'): StringFactory |
Encrypts the string |
decrypt(string $key, string $method = 'aes-256-cbc'): StringFactory |
Decrypts the string |
truncate(int $length = 100, string $append = '...'): StringFactory |
Truncates the string to specified length |
toString(): string |
Returns the string value |
DateTimeFactory
| Method | Description |
|---|---|
format(string $format = 'Y-m-d H:i:s'): string |
Formats the date using the specified format |
timeAgo(): string |
Returns a human-readable time difference |
setTimezone(string $timezone): DateTimeFactory |
Sets the timezone |
modify(string $modifier): DateTimeFactory |
Modifies the date/time |
diff(string $datetime): \DateInterval |
Returns the difference between dates |
getDateTime(): DateTime |
Returns the PHP DateTime object |
toString(string $format = 'Y-m-d H:i:s'): string |
Returns the formatted date string |
PaginationFactory
| Method | Description |
|---|---|
setData(array $data): PaginationFactory |
Sets the data to paginate |
search(string $searchTerm, array $searchColumns = []): PaginationFactory |
Filters data by search term |
paginate(int $offset = 0, int $limit = 10): PaginationFactory |
Sets pagination parameters |
getResult(): array |
Returns the paginated results |
SecurityFactory
| Method | Description |
|---|---|
parseCookies(string $cookieHeader): array |
Parses cookies from a header string |
parseAuthorization(string $authorizationHeader): ?string |
Extracts token from Authorization header |
calculateExpiryDate(DateTime $createdAt, int $maxAge, int $refreshAge): DateTime |
Calculates token expiry date |
generateCookieHeader(string $name, string $value, array $options = []): string |
Generates a cookie header |
hashPassword(string $password): string |
Hashes a password using bcrypt |
verifyPassword(string $password, string $hash): bool |
Verifies a password against a hash |
generateCSRFToken(): string |
Generates a CSRF token |
validateCSRFToken(string $token, string $storedToken): bool |
Validates a CSRF token |
FileFactory
| Method | Description |
|---|---|
open(string $filePath = null, string $mode = 'r'): FileFactory |
Opens a file |
read(int $length = null): string |
Reads the file contents |
write(string $data): FileFactory |
Writes data to the file |
close(): void |
Closes the file handle |
readCsv(bool $hasHeader = true): array |
Reads and parses a CSV file |
writeCsv(array $data, bool $includeHeader = true): FileFactory |
Writes data to a CSV file |
ValidationFactory
| Method | Description |
|---|---|
date(string $date, string $format = 'm/d/Y', bool $strict = true): bool |
Validates a date string |
email(string $email): bool |
Validates an email address |
url(string $url): bool |
Validates a URL |
ip(string $ip): bool |
Validates an IP address |
required(string $value, string $fieldName): bool |
Checks if a value is not empty |
minLength(string $value, int $length, string $fieldName): bool |
Validates minimum string length |
maxLength(string $value, int $length, string $fieldName): bool |
Validates maximum string length |
numeric(string $value, string $fieldName): bool |
Validates if a value is numeric |
getErrors(): array |
Returns validation errors |
hasErrors(): bool |
Checks if there are validation errors |
clearErrors(): ValidationFactory |
Clears validation errors |
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
The MIT License (MIT). Please see the License File for more information.