sindla/aurora
最新稳定版本:v8.0.1
Composer 安装命令:
composer require sindla/aurora
包简介
Aurora - Symfony 8.0 bundle
README 文档
README
Installation
The Aurora package is Packagist ready, and Composer can be used to install it (PHP 8.4+ required).
composer require sindla/aurora:8.0.*
The x-dev flag can be used to install the development version:
composer require sindla/aurora:8.0.x-dev
Configuration
Even if Aurora is Packagist-ready and is a Symfony bundle, no recipe will be installed automatically.
🗂️ config/packages/aurora.yaml
- Create the file
config/packages/aurora.yamland add the following content:
parameters: aurora.bundle: 'App' aurora.root: '%kernel.project_dir%' aurora.tmp: '%kernel.project_dir%/var/tmp' aurora.resources: '%kernel.project_dir%/var/resources' aurora.static: '%kernel.project_dir%/public/static' aurora.locales: [ 'en', 'ro' ] aurora.locale: 'ro' # maxmind.com license key aurora.maxmind.license_key: '%env(default::MAXMIND_LICENSE_KEY)%' # Minify output aurora.minify.output: false aurora.minify.output.ignore.extensions: [ '.pdf', '.csv', '.jpg', '.png', '.gif', '.doc', '.docx', '.xls', '.xlsm', '.xlsx', '.xml', '.zip' ] aurora.minify.output.ignore.content.type: [ 'text/plain', 'text/csv', 'application/octet-stream', 'image/jpeg', 'image/png', 'image/gif', 'application/pdf', 'application/xml', 'application/zip' ] # https://developers.google.com/web/fundamentals/web-app-manifest #aurora.pwa.version_append: "!php/eval `date('Y-m-d H')`" aurora.pwa.enabled: '%env(bool:AURORA_PWA_ENABLED)%' aurora.pwa.debug: '%env(bool:AURORA_PWA_DEBUG)%' aurora.pwa.version_append: "!php/eval `App\Utils::pwaVersionAppend()`" aurora.pwa.automatically_prompt: false aurora.pwa.app_name: '' aurora.pwa.app_short_name: '' aurora.pwa.app_description: '' aurora.pwa.start_url: '/?pwa' aurora.pwa.display: 'fullscreen' # fullscreen | standalone | minimal-ui aurora.pwa.icons: '%kernel.project_dir%/public/static/img/favicon' aurora.pwa.theme_color: '#2C3E50' # Sets the color of the tool bar, and may be reflected in the app's preview in task switchers aurora.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 aurora.pwa.offline: '/aurora/pwa-offline' aurora.pwa.precache: - '/' aurora.pwa.prevent_cache_header_request_accept: - 'text/html' - 'text/html; charset=UTF-8' - 'application/json' aurora.pwa.prevent_cache: - '/ajax-requests' - '/q' - '/xhr' - '/login' - '/logout' - '/admin' - '.*\.mp4' # mp4 files are large, some browsers will not be able to fully cache it, meaning the video will not be displayed - '.*\/match-this\/.*' aurora.pwa.external_cache: - 'fonts.gstatic.com' - 'fonts.googleapis.com' aurora.dns_prefetch: - 'www.google.com' - 'fonts.googleapis.com' - 'fonts.gstatic.com' - 'googletagmanager.com' - 'www.googletagmanager.com' - 'www.google-analytics.com' - 'google-analytics.com' - 'googleads.g.doubleclick.net' - 'www.googletagservices.com' - 'adservice.google.com' - 'adservice.google.ro' - 'www.facebook.com' - 'gstatic.com' - 'www.gstatic.com' - 'google.com' - 'google.ro' - 'connect.facebook.net' - 'youtube.com' - 'addthis.com' - 'gemius.pl' - 'pubmatic.com' - 'innovid.com' - 'everesttech.net' - 'quantserve.com' - 'rubiconproject.com' - 'facebook.com' - 'agkn.com' - 'casalemedia.com'
🗂️ config/packages/dev/aurora.yaml
- Create the file
config/packages/dev/aurora.yamland add the following content:
parameters: aurora.minify.output: false
🗂️ composer.json
- Edit
composer.jsonand add the following content:
"post-install-cmd": [ "Sindla\\Bundle\\AuroraBundle\\Composer\\ScriptHandler::postInstall" ], "post-update-cmd": [ "Sindla\\Bundle\\AuroraBundle\\Composer\\ScriptHandler::postUpdate" ]
🗂️ config/packages/twig.yaml
- Edit
config/packages/twig.yamland add the following content:
twig: default_path: '%kernel.project_dir%/templates' debug: '%kernel.debug%' strict_variables: '%kernel.debug%' exception_controller: ~ paths: '%kernel.project_dir%/vendor/sindla/aurora/src/templates': Aurora globals: aurora: '@aurora.twig.utility'
🗂️ config/routes.yaml
- Will enable Aurora Black Hole, Favicons, Manifest & PWA (Progressive Web Application) controllers
- Edit
config/routes.yamland add the following content:
aurora: resource: "@AuroraBundle/Resources/config/routes/routes.yaml"
Then run composer update to update and install the rest of the dependencies.
⚙️ Progressive Web Apps
- To use Progressive Web Apps (PWA), edit your Twig template and between
<head>and</head>add the following content:
{{ aurora.pwa(app.request) }}
⚙️ HTML Minifier
- To enable HTML Minifier edit
config/packages/aurora.yamland changeaurora.minify.outputtotrue, then editconfig/services.yamladd the following content:
Sindla\Bundle\AuroraBundle\EventSubscriber\OutputSubscriber: arguments: $container: '@service_container' $utilityExtension: '@aurora.twig.utility' #$headers: #text/html: #Strict-Transport-Security: "max-age=1536000; includeSubDomains" #Content-Security-Policy: "default-src 'self'" # ?aurora.nonce? will be replace with uniq nonce. for twig, use {{ aurora.nonce() }} #Content-Security-Policy: "script-src 'nonce-?aurora.nonce?' 'unsafe-inline' 'unsafe-eval' 'strict-dynamic' https: http:; object-src 'none'" #Content-Security-Policy: "script-src 'self' 'unsafe-inline' 'unsafe-eval' https: http:; object-src 'none'" #Referrer-Policy: "no-referrer-when-downgrade" tags: - { name: kernel.event_listener, event: kernel.response }
⚙️ MaxMind GeoLite2Country & GeoLite2City
- When
composer installand/orcomposer updateare used, Aurora will try to automatically download the MaxMind GeoLite2Country & GeoLite2City - To enable this, edit your
.env.localand add the following content (you will need a MaxMind licence key):
MAXMIND_LICENSE_KEY=_CHANGE_THIS_WITH_YOUR_PRIVATE_LICENTE_KEY_ SINDLA_AURORA_GEO_LITE2_COUNTRY=true SINDLA_AURORA_GEO_LITE2_CITY=true SINDLA_AURORA_GEO_LITE2_ASN=true
- Edit
config/services.yamland add/append the following content:
services: _defaults: bind: $auroraClient: '@aurora.client'
- Or edit
config/services.yamland add the following code to inject the@aurora.clientonly where it is needed:
services: App\Controller\TestController: arguments: $auroraClient: '@aurora.client'
- Edit your controller and add/append the following code:
<?php namespace App\Controller; use Sindla\Bundle\AuroraBundle\Utils\AuroraClient\Client; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\Cache; use Symfony\Component\Routing\Annotation\Route; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; #[Route('/test-controller')] final class TestController extends AbstractController { public function __construct( protected Client $auroraClient ) { } #[Route(path: '/client-ip-2-country', name: 'TestController:clientIp2Country', methods: ['OPTIONS', 'GET'])] #[Cache(maxage: 60, smaxage: 120, public: true, mustRevalidate: true)] public function clientIp2Country(Request $request): JsonResponse { return new JsonResponse([ 'countryCode' => $this->auroraClient->ip2CountryCode($this->auroraClient->ip($request)) ]); } }
Inject ContainerAwareInterface into Doctrine Migrations
config/services.yaml
... ################################################################################################################### ### Doctrine Migration ############################################################################################ ### Inject Container into migrations; also, check doctrine_migrations.yaml > Doctrine\Migrations\Version\MigrationFactory Doctrine\Migrations\Version\DbalMigrationFactory: ~ Sindla\Bundle\AuroraBundle\Doctrine\Migrations\Factory\MigrationFactoryDecorator: decorates: Doctrine\Migrations\Version\DbalMigrationFactory arguments: [ '@Sindla\Bundle\AuroraBundle\Doctrine\Migrations\Factory\MigrationFactoryDecorator.inner', '@service_container' ] ...
config/packages/doctrine_migrations.yaml
doctrine_migrations: services: 'Doctrine\Migrations\Version\MigrationFactory': 'Sindla\Bundle\AuroraBundle\Doctrine\Migrations\Factory\MigrationFactoryDecorator' ...
- For favicons, can use https://www.favicon-generator.org/
DEV
cd installed/ cp ../composer.json composer.json composer install mkdir symfony/ cd symfony/ composer create-project symfony/skeleton:8.0.* . --no-cache yes | composer require symfony/webapp-pack yes | composer require sindla/aurora:8.0.x-dev -W --no-cache --no-progress yes | composer require phpunit/phpunit:10.5.* -W --dev --no-progress yes | composer require dama/doctrine-test-bundle:8.0.* -W --dev --no-progress php vendor/bin/phpunit -c phpunit.dist.xml vendor/sindla/aurora/tests/ php vendor/bin/phpunit -c vendor/sindla/aurora/phpunit.xml.dist vendor/sindla/aurora/tests/
统计信息
- 总下载量: 5.97k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-30