Phalcon\Db\Adapter\MongoDB\Functions::isStringArray PHP Method

isStringArray() public static method

public static isStringArray ( $input ) : boolean
$input
return boolean
    public static function isStringArray($input)
    {
        if (!is_array($input)) {
            return false;
        }
        foreach ($input as $item) {
            if (!is_string($item)) {
                return false;
            }
        }
        return true;
    }

Usage Example

Example #1
0
 /**
  * Constructs a writable GridFS stream.
  *
  * Supported options:
  *
  *  * _id (mixed): File document identifier. Defaults to a new ObjectId.
  *
  *  * aliases (array of strings): DEPRECATED An array of aliases.
  *    Applications wishing to store aliases should add an aliases field to
  *    the metadata document instead.
  *
  *  * chunkSizeBytes (integer): The chunk size in bytes. Defaults to
  *    261120 (i.e. 255 KiB).
  *
  *  * contentType (string): DEPRECATED content type to be stored with the
  *    file. This information should now be added to the metadata.
  *
  *  * metadata (document): User data for the "metadata" field of the files
  *    collection document.
  *
  * @param CollectionWrapper $collectionWrapper GridFS collection wrapper
  * @param string            $filename Filename
  * @param array             $options Upload options
  *
  * @throws InvalidArgumentException
  */
 public function __construct(CollectionWrapper $collectionWrapper, $filename, array $options = [])
 {
     $options += ['_id' => new ObjectId(), 'chunkSizeBytes' => self::$defaultChunkSizeBytes];
     if (isset($options['aliases']) && !Functions::isStringArray($options['aliases'])) {
         throw InvalidArgumentException::invalidType('"aliases" option', $options['aliases'], 'array of strings');
     }
     if (isset($options['chunkSizeBytes']) && !is_integer($options['chunkSizeBytes'])) {
         throw InvalidArgumentException::invalidType('"chunkSizeBytes" option', $options['chunkSizeBytes'], 'integer');
     }
     if (isset($options['contentType']) && !is_string($options['contentType'])) {
         throw InvalidArgumentException::invalidType('"contentType" option', $options['contentType'], 'string');
     }
     if (isset($options['metadata']) && !is_array($options['metadata']) && !is_object($options['metadata'])) {
         throw InvalidArgumentException::invalidType('"metadata" option', $options['metadata'], 'array or object');
     }
     $this->chunkSize = $options['chunkSizeBytes'];
     $this->collectionWrapper = $collectionWrapper;
     $this->buffer = fopen('php://temp', 'w+');
     $this->ctx = hash_init('md5');
     $this->file = ['_id' => $options['_id'], 'chunkSize' => $this->chunkSize, 'filename' => (string) $filename, 'uploadDate' => new UTCDateTime(floor(microtime(true) * 1000))] + array_intersect_key($options, ['aliases' => 1, 'contentType' => 1, 'metadata' => 1]);
 }