2017 © Pedro Peláez
 

library cached-prezent-translation

Provides a trait to be used with prezent/translatable-bundle

image

barthy/cached-prezent-translation

Provides a trait to be used with prezent/translatable-bundle

  • Wednesday, July 18, 2018
  • by barthy.koeln
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Cached Translation

CircleCI Coverage, (*1)

This library provides a simple trait that can be used with the prezent/doctrine-translatable-bundle., (*2)

This is mostly a copy-pasted php trait from the prezent/doctrine-translatable docs about proxy getters and setters, adapted for php >= 7.4 and opinionated code styles., (*3)

The trait stores the current locale, fallback locale, and caches the last fetched translation., (*4)

Usually, only one translation is necessary for an app: the current locale's translation or the fallback translation. Since prezent/translatable-bundle uses FETCH_EXTRA_LAZY, the cached translation does not trigger any additional straight SELECT statements if queried from the object multiple times., (*5)

In a situation where more than one translation is needed (i.e. multiple translations must be loaded for the application, it is best to either manually fully initialise the collection or to handle caching yourself., (*6)

Installation

shell script composer require barthy-koeln/cached-prezent-translation, (*7)

Usage

Entity

<?php

use BarthyKoeln\CachedPrezentTranslation\CachedPrezentTranslationTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Prezent\Doctrine\Translatable\Entity\AbstractTranslatable;

class TranslatedEntity extends AbstractTranslatable
{

    use CachedPrezentTranslationTrait;

    /**
     * @Assert\Valid()
     * @Prezent\Translations(targetEntity="App\Entity\TranslatedEntityTranslation")
     * @var ArrayCollection
     */
    protected $translations;

    public function __construct()
    {
        $this->translations = new ArrayCollection();
    }

    public function getTitle(?string $locale = null): string
    {
        return $this->translate($locale)->getTitle();
    }
}

The Versions

18/07 2018

dev-master

9999999-dev https://github.com/BarthyB/cached-prezent-translation

Provides a trait to be used with prezent/translatable-bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Barthy

translatable cached

18/07 2018

0.1.0

0.1.0.0 https://github.com/BarthyB/cached-prezent-translation

Provides a trait to be used with prezent/translatable-bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Barthy

translatable cached