snapflowio/parser

A simple and lightweight library for parsing domains and DSN strings.

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/snapflowio/parser

v0.1.0 2025-12-16 18:57 UTC

This package is auto-updated.

Last update: 2025-12-16 19:03:18 UTC


README

A simple and lightweight library for parsing domains and DSN strings.

Installation

composer require snapflowio/parser

Quick Start

DSN Parsing

Parse Data Source Names (connection strings) for databases, APIs, and other services:

<?php

use Snapflow\Parser\DSN;

// Parse a database connection string
$dsn = new DSN('mysql://user:password@localhost:3306/myapp?charset=utf8mb4&timeout=30');

// Access connection details
echo $dsn->getScheme();    // mysql
echo $dsn->getUser();      // user
echo $dsn->getPassword();  // password
echo $dsn->getHost();      // localhost
echo $dsn->getPort();      // 3306
echo $dsn->getPath();      // myapp

// Get query parameters with optional defaults
echo $dsn->getParam('charset');           // utf8mb4
echo $dsn->getParam('timeout');           // 30
echo $dsn->getParam('pool_size', '10');   // 10 (default)

Domain Parsing

Parse domains using the Public Suffix List to extract TLD, registrable domain, and subdomains:

<?php

use Snapflow\Parser\Domain;

// Parse a domain with subdomain
$domain = new Domain('www.example.gov.ac');

// Extract domain components
echo $domain->get();              // www.example.gov.ac
echo $domain->getTLD();           // ac
echo $domain->getSuffix();        // gov.ac
echo $domain->getName();          // example
echo $domain->getRegisterable();  // example.gov.ac
echo $domain->getSub();           // www
echo $domain->getApex();          // example.gov.ac

// Check domain properties
echo $domain->isKnown();    // true (suffix exists in Public Suffix List)
echo $domain->isICANN();    // false
echo $domain->isPrivate();  // false
echo $domain->isTest();     // false

License

This library is available under the MIT License.

Copyright

Copyright (c) 2025 Snapflow