Merge branch '2.4' into 2.5

* 2.4:
  fix typos
  [HttpKernel] add use statement for phpdoc
  Disabled the PHPUnit self-update on Travis
  [ClassLoader] simplified phpdoc
  [ClassLoader] Add a __call() method to XcacheClassLoader
  fix some minor typos in tests
  [Yaml] fixed mapping keys containing a quoted #
  Added fixture to test parsing of hash keys ending with a space and #
  [Filesystem Component] mkdir race condition fix #11626
  [Validator] reverted permissions change on translation files
  Fixed Factory services not within the ServiceReferenceGraph.
  [CssSelector] Fix URL to SimonSapin/cssselect repo
  [Validator] Fixed wrong translation keys/messages for Collection constraint. The error messages for a missing field and an unexpected field did not match the Contraint class
  [YAML] resolve variables in inlined YAML
  Disallow abstract definitions from doctrine event listener registration

Conflicts:
	src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php
	src/Symfony/Component/Yaml/Inline.php
This commit is contained in:
Fabien Potencier 2014-08-31 05:22:04 +02:00
commit 6ff62cc675
66 changed files with 465 additions and 229 deletions

View File

@ -23,7 +23,7 @@ before_script:
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm-nightly" ]; then echo "extension = memcache.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi;'
- sudo locale-gen fr_FR.UTF-8 && sudo update-locale
- COMPOSER_ROOT_VERSION=dev-master composer --prefer-source --dev install
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "5.3.3" ]; then phpunit --self-update; fi;'
# - sh -c 'if [ "$TRAVIS_PHP_VERSION" != "5.3.3" ]; then phpunit --self-update; fi;'
script:
- ls -d src/Symfony/*/* | parallel --gnu --keep-order 'echo "Running {} tests"; phpunit --exclude-group tty,benchmark {};'

View File

@ -69,7 +69,6 @@ class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface
return $a > $b ? -1 : 1;
};
if (!empty($taggedSubscribers)) {
$subscribersPerCon = $this->groupByConnection($taggedSubscribers);
foreach ($subscribersPerCon as $con => $subscribers) {
@ -77,6 +76,10 @@ class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface
uasort($subscribers, $sortFunc);
foreach ($subscribers as $id => $instance) {
if ($container->getDefinition($id)->isAbstract()) {
throw new \InvalidArgumentException(sprintf('The abstract service "%s" cannot be tagged as a doctrine event subscriber.', $id));
}
$em->addMethodCall('addEventSubscriber', array(new Reference($id)));
}
}
@ -89,6 +92,10 @@ class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface
uasort($listeners, $sortFunc);
foreach ($listeners as $id => $instance) {
if ($container->getDefinition($id)->isAbstract()) {
throw new \InvalidArgumentException(sprintf('The abstract service "%s" cannot be tagged as a doctrine event listener.', $id));
}
$em->addMethodCall('addEventListener', array(
array_unique($instance['event']),
isset($instance['lazy']) && $instance['lazy'] ? $id : new Reference($id),

View File

@ -13,9 +13,42 @@ namespace Symfony\Bridge\Doctrine\Tests\DependencyInjection\CompilerPass;
use Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterEventListenersAndSubscribersPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
class RegisterEventListenersAndSubscribersPassTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException InvalidArgumentException
*/
public function testExceptionOnAbstractTaggedSubscriber()
{
$container = $this->createBuilder();
$abstractDefinition = new Definition('stdClass');
$abstractDefinition->setAbstract(true);
$abstractDefinition->addTag('doctrine.event_subscriber');
$container->setDefinition('a', $abstractDefinition);
$this->process($container);
}
/**
* @expectedException InvalidArgumentException
*/
public function testExceptionOnAbstractTaggedListener()
{
$container = $this->createBuilder();
$abstractDefinition = new Definition('stdClass');
$abstractDefinition->setAbstract(true);
$abstractDefinition->addTag('doctrine.event_listener', array('event' => 'test'));
$container->setDefinition('a', $abstractDefinition);
$this->process($container);
}
public function testProcessEventListenersWithPriorities()
{
$container = $this->createBuilder();

View File

@ -15,7 +15,7 @@ namespace Symfony\Component\ClassLoader;
* ApcClassLoader implements a wrapping autoloader cached in APC for PHP 5.3.
*
* It expects an object implementing a findFile method to find the file. This
* allow using it as a wrapper around the other loaders of the component (the
* allows using it as a wrapper around the other loaders of the component (the
* ClassLoader and the UniversalClassLoader for instance) but also around any
* other autoloader following this convention (the Composer one for instance)
*
@ -46,7 +46,7 @@ class ApcClassLoader
/**
* The class loader object being decorated.
*
* @var \Symfony\Component\ClassLoader\ClassLoader
* @var object
* A class loader object that implements the findFile() method.
*/
protected $decorated;
@ -133,5 +133,4 @@ class ApcClassLoader
{
return call_user_func_array(array($this->decorated, $method), $args);
}
}

View File

@ -12,7 +12,7 @@
namespace Symfony\Component\ClassLoader;
/**
* XcacheClassLoader implements a wrapping autoloader cached in Xcache for PHP 5.3.
* XcacheClassLoader implements a wrapping autoloader cached in XCache for PHP 5.3.
*
* It expects an object implementing a findFile method to find the file. This
* allows using it as a wrapper around the other loaders of the component (the
@ -43,31 +43,35 @@ namespace Symfony\Component\ClassLoader;
class XcacheClassLoader
{
private $prefix;
private $classFinder;
/**
* @var object A class loader object that implements the findFile() method
*/
private $decorated;
/**
* Constructor.
*
* @param string $prefix A prefix to create a namespace in Xcache
* @param object $classFinder An object that implements findFile() method.
* @param string $prefix The XCache namespace prefix to use.
* @param object $decorated A class loader object that implements the findFile() method.
*
* @throws \RuntimeException
* @throws \InvalidArgumentException
*
* @api
*/
public function __construct($prefix, $classFinder)
public function __construct($prefix, $decorated)
{
if (!extension_loaded('Xcache')) {
throw new \RuntimeException('Unable to use XcacheClassLoader as Xcache is not enabled.');
if (!extension_loaded('xcache')) {
throw new \RuntimeException('Unable to use XcacheClassLoader as XCache is not enabled.');
}
if (!method_exists($classFinder, 'findFile')) {
if (!method_exists($decorated, 'findFile')) {
throw new \InvalidArgumentException('The class finder must implement a "findFile" method.');
}
$this->prefix = $prefix;
$this->classFinder = $classFinder;
$this->decorated = $decorated;
}
/**
@ -116,10 +120,18 @@ class XcacheClassLoader
if (xcache_isset($this->prefix.$class)) {
$file = xcache_get($this->prefix.$class);
} else {
$file = $this->classFinder->findFile($class);
$file = $this->decorated->findFile($class);
xcache_set($this->prefix.$class, $file);
}
return $file;
}
/**
* Passes through all unknown calls onto the decorated object.
*/
public function __call($method, $args)
{
return call_user_func_array(array($this->decorated, $method), $args);
}
}

View File

@ -12,7 +12,7 @@
namespace Symfony\Component\Config\Definition\Builder;
/**
* Abstract class that contain common code of integer and float node definition.
* Abstract class that contains common code of integer and float node definitions.
*
* @author David Jeanmonod <david.jeanmonod@gmail.com>
*/

View File

@ -35,7 +35,7 @@ Resources
This component is a port of the Python lxml library, which is copyright Infrae
and distributed under the BSD license.
Current code is a port of https://github.com/SimonSapin/cssselect@v0.7.1
Current code is a port of https://github.com/SimonSapin/cssselect/releases/tag/v0.7.1
You can run the unit tests with the following command:

View File

@ -69,7 +69,11 @@ class AnalyzeServiceReferencesPass implements RepeatablePassInterface
$this->currentId = $id;
$this->currentDefinition = $definition;
$this->processArguments($definition->getArguments());
if ($definition->getFactoryService()) {
$this->processArguments(array(new Reference($definition->getFactoryService())));
}
if (!$this->onlyConstructorArguments) {
$this->processArguments($definition->getMethodCalls());

View File

@ -97,6 +97,26 @@ class AnalyzeServiceReferencesPassTest extends \PHPUnit_Framework_TestCase
$this->assertCount(2, $graph->getNode('a')->getInEdges());
}
public function testProcessDetectsFactoryReferences()
{
$container = new ContainerBuilder();
$container
->register('foo', 'stdClass')
->setFactoryClass('stdClass')
->setFactoryMethod('getInstance');
$container
->register('bar', 'stdClass')
->setFactoryService('foo')
->setFactoryMethod('getInstance');
$graph = $this->process($container);
$this->assertTrue($graph->hasNode('foo'));
$this->assertCount(1, $graph->getNode('foo')->getInEdges());
}
protected function process(ContainerBuilder $container)
{
$pass = new RepeatedPass(array(new AnalyzeServiceReferencesPass()));

View File

@ -48,6 +48,26 @@ class CheckCircularReferencesPassTest extends \PHPUnit_Framework_TestCase
$this->process($container);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
*/
public function testProcessWithFactory()
{
$container = new ContainerBuilder();
$container
->register('a', 'stdClass')
->setFactoryService('b')
->setFactoryMethod('getInstance');
$container
->register('b', 'stdClass')
->setFactoryService('a')
->setFactoryMethod('getInstance');
$this->process($container);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
*/
@ -61,6 +81,25 @@ class CheckCircularReferencesPassTest extends \PHPUnit_Framework_TestCase
$this->process($container);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
*/
public function testProcessDetectsIndirectCircularReferenceWithFactory()
{
$container = new ContainerBuilder();
$container->register('a')->addArgument(new Reference('b'));
$container
->register('b', 'stdClass')
->setFactoryService('c')
->setFactoryMethod('getInstance');
$container->register('c')->addArgument(new Reference('a'));
$this->process($container);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
*/

View File

@ -81,6 +81,33 @@ class RemoveUnusedDefinitionsPassTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($container->hasDefinition('bar'));
}
public function testProcessWontRemovePrivateFactory()
{
$container = new ContainerBuilder();
$container
->register('foo', 'stdClass')
->setFactoryClass('stdClass')
->setFactoryMethod('getInstance')
->setPublic(false);
$container
->register('bar', 'stdClass')
->setFactoryService('foo')
->setFactoryMethod('getInstance')
->setPublic(false);
$container
->register('foobar')
->addArgument(new Reference('bar'));
$this->process($container);
$this->assertTrue($container->hasDefinition('foo'));
$this->assertTrue($container->hasDefinition('bar'));
$this->assertTrue($container->hasDefinition('foobar'));
}
protected function process(ContainerBuilder $container)
{
$repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), new RemoveUnusedDefinitionsPass()));

View File

@ -80,7 +80,14 @@ class Filesystem
}
if (true !== @mkdir($dir, $mode, true)) {
throw new IOException(sprintf('Failed to create "%s".', $dir), 0, null, $dir);
$error = error_get_last();
if (!is_dir($dir)) {
// The directory was not created by a concurrent process. Let's throw an exception with a developer friendly error message if we have one
if ($error) {
throw new IOException(sprintf('Failed to create "%s": %s.', $dir, $error['message']), 0, null, $dir);
}
throw new IOException(sprintf('Failed to create "%s"', $dir), 0, null, $dir);
}
}
}
}

