I don't see how true DCI can be implemented in PHP without source code transformation or a custom PHP extension written in C. Of these I think source code transformation would be easier to implement and also have fewer potential installation issues. ....
transfer
(TransferMoneySource withdraw: Amount)
ifTrue: [TransferMoneySink deposit].
My compiler extensions translate this into this code that is compiled in the usual manner
transfer
((BB1ContextStack playerForRole: #cc)
to: #TransferMoneySource
send: #withdraw:
withArgs: {BB1ContextStack playerForRole: #Amount})
ifTrue: [(BB1ContextStack playerForRole: #cc)
to: #TransferMoneySink
send: #deposit
withArgs: {}] transfer
(CurrentContext
to: #TransferMoneySource
send: #withdraw:
withArgs: Amount)
ifTrue: [CurrentContext to: #TransferMoneySink
send: #deposit
withArgs: {}]
The next step is the tricky one: to send a message through a
role:1. to: roleName send: selector withArgs: argCollection
2. | receiver roleClass compiledMethod |
3. receiver := roleMap at: roleName.
4. roleClass := self class roleClassForRoleName: roleName.
5. roleClass ifNotNil: [compiledMethod := roleClass methodDict
at: selector ifAbsent: [nil]].
6. compiledMethod
7. ifNil: [^receiver perform: selector withArguments:
argCollection asArray]
8. ifNotNil: [^receiver withArgs: argCollection asArray
executeMethod: compiledMethod]