UserService.php 522 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. class UserService
  3. {
  4. /**
  5. * @var UserModel
  6. */
  7. protected $user;
  8. function __construct(UserModel $user)
  9. {
  10. $this->user = $user;
  11. }
  12. function create($name)
  13. {
  14. $this->user->setName($name);
  15. $this->user->set('role','user');
  16. $this->user->set('email',$name.'@service.com');
  17. $this->user->save();
  18. return true;
  19. }
  20. public static function validateName($name)
  21. {
  22. if ($name == 'admin') return false;
  23. return true;
  24. }
  25. }