update v1.0.4

This commit is contained in:
sujitprasad
2016-01-04 18:05:45 +05:30
parent 372485336b
commit 4864e5a3f1
529 changed files with 20956 additions and 8178 deletions

View File

@@ -131,6 +131,16 @@ class ContainerAwareEventDispatcher extends EventDispatcher
return parent::getListeners($eventName);
}
/**
* {@inheritdoc}
*/
public function getListenerPriority($eventName, $listener)
{
$this->lazyLoad($eventName);
return parent::getListenerPriority($eventName, $listener);
}
/**
* Adds a service as event subscriber.
*

View File

@@ -99,6 +99,14 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
return $this->dispatcher->getListeners($eventName);
}
/**
* {@inheritdoc}
*/
public function getListenerPriority($eventName, $listener)
{
return $this->dispatcher->getListenerPriority($eventName, $listener);
}
/**
* {@inheritdoc}
*/
@@ -186,6 +194,8 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
}
}
uasort($notCalled, array($this, 'sortListenersByPriority'));
return $notCalled;
}
@@ -285,6 +295,7 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
{
$info = array(
'event' => $eventName,
'priority' => $this->getListenerPriority($eventName, $listener),
);
if ($listener instanceof \Closure) {
$info += array(
@@ -332,4 +343,25 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
return $info;
}
private function sortListenersByPriority($a, $b)
{
if (is_int($a['priority']) && !is_int($b['priority'])) {
return 1;
}
if (!is_int($a['priority']) && is_int($b['priority'])) {
return -1;
}
if ($a['priority'] === $b['priority']) {
return 0;
}
if ($a['priority'] > $b['priority']) {
return -1;
}
return 1;
}
}

View File

@@ -75,6 +75,29 @@ class EventDispatcher implements EventDispatcherInterface
return array_filter($this->sorted);
}
/**
* Gets the listener priority for a specific event.
*
* Returns null if the event or the listener does not exist.
*
* @param string $eventName The name of the event
* @param callable $listener The listener
*
* @return int|null The event listener priority
*/
public function getListenerPriority($eventName, $listener)
{
if (!isset($this->listeners[$eventName])) {
return;
}
foreach ($this->listeners[$eventName] as $priority => $listeners) {
if (false !== ($key = array_search($listener, $listeners, true))) {
return $priority;
}
}
}
/**
* {@inheritdoc}
*/
@@ -169,8 +192,6 @@ class EventDispatcher implements EventDispatcherInterface
*/
private function sortListeners($eventName)
{
$this->sorted[$eventName] = array();
krsort($this->listeners[$eventName]);
$this->sorted[$eventName] = call_user_func_array('array_merge', $this->listeners[$eventName]);
}

View File

@@ -83,6 +83,14 @@ class ImmutableEventDispatcher implements EventDispatcherInterface
return $this->dispatcher->getListeners($eventName);
}
/**
* {@inheritdoc}
*/
public function getListenerPriority($eventName, $listener)
{
return $this->dispatcher->getListenerPriority($eventName, $listener);
}
/**
* {@inheritdoc}
*/

View File

@@ -108,6 +108,20 @@ abstract class AbstractEventDispatcherTest extends \PHPUnit_Framework_TestCase
$this->assertSame($expected, $this->dispatcher->getListeners());
}
public function testGetListenerPriority()
{
$listener1 = new TestEventListener();
$listener2 = new TestEventListener();
$this->dispatcher->addListener('pre.foo', $listener1, -10);
$this->dispatcher->addListener('pre.foo', $listener2);
$this->assertSame(-10, $this->dispatcher->getListenerPriority('pre.foo', $listener1));
$this->assertSame(0, $this->dispatcher->getListenerPriority('pre.foo', $listener2));
$this->assertNull($this->dispatcher->getListenerPriority('pre.bar', $listener2));
$this->assertNull($this->dispatcher->getListenerPriority('pre.foo', function () {}));
}
public function testDispatch()
{
$this->dispatcher->addListener('pre.foo', array($this->listener, 'preFoo'));

View File

@@ -92,6 +92,7 @@ class ContainerAwareEventDispatcherTest extends AbstractEventDispatcherTest
/**
* @expectedException \InvalidArgumentException
* @group legacy
*/
public function testTriggerAListenerServiceOutOfScope()
{
@@ -111,6 +112,9 @@ class ContainerAwareEventDispatcherTest extends AbstractEventDispatcherTest
$dispatcher->dispatch('onEvent');
}
/**
* @group legacy
*/
public function testReEnteringAScope()
{
$event = new Event();

View File

@@ -25,7 +25,7 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
$dispatcher = new EventDispatcher();
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch());
$tdispatcher->addListener('foo', $listener = function () {; });
$tdispatcher->addListener('foo', $listener = function () {});
$listeners = $dispatcher->getListeners('foo');
$this->assertCount(1, $listeners);
$this->assertSame($listener, $listeners[0]);
@@ -39,7 +39,7 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
$dispatcher = new EventDispatcher();
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch());
$tdispatcher->addListener('foo', $listener = function () {; });
$tdispatcher->addListener('foo', $listener = function () {});
$this->assertSame($dispatcher->getListeners('foo'), $tdispatcher->getListeners('foo'));
}
@@ -51,7 +51,7 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($dispatcher->hasListeners('foo'));
$this->assertFalse($tdispatcher->hasListeners('foo'));
$tdispatcher->addListener('foo', $listener = function () {; });
$tdispatcher->addListener('foo', $listener = function () {});
$this->assertTrue($dispatcher->hasListeners('foo'));
$this->assertTrue($tdispatcher->hasListeners('foo'));
}
@@ -76,14 +76,14 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
{
$dispatcher = new EventDispatcher();
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch());
$tdispatcher->addListener('foo', $listener = function () {; });
$tdispatcher->addListener('foo', $listener = function () {});
$this->assertEquals(array(), $tdispatcher->getCalledListeners());
$this->assertEquals(array('foo.closure' => array('event' => 'foo', 'type' => 'Closure', 'pretty' => 'closure')), $tdispatcher->getNotCalledListeners());
$this->assertEquals(array('foo.closure' => array('event' => 'foo', 'type' => 'Closure', 'pretty' => 'closure', 'priority' => 0)), $tdispatcher->getNotCalledListeners());
$tdispatcher->dispatch('foo');
$this->assertEquals(array('foo.closure' => array('event' => 'foo', 'type' => 'Closure', 'pretty' => 'closure')), $tdispatcher->getCalledListeners());
$this->assertEquals(array('foo.closure' => array('event' => 'foo', 'type' => 'Closure', 'pretty' => 'closure', 'priority' => null)), $tdispatcher->getCalledListeners());
$this->assertEquals(array(), $tdispatcher->getNotCalledListeners());
}
@@ -107,8 +107,8 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
$dispatcher = new EventDispatcher();
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch(), $logger);
$tdispatcher->addListener('foo', $listener1 = function () {; });
$tdispatcher->addListener('foo', $listener2 = function () {; });
$tdispatcher->addListener('foo', $listener1 = function () {});
$tdispatcher->addListener('foo', $listener2 = function () {});
$logger->expects($this->at(0))->method('debug')->with('Notified event "foo" to listener "closure".');
$logger->expects($this->at(1))->method('debug')->with('Notified event "foo" to listener "closure".');
@@ -123,7 +123,7 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
$dispatcher = new EventDispatcher();
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch(), $logger);
$tdispatcher->addListener('foo', $listener1 = function (Event $event) { $event->stopPropagation(); });
$tdispatcher->addListener('foo', $listener2 = function () {; });
$tdispatcher->addListener('foo', $listener2 = function () {});
$logger->expects($this->at(0))->method('debug')->with('Notified event "foo" to listener "closure".');
$logger->expects($this->at(1))->method('debug')->with('Listener "closure" stopped propagation of the event "foo".');

