ZF\Apigility\Doctrine\Server\Resource\DoctrineResource::patchList PHP Method

patchList() public method

Respond to the PATCH method (partial update of existing entity) on a collection, i.e. update multiple entities in a collection.
public patchList ( array $data ) : array
$data array
return array
    public function patchList($data)
    {
        $return = new ArrayCollection();
        $results = $this->triggerDoctrineEvent(DoctrineResourceEvent::EVENT_PATCH_LIST_PRE, $data, $data);
        if ($results->last() instanceof ApiProblem) {
            return $results->last();
        }
        if (!$this->getObjectManager() instanceof EntityManagerInterface) {
            throw new InvalidArgumentException('Invalid Object Manager, must implement EntityManagerInterface');
        }
        $this->getObjectManager()->getConnection()->beginTransaction();
        foreach ($data as $row) {
            $result = $this->patch($row[$this->getEntityIdentifierName()], $row);
            if ($result instanceof ApiProblem) {
                $this->getObjectManager()->getConnection()->rollback();
                return $result;
            }
            $return->add($result);
        }
        $this->getObjectManager()->getConnection()->commit();
        $results = $this->triggerDoctrineEvent(DoctrineResourceEvent::EVENT_PATCH_LIST_POST, $return, $data);
        if ($results->last() instanceof ApiProblem) {
            return $results->last();
        }
        return $return;
    }