sindla/aurora

Aurora - Symfony 7.0 bundle

Installs: 2 294

Dependents: 0

Suggesters: 1

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 1

Type:symfony-bundle

v7.0.2 2024-03-30 08:28 UTC

README

Version Unit testing Latest Version Last Commit Required PHP
5.2 PHPUnit Latest Version Last Commit >=7.4
5.3 PHPUnit Latest Version Last Commit >=7.4 & >= 8.0
5.4 PHPUnit Latest Version Last Commit >=7.4 & >= 8.0
6.1 PHPUnit Latest Version Last Commit >= 8.1
6.2 PHPUnit Latest Version Last Commit >= 8.2
6.3 PHPUnit Latest Version Last Commit >= 8.2
7.0 PHPUnit Latest Version Last Commit >= 8.3

Installation

The Aurora package is Packagist ready, and Composer can be used to install it.

composer require sindla/aurora:7.0.*

The x-dev flag can be used to install the development version:

composer require sindla/aurora:7.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.yaml and 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', '.jpg', '.png', '.gif', '.doc' ]
    aurora.minify.output.ignore.content.type: [ 'text/plain' ]
    # https://developers.google.com/web/fundamentals/web-app-manifest
    #aurora.pwa.version_append:        "!php/eval `date('Y-m-d H')`"
    aurora.pwa.enabled:                 '%env(default:true:bool:AURORA_PWA_ENABLED)%'
    aurora.pwa.debug:                   '%env(default:true:bool:AURORA_PWA_DEBUG)%'
    aurora.pwa.version_append: "!php/eval `App\Utils::pwaVersioAppend()`"
    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.yaml and add the following content:
parameters:
    aurora.minify.output: false

🗂️ composer.json

  • Edit composer.json and 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.yaml and 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.yaml and 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.yaml and change aurora.minify.output to true, then edit config/services.yaml add 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 install and/or composer update are used, Aurora will try to automatically download the MaxMind GeoLite2Country & GeoLite2City
  • To enable this, edit your .env.local and 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
  • Edit config/services.yaml and add/append the following content:
services:
    _defaults:
        bind:
            $auroraClient: '@aurora.client'
  • Or edit config/services.yaml and add the following code to inject the @aurora.client only 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

  1. 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' ]

        ...
  1. config/packages/doctrine_migrations.yaml
doctrine_migrations:
    services:
        'Doctrine\Migrations\Version\MigrationFactory': 'Sindla\Bundle\AuroraBundle\Doctrine\Migrations\Factory\MigrationFactoryDecorator'
    ...