zendframework / zend-config

Config component from Zend Framework
BSD 3-Clause "New" or "Revised" License
90 stars 38 forks source link

PR: Writer\PhpArray option to use ::class literals #5

Closed akomm closed 8 years ago

akomm commented 9 years ago

Similar to the use_bracket_array_syntax-option, I would propose to add a use_class_contant-option.

If enabled, string keys and values should be checked for being a known full qualified class- or-interface name, using class_exists and interface_exists.

Additional option use_class_constant_autoload might be added, to set whether autoload should be used.

It only works if the names are defined in the main file, were included/required from another script or a registered autoloader can resolve them.

I'v tried it on some packages, which use this writer and it worked well without breaking anything.

Possible issues:

Writing config in a different context than reading it (e. G. different autoloader configs). But since it is an option you don't have to use it. Depending on usage context you can localy enable this option for development and disable for deployment.

Ocramius commented 9 years ago

@akomm seems like an interesting/useful change. Give it a spin, and then we discuss on a PR directly.

florentsorel commented 7 years ago

The PR doesn't seems to contain the autoloading feature :/

For example, when I want to write a FQCN with the ::class I would like to change the context from autoload because my CLI application create some config file (factories for example) and obiously the checkStringIsFqn method return always false because my class doesn't exists in my autoloader.

akomm commented 7 years ago

@florentsorel I can't quite follow you in a way which would make this feature being responsible to handle it. this feature is and should not be aware of how your classes are loaded and made available. You either include/require them manually or use any autoloading feature. If you do not make your classes available, they can not be verified.

If you meant something different, please explain it with an example.