Skip to content

Commit

Permalink
refactor(TemplateCardMessage): optimize options configuration
Browse files Browse the repository at this point in the history
- Updated the `addHorizontalContent`, `addJump`, and `addVerticalContent` methods to directly assign the provided arrays to their respective options lists.
- Refactored the options configuration in the `configureOptions` method to set default values and define prototypes for `horizontal_content_list`, `jump_list`, and `vertical_content_list`.
  • Loading branch information
guanguans committed Mar 2, 2024
1 parent d5ffe1c commit 65f203a
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions src/WeWork/Messages/TemplateCardMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,52 +67,21 @@ class TemplateCardMessage extends Message

public function addHorizontalContent(array $horizontalContent): self
{
$this->options['horizontal_content_list'][] = $this->configureAndResolveOptions(
$horizontalContent,
static function (OptionsResolver $optionsResolver): void {
$optionsResolver->setDefined([
'type',
'keyname',
'value',
'url',
'media_id',
'userid',
]);
}
);
$this->options['horizontal_content_list'][] = $horizontalContent;

return $this;
}

public function addJump(array $jump): self
{
$this->options['jump_list'][] = $this->configureAndResolveOptions(
$jump,
static function (OptionsResolver $optionsResolver): void {
$optionsResolver->setDefined([
'type',
'title',
'url',
'appid',
'pagepath',
]);
}
);
$this->options['jump_list'][] = $jump;

return $this;
}

public function addVerticalContent(array $verticalContent): self
{
$this->options['vertical_content_list'][] = $this->configureAndResolveOptions(
$verticalContent,
static function (OptionsResolver $optionsResolver): void {
$optionsResolver->setDefined([
'title',
'desc',
]);
}
);
$this->options['vertical_content_list'][] = $verticalContent;

return $this;
}
Expand Down Expand Up @@ -178,6 +147,37 @@ protected function configureOptionsResolver(OptionsResolver $optionsResolver): v
'desc',
'image_url',
]);
})
->setDefault('horizontal_content_list', static function (OptionsResolver $optionsResolver): void {
$optionsResolver
->setPrototype(true)
->setDefined([
'type',
'keyname',
'value',
'url',
'media_id',
'userid',
]);
})
->setDefault('jump_list', static function (OptionsResolver $optionsResolver): void {
$optionsResolver
->setPrototype(true)
->setDefined([
'type',
'title',
'url',
'appid',
'pagepath',
]);
})
->setDefault('vertical_content_list', static function (OptionsResolver $optionsResolver): void {
$optionsResolver
->setPrototype(true)
->setDefined([
'title',
'desc',
]);
});
}
}

0 comments on commit 65f203a

Please sign in to comment.