PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
BanEntry.php
1 <?php
2 
3 /*
4  *
5  * ____ _ _ __ __ _ __ __ ____
6  * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7  * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8  * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9  * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * @author PocketMine Team
17  * @link http://www.pocketmine.net/
18  *
19  *
20 */
21 
22 namespace pocketmine\permission;
23 
24 class BanEntry{
25  public static $format = "Y-m-d H:i:s O";
26 
27  private $name;
29  private $creationDate = null;
30  private $source = "(Unknown)";
32  private $expirationDate = null;
33  private $reason = "Banned by an operator.";
34 
35  public function __construct($name){
36  $this->name = strtolower($name);
37  $this->creationDate = new \DateTime();
38  }
39 
40  public function getName(){
41  return $this->name;
42  }
43 
44  public function getCreated(){
45  return $this->creationDate;
46  }
47 
48  public function setCreated(\DateTime $date){
49  $this->creationDate = $date;
50  }
51 
52  public function getSource(){
53  return $this->source;
54  }
55 
56  public function setSource($source){
57  $this->source = $source;
58  }
59 
60  public function getExpires(){
61  return $this->expirationDate;
62  }
63 
67  public function setExpires($date){
68  $this->expirationDate = $date;
69  }
70 
71  public function hasExpired(){
72  $now = new \DateTime();
73 
74  return $this->expirationDate === null ? false : $this->expirationDate < $now;
75  }
76 
77  public function getReason(){
78  return $this->reason;
79  }
80 
81  public function setReason($reason){
82  $this->reason = $reason;
83  }
84 
85  public function getString(){
86  $str = "";
87  $str .= $this->getName();
88  $str .= "|";
89  $str .= $this->getCreated()->format(self::$format);
90  $str .= "|";
91  $str .= $this->getSource();
92  $str .= "|";
93  $str .= $this->getExpires() === null ? "Forever" : $this->getExpires()->format(self::$format);
94  $str .= "|";
95  $str .= $this->getReason();
96 
97  return $str;
98  }
99 
105  public static function fromString($str){
106  if(strlen($str) < 2){
107  return null;
108  }else{
109  $str = explode("|", trim($str));
110  $entry = new BanEntry(trim(array_shift($str)));
111  if(count($str) > 0){
112  $entry->setCreated(\DateTime::createFromFormat(self::$format, array_shift($str)));
113  if(count($str) > 0){
114  $entry->setSource(trim(array_shift($str)));
115  if(count($str) > 0){
116  $expire = trim(array_shift($str));
117  if(strtolower($expire) !== "forever" and strlen($expire) > 0){
118  $entry->setExpires(\DateTime::createFromFormat(self::$format, $expire));
119  }
120  if(count($str) > 0){
121  $entry->setReason(trim(array_shift($str)));
122 
123  return $entry;
124  }else{
125  return $entry;
126  }
127  }
128  }else{
129  return $entry;
130  }
131  }else{
132  return $entry;
133  }
134  }
135  }
136 }
setExpires($date)
Definition: BanEntry.php:67
Definition: BanEntry.php:24
static fromString($str)
Definition: BanEntry.php:105