Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility support from v7 to v10 for startThread and namespace #1105

Merged
merged 2 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Discord/Parts/Channel/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -942,8 +942,20 @@ protected function getDefaultReactionEmojiAttribute(): ?Reaction
*
* @since 10.0.0 Arguments for `$name`, `$private` and `$auto_archive_duration` are now inside `$options`
*/
public function startThread(array $options, ?string $reason = null): ExtendedPromiseInterface
public function startThread(array|string $options, string|null|bool $reason = null, int $_auto_archive_duration = 1440, ?string $_reason = null): ExtendedPromiseInterface
{
// Old v7 signature
if (is_string($options)) {
$options = [
'name' => $options,
'auto_archive_duration' => $_auto_archive_duration,
];
if (is_bool($reason)) {
$options['private'] = $reason;
}
$reason = $_reason;
}

$resolver = new OptionsResolver();
$resolver
->setDefined([
Expand Down
13 changes: 12 additions & 1 deletion src/Discord/Parts/Channel/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,19 @@ public function getLinkAttribute(): ?string
*
* @since 10.0.0 Arguments for `$name` and `$auto_archive_duration` are now inside `$options`
*/
public function startThread(array $options, ?string $reason = null): ExtendedPromiseInterface
public function startThread(array|string $options, string|null|int $reason = null, ?string $_reason = null): ExtendedPromiseInterface
{
// Old v7 signature
if (is_string($options)) {
$options = [
'name' => $options,
];
if (! is_string($reason)) {
$options['auto_archive_duration'] = $reason ?? 1440;
}
$reason = $_reason;
}

$resolver = new OptionsResolver();
$resolver
->setDefined([
Expand Down
7 changes: 7 additions & 0 deletions src/Discord/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,10 @@ function nowait(PromiseInterface $promiseInterface)

return $resolved;
}

/**
* File namespaces that were changed in new versions are aliased
*/
class_alias(\Discord\Repository\Channel\StageInstanceRepository::class, '\Discord\Repository\Guild\StageInstanceRepository'); // @since 10.0.0
class_alias(\Discord\Parts\Guild\CommandPermissions::class, '\Discord\Parts\Interactions\Command\Overwrite'); // @since 10.0.0
class_alias(\Discord\Repository\Guild\CommandPermissionsRepository::class, '\Discord\Repository\Guild\OverwriteRepository'); // @since 10.0.0