Browse Source

route parsing for laravel

master
anonymous 1 year ago
parent
commit
4b2b93eed5
4 changed files with 64 additions and 0 deletions
  1. +3
    -0
      deps.edn
  2. +0
    -0
      main.hs
  3. +43
    -0
      src/main/clj/gen/core.clj
  4. +18
    -0
      src/main/clj/scan/lang/php/laravel5/scan.clj

+ 3
- 0
deps.edn View File

@@ -0,0 +1,3 @@
{:paths ["src/main/clj"]
:deps {org.clojure/clojure {:mvn/version "1.10.3"}
clj-commons/clj-yaml {:mvn/version "0.7.0"}}}

+ 0
- 0
main.hs View File

@@ -1 +0,0 @@

+ 43
- 0
src/main/clj/gen/core.clj View File

@@ -0,0 +1,43 @@
(ns gen.core
(:require [clojure.string :as str]
[clj-yaml.core :as yaml]
[scan.lang.php.laravel5.scan :as laravel5]))

(def
^{}
run
(fn [args]
(laravel5/routes (first args))
#_(println
(yaml/generate-string
{"openapi" "3.0.0"
:info
{:version 1
:title "thing"
:license
{:name "MIT"}}
:servers
[{:url "thing"}]
:paths
{"/pets"
{:get
{:parameters
[{:name "limit"
:in "query"
:description "aaaaaaaa"
:required false
:schema
{:type "integer"
:format "int32"}}]}}
"/lists"
{:get
{:responses
{"200"
{:description "ok"}}}}}
:spec {:lorem "ipsum" :thing true}}
:dumper-options {:indent 2
:indicator-indent 1
:flow-style :block}))))

(defn -main [& argv]
(prn (run argv)))

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

@@ -0,0 +1,18 @@
(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