From 4f128f90759b7ec44e81432a91d28e9cd4362004 Mon Sep 17 00:00:00 2001 From: Liubov Yaronskaya Date: Thu, 7 Nov 2019 13:40:35 +0300 Subject: [PATCH] feat: add php project heuristics(bootstrap, illuminate) --- src/main/kotlin/app/extractors/Heuristics.kt | 22 ++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/app/extractors/Heuristics.kt b/src/main/kotlin/app/extractors/Heuristics.kt index 6da1eae5..70ce3be4 100644 --- a/src/main/kotlin/app/extractors/Heuristics.kt +++ b/src/main/kotlin/app/extractors/Heuristics.kt @@ -122,6 +122,9 @@ val Perl6Regex = Regex( val PhpRegex = Regex( "^<\\?(?:php)?" ) +val PhpIlluminateRegex = Regex( + "(Auth|Bootstrap|Bus|Console|Events|Exceptions|Http|Providers" + + "|Support|Testing|Validation)") val PicoLispRegex = Regex( "^\\((de|class|rel|code|data|must)\\s", RegexOption.MULTILINE @@ -235,6 +238,11 @@ val k8sExp = { buf: String -> && buf.contains("metadata") } +val bootstrapWebpackExp = { buf: String -> + // Handling php projects with bootstrap Webpack. + buf.contains("/******/ (function(modules) { // webpackBootstrap") +} + /** * Heuristics to detect a programming language by file extension and content. * Inspired by GitHub Liguist heuristics (https://github.com/github/linguist). @@ -638,8 +646,11 @@ val HeuristicsMap = mapOf ExtractorInterface?>( "jl" to { _, _ -> CommonExtractor(Lang.JULIA) }, - "js" to { _, _ -> - JavascriptExtractor() + "js" to { buf, _ -> + if (bootstrapWebpackExp(buf)) { + null + } + else JavascriptExtractor() }, "jsx" to { _, _ -> JavascriptExtractor() @@ -793,10 +804,13 @@ val HeuristicsMap = mapOf ExtractorInterface?>( "pde" to { _, _ -> CommonExtractor(Lang.PROCESSING) }, - "php" to { buf, _ -> + "php" to { buf, path -> if (buf.contains("