@@ -36,6 +36,10 @@ class Sqlp {
36
36
37
37
private $ tree = [];
38
38
39
+ private $ filters = [];
40
+
41
+ private $ params = [];
42
+
39
43
private $ db ;
40
44
41
45
private $ namespace ;
@@ -414,17 +418,20 @@ function ($matches) {
414
418
$ filter [$ name ] = $ column ;
415
419
}
416
420
417
- $ filterArray = var_export ($ filter , true );
421
+ // $filterArray = var_export($filter, true);
418
422
$ return = ! empty ($ match ['return ' ]) ? $ match ['return ' ] : $ match ['data ' ];
419
423
$ return = '$params ' . $ this ->sqlPhpArrayKey ($ return );
420
424
$ key = '$params ' . $ this ->sqlPhpArrayKey ($ match ['data ' ]);
425
+ $ filterName = '$this->filters[ \'' . $ this ->prefix . $ match ['columns ' ] . '\'] ' ;
421
426
422
- $ filterFunction = '\'; ' . TAB . '$filterArray = ' . $ filterArray . "; \n" . TAB ;
427
+ //$filterFunction = '\';' . TAB . '$filterArray = ' . $filterArray . ";\n" . TAB;
428
+ $ filterFunction = '\'; ' . TAB ;
429
+ $ this ->filters [$ this ->prefix . $ match ['columns ' ]] = $ filter ;
423
430
424
431
if ($ isArray == 'true ' ) {
425
- $ filterFunction .= 'foreach ( ' . $ key . ' as $key => &$filter) ' . $ return . '[$key] = $this->db->filter($filter, $filterArray , ' . $ addMissingDefaults . '); ' . TAB . '$sql = \'' ;
432
+ $ filterFunction .= 'if (isset( ' . $ key . ' ) && is_array( ' . $ key . ' )) foreach ( ' . $ key . ' as $key => &$filter) ' . $ return . '[$key] = $this->db->filter($filter, ' . $ filterName . ' , ' . $ addMissingDefaults . '); ' . TAB . '$sql = \'' ;
426
433
} else {
427
- $ filterFunction .= $ return . '= $this->db->filter( ' . $ key . ', $filterArray , ' . $ addMissingDefaults . '); ' . TAB . '$sql = \'' ;
434
+ $ filterFunction .= $ return . '= $this->db->filter( ' . $ key . ', ' . $ filterName . ' , ' . $ addMissingDefaults . '); ' . TAB . '$sql = \'' ;
428
435
}
429
436
430
437
$ statement = str_replace ($ match [0 ], $ filterFunction , $ statement );
@@ -452,6 +459,10 @@ function parseParameters($params) {
452
459
$ param ['length ' ] = (int )preg_replace ('/[^\d]/ ' , '' ,$ match [4 ]);
453
460
}
454
461
462
+ if (isset ($ match [5 ])) {
463
+ $ param ['comment ' ] = trim ($ match [5 ], " \n\r\t\v\x00- " );
464
+ }
465
+
455
466
$ parameters [] = $ param ;
456
467
}
457
468
}
@@ -510,12 +521,14 @@ function ($m) {
510
521
511
522
//remove comments
512
523
$ sql = preg_replace ('@(--.*)\s+@ ' , '' , $ sql );
524
+ $ this ->tree = [];
513
525
514
526
if (preg_match_all ($ this ->config ['functionRegex ' ], $ sql , $ matches , PREG_SET_ORDER )) {
515
527
foreach ($ matches as $ match ) {
516
528
$ method ['name ' ] = trim ($ match ['name ' ], '`" \'' );
517
529
//add slashes only for single quotes
518
530
$ method ['statement ' ] = str_replace ("' " , "\' " ,trim ($ match ['statement ' ]));
531
+ $ method ['statement ' ] = preg_replace ('@(--.*)\s+@ ' , '' , $ method ['statement ' ]);
519
532
520
533
$ method ['params ' ] = $ this ->parseParameters ($ match ['params ' ]);
521
534
@@ -526,6 +539,10 @@ function ($m) {
526
539
}
527
540
}
528
541
542
+ function getModel () {
543
+ return $ this ->tree ;
544
+ }
545
+
529
546
function generateModel () {
530
547
$ methods = '' ;
531
548
@@ -614,12 +631,26 @@ function ($param) {
614
631
}
615
632
} ,$method['params'])), "\n\t");
616
633
*/
634
+ /*
617
635
$method['param_types'] = 'array(' . trim(implode(', ', array_map(
618
636
function ($param) {
619
637
if ($param['in_out'] == 'IN' && ($type = $this->paramType($param['type']))) {
620
638
return '\'' . $param['name'] . '\' => \'' . $type . '\'';
621
639
}
622
640
} ,$method['params'])), ', ') . ')';
641
+ */
642
+
643
+ $ paramTypes = [];
644
+
645
+ foreach ($ method ['params ' ] as $ param ) {
646
+ if ($ param ['in_out ' ] == 'IN ' && ($ type = $ this ->paramType ($ param ['type ' ]))) {
647
+ $ paramTypes [$ param ['name ' ]] = $ type ;
648
+ }
649
+ }
650
+
651
+ $ this ->paramTypes [$ method ['name ' ]] = $ paramTypes ;
652
+
653
+ $ method ['param_types ' ] = '$this->paramTypes[ \'' . $ method ['name ' ] . '\'] ' ;
623
654
624
655
$ method ['fetch ' ] = $ this ->fetchType ('fetch_all ' );
625
656
@@ -661,10 +692,12 @@ function ($param) {
661
692
}
662
693
663
694
$ model = $ this ->template ($ this ->model ['model ' ],[
664
- 'name ' => ucfirst ($ this ->modelName ),
665
- 'namespace ' => ucfirst ($ this ->namespace ),
666
- 'filename ' => $ this ->filename ,
667
- 'methods ' => $ methods ,
695
+ 'name ' => ucfirst ($ this ->modelName ),
696
+ 'namespace ' => ucfirst ($ this ->namespace ),
697
+ 'filename ' => $ this ->filename ,
698
+ 'methods ' => $ methods ,
699
+ 'filters ' => var_export ($ this ->filters , true ),
700
+ 'paramTypes ' => var_export ($ this ->paramTypes , true ),
668
701
]);
669
702
670
703
return $ model ;
0 commit comments