├── craft2yml ├── vendor │ ├── symfony │ │ └── yaml │ │ │ ├── .gitignore │ │ │ ├── Tests │ │ │ ├── Fixtures │ │ │ │ ├── embededPhp.yml │ │ │ │ ├── sfObjects.yml │ │ │ │ ├── index.yml │ │ │ │ ├── YtsErrorTests.yml │ │ │ │ ├── sfQuotes.yml │ │ │ │ ├── YtsNullsAndEmpties.yml │ │ │ │ ├── YtsAnchorAlias.yml │ │ │ │ ├── YtsBlockMapping.yml │ │ │ │ ├── YtsFlowCollections.yml │ │ │ │ ├── YtsDocumentSeparator.yml │ │ │ │ ├── sfComments.yml │ │ │ │ ├── sfMergeKey.yml │ │ │ │ ├── unindentedCollections.yml │ │ │ │ ├── escapedCharacters.yml │ │ │ │ ├── sfTests.yml │ │ │ │ ├── sfCompact.yml │ │ │ │ ├── YtsFoldedScalars.yml │ │ │ │ ├── YtsBasicTests.yml │ │ │ │ └── YtsTypeTransfers.yml │ │ │ ├── ParseExceptionTest.php │ │ │ ├── YamlTest.php │ │ │ ├── DumperTest.php │ │ │ ├── InlineTest.php │ │ │ └── ParserTest.php │ │ │ ├── README.md │ │ │ ├── Exception │ │ │ ├── ExceptionInterface.php │ │ │ ├── DumpException.php │ │ │ ├── RuntimeException.php │ │ │ └── ParseException.php │ │ │ ├── CHANGELOG.md │ │ │ ├── composer.json │ │ │ ├── phpunit.xml.dist │ │ │ ├── LICENSE │ │ │ ├── Dumper.php │ │ │ ├── Yaml.php │ │ │ ├── Escaper.php │ │ │ ├── Unescaper.php │ │ │ └── Inline.php │ ├── autoload.php │ └── composer │ │ ├── autoload_classmap.php │ │ ├── autoload_namespaces.php │ │ ├── autoload_psr4.php │ │ ├── autoload_static.php │ │ ├── LICENSE │ │ ├── installed.json │ │ ├── autoload_real.php │ │ └── ClassLoader.php ├── composer.json ├── config.php ├── consolecommands │ └── Craft2ymlCommand.php ├── controllers │ └── Craft2ymlController.php ├── Craft2ymlPlugin.php ├── composer.lock └── services │ └── Craft2ymlService.php ├── README.md ├── releases.json └── LICENSE /craft2yml/vendor/symfony/yaml/.gitignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | composer.lock 3 | phpunit.xml 4 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/Fixtures/embededPhp.yml: -------------------------------------------------------------------------------- 1 | value: 2 | -------------------------------------------------------------------------------- /craft2yml/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "symfony/yaml": "v2.8.20" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /craft2yml/vendor/autoload.php: -------------------------------------------------------------------------------- 1 | array($vendorDir . '/symfony/yaml'), 10 | ); 11 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/Fixtures/sfObjects.yml: -------------------------------------------------------------------------------- 1 | --- %YAML:1.0 2 | test: Objects 3 | brief: > 4 | Comments at the end of a line 5 | yaml: | 6 | ex1: "foo # bar" 7 | ex2: "foo # bar" # comment 8 | ex3: 'foo # bar' # comment 9 | ex4: foo # comment 10 | php: | 11 | array('ex1' => 'foo # bar', 'ex2' => 'foo # bar', 'ex3' => 'foo # bar', 'ex4' => 'foo') 12 | -------------------------------------------------------------------------------- /craft2yml/config.php: -------------------------------------------------------------------------------- 1 | 4, 8 | 9 | // Enable yml output for entry urls with appended '.yml' (e.g. /my-article.yml) 10 | 'useYmlUrlRoute' => true, 11 | ]; 12 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/Fixtures/index.yml: -------------------------------------------------------------------------------- 1 | - escapedCharacters 2 | - sfComments 3 | - sfCompact 4 | - sfTests 5 | - sfObjects 6 | - sfMergeKey 7 | - sfQuotes 8 | - YtsAnchorAlias 9 | - YtsBasicTests 10 | - YtsBlockMapping 11 | - YtsDocumentSeparator 12 | - YtsErrorTests 13 | - YtsFlowCollections 14 | - YtsFoldedScalars 15 | - YtsNullsAndEmpties 16 | - YtsSpecificationExamples 17 | - YtsTypeTransfers 18 | - unindentedCollections 19 | -------------------------------------------------------------------------------- /craft2yml/consolecommands/Craft2ymlCommand.php: -------------------------------------------------------------------------------- 1 | craft2yml->getYmlByEntryId($entryId); 13 | file_put_contents($targetFile, $yml); 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # craft2yml 2 | 3 | a craft cms plugin that translates entries and data structures to yml 4 | 5 | ## Settings 6 | 7 | to adjust settings copy [config.php](craft2yml/config.php) to **craft/config/craft2yml.php** and edit the settings. 8 | 9 | ## Show/download yml file in browser 10 | 11 | open your entry url and just append **'.yml'** to it. (this route can be disabled in settings) 12 | 13 | ## Generate yml file via console 14 | 15 | ``` 16 | craft/app/etc/console/yiic craft2yml saveYml --entryId=2 --targetFile=data.yml 17 | ``` -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/README.md: -------------------------------------------------------------------------------- 1 | Yaml Component 2 | ============== 3 | 4 | The Yaml component loads and dumps YAML files. 5 | 6 | Resources 7 | --------- 8 | 9 | * [Documentation](https://symfony.com/doc/current/components/yaml/index.html) 10 | * [Contributing](https://symfony.com/doc/current/contributing/index.html) 11 | * [Report issues](https://github.com/symfony/symfony/issues) and 12 | [send Pull Requests](https://github.com/symfony/symfony/pulls) 13 | in the [main Symfony repository](https://github.com/symfony/symfony) 14 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Exception/ExceptionInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Symfony\Component\Yaml\Exception; 13 | 14 | /** 15 | * Exception interface for all exceptions thrown by the component. 16 | * 17 | * @author Fabien Potencier 18 | */ 19 | interface ExceptionInterface 20 | { 21 | } 22 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Exception/DumpException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Symfony\Component\Yaml\Exception; 13 | 14 | /** 15 | * Exception class thrown when an error occurs during dumping. 16 | * 17 | * @author Fabien Potencier 18 | */ 19 | class DumpException extends RuntimeException 20 | { 21 | } 22 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Exception/RuntimeException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Symfony\Component\Yaml\Exception; 13 | 14 | /** 15 | * Exception class thrown when an error occurs during parsing. 16 | * 17 | * @author Romain Neutron 18 | */ 19 | class RuntimeException extends \RuntimeException implements ExceptionInterface 20 | { 21 | } 22 | -------------------------------------------------------------------------------- /craft2yml/controllers/Craft2ymlController.php: -------------------------------------------------------------------------------- 1 | elements->getCriteria(ElementType::Entry); 11 | $criteria->uri = $variables['entryUri']; 12 | $criteria->limit = 1; 13 | $entry = $criteria->first(); 14 | 15 | if (empty($entry)) { 16 | return 'entry not found'; 17 | } 18 | 19 | $yml = craft()->craft2yml->getYmlByEntryId($entry->id); 20 | 21 | header('Content-Type: text/yaml; charset=utf-8'); 22 | 23 | echo $yml; 24 | craft()->end(); 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | CHANGELOG 2 | ========= 3 | 4 | 2.8.0 5 | ----- 6 | 7 | * Deprecated usage of a colon in an unquoted mapping value 8 | * Deprecated usage of @, \`, | and > at the beginning of an unquoted string 9 | * When surrounding strings with double-quotes, you must now escape `\` characters. Not 10 | escaping those characters (when surrounded by double-quotes) is deprecated. 11 | 12 | Before: 13 | 14 | ```yml 15 | class: "Foo\Var" 16 | ``` 17 | 18 | After: 19 | 20 | ```yml 21 | class: "Foo\\Var" 22 | ``` 23 | 24 | 2.1.0 25 | ----- 26 | 27 | * Yaml::parse() does not evaluate loaded files as PHP files by default 28 | anymore (call Yaml::enablePhpParsing() to get back the old behavior) 29 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/Fixtures/YtsErrorTests.yml: -------------------------------------------------------------------------------- 1 | --- 2 | test: Missing value for hash item 3 | todo: true 4 | brief: | 5 | Third item in this hash doesn't have a value 6 | yaml: | 7 | okay: value 8 | also okay: ~ 9 | causes error because no value specified 10 | last key: value okay here too 11 | python-error: causes error because no value specified 12 | 13 | --- 14 | test: Not indenting enough 15 | brief: | 16 | There was a bug in PyYaml where it was off by one 17 | in the indentation check. It was allowing the YAML 18 | below. 19 | # This is actually valid YAML now. Someone should tell showell. 20 | yaml: | 21 | foo: 22 | firstline: 1 23 | secondline: 2 24 | php: | 25 | array('foo' => null, 'firstline' => 1, 'secondline' => 2) 26 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "symfony/yaml", 3 | "type": "library", 4 | "description": "Symfony Yaml Component", 5 | "keywords": [], 6 | "homepage": "https://symfony.com", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Fabien Potencier", 11 | "email": "fabien@symfony.com" 12 | }, 13 | { 14 | "name": "Symfony Community", 15 | "homepage": "https://symfony.com/contributors" 16 | } 17 | ], 18 | "require": { 19 | "php": ">=5.3.9" 20 | }, 21 | "autoload": { 22 | "psr-4": { "Symfony\\Component\\Yaml\\": "" }, 23 | "exclude-from-classmap": [ 24 | "/Tests/" 25 | ] 26 | }, 27 | "minimum-stability": "dev", 28 | "extra": { 29 | "branch-alias": { 30 | "dev-master": "2.8-dev" 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/Fixtures/sfQuotes.yml: -------------------------------------------------------------------------------- 1 | --- %YAML:1.0 2 | test: Some characters at the beginning of a string must be escaped 3 | brief: > 4 | Some characters at the beginning of a string must be escaped 5 | yaml: | 6 | foo: '| bar' 7 | php: | 8 | array('foo' => '| bar') 9 | --- 10 | test: A key can be a quoted string 11 | brief: > 12 | A key can be a quoted string 13 | yaml: | 14 | "foo1": bar 15 | 'foo2': bar 16 | "foo \" bar": bar 17 | 'foo '' bar': bar 18 | 'foo3: ': bar 19 | "foo4: ": bar 20 | foo5: { "foo \" bar: ": bar, 'foo '' bar: ': bar } 21 | php: | 22 | array( 23 | 'foo1' => 'bar', 24 | 'foo2' => 'bar', 25 | 'foo " bar' => 'bar', 26 | 'foo \' bar' => 'bar', 27 | 'foo3: ' => 'bar', 28 | 'foo4: ' => 'bar', 29 | 'foo5' => array( 30 | 'foo " bar: ' => 'bar', 31 | 'foo \' bar: ' => 'bar', 32 | ), 33 | ) 34 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/Fixtures/YtsNullsAndEmpties.yml: -------------------------------------------------------------------------------- 1 | --- %YAML:1.0 2 | test: Empty Sequence 3 | brief: > 4 | You can represent the empty sequence 5 | with an empty inline sequence. 6 | yaml: | 7 | empty: [] 8 | php: | 9 | array('empty' => array()) 10 | --- 11 | test: Empty Mapping 12 | brief: > 13 | You can represent the empty mapping 14 | with an empty inline mapping. 15 | yaml: | 16 | empty: {} 17 | php: | 18 | array('empty' => array()) 19 | --- 20 | test: Empty Sequence as Entire Document 21 | yaml: | 22 | [] 23 | php: | 24 | array() 25 | --- 26 | test: Empty Mapping as Entire Document 27 | yaml: | 28 | {} 29 | php: | 30 | array() 31 | --- 32 | test: Null as Document 33 | yaml: | 34 | ~ 35 | php: | 36 | null 37 | --- 38 | test: Empty String 39 | brief: > 40 | You can represent an empty string 41 | with a pair of quotes. 42 | yaml: | 43 | '' 44 | php: | 45 | '' 46 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | ./Tests/ 18 | 19 | 20 | 21 | 22 | 23 | ./ 24 | 25 | ./Tests 26 | ./vendor 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /craft2yml/vendor/composer/autoload_static.php: -------------------------------------------------------------------------------- 1 | 11 | array ( 12 | 'Symfony\\Component\\Yaml\\' => 23, 13 | ), 14 | ); 15 | 16 | public static $prefixDirsPsr4 = array ( 17 | 'Symfony\\Component\\Yaml\\' => 18 | array ( 19 | 0 => __DIR__ . '/..' . '/symfony/yaml', 20 | ), 21 | ); 22 | 23 | public static function getInitializer(ClassLoader $loader) 24 | { 25 | return \Closure::bind(function () use ($loader) { 26 | $loader->prefixLengthsPsr4 = ComposerStaticInit302d294513c4427a12f72ed5e81e0e93::$prefixLengthsPsr4; 27 | $loader->prefixDirsPsr4 = ComposerStaticInit302d294513c4427a12f72ed5e81e0e93::$prefixDirsPsr4; 28 | 29 | }, null, ClassLoader::class); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/Fixtures/YtsAnchorAlias.yml: -------------------------------------------------------------------------------- 1 | --- %YAML:1.0 2 | test: Simple Alias Example 3 | brief: > 4 | If you need to refer to the same item of data twice, 5 | you can give that item an alias. The alias is a plain 6 | string, starting with an ampersand. The item may then 7 | be referred to by the alias throughout your document 8 | by using an asterisk before the name of the alias. 9 | This is called an anchor. 10 | yaml: | 11 | - &showell Steve 12 | - Clark 13 | - Brian 14 | - Oren 15 | - *showell 16 | php: | 17 | array('Steve', 'Clark', 'Brian', 'Oren', 'Steve') 18 | 19 | --- 20 | test: Alias of a Mapping 21 | brief: > 22 | An alias can be used on any item of data, including 23 | sequences, mappings, and other complex data types. 24 | yaml: | 25 | - &hello 26 | Meat: pork 27 | Starch: potato 28 | - banana 29 | - *hello 30 | php: | 31 | array(array('Meat'=>'pork', 'Starch'=>'potato'), 'banana', array('Meat'=>'pork', 'Starch'=>'potato')) 32 | -------------------------------------------------------------------------------- /craft2yml/Craft2ymlPlugin.php: -------------------------------------------------------------------------------- 1 | config->get('useYmlUrlRoute', 'craft2yml')) { 45 | return array( 46 | '(?P.*)\.yml$' => array('action' => 'craft2yml/showYml'), 47 | ); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /releases.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "version": "1.0.3", 4 | "downloadUrl": "https://github.com/fork/craft2yml/archive/1.0.3.zip", 5 | "date": "2017-05-24T14:17:53.119Z", 6 | "notes": [ 7 | "[Added] Support neo fields and tags, categories and entries references (currently title and uri attribute)" 8 | ] 9 | }, 10 | { 11 | "version": "1.0.2", 12 | "downloadUrl": "https://github.com/fork/craft2yml/archive/1.0.2.zip", 13 | "date": "2017-05-24T13:03:02.530Z", 14 | "notes": [ 15 | "[Added] Show/download yml directly in browser. Just append '.yml' to the url", 16 | "[Added] Settings via config.php file which can be copied to craft/config/craft2yml.php", 17 | "[Fixed] Added getSchemaVersion() to plugin file (even if we don't have db migrations, craft checks this...)" 18 | ] 19 | }, 20 | { 21 | "version": "1.0.1", 22 | "downloadUrl": "https://github.com/fork/craft2yml/archive/1.0.1.zip", 23 | "date": "2017-05-24T10:37:41.431Z", 24 | "notes": [ 25 | "[Improved] No need for yaml pecl extension anymore, use symfony yaml package instead." 26 | ] 27 | } 28 | ] -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Fork Unstable Media GmbH 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2004-2017 Fabien Potencier 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /craft2yml/vendor/composer/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) Nils Adermann, Jordi Boggiano 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is furnished 9 | to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | 22 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/Fixtures/YtsBlockMapping.yml: -------------------------------------------------------------------------------- 1 | --- 2 | test: One Element Mapping 3 | brief: | 4 | A mapping with one key/value pair 5 | yaml: | 6 | foo: bar 7 | php: | 8 | array('foo' => 'bar') 9 | --- 10 | test: Multi Element Mapping 11 | brief: | 12 | More than one key/value pair 13 | yaml: | 14 | red: baron 15 | white: walls 16 | blue: berries 17 | php: | 18 | array( 19 | 'red' => 'baron', 20 | 'white' => 'walls', 21 | 'blue' => 'berries', 22 | ) 23 | --- 24 | test: Values aligned 25 | brief: | 26 | Often times human editors of documents will align the values even 27 | though YAML emitters generally don't. 28 | yaml: | 29 | red: baron 30 | white: walls 31 | blue: berries 32 | php: | 33 | array( 34 | 'red' => 'baron', 35 | 'white' => 'walls', 36 | 'blue' => 'berries', 37 | ) 38 | --- 39 | test: Colons aligned 40 | brief: | 41 | Spaces can come before the ': ' key/value separator. 42 | yaml: | 43 | red : baron 44 | white : walls 45 | blue : berries 46 | php: | 47 | array( 48 | 'red' => 'baron', 49 | 'white' => 'walls', 50 | 'blue' => 'berries', 51 | ) 52 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/ParseExceptionTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Symfony\Component\Yaml\Tests; 13 | 14 | use PHPUnit\Framework\TestCase; 15 | use Symfony\Component\Yaml\Exception\ParseException; 16 | 17 | class ParseExceptionTest extends TestCase 18 | { 19 | public function testGetMessage() 20 | { 21 | $exception = new ParseException('Error message', 42, 'foo: bar', '/var/www/app/config.yml'); 22 | if (PHP_VERSION_ID >= 50400) { 23 | $message = 'Error message in "/var/www/app/config.yml" at line 42 (near "foo: bar")'; 24 | } else { 25 | $message = 'Error message in "\\/var\\/www\\/app\\/config.yml" at line 42 (near "foo: bar")'; 26 | } 27 | 28 | $this->assertEquals($message, $exception->getMessage()); 29 | } 30 | 31 | public function testGetMessageWithUnicodeInFilename() 32 | { 33 | $exception = new ParseException('Error message', 42, 'foo: bar', 'äöü.yml'); 34 | if (PHP_VERSION_ID >= 50400) { 35 | $message = 'Error message in "äöü.yml" at line 42 (near "foo: bar")'; 36 | } else { 37 | $message = 'Error message in "\u00e4\u00f6\u00fc.yml" at line 42 (near "foo: bar")'; 38 | } 39 | 40 | $this->assertEquals($message, $exception->getMessage()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /craft2yml/vendor/composer/installed.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "symfony/yaml", 4 | "version": "v2.8.20", 5 | "version_normalized": "2.8.20.0", 6 | "source": { 7 | "type": "git", 8 | "url": "https://github.com/symfony/yaml.git", 9 | "reference": "93ccdde79f4b079c7558da4656a3cb1c50c68e02" 10 | }, 11 | "dist": { 12 | "type": "zip", 13 | "url": "https://api.github.com/repos/symfony/yaml/zipball/93ccdde79f4b079c7558da4656a3cb1c50c68e02", 14 | "reference": "93ccdde79f4b079c7558da4656a3cb1c50c68e02", 15 | "shasum": "" 16 | }, 17 | "require": { 18 | "php": ">=5.3.9" 19 | }, 20 | "time": "2017-05-01T14:31:55+00:00", 21 | "type": "library", 22 | "extra": { 23 | "branch-alias": { 24 | "dev-master": "2.8-dev" 25 | } 26 | }, 27 | "installation-source": "dist", 28 | "autoload": { 29 | "psr-4": { 30 | "Symfony\\Component\\Yaml\\": "" 31 | }, 32 | "exclude-from-classmap": [ 33 | "/Tests/" 34 | ] 35 | }, 36 | "notification-url": "https://packagist.org/downloads/", 37 | "license": [ 38 | "MIT" 39 | ], 40 | "authors": [ 41 | { 42 | "name": "Fabien Potencier", 43 | "email": "fabien@symfony.com" 44 | }, 45 | { 46 | "name": "Symfony Community", 47 | "homepage": "https://symfony.com/contributors" 48 | } 49 | ], 50 | "description": "Symfony Yaml Component", 51 | "homepage": "https://symfony.com" 52 | } 53 | ] 54 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/YamlTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Symfony\Component\Yaml\Tests; 13 | 14 | use PHPUnit\Framework\TestCase; 15 | use Symfony\Component\Yaml\Yaml; 16 | 17 | class YamlTest extends TestCase 18 | { 19 | public function testParseAndDump() 20 | { 21 | $data = array('lorem' => 'ipsum', 'dolor' => 'sit'); 22 | $yml = Yaml::dump($data); 23 | $parsed = Yaml::parse($yml); 24 | $this->assertEquals($data, $parsed); 25 | } 26 | 27 | /** 28 | * @group legacy 29 | */ 30 | public function testLegacyParseFromFile() 31 | { 32 | $filename = __DIR__.'/Fixtures/index.yml'; 33 | $contents = file_get_contents($filename); 34 | $parsedByFilename = Yaml::parse($filename); 35 | $parsedByContents = Yaml::parse($contents); 36 | $this->assertEquals($parsedByFilename, $parsedByContents); 37 | } 38 | 39 | /** 40 | * @expectedException \InvalidArgumentException 41 | * @expectedExceptionMessage The indentation must be greater than zero 42 | */ 43 | public function testZeroIndentationThrowsException() 44 | { 45 | Yaml::dump(array('lorem' => 'ipsum', 'dolor' => 'sit'), 2, 0); 46 | } 47 | 48 | /** 49 | * @expectedException \InvalidArgumentException 50 | * @expectedExceptionMessage The indentation must be greater than zero 51 | */ 52 | public function testNegativeIndentationThrowsException() 53 | { 54 | Yaml::dump(array('lorem' => 'ipsum', 'dolor' => 'sit'), 2, -4); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/Fixtures/YtsFlowCollections.yml: -------------------------------------------------------------------------------- 1 | --- 2 | test: Simple Inline Array 3 | brief: > 4 | Sequences can be contained on a 5 | single line, using the inline syntax. 6 | Separate each entry with commas and 7 | enclose in square brackets. 8 | yaml: | 9 | seq: [ a, b, c ] 10 | php: | 11 | array('seq' => array('a', 'b', 'c')) 12 | --- 13 | test: Simple Inline Hash 14 | brief: > 15 | Mapping can also be contained on 16 | a single line, using the inline 17 | syntax. Each key-value pair is 18 | separated by a colon, with a comma 19 | between each entry in the mapping. 20 | Enclose with curly braces. 21 | yaml: | 22 | hash: { name: Steve, foo: bar } 23 | php: | 24 | array('hash' => array('name' => 'Steve', 'foo' => 'bar')) 25 | --- 26 | test: Multi-line Inline Collections 27 | todo: true 28 | brief: > 29 | Both inline sequences and inline mappings 30 | can span multiple lines, provided that you 31 | indent the additional lines. 32 | yaml: | 33 | languages: [ Ruby, 34 | Perl, 35 | Python ] 36 | websites: { YAML: yaml.org, 37 | Ruby: ruby-lang.org, 38 | Python: python.org, 39 | Perl: use.perl.org } 40 | php: | 41 | array( 42 | 'languages' => array('Ruby', 'Perl', 'Python'), 43 | 'websites' => array( 44 | 'YAML' => 'yaml.org', 45 | 'Ruby' => 'ruby-lang.org', 46 | 'Python' => 'python.org', 47 | 'Perl' => 'use.perl.org' 48 | ) 49 | ) 50 | --- 51 | test: Commas in Values (not in the spec!) 52 | todo: true 53 | brief: > 54 | List items in collections are delimited by commas, but 55 | there must be a space after each comma. This allows you 56 | to add numbers without quoting. 57 | yaml: | 58 | attendances: [ 45,123, 70,000, 17,222 ] 59 | php: | 60 | array('attendances' => array(45123, 70000, 17222)) 61 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/Fixtures/YtsDocumentSeparator.yml: -------------------------------------------------------------------------------- 1 | --- %YAML:1.0 2 | test: Trailing Document Separator 3 | todo: true 4 | brief: > 5 | You can separate YAML documents 6 | with a string of three dashes. 7 | yaml: | 8 | - foo: 1 9 | bar: 2 10 | --- 11 | more: stuff 12 | python: | 13 | [ 14 | [ { 'foo': 1, 'bar': 2 } ], 15 | { 'more': 'stuff' } 16 | ] 17 | ruby: | 18 | [ { 'foo' => 1, 'bar' => 2 } ] 19 | 20 | --- 21 | test: Leading Document Separator 22 | todo: true 23 | brief: > 24 | You can explicitly give an opening 25 | document separator to your YAML stream. 26 | yaml: | 27 | --- 28 | - foo: 1 29 | bar: 2 30 | --- 31 | more: stuff 32 | python: | 33 | [ 34 | [ {'foo': 1, 'bar': 2}], 35 | {'more': 'stuff'} 36 | ] 37 | ruby: | 38 | [ { 'foo' => 1, 'bar' => 2 } ] 39 | 40 | --- 41 | test: YAML Header 42 | todo: true 43 | brief: > 44 | The opening separator can contain directives 45 | to the YAML parser, such as the version 46 | number. 47 | yaml: | 48 | --- %YAML:1.0 49 | foo: 1 50 | bar: 2 51 | php: | 52 | array('foo' => 1, 'bar' => 2) 53 | documents: 1 54 | 55 | --- 56 | test: Red Herring Document Separator 57 | brief: > 58 | Separators included in blocks or strings 59 | are treated as blocks or strings, as the 60 | document separator should have no indentation 61 | preceding it. 62 | yaml: | 63 | foo: | 64 | --- 65 | php: | 66 | array('foo' => "---\n") 67 | 68 | --- 69 | test: Multiple Document Separators in Block 70 | brief: > 71 | This technique allows you to embed other YAML 72 | documents within literal blocks. 73 | yaml: | 74 | foo: | 75 | --- 76 | foo: bar 77 | --- 78 | yo: baz 79 | bar: | 80 | fooness 81 | php: | 82 | array( 83 | 'foo' => "---\nfoo: bar\n---\nyo: baz\n", 84 | 'bar' => "fooness\n" 85 | ) 86 | -------------------------------------------------------------------------------- /craft2yml/vendor/composer/autoload_real.php: -------------------------------------------------------------------------------- 1 | = 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); 27 | if ($useStaticLoader) { 28 | require_once __DIR__ . '/autoload_static.php'; 29 | 30 | call_user_func(\Composer\Autoload\ComposerStaticInit302d294513c4427a12f72ed5e81e0e93::getInitializer($loader)); 31 | } else { 32 | $map = require __DIR__ . '/autoload_namespaces.php'; 33 | foreach ($map as $namespace => $path) { 34 | $loader->set($namespace, $path); 35 | } 36 | 37 | $map = require __DIR__ . '/autoload_psr4.php'; 38 | foreach ($map as $namespace => $path) { 39 | $loader->setPsr4($namespace, $path); 40 | } 41 | 42 | $classMap = require __DIR__ . '/autoload_classmap.php'; 43 | if ($classMap) { 44 | $loader->addClassMap($classMap); 45 | } 46 | } 47 | 48 | $loader->register(true); 49 | 50 | return $loader; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/Fixtures/sfComments.yml: -------------------------------------------------------------------------------- 1 | --- %YAML:1.0 2 | test: Comments at the end of a line 3 | brief: > 4 | Comments at the end of a line 5 | yaml: | 6 | ex1: "foo # bar" 7 | ex2: "foo # bar" # comment 8 | ex3: 'foo # bar' # comment 9 | ex4: foo # comment 10 | ex5: foo # comment with tab before 11 | ex6: foo#foo # comment here 12 | ex7: foo # ignore me # and me 13 | php: | 14 | array('ex1' => 'foo # bar', 'ex2' => 'foo # bar', 'ex3' => 'foo # bar', 'ex4' => 'foo', 'ex5' => 'foo', 'ex6' => 'foo#foo', 'ex7' => 'foo') 15 | --- 16 | test: Comments in the middle 17 | brief: > 18 | Comments in the middle 19 | yaml: | 20 | foo: 21 | # some comment 22 | # some comment 23 | bar: foo 24 | # some comment 25 | # some comment 26 | php: | 27 | array('foo' => array('bar' => 'foo')) 28 | --- 29 | test: Comments on a hash line 30 | brief: > 31 | Comments on a hash line 32 | yaml: | 33 | foo: # a comment 34 | foo: bar # a comment 35 | php: | 36 | array('foo' => array('foo' => 'bar')) 37 | --- 38 | test: 'Value starting with a #' 39 | brief: > 40 | 'Value starting with a #' 41 | yaml: | 42 | foo: '#bar' 43 | php: | 44 | array('foo' => '#bar') 45 | --- 46 | test: Document starting with a comment and a separator 47 | brief: > 48 | Commenting before document start is allowed 49 | yaml: | 50 | # document comment 51 | --- 52 | foo: bar # a comment 53 | php: | 54 | array('foo' => 'bar') 55 | --- 56 | test: Comment containing a colon on a hash line 57 | brief: > 58 | Comment containing a colon on a scalar line 59 | yaml: 'foo # comment: this is also part of the comment' 60 | php: | 61 | 'foo' 62 | --- 63 | test: 'Hash key containing a #' 64 | brief: > 65 | 'Hash key containing a #' 66 | yaml: 'foo#bar: baz' 67 | php: | 68 | array('foo#bar' => 'baz') 69 | --- 70 | test: 'Hash key ending with a space and a #' 71 | brief: > 72 | 'Hash key ending with a space and a #' 73 | yaml: | 74 | 'foo #': baz 75 | php: | 76 | array('foo #' => 'baz') 77 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/Fixtures/sfMergeKey.yml: -------------------------------------------------------------------------------- 1 | --- %YAML:1.0 2 | test: Simple In Place Substitution 3 | brief: > 4 | If you want to reuse an entire alias, only overwriting what is different 5 | you can use a << in place substitution. This is not part of the official 6 | YAML spec, but a widely implemented extension. See the following URL for 7 | details: http://yaml.org/type/merge.html 8 | yaml: | 9 | foo: &foo 10 | a: Steve 11 | b: Clark 12 | c: Brian 13 | e: notnull 14 | bar: 15 | a: before 16 | d: other 17 | e: ~ 18 | <<: *foo 19 | b: new 20 | x: Oren 21 | c: 22 | foo: bar 23 | foo: ignore 24 | bar: foo 25 | duplicate: 26 | foo: bar 27 | foo: ignore 28 | foo2: &foo2 29 | a: Ballmer 30 | ding: &dong [ fi, fei, fo, fam] 31 | check: 32 | <<: 33 | - *foo 34 | - *dong 35 | isit: tested 36 | head: 37 | <<: [ *foo , *dong , *foo2 ] 38 | taz: &taz 39 | a: Steve 40 | w: 41 | p: 1234 42 | nested: 43 | <<: *taz 44 | d: Doug 45 | w: &nestedref 46 | p: 12345 47 | z: 48 | <<: *nestedref 49 | php: | 50 | array( 51 | 'foo' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'e' => 'notnull'), 52 | 'bar' => array('a' => 'before', 'd' => 'other', 'e' => null, 'b' => 'new', 'c' => array('foo' => 'bar', 'bar' => 'foo'), 'x' => 'Oren'), 53 | 'duplicate' => array('foo' => 'bar'), 54 | 'foo2' => array('a' => 'Ballmer'), 55 | 'ding' => array('fi', 'fei', 'fo', 'fam'), 56 | 'check' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'e' => 'notnull', 'fi', 'fei', 'fo', 'fam', 'isit' => 'tested'), 57 | 'head' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'e' => 'notnull', 'fi', 'fei', 'fo', 'fam'), 58 | 'taz' => array('a' => 'Steve', 'w' => array('p' => 1234)), 59 | 'nested' => array('a' => 'Steve', 'w' => array('p' => 12345), 'd' => 'Doug', 'z' => array('p' => 12345)) 60 | ) 61 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/Fixtures/unindentedCollections.yml: -------------------------------------------------------------------------------- 1 | --- %YAML:1.0 2 | test: Unindented collection 3 | brief: > 4 | Unindented collection 5 | yaml: | 6 | collection: 7 | - item1 8 | - item2 9 | - item3 10 | php: | 11 | array('collection' => array('item1', 'item2', 'item3')) 12 | --- 13 | test: Nested unindented collection (two levels) 14 | brief: > 15 | Nested unindented collection 16 | yaml: | 17 | collection: 18 | key: 19 | - a 20 | - b 21 | - c 22 | php: | 23 | array('collection' => array('key' => array('a', 'b', 'c'))) 24 | --- 25 | test: Nested unindented collection (three levels) 26 | brief: > 27 | Nested unindented collection 28 | yaml: | 29 | collection: 30 | key: 31 | subkey: 32 | - one 33 | - two 34 | - three 35 | php: | 36 | array('collection' => array('key' => array('subkey' => array('one', 'two', 'three')))) 37 | --- 38 | test: Key/value after unindented collection (1) 39 | brief: > 40 | Key/value after unindented collection (1) 41 | yaml: | 42 | collection: 43 | key: 44 | - a 45 | - b 46 | - c 47 | foo: bar 48 | php: | 49 | array('collection' => array('key' => array('a', 'b', 'c')), 'foo' => 'bar') 50 | --- 51 | test: Key/value after unindented collection (at the same level) 52 | brief: > 53 | Key/value after unindented collection 54 | yaml: | 55 | collection: 56 | key: 57 | - a 58 | - b 59 | - c 60 | foo: bar 61 | php: | 62 | array('collection' => array('key' => array('a', 'b', 'c'), 'foo' => 'bar')) 63 | --- 64 | test: Shortcut Key after unindented collection 65 | brief: > 66 | Key/value after unindented collection 67 | yaml: | 68 | collection: 69 | - key: foo 70 | foo: bar 71 | php: | 72 | array('collection' => array(array('key' => 'foo', 'foo' => 'bar'))) 73 | --- 74 | test: Shortcut Key after unindented collection with custom spaces 75 | brief: > 76 | Key/value after unindented collection 77 | yaml: | 78 | collection: 79 | - key: foo 80 | foo: bar 81 | php: | 82 | array('collection' => array(array('key' => 'foo', 'foo' => 'bar'))) 83 | -------------------------------------------------------------------------------- /craft2yml/composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "688d8cf350329c0a36fe470e54e8ae62", 8 | "packages": [ 9 | { 10 | "name": "symfony/yaml", 11 | "version": "v2.8.20", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/symfony/yaml.git", 15 | "reference": "93ccdde79f4b079c7558da4656a3cb1c50c68e02" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/symfony/yaml/zipball/93ccdde79f4b079c7558da4656a3cb1c50c68e02", 20 | "reference": "93ccdde79f4b079c7558da4656a3cb1c50c68e02", 21 | "shasum": "" 22 | }, 23 | "require": { 24 | "php": ">=5.3.9" 25 | }, 26 | "type": "library", 27 | "extra": { 28 | "branch-alias": { 29 | "dev-master": "2.8-dev" 30 | } 31 | }, 32 | "autoload": { 33 | "psr-4": { 34 | "Symfony\\Component\\Yaml\\": "" 35 | }, 36 | "exclude-from-classmap": [ 37 | "/Tests/" 38 | ] 39 | }, 40 | "notification-url": "https://packagist.org/downloads/", 41 | "license": [ 42 | "MIT" 43 | ], 44 | "authors": [ 45 | { 46 | "name": "Fabien Potencier", 47 | "email": "fabien@symfony.com" 48 | }, 49 | { 50 | "name": "Symfony Community", 51 | "homepage": "https://symfony.com/contributors" 52 | } 53 | ], 54 | "description": "Symfony Yaml Component", 55 | "homepage": "https://symfony.com", 56 | "time": "2017-05-01T14:31:55+00:00" 57 | } 58 | ], 59 | "packages-dev": [], 60 | "aliases": [], 61 | "minimum-stability": "stable", 62 | "stability-flags": [], 63 | "prefer-stable": false, 64 | "prefer-lowest": false, 65 | "platform": [], 66 | "platform-dev": [] 67 | } 68 | -------------------------------------------------------------------------------- /craft2yml/services/Craft2ymlService.php: -------------------------------------------------------------------------------- 1 | globals->getAllSets(); 19 | /** @var GlobalSetModel $globalSet */ 20 | foreach ($globalSets as $globalSet) { 21 | $globalsContent[$globalSet->handle] = $this->getFieldData($globalSet); 22 | } 23 | $ymlContent = array_merge($ymlContent, $globalsContent); 24 | 25 | // entry data 26 | $entry = craft()->entries->getEntryById($entryId); 27 | $content = array('entry' => $this->getFieldData($entry)); 28 | 29 | $ymlContent = array_merge($ymlContent, $content); 30 | 31 | // build yaml 32 | $inlineLimit = craft()->config->get('inlineLimit', 'craft2yml'); 33 | return Yaml::dump($ymlContent, $inlineLimit, 2); 34 | } 35 | 36 | // TODO: handle more field types (date, table...) 37 | /** 38 | * @param mixed $element 39 | * @return array 40 | */ 41 | private function getFieldData($element) { 42 | $layout = $element->getFieldLayout(); 43 | $fields = $layout->getFields(); 44 | 45 | $content = array(); 46 | /** @var FieldLayoutFieldModel $fieldLayout */ 47 | foreach ($fields as $fieldLayout) { 48 | /** @var FieldModel $field */ 49 | $field = $fieldLayout->getField(); 50 | if ($field->type == 'Assets') { 51 | $asset = $element->getFieldValue($field->handle)->first(); 52 | $content[$field->handle] = $asset->getUrl(); 53 | } elseif ($field->type == 'Matrix' || $field->type == 'Neo') { 54 | /** @var MatrixBlockModel $matrixBlock */ 55 | $matrixBlock = $element->getFieldValue($field->handle); 56 | /** @var MatrixBlockModel $item */ 57 | foreach ($matrixBlock->getChildren() as $item) { 58 | $content[$field->handle][] = array_merge(array('type' => $item->getType()->handle), $this->getFieldData($item)); 59 | } 60 | } else if ($field->type == 'Entries' || $field->type == 'Categories' || $field->type == 'Tags') { 61 | $entries = $element->getFieldValue($field->handle); 62 | foreach ($entries->find() as $entry) { 63 | $content[$field->handle][] = array( 64 | 'title' => $entry->title, 65 | 'uri' => $entry->uri 66 | ); 67 | } 68 | } else { 69 | $content[$field->handle] = $element->getContent()->getAttribute($field->handle); 70 | } 71 | } 72 | 73 | return $content; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Dumper.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Symfony\Component\Yaml; 13 | 14 | /** 15 | * Dumper dumps PHP variables to YAML strings. 16 | * 17 | * @author Fabien Potencier 18 | */ 19 | class Dumper 20 | { 21 | /** 22 | * The amount of spaces to use for indentation of nested nodes. 23 | * 24 | * @var int 25 | */ 26 | protected $indentation = 4; 27 | 28 | /** 29 | * Sets the indentation. 30 | * 31 | * @param int $num The amount of spaces to use for indentation of nested nodes 32 | */ 33 | public function setIndentation($num) 34 | { 35 | if ($num < 1) { 36 | throw new \InvalidArgumentException('The indentation must be greater than zero.'); 37 | } 38 | 39 | $this->indentation = (int) $num; 40 | } 41 | 42 | /** 43 | * Dumps a PHP value to YAML. 44 | * 45 | * @param mixed $input The PHP value 46 | * @param int $inline The level where you switch to inline YAML 47 | * @param int $indent The level of indentation (used internally) 48 | * @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise 49 | * @param bool $objectSupport true if object support is enabled, false otherwise 50 | * 51 | * @return string The YAML representation of the PHP value 52 | */ 53 | public function dump($input, $inline = 0, $indent = 0, $exceptionOnInvalidType = false, $objectSupport = false) 54 | { 55 | $output = ''; 56 | $prefix = $indent ? str_repeat(' ', $indent) : ''; 57 | 58 | if ($inline <= 0 || !is_array($input) || empty($input)) { 59 | $output .= $prefix.Inline::dump($input, $exceptionOnInvalidType, $objectSupport); 60 | } else { 61 | $isAHash = Inline::isHash($input); 62 | 63 | foreach ($input as $key => $value) { 64 | $willBeInlined = $inline - 1 <= 0 || !is_array($value) || empty($value); 65 | 66 | $output .= sprintf('%s%s%s%s', 67 | $prefix, 68 | $isAHash ? Inline::dump($key, $exceptionOnInvalidType, $objectSupport).':' : '-', 69 | $willBeInlined ? ' ' : "\n", 70 | $this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + $this->indentation, $exceptionOnInvalidType, $objectSupport) 71 | ).($willBeInlined ? "\n" : ''); 72 | } 73 | } 74 | 75 | return $output; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/Fixtures/escapedCharacters.yml: -------------------------------------------------------------------------------- 1 | test: outside double quotes 2 | yaml: | 3 | \0 \ \a \b \n 4 | php: | 5 | "\\0 \\ \\a \\b \\n" 6 | --- 7 | test: null 8 | yaml: | 9 | "\0" 10 | php: | 11 | "\x00" 12 | --- 13 | test: bell 14 | yaml: | 15 | "\a" 16 | php: | 17 | "\x07" 18 | --- 19 | test: backspace 20 | yaml: | 21 | "\b" 22 | php: | 23 | "\x08" 24 | --- 25 | test: horizontal tab (1) 26 | yaml: | 27 | "\t" 28 | php: | 29 | "\x09" 30 | --- 31 | test: horizontal tab (2) 32 | yaml: | 33 | "\ " 34 | php: | 35 | "\x09" 36 | --- 37 | test: line feed 38 | yaml: | 39 | "\n" 40 | php: | 41 | "\x0a" 42 | --- 43 | test: vertical tab 44 | yaml: | 45 | "\v" 46 | php: | 47 | "\x0b" 48 | --- 49 | test: form feed 50 | yaml: | 51 | "\f" 52 | php: | 53 | "\x0c" 54 | --- 55 | test: carriage return 56 | yaml: | 57 | "\r" 58 | php: | 59 | "\x0d" 60 | --- 61 | test: escape 62 | yaml: | 63 | "\e" 64 | php: | 65 | "\x1b" 66 | --- 67 | test: space 68 | yaml: | 69 | "\ " 70 | php: | 71 | "\x20" 72 | --- 73 | test: slash 74 | yaml: | 75 | "\/" 76 | php: | 77 | "\x2f" 78 | --- 79 | test: backslash 80 | yaml: | 81 | "\\" 82 | php: | 83 | "\\" 84 | --- 85 | test: Unicode next line 86 | yaml: | 87 | "\N" 88 | php: | 89 | "\xc2\x85" 90 | --- 91 | test: Unicode non-breaking space 92 | yaml: | 93 | "\_" 94 | php: | 95 | "\xc2\xa0" 96 | --- 97 | test: Unicode line separator 98 | yaml: | 99 | "\L" 100 | php: | 101 | "\xe2\x80\xa8" 102 | --- 103 | test: Unicode paragraph separator 104 | yaml: | 105 | "\P" 106 | php: | 107 | "\xe2\x80\xa9" 108 | --- 109 | test: Escaped 8-bit Unicode 110 | yaml: | 111 | "\x42" 112 | php: | 113 | "B" 114 | --- 115 | test: Escaped 16-bit Unicode 116 | yaml: | 117 | "\u20ac" 118 | php: | 119 | "\xe2\x82\xac" 120 | --- 121 | test: Escaped 32-bit Unicode 122 | yaml: | 123 | "\U00000043" 124 | php: | 125 | "C" 126 | --- 127 | test: Example 5.13 Escaped Characters 128 | note: | 129 | Currently throws an error parsing first line. Maybe Symfony Yaml doesn't support 130 | continuation of string across multiple lines? Keeping test here but disabled. 131 | todo: true 132 | yaml: | 133 | "Fun with \\ 134 | \" \a \b \e \f \ 135 | \n \r \t \v \0 \ 136 | \ \_ \N \L \P \ 137 | \x41 \u0041 \U00000041" 138 | php: | 139 | "Fun with \x5C\n\x22 \x07 \x08 \x1B \x0C\n\x0A \x0D \x09 \x0B \x00\n\x20 \xA0 \x85 \xe2\x80\xa8 \xe2\x80\xa9\nA A A" 140 | --- 141 | test: Double quotes with a line feed 142 | yaml: | 143 | { double: "some value\n \"some quoted string\" and 'some single quotes one'" } 144 | php: | 145 | array( 146 | 'double' => "some value\n \"some quoted string\" and 'some single quotes one'" 147 | ) 148 | --- 149 | test: Backslashes 150 | yaml: | 151 | { single: 'foo\Var', no-quotes: foo\Var, double: "foo\\Var" } 152 | php: | 153 | array( 154 | 'single' => 'foo\Var', 'no-quotes' => 'foo\Var', 'double' => 'foo\Var' 155 | ) 156 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/Fixtures/sfTests.yml: -------------------------------------------------------------------------------- 1 | --- %YAML:1.0 2 | test: Multiple quoted string on one line 3 | brief: > 4 | Multiple quoted string on one line 5 | yaml: | 6 | stripped_title: { name: "foo bar", help: "bar foo" } 7 | php: | 8 | array('stripped_title' => array('name' => 'foo bar', 'help' => 'bar foo')) 9 | --- 10 | test: Empty sequence 11 | yaml: | 12 | foo: [ ] 13 | php: | 14 | array('foo' => array()) 15 | --- 16 | test: Empty value 17 | yaml: | 18 | foo: 19 | php: | 20 | array('foo' => null) 21 | --- 22 | test: Inline string parsing 23 | brief: > 24 | Inline string parsing 25 | yaml: | 26 | test: ['complex: string', 'another [string]'] 27 | php: | 28 | array('test' => array('complex: string', 'another [string]')) 29 | --- 30 | test: Boolean 31 | brief: > 32 | Boolean 33 | yaml: | 34 | - false 35 | - true 36 | - null 37 | - ~ 38 | - 'false' 39 | - 'true' 40 | - 'null' 41 | - '~' 42 | php: | 43 | array( 44 | false, 45 | true, 46 | null, 47 | null, 48 | 'false', 49 | 'true', 50 | 'null', 51 | '~', 52 | ) 53 | --- 54 | test: Empty lines in literal blocks 55 | brief: > 56 | Empty lines in literal blocks 57 | yaml: | 58 | foo: 59 | bar: | 60 | foo 61 | 62 | 63 | 64 | bar 65 | php: | 66 | array('foo' => array('bar' => "foo\n\n\n \nbar\n")) 67 | --- 68 | test: Empty lines in folded blocks 69 | brief: > 70 | Empty lines in folded blocks 71 | yaml: | 72 | foo: 73 | bar: > 74 | 75 | foo 76 | 77 | 78 | bar 79 | php: | 80 | array('foo' => array('bar' => "\nfoo\n\nbar\n")) 81 | --- 82 | test: IP addresses 83 | brief: > 84 | IP addresses 85 | yaml: | 86 | foo: 10.0.0.2 87 | php: | 88 | array('foo' => '10.0.0.2') 89 | --- 90 | test: A sequence with an embedded mapping 91 | brief: > 92 | A sequence with an embedded mapping 93 | yaml: | 94 | - foo 95 | - bar: { bar: foo } 96 | php: | 97 | array('foo', array('bar' => array('bar' => 'foo'))) 98 | --- 99 | test: A sequence with an unordered array 100 | brief: > 101 | A sequence with an unordered array 102 | yaml: | 103 | 1: foo 104 | 0: bar 105 | php: | 106 | array(1 => 'foo', 0 => 'bar') 107 | --- 108 | test: Octal 109 | brief: as in spec example 2.19, octal value is converted 110 | yaml: | 111 | foo: 0123 112 | php: | 113 | array('foo' => 83) 114 | --- 115 | test: Octal strings 116 | brief: Octal notation in a string must remain a string 117 | yaml: | 118 | foo: "0123" 119 | php: | 120 | array('foo' => '0123') 121 | --- 122 | test: Octal strings 123 | brief: Octal notation in a string must remain a string 124 | yaml: | 125 | foo: '0123' 126 | php: | 127 | array('foo' => '0123') 128 | --- 129 | test: Octal strings 130 | brief: Octal notation in a string must remain a string 131 | yaml: | 132 | foo: | 133 | 0123 134 | php: | 135 | array('foo' => "0123\n") 136 | --- 137 | test: Document as a simple hash 138 | brief: Document as a simple hash 139 | yaml: | 140 | { foo: bar } 141 | php: | 142 | array('foo' => 'bar') 143 | --- 144 | test: Document as a simple array 145 | brief: Document as a simple array 146 | yaml: | 147 | [ foo, bar ] 148 | php: | 149 | array('foo', 'bar') 150 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/Fixtures/sfCompact.yml: -------------------------------------------------------------------------------- 1 | --- %YAML:1.0 2 | test: Compact notation 3 | brief: | 4 | Compact notation for sets of mappings with single element 5 | yaml: | 6 | --- 7 | # products purchased 8 | - item : Super Hoop 9 | - item : Basketball 10 | quantity: 1 11 | - item: 12 | name: Big Shoes 13 | nick: Biggies 14 | quantity: 1 15 | php: | 16 | array ( 17 | array ( 18 | 'item' => 'Super Hoop', 19 | ), 20 | array ( 21 | 'item' => 'Basketball', 22 | 'quantity' => 1, 23 | ), 24 | array ( 25 | 'item' => array( 26 | 'name' => 'Big Shoes', 27 | 'nick' => 'Biggies' 28 | ), 29 | 'quantity' => 1 30 | ) 31 | ) 32 | --- 33 | test: Compact notation combined with inline notation 34 | brief: | 35 | Combinations of compact and inline notation are allowed 36 | yaml: | 37 | --- 38 | items: 39 | - { item: Super Hoop, quantity: 1 } 40 | - [ Basketball, Big Shoes ] 41 | php: | 42 | array ( 43 | 'items' => array ( 44 | array ( 45 | 'item' => 'Super Hoop', 46 | 'quantity' => 1, 47 | ), 48 | array ( 49 | 'Basketball', 50 | 'Big Shoes' 51 | ) 52 | ) 53 | ) 54 | --- %YAML:1.0 55 | test: Compact notation 56 | brief: | 57 | Compact notation for sets of mappings with single element 58 | yaml: | 59 | --- 60 | # products purchased 61 | - item : Super Hoop 62 | - item : Basketball 63 | quantity: 1 64 | - item: 65 | name: Big Shoes 66 | nick: Biggies 67 | quantity: 1 68 | php: | 69 | array ( 70 | array ( 71 | 'item' => 'Super Hoop', 72 | ), 73 | array ( 74 | 'item' => 'Basketball', 75 | 'quantity' => 1, 76 | ), 77 | array ( 78 | 'item' => array( 79 | 'name' => 'Big Shoes', 80 | 'nick' => 'Biggies' 81 | ), 82 | 'quantity' => 1 83 | ) 84 | ) 85 | --- 86 | test: Compact notation combined with inline notation 87 | brief: | 88 | Combinations of compact and inline notation are allowed 89 | yaml: | 90 | --- 91 | items: 92 | - { item: Super Hoop, quantity: 1 } 93 | - [ Basketball, Big Shoes ] 94 | php: | 95 | array ( 96 | 'items' => array ( 97 | array ( 98 | 'item' => 'Super Hoop', 99 | 'quantity' => 1, 100 | ), 101 | array ( 102 | 'Basketball', 103 | 'Big Shoes' 104 | ) 105 | ) 106 | ) 107 | --- %YAML:1.0 108 | test: Compact notation 109 | brief: | 110 | Compact notation for sets of mappings with single element 111 | yaml: | 112 | --- 113 | # products purchased 114 | - item : Super Hoop 115 | - item : Basketball 116 | quantity: 1 117 | - item: 118 | name: Big Shoes 119 | nick: Biggies 120 | quantity: 1 121 | php: | 122 | array ( 123 | array ( 124 | 'item' => 'Super Hoop', 125 | ), 126 | array ( 127 | 'item' => 'Basketball', 128 | 'quantity' => 1, 129 | ), 130 | array ( 131 | 'item' => array( 132 | 'name' => 'Big Shoes', 133 | 'nick' => 'Biggies' 134 | ), 135 | 'quantity' => 1 136 | ) 137 | ) 138 | --- 139 | test: Compact notation combined with inline notation 140 | brief: | 141 | Combinations of compact and inline notation are allowed 142 | yaml: | 143 | --- 144 | items: 145 | - { item: Super Hoop, quantity: 1 } 146 | - [ Basketball, Big Shoes ] 147 | php: | 148 | array ( 149 | 'items' => array ( 150 | array ( 151 | 'item' => 'Super Hoop', 152 | 'quantity' => 1, 153 | ), 154 | array ( 155 | 'Basketball', 156 | 'Big Shoes' 157 | ) 158 | ) 159 | ) 160 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Yaml.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Symfony\Component\Yaml; 13 | 14 | use Symfony\Component\Yaml\Exception\ParseException; 15 | 16 | /** 17 | * Yaml offers convenience methods to load and dump YAML. 18 | * 19 | * @author Fabien Potencier 20 | */ 21 | class Yaml 22 | { 23 | /** 24 | * Parses YAML into a PHP value. 25 | * 26 | * Usage: 27 | * 28 | * $array = Yaml::parse(file_get_contents('config.yml')); 29 | * print_r($array); 30 | * 31 | * 32 | * As this method accepts both plain strings and file names as an input, 33 | * you must validate the input before calling this method. Passing a file 34 | * as an input is a deprecated feature and will be removed in 3.0. 35 | * 36 | * Note: the ability to pass file names to the Yaml::parse method is deprecated since version 2.2 and will be removed in 3.0. Pass the YAML contents of the file instead. 37 | * 38 | * @param string $input Path to a YAML file or a string containing YAML 39 | * @param bool $exceptionOnInvalidType True if an exception must be thrown on invalid types false otherwise 40 | * @param bool $objectSupport True if object support is enabled, false otherwise 41 | * @param bool $objectForMap True if maps should return a stdClass instead of array() 42 | * 43 | * @return mixed The YAML converted to a PHP value 44 | * 45 | * @throws ParseException If the YAML is not valid 46 | */ 47 | public static function parse($input, $exceptionOnInvalidType = false, $objectSupport = false, $objectForMap = false) 48 | { 49 | // if input is a file, process it 50 | $file = ''; 51 | if (strpos($input, "\n") === false && is_file($input)) { 52 | @trigger_error('The ability to pass file names to the '.__METHOD__.' method is deprecated since version 2.2 and will be removed in 3.0. Pass the YAML contents of the file instead.', E_USER_DEPRECATED); 53 | 54 | if (false === is_readable($input)) { 55 | throw new ParseException(sprintf('Unable to parse "%s" as the file is not readable.', $input)); 56 | } 57 | 58 | $file = $input; 59 | $input = file_get_contents($file); 60 | } 61 | 62 | $yaml = new Parser(); 63 | 64 | try { 65 | return $yaml->parse($input, $exceptionOnInvalidType, $objectSupport, $objectForMap); 66 | } catch (ParseException $e) { 67 | if ($file) { 68 | $e->setParsedFile($file); 69 | } 70 | 71 | throw $e; 72 | } 73 | } 74 | 75 | /** 76 | * Dumps a PHP value to a YAML string. 77 | * 78 | * The dump method, when supplied with an array, will do its best 79 | * to convert the array into friendly YAML. 80 | * 81 | * @param mixed $input The PHP value 82 | * @param int $inline The level where you switch to inline YAML 83 | * @param int $indent The amount of spaces to use for indentation of nested nodes 84 | * @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise 85 | * @param bool $objectSupport true if object support is enabled, false otherwise 86 | * 87 | * @return string A YAML string representing the original PHP value 88 | */ 89 | public static function dump($input, $inline = 2, $indent = 4, $exceptionOnInvalidType = false, $objectSupport = false) 90 | { 91 | if ($indent < 1) { 92 | throw new \InvalidArgumentException('The indentation must be greater than zero.'); 93 | } 94 | 95 | $yaml = new Dumper(); 96 | $yaml->setIndentation($indent); 97 | 98 | return $yaml->dump($input, $inline, 0, $exceptionOnInvalidType, $objectSupport); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Exception/ParseException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Symfony\Component\Yaml\Exception; 13 | 14 | /** 15 | * Exception class thrown when an error occurs during parsing. 16 | * 17 | * @author Fabien Potencier 18 | */ 19 | class ParseException extends RuntimeException 20 | { 21 | private $parsedFile; 22 | private $parsedLine; 23 | private $snippet; 24 | private $rawMessage; 25 | 26 | /** 27 | * Constructor. 28 | * 29 | * @param string $message The error message 30 | * @param int $parsedLine The line where the error occurred 31 | * @param string|null $snippet The snippet of code near the problem 32 | * @param string|null $parsedFile The file name where the error occurred 33 | * @param \Exception|null $previous The previous exception 34 | */ 35 | public function __construct($message, $parsedLine = -1, $snippet = null, $parsedFile = null, \Exception $previous = null) 36 | { 37 | $this->parsedFile = $parsedFile; 38 | $this->parsedLine = $parsedLine; 39 | $this->snippet = $snippet; 40 | $this->rawMessage = $message; 41 | 42 | $this->updateRepr(); 43 | 44 | parent::__construct($this->message, 0, $previous); 45 | } 46 | 47 | /** 48 | * Gets the snippet of code near the error. 49 | * 50 | * @return string The snippet of code 51 | */ 52 | public function getSnippet() 53 | { 54 | return $this->snippet; 55 | } 56 | 57 | /** 58 | * Sets the snippet of code near the error. 59 | * 60 | * @param string $snippet The code snippet 61 | */ 62 | public function setSnippet($snippet) 63 | { 64 | $this->snippet = $snippet; 65 | 66 | $this->updateRepr(); 67 | } 68 | 69 | /** 70 | * Gets the filename where the error occurred. 71 | * 72 | * This method returns null if a string is parsed. 73 | * 74 | * @return string The filename 75 | */ 76 | public function getParsedFile() 77 | { 78 | return $this->parsedFile; 79 | } 80 | 81 | /** 82 | * Sets the filename where the error occurred. 83 | * 84 | * @param string $parsedFile The filename 85 | */ 86 | public function setParsedFile($parsedFile) 87 | { 88 | $this->parsedFile = $parsedFile; 89 | 90 | $this->updateRepr(); 91 | } 92 | 93 | /** 94 | * Gets the line where the error occurred. 95 | * 96 | * @return int The file line 97 | */ 98 | public function getParsedLine() 99 | { 100 | return $this->parsedLine; 101 | } 102 | 103 | /** 104 | * Sets the line where the error occurred. 105 | * 106 | * @param int $parsedLine The file line 107 | */ 108 | public function setParsedLine($parsedLine) 109 | { 110 | $this->parsedLine = $parsedLine; 111 | 112 | $this->updateRepr(); 113 | } 114 | 115 | private function updateRepr() 116 | { 117 | $this->message = $this->rawMessage; 118 | 119 | $dot = false; 120 | if ('.' === substr($this->message, -1)) { 121 | $this->message = substr($this->message, 0, -1); 122 | $dot = true; 123 | } 124 | 125 | if (null !== $this->parsedFile) { 126 | if (PHP_VERSION_ID >= 50400) { 127 | $jsonOptions = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE; 128 | } else { 129 | $jsonOptions = 0; 130 | } 131 | $this->message .= sprintf(' in %s', json_encode($this->parsedFile, $jsonOptions)); 132 | } 133 | 134 | if ($this->parsedLine >= 0) { 135 | $this->message .= sprintf(' at line %d', $this->parsedLine); 136 | } 137 | 138 | if ($this->snippet) { 139 | $this->message .= sprintf(' (near "%s")', $this->snippet); 140 | } 141 | 142 | if ($dot) { 143 | $this->message .= '.'; 144 | } 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Escaper.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Symfony\Component\Yaml; 13 | 14 | /** 15 | * Escaper encapsulates escaping rules for single and double-quoted 16 | * YAML strings. 17 | * 18 | * @author Matthew Lewinski 19 | * 20 | * @internal 21 | */ 22 | class Escaper 23 | { 24 | // Characters that would cause a dumped string to require double quoting. 25 | const REGEX_CHARACTER_TO_ESCAPE = "[\\x00-\\x1f]|\xc2\x85|\xc2\xa0|\xe2\x80\xa8|\xe2\x80\xa9"; 26 | 27 | // Mapping arrays for escaping a double quoted string. The backslash is 28 | // first to ensure proper escaping because str_replace operates iteratively 29 | // on the input arrays. This ordering of the characters avoids the use of strtr, 30 | // which performs more slowly. 31 | private static $escapees = array('\\', '\\\\', '\\"', '"', 32 | "\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", 33 | "\x08", "\x09", "\x0a", "\x0b", "\x0c", "\x0d", "\x0e", "\x0f", 34 | "\x10", "\x11", "\x12", "\x13", "\x14", "\x15", "\x16", "\x17", 35 | "\x18", "\x19", "\x1a", "\x1b", "\x1c", "\x1d", "\x1e", "\x1f", 36 | "\xc2\x85", "\xc2\xa0", "\xe2\x80\xa8", "\xe2\x80\xa9", 37 | ); 38 | private static $escaped = array('\\\\', '\\"', '\\\\', '\\"', 39 | '\\0', '\\x01', '\\x02', '\\x03', '\\x04', '\\x05', '\\x06', '\\a', 40 | '\\b', '\\t', '\\n', '\\v', '\\f', '\\r', '\\x0e', '\\x0f', 41 | '\\x10', '\\x11', '\\x12', '\\x13', '\\x14', '\\x15', '\\x16', '\\x17', 42 | '\\x18', '\\x19', '\\x1a', '\\e', '\\x1c', '\\x1d', '\\x1e', '\\x1f', 43 | '\\N', '\\_', '\\L', '\\P', 44 | ); 45 | 46 | /** 47 | * Determines if a PHP value would require double quoting in YAML. 48 | * 49 | * @param string $value A PHP value 50 | * 51 | * @return bool True if the value would require double quotes 52 | */ 53 | public static function requiresDoubleQuoting($value) 54 | { 55 | return 0 < preg_match('/'.self::REGEX_CHARACTER_TO_ESCAPE.'/u', $value); 56 | } 57 | 58 | /** 59 | * Escapes and surrounds a PHP value with double quotes. 60 | * 61 | * @param string $value A PHP value 62 | * 63 | * @return string The quoted, escaped string 64 | */ 65 | public static function escapeWithDoubleQuotes($value) 66 | { 67 | return sprintf('"%s"', str_replace(self::$escapees, self::$escaped, $value)); 68 | } 69 | 70 | /** 71 | * Determines if a PHP value would require single quoting in YAML. 72 | * 73 | * @param string $value A PHP value 74 | * 75 | * @return bool True if the value would require single quotes 76 | */ 77 | public static function requiresSingleQuoting($value) 78 | { 79 | // Determines if a PHP value is entirely composed of a value that would 80 | // require single quoting in YAML. 81 | if (in_array(strtolower($value), array('null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off'))) { 82 | return true; 83 | } 84 | 85 | // Determines if the PHP value contains any single characters that would 86 | // cause it to require single quoting in YAML. 87 | return 0 < preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value); 88 | } 89 | 90 | /** 91 | * Escapes and surrounds a PHP value with single quotes. 92 | * 93 | * @param string $value A PHP value 94 | * 95 | * @return string The quoted, escaped string 96 | */ 97 | public static function escapeWithSingleQuotes($value) 98 | { 99 | return sprintf("'%s'", str_replace('\'', '\'\'', $value)); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/Fixtures/YtsFoldedScalars.yml: -------------------------------------------------------------------------------- 1 | --- %YAML:1.0 2 | test: Single ending newline 3 | brief: > 4 | A pipe character, followed by an indented 5 | block of text is treated as a literal 6 | block, in which newlines are preserved 7 | throughout the block, including the final 8 | newline. 9 | yaml: | 10 | --- 11 | this: | 12 | Foo 13 | Bar 14 | php: | 15 | array('this' => "Foo\nBar\n") 16 | --- 17 | test: The '+' indicator 18 | brief: > 19 | The '+' indicator says to keep newlines at the end of text 20 | blocks. 21 | yaml: | 22 | normal: | 23 | extra new lines not kept 24 | 25 | preserving: |+ 26 | extra new lines are kept 27 | 28 | 29 | dummy: value 30 | php: | 31 | array( 32 | 'normal' => "extra new lines not kept\n", 33 | 'preserving' => "extra new lines are kept\n\n\n", 34 | 'dummy' => 'value' 35 | ) 36 | --- 37 | test: Three trailing newlines in literals 38 | brief: > 39 | To give you more control over how space 40 | is preserved in text blocks, YAML has 41 | the keep '+' and chomp '-' indicators. 42 | The keep indicator will preserve all 43 | ending newlines, while the chomp indicator 44 | will strip all ending newlines. 45 | yaml: | 46 | clipped: | 47 | This has one newline. 48 | 49 | 50 | 51 | same as "clipped" above: "This has one newline.\n" 52 | 53 | stripped: |- 54 | This has no newline. 55 | 56 | 57 | 58 | same as "stripped" above: "This has no newline." 59 | 60 | kept: |+ 61 | This has four newlines. 62 | 63 | 64 | 65 | same as "kept" above: "This has four newlines.\n\n\n\n" 66 | php: | 67 | array( 68 | 'clipped' => "This has one newline.\n", 69 | 'same as "clipped" above' => "This has one newline.\n", 70 | 'stripped' => 'This has no newline.', 71 | 'same as "stripped" above' => 'This has no newline.', 72 | 'kept' => "This has four newlines.\n\n\n\n", 73 | 'same as "kept" above' => "This has four newlines.\n\n\n\n" 74 | ) 75 | --- 76 | test: Extra trailing newlines with spaces 77 | todo: true 78 | brief: > 79 | Normally, only a single newline is kept 80 | from the end of a literal block, unless the 81 | keep '+' character is used in combination 82 | with the pipe. The following example 83 | will preserve all ending whitespace 84 | since the last line of both literal blocks 85 | contains spaces which extend past the indentation 86 | level. 87 | yaml: | 88 | --- 89 | this: | 90 | Foo 91 | 92 | 93 | kept: |+ 94 | Foo 95 | 96 | 97 | php: | 98 | array('this' => "Foo\n\n \n", 99 | 'kept' => "Foo\n\n \n" ) 100 | 101 | --- 102 | test: Folded Block in a Sequence 103 | brief: > 104 | A greater-then character, followed by an indented 105 | block of text is treated as a folded block, in 106 | which lines of text separated by a single newline 107 | are concatenated as a single line. 108 | yaml: | 109 | --- 110 | - apple 111 | - banana 112 | - > 113 | can't you see 114 | the beauty of yaml? 115 | hmm 116 | - dog 117 | php: | 118 | array( 119 | 'apple', 120 | 'banana', 121 | "can't you see the beauty of yaml? hmm\n", 122 | 'dog' 123 | ) 124 | --- 125 | test: Folded Block as a Mapping Value 126 | brief: > 127 | Both literal and folded blocks can be 128 | used in collections, as values in a 129 | sequence or a mapping. 130 | yaml: | 131 | --- 132 | quote: > 133 | Mark McGwire's 134 | year was crippled 135 | by a knee injury. 136 | source: espn 137 | php: | 138 | array( 139 | 'quote' => "Mark McGwire's year was crippled by a knee injury.\n", 140 | 'source' => 'espn' 141 | ) 142 | --- 143 | test: Three trailing newlines in folded blocks 144 | brief: > 145 | The keep and chomp indicators can also 146 | be applied to folded blocks. 147 | yaml: | 148 | clipped: > 149 | This has one newline. 150 | 151 | 152 | 153 | same as "clipped" above: "This has one newline.\n" 154 | 155 | stripped: >- 156 | This has no newline. 157 | 158 | 159 | 160 | same as "stripped" above: "This has no newline." 161 | 162 | kept: >+ 163 | This has four newlines. 164 | 165 | 166 | 167 | same as "kept" above: "This has four newlines.\n\n\n\n" 168 | php: | 169 | array( 170 | 'clipped' => "This has one newline.\n", 171 | 'same as "clipped" above' => "This has one newline.\n", 172 | 'stripped' => 'This has no newline.', 173 | 'same as "stripped" above' => 'This has no newline.', 174 | 'kept' => "This has four newlines.\n\n\n\n", 175 | 'same as "kept" above' => "This has four newlines.\n\n\n\n" 176 | ) 177 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Unescaper.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Symfony\Component\Yaml; 13 | 14 | /** 15 | * Unescaper encapsulates unescaping rules for single and double-quoted 16 | * YAML strings. 17 | * 18 | * @author Matthew Lewinski 19 | * 20 | * @internal 21 | */ 22 | class Unescaper 23 | { 24 | /** 25 | * Parser and Inline assume UTF-8 encoding, so escaped Unicode characters 26 | * must be converted to that encoding. 27 | * 28 | * @deprecated since version 2.5, to be removed in 3.0 29 | * 30 | * @internal 31 | */ 32 | const ENCODING = 'UTF-8'; 33 | 34 | /** 35 | * Regex fragment that matches an escaped character in a double quoted string. 36 | */ 37 | const REGEX_ESCAPED_CHARACTER = '\\\\(x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|.)'; 38 | 39 | /** 40 | * Unescapes a single quoted string. 41 | * 42 | * @param string $value A single quoted string 43 | * 44 | * @return string The unescaped string 45 | */ 46 | public function unescapeSingleQuotedString($value) 47 | { 48 | return str_replace('\'\'', '\'', $value); 49 | } 50 | 51 | /** 52 | * Unescapes a double quoted string. 53 | * 54 | * @param string $value A double quoted string 55 | * 56 | * @return string The unescaped string 57 | */ 58 | public function unescapeDoubleQuotedString($value) 59 | { 60 | $self = $this; 61 | $callback = function ($match) use ($self) { 62 | return $self->unescapeCharacter($match[0]); 63 | }; 64 | 65 | // evaluate the string 66 | return preg_replace_callback('/'.self::REGEX_ESCAPED_CHARACTER.'/u', $callback, $value); 67 | } 68 | 69 | /** 70 | * Unescapes a character that was found in a double-quoted string. 71 | * 72 | * @param string $value An escaped character 73 | * 74 | * @return string The unescaped character 75 | * 76 | * @internal This method is public to be usable as callback. It should not 77 | * be used in user code. Should be changed in 3.0. 78 | */ 79 | public function unescapeCharacter($value) 80 | { 81 | switch ($value[1]) { 82 | case '0': 83 | return "\x0"; 84 | case 'a': 85 | return "\x7"; 86 | case 'b': 87 | return "\x8"; 88 | case 't': 89 | return "\t"; 90 | case "\t": 91 | return "\t"; 92 | case 'n': 93 | return "\n"; 94 | case 'v': 95 | return "\xB"; 96 | case 'f': 97 | return "\xC"; 98 | case 'r': 99 | return "\r"; 100 | case 'e': 101 | return "\x1B"; 102 | case ' ': 103 | return ' '; 104 | case '"': 105 | return '"'; 106 | case '/': 107 | return '/'; 108 | case '\\': 109 | return '\\'; 110 | case 'N': 111 | // U+0085 NEXT LINE 112 | return "\xC2\x85"; 113 | case '_': 114 | // U+00A0 NO-BREAK SPACE 115 | return "\xC2\xA0"; 116 | case 'L': 117 | // U+2028 LINE SEPARATOR 118 | return "\xE2\x80\xA8"; 119 | case 'P': 120 | // U+2029 PARAGRAPH SEPARATOR 121 | return "\xE2\x80\xA9"; 122 | case 'x': 123 | return self::utf8chr(hexdec(substr($value, 2, 2))); 124 | case 'u': 125 | return self::utf8chr(hexdec(substr($value, 2, 4))); 126 | case 'U': 127 | return self::utf8chr(hexdec(substr($value, 2, 8))); 128 | default: 129 | @trigger_error('Not escaping a backslash in a double-quoted string is deprecated since Symfony 2.8 and will throw a ParseException in 3.0.', E_USER_DEPRECATED); 130 | 131 | return $value; 132 | } 133 | } 134 | 135 | /** 136 | * Get the UTF-8 character for the given code point. 137 | * 138 | * @param int $c The unicode code point 139 | * 140 | * @return string The corresponding UTF-8 character 141 | */ 142 | private static function utf8chr($c) 143 | { 144 | if (0x80 > $c %= 0x200000) { 145 | return chr($c); 146 | } 147 | if (0x800 > $c) { 148 | return chr(0xC0 | $c >> 6).chr(0x80 | $c & 0x3F); 149 | } 150 | if (0x10000 > $c) { 151 | return chr(0xE0 | $c >> 12).chr(0x80 | $c >> 6 & 0x3F).chr(0x80 | $c & 0x3F); 152 | } 153 | 154 | return chr(0xF0 | $c >> 18).chr(0x80 | $c >> 12 & 0x3F).chr(0x80 | $c >> 6 & 0x3F).chr(0x80 | $c & 0x3F); 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/Fixtures/YtsBasicTests.yml: -------------------------------------------------------------------------------- 1 | --- %YAML:1.0 2 | test: Simple Sequence 3 | brief: | 4 | You can specify a list in YAML by placing each 5 | member of the list on a new line with an opening 6 | dash. These lists are called sequences. 7 | yaml: | 8 | - apple 9 | - banana 10 | - carrot 11 | php: | 12 | array('apple', 'banana', 'carrot') 13 | --- 14 | test: Sequence With Item Being Null In The Middle 15 | brief: | 16 | You can specify a list in YAML by placing each 17 | member of the list on a new line with an opening 18 | dash. These lists are called sequences. 19 | yaml: | 20 | - apple 21 | - 22 | - carrot 23 | php: | 24 | array('apple', null, 'carrot') 25 | --- 26 | test: Sequence With Last Item Being Null 27 | brief: | 28 | You can specify a list in YAML by placing each 29 | member of the list on a new line with an opening 30 | dash. These lists are called sequences. 31 | yaml: | 32 | - apple 33 | - banana 34 | - 35 | php: | 36 | array('apple', 'banana', null) 37 | --- 38 | test: Nested Sequences 39 | brief: | 40 | You can include a sequence within another 41 | sequence by giving the sequence an empty 42 | dash, followed by an indented list. 43 | yaml: | 44 | - 45 | - foo 46 | - bar 47 | - baz 48 | php: | 49 | array(array('foo', 'bar', 'baz')) 50 | --- 51 | test: Mixed Sequences 52 | brief: | 53 | Sequences can contain any YAML data, 54 | including strings and other sequences. 55 | yaml: | 56 | - apple 57 | - 58 | - foo 59 | - bar 60 | - x123 61 | - banana 62 | - carrot 63 | php: | 64 | array('apple', array('foo', 'bar', 'x123'), 'banana', 'carrot') 65 | --- 66 | test: Deeply Nested Sequences 67 | brief: | 68 | Sequences can be nested even deeper, with each 69 | level of indentation representing a level of 70 | depth. 71 | yaml: | 72 | - 73 | - 74 | - uno 75 | - dos 76 | php: | 77 | array(array(array('uno', 'dos'))) 78 | --- 79 | test: Simple Mapping 80 | brief: | 81 | You can add a keyed list (also known as a dictionary or 82 | hash) to your document by placing each member of the 83 | list on a new line, with a colon separating the key 84 | from its value. In YAML, this type of list is called 85 | a mapping. 86 | yaml: | 87 | foo: whatever 88 | bar: stuff 89 | php: | 90 | array('foo' => 'whatever', 'bar' => 'stuff') 91 | --- 92 | test: Sequence in a Mapping 93 | brief: | 94 | A value in a mapping can be a sequence. 95 | yaml: | 96 | foo: whatever 97 | bar: 98 | - uno 99 | - dos 100 | php: | 101 | array('foo' => 'whatever', 'bar' => array('uno', 'dos')) 102 | --- 103 | test: Nested Mappings 104 | brief: | 105 | A value in a mapping can be another mapping. 106 | yaml: | 107 | foo: whatever 108 | bar: 109 | fruit: apple 110 | name: steve 111 | sport: baseball 112 | php: | 113 | array( 114 | 'foo' => 'whatever', 115 | 'bar' => array( 116 | 'fruit' => 'apple', 117 | 'name' => 'steve', 118 | 'sport' => 'baseball' 119 | ) 120 | ) 121 | --- 122 | test: Mixed Mapping 123 | brief: | 124 | A mapping can contain any assortment 125 | of mappings and sequences as values. 126 | yaml: | 127 | foo: whatever 128 | bar: 129 | - 130 | fruit: apple 131 | name: steve 132 | sport: baseball 133 | - more 134 | - 135 | python: rocks 136 | perl: papers 137 | ruby: scissorses 138 | php: | 139 | array( 140 | 'foo' => 'whatever', 141 | 'bar' => array( 142 | array( 143 | 'fruit' => 'apple', 144 | 'name' => 'steve', 145 | 'sport' => 'baseball' 146 | ), 147 | 'more', 148 | array( 149 | 'python' => 'rocks', 150 | 'perl' => 'papers', 151 | 'ruby' => 'scissorses' 152 | ) 153 | ) 154 | ) 155 | --- 156 | test: Mapping-in-Sequence Shortcut 157 | todo: true 158 | brief: | 159 | If you are adding a mapping to a sequence, you 160 | can place the mapping on the same line as the 161 | dash as a shortcut. 162 | yaml: | 163 | - work on YAML.py: 164 | - work on Store 165 | php: | 166 | array(array('work on YAML.py' => array('work on Store'))) 167 | --- 168 | test: Sequence-in-Mapping Shortcut 169 | todo: true 170 | brief: | 171 | The dash in a sequence counts as indentation, so 172 | you can add a sequence inside of a mapping without 173 | needing spaces as indentation. 174 | yaml: | 175 | allow: 176 | - 'localhost' 177 | - '%.sourceforge.net' 178 | - '%.freepan.org' 179 | php: | 180 | array('allow' => array('localhost', '%.sourceforge.net', '%.freepan.org')) 181 | --- 182 | todo: true 183 | test: Merge key 184 | brief: | 185 | A merge key ('<<') can be used in a mapping to insert other mappings. If 186 | the value associated with the merge key is a mapping, each of its key/value 187 | pairs is inserted into the current mapping. 188 | yaml: | 189 | mapping: 190 | name: Joe 191 | job: Accountant 192 | <<: 193 | age: 38 194 | php: | 195 | array( 196 | 'mapping' => 197 | array( 198 | 'name' => 'Joe', 199 | 'job' => 'Accountant', 200 | 'age' => 38 201 | ) 202 | ) 203 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/Fixtures/YtsTypeTransfers.yml: -------------------------------------------------------------------------------- 1 | --- %YAML:1.0 2 | test: Strings 3 | brief: > 4 | Any group of characters beginning with an 5 | alphabetic or numeric character is a string, 6 | unless it belongs to one of the groups below 7 | (such as an Integer or Time). 8 | yaml: | 9 | String 10 | php: | 11 | 'String' 12 | --- 13 | test: String characters 14 | brief: > 15 | A string can contain any alphabetic or 16 | numeric character, along with many 17 | punctuation characters, including the 18 | period, dash, space, quotes, exclamation, and 19 | question mark. 20 | yaml: | 21 | - What's Yaml? 22 | - It's for writing data structures in plain text. 23 | - And? 24 | - And what? That's not good enough for you? 25 | - No, I mean, "And what about Yaml?" 26 | - Oh, oh yeah. Uh.. Yaml for Ruby. 27 | php: | 28 | array( 29 | "What's Yaml?", 30 | "It's for writing data structures in plain text.", 31 | "And?", 32 | "And what? That's not good enough for you?", 33 | "No, I mean, \"And what about Yaml?\"", 34 | "Oh, oh yeah. Uh.. Yaml for Ruby." 35 | ) 36 | --- 37 | test: Indicators in Strings 38 | brief: > 39 | Be careful using indicators in strings. In particular, 40 | the comma, colon, and pound sign must be used carefully. 41 | yaml: | 42 | the colon followed by space is an indicator: but is a string:right here 43 | same for the pound sign: here we have it#in a string 44 | the comma can, honestly, be used in most cases: [ but not in, inline collections ] 45 | php: | 46 | array( 47 | 'the colon followed by space is an indicator' => 'but is a string:right here', 48 | 'same for the pound sign' => 'here we have it#in a string', 49 | 'the comma can, honestly, be used in most cases' => array('but not in', 'inline collections') 50 | ) 51 | --- 52 | test: Forcing Strings 53 | brief: > 54 | Any YAML type can be forced into a string using the 55 | explicit !str method. 56 | yaml: | 57 | date string: !str 2001-08-01 58 | number string: !str 192 59 | php: | 60 | array( 61 | 'date string' => '2001-08-01', 62 | 'number string' => '192' 63 | ) 64 | --- 65 | test: Single-quoted Strings 66 | brief: > 67 | You can also enclose your strings within single quotes, 68 | which allows use of slashes, colons, and other indicators 69 | freely. Inside single quotes, you can represent a single 70 | quote in your string by using two single quotes next to 71 | each other. 72 | yaml: | 73 | all my favorite symbols: '#:!/%.)' 74 | a few i hate: '&(*' 75 | why do i hate them?: 'it''s very hard to explain' 76 | entities: '£ me' 77 | php: | 78 | array( 79 | 'all my favorite symbols' => '#:!/%.)', 80 | 'a few i hate' => '&(*', 81 | 'why do i hate them?' => 'it\'s very hard to explain', 82 | 'entities' => '£ me' 83 | ) 84 | --- 85 | test: Double-quoted Strings 86 | brief: > 87 | Enclosing strings in double quotes allows you 88 | to use escapings to represent ASCII and 89 | Unicode characters. 90 | yaml: | 91 | i know where i want my line breaks: "one here\nand another here\n" 92 | php: | 93 | array( 94 | 'i know where i want my line breaks' => "one here\nand another here\n" 95 | ) 96 | --- 97 | test: Multi-line Quoted Strings 98 | todo: true 99 | brief: > 100 | Both single- and double-quoted strings may be 101 | carried on to new lines in your YAML document. 102 | They must be indented a step and indentation 103 | is interpreted as a single space. 104 | yaml: | 105 | i want a long string: "so i'm going to 106 | let it go on and on to other lines 107 | until i end it with a quote." 108 | php: | 109 | array('i want a long string' => "so i'm going to ". 110 | "let it go on and on to other lines ". 111 | "until i end it with a quote." 112 | ) 113 | 114 | --- 115 | test: Plain scalars 116 | todo: true 117 | brief: > 118 | Unquoted strings may also span multiple lines, if they 119 | are free of YAML space indicators and indented. 120 | yaml: | 121 | - My little toe is broken in two places; 122 | - I'm crazy to have skied this way; 123 | - I'm not the craziest he's seen, since there was always the German guy 124 | who skied for 3 hours on a broken shin bone (just below the kneecap); 125 | - Nevertheless, second place is respectable, and he doesn't 126 | recommend going for the record; 127 | - He's going to put my foot in plaster for a month; 128 | - This would impair my skiing ability somewhat for the 129 | duration, as can be imagined. 130 | php: | 131 | array( 132 | "My little toe is broken in two places;", 133 | "I'm crazy to have skied this way;", 134 | "I'm not the craziest he's seen, since there was always ". 135 | "the German guy who skied for 3 hours on a broken shin ". 136 | "bone (just below the kneecap);", 137 | "Nevertheless, second place is respectable, and he doesn't ". 138 | "recommend going for the record;", 139 | "He's going to put my foot in plaster for a month;", 140 | "This would impair my skiing ability somewhat for the duration, ". 141 | "as can be imagined." 142 | ) 143 | --- 144 | test: 'Null' 145 | brief: > 146 | You can use the tilde '~' character for a null value. 147 | yaml: | 148 | name: Mr. Show 149 | hosted by: Bob and David 150 | date of next season: ~ 151 | php: | 152 | array( 153 | 'name' => 'Mr. Show', 154 | 'hosted by' => 'Bob and David', 155 | 'date of next season' => null 156 | ) 157 | --- 158 | test: Boolean 159 | brief: > 160 | You can use 'true' and 'false' for Boolean values. 161 | yaml: | 162 | Is Gus a Liar?: true 163 | Do I rely on Gus for Sustenance?: false 164 | php: | 165 | array( 166 | 'Is Gus a Liar?' => true, 167 | 'Do I rely on Gus for Sustenance?' => false 168 | ) 169 | --- 170 | test: Integers 171 | dump_skip: true 172 | brief: > 173 | An integer is a series of numbers, optionally 174 | starting with a positive or negative sign. Integers 175 | may also contain commas for readability. 176 | yaml: | 177 | zero: 0 178 | simple: 12 179 | one-thousand: 1,000 180 | negative one-thousand: -1,000 181 | php: | 182 | array( 183 | 'zero' => 0, 184 | 'simple' => 12, 185 | 'one-thousand' => 1000.0, 186 | 'negative one-thousand' => -1000.0 187 | ) 188 | --- 189 | test: Integers as Map Keys 190 | brief: > 191 | An integer can be used a dictionary key. 192 | yaml: | 193 | 1: one 194 | 2: two 195 | 3: three 196 | php: | 197 | array( 198 | 1 => 'one', 199 | 2 => 'two', 200 | 3 => 'three' 201 | ) 202 | --- 203 | test: Floats 204 | dump_skip: true 205 | brief: > 206 | Floats are represented by numbers with decimals, 207 | allowing for scientific notation, as well as 208 | positive and negative infinity and "not a number." 209 | yaml: | 210 | a simple float: 2.00 211 | larger float: 1,000.09 212 | scientific notation: 1.00009e+3 213 | php: | 214 | array( 215 | 'a simple float' => 2.0, 216 | 'larger float' => 1000.09, 217 | 'scientific notation' => 1000.09 218 | ) 219 | --- 220 | test: Time 221 | todo: true 222 | brief: > 223 | You can represent timestamps by using 224 | ISO8601 format, or a variation which 225 | allows spaces between the date, time and 226 | time zone. 227 | yaml: | 228 | iso8601: 2001-12-14t21:59:43.10-05:00 229 | space separated: 2001-12-14 21:59:43.10 -05:00 230 | php: | 231 | array( 232 | 'iso8601' => mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ), 233 | 'space separated' => mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ) 234 | ) 235 | --- 236 | test: Date 237 | todo: true 238 | brief: > 239 | A date can be represented by its year, 240 | month and day in ISO8601 order. 241 | yaml: | 242 | 1976-07-31 243 | php: | 244 | date( 1976, 7, 31 ) 245 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/DumperTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Symfony\Component\Yaml\Tests; 13 | 14 | use PHPUnit\Framework\TestCase; 15 | use Symfony\Component\Yaml\Parser; 16 | use Symfony\Component\Yaml\Dumper; 17 | 18 | class DumperTest extends TestCase 19 | { 20 | protected $parser; 21 | protected $dumper; 22 | protected $path; 23 | 24 | protected $array = array( 25 | '' => 'bar', 26 | 'foo' => '#bar', 27 | 'foo\'bar' => array(), 28 | 'bar' => array(1, 'foo'), 29 | 'foobar' => array( 30 | 'foo' => 'bar', 31 | 'bar' => array(1, 'foo'), 32 | 'foobar' => array( 33 | 'foo' => 'bar', 34 | 'bar' => array(1, 'foo'), 35 | ), 36 | ), 37 | ); 38 | 39 | protected function setUp() 40 | { 41 | $this->parser = new Parser(); 42 | $this->dumper = new Dumper(); 43 | $this->path = __DIR__.'/Fixtures'; 44 | } 45 | 46 | protected function tearDown() 47 | { 48 | $this->parser = null; 49 | $this->dumper = null; 50 | $this->path = null; 51 | $this->array = null; 52 | } 53 | 54 | public function testSetIndentation() 55 | { 56 | $this->dumper->setIndentation(7); 57 | 58 | $expected = <<<'EOF' 59 | '': bar 60 | foo: '#bar' 61 | 'foo''bar': { } 62 | bar: 63 | - 1 64 | - foo 65 | foobar: 66 | foo: bar 67 | bar: 68 | - 1 69 | - foo 70 | foobar: 71 | foo: bar 72 | bar: 73 | - 1 74 | - foo 75 | 76 | EOF; 77 | $this->assertEquals($expected, $this->dumper->dump($this->array, 4, 0)); 78 | } 79 | 80 | public function testSpecifications() 81 | { 82 | $files = $this->parser->parse(file_get_contents($this->path.'/index.yml')); 83 | foreach ($files as $file) { 84 | $yamls = file_get_contents($this->path.'/'.$file.'.yml'); 85 | 86 | // split YAMLs documents 87 | foreach (preg_split('/^---( %YAML\:1\.0)?/m', $yamls) as $yaml) { 88 | if (!$yaml) { 89 | continue; 90 | } 91 | 92 | $test = $this->parser->parse($yaml); 93 | if (isset($test['dump_skip']) && $test['dump_skip']) { 94 | continue; 95 | } elseif (isset($test['todo']) && $test['todo']) { 96 | // TODO 97 | } else { 98 | eval('$expected = '.trim($test['php']).';'); 99 | $this->assertSame($expected, $this->parser->parse($this->dumper->dump($expected, 10)), $test['test']); 100 | } 101 | } 102 | } 103 | } 104 | 105 | public function testInlineLevel() 106 | { 107 | $expected = <<<'EOF' 108 | { '': bar, foo: '#bar', 'foo''bar': { }, bar: [1, foo], foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } } } 109 | EOF; 110 | $this->assertEquals($expected, $this->dumper->dump($this->array, -10), '->dump() takes an inline level argument'); 111 | $this->assertEquals($expected, $this->dumper->dump($this->array, 0), '->dump() takes an inline level argument'); 112 | 113 | $expected = <<<'EOF' 114 | '': bar 115 | foo: '#bar' 116 | 'foo''bar': { } 117 | bar: [1, foo] 118 | foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } } 119 | 120 | EOF; 121 | $this->assertEquals($expected, $this->dumper->dump($this->array, 1), '->dump() takes an inline level argument'); 122 | 123 | $expected = <<<'EOF' 124 | '': bar 125 | foo: '#bar' 126 | 'foo''bar': { } 127 | bar: 128 | - 1 129 | - foo 130 | foobar: 131 | foo: bar 132 | bar: [1, foo] 133 | foobar: { foo: bar, bar: [1, foo] } 134 | 135 | EOF; 136 | $this->assertEquals($expected, $this->dumper->dump($this->array, 2), '->dump() takes an inline level argument'); 137 | 138 | $expected = <<<'EOF' 139 | '': bar 140 | foo: '#bar' 141 | 'foo''bar': { } 142 | bar: 143 | - 1 144 | - foo 145 | foobar: 146 | foo: bar 147 | bar: 148 | - 1 149 | - foo 150 | foobar: 151 | foo: bar 152 | bar: [1, foo] 153 | 154 | EOF; 155 | $this->assertEquals($expected, $this->dumper->dump($this->array, 3), '->dump() takes an inline level argument'); 156 | 157 | $expected = <<<'EOF' 158 | '': bar 159 | foo: '#bar' 160 | 'foo''bar': { } 161 | bar: 162 | - 1 163 | - foo 164 | foobar: 165 | foo: bar 166 | bar: 167 | - 1 168 | - foo 169 | foobar: 170 | foo: bar 171 | bar: 172 | - 1 173 | - foo 174 | 175 | EOF; 176 | $this->assertEquals($expected, $this->dumper->dump($this->array, 4), '->dump() takes an inline level argument'); 177 | $this->assertEquals($expected, $this->dumper->dump($this->array, 10), '->dump() takes an inline level argument'); 178 | } 179 | 180 | public function testObjectSupportEnabled() 181 | { 182 | $dump = $this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, false, true); 183 | 184 | $this->assertEquals('{ foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";}, bar: 1 }', $dump, '->dump() is able to dump objects'); 185 | } 186 | 187 | public function testObjectSupportDisabledButNoExceptions() 188 | { 189 | $dump = $this->dumper->dump(array('foo' => new A(), 'bar' => 1)); 190 | 191 | $this->assertEquals('{ foo: null, bar: 1 }', $dump, '->dump() does not dump objects when disabled'); 192 | } 193 | 194 | /** 195 | * @expectedException \Symfony\Component\Yaml\Exception\DumpException 196 | */ 197 | public function testObjectSupportDisabledWithExceptions() 198 | { 199 | $this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, true, false); 200 | } 201 | 202 | /** 203 | * @dataProvider getEscapeSequences 204 | */ 205 | public function testEscapedEscapeSequencesInQuotedScalar($input, $expected) 206 | { 207 | $this->assertEquals($expected, $this->dumper->dump($input)); 208 | } 209 | 210 | public function getEscapeSequences() 211 | { 212 | return array( 213 | 'empty string' => array('', "''"), 214 | 'null' => array("\x0", '"\\0"'), 215 | 'bell' => array("\x7", '"\\a"'), 216 | 'backspace' => array("\x8", '"\\b"'), 217 | 'horizontal-tab' => array("\t", '"\\t"'), 218 | 'line-feed' => array("\n", '"\\n"'), 219 | 'vertical-tab' => array("\v", '"\\v"'), 220 | 'form-feed' => array("\xC", '"\\f"'), 221 | 'carriage-return' => array("\r", '"\\r"'), 222 | 'escape' => array("\x1B", '"\\e"'), 223 | 'space' => array(' ', "' '"), 224 | 'double-quote' => array('"', "'\"'"), 225 | 'slash' => array('/', '/'), 226 | 'backslash' => array('\\', '\\'), 227 | 'next-line' => array("\xC2\x85", '"\\N"'), 228 | 'non-breaking-space' => array("\xc2\xa0", '"\\_"'), 229 | 'line-separator' => array("\xE2\x80\xA8", '"\\L"'), 230 | 'paragraph-separator' => array("\xE2\x80\xA9", '"\\P"'), 231 | 'colon' => array(':', "':'"), 232 | ); 233 | } 234 | 235 | /** 236 | * @expectedException \InvalidArgumentException 237 | * @expectedExceptionMessage The indentation must be greater than zero 238 | */ 239 | public function testZeroIndentationThrowsException() 240 | { 241 | $this->dumper->setIndentation(0); 242 | } 243 | 244 | /** 245 | * @expectedException \InvalidArgumentException 246 | * @expectedExceptionMessage The indentation must be greater than zero 247 | */ 248 | public function testNegativeIndentationThrowsException() 249 | { 250 | $this->dumper->setIndentation(-4); 251 | } 252 | } 253 | 254 | class A 255 | { 256 | public $a = 'foo'; 257 | } 258 | -------------------------------------------------------------------------------- /craft2yml/vendor/composer/ClassLoader.php: -------------------------------------------------------------------------------- 1 | 7 | * Jordi Boggiano 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Composer\Autoload; 14 | 15 | /** 16 | * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. 17 | * 18 | * $loader = new \Composer\Autoload\ClassLoader(); 19 | * 20 | * // register classes with namespaces 21 | * $loader->add('Symfony\Component', __DIR__.'/component'); 22 | * $loader->add('Symfony', __DIR__.'/framework'); 23 | * 24 | * // activate the autoloader 25 | * $loader->register(); 26 | * 27 | * // to enable searching the include path (eg. for PEAR packages) 28 | * $loader->setUseIncludePath(true); 29 | * 30 | * In this example, if you try to use a class in the Symfony\Component 31 | * namespace or one of its children (Symfony\Component\Console for instance), 32 | * the autoloader will first look for the class under the component/ 33 | * directory, and it will then fallback to the framework/ directory if not 34 | * found before giving up. 35 | * 36 | * This class is loosely based on the Symfony UniversalClassLoader. 37 | * 38 | * @author Fabien Potencier 39 | * @author Jordi Boggiano 40 | * @see http://www.php-fig.org/psr/psr-0/ 41 | * @see http://www.php-fig.org/psr/psr-4/ 42 | */ 43 | class ClassLoader 44 | { 45 | // PSR-4 46 | private $prefixLengthsPsr4 = array(); 47 | private $prefixDirsPsr4 = array(); 48 | private $fallbackDirsPsr4 = array(); 49 | 50 | // PSR-0 51 | private $prefixesPsr0 = array(); 52 | private $fallbackDirsPsr0 = array(); 53 | 54 | private $useIncludePath = false; 55 | private $classMap = array(); 56 | private $classMapAuthoritative = false; 57 | private $missingClasses = array(); 58 | private $apcuPrefix; 59 | 60 | public function getPrefixes() 61 | { 62 | if (!empty($this->prefixesPsr0)) { 63 | return call_user_func_array('array_merge', $this->prefixesPsr0); 64 | } 65 | 66 | return array(); 67 | } 68 | 69 | public function getPrefixesPsr4() 70 | { 71 | return $this->prefixDirsPsr4; 72 | } 73 | 74 | public function getFallbackDirs() 75 | { 76 | return $this->fallbackDirsPsr0; 77 | } 78 | 79 | public function getFallbackDirsPsr4() 80 | { 81 | return $this->fallbackDirsPsr4; 82 | } 83 | 84 | public function getClassMap() 85 | { 86 | return $this->classMap; 87 | } 88 | 89 | /** 90 | * @param array $classMap Class to filename map 91 | */ 92 | public function addClassMap(array $classMap) 93 | { 94 | if ($this->classMap) { 95 | $this->classMap = array_merge($this->classMap, $classMap); 96 | } else { 97 | $this->classMap = $classMap; 98 | } 99 | } 100 | 101 | /** 102 | * Registers a set of PSR-0 directories for a given prefix, either 103 | * appending or prepending to the ones previously set for this prefix. 104 | * 105 | * @param string $prefix The prefix 106 | * @param array|string $paths The PSR-0 root directories 107 | * @param bool $prepend Whether to prepend the directories 108 | */ 109 | public function add($prefix, $paths, $prepend = false) 110 | { 111 | if (!$prefix) { 112 | if ($prepend) { 113 | $this->fallbackDirsPsr0 = array_merge( 114 | (array) $paths, 115 | $this->fallbackDirsPsr0 116 | ); 117 | } else { 118 | $this->fallbackDirsPsr0 = array_merge( 119 | $this->fallbackDirsPsr0, 120 | (array) $paths 121 | ); 122 | } 123 | 124 | return; 125 | } 126 | 127 | $first = $prefix[0]; 128 | if (!isset($this->prefixesPsr0[$first][$prefix])) { 129 | $this->prefixesPsr0[$first][$prefix] = (array) $paths; 130 | 131 | return; 132 | } 133 | if ($prepend) { 134 | $this->prefixesPsr0[$first][$prefix] = array_merge( 135 | (array) $paths, 136 | $this->prefixesPsr0[$first][$prefix] 137 | ); 138 | } else { 139 | $this->prefixesPsr0[$first][$prefix] = array_merge( 140 | $this->prefixesPsr0[$first][$prefix], 141 | (array) $paths 142 | ); 143 | } 144 | } 145 | 146 | /** 147 | * Registers a set of PSR-4 directories for a given namespace, either 148 | * appending or prepending to the ones previously set for this namespace. 149 | * 150 | * @param string $prefix The prefix/namespace, with trailing '\\' 151 | * @param array|string $paths The PSR-4 base directories 152 | * @param bool $prepend Whether to prepend the directories 153 | * 154 | * @throws \InvalidArgumentException 155 | */ 156 | public function addPsr4($prefix, $paths, $prepend = false) 157 | { 158 | if (!$prefix) { 159 | // Register directories for the root namespace. 160 | if ($prepend) { 161 | $this->fallbackDirsPsr4 = array_merge( 162 | (array) $paths, 163 | $this->fallbackDirsPsr4 164 | ); 165 | } else { 166 | $this->fallbackDirsPsr4 = array_merge( 167 | $this->fallbackDirsPsr4, 168 | (array) $paths 169 | ); 170 | } 171 | } elseif (!isset($this->prefixDirsPsr4[$prefix])) { 172 | // Register directories for a new namespace. 173 | $length = strlen($prefix); 174 | if ('\\' !== $prefix[$length - 1]) { 175 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); 176 | } 177 | $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; 178 | $this->prefixDirsPsr4[$prefix] = (array) $paths; 179 | } elseif ($prepend) { 180 | // Prepend directories for an already registered namespace. 181 | $this->prefixDirsPsr4[$prefix] = array_merge( 182 | (array) $paths, 183 | $this->prefixDirsPsr4[$prefix] 184 | ); 185 | } else { 186 | // Append directories for an already registered namespace. 187 | $this->prefixDirsPsr4[$prefix] = array_merge( 188 | $this->prefixDirsPsr4[$prefix], 189 | (array) $paths 190 | ); 191 | } 192 | } 193 | 194 | /** 195 | * Registers a set of PSR-0 directories for a given prefix, 196 | * replacing any others previously set for this prefix. 197 | * 198 | * @param string $prefix The prefix 199 | * @param array|string $paths The PSR-0 base directories 200 | */ 201 | public function set($prefix, $paths) 202 | { 203 | if (!$prefix) { 204 | $this->fallbackDirsPsr0 = (array) $paths; 205 | } else { 206 | $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; 207 | } 208 | } 209 | 210 | /** 211 | * Registers a set of PSR-4 directories for a given namespace, 212 | * replacing any others previously set for this namespace. 213 | * 214 | * @param string $prefix The prefix/namespace, with trailing '\\' 215 | * @param array|string $paths The PSR-4 base directories 216 | * 217 | * @throws \InvalidArgumentException 218 | */ 219 | public function setPsr4($prefix, $paths) 220 | { 221 | if (!$prefix) { 222 | $this->fallbackDirsPsr4 = (array) $paths; 223 | } else { 224 | $length = strlen($prefix); 225 | if ('\\' !== $prefix[$length - 1]) { 226 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); 227 | } 228 | $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; 229 | $this->prefixDirsPsr4[$prefix] = (array) $paths; 230 | } 231 | } 232 | 233 | /** 234 | * Turns on searching the include path for class files. 235 | * 236 | * @param bool $useIncludePath 237 | */ 238 | public function setUseIncludePath($useIncludePath) 239 | { 240 | $this->useIncludePath = $useIncludePath; 241 | } 242 | 243 | /** 244 | * Can be used to check if the autoloader uses the include path to check 245 | * for classes. 246 | * 247 | * @return bool 248 | */ 249 | public function getUseIncludePath() 250 | { 251 | return $this->useIncludePath; 252 | } 253 | 254 | /** 255 | * Turns off searching the prefix and fallback directories for classes 256 | * that have not been registered with the class map. 257 | * 258 | * @param bool $classMapAuthoritative 259 | */ 260 | public function setClassMapAuthoritative($classMapAuthoritative) 261 | { 262 | $this->classMapAuthoritative = $classMapAuthoritative; 263 | } 264 | 265 | /** 266 | * Should class lookup fail if not found in the current class map? 267 | * 268 | * @return bool 269 | */ 270 | public function isClassMapAuthoritative() 271 | { 272 | return $this->classMapAuthoritative; 273 | } 274 | 275 | /** 276 | * APCu prefix to use to cache found/not-found classes, if the extension is enabled. 277 | * 278 | * @param string|null $apcuPrefix 279 | */ 280 | public function setApcuPrefix($apcuPrefix) 281 | { 282 | $this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null; 283 | } 284 | 285 | /** 286 | * The APCu prefix in use, or null if APCu caching is not enabled. 287 | * 288 | * @return string|null 289 | */ 290 | public function getApcuPrefix() 291 | { 292 | return $this->apcuPrefix; 293 | } 294 | 295 | /** 296 | * Registers this instance as an autoloader. 297 | * 298 | * @param bool $prepend Whether to prepend the autoloader or not 299 | */ 300 | public function register($prepend = false) 301 | { 302 | spl_autoload_register(array($this, 'loadClass'), true, $prepend); 303 | } 304 | 305 | /** 306 | * Unregisters this instance as an autoloader. 307 | */ 308 | public function unregister() 309 | { 310 | spl_autoload_unregister(array($this, 'loadClass')); 311 | } 312 | 313 | /** 314 | * Loads the given class or interface. 315 | * 316 | * @param string $class The name of the class 317 | * @return bool|null True if loaded, null otherwise 318 | */ 319 | public function loadClass($class) 320 | { 321 | if ($file = $this->findFile($class)) { 322 | includeFile($file); 323 | 324 | return true; 325 | } 326 | } 327 | 328 | /** 329 | * Finds the path to the file where the class is defined. 330 | * 331 | * @param string $class The name of the class 332 | * 333 | * @return string|false The path if found, false otherwise 334 | */ 335 | public function findFile($class) 336 | { 337 | // class map lookup 338 | if (isset($this->classMap[$class])) { 339 | return $this->classMap[$class]; 340 | } 341 | if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { 342 | return false; 343 | } 344 | if (null !== $this->apcuPrefix) { 345 | $file = apcu_fetch($this->apcuPrefix.$class, $hit); 346 | if ($hit) { 347 | return $file; 348 | } 349 | } 350 | 351 | $file = $this->findFileWithExtension($class, '.php'); 352 | 353 | // Search for Hack files if we are running on HHVM 354 | if (false === $file && defined('HHVM_VERSION')) { 355 | $file = $this->findFileWithExtension($class, '.hh'); 356 | } 357 | 358 | if (null !== $this->apcuPrefix) { 359 | apcu_add($this->apcuPrefix.$class, $file); 360 | } 361 | 362 | if (false === $file) { 363 | // Remember that this class does not exist. 364 | $this->missingClasses[$class] = true; 365 | } 366 | 367 | return $file; 368 | } 369 | 370 | private function findFileWithExtension($class, $ext) 371 | { 372 | // PSR-4 lookup 373 | $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; 374 | 375 | $first = $class[0]; 376 | if (isset($this->prefixLengthsPsr4[$first])) { 377 | $subPath = $class; 378 | while (false !== $lastPos = strrpos($subPath, '\\')) { 379 | $subPath = substr($subPath, 0, $lastPos); 380 | $search = $subPath.'\\'; 381 | if (isset($this->prefixDirsPsr4[$search])) { 382 | foreach ($this->prefixDirsPsr4[$search] as $dir) { 383 | $length = $this->prefixLengthsPsr4[$first][$search]; 384 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { 385 | return $file; 386 | } 387 | } 388 | } 389 | } 390 | } 391 | 392 | // PSR-4 fallback dirs 393 | foreach ($this->fallbackDirsPsr4 as $dir) { 394 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { 395 | return $file; 396 | } 397 | } 398 | 399 | // PSR-0 lookup 400 | if (false !== $pos = strrpos($class, '\\')) { 401 | // namespaced class name 402 | $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) 403 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); 404 | } else { 405 | // PEAR-like class name 406 | $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; 407 | } 408 | 409 | if (isset($this->prefixesPsr0[$first])) { 410 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { 411 | if (0 === strpos($class, $prefix)) { 412 | foreach ($dirs as $dir) { 413 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { 414 | return $file; 415 | } 416 | } 417 | } 418 | } 419 | } 420 | 421 | // PSR-0 fallback dirs 422 | foreach ($this->fallbackDirsPsr0 as $dir) { 423 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { 424 | return $file; 425 | } 426 | } 427 | 428 | // PSR-0 include paths. 429 | if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { 430 | return $file; 431 | } 432 | 433 | return false; 434 | } 435 | } 436 | 437 | /** 438 | * Scope isolated include. 439 | * 440 | * Prevents access to $this/self from included files. 441 | */ 442 | function includeFile($file) 443 | { 444 | include $file; 445 | } 446 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/InlineTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Symfony\Component\Yaml\Tests; 13 | 14 | use PHPUnit\Framework\TestCase; 15 | use Symfony\Component\Yaml\Inline; 16 | 17 | class InlineTest extends TestCase 18 | { 19 | /** 20 | * @dataProvider getTestsForParse 21 | */ 22 | public function testParse($yaml, $value) 23 | { 24 | $this->assertSame($value, Inline::parse($yaml), sprintf('::parse() converts an inline YAML to a PHP structure (%s)', $yaml)); 25 | } 26 | 27 | /** 28 | * @dataProvider getTestsForParseWithMapObjects 29 | */ 30 | public function testParseWithMapObjects($yaml, $value) 31 | { 32 | $actual = Inline::parse($yaml, false, false, true); 33 | 34 | $this->assertSame(serialize($value), serialize($actual)); 35 | } 36 | 37 | /** 38 | * @dataProvider getTestsForDump 39 | */ 40 | public function testDump($yaml, $value) 41 | { 42 | $this->assertEquals($yaml, Inline::dump($value), sprintf('::dump() converts a PHP structure to an inline YAML (%s)', $yaml)); 43 | 44 | $this->assertSame($value, Inline::parse(Inline::dump($value)), 'check consistency'); 45 | } 46 | 47 | public function testDumpNumericValueWithLocale() 48 | { 49 | $locale = setlocale(LC_NUMERIC, 0); 50 | if (false === $locale) { 51 | $this->markTestSkipped('Your platform does not support locales.'); 52 | } 53 | 54 | try { 55 | $requiredLocales = array('fr_FR.UTF-8', 'fr_FR.UTF8', 'fr_FR.utf-8', 'fr_FR.utf8', 'French_France.1252'); 56 | if (false === setlocale(LC_NUMERIC, $requiredLocales)) { 57 | $this->markTestSkipped('Could not set any of required locales: '.implode(', ', $requiredLocales)); 58 | } 59 | 60 | $this->assertEquals('1.2', Inline::dump(1.2)); 61 | $this->assertContains('fr', strtolower(setlocale(LC_NUMERIC, 0))); 62 | setlocale(LC_NUMERIC, $locale); 63 | } catch (\Exception $e) { 64 | setlocale(LC_NUMERIC, $locale); 65 | throw $e; 66 | } 67 | } 68 | 69 | public function testHashStringsResemblingExponentialNumericsShouldNotBeChangedToINF() 70 | { 71 | $value = '686e444'; 72 | 73 | $this->assertSame($value, Inline::parse(Inline::dump($value))); 74 | } 75 | 76 | /** 77 | * @group legacy 78 | * throws \Symfony\Component\Yaml\Exception\ParseException in 3.0 79 | */ 80 | public function testParseScalarWithNonEscapedBlackslashShouldThrowException() 81 | { 82 | $this->assertSame('Foo\Var', Inline::parse('"Foo\Var"')); 83 | } 84 | 85 | /** 86 | * @expectedException \Symfony\Component\Yaml\Exception\ParseException 87 | */ 88 | public function testParseScalarWithNonEscapedBlackslashAtTheEndShouldThrowException() 89 | { 90 | Inline::parse('"Foo\\"'); 91 | } 92 | 93 | /** 94 | * @expectedException \Symfony\Component\Yaml\Exception\ParseException 95 | */ 96 | public function testParseScalarWithIncorrectlyQuotedStringShouldThrowException() 97 | { 98 | $value = "'don't do somthin' like that'"; 99 | Inline::parse($value); 100 | } 101 | 102 | /** 103 | * @expectedException \Symfony\Component\Yaml\Exception\ParseException 104 | */ 105 | public function testParseScalarWithIncorrectlyDoubleQuotedStringShouldThrowException() 106 | { 107 | $value = '"don"t do somthin" like that"'; 108 | Inline::parse($value); 109 | } 110 | 111 | /** 112 | * @expectedException \Symfony\Component\Yaml\Exception\ParseException 113 | */ 114 | public function testParseInvalidMappingKeyShouldThrowException() 115 | { 116 | $value = '{ "foo " bar": "bar" }'; 117 | Inline::parse($value); 118 | } 119 | 120 | /** 121 | * @expectedException \Symfony\Component\Yaml\Exception\ParseException 122 | */ 123 | public function testParseInvalidMappingShouldThrowException() 124 | { 125 | Inline::parse('[foo] bar'); 126 | } 127 | 128 | /** 129 | * @expectedException \Symfony\Component\Yaml\Exception\ParseException 130 | */ 131 | public function testParseInvalidSequenceShouldThrowException() 132 | { 133 | Inline::parse('{ foo: bar } bar'); 134 | } 135 | 136 | public function testParseScalarWithCorrectlyQuotedStringShouldReturnString() 137 | { 138 | $value = "'don''t do somthin'' like that'"; 139 | $expect = "don't do somthin' like that"; 140 | 141 | $this->assertSame($expect, Inline::parseScalar($value)); 142 | } 143 | 144 | /** 145 | * @dataProvider getDataForParseReferences 146 | */ 147 | public function testParseReferences($yaml, $expected) 148 | { 149 | $this->assertSame($expected, Inline::parse($yaml, false, false, false, array('var' => 'var-value'))); 150 | } 151 | 152 | public function getDataForParseReferences() 153 | { 154 | return array( 155 | 'scalar' => array('*var', 'var-value'), 156 | 'list' => array('[ *var ]', array('var-value')), 157 | 'list-in-list' => array('[[ *var ]]', array(array('var-value'))), 158 | 'map-in-list' => array('[ { key: *var } ]', array(array('key' => 'var-value'))), 159 | 'embedded-mapping-in-list' => array('[ key: *var ]', array(array('key' => 'var-value'))), 160 | 'map' => array('{ key: *var }', array('key' => 'var-value')), 161 | 'list-in-map' => array('{ key: [*var] }', array('key' => array('var-value'))), 162 | 'map-in-map' => array('{ foo: { bar: *var } }', array('foo' => array('bar' => 'var-value'))), 163 | ); 164 | } 165 | 166 | public function testParseMapReferenceInSequence() 167 | { 168 | $foo = array( 169 | 'a' => 'Steve', 170 | 'b' => 'Clark', 171 | 'c' => 'Brian', 172 | ); 173 | $this->assertSame(array($foo), Inline::parse('[*foo]', false, false, false, array('foo' => $foo))); 174 | } 175 | 176 | /** 177 | * @expectedException \Symfony\Component\Yaml\Exception\ParseException 178 | * @expectedExceptionMessage A reference must contain at least one character. 179 | */ 180 | public function testParseUnquotedAsterisk() 181 | { 182 | Inline::parse('{ foo: * }'); 183 | } 184 | 185 | /** 186 | * @expectedException \Symfony\Component\Yaml\Exception\ParseException 187 | * @expectedExceptionMessage A reference must contain at least one character. 188 | */ 189 | public function testParseUnquotedAsteriskFollowedByAComment() 190 | { 191 | Inline::parse('{ foo: * #foo }'); 192 | } 193 | 194 | /** 195 | * @group legacy 196 | * @expectedDeprecation Not quoting the scalar "@foo " starting with "@" is deprecated since Symfony 2.8 and will throw a ParseException in 3.0. 197 | * throws \Symfony\Component\Yaml\Exception\ParseException in 3.0 198 | */ 199 | public function testParseUnquotedScalarStartingWithReservedAtIndicator() 200 | { 201 | Inline::parse('{ foo: @foo }'); 202 | } 203 | 204 | /** 205 | * @group legacy 206 | * @expectedDeprecation Not quoting the scalar "`foo " starting with "`" is deprecated since Symfony 2.8 and will throw a ParseException in 3.0. 207 | * throws \Symfony\Component\Yaml\Exception\ParseException in 3.0 208 | */ 209 | public function testParseUnquotedScalarStartingWithReservedBacktickIndicator() 210 | { 211 | Inline::parse('{ foo: `foo }'); 212 | } 213 | 214 | /** 215 | * @group legacy 216 | * @expectedDeprecation Not quoting the scalar "|foo " starting with "|" is deprecated since Symfony 2.8 and will throw a ParseException in 3.0. 217 | * throws \Symfony\Component\Yaml\Exception\ParseException in 3.0 218 | */ 219 | public function testParseUnquotedScalarStartingWithLiteralStyleIndicator() 220 | { 221 | Inline::parse('{ foo: |foo }'); 222 | } 223 | 224 | /** 225 | * @group legacy 226 | * @expectedDeprecation Not quoting the scalar ">foo " starting with ">" is deprecated since Symfony 2.8 and will throw a ParseException in 3.0. 227 | * throws \Symfony\Component\Yaml\Exception\ParseException in 3.0 228 | */ 229 | public function testParseUnquotedScalarStartingWithFoldedStyleIndicator() 230 | { 231 | Inline::parse('{ foo: >foo }'); 232 | } 233 | 234 | public function getScalarIndicators() 235 | { 236 | return array(array('|'), array('>')); 237 | } 238 | 239 | /** 240 | * @dataProvider getDataForIsHash 241 | */ 242 | public function testIsHash($array, $expected) 243 | { 244 | $this->assertSame($expected, Inline::isHash($array)); 245 | } 246 | 247 | public function getDataForIsHash() 248 | { 249 | return array( 250 | array(array(), false), 251 | array(array(1, 2, 3), false), 252 | array(array(2 => 1, 1 => 2, 0 => 3), true), 253 | array(array('foo' => 1, 'bar' => 2), true), 254 | ); 255 | } 256 | 257 | public function getTestsForParse() 258 | { 259 | return array( 260 | array('', ''), 261 | array('null', null), 262 | array('false', false), 263 | array('true', true), 264 | array('12', 12), 265 | array('-12', -12), 266 | array('"quoted string"', 'quoted string'), 267 | array("'quoted string'", 'quoted string'), 268 | array('12.30e+02', 12.30e+02), 269 | array('0x4D2', 0x4D2), 270 | array('02333', 02333), 271 | array('.Inf', -log(0)), 272 | array('-.Inf', log(0)), 273 | array("'686e444'", '686e444'), 274 | array('686e444', 646e444), 275 | array('123456789123456789123456789123456789', '123456789123456789123456789123456789'), 276 | array('"foo\r\nbar"', "foo\r\nbar"), 277 | array("'foo#bar'", 'foo#bar'), 278 | array("'foo # bar'", 'foo # bar'), 279 | array("'#cfcfcf'", '#cfcfcf'), 280 | array('::form_base.html.twig', '::form_base.html.twig'), 281 | 282 | // Pre-YAML-1.2 booleans 283 | array("'y'", 'y'), 284 | array("'n'", 'n'), 285 | array("'yes'", 'yes'), 286 | array("'no'", 'no'), 287 | array("'on'", 'on'), 288 | array("'off'", 'off'), 289 | 290 | array('2007-10-30', gmmktime(0, 0, 0, 10, 30, 2007)), 291 | array('2007-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 2007)), 292 | array('2007-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 2007)), 293 | array('1960-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 1960)), 294 | array('1730-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 1730)), 295 | 296 | array('"a \\"string\\" with \'quoted strings inside\'"', 'a "string" with \'quoted strings inside\''), 297 | array("'a \"string\" with ''quoted strings inside'''", 'a "string" with \'quoted strings inside\''), 298 | 299 | // sequences 300 | // urls are no key value mapping. see #3609. Valid yaml "key: value" mappings require a space after the colon 301 | array('[foo, http://urls.are/no/mappings, false, null, 12]', array('foo', 'http://urls.are/no/mappings', false, null, 12)), 302 | array('[ foo , bar , false , null , 12 ]', array('foo', 'bar', false, null, 12)), 303 | array('[\'foo,bar\', \'foo bar\']', array('foo,bar', 'foo bar')), 304 | 305 | // mappings 306 | array('{foo:bar,bar:foo,false:false,null:null,integer:12}', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)), 307 | array('{ foo : bar, bar : foo, false : false, null : null, integer : 12 }', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)), 308 | array('{foo: \'bar\', bar: \'foo: bar\'}', array('foo' => 'bar', 'bar' => 'foo: bar')), 309 | array('{\'foo\': \'bar\', "bar": \'foo: bar\'}', array('foo' => 'bar', 'bar' => 'foo: bar')), 310 | array('{\'foo\'\'\': \'bar\', "bar\"": \'foo: bar\'}', array('foo\'' => 'bar', 'bar"' => 'foo: bar')), 311 | array('{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}', array('foo: ' => 'bar', 'bar: ' => 'foo: bar')), 312 | 313 | // nested sequences and mappings 314 | array('[foo, [bar, foo]]', array('foo', array('bar', 'foo'))), 315 | array('[foo, {bar: foo}]', array('foo', array('bar' => 'foo'))), 316 | array('{ foo: {bar: foo} }', array('foo' => array('bar' => 'foo'))), 317 | array('{ foo: [bar, foo] }', array('foo' => array('bar', 'foo'))), 318 | 319 | array('[ foo, [ bar, foo ] ]', array('foo', array('bar', 'foo'))), 320 | 321 | array('[{ foo: {bar: foo} }]', array(array('foo' => array('bar' => 'foo')))), 322 | 323 | array('[foo, [bar, [foo, [bar, foo]], foo]]', array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo'))), 324 | 325 | array('[foo, {bar: foo, foo: [foo, {bar: foo}]}, [foo, {bar: foo}]]', array('foo', array('bar' => 'foo', 'foo' => array('foo', array('bar' => 'foo'))), array('foo', array('bar' => 'foo')))), 326 | 327 | array('[foo, bar: { foo: bar }]', array('foo', '1' => array('bar' => array('foo' => 'bar')))), 328 | array('[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']', array('foo', '@foo.baz', array('%foo%' => 'foo is %foo%', 'bar' => '%foo%'), true, '@service_container')), 329 | ); 330 | } 331 | 332 | public function getTestsForParseWithMapObjects() 333 | { 334 | return array( 335 | array('', ''), 336 | array('null', null), 337 | array('false', false), 338 | array('true', true), 339 | array('12', 12), 340 | array('-12', -12), 341 | array('"quoted string"', 'quoted string'), 342 | array("'quoted string'", 'quoted string'), 343 | array('12.30e+02', 12.30e+02), 344 | array('0x4D2', 0x4D2), 345 | array('02333', 02333), 346 | array('.Inf', -log(0)), 347 | array('-.Inf', log(0)), 348 | array("'686e444'", '686e444'), 349 | array('686e444', 646e444), 350 | array('123456789123456789123456789123456789', '123456789123456789123456789123456789'), 351 | array('"foo\r\nbar"', "foo\r\nbar"), 352 | array("'foo#bar'", 'foo#bar'), 353 | array("'foo # bar'", 'foo # bar'), 354 | array("'#cfcfcf'", '#cfcfcf'), 355 | array('::form_base.html.twig', '::form_base.html.twig'), 356 | 357 | array('2007-10-30', gmmktime(0, 0, 0, 10, 30, 2007)), 358 | array('2007-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 2007)), 359 | array('2007-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 2007)), 360 | array('1960-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 1960)), 361 | array('1730-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 1730)), 362 | 363 | array('"a \\"string\\" with \'quoted strings inside\'"', 'a "string" with \'quoted strings inside\''), 364 | array("'a \"string\" with ''quoted strings inside'''", 'a "string" with \'quoted strings inside\''), 365 | 366 | // sequences 367 | // urls are no key value mapping. see #3609. Valid yaml "key: value" mappings require a space after the colon 368 | array('[foo, http://urls.are/no/mappings, false, null, 12]', array('foo', 'http://urls.are/no/mappings', false, null, 12)), 369 | array('[ foo , bar , false , null , 12 ]', array('foo', 'bar', false, null, 12)), 370 | array('[\'foo,bar\', \'foo bar\']', array('foo,bar', 'foo bar')), 371 | 372 | // mappings 373 | array('{foo:bar,bar:foo,false:false,null:null,integer:12}', (object) array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)), 374 | array('{ foo : bar, bar : foo, false : false, null : null, integer : 12 }', (object) array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)), 375 | array('{foo: \'bar\', bar: \'foo: bar\'}', (object) array('foo' => 'bar', 'bar' => 'foo: bar')), 376 | array('{\'foo\': \'bar\', "bar": \'foo: bar\'}', (object) array('foo' => 'bar', 'bar' => 'foo: bar')), 377 | array('{\'foo\'\'\': \'bar\', "bar\"": \'foo: bar\'}', (object) array('foo\'' => 'bar', 'bar"' => 'foo: bar')), 378 | array('{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}', (object) array('foo: ' => 'bar', 'bar: ' => 'foo: bar')), 379 | 380 | // nested sequences and mappings 381 | array('[foo, [bar, foo]]', array('foo', array('bar', 'foo'))), 382 | array('[foo, {bar: foo}]', array('foo', (object) array('bar' => 'foo'))), 383 | array('{ foo: {bar: foo} }', (object) array('foo' => (object) array('bar' => 'foo'))), 384 | array('{ foo: [bar, foo] }', (object) array('foo' => array('bar', 'foo'))), 385 | 386 | array('[ foo, [ bar, foo ] ]', array('foo', array('bar', 'foo'))), 387 | 388 | array('[{ foo: {bar: foo} }]', array((object) array('foo' => (object) array('bar' => 'foo')))), 389 | 390 | array('[foo, [bar, [foo, [bar, foo]], foo]]', array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo'))), 391 | 392 | array('[foo, {bar: foo, foo: [foo, {bar: foo}]}, [foo, {bar: foo}]]', array('foo', (object) array('bar' => 'foo', 'foo' => array('foo', (object) array('bar' => 'foo'))), array('foo', (object) array('bar' => 'foo')))), 393 | 394 | array('[foo, bar: { foo: bar }]', array('foo', '1' => (object) array('bar' => (object) array('foo' => 'bar')))), 395 | array('[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']', array('foo', '@foo.baz', (object) array('%foo%' => 'foo is %foo%', 'bar' => '%foo%'), true, '@service_container')), 396 | 397 | array('{}', new \stdClass()), 398 | array('{ foo : bar, bar : {} }', (object) array('foo' => 'bar', 'bar' => new \stdClass())), 399 | array('{ foo : [], bar : {} }', (object) array('foo' => array(), 'bar' => new \stdClass())), 400 | array('{foo: \'bar\', bar: {} }', (object) array('foo' => 'bar', 'bar' => new \stdClass())), 401 | array('{\'foo\': \'bar\', "bar": {}}', (object) array('foo' => 'bar', 'bar' => new \stdClass())), 402 | array('{\'foo\': \'bar\', "bar": \'{}\'}', (object) array('foo' => 'bar', 'bar' => '{}')), 403 | 404 | array('[foo, [{}, {}]]', array('foo', array(new \stdClass(), new \stdClass()))), 405 | array('[foo, [[], {}]]', array('foo', array(array(), new \stdClass()))), 406 | array('[foo, [[{}, {}], {}]]', array('foo', array(array(new \stdClass(), new \stdClass()), new \stdClass()))), 407 | array('[foo, {bar: {}}]', array('foo', '1' => (object) array('bar' => new \stdClass()))), 408 | ); 409 | } 410 | 411 | public function getTestsForDump() 412 | { 413 | return array( 414 | array('null', null), 415 | array('false', false), 416 | array('true', true), 417 | array('12', 12), 418 | array("'quoted string'", 'quoted string'), 419 | array('!!float 1230', 12.30e+02), 420 | array('1234', 0x4D2), 421 | array('1243', 02333), 422 | array('.Inf', -log(0)), 423 | array('-.Inf', log(0)), 424 | array("'686e444'", '686e444'), 425 | array('"foo\r\nbar"', "foo\r\nbar"), 426 | array("'foo#bar'", 'foo#bar'), 427 | array("'foo # bar'", 'foo # bar'), 428 | array("'#cfcfcf'", '#cfcfcf'), 429 | 430 | array("'a \"string\" with ''quoted strings inside'''", 'a "string" with \'quoted strings inside\''), 431 | 432 | array("'-dash'", '-dash'), 433 | array("'-'", '-'), 434 | 435 | // Pre-YAML-1.2 booleans 436 | array("'y'", 'y'), 437 | array("'n'", 'n'), 438 | array("'yes'", 'yes'), 439 | array("'no'", 'no'), 440 | array("'on'", 'on'), 441 | array("'off'", 'off'), 442 | 443 | // sequences 444 | array('[foo, bar, false, null, 12]', array('foo', 'bar', false, null, 12)), 445 | array('[\'foo,bar\', \'foo bar\']', array('foo,bar', 'foo bar')), 446 | 447 | // mappings 448 | array('{ foo: bar, bar: foo, \'false\': false, \'null\': null, integer: 12 }', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)), 449 | array('{ foo: bar, bar: \'foo: bar\' }', array('foo' => 'bar', 'bar' => 'foo: bar')), 450 | 451 | // nested sequences and mappings 452 | array('[foo, [bar, foo]]', array('foo', array('bar', 'foo'))), 453 | 454 | array('[foo, [bar, [foo, [bar, foo]], foo]]', array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo'))), 455 | 456 | array('{ foo: { bar: foo } }', array('foo' => array('bar' => 'foo'))), 457 | 458 | array('[foo, { bar: foo }]', array('foo', array('bar' => 'foo'))), 459 | 460 | array('[foo, { bar: foo, foo: [foo, { bar: foo }] }, [foo, { bar: foo }]]', array('foo', array('bar' => 'foo', 'foo' => array('foo', array('bar' => 'foo'))), array('foo', array('bar' => 'foo')))), 461 | 462 | array('[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']', array('foo', '@foo.baz', array('%foo%' => 'foo is %foo%', 'bar' => '%foo%'), true, '@service_container')), 463 | 464 | array('{ foo: { bar: { 1: 2, baz: 3 } } }', array('foo' => array('bar' => array(1 => 2, 'baz' => 3)))), 465 | ); 466 | } 467 | 468 | /** 469 | * @expectedException \Symfony\Component\Yaml\Exception\ParseException 470 | * @expectedExceptionMessage Malformed inline YAML string: {this, is not, supported}. 471 | */ 472 | public function testNotSupportedMissingValue() 473 | { 474 | Inline::parse('{this, is not, supported}'); 475 | } 476 | 477 | public function testVeryLongQuotedStrings() 478 | { 479 | $longStringWithQuotes = str_repeat("x\r\n\\\"x\"x", 1000); 480 | 481 | $yamlString = Inline::dump(array('longStringWithQuotes' => $longStringWithQuotes)); 482 | $arrayFromYaml = Inline::parse($yamlString); 483 | 484 | $this->assertEquals($longStringWithQuotes, $arrayFromYaml['longStringWithQuotes']); 485 | } 486 | 487 | public function testBooleanMappingKeysAreConvertedToStrings() 488 | { 489 | $this->assertSame(array('false' => 'foo'), Inline::parse('{false: foo}')); 490 | $this->assertSame(array('true' => 'foo'), Inline::parse('{true: foo}')); 491 | } 492 | 493 | public function testTheEmptyStringIsAValidMappingKey() 494 | { 495 | $this->assertSame(array('' => 'foo'), Inline::parse('{ "": foo }')); 496 | } 497 | } 498 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Inline.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Symfony\Component\Yaml; 13 | 14 | use Symfony\Component\Yaml\Exception\ParseException; 15 | use Symfony\Component\Yaml\Exception\DumpException; 16 | 17 | /** 18 | * Inline implements a YAML parser/dumper for the YAML inline syntax. 19 | * 20 | * @author Fabien Potencier 21 | */ 22 | class Inline 23 | { 24 | const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*+(?:\\\\.[^"\\\\]*+)*+)"|\'([^\']*+(?:\'\'[^\']*+)*+)\')'; 25 | 26 | private static $exceptionOnInvalidType = false; 27 | private static $objectSupport = false; 28 | private static $objectForMap = false; 29 | 30 | /** 31 | * Converts a YAML string to a PHP value. 32 | * 33 | * @param string $value A YAML string 34 | * @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise 35 | * @param bool $objectSupport true if object support is enabled, false otherwise 36 | * @param bool $objectForMap true if maps should return a stdClass instead of array() 37 | * @param array $references Mapping of variable names to values 38 | * 39 | * @return mixed A PHP value 40 | * 41 | * @throws ParseException 42 | */ 43 | public static function parse($value, $exceptionOnInvalidType = false, $objectSupport = false, $objectForMap = false, $references = array()) 44 | { 45 | self::$exceptionOnInvalidType = $exceptionOnInvalidType; 46 | self::$objectSupport = $objectSupport; 47 | self::$objectForMap = $objectForMap; 48 | 49 | $value = trim($value); 50 | 51 | if ('' === $value) { 52 | return ''; 53 | } 54 | 55 | if (2 /* MB_OVERLOAD_STRING */ & (int) ini_get('mbstring.func_overload')) { 56 | $mbEncoding = mb_internal_encoding(); 57 | mb_internal_encoding('ASCII'); 58 | } 59 | 60 | $i = 0; 61 | switch ($value[0]) { 62 | case '[': 63 | $result = self::parseSequence($value, $i, $references); 64 | ++$i; 65 | break; 66 | case '{': 67 | $result = self::parseMapping($value, $i, $references); 68 | ++$i; 69 | break; 70 | default: 71 | $result = self::parseScalar($value, null, array('"', "'"), $i, true, $references); 72 | } 73 | 74 | // some comments are allowed at the end 75 | if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) { 76 | throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i))); 77 | } 78 | 79 | if (isset($mbEncoding)) { 80 | mb_internal_encoding($mbEncoding); 81 | } 82 | 83 | return $result; 84 | } 85 | 86 | /** 87 | * Dumps a given PHP variable to a YAML string. 88 | * 89 | * @param mixed $value The PHP variable to convert 90 | * @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise 91 | * @param bool $objectSupport true if object support is enabled, false otherwise 92 | * 93 | * @return string The YAML string representing the PHP value 94 | * 95 | * @throws DumpException When trying to dump PHP resource 96 | */ 97 | public static function dump($value, $exceptionOnInvalidType = false, $objectSupport = false) 98 | { 99 | switch (true) { 100 | case is_resource($value): 101 | if ($exceptionOnInvalidType) { 102 | throw new DumpException(sprintf('Unable to dump PHP resources in a YAML file ("%s").', get_resource_type($value))); 103 | } 104 | 105 | return 'null'; 106 | case is_object($value): 107 | if ($objectSupport) { 108 | return '!php/object:'.serialize($value); 109 | } 110 | 111 | if ($exceptionOnInvalidType) { 112 | throw new DumpException('Object support when dumping a YAML file has been disabled.'); 113 | } 114 | 115 | return 'null'; 116 | case is_array($value): 117 | return self::dumpArray($value, $exceptionOnInvalidType, $objectSupport); 118 | case null === $value: 119 | return 'null'; 120 | case true === $value: 121 | return 'true'; 122 | case false === $value: 123 | return 'false'; 124 | case ctype_digit($value): 125 | return is_string($value) ? "'$value'" : (int) $value; 126 | case is_numeric($value): 127 | $locale = setlocale(LC_NUMERIC, 0); 128 | if (false !== $locale) { 129 | setlocale(LC_NUMERIC, 'C'); 130 | } 131 | if (is_float($value)) { 132 | $repr = (string) $value; 133 | if (is_infinite($value)) { 134 | $repr = str_ireplace('INF', '.Inf', $repr); 135 | } elseif (floor($value) == $value && $repr == $value) { 136 | // Preserve float data type since storing a whole number will result in integer value. 137 | $repr = '!!float '.$repr; 138 | } 139 | } else { 140 | $repr = is_string($value) ? "'$value'" : (string) $value; 141 | } 142 | if (false !== $locale) { 143 | setlocale(LC_NUMERIC, $locale); 144 | } 145 | 146 | return $repr; 147 | case '' == $value: 148 | return "''"; 149 | case Escaper::requiresDoubleQuoting($value): 150 | return Escaper::escapeWithDoubleQuotes($value); 151 | case Escaper::requiresSingleQuoting($value): 152 | case Parser::preg_match(self::getHexRegex(), $value): 153 | case Parser::preg_match(self::getTimestampRegex(), $value): 154 | return Escaper::escapeWithSingleQuotes($value); 155 | default: 156 | return $value; 157 | } 158 | } 159 | 160 | /** 161 | * Check if given array is hash or just normal indexed array. 162 | * 163 | * @internal 164 | * 165 | * @param array $value The PHP array to check 166 | * 167 | * @return bool true if value is hash array, false otherwise 168 | */ 169 | public static function isHash(array $value) 170 | { 171 | $expectedKey = 0; 172 | 173 | foreach ($value as $key => $val) { 174 | if ($key !== $expectedKey++) { 175 | return true; 176 | } 177 | } 178 | 179 | return false; 180 | } 181 | 182 | /** 183 | * Dumps a PHP array to a YAML string. 184 | * 185 | * @param array $value The PHP array to dump 186 | * @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise 187 | * @param bool $objectSupport true if object support is enabled, false otherwise 188 | * 189 | * @return string The YAML string representing the PHP array 190 | */ 191 | private static function dumpArray($value, $exceptionOnInvalidType, $objectSupport) 192 | { 193 | // array 194 | if ($value && !self::isHash($value)) { 195 | $output = array(); 196 | foreach ($value as $val) { 197 | $output[] = self::dump($val, $exceptionOnInvalidType, $objectSupport); 198 | } 199 | 200 | return sprintf('[%s]', implode(', ', $output)); 201 | } 202 | 203 | // hash 204 | $output = array(); 205 | foreach ($value as $key => $val) { 206 | $output[] = sprintf('%s: %s', self::dump($key, $exceptionOnInvalidType, $objectSupport), self::dump($val, $exceptionOnInvalidType, $objectSupport)); 207 | } 208 | 209 | return sprintf('{ %s }', implode(', ', $output)); 210 | } 211 | 212 | /** 213 | * Parses a YAML scalar. 214 | * 215 | * @param string $scalar 216 | * @param string[] $delimiters 217 | * @param string[] $stringDelimiters 218 | * @param int &$i 219 | * @param bool $evaluate 220 | * @param array $references 221 | * 222 | * @return string 223 | * 224 | * @throws ParseException When malformed inline YAML string is parsed 225 | * 226 | * @internal 227 | */ 228 | public static function parseScalar($scalar, $delimiters = null, $stringDelimiters = array('"', "'"), &$i = 0, $evaluate = true, $references = array()) 229 | { 230 | if (in_array($scalar[$i], $stringDelimiters)) { 231 | // quoted scalar 232 | $output = self::parseQuotedScalar($scalar, $i); 233 | 234 | if (null !== $delimiters) { 235 | $tmp = ltrim(substr($scalar, $i), ' '); 236 | if (!in_array($tmp[0], $delimiters)) { 237 | throw new ParseException(sprintf('Unexpected characters (%s).', substr($scalar, $i))); 238 | } 239 | } 240 | } else { 241 | // "normal" string 242 | if (!$delimiters) { 243 | $output = substr($scalar, $i); 244 | $i += strlen($output); 245 | 246 | // remove comments 247 | if (Parser::preg_match('/[ \t]+#/', $output, $match, PREG_OFFSET_CAPTURE)) { 248 | $output = substr($output, 0, $match[0][1]); 249 | } 250 | } elseif (Parser::preg_match('/^(.+?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) { 251 | $output = $match[1]; 252 | $i += strlen($output); 253 | } else { 254 | throw new ParseException(sprintf('Malformed inline YAML string: %s.', $scalar)); 255 | } 256 | 257 | // a non-quoted string cannot start with @ or ` (reserved) nor with a scalar indicator (| or >) 258 | if ($output && ('@' === $output[0] || '`' === $output[0] || '|' === $output[0] || '>' === $output[0])) { 259 | @trigger_error(sprintf('Not quoting the scalar "%s" starting with "%s" is deprecated since Symfony 2.8 and will throw a ParseException in 3.0.', $output, $output[0]), E_USER_DEPRECATED); 260 | 261 | // to be thrown in 3.0 262 | // throw new ParseException(sprintf('The reserved indicator "%s" cannot start a plain scalar; you need to quote the scalar.', $output[0])); 263 | } 264 | 265 | if ($evaluate) { 266 | $output = self::evaluateScalar($output, $references); 267 | } 268 | } 269 | 270 | return $output; 271 | } 272 | 273 | /** 274 | * Parses a YAML quoted scalar. 275 | * 276 | * @param string $scalar 277 | * @param int &$i 278 | * 279 | * @return string 280 | * 281 | * @throws ParseException When malformed inline YAML string is parsed 282 | */ 283 | private static function parseQuotedScalar($scalar, &$i) 284 | { 285 | if (!Parser::preg_match('/'.self::REGEX_QUOTED_STRING.'/Au', substr($scalar, $i), $match)) { 286 | throw new ParseException(sprintf('Malformed inline YAML string: %s.', substr($scalar, $i))); 287 | } 288 | 289 | $output = substr($match[0], 1, strlen($match[0]) - 2); 290 | 291 | $unescaper = new Unescaper(); 292 | if ('"' == $scalar[$i]) { 293 | $output = $unescaper->unescapeDoubleQuotedString($output); 294 | } else { 295 | $output = $unescaper->unescapeSingleQuotedString($output); 296 | } 297 | 298 | $i += strlen($match[0]); 299 | 300 | return $output; 301 | } 302 | 303 | /** 304 | * Parses a YAML sequence. 305 | * 306 | * @param string $sequence 307 | * @param int &$i 308 | * @param array $references 309 | * 310 | * @return array 311 | * 312 | * @throws ParseException When malformed inline YAML string is parsed 313 | */ 314 | private static function parseSequence($sequence, &$i = 0, $references = array()) 315 | { 316 | $output = array(); 317 | $len = strlen($sequence); 318 | ++$i; 319 | 320 | // [foo, bar, ...] 321 | while ($i < $len) { 322 | switch ($sequence[$i]) { 323 | case '[': 324 | // nested sequence 325 | $output[] = self::parseSequence($sequence, $i, $references); 326 | break; 327 | case '{': 328 | // nested mapping 329 | $output[] = self::parseMapping($sequence, $i, $references); 330 | break; 331 | case ']': 332 | return $output; 333 | case ',': 334 | case ' ': 335 | break; 336 | default: 337 | $isQuoted = in_array($sequence[$i], array('"', "'")); 338 | $value = self::parseScalar($sequence, array(',', ']'), array('"', "'"), $i, true, $references); 339 | 340 | // the value can be an array if a reference has been resolved to an array var 341 | if (!is_array($value) && !$isQuoted && false !== strpos($value, ': ')) { 342 | // embedded mapping? 343 | try { 344 | $pos = 0; 345 | $value = self::parseMapping('{'.$value.'}', $pos, $references); 346 | } catch (\InvalidArgumentException $e) { 347 | // no, it's not 348 | } 349 | } 350 | 351 | $output[] = $value; 352 | 353 | --$i; 354 | } 355 | 356 | ++$i; 357 | } 358 | 359 | throw new ParseException(sprintf('Malformed inline YAML string: %s.', $sequence)); 360 | } 361 | 362 | /** 363 | * Parses a YAML mapping. 364 | * 365 | * @param string $mapping 366 | * @param int &$i 367 | * @param array $references 368 | * 369 | * @return array|\stdClass 370 | * 371 | * @throws ParseException When malformed inline YAML string is parsed 372 | */ 373 | private static function parseMapping($mapping, &$i = 0, $references = array()) 374 | { 375 | $output = array(); 376 | $len = strlen($mapping); 377 | ++$i; 378 | 379 | // {foo: bar, bar:foo, ...} 380 | while ($i < $len) { 381 | switch ($mapping[$i]) { 382 | case ' ': 383 | case ',': 384 | ++$i; 385 | continue 2; 386 | case '}': 387 | if (self::$objectForMap) { 388 | return (object) $output; 389 | } 390 | 391 | return $output; 392 | } 393 | 394 | // key 395 | $key = self::parseScalar($mapping, array(':', ' '), array('"', "'"), $i, false); 396 | 397 | // value 398 | $done = false; 399 | 400 | while ($i < $len) { 401 | switch ($mapping[$i]) { 402 | case '[': 403 | // nested sequence 404 | $value = self::parseSequence($mapping, $i, $references); 405 | // Spec: Keys MUST be unique; first one wins. 406 | // Parser cannot abort this mapping earlier, since lines 407 | // are processed sequentially. 408 | if (!isset($output[$key])) { 409 | $output[$key] = $value; 410 | } 411 | $done = true; 412 | break; 413 | case '{': 414 | // nested mapping 415 | $value = self::parseMapping($mapping, $i, $references); 416 | // Spec: Keys MUST be unique; first one wins. 417 | // Parser cannot abort this mapping earlier, since lines 418 | // are processed sequentially. 419 | if (!isset($output[$key])) { 420 | $output[$key] = $value; 421 | } 422 | $done = true; 423 | break; 424 | case ':': 425 | case ' ': 426 | break; 427 | default: 428 | $value = self::parseScalar($mapping, array(',', '}'), array('"', "'"), $i, true, $references); 429 | // Spec: Keys MUST be unique; first one wins. 430 | // Parser cannot abort this mapping earlier, since lines 431 | // are processed sequentially. 432 | if (!isset($output[$key])) { 433 | $output[$key] = $value; 434 | } 435 | $done = true; 436 | --$i; 437 | } 438 | 439 | ++$i; 440 | 441 | if ($done) { 442 | continue 2; 443 | } 444 | } 445 | } 446 | 447 | throw new ParseException(sprintf('Malformed inline YAML string: %s.', $mapping)); 448 | } 449 | 450 | /** 451 | * Evaluates scalars and replaces magic values. 452 | * 453 | * @param string $scalar 454 | * @param array $references 455 | * 456 | * @return mixed The evaluated YAML string 457 | * 458 | * @throws ParseException when object parsing support was disabled and the parser detected a PHP object or when a reference could not be resolved 459 | */ 460 | private static function evaluateScalar($scalar, $references = array()) 461 | { 462 | $scalar = trim($scalar); 463 | $scalarLower = strtolower($scalar); 464 | 465 | if (0 === strpos($scalar, '*')) { 466 | if (false !== $pos = strpos($scalar, '#')) { 467 | $value = substr($scalar, 1, $pos - 2); 468 | } else { 469 | $value = substr($scalar, 1); 470 | } 471 | 472 | // an unquoted * 473 | if (false === $value || '' === $value) { 474 | throw new ParseException('A reference must contain at least one character.'); 475 | } 476 | 477 | if (!array_key_exists($value, $references)) { 478 | throw new ParseException(sprintf('Reference "%s" does not exist.', $value)); 479 | } 480 | 481 | return $references[$value]; 482 | } 483 | 484 | switch (true) { 485 | case 'null' === $scalarLower: 486 | case '' === $scalar: 487 | case '~' === $scalar: 488 | return; 489 | case 'true' === $scalarLower: 490 | return true; 491 | case 'false' === $scalarLower: 492 | return false; 493 | // Optimise for returning strings. 494 | case $scalar[0] === '+' || $scalar[0] === '-' || $scalar[0] === '.' || $scalar[0] === '!' || is_numeric($scalar[0]): 495 | switch (true) { 496 | case 0 === strpos($scalar, '!str'): 497 | return (string) substr($scalar, 5); 498 | case 0 === strpos($scalar, '! '): 499 | return (int) self::parseScalar(substr($scalar, 2)); 500 | case 0 === strpos($scalar, '!php/object:'): 501 | if (self::$objectSupport) { 502 | return unserialize(substr($scalar, 12)); 503 | } 504 | 505 | if (self::$exceptionOnInvalidType) { 506 | throw new ParseException('Object support when parsing a YAML file has been disabled.'); 507 | } 508 | 509 | return; 510 | case 0 === strpos($scalar, '!!php/object:'): 511 | if (self::$objectSupport) { 512 | return unserialize(substr($scalar, 13)); 513 | } 514 | 515 | if (self::$exceptionOnInvalidType) { 516 | throw new ParseException('Object support when parsing a YAML file has been disabled.'); 517 | } 518 | 519 | return; 520 | case 0 === strpos($scalar, '!!float '): 521 | return (float) substr($scalar, 8); 522 | case ctype_digit($scalar): 523 | $raw = $scalar; 524 | $cast = (int) $scalar; 525 | 526 | return '0' == $scalar[0] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw); 527 | case '-' === $scalar[0] && ctype_digit(substr($scalar, 1)): 528 | $raw = $scalar; 529 | $cast = (int) $scalar; 530 | 531 | return '0' == $scalar[1] ? octdec($scalar) : (((string) $raw === (string) $cast) ? $cast : $raw); 532 | case is_numeric($scalar): 533 | case Parser::preg_match(self::getHexRegex(), $scalar): 534 | return '0x' === $scalar[0].$scalar[1] ? hexdec($scalar) : (float) $scalar; 535 | case '.inf' === $scalarLower: 536 | case '.nan' === $scalarLower: 537 | return -log(0); 538 | case '-.inf' === $scalarLower: 539 | return log(0); 540 | case Parser::preg_match('/^(-|\+)?[0-9,]+(\.[0-9]+)?$/', $scalar): 541 | return (float) str_replace(',', '', $scalar); 542 | case Parser::preg_match(self::getTimestampRegex(), $scalar): 543 | $timeZone = date_default_timezone_get(); 544 | date_default_timezone_set('UTC'); 545 | $time = strtotime($scalar); 546 | date_default_timezone_set($timeZone); 547 | 548 | return $time; 549 | } 550 | default: 551 | return (string) $scalar; 552 | } 553 | } 554 | 555 | /** 556 | * Gets a regex that matches a YAML date. 557 | * 558 | * @return string The regular expression 559 | * 560 | * @see http://www.yaml.org/spec/1.2/spec.html#id2761573 561 | */ 562 | private static function getTimestampRegex() 563 | { 564 | return <<[0-9][0-9][0-9][0-9]) 567 | -(?P[0-9][0-9]?) 568 | -(?P[0-9][0-9]?) 569 | (?:(?:[Tt]|[ \t]+) 570 | (?P[0-9][0-9]?) 571 | :(?P[0-9][0-9]) 572 | :(?P[0-9][0-9]) 573 | (?:\.(?P[0-9]*))? 574 | (?:[ \t]*(?PZ|(?P[-+])(?P[0-9][0-9]?) 575 | (?::(?P[0-9][0-9]))?))?)? 576 | $~x 577 | EOF; 578 | } 579 | 580 | /** 581 | * Gets a regex that matches a YAML number in hexadecimal notation. 582 | * 583 | * @return string 584 | */ 585 | private static function getHexRegex() 586 | { 587 | return '~^0x[0-9a-f]++$~i'; 588 | } 589 | } 590 | -------------------------------------------------------------------------------- /craft2yml/vendor/symfony/yaml/Tests/ParserTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Symfony\Component\Yaml\Tests; 13 | 14 | use PHPUnit\Framework\TestCase; 15 | use Symfony\Component\Yaml\Yaml; 16 | use Symfony\Component\Yaml\Parser; 17 | 18 | class ParserTest extends TestCase 19 | { 20 | /** @var Parser */ 21 | protected $parser; 22 | 23 | protected function setUp() 24 | { 25 | $this->parser = new Parser(); 26 | } 27 | 28 | protected function tearDown() 29 | { 30 | $this->parser = null; 31 | } 32 | 33 | /** 34 | * @dataProvider getDataFormSpecifications 35 | */ 36 | public function testSpecifications($file, $expected, $yaml, $comment) 37 | { 38 | $this->assertEquals($expected, var_export($this->parser->parse($yaml), true), $comment); 39 | } 40 | 41 | public function getDataFormSpecifications() 42 | { 43 | $parser = new Parser(); 44 | $path = __DIR__.'/Fixtures'; 45 | 46 | $tests = array(); 47 | $files = $parser->parse(file_get_contents($path.'/index.yml')); 48 | foreach ($files as $file) { 49 | $yamls = file_get_contents($path.'/'.$file.'.yml'); 50 | 51 | // split YAMLs documents 52 | foreach (preg_split('/^---( %YAML\:1\.0)?/m', $yamls) as $yaml) { 53 | if (!$yaml) { 54 | continue; 55 | } 56 | 57 | $test = $parser->parse($yaml); 58 | if (isset($test['todo']) && $test['todo']) { 59 | // TODO 60 | } else { 61 | eval('$expected = '.trim($test['php']).';'); 62 | 63 | $tests[] = array($file, var_export($expected, true), $test['yaml'], $test['test']); 64 | } 65 | } 66 | } 67 | 68 | return $tests; 69 | } 70 | 71 | public function testTabsInYaml() 72 | { 73 | // test tabs in YAML 74 | $yamls = array( 75 | "foo:\n bar", 76 | "foo:\n bar", 77 | "foo:\n bar", 78 | "foo:\n bar", 79 | ); 80 | 81 | foreach ($yamls as $yaml) { 82 | try { 83 | $content = $this->parser->parse($yaml); 84 | 85 | $this->fail('YAML files must not contain tabs'); 86 | } catch (\Exception $e) { 87 | $this->assertInstanceOf('\Exception', $e, 'YAML files must not contain tabs'); 88 | $this->assertEquals('A YAML file cannot contain tabs as indentation at line 2 (near "'.strpbrk($yaml, "\t").'").', $e->getMessage(), 'YAML files must not contain tabs'); 89 | } 90 | } 91 | } 92 | 93 | public function testEndOfTheDocumentMarker() 94 | { 95 | $yaml = <<<'EOF' 96 | --- %YAML:1.0 97 | foo 98 | ... 99 | EOF; 100 | 101 | $this->assertEquals('foo', $this->parser->parse($yaml)); 102 | } 103 | 104 | public function getBlockChompingTests() 105 | { 106 | $tests = array(); 107 | 108 | $yaml = <<<'EOF' 109 | foo: |- 110 | one 111 | two 112 | bar: |- 113 | one 114 | two 115 | 116 | EOF; 117 | $expected = array( 118 | 'foo' => "one\ntwo", 119 | 'bar' => "one\ntwo", 120 | ); 121 | $tests['Literal block chomping strip with single trailing newline'] = array($expected, $yaml); 122 | 123 | $yaml = <<<'EOF' 124 | foo: |- 125 | one 126 | two 127 | 128 | bar: |- 129 | one 130 | two 131 | 132 | 133 | EOF; 134 | $expected = array( 135 | 'foo' => "one\ntwo", 136 | 'bar' => "one\ntwo", 137 | ); 138 | $tests['Literal block chomping strip with multiple trailing newlines'] = array($expected, $yaml); 139 | 140 | $yaml = <<<'EOF' 141 | {} 142 | 143 | 144 | EOF; 145 | $expected = array(); 146 | $tests['Literal block chomping strip with multiple trailing newlines after a 1-liner'] = array($expected, $yaml); 147 | 148 | $yaml = <<<'EOF' 149 | foo: |- 150 | one 151 | two 152 | bar: |- 153 | one 154 | two 155 | EOF; 156 | $expected = array( 157 | 'foo' => "one\ntwo", 158 | 'bar' => "one\ntwo", 159 | ); 160 | $tests['Literal block chomping strip without trailing newline'] = array($expected, $yaml); 161 | 162 | $yaml = <<<'EOF' 163 | foo: | 164 | one 165 | two 166 | bar: | 167 | one 168 | two 169 | 170 | EOF; 171 | $expected = array( 172 | 'foo' => "one\ntwo\n", 173 | 'bar' => "one\ntwo\n", 174 | ); 175 | $tests['Literal block chomping clip with single trailing newline'] = array($expected, $yaml); 176 | 177 | $yaml = <<<'EOF' 178 | foo: | 179 | one 180 | two 181 | 182 | bar: | 183 | one 184 | two 185 | 186 | 187 | EOF; 188 | $expected = array( 189 | 'foo' => "one\ntwo\n", 190 | 'bar' => "one\ntwo\n", 191 | ); 192 | $tests['Literal block chomping clip with multiple trailing newlines'] = array($expected, $yaml); 193 | 194 | $yaml = <<<'EOF' 195 | foo: 196 | - bar: | 197 | one 198 | 199 | two 200 | EOF; 201 | $expected = array( 202 | 'foo' => array( 203 | array( 204 | 'bar' => "one\n\ntwo", 205 | ), 206 | ), 207 | ); 208 | $tests['Literal block chomping clip with embedded blank line inside unindented collection'] = array($expected, $yaml); 209 | 210 | $yaml = <<<'EOF' 211 | foo: | 212 | one 213 | two 214 | bar: | 215 | one 216 | two 217 | EOF; 218 | $expected = array( 219 | 'foo' => "one\ntwo\n", 220 | 'bar' => "one\ntwo", 221 | ); 222 | $tests['Literal block chomping clip without trailing newline'] = array($expected, $yaml); 223 | 224 | $yaml = <<<'EOF' 225 | foo: |+ 226 | one 227 | two 228 | bar: |+ 229 | one 230 | two 231 | 232 | EOF; 233 | $expected = array( 234 | 'foo' => "one\ntwo\n", 235 | 'bar' => "one\ntwo\n", 236 | ); 237 | $tests['Literal block chomping keep with single trailing newline'] = array($expected, $yaml); 238 | 239 | $yaml = <<<'EOF' 240 | foo: |+ 241 | one 242 | two 243 | 244 | bar: |+ 245 | one 246 | two 247 | 248 | 249 | EOF; 250 | $expected = array( 251 | 'foo' => "one\ntwo\n\n", 252 | 'bar' => "one\ntwo\n\n", 253 | ); 254 | $tests['Literal block chomping keep with multiple trailing newlines'] = array($expected, $yaml); 255 | 256 | $yaml = <<<'EOF' 257 | foo: |+ 258 | one 259 | two 260 | bar: |+ 261 | one 262 | two 263 | EOF; 264 | $expected = array( 265 | 'foo' => "one\ntwo\n", 266 | 'bar' => "one\ntwo", 267 | ); 268 | $tests['Literal block chomping keep without trailing newline'] = array($expected, $yaml); 269 | 270 | $yaml = <<<'EOF' 271 | foo: >- 272 | one 273 | two 274 | bar: >- 275 | one 276 | two 277 | 278 | EOF; 279 | $expected = array( 280 | 'foo' => 'one two', 281 | 'bar' => 'one two', 282 | ); 283 | $tests['Folded block chomping strip with single trailing newline'] = array($expected, $yaml); 284 | 285 | $yaml = <<<'EOF' 286 | foo: >- 287 | one 288 | two 289 | 290 | bar: >- 291 | one 292 | two 293 | 294 | 295 | EOF; 296 | $expected = array( 297 | 'foo' => 'one two', 298 | 'bar' => 'one two', 299 | ); 300 | $tests['Folded block chomping strip with multiple trailing newlines'] = array($expected, $yaml); 301 | 302 | $yaml = <<<'EOF' 303 | foo: >- 304 | one 305 | two 306 | bar: >- 307 | one 308 | two 309 | EOF; 310 | $expected = array( 311 | 'foo' => 'one two', 312 | 'bar' => 'one two', 313 | ); 314 | $tests['Folded block chomping strip without trailing newline'] = array($expected, $yaml); 315 | 316 | $yaml = <<<'EOF' 317 | foo: > 318 | one 319 | two 320 | bar: > 321 | one 322 | two 323 | 324 | EOF; 325 | $expected = array( 326 | 'foo' => "one two\n", 327 | 'bar' => "one two\n", 328 | ); 329 | $tests['Folded block chomping clip with single trailing newline'] = array($expected, $yaml); 330 | 331 | $yaml = <<<'EOF' 332 | foo: > 333 | one 334 | two 335 | 336 | bar: > 337 | one 338 | two 339 | 340 | 341 | EOF; 342 | $expected = array( 343 | 'foo' => "one two\n", 344 | 'bar' => "one two\n", 345 | ); 346 | $tests['Folded block chomping clip with multiple trailing newlines'] = array($expected, $yaml); 347 | 348 | $yaml = <<<'EOF' 349 | foo: > 350 | one 351 | two 352 | bar: > 353 | one 354 | two 355 | EOF; 356 | $expected = array( 357 | 'foo' => "one two\n", 358 | 'bar' => 'one two', 359 | ); 360 | $tests['Folded block chomping clip without trailing newline'] = array($expected, $yaml); 361 | 362 | $yaml = <<<'EOF' 363 | foo: >+ 364 | one 365 | two 366 | bar: >+ 367 | one 368 | two 369 | 370 | EOF; 371 | $expected = array( 372 | 'foo' => "one two\n", 373 | 'bar' => "one two\n", 374 | ); 375 | $tests['Folded block chomping keep with single trailing newline'] = array($expected, $yaml); 376 | 377 | $yaml = <<<'EOF' 378 | foo: >+ 379 | one 380 | two 381 | 382 | bar: >+ 383 | one 384 | two 385 | 386 | 387 | EOF; 388 | $expected = array( 389 | 'foo' => "one two\n\n", 390 | 'bar' => "one two\n\n", 391 | ); 392 | $tests['Folded block chomping keep with multiple trailing newlines'] = array($expected, $yaml); 393 | 394 | $yaml = <<<'EOF' 395 | foo: >+ 396 | one 397 | two 398 | bar: >+ 399 | one 400 | two 401 | EOF; 402 | $expected = array( 403 | 'foo' => "one two\n", 404 | 'bar' => 'one two', 405 | ); 406 | $tests['Folded block chomping keep without trailing newline'] = array($expected, $yaml); 407 | 408 | return $tests; 409 | } 410 | 411 | /** 412 | * @dataProvider getBlockChompingTests 413 | */ 414 | public function testBlockChomping($expected, $yaml) 415 | { 416 | $this->assertSame($expected, $this->parser->parse($yaml)); 417 | } 418 | 419 | /** 420 | * Regression test for issue #7989. 421 | * 422 | * @see https://github.com/symfony/symfony/issues/7989 423 | */ 424 | public function testBlockLiteralWithLeadingNewlines() 425 | { 426 | $yaml = <<<'EOF' 427 | foo: |- 428 | 429 | 430 | bar 431 | 432 | EOF; 433 | $expected = array( 434 | 'foo' => "\n\nbar", 435 | ); 436 | 437 | $this->assertSame($expected, $this->parser->parse($yaml)); 438 | } 439 | 440 | public function testObjectSupportEnabled() 441 | { 442 | $input = <<<'EOF' 443 | foo: !!php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";} 444 | bar: 1 445 | EOF; 446 | $this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, false, true), '->parse() is able to parse objects'); 447 | 448 | $input = <<<'EOF' 449 | foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";} 450 | bar: 1 451 | EOF; 452 | $this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, false, true), '->parse() is able to parse objects'); 453 | } 454 | 455 | /** 456 | * @dataProvider invalidDumpedObjectProvider 457 | */ 458 | public function testObjectSupportDisabledButNoExceptions($input) 459 | { 460 | $this->assertEquals(array('foo' => null, 'bar' => 1), $this->parser->parse($input), '->parse() does not parse objects'); 461 | } 462 | 463 | /** 464 | * @dataProvider getObjectForMapTests 465 | */ 466 | public function testObjectForMap($yaml, $expected) 467 | { 468 | $this->assertEquals($expected, $this->parser->parse($yaml, false, false, true)); 469 | } 470 | 471 | public function getObjectForMapTests() 472 | { 473 | $tests = array(); 474 | 475 | $yaml = <<<'EOF' 476 | foo: 477 | fiz: [cat] 478 | EOF; 479 | $expected = new \stdClass(); 480 | $expected->foo = new \stdClass(); 481 | $expected->foo->fiz = array('cat'); 482 | $tests['mapping'] = array($yaml, $expected); 483 | 484 | $yaml = '{ "foo": "bar", "fiz": "cat" }'; 485 | $expected = new \stdClass(); 486 | $expected->foo = 'bar'; 487 | $expected->fiz = 'cat'; 488 | $tests['inline-mapping'] = array($yaml, $expected); 489 | 490 | $yaml = "foo: bar\nbaz: foobar"; 491 | $expected = new \stdClass(); 492 | $expected->foo = 'bar'; 493 | $expected->baz = 'foobar'; 494 | $tests['object-for-map-is-applied-after-parsing'] = array($yaml, $expected); 495 | 496 | $yaml = <<<'EOT' 497 | array: 498 | - key: one 499 | - key: two 500 | EOT; 501 | $expected = new \stdClass(); 502 | $expected->array = array(); 503 | $expected->array[0] = new \stdClass(); 504 | $expected->array[0]->key = 'one'; 505 | $expected->array[1] = new \stdClass(); 506 | $expected->array[1]->key = 'two'; 507 | $tests['nest-map-and-sequence'] = array($yaml, $expected); 508 | 509 | $yaml = <<<'YAML' 510 | map: 511 | 1: one 512 | 2: two 513 | YAML; 514 | $expected = new \stdClass(); 515 | $expected->map = new \stdClass(); 516 | $expected->map->{1} = 'one'; 517 | $expected->map->{2} = 'two'; 518 | $tests['numeric-keys'] = array($yaml, $expected); 519 | 520 | $yaml = <<<'YAML' 521 | map: 522 | 0: one 523 | 1: two 524 | YAML; 525 | $expected = new \stdClass(); 526 | $expected->map = new \stdClass(); 527 | $expected->map->{0} = 'one'; 528 | $expected->map->{1} = 'two'; 529 | $tests['zero-indexed-numeric-keys'] = array($yaml, $expected); 530 | 531 | return $tests; 532 | } 533 | 534 | /** 535 | * @dataProvider invalidDumpedObjectProvider 536 | * @expectedException \Symfony\Component\Yaml\Exception\ParseException 537 | */ 538 | public function testObjectsSupportDisabledWithExceptions($yaml) 539 | { 540 | $this->parser->parse($yaml, true, false); 541 | } 542 | 543 | public function invalidDumpedObjectProvider() 544 | { 545 | $yamlTag = <<<'EOF' 546 | foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";} 547 | bar: 1 548 | EOF; 549 | $localTag = <<<'EOF' 550 | foo: !php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";} 551 | bar: 1 552 | EOF; 553 | 554 | return array( 555 | 'yaml-tag' => array($yamlTag), 556 | 'local-tag' => array($localTag), 557 | ); 558 | } 559 | 560 | /** 561 | * @requires extension iconv 562 | */ 563 | public function testNonUtf8Exception() 564 | { 565 | $yamls = array( 566 | iconv('UTF-8', 'ISO-8859-1', "foo: 'äöüß'"), 567 | iconv('UTF-8', 'ISO-8859-15', "euro: '€'"), 568 | iconv('UTF-8', 'CP1252', "cp1252: '©ÉÇáñ'"), 569 | ); 570 | 571 | foreach ($yamls as $yaml) { 572 | try { 573 | $this->parser->parse($yaml); 574 | 575 | $this->fail('charsets other than UTF-8 are rejected.'); 576 | } catch (\Exception $e) { 577 | $this->assertInstanceOf('Symfony\Component\Yaml\Exception\ParseException', $e, 'charsets other than UTF-8 are rejected.'); 578 | } 579 | } 580 | } 581 | 582 | /** 583 | * @expectedException \Symfony\Component\Yaml\Exception\ParseException 584 | */ 585 | public function testUnindentedCollectionException() 586 | { 587 | $yaml = <<<'EOF' 588 | 589 | collection: 590 | -item1 591 | -item2 592 | -item3 593 | 594 | EOF; 595 | 596 | $this->parser->parse($yaml); 597 | } 598 | 599 | /** 600 | * @expectedException \Symfony\Component\Yaml\Exception\ParseException 601 | */ 602 | public function testShortcutKeyUnindentedCollectionException() 603 | { 604 | $yaml = <<<'EOF' 605 | 606 | collection: 607 | - key: foo 608 | foo: bar 609 | 610 | EOF; 611 | 612 | $this->parser->parse($yaml); 613 | } 614 | 615 | /** 616 | * @expectedException \Symfony\Component\Yaml\Exception\ParseException 617 | * @expectedExceptionMessageRegExp /^Multiple documents are not supported.+/ 618 | */ 619 | public function testMultipleDocumentsNotSupportedException() 620 | { 621 | Yaml::parse(<<<'EOL' 622 | # Ranking of 1998 home runs 623 | --- 624 | - Mark McGwire 625 | - Sammy Sosa 626 | - Ken Griffey 627 | 628 | # Team ranking 629 | --- 630 | - Chicago Cubs 631 | - St Louis Cardinals 632 | EOL 633 | ); 634 | } 635 | 636 | /** 637 | * @expectedException \Symfony\Component\Yaml\Exception\ParseException 638 | */ 639 | public function testSequenceInAMapping() 640 | { 641 | Yaml::parse(<<<'EOF' 642 | yaml: 643 | hash: me 644 | - array stuff 645 | EOF 646 | ); 647 | } 648 | 649 | public function testSequenceInMappingStartedBySingleDashLine() 650 | { 651 | $yaml = <<<'EOT' 652 | a: 653 | - 654 | b: 655 | - 656 | bar: baz 657 | - foo 658 | d: e 659 | EOT; 660 | $expected = array( 661 | 'a' => array( 662 | array( 663 | 'b' => array( 664 | array( 665 | 'bar' => 'baz', 666 | ), 667 | ), 668 | ), 669 | 'foo', 670 | ), 671 | 'd' => 'e', 672 | ); 673 | 674 | $this->assertSame($expected, $this->parser->parse($yaml)); 675 | } 676 | 677 | public function testSequenceFollowedByCommentEmbeddedInMapping() 678 | { 679 | $yaml = <<<'EOT' 680 | a: 681 | b: 682 | - c 683 | # comment 684 | d: e 685 | EOT; 686 | $expected = array( 687 | 'a' => array( 688 | 'b' => array('c'), 689 | 'd' => 'e', 690 | ), 691 | ); 692 | 693 | $this->assertSame($expected, $this->parser->parse($yaml)); 694 | } 695 | 696 | /** 697 | * @expectedException \Symfony\Component\Yaml\Exception\ParseException 698 | */ 699 | public function testMappingInASequence() 700 | { 701 | Yaml::parse(<<<'EOF' 702 | yaml: 703 | - array stuff 704 | hash: me 705 | EOF 706 | ); 707 | } 708 | 709 | /** 710 | * @expectedException \Symfony\Component\Yaml\Exception\ParseException 711 | * @expectedExceptionMessage missing colon 712 | */ 713 | public function testScalarInSequence() 714 | { 715 | Yaml::parse(<<<'EOF' 716 | foo: 717 | - bar 718 | "missing colon" 719 | foo: bar 720 | EOF 721 | ); 722 | } 723 | 724 | /** 725 | * > It is an error for two equal keys to appear in the same mapping node. 726 | * > In such a case the YAML processor may continue, ignoring the second 727 | * > `key: value` pair and issuing an appropriate warning. This strategy 728 | * > preserves a consistent information model for one-pass and random access 729 | * > applications. 730 | * 731 | * @see http://yaml.org/spec/1.2/spec.html#id2759572 732 | * @see http://yaml.org/spec/1.1/#id932806 733 | */ 734 | public function testMappingDuplicateKeyBlock() 735 | { 736 | $input = <<<'EOD' 737 | parent: 738 | child: first 739 | child: duplicate 740 | parent: 741 | child: duplicate 742 | child: duplicate 743 | EOD; 744 | $expected = array( 745 | 'parent' => array( 746 | 'child' => 'first', 747 | ), 748 | ); 749 | $this->assertSame($expected, Yaml::parse($input)); 750 | } 751 | 752 | public function testMappingDuplicateKeyFlow() 753 | { 754 | $input = <<<'EOD' 755 | parent: { child: first, child: duplicate } 756 | parent: { child: duplicate, child: duplicate } 757 | EOD; 758 | $expected = array( 759 | 'parent' => array( 760 | 'child' => 'first', 761 | ), 762 | ); 763 | $this->assertSame($expected, Yaml::parse($input)); 764 | } 765 | 766 | public function testEmptyValue() 767 | { 768 | $input = <<<'EOF' 769 | hash: 770 | EOF; 771 | 772 | $this->assertEquals(array('hash' => null), Yaml::parse($input)); 773 | } 774 | 775 | public function testCommentAtTheRootIndent() 776 | { 777 | $this->assertEquals(array( 778 | 'services' => array( 779 | 'app.foo_service' => array( 780 | 'class' => 'Foo', 781 | ), 782 | 'app/bar_service' => array( 783 | 'class' => 'Bar', 784 | ), 785 | ), 786 | ), Yaml::parse(<<<'EOF' 787 | # comment 1 788 | services: 789 | # comment 2 790 | # comment 3 791 | app.foo_service: 792 | class: Foo 793 | # comment 4 794 | # comment 5 795 | app/bar_service: 796 | class: Bar 797 | EOF 798 | )); 799 | } 800 | 801 | public function testStringBlockWithComments() 802 | { 803 | $this->assertEquals(array('content' => <<<'EOT' 804 | # comment 1 805 | header 806 | 807 | # comment 2 808 | 809 |

title

810 | 811 | 812 | footer # comment3 813 | EOT 814 | ), Yaml::parse(<<<'EOF' 815 | content: | 816 | # comment 1 817 | header 818 | 819 | # comment 2 820 | 821 |

title

822 | 823 | 824 | footer # comment3 825 | EOF 826 | )); 827 | } 828 | 829 | public function testFoldedStringBlockWithComments() 830 | { 831 | $this->assertEquals(array(array('content' => <<<'EOT' 832 | # comment 1 833 | header 834 | 835 | # comment 2 836 | 837 |

title

838 | 839 | 840 | footer # comment3 841 | EOT 842 | )), Yaml::parse(<<<'EOF' 843 | - 844 | content: | 845 | # comment 1 846 | header 847 | 848 | # comment 2 849 | 850 |

title

851 | 852 | 853 | footer # comment3 854 | EOF 855 | )); 856 | } 857 | 858 | public function testNestedFoldedStringBlockWithComments() 859 | { 860 | $this->assertEquals(array(array( 861 | 'title' => 'some title', 862 | 'content' => <<<'EOT' 863 | # comment 1 864 | header 865 | 866 | # comment 2 867 | 868 |

title

869 | 870 | 871 | footer # comment3 872 | EOT 873 | )), Yaml::parse(<<<'EOF' 874 | - 875 | title: some title 876 | content: | 877 | # comment 1 878 | header 879 | 880 | # comment 2 881 | 882 |

