Skip to content
This repository was archived by the owner on Apr 5, 2020. It is now read-only.

Conversation

@mikey179
Copy link

@mikey179 mikey179 commented Jul 7, 2011

Hi,

I just added the port of the Stubbles IoC mechanism to XP. It comes with full unit test coverage, but no further integration into the framework. It may have issues with the XP coding standard, please feel free to point those out.

I do not intend that this pull request gets merged soon (however: feel free if you want to ;), it should be used as a platform to discussion on what should be improved or even how it might be integrated into the framework itself beside being available as code.

Regards,
Frank

@mikey179
Copy link
Author

mikey179 commented Jul 7, 2011

Hm, this shouldn't include the ignore commit... well, ignore the ignores. :)

@kiesel
Copy link
Member

kiesel commented Jul 8, 2011

Nice to see this patch here - thanks!

Frank Kleine added 5 commits July 10, 2011 19:50
…ternal comparing mechanism of lang.Object as it's base implementation not only checks for equality but also for identity which was tried to achieve using spl_object_hash()
@mikey179
Copy link
Author

  • Regarding $ in api doc parameters: this is the standard throughout the PHP world. From a quick check it shouldn't be too complicated to support this?
  • Type union syntax: question is how it should be supported by reflection - when reflecting for the type what should it return? One class which denotes it's a combined type (would be backward compatible), or an array of types. Interestingly, Stubbles' reflection doesn't support it either, but I never stumbled about a problem with this.

@thekid
Copy link
Member

thekid commented Jul 11, 2011

@mikey179:

  1. I think we can support both $ and no-$ variants. This is just an update to the coding standards sind lang.XPClass doesn't parse the parameter name.

  2. @implementedBy and @providedBy are better than all-lowercase, yes.

  3. Type unions might come in handy but will need some thought in exactly the direction you were going in:-) In the XP Framework, we currently solve this by using var (accepts every type), but seeing either a string or an xml.Tree can be passed to xml.XPath's constructor would be cooler. ECMAScript 5 has this, IIRC.

@mikey179
Copy link
Author

Ok, then I'll leave it as it is now. Which in turn brings me to the question of integration into XP. Do we want to cover it within this pull request? Personally I don't think it should be done here - the code is already usable and allows developers to toy around with it. I suggest to gather ideas and handle it with another branch (and pull request), as it takes much more time to develop a working and thought out solution.

@kiesel
Copy link
Member

kiesel commented Jul 26, 2011

No, this pull request should just focus on getting the initial code in, so I agree with @mikey179. We can then take care of integrating this where suitable or toy around with it at the beginning.

What I see as the next steps: we'd like to soonish release XP 5.8.2 - our first github release. After this has been released, I'd like to merge this pull request.

@ghost
Copy link

ghost commented Aug 30, 2011

Are there any News on this? We are currently reimplementing the Dataset layer, where this would come in handy in a number of situations, along with an integration into the Scriptlet engine.

@kiesel
Copy link
Member

kiesel commented Sep 4, 2011

We plan to include this into HEAD, once 5.8.2 is out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we cannot set a name for every method parameter, the @named option (in the implementation above) doesn't really makes sense on methods with more than 1 argument:

#[@inject, @named('???')]
function setTires(Tire $frontLeftTire, Tire $frontRightTire, Tire $backLeftTire, Tire $backRightTire)

Maybe something like this would be more fitting, but I don't find it is very readable:

#[@inject, @named('front-left', 'front-right', 'back-left', 'back-right')]
function setTires(Tire $frontLeftTire, Tire $frontRightTire, Tire $backLeftTire, Tire $backRightTire)

And one other thing that doesn't seem right to me: shouldn't @named be treated as part of the @inject annotation, exactly like the optional= TRUE?

#[@xmlmapping(element= 'tires'), @inject(optional= TRUE, named=['front-left', 'front-right', 'back-left', 'back-right']]
function setTires(Tire $frontLeftTire, Tire $frontRightTire, Tire $backLeftTire, Tire $backRightTire)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would it look like if only the last parameter should be named? Something like this?

#[@inject(named=[null, null, 'myapp.config.path'])]
__construct(Processor $proc, Request $req, $configPath)

As there probably will be no parameter annotations in XP it might make sense to treat named as part of the @inject annotation, it just didn't make sense in where it comes from. One might want to move back once parameter annotations become possible, however, I'm undecided on this. What's your take on this, @thekid and @kiesel?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we're not adding this before 5.9 we might as well add parameter annotations, too:)

__construct(Processor $proc, Request $req, /*[@inject(named = 'Myapp.config.path')]*/ $configPath)

Not sure what kind of a performance impact these would have.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if there will be parameter annotations the merge of @inject and @named wouldn't make sense, so this should be decided beforehand then. :-)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... the example in #116 (method parameter annotations) makes me think about integrating the @named into @inject - having @inject on parameters and not restricted to methods only makes the injector slower and more complicated, as it now must not only check for method annotations, but also for parameter annotations in order to know if the method needs to be called for completing the injection on an instance. I'd rather deny this request now. If you have more than one parameter, and only one is annotated with @inject and the other is not, what's the meaning of that?

@thekid
Copy link
Member

thekid commented Dec 20, 2011

Wiring could be done in classpath initializers, see xp-framework/rfc#220

@xpbot
Copy link

xpbot commented Feb 12, 2013

Can one of the admins verify this patch?

@thekid thekid closed this May 12, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants