-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7939e2f
commit 861c94e
Showing
10 changed files
with
961 additions
and
3 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
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,115 @@ | ||
<?php | ||
namespace MassimoFilippi\SlackModule\Model; | ||
|
||
/** | ||
* Class Attachment | ||
* @package MassimoFilippi\SlackModule\Model | ||
*/ | ||
class Attachment extends \Maknz\Slack\Attachment | ||
{ | ||
/** | ||
* The actions of the attachment | ||
* | ||
* @var array | ||
*/ | ||
protected $actions = []; | ||
|
||
/** | ||
* Attachment constructor. | ||
* @param array $attributes | ||
*/ | ||
public function __construct(array $attributes) | ||
{ | ||
parent::__construct($attributes); | ||
|
||
if(isset($attributes['actions'])) $this->setActions($attributes['actions']); | ||
} | ||
|
||
/** | ||
* Get the actions for the attachment | ||
* | ||
* @return array | ||
*/ | ||
public function getActions() | ||
{ | ||
return $this->actions; | ||
} | ||
|
||
/** | ||
* Set the actions for the attachment | ||
* | ||
* @param array $actions | ||
* @return $this | ||
*/ | ||
public function setActions(array $actions) | ||
{ | ||
$this->clearActions(); | ||
|
||
foreach ($actions as $action) { | ||
$this->addAction($action); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Add a action to the attachment | ||
* | ||
* @param mixed $action | ||
* @return $this | ||
*/ | ||
public function addAction($action) | ||
{ | ||
if ($action instanceof AttachmentAction) { | ||
$this->actions[] = $action; | ||
|
||
return $this; | ||
} elseif (is_array($action)) { | ||
$this->actions[] = new AttachmentAction($action); | ||
|
||
return $this; | ||
} | ||
|
||
throw new \InvalidArgumentException('The attachment action must be an instance of '. AttachmentAction::class .' or a keyed array'); | ||
} | ||
|
||
/** | ||
* Clear the actions for the attachment | ||
* | ||
* @return $this | ||
*/ | ||
public function clearActions() { | ||
$this->actions = []; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Convert this attachment to its array representation | ||
* | ||
* @return array | ||
*/ | ||
public function toArray() | ||
{ | ||
$data = parent::toArray(); | ||
|
||
$data['actions'] = $this->getActionsAsArrays(); | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* Iterates over all actions in this attachment and returns | ||
* them in their array form | ||
* | ||
* @return array | ||
*/ | ||
protected function getActionsAsArrays() | ||
{ | ||
$actions = []; | ||
|
||
foreach ($this->getActions() as $action) $actions[] = $action->toArray(); | ||
|
||
return $actions; | ||
} | ||
} |
Oops, something went wrong.