-
Notifications
You must be signed in to change notification settings - Fork 5
/
symfony2-proxy.coffee
130 lines (107 loc) · 3.32 KB
/
symfony2-proxy.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
config = require '../config.coffee'
module.exports =
phpProxy: null
data:
entities: {}
services: {}
routes: {}
###*
* Execute a symfony2 command
* @param {array} command
* @return {mixed}
###
execute: (command) ->
if !@phpProxy
return []
for directory in atom.project.getDirectories()
for cons in config.config["console"]
res = @phpProxy.execute([cons].concat(command), false, {cwd: directory.path}, true)
if not res.error? and res.result?.split("\n").length > 2
return res
else
res = []
return []
###*
* Adds the atom autocomplete php proxy
* @param {Object} proxy
###
providePhpProxy: (proxy) ->
@phpProxy = proxy
###*
* Returns sf2 services
*
* @param {bool} force Force refresh or not ?
*
* @return {array}
###
getServices: (force) ->
if Object.keys(@data.services).length == 0 || force
@data.services = {}
lines = @execute("debug:container")
if lines != [] and lines.result
lines = lines.result.split("\n")
list = false
for line in lines
if list == false
if line.indexOf("Service ID") != -1
list = true
continue
## @TODO Manage aliases
regex = /([^\s]+)[\s]+([^\s]+)/g
result = regex.exec(line)
if result and result[1]? and result[2]? and not result[3]?
@data.services[result[1]] = result[2]
return @data.services
###*
* Récupère les entités gérées par doctrine
*
* @param {bool} force Force refresh or not ?
*
* @return {Array}
###
getEntities: (force) ->
if Object.keys(@data.entities).length == 0 || force
@data.entities = []
lines = @execute("doctrine:mapping:info")
if lines != [] and lines.result
lines = lines.result.split("\n")
list = false
for line in lines
if list == false
if line.indexOf("mapped entities") != -1
list = true
continue
regex = /([^\s]+)[\s]+([^\s]+)/g
result = regex.exec(line)
if result and result[1]? and result[2]?
@data.entities.push result[2].replace(/\\/g, '').replace(/(Entity)/g, ':')
return @data.entities
###*
* Returns SF2 routes
*
* @param {bool} force Force refresh or not ?
*
* @return {array}
###
getRoutes: (force) ->
if @data.routes.length == 0 || force
@data.routes = @execute("debug:router")
return @data.routes
###*
* Clear all cache of the plugin
###
clearCache: () ->
# Fill cache asynchronously
(() =>
@getEntities(true)
@getServices(true)
@getRoutes(true)
)()
###*
* Method called on plugin activation
###
init: () ->
atom.workspace.observeTextEditors (editor) =>
editor.onDidSave((event) =>
@clearCache()
)