composer-config-plugin icon indicating copy to clipboard operation
composer-config-plugin copied to clipboard

Rewrite to use parser or tokenizer instead of serializing

Open samdark opened this issue 5 years ago • 4 comments

The idea is further development of https://github.com/yiisoft/composer-config-plugin/pull/117.

Potentially we can avoid serializing by following these steps while merging configs:

  1. Tokenize/parse config. Replace all closures, $_ENV references and require with unique placeholders. Original code strings are kept in an array where key is this unique unique placeholder name.
  2. Read configs produced during step 1 with PHP. Merge them.
  3. Tokenize/parse config produced during step 2. Replace unique placeholders with strings saved during step 1.

Advantages

  • No need to serialize anything.
  • Will likely work well with PHP 8.
  • No need to depend on opis/closure (PHP 8 isn't ready, requires FFI for it) or riimu/kit-phpencoder (isn't active, extra layer).
  • End user will get native syntax for require and $_ENV.

Disadvantages

  • Likely not straightforward to implement.
  • Requires maintenance.

samdark avatar Aug 25 '20 19:08 samdark

https://trello.com/c/zxrr0ArI/98-rewrite-composer-config-plugin-to-use-parser-or-tokenizer-instead-of-serializing

samdark avatar Aug 25 '20 19:08 samdark

@Mirocow will attempt implementing it.

samdark avatar Aug 31 '20 19:08 samdark

https://gist.github.com/samdark/86f2b9ff01a96892efbbf254eca8482d

samdark avatar Sep 16 '20 20:09 samdark

Updated gist above based on recent chat discussions.

samdark avatar Nov 27 '20 17:11 samdark