View File

@@ -19,10 +19,10 @@
"php": ">=5.3.9"
},
"require-dev": {
"symfony/dependency-injection": "~2.6",
"symfony/expression-language": "~2.6",
"symfony/config": "~2.0,>=2.0.5",
"symfony/stopwatch": "~2.3",
"symfony/dependency-injection": "~2.6|~3.0.0",
"symfony/expression-language": "~2.6|~3.0.0",
"symfony/config": "~2.0,>=2.0.5|~3.0.0",
"symfony/stopwatch": "~2.3|~3.0.0",
"psr/log": "~1.0"
},
"suggest": {
@@ -30,12 +30,15 @@
"symfony/http-kernel": ""
},
"autoload": {
"psr-4": { "Symfony\\Component\\EventDispatcher\\": "" }
"psr-4": { "Symfony\\Component\\EventDispatcher\\": "" },
"exclude-from-classmap": [
"/Tests/"
]
},
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "2.7-dev"
"dev-master": "2.8-dev"
}
}
}

View File

@@ -1,6 +1,11 @@
CHANGELOG
=========
2.8.0
-----
* added tempnam() a stream aware version of PHP's native tempnam()
2.6.0
-----

View File

@@ -192,12 +192,12 @@ class Filesystem
public function chmod($files, $mode, $umask = 0000, $recursive = false)
{
foreach ($this->toIterator($files) as $file) {
if ($recursive && is_dir($file) && !is_link($file)) {
$this->chmod(new \FilesystemIterator($file), $mode, $umask, true);
}
if (true !== @chmod($file, $mode & ~$umask)) {
throw new IOException(sprintf('Failed to chmod file "%s".', $file), 0, null, $file);
}
if ($recursive && is_dir($file) && !is_link($file)) {
$this->chmod(new \FilesystemIterator($file), $mode, $umask, true);
}
}
}
@@ -443,13 +443,65 @@ class Filesystem
*/
public function isAbsolutePath($file)
{
return (strspn($file, '/\\', 0, 1)
return strspn($file, '/\\', 0, 1)
|| (strlen($file) > 3 && ctype_alpha($file[0])
&& substr($file, 1, 1) === ':'
&& (strspn($file, '/\\', 2, 1))
)
|| null !== parse_url($file, PHP_URL_SCHEME)
);
;
}
/**
* Creates a temporary file with support for custom stream wrappers.
*
* @param string $dir The directory where the temporary filename will be created.
* @param string $prefix The prefix of the generated temporary filename.
* Note: Windows uses only the first three characters of prefix.
*
* @return string The new temporary filename (with path), or throw an exception on failure.
*/
public function tempnam($dir, $prefix)
{
list($scheme, $hierarchy) = $this->getSchemeAndHierarchy($dir);
// If no scheme or scheme is "file" create temp file in local filesystem
if (null === $scheme || 'file' === $scheme) {
$tmpFile = tempnam($hierarchy, $prefix);
// If tempnam failed or no scheme return the filename otherwise prepend the scheme
if (false !== $tmpFile) {
if (null !== $scheme) {
return $scheme.'://'.$tmpFile;
}
return $tmpFile;
}
throw new IOException('A temporary file could not be created.');
}
// Loop until we create a valid temp file or have reached 10 attempts
for ($i = 0; $i < 10; ++$i) {
// Create a unique filename
$tmpFile = $dir.'/'.$prefix.uniqid(mt_rand(), true);
// Use fopen instead of file_exists as some streams do not support stat
// Use mode 'x+' to atomically check existence and create to avoid a TOCTOU vulnerability
$handle = @fopen($tmpFile, 'x+');
// If unsuccessful restart the loop
if (false === $handle) {
continue;
}
// Close the file if it was successfully opened
@fclose($handle);
return $tmpFile;
}
throw new IOException('A temporary file could not be created.');
}
/**
@@ -472,7 +524,7 @@ class Filesystem
throw new IOException(sprintf('Unable to write to the "%s" directory.', $dir), 0, null, $dir);
}
$tmpFile = tempnam($dir, basename($filename));
$tmpFile = $this->tempnam($dir, basename($filename));
if (false === @file_put_contents($tmpFile, $content)) {
throw new IOException(sprintf('Failed to write file "%s".', $filename), 0, null, $filename);
@@ -501,4 +553,18 @@ class Filesystem
return $files;
}
/**
* Gets a 2-tuple of scheme (may be null) and hierarchical part of a filename (e.g. file:///tmp -> array(file, tmp)).
*
* @param string $filename The filename to be parsed.
*
* @return array The filename scheme and hierarchical part
*/
private function getSchemeAndHierarchy($filename)
{
$components = explode('://', $filename, 2);
return 2 === count($components) ? array($components[0], $components[1]) : array(null, $components[0]);
}
}

View File

