1. Go to this page and download the library: Download fortuneglobe/types library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fortuneglobe / types example snippets
class ClientId extends AbstractStringType
{
public static function isValid( string $value ): bool
{
return $value !== '';
}
}
class ChannelId extends AbstractStringType
{
public static function isValid( string $value ): bool
{
return $value !== '';
}
}
$clientId = new ClientId( 'gmo' );
$anotherClientId = new ClientId( 'gmo' );
$yetAnotherClientId = new ClientId( 'maerz' );
$channelId = new ChannelId( 'gmo' );
$anotherChannelId = new ChannelId( 'zalando' );
$clientId->equals( $anotherClientId ) //true
$clientId->equals( $yetAnotherClientId ) //false
$clientId->equals( $channelId ) //false
$clientId->equalsValue( $channelId ) //true
$clientId->equalsValue( 'gmo' ) //true
$newClientId = ClientId::fromStringType( $anotherChannelId );
get_class( $newClientId ); //ClientId
$newClientId->toString(); //zalando
(string)$newClientId; //zalando
class Quantity extends AbstractStringType
{
public static function isValid( int $value ): bool
{
return $value > 0;
}
}
$quantityOfFirstItem = new Quantity( 2 );
$quantityOfSecondItem = new Quantity( 5 );
$totalQuantity = $quantityOfFirstItem->add( $quantityOfSecondItem ); //7
$difference = $quantityOfFirstItem->subtract( $quantityOfSecondItem ); //throws ValidationException
$difference = $quantityOfSecondItem->subtract( $quantityOfFirstItem ); //3
$incrementedQuantity = $quantityOfFirstItem->increment( $quantityOfSecondItem ); //7
class FulfillmentId extends Uuid4
{
}
$fulfillmentId = FulfillmentId::generate(); //some UUID4
$anotherFulfillmentId = new FulfillmentId( '9b856c0e-610a-4e38-9ea6-b9ac63cfb521' );
$uuid4 = (string)Uuid4::generate();
class UpdatedOn extends AbstractDateType
{
public static function isValid( \DateTimeInterface $value ): bool
{
return true;
}
}
$updatedOn = new UpdatedOn('2023-07-07 08:01:20', new \DateTimeZone( '+0200' ) ))->toString() ); //some UUID4
$updatedOn->hasExpired(); //Checks if current date time is greater than date time of UpdatedOn. Returns boolean
$updatedOn->hasExpired( new \DateInterval('PT15M') ); //Checks if current date time is greater than date time of UpdatedOn and added \DateInterval. Returns boolean
$types = [
new AnyStringType( 'one' ),
new AnyStringType( 'two' ),
new AnotherStringType( 'three' ),
];
TypesToArrayHelper::toStringArray( $types ); // [ 'one', 'two', 'three' ]
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.