public static function key($values = null)
{
$key = static::meta('key');
if ($values === null) {
return $key;
}
$self = static::_object();
$entity = $self->_classes['entity'];
if (is_object($values) && is_string($key)) {
return static::_key($key, $values, $entity);
} elseif ($values instanceof $entity) {
$values = $values->to('array');
}
if (!is_array($values) && !is_array($key)) {
return array($key => $values);
}
$key = (array) $key;
$result = array();
foreach ($key as $value) {
if (!isset($values[$value])) {
return null;
}
$result[$value] = $values[$value];
}
return $result;
}