enum() public static method

The main method for any enumeration, should be called statically Now also supports reordering/filtering
public static enum ( string | array | null $value, array $options, string | null $default = null ) : string | array
$value string | array | null Integer or array of keys or NULL for complete array result
$options array Options
$default string | null Default value
return string | array
示例#1
0
 /**
  * MyModelTest::testEnum()
  *
  * @return void
  */
 public function testEnum()
 {
     $array = [1 => 'foo', 2 => 'bar'];
     $res = Entity::enum(null, $array, false);
     $this->assertEquals($array, $res);
     $res = Entity::enum(2, $array, false);
     $this->assertEquals('bar', $res);
     $res = Entity::enum('2', $array, false);
     $this->assertEquals('bar', $res);
     $res = Entity::enum(3, $array, false);
     $this->assertFalse($res);
 }
 public static function statuses($value = null)
 {
     $options = [static::STATUS_ACTIVE => __d('tools', 'Active'), static::STATUS_PUBLISHED => __d('tools', 'Published'), static::STATUS_APPROVED => __d('tools', 'Approved'), static::STATUS_FLAGGED => __d('tools', 'Flagged')];
     return parent::enum($value, $options);
 }
示例#3
0
 public static function statuses($value = null)
 {
     $options = [static::STATUS_INACTIVE => 'Inactive', static::STATUS_ACTIVE => 'Active'];
     return parent::enum($value, $options);
 }
示例#4
0
 /**
  * Language::directions()
  *
  * @param mixed $value
  * @return mixed
  */
 public static function directions($value = null)
 {
     $options = [self::DIR_LTR => 'LTR', self::DIR_RTL => 'RTL'];
     return parent::enum($value, $options);
 }