Merge branch '2.0'

This commit is contained in:
William DURAND 2012-02-10 16:06:49 +01:00
commit b019559de8
8 changed files with 175 additions and 16 deletions

View file

@ -163,9 +163,7 @@ EOT
return;
}
$finder = new Finder();
$tmpdir = $this->getApplication()->getKernel()->getRootDir() . '/cache/propel';
$datas = $finder->name('*.' . $type)->in($this->absoluteFixturesPath);
$datas = $this->getFixtureFiles($type);
if (count(iterator_to_array($datas)) === 0) {
return -1;
@ -210,9 +208,8 @@ EOT
*/
protected function loadSqlFixtures(InputInterface $input, OutputInterface $output)
{
$finder = new Finder();
$tmpdir = $this->getApplication()->getKernel()->getRootDir() . '/cache/propel';
$datas = $finder->name('*.sql')->in($this->absoluteFixturesPath);
$datas = $this->getFixtureFiles('sql');
$this->prepareCache($tmpdir);
@ -286,4 +283,21 @@ EOT
return true;
}
/**
* Returns the fixtures files to load.
*
* @param string $type The extension of the files.
* @param string $in The directory in which we search the files. If null,
* we'll use the absoluteFixturesPath property.
*
* @return \Iterator An iterator through the files.
*/
protected function getFixtureFiles($type = 'sql', $in = null)
{
$finder = new Finder();
$finder->sortByName()->name('*.' . $type);
return $finder->in(null !== $in ? $in : $this->absoluteFixturesPath);
}
}

View file

