Skip to content

Commit 0d08e67

Browse files
committed
tweak: do some micro optimizations in pathresolver
1 parent efd31bc commit 0d08e67

File tree

2 files changed

+6
-41
lines changed

2 files changed

+6
-41
lines changed

README.md

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -158,31 +158,6 @@ The plugin automatically registers a file-based cache configuration named `attri
158158

159159
2. **Manual Configuration**: Define your own `attribute_registry` cache config in `config/app.php` before the plugin loads
160160

161-
### Context-Aware Caching
162-
163-
The plugin uses **separate cache keys** for CLI and web contexts to ensure accuracy when plugins are loaded conditionally:
164-
165-
- **Web Context**: `attribute_registry_web` - Only includes plugins loaded in web requests
166-
- **CLI Context**: `attribute_registry_cli` - Includes CLI-only plugins (marked with `'onlyCli' => true`)
167-
168-
This prevents issues where CLI-only plugins would be cached but unavailable in web requests, or vice versa.
169-
170-
**Key Points:**
171-
- Each context discovers and caches independently on first access
172-
- `clearCache()` automatically clears both context caches
173-
- Storage overhead is minimal (~2x cache space, negligible for most applications)
174-
- Cache expiration handles staleness automatically (1 month default)
175-
176-
**Example workflow:**
177-
```php
178-
// Run discovery in CLI (includes CLI-only plugins)
179-
$ bin/cake attribute discover
180-
181-
// Web requests use their own cache (only web-accessible plugins)
182-
$registry = AttributeRegistry::getInstance();
183-
$attributes = $registry->discover(); // Uses web context cache
184-
```
185-
186161
## Usage
187162

188163
### Accessing the AttributeRegistry
@@ -506,7 +481,7 @@ bin/cake attribute list --type method
506481

507482
Output:
508483
```
509-
Found 8 attributes:
484+
Found 5 attributes:
510485
511486
+---------------------------+----------------------------------+--------+-----------------+
512487
| Attribute | Class | Type | Target |
@@ -556,14 +531,6 @@ The panel provides:
556531
- Search functionality to filter attributes
557532
- Re-discover button to refresh the attribute cache
558533

559-
> [!NOTE]
560-
> **Context-aware caching**: The plugin uses separate cache keys for CLI and web contexts. If you notice different attributes in the DebugKit panel compared to CLI commands, this is expected behavior when plugins are configured with `'onlyCli' => true` in your `config/plugins.php`.
561-
>
562-
> - **Web context** (DebugKit panel): Only shows attributes from plugins loaded in web requests
563-
> - **CLI context** (commands): Shows attributes from all plugins, including CLI-only plugins
564-
>
565-
> Each context maintains its own cache and discovers attributes independently based on which plugins are actually loaded.
566-
567534
## Testing
568535

569536
Run the test suite:

src/Service/PathResolver.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private function expandGlobPattern(string $pattern): Generator
9797
if (strpos($pattern, '**') !== false) {
9898
yield from $this->expandRecursivePattern($pattern);
9999
} else {
100-
$files = glob($pattern, GLOB_BRACE) ?: [];
100+
$files = glob($pattern, GLOB_BRACE | GLOB_NOSORT) ?: [];
101101
yield from $files;
102102
}
103103
}
@@ -120,15 +120,13 @@ private function expandRecursivePattern(string $pattern): Generator
120120

121121
$iterator = new RecursiveIteratorIterator(
122122
new RecursiveDirectoryIterator($basePath, RecursiveDirectoryIterator::SKIP_DOTS),
123-
RecursiveIteratorIterator::SELF_FIRST,
123+
RecursiveIteratorIterator::LEAVES_ONLY,
124124
);
125125

126126
foreach ($iterator as $file) {
127-
if ($file->isFile()) {
128-
$filePath = $file->getPathname();
129-
if (empty($suffix) || fnmatch('*' . $suffix, basename($filePath))) {
130-
yield $filePath;
131-
}
127+
$filePath = $file->getPathname();
128+
if (empty($suffix) || fnmatch('*' . $suffix, basename($filePath))) {
129+
yield $filePath;
132130
}
133131
}
134132
}

0 commit comments

Comments
 (0)