Skip to content

Repository files navigation

Inteve\Types

Build StatusDownloads this MonthLatest Stable VersionLicense

Value objects and helpers for PHP.

Donate

Installation

Download a latest package or use Composer:

composer require inteve/types

Inteve\Types requires PHP 8.0 or later.

Usage

DatabaseDataType

useInteve\Types\DatabaseDataType;
$type = newDatabaseDataType('INT', [10], ['UNSIGNED']);
$type->getType();
$type->getParameters();
$type->getOptions();
$type->hasOption('UNSIGNED'); // returns TRUE$type->getOptionValue('UNSINGED'); // returns mixed|NULL

HexColor

useInteve\Types\HexColor;
$color = newHexColor('0088FF');
$color->getValue(); // returns '0088ff'$color->getCssValue(); // returns '#0088ff'// from CSS color$color = HexColor::fromCssColor('#0088ff');

Html

useInteve\Types\Html;
$html = newHtml('<p>Lorem &gt; ipsum</p>');
$html->getHtml();
(string) $html; // alias for getHtml()$html->getPlainText(); // returns text without HTML tags & entities ('Lorem > ipsum')

It implements Nette\Utils\IHtmlString so can be used directly in Latte template ({$html}) without |noescape modifier.

Md5Hash

useInteve\Types\Md5Hash;
$md5 = newMd5Hash($hash);
$md5->getHash(); // returns $hash// from string$md5 = Md5Hash::from('Lorem ipsum dolor.');
// from file$md5 = Md5Hash::fromFile('/path/to/file');

PhpType

useInteve\Types\PhpType;
$type = newPhpType('bool');
$type->getType();
(string) $type; // alias for getType()$type->isBasicType(); // returns TRUE$type = newPhpType(PhpType::class);
$type->isBasicType(); // returns FALSE

You can use static factories:

$type = PhpType::arrayType();
$type = PhpType::boolType();
$type = PhpType::floatType();
$type = PhpType::intType();
$type = PhpType::stringType();
$type = PhpType::classType(PhpType::class);
$type = PhpType::fromParameterType(newPhpParameterType('string'));

It implements Inteve\Types\IPhpParameterType.

PhpParameterType

useInteve\Types\PhpParameterType;
$type = newPhpParameterType('bool');
$type->getType();
(string) $type; // alias for getType()$type->isBasicType(); // returns TRUE$type = newPhpParameterType(PhpParameterType::class);
$type->isBasicType(); // returns FALSE

You can use static factories:

$type = PhpParameterType::arrayType();
$type = PhpParameterType::boolType();
$type = PhpParameterType::floatType();
$type = PhpParameterType::intType();
$type = PhpParameterType::stringType();
$type = PhpParameterType::callableType();
$type = PhpParameterType::iterableType();
$type = PhpParameterType::selfType();
$type = PhpParameterType::objectType();
$type = PhpParameterType::classType(PhpParameterType::class);
$type = PhpParameterType::fromPhpType(newPhpType('string'));

It implements Inteve\Types\IPhpParameterType.

Url

useInteve\Types\Url;
$url = newUrl('https://example.com/page');
$url->getUrl();
(string) $url; // alias for getUrl()

License: New BSD License
Author: Jan Pecha, https://www.janpecha.cz/

About

Value objects and helpers for PHP.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages