pamellayamada / pamytools
Enterprise-Grade Fault-Tolerant Web Scraper, Async Transport & Auto-Hydrating Engine for PHP 8.2+
v1.0.1
2026-08-01 18:54 UTC
Requires
- php: >=8.2
- ext-curl: *
- ext-dom: *
- ext-json: *
- ext-libxml: *
Requires (Dev)
- phpunit/phpunit: ^10.0
README
Pamytools is a high-performance, fault-tolerant PHP 8.2+ framework designed for async HTTP transport, web scraping resilience via Circuit Breakers, and auto-hydration of HTML/Regex into typed DTOs using native PHP Attributes.
โจ Features
- โก Async HTTP Engine: High-concurrency native multi-cURL transport driver.
- ๐ก๏ธ Circuit Breaker Pattern: Prevent cascading failures with customizable thresholds.
- ๐ท๏ธ Native PHP Attributes: Declarative mapping of DOMXPath and Regex into strongly-typed DTOs.
- ๐ Built-in I18n: Multi-language exception and message translator out of the box (
pt-BR,en-US,es-ES). - ๐ ๏ธ SOLID Architecture: Clean, extensible interfaces designed for testability and high coverage.
๐ Requirements
- PHP:
^8.2 - Extensions:
ext-curl,ext-dom,ext-json,ext-libxml
๐ฆ Installation
Install the package via Composer:
composer require pamellayamada/pamytools
๐ Quick Start
1. Define your DTO with Native Attributes
Use #[ExtractPath] to declaratively map HTML elements or Regex patterns directly into your Data Transfer Object properties.
namespace App\DTOs; use Pamytools\Attributes\ExtractPath; final readonly class CompanyDTO { public function __construct( #[ExtractPath(query: "//h1[@class='title']")] public ?string $companyName, #[ExtractPath(query: '/token=([a-z0-9]+)/', type: 'regex')] public ?string $csrfToken ) {} }
2. Fetch & Auto-Hydrate with Resilience
Combine the async transport engine, the Circuit Breaker pattern, and the Data Hydrator into a seamless execution pipeline:
use App\DTOs\CompanyDTO; use Pamytools\Http\AsyncHttpEngine; use Pamytools\Resilience\CircuitBreaker; use Pamytools\Parser\DataHydrator; use Pamytools\I18n\Translator; // 1. Set global translation locale (Default: pt-BR. Available: en-US, es-ES, pt-BR) Translator::setLocale('en-US'); // 2. Initialize HTTP client and Circuit Breaker guard $http = new AsyncHttpEngine(); $breaker = new CircuitBreaker(serviceName: 'ExternalAPI', failureThreshold: 3); // 3. Execute request safely $response = $breaker->execute( fn() => $http->send('GET', 'https://example.com') ); // 4. Hydrate HTML directly into DTO $hydrator = new DataHydrator(); /** @var CompanyDTO $dto */ $dto = $hydrator->hydrate($response->body, CompanyDTO::class); echo $dto->companyName; // Outputs extracted text from //h1[@class='title']
๐๏ธ Project Architecture
pamytools/
โโโ .github/
โ โโโ workflows/
โ โโโ tests.yml <-- CI/CD Pipeline
โโโ lang/ <-- I18n Translation Dictionaries
โ โโโ en-US.json
โ โโโ es-ES.json
โ โโโ pt-BR.json
โโโ src/
โ โโโ Attributes/
โ โ โโโ ExtractPath.php <-- PHP 8.2+ Attribute definition
โ โโโ Contracts/
โ โ โโโ HttpClientInterface.php <-- SOLID Interfaces
โ โ โโโ HydratorInterface.php
โ โโโ Exception/
โ โ โโโ PamytoolsException.php <-- Translated Core Exceptions
โ โ โโโ CircuitBreakerOpenException.php
โ โ โโโ HydrationException.php
โ โโโ Http/
โ โ โโโ AsyncHttpEngine.php <-- Native Multi-cURL Driver
โ โ โโโ HttpResponse.php
โ โโโ I18n/
โ โ โโโ Translator.php <-- Global Translation Engine
โ โโโ Parser/
โ โ โโโ DataHydrator.php <-- Hydration Engine (DOMXPath/Regex)
โ โโโ Resilience/
โ โโโ CircuitBreaker.php <-- Circuit Breaker Guard
โโโ tests/ <-- PHPUnit Test Suite
๐งช Testing
Run tests with PHPUnit:
composer test
๐ License
This project is licensed under the MIT License.