Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stable v0.1 - move from CoreBundle #80

Merged
merged 1 commit into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@
"require": {
"php": "^7.2",
"sonata-project/doctrine-extensions": "^1.5",
"symfony/config": "^3.4 || ^4.0 || ^5.0",
"symfony/translation": "^3.4 || ^4.0 || ^5.0",
"symfony/twig-bridge": "^3.4 || ^4.3 || ^5.0",
"twig/twig": "^2.0 || ^3.0"
"symfony/config": "^4.3",
"symfony/translation": "^4.3",
"symfony/twig-bridge": "^4.3",
"twig/twig": "^2.12.1"
},
"conflict": {
"sonata-project/core-bundle": "<3.19"
"sonata-project/core-bundle": "<3.20"
},
"require-dev": {
"jms/serializer-bundle": "^3.3",
"matthiasnoback/symfony-config-test": "^4.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.0",
"symfony/browser-kit": "^3.4 || ^4.3 || ^5.0",
"symfony/dependency-injection": "^3.4 || ^4.0 || ^5.0",
"symfony/framework-bundle": "^3.4.36 || ^4.3 || ^5.0",
"symfony/http-foundation": "^3.4 || ^4.0 || ^5.0",
"symfony/http-kernel": "^3.4 || ^4.0 || ^5.0",
"jms/serializer-bundle": "^2.4 || ^3.0",
"matthiasnoback/symfony-config-test": "^4.2",
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
"symfony/browser-kit": "^4.3",
"symfony/dependency-injection": "^4.3",
"symfony/framework-bundle": "^4.3",
"symfony/http-foundation": "^4.3",
"symfony/http-kernel": "^4.3",
"symfony/phpunit-bridge": "^5.0",
"symfony/twig-bundle": "^3.4 || ^4.3 || ^5.0"
"symfony/twig-bundle": "^4.3"
},
"config": {
"sort-packages": true
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ parameters:
- vendor/autoload.php

ignoreErrors:
- '#Class Symfony\\Component\\Translation\\TranslatorInterface not found.#'
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function load(array $configs, ContainerBuilder $container): void
/**
* Registers flash message types defined in configuration to flash manager.
*/
private function registerFlashTypes(ContainerBuilder $container, array $config): void
public function registerFlashTypes(ContainerBuilder $container, array $config)
{
$mergedConfig = array_merge_recursive($config['flashmessage'], [
'success' => ['types' => [
Expand Down Expand Up @@ -71,8 +71,8 @@ private function registerFlashTypes(ContainerBuilder $container, array $config):
$identifier = 'sonata.twig.flashmessage.manager';

$definition = $container->getDefinition($identifier);
$definition->replaceArgument(1, $types);
$definition->replaceArgument(2, $cssClasses);
$definition->replaceArgument(2, $types);
$definition->replaceArgument(3, $cssClasses);

$container->setDefinition($identifier, $definition);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Bridge/Symfony/Resources/config/flash.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
<service id="sonata.twig.flashmessage.manager" class="%sonata.twig.flashmessage.manager.class%" public="true">
<tag name="sonata.status.renderer"/>
<argument type="service" id="session"/>
<argument/>
<argument/>
<argument type="service" id="translator"/>
<argument type="collection"/>
<argument type="collection"/>
</service>
<service id="sonata.twig.flashmessage.twig.runtime" class="Sonata\Twig\Extension\FlashMessageRuntime">
<tag name="twig.runtime"/>
Expand Down
1 change: 1 addition & 0 deletions src/Bridge/Symfony/Resources/config/twig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<service id="sonata.twig.template_extension" class="Sonata\Twig\Extension\TemplateExtension">
<tag name="twig.extension"/>
<argument>%kernel.debug%</argument>
<argument type="service" id="translator"/>
<argument type="service" id="sonata.doctrine.model.adapter.chain"/>
</service>
</services>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file source-language="en" datatype="plaintext" original="SonataTwigBundle.en.xliff">
<body>
<trans-unit id="sonata_core_template_box_file_found_in">
<source>sonata_core_template_box_file_found_in</source>
<target>sonata_core_template_box_file_found_in</target>
</trans-unit>
<trans-unit id="message_close">
<source>message_close</source>
<target>Schließen</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file source-language="en" datatype="plaintext" original="">
<body>
<trans-unit id="sonata_core_template_box_file_found_in">
<source>sonata_core_template_box_file_found_in</source>
<target>This file can be found in</target>
</trans-unit>
<trans-unit id="message_close">
<source>message_close</source>
<target>Close</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file source-language="en" datatype="plaintext" original="SonataTwigBundle.en.xliff">
<body>
<trans-unit id="sonata_core_template_box_file_found_in">
<source>sonata_core_template_box_file_found_in</source>
<target>Ce fichier est localisé à l'emplacement</target>
</trans-unit>
<trans-unit id="message_close">
<source>message_close</source>
<target>Fermer</target>
</trans-unit>
<trans-unit id="more">
<source>more</source>
<target>more</target>
</trans-unit>
<trans-unit id="less">
<source>less</source>
<target>less</target>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file source-language="en" datatype="plaintext" original="SonataTwigBundle.en.xliff">
<body>
<trans-unit id="sonata_core_template_box_file_found_in">
<source>sonata_core_template_box_file_found_in</source>
<target>Plik szablony znajdziesz w</target>
</trans-unit>
<trans-unit id="message_close">
<source>message_close</source>
<target>Zamknij</target>
</trans-unit>
<trans-unit id="more">
<source>more</source>
<target>więcej</target>
</trans-unit>
<trans-unit id="less">
<source>less</source>
<target>mniej</target>
</trans-unit>
</body>
</file>
</xliff>
3 changes: 3 additions & 0 deletions src/Bridge/Symfony/SonataTwigBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
* @author Thomas Rabaix <[email protected]>
*/
final class SonataTwigBundle extends Bundle
{
public function build(ContainerBuilder $container): void
Expand Down
21 changes: 21 additions & 0 deletions src/Extension/FlashMessageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Sonata\Twig\Extension;

use Sonata\Twig\FlashMessage\FlashManager;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

Expand All @@ -26,6 +27,26 @@
*/
class FlashMessageExtension extends AbstractExtension
{
/**
* @deprecated since sonata-project/twig-extensions 0.x, to be removed in 1.0.
*
* @var FlashManager
*/
protected $flashManager;

public function __construct(?FlashManager $flashManager = null)
{
$this->flashManager = $flashManager;

if ($this->flashManager) {
@trigger_error(
'Argument "flashManager" in FlashMessageExtension is deprecated since sonata-project/twig-extensions 0.x'.
' and will be removed in 1.0.',
E_USER_DEPRECATED
);
}
}

/**
* @return TwigFunction[]
*/
Expand Down
76 changes: 20 additions & 56 deletions src/Extension/FormTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,69 +16,33 @@
use Twig\Extension\AbstractExtension;
use Twig\Extension\GlobalsInterface;

if (class_exists('Twig_Extension_GlobalsInterface')) {
/**
* @final since sonata-project/twig-extensions 0.x
*/
class FormTypeExtension extends AbstractExtension implements GlobalsInterface
{
/**
* @final since sonata-project/twig-extensions 0.x
* @var bool
*/
class FormTypeExtension extends AbstractExtension implements GlobalsInterface
{
/**
* @var bool
*/
private $wrapFieldsWithAddons;

public function __construct($formType)
{
$this->wrapFieldsWithAddons = (true === $formType || 'standard' === $formType);
}
private $wrapFieldsWithAddons;

/**
* @return array
*/
public function getGlobals()
{
return [
'wrap_fields_with_addons' => $this->wrapFieldsWithAddons,
];
}
public function __construct($formType)
{
$this->wrapFieldsWithAddons = (true === $formType || 'standard' === $formType);
}

/**
* @return string
*/
public function getName()
{
return 'sonata_twig_wrapping';
}
public function getGlobals(): array
{
return [
'wrap_fields_with_addons' => $this->wrapFieldsWithAddons,
];
}
} else {

/**
* @final since sonata-project/twig-extensions 0.x
* @return string
*/
class FormTypeExtension extends AbstractExtension implements GlobalsInterface
public function getName()
{
/**
* @var bool
*/
private $wrapFieldsWithAddons;

public function __construct($formType)
{
$this->wrapFieldsWithAddons = (true === $formType || 'standard' === $formType);
}

public function getGlobals(): array
{
return [
'wrap_fields_with_addons' => $this->wrapFieldsWithAddons,
];
}

/**
* @return string
*/
public function getName()
{
return 'sonata_twig_wrapping';
}
return 'sonata_twig_wrapping';
}
}
4 changes: 2 additions & 2 deletions src/Extension/StatusExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
*/
class StatusExtension extends AbstractExtension
{
public function getFilters(): array
public function getFilters()
{
return [
new TwigFilter('sonata_status_class', [StatusRuntime::class, 'statusClass']),
];
}

public function getName(): string
public function getName()
{
return 'sonata_twig_status';
}
Expand Down
50 changes: 12 additions & 38 deletions src/Extension/TemplateExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,60 +38,34 @@ class TemplateExtension extends AbstractExtension
/**
* NEXT_MAJOR: remove this property.
*
* @var LegacyTranslatorInterface|TranslatorInterface|null
*
* @deprecated translator property is deprecated since sonata-project/twig-extensions 0.x, to be removed in 1.0
*
* @var LegacyTranslatorInterface|TranslatorInterface
*/
protected $translator;

/**
* @param bool $debug Is Symfony debug enabled?
* @param LegacyTranslatorInterface|TranslatorInterface|AdapterInterface|null $deprecatedTranslatorOrModelAdapter
* @param bool $debug Is Symfony debug enabled?
* @param LegacyTranslatorInterface|TranslatorInterface $translator
*/
public function __construct($debug, $deprecatedTranslatorOrModelAdapter = null, ?AdapterInterface $deprecatedModelAdapter = null)
public function __construct($debug, $translator, AdapterInterface $modelAdapter)
{
$this->debug = $debug;

if (
!$deprecatedTranslatorOrModelAdapter instanceof LegacyTranslatorInterface &&
!$deprecatedTranslatorOrModelAdapter instanceof TranslatorInterface &&
!$deprecatedTranslatorOrModelAdapter instanceof AdapterInterface &&
null !== $deprecatedTranslatorOrModelAdapter
!$translator instanceof LegacyTranslatorInterface &&
!$translator instanceof TranslatorInterface
) {
throw new \InvalidArgumentException(sprintf(
'Argument 2 should be an instance of %s or %s or %s or %s',
'Argument 2 should be an instance of %s or %s',
LegacyTranslatorInterface::class,
TranslatorInterface::class,
'null',
AdapterInterface::class
));
}

if (!$deprecatedTranslatorOrModelAdapter instanceof AdapterInterface && !$deprecatedModelAdapter instanceof AdapterInterface) {
throw new \InvalidArgumentException(sprintf(
'Argument 3 should be an instance of %s, %s given.',
AdapterInterface::class,
\get_class($deprecatedModelAdapter)
TranslatorInterface::class
));
}

if ($deprecatedTranslatorOrModelAdapter instanceof AdapterInterface) {
$this->modelAdapter = $deprecatedTranslatorOrModelAdapter;
} else {
$this->translator = $deprecatedTranslatorOrModelAdapter;
$this->modelAdapter = $deprecatedModelAdapter;

@trigger_error(
'The translator dependency in '.__CLASS__.' is deprecated since 0.x and will be removed in 1.0. '.
'Please prepare your dependencies for this change.',
E_USER_DEPRECATED
);
}
$this->debug = $debug;
$this->translator = $translator;
$this->modelAdapter = $modelAdapter;
}

/**
* @return TwigFilter[]
*/
public function getFilters()
{
return [
Expand Down
Loading