pamellayamada/pamytools

Enterprise-Grade Fault-Tolerant Web Scraper, Async Transport & Auto-Hydrating Engine for PHP 8.2+

Maintainers

Package info

github.com/PamellaYamada/Pamytools

pkg:composer/pamellayamada/pamytools

Transparency log

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.1 2026-08-01 18:54 UTC

This package is auto-updated.

Last update: 2026-08-01 18:54:42 UTC


README

Latest Stable Version Total Downloads License PHP Version Require

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.