/** * Creates a detailed description of an exception which is used for exception mails, * exception info files and fatal exception views * * @param \Exception $e * @return string detailed description */ private function createDetailLogMessage(\Throwable $e) { // build title $eName = get_class($e); $title = 'An ' . $eName . ' occurred'; $debugContent = $title . PHP_EOL . str_repeat('+', mb_strlen($title)) . PHP_EOL . PHP_EOL; $debugContent .= $e->getMessage() . PHP_EOL . PHP_EOL; if ($e instanceof \ErrorException || $e instanceof \Error) { $debugContent .= 'File: ' . $e->getFile() . PHP_EOL . 'Line: ' . $e->getLine() . PHP_EOL . PHP_EOL; } // build query info for PDOExceptions if ($e instanceof QueryStumble) { $debugContent .= 'STATEMENT' . PHP_EOL . '---------' . PHP_EOL; $debugContent .= $e->getQueryString() . PHP_EOL . PHP_EOL; if ($e instanceof PdoPreparedExecutionException) { $boundValuesStr = ""; foreach ($e->getBoundValues() as $name => $value) { if (!mb_strlen($boundValuesStr)) { $boundValuesStr .= ', '; } $boundValuesStr .= $name . '=' . ReflectionUtils::buildScalar($value); } $debugContent .= 'Bound values: ' . $boundValuesStr . PHP_EOL . PHP_EOL; } } // build stack trace $debugContent .= 'STACK TRACE' . PHP_EOL . '-----------' . PHP_EOL; $debugContent .= $eName . ': ' . $e->getTraceAsString() . PHP_EOL; $curE = $e; while (null != ($curE = $curE->getPrevious())) { $debugContent .= PHP_EOL . get_class($curE) . ': ' . $this->createSimpleLogMessage($curE) . PHP_EOL . $curE->getTraceAsString() . PHP_EOL; } $debugContent .= PHP_EOL; if (isset($_SERVER['REQUEST_URI'])) { // build http request $debugContent .= 'HTTP REQUEST' . PHP_EOL . '------------' . PHP_EOL; $debugContent .= $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . PHP_EOL; foreach ($_SERVER as $name => $value) { if (stristr($name, 'HTTP_')) { $debugContent .= substr($name, 5) . "\t" . $value . PHP_EOL; } } } if (!$this->stable) { $debugContent .= 'VARS CANNOT BE DISPLAYED DUE TO UNSTABLE PHP STATE'; } else { $debugContent .= $this->createLogArrayStr('SERVER VARS', $_SERVER); if (!empty($_GET)) { $debugContent .= $this->createLogArrayStr('HTTP GET VARS', $_GET); } if (!empty($_POST)) { $debugContent .= $this->createLogArrayStr('HTTP POST VARS', $_POST); } } return $debugContent; }
private static function applyQueryStumble(ThrowableInfo $throwableInfo, QueryStumble $e) { $throwableInfo->setStatementString(SyntaxUtils::formatSql($e->getQueryString())); $boundValues = array(); foreach ((array) $e->getBoundValues() as $key => $value) { $boundValues[$key] = ReflectionUtils::buildScalar($value); } $throwableInfo->setBoundValues($boundValues); }
public function createInstallDescriber() : InstallDescriber { $describerClassName = $this->getModuleInfo()->getInstallDescriberClassName(); if ($describerClassName === null) { throw new IllegalStateException('No install describer available.'); } $describerClass = null; try { $describerClass = ReflectionUtils::createReflectionClass($describerClassName); } catch (TypeNotFoundException $e) { throw $this->createInvalidInstallDescriberException($e); } if (!$describerClass->implementsInterface(InstallDescriber::class)) { throw $this->createInvalidInstallDescriberException(new InvalidConfigurationException('InstallDescriber must implement interface ' . InstallDescriber::class . ': ' . $describerClass->getName())); } return $this->installDescriber = $describerClass->newInstance(); }
/** * * @param string $namespace * @throws TypeLoaderErrorException * @return array */ public static function getNamespaceDirPaths($namespace) { if (ReflectionUtils::hasSpecialChars($namespace, false)) { throw new \InvalidArgumentException('Namespace contains invalid characters: ' . $namespace); } $dirPaths = array(); foreach ($this->buildPs4Paths($namespace, '') as $psr4Path) { if (!is_dir($psr4Path)) { $dirPaths[] = $psr4Path; } } foreach (explode(PATH_SEPARATOR, get_include_path()) as $includePath) { $path = $includePath . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $namespace); if (is_dir($path)) { $dirPaths[] = $path; } } return $dirPaths; }
public static function dirNameToNamespace(string $dirName) { $namespace = ReflectionUtils::decodeNamespace($dirName); if (ReflectionUtils::hasSpecialChars($namespace, false)) { throw new \InvalidArgumentException('Invalid namespace: ' . $namespace); } return $namespace; }
public function lookupParameterValue(\ReflectionParameter $parameter) { $parameterClass = ReflectionUtils::extractParameterClass($parameter); if ($parameterClass === null) { throw new MagicObjectUnavailableException(); } switch ($parameterClass->getName()) { case 'n2n\\l10n\\DynamicTextCollection': $module = null; try { $module = $this->moduleManager->getModuleOfTypeName($this->determineNamespaceOfParameter($parameter), !$parameter->allowsNull()); } catch (UnknownModuleException $e) { throw new MagicObjectUnavailableException('Could not determine module for DynamicTextCollection.', 0, $e); } if ($module === null) { return null; } return new DynamicTextCollection($module, $this->getN2nLocale()); case 'n2n\\core\\module\\Module': try { return $this->moduleManager->getModuleOfTypeName($this->determineNamespaceOfParameter($parameter), !$parameter->allowsNull()); } catch (UnknownModuleException $e) { throw new MagicObjectUnavailableException('Could not determine module.', 0, $e); } default: if ($parameter->isDefaultValueAvailable()) { if (null !== ($value = $this->lookup($parameterClass->getName(), false))) { return $value; } return $parameter->getDefaultValue(); } else { if ($parameter->allowsNull()) { return $this->lookup($parameterClass->getName(), false); } } return $this->lookup($parameterClass->getName(), true); } }