datatypes/datatypes

Data type classes for PHP

v2.1.0 2019-06-25 18:43 UTC

README

Build Status AppVeyor codecov.io StyleCI License Latest Stable Version Total Downloads

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

Requirements

  • PHP >= 7.1

Install with Composer

$ composer require datatypes/datatypes

Basic usage

<?php

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

// Parse a url.
$url = \DataTypes\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 = \DataTypes\EmailAddress::parse('foo.bar@example.com');

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

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

License

MIT