From 9f3d6b16a41cdb7263bb37fffd0eec70d5148b43 Mon Sep 17 00:00:00 2001 From: anonymous Date: Sun, 28 Aug 2022 13:03:47 +0200 Subject: [PATCH] read controllers --- src/main/clj/gen/core.clj | 8 +++-- src/main/clj/scan/lang/php/laravel5.clj | 47 ++++++++++++++++++++++++++++ src/main/clj/scan/lang/php/laravel5/scan.clj | 18 ----------- 3 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 src/main/clj/scan/lang/php/laravel5.clj delete mode 100644 src/main/clj/scan/lang/php/laravel5/scan.clj diff --git a/src/main/clj/gen/core.clj b/src/main/clj/gen/core.clj index 456fc57..698b1e6 100644 --- a/src/main/clj/gen/core.clj +++ b/src/main/clj/gen/core.clj @@ -1,13 +1,13 @@ (ns gen.core (:require [clojure.string :as str] [clj-yaml.core :as yaml] - [scan.lang.php.laravel5.scan :as laravel5])) + [scan.lang.php.laravel5])) (def ^{} run (fn [args] - (laravel5/routes (first args)) + (scan.lang.php.laravel5/routes (first args)) #_(println (yaml/generate-string {"openapi" "3.0.0" @@ -39,5 +39,9 @@ :indicator-indent 1 :flow-style :block})))) +(comment + + ) + (defn -main [& argv] (prn (run argv))) \ No newline at end of file diff --git a/src/main/clj/scan/lang/php/laravel5.clj b/src/main/clj/scan/lang/php/laravel5.clj new file mode 100644 index 0000000..bf43eea --- /dev/null +++ b/src/main/clj/scan/lang/php/laravel5.clj @@ -0,0 +1,47 @@ +(ns scan.lang.php.laravel5 + (:require [clojure.string :as str] + [clojure.java.io :as io])) + +(def + ^{} + load-method-signature! + (fn [route] + (cond (.exists (io/file (:ctl route))) + (let [src (slurp (:ctl route))] + (->> + (-> (re-pattern (str "function " (:act route) "\\((.*)\\)")) + (re-find src) + last + (or "") + (str/split #",")) + (map str/trim) + (filter (fn [e] (not (str/includes? e "Request")))) + (into []))) + :else nil))) + +(def + ^{} + routes + (fn [project-path] + (map (fn [route] + (assoc route + :signature + (load-method-signature! route))) + (let [route-file (str project-path "/routes/web.php")] + (filter + (fn [e] + (not (nil? e))) + (map + (fn [hit] + (let [[_ verb raw-params] hit + params (map (fn [e] (str/trim (str/escape e {\' ""}))) (str/split raw-params #",")) + [route ctl] params] + (if ctl + {:verb verb + :path route + :ctl (str project-path "/app/Http/Controllers/" (str/replace (str/replace ctl #"\@(.*)" ".php") "\\" "/")) + :act (str/replace ctl #"(.*)\@" "")} + nil))) + (re-seq + #"router->(.*)\((.*)\)" + (slurp route-file)))))))) \ No newline at end of file diff --git a/src/main/clj/scan/lang/php/laravel5/scan.clj b/src/main/clj/scan/lang/php/laravel5/scan.clj deleted file mode 100644 index dd8faac..0000000 --- a/src/main/clj/scan/lang/php/laravel5/scan.clj +++ /dev/null @@ -1,18 +0,0 @@ -(ns scan.lang.php.laravel5.scan - (:require [clojure.string :as str])) - -(def - ^{} - routes - (fn [project-path] - (let [route-file (str project-path "/routes/web.php")] - (map (fn [hit] - (let [[_ verb raw-params] hit - params (map (fn [e] (str/trim (str/escape e {\' ""}))) (str/split raw-params #",")) - [route ctl] params] - {:verb verb - :route route - :ctl ctl})) - (re-seq - #"router->(.*)\((.*)\)" - (slurp route-file))))))