$order) { if ( ! is_int($order) && ! is_float($order) && ! is_string($order)) { throw InvalidArgumentException::invalidType(sprintf('order value for "%s" field within "key" option', $fieldName), $order, 'numeric or string'); } } if ( ! isset($index['ns'])) { throw new InvalidArgumentException('Required "ns" option is missing from index specification'); } if ( ! is_string($index['ns'])) { throw InvalidArgumentException::invalidType('"ns" option', $index['ns'], 'string'); } if ( ! isset($index['name'])) { $index['name'] = \MongoDB\generate_index_name($index['key']); } if ( ! is_string($index['name'])) { throw InvalidArgumentException::invalidType('"name" option', $index['name'], 'string'); } $this->index = $index; } /** * Return the index name. * * @param string */ public function __toString() { return $this->index['name']; } /** * Serialize the index information to BSON for index creation. * * @see \MongoDB\Collection::createIndexes() * @see http://php.net/mongodb-bson-serializable.bsonserialize * @return array */ public function bsonSerialize() { return $this->index; } }