now.php 685 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Clock;
  11. if (!\function_exists(now::class)) {
  12. /**
  13. * @throws \DateMalformedStringException When the modifier is invalid
  14. */
  15. function now(string $modifier = 'now'): DatePoint
  16. {
  17. if ('now' !== $modifier) {
  18. return new DatePoint($modifier);
  19. }
  20. $now = Clock::get()->now();
  21. return $now instanceof DatePoint ? $now : DatePoint::createFromInterface($now);
  22. }
  23. }