public function testGetClass() { $std = new \Psc\Exception('Standard'); $this->assertEquals('Psc\\Exception', $std->getClass()); $special = new MySpecialException('spec'); $this->assertEquals('Psc\\MySpecialException', $special->getClass()); }
public function __construct($message, $code, $severity, $filename, $line) { parent::__construct($message, $code); $this->severity = $severity; $this->file = $filename; $this->line = $line; }
public function init() { $this->rows = $this->cache->load('excelRows', $loaded); if ($this->updateCache) { $this->logger->write('Force '); } if (!$loaded || $this->updateCache) { $this->logger->writeln('Updating Cache'); $this->reader->setLoadSheetsOnly(array($this->getWorksheet())); parent::init(); parent::process(); // parse excelSheet $this->rows = $this->getData()->get('rows'); if (count($this->rows) == 0) { if (count($this->columnMapping) === 0) { throw new \Psc\Exception('Es kann nichts importiert werden, da keine ColumnMappings gesetzt worden sind'); } else { throw \Psc\Exception::create("Im Excel wurden keine Zeilen gefunden. Worksheet: '%s' ", $this->getWorksheet()); } } $this->cache->store('excelRows', serialize($this->rows))->hit('excelRows'); $this->cache->persist(); // in Datei abspeichern } else { /* phpexcel lässt sich nicht gern exporten, deshalb serializieren wir hier noch */ $this->rows = unserialize($this->rows); $this->logger->writeln('Loaded from Cache'); } }
/** * $this->invalidArgument(1, $param1, 'PositiveInteger', __FUNCTION__); * @param string|Type $expected der Type oder ein String der den Typ beschreibt * @cc-ignore */ protected function invalidArgument($num, $actual, $expected, $function) { $class = Code::getClass($this); $namespace = Code::getNamespace($class); $context = $class . '::' . $function . '()'; $expandType = function ($type) use($class, $namespace) { if (is_string($type)) { $type = Type::create($type); if ($type instanceof ObjectType) { $type->expandNamespace($namespace); } } return $type; }; if (is_array($expected)) { $composite = Type::create('Composite'); foreach ($expected as $type) { $composite->addComponent($expandType($type)); } $expected = $composite; } else { $expected = $expandType($expected); } return Exception::invalidArgument($num, $context, $actual, $expected); }
public function testExceptionText_noticesPreviousException() { $text = Exception::getExceptionText($this->createFullException(), 'text'); $this->assertContains('Previous Exception', $text); $html = Exception::getExceptionText($this->createFullException(), 'html'); $this->assertContains('Previous Exception', $html); }
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 logError(\Exception $e, $detailLevel = 1, $level = 1) { if ($detailLevel >= 5) { return $this->log("\n" . 'ERROR: ' . \Psc\Exception::getExceptionText($e, 'text')); } else { return $this->log("\n" . 'ERROR: Exception: ' . $e->getMessage(), $level); } }
public function __construct(array $exceptions) { $this->setExceptions($exceptions); $msg = "Exception List with Exceptions:\n"; foreach ($exceptions as $key => $exception) { $msg .= sprintf(" #%d %s\n", $key + 1, $exception->getMessage()); } parent::__construct($msg); }
public function __construct($message = "", $code = 0, \Exception $previous = NULL) { if (is_array($message)) { $this->keys = $message; $ccode = '$conf' . A::join($this->keys, "['%s']"); $message = sprintf("Cannot read variable: '%s' from config. Put %s to your config.php", implode('.', $this->keys), $ccode); $this->phpCode = $ccode . ' = NULL;'; } parent::__construct($message, $code, $previous); }
public static function getExceptionText(\Exception $e, $format = 'html', $project = NULL, $label = 'ROOT') { // webforge-common extends much cooler, don't type $project here $cr = $format == 'html' ? "<br />" : "\n"; if (isset($project)) { // versuche die Pfade übersichtlich zu machen $root = $project->getRootDirectory(); $trace = str_replace(array((string) $root, "\n"), array('{' . $label . '}' . DIRECTORY_SEPARATOR, $cr), $e->getTraceAsString()); $file = str_replace(array((string) $root), array('{' . $label . '}' . DIRECTORY_SEPARATOR), $e->getFile()); } else { $trace = $e->getTraceAsString(); $file = $e->getFile(); } $text = NULL; if ($format == 'html') { $text = '<pre class="php-error">' . "\n"; $text .= $cr . '<b>Fatal Error:</b> '; } $text .= 'Uncaught exception \'' . get_class($e) . '\' with message:' . $cr; if ($e instanceof \Psc\Code\ExceptionExportable) { $text .= str_replace("\n", $cr, wordwrap($e->exportExceptionText(), 140, "\n")) . $cr; } else { $text .= "'" . str_replace("\n", $cr, wordwrap($e->getMessage(), 140, "\n")) . "'" . $cr; } $text .= 'in ' . $file . ':' . $e->getLine() . $cr; $text .= 'StackTrace: ' . $cr . $trace . $cr; if ($format == 'html') { $text .= 'in <b>' . $file . ':' . $e->getLine() . '</b>' . '</pre>'; } else { $text .= 'in ' . $file . ':' . $e->getLine(); } if ($e->getPrevious() instanceof \Exception) { $text .= $cr . 'Previous Exception:' . $cr; $text .= self::getExceptionText($e->getPrevious(), $format) . $cr; } return $text; }
public function testInvalidArgumentException() { $this->assertEquals(Exception::invalidArgument(1, 'Psc\\ASimpleObjectClass::doSomething()', 'wrongValue', Type::create('Composite')->setComponents(Type::create('Integer'), Type::create('Object<Psc\\NiceClass>'))), $this->simpleObject->doSomething('wrongValue')); }
public static function registerExceptionHandler() { /* Exception Handling schöner */ Exception::registerHandler(); }
public static function missingVariable($variable) { return parent::create('Der MockBuilder ist nicht komplett. Es muss noch "%s" gesetzt werden.', $variable); }
/** * Erstellt aus dem Request und dem FormPanel ein Set mit allen FormularDaten * * man könnte sich hier auch mal vorstellen die formulardaten im set aufzusplitten * Sicherheit: alle Felder die nicht registriert sind durch Componenten oder den Formpanel (getControlFields) schmeissen hier eine Exception */ public function createFormDataSet(FormData $requestData, EntityFormPanel $panel, Entity $entity) { $meta = $entity->getSetMeta(); // wir müssen die Spezial-Felder vom EntityFormPanel hier tracken foreach ($panel->getControlFields() as $field) { $meta->setFieldType($field, Type::create('String')); } // sonderfeld disabled wird ignored $meta->setFieldType('disabled', Type::create('Array')); try { $set = new Set((array) $requestData, $meta); } catch (\Psc\Data\FieldNotDefinedException $e) { throw \Psc\Exception::create("In den FormularDaten befindet sich ein Feld '%s', welches kein Feld aus Entity getSetMeta ist (%s).", implode('.', $e->field), implode(', ', $e->avaibleFields)); } return $set; }
/** */ public function addExInner(\Psc\Exception $e) { $msg = $e->errorMessage; $ei = $e->getPrevious(); $devInfo = NULL; if (DEV) { $devInfo = 'InnerException: <br />'; $file = mb_substr($ei->getFile(), mb_strlen(BASE_DIR)); // relativ machen weil kürzer $devInfo .= get_class($ei) . ' message: ' . nl2br(HTML::esc($ei->getMessage())) . ' in {base}' . DIRECTORY_SEPARATOR . $file . ':' . $ei->getLine() . '<br />'; $devInfo .= 'Stack trace: <br />'; $devInfo .= nl2br($ei->getTraceAsString()); } return $this->add($msg, $e->errorStatus, $devInfo); }