Yaml Component
The Yaml component loads and dumps YAML files.
The Yaml component loads and dumps YAML files.
I think there is a bug with nested keys in some case. For starters I updated the merge key test to show the behavior I expect and the error that is instead produce
Items now get referenced sub-properties merged:
refDef: &reference
subitem:
refUnique: true
shared: "Reference value"
item:
<<: *reference
subitem:
itemUnique: true
shared: "Item value"
OLD RESULT:
item:
subitem:
itemUnique: true
shared: "Item value"
NEW RESULT
item:
subitem:
itemUnique: true
shared: "Item value"
refUnique: true
Inheritance is reversed when reference is pulled-in after all the elements:
item:
subitem:
itemUnique: true
shared: "Item value"
<<: *reference
NEW RESULT
item:
subitem:
itemUnique: true
shared: "Reference value"
refUnique: true
Inline definitions will pick-up the same behavior.
I made this little change because I am converting a LOT of data into Yaml from a database, and I wanted to make sure that the data as as user-friendly as possible.
I asked this on SO: http://stackoverflow.com/questions/34805558/phps-yaml-deciding-how-to-generate-multiline-strings
Then I discovered your wonderful YAML module, which makes much better YAML than PHP's (at least in terms of user readibility) AND it was reallllyyyy easy to hack to add this simple feature (this tells you something about the quality of your code).
Disclaimer: I don't even know PHP. I am a nodeJS boy. But, I think the patch works, and I think it's worthwhile having.
Note: I am not sure how it should deal with \n
so that it's actually compatible with any Windows etc. If you feel this is a good addition, let me know and I will try and make it more generic...
Only supported in folded-scalar (lines ending with | or >) form, or inline form.
name_enc: !!binary "SGVsbG8sIHdvcmxkLg=="
desc_enc: !!binary |
SGVsbG8sIH
dvcmxkLg==
According to the YAML 1.2 specs section 2.2 Structures, the Examples 2.7 and 2.8 show that the document start ---
and end ...
can have content (such as whitespaces and comments) before and after respectively.
The current implementation of cleanup()
does not clean up the document start marker ---
if the marker is placed after comments. As a result, the Parser will throw an exception.
However, in this hotfix, I've changed the regular expression in the cleanup()
process such that as long as that line contains ---
or ...
only, we remove it.
If the markers are not used, then the usage is not affected.
Currently if you parse multiple files with the same Parser
instance, you get different results in the error reporting since the parser doesn't reset the offset.
<?php
include "vendor/autoload.php";
use Symfony\Component\Yaml\Parser;
$yamlString = "# translations/messages.en.yaml
sylius:
form:
catalog_promotion:
action:
fixed_price: 'Fixed price'
";
$yaml = new Parser();
$yaml->parse($yamlString);
$yaml->parse($yamlString);
try {
$yaml->parse("abc:
abc");
} catch (\Exception $e) {
echo $e->getMessage();
// Returns: A YAML file cannot contain tabs as indentation at line 4 (near " abc")
// This is incorrect because the error is on line 2.
// Adding more calls to $yaml->parse($yamlString) will mess with the error reporting even more
}
Hello,
As I investigated this issue, I noticed this rule which seems to me implicit. Here is the most surgical changes to obtain the expected result without break the existing output.
I have adding phpunit into project and update tests to remove coming deprecations of phpunit, because this is not bundled, and I have started the tests with my local phpunit (8).
Adding this failing test to demonstrate the issue I'm seeing. I'm afraid a fix has me puzzled for the moment.
Lines starting with a hash, within deeply-nested string blocks, are stripped from the parsed output.
Lines starting with a hash within top-level string blocks are parsed correctly and end up in the output.
So
my:
nested:
block: |
This is a bit
# of text
as an example
Will parse to
array(
'my' => array(
'nested' => array(
'block' => "This is a bit\nas an example\n"
)
)
)
But it should be
array(
'my' => array(
'nested' => array(
'block' => "This is a bit\n# of text\nas an example\n"
)
)
)
But
stuff:|
Something that
# works well
Parses to
array('stuff' => "Something that\n# works well");
...as far as I can tell.
Make sense?
Thanks.
At present parser only substitutes aliases when mapping is in a multiline. When the alias is used in the mapping stored in a single line, alias substitution doesn't work.
So I modified Parser to fix it.
keyname1: value1 subkeyname1: a value subkeyname2: <----Must leave blank here, if previous line-value is empty!! keyname2: value2
keyname1: value1
subkeyname1: a value
subkeyname2:
For example, if LC_ALL is set to fr_FR then float number got ',' as separator ; example : 4,75
In order to follow Yaml Specifications (http://yaml.org/type/float.html) we must replace the comma with a dot, and specify the float type.
Code to reproduce the bug :
<?php
setlocale(LC_ALL, 'fr_FR.UTF-8', 'fr_FR.UTF8', 'fr_FR.utf-8', 'fr_FR.utf8');
require_once dirname(__FILE__) . '/symfony/src/Symfony/Component/Yaml/Escaper.php';
require_once dirname(__FILE__) . '/symfony/src/Symfony/Component/Yaml/Unescaper.php';
require_once dirname(__FILE__) . '/symfony/src/Symfony/Component/Yaml/Inline.php';
require_once dirname(__FILE__) . '/symfony/src/Symfony/Component/Yaml/Dumper.php';
require_once dirname(__FILE__) . '/symfony/src/Symfony/Component/Yaml/Parser.php';
$tab = array('value' => round(54 / 72, 4));
var_dump($tab);
$dumper = new Symfony\Component\Yaml\Dumper();
$dump = $dumper->dump($tab, 1);
var_dump($dump);
$parser = new Symfony\Component\Yaml\Parser();
$parsed = $parser->parse($dump);
var_dump($parsed);
assert($parsed === $tab);
Changelog (https://github.com/symfony/yaml/compare/v6.1.8...v6.1.9)
Changelog (https://github.com/symfony/yaml/compare/v6.0.16...v6.0.17)
Changelog (https://github.com/symfony/yaml/compare/v5.4.16...v5.4.17)
Changelog (https://github.com/symfony/yaml/compare/v6.2.1...v6.2.2)
Changelog (https://github.com/symfony/yaml/compare/v6.2.0-RC2...v6.2.0)
Changelog (https://github.com/symfony/yaml/compare/v6.2.0-RC1...v6.2.0-RC2)
Changelog (https://github.com/symfony/yaml/compare/v6.1.7...v6.1.8)
Changelog (https://github.com/symfony/yaml/compare/v6.0.15...v6.0.16)
Changelog (https://github.com/symfony/yaml/compare/v5.4.15...v5.4.16)
Changelog (https://github.com/symfony/yaml/compare/v6.2.0-BETA3...v6.2.0-RC1)
Changelog (https://github.com/symfony/yaml/compare/v6.2.0-BETA2...v6.2.0-BETA3)
Changelog (https://github.com/symfony/yaml/compare/v6.1.6...v6.2.0-BETA1)
!php/enum *->value
syntax (nicolas-grekas)Changelog (https://github.com/symfony/yaml/compare/v6.1.5...v6.1.6)
Changelog (https://github.com/symfony/yaml/compare/v6.0.13...v6.0.14)
Changelog (https://github.com/symfony/yaml/compare/v5.4.13...v5.4.14)
Changelog (https://github.com/symfony/yaml/compare/v6.1.3...v6.1.4)
Changelog (https://github.com/symfony/yaml/compare/v6.0.11...v6.0.12)
Changelog (https://github.com/symfony/yaml/compare/v5.4.11...v5.4.12)
Changelog (https://github.com/symfony/yaml/compare/v4.4.44...v4.4.45)
Changelog (https://github.com/symfony/yaml/compare/v6.1.2...v6.1.3)
Changelog (https://github.com/symfony/yaml/compare/v6.0.10...v6.0.11)
Changelog (https://github.com/symfony/yaml/compare/v5.4.10...v5.4.11)
Changelog (https://github.com/symfony/yaml/compare/v4.4.43...v4.4.44)
Changelog (https://github.com/symfony/yaml/compare/v6.1.1...v6.1.2)
Changelog (https://github.com/symfony/yaml/compare/v6.0.9...v6.0.10)
Changelog (https://github.com/symfony/yaml/compare/v5.4.9...v5.4.10)
Changelog (https://github.com/symfony/yaml/compare/v4.4.42...v4.4.43)
Changelog (https://github.com/symfony/yaml/compare/v6.1.0-RC1...v6.1.0)
Changelog (https://github.com/symfony/yaml/compare/v6.1.0-BETA2...v6.1.0-RC1)
Changelog (https://github.com/symfony/yaml/compare/v6.1.0-BETA1...v6.1.0-BETA2)
Drest Dress up doctrine entities and expose them as REST resources This library allows you to quickly annotate your doctrine entities into restful res
PoP PoP is a monorepo containing several projects. The GraphQL API for WordPress plugin GraphQL API for WordPress is a forward-looking and powerful Gr
API Platform Core API Platform Core is an easy to use and powerful system to create hypermedia-driven REST and GraphQL APIs. It is a component of the
PoP PoP is a monorepo containing several projects. The GraphQL API for WordPress plugin GraphQL API for WordPress is a forward-looking and powerful Gr
Rate Limiter Component Fork (Compatible with Symfony <=4.4) The Rate Limiter component provides a Token Bucket implementation to rate limit input and
PasswordHasher Component The PasswordHasher component provides secure password hashing utilities. Getting Started $ composer require symfony/password-
Enter to the Matrix (with Symfony Console) Reproduction of the "Matrix characterfall" effect with the Symfony Console component. Run Clone the project
HttpKernel Component The HttpKernel component provides a structured process for converting a Request into a Response by making use of the EventDispatc
BrowserKit Component The BrowserKit component simulates the behavior of a web browser, allowing you to make requests, click on links and submit forms
Step-up Middleware This component is part of "Step-up Authentication as-a Service". See Stepup-Deploy for an overview and installation instructions fo
Best practices We don't recommend using this resource proxy. It is not being maintained and there's been no active development for many years. There a
Welcome to hook ![Gitter](https://badges.gitter.im/Join Chat.svg) hook is a RESTful, extendable Backend as a Service that provides instant backend to
Online-Book-Store Online Book Store is a E-commerce Website and Book Conversion(pdf to audio and Img to txt) and Book Sharing platform. The main descr
Luracast Restler ![Gitter](https://badges.gitter.im/Join Chat.svg) Version 3.0 Release Candidate 5 Restler is a simple and effective multi-format Web
Woohoo Labs. Harmony Woohoo Labs. Harmony is a PSR-15 compatible middleware dispatcher. Harmony was born to be a totally flexible and almost invisible
WOPI Bundle A Symfony bundle to facilitate the implementation of the WOPI endpoints and protocol. Description The Web Application Open Platform Interf
PHP API TO-DO-LIST v.2.0 This API aims to present a brief to consume a API resources, mainly for students in the early years of Computer Science cours
FACEBOOK TOOLKIT a tool to get Facebook data, and some Facebook bots, and extra tools found on Facebook Toolkit ++. Graph API Facebook. Made with ❤️ b
API Platform is a next-generation web framework designed to easily create API-first projects without compromising extensibility and flexibility: Desig