SHARE
TWEET

Untitled

a guest Sep 4th, 2018 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     $domain = "iniquitous";
  3.  
  4.     class User {
  5.         private $type = "user";
  6.        
  7.         protected $id;
  8.         protected $username;
  9.         protected $password;
  10.        
  11.         public function __construct() {}
  12.        
  13.         public static function get_by_id($id) {
  14.             $instance = new self();
  15.             // Select user where id = $id;
  16.             return $instance;
  17.         }
  18.        
  19.         public function get_id() {
  20.             return $this->id;
  21.         }
  22.        
  23.         public function get_username() {
  24.             return $this->username;
  25.         }
  26.        
  27.         public static function create($username, $password) {
  28.             global $domain;
  29.            
  30.             $instance = new self();
  31.             $instance->id = uniqid($domain."_".$instance->type."_");
  32.             $instance->username = $username;
  33.             $instance->password = $password;
  34.             // Save to database;
  35.             return $instance;
  36.         }
  37.     }
  38.    
  39.     class Data {
  40.         private $type = "data";
  41.        
  42.         protected $id;
  43.         protected $created_by;
  44.         protected $created_on;
  45.        
  46.         public function __construct() {}
  47.        
  48.         public static function get_by_id($id) {
  49.             $instance = new self();
  50.             // Select data where id = $id;
  51.             return $instance;
  52.         }
  53.        
  54.         public function get_id() {
  55.             return $this->id;
  56.         }
  57.        
  58.         public function get_created_on() {
  59.             return $this->created_on;
  60.         }
  61.        
  62.         public function get_created_by() {
  63.             return $this->created_by;
  64.         }
  65.        
  66.         public static function create() {
  67.             global $domain;
  68.             global $user;
  69.            
  70.             $instance = new self();
  71.             $instance->id = uniqid($domain."_".$instance->type."_");
  72.            
  73.             $instance->created_by = $user->get_id();
  74.             $instance->created_on = time();
  75.             // Save to database
  76.             return $instance;
  77.         }
  78.     }
  79.    
  80.     $user = User::create("technics", "password");
  81.     echo "<p>".$user->get_id()."</p>";
  82.     echo "<p>".$user->get_username()."</p>";
  83.    
  84.     $data = Data::create();
  85.     echo "<p>".$data->get_id()."</p>";
  86.     echo "<p>".$data->get_created_by()."</p>";
  87.     echo "<p>".$data->get_created_on()."</p>";
  88. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top