Sitelet https://github.com/dereuromark/cakephp-templating/pull/20
Skip to content

Collect icon names from svgPath directories and JSON maps - #20

Merged
dereuromark merged 1 commit into
masterfrom
fix/svg-dir-names
Oct 2, 2026
Merged

dereuromark merged 1 commit into
masterfrom
fix/svg-dir-names

Conversation

@dereuromark

Copy link
Copy Markdown
Owner

Setting svgPath to a directory of individual SVGs (for example vendor/fortawesome/font-awesome/svgs/solid/ with FontAwesome7Icon) and leaving path unset triggered this notice on every helper init:

file_get_contents(): Read of 73728 bytes failed with errno=21 Is a directory

Without path, AbstractIcon::path() falls back to svgPath for name collection, and IconCollection::buildMap() calls names() in its constructor. Several collectors did not handle that fallback.

Fixes

  • SVG directory as svgPath: the FontAwesome 4/5/6/7, Bootstrap and Material collectors passed the directory to file_get_contents(). They now collect the .svg file names, like Lucide and Feather already did.
  • JSON SVG map as svgPath: path() rejected it with "is not a directory". buildMap() swallowed that error, so auto-prefixing silently stopped working. With checkExistence on, the helper failed at construction. This hit the Feather JSON map example in the docs. The map keys are now used as icon names for every set.
  • Collector cache collision: the in-memory collector cache was one static array shared by all collector classes and keyed only by path. Two sets reading the same path through different collectors got the first collector's result. The cache key now includes the collector class.
  • Standalone IconCollection: render() failed with a TypeError unless separator was passed explicitly. Only IconHelper set a default. IconCollection now defaults it to : as well.

I probed all nine icon classes through IconCollection with checkExistence on, in both modes (SVG directory and JSON map). Each case now returns names and raises no notices.

The docs page docs/helpers/icon-configuration.md now describes the svgPath fallback for name collection.

Without a `path`, AbstractIcon::path() falls back to `svgPath` for name
collection. IconCollection::buildMap() calls names() on construction, so
the fallback runs on every helper init, not only with checkExistence.

- FontAwesome4/5/6 (and so 7), Bootstrap and Material collectors fed an
  svgPath directory straight to file_get_contents(), raising
  "Read of N bytes failed with errno=21 Is a directory". They now scan
  the directory for .svg file names, like Lucide/Feather already did.
- A JSON SVG map as svgPath was rejected with "is not a directory",
  which buildMap() swallowed, silently disabling auto-prefixing (and
  failing hard with checkExistence). path() now accepts an existing
  .json map; the map keys are the icon names. FA4/Material read it as
  JSON, FA6 skips style detection for plain string map entries.
- The collector in-memory cache is a single static array shared by all
  subclasses and was keyed by path only, so two collectors reading the
  same path got each other's result. The key now includes the class.
- IconCollection defaults `separator` to ':' so it works standalone
  without IconHelper.
@dereuromark dereuromark added the bug Something isn't working label Oct 2, 2026
@coderabbitai

coderabbitai Bot commented Oct 2, 2026

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 494639d5-e02e-44f0-acd5-12eee837bb0b

📥 Commits

Reviewing files that changed from the base of the PR and between dd00d46 and d5ddf99.

⛔ Files ignored due to path filters (4)
  • tests/test_files/font_icon/bootstrap_svg/gear.svg is excluded by !**/*.svg
  • tests/test_files/font_icon/bootstrap_svg/house.svg is excluded by !**/*.svg
  • tests/test_files/font_icon/fa6_svg/thumbs-up.svg is excluded by !**/*.svg
  • tests/test_files/font_icon/fa6_svg/user.svg is excluded by !**/*.svg
📒 Files selected for processing (19)
  • docs/helpers/icon-configuration.md
  • src/View/Icon/AbstractIcon.php
  • src/View/Icon/Collector/AbstractCollector.php
  • src/View/Icon/Collector/BootstrapIconCollector.php
  • src/View/Icon/Collector/FontAwesome4IconCollector.php
  • src/View/Icon/Collector/FontAwesome5IconCollector.php
  • src/View/Icon/Collector/FontAwesome6IconCollector.php
  • src/View/Icon/Collector/MaterialIconCollector.php
  • src/View/Icon/IconCollection.php
  • tests/TestCase/View/Icon/AbstractIconTest.php
  • tests/TestCase/View/Icon/Collector/BootstrapIconCollectorTest.php
  • tests/TestCase/View/Icon/Collector/FontAwesome4CollectorTest.php
  • tests/TestCase/View/Icon/Collector/FontAwesome5CollectorTest.php
  • tests/TestCase/View/Icon/Collector/FontAwesome6CollectorTest.php
  • tests/TestCase/View/Icon/Collector/HeroiconsIconCollectorTest.php
  • tests/TestCase/View/Icon/Collector/MaterialIconCollectorTest.php
  • tests/TestCase/View/Icon/FontAwesome6IconTest.php
  • tests/TestCase/View/Icon/IconCollectionTest.php
  • tests/test_files/font_icon/svg_map.json
 _________________________________________________
< Let's pair program: you type, I judge lovingly. >
 -------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dereuromark
dereuromark merged commit 6879ab2 into master Oct 2, 2026
4 of 5 checks passed
@dereuromark
dereuromark deleted the fix/svg-dir-names branch October 2, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant