| 1 |
<?php |
| 2 |
/** |
| 3 |
* Model class for handling the option of cdegn_functions |
| 4 |
*/ |
| 5 |
final class Meow_CDEGN_Models_Cdegn_Function implements JsonSerializable { |
| 6 |
|
| 7 |
/** @var int */ |
| 8 |
private $snippet_id; |
| 9 |
|
| 10 |
/** @var string */ |
| 11 |
private $snippet_src; |
| 12 |
|
| 13 |
/** @var string */ |
| 14 |
private $name; |
| 15 |
|
| 16 |
/** @var string */ |
| 17 |
private $desc; |
| 18 |
|
| 19 |
/** @var array */ |
| 20 |
private $args; |
| 21 |
|
| 22 |
public function __construct( array $item ) { |
| 23 |
$this->snippet_id = $item['snippet_id']; |
| 24 |
$this->snippet_src = $item['snippet_src']; |
| 25 |
$this->name = $item['name']; |
| 26 |
$this->desc = $item['desc']; |
| 27 |
$this->args = array_map( function( $arg_variable, $arg_info ) { |
| 28 |
return new Meow_CDEGN_Models_Cdegn_Function_Arg( $arg_variable, $arg_info ); |
| 29 |
}, array_keys( $item['args'] ), $item['args'] ); |
| 30 |
} |
| 31 |
|
| 32 |
public function snippet_id(): int { |
| 33 |
return $this->snippet_id; |
| 34 |
} |
| 35 |
|
| 36 |
public function snippet_src(): string { |
| 37 |
return $this->snippet_src; |
| 38 |
} |
| 39 |
|
| 40 |
public function overview(): string { |
| 41 |
$args = array_map( function( $arg ) { return $arg->format(); }, $this->args ); |
| 42 |
$overview = sprintf( 'function %s( %s )', $this->name, implode( ', ', $args ) ); |
| 43 |
return $overview; |
| 44 |
} |
| 45 |
|
| 46 |
public function jsonSerialize(): mixed { |
| 47 |
return [ |
| 48 |
'snippetId' => $this->snippet_id, |
| 49 |
'snippetSrc' => $this->snippet_src, |
| 50 |
'name' => $this->name, |
| 51 |
'desc' => $this->desc, |
| 52 |
'args' => $this->args, |
| 53 |
]; |
| 54 |
} |
| 55 |
} |
| 56 |
|