jumpersoft/symfony-base-bundle

Symfony基础包,包含通用类、控件和模板。

安装: 696

依赖者: 1

建议者: 0

安全性: 0

类型:symfony-bundle


README

步骤 1:下载Bundle

打开命令行控制台,进入您的项目目录,并执行以下命令以下载此Bundle的最新稳定版本

$ composer require jumpersoft/symfony-base-bundle

此命令需要您已全局安装Composer,如Composer文档中的安装章节中所述。

步骤 2:启用Bundle

然后,通过将其添加到项目中app/AppKernel.php文件中注册的Bundle列表中来启用Bundle

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Jumpersoft\BaseBundle\JumpersoftBaseBundle(),
        );

        // ...
    }

    // ...
}

步骤 3:配置Bundle

在"app/config/parameters.yml"和".."parameters.yml.dist"中设置配置,

  • 基础参数,将所有具有可选值的参数放入每个工具中

    # 秘密api captcha密钥(如google recaptcha) jumpersoft.recaptcha.secretCaptchaKey: ''

    # 用于身份验证工具的示例,例如'MyBundleBundle:User'或'JumpersoftEcommerceBundle:User' jumpersoft.entityUser: ''

    # 身份验证失败时重定向的路线 jumpersoft.redirectToOnAuthenticationFailure: ''

    # 用于与JumpersoftEcommerceBundle一起使用的默认商店ID jscommerce.defaultStoreId: ''

    # 用于无回复通知的电子邮件 mailer_email_no_reply: 'info@jumpersoft.com'

    # 用于与JumpersoftEcommerceBundle通知一起使用的电子邮件 mailer_email_intern_for_notifications: 'webadmin@jumpersoft.com'

  • 服务参数,将此配置添加到您的services.yml主文件中

    services

      ...
      _defaults:
          bind:
              $defaultStoreId: '%jscommerce.defaultStoreId%'
              $debug: '%kernel.debug%'
    
  • 安全参数,您可以更改您的名称

    jumpersoft.security.token_key: '' # csrf token jumpersoft.security.jwt_private_key_path: '' # ssh路径私钥路径 jumpersoft.security.jwt_public_key_path: '' # ssh路径公钥路径 jumpersoft.security.jwt_key_pass_phrase: '' # ssh密钥密码短语 jumpersoft.security.jwt_token_ttl: 86400 # jwt持续时间

在"app/config/config.yml"中设置下一个lex jwt身份验证配置

  • 添加以下配置以用于异常监听器

    framework

      ...
      templating:
          engines: ['twig']
    
  • 可选,添加以下配置以添加对DQL中实体的快捷访问

    doctrine: ...

      orm:
          ..
          mappings:
              MainEntities:
                  type: annotation
                  # Changue to your bundle name
                  dir: '%kernel.project_dir%/src/AppBundle/Entity'
                  prefix: AppBundle\Entity
                  alias: E
    
  • 添加Lexit JWT身份验证配置

    lexik_jwt_authentication

      private_key_path: %jumpersoft.security.jwt_private_key_path%
      public_key_path:  %jumpersoft.security.jwt_public_key_path%
      pass_phrase:      %jumpersoft.security.jwt_key_pass_phrase%
      token_ttl:        %jumpersoft.security.jwt_token_ttl%
    

步骤 4:使用Bundle

与该Bundle相关的主题

  1. 模板

    • 控件:文本、组合、单选和其他相关输入控件,如与jQuery和Bootstrap控件(如select2、datetimepicker等)相关的更复杂控件。
    • 表单:通用表单,如用户登录、用户注册、地址等。
    • JumpersoftBaseController:用于多种目的的Controller symfony类的扩展。
    • JwtAuthenticator:用于身份验证和授权的类,使用"GuardAuthenticator"。
  2. 扩展

    • JumpersoftMailerExtension:用于多种目的的Mailer扩展。
    • JumpersoftMapArrayExtension:用于从json请求映射数组、对类验证器-regex进行验证等的功能。
    • JumpersoftReCaptchaExtension:用于处理captcha功能的功能。
    • JwtAuthenticator:处理Json Web Token身份验证的类。
  3. 注解

    • CsrfTokenValidation:用于在控制器中处理CSRF功能的注解。
  4. Twig扩展

    • JumpersoftBaseTwigExtension:用于在"America/Mexico_City"时区中处理格式化日期的通用函数。
  5. MySQL的Doctrine扩展

    • 字符串函数:FORMAT
    • 日期时间函数:DATE_FORMAT

步骤 5:注意

我们建议使用"nelmio/cors-bundle": "~1.4"的Bundle,以充分利用json web tokens的所有优点。