Skip to content

Commit

Permalink
修复语法兼容性问题
Browse files Browse the repository at this point in the history
  • Loading branch information
iwillhappy1314 committed Aug 15, 2023
1 parent c372821 commit 89b0046
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 44 deletions.
4 changes: 2 additions & 2 deletions src/Controls/AjaxUploadInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class AjaxUploadInput extends BaseControl
public function __construct($label = null, bool $multiple = false, array $settings = null)
{
parent::__construct($label);
$this->control->multiple = (bool)$multiple;
$this->control->multiple = $multiple;
$this->control->type = 'text';
$this->settings = (array)$settings;

Expand Down Expand Up @@ -187,7 +187,7 @@ public function getHtmlName(): string
*
* @return $this
*/
public function setUrl($url): static {
public function setUrl($url) {
$this->url = $url;

return $this;
Expand Down
4 changes: 2 additions & 2 deletions src/Controls/AutoCompleteInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AutoCompleteInput extends TextInput {

private array $settings = [];

public string|array $source = '';
public $source = '';

/**
* @param null $label
Expand Down Expand Up @@ -54,7 +54,7 @@ public function getControl(): Html {
/**
* 设置输入提示源
*/
public function setSource( $source ): static {
public function setSource( $source ) {
$this->source = $source;

return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/Controls/CaptchaInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function getControl(): Html {
*
* @return $this
*/
public function setUrl( $url ): static {
public function setUrl( $url ) {
$this->url = $url;

return $this;
Expand Down
14 changes: 8 additions & 6 deletions src/Controls/CheckboxTreeInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace Wenprise\Forms\Controls;

use Nette\Forms\Controls\MultiChoiceControl;
use Nette\InvalidArgumentException;
use Nette\Utils\Html;
use Nette\Utils\Strings;

/**
* 克隆输入
Expand Down Expand Up @@ -46,16 +48,16 @@ private function recursiveRender($list): Html {
return $html;
}

public function setValue($values): CheckboxTreeInput|static {
public function setValue($values) {
if (is_scalar($values) || $values === null) {
$values = (array)$values;
} elseif ( ! is_array($values)) {
throw new \Nette\InvalidArgumentException(sprintf("Value must be array or NULL, %s given in field '%s'.", gettype($values), $this->name));
throw new InvalidArgumentException(sprintf("Value must be array or NULL, %s given in field '%s'.", gettype($values), $this->name));
}
$flip = [];
foreach ($values as $value) {
if ( ! is_scalar($value) && ! method_exists($value, '__toString')) {
throw new \Nette\InvalidArgumentException(sprintf("Values must be scalar, %s given in field '%s'.", gettype($value), $this->name));
throw new InvalidArgumentException(sprintf("Values must be scalar, %s given in field '%s'.", gettype($value), $this->name));
}
$flip[ (string)$value ] = true;
}
Expand All @@ -67,16 +69,16 @@ public function setValue($values): CheckboxTreeInput|static {
$nestedKeys[] = $key;
});
if ($diff = array_diff($values, $nestedKeys)) {
$range = \Nette\Utils\Strings::truncate(implode(', ', array_map(function ($s) { return var_export($s, true); }, $nestedKeys)), 70, '...');
$range = Strings::truncate(implode(', ', array_map(function ($s) { return var_export($s, true); }, $nestedKeys)), 70, '...');
$vals = (count($diff) > 1 ? 's' : '') . " '" . implode("', '", $diff) . "'";
throw new \Nette\InvalidArgumentException("Value$vals are out of allowed range [$range] in field '{$this->name}'.");
throw new InvalidArgumentException("Value$vals are out of allowed range [$range] in field '$this->name'.");
}
$this->value = $values;

return $this;
}

public function getLabel($caption = null): Html|string|null {
public function getLabel($caption = null) {
return parent::getLabel($caption)->for(null);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Controls/CsrfInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CsrfInput extends HiddenField


/**
* @param string|object
* @param string|object $errorMessage
*/
public function __construct($errorMessage)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Controls/GroupInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class GroupInput extends TextInput {
/**
* @var string|null
*/
public string|null $prefix;
public $prefix;

/**
* @var string|null
*/
public string|null $suffix;
public $suffix;


/**
Expand Down Expand Up @@ -46,7 +46,7 @@ public function __construct( $label = null, $maxLength = null, string $prefix =
*
* @return $this
*/
public function setPrefix( string $prefix ): static {
public function setPrefix( string $prefix ) {
$this->prefix = $prefix;

return $this;
Expand All @@ -60,7 +60,7 @@ public function setPrefix( string $prefix ): static {
*
* @return $this
*/
public function setSuffix( string $suffix ): static {
public function setSuffix( string $suffix ) {
$this->suffix = $suffix;

return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/Controls/HtmlContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getLabel( $caption = null ): void {
*
* @return string
*/
public function getControl(object|string $caption = null ): string {
public function getControl( $caption = null ): string {
$this->setOption( 'rendered', true );

return $this->getCaption();
Expand Down
8 changes: 4 additions & 4 deletions src/Controls/InquiryInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function getControl(): string
<?php foreach ($fields as $field): ?>
<?php
$field_type = Helpers::data_get($field, 'type', 'text');
$field_name= Helpers::data_get($field, 'name', );
$field_name= Helpers::data_get($field, 'name' );
?>
<td>
<?php if ( $field_type === 'text' ) : ?>
Expand All @@ -151,7 +151,7 @@ public function getControl(): string
<textarea x-model="field.<?= $field_name; ?>" name="<?= $field_name; ?>[]" cols="30" rows="10"></textarea>
<?php elseif($field_type === 'select'): ?>
<select x-model="field.<?= $field_name; ?>" name="<?= $field_name; ?>[]">
<?php foreach (Helpers::data_get($field, 'options', ) as $option_key => $option_value): ?>
<?php foreach (Helpers::data_get($field, 'options' ) as $option_key => $option_value): ?>
<option value="<?= $option_key; ?>"><?= $option_value; ?></option>
<?php endforeach; ?>
</select>
Expand Down Expand Up @@ -192,7 +192,7 @@ public function getControl(): string
<?php foreach ($fields as $field): ?>
<?php
$field_type = Helpers::data_get($field, 'type', 'text');
$field_name= Helpers::data_get($field, 'name', );
$field_name= Helpers::data_get($field, 'name' );
?>
<div class="rs-form-group rs-form--text rs-row rs-col-md-12" id="rs-form-company_name">
<div class="rs-col-sm-3 rs-control-label">
Expand All @@ -207,7 +207,7 @@ public function getControl(): string
<textarea x-model="_field._<?= $field_name; ?>" name="_<?= $field_name; ?>" cols="30" rows="10" class="form-control rs-form-control"></textarea>
<?php elseif($field_type === 'select'): ?>
<select x-model="_field._<?= $field_name; ?>" name="_<?= $field_name; ?>">
<?php foreach (Helpers::data_get($field, 'options', ) as $option_key => $option_value): ?>
<?php foreach (Helpers::data_get($field, 'options' ) as $option_key => $option_value): ?>
<option value="<?= $option_key; ?>"><?= $option_value; ?></option>
<?php endforeach; ?>
</select>
Expand Down
2 changes: 1 addition & 1 deletion src/Controls/SmsInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function getControl(): Html
*
* @return $this
*/
public function setUrl($url): static
public function setUrl($url)
{
$this->url = $url;

Expand Down
8 changes: 4 additions & 4 deletions src/Controls/WpUploaderInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ class WpUploaderInput extends BaseControl {

/**
* @param null $label
* @param bool
* @param array|null $settings Chosen 设置
* @param bool $multiple
* @param array|null $settings Chosen 设置
*/
public function __construct( $label = null, $multiple = false, array $settings = null ) {
public function __construct($label = null, bool $multiple = false, array $settings = null ) {
parent::__construct( $label );
$this->control->multiple = (bool) $multiple;
$this->control->multiple = $multiple;
$this->control->type = 'text';
$this->settings = (array) $settings;

Expand Down
2 changes: 1 addition & 1 deletion src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Form extends \Nette\Forms\Form implements HtmlStringable
{

public IDatastore|null $datastore = null;
public $datastore = null;

/**
* @param \Wenprise\Forms\Datastores\IDatastore $datastore
Expand Down
14 changes: 8 additions & 6 deletions src/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Wenprise\Forms;

use Closure;

class Helpers
{

Expand All @@ -12,7 +14,7 @@ class Helpers
*
* @return false|string
*/
public static function get_grandparent_class($object): bool|string
public static function get_grandparent_class($object)
{
if (is_object($object)) {
$object = get_class($object);
Expand All @@ -29,9 +31,9 @@ public static function get_grandparent_class($object): bool|string
*
* @return mixed
*/
public static function value(mixed $value): mixed
public static function value($value)
{
return $value instanceof \Closure ? $value() : $value;
return $value instanceof Closure ? $value() : $value;
}


Expand All @@ -44,7 +46,7 @@ public static function value(mixed $value): mixed
*
* @return mixed
*/
public static function data_get(array $array, string $key, mixed $default = null): mixed
public static function data_get(array $array, string $key, $default = null)
{

if (isset($array[ $key ])) {
Expand All @@ -71,7 +73,7 @@ public static function data_get(array $array, string $key, mixed $default = null
*
* @return mixed|null
*/
public static function http_get($key = null, $default = null): mixed
public static function input_get($key = null, $default = null)
{
return static::data_get($_REQUEST, $key, $default);
}
Expand Down Expand Up @@ -116,7 +118,7 @@ public static function dir_to_url($directory): string
*
* @return mixed
*/
public static function get_manifest(): mixed
public static function get_manifest()
{
static $manifest;
static $manifest_path;
Expand Down
2 changes: 1 addition & 1 deletion src/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function register_assets(): void
*
* @return void
*/
#[NoReturn] function save_form_data(): void
function save_form_data(): void
{
$data = $_POST;

Expand Down
2 changes: 1 addition & 1 deletion src/Renders/AdminFormRender.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AdminFormRender extends BaseFormRender
{
use Nette\SmartObject;

var mixed $type = 'post_meta';
var $type = 'post_meta';

public function __construct($type = 'post_meta')
{
Expand Down
11 changes: 6 additions & 5 deletions src/Renders/BaseFormRender.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Wenprise\Forms\Renders;

use Nette;
use Nette\InvalidArgumentException;
use Nette\Utils\Html;
use Nette\HtmlStringable;

Expand Down Expand Up @@ -43,14 +44,14 @@ public function __construct($type = 'horizontal')
/**
* 渲染控件组,主要添加 Html render
*
* @param Nette\Forms\Container|Nette\Forms\ControlGroup
* @param Nette\Forms\Container|Nette\Forms\ControlGroup $parent
*
* @return string
*/
public function renderControls($parent): string
{
if ( ! ($parent instanceof Nette\Forms\Container || $parent instanceof Nette\Forms\ControlGroup)) {
throw new \Nette\InvalidArgumentException('Argument must be Nette\Forms\Container or Nette\Forms\ControlGroup instance.');
throw new InvalidArgumentException('Argument must be Nette\Forms\Container or Nette\Forms\ControlGroup instance.');
}

$container = $this->getWrapper('controls container');
Expand Down Expand Up @@ -89,7 +90,7 @@ public function renderControls($parent): string
/**
* 在一行中渲染多个控件,主要添加 wrapper class
*
* @param Nette\Forms\IControl[]
* @param Nette\Forms\IControl[] $controls
*
* @return string
*/
Expand All @@ -98,7 +99,7 @@ public function renderPairMulti(array $controls): string
$s = [];
foreach ($controls as $control) {
if ( ! $control instanceof Nette\Forms\Control) {
throw new Nette\InvalidArgumentException('Argument must be array of Nette\Forms\IControl instances.');
throw new InvalidArgumentException('Argument must be array of Nette\Forms\IControl instances.');
}

$description = $control->getOption('description');
Expand Down Expand Up @@ -161,7 +162,7 @@ public function renderPairMulti(array $controls): string
*
* @return \Nette\Utils\Html|string
*/
public function renderControlGroup($control): Html|string
public function renderControlGroup($control)
{
$html = '';

Expand Down
8 changes: 4 additions & 4 deletions src/Renders/FormRender.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class FormRender extends Nette\Forms\Rendering\DefaultFormRenderer
/**
* 渲染控件组
*
* @param Nette\Forms\Container|Nette\Forms\ControlGroup
* @param Nette\Forms\Container|Nette\Forms\ControlGroup $parent
*
* @return string
*/
Expand Down Expand Up @@ -206,7 +206,7 @@ public function renderPair(Nette\Forms\Control $control): string
}

// 中间
$group->addHtml($this->renderControl($control->setAttribute('class', 'rs-form-control'))
$group->addHtml($this->renderControl($control->setHtmlAttribute('class', 'rs-form-control'))
->getChildren()[ 0 ]);

// 后缀
Expand Down Expand Up @@ -245,15 +245,15 @@ public function renderPair(Nette\Forms\Control $control): string
/**
* 在一行中渲染多个控件
*
* @param Nette\Forms\IControl[]
* @param Nette\Forms\IControl[] $controls
*
* @return string
*/
public function renderPairMulti(array $controls): string
{
$s = [];
foreach ($controls as $control) {
if ( ! $control instanceof Nette\Forms\IControl) {
if ( ! $control instanceof Nette\Forms\Control) {
throw new Nette\InvalidArgumentException('Argument must be array of Nette\Forms\IControl instances.');
}

Expand Down

0 comments on commit 89b0046

Please sign in to comment.