11<?php
22
3+ declare (strict_types=1 );
4+
35namespace GeneaLabs \LaravelModelCaching ;
46
57use BackedEnum ;
8+ use DateTimeInterface ;
69use Exception ;
710use GeneaLabs \LaravelModelCaching \Traits \CachePrefixing ;
811use Illuminate \Database \Query \Expression ;
@@ -137,11 +140,6 @@ protected function getInAndNotInClauses(array $where) : string
137140
138141 $ type = strtolower ($ where ["type " ]);
139142 $ subquery = $ this ->getValuesFromWhere ($ where );
140- $ values = collect ($ this ->getCurrentBinding ('where ' , []));
141-
142- if (Str::startsWith ($ subquery , $ values ->first ())) {
143- $ this ->currentBinding += count ($ where ["values " ]);
144- }
145143
146144 if (! is_numeric ($ subquery ) && ! is_numeric (str_replace ("_ " , "" , $ subquery ))) {
147145 try {
@@ -154,6 +152,23 @@ protected function getInAndNotInClauses(array $where) : string
154152 }
155153 }
156154
155+ $ placeholderCount = preg_match_all ('/\?(?=(?:[^"]*"[^"]*")*[^"]*\Z)/m ' , $ subquery );
156+
157+ if ($ placeholderCount === 0 ) {
158+ if (data_get ($ where , "values " )) {
159+ $ this ->currentBinding += count (data_get ($ where , "values " ));
160+ }
161+
162+ $ values = $ this ->recursiveImplode ([$ subquery ], "_ " );
163+
164+ return "- {$ where ["column " ]}_ {$ type }{$ values }" ;
165+ }
166+
167+ $ values = collect (data_get ($ this ->query ->bindings , "where " ))
168+ ->slice ($ this ->currentBinding , $ placeholderCount )
169+ ->values ();
170+ $ this ->currentBinding += $ placeholderCount ;
171+
157172 $ subquery = preg_replace ('/\?(?=(?:[^"]*"[^"]*")*[^"]*\Z)/m ' , "_??_ " , $ subquery );
158173 $ subquery = str_replace ('% ' , '%% ' , $ subquery );
159174 $ subquery = collect (vsprintf (str_replace ("_??_ " , "%s " , $ subquery ), $ values ->toArray ()));
@@ -370,7 +385,7 @@ protected function getValuesFromBindings(array $where, string $values) : string
370385 $ values = $ values ->format ("Y-m-d-H-i-s " );
371386 }
372387
373- return $ values ;
388+ return ( string ) $ values ;
374389 }
375390
376391 protected function getWhereClauses (array $ wheres = []) : string
@@ -483,17 +498,20 @@ protected function recursiveImplode(array $items, string $glue = ",") : string
483498 return $ result ;
484499 }
485500
486- private function processEnum (BackedEnum |UnitEnum |Expression |string |null $ value ): ?string
487- {
501+ private function processEnum (
502+ BackedEnum |UnitEnum |Expression |DateTimeInterface |int |float |bool |string |null $ value ,
503+ ): string {
488504 if ($ value instanceof BackedEnum) {
489505 return $ value ->value ;
490506 } elseif ($ value instanceof UnitEnum) {
491507 return $ value ->name ;
492508 } elseif ($ value instanceof Expression) {
493509 return $ this ->expressionToString ($ value );
510+ } elseif ($ value instanceof DateTimeInterface) {
511+ return $ value ->format ("Y-m-d-H-i-s " );
494512 }
495513
496- return $ value ;
514+ return "{ $ value}" ;
497515 }
498516
499517 private function processEnums (array $ values ): array
0 commit comments