PHP code example of compono-kit / types

1. Go to this page and download the library: Download compono-kit/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/ */

    

compono-kit / types example snippets


   class MyString {
       use RepresentingString;
   }

   $str = new MyString("Hello World");
   echo $str->toUpperCase(); // "HELLO WORLD"
   

   abstract class AbstractEmail extends AbstractString {
       public static function isValid(string $value): bool {
           return filter_var($value, FILTER_VALIDATE_EMAIL) !== false;
       }
   }
   

   $string = new StringType("Hello World");
   echo $string->toUpperCase(); // "HELLO WORLD"
   

use ComponoKit\Types\StringType;

$string = new StringType("Hello World");

echo $string->toLowerCase();   // "hello world"
echo $string->capitalizeFirst(); // "Hello World"
echo $string->contains("World");  // true

use ComponoKit\Types\IntegerType;

$int = new IntegerType(42);

$int2 = $int->add(8); // 50
var_dump($int2->isPositive()); // true

use ComponoKit\Types\FloatType;

$float = new FloatType(3.14);

$float2 = $float->multiply(2); // 6.28
var_dump($float2->isGreaterThan(5.0)); // true

use ComponoKit\Types\BooleanType;

$bool = new BooleanType(true);

var_dump($bool->isTrue()); // true
var_dump($bool->toInteger()); // 1

use ComponoKit\Types\DateType;

$date = new DateType(new \DateTimeImmutable("2025-11-22"));

$tomorrow = $date->add(new \DateInterval('P1D'));
var_dump($tomorrow->isGreaterThan($date)); // true

$diff = $date->diff($tomorrow, false);
echo $diff->format('%d days'); // "1 days"

use ComponoKit\Types\Uuid4;

$uuid = Uuid4::generate();
echo $uuid->toString(); // e.g., "550e8400-e29b-41d4-a716-446655440000"