This commit is contained in:
Xes
2025-08-14 22:41:49 +02:00
parent 2de81ccc46
commit 8ce45119b6
39774 changed files with 4309466 additions and 0 deletions

5
vendor/sylius/translation/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
vendor/
bin/
composer.phar
composer.lock

19
vendor/sylius/translation/LICENSE vendored Normal file
View File

@@ -0,0 +1,19 @@
Copyright (c) 2011-2015 Paweł Jędrzejewski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,206 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Component\Translation\Model;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
*/
abstract class AbstractTranslatable implements TranslatableInterface
{
/**
* Translations
*
* @var TranslationInterface[]
*/
protected $translations;
/**
* Current locale
*
* @var string
*/
protected $currentLocale;
/**
* Cache current translation. Useful in Doctrine 2.4+
*
* @var string
*/
protected $currentTranslation;
/**
* Fallback locale
*
* @var string
*/
protected $fallbackLocale;
/**
* Constructor.
*/
public function __construct()
{
$this->translations = new ArrayCollection();
}
/**
* {@inheritdoc}
*/
public function getTranslations()
{
return $this->translations;
}
/**
* {@inheritdoc}
*/
public function addTranslation(TranslationInterface $translation)
{
if (!$this->translations->containsKey($translation->getLocale())) {
$this->translations->set($translation->getLocale(), $translation);
$translation->setTranslatable($this);
}
return $this;
}
/**
* {@inheritdoc}
*/
public function removeTranslation(TranslationInterface $translation)
{
if ($this->translations->removeElement($translation)) {
$translation->setTranslatable(null);
}
return $this;
}
/**
* @param TranslationInterface $translation
*
* @return bool
*/
public function hasTranslation(TranslationInterface $translation)
{
return $this->translations->containsKey($translation->getLocale());
}
/**
* @param string $currentLocale
*
* @return $this
*/
public function setCurrentLocale($currentLocale)
{
$this->currentLocale = $currentLocale;
return $this;
}
/**
* @return string
*/
public function getCurrentLocale()
{
return $this->currentLocale;
}
/**
* @param TranslationInterface $currentTranslation
*
* @return $this
*/
public function setCurrentTranslation(TranslationInterface $currentTranslation)
{
$this->currentTranslation = $currentTranslation;
return $this;
}
/**
* @return TranslationInterface
*/
public function getCurrentTranslation()
{
return $this->currentTranslation;
}
/**
* @param string $fallbackLocale
*
* @return $this
*/
public function setFallbackLocale($fallbackLocale)
{
$this->fallbackLocale = $fallbackLocale;
return $this;
}
/**
* @return string
*/
public function getFallbackLocale()
{
return $this->fallbackLocale;
}
/**
* Translation helper method
*
* @param string $locale
*
* @return TranslationInterface
*
* @throws \RuntimeException
*/
public function translate($locale = null)
{
if (null === $locale) {
$locale = $this->currentLocale;
}
if (!$locale) {
throw new \RuntimeException('No locale has been set and currentLocale is empty');
}
if ($this->currentTranslation && $this->currentTranslation->getLocale() === $locale) {
return $this->currentTranslation;
}
// TODO Throw exception? Get default translation?
if (!$translation = $this->translations->get($locale)) {
if (!$fallbackTranslation = $this->translations->get($this->getFallbackLocale())) {
$className = $this->getTranslationEntityClass();
$translation = new $className();
$translation->setLocale($locale);
$this->addTranslation($translation);
} else {
$translation = clone $fallbackTranslation;
}
}
$this->currentTranslation = $translation;
return $translation;
}
/**
* Return translation entity class
*
* @return string
*/
abstract protected function getTranslationEntityClass();
}

View File

@@ -0,0 +1,82 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Component\Translation\Model;
/**
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
*/
class AbstractTranslation implements TranslationInterface
{
/**
* Locale
*
* @var string
*/
protected $locale;
/**
* Translatable object
*
* @var TranslatableInterface
*/
protected $translatable;
/**
* {@inheritdoc}
*/
public function getTranslatable()
{
return $this->translatable;
}
/**
* {@inheritdoc}
*/
public function setTranslatable(TranslatableInterface $translatable = null)
{
if ($translatable === $this->translatable) {
return $this;
}
$old = $this->translatable;
$this->translatable = $translatable;
if (null !== $old) {
$old->removeTranslation($this);
}
if (null !== $translatable) {
$translatable->addTranslation($this);
}
return $this;
}
/**
* {@inheritdoc}
*/
public function getLocale()
{
return $this->locale;
}
/**
* {@inheritdoc}
*/
public function setLocale($locale)
{
$this->locale = $locale;
return $this;
}
}

