ether-code 0.5.1 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,41 +26,27 @@ class PHPGenerator {
26
26
  const addToMap = (map, section) => {
27
27
  if (!section) return
28
28
  for (const [key, translations] of Object.entries(section)) {
29
- if (translations && translations.fr && translations.php) {
30
- map[translations.fr.toLowerCase()] = translations.php
29
+ if (translations && translations.fr) {
30
+ map[translations.fr.toLowerCase()] = key
31
31
  }
32
32
  }
33
33
  }
34
34
 
35
- addToMap(this.keywordMap, this.i18n.variables)
36
- addToMap(this.keywordMap, this.i18n.types)
37
- addToMap(this.keywordMap, this.i18n.operateursArithmetiques)
38
- addToMap(this.keywordMap, this.i18n.operateursComparaison)
39
- addToMap(this.keywordMap, this.i18n.operateursLogiques)
40
- addToMap(this.keywordMap, this.i18n.conditions)
41
- addToMap(this.keywordMap, this.i18n.boucles)
42
- addToMap(this.keywordMap, this.i18n.fonctions)
43
- addToMap(this.keywordMap, this.i18n.classes)
44
- addToMap(this.keywordMap, this.i18n.visibilite)
45
- addToMap(this.keywordMap, this.i18n.erreursExceptions)
46
-
47
- addToMap(this.functionMap, this.i18n.chainesManipulation)
48
- addToMap(this.functionMap, this.i18n.chainesRecherche)
49
- addToMap(this.functionMap, this.i18n.chainesCasse)
50
- addToMap(this.functionMap, this.i18n.tableauxBase)
51
- addToMap(this.functionMap, this.i18n.tableauxTri)
52
- addToMap(this.functionMap, this.i18n.tableauxFonctionnels)
53
- addToMap(this.functionMap, this.i18n.mathsBase)
54
- addToMap(this.functionMap, this.i18n.datesBase)
55
- addToMap(this.functionMap, this.i18n.fichiersOuverture)
56
- addToMap(this.functionMap, this.i18n.fichiersOperations)
57
- addToMap(this.functionMap, this.i18n.regexFonctions)
58
- addToMap(this.functionMap, this.i18n.jsonFonctions)
35
+ const addAllSections = (map) => {
36
+ for (const [sectionName, section] of Object.entries(this.i18n)) {
37
+ if (typeof section === 'object' && section !== null) {
38
+ addToMap(map, section)
39
+ }
40
+ }
41
+ }
42
+
43
+ addAllSections(this.keywordMap)
44
+ addAllSections(this.functionMap)
59
45
  }
60
46
 
61
47
  translate(word) {
62
48
  const lower = word.toLowerCase()
63
- return this.keywordMap[lower] || this.functionMap[lower] || this.translateGeneric(word)
49
+ return this.translateGeneric(lower)
64
50
  }
65
51
 
66
52
  translateGeneric(word) {
@@ -160,6 +146,8 @@ class PHPGenerator {
160
146
  'convertir chaine': 'strval',
161
147
  'convertir entier': 'intval',
162
148
  'convertir flottant': 'floatval',
149
+ 'convertir booleen': 'boolval',
150
+ 'definir type': 'settype',
163
151
  'date': 'date',
164
152
  'temps': 'time',
165
153
  'maintenant': 'now',
@@ -190,7 +178,149 @@ class PHPGenerator {
190
178
  'inclure': 'include',
191
179
  'inclure une fois': 'include_once',
192
180
  'requiert': 'require',
193
- 'requiert une fois': 'require_once'
181
+ 'requiert une fois': 'require_once',
182
+ 'mapper tableau': 'array_map',
183
+ 'filtrer tableau': 'array_filter',
184
+ 'reduire tableau': 'array_reduce',
185
+ 'parcourir tableau': 'array_walk',
186
+ 'parcourir recursif': 'array_walk_recursive',
187
+ 'decaler tableau': 'array_shift',
188
+ 'depiler tableau': 'array_pop',
189
+ 'empiler tableau': 'array_push',
190
+ 'prefixer tableau': 'array_unshift',
191
+ 'chercher tableau': 'array_search',
192
+ 'cle existe tableau': 'array_key_exists',
193
+ 'dans tableau': 'in_array',
194
+ 'somme tableau': 'array_sum',
195
+ 'produit tableau': 'array_product',
196
+ 'compter valeurs': 'array_count_values',
197
+ 'aleatoire tableau': 'array_rand',
198
+ 'element courant': 'current',
199
+ 'element suivant': 'next',
200
+ 'element precedent': 'prev',
201
+ 'cle courante': 'key',
202
+ 'premier element': 'reset',
203
+ 'dernier element': 'end',
204
+ 'remplir tableau': 'array_fill',
205
+ 'remplir cles tableau': 'array_fill_keys',
206
+ 'rembourrer tableau': 'array_pad',
207
+ 'plage': 'range',
208
+ 'fonction existe': 'function_exists',
209
+ 'classe existe': 'class_exists',
210
+ 'methode existe': 'method_exists',
211
+ 'propriete existe': 'property_exists',
212
+ 'interface existe': 'interface_exists',
213
+ 'trait existe': 'trait_exists',
214
+ 'obtenir classe': 'get_class',
215
+ 'obtenir parent classe': 'get_parent_class',
216
+ 'obtenir methodes classe': 'get_class_methods',
217
+ 'obtenir variables classe': 'get_class_vars',
218
+ 'obtenir variables objet': 'get_object_vars',
219
+ 'est instance de': 'is_a',
220
+ 'est sous-classe de': 'is_subclass_of',
221
+ 'classes declarees': 'get_declared_classes',
222
+ 'interfaces declarees': 'get_declared_interfaces',
223
+ 'traits declares': 'get_declared_traits',
224
+ 'entete http': 'header',
225
+ 'entetes envoyes': 'headers_sent',
226
+ 'liste entetes': 'headers_list',
227
+ 'retirer entete': 'header_remove',
228
+ 'code reponse http': 'http_response_code',
229
+ 'analyser url': 'parse_url',
230
+ 'construire requete http': 'http_build_query',
231
+ 'analyser parametres': 'parse_str',
232
+ 'encoder url': 'urlencode',
233
+ 'decoder url': 'urldecode',
234
+ 'encoder url brut': 'rawurlencode',
235
+ 'decoder url brut': 'rawurldecode',
236
+ 'encoder base64': 'base64_encode',
237
+ 'decoder base64': 'base64_decode',
238
+ 'hacher mot de passe': 'password_hash',
239
+ 'verifier mot de passe': 'password_verify',
240
+ 'rehachage necessaire': 'password_needs_rehash',
241
+ 'info mot de passe': 'password_get_info',
242
+ 'bcrypt par defaut': 'PASSWORD_DEFAULT',
243
+ 'bcrypt': 'PASSWORD_BCRYPT',
244
+ 'argon2i': 'PASSWORD_ARGON2I',
245
+ 'argon2id': 'PASSWORD_ARGON2ID',
246
+ 'appeler fonction utilisateur': 'call_user_func',
247
+ 'appeler avec arguments': 'call_user_func_array',
248
+ 'creer fonction': 'create_function',
249
+ 'filtrer variable': 'filter_var',
250
+ 'filtrer entree': 'filter_input',
251
+ 'filtrer tableau entree': 'filter_input_array',
252
+ 'filtrer tableau variable': 'filter_var_array',
253
+ 'liste filtres': 'filter_list',
254
+ 'id filtre': 'filter_id',
255
+ 'valider email': 'FILTER_VALIDATE_EMAIL',
256
+ 'valider url': 'FILTER_VALIDATE_URL',
257
+ 'valider ip': 'FILTER_VALIDATE_IP',
258
+ 'valider entier': 'FILTER_VALIDATE_INT',
259
+ 'valider flottant': 'FILTER_VALIDATE_FLOAT',
260
+ 'valider booleen': 'FILTER_VALIDATE_BOOLEAN',
261
+ 'nettoyer chaine': 'FILTER_SANITIZE_STRING',
262
+ 'nettoyer email': 'FILTER_SANITIZE_EMAIL',
263
+ 'nettoyer url': 'FILTER_SANITIZE_URL',
264
+ 'nettoyer entier': 'FILTER_SANITIZE_NUMBER_INT',
265
+ 'nettoyer flottant': 'FILTER_SANITIZE_NUMBER_FLOAT',
266
+ 'obtenir config': 'ini_get',
267
+ 'definir config': 'ini_set',
268
+ 'restaurer config': 'ini_restore',
269
+ 'toutes configs': 'ini_get_all',
270
+ 'obtenir environnement': 'getenv',
271
+ 'definir environnement': 'putenv',
272
+ 'version php': 'phpversion',
273
+ 'info php': 'phpinfo',
274
+ 'comparer versions': 'version_compare',
275
+ 'extension chargee': 'extension_loaded',
276
+ 'extensions chargees': 'get_loaded_extensions',
277
+ 'formater chaine': 'sprintf',
278
+ 'afficher formate': 'printf',
279
+ 'formater vers flux': 'fprintf',
280
+ 'formater avec tableau': 'vsprintf',
281
+ 'afficher avec tableau': 'vprintf',
282
+ 'analyser formate': 'sscanf',
283
+ 'formater nombre': 'number_format',
284
+ 'formater monnaie': 'money_format',
285
+ 'ajouter echappements': 'addslashes',
286
+ 'retirer echappements': 'stripslashes',
287
+ 'ajouter echappements c': 'addcslashes',
288
+ 'retirer echappements c': 'stripcslashes',
289
+ 'citer meta': 'quotemeta',
290
+ 'compacter': 'compact',
291
+ 'extraire': 'extract',
292
+ 'variables definies': 'get_defined_vars',
293
+ 'enregistrer autoload': 'spl_autoload_register',
294
+ 'desenregistrer autoload': 'spl_autoload_unregister',
295
+ 'fonctions autoload': 'spl_autoload_functions',
296
+ 'autoload': 'spl_autoload',
297
+ 'extensions autoload': 'spl_autoload_extensions',
298
+ 'hacher': 'hash',
299
+ 'hacher fichier': 'hash_file',
300
+ 'hacher hmac': 'hash_hmac',
301
+ 'algorithmes hachage': 'hash_algos',
302
+ 'md5': 'md5',
303
+ 'md5 fichier': 'md5_file',
304
+ 'sha1': 'sha1',
305
+ 'sha1 fichier': 'sha1_file',
306
+ 'crc32': 'crc32',
307
+ 'octets aleatoires': 'random_bytes',
308
+ 'entier aleatoire': 'random_int',
309
+ 'traduire caracteres': 'strtr',
310
+ 'sous-chaine compte': 'substr_count',
311
+ 'sous-chaine remplacer': 'substr_replace',
312
+ 'comparer sous-chaine': 'substr_compare',
313
+ 'chercher chaine': 'strstr',
314
+ 'chercher insensible': 'stristr',
315
+ 'chercher caractere': 'strchr',
316
+ 'chercher caractere inverse': 'strrchr',
317
+ 'dormir': 'sleep',
318
+ 'dormir micro': 'usleep',
319
+ 'memoire utilisee': 'memory_get_usage',
320
+ 'memoire pic': 'memory_get_peak_usage',
321
+ 'limite memoire': "ini_get('memory_limit')",
322
+ 'chemin inclus': 'get_include_path',
323
+ 'definir chemin inclus': 'set_include_path'
194
324
  }
195
325
 
196
326
  const lower = word.toLowerCase()
@@ -220,13 +350,6 @@ class PHPGenerator {
220
350
  if (!node) return ''
221
351
 
222
352
  switch (node.type) {
223
- case 'Program':
224
- if (node.body) {
225
- for (const child of node.body) {
226
- this.generateNode(child)
227
- }
228
- }
229
- return
230
353
  case 'VariableDeclaration':
231
354
  return this.generateVariableDeclaration(node)
232
355
  case 'FunctionDeclaration':
@@ -265,6 +388,10 @@ class PHPGenerator {
265
388
  return this.generateNamespace(node)
266
389
  case 'UseStatement':
267
390
  return this.generateUseStatement(node)
391
+ case 'IncludeStatement':
392
+ return this.generateIncludeStatement(node)
393
+ case 'Include':
394
+ return this.generateInclude(node)
268
395
  case 'CallExpression':
269
396
  return this.generateCallExpression(node)
270
397
  case 'MemberExpression':
@@ -289,33 +416,31 @@ class PHPGenerator {
289
416
  }
290
417
 
291
418
  generateVariableDeclaration(node) {
292
- if (node.declarations && node.declarations.length > 0) {
293
- for (const decl of node.declarations) {
294
- const name = this.generateIdentifier(decl.id || { name: decl.name })
295
- if (decl.init) {
296
- const init = this.generateNode(decl.init)
297
- this.writeLine(`${name} = ${init};`)
298
- } else {
299
- this.writeLine(`${name};`)
300
- }
301
- }
302
- } else {
303
- const name = '$' + (node.name || (node.id && node.id.name) || 'var')
304
- if (node.init) {
305
- const init = this.generateNode(node.init)
306
- this.writeLine(`${name} = ${init};`)
419
+ for (const decl of node.declarations || [node]) {
420
+ const name = this.generateIdentifier(decl.id || decl.name)
421
+ if (decl.init) {
422
+ const value = this.generateNode(decl.init)
423
+ this.writeLine(`${name} = ${value};`)
307
424
  } else {
308
- this.writeLine(`${name};`)
425
+ this.writeLine(`${name} = null;`)
309
426
  }
310
427
  }
311
428
  }
312
429
 
313
430
  generateFunctionDeclaration(node) {
314
- const name = this.translate(node.name || node.id?.name || '')
315
- const params = (node.params || []).map(p => this.generateParam(p)).join(', ')
316
- const returnType = node.returnType ? ': ' + this.translate(node.returnType) : ''
317
-
318
- this.writeLine(`function ${name}(${params})${returnType} {`)
431
+ const name = node.id ? node.id.name || node.id : node.name
432
+ const params = (node.params || []).map(p => {
433
+ let param = this.generateIdentifier(p.name || p)
434
+ if (p.type) param = p.type + ' ' + param
435
+ if (p.default) param += ' = ' + this.generateNode(p.default)
436
+ return param
437
+ }).join(', ')
438
+
439
+ const returnType = node.returnType ? ': ' + node.returnType : ''
440
+ const visibility = node.visibility ? node.visibility + ' ' : ''
441
+ const isStatic = node.static ? 'static ' : ''
442
+
443
+ this.writeLine(`${visibility}${isStatic}function ${name}(${params})${returnType} {`)
319
444
  this.indent++
320
445
 
321
446
  if (node.body) {
@@ -323,6 +448,10 @@ class PHPGenerator {
323
448
  for (const stmt of node.body) {
324
449
  this.generateNode(stmt)
325
450
  }
451
+ } else if (node.body.body) {
452
+ for (const stmt of node.body.body) {
453
+ this.generateNode(stmt)
454
+ }
326
455
  } else {
327
456
  this.generateNode(node.body)
328
457
  }
@@ -333,84 +462,35 @@ class PHPGenerator {
333
462
  this.writeLine('')
334
463
  }
335
464
 
336
- generateParam(param) {
337
- let result = ''
338
-
339
- if (param.type && param.type !== 'Identifier') {
340
- result += this.translate(param.type) + ' '
341
- }
342
-
343
- result += this.generateIdentifier(param)
344
-
345
- if (param.default) {
346
- result += ' = ' + this.generateNode(param.default)
347
- }
348
-
349
- return result
350
- }
351
-
352
465
  generateClassDeclaration(node) {
353
- const name = node.name || node.id?.name || ''
466
+ const name = node.id ? node.id.name || node.id : node.name
354
467
  let declaration = 'class ' + name
355
-
356
- if (node.extends) {
357
- declaration += ' extends ' + node.extends
468
+
469
+ if (node.superClass) {
470
+ declaration += ' extends ' + (node.superClass.name || node.superClass)
358
471
  }
359
-
360
472
  if (node.implements && node.implements.length > 0) {
361
- declaration += ' implements ' + node.implements.join(', ')
473
+ const interfaces = node.implements.map(i => i.name || i).join(', ')
474
+ declaration += ' implements ' + interfaces
362
475
  }
363
-
476
+
364
477
  this.writeLine(declaration + ' {')
365
478
  this.indent++
366
-
367
- const members = node.body?.body || node.members || node.body || []
368
- for (const member of members) {
369
- this.generateClassMember(member)
370
- }
371
-
372
- this.indent--
373
- this.writeLine('}')
374
- this.writeLine('')
375
- }
376
-
377
- generateClassMember(node) {
378
- const visibility = node.visibility || 'public'
379
- const isStatic = node.static ? 'static ' : ''
380
479
 
381
- if (node.type === 'Property' || node.kind === 'property') {
382
- const name = this.generateIdentifier(node.key || { name: node.name })
383
- const typeHint = node.typeHint ? this.translate(node.typeHint) + ' ' : ''
384
- const value = node.value ? ' = ' + this.generateNode(node.value) : ''
385
- this.writeLine(`${visibility} ${isStatic}${typeHint}${name}${value};`)
386
- this.writeLine('')
387
- } else if (node.type === 'Method' || node.kind === 'method' || node.type === 'FunctionDeclaration') {
388
- const name = this.translate(node.key?.name || node.name || '')
389
- const params = (node.params || node.value?.params || []).map(p => this.generateParam(p)).join(', ')
390
- const returnType = node.returnType ? ': ' + this.translate(node.returnType) : ''
391
-
392
- this.writeLine(`${visibility} ${isStatic}function ${name}(${params})${returnType} {`)
393
- this.indent++
394
-
395
- const body = node.body || node.value?.body
396
- if (body) {
397
- if (Array.isArray(body)) {
398
- for (const stmt of body) {
399
- this.generateNode(stmt)
400
- }
401
- } else if (body.body) {
402
- for (const stmt of body.body) {
403
- this.generateNode(stmt)
404
- }
405
- } else {
406
- this.generateNode(body)
480
+ if (node.body) {
481
+ const body = node.body.body || node.body
482
+ if (Array.isArray(body)) {
483
+ for (const member of body) {
484
+ this.generateNode(member)
407
485
  }
486
+ } else {
487
+ this.generateNode(body)
408
488
  }
409
-
410
- this.indent--
411
- this.writeLine('}')
412
- this.writeLine('')
413
489
  }
490
+
491
+ this.indent--
492
+ this.writeLine('}')
493
+ this.writeLine('')
414
494
  }
415
495
 
416
496
  generateIfStatement(node) {
@@ -570,6 +650,22 @@ class PHPGenerator {
570
650
  this.writeLine(`use ${name}${alias};`)
571
651
  }
572
652
 
653
+ generateIncludeStatement(node) {
654
+ const type = node.once ? (node.required ? 'require_once' : 'include_once') : (node.required ? 'require' : 'include')
655
+ const path = typeof node.path === 'string' ? `'${node.path}'` : this.generateNode(node.path)
656
+ this.writeLine(`${type} ${path};`)
657
+ }
658
+
659
+ generateInclude(node) {
660
+ if (node.resolved && node.children) {
661
+ for (const child of node.children) {
662
+ this.generateNode(child)
663
+ }
664
+ } else {
665
+ this.writeLine(`// Include non résolu: ${node.path || 'inconnu'}`)
666
+ }
667
+ }
668
+
573
669
  generateCallExpression(node) {
574
670
  const callee = typeof node.callee === 'string'
575
671
  ? this.translate(node.callee)
@@ -647,6 +743,7 @@ class PHPGenerator {
647
743
  return translated
648
744
  }
649
745
  if (/^[A-Z]/.test(translated)) return translated
746
+ if (translated.includes('(')) return translated
650
747
 
651
748
  return '$' + translated
652
749
  }
@@ -681,4 +778,4 @@ class PHPGenerator {
681
778
 
682
779
  module.exports = {
683
780
  PHPGenerator
684
- }
781
+ }