Form.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  1. <?php
  2. namespace Dcat\Admin\Widgets;
  3. use Closure;
  4. use Dcat\Admin\Admin;
  5. use Dcat\Admin\Contracts\LazyRenderable;
  6. use Dcat\Admin\Exception\RuntimeException;
  7. use Dcat\Admin\Form\Concerns\HandleCascadeFields;
  8. use Dcat\Admin\Form\Concerns\HasLayout;
  9. use Dcat\Admin\Form\Concerns\HasRows;
  10. use Dcat\Admin\Form\Concerns\HasTabs;
  11. use Dcat\Admin\Form\Field;
  12. use Dcat\Admin\Support\Helper;
  13. use Dcat\Admin\Traits\HasAuthorization;
  14. use Dcat\Admin\Traits\HasFormResponse;
  15. use Dcat\Admin\Traits\HasHtmlAttributes;
  16. use Illuminate\Contracts\Support\Arrayable;
  17. use Illuminate\Contracts\Support\Renderable;
  18. use Illuminate\Http\Request;
  19. use Illuminate\Support\Arr;
  20. use Illuminate\Support\Collection;
  21. use Illuminate\Support\Fluent;
  22. use Illuminate\Support\MessageBag;
  23. use Illuminate\Support\Str;
  24. use Illuminate\Support\Traits\Macroable;
  25. use Illuminate\Validation\Validator;
  26. /**
  27. * Class Form.
  28. *
  29. * @method Field\Text text($column, $label = '')
  30. * @method Field\Checkbox checkbox($column, $label = '')
  31. * @method Field\Radio radio($column, $label = '')
  32. * @method Field\Select select($column, $label = '')
  33. * @method Field\MultipleSelect multipleSelect($column, $label = '')
  34. * @method Field\Textarea textarea($column, $label = '')
  35. * @method Field\Hidden hidden($column, $label = '')
  36. * @method Field\Id id($column, $label = '')
  37. * @method Field\Ip ip($column, $label = '')
  38. * @method Field\Url url($column, $label = '')
  39. * @method Field\Email email($column, $label = '')
  40. * @method Field\Mobile mobile($column, $label = '')
  41. * @method Field\Slider slider($column, $label = '')
  42. * @method Field\Map map($latitude, $longitude, $label = '')
  43. * @method Field\Editor editor($column, $label = '')
  44. * @method Field\Date date($column, $label = '')
  45. * @method Field\Datetime datetime($column, $label = '')
  46. * @method Field\Time time($column, $label = '')
  47. * @method Field\Year year($column, $label = '')
  48. * @method Field\Month month($column, $label = '')
  49. * @method Field\DateRange dateRange($start, $end, $label = '')
  50. * @method Field\DateTimeRange datetimeRange($start, $end, $label = '')
  51. * @method Field\TimeRange timeRange($start, $end, $label = '')
  52. * @method Field\Number number($column, $label = '')
  53. * @method Field\Currency currency($column, $label = '')
  54. * @method Field\SwitchField switch($column, $label = '')
  55. * @method Field\Display display($column, $label = '')
  56. * @method Field\Rate rate($column, $label = '')
  57. * @method Field\Divide divider()
  58. * @method Field\Password password($column, $label = '')
  59. * @method Field\Decimal decimal($column, $label = '')
  60. * @method Field\Html html($html, $label = '')
  61. * @method Field\Tags tags($column, $label = '')
  62. * @method Field\Icon icon($column, $label = '')
  63. * @method Field\Embeds embeds($column, $label = '')
  64. * @method Field\Captcha captcha($column, $label = '')
  65. * @method Field\Listbox listbox($column, $label = '')
  66. * @method Field\File file($column, $label = '')
  67. * @method Field\Image image($column, $label = '')
  68. * @method Field\MultipleFile multipleFile($column, $label = '')
  69. * @method Field\MultipleImage multipleImage($column, $label = '')
  70. * @method Field\Tree tree($column, $label = '')
  71. * @method Field\Table table($column, $callback)
  72. * @method Field\ListField list($column, $label = '')
  73. * @method Field\Timezone timezone($column, $label = '')
  74. * @method Field\KeyValue keyValue($column, $label = '')
  75. * @method Field\Tel tel($column, $label = '')
  76. * @method Field\Markdown markdown($column, $label = '')
  77. * @method Field\Range range($start, $end, $label = '')
  78. * @method Field\Color color($column, $label = '')
  79. * @method Field\ArrayField array($column, $labelOrCallback, $callback = null)
  80. * @method Field\SelectTable selectTable($column, $label = '')
  81. * @method Field\MultipleSelectTable multipleSelectTable($column, $label = '')
  82. * @method Field\Button button(string $html = null)
  83. */
  84. class Form implements Renderable
  85. {
  86. use HasHtmlAttributes;
  87. use HasAuthorization;
  88. use HandleCascadeFields;
  89. use HasRows;
  90. use HasTabs;
  91. use HasLayout;
  92. use HasFormResponse {
  93. setCurrentUrl as defaultSetCurrentUrl;
  94. }
  95. use Macroable {
  96. __call as macroCall;
  97. }
  98. const REQUEST_NAME = '_form_';
  99. const CURRENT_URL_NAME = '_current_';
  100. const LAZY_PAYLOAD_NAME = '_payload_';
  101. /**
  102. * @var string
  103. */
  104. protected $view = 'admin::widgets.form';
  105. /**
  106. * @var Field[]|Collection
  107. */
  108. protected $fields;
  109. /**
  110. * @var array
  111. */
  112. protected $variables = [];
  113. /**
  114. * @var bool
  115. */
  116. protected $ajax = true;
  117. /**
  118. * @var Fluent
  119. */
  120. protected $data;
  121. /**
  122. * @var mixed
  123. */
  124. protected $primaryKey;
  125. /**
  126. * Available buttons.
  127. *
  128. * @var array
  129. */
  130. protected $buttons = ['reset' => true, 'submit' => true];
  131. /**
  132. * @var bool
  133. */
  134. protected $useFormTag = true;
  135. /**
  136. * @var string
  137. */
  138. protected $elementId;
  139. /**
  140. * @var array
  141. */
  142. protected $width = [
  143. 'label' => 2,
  144. 'field' => 8,
  145. ];
  146. /**
  147. * @var array
  148. */
  149. protected $confirm = [];
  150. /**
  151. * Form constructor.
  152. *
  153. * @param array $data
  154. * @param mixed $key
  155. */
  156. public function __construct($data = [], $key = null)
  157. {
  158. if ($data) {
  159. $this->fill($data);
  160. }
  161. $this->setKey($key);
  162. $this->setUp();
  163. }
  164. protected function setUp()
  165. {
  166. $this->initFields();
  167. $this->initFormAttributes();
  168. $this->initCurrentUrl();
  169. $this->initPayload();
  170. }
  171. /**
  172. * Initialize the form fields.
  173. */
  174. protected function initFields()
  175. {
  176. $this->fields = new Collection();
  177. }
  178. /**
  179. * Initialize the form attributes.
  180. */
  181. protected function initFormAttributes()
  182. {
  183. $this->setHtmlAttribute([
  184. 'method' => 'POST',
  185. 'action' => '',
  186. 'class' => 'form-horizontal',
  187. 'accept-charset' => 'UTF-8',
  188. 'pjax-container' => true,
  189. ]);
  190. }
  191. protected function initCurrentUrl()
  192. {
  193. if ($this instanceof LazyRenderable) {
  194. $this->setCurrentUrl($this->getCurrentUrl());
  195. }
  196. }
  197. protected function initPayload()
  198. {
  199. if ($payload = \request(static::LAZY_PAYLOAD_NAME)) {
  200. $this->payload(json_decode($payload, true) ?? []);
  201. }
  202. }
  203. /**
  204. * Action uri of the form.
  205. *
  206. * @param string $action
  207. *
  208. * @return $this|string
  209. */
  210. public function action($action = null)
  211. {
  212. if ($action === null) {
  213. return $this->getHtmlAttribute('action');
  214. }
  215. return $this->setHtmlAttribute('action', admin_url($action));
  216. }
  217. /**
  218. * Method of the form.
  219. *
  220. * @param string $method
  221. *
  222. * @return $this
  223. */
  224. public function method(string $method = 'POST')
  225. {
  226. return $this->setHtmlAttribute('method', strtoupper($method));
  227. }
  228. /**
  229. * @param string $title
  230. * @param string $content
  231. *
  232. * @return $this
  233. */
  234. public function confirm(?string $title = null, ?string $content = null)
  235. {
  236. $this->confirm['title'] = $title;
  237. $this->confirm['content'] = $content;
  238. return $this;
  239. }
  240. /**
  241. * Set primary key.
  242. *
  243. * @param mixed $value
  244. *
  245. * @return $this
  246. */
  247. public function setKey($value)
  248. {
  249. $this->primaryKey = $value;
  250. return $this;
  251. }
  252. /**
  253. * Get primary key.
  254. *
  255. * @return mixed
  256. */
  257. public function getKey()
  258. {
  259. return $this->primaryKey;
  260. }
  261. /**
  262. * @param array|Arrayable|Closure $data
  263. *
  264. * @return Fluent
  265. */
  266. public function data()
  267. {
  268. if (! $this->data) {
  269. $this->fill([]);
  270. }
  271. return $this->data;
  272. }
  273. /**
  274. * @param array|Arrayable|Closure $data
  275. *
  276. * @return $this
  277. */
  278. public function fill($data)
  279. {
  280. $this->data = new Fluent(Helper::array($data));
  281. return $this;
  282. }
  283. /**
  284. * @return Fluent
  285. */
  286. public function model()
  287. {
  288. return $this->data();
  289. }
  290. /**
  291. * Add a fieldset to form.
  292. *
  293. * @param string $title
  294. * @param Closure $setCallback
  295. *
  296. * @return Field\Fieldset
  297. */
  298. public function fieldset(string $title, Closure $setCallback)
  299. {
  300. $fieldset = new Field\Fieldset();
  301. $this->html($fieldset->start($title))->plain();
  302. $setCallback($this);
  303. $this->html($fieldset->end())->plain();
  304. return $fieldset;
  305. }
  306. /**
  307. * Get specify field.
  308. *
  309. * @param string|Field $name
  310. *
  311. * @return Field|null
  312. */
  313. public function field($name)
  314. {
  315. foreach ($this->fields as $field) {
  316. if (is_array($field->column())) {
  317. return in_array($name, $field->column(), true) ? $field : null;
  318. }
  319. if ($field === $name || $field->column() === $name) {
  320. return $field;
  321. }
  322. }
  323. }
  324. /**
  325. * @return Field[]|Collection
  326. */
  327. public function fields()
  328. {
  329. return $this->fields;
  330. }
  331. /**
  332. * Validate this form fields.
  333. *
  334. * @param Request $request
  335. *
  336. * @return bool|MessageBag
  337. */
  338. public function validate(Request $request)
  339. {
  340. $failedValidators = [];
  341. /** @var \Dcat\Admin\Form\Field $field */
  342. foreach ($this->fields() as $field) {
  343. if (! $validator = $field->getValidator($request->all())) {
  344. continue;
  345. }
  346. if (($validator instanceof Validator) && ! $validator->passes()) {
  347. $failedValidators[] = $validator;
  348. }
  349. }
  350. $message = $this->mergeValidationMessages($failedValidators);
  351. return $message->any() ? $message : false;
  352. }
  353. /**
  354. * Merge validation messages from input validators.
  355. *
  356. * @param \Illuminate\Validation\Validator[] $validators
  357. *
  358. * @return MessageBag
  359. */
  360. protected function mergeValidationMessages($validators)
  361. {
  362. $messageBag = new MessageBag();
  363. foreach ($validators as $validator) {
  364. $messageBag = $messageBag->merge($validator->messages());
  365. }
  366. return $messageBag;
  367. }
  368. /**
  369. * Disable Pjax.
  370. *
  371. * @return $this
  372. */
  373. public function disablePjax()
  374. {
  375. $this->forgetHtmlAttribute('pjax-container');
  376. return $this;
  377. }
  378. public function useFormTag(bool $tag = true)
  379. {
  380. $this->useFormTag = $tag;
  381. return $this;
  382. }
  383. /**
  384. * Disable reset button.
  385. *
  386. * @param bool $value
  387. *
  388. * @return $this
  389. */
  390. public function disableResetButton(bool $value = true)
  391. {
  392. $this->buttons['reset'] = ! $value;
  393. return $this;
  394. }
  395. /**
  396. * Disable submit button.
  397. *
  398. * @param bool $value
  399. *
  400. * @return $this
  401. */
  402. public function disableSubmitButton(bool $value = true)
  403. {
  404. $this->buttons['submit'] = ! $value;
  405. return $this;
  406. }
  407. /**
  408. * Set field and label width in current form.
  409. *
  410. * @param int $fieldWidth
  411. * @param int $labelWidth
  412. *
  413. * @return $this
  414. */
  415. public function width($fieldWidth = 8, $labelWidth = 2)
  416. {
  417. $this->width = [
  418. 'label' => $labelWidth,
  419. 'field' => $fieldWidth,
  420. ];
  421. $this->fields->each(function ($field) use ($fieldWidth, $labelWidth) {
  422. /* @var Field $field */
  423. $field->width($fieldWidth, $labelWidth);
  424. });
  425. return $this;
  426. }
  427. /**
  428. * Find field class with given name.
  429. *
  430. * @param string $method
  431. *
  432. * @return bool|string
  433. */
  434. public static function findFieldClass($method)
  435. {
  436. $class = Arr::get(\Dcat\Admin\Form::extensions(), $method);
  437. if (class_exists($class)) {
  438. return $class;
  439. }
  440. return false;
  441. }
  442. /**
  443. * Add a form field to form.
  444. *
  445. * @param Field $field
  446. *
  447. * @return $this
  448. */
  449. public function pushField(Field $field)
  450. {
  451. $this->fields->push($field);
  452. if ($this->layout()->hasColumns()) {
  453. $this->layout()->addField($field);
  454. }
  455. $field->setForm($this);
  456. $field->width($this->width['field'], $this->width['label']);
  457. $this->setFileUploadUrl($field);
  458. $field::requireAssets();
  459. return $this;
  460. }
  461. protected function setFileUploadUrl(Field $field)
  462. {
  463. if ($field instanceof Field\File && method_exists($this, 'form')) {
  464. $formData = [static::REQUEST_NAME => get_called_class()];
  465. $field->url(route(admin_api_route('form.upload')));
  466. $field->deleteUrl(route(admin_api_route('form.destroy-file'), $formData));
  467. $field->withFormData($formData);
  468. }
  469. }
  470. /**
  471. * Get variables for render form.
  472. *
  473. * @return array
  474. */
  475. protected function variables()
  476. {
  477. $this->setHtmlAttribute('id', $this->getElementId());
  478. $this->fillFields($this->model()->toArray());
  479. return array_merge([
  480. 'start' => $this->open(),
  481. 'end' => $this->close(),
  482. 'fields' => $this->fields,
  483. 'method' => $this->getHtmlAttribute('method'),
  484. 'rows' => $this->rows(),
  485. 'layout' => $this->layout(),
  486. 'elementId' => $this->getElementId(),
  487. 'ajax' => $this->ajax,
  488. 'footer' => $this->renderFooter(),
  489. ], $this->variables);
  490. }
  491. /**
  492. * 表单底部内容.
  493. *
  494. * @return string
  495. */
  496. protected function renderFooter()
  497. {
  498. if (empty($this->buttons['reset']) && empty($this->buttons['submit'])) {
  499. return;
  500. }
  501. $buttons = '';
  502. if (! empty($this->buttons['reset'])) {
  503. $reset = trans('admin.reset');
  504. $buttons .= "<button type=\"reset\" class=\"btn btn-white pull-left\"><i class=\"feather icon-rotate-ccw\"></i> {$reset}</button>";
  505. }
  506. if (! empty($this->buttons['submit'])) {
  507. $submit = $this->getSubmitButtonLabel();
  508. $buttons .= "<button type=\"submit\" class=\"btn btn-primary pull-right\"><i class=\"feather icon-save\"></i> {$submit}</button>";
  509. }
  510. return <<<HTML
  511. <div class="box-footer row d-flex">
  512. <div class="col-md-2"> &nbsp;</div>
  513. <div class="col-md-8">{$buttons}</div>
  514. </div>
  515. HTML;
  516. }
  517. /**
  518. * 提交按钮文本.
  519. *
  520. * @return string
  521. */
  522. protected function getSubmitButtonLabel()
  523. {
  524. return trans('admin.submit');
  525. }
  526. /**
  527. * 设置视图变量.
  528. *
  529. * @param array $variables
  530. *
  531. * @return $this
  532. */
  533. public function addVariables(array $variables)
  534. {
  535. $this->variables = array_merge($this->variables, $variables);
  536. return $this;
  537. }
  538. public function fillFields(array $data)
  539. {
  540. foreach ($this->fields as $field) {
  541. if (! $field->hasAttribute(Field::BUILD_IGNORE)) {
  542. $field->fill($data);
  543. }
  544. }
  545. }
  546. /**
  547. * @return string
  548. */
  549. protected function open()
  550. {
  551. if (! $this->useFormTag) {
  552. return;
  553. }
  554. return <<<HTML
  555. <form {$this->formatHtmlAttributes()}>
  556. HTML;
  557. }
  558. /**
  559. * @return string
  560. */
  561. protected function close()
  562. {
  563. if (! $this->useFormTag) {
  564. return;
  565. }
  566. return '</form>';
  567. }
  568. /**
  569. * Determine if form fields has files.
  570. *
  571. * @return bool
  572. */
  573. public function hasFile()
  574. {
  575. foreach ($this->fields as $field) {
  576. if ($field instanceof Field\File) {
  577. return true;
  578. }
  579. }
  580. return false;
  581. }
  582. /**
  583. * @param $id
  584. *
  585. * @return $this
  586. */
  587. public function setFormId($id)
  588. {
  589. $this->elementId = $id;
  590. return $this;
  591. }
  592. /**
  593. * @return string
  594. */
  595. public function getElementId()
  596. {
  597. return $this->elementId ?: ($this->elementId = 'form-'.Str::random(8));
  598. }
  599. /**
  600. * {@inheritdoc}
  601. */
  602. public function setCurrentUrl($url)
  603. {
  604. if ($this instanceof LazyRenderable) {
  605. $this->payload([static::CURRENT_URL_NAME => $url]);
  606. }
  607. return $this->defaultSetCurrentUrl($url);
  608. }
  609. /**
  610. * @param bool $disable
  611. *
  612. * @return $this
  613. */
  614. public function ajax(bool $value = true)
  615. {
  616. $this->ajax = $value;
  617. return $this;
  618. }
  619. /**
  620. * @return bool
  621. */
  622. public function allowAjaxSubmit()
  623. {
  624. return $this->ajax === true;
  625. }
  626. /**
  627. * @return string|void
  628. */
  629. protected function savedScript()
  630. {
  631. }
  632. /**
  633. * @return string|void
  634. */
  635. protected function errorScript()
  636. {
  637. }
  638. /**
  639. * @param array $input
  640. *
  641. * @return array
  642. */
  643. public function sanitize(array $input)
  644. {
  645. Arr::forget($input, [static::REQUEST_NAME, '_token', static::CURRENT_URL_NAME]);
  646. return $this->prepareInput($input);
  647. }
  648. public function prepareInput(array $input)
  649. {
  650. Helper::prepareHasOneRelation($this->fields, $input);
  651. foreach ($input as $column => $value) {
  652. $field = $this->field($column);
  653. if (! $field instanceof Field) {
  654. unset($input[$column]);
  655. continue;
  656. }
  657. $input[$column] = $field->prepare($value);
  658. }
  659. $prepared = [];
  660. foreach ($input as $key => $value) {
  661. Arr::set($prepared, $key, $value);
  662. }
  663. return $prepared;
  664. }
  665. protected function prepareForm()
  666. {
  667. if (method_exists($this, 'form')) {
  668. $this->form();
  669. }
  670. if (! $this->data && method_exists($this, 'default')) {
  671. $data = $this->default();
  672. if (is_array($data)) {
  673. $this->fill($data);
  674. }
  675. }
  676. }
  677. protected function prepareHandler()
  678. {
  679. if (method_exists($this, 'handle')) {
  680. $addHiddenFields = function () {
  681. $this->method('POST');
  682. $this->action(route(admin_api_route('form')));
  683. $this->hidden(static::REQUEST_NAME)->default(get_called_class());
  684. $this->hidden(static::CURRENT_URL_NAME)->default($this->getCurrentUrl());
  685. if (! empty($this->payload) && is_array($this->payload)) {
  686. $this->hidden(static::LAZY_PAYLOAD_NAME)->default(json_encode($this->payload));
  687. }
  688. };
  689. $this->layout()->hasColumns() ? $this->column(1, $addHiddenFields) : $addHiddenFields();
  690. }
  691. }
  692. /**
  693. * Render the form.
  694. *
  695. * @return string
  696. */
  697. public function render()
  698. {
  699. $this->prepareForm();
  700. $this->prepareHandler();
  701. if ($this->allowAjaxSubmit()) {
  702. $this->addAjaxScript();
  703. }
  704. $tabObj = $this->getTab();
  705. if (! $tabObj->isEmpty()) {
  706. $tabObj->addScript();
  707. }
  708. $this->addVariables([
  709. 'tabObj' => $tabObj,
  710. ]);
  711. return view($this->view, $this->variables())->render();
  712. }
  713. protected function addAjaxScript()
  714. {
  715. $confirm = admin_javascript_json($this->confirm);
  716. Admin::script(
  717. <<<JS
  718. $('#{$this->getElementId()}').form({
  719. validate: true,
  720. confirm: {$confirm},
  721. success: function (data) {
  722. {$this->savedScript()}
  723. },
  724. error: function (response) {
  725. {$this->errorScript()}
  726. }
  727. });
  728. JS
  729. );
  730. }
  731. /**
  732. * Generate a Field object and add to form builder if Field exists.
  733. *
  734. * @param string $method
  735. * @param array $arguments
  736. *
  737. * @return Field|null
  738. */
  739. public function __call($method, $arguments)
  740. {
  741. if ($className = static::findFieldClass($method)) {
  742. $name = Arr::get($arguments, 0, '');
  743. $element = new $className($name, array_slice($arguments, 1));
  744. $this->pushField($element);
  745. return $element;
  746. }
  747. if (static::hasMacro($method)) {
  748. return $this->macroCall($method, $arguments);
  749. }
  750. throw new RuntimeException("Field [{$method}] does not exist.");
  751. }
  752. /**
  753. * Output as string.
  754. *
  755. * @return string
  756. */
  757. public function __toString()
  758. {
  759. return $this->render();
  760. }
  761. /**
  762. * @param mixed ...$params
  763. *
  764. * @return $this
  765. */
  766. public static function make(...$params)
  767. {
  768. return new static(...$params);
  769. }
  770. }