title

883 | 884 | 885 | footer # comment3 886 | EOF 887 | )); 888 | } 889 | 890 | public function testReferenceResolvingInInlineStrings() 891 | { 892 | $this->assertEquals(array( 893 | 'var' => 'var-value', 894 | 'scalar' => 'var-value', 895 | 'list' => array('var-value'), 896 | 'list_in_list' => array(array('var-value')), 897 | 'map_in_list' => array(array('key' => 'var-value')), 898 | 'embedded_mapping' => array(array('key' => 'var-value')), 899 | 'map' => array('key' => 'var-value'), 900 | 'list_in_map' => array('key' => array('var-value')), 901 | 'map_in_map' => array('foo' => array('bar' => 'var-value')), 902 | ), Yaml::parse(<<<'EOF' 903 | var: &var var-value 904 | scalar: *var 905 | list: [ *var ] 906 | list_in_list: [[ *var ]] 907 | map_in_list: [ { key: *var } ] 908 | embedded_mapping: [ key: *var ] 909 | map: { key: *var } 910 | list_in_map: { key: [*var] } 911 | map_in_map: { foo: { bar: *var } } 912 | EOF 913 | )); 914 | } 915 | 916 | public function testYamlDirective() 917 | { 918 | $yaml = <<<'EOF' 919 | %YAML 1.2 920 | --- 921 | foo: 1 922 | bar: 2 923 | EOF; 924 | $this->assertEquals(array('foo' => 1, 'bar' => 2), $this->parser->parse($yaml)); 925 | } 926 | 927 | public function testFloatKeys() 928 | { 929 | $yaml = <<<'EOF' 930 | foo: 931 | 1.2: "bar" 932 | 1.3: "baz" 933 | EOF; 934 | 935 | $expected = array( 936 | 'foo' => array( 937 | '1.2' => 'bar', 938 | '1.3' => 'baz', 939 | ), 940 | ); 941 | 942 | $this->assertEquals($expected, $this->parser->parse($yaml)); 943 | } 944 | 945 | /** 946 | * @group legacy 947 | * @expectedDeprecation Using a colon in the unquoted mapping value "bar: baz" in line 1 is deprecated since Symfony 2.8 and will throw a ParseException in 3.0. 948 | * throw ParseException in Symfony 3.0 949 | */ 950 | public function testColonInMappingValueException() 951 | { 952 | $yaml = <<<'EOF' 953 | foo: bar: baz 954 | EOF; 955 | 956 | $this->parser->parse($yaml); 957 | } 958 | 959 | public function testColonInMappingValueExceptionNotTriggeredByColonInComment() 960 | { 961 | $yaml = <<<'EOT' 962 | foo: 963 | bar: foobar # Note: a comment after a colon 964 | EOT; 965 | 966 | $this->assertSame(array('foo' => array('bar' => 'foobar')), $this->parser->parse($yaml)); 967 | } 968 | 969 | /** 970 | * @dataProvider getCommentLikeStringInScalarBlockData 971 | */ 972 | public function testCommentLikeStringsAreNotStrippedInBlockScalars($yaml, $expectedParserResult) 973 | { 974 | $this->assertSame($expectedParserResult, $this->parser->parse($yaml)); 975 | } 976 | 977 | public function getCommentLikeStringInScalarBlockData() 978 | { 979 | $tests = array(); 980 | 981 | $yaml = <<<'EOT' 982 | pages: 983 | - 984 | title: some title 985 | content: | 986 | # comment 1 987 | header 988 | 989 | # comment 2 990 | 991 |

