decorated = $decorated; } abstract public function supports($data, array $context = []): bool; public function persist($data, array $context = []) { $this->context = $context; $data = $this->preProcess($data); $this->prePersist($data); $result = $this->decorated->persist($data, $context); $this->postPersist($data); return $result; } protected function preProcess($data) { return $data; } protected function prePersist($data): void { } protected function postPersist($data): void { } abstract public function remove($data, array $context = []): void; protected function isPostRequest(): bool { return $this->context['collection_operation_name'] ?? null === 'post'; } protected function isPutRequest(): bool { return $this->context['item_operation_name'] ?? null === 'put'; } protected function previousData() { if (!$this->isPutRequest()) { return null; } return $this->context['previous_data']; } }