-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split replace/delete original from response type
- Loading branch information
Showing
7 changed files
with
205 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SlackPhp\BlockKit\Surfaces\MessageDirective; | ||
|
||
use SlackPhp\BlockKit\Exception; | ||
|
||
enum DeleteOriginal | ||
{ | ||
case DELETE_ORIGINAL; | ||
case DONT_DELETE_ORIGINAL; | ||
|
||
/** | ||
* @return array<string, string> | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return match ($this) { | ||
self::DELETE_ORIGINAL => ['delete_original' => 'true'], | ||
self::DONT_DELETE_ORIGINAL => ['delete_original' => 'false'], | ||
}; | ||
} | ||
|
||
/** | ||
* @param self|array<string, string>|bool|null $data | ||
* @return static|null | ||
*/ | ||
public static function fromValue(self|array|bool|null $data): ?self | ||
{ | ||
if ($data instanceof self) { | ||
return $data; | ||
} | ||
|
||
if (is_bool($data)) { | ||
return $data ? self::DELETE_ORIGINAL : self::DONT_DELETE_ORIGINAL; | ||
} | ||
|
||
if (is_array($data)) { | ||
$data = array_filter($data); | ||
return match ($data) { | ||
['delete_original' => 'true'] => self::DELETE_ORIGINAL, | ||
['delete_original' => 'false'] => self::DONT_DELETE_ORIGINAL, | ||
[] => null, | ||
default => throw new Exception('Invalid Delete Original enum encountered: %s', [json_encode($data)]), | ||
}; | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SlackPhp\BlockKit\Surfaces\MessageDirective; | ||
|
||
use SlackPhp\BlockKit\Exception; | ||
|
||
enum ReplaceOriginal | ||
{ | ||
case REPLACE_ORIGINAL; | ||
case DONT_REPLACE_ORIGINAL; | ||
|
||
/** | ||
* @return array<string, string> | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return match ($this) { | ||
self::REPLACE_ORIGINAL => ['replace_original' => 'true'], | ||
self::DONT_REPLACE_ORIGINAL => ['replace_original' => 'false'], | ||
}; | ||
} | ||
|
||
/** | ||
* @param self|array<string, string>|bool|null $data | ||
* @return static|null | ||
*/ | ||
public static function fromValue(self|array|bool|null $data): ?self | ||
{ | ||
if ($data instanceof self) { | ||
return $data; | ||
} | ||
|
||
if (is_bool($data)) { | ||
return $data ? self::REPLACE_ORIGINAL : self::DONT_REPLACE_ORIGINAL; | ||
} | ||
|
||
if (is_array($data)) { | ||
$data = array_filter($data); | ||
return match ($data) { | ||
['replace_original' => 'true'] => self::REPLACE_ORIGINAL, | ||
['replace_original' => 'false'] => self::DONT_REPLACE_ORIGINAL, | ||
[] => null, | ||
default => throw new Exception('Invalid Replace Original enum encountered: %s', [json_encode($data)]), | ||
}; | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.