title

992 | 993 | 994 | footer # comment3 995 | EOT; 996 | $expected = array( 997 | 'pages' => array( 998 | array( 999 | 'title' => 'some title', 1000 | 'content' => <<<'EOT' 1001 | # comment 1 1002 | header 1003 | 1004 | # comment 2 1005 | 1006 |

title

1007 | 1008 | 1009 | footer # comment3 1010 | EOT 1011 | , 1012 | ), 1013 | ), 1014 | ); 1015 | $tests[] = array($yaml, $expected); 1016 | 1017 | $yaml = <<<'EOT' 1018 | test: | 1019 | foo 1020 | # bar 1021 | baz 1022 | collection: 1023 | - one: | 1024 | foo 1025 | # bar 1026 | baz 1027 | - two: | 1028 | foo 1029 | # bar 1030 | baz 1031 | EOT; 1032 | $expected = array( 1033 | 'test' => <<<'EOT' 1034 | foo 1035 | # bar 1036 | baz 1037 | 1038 | EOT 1039 | , 1040 | 'collection' => array( 1041 | array( 1042 | 'one' => <<<'EOT' 1043 | foo 1044 | # bar 1045 | baz 1046 | 1047 | EOT 1048 | , 1049 | ), 1050 | array( 1051 | 'two' => <<<'EOT' 1052 | foo 1053 | # bar 1054 | baz 1055 | EOT 1056 | , 1057 | ), 1058 | ), 1059 | ); 1060 | $tests[] = array($yaml, $expected); 1061 | 1062 | $yaml = <<<'EOT' 1063 | foo: 1064 | bar: 1065 | scalar-block: > 1066 | line1 1067 | line2> 1068 | baz: 1069 | # comment 1070 | foobar: ~ 1071 | EOT; 1072 | $expected = array( 1073 | 'foo' => array( 1074 | 'bar' => array( 1075 | 'scalar-block' => "line1 line2>\n", 1076 | ), 1077 | 'baz' => array( 1078 | 'foobar' => null, 1079 | ), 1080 | ), 1081 | ); 1082 | $tests[] = array($yaml, $expected); 1083 | 1084 | $yaml = <<<'EOT' 1085 | a: 1086 | b: hello 1087 | # c: | 1088 | # first row 1089 | # second row 1090 | d: hello 1091 | EOT; 1092 | $expected = array( 1093 | 'a' => array( 1094 | 'b' => 'hello', 1095 | 'd' => 'hello', 1096 | ), 1097 | ); 1098 | $tests[] = array($yaml, $expected); 1099 | 1100 | return $tests; 1101 | } 1102 | 1103 | public function testBlankLinesAreParsedAsNewLinesInFoldedBlocks() 1104 | { 1105 | $yaml = <<<'EOT' 1106 | test: > 1107 |

