Tools\Model\Table\Table::validateIdentical PHP Method

validateIdentical() public method

Options: - compare: field to compare to - cast: if casting should be applied to both values
public validateIdentical ( mixed $value, array | string $options = [], array $context = [] ) : boolean
$value mixed
$options array | string
$context array
return boolean Success
    public function validateIdentical($value, $options = [], array $context = [])
    {
        if (!is_array($options)) {
            $options = ['compare' => $options];
        }
        if (!isset($context['data'][$options['compare']])) {
            return false;
        }
        $compareValue = $context['data'][$options['compare']];
        $matching = ['string' => 'string', 'int' => 'integer', 'float' => 'float', 'bool' => 'boolean'];
        if (!empty($options['cast']) && array_key_exists($options['cast'], $matching)) {
            // cast values to string/int/float/bool if desired
            settype($compareValue, $matching[$options['cast']]);
            settype($value, $matching[$options['cast']]);
        }
        return $compareValue === $value;
    }