Newscoop\Utils\Validation::notEmpty PHP Метод

notEmpty() публичный статический Метод

Will throw exception if this is the case.
public static notEmpty ( mixed $parameter, string $name = 'unknown' )
$parameter mixed The parameter to check for nullity or empty.
$name string The parameter name used for displaying the exception default 'unknown'.
    public static function notEmpty($parameter, $name = 'unknown')
    {
        if (is_null($parameter)) {
            throw new \Exception("Please provide a value for the parameter '{$name}'.");
        } else {
            if (is_string($parameter) && trim($parameter) == '') {
                throw new \Exception("Please provide a none empty value for the parameter '{$name}'.");
            }
        }
    }

Usage Example

 function findByName($name)
 {
     Validation::notEmpty($name, 'name');
     $em = $this->getManager();
     $outputs = $em->getRepository($this->entityClassName)->findByName($name);
     if (isset($outputs) && count($outputs) > 0) {
         return $outputs[0];
     }
     return NULL;
 }
All Usage Examples Of Newscoop\Utils\Validation::notEmpty