Exemplo n.º 1
0
 /**
  * @validate $syntax NotEmpty
  * @validate $extensions NotEmpty
  * @validate $formats NotEmpty
  * @ignorevalidation $filteredFiles
  * @param array $syntax
  * @param array $extensions
  * @param array $formats
  * @param array $filteredFiles
  */
 public function syntaxAction(array $syntax, array $extensions, array $formats, array $filteredFiles = [])
 {
     /** @var DocumentTemplate $document */
     $document =& $GLOBALS['TBE_TEMPLATE'];
     $resourcePath = $document->backPath . ExtensionManagementUtility::extRelPath('builder') . 'Resources/Public/';
     $pageRenderer = new PageRenderer();
     $pageRenderer->addJsFile($resourcePath . 'Javascript/jqplot.min.js');
     $pageRenderer->addJsFile($resourcePath . 'Javascript/jqplot.canvasTextRenderer.min.js');
     $pageRenderer->addJsFile($resourcePath . 'Javascript/jqplot.canvasAxisTickRenderer.min.js');
     $pageRenderer->addJsFile($resourcePath . 'Javascript/jqplot.cursor.min.js');
     $pageRenderer->addJsFile($resourcePath . 'Javascript/jqplot.categoryAxisRenderer.min.js');
     $pageRenderer->addJsFile($resourcePath . 'Javascript/jqplot.barRenderer.min.js');
     $pageRenderer->addJsFile($resourcePath . 'Javascript/jqplot.pointLabels.min.js');
     $pageRenderer->addJsFile($resourcePath . 'Javascript/plotter.js');
     $reports = [];
     $csvFormats = trim(implode(',', $formats), ',');
     foreach ($extensions as $extensionKey) {
         if (true === empty($extensionKey)) {
             continue;
         }
         $extensionFolder = ExtensionManagementUtility::extPath($extensionKey);
         $reports[$extensionKey] = [];
         foreach ($syntax as $syntaxName) {
             if (true === empty($syntaxName)) {
                 continue;
             }
             $reportsForSyntaxName = [];
             if ('php' === $syntaxName) {
                 $reportsForSyntaxName = $this->syntaxService->syntaxCheckPhpFilesInPath($extensionFolder . '/Classes');
             } elseif ('fluid' === $syntaxName) {
                 $reportsForSyntaxName = $this->syntaxService->syntaxCheckFluidTemplateFilesInPath($extensionFolder . '/Resources', $csvFormats);
             } elseif ('profile' === $syntaxName) {
                 $files = GeneralUtility::getAllFilesAndFoldersInPath([], $extensionFolder, $csvFormats);
                 if (0 === count($filteredFiles)) {
                     $filteredFiles = $files;
                 }
                 $this->view->assign('files', $files);
                 $this->view->assign('basePathLength', strlen($extensionFolder . '/Resources/Private'));
                 foreach ($files as $file) {
                     if (0 < count($filteredFiles) && false === in_array($file, $filteredFiles)) {
                         continue;
                     }
                     $shortFilename = substr($file, strlen($extensionFolder . '/Resources/Private'));
                     /** @var TemplateAnalyzer $templateAnalyzer */
                     $templateAnalyzer = $this->objectManager->get(TemplateAnalyzer::class);
                     $reportsForSyntaxName[$shortFilename] = $templateAnalyzer->analyzePathAndFilename($file);
                 }
                 $reports[$extensionKey][$syntaxName]['json'] = $this->encodeMetricsToJson($reportsForSyntaxName);
             }
             $reports[$extensionKey][$syntaxName]['reports'] = $reportsForSyntaxName;
             $reports[$extensionKey][$syntaxName]['errors'] = $this->syntaxService->countErrorsInResultCollection($reportsForSyntaxName);
         }
     }
     $this->view->assign('filteredFiles', $filteredFiles);
     $this->view->assign('reports', $reports);
     $this->view->assign('extensions', $extensions);
     $this->view->assign('formats', $formats);
     $this->view->assign('syntax', $syntax);
     $this->view->assign('view', 'Index');
 }
 /**
  * Syntax check PHP code
  *
  * Checks PHP source files in $path, if extension
  * key is also given, only files in that path relative
  * to that extension are checked.
  *
  * @param string $extension Optional extension key (if path is set too it will apply to sub-folders in extension)
  * @param string $path file or folder path (if extensionKey is included, path is relative to this extension)
  * @param boolean $verbose If TRUE outputs more information about each file check - default is to only output errors
  * @return void
  */
 public function phpsyntaxCommand($extension = null, $path = null, $verbose = false)
 {
     $verbose = (bool) $verbose;
     $this->assertEitherExtensionKeyOrPathOrBothAreProvidedOrExit($extension, $path);
     if (null !== $extension) {
         $results = $this->syntaxService->syntaxCheckPhpFilesInExtension($extension);
     } else {
         $results = $this->syntaxService->syntaxCheckPhpFilesInPath($path);
     }
     $errors = false;
     foreach ($results as $filePathAndFilename => $result) {
         $result = $this->syntaxService->syntaxCheckPhpFile($filePathAndFilename);
         if (null !== $result->getError()) {
             $errors = true;
             $this->response->setContent('[ERROR] ' . $result->getError()->getMessage() . ' (' . $result->getError()->getCode() . ')' . LF);
         }
     }
     $this->stop($results, $errors, $verbose);
 }