Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
42f199cc
Commit
42f199cc
authored
Sep 15, 2015
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.3'
* 1.3: fixed translation registration for the validators
parents
6d56243b
53f0df43
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
25 deletions
+29
-25
doc/changelog.rst
doc/changelog.rst
+1
-1
src/Silex/Provider/FormServiceProvider.php
src/Silex/Provider/FormServiceProvider.php
+0
-8
src/Silex/Provider/TranslationServiceProvider.php
src/Silex/Provider/TranslationServiceProvider.php
+16
-0
src/Silex/Provider/ValidatorServiceProvider.php
src/Silex/Provider/ValidatorServiceProvider.php
+0
-14
tests/Silex/Tests/Provider/ValidatorServiceProviderTest.php
tests/Silex/Tests/Provider/ValidatorServiceProviderTest.php
+12
-2
No files found.
doc/changelog.rst
View file @
42f199cc
...
...
@@ -27,7 +27,7 @@ Changelog
1.3.4 (2015-XX-XX)
------------------
*
n/a
*
fixed translation registration for the validators
1.3.3 (2015-09-08)
------------------
...
...
src/Silex/Provider/FormServiceProvider.php
View file @
42f199cc
...
...
@@ -74,14 +74,6 @@ class FormServiceProvider implements ServiceProviderInterface
if
(
isset
(
$app
[
'validator'
]))
{
$extensions
[]
=
new
FormValidatorExtension
(
$app
[
'validator'
]);
if
(
isset
(
$app
[
'translator'
])
&&
method_exists
(
$app
[
'translator'
],
'addResource'
))
{
$r
=
new
\ReflectionClass
(
'Symfony\Component\Form\Form'
);
$file
=
dirname
(
$r
->
getFilename
())
.
'/Resources/translations/validators.'
.
$app
[
'locale'
]
.
'.xlf'
;
if
(
file_exists
(
$file
))
{
$app
[
'translator'
]
->
addResource
(
'xliff'
,
$file
,
$app
[
'locale'
],
'validators'
);
}
}
}
return
$extensions
;
...
...
src/Silex/Provider/TranslationServiceProvider.php
View file @
42f199cc
...
...
@@ -40,6 +40,22 @@ class TranslationServiceProvider implements ServiceProviderInterface, EventListe
$translator
->
addLoader
(
'array'
,
new
ArrayLoader
());
$translator
->
addLoader
(
'xliff'
,
new
XliffFileLoader
());
if
(
isset
(
$app
[
'validator'
]))
{
$r
=
new
\ReflectionClass
(
'Symfony\Component\Validator\Validation'
);
$file
=
dirname
(
$r
->
getFilename
())
.
'/Resources/translations/validators.'
.
$app
[
'locale'
]
.
'.xlf'
;
if
(
file_exists
(
$file
))
{
$translator
->
addResource
(
'xliff'
,
$file
,
$app
[
'locale'
],
'validators'
);
}
}
if
(
isset
(
$app
[
'form.factory'
]))
{
$r
=
new
\ReflectionClass
(
'Symfony\Component\Form\Form'
);
$file
=
dirname
(
$r
->
getFilename
())
.
'/Resources/translations/validators.'
.
$app
[
'locale'
]
.
'.xlf'
;
if
(
file_exists
(
$file
))
{
$translator
->
addResource
(
'xliff'
,
$file
,
$app
[
'locale'
],
'validators'
);
}
}
// Register default resources
foreach
(
$app
[
'translator.resources'
]
as
$resource
)
{
$translator
->
addResource
(
$resource
[
0
],
$resource
[
1
],
$resource
[
2
],
$resource
[
3
]);
...
...
src/Silex/Provider/ValidatorServiceProvider.php
View file @
42f199cc
...
...
@@ -29,20 +29,6 @@ class ValidatorServiceProvider implements ServiceProviderInterface
public
function
register
(
Container
$app
)
{
$app
[
'validator'
]
=
function
(
$app
)
{
if
(
isset
(
$app
[
'translator'
]))
{
$r
=
new
\ReflectionClass
(
'Symfony\Component\Validator\Validation'
);
$file
=
dirname
(
$r
->
getFilename
())
.
'/Resources/translations/validators.'
.
$app
[
'locale'
]
.
'.xlf'
;
if
(
file_exists
(
$file
))
{
$app
->
extend
(
'translator.resources'
,
function
(
$resources
,
$app
)
use
(
$file
)
{
$resources
=
array_merge
(
array
(
array
(
'xliff'
,
$file
,
$app
[
'locale'
],
'validators'
),
),
$resources
);
return
$resources
;
});
}
}
return
$app
[
'validator.builder'
]
->
getValidator
();
};
...
...
tests/Silex/Tests/Provider/ValidatorServiceProviderTest.php
View file @
42f199cc
...
...
@@ -146,7 +146,10 @@ class ValidatorServiceProviderTest extends \PHPUnit_Framework_TestCase
);
}
public
function
testAddResource
()
/**
* @dataProvider getAddResourceData
*/
public
function
testAddResource
(
$registerValidatorFirst
)
{
$app
=
new
Application
();
$app
[
'locale'
]
=
'fr'
;
...
...
@@ -159,11 +162,18 @@ class ValidatorServiceProviderTest extends \PHPUnit_Framework_TestCase
return
$translator
;
});
if
(
$registerValidatorFirst
)
{
$app
[
'validator'
];
}
$this
->
assertEquals
(
'Pas vide'
,
$app
[
'translator'
]
->
trans
(
'This value should not be blank.'
,
array
(),
'validators'
,
'fr'
));
}
public
function
getAddResourceData
()
{
return
array
(
array
(
false
),
array
(
true
));
}
public
function
testAddResourceAlternate
()
{
$app
=
new
Application
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment