Пример #1
0
 public function testSetsScheduleWeekend()
 {
     // Instead of starting out with an empty collection, EnumSet comes with a couple of convenient initialization methods
     // The of() static method will create a new collection and initialize it with the given enums
     $weekend = Websublime\Enum\EnumSet::of(Day::SATURDAY(), Day::SUNDAY());
     // Since we already have the weekend definition above, we can complement it, ending up with a collection of week days
     // This effectively generates a collection with all enums NOT present in the given set
     $weekdays = Websublime\Enum\EnumSet::complement($weekend);
     // An alternative way of generating the collection of week days is through a range using the range() static method
     $weekdays = Websublime\Enum\EnumSet::range(Day::MONDAY(), Day::FRIDAY());
     $weekdays = Websublime\Enum\EnumSet::range(Day::FRIDAY(), Day::MONDAY());
     // The order is insignificant
     // Lastly, it's possibly to fetch all enums by using the all() static method
     $all = Websublime\Enum\EnumSet::all('Day');
     // EnumSet too, supports binary flag/mask support
     $weekdays->getBinary();
     // Results in 31 (0x0000001F in hex or 00000000 00000000 00000000 00011111 in binary)
     // And alternatively, constructing an EnumSet using a binary mask
     $weekend = Websublime\Enum\EnumSet::byBinary('Day', 96);
     $this->assertInstanceOf('Websublime\\Enum\\EnumSet', $weekend);
     $this->assertInstanceOf('Websublime\\Enum\\EnumSet', $weekdays);
     $this->assertInstanceOf('Websublime\\Enum\\EnumSet', $all);
     // Iterating over a set
     foreach ($weekdays as $enum) {
         print 'Verbose testSetsScheduleWeekend: ' . $enum . PHP_EOL;
     }
 }