szurubooru/src/Models/Enums/AccessRank.php

42 lines
769 B
PHP
Raw Normal View History

2013-10-05 12:55:03 +02:00
<?php
2014-05-04 19:06:40 +02:00
class AccessRank extends Enum implements IValidatable
2013-10-05 12:55:03 +02:00
{
const Anonymous = 0;
const Registered = 1;
const PowerUser = 2;
const Moderator = 3;
const Admin = 4;
const Nobody = 5;
2014-05-04 19:06:40 +02:00
protected $accessRank;
public function __construct($accessRank)
{
$this->accessRank = $accessRank;
}
public function toInteger()
{
return $this->accessRank;
}
public function toString()
{
return self::_toString($this->accessRank);
}
public static function getAll()
{
return array_map(function($constantName)
{
return new self($constantName);
}, self::getAllConstants());
}
public function validate()
{
if (!in_array($this->accessRank, self::getAllConstants()))
throw new SimpleException('Invalid access rank "%s"', $this->accessRank);
}
2013-10-05 12:55:03 +02:00
}