/** * Erstellt "from" für eine Message * * Der $sender hat ein Default von Config[mail.from] * wenn das nicht gestzt ist, wird www@host genommen */ public static function from($sender = NULL) { if (!isset($sender) && ($sender = Config::get('mail.from')) == NULL) { $sender = 'www@' . PSC::getEnvironment()->getHostName(); } return self::recipient($sender); }
protected function log(\Exception $e, $contextInfo = NULL) { if ($e instanceof \ErrorException) { $errorType = self::$errors[$e->getSeverity()]; } else { $errorType = Code::getClass($e); } // wir müssen hier den error selbst loggen, da php nichts mehr macht (die faule banane) $php = NULL; $php .= 'PHP ' . $errorType . ': ' . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() . "\n"; $php .= $errorType . ': ' . \Psc\Exception::getExceptionText($e, 'text') . "\n"; error_log($php, 0); /* Debug-Mail */ $debug = NULL; $debug .= '[' . date('d.M.Y H:i:s') . "] "; $debug .= $errorType . ': ' . \Psc\Exception::getExceptionText($e, 'text') . "\n"; if ($e instanceof \Psc\Code\ErrorException) { $debug .= "\n" . $e->contextDump; } if (isset($contextInfo)) { $debug .= "\nContextInfo: \n" . $contextInfo; } if (isset($this->recipient) && !PSC::inTests()) { if ($ret = @mail($this->recipient, '[Psc-ErrorHandler] [' . $e->getCode() . '] ' . $e->getMessage(), $debug, 'From: www@' . PSC::getEnvironment()->getHostName() . "\r\n" . 'Content-Type: text/plain; charset=UTF-8' . "\r\n") === FALSE) { error_log('[\\Psc\\Code\\ErrorHandler.php:' . __LINE__ . '] Die Fehlerinformationen konnten nicht an den lokalen Mailer übergeben werden.', 0); } } }
public function testHandlerPrintsTextAndDelegatesToErrorHandler() { $handlerMock = $this->getMock('Psc\\Code\\ErrorHandler', array('handleCaughtException')); $handlerMock->expects($this->once())->method('handleCaughtException')->will($this->returnSelf()); PSC::getEnvironment()->setErrorHandler($handlerMock); $this->expectOutputRegex('/does not matter/'); Exception::handler(new Exception('does not matter')); }
public function testRegister() { $this->assertInstanceOf($this->c, PSC::registerErrorHandler()); $eh = PSC::getEnvironment()->getErrorHandler(); $this->assertEquals(\Psc\Config::get('debug.errorRecipient.mail'), $eh->getRecipient()); // denn das steht in der Config PSC::unregisterErrorHandler(); }
public function testToSubstr() { $env = PSC::getEnvironment(); $env->addIncludePath('/var/share/PEAR/'); $evil = '/var/share/'; $this->assertFalse($env->hasIncludePath($evil), 'hasIncludePath'); $this->assertInstanceOf('\\Psc\\Environment', $env->addIncludePath($evil), 'append'); $this->assertTrue($env->hasIncludePath($evil), 'hasIncludePath'); }
public function testWrappedConstructor() { $fileString = 'phar://' . ($pf = \Psc\PSC::getEnvironment()->isWindows() ? 'D:/' : '/') . 'does/not/matter/my.phar.gz/i/am/wrapped/class.php'; $file = new File($fileString); $this->assertEquals('php', $file->getExtension()); $this->assertEquals('class.php', $file->getName()); $this->assertEquals('phar://' . $pf . 'does/not/matter/my.phar.gz/i/am/wrapped/', (string) $file->getDirectory()); $this->assertEquals($fileString, (string) $file); }
public static function handler(\Exception $e) { try { $project = PSC::getProject(); } catch (\Exception $noProjet) { $project = NULL; } $format = PHP_SAPI === 'cli' ? 'text' : 'html'; $text = self::getExceptionText($e, $format, $project); print $text; PSC::getEnvironment()->getErrorHandler()->handleCaughtException($e); }
public static function escapeExecutable(File $executable) { $win = PSC::getEnvironment()->getOS() == Environment::WINDOWS; $script = (string) $executable; if ($win && mb_strpos($script, ' ')) { return '"' . $script . '"'; } elseif (!$win) { return addcslashes($script, '\\ '); } else { return $script; } }
/** * @return Response */ public function handle(Request $request) { $this->log($request->debug()); $this->request = $request; try { $serviceRequest = $this->createServiceRequest($this->request); $serviceResponse = $this->route($serviceRequest); $this->response = $this->convertResponse($serviceResponse); } catch (HTTPResponseException $e) { $this->response = Response::create($e->getCode(), $e->getResponseBody(), $e->getHeaders()); } catch (HTTPException $e) { // die darstellung sollte eigentlich woanders sein, nicht hier // eigentlich müssten wir hier auch request->content-type auswerten und response umwandeln $this->response = Response::create($e->getCode(), sprintf("%s\n\n%s\n%s", $e->getResponseBody(), $request->getResource(), $this->getDebugInfo()), $e->getHeaders()); } catch (NoServiceFoundException $e) { $this->logError($e, $this->debugLevel, 1); $e->setCode(404); $this->response = Response::create(404, sprintf("Es wurde kein Service für: %s gefunden\n\n%s", $request->getResource(), $this->getDebugInfo())); } catch (\Psc\CMS\Service\ControllerRouteException $e) { $this->logError($e, $this->debugLevel, 5); // nicht 1 da das mit dem Klassennamen ja schon "interna" sind $e->setCode(404); $this->response = Response::create(404, sprintf($e->getMessage() . "\n\n%s", $this->getDebugInfo())); } catch (\Exception $e) { $this->logError($e, $this->debugLevel, 1); $this->response = Response::create(500, sprintf("Es ist ein Fehler aufgetreten. URL: %s%s\n\n%s", $request->getResource(), $this->debugLevel >= 5 ? "\nFehler: " . $e->getMessage() : NULL, $this->getDebugInfo()), $this->getErrorMessageHeaders($e)); } if (isset($e)) { // oder halt code >= 400 if (!$this->isIgnoredError($e)) { $contextInfo = 'im RequestHandler. ' . "\n"; $contextInfo .= ' ' . $request->getMethod() . ' /' . implode('/', $request->getParts()) . "\n"; $contextInfo .= ' Accept: ' . $request->getHeaderField('Accept') . "\n"; $contextInfo .= ' Referer: ' . $request->getReferer() . "\n"; $contextInfo .= ' User-Agent: ' . $request->getUserAgent(); if (isset($this->contextInfo)) { $contextInfo .= "\n" . $this->contextInfo; } $contextInfo .= "\n\n" . $this->dumpRequest($request); \Psc\PSC::getEnvironment()->getErrorHandler()->handleCaughtException($e, $contextInfo); } } return $this->response; }
public function testEnvironmentInstance() { $this->assertInstanceOf('Psc\\Environment', PSC::getEnvironment()); }
public function __construct(WebforgeProject $project = NULL, DCPackage $dc = NULL, RightContent $rightContent = NULL, EntityService $entityService = NULL, $debugLevel = 5, FrontController $frontController = NULL, \Psc\Environment $env = NULL) { $this->environment = $env ?: PSC::getEnvironment(); $this->project = $project ?: PSC::getProject(); $this->dc = $dc; // getter injection, wegen EntityManager $this->debugLevel = $debugLevel; $this->entityService = $entityService; // getter injection $this->frontController = $frontController; // getter injection wegen services für requesthandler und debuglevel $this->rightContent = $rightContent; // getter injection }
public function useSSL() { if (PSC::getEnvironment()->getOS() === 'windows') { $this->setOption(CURLOPT_CAINFO, $this->getCABundle()); } return $this; }