Validators.php 948 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /*
  3. * This file is part of the Sonata package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  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 Sonata\AdminBundle\Command;
  11. class Validators
  12. {
  13. static public function validateUsername($username)
  14. {
  15. if (is_null($username)) {
  16. throw new \InvalidArgumentException('The username must be set');
  17. }
  18. return $username;
  19. }
  20. static public function validateEntityName($shortcut)
  21. {
  22. $entity = str_replace('/', '\\', $shortcut);
  23. if (false === $pos = strpos($entity, ':')) {
  24. throw new \InvalidArgumentException(sprintf('The entity name must contain a : ("%s" given, expecting something like AcmeBlogBundle:Post)', $entity));
  25. }
  26. return array(substr($entity, 0, $pos), substr($entity, $pos + 1));
  27. }
  28. }