View File

@@ -0,0 +1,41 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Component\Translation\Model;
/**
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
*/
interface TranslatableInterface
{
/**
* Get all translations
*
* @return TranslationInterface[]
*/
public function getTranslations();
/**
* Add a new translation
*
* @param TranslationInterface $translation
* @return self
*/
public function addTranslation(TranslationInterface $translation);
/**
* Remove a translation
*
* @param TranslationInterface $translation
* @return $this
*/
public function removeTranslation(TranslationInterface $translation);
}

View File

@@ -0,0 +1,48 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Component\Translation\Model;
/**
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
*/
interface TranslationInterface
{
/**
* Get the translatable object
*
* @return TranslatableInterface
*/
public function getTranslatable();
/**
* Set the translatable object
*
* @param TranslatableInterface $translatable
* @return self
*/
public function setTranslatable(TranslatableInterface $translatable = null);
/**
* Get the locale
*
* @return string
*/
public function getLocale();
/**
* Set the locale
*
* @param string $locale
* @return $this
*/
public function setLocale($locale);
}

45
vendor/sylius/translation/README.md vendored Normal file
View File

@@ -0,0 +1,45 @@
Translation Component [![Build status...](https://secure.travis-ci.org/Sylius/Translation.png?branch=master)](http://travis-ci.org/Sylius/Translation)
===================
Sylius
------
Modern ecommerce for PHP and Symfony2. Visit [Sylius.org](http://sylius.org).
Documentation
-------------
Documentation is available on [**docs.sylius.org**](http://docs.sylius.org/en/latest/components/Translation/index.html).
Contributing
------------
All instructions for contributing to Sylius can be found in the [Contributing Guide](http://docs.sylius.org/en/latest/contributing/index.html).
Support
-------
If you have a question regarding the usage of this library, please ask on
[Stackoverflow](http://stackoverflow.com). You should use "sylius"
tag when posting and make sure to [browse existing questions](http://stackoverflow.com/questions/tagged/sylius).
Sylius on Twitter
-----------------
[Follow the official Sylius account on Twitter!](http://twitter.com/Sylius).
Bug Tracking
------------
If you find a bug, please refer to the [Reporting a Bug](http://docs.sylius.org/en/latest/contributing/code/bugs.html) guide.
MIT License
-----------
License can be found [here](https://github.com/Sylius/Translation/blob/master/LICENSE).
Authors
-------
The component was originally created by [Paweł Jędrzejewski](http://pjedrzejewski.com).
See the list of [contributors](https://github.com/Sylius/Translation/contributors).

45
vendor/sylius/translation/composer.json vendored Normal file
View File

@@ -0,0 +1,45 @@
{
"name": "sylius/translation",
"type": "library",
"description": "Translation helper.",
"keywords": ["translation"],
"homepage": "http://sylius.org",
"license": "MIT",
"authors": [
{
"name": "Paweł Jędrzejewski",
"homepage": "http://pjedrzejewski.com"
},
{
"name": "Sylius project",
"homepage": "http://sylius.org"
},
{
"name": "Community contributions",
"homepage": "http://github.com/Sylius/Sylius/contributors"
}
],
"require": {
"php": ">=5.3.3",
"doctrine/collections" : "~1.2",
"doctrine/orm" : "~2.4"
},
"require-dev": {
"phpspec/phpspec": "~2.0"
},
"config": {
"bin-dir": "bin"
},
"autoload": {
"psr-4": { "Sylius\\Component\\Translation\\": "" }
},
"autoload-dev": {
"psr-4": { "Sylius\\Component\\Translation\\spec\\": "spec/" }
},
"extra": {
"branch-alias": {
"dev-master": "0.13-dev"
}
}
}

5
vendor/sylius/translation/phpspec.yml vendored Normal file
View File

@@ -0,0 +1,5 @@
suites:
main:
namespace: Sylius\Component\Translation
psr4_prefix: Sylius\Component\Translation
src_path: .

View File

@@ -0,0 +1,108 @@
<?php
namespace spec\Sylius\Component\Translation\Model;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Translation\Model\TranslationInterface;
use Sylius\Component\Translation\Model\AbstractTranslatable;
use Sylius\Component\Translation\Model\AbstractTranslation;
class AbstractTranslatableSpec extends ObjectBehavior
{
function let()
{
$this->beAnInstanceOf('spec\Sylius\Component\Translation\Model\ConcreteTranslatable');
}
function it_is_translatable()
{
$this->shouldImplement('Sylius\Component\Translation\Model\TranslatableInterface');
}
function it_initializes_translattion_collection_by_default()
{
$this->getTranslations()->shouldHaveType('Doctrine\Common\Collections\Collection');
}
function it_adds_translation(TranslationInterface $translation)
{
$translation->getLocale()->willReturn('en');
$translation->setTranslatable($this)->shouldBeCalled();
$this->addTranslation($translation)->shouldReturn($this);
$this->hasTranslation($translation)->shouldReturn(true);
}
function it_removes_translation(TranslationInterface $translation)
{
$this->addTranslation($translation);
$this->removeTranslation($translation)->shouldReturn($this);
$this->hasTranslation($translation)->shouldReturn(false);
}
function its_current_locale_is_mutable()
{
$this->setCurrentLocale('en')->shouldReturn($this);
$this->getCurrentLocale()->shouldReturn('en');
}
function its_current_translation_is_mutable(TranslationInterface $translation)
{
$this->setCurrentTranslation($translation);
$this->getCurrentTranslation()->shouldReturn($translation);
}
function its_fallback_locale_is_mutable()
{
$this->setFallbackLocale('en');
$this->getFallbackLocale()->shouldReturn('en');
}
function it_throws_exception_if_no_locale_has_been_set()
{
$this->shouldThrow('\RuntimeException')->duringTranslate();
}
function it_translates_properly(TranslationInterface $translation)
{
$translation->getLocale()->willReturn('en');
$translation->setTranslatable($this)->shouldBeCalled();
$this->addTranslation($translation);
$this->setCurrentLocale('en');
$this->translate()->shouldReturn($translation);
}
function it_creates_new_empty_translation_properly()
{
$this->setCurrentLocale('en');
$this->translate()->shouldHaveType('spec\Sylius\Component\Translation\Model\ConcreteTranslatableTranslation');
}
function it_clones_new_translation_properly(TranslationInterface $translation)
{
$translation->getLocale()->willReturn('en');
$translation->setTranslatable($this)->shouldBeCalled();
$translation->acmeProperty = 'acmeProp';
$this->addTranslation($translation);
$this->setCurrentLocale('en');
$translation = $this->translate();
$translation->shouldImplement('Sylius\Component\Translation\Model\TranslationInterface');
$translation->acmeProperty->shouldBe('acmeProp');
}
}
class ConcreteTranslatable extends AbstractTranslatable
{
protected function getTranslationEntityClass(){
return 'spec\Sylius\Component\Translation\Model\ConcreteTranslatableTranslation';
}
}
class ConcreteTranslatableTranslation extends AbstractTranslation
{
}

View File

@@ -0,0 +1,49 @@
<?php
namespace spec\Sylius\Component\Translation\Model;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Translation\Model\TranslatableInterface;
use Sylius\Component\Translation\Model\AbstractTranslation;
class AbstractTranslationSpec extends ObjectBehavior
{
function let()
{
$this->beAnInstanceOf('spec\Sylius\Component\Translation\Model\ConcreteTranslation');
}
function it_is_a_translation()
{
$this->shouldImplement('Sylius\Component\Translation\Model\TranslationInterface');
}
function its_translatable_is_mutabale(TranslatableInterface $translatable)
{
$this->setTranslatable($translatable)->shouldReturn($this);
$this->getTranslatable()->shouldReturn($translatable);
}
function its_detaches_from_its_translatable_correctly(
TranslatableInterface $translatable1,
TranslatableInterface $translatable2
) {
$translatable1->addTranslation(Argument::type('Sylius\Component\Translation\Model\AbstractTranslation'));
$this->setTranslatable($translatable1);
$translatable1->removeTranslation(Argument::type('Sylius\Component\Translation\Model\AbstractTranslation'));
$translatable2->addTranslation(Argument::type('Sylius\Component\Translation\Model\AbstractTranslation'));
$this->setTranslatable($translatable2);
}
function its_locale_is_mutable()
{
$this->setLocale('en')->shouldReturn($this);
$this->getLocale()->shouldReturn('en');
}
}
class ConcreteTranslation extends AbstractTranslation
{
}