Browse Source

read controllers

master
anonymous 1 year ago
parent
commit
9f3d6b16a4
3 changed files with 53 additions and 20 deletions
  1. +6
    -2
      src/main/clj/gen/core.clj
  2. +47
    -0
      src/main/clj/scan/lang/php/laravel5.clj
  3. +0
    -18
      src/main/clj/scan/lang/php/laravel5/scan.clj

+ 6
- 2
src/main/clj/gen/core.clj View File

@@ -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)))

+ 47
- 0
src/main/clj/scan/lang/php/laravel5.clj View File

@@ -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))))))))

+ 0
- 18
src/main/clj/scan/lang/php/laravel5/scan.clj View File

@@ -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))))))

Loading…
Cancel
Save