Skip to content

Commit 440dcb3

Browse files
committed
Merge remote branch 'origin/master' into methodInjection
2 parents bdcf802 + 3854d34 commit 440dcb3

File tree

63 files changed

+716
-172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+716
-172
lines changed

UPDATE.md

+7
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ beta1 to beta2
123123
'allow_add' => true,
124124
'allow_delete' => true,
125125
));
126+
127+
* Request::hasSession() has been renamed to Request::hasPreviousSession(). The
128+
method hasSession() still exists, but only checks if the request contains a
129+
session object, not if the session was started in a previous request.
126130

127131
* Serializer: The NormalizerInterface's `supports()` method has been split in
128132
two methods: `supportsNormalization` and `supportsDenormalization`.
@@ -147,6 +151,9 @@ PR12 to beta1
147151
* The `File::getWebPath()` and `File::rename()` methods have been removed, as
148152
well as the `framework.document_root` configuration setting.
149153

154+
* The `File::getDefaultExtension()` method has been renamed to `File::guessExtension()`.
155+
The renamed method now returns null if it cannot guess the extension.
156+
150157
* The `session` configuration has been refactored:
151158

152159
* The `class` option has been removed (use the `session.class` parameter

src/Symfony/Bundle/MonologBundle/Logger/DebugHandler.php renamed to src/Symfony/Bridge/Monolog/Handler/DebugHandler.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Bundle\MonologBundle\Logger;
12+
namespace Symfony\Bridge\Monolog\Handler;
1313

14-
use Monolog\Logger as MonologLogger;
14+
use Monolog\Logger;
1515
use Monolog\Handler\TestHandler;
1616
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
1717

@@ -46,7 +46,7 @@ public function getLogs()
4646
public function countErrors()
4747
{
4848
$cnt = 0;
49-
foreach (array(MonologLogger::ERROR, MonologLogger::CRITICAL, MonologLogger::ALERT) as $level) {
49+
foreach (array(Logger::ERROR, Logger::CRITICAL, Logger::ALERT) as $level) {
5050
if (isset($this->recordsByLevel[$level])) {
5151
$cnt += count($this->recordsByLevel[$level]);
5252
}

src/Symfony/Bundle/MonologBundle/Logger/FirePHPHandler.php renamed to src/Symfony/Bridge/Monolog/Handler/FirePHPHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Bundle\MonologBundle\Logger;
12+
namespace Symfony\Bridge\Monolog\Handler;
1313

1414
use Monolog\Handler\FirePHPHandler as BaseFirePHPHandler;
1515
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;

src/Symfony/Bundle/MonologBundle/Logger/Logger.php renamed to src/Symfony/Bridge/Monolog/Logger.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Bundle\MonologBundle\Logger;
12+
namespace Symfony\Bridge\Monolog;
1313

1414
use Monolog\Logger as BaseLogger;
1515
use Symfony\Component\HttpKernel\Log\LoggerInterface;
@@ -35,9 +35,4 @@ public function getDebugLogger()
3535
}
3636
}
3737
}
38-
39-
public function log($message, $level)
40-
{
41-
return $this->addRecord($level, $message);
42-
}
4338
}

src/Symfony/Bundle/AsseticBundle/Command/DumpCommand.php

