/** * Execute the insert query and persist the GridFSFile if necessary. * * @see Collection::doInsert() * @param array $a * @param array $options * @return mixed */ protected function doInsert(array &$a, array $options = []) { // If there is no file, perform a basic insertion if (!isset($a['file'])) { parent::doInsert($a, $options); return; } /* If the file is dirty (i.e. it must be persisted), delegate to the * storeFile() method. Otherwise, perform a basic insertion. */ $file = $a['file']; // instanceof GridFSFile unset($a['file']); if ($file->isDirty()) { $this->storeFile($file, $a, $options); } else { parent::doInsert($a, $options); } $a['file'] = $file; return $a; }