tereta / utilities
Lightweight utility helpers for the Tereta Framework: byte formatting, slug/template strings, CIDR matching, path normalization, and Factory-enabled DOMDocument/DOMXPath wrappers.
Requires
- php: >=8.4
- tereta/core: ^1.0.5
README
π Π ΡΡΡΠΊΠΈΠΉ | English
Overview
Lightweight utility module providing common helpers used across the application: math, string, network and filesystem-path primitives, plus Factory-trait wrappers around the native PHP DOM classes.
Services
Mathβ unit-conversion helpers.formatBytes(int $bytes)β human-readable byte formatting (1048576β1.00 MB; scales B β KB β MB β GB β TB).
Stringableβ string-oriented helpers.file(string $path, array $variables = [])β renders a.phtmltemplate withextract()ed variables and a second{key}placeholder pass. Path is hardened viarealpath()+is_file()to block path-traversal and null-byte injection.identifier(string $string)β normalises arbitrary text into a slug-likesnake_casetoken (lowercase, non-alphanumeric runs collapsed to_). Useful for cache keys, filenames, attribute names.code(string $code)β prepares a heredoc-style snippet for<pre>output: trims blank edge lines, removes the common leading indent, HTML-escapes the result.splitLines(string $string, int $length)β soft-wraps text at whitespace boundaries while preserving existing line breaks; counts length in Unicode code points.
Networkβ network-related helpers.cidrMatch(string $ip, string $cidr)β tests whether an IPv4 or IPv6 address falls within a CIDR range; returnsfalseon malformed input or family mismatch.isPortOpen(string $host, int $port, float $timeout = 5.0)β TCP probe viafsockopen.
Fileβ filesystem-path helpers (string-only, no I/O).path(string $path, ?string $allowBase = null)β collapses empty segments,.and..purely textually. When$allowBaseis provided, throwsRuntimeExceptionif the resolved path falls outside that base β handy for sandboxing user-supplied paths.
DOM wrappers (
Tereta\Utilities\DOMDocument,Tereta\Utilities\DOMXPath) β extend the native classes and add theTereta\Core\Traits\Factorytrait so they can be instantiated through the framework's DI factory pipeline.
Installation
composer require tereta/utilities
Author and License
Author: Tereta Alexander
Website: tereta.dev
License: Apache License 2.0. See LICENSE.
www.ββββββββββββββββββββββββ βββββββββββββββββ ββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββ
βββ ββββββ ββββββββββββββ βββ ββββββββ
βββ ββββββ ββββββββββββββ βββ ββββββββ
βββ βββββββββββ βββββββββββ βββ βββ βββ
βββ βββββββββββ βββββββββββ βββ βββ βββ
.dev
Copyright (c) 2008-2026 Tereta Alexander