Skip to content

Instantly share code, notes, and snippets.

@RayhanYulanda
Last active November 24, 2020 05:38
Show Gist options
  • Save RayhanYulanda/370a5d91b33936642d70d3360b69d8e3 to your computer and use it in GitHub Desktop.
Save RayhanYulanda/370a5d91b33936642d70d3360b69d8e3 to your computer and use it in GitHub Desktop.
User good class
<?php
class UserRequest {
protected static $rules = [
'name' => 'string',
'email' => 'string'
];
public static function validate($data){
foreach(static::$rules as $property => $type){
if (gettype($data[$property]) != $type)
throw new \Exception("User Property {$property} Must Be Of Type {$type}");
}
}
}
class Json{
public static function from($data){
return json_encode($data);
}
}
class User {
public $name;
public $email;
public function __construct($data) {
$this->name = $data['name'];
$this->email = $data['email'];
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment