/** * Log a blocked submission * * @param \Tollwerk\TwAntibot\Validation\Exception $e Occured exception * @return \Tollwerk\TwAntibot\Domain\Model\Submission Submission */ protected function _logSubmission(\Tollwerk\TwAntibot\Validation\Exception $e) { $persistence = $this->_setup('persistence.'); // Readable reason switch (true) { case $e instanceof Exception\MissingTokenException: $reason = 'Missing token'; break; case $e instanceof Exception\InvalidTokenException: $reason = 'Invalid token'; break; case $e instanceof Exception\InvalidSettingsException: $reason = 'Invalid settings'; break; case $e instanceof Exception\InvalidRequestMethodOrderException: $reason = sprintf('Invalid request method (%s)', $e->getMessage()); break; case $e instanceof Exception\HoneypotException: $reason = sprintf('Honeypot alert (%s)', $e->getMessage()); break; case $e instanceof Exception\BotSmasherException: $badguy = array(); if ($e->ipMatch()) { $badguy[] = 'IP'; } if ($e->emailMatch()) { $badguy[] = 'email'; } if ($e->nameMatch()) { $badguy[] = 'name'; } $reason = sprintf('BotSmasher badguy (%s)', implode(',', $badguy)); break; default: $reason = 'Unknown'; break; } $submission = new \Tollwerk\TwAntibot\Domain\Model\Submission(); $submission->setReason($reason); $submission->setPid(intval($persistence['storagePid'])); $submission->setIp($this->_ip); $submission->setSettings(json_encode($this->_settings)); $submission->setData(json_encode($this->_data)); $submission->setFields(json_encode($this->_fields)); /* @var $submissionRepository \Tollwerk\TwAntibot\Domain\Repository\SubmissionRepository */ $submissionRepository = $this->_objectManager->get('Tollwerk\\TwAntibot\\Domain\\Repository\\SubmissionRepository'); $submissionRepository->add($submission); return $submission; }