Doctrine\ODM\CouchDB\UnitOfWork::getDocumentState PHP Method

getDocumentState() public method

Get the state of a document.
public getDocumentState ( object $document ) : integer
$document object
return integer
    public function getDocumentState($document)
    {
        $oid = \spl_object_hash($document);
        if (!isset($this->documentState[$oid])) {
            $class = $this->dm->getClassMetadata(get_class($document));
            $id = $class->getIdentifierValue($document);
            if (!$id) {
                return self::STATE_NEW;
            } else {
                if ($class->idGenerator == ClassMetadata::IDGENERATOR_ASSIGNED) {
                    if ($class->isVersioned) {
                        if ($class->getFieldValue($document, $class->versionField)) {
                            return self::STATE_DETACHED;
                        } else {
                            return self::STATE_NEW;
                        }
                    } else {
                        if ($this->tryGetById($id)) {
                            return self::STATE_DETACHED;
                        } else {
                            $response = $this->dm->getCouchDBClient()->findDocument($id);
                            if ($response->status == 404) {
                                return self::STATE_NEW;
                            } else {
                                return self::STATE_DETACHED;
                            }
                        }
                    }
                } else {
                    return self::STATE_DETACHED;
                }
            }
        }
        return $this->documentState[$oid];
    }