public function send(Sendable $email) { $recipientList = $email->getRecipientList(); Log::debug("Sending message to " . $recipientList, "EMAIL"); mail($recipientList, $email->getSubject(), $email->getBodyRaw(), $email->getMailHeadersAsString(), "-f" . $email->getSender()->email); Log::indent(); Log::debug("Sent message to " . $recipientList, "EMAIL"); Log::outdent(); }
public function testLogCanIndent() { Log::indent(); Log::error("This is a test", "test"); $this->assertEquals(1, $this->log->entries[0][2]); Log::indent(); Log::error("This is a test", "test"); $this->assertEquals(2, $this->log->entries[1][2]); Log::outdent(); Log::error("This is a test", "test"); $this->assertEquals(1, $this->log->entries[2][2]); }
/** * Return the response when appropriate or false if no response could be generated. * * If child handlers are present they are given priority. * * @param mixed $request * @param bool|string $currentUrlFragment * @return bool|Response */ public function generateResponse($request = null, $currentUrlFragment = false) { if ($currentUrlFragment === false) { $currentUrlFragment = $request->urlPath; } if (!$this->matchesRequest($request, $currentUrlFragment)) { return false; } UrlHandler::setExecutingUrlHandler($this); Log::debug(function () { return "Handler " . get_class($this) . " selected to generate response"; }, "ROUTER"); Log::indent(); $context = new PhpContext(); $context->UrlHandler = $this; $this->matchingUrl = $this->getMatchingUrlFragment($request, $currentUrlFragment); if ($this->parentHandler) { $this->handledUrl = $this->parentHandler->handledUrl . $this->matchingUrl; } else { $this->handledUrl = $this->matchingUrl; } $childUrlFragment = substr($currentUrlFragment, strlen($this->matchingUrl)); foreach ($this->childUrlHandlers as $childHandler) { $response = $childHandler->generateResponse($request, $childUrlFragment); if ($response !== false) { return $response; } } $response = $this->generateResponseForRequest($request, $currentUrlFragment); Log::debug(function () use($response) { if ($response !== false) { return "Response generated by handler"; } return "Handler deferred generation"; }, "ROUTER"); Log::outdent(); return $response; }
/** * Generates the response content for the client. * * This is normally called by platform/execute-http.php and must be called after all * modules have been registered to guarantee the correct output. * * @static * @param Request $request * @return string|Response */ public final function generateResponseForRequest(Request $request) { $this->setAsRunningApplication(); $this->request = $request; $this->activeRequest = $request; $additionalData = []; if ($request instanceof WebRequest) { if (!empty($request->GetData)) { $additionalData = $request->GetData; } } Log::createEntry(Log::PERFORMANCE_LEVEL | Log::DEBUG_LEVEL, function () use($request) { if ($request instanceof WebRequest) { return "Generating response for url " . $request->urlPath; } if ($request instanceof CliRequest) { return "Starting CLI response"; } return ""; }, "ROUTER", $additionalData); Log::indent(); // an empty-string Response to fall back on if nothing else is generated $response = new HtmlResponse(); $response->setContent(''); $filterResponse = true; try { // Iterate over each handler and ask them to generate a response. // If they do return a response we return that and exit the loop. // If they return false then we assume they couldn't handle the URL // and continue to the next handler. foreach ($this->rootHandlers as $handler) { $generatedResponse = $handler->generateResponse($request); if ($generatedResponse !== false) { Log::debug(function () use($handler) { return ["Handler `" . get_class($handler) . "` generated response.", []]; }, "ROUTER"); // it should be preferred for a handler to return a Response object, // but checking this here retains the option for them to just return // their output if ($generatedResponse instanceof Response) { $response = $generatedResponse; } else { $response->setContent($generatedResponse); } break; } } } catch (ForceResponseException $er) { // Clear any previous output in buffers to ensure we only send the forced response while (ob_get_level()) { ob_end_clean(); } $response = $er->getResponse(); $filterResponse = false; } catch (StopGeneratingResponseException $er) { $filterResponse = false; } catch (RhubarbException $er) { $handler = $this->container()->getInstance(ExceptionHandler::class); $response = $handler->processException($er); } catch (\Exception $er) { $handler = $this->container()->getInstance(ExceptionHandler::class); $response = $handler->processException(new NonRhubarbException($er)); } if ($filterResponse) { Log::createEntry(Log::PERFORMANCE_LEVEL | Log::DEBUG_LEVEL, "Output filters started", "ROUTER"); Log::indent(); $filters = $this->getAllResponseFilters(); foreach ($filters as $filter) { $response = $filter->processResponse($response); } Log::createEntry(Log::PERFORMANCE_LEVEL | Log::DEBUG_LEVEL, "Output filters finished", "ROUTER"); Log::outdent(); } Log::performance("Response generated", "ROUTER"); Log::outdent(); return $response; }
/** * Generates the response content for the client. * * This is normally called by platform/execute-http.php and must be called after all * modules have been registered to guarantee the correct output. * * @static * @param Request\Request $request * @return string */ public static function generateResponseForRequest(Request\Request $request) { // Set the current request to be this one. $context = new Context(); $context->Request = $request; $additionalData = []; if ($request instanceof WebRequest) { if (!empty($request->GetData)) { $additionalData = $request->GetData; } } Log::createEntry(Log::PERFORMANCE_LEVEL | Log::DEBUG_LEVEL, function () use($request) { if ($request instanceof WebRequest) { return "Generating response for url " . $request->UrlPath; } if ($request instanceof CliRequest) { return "Starting CLI response"; } return ""; }, "ROUTER", $additionalData); Log::indent(); $handlers = self::getAllUrlHandlers(); // an empty-string Response to fall back on if nothing else is generated $response = new HtmlResponse(); $response->SetContent(''); $filterResponse = true; try { // Iterate over each handler and ask them to generate a response. // If they do return a response we return that and exit the loop. // If they return false then we assume they couldn't handle the URL // and continue to the next handler. foreach ($handlers as $handler) { $generatedResponse = $handler->generateResponse($request); if ($generatedResponse !== false) { Log::Debug(function () use($handler) { return ["Handler `" . get_class($handler) . "` generated response.", []]; }, "ROUTER"); // it should be preferred for a handler to return a Response object, // but checking this here retains the option for them to just return // their output if ($generatedResponse instanceof Response) { $response = $generatedResponse; } else { $response->setContent($generatedResponse); } break; } } } catch (ForceResponseException $er) { $response = $er->getResponse(); $filterResponse = false; } catch (StopGeneratingResponseException $er) { $filterResponse = false; } catch (RhubarbException $er) { $response = ExceptionHandler::processException($er); } catch (\Exception $er) { $response = ExceptionHandler::processException(new NonRhubarbException($er)); } if ($filterResponse) { Log::createEntry(Log::PERFORMANCE_LEVEL | Log::DEBUG_LEVEL, "Output filters started", "ROUTER"); Log::indent(); $filters = self::getAllResponseFilters(); foreach ($filters as $filter) { $response = $filter->processResponse($response); } Log::createEntry(Log::PERFORMANCE_LEVEL | Log::DEBUG_LEVEL, "Output filters finished", "ROUTER"); Log::outdent(); } Log::performance("Response generated", "ROUTER"); Log::outdent(); return $response; }