From 9d3360f2642d76963eb966d0276fe32f1a643167 Mon Sep 17 00:00:00 2001
From: Eric Lupinacci <eric@smellup.net>
Date: Sun, 31 Mar 2024 11:21:21 +0200
Subject: [PATCH] =?UTF-8?q?feat:=20ajouter=20une=20option=20=C3=A0=20la=20?=
 =?UTF-8?q?fonction=20find=5Fall=5Fin=5Fpath()=20pour=20renvoyer=20tous=20?=
 =?UTF-8?q?les=20fichiers=20r=C3=A9pondant=20=C3=A0=20un=20pattern?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Refs: #5454
---
 ecrire/bootstrap/inc/path.php | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/ecrire/bootstrap/inc/path.php b/ecrire/bootstrap/inc/path.php
index eefaa3f977..43f830c081 100644
--- a/ecrire/bootstrap/inc/path.php
+++ b/ecrire/bootstrap/inc/path.php
@@ -308,7 +308,7 @@ function save_path_cache() {
  * Trouve tous les fichiers du path correspondants à un pattern
  *
  * Pour un nom de fichier donné, ne retourne que le premier qui sera trouvé
- * par un `find_in_path()`
+ * par un `find_in_path()`, sauf si l'option `all_files` est activée.
  *
  * @api
  * @uses creer_chemin()
@@ -316,10 +316,11 @@ function save_path_cache() {
  *
  * @param string $dir
  * @param string $pattern
- * @param bool $recurs
+ * @param bool   $recurs
+ * @param bool   $all_files
  * @return array
  */
-function find_all_in_path($dir, $pattern, $recurs = false) {
+function find_all_in_path($dir, $pattern, $recurs = false, bool $all_files = false) {
 	$liste_fichiers = [];
 	$maxfiles = 10000;
 
@@ -336,10 +337,13 @@ function find_all_in_path($dir, $pattern, $recurs = false) {
 			$liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs);
 			foreach ($liste as $chemin) {
 				$nom = basename($chemin);
-				// ne prendre que les fichiers pas deja trouves
-				// car find_in_path prend le premier qu'il trouve,
-				// les autres sont donc masques
-				if (!isset($liste_fichiers[$nom])) {
+				if ($all_files) {
+					// On accumule tous les fichiers de même nom
+					$liste_fichiers[$nom][] = $chemin;
+				} elseif (!isset($liste_fichiers[$nom])) {
+					// ne prendre que les fichiers pas deja trouves
+					// car find_in_path prend le premier qu'il trouve,
+					// les autres sont donc masques
 					$liste_fichiers[$nom] = $chemin;
 				}
 			}
-- 
GitLab