backend-01

commit 69ca9023e334a6ee88856de44e812ff36d9d30e1

Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>

models: add an abstract base class

 app/models/Base.php | 17 +++++++++++++++++
 app/models/User.php | 19 ++++++++++++-------


diff --git a/app/models/Base.php b/app/models/Base.php
new file mode 100644
index 0000000000000000000000000000000000000000..581e1ec647e35a815c68182533448ca76e773c75
--- /dev/null
+++ b/app/models/Base.php
@@ -0,0 +1,17 @@
+<?php
+
+abstract class Base {
+  protected $id;
+
+  public function isPersisted() {
+    return !empty($this->id);
+  }
+
+  public function getId() {
+    return $this->id;
+  }
+
+  public function setId($id) {
+    $this->id = $id;
+  }
+}




diff --git a/app/models/User.php b/app/models/User.php
index 25d7845fab506733857cc6c3a7367e52639a2689..2f26326ffbc45b5562e36b368ce37e6371e77f1b 100644
--- a/app/models/User.php
+++ b/app/models/User.php
@@ -1,14 +1,15 @@
 <?php
 
-class User {
-  private $id;
-  private $name;
+require_once __DIR__ . '/Base.php';
+
+class User extends Base {
+  private $userName;
   private $email;
   private $encryptedPassword;
 
-  public function __construct($id, $name, $email, $encryptedPassword) {
+  public function __construct($id, $userName, $email, $encryptedPassword) {
     $this->id = $id;
-    $this->name = $name;
+    $this->userName = $userName;
     $this->email = $email;
     $this->encryptedPassword = $encryptedPassword;
   }
@@ -21,11 +22,15 @@   public function getId() {
     return $this->id;
   }
 
-  public function getName() {
-    return $this->name;
+  public function getUserName() {
+    return $this->userName;
   }
 
   public function getEmail() {
     return $this->email;
+  }
+
+  public function getEncryptedPassword() {
+    return $this->encryptedPassword;
   }
 }