danadesrosiers/silex-annotation-provider

Annotation context?

Closed this issue · 1 comments

I was wondering if it would be possible to add a way to pass some sort of context (array/map/object) into the generated annotations? This would be very useful for me :)

The point is that it could allow to make the annotations behave differently depending on the environment, etc.

For example, I'd like to add an environment requirement, so some annotations are only active/used if the environment matches.

if this sounds like something useful I'd be happy to create a pull request...

Just looked at the code again - maybe an optional ContextAwareInterface so the process method can look for that?

Also, any implementations would need to make the context transient to avoid caching issues, I suppose...

Something like this:

interface ContextAware {
  function setContext($context);
}

With an optional context in pimple, for example:

$app["annot.context"] = $app->share(function () { return array('env' => 'dev'); });