CRUDlex\Entity::get PHP Méthode

get() public méthode

Gets the value of a field in its specific type.
public get ( string $field ) : mixed
$field string the field
Résultat mixed null on invalid field, an integer if the definition says that the type of the field is an integer, a boolean if the field is a boolean or else the raw value
    public function get($field)
    {
        if ($this->definition->getField($field, 'value') !== null) {
            return $this->definition->getField($field, 'value');
        }
        if (!array_key_exists($field, $this->entity)) {
            return null;
        }
        $type = $this->definition->getType($field);
        $value = $this->toType($this->entity[$field], $type);
        return $value;
    }

Usage Example

Exemple #1
0
 /**
  * Performs the regular unique validation.
  *
  * @param $value
  * the value to validate
  * @param $data
  * the data instance to validate with
  * @param $entity
  * the entity of the field
  * @param $field
  * the field to validate
  *
  * @return boolean
  * true if everything is valid
  */
 protected function isValidUnique($value, AbstractData $data, Entity $entity, $field)
 {
     $params = [$field => $value];
     $paramsOperators = [$field => '='];
     if ($entity->get('id') !== null) {
         $params['id'] = $entity->get('id');
         $paramsOperators['id'] = '!=';
     }
     $amount = intval($data->countBy($data->getDefinition()->getTable(), $params, $paramsOperators, true));
     return $amount == 0;
 }
All Usage Examples Of CRUDlex\Entity::get