@@ -483,6 +483,22 @@ class FilesystemTest extends FilesystemTestCase
$this->assertFilePermissions(753, $directory);
}
public function testChmodChangesZeroModeOnSubdirectoriesOnRecursive()
{
$this->markAsSkippedIfChmodIsMissing();
$directory = $this->workspace.DIRECTORY_SEPARATOR.'directory';
$subdirectory = $directory.DIRECTORY_SEPARATOR.'subdirectory';
mkdir($directory);
mkdir($subdirectory);
chmod($subdirectory, 0000);
$this->filesystem->chmod($directory, 0753, 0000, true);
$this->assertFilePermissions(753, $subdirectory);
}
public function testChown()
{
$this->markAsSkippedIfPosixIsMissing();
@@ -946,6 +962,110 @@ class FilesystemTest extends FilesystemTestCase
);
}
public function testTempnam()
{
$dirname = $this->workspace;
$filename = $this->filesystem->tempnam($dirname, 'foo');
$this->assertFileExists($filename);
}
public function testTempnamWithFileScheme()
{
$scheme = 'file://';
$dirname = $scheme.$this->workspace;
$filename = $this->filesystem->tempnam($dirname, 'foo');
$this->assertStringStartsWith($scheme, $filename);
$this->assertFileExists($filename);
}
public function testTempnamWithMockScheme()
{
stream_wrapper_register('mock', 'Symfony\Component\Filesystem\Tests\Fixtures\MockStream\MockStream');
$scheme = 'mock://';
$dirname = $scheme.$this->workspace;
$filename = $this->filesystem->tempnam($dirname, 'foo');
$this->assertStringStartsWith($scheme, $filename);
$this->assertFileExists($filename);
}
/**
* @expectedException \Symfony\Component\Filesystem\Exception\IOException
*/
public function testTempnamWithZlibSchemeFails()
{
$scheme = 'compress.zlib://';
$dirname = $scheme.$this->workspace;
// The compress.zlib:// stream does not support mode x: creates the file, errors "failed to open stream: operation failed" and returns false
$this->filesystem->tempnam($dirname, 'bar');
}
public function testTempnamWithPHPTempSchemeFails()
{
$scheme = 'php://temp';
$dirname = $scheme;
$filename = $this->filesystem->tempnam($dirname, 'bar');
$this->assertStringStartsWith($scheme, $filename);
// The php://temp stream deletes the file after close
$this->assertFileNotExists($filename);
}
/**
* @expectedException \Symfony\Component\Filesystem\Exception\IOException
*/
public function testTempnamWithPharSchemeFails()
{
// Skip test if Phar disabled phar.readonly must be 0 in php.ini
if (!\Phar::canWrite()) {
$this->markTestSkipped('This test cannot run when phar.readonly is 1.');
}
$scheme = 'phar://';
$dirname = $scheme.$this->workspace;
$pharname = 'foo.phar';
new \Phar($this->workspace.'/'.$pharname, 0, $pharname);
// The phar:// stream does not support mode x: fails to create file, errors "failed to open stream: phar error: "$filename" is not a file in phar "$pharname"" and returns false
$this->filesystem->tempnam($dirname, $pharname.'/bar');
}
/**
* @expectedException \Symfony\Component\Filesystem\Exception\IOException
*/
public function testTempnamWithHTTPSchemeFails()
{
$scheme = 'http://';
$dirname = $scheme.$this->workspace;
// The http:// scheme is read-only
$this->filesystem->tempnam($dirname, 'bar');
}
public function testTempnamOnUnwritableFallsBackToSysTmp()
{
$scheme = 'file://';
$dirname = $scheme.$this->workspace.DIRECTORY_SEPARATOR.'does_not_exist';
$filename = $this->filesystem->tempnam($dirname, 'bar');
$realTempDir = realpath(sys_get_temp_dir());
$this->assertStringStartsWith(rtrim($scheme.$realTempDir, DIRECTORY_SEPARATOR), $filename);
$this->assertFileExists($filename);
// Tear down
@unlink($filename);
}
public function testDumpFile()
{
$filename = $this->workspace.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'baz.txt';
@@ -1000,6 +1120,33 @@ class FilesystemTest extends FilesystemTestCase
$this->assertSame('bar', file_get_contents($filename));
}
public function testDumpFileWithFileScheme()
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('HHVM does not handle the file:// scheme correctly');
}
$scheme = 'file://';
$filename = $scheme.$this->workspace.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'baz.txt';
$this->filesystem->dumpFile($filename, 'bar', null);
$this->assertFileExists($filename);
$this->assertSame('bar', file_get_contents($filename));
}
public function testDumpFileWithZlibScheme()
{
$scheme = 'compress.zlib://';
$filename = $this->workspace.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'baz.txt';
$this->filesystem->dumpFile($filename, 'bar', null);
// Zlib stat uses file:// wrapper so remove scheme
$this->assertFileExists(str_replace($scheme, '', $filename));
$this->assertSame('bar', file_get_contents($filename));
}
public function testCopyShouldKeepExecutionPermission()
{
$this->markAsSkippedIfChmodIsMissing();

View File

@@ -0,0 +1,46 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Filesystem\Tests\Fixtures\MockStream;
/**
* Mock stream class to be used with stream_wrapper_register.
* stream_wrapper_register('mock', 'Symfony\Component\Filesystem\Tests\Fixtures\MockStream\MockStream').
*/
class MockStream
{
/**
* Opens file or URL.
*
* @param string $path Specifies the URL that was passed to the original function
* @param string $mode The mode used to open the file, as detailed for fopen()
* @param int $options Holds additional flags set by the streams API
* @param string $opened_path If the path is opened successfully, and STREAM_USE_PATH is set in options,
* opened_path should be set to the full path of the file/resource that was actually opened
*
* @return bool
*/
public function stream_open($path, $mode, $options, &$opened_path)
{
return true;
}
/**
* @param string $path The file path or URL to stat
* @param array $flags Holds additional flags set by the streams API
*
* @return array File stats
*/
public function url_stat($path, $flags)
{
return array();
}
}

View File

@@ -19,12 +19,15 @@
"php": ">=5.3.9"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Filesystem\\": "" }
"psr-4": { "Symfony\\Component\\Filesystem\\": "" },
"exclude-from-classmap": [
"/Tests/"
]
},
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "2.7-dev"
"dev-master": "2.8-dev"
}
}
}

View File

@@ -21,6 +21,7 @@
<directory>./</directory>
<exclude>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>

View File

@@ -60,11 +60,11 @@ abstract class Kernel implements KernelInterface, TerminableInterface
protected $startTime;
protected $loadClassCache;
const VERSION = '2.6.11';
const VERSION_ID = '20611';
const VERSION = '2.6.12';
const VERSION_ID = '20612';
const MAJOR_VERSION = '2';
const MINOR_VERSION = '6';
const RELEASE_VERSION = '11';
const RELEASE_VERSION = '12';
const EXTRA_VERSION = '';
/**

19
vendor/symfony/polyfill-php56/LICENSE vendored Normal file
View File

@@ -0,0 +1,19 @@
Copyright (c) 2014-2015 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

127
vendor/symfony/polyfill-php56/Php56.php vendored Normal file
View File

@@ -0,0 +1,127 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Polyfill\Php56;
use Symfony\Polyfill\Util\Binary;
/**
* @internal
*/
final class Php56
{
const LDAP_ESCAPE_FILTER = 1;
const LDAP_ESCAPE_DN = 2;
public static function hash_equals($knownString, $userInput)
{
if (!is_string($knownString)) {
trigger_error('Expected known_string to be a string, '.gettype($knownString).' given', E_USER_WARNING);
return false;
}
if (!is_string($userInput)) {
trigger_error('Expected user_input to be a string, '.gettype($userInput).' given', E_USER_WARNING);
return false;
}
$knownLen = Binary::strlen($knownString);
$userLen = Binary::strlen($userInput);
if ($knownLen !== $userLen) {
return false;
}
$result = 0;
for ($i = 0; $i < $knownLen; ++$i) {
$result |= ord($knownString[$i]) ^ ord($userInput[$i]);
}
return 0 === $result;
}
/**
* Stub implementation of the {@link ldap_escape()} function of the ldap
* extension.
*
* Escape strings for safe use in LDAP filters and DNs.
*
* @author Chris Wright <ldapi@daverandom.com>
*
* @param string $subject
* @param string $ignore
* @param int $flags
*
* @return string
*
* @see http://stackoverflow.com/a/8561604
*/
public static function ldap_escape($subject, $ignore = '', $flags = 0)
{
static $charMaps = null;
if (null === $charMaps) {
$charMaps = array(
self::LDAP_ESCAPE_FILTER => array('\\', '*', '(', ')', "\x00"),
self::LDAP_ESCAPE_DN => array('\\', ',', '=', '+', '<', '>', ';', '"', '#'),
);
$charMaps[0] = array();
for ($i = 0; $i < 256; ++$i) {
$charMaps[0][chr($i)] = sprintf('\\%02x', $i);
}
for ($i = 0, $l = count($charMaps[self::LDAP_ESCAPE_FILTER]); $i < $l; ++$i) {
$chr = $charMaps[self::LDAP_ESCAPE_FILTER][$i];
unset($charMaps[self::LDAP_ESCAPE_FILTER][$i]);
$charMaps[self::LDAP_ESCAPE_FILTER][$chr] = $charMaps[0][$chr];
}
for ($i = 0, $l = count($charMaps[self::LDAP_ESCAPE_DN]); $i < $l; ++$i) {
$chr = $charMaps[self::LDAP_ESCAPE_DN][$i];
unset($charMaps[self::LDAP_ESCAPE_DN][$i]);
$charMaps[self::LDAP_ESCAPE_DN][$chr] = $charMaps[0][$chr];
}
}
// Create the base char map to escape
$flags = (int) $flags;
$charMap = array();
if ($flags & self::LDAP_ESCAPE_FILTER) {
$charMap += $charMaps[self::LDAP_ESCAPE_FILTER];
}
if ($flags & self::LDAP_ESCAPE_DN) {
$charMap += $charMaps[self::LDAP_ESCAPE_DN];
}
if (!$charMap) {
$charMap = $charMaps[0];
}
// Remove any chars to ignore from the list
$ignore = (string) $ignore;
for ($i = 0, $l = strlen($ignore); $i < $l; ++$i) {
unset($charMap[$ignore[$i]]);
}
// Do the main replacement
$result = strtr($subject, $charMap);
return $result;
}
}

