sinla/borealis

Borealis - Symfony 4 扩展包

该软件包的官方仓库似乎已消失,因此该软件包已被冻结。

安装: 132

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 0

分支: 0

开放问题: 0

类型:symfony-bundle

v0.1.11 2019-11-30 09:12 UTC

README

Composer

  • PRD: composer require sindla/borealis
  • DEV: composer require sindla/borealis:dev-master

config/packages/borealis.yaml

parameters:
    borealis.bundle:     'App'
    borealis.root:       '%kernel.project_dir%'
    borealis.tmp:        '%kernel.project_dir%/var/tmp'
    borealis.resources:  '%kernel.project_dir%/var/resources'
    borealis.static:     '%kernel.project_dir%/public/static'
    borealis.locales:    ['en', 'ro']
    borealis.locale:     'ro'
    # Minify output
    borealis.minify.output:                     false
    borealis.minify.output.ignore.extensions:   ['.pdf', '.jpg', '.png', '.gif', '.doc']
    borealis.minify.output.ignore.content.type: ['text/plain']
    # https://developers.google.com/web/fundamentals/web-app-manifest
    borealis.pwa.app_name:          ''
    borealis.pwa.app_short_name:    ''
    borealis.pwa.app_description:   ''
    borealis.pwa.start_url:         '/?pwa'
    borealis.pwa.display:           'fullscreen'   # fullscreen | standalone | minimal-ui
    borealis.pwa.icons:             '%kernel.project_dir%/public/static/img/favicon'
    borealis.pwa.theme_color:       '#2C3E50' # Sets the color of the tool bar, and may be reflected in the app's preview in task switchers
    borealis.pwa.background_color:  '#2C3E50' # Should be the same color as the load page, to provide a smooth transition from the splash screen to your app
    borealis.pwa.offline:           '/pwa-offline'
    borealis.pwa.precache:
        - '/'
    borealis.pwa.prevent_cache:
        - '/ajax-requests'
        - '/q'
    borealis.pwa.external_cache:
        - 'fonts.gstatic.com'
        - 'fonts.googleapis.com'
  • 编辑composer.json并添加
    "post-update-cmd": [
        "Sindla\\Bundle\\BorealisBundle\\Composer\\ScriptHandler::postUpdate" 
    ]
  • 编辑config/packages/twig.yaml并添加
twig:
    default_path: '%kernel.project_dir%/templates'
    debug: '%kernel.debug%'
    strict_variables: '%kernel.debug%'
    exception_controller: ~
    paths:
        '%kernel.project_dir%/vendor/sindla/borealis/src/templates': Borealis
    globals:
        borealis: '@borealis.twig.utility'

运行composer update以更新和安装其余依赖。

如何在PROD中启用自定义错误控制器?

[1/1] config/packages/prod/twig.yaml

twig:
    exception_controller: 'Sindla\Bundle\BorealisBundle\Controller\CustomExceptionController::handler'

如何启用黑洞控制器?

[1/1] app/config/routing.yml

borealis.blackhole:
    resource: '@BorealisBundle/Controller/BlackHoleController.php'
    type: annotation

如何启用Favicons、Manifest和PWA(渐进式Web应用)?

[1/2] app/config/routing.yml

borealis.pwa:
    resource: '@BorealisBundle/Controller/PWAController.php'
    type: annotation

[2/2] 在您的twig模板中,在HTML的head标签中添加

{{ borealis.pwa(app.request) }}

如何启用HTML压缩器?

  • 编辑config/packages/borealis.yaml并将borealis.minify.output改为true
  • 编辑templates/services/services.html.twig
    Sindla\Bundle\BorealisBundle\EventListener\OutputSubscriber:
        arguments: ['@service_container']
        tags:
            - { name: kernel.event_listener, event: kernel.response }

如何在控制器(DI)中访问服务?

[1/2] src/Controller/StaticController.php的示例

use Sindla\Bundle\BorealisBundle\Utils\Client\Client as BorelisClient;

class StaticController {
    private $BorelisClient;
    
    public function __construct(BorelisClient $BorelisClient)
    {
        /** @var BorelisClient */
        $this->BorelisClient = $BorelisClient;
    }
    
    public function () ...
    {
        $this->BorelisClient->ip2CountryCode($this->BorelisClient->ip($Request));
    }
}

[2/2] config/services.yaml

services:
    App\Controller\StaticController:
        arguments:
            $BorelisClient: '@borealis.client'

如何在控制器(直接调用)中访问服务?

$Strink = new Strink();