datatypes/datatypes

Data type classes for PHP

v3.0.0 2022-03-14 17:15 UTC

This package is auto-updated.

Last update: 2024-04-16 19:44:03 UTC


README

Tests StyleCI License Latest Stable Version Total Downloads

Data Types is a collection of data types classes for PHP.

Requirements

  • PHP >= 8.0

Install with Composer

$ composer require datatypes/datatypes

Basic usage

<?php

use DataTypes\Net\EmailAddress;
use DataTypes\Net\Url;

require __DIR__ . '/vendor/autoload.php';

// Parse a url.
$url = Url::parse('https://www.example.com/foo/bar');

// Prints "https".
echo $url->getScheme();
// Prints "https://www.example.com/foo/bar?query".
echo $url->withQueryString('query');

$path = $url->getPath();

// Prints "/foo/bar".
echo $path;
// Prints "/foo/".
echo $path->getDirectory();

// Parse an email address.
$email = EmailAddress::parse('foo.bar@example.com');

// Prints "example.com".
echo $email->getHost();

// Returns false.
Url::isValid('foo');
// Returns null.
Url::tryParse('foo');
// Throws \DataTypes\Net\Exceptions\UrlInvalidArgumentException.
Url::parse('foo');

License

MIT