Skip to content

Commit 6ec5537

Browse files
committed
Merge branch '2.3' into 2.7
* 2.3: [Process] Remove a misleading comment Improve the phpdoc of SplFileInfo methods [Process] Use stream based storage to avoid memory issues Fixed the documentation of VoterInterface::supportsAttribute Remove useless duplicated tests [FrameworkBundle] Optimize framework extension tests Use is_subclass_of instead of Reflection when possible
2 parents 20f0d60 + 6d8078f commit 6ec5537

File tree

6 files changed

+41
-29
lines changed

6 files changed

+41
-29
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
abstract class FrameworkExtensionTest extends TestCase
2424
{
25+
private static $containerCache = array();
26+
2527
abstract protected function loadFromFile(ContainerBuilder $container, $file);
2628

2729
public function testCsrfProtection()
@@ -470,6 +472,10 @@ protected function createContainer(array $data = array())
470472

471473
protected function createContainerFromFile($file, $data = array())
472474
{
475+
$cacheKey = md5($file.serialize($data));
476+
if (isset(self::$containerCache[$cacheKey])) {
477+
return self::$containerCache[$cacheKey];
478+
}
473479
$container = $this->createContainer($data);
474480
$container->registerExtension(new FrameworkExtension());
475481
$this->loadFromFile($container, $file);
@@ -478,7 +484,7 @@ protected function createContainerFromFile($file, $data = array())
478484
$container->getCompilerPassConfig()->setRemovingPasses(array());
479485
$container->compile();
480486

481-
return $container;
487+
return self::$containerCache[$cacheKey] = $container;
482488
}
483489

484490
protected function createContainerFromClosure($closure, $data = array())

src/Symfony/Component/Finder/SplFileInfo.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public function __construct($file, $relativePath, $relativePathname)
3838
/**
3939
* Returns the relative path.
4040
*
41+
* This path does not contain the file name.
42+
*
4143
* @return string the relative path
4244
*/
4345
public function getRelativePath()
@@ -48,6 +50,8 @@ public function getRelativePath()
4850
/**
4951
* Returns the relative path name.
5052
*
53+
* This path contains the file name.
54+
*
5155
* @return string the relative path name
5256
*/
5357
public function getRelativePathname()

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717

1818
class RequestTest extends \PHPUnit_Framework_TestCase
1919
{
20-
public function testConstructor()
21-
{
22-
$this->testInitialize();
23-
}
24-
2520
public function testInitialize()
2621
{
2722
$request = new Request();

src/Symfony/Component/Process/Process.php

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,6 @@ public function mustRun($callback = null)
240240
* The callback receives the type of output (out or err) and some bytes from
241241
* the output in real-time while writing the standard input to the process.
242242
* It allows to have feedback from the independent process during execution.
243-
* If there is no callback passed, the wait() method can be called
244-
* with true as a second parameter then the callback will get all data occurred
245-
* in (and since) the start call.
246243
*
247244
* @param callable|null $callback A PHP callback to run whenever there is some
248245
* output available on STDOUT or STDERR
@@ -474,7 +471,11 @@ public function getOutput()
474471

475472
$this->readPipes(false, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);
476473

477-
return $this->stdout;
474+
if (false === $ret = stream_get_contents($this->stdout, -1, 0)) {
475+
return '';
476+
}
477+
478+
return $ret;
478479
}
479480

480481
/**
@@ -492,16 +493,13 @@ public function getIncrementalOutput()
492493
{
493494
$this->requireProcessIsStarted(__FUNCTION__);
494495

495-
$data = $this->getOutput();
496-
497-
$latest = substr($data, $this->incrementalOutputOffset);
496+
$latest = stream_get_contents($this->stdout, -1, $this->incrementalOutputOffset);
497+
$this->incrementalOutputOffset = ftell($this->stdout);
498498

499499
if (false === $latest) {
500500
return '';
501501
}
502502

503-
$this->incrementalOutputOffset = strlen($data);
504-
505503
return $latest;
506504
}
507505

@@ -536,7 +534,11 @@ public function getErrorOutput()
536534

537535
$this->readPipes(false, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);
538536

539-
return $this->stderr;
537+
if (false === $ret = stream_get_contents($this->stderr, -1, 0)) {
538+
return '';
539+
}
540+
541+
return $ret;
540542
}
541543

542544
/**
@@ -555,16 +557,13 @@ public function getIncrementalErrorOutput()
555557
{
556558
$this->requireProcessIsStarted(__FUNCTION__);
557559

558-
$data = $this->getErrorOutput();
559-
560-
$latest = substr($data, $this->incrementalErrorOutputOffset);
560+
$latest = stream_get_contents($this->stderr, -1, $this->incrementalErrorOutputOffset);
561+
$this->incrementalErrorOutputOffset = ftell($this->stderr);
561562

562563
if (false === $latest) {
563564
return '';
564565
}
565566

566-
$this->incrementalErrorOutputOffset = strlen($data);
567-
568567
return $latest;
569568
}
570569

@@ -795,23 +794,33 @@ public function stop($timeout = 10, $signal = null)
795794
/**
796795
* Adds a line to the STDOUT stream.
797796
*
797+
* @internal
798+
*
798799
* @param string $line The line to append
799800
*/
800801
public function addOutput($line)
801802
{
802803
$this->lastOutputTime = microtime(true);
803-
$this->stdout .= $line;
804+
805+
fseek($this->stdout, 0, SEEK_END);
806+
fwrite($this->stdout, $line);
807+
fseek($this->stdout, $this->incrementalOutputOffset);
804808
}
805809

806810
/**
807811
* Adds a line to the STDERR stream.
808812
*
813+
* @internal
814+
*
809815
* @param string $line The line to append
810816
*/
811817
public function addErrorOutput($line)
812818
{
813819
$this->lastOutputTime = microtime(true);
814-
$this->stderr .= $line;
820+
821+
fseek($this->stderr, 0, SEEK_END);
822+
fwrite($this->stderr, $line);
823+
fseek($this->stderr, $this->incrementalErrorOutputOffset);
815824
}
816825

817826
/**
@@ -1393,8 +1402,8 @@ private function resetProcessData()
13931402
$this->exitcode = null;
13941403
$this->fallbackStatus = array();
13951404
$this->processInformation = null;
1396-
$this->stdout = null;
1397-
$this->stderr = null;
1405+
$this->stdout = fopen('php://temp/maxmemory:'.(1024 * 1024), 'wb+');
1406+
$this->stderr = fopen('php://temp/maxmemory:'.(1024 * 1024), 'wb+');
13981407
$this->process = null;
13991408
$this->latestSignal = null;
14001409
$this->status = self::STATUS_READY;

src/Symfony/Component/Security/Core/Authorization/Voter/VoterInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface VoterInterface
2727
/**
2828
* Checks if the voter supports the given attribute.
2929
*
30-
* @param string $attribute An attribute
30+
* @param mixed $attribute An attribute (usually the attribute name string)
3131
*
3232
* @return bool true if this Voter supports the attribute, false otherwise
3333
*/

src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ public function supportsNormalization($data, $format = null)
5959
*/
6060
public function supportsDenormalization($data, $type, $format = null)
6161
{
62-
$class = new \ReflectionClass($type);
63-
64-
return $class->isSubclassOf('Symfony\Component\Serializer\Normalizer\DenormalizableInterface');
62+
return is_subclass_of($type, 'Symfony\Component\Serializer\Normalizer\DenormalizableInterface');
6563
}
6664
}

0 commit comments

Comments
 (0)