Sokil\Mongo\Collection::hasDocument PHP Method

hasDocument() public method

Check if document belongs to collection
public hasDocument ( Document $document ) : type
$document Document
return type
    public function hasDocument(Document $document)
    {
        // check connection
        if ($document->getCollection()->getDatabase()->getClient()->getDsn() !== $this->getDatabase()->getClient()->getDsn()) {
            return false;
        }
        // check database
        if ($document->getCollection()->getDatabase()->getName() !== $this->getDatabase()->getName()) {
            return false;
        }
        // check collection
        return $document->getCollection()->getName() == $this->getName();
    }

Usage Example

Esempio n. 1
0
 /**
  * Check if document belongs to specified collection
  *
  * @deprecated since 1.12.8 Use Collection::hasDocument()
  * @param \Sokil\Mongo\Collection $collection collection instance
  * @return boolean
  */
 public function belongsToCollection(Collection $collection)
 {
     return $collection->hasDocument($this);
 }