/** * Show the current status of entities and mappings * * Shows basic information about which entities exist and possibly if their * mapping information contains errors or not. * * To run a full validation, use the validate command. * * @param boolean $dumpMappingData If set, the mapping data will be output * @return void * @see typo3.flow3:doctrine:validate */ public function entityStatusCommand($dumpMappingData = FALSE) { $info = $this->doctrineService->getEntityStatus(); if ($info === array()) { $this->output('You do not have any mapped Doctrine ORM entities according to the current configuration. '); $this->outputLine('If you have entities or mapping files you should check your mapping configuration for errors.'); } else { $this->outputLine('Found %d mapped entities:', array(count($info))); foreach ($info as $entityClassName => $entityStatus) { if ($entityStatus instanceof \Doctrine\Common\Persistence\Mapping\ClassMetadata) { $this->outputLine('[OK] %s', array($entityClassName)); if ($dumpMappingData) { \TYPO3\FLOW3\Error\Debugger::clearState(); $this->outputLine(\TYPO3\FLOW3\Error\Debugger::renderDump($entityStatus, 0, TRUE, TRUE)); } } else { $this->outputLine('[FAIL] %s', array($entityClassName)); $this->outputLine($entityStatus); $this->outputLine(); } } } }
/** * Writes information about the given exception into the log. * * @param \Exception $exception The exception to log * @param array $additionalData Additional data to log * @return void * @api */ public function logException(\Exception $exception, array $additionalData = array()) { $backTrace = $exception->getTrace(); $className = isset($backTrace[0]['class']) ? $backTrace[0]['class'] : '?'; $methodName = isset($backTrace[0]['function']) ? $backTrace[0]['function'] : '?'; $message = $this->getExceptionLogMessage($exception); if ($exception->getPrevious() !== NULL) { $additionalData['previousException'] = $this->getExceptionLogMessage($exception->getPrevious()); } $explodedClassName = explode('\\', $className); // FIXME: This is not really the package key: $packageKey = isset($explodedClassName[1]) ? $explodedClassName[1] : NULL; if (!file_exists(FLOW3_PATH_DATA . 'Logs/Exceptions')) { mkdir(FLOW3_PATH_DATA . 'Logs/Exceptions'); } if (file_exists(FLOW3_PATH_DATA . 'Logs/Exceptions') && is_dir(FLOW3_PATH_DATA . 'Logs/Exceptions') && is_writable(FLOW3_PATH_DATA . 'Logs/Exceptions')) { $referenceCode = $exception instanceof \TYPO3\FLOW3\Exception ? $exception->getReferenceCode() : date('YmdHis', $_SERVER['REQUEST_TIME']) . substr(md5(rand()), 0, 6); $exceptionDumpPathAndFilename = FLOW3_PATH_DATA . 'Logs/Exceptions/' . $referenceCode . '.txt'; file_put_contents($exceptionDumpPathAndFilename, $message . PHP_EOL . PHP_EOL . \TYPO3\FLOW3\Error\Debugger::getBacktraceCode($backTrace, FALSE, TRUE)); $message .= ' - See also: ' . basename($exceptionDumpPathAndFilename); } else { $this->log(sprintf('Could not write exception backtrace into %s because the directory could not be created or is not writable.', FLOW3_PATH_DATA . 'Logs/Exceptions/'), LOG_WARNING, array(), 'FLOW3', __CLASS__, __FUNCTION__); } $this->log($message, LOG_CRIT, $additionalData, $packageKey, $className, $methodName); }
/** * Sends the given HTTP request * * @param \TYPO3\FLOW3\Http\Request $request * @return \TYPO3\FLOW3\Http\Response * @throws \TYPO3\FLOW3\Http\Exception * @api */ public function sendRequest(Request $request) { $requestHandler = $this->bootstrap->getActiveRequestHandler(); if (!$requestHandler instanceof \TYPO3\FLOW3\Tests\FunctionalTestRequestHandler) { throw new \TYPO3\FLOW3\Http\Exception('The browser\'s internal request engine has only been designed for use within functional tests.', 1335523749); } $response = new Response(); $requestHandler->setHttpRequest($request); $requestHandler->setHttpResponse($response); try { $actionRequest = $this->router->route($request); $this->securityContext->clearContext(); $this->securityContext->injectRequest($actionRequest); $this->dispatcher->dispatch($actionRequest, $response); } catch (\Exception $exception) { $pathPosition = strpos($exception->getFile(), 'Packages/'); $filePathAndName = $pathPosition !== FALSE ? substr($exception->getFile(), $pathPosition) : $exception->getFile(); $exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : ''; $content = PHP_EOL . 'Uncaught Exception in FLOW3 ' . $exceptionCodeNumber . $exception->getMessage() . PHP_EOL; $content .= 'thrown in file ' . $filePathAndName . PHP_EOL; $content .= 'in line ' . $exception->getLine() . PHP_EOL . PHP_EOL; $content .= \TYPO3\FLOW3\Error\Debugger::getBacktraceCode($exception->getTrace(), FALSE, TRUE) . PHP_EOL; $response->setStatus(500); $response->setContent($content); $response->setHeader('X-FLOW3-ExceptionCode', $exceptionCodeNumber); $response->setHeader('X-FLOW3-ExceptionMessage', $exception->getMessage()); } return $response; }
/** * A var_dump function optimized for FLOW3's object structures * * @param mixed $variable The variable to display a dump of * @param string $title optional custom title for the debug output * @param boolean $return if TRUE, the dump is returned for displaying it embedded in custom HTML. If FALSE (default), the variable dump is directly displayed. * @param boolean $plaintext If TRUE, the dump is in plain text, if FALSE the debug output is in HTML format. If not specified, the mode is guessed from FLOW3_SAPITYPE * @return void|string if $return is TRUE, the variable dump is returned. By default, the dump is directly displayed, and nothing is returned. * @api */ function var_dump($variable, $title = NULL, $return = FALSE, $plaintext = NULL) { if ($plaintext === NULL) { $plaintext = FLOW3_SAPITYPE === 'CLI'; $ansiColors = $plaintext && DIRECTORY_SEPARATOR === '/'; } else { $ansiColors = FALSE; } if ($title === NULL) { $title = 'FLOW3 Variable Dump'; } if ($ansiColors) { $title = "[1m" . $title . "[0m"; } \TYPO3\FLOW3\Error\Debugger::clearState(); if (!$plaintext && \TYPO3\FLOW3\Error\Debugger::$stylesheetEchoed === FALSE) { echo '<link rel="stylesheet" type="text/css" href="/_Resources/Static/Packages/TYPO3.FLOW3/Error/Debugger.css" />'; \TYPO3\FLOW3\Error\Debugger::$stylesheetEchoed = TRUE; } if ($plaintext) { $output = $title . chr(10) . \TYPO3\FLOW3\Error\Debugger::renderDump($variable, 0, TRUE, $ansiColors) . chr(10) . chr(10); } else { $output = ' <div class="FLOW3-Error-Debugger-VarDump ' . ($return ? 'FLOW3-Error-Debugger-VarDump-Inline' : 'FLOW3-Error-Debugger-VarDump-Floating') . '"> <div class="FLOW3-Error-Debugger-VarDump-Top"> ' . htmlspecialchars($title) . ' </div> <div class="FLOW3-Error-Debugger-VarDump-Center"> <pre dir="ltr">' . \TYPO3\FLOW3\Error\Debugger::renderDump($variable, 0, FALSE, FALSE) . '</pre> </div> </div> '; } if ($return === TRUE) { return $output; } else { echo $output; } }
/** * Returns a link pointing to Forge to create a new issue. * * @param \Exception $exception * @return string */ protected function getCreateIssueLink(\Exception $exception) { $filename = basename($exception->getFile()); return 'http://forge.typo3.org/projects/package-typo3-flow3/issues/new?issue[subject]=' . urlencode(get_class($exception) . ' thrown in file ' . $filename) . '&issue[description]=' . urlencode($exception->getMessage() . chr(10) . strip_tags(str_replace(array('<br />', '</pre>'), chr(10), \TYPO3\FLOW3\Error\Debugger::getBacktraceCode($exception->getTrace(), FALSE))) . chr(10) . 'Please include more helpful information!') . '&issue[category_id]=554&issue[priority_id]=7'; }
/** * Initializes the runtime Object Manager * * @param \TYPO3\FLOW3\Core\Bootstrap $bootstrap * @return void */ public static function initializeObjectManager(Bootstrap $bootstrap) { $configurationManager = $bootstrap->getEarlyInstance('TYPO3\\FLOW3\\Configuration\\ConfigurationManager'); $objectConfigurationCache = $bootstrap->getEarlyInstance('TYPO3\\FLOW3\\Cache\\CacheManager')->getCache('FLOW3_Object_Configuration'); $objectManager = new \TYPO3\FLOW3\Object\ObjectManager($bootstrap->getContext()); Bootstrap::$staticObjectManager = $objectManager; $objectManager->injectAllSettings($configurationManager->getConfiguration(\TYPO3\FLOW3\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS)); $objectManager->setObjects($objectConfigurationCache->get('objects')); foreach ($bootstrap->getEarlyInstances() as $objectName => $instance) { $objectManager->setInstance($objectName, $instance); } $objectManager->get('TYPO3\\FLOW3\\SignalSlot\\Dispatcher')->injectObjectManager($objectManager); \TYPO3\FLOW3\Error\Debugger::injectObjectManager($objectManager); $bootstrap->setEarlyInstance('TYPO3\\FLOW3\\Object\\ObjectManagerInterface', $objectManager); }