Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class UserRegForm
- {
- private $username;
- private $password;
- private $confirm;
- private $email;
- public function getUsername()
- {
- return $this->username;
- }
- public function setUsername($username)
- {
- $this->username = $username;
- }
- public function getPassword()
- {
- return $this->password;
- }
- public function setPassword($password)
- {
- $this->password = $password;
- }
- public function getConfirm()
- {
- return $this->confirm;
- }
- public function setConfirm($confirm)
- {
- $this->confirm = $confirm;
- }
- public function getEmail()
- {
- return $this->email;
- }
- public function setEmail($email)
- {
- $this->email = $email;
- }
- }
- class UserController
- {
- public function registerPost(UserRegForm $form)
- {
- if ($form->getPassword() != $form->getConfirm()) {
- // do smth;
- }
- }
- }
- $form = new UserRegForm();
- $formInfo = new \ReflectionClass($form);
- foreach ($_POST as $key => $value) {
- if (!$formInfo->hasProperty($key)) {
- throw new Exception("POST malformed");
- }
- $setterMethod = 'set' . ucfirst($key);
- $form->$setterMethod($value);
- }
- $controller = new UserController();
- $controller->registerPost($form);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement