Jarves\Storage\AbstractStorage::normalizePrimaryKey PHP Method

normalizePrimaryKey() public method

Possible input: array('bla'), 'peter', 123, Output array('id' => 'bla'), array('id' => 'peter'), array('id' => 123) if the only primary key is named id.
public normalizePrimaryKey ( mixed $pk ) : array
$pk mixed
return array A single primary key as array. Example: array('id' => 1).
    public function normalizePrimaryKey($pk)
    {
        if (!is_array($pk)) {
            $result = array();
            $result[$this->primaryKeys[0]] = $pk;
        } elseif (is_numeric(key($pk))) {
            $result = array();
            $length = count($this->primaryKeys);
            for ($i = 0; $i < $length; $i++) {
                $result[$this->primaryKeys[$i]] = $pk[$i];
            }
        } else {
            $result = $pk;
        }
        if (count($this->primaryKeys) > count($result)) {
            foreach ($this->primaryKeys as $pk2) {
                if (!isset($result[$pk2])) {
                    $result[$pk2] = null;
                }
            }
        }
        return $result;
    }