PHP code example of saritasa / php-common

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

    

saritasa / php-common example snippets


class Gender extends Saritasa\Enum
{
    const MALE = 'Male';
    const FEMALE = 'Female';
}

$allGenders = Gender::getConstants();
$gender = new Gender($stringValue); // Will throw UnexpectedValueException on unknown value;
function getGenderDependentValue(Gender $gender) { ... }

/**
 * @property-read string $name Person full name
 * @property-read string $address Street address
 * @property-read string $city City
 * @property-read string $state State
 * @property-read string $zip Zip Code
 */
class Address extends Dto
{
    protected $name;
    protected $address;
    protected $city;
    protected $state;
    protected $zip;
}
...
$address = new Address($request->all()) // Read only Address fields from HTTP Request
$address->toArray() // Convert to assotiative array
$address->toJson()  // Serialize to JSON format


$isEmail = new RegExp('/\w+@\w+\.\w+/');
$result = $isEmail('test@it');
 vendor/bin/phpcs
 vendor/bin/phpcbf
 vendor/bin/phpunit
saritasa/php-common
bash
$ composer