Phalcon\Db\Adapter\MongoDB\GridFS\Exception\FileNotFoundException::byId PHP Method

byId() public static method

Thrown when a file cannot be found by its ID.
public static byId ( mixed $id, string $namespace ) : self
$id mixed File ID
$namespace string Namespace for the files collection
return self
    public static function byId($id, $namespace)
    {
        $json = \MongoDB\BSON\toJSON(\MongoDB\BSON\fromPHP(['_id' => $id]));
        return new static(sprintf('File "%s" not found in "%s"', $json, $namespace));
    }

Usage Example

Beispiel #1
0
 /**
  * Renames the GridFS file with the specified ID.
  *
  * @param mixed  $id File ID
  * @param string $newFilename New filename
  *
  * @throws FileNotFoundException
  */
 public function rename($id, $newFilename)
 {
     $updateResult = $this->collectionWrapper->updateFilenameForId($id, $newFilename);
     if ($updateResult->getModifiedCount() === 1) {
         return;
     }
     /* If the update resulted in no modification, it's possible that the
      * file did not exist, in which case we must raise an error. Checking
      * the write result's matched count will be most efficient, but fall
      * back to a findOne operation if necessary (i.e. legacy writes).
      */
     $found = $updateResult->getMatchedCount() !== null ? $updateResult->getMatchedCount() === 1 : $this->collectionWrapper->findFileById($id) !== null;
     if (!$found) {
         throw FileNotFoundException::byId($id, $this->getFilesNamespace());
     }
 }
FileNotFoundException