Little background: payload is the representation of a message being send, using a specific transport. The builder pattern is used to build different representation (as
array, or as a
Swift_Message object) of the same message.
But depending on the method used (basic, classic, etc...) and transport itself, some properties should be ignored (for example
validity shouldn't be included if message is
"basic"): here comes the decorator pattern, that decorates the builder itself (it's a builder).
BasicPayloadDecorator has an empty implementation of
buildValidity() method. The
MethodGuzzleDecorator adds some authentication information to the
array representation of the message (created by
For building an array representation of a "basic" message, adding authentication information:
$builder = new MethodGuzzleDecorator( new BasicPayloadDecorator(new GuzzlePostDataPayloadBuilder()), 'username', 'password', 'method' ); $message = new Message(); $builder->build(); $builder->buildText($message); $builder->buildEncoding($message); $builder->buildCharset($message); $builder->buildRecipients($message); $builder->buildSenderNumber($message); $builder->buildSenderString($message); $builder->buildValidity($message); $builder->buildDeliveryStart($message); $builder->buildUserReference($message); /** @var $payload array */ $payload = $builder->getResult(); $response = $transport->handle(payload);
Do you think I'm doing this right? I can't find any information about using the decorator against the builder. Here is the full diagram image. Thanks.