定制 lexal/laravel-stepped-form 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lexal/laravel-stepped-form

Composer 安装命令:

composer require lexal/laravel-stepped-form

包简介

Stepped Form for Laravel.

README 文档

README

PHPUnit, PHPCS, PHPStan Tests

The package is based on the HTTP Stepped Form and built for Laravel framework.

Table of Contents

  1. Requirements
  2. Installation
  3. Configuration
  4. Usage
  5. License

Requirements

PHP: >=8.2

Laravel: ^11.0 || ^12.0

Installation

Via Composer

composer require lexal/laravel-stepped-form
(back to top)

Configuration

Publish the config

Run the following command to publish the package config file:

php artisan vendor:publish --provider="Lexal\LaravelSteppedForm\ServiceProvider\ServiceProvider"

Available config options

The configuration file config/stepped-form.php has the following options:

  1. renderer - contains Renderer class, instance or service alias that translates step's template definition into the response. Must implement Lexal\HttpSteppedForm\Renderer\RendererInterface;
  2. redirector - contains Redirector class, instance or service alias that redirects user between form steps. Must implement Lexal\HttpSteppedForm\Routing\RedirectorInterface;
  3. event_dispatcher - contains Event Dispatcher class, instance or service alias that dispatches form events. Must implement Lexal\SteppedForm\EventDispatcher\EventDispatcherInterface;
  4. exception_normalizers - contains exception normalizers that the form uses for normalizing SteppedFormException into the Response instance. Read more about them in the HTTP Stepped Form docs;
  5. forms - contains array of all application forms definitions. Form definition must have builder class for dynamic forms or array of steps for the static forms, settings class and storage where the form stores its data.
(back to top)

Usage

  1. Publish configuration file.

  2. Replace redirector, renderer and event dispatcher with your own implementation and add custom exception normalizers, if necessary.

  3. Declare form settings.

     use Lexal\HttpSteppedForm\Settings\FormSettingsInterface;
     use Lexal\SteppedForm\Step\StepKey;
    
     final class FormSettings implements FormSettingsInterface
     {
         public function getStepUrl(StepKey $key): string
         {
             // return step URL
         }
    
         public function getUrlBeforeStart(): string
         {
             // returns a URL to redirect to when there is no previously renderable step
         }
    
         public function getUrlAfterFinish(): string
         {
             // return a URL to redirect to when the form was finishing
         }
     }
    
     $formSettings = new FormSettings();
  4. Add forms definitions.

    • Static form
      return [
         // ...
      
         'forms' => [
             'customer' => [
                 'steps' => [
                     'customer' => CustomerStep::class,
                     'broker' => BrokerStep::class,
                     'confirmation' => ConfirmationStep::class,
                     // other steps
                 ],
                 'settings_class' => FormSettings::class,
                 'storage' => SessionStorage::class,
                 'session_key_storage' => SessionSessionKeyStorage::class,
             ],
         ],
      
         // ...
      ];
    • Dynamic form
      return [
         // ...
      
         'forms' => [
             'customer' => [
                 'builder_class' => CustomBuilder::class,
                 'settings_class' => FormSettings::class,
                 'storage' => SessionStorage::class,
                 'session_key_storage' => SessionSessionKeyStorage::class,
             ],
         ],
      
         // ...
      ];
  5. Use Stepped Form in you controller. Stepped Form service is registered under "stepped-form.{{form key}}" alias in the container.

    ServiceProvider.php

    use Lexal\HttpSteppedForm\SteppedFormInterface;
    
    $this->app->when(CustomerController::class)
         ->needs(SteppedFormInterface::class)
         ->give('stepped-form.customer');

    CustomerController.php

    use Lexal\HttpSteppedForm\SteppedFormInterface;
    
    final class CustomerController
    {
        public function __construct(private readonly SteppedFormInterface $form)
        {
        }
    
        // POST /customers
        public function start(): Response
        {
            return $this->form->start(new Customer(), /* nothing or customer id to split different sessions */);
        }
    
        // GET /customers/step/{step-key}
        public function render(string $key): Response
        {
            return $this->form->render($key);
        }
    
        // POST /customers/step/{step-key}
        public function handle(Request $request, string $key): Response
        {
            return $this->form->handle($key, $request);
        }
    
        // POST /customers/cansel
        public function cancel(): Response
        {
            return $this->form->cancel(route('customer.index'));
        }
    }

See configuration file for more information.

(back to top)

License

Laravel Stepped Form is licensed under the MIT License. See LICENSE for the full license text.

统计信息

  • 总下载量: 489
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固