From 6a0ff0f29c671577ce51488dca662337898c1cd8 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 23 Sep 2022 10:25:10 -0600 Subject: [PATCH 1/6] reverted as not used --- StreamWrapper/src/ReadOnlyStream.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/StreamWrapper/src/ReadOnlyStream.php b/StreamWrapper/src/ReadOnlyStream.php index b2e3e0f..d53b0c5 100644 --- a/StreamWrapper/src/ReadOnlyStream.php +++ b/StreamWrapper/src/ReadOnlyStream.php @@ -18,8 +18,6 @@ class ReadOnlyStream extends Stream /** @var ResourceLocatorInterface */ protected static $locator; - public $context; - /** * @param string $uri * @param string $mode From 2e98d3b82760e6781493d2b380d00c4fccf9117b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Droz?= Date: Fri, 29 Apr 2022 12:48:12 -0300 Subject: [PATCH 2/6] expand import@ before applying other transformations --- Blueprints/src/BlueprintForm.php | 44 +++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/Blueprints/src/BlueprintForm.php b/Blueprints/src/BlueprintForm.php index 242d257..fcc22d2 100644 --- a/Blueprints/src/BlueprintForm.php +++ b/Blueprints/src/BlueprintForm.php @@ -142,6 +142,7 @@ public function load($extends = null) } // Import blueprints. + while ($this->deepImport($this->items)) {} $this->deepInit($this->items); } catch (Exception $e) { $filename = $this->filename; @@ -387,6 +388,45 @@ protected function deepMerge(array $a, array $b) return $a; } + + /** + * @param array $items + * @param array $path + * @return string + */ + protected function deepImport(array &$items, $path = []) + { + $run_again = false; + $field = end($path) === 'fields'; + + foreach ($items as $key => &$item) { + if ($field && isset($item['type'])) { + $item['name'] = $key; + } + // Handle special instructions in the form. + if (strpos($key, '@') !== false) { + // Remove @ from the start and the end. Key syntax `import@2` is supported to allow multiple operations of the same type. + $list = explode('-', (string)preg_replace('/^(@*)?([^@]+)(@\d*)?$/', '\2', $key), 2); + $action = array_shift($list); + + if ($action == 'import') { + unset($items[$key]); + $this->doImport($item, $path); + $run_again = true; + break; + } + } elseif (\is_array($item)) { + // Recursively initialize form. + $newPath = array_merge($path, [$key]); + while ($this->deepImport($item, $newPath)) { + } + } + } + unset($item); + + return $run_again; + } + /** * @param array $items * @param array $path @@ -418,10 +458,6 @@ protected function deepInit(array &$items, $path = []) return null; } break; - case 'import': - unset($items[$key]); - $this->doImport($item, $path); - break; case 'ordering': $ordering = $item; unset($items[$key]); From e9bff204059a600edb92bf6774ab0ef277969e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Droz?= Date: Fri, 29 Apr 2022 12:53:36 -0300 Subject: [PATCH 3/6] fix #33 --- Blueprints/src/BlueprintForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Blueprints/src/BlueprintForm.php b/Blueprints/src/BlueprintForm.php index fcc22d2..796fbb9 100644 --- a/Blueprints/src/BlueprintForm.php +++ b/Blueprints/src/BlueprintForm.php @@ -471,7 +471,7 @@ protected function deepInit(array &$items, $path = []) $newPath = array_merge($path, [$key]); $location = $this->deepInit($item, $newPath); - if ($location) { + if ($location || $location === 0) { $order[$key] = $location; } elseif ($location === null) { unset($items[$key]); From 01793d8815d1a97cc32eae74b3036c533b56579b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Droz?= Date: Tue, 27 Sep 2022 11:49:11 -0300 Subject: [PATCH 4/6] further simplify deepImport() --- Blueprints/src/BlueprintForm.php | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/Blueprints/src/BlueprintForm.php b/Blueprints/src/BlueprintForm.php index 796fbb9..79f79f6 100644 --- a/Blueprints/src/BlueprintForm.php +++ b/Blueprints/src/BlueprintForm.php @@ -404,17 +404,11 @@ protected function deepImport(array &$items, $path = []) $item['name'] = $key; } // Handle special instructions in the form. - if (strpos($key, '@') !== false) { - // Remove @ from the start and the end. Key syntax `import@2` is supported to allow multiple operations of the same type. - $list = explode('-', (string)preg_replace('/^(@*)?([^@]+)(@\d*)?$/', '\2', $key), 2); - $action = array_shift($list); - - if ($action == 'import') { - unset($items[$key]); - $this->doImport($item, $path); - $run_again = true; - break; - } + if (strpos($key, '@') !== false && preg_match('/^(@*)?import(@\d*)?$/', $key)) { + unset($items[$key]); + $this->doImport($item, $path); + $run_again = true; + break; } elseif (\is_array($item)) { // Recursively initialize form. $newPath = array_merge($path, [$key]); From 31e06263f1f6665b12456ee81320afdc66c78ea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Droz?= Date: Tue, 27 Sep 2022 11:49:36 -0300 Subject: [PATCH 5/6] process @ as long as suffix is not null --- Blueprints/src/BlueprintForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Blueprints/src/BlueprintForm.php b/Blueprints/src/BlueprintForm.php index 79f79f6..db1ea36 100644 --- a/Blueprints/src/BlueprintForm.php +++ b/Blueprints/src/BlueprintForm.php @@ -465,7 +465,7 @@ protected function deepInit(array &$items, $path = []) $newPath = array_merge($path, [$key]); $location = $this->deepInit($item, $newPath); - if ($location || $location === 0) { + if (null !== $location) { $order[$key] = $location; } elseif ($location === null) { unset($items[$key]); From 1aabe9e45393b99d7eff13aa1854bf6db45375b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Droz?= Date: Tue, 27 Sep 2022 11:59:28 -0300 Subject: [PATCH 6/6] cleaner recursion --- Blueprints/src/BlueprintForm.php | 42 +++++++++++++++----------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/Blueprints/src/BlueprintForm.php b/Blueprints/src/BlueprintForm.php index db1ea36..0437a1e 100644 --- a/Blueprints/src/BlueprintForm.php +++ b/Blueprints/src/BlueprintForm.php @@ -142,7 +142,7 @@ public function load($extends = null) } // Import blueprints. - while ($this->deepImport($this->items)) {} + $this->deepImport($this->items); $this->deepInit($this->items); } catch (Exception $e) { $filename = $this->filename; @@ -396,29 +396,27 @@ protected function deepMerge(array $a, array $b) */ protected function deepImport(array &$items, $path = []) { - $run_again = false; - $field = end($path) === 'fields'; - - foreach ($items as $key => &$item) { - if ($field && isset($item['type'])) { - $item['name'] = $key; - } - // Handle special instructions in the form. - if (strpos($key, '@') !== false && preg_match('/^(@*)?import(@\d*)?$/', $key)) { - unset($items[$key]); - $this->doImport($item, $path); - $run_again = true; - break; - } elseif (\is_array($item)) { - // Recursively initialize form. - $newPath = array_merge($path, [$key]); - while ($this->deepImport($item, $newPath)) { + do { + $run_again = false; + $field = end($path) === 'fields'; + foreach ($items as $key => &$item) { + if ($field && isset($item['type'])) { + $item['name'] = $key; + } + // Handle import@ + if (strpos($key, '@') !== false && preg_match('/^(@*)?import(@\d*)?$/', $key)) { + unset($items[$key]); + $this->doImport($item, $path); + $run_again = true; + break; + } elseif (\is_array($item)) { + // Recursively initialize form. + $newPath = array_merge($path, [$key]); + $this->deepImport($item, $newPath); } } - } - unset($item); - - return $run_again; + unset($item); + } while ($run_again); } /**