1

This question is about PSR-0 autoloaded libraries and the way main configuration constants should be declared and used.

From your point of view (lib/framework developer), where/how should be declared your library configuration PHP constants (such as ESCAPE_SOMETHING, USE_DOM, API_URL, ...) in such a way that

  • your code can easily address them
  • client code can easily modify them depending on needs

Is there any convention, recommendation, or even something I missed in PSR-0 I should be aware of?

asked Jan 9, 2014 at 14:32
1
  • I am wondering if they could go directly into the file which contains the autoloader logic itself. However, I do not like the fact that people will have to edit this file to modify configuration. Commented Jan 9, 2014 at 14:35

1 Answer 1

1

This question is about PSR-0 autoloaded libraries

I think you're conflating two different issues. Finding and loading the PHP code for FooClass is (or ought to be) a different problem from how new FooClass() or FooClass::staticThing() should behave.

Ideally, FooClass shouldn't care whether I (the guy using the library) relied on an autoloader or whether I hard-coded my own require_once() statement.

library configuration PHP constants

One ground-rule first... never with constants from define(). Polluting the global namespace is a bad idea, and IIRC even the new namespace features are a little weird in that regard. Class-constants on the library classes are acceptable, but as the library-consumer you probably aren't hand-editing those.

From your point of view (lib/framework developer), where/how should be declared your library configuration PHP constants

You mean, how would I prefer for consumer code to set options that affect my code? I'd prefer something like:

FooLibraryConfigurator::set("a","b");
FooClass::doStuffThatNeededConfData();

In other words, configure my library based on a mechanism I created for you to use. :p

answered Jan 9, 2014 at 19:30
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.