pocketmine\permission\BanEntry::fromString PHP Метод

fromString() публичный статический Метод

public static fromString ( string $str ) : BanEntry
$str string
Результат BanEntry
    public static function fromString($str)
    {
        if (strlen($str) < 2) {
            return null;
        } else {
            $str = explode("|", trim($str));
            $entry = new BanEntry(trim(array_shift($str)));
            if (count($str) > 0) {
                $entry->setCreated(\DateTime::createFromFormat(self::$format, array_shift($str)));
                if (count($str) > 0) {
                    $entry->setSource(trim(array_shift($str)));
                    if (count($str) > 0) {
                        $expire = trim(array_shift($str));
                        if (strtolower($expire) !== "forever" and strlen($expire) > 0) {
                            $entry->setExpires(\DateTime::createFromFormat(self::$format, $expire));
                        }
                        if (count($str) > 0) {
                            $entry->setReason(trim(array_shift($str)));
                        }
                    }
                }
            }
            return $entry;
        }
    }

Usage Example

Пример #1
0
 public function load()
 {
     $this->list = [];
     $fp = @\fopen($this->file, "r");
     if (\is_resource($fp)) {
         while (($line = \fgets($fp)) !== \false) {
             if ($line[0] !== "#") {
                 $entry = BanEntry::fromString($line);
                 if ($entry instanceof BanEntry) {
                     $this->list[$entry->getName()] = $entry;
                 }
             }
         }
         \fclose($fp);
     } else {
         MainLogger::getLogger()->error("Could not load ban list");
     }
 }