PHP code example of kakaprodo / custom-data

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

    

kakaprodo / custom-data example snippets


class CreateUserData extends CustomData
{
    protected function expectedProperties(): array
    {
        return [
            'name' => $this->dataType()->string(),
            'email' => $this->dataType()->string(),
            'password' => $this->dataType()->string(),
            'age?' => $this->dataType()->string(),
            'sexe' => $this->dataType()->inArray(['M','F'])
        ];
    }
}

CreateUserData::make([
    'name' => 'kakaprodo',
    'email' => '[email protected]',
    'password' => 'is_unique_pass',
    'sexe' => 'M'
]);

class CreateUserAction extends CustomActionBuilder
{
   public function handle(CreateUserData $data)
   {
       return $data->onlyValidated();
   }
}

CreateUserAction::process([
    'name' => 'kakaprodo',
    'email' => '[email protected]',
    'password' => 'is_unique_pass',
    'sexe' => 'M'
]);