filtre de base
This commit is contained in:
		
							parent
							
								
									f34694e12d
								
							
						
					
					
						commit
						2c7020f44d
					
				| @ -146,8 +146,11 @@ class Capacitor implements ITransactor { | ||||
|   function chargeAll(?iterable $items, $func=null, ?array $args=null): int { | ||||
|     $count = 0; | ||||
|     if ($items !== null) { | ||||
|       if ($func !== null) { | ||||
|         $func = func::with($func, $args)->bind($this->channel); | ||||
|       } | ||||
|       foreach ($items as $item) { | ||||
|         $count += $this->charge($item, $func, $args); | ||||
|         $count += $this->charge($item, $func); | ||||
|       } | ||||
|     } | ||||
|     return $count; | ||||
|  | ||||
| @ -444,7 +444,7 @@ class CapacitorChannel implements ITransactor { | ||||
|     return $this->capacitor->charge($item, $func, $args, $row); | ||||
|   } | ||||
| 
 | ||||
|   function chargeAll(iterable $items, $func=null, ?array $args=null): int { | ||||
|   function chargeAll(?iterable $items, $func=null, ?array $args=null): int { | ||||
|     return $this->capacitor->chargeAll($items, $func, $args); | ||||
|   } | ||||
| 
 | ||||
| @ -452,23 +452,49 @@ class CapacitorChannel implements ITransactor { | ||||
|     return $this->capacitor->discharge($reset); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * retourner le filtre de base: les filtres de toutes les fonctions ci-dessous | ||||
|    * sont fusionnées avec le filtre de base | ||||
|    * | ||||
|    * cela permet de limiter toutes les opérations à un sous-ensemble des données | ||||
|    * du canal | ||||
|    */ | ||||
|   function getBaseFilter(): ?array { | ||||
|     return null; | ||||
|   } | ||||
| 
 | ||||
|   protected function verifixFilter(&$filter): void { | ||||
|     if ($filter !== null && !is_array($filter)) { | ||||
|       $primaryKeys = $this->primaryKeys ?? ["id_"]; | ||||
|       $id = $filter; | ||||
|       $this->verifixId($id); | ||||
|       $filter = [$primaryKeys[0] => $id]; | ||||
|     } | ||||
|     $filter = cl::merge($this->getBaseFilter(), $filter); | ||||
|   } | ||||
| 
 | ||||
|   function count($filter=null): int { | ||||
|     $this->verifixFilter($filter); | ||||
|     return $this->capacitor->count($filter); | ||||
|   } | ||||
| 
 | ||||
|   function one($filter, ?array $mergeQuery=null): ?array { | ||||
|     $this->verifixFilter($filter); | ||||
|     return $this->capacitor->one($filter, $mergeQuery); | ||||
|   } | ||||
| 
 | ||||
|   function all($filter, ?array $mergeQuery=null): Traversable { | ||||
|     $this->verifixFilter($filter); | ||||
|     return $this->capacitor->all($filter, $mergeQuery); | ||||
|   } | ||||
| 
 | ||||
|   function each($filter, $func=null, ?array $args=null, ?array $mergeQuery=null, ?int &$nbUpdated=null): int { | ||||
|     $this->verifixFilter($filter); | ||||
|     return $this->capacitor->each($filter, $func, $args, $mergeQuery, $nbUpdated); | ||||
|   } | ||||
| 
 | ||||
|   function delete($filter, $func=null, ?array $args=null): int { | ||||
|     $this->verifixFilter($filter); | ||||
|     return $this->capacitor->delete($filter, $func, $args); | ||||
|   } | ||||
| 
 | ||||
|  | ||||
| @ -434,7 +434,7 @@ abstract class CapacitorStorage { | ||||
|     } | ||||
| 
 | ||||
|     if ($func !== null) { | ||||
|       $updates = func::with($func) | ||||
|       $updates = func::with($func, $args) | ||||
|         ->prependArgs([$item, $row, $prow]) | ||||
|         ->bind($channel) | ||||
|         ->invoke(); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user