Example #1
0
function Dwoo_Plugin_spacify_caps(Dwoo $dwoo, $text)
{
    return Inflector::spacifyCaps($text);
}
 public function validate($options)
 {
     // apply default
     $options = array_merge(array('validator' => 'string', 'required' => true), $options);
     // check 'field'
     if (empty($options['field'])) {
         die('FormValidator: required option "field" missing');
     }
     // check 'id' and default to 'field'
     if (empty($options['id'])) {
         if (is_array($options['field'])) {
             throw new Exception('Option "id" is required when option "field" is an array');
         } else {
             $options['id'] = $options['field'];
         }
     }
     // get validator
     if (is_string($options['validator'])) {
         $validator = array('Validators', $options['validator']);
     } else {
         $validator = $options['validator'];
     }
     // check validator
     if (!is_callable($validator)) {
         throw new Exception('Validator for field ' . $options['id'] . ' is not callable');
     }
     // return false if any errors are already registered under 'id'
     if (array_key_exists($options['id'], $this->_errors)) {
         return false;
     }
     // parse 'field' for multiple values and array paths
     if (is_array($options['field'])) {
         $value = array();
         foreach ($options['field'] as $field_single) {
             $value[] = $this->resolveValue($field_single);
         }
         // skip validation for empty fields that aren't required
         if (!$options['required'] && !count(array_filter($value))) {
             return true;
         }
     } else {
         $value = $this->resolveValue($options['field']);
         // skip validation for empty fields that aren't required
         if (!$options['required'] && empty($value)) {
             return true;
         }
     }
     // call validator
     $isValid = call_user_func($validator, $value, $options);
     if ($isValid == false) {
         if (!empty($options['errorMessage'])) {
             $this->_errors[$options['id']] = gettext($options['errorMessage']);
         } else {
             // default 'errorMessage' built from 'id'
             $this->_errors[$options['id']] = sprintf($options['required'] && empty($value) ? _('%s is missing.') : _('%s is invalid.'), Inflector::spacifyCaps($options['id']));
         }
         return false;
     } else {
         return true;
     }
 }
Example #3
0
 public static function getColumnHeader($field)
 {
     return !empty($field['label']) ? $field['label'] : Inflector::spacifyCaps($field['columnName']);
 }