Skip to content

Commit

Permalink
new types
Browse files Browse the repository at this point in the history
  • Loading branch information
madmages committed May 2, 2021
1 parent 96a9e4e commit 820af21
Show file tree
Hide file tree
Showing 111 changed files with 5,359 additions and 917 deletions.
904 changes: 696 additions & 208 deletions src/Client.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Type/AbstractInlineQueryResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace MadmagesTelegram\Types\Type;

abstract class AbstractInlineQueryResult {}
abstract class AbstractInlineQueryResult extends AbstractType {}
2 changes: 1 addition & 1 deletion src/Type/AbstractInputMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace MadmagesTelegram\Types\Type;

abstract class AbstractInputMedia {}
abstract class AbstractInputMedia extends AbstractType {}
2 changes: 1 addition & 1 deletion src/Type/AbstractInputMessageContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace MadmagesTelegram\Types\Type;

abstract class AbstractInputMessageContent {}
abstract class AbstractInputMessageContent extends AbstractType {}
2 changes: 1 addition & 1 deletion src/Type/AbstractPassportElementError.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace MadmagesTelegram\Types\Type;

abstract class AbstractPassportElementError {}
abstract class AbstractPassportElementError extends AbstractType {}
11 changes: 10 additions & 1 deletion src/Type/AbstractType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ abstract public static function _getPropertyNames(): array;
*
* @return array
*/
abstract public function _getRawData(): array;
abstract public function _getData(): array;

protected function normalizeData(array $data):array {
array_filter($data);
array_walk_recursive($data, static function(&$item){
$item = $item instanceof AbstractType ? $item->_getData(): $item;
});

return $data;
}

}
7 changes: 2 additions & 5 deletions src/Type/Animation.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function _getPropertyNames(): array
*
* @return array
*/
public function _getRawData(): array
public function _getData(): array
{
$result = [
'file_id' => $this->getFileId(),
Expand All @@ -59,10 +59,7 @@ public function _getRawData(): array
'file_size' => $this->getFileSize(),
];

$result = array_filter($result, static function($item){ return $item!==null; });
return array_map(static function(&$item){
return is_object($item) ? $item->_getRawData():$item;
}, $result);
return parent::normalizeData($result);
}

/**
Expand Down
39 changes: 34 additions & 5 deletions src/Type/Audio.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static function _getPropertyNames(): array
'duration',
'performer',
'title',
'file_name',
'mime_type',
'file_size',
'thumb',
Expand All @@ -44,23 +45,21 @@ public static function _getPropertyNames(): array
*
* @return array
*/
public function _getRawData(): array
public function _getData(): array
{
$result = [
'file_id' => $this->getFileId(),
'file_unique_id' => $this->getFileUniqueId(),
'duration' => $this->getDuration(),
'performer' => $this->getPerformer(),
'title' => $this->getTitle(),
'file_name' => $this->getFileName(),
'mime_type' => $this->getMimeType(),
'file_size' => $this->getFileSize(),
'thumb' => $this->getThumb(),
];

$result = array_filter($result, static function($item){ return $item!==null; });
return array_map(static function(&$item){
return is_object($item) ? $item->_getRawData():$item;
}, $result);
return parent::normalizeData($result);
}

/**
Expand Down Expand Up @@ -116,6 +115,17 @@ public function _getRawData(): array
*/
protected $title;

/**
* Optional. Original filename as defined by sender
*
* @var string|null
* @SkipWhenEmpty
* @SerializedName("file_name")
* @Accessor(getter="getFileName",setter="setFileName")
* @Type("string")
*/
protected $fileName;

/**
* Optional. MIME type of the file as defined by sender
*
Expand Down Expand Up @@ -245,6 +255,25 @@ public function getTitle(): ?string
return $this->title;
}

/**
* @param string $fileName
* @return static
*/
public function setFileName(string $fileName): self
{
$this->fileName = $fileName;

return $this;
}

/**
* @return string|null
*/
public function getFileName(): ?string
{
return $this->fileName;
}

/**
* @param string $mimeType
* @return static
Expand Down
7 changes: 2 additions & 5 deletions src/Type/BotCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,14 @@ public static function _getPropertyNames(): array
*
* @return array
*/
public function _getRawData(): array
public function _getData(): array
{
$result = [
'command' => $this->getCommand(),
'description' => $this->getDescription(),
];

$result = array_filter($result, static function($item){ return $item!==null; });
return array_map(static function(&$item){
return is_object($item) ? $item->_getRawData():$item;
}, $result);
return parent::normalizeData($result);
}

/**
Expand Down
10 changes: 4 additions & 6 deletions src/Type/CallbackQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
* https://core.telegram.org/bots/api#callbackquery
*
* This object represents an incoming callback query from a callback button in an inline keyboard. If the button that originated the query was attached to a message sent by the bot, the field
* message will be present. If the button was attached to a message sent via the bot (in inline mode), the field inline_message_id will be present. Exactly one of the fields data or
* message will be present. If the button was attached to a message sent via the bot (in inline
* mode), the field inline_message_id will be present. Exactly one of the fields data or
* game_short_name will be present.
*
* @ExclusionPolicy("none")
Expand Down Expand Up @@ -45,7 +46,7 @@ public static function _getPropertyNames(): array
*
* @return array
*/
public function _getRawData(): array
public function _getData(): array
{
$result = [
'id' => $this->getId(),
Expand All @@ -57,10 +58,7 @@ public function _getRawData(): array
'game_short_name' => $this->getGameShortName(),
];

$result = array_filter($result, static function($item){ return $item!==null; });
return array_map(static function(&$item){
return is_object($item) ? $item->_getRawData():$item;
}, $result);
return parent::normalizeData($result);
}

/**
Expand Down
Loading

0 comments on commit 820af21

Please sign in to comment.