@ -68,16 +68,14 @@ class PropelExtension extends Extension
$loader->load('converters.xml');
}
if (0 === strncasecmp(PHP_SAPI, 'cli', 3)) {
if (isset($config['build_properties']) && is_array($config['build_properties'])) {
$buildProperties = $config['build_properties'];
} else {
$buildProperties = array();
}
$container->getDefinition('propel.build_properties')->setArguments(array($buildProperties));
if (isset($config['build_properties']) && is_array($config['build_properties'])) {
$buildProperties = $config['build_properties'];
} else {
$buildProperties = array();
}
$container->getDefinition('propel.build_properties')->setArguments(array($buildProperties));
if (!empty($config['dbal'])) {
$this->dbalLoad($config['dbal'], $container);
}

View file

@ -29,6 +29,17 @@
<style type="text/css">
.SQLKeyword {
color: blue;
white-space: nowrap;
}
.SQLName {
color: #464646;
white-space: nowrap;
}
.SQLInfo, .SQLComment {
color: gray;
display: block;
font-size: 0.9em;
margin: 3px 0;
}
</style>
@ -47,7 +58,7 @@
<tr>
<td>
<code>{{ query.sql|format_sql }}</code>
<div style="color: gray;font-size: 0.9em;">Time: {{ query.time }} - Memory: {{ query.memory }}</div>
<div class="SQLInfo">Time: {{ query.time }} - Memory: {{ query.memory }}</div>
</td>
</tr>
{% endfor %}

View file

@ -0,0 +1,77 @@
<?php
/**
* This file is part of the PropelBundle package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
namespace Tests\Command;
use Symfony\Component\Filesystem\Filesystem;
use Propel\PropelBundle\Tests\TestCase;
use Propel\PropelBundle\Command\FixturesLoadCommand;
/**
* @author Kévin Gomez <contact@kevingomez.fr>
*/
class FixturesLoadCommandTest extends TestCase
{
protected $command;
public function setUp()
{
$this->command = new TestableFixturesLoadCommand('testable-command');
// let's create some dummy fixture files
$this->fixtures_dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'propel';
$this->fixtures_files = array(
'10_foo.yml', '20_bar.yml', '15_biz.yml', '18_boo.sql', '42_baz.sql'
);
$this->filesystem = new Filesystem();
$this->filesystem->mkdir($this->fixtures_dir);
foreach ($this->fixtures_files as $file)
{
$this->filesystem->touch($this->fixtures_dir . DIRECTORY_SEPARATOR . $file);
}
}
public function tearDown()
{
$this->filesystem->remove($this->fixtures_dir);
}
public function testOrderedFixturesFiles()
{
$this->assertEquals(
array('10_foo.yml', '15_biz.yml', '20_bar.yml',),
$this->cleanFixtureIterator($this->command->getFixtureFiles('yml', $this->fixtures_dir))
);
$this->assertEquals(
array('18_boo.sql', '42_baz.sql',),
$this->cleanFixtureIterator($this->command->getFixtureFiles('sql', $this->fixtures_dir))
);
}
protected function cleanFixtureIterator($file_iterator)
{
$tmp_dir = $this->fixtures_dir;
return array_map(function($file) use($tmp_dir) {
return str_replace($tmp_dir . DIRECTORY_SEPARATOR, '', $file);
}, array_keys(iterator_to_array($file_iterator)));
}
}
class TestableFixturesLoadCommand extends FixturesLoadCommand
{
public function getFixtureFiles($type = 'sql', $in = null)
{
return parent::getFixtureFiles($type, $in);
}
}

View file

@ -10,6 +10,9 @@ $loader->registerNamespaces(array(
'Symfony' => array($vendorDir.'/symfony/src'),
'Sensio\\Bundle\\FrameworkExtraBundle' => array($vendorDir),
));
$loader->registerPrefixes(array(
'Twig_' => $vendorDir.'/symfony/vendor/twig/lib',
));
$loader->register();
set_include_path(get_include_path() . PATH_SEPARATOR . $vendorDir.'/phing/classes');

View file

@ -33,9 +33,62 @@ class SyntaxExtension extends \Twig_Extension
public function formatSQL($sql)
{
$sql = preg_replace('/\b(UPDATE|SET|SELECT|FROM|AS|LIMIT|ASC|COUNT|DESC|WHERE|LEFT JOIN|INNER JOIN|RIGHT JOIN|ORDER BY|GROUP BY|IN|LIKE|DISTINCT|DELETE|INSERT|INTO|VALUES|ON|AND|OR)\b/', '<span class="SQLKeyword">\\1</span>', $sql);
// list of keywords to prepend a newline in output
$newlines = array(
'FROM',
'(((FULL|LEFT|RIGHT)? ?(OUTER|INNER)?|CROSS|NATURAL)? JOIN)',
'VALUES',
'WHERE',
'ORDER BY',
'GROUP BY',
'HAVING',
'LIMIT',
);
$sql = preg_replace('/\b(FROM|WHERE|INNER JOIN|LEFT JOIN|RIGHT JOIN|ORDER BY|GROUP BY)\b/', '<br />\\1', $sql);
// list of keywords to highlight
$keywords = array_merge($newlines, array(
// base
'SELECT', 'UPDATE', 'DELETE', 'INSERT', 'REPLACE',
'SET',
'INTO',
'AS',
'DISTINCT',
// most used methods
'COUNT',
'AVG',
'MIN',
'MAX',
// joins
'ON', 'USING',
// where clause
'(IS (NOT)?)?NULL',
'(NOT )?IN',
'(NOT )?I?LIKE',
'AND', 'OR', 'XOR',
'BETWEEN',
// order, group, limit ..
'ASC',
'DESC',
'OFFSET',
));
$sql = preg_replace(array(
'/\b('.implode('|', $newlines).')\b/',
'/\b('.implode('|', $keywords).')\b/',
'/(\/\*.*\*\/)/',
'/(`[^`.]*`)/',
'/(([0-9a-zA-Z$_]+)\.([0-9a-zA-Z$_]+))/',
), array(
'<br />\\1',
'<span class="SQLKeyword">\\1</span>',
'<span class="SQLComment">\\1</span>',
'<span class="SQLName">\\1</span>',
'<span class="SQLName">\\1</span>',
), $sql);
return $sql;
}

View file

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

View file

@ -23,3 +23,5 @@ foreach ($deps as $dep) {
system(sprintf('cd %s && git fetch -q origin && git reset --hard %s', escapeshellarg($installDir), escapeshellarg($rev)));
}
system(sprintf('cd %s && php vendors.php', escapeshellarg($vendorDir.'/symfony')));