Last active
November 24, 2020 05:38
-
-
Save RayhanYulanda/370a5d91b33936642d70d3360b69d8e3 to your computer and use it in GitHub Desktop.
User good class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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