2022-09-01 09:49:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
2024-03-30 16:44:38 +01:00
|
|
|
namespace Hosterra\FluxBuilder\Type;
|
|
|
|
|
|
|
|
|
|
use Hosterra\FluxBuilder\Type;
|
|
|
|
|
|
|
|
|
|
class FnType implements TypeInterface {
|
|
|
|
|
/**
|
|
|
|
|
* @var array $params
|
|
|
|
|
*/
|
|
|
|
|
protected $params;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string $content
|
|
|
|
|
*/
|
|
|
|
|
protected $content;
|
|
|
|
|
|
|
|
|
|
private function __construct( array $params ) {
|
|
|
|
|
$this->params = $params;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function params( array $params ) {
|
|
|
|
|
return new self( $params );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function withBody( string $content ) {
|
|
|
|
|
$this->content = $content;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function withBlock( string $content ) {
|
|
|
|
|
$this->content = '{ ' . $content . ' }';
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function __toString(): string {
|
|
|
|
|
array_walk( $this->params, function ( &$value, $key ) {
|
|
|
|
|
if ( is_string( $key ) ) {
|
|
|
|
|
$value = $key . ' = ' . new Type( $value );
|
|
|
|
|
}
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
return '(' . implode( ', ', $this->params ) . ') => ' . $this->content;
|
|
|
|
|
}
|
2022-09-01 09:49:14 +00:00
|
|
|
}
|