15
vendor/symfony/polyfill-php56/README.md vendored Normal file
View File

@@ -0,0 +1,15 @@
Symfony Polyfill / Php56
========================
This component provides functions unavailable in releases prior to PHP 5.6:
- [`hash_equals`](http://php.net/hash_equals) (part of [hash](http://php.net/hash) extension)
- [`ldap_escape`](http://php.net/ldap_escape) (part of [ldap](http://php.net/ldap) extension)
More information can be found in the
[main Polyfill README](https://github.com/symfony/polyfill/blob/master/README.md).
License
=======
This library is released under the [MIT license](LICENSE).

View File

@@ -0,0 +1,38 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Symfony\Polyfill\Php56 as p;
if (PHP_VERSION_ID < 50600) {
if (!function_exists('hash_equals')) {
function hash_equals($knownString, $userInput) { return p\Php56::hash_equals($knownString, $userInput); }
}
if (extension_loaded('ldap') && !function_exists('ldap_escape')) {
define('LDAP_ESCAPE_FILTER', 1);
define('LDAP_ESCAPE_DN', 2);
function ldap_escape($subject, $ignore = '', $flags = 0) { return p\Php56::ldap_escape($subject, $ignore, $flags); }
}
if (50509 === PHP_VERSION_ID && 4 === PHP_INT_SIZE) {
// Missing functions in PHP 5.5.9 - affects 32 bit builds of Ubuntu 14.04LTS
// See https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1315888
if (!function_exists('gzopen') && function_exists('gzopen64')) {
function gzopen($filename, $mode, $use_include_path = 0) { return gzopen64($filename, $mode, $use_include_path); }
}
if (!function_exists('gzseek') && function_exists('gzseek64')) {
function gzseek($zp, $offset, $whence = SEEK_SET) { return gzseek64($zp, $offset, $whence); }
}
if (!function_exists('gztell') && function_exists('gztell64')) {
function gztell($zp) { return gztell64($zp); }
}
}
}

View File

@@ -0,0 +1,32 @@
{
"name": "symfony/polyfill-php56",
"type": "library",
"description": "Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions",
"keywords": ["polyfill", "shim", "compatibility", "portable"],
"homepage": "https://symfony.com",
"license": "MIT",
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"require": {
"php": ">=5.3.3",
"symfony/polyfill-util": "~1.0"
},
"autoload": {
"psr-4": { "Symfony\\Polyfill\\Php56\\": "" },
"files": [ "bootstrap.php" ]
},
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
}
}

18
vendor/symfony/polyfill-util/Binary.php vendored Normal file
View File

@@ -0,0 +1,18 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Polyfill\Util;
if (extension_loaded('mbstring')) {
class Binary extends BinaryOnFuncOverload {}
} else {
class Binary extends BinaryNoFuncOverload {}
}

View File

@@ -0,0 +1,65 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Polyfill\Util;
/**
* @author Nicolas Grekas <p@tchwork.com>
*
* @internal
*/
class BinaryNoFuncOverload
{
public static function strlen($s)
{
return strlen($s);
}
public static function strpos($haystack, $needle, $offset = 0)
{
return strpos($haystack, $needle, $offset);
}
public static function strrpos($haystack, $needle, $offset = 0)
{
return strrpos($haystack, $needle, $offset);
}
public static function substr($string, $start, $length = PHP_INT_MAX)
{
return substr($string, $start, $length);
}
public static function stripos($s, $needle, $offset = 0)
{
return stripos($s, $needle, $offset);
}
public static function stristr($s, $needle, $part = false)
{
return stristr($s, $needle, $part);
}
public static function strrchr($s, $needle, $part = false)
{
return strrchr($s, $needle, $part);
}
public static function strripos($s, $needle, $offset = 0)
{
return strripos($s, $needle, $offset);
}
public static function strstr($s, $needle, $part = false)
{
return strstr($s, $needle, $part);
}
}

View File

@@ -0,0 +1,67 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Polyfill\Util;
/**
* Binary safe version of string functions overloaded when MB_OVERLOAD_STRING is enabled.
*
* @author Nicolas Grekas <p@tchwork.com>
*
* @internal
*/
class BinaryOnFuncOverload
{
public static function strlen($s)
{
return mb_strlen($s, '8bit');
}
public static function strpos($haystack, $needle, $offset = 0)
{
return mb_strpos($haystack, $needle, $offset, '8bit');
}
public static function strrpos($haystack, $needle, $offset = 0)
{
return mb_strrpos($haystack, $needle, $offset, '8bit');
}
public static function substr($string, $start, $length = 2147483647)
{
return mb_substr($string, $start, $length, '8bit');
}
public static function stripos($s, $needle, $offset = 0)
{
return mb_stripos($s, $needle, $offset, '8bit');
}
public static function stristr($s, $needle, $part = false)
{
return mb_stristr($s, $needle, $part, '8bit');
}
public static function strrchr($s, $needle, $part = false)
{
return mb_strrchr($s, $needle, $part, '8bit');
}
public static function strripos($s, $needle, $offset = 0)
{
return mb_strripos($s, $needle, $offset, '8bit');
}
public static function strstr($s, $needle, $part = false)
{
return mb_strstr($s, $needle, $part, '8bit');
}
}

19
vendor/symfony/polyfill-util/LICENSE vendored Normal file
View File

@@ -0,0 +1,19 @@
Copyright (c) 2014-2015 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

13
vendor/symfony/polyfill-util/README.md vendored Normal file
View File

@@ -0,0 +1,13 @@
Symfony Polyfill / Util
=======================
This component provides binary-safe string functions, using the
[mbstring](https://php.net/mbstring) extension when available.
More information can be found in the
[main Polyfill README](https://github.com/symfony/polyfill/blob/master/README.md).
License
=======
This library is released under the [MIT license](LICENSE).

View File

@@ -0,0 +1,151 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Polyfill\Util;
/**
* @author Nicolas Grekas <p@tchwork.com>
*/
class TestListener extends \PHPUnit_Framework_TestSuite implements \PHPUnit_Framework_TestListener
{
public static $enabledPolyfills;
private $suite;
public function __construct(\PHPUnit_Framework_TestSuite $suite = null)
{
if ($suite) {
$this->suite = $suite;
$this->setName($suite->getName().' with polyfills enabled');
$this->addTest($suite);
}
}
public function startTestSuite(\PHPUnit_Framework_TestSuite $mainSuite)
{
if (null !== self::$enabledPolyfills) {
return;
}
self::$enabledPolyfills = false;
foreach ($mainSuite->tests() as $suite) {
$testClass = $suite->getName();
if (!$tests = $suite->tests()) {
continue;
}
if (!preg_match('/^(.+)\\\\Tests(\\\\.*)Test$/', $testClass, $m)) {
$mainSuite->addTest(self::warning('Unknown naming convention for '.$testClass));
continue;
}
$testedClass = new \ReflectionClass($m[1].$m[2]);
$bootstrap = new \SplFileObject(dirname($testedClass->getFileName()).'/bootstrap.php');
$warnings = array();
$defLine = null;
foreach (new \RegexIterator($bootstrap, '/return p\\\\'.$testedClass->getShortName().'::/') as $defLine) {
if (!preg_match('/^\s*function (?P<name>[^\(]++)(?P<signature>\([^\)]*+\)) \{ (?<return>return p\\\\'.$testedClass->getShortName().'::[^\(]++)(?P<args>\([^\)]*+\)); \}$/', $defLine, $f)) {
$warnings[] = self::warning('Invalid line in bootstrap.php: '.trim($defLine));
continue;
}
$testNamespace = substr($testClass, 0, strrpos($testClass, '\\'));
if (function_exists($testNamespace.'\\'.$f['name'])) {
continue;
}
try {
$r = new \ReflectionFunction($f['name']);
if ($r->isUserDefined()) {
throw new \ReflectionException();
}
if (false !== strpos($f['signature'], '&')) {
$defLine = sprintf('return \\%s%s', $f['name'], $f['args']);
} else {
$defLine = sprintf("return \\call_user_func_array('%s', func_get_args())", $f['name']);
}
} catch (\ReflectionException $e) {
$defLine = sprintf("throw new \PHPUnit_Framework_SkippedTestError('Internal function not found: %s')", $f['name']);
}
eval(<<<EOPHP
namespace {$testNamespace};
use Symfony\Polyfill\Util\TestListener;
use {$testedClass->getNamespaceName()} as p;
function {$f['name']}{$f['signature']}
{
if ('{$testClass}' === TestListener::\$enabledPolyfills) {
{$f['return']}{$f['args']};
}
{$defLine};
}
EOPHP
);
}
if (!$warnings && null === $defLine) {
$warnings[] = new \PHPUnit_Framework_SkippedTestCase('No Polyfills found in bootstrap.php for '.$testClass);
} else {
$mainSuite->addTest(new static($suite));
}
}
foreach ($warnings as $w) {
$mainSuite->addTest($w);
}
}
protected function setUp()
{
self::$enabledPolyfills = $this->suite->getName();
}
protected function tearDown()
{
self::$enabledPolyfills = false;
}
public function addError(\PHPUnit_Framework_Test $test, \Exception $e, $time)
{
if (false !== self::$enabledPolyfills) {
$r = new \ReflectionProperty('Exception', 'message');
$r->setAccessible(true);
$r->setValue($e, 'Polyfills enabled, '.$r->getValue($e));
}
}
public function addFailure(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $e, $time)
{
$this->addError($test, $e, $time);
}
public function addIncompleteTest(\PHPUnit_Framework_Test $test, \Exception $e, $time)
{
}
public function addRiskyTest(\PHPUnit_Framework_Test $test, \Exception $e, $time)
{
}
public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $time)
{
}
public function endTestSuite(\PHPUnit_Framework_TestSuite $suite)
{
}
public function startTest(\PHPUnit_Framework_Test $test)
{
}
public function endTest(\PHPUnit_Framework_Test $test, $time)
{
}
}

View File

@@ -0,0 +1,30 @@
{
"name": "symfony/polyfill-util",
"type": "library",
"description": "Symfony utilities for portability of PHP codes",
"keywords": ["polyfill", "shim", "compat", "compatibility"],
"homepage": "https://symfony.com",
"license": "MIT",
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"require": {
"php": ">=5.3.3"
},
"autoload": {
"psr-4": { "Symfony\\Polyfill\\Util\\": "" }
},
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
}
}

View File

@@ -1,6 +1,32 @@
CHANGELOG
=========
3.0.0
-----
* Yaml::parse() now throws an exception when a blackslash is not escaped
in double-quoted strings
2.8.0
-----
* Deprecated usage of a colon in an unquoted mapping value
* Deprecated usage of @, \`, | and > at the beginning of an unquoted string
* When surrounding strings with double-quotes, you must now escape `\` characters. Not
escaping those characters (when surrounded by double-quotes) is deprecated.
Before:
```yml
class: "Foo\Var"
```
After:
```yml
class: "Foo\\Var"
```
2.1.0
-----

View File

@@ -16,6 +16,8 @@ namespace Symfony\Component\Yaml;
* YAML strings.
*
* @author Matthew Lewinski <matthew@lewinski.org>
*
* @internal
*/
class Escaper
{

View File

@@ -123,12 +123,7 @@ class ParseException extends RuntimeException
}
if (null !== $this->parsedFile) {
if (PHP_VERSION_ID >= 50400) {
$jsonOptions = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
} else {
$jsonOptions = 0;
}
$this->message .= sprintf(' in %s', json_encode($this->parsedFile, $jsonOptions));
$this->message .= sprintf(' in %s', json_encode($this->parsedFile, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
}
if ($this->parsedLine >= 0) {

View File

@@ -52,7 +52,7 @@ class Inline
return '';
}
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
if (2 /* MB_OVERLOAD_STRING */ & (int) ini_get('mbstring.func_overload')) {
$mbEncoding = mb_internal_encoding();
mb_internal_encoding('ASCII');
}
@@ -204,6 +204,8 @@ class Inline
* @return string A YAML string
*
* @throws ParseException When malformed inline YAML string is parsed
*
* @internal
*/
public static function parseScalar($scalar, $delimiters = null, $stringDelimiters = array('"', "'"), &$i = 0, $evaluate = true, $references = array())
{
@@ -234,6 +236,11 @@ class Inline
throw new ParseException(sprintf('Malformed inline YAML string (%s).', $scalar));
}
// a non-quoted string cannot start with @ or ` (reserved) nor with a scalar indicator (| or >)
if ($output && ('@' === $output[0] || '`' === $output[0] || '|' === $output[0] || '>' === $output[0])) {
throw new ParseException(sprintf('The reserved indicator "%s" cannot start a plain scalar; you need to quote the scalar.', $output[0]));
}
if ($evaluate) {
$output = self::evaluateScalar($output, $references);
}

View File

@@ -21,8 +21,6 @@ use Symfony\Component\Yaml\Exception\ParseException;
class Parser
{
const BLOCK_SCALAR_HEADER_PATTERN = '(?P<separator>\||>)(?P<modifiers>\+|\-|\d+|\+\d+|\-\d+|\d+\+|\d+\-)?(?P<comments> +#.*)?';
// BC - wrongly named
const FOLDED_SCALAR_PATTERN = self::BLOCK_SCALAR_HEADER_PATTERN;
private $offset = 0;
private $lines = array();
@@ -62,7 +60,7 @@ class Parser
$value = $this->cleanup($value);
$this->lines = explode("\n", $value);
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
if (2 /* MB_OVERLOAD_STRING */ & (int) ini_get('mbstring.func_overload')) {
$mbEncoding = mb_internal_encoding();
mb_internal_encoding('UTF-8');
}
@@ -114,7 +112,7 @@ class Parser
$data[] = $parser->parse($block, $exceptionOnInvalidType, $objectSupport, $objectForMap);
} else {
$data[] = $this->parseValue($values['value'], $exceptionOnInvalidType, $objectSupport, $objectForMap);
$data[] = $this->parseValue($values['value'], $exceptionOnInvalidType, $objectSupport, $objectForMap, $context);
}
}
if ($isRef) {
@@ -230,7 +228,7 @@ class Parser
}
}
} else {
$value = $this->parseValue($values['value'], $exceptionOnInvalidType, $objectSupport, $objectForMap);
$value = $this->parseValue($values['value'], $exceptionOnInvalidType, $objectSupport, $objectForMap, $context);
// Spec: Keys MUST be unique; first one wins.
// But overwriting is allowed when a merge node is used in current block.
if ($allowOverwrite || !isset($data[$key])) {
@@ -240,6 +238,10 @@ class Parser
if ($isRef) {
$this->refs[$isRef] = $data[$key];
}
if ($objectForMap && !is_object($data)) {
$data = (object) $data;
}
} else {
// multiple documents are not supported
if ('---' === $this->currentLine) {
@@ -339,6 +341,7 @@ class Parser
private function getNextEmbedBlock($indentation = null, $inSequence = false)
{
$oldLineIndentation = $this->getCurrentLineIndentation();
$insideBlockScalar = $this->isBlockScalarHeader();
if (!$this->moveToNextLine()) {
return;
@@ -347,7 +350,7 @@ class Parser
if (null === $indentation) {
$newIndent = $this->getCurrentLineIndentation();
$unindentedEmbedBlock = $this->isStringUnIndentedCollectionItem($this->currentLine);
$unindentedEmbedBlock = $this->isStringUnIndentedCollectionItem();
if (!$this->isCurrentLineEmpty() && 0 === $newIndent && !$unindentedEmbedBlock) {
throw new ParseException('Indentation problem.', $this->getRealCurrentLineNb() + 1, $this->currentLine);
@@ -373,20 +376,24 @@ class Parser
return;
}
$isItUnindentedCollection = $this->isStringUnIndentedCollectionItem($this->currentLine);
$isItUnindentedCollection = $this->isStringUnIndentedCollectionItem();
// Comments must not be removed inside a block scalar
$removeCommentsPattern = '~'.self::BLOCK_SCALAR_HEADER_PATTERN.'$~';
$removeComments = !preg_match($removeCommentsPattern, $this->currentLine);
if (!$insideBlockScalar) {
$insideBlockScalar = $this->isBlockScalarHeader();
}
$previousLineIndentation = $this->getCurrentLineIndentation();
while ($this->moveToNextLine()) {
$indent = $this->getCurrentLineIndentation();
if ($indent === $newIndent) {
$removeComments = !preg_match($removeCommentsPattern, $this->currentLine);
if (!$insideBlockScalar && $indent === $previousLineIndentation) {
$insideBlockScalar = $this->isBlockScalarHeader();
}
if ($isItUnindentedCollection && !$this->isStringUnIndentedCollectionItem($this->currentLine) && $newIndent === $indent) {
$previousLineIndentation = $indent;
if ($isItUnindentedCollection && !$this->isStringUnIndentedCollectionItem() && $newIndent === $indent) {
$this->moveToPreviousLine();
break;
}
@@ -396,7 +403,8 @@ class Parser
continue;
}
if ($removeComments && $this->isCurrentLineComment()) {
// we ignore "comment" lines only when we are not inside a scalar block
if (!$insideBlockScalar && $this->isCurrentLineComment()) {
continue;
}
@@ -445,12 +453,13 @@ class Parser
* @param bool $exceptionOnInvalidType True if an exception must be thrown on invalid types false otherwise
* @param bool $objectSupport True if object support is enabled, false otherwise
* @param bool $objectForMap true if maps should return a stdClass instead of array()
* @param string $context The parser context (either sequence or mapping)
*
* @return mixed A PHP value
*
* @throws ParseException When reference does not exist
*/
private function parseValue($value, $exceptionOnInvalidType, $objectSupport, $objectForMap)
private function parseValue($value, $exceptionOnInvalidType, $objectSupport, $objectForMap, $context)
{
if (0 === strpos($value, '*')) {
if (false !== $pos = strpos($value, '#')) {
@@ -473,7 +482,13 @@ class Parser
}
try {
return Inline::parse($value, $exceptionOnInvalidType, $objectSupport, $objectForMap, $this->refs);
$parsedValue = Inline::parse($value, $exceptionOnInvalidType, $objectSupport, $objectForMap, $this->refs);
if ('mapping' === $context && '"' !== $value[0] && "'" !== $value[0] && '[' !== $value[0] && '{' !== $value[0] && '!' !== $value[0] && false !== strpos($parsedValue, ': ')) {
throw new ParseException('A colon cannot be used in an unquoted mapping value.');
}
return $parsedValue;
} catch (ParseException $e) {
$e->setParsedLine($this->getRealCurrentLineNb() + 1);
$e->setSnippet($this->currentLine);
@@ -499,13 +514,13 @@ class Parser
}
$isCurrentLineBlank = $this->isCurrentLineBlank();
$text = '';
$blockLines = array();
// leading blank lines are consumed before determining indentation
while ($notEOF && $isCurrentLineBlank) {
// newline only if not EOF
if ($notEOF = $this->moveToNextLine()) {
$text .= "\n";
$blockLines[] = '';
$isCurrentLineBlank = $this->isCurrentLineBlank();
}
}
@@ -526,37 +541,59 @@ class Parser
preg_match($pattern, $this->currentLine, $matches)
)
) {
if ($isCurrentLineBlank) {
$text .= substr($this->currentLine, $indentation);
if ($isCurrentLineBlank && strlen($this->currentLine) > $indentation) {
$blockLines[] = substr($this->currentLine, $indentation);
} elseif ($isCurrentLineBlank) {
$blockLines[] = '';
} else {
$text .= $matches[1];
$blockLines[] = $matches[1];
}
// newline only if not EOF
if ($notEOF = $this->moveToNextLine()) {
$text .= "\n";
$isCurrentLineBlank = $this->isCurrentLineBlank();
}
}
} elseif ($notEOF) {
$text .= "\n";
$blockLines[] = '';
}
if ($notEOF) {
$blockLines[] = '';
$this->moveToPreviousLine();
}
// folded style
if ('>' === $style) {
// folded lines
// replace all non-leading/non-trailing single newlines with spaces
preg_match('/(\n*)$/', $text, $matches);
$text = preg_replace('/(?<!\n|^)\n(?!\n)/', ' ', rtrim($text, "\n"));
$text .= $matches[1];
$text = '';
$previousLineIndented = false;
$previousLineBlank = false;
// empty separation lines
// remove one newline from each group of non-leading/non-trailing newlines
$text = preg_replace('/[^\n]\n+\K\n(?=[^\n])/', '', $text);
for ($i = 0; $i < count($blockLines); $i++) {
if ('' === $blockLines[$i]) {
$text .= "\n";
$previousLineIndented = false;
$previousLineBlank = true;
} elseif (' ' === $blockLines[$i][0]) {
$text .= "\n".$blockLines[$i];
$previousLineIndented = true;
$previousLineBlank = false;
} elseif ($previousLineIndented) {
$text .= "\n".$blockLines[$i];
$previousLineIndented = false;
$previousLineBlank = false;
} elseif ($previousLineBlank || 0 === $i) {
$text .= $blockLines[$i];
$previousLineIndented = false;
$previousLineBlank = false;
} else {
$text .= ' '.$blockLines[$i];
$previousLineIndented = false;
$previousLineBlank = false;
}
}
} else {
$text = implode("\n", $blockLines);
}
// deal with trailing newlines
@@ -690,7 +727,7 @@ class Parser
if (
$this->getCurrentLineIndentation() == $currentIndentation
&&
$this->isStringUnIndentedCollectionItem($this->currentLine)
$this->isStringUnIndentedCollectionItem()
) {
$ret = true;
}
@@ -707,6 +744,16 @@ class Parser
*/
private function isStringUnIndentedCollectionItem()
{
return (0 === strpos($this->currentLine, '- '));
return 0 === strpos($this->currentLine, '- ');
}
/**
* Tests whether or not the current line is the header of a block scalar.
*
* @return bool
*/
private function isBlockScalarHeader()
{
return (bool) preg_match('~'.self::BLOCK_SCALAR_HEADER_PATTERN.'$~', $this->currentLine);
}
}

View File

@@ -145,3 +145,11 @@ php: |
array(
'double' => "some value\n \"some quoted string\" and 'some single quotes one'"
)
---
test: Backslashes
yaml: |
{ single: 'foo\Var', no-quotes: foo\Var, double: "foo\\Var" }
php: |
array(
'single' => 'foo\Var', 'no-quotes' => 'foo\Var', 'double' => 'foo\Var'
)

View File

@@ -3,7 +3,7 @@ test: Some characters at the beginning of a string must be escaped
brief: >
Some characters at the beginning of a string must be escaped
yaml: |
foo: | bar
foo: '| bar'
php: |
array('foo' => '| bar')
---

View File

@@ -58,10 +58,8 @@ class InlineTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('1.2', Inline::dump(1.2));
$this->assertContains('fr', strtolower(setlocale(LC_NUMERIC, 0)));
} finally {
setlocale(LC_NUMERIC, $locale);
} catch (\Exception $e) {
setlocale(LC_NUMERIC, $locale);
throw $e;
}
}
@@ -72,6 +70,23 @@ class InlineTest extends \PHPUnit_Framework_TestCase
$this->assertSame($value, Inline::parse(Inline::dump($value)));
}
/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage Found unknown escape character "\V".
*/
public function testParseScalarWithNonEscapedBlackslashShouldThrowException()
{
Inline::parse('"Foo\Var"');
}
/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
*/
public function testParseScalarWithNonEscapedBlackslashAtTheEndShouldThrowException()
{
Inline::parse('"Foo\\"');
}
/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
*/
@@ -173,6 +188,36 @@ class InlineTest extends \PHPUnit_Framework_TestCase
Inline::parse('{ foo: * #foo }');
}
/**
* @dataProvider getReservedIndicators
* @expectedException Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage cannot start a plain scalar; you need to quote the scalar.
*/
public function testParseUnquotedScalarStartingWithReservedIndicator($indicator)
{
Inline::parse(sprintf('{ foo: %sfoo }', $indicator));
}
public function getReservedIndicators()
{
return array(array('@'), array('`'));
}
/**
* @dataProvider getScalarIndicators
* @expectedException Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage cannot start a plain scalar; you need to quote the scalar.
*/
public function testParseUnquotedScalarStartingWithScalarIndicator($indicator)
{
Inline::parse(sprintf('{ foo: %sfoo }', $indicator));
}
public function getScalarIndicators()
{
return array(array('|'), array('>'));
}
public function getTestsForParse()
{
return array(

View File

@@ -18,11 +18,7 @@ class ParseExceptionTest extends \PHPUnit_Framework_TestCase
public function testGetMessage()
{
$exception = new ParseException('Error message', 42, 'foo: bar', '/var/www/app/config.yml');
if (PHP_VERSION_ID >= 50400) {
$message = 'Error message in "/var/www/app/config.yml" at line 42 (near "foo: bar")';
} else {
$message = 'Error message in "\\/var\\/www\\/app\\/config.yml" at line 42 (near "foo: bar")';
}
$message = 'Error message in "/var/www/app/config.yml" at line 42 (near "foo: bar")';
$this->assertEquals($message, $exception->getMessage());
}
@@ -30,11 +26,7 @@ class ParseExceptionTest extends \PHPUnit_Framework_TestCase
public function testGetMessageWithUnicodeInFilename()
{
$exception = new ParseException('Error message', 42, 'foo: bar', 'äöü.yml');
if (PHP_VERSION_ID >= 50400) {
$message = 'Error message in "äöü.yml" at line 42 (near "foo: bar")';
} else {
$message = 'Error message in "\u00e4\u00f6\u00fc.yml" at line 42 (near "foo: bar")';
}
$message = 'Error message in "äöü.yml" at line 42 (near "foo: bar")';
$this->assertEquals($message, $exception->getMessage());
}

View File

@@ -438,6 +438,28 @@ EOF;
$this->assertEquals(array('foo' => null, 'bar' => 1), $this->parser->parse($input), '->parse() does not parse objects');
}
public function testObjectForMapEnabledWithMapping()
{
$yaml = <<<EOF
foo:
fiz: [cat]
EOF;
$result = $this->parser->parse($yaml, false, false, true);
$this->assertInstanceOf('stdClass', $result);
$this->assertInstanceOf('stdClass', $result->foo);
$this->assertEquals(array('cat'), $result->foo->fiz);
}
public function testObjectForMapEnabledWithInlineMapping()
{
$result = $this->parser->parse('{ "foo": "bar", "fiz": "cat" }', false, false, true);
$this->assertInstanceOf('stdClass', $result);
$this->assertEquals('bar', $result->foo);
$this->assertEquals('cat', $result->fiz);
}
/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
*/
@@ -572,8 +594,6 @@ EOF
*
* @see http://yaml.org/spec/1.2/spec.html#id2759572
* @see http://yaml.org/spec/1.1/#id932806
*
* @covers \Symfony\Component\Yaml\Parser::parse
*/
public function testMappingDuplicateKeyBlock()
{
@@ -593,9 +613,6 @@ EOD;
$this->assertSame($expected, Yaml::parse($input));
}
/**
* @covers \Symfony\Component\Yaml\Inline::parseMapping
*/
public function testMappingDuplicateKeyFlow()
{
$input = <<<EOD
@@ -788,6 +805,174 @@ EOF;
$this->assertEquals($expected, $this->parser->parse($yaml));
}
/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage A colon cannot be used in an unquoted mapping value
*/
public function testColonInMappingValueException()
{
$yaml = <<<EOF
foo: bar: baz
EOF;
$this->parser->parse($yaml);
}
public function testColonInMappingValueExceptionNotTriggeredByColonInComment()
{
$yaml = <<<EOT
foo:
bar: foobar # Note: a comment after a colon
EOT;
$this->assertSame(array('foo' => array('bar' => 'foobar')), $this->parser->parse($yaml));
}
/**
* @dataProvider getCommentLikeStringInScalarBlockData
*/
public function testCommentLikeStringsAreNotStrippedInBlockScalars($yaml, $expectedParserResult)
{
$this->assertSame($expectedParserResult, $this->parser->parse($yaml));
}
public function getCommentLikeStringInScalarBlockData()
{
$yaml1 = <<<EOT
pages:
-
title: some title
content: |
# comment 1
header
# comment 2
<body>
<h1>title</h1>
</body>
footer # comment3
EOT;
$expected1 = array(
'pages' => array(
array(
'title' => 'some title',
'content' => <<<EOT
# comment 1
header
# comment 2
<body>
<h1>title</h1>
</body>
footer # comment3
EOT
,
),
),
);
$yaml2 = <<<EOT
test: |
foo
# bar
baz
collection:
- one: |
foo
# bar
baz
- two: |
foo
# bar
baz
EOT;
$expected2 = array(
'test' => <<<EOT
foo
# bar
baz
EOT
,
'collection' => array(
array(
'one' => <<<EOT
foo
# bar
baz
EOT
,
),
array(
'two' => <<<EOT
foo
# bar
baz
EOT
,
),
),
);
return array(
array($yaml1, $expected1),
array($yaml2, $expected2),
);
}
public function testBlankLinesAreParsedAsNewLinesInFoldedBlocks()
{
$yaml = <<<EOT
test: >
<h2>A heading</h2>
<ul>
<li>a list</li>
<li>may be a good example</li>
</ul>
EOT;
$this->assertSame(
array(
'test' => <<<EOT
<h2>A heading</h2>
<ul> <li>a list</li> <li>may be a good example</li> </ul>
EOT
,
),
$this->parser->parse($yaml)
);
}
public function testAdditionallyIndentedLinesAreParsedAsNewLinesInFoldedBlocks()
{
$yaml = <<<EOT
test: >
<h2>A heading</h2>
<ul>
<li>a list</li>
<li>may be a good example</li>
</ul>
EOT;
$this->assertSame(
array(
'test' => <<<EOT
<h2>A heading</h2>
<ul>
<li>a list</li>
<li>may be a good example</li>
</ul>
EOT
,
),
$this->parser->parse($yaml)
);
}
}
class B

View File

@@ -22,16 +22,4 @@ class YamlTest extends \PHPUnit_Framework_TestCase
$parsed = Yaml::parse($yml);
$this->assertEquals($data, $parsed);
}
/**
* @group legacy
*/
public function testLegacyParseFromFile()
{
$filename = __DIR__.'/Fixtures/index.yml';
$contents = file_get_contents($filename);
$parsedByFilename = Yaml::parse($filename);
$parsedByContents = Yaml::parse($contents);
$this->assertEquals($parsedByFilename, $parsedByContents);
}
}

View File

@@ -11,28 +11,22 @@
namespace Symfony\Component\Yaml;
use Symfony\Component\Yaml\Exception\ParseException;
/**
* Unescaper encapsulates unescaping rules for single and double-quoted
* YAML strings.
*
* @author Matthew Lewinski <matthew@lewinski.org>
*
* @internal
*/
class Unescaper
{
/**
* Parser and Inline assume UTF-8 encoding, so escaped Unicode characters
* must be converted to that encoding.
*
* @deprecated since version 2.5, to be removed in 3.0
*
* @internal
*/
const ENCODING = 'UTF-8';
/**
* Regex fragment that matches an escaped character in a double quoted string.
*/
const REGEX_ESCAPED_CHARACTER = "\\\\([0abt\tnvfre \\\"\\/\\\\N_LP]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})";
const REGEX_ESCAPED_CHARACTER = "\\\\(x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|.)";
/**
* Unescapes a single quoted string.
@@ -55,9 +49,8 @@ class Unescaper
*/
public function unescapeDoubleQuotedString($value)
{
$self = $this;
$callback = function ($match) use ($self) {
return $self->unescapeCharacter($match[0]);
$callback = function ($match) {
return $this->unescapeCharacter($match[0]);
};
// evaluate the string
@@ -71,9 +64,9 @@ class Unescaper
*
* @return string The unescaped character
*/
public function unescapeCharacter($value)
private function unescapeCharacter($value)
{
switch ($value{1}) {
switch ($value[1]) {
case '0':
return "\x0";
case 'a':
@@ -120,6 +113,8 @@ class Unescaper
return self::utf8chr(hexdec(substr($value, 2, 4)));
case 'U':
return self::utf8chr(hexdec(substr($value, 2, 8)));
default:
throw new ParseException(sprintf('Found unknown escape character "%s".', $value));
}
}

View File

@@ -32,13 +32,7 @@ class Yaml
* print_r($array);
* </code>
*
* As this method accepts both plain strings and file names as an input,
* you must validate the input before calling this method. Passing a file
* as an input is a deprecated feature and will be removed in 3.0.
*
* 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.
*
* @param string $input Path to a YAML file or a string containing YAML
* @param string $input A string containing YAML
* @param bool $exceptionOnInvalidType True if an exception must be thrown on invalid types false otherwise
* @param bool $objectSupport True if object support is enabled, false otherwise
* @param bool $objectForMap True if maps should return a stdClass instead of array()
@@ -49,30 +43,9 @@ class Yaml
*/
public static function parse($input, $exceptionOnInvalidType = false, $objectSupport = false, $objectForMap = false)
{
// if input is a file, process it
$file = '';
if (strpos($input, "\n") === false && is_file($input)) {
@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);
if (false === is_readable($input)) {
throw new ParseException(sprintf('Unable to parse "%s" as the file is not readable.', $input));
}
$file = $input;
$input = file_get_contents($file);
}
$yaml = new Parser();
try {
return $yaml->parse($input, $exceptionOnInvalidType, $objectSupport, $objectForMap);
} catch (ParseException $e) {
if ($file) {
$e->setParsedFile($file);
}
throw $e;
}
return $yaml->parse($input, $exceptionOnInvalidType, $objectSupport, $objectForMap);
}
/**

View File

@@ -16,15 +16,18 @@
}
],
"require": {
"php": ">=5.3.9"
"php": ">=5.5.9"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Yaml\\": "" }
"psr-4": { "Symfony\\Component\\Yaml\\": "" },
"exclude-from-classmap": [
"/Tests/"
]
},
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "2.7-dev"
"dev-master": "3.0-dev"
}
}
}

View File

@@ -20,8 +20,8 @@
<whitelist>
<directory>./</directory>
<exclude>
<directory>./vendor</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>