Day of week library
Please read the docs of php-enum first.
use Hrevert\Day\Day;
/** @var Day */
$day = Day::get(Day::MONDAY);
// or $day = Day::MONDAY();
// or $day = Day::getByName('MONDAY');
// or $day = Day::getByOrdinal(1); i.e. find by ISO-8601 numeric representation of day
/** @var Day */
$today = Day::getToday();
use Hrevert\Day\Day;
use Hrevert\Day\DayCollection;
$days = new DayCollection([Day::SUNDAY(), Day::MONDAY()]);
var_dump($days->contains(Day::SUNDAY())); // bool(true)
var_dump($days->contains(Day::MONDAY())); // bool(true)
$days->remove(Day::MONDAY());
var_dump($days->contains(Day::MONDAY())); // bool(false)
$days->add(Day::MONDAY());
var_dump($days->contains(Day::MONDAY())); // bool(true)
Since Hrevert\Day\DayCollection
is just an extension of Doctrine\Common\Collections\ArrayCollection
, it should not be so difficult.
use Hrevert\Day\Day;
echo '<select name="day">';
foreach (Day::getOptions() as $iso => $display) {
echo '<option value="' . $iso . '">' . $display . '</option>';
}
echo '</select>';
// on form submit
/** @var Hrevert\Day\Day */
$day = Hrevert\Day\Day::get((int) $_POST['day']);