modxcms/revolution — pull request #557 by pbowyer (2013-08-13 08:13:10+00:00)
Title: Support the `use` statement in MODX snippets/plugins

This patch gives MODX Revolution support for using the `use` statement (and hence namespaced code) in snippets and plugins (anything extending modScript).

### Why is this change needed?

MODX wraps snippet and plugin code in function calls, and use statements cannot be inside a function or method. Our change extracts use statements and puts them outside the function.

### Why is this important?

Anyone using Composer-installed packages needs to be able to reference namespaced code.

### About the patch

This code makes use of PHP's tokenizer. So far we have not found any examples that break the patch and throw errors, but somewhere in the Gigabytes of PHP code written there may be something that does...

The patch is unopinionated about how namespaced code is loaded. It does not contain a class loader, and one isn't necessary to benefit from the change.