BooleanStringFormatter.php 850 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\Migrations\Tools;
  4. use function strtolower;
  5. /**
  6. * The BooleanStringFormatter class is responsible for formatting a string boolean representation to a PHP boolean value.
  7. * It is used in the XmlConfiguration class to convert the string XML boolean value to a PHP boolean value.
  8. *
  9. * @internal
  10. *
  11. * @see Doctrine\Migrations\Configuration\XmlConfiguration
  12. */
  13. class BooleanStringFormatter
  14. {
  15. public static function toBoolean(string $value, bool $default): bool
  16. {
  17. switch (strtolower($value)) {
  18. case 'true':
  19. return true;
  20. case '1':
  21. return true;
  22. case 'false':
  23. return false;
  24. case '0':
  25. return false;
  26. default:
  27. return $default;
  28. }
  29. }
  30. }