A heading

1108 | 1109 |
    1110 |
  • a list
  • 1111 |
  • may be a good example
  • 1112 |
1113 | EOT; 1114 | 1115 | $this->assertSame( 1116 | array( 1117 | 'test' => <<<'EOT' 1118 |

A heading

1119 |
  • a list
  • may be a good example
1120 | EOT 1121 | , 1122 | ), 1123 | $this->parser->parse($yaml) 1124 | ); 1125 | } 1126 | 1127 | public function testAdditionallyIndentedLinesAreParsedAsNewLinesInFoldedBlocks() 1128 | { 1129 | $yaml = <<<'EOT' 1130 | test: > 1131 |

A heading

1132 | 1133 |
    1134 |
  • a list
  • 1135 |
  • may be a good example
  • 1136 |
1137 | EOT; 1138 | 1139 | $this->assertSame( 1140 | array( 1141 | 'test' => <<<'EOT' 1142 |

A heading

1143 |
    1144 |
  • a list
  • 1145 |
  • may be a good example
  • 1146 |
1147 | EOT 1148 | , 1149 | ), 1150 | $this->parser->parse($yaml) 1151 | ); 1152 | } 1153 | 1154 | /** 1155 | * @param $lineNumber 1156 | * @param $yaml 1157 | * @dataProvider parserThrowsExceptionWithCorrectLineNumberProvider 1158 | */ 1159 | public function testParserThrowsExceptionWithCorrectLineNumber($lineNumber, $yaml) 1160 | { 1161 | if (method_exists($this, 'expectException')) { 1162 | $this->expectException('\Symfony\Component\Yaml\Exception\ParseException'); 1163 | $this->expectExceptionMessage(sprintf('Unexpected characters near "," at line %d (near "bar: "123",").', $lineNumber)); 1164 | } else { 1165 | $this->setExpectedException('\Symfony\Component\Yaml\Exception\ParseException', sprintf('Unexpected characters near "," at line %d (near "bar: "123",").', $lineNumber)); 1166 | } 1167 | 1168 | $this->parser->parse($yaml); 1169 | } 1170 | 1171 | public function parserThrowsExceptionWithCorrectLineNumberProvider() 1172 | { 1173 | return array( 1174 | array( 1175 | 4, 1176 | <<<'YAML' 1177 | foo: 1178 | - 1179 | # bar 1180 | bar: "123", 1181 | YAML 1182 | ), 1183 | array( 1184 | 5, 1185 | <<<'YAML' 1186 | foo: 1187 | - 1188 | # bar 1189 | # bar 1190 | bar: "123", 1191 | YAML 1192 | ), 1193 | array( 1194 | 8, 1195 | <<<'YAML' 1196 | foo: 1197 | - 1198 | # foobar 1199 | baz: 123 1200 | bar: 1201 | - 1202 | # bar 1203 | bar: "123", 1204 | YAML 1205 | ), 1206 | array( 1207 | 10, 1208 | <<<'YAML' 1209 | foo: 1210 | - 1211 | # foobar 1212 | # foobar 1213 | baz: 123 1214 | bar: 1215 | - 1216 | # bar 1217 | # bar 1218 | bar: "123", 1219 | YAML 1220 | ), 1221 | ); 1222 | } 1223 | 1224 | public function testCanParseVeryLongValue() 1225 | { 1226 | $longStringWithSpaces = str_repeat('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ', 20000); 1227 | $trickyVal = array('x' => $longStringWithSpaces); 1228 | 1229 | $yamlString = Yaml::dump($trickyVal); 1230 | $arrayFromYaml = $this->parser->parse($yamlString); 1231 | 1232 | $this->assertEquals($trickyVal, $arrayFromYaml); 1233 | } 1234 | 1235 | /** 1236 | * @expectedException \Symfony\Component\Yaml\Exception\ParseException 1237 | * @expectedExceptionMessage Reference "foo" does not exist at line 2 1238 | */ 1239 | public function testParserCleansUpReferencesBetweenRuns() 1240 | { 1241 | $yaml = <<parser->parse($yaml); 1248 | 1249 | $yaml = <<parser->parse($yaml); 1254 | } 1255 | } 1256 | 1257 | class B 1258 | { 1259 | public $b = 'foo'; 1260 | } 1261 | --------------------------------------------------------------------------------