src/Leevel/Database/Ddd/UnitOfWork.php
protected function deleteEntity(IEntity $entity): IUnitOfWork
    {
        $this->validateClosed();

        $id = spl_object_id($entity);

        if (isset($this->entityCreates[$id])) {
            unset($this->entityCreates[$id], $this->entityStates[$id]);

            foreach (['createsFlagBefore', 'createsFlag', 'createsFlagAfter'] as $flag) {
                if (isset($this->{$flag}[$id])) {
                    unset($this->{$flag}[$id]);
                }
            }

            return $this;
        }

        if (isset($this->entityReplaces[$id])) {
            unset($this->entityReplaces[$id]);

            foreach (['replacesFlagBefore', 'replacesFlag', 'replacesFlagAfter'] as $flag) {
                if (isset($this->{$flag}[$id])) {
                    unset($this->{$flag}[$id]);
                }
            }

            if (!$entity->id()) {
                return $this;
            }
        }

        if (!$entity->id()) {
            $e = sprintf('Entity `%s` has no identity for delete.', get_class($entity));

            throw new InvalidArgumentException($e);
        }

        if (isset($this->entityUpdates[$id])) {
            unset($this->entityUpdates[$id]);

            foreach (['updatesFlagBefore', 'updatesFlag', 'updatesFlagAfter'] as $flag) {
                if (isset($this->{$flag}[$id])) {
                    unset($this->{$flag}[$id]);
                }
            }
        }

        if (isset($this->entityDeletes[$id])) {
            $e = sprintf('Entity `%s` cannot be deleted for twice.', get_class($entity));

            throw new InvalidArgumentException($e);
        }

        $this->entityDeletes[$id] = $entity;
        $this->entityStates[$id] = self::STATE_REMOVED;

        return $this;
    }
protected function deleteEntity(IEntity $entity): IUnitOfWork
    {
        $this->validateClosed();

        $id = spl_object_id($entity);

        if (isset($this->entityCreates[$id])) {
            unset($this->entityCreates[$id], $this->entityStates[$id]);

            foreach (['createsFlagBefore', 'createsFlag', 'createsFlagAfter'] as $flag) {
                if (isset($this->{$flag}[$id])) {
                    unset($this->{$flag}[$id]);
                }
            }

            return $this;
        }

        if (isset($this->entityReplaces[$id])) {
            unset($this->entityReplaces[$id]);

            foreach (['replacesFlagBefore', 'replacesFlag', 'replacesFlagAfter'] as $flag) {
                if (isset($this->{$flag}[$id])) {
                    unset($this->{$flag}[$id]);
                }
            }

            if (!$entity->id()) {
                return $this;
            }
        }

        if (!$entity->id()) {
            $e = sprintf('Entity `%s` has no identity for delete.', get_class($entity));

            throw new InvalidArgumentException($e);
        }

        if (isset($this->entityUpdates[$id])) {
            unset($this->entityUpdates[$id]);

            foreach (['updatesFlagBefore', 'updatesFlag', 'updatesFlagAfter'] as $flag) {
                if (isset($this->{$flag}[$id])) {
                    unset($this->{$flag}[$id]);
                }
            }
        }

        if (isset($this->entityDeletes[$id])) {
            $e = sprintf('Entity `%s` cannot be deleted for twice.', get_class($entity));

            throw new InvalidArgumentException($e);
        }

        $this->entityDeletes[$id] = $entity;
        $this->entityStates[$id] = self::STATE_REMOVED;

        return $this;
    }
注册删除实体.

@param \Leevel\Database\Ddd\IEntity $entity

@return $this