Lazer\Classes\Helpers\Validate::types PHP Method

types() public static method

Checking that types from array matching with [boolean, integer, string, double]
public static types ( array $types ) : boolean
$types array Indexed array
return boolean
    public static function types(array $types)
    {
        $defined = array('boolean', 'integer', 'string', 'double');
        $diff = array_diff($types, $defined);
        if (empty($diff)) {
            return TRUE;
        }
        throw new LazerException('Wrong types: "' . implode(', ', $diff) . '". Available "boolean, integer, string, double"');
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Add new fields to table, array schema like in create() function
  * @param array $fields Associative array
  */
 public function addFields(array $fields)
 {
     $fields = Helpers\Validate::arrToLower($fields);
     Helpers\Validate::types(array_values($fields));
     $schema = $this->schema();
     $fields = array_diff_assoc($fields, $schema);
     if (!empty($fields)) {
         $config = $this->config();
         $config->schema = array_merge($schema, $fields);
         $data = $this->getData();
         foreach ($data as $key => $object) {
             foreach ($fields as $name => $type) {
                 if (Helpers\Validate::isNumeric($type)) {
                     $data[$key]->{$name} = 0;
                 } else {
                     $data[$key]->{$name} = null;
                 }
             }
         }
         Helpers\Data::table($this->name)->put($data);
         Helpers\Config::table($this->name)->put($config);
     }
 }
All Usage Examples Of Lazer\Classes\Helpers\Validate::types