-
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.
Support messages in output handlers using OutputResponse (#13)
- Loading branch information
Showing
14 changed files
with
451 additions
and
149 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Valantic\PimcoreFormsBundle\Constant; | ||
|
||
interface MessageConstants | ||
{ | ||
public const MESSAGE_TYPE_SUCCESS = 'success'; | ||
public const MESSAGE_TYPE_ERROR = 'error'; | ||
public const MESSAGE_TYPE_WARNING = 'warning'; | ||
public const MESSAGE_TYPE_INFO = 'info'; | ||
|
||
public const MESSAGE_TYPES = [ | ||
self::MESSAGE_TYPE_SUCCESS, | ||
self::MESSAGE_TYPE_ERROR, | ||
self::MESSAGE_TYPE_WARNING, | ||
self::MESSAGE_TYPE_INFO, | ||
]; | ||
} |
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
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,104 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Valantic\PimcoreFormsBundle\Model; | ||
|
||
use Iterator; | ||
use JsonSerializable; | ||
use ReturnTypeWillChange; | ||
use RuntimeException; | ||
use Stringable; | ||
|
||
/** | ||
* @implements Iterator<string, mixed> | ||
*/ | ||
abstract class AbstractMessage implements JsonSerializable, Iterator, Stringable | ||
{ | ||
protected ?string $position = null; | ||
|
||
public function __toString(): string | ||
{ | ||
return (string) json_encode($this->jsonSerialize(), \JSON_THROW_ON_ERROR); | ||
} | ||
|
||
/** | ||
* @return array<mixed> | ||
*/ | ||
public function jsonSerialize(): array | ||
{ | ||
return $this->arraySerialize(); | ||
} | ||
|
||
public function valid(): bool | ||
{ | ||
return in_array($this->position, $this->validKeys(), true); | ||
} | ||
|
||
public function next(): void | ||
{ | ||
$keys = $this->validKeys(); | ||
$pos = array_search($this->position, $keys, true); | ||
|
||
$this->position = $keys[(int) $pos + 1] ?? null; | ||
} | ||
|
||
#[ReturnTypeWillChange] | ||
public function current() | ||
{ | ||
return $this->{$this->position}; | ||
} | ||
|
||
public function rewind(): void | ||
{ | ||
$this->position = $this->validKeys()[0]; | ||
} | ||
|
||
/** | ||
* @return array<mixed> | ||
*/ | ||
public function arraySerialize(): array | ||
{ | ||
$data = []; | ||
|
||
foreach ($this->requiredAttributes() as $attribute) { | ||
if (!isset($this->{$attribute})) { | ||
throw new RuntimeException(); | ||
} | ||
$data[$attribute] = $this->{$attribute}; | ||
} | ||
|
||
foreach ($this->optionalAttributes() as $attribute) { | ||
if (!isset($this->{$attribute})) { | ||
continue; | ||
} | ||
|
||
$data[$attribute] = $this->{$attribute}; | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
public function key(): ?string | ||
{ | ||
return $this->position; | ||
} | ||
|
||
/** | ||
* @return array<mixed> | ||
*/ | ||
protected function validKeys(): array | ||
{ | ||
return array_keys($this->arraySerialize()); | ||
} | ||
|
||
/** | ||
* @return array<mixed> | ||
*/ | ||
abstract protected function requiredAttributes(): array; | ||
|
||
/** | ||
* @return array<mixed> | ||
*/ | ||
abstract protected function optionalAttributes(): array; | ||
} |
Oops, something went wrong.