src/Bandolier/Type/Collection.php
public function setItem($obj, $key = null)
    {
        if (!$key) {
            throw new KeyInvalidException("A key is required.");
        } elseif (!is_string($key)) {
            throw new KeyInvalidException("The key should be a string.");
        } else {
            if (!array_key_exists($key, $this->getItems())) {
                throw new KeyInvalidException("Invalid key $key.");
            }
            $this->items[$key] = $obj;
        }

        return $this;
    }
public function setItem($obj, $key = null)
    {
        if (!$key) {
            throw new KeyInvalidException("A key is required.");
        } elseif (!is_string($key)) {
            throw new KeyInvalidException("The key should be a string.");
        } else {
            if (!array_key_exists($key, $this->getItems())) {
                throw new KeyInvalidException("Invalid key $key.");
            }
            $this->items[$key] = $obj;
        }

        return $this;
    }
public function setItem ( $ obj , $ key = null ) { if ( ! $ key ) { throw new KeyInvalidException ( "A key is required." ) ; } elseif ( ! is_string ( $ key ) ) { throw new KeyInvalidException ( "The key should be a string." ) ; } else { if ( ! array_key_exists ( $ key , $ this -> getItems ( ) ) ) { throw new KeyInvalidException ( "Invalid key $key." ) ; } $ this -> items [ $ key ] = $ obj ; } return $ this ; }
Set a collection item by key
@param $obj
@param mixed $key
@return $this
@throws KeyInvalidException
Set a collection item by key