View File

@ -48,7 +48,7 @@ abstract class SessionListener implements EventSubscriberInterface
/**
* Gets the session object.
*
* @return SessionInterface|null A SessionInterface instance of null if no session is available
* @return SessionInterface|null A SessionInterface instance or null if no session is available
*/
abstract protected function getSession();
}

View File

@ -78,7 +78,7 @@ abstract class TestSessionListener implements EventSubscriberInterface
/**
* Gets the session object.
*
* @return SessionInterface|null A SessionInterface instance of null if no session is available
* @return SessionInterface|null A SessionInterface instance or null if no session is available
*/
abstract protected function getSession();
}

View File

@ -648,7 +648,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
public function testPhpDeadlock()
{
$this->markTestSkipped('Can course PHP to hang');
$this->markTestSkipped('Can cause PHP to hang');
// Sleep doesn't work as it will allow the process to handle signals and close
// file handles from the other end.

View File

@ -85,7 +85,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage his PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessWithTermSignal()
{
@ -94,7 +94,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage his PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessIsNotSignaled()
{
@ -103,7 +103,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage his PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessWithoutTermSignal()
{

View File

@ -35,12 +35,12 @@
<target>Een of meer van die gegewe waardes is ongeldig.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Die velde {{ fields }} is nie verwag nie.</target>
<source>This field was not expected.</source>
<target>Die veld is nie verwag nie.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Die velde {{ fields }} ontbreek.</target>
<source>This field is missing.</source>
<target>Hierdie veld ontbreek.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>واحد أو أكثر من القيم المعطاه خاطئ.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>القيم {{ fields }} لم تكن متوقعة.</target>
<source>This field was not expected.</source>
<target>لم يكن من المتوقع هذا المجال.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>القيم {{ fields }} مفقودة.</target>
<source>This field is missing.</source>
<target>هذا المجال مفقود.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Една или повече от зададените стойности е невалидна.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Полетата {{ fields }} не бяха очаквани.</target>
<source>This field was not expected.</source>
<target>Това поле не се е очаквало.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Полетата {{ fields }} липсват.</target>
<source>This field is missing.</source>
<target>Това поле липсва.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Un o més dels valors facilitats són incorrectes.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>No s'esperaven els camps {{ fields }}.</target>
<source>This field was not expected.</source>
<target>Aquest camp no s'esperava.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Falten els camps {{ fields }}.</target>
<source>This field is missing.</source>
<target>Aquest camp està desaparegut.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Některé z uvedených hodnot jsou neplatné.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Neočekávaná pole {{ fields }}.</target>
<source>This field was not expected.</source>
<target>Toto pole nebyla očekávána.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Chybí následující pole {{ fields }}.</target>
<source>This field is missing.</source>
<target>Toto pole chybí.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Mae un neu fwy o'r gwerthoedd a roddwyd yn annilys.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Roedd y maesydd {{ fields }} yn anisgwyl.</target>
<source>This field was not expected.</source>
<target>Nid oedd disgwyl y maes hwn.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Roedd y maesydd {{ fields }} ar goll.</target>
<source>This field is missing.</source>
<target>Mae'r maes hwn ar goll.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>En eller flere af de oplyste værdier er ugyldige.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Felterne {{ fields }} var ikke forventet.</target>
<source>This field was not expected.</source>
<target>Feltet blev ikke forventet.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Felterne {{ fields }} mangler.</target>
<source>This field is missing.</source>
<target>Dette felt er mangler.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Einer oder mehrere der angegebenen Werte sind ungültig.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Die Felder {{ fields }} wurden nicht erwartet.</target>
<source>This field was not expected.</source>
<target>Dieses Feld wurde nicht erwartet.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Die erwarteten Felder {{ fields }} fehlen.</target>
<source>This field is missing.</source>
<target>Dieses Feld fehlt.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Μια ή περισσότερες τιμές δεν είναι έγκυρες.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Τα πεδία {{ fields }} δεν ήταν αναμενόμενα.</target>
<source>This field was not expected.</source>
<target>Αυτό το πεδίο δεν ήταν αναμενόμενο.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Τα πεδία {{ fields }} απουσιάζουν.</target>
<source>This field is missing.</source>
<target>Λείπει αυτό το πεδίο.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>One or more of the given values is invalid.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>The fields {{ fields }} were not expected.</target>
<source>This field was not expected.</source>
<target>This field was not expected.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>The fields {{ fields }} are missing.</target>
<source>This field is missing.</source>
<target>This field is missing.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Uno o más de los valores indicados no son válidos.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>No se esperaban los campos {{ fields }}.</target>
<source>This field was not expected.</source>
<target>Este campo no se esperaba.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Faltan los campos {{ fields }}.</target>
<source>This field is missing.</source>
<target>Este campo está desaparecido.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>One or more of the given values is invalid.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Väljad {{ fields }} olid ootamatud.</target>
<source>This field was not expected.</source>
<target>See väli ei oodatud.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Väljad {{ fields }} on puudu.</target>
<source>This field is missing.</source>
<target>See väli on puudu.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Emandako balioetatik gutxienez bat ez da egokia.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>{{ fields }} eremuak ez ziren espero.</target>
<source>This field was not expected.</source>
<target>Eremu hau ez zen espero.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>{{ fields }} eremuak falta dira.</target>
<source>This field is missing.</source>
<target>Eremu hau falta da.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Yksi tai useampi annetuista arvoista on virheellinen.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Odottamattomia kenttiä {{ fields }}.</target>
<source>This field was not expected.</source>
<target>Tässä kentässä ei odotettu.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Kentät {{ fields }} puuttuvat.</target>
<source>This field is missing.</source>
<target>Tämä kenttä puuttuu.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Une ou plusieurs des valeurs soumises sont invalides.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Les champs {{ fields }} n'ont pas été prévus.</target>
<source>This field was not expected.</source>
<target>Ce champ n'a pas été prévu.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Les champs {{ fields }} sont manquants.</target>
<source>This field is missing.</source>
<target>Ce champ est manquant.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Un ou máis dos valores indicados non son válidos.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Non se esperaban os campos {{ fields }}.</target>
<source>This field was not expected.</source>
<target>Este campo non era esperado.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Faltan os campos {{ fields }}.</target>
<source>This field is missing.</source>
<target>Este campo falta.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>אחד או יותר מהערכים אינו חוקי.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>השדות {{ fields }} לא היו צפויים.</target>
<source>This field was not expected.</source>
<target>שדה זה לא היה צפוי</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>השדות {{ fields }} חסרים.</target>
<source>This field is missing.</source>
<target>שדה זה חסר.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Jedna ili više danih vrijednosti nije ispravna.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Polja {{ fields }} nisu bila očekivana.</target>
<source>This field was not expected.</source>
<target>Ovo polje nije očekivalo.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Polja {{ fields }} nedostaju.</target>
<source>This field is missing.</source>
<target>Ovo polje nedostaje.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>A megadott értékek közül legalább egy érvénytelen.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Váratlan mezők: {{ fields }}.</target>
<source>This field was not expected.</source>
<target>Ez a mező nem számítottak.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>A következő mezők hiányoznak: {{ fields }}.</target>
<source>This field is missing.</source>
<target>Ez a mező hiányzik.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Մեկ կամ ավելի տրված արժեքները անթույլատրելի են.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>{{ fields }} տողերը չէին սպասվում.</target>
<source>This field was not expected.</source>
<target>Այս դաշտը չի սպասվում.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>{{ fields }} տողերը բացակայում են.</target>
<source>This field is missing.</source>
<target>Այս դաշտը բացակայում է.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Satu atau lebih nilai yang diberikan tidak sah.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Kolom {{ fields }} tidak seperti yang diharapkan.</target>
<source>This field was not expected.</source>
<target>Bidang ini tidak diharapkan.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Kolom {{ fields }} hilang.</target>
<source>This field is missing.</source>
<target>Bidang ini hilang.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Uno o più valori inseriti non sono validi.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>I campi {{ fields }} non sono validi.</target>
<source>This field was not expected.</source>
<target>Questo campo non è stato previsto.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>I campi {{ fields }} sono mancanti.</target>
<source>This field is missing.</source>
<target>Questo campo è manca.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>無効な選択肢が含まれています。</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>フィールド{{ fields }}は無効です。</target>
<source>This field was not expected.</source>
<target>このフィールドは予期されていませんでした。</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>フィールド{{ fields }}は必須です。</target>
<source>This field is missing.</source>
<target>このフィールドは、欠落しています。</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Viena ar daugiau įvestų reikšmių yra netinkamos.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Laukai {{ fields }} yra nenumatyti.</target>
<source>This field was not expected.</source>
<target>Nebuvo tikimasi Šis laukas.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Trūkstami laukai {{ fields }}.</target>
<source>This field is missing.</source>
<target>Šiame lauke yra dingęs.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Өгөгдсөн нэг эсвэл нэгээс олон утга буруу байна.</target>
</trans-unit>
<trans-unit id="9">
<source>Талбарууд {{ fields }} зөвшөөрөгдөөгүй байна.</source>
<target>{{ fields }}.</target>
<source>This field was not expected.</source>
<target>Энэ талбар нь хүлээгдэж байсан юм.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>{{ fields }} талбарууд дутуу байна.</target>
<source>This field is missing.</source>
<target>Энэ талбар нь алга болсон байна.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>En eller flere av de oppgitte verdier er ugyldige.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Feltene {{ fields }} var ikke forventet.</target>
<source>This field was not expected.</source>
<target>Dette feltet ikke var forventet.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Feltene {{ fields }} mangler.</target>
<source>This field is missing.</source>
<target>Dette feltet mangler.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Eén of meer van de ingegeven waarden zijn ongeldig.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>De velden {{ fields }} werden niet verwacht.</target>
<source>This field was not expected.</source>
<target>Dit veld was niet verwacht.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>De velden {{ fields }} ontbreken.</target>
<source>This field is missing.</source>
<target>Dit veld ontbreekt.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Ein eller fleire av dei opplyste verdiane er ugyldige.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Felta {{ fields }} var ikkje forventa.</target>
<source>This field was not expected.</source>
<target>Dette feltet var ikke forventet.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Felta {{ fields }} manglar.</target>
<source>This field is missing.</source>
<target>Dette feltet mangler.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Jedna lub więcej z podanych wartości jest nieprawidłowa.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Pola {{ fields }} nie były oczekiwane.</target>
<source>This field was not expected.</source>
<target>To pole nie spodziewano.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Brakuje pól {{ fields }}.</target>
<source>This field is missing.</source>
<target>To pole jest chybianie.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Um ou mais dos valores introduzidos não são válidos.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Os campos {{ fields }} não eram esperados.</target>
<source>This field was not expected.</source>
<target>Este campo não era esperado.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Os campos {{ fields }} estão ausentes.</target>
<source>This field is missing.</source>
<target>Este campo está faltando.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Um ou mais valores informados são inválidos.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Os campos {{ fields }} não são esperados.</target>
<source>This field was not expected.</source>
<target>Este campo não era esperado.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Os campos {{ fields }} estão ausentes.</target>
<source>This field is missing.</source>
<target>Este campo está ausente.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Una sau mai multe dintre valorile furnizate sunt invalide.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Câmpurile {{ fields }} nu erau așteptate.</target>
<source>This field was not expected.</source>
<target>Acest câmp nu era de aşteptat.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Câmpurile {{ fields }} lipsesc.</target>
<source>This field is missing.</source>
<target>Acest câmp este lipsă.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Одно или несколько заданных значений недопустимо.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Поля {{ fields }} не ожидались.</target>
<source>This field was not expected.</source>
<target>Это поле не ожидалось.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Поля {{ fields }} отсутствуют.</target>
<source>This field is missing.</source>
<target>Это поле отсутствует.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Niektoré z uvedených hodnôt sú neplatné.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Polia {{ fields }} neboli očakávané.</target>
<source>This field was not expected.</source>
<target>Toto pole sa neočakáva.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Chýbajú polia {{ fields }} .</target>
<source>This field is missing.</source>
<target>Toto pole chýba.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Ena ali več podanih vrednosti ni veljavnih.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Polja {{ fields }} niso bila pričakovana.</target>
<source>This field was not expected.</source>
<target>To polje ni bilo pričakovati.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Polja {{ fields }} manjkajo.</target>
<source>This field is missing.</source>
<target>To polje manjka.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Një apo më shumë nga vlerat e dhëna nuk janë të sakta.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Fushat {{ fields }} nuk ishin të pritura.</target>
<source>This field was not expected.</source>
<target>Kjo fushë nuk pritej.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Fushat {{ fields }} mungojnë.</target>
<source>This field is missing.</source>
<target>Kjo fushë është zhdukur.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Једна или више вредности је невалидна.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Поља {{ fields }} нису била очекивана.</target>
<source>This field was not expected.</source>
<target>Ово поље не очекује.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Поља {{ fields }} недостају.</target>
<source>This field is missing.</source>
<target>Ово поље недостаје.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Jedna ili više vrednosti je nevalidna.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Polja {{ fields }} nisu bila očekivana.</target>
<source>This field was not expected.</source>
<target>Ovo polje ne očekuje.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Polja {{ fields }} nedostaju.</target>
<source>This field is missing.</source>
<target>Ovo polje nedostaje.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Ett eller fler av de angivna värdena är ogiltigt.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Fälten {{ fields }} var oväntade.</target>
<source>This field was not expected.</source>
<target>Det här fältet förväntades inte.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Fälten {{ fields }} saknas.</target>
<source>This field is missing.</source>
<target>Det här fältet saknas.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>มีบางค่าที่ส่งมาไม่ถูกต้อง</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>{{ fields }} ฟิลด์เหล่านี้ไม่ใช่ฟิลด์ที่ถูกต้อง</target>
<source>This field was not expected.</source>
<target>ฟิลด์นี้ที่ไม่ได้คาดหวัง</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>{{ fields }} ฟิลด์เหล่านี้หายไป</target>
<source>This field is missing.</source>
<target>ฟิลด์นี้จะหายไป</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Verilen değerlerden bir veya daha fazlası geçersiz.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>{{ fields }} alanları kabul edilmedi.</target>
<source>This field was not expected.</source>
<target>Bu alan beklenen olmadı.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>{{ fields }} alanları eksik.</target>
<source>This field is missing.</source>
<target>Bu alan, eksik</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Одне або кілька заданих значень є недопустимі.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Поля {{ fields }} не очікувалися.</target>
<source>This field was not expected.</source>
<target>Це поле не очікується.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Поля {{ fields }} відсутні.</target>
<source>This field is missing.</source>
<target>Це поле не вистачає.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>Một hoặc nhiều giá trị được chọn không hợp lệ.</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>Trường có tên {{ fields }} không được chấp nhận.</target>
<source>This field was not expected.</source>
<target>Lĩnh vực này không được dự kiến.</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>Trường có tên {{ fields }} không tìm thấy.</target>
<source>This field is missing.</source>
<target>Lĩnh vực này là mất tích.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>一个或者多个给定的值无效。</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>非预期字段 {{ fields }} 。</target>
<source>This field was not expected.</source>
<target>此字段是没有预料到。</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>遗漏字段 {{ fields }} 。</target>
<source>This field is missing.</source>
<target>此字段是失踪。</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -35,12 +35,12 @@
<target>一個或者多個給定的值無效。</target>
</trans-unit>
<trans-unit id="9">
<source>The fields {{ fields }} were not expected.</source>
<target>非預期的欄位 {{ fields }} 。</target>
<source>This field was not expected.</source>
<target>此字段是沒有預料到。</target>
</trans-unit>
<trans-unit id="10">
<source>The fields {{ fields }} are missing.</source>
<target>缺少的欄位 {{ fields }} 。</target>
<source>This field is missing.</source>
<target>此字段缺失。</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>

View File

@ -32,12 +32,13 @@ class Inline
* @param string $value A YAML string
* @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
* @param bool $objectSupport true if object support is enabled, false otherwise
* @param array $references Mapping of variable names to values
*
* @return array A PHP array representing the YAML string
*
* @throws ParseException
*/
public static function parse($value, $exceptionOnInvalidType = false, $objectSupport = false)
public static function parse($value, $exceptionOnInvalidType = false, $objectSupport = false, $references = array())
{
self::$exceptionOnInvalidType = $exceptionOnInvalidType;
self::$objectSupport = $objectSupport;
@ -56,15 +57,15 @@ class Inline
$i = 0;
switch ($value[0]) {
case '[':
$result = self::parseSequence($value, $i);
$result = self::parseSequence($value, $i, $references);
++$i;
break;
case '{':
$result = self::parseMapping($value, $i);
$result = self::parseMapping($value, $i, $references);
++$i;
break;
default:
$result = self::parseScalar($value, null, array('"', "'"), $i);
$result = self::parseScalar($value, null, array('"', "'"), $i, true, $references);
}
// some comments are allowed at the end
@ -184,14 +185,15 @@ class Inline
* @param scalar $scalar
* @param string $delimiters
* @param array $stringDelimiters
* @param int &$i
* @param bool $evaluate
* @param int &$i
* @param bool $evaluate
* @param array $references
*
* @return string A YAML string
*
* @throws ParseException When malformed inline YAML string is parsed
*/
public static function parseScalar($scalar, $delimiters = null, $stringDelimiters = array('"', "'"), &$i = 0, $evaluate = true)
public static function parseScalar($scalar, $delimiters = null, $stringDelimiters = array('"', "'"), &$i = 0, $evaluate = true, $references = array())
{
if (in_array($scalar[$i], $stringDelimiters)) {
// quoted scalar
@ -221,7 +223,7 @@ class Inline
}
if ($evaluate) {
$output = self::evaluateScalar($output);
$output = self::evaluateScalar($output, $references);
}
}
@ -262,13 +264,14 @@ class Inline
* Parses a sequence to a YAML string.
*
* @param string $sequence
* @param int &$i
* @param int &$i
* @param array $references
*
* @return string A YAML string
*
* @throws ParseException When malformed inline YAML string is parsed
*/
private static function parseSequence($sequence, &$i = 0)
private static function parseSequence($sequence, &$i = 0, $references = array())
{
$output = array();
$len = strlen($sequence);
@ -279,11 +282,11 @@ class Inline
switch ($sequence[$i]) {
case '[':
// nested sequence
$output[] = self::parseSequence($sequence, $i);
$output[] = self::parseSequence($sequence, $i, $references);
break;
case '{':
// nested mapping
$output[] = self::parseMapping($sequence, $i);
$output[] = self::parseMapping($sequence, $i, $references);
break;
case ']':
return $output;
@ -292,12 +295,14 @@ class Inline
break;
default:
$isQuoted = in_array($sequence[$i], array('"', "'"));
$value = self::parseScalar($sequence, array(',', ']'), array('"', "'"), $i);
$value = self::parseScalar($sequence, array(',', ']'), array('"', "'"), $i, true, $references);
if (!$isQuoted && false !== strpos($value, ': ')) {
// the value can be an array if a reference has been resolved to an array var
if (!is_array($value) && !$isQuoted && false !== strpos($value, ': ')) {
// embedded mapping?
try {
$value = self::parseMapping('{'.$value.'}');
$pos = 0;
$value = self::parseMapping('{'.$value.'}', $pos, $references);
} catch (\InvalidArgumentException $e) {
// no, it's not
}
@ -318,13 +323,14 @@ class Inline
* Parses a mapping to a YAML string.
*
* @param string $mapping
* @param int &$i
* @param int &$i
* @param array $references
*
* @return string A YAML string
*
* @throws ParseException When malformed inline YAML string is parsed
*/
private static function parseMapping($mapping, &$i = 0)
private static function parseMapping($mapping, &$i = 0, $references = array())
{
$output = array();
$len = strlen($mapping);
@ -350,7 +356,7 @@ class Inline
switch ($mapping[$i]) {
case '[':
// nested sequence
$value = self::parseSequence($mapping, $i);
$value = self::parseSequence($mapping, $i, $references);
// Spec: Keys MUST be unique; first one wins.
// Parser cannot abort this mapping earlier, since lines
// are processed sequentially.
@ -361,7 +367,7 @@ class Inline
break;
case '{':
// nested mapping
$value = self::parseMapping($mapping, $i);
$value = self::parseMapping($mapping, $i, $references);
// Spec: Keys MUST be unique; first one wins.
// Parser cannot abort this mapping earlier, since lines
// are processed sequentially.
@ -374,7 +380,7 @@ class Inline
case ' ':
break;
default:
$value = self::parseScalar($mapping, array(',', '}'), array('"', "'"), $i);
$value = self::parseScalar($mapping, array(',', '}'), array('"', "'"), $i, true, $references);
// Spec: Keys MUST be unique; first one wins.
// Parser cannot abort this mapping earlier, since lines
// are processed sequentially.
@ -400,15 +406,31 @@ class Inline
* Evaluates scalars and replaces magic values.
*
* @param string $scalar
* @param array $references
*
* @return string A YAML string
*
* @throws ParseException when object parsing support was disabled and the parser detected a PHP object
*/
private static function evaluateScalar($scalar)
private static function evaluateScalar($scalar, $references = array())
{
$scalar = trim($scalar);
$scalarLower = strtolower($scalar);
if (0 === strpos($scalar, '*')) {
if (false !== $pos = strpos($scalar, '#')) {
$value = substr($scalar, 1, $pos - 2);
} else {
$value = substr($scalar, 1);
}
if (!array_key_exists($value, $references)) {
throw new ParseException(sprintf('Reference "%s" does not exist.', $value));
}
return $references[$value];
}
switch (true) {
case 'null' === $scalarLower:
case '' === $scalar:

View File

@ -115,14 +115,14 @@ class Parser
$data[] = $this->parseValue($values['value'], $exceptionOnInvalidType, $objectSupport);
}
}
} elseif (preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\[\{].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->currentLine, $values) && false === strpos($values['key'],' #')) {
} elseif (preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\[\{].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->currentLine, $values) && (false === strpos($values['key'],' #') || in_array($values['key'][0], array('"', "'")))) {
if ($context && 'sequence' == $context) {
throw new ParseException('You cannot define a mapping item when in a sequence');
}
$context = 'mapping';
// force correct settings
Inline::parse(null, $exceptionOnInvalidType, $objectSupport);
Inline::parse(null, $exceptionOnInvalidType, $objectSupport, $this->refs);
try {
$key = Inline::parseScalar($values['key']);
} catch (ParseException $e) {
@ -232,7 +232,7 @@ class Parser
$lineCount = count($this->lines);
if (1 === $lineCount || (2 === $lineCount && empty($this->lines[1]))) {
try {
$value = Inline::parse($this->lines[0], $exceptionOnInvalidType, $objectSupport);
$value = Inline::parse($this->lines[0], $exceptionOnInvalidType, $objectSupport, $this->refs);
} catch (ParseException $e) {
$e->setParsedLine($this->getRealCurrentLineNb() + 1);
$e->setSnippet($this->currentLine);
@ -439,7 +439,7 @@ class Parser
}
try {
return Inline::parse($value, $exceptionOnInvalidType, $objectSupport);
return Inline::parse($value, $exceptionOnInvalidType, $objectSupport, $this->refs);
} catch (ParseException $e) {
$e->setParsedLine($this->getRealCurrentLineNb() + 1);
$e->setSnippet($this->currentLine);

View File

@ -63,3 +63,11 @@ brief: >
yaml: 'foo#bar: baz'
php: |
array('foo#bar' => 'baz')
---
test: 'Hash key ending with a space and a #'
brief: >
'Hash key ending with a space and a #'
yaml: |
'foo #': baz
php: |
array('foo #' => 'baz')

View File

@ -115,6 +115,38 @@ class InlineTest extends \PHPUnit_Framework_TestCase
$this->assertSame($expect, Inline::parseScalar($value));
}
/**
* @dataProvider getDataForParseReferences
*/
public function testParseReferences($yaml, $expected)
{
$this->assertSame($expected, Inline::parse($yaml, false, false, array('var' => 'var-value')));
}
public function getDataForParseReferences()
{
return array(
'scalar' => array('*var', 'var-value'),
'list' => array('[ *var ]', array('var-value')),
'list-in-list' => array('[[ *var ]]', array(array('var-value'))),
'map-in-list' => array('[ { key: *var } ]', array(array('key' => 'var-value'))),
'embedded-mapping-in-list' => array('[ key: *var ]', array(array('key' => 'var-value'))),
'map' => array('{ key: *var }', array('key' => 'var-value')),
'list-in-map' => array('{ key: [*var] }', array('key' => array('var-value'))),
'map-in-map' => array('{ foo: { bar: *var } }', array('foo' => array('bar' => 'var-value'))),
);
}
public function testParseMapReferenceInSequence()
{
$foo = array(
'a' => 'Steve',
'b' => 'Clark',
'c' => 'Brian',
);
$this->assertSame(array($foo), Inline::parse('[*foo]', false, false, array('foo' => $foo)));
}
protected function getTestsForParse()
{
return array(

View File

@ -649,6 +649,32 @@ EOT
</body>
footer # comment3
EOF
));
}
public function testReferenceResolvingInInlineStrings()
{
$this->assertEquals(array(
'var' => 'var-value',
'scalar' => 'var-value',
'list' => array('var-value'),
'list_in_list' => array(array('var-value')),
'map_in_list' => array(array('key' => 'var-value')),
'embedded_mapping' => array(array('key' => 'var-value')),
'map' => array('key' => 'var-value'),
'list_in_map' => array('key' => array('var-value')),
'map_in_map' => array('foo' => array('bar' => 'var-value')),
), Yaml::parse(<<<EOF
var: &var var-value
scalar: *var
list: [ *var ]
list_in_list: [[ *var ]]
map_in_list: [ { key: *var } ]
embedded_mapping: [ key: *var ]
map: { key: *var }
list_in_map: { key: [*var] }
map_in_map: { foo: { bar: *var } }
EOF
));
}