Exemplo n.º 1
0
 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();
 }
 private static final function sendItem(CommunicationItem $item)
 {
     if ($item->Sent) {
         Log::warning("Attempt blocked to send already sent email", "COMMS", ["CommunicationItemID" => $item->CommunicationItemID, "EmailProvider" => self::$emailProviderClassName]);
         return true;
     }
     $sendable = $item->getSendable();
     $providerClass = $sendable->getProviderClassName();
     $provider = self::getContainer()->getInstance($providerClass);
     if ($provider instanceof CaptureToCommunicationsProcessorInterface) {
         throw new InvalidProviderException();
     }
     try {
         $provider->send($sendable);
         $item->markSent();
     } catch (\Exception $exception) {
         $item->Status = CommunicationItem::STATUS_FAILED;
     }
     $item->markSent();
     $item->save();
     Log::debug("Sending communication by Email", "COMMS", ["CommunicationID" => $item->CommunicationID, "EmailProvider" => self::$emailProviderClassName]);
     return $item->Status == CommunicationItem::STATUS_SENT;
 }
 public function testMessageIsIndented()
 {
     Log::indent();
     Log::debug("Indented Message", "test");
     $this->assertEquals("    Indented Message", $this->log->entries[0][0]);
 }
Exemplo n.º 4
0
 /**
  * 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;
 }
Exemplo n.º 5
0
 /**
  * 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;
 }
Exemplo n.º 6
0
 *  limitations under the License.
 */
/**
 * execute-http.php is the entry point for all HTTP requests for Rhubarb applications.
 * The only exceptions to this are when webserver URL rewriting goes directly to
 * a resource for performance reasons, e.g. accessing static content like images
 * and CSS files.
 */
use Rhubarb\Crown\Logging\Log;
use Rhubarb\Crown\Module;
// Change the working directory to the top level project folder.
chdir(__DIR__ . "/../../../../");
// Initiate our bootstrap script to boot all libraries required.
require_once __DIR__ . "/boot.php";
require_once __DIR__ . "/../src/Module.php";
require_once __DIR__ . "/../src/Context.php";
$request = \Rhubarb\Crown\Context::currentRequest();
try {
    // Pass control to the Module class and ask it to generate a response for the
    // incoming request.
    $response = Module::generateResponseForRequest($request);
    $response->send();
} catch (\Exception $er) {
    $context = new \Rhubarb\Crown\Context();
    if ($context->DeveloperMode) {
        Log::error($er->getMessage(), "ERROR");
        print "<pre>Exception: " . get_class($er) . "\nMessage: " . $er->getMessage() . "\nStack Trace:\n" . $er->getTraceAsString();
    }
}
Log::debug("Request Complete", "ROUTER");
Exemplo n.º 7
0
 public function testLogGetsHitWhenCorrectLevel()
 {
     Log::debug("This is a test", "test", ["a" => "b"]);
     $this->assertCount(0, $this->log->entries);
 }
Exemplo n.º 8
0
 protected function logSending()
 {
     $subject = $this->getSubject();
     $html = $this->getHtml();
     $text = $this->getText();
     Log::debug("Sending email `" . $subject . "` to recipients: " . $this->getRecipientList(), "EMAIL");
     Log::bulkData("Email content", "EMAIL", $this->getMailHeadersAsString() . "\r\n\r\n" . ($html != "") ? $html : $text);
 }