+62-35
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
*/
2727
class DumpCommand extends Command
2828
{
29+
private $basePath;
30+
private $am;
31+
2932
protected function configure()
3033
{
3134
$this
@@ -36,21 +39,29 @@ protected function configure()
3639
;
3740
}
3841

39-
protected function execute(InputInterface $input, OutputInterface $output)
42+
protected function initialize(InputInterface $input, OutputInterface $output)
4043
{
41-
if (!$basePath = $input->getArgument('write_to')) {
42-
$basePath = $this->container->getParameter('assetic.write_to');
43-
}
44+
parent::initialize($input, $output);
4445

45-
$am = $this->container->get('assetic.asset_manager');
46+
$this->basePath = $input->getArgument('write_to') ?: $this->container->getParameter('assetic.write_to');
47+
$this->am = $this->container->get('assetic.asset_manager');
48+
}
49+
50+
protected function execute(InputInterface $input, OutputInterface $output)
51+
{
52+
if (!$input->getOption('watch')) {
53+
foreach ($this->am->getNames() as $name) {
54+
$this->dumpAsset($name, $output);
55+
}
4656

47-
if ($input->getOption('watch')) {
48-
return $this->watch($am, $basePath, $output, $this->container->getParameter('kernel.debug'));
57+
return;
4958
}
5059

51-
foreach ($am->getNames() as $name) {
52-
$this->dumpAsset($am->get($name), $basePath, $output);
60+
if (!$this->am->isDebug()) {
61+
throw new \RuntimeException('The --watch option is only available in debug mode.');
5362
}
63+
64+
$this->watch($output);
5465
}
5566

5667
/**
@@ -59,22 +70,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
5970
* This method includes an infinite loop the continuously polls the asset
6071
* manager for changes.
6172
*
62-
* @param LazyAssetManager $am The asset manager
63-
* @param string $basePath The base directory to write to
64-
* @param OutputInterface $output The command output
65-
* @param Boolean $debug Debug mode
73+
* @param OutputInterface $output The command output
6674
*/
67-
protected function watch(LazyAssetManager $am, $basePath, OutputInterface $output, $debug = false)
75+
private function watch(OutputInterface $output)
6876
{
69-
if (!$debug) {
70-
throw new \RuntimeException('The --watch option is only available in debug mode.');
71-
}
72-
7377
$refl = new \ReflectionClass('Assetic\\AssetManager');
7478
$prop = $refl->getProperty('assets');
7579
$prop->setAccessible(true);
7680

77-
$cache = sys_get_temp_dir().'/assetic_watch_'.substr(sha1($basePath), 0, 7);
81+
$cache = sys_get_temp_dir().'/assetic_watch_'.substr(sha1($this->basePath), 0, 7);
7882
if (file_exists($cache)) {
7983
$previously = unserialize(file_get_contents($cache));
8084
} else {
@@ -84,15 +88,15 @@ protected function watch(LazyAssetManager $am, $basePath, OutputInterface $outpu
8488
$error = '';
8589
while (true) {
8690
try {
87-
foreach ($am->getNames() as $name) {
88-
if ($asset = $this->checkAsset($am, $name, $previously)) {
89-
$this->dumpAsset($asset, $basePath, $output);
91+
foreach ($this->am->getNames() as $name) {
92+
if ($asset = $this->checkAsset($name, $previously)) {
93+
$this->dumpAsset($asset, $output);
9094
}
9195
}
9296

9397
// reset the asset manager
94-
$prop->setValue($am, array());
95-
$am->load();
98+
$prop->setValue($this->am, array());
99+
$this->am->load();
96100

97101
file_put_contents($cache, serialize($previously));
98102
$error = '';
@@ -110,16 +114,15 @@ protected function watch(LazyAssetManager $am, $basePath, OutputInterface $outpu
110114
/**
111115
* Checks if an asset should be dumped.
112116
*
113-
* @param LazyAssetManager $am The asset manager
114-
* @param string $name The asset name
115-
* @param array &$previously An array of previous visits
117+
* @param string $name The asset name
118+
* @param array &$previously An array of previous visits
116119
*
117120
* @return AssetInterface|Boolean The asset if it should be dumped
118121
*/
119-
protected function checkAsset(LazyAssetManager $am, $name, array &$previously)
122+
private function checkAsset($name, array &$previously)
120123
{
121-
$formula = $am->hasFormula($name) ? serialize($am->getFormula($name)) : null;
122-
$asset = $am->get($name);
124+
$formula = $this->am->hasFormula($name) ? serialize($this->am->getFormula($name)) : null;
125+
$asset = $this->am->get($name);
123126
$mtime = $asset->getLastModified();
124127

125128
if (isset($previously[$name])) {
@@ -136,15 +139,39 @@ protected function checkAsset(LazyAssetManager $am, $name, array &$previously)
136139
/**
137140
* Writes an asset.
138141
*
139-
* @param AssetInterface $asset An asset
140-
* @param string $basePath The base directory to write to
141-
* @param OutputInterface $output The command output
142+
* If the application or asset is in debug mode, each leaf asset will be
143+
* dumped as well.
144+
*
145+
* @param string $name An asset name
146+
* @param OutputInterface $output The command output
147+
*/
148+
private function dumpAsset($name, OutputInterface $output)
149+
{
150+
$asset = $this->am->get($name);
151+
$formula = $this->am->getFormula($name);
152+
153+
// start by dumping the main asset
154+
$this->doDump($asset, $output);
155+
156+
// dump each leaf if debug
157+
if (isset($formula[2]['debug']) ? $formula[2]['debug'] : $this->am->isDebug()) {
158+
foreach ($asset as $leaf) {
159+
$this->doDump($leaf, $output);
160+
}
161+
}
162+
}
163+
164+
/**
165+
* Performs the asset dump.
166+
*
167+
* @param AssetInterface $asset An asset
168+
* @param OutputInterface $output The command output
142169
*
143170
* @throws RuntimeException If there is a problem writing the asset
144171
*/
145-
protected function dumpAsset(AssetInterface $asset, $basePath, OutputInterface $output)
172+
private function doDump(AssetInterface $asset, OutputInterface $output)
146173
{
147-
$target = rtrim($basePath, '/').'/'.str_replace('_controller/', '', $asset->getTargetUrl());
174+
$target = rtrim($this->basePath, '/').'/'.str_replace('_controller/', '', $asset->getTargetUrl());
148175
if (!is_dir($dir = dirname($target))) {
149176
$output->writeln('<info>[dir+]</info> '.$dir);
150177
if (false === @mkdir($dir, 0777, true)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony framework.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Symfony\Bundle\AsseticBundle\Tests\Command;
13+
14+
use Symfony\Bundle\AsseticBundle\Command\DumpCommand;
15+
use Symfony\Component\Console\Input\ArrayInput;
16+
use Symfony\Component\Console\Output\NullOutput;
17+
18+
class DumpCommandTest extends \PHPUnit_Framework_TestCase
19+
{
20+
private $writeTo;
21+
private $application;
22+
private $definition;
23+
private $kernel;
24+
private $container;
25+
private $am;
26+
27+
protected function setUp()
28+
{
29+
if (!class_exists('Assetic\\AssetManager')) {
30+
$this->markTestSkipped('Assetic is not available.');
31+
}
32+
33+
$this->writeTo = sys_get_temp_dir().'/assetic_dump';
34+
35+
$this->application = $this->getMockBuilder('Symfony\\Bundle\\FrameworkBundle\\Console\\Application')
36+
->disableOriginalConstructor()
37+
->getMock();
38+
$this->definition = $this->getMockBuilder('Symfony\\Component\\Console\\Input\\InputDefinition')
39+
->disableOriginalConstructor()
40+
->getMock();
41+
$this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface');
42+
$this->container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
43+
$this->am = $this->getMockBuilder('Assetic\\Factory\\LazyAssetManager')
44+
->disableOriginalConstructor()
45+
->getMock();
46+
47+
$this->application->expects($this->any())
48+
->method('getDefinition')
49+
->will($this->returnValue($this->definition));
50+
$this->definition->expects($this->any())
51+
->method('getArguments')
52+
->will($this->returnValue(array()));
53+
$this->definition->expects($this->any())
54+
->method('getOptions')
55+
->will($this->returnValue(array()));
56+
$this->application->expects($this->any())
57+
->method('getKernel')
58+
->will($this->returnValue($this->kernel));
59+
$this->kernel->expects($this->any())
60+
->method('getContainer')
61+
->will($this->returnValue($this->container));
62+
$this->container->expects($this->any())
63+
->method('getParameter')
64+
->with('assetic.write_to')
65+
->will($this->returnValue($this->writeTo));
66+
$this->container->expects($this->once())
67+
->method('get')
68+
->with('assetic.asset_manager')
69+
->will($this->returnValue($this->am));
70+
71+
$this->command = new DumpCommand();
72+
$this->command->setApplication($this->application);
73+
}
74+
75+
protected function tearDown()
76+
{
77+
if (is_dir($this->writeTo)) {
78+
array_map('unlink', glob($this->writeTo.'/*'));
79+
rmdir($this->writeTo);
80+
}
81+
}
82+
83+
public function testEmptyAssetManager()
84+
{
85+
$this->am->expects($this->once())
86+
->method('getNames')
87+
->will($this->returnValue(array()));
88+
89+
$this->command->run(new ArrayInput(array()), new NullOutput());
90+
}
91+
92+
public function testDumpOne()
93+
{
94+
$asset = $this->getMock('Assetic\\Asset\\AssetInterface');
95+
96+
$this->am->expects($this->once())
97+
->method('getNames')
98+
->will($this->returnValue(array('test_asset')));
99+
$this->am->expects($this->once())
100+
->method('get')
101+
->with('test_asset')
102+
->will($this->returnValue($asset));
103+
$this->am->expects($this->once())
104+
->method('getFormula')
105+
->with('test_asset')
106+
->will($this->returnValue(array()));
107+
$this->am->expects($this->once())
108+
->method('isDebug')
109+
->will($this->returnValue(false));
110+
$asset->expects($this->once())
111+
->method('getTargetUrl')
112+
->will($this->returnValue('test_asset.css'));
113+
$asset->expects($this->once())
114+
->method('dump')
115+
->will($this->returnValue('/* test_asset */'));
116+
117+
$this->command->run(new ArrayInput(array()), new NullOutput());
118+
119+
$this->assertFileExists($this->writeTo.'/test_asset.css');
120+
$this->assertEquals('/* test_asset */', file_get_contents($this->writeTo.'/test_asset.css'));
121+
}
122+
123+
public function testDumpDebug()
124+
{
125+
$asset = $this->getMock('Assetic\\Asset\\AssetCollection');
126+
$leaf = $this->getMock('Assetic\\Asset\\AssetInterface');
127+
128+
$this->am->expects($this->once())
129+
->method('getNames')
130+
->will($this->returnValue(array('test_asset')));
131+
$this->am->expects($this->once())
132+
->method('get')
133+
->with('test_asset')
134+
->will($this->returnValue($asset));
135+
$this->am->expects($this->once())
136+
->method('getFormula')
137+
->with('test_asset')
138+
->will($this->returnValue(array()));
139+
$this->am->expects($this->once())
140+
->method('isDebug')
141+
->will($this->returnValue(true));
142+
$asset->expects($this->once())
143+
->method('getTargetUrl')
144+
->will($this->returnValue('test_asset.css'));
145+
$asset->expects($this->once())
146+
->method('dump')
147+
->will($this->returnValue('/* test_asset */'));
148+
$asset->expects($this->once())
149+
->method('getIterator')
150+
->will($this->returnValue(new \ArrayIterator(array($leaf))));
151+
$leaf->expects($this->once())
152+
->method('getTargetUrl')
153+
->will($this->returnValue('test_leaf.css'));
154+
$leaf->expects($this->once())
155+
->method('dump')
156+
->will($this->returnValue('/* test_leaf */'));
157+
158+
$this->command->run(new ArrayInput(array()), new NullOutput());
159+
160+
$this->assertFileExists($this->writeTo.'/test_asset.css');
161+
$this->assertFileExists($this->writeTo.'/test_leaf.css');
162+
$this->assertEquals('/* test_asset */', file_get_contents($this->writeTo.'/test_asset.css'));
163+
$this->assertEquals('/* test_leaf */', file_get_contents($this->writeTo.'/test_leaf.css'));
164+
}
165+
}

0 commit comments

Comments
 (0)