FormUtil.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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\Form\Util;
  11. /**
  12. * @author Bernhard Schussek <bschussek@gmail.com>
  13. */
  14. class FormUtil
  15. {
  16. /**
  17. * This class should not be instantiated.
  18. */
  19. private function __construct()
  20. {
  21. }
  22. /**
  23. * Returns whether the given data is empty.
  24. *
  25. * This logic is reused multiple times throughout the processing of
  26. * a form and needs to be consistent. PHP keyword `empty` cannot
  27. * be used as it also considers 0 and "0" to be empty.
  28. *
  29. * @param mixed $data
  30. *
  31. * @return bool
  32. */
  33. public static function isEmpty($data)
  34. {
  35. // Should not do a check for [] === $data!!!
  36. // This method is used in occurrences where arrays are
  37. // not considered to be empty, ever.
  38. return null === $data || '' === $data;
  39. }
  40. }