Skip to content

Commit

Permalink
[Bridge] [Propel] minor improvements to the Propel bridge.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Hamon committed Dec 21, 2014
1 parent ff52a9f commit 6d9d460
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 67 deletions.
24 changes: 12 additions & 12 deletions src/Symfony/Bridge/Propel1/DataCollector/PropelDataCollector.php
Expand Up @@ -26,7 +26,7 @@ class PropelDataCollector extends DataCollector
/**
* Propel logger
*
* @var \Symfony\Bridge\Propel1\Logger\PropelLogger
* @var PropelLogger
*/
private $logger;

Expand All @@ -38,7 +38,7 @@ class PropelDataCollector extends DataCollector
protected $propelConfiguration;

/**
* Constructor
* Constructor.
*
* @param PropelLogger $logger A Propel logger.
* @param \PropelConfiguration $propelConfiguration The Propel configuration object.
Expand All @@ -63,17 +63,17 @@ public function collect(Request $request, Response $response, \Exception $except
/**
* Returns the collector name.
*
* @return string The collector name.
* @return string
*/
public function getName()
{
return 'propel';
}

/**
* Returns queries.
* Returns the collected stats for all executed SQL queries.
*
* @return array Queries
* @return array
*/
public function getQueries()
{
Expand All @@ -83,17 +83,17 @@ public function getQueries()
/**
* Returns the query count.
*
* @return int The query count
* @return int
*/
public function getQueryCount()
{
return $this->data['querycount'];
}

/**
* Returns the total time of queries.
* Returns the total time spent on running all queries.
*
* @return float The total time of queries
* @return float
*/
public function getTime()
{
Expand All @@ -106,9 +106,9 @@ public function getTime()
}

/**
* Creates an array of Build objects.
* Computes the stats of all executed SQL queries.
*
* @return array An array of Build objects
* @return array
*/
private function buildQueries()
{
Expand Down Expand Up @@ -136,9 +136,9 @@ private function buildQueries()
}

/**
* Count queries.
* Returns the total count of SQL queries.
*
* @return int The number of queries.
* @return int
*/
private function countQueries()
{
Expand Down
Expand Up @@ -26,6 +26,12 @@ class PropelFactory implements UserProviderFactoryInterface
private $key;
private $providerId;

/**
* Constructor.
*
* @param string $key
* @param string $providerId
*/
public function __construct($key, $providerId)
{
$this->key = $key;
Expand All @@ -38,7 +44,7 @@ public function create(ContainerBuilder $container, $id, $config)
->setDefinition($id, new DefinitionDecorator($this->providerId))
->addArgument($config['class'])
->addArgument($config['property'])
;
;
}

public function getKey()
Expand All @@ -50,9 +56,14 @@ public function addConfiguration(NodeDefinition $node)
{
$node
->children()
->scalarNode('class')->isRequired()->cannotBeEmpty()->end()
->scalarNode('property')->defaultNull()->end()
->scalarNode('class')
->isRequired()
->cannotBeEmpty()
->end()
->scalarNode('property')
->defaultNull()
->end()
->end()
;
;
}
}
17 changes: 17 additions & 0 deletions src/Symfony/Bridge/Propel1/Form/Type/ModelType.php
Expand Up @@ -55,18 +55,29 @@ class ModelType extends AbstractType
*/
private $propertyAccessor;

/**
* Constructor.
*
* @param PropertyAccessorInterface|null $propertyAccessor
*/
public function __construct(PropertyAccessorInterface $propertyAccessor = null)
{
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
}

/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if ($options['multiple']) {
$builder->addViewTransformer(new CollectionToArrayTransformer(), true);
}
}

/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$propertyAccessor = $this->propertyAccessor;
Expand Down Expand Up @@ -97,11 +108,17 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
));
}

/**
* {@inheritdoc}
*/
public function getParent()
{
return 'choice';
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'model';
Expand Down
Expand Up @@ -18,7 +18,7 @@
use Symfony\Bridge\Propel1\Form\EventListener\TranslationCollectionFormListener;

/**
* form type for i18n-columns in propel
* Form type for i18n-columns in propel
*
* @author Patrick Kaufmann
*/
Expand All @@ -40,6 +40,9 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$builder->addEventSubscriber($listener);
}

/**
* {@inheritdoc}
*/
public function getParent()
{
return 'collection';
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Propel1/Form/Type/TranslationType.php
Expand Up @@ -17,7 +17,7 @@
use Symfony\Bridge\Propel1\Form\EventListener\TranslationFormListener;

/**
* Translation type class
* Translation type class.
*
* @author Patrick Kaufmann
*/
Expand Down
Expand Up @@ -92,18 +92,19 @@ public function testCollectWithMultipleData()
private function createCollector($queries)
{
$config = $this->getMock('\PropelConfiguration');

$config
->expects($this->any())
->method('getParameter')
->will($this->returnArgument(1))
;
;

$logger = $this->getMock('\Symfony\Bridge\Propel1\Logger\PropelLogger');
$logger
->expects($this->any())
->method('getQueries')
->will($this->returnValue($queries))
;
;

return new PropelDataCollector($logger, $config);
}
Expand Down
17 changes: 8 additions & 9 deletions src/Symfony/Bridge/Propel1/Tests/Fixtures/Column.php
Expand Up @@ -14,7 +14,6 @@
class Column
{
private $name;

private $type;

public function __construct($name, $type)
Expand All @@ -35,13 +34,13 @@ public function isText()
}

switch ($this->type) {
case \PropelColumnTypes::CHAR:
case \PropelColumnTypes::VARCHAR:
case \PropelColumnTypes::LONGVARCHAR:
case \PropelColumnTypes::BLOB:
case \PropelColumnTypes::CLOB:
case \PropelColumnTypes::CLOB_EMU:
return true;
case \PropelColumnTypes::CHAR:
case \PropelColumnTypes::VARCHAR:
case \PropelColumnTypes::LONGVARCHAR:
case \PropelColumnTypes::BLOB:
case \PropelColumnTypes::CLOB:
case \PropelColumnTypes::CLOB_EMU:
return true;
}

return false;
Expand All @@ -54,6 +53,6 @@ public function getSize()

public function isNotNull()
{
return ('id' === $this->name);
return 'id' === $this->name;
}
}
9 changes: 2 additions & 7 deletions src/Symfony/Bridge/Propel1/Tests/Fixtures/Item.php
Expand Up @@ -11,16 +11,11 @@

namespace Symfony\Bridge\Propel1\Tests\Fixtures;

use PropelPDO;

class Item implements \Persistent
{
private $id;

private $value;

private $groupName;

private $price;

public function __construct($id = null, $value = null, $groupName = null, $price = null)
Expand Down Expand Up @@ -98,11 +93,11 @@ public function setDeleted($b)
{
}

public function delete(PropelPDO $con = null)
public function delete(\PropelPDO $con = null)
{
}

public function save(PropelPDO $con = null)
public function save(\PropelPDO $con = null)
{
}
}
11 changes: 3 additions & 8 deletions src/Symfony/Bridge/Propel1/Tests/Fixtures/TranslatableItem.php
Expand Up @@ -11,16 +11,11 @@

namespace Symfony\Bridge\Propel1\Tests\Fixtures;

use PropelPDO;

class TranslatableItem implements \Persistent
{
private $id;

private $currentTranslations;

private $groupName;

private $price;

public function __construct($id = null, $translations = array())
Expand Down Expand Up @@ -91,15 +86,15 @@ public function setDeleted($b)
{
}

public function delete(PropelPDO $con = null)
public function delete(\PropelPDO $con = null)
{
}

public function save(PropelPDO $con = null)
public function save(\PropelPDO $con = null)
{
}

public function getTranslation($locale = 'de', PropelPDO $con = null)
public function getTranslation($locale = 'de', \PropelPDO $con = null)
{
if (!isset($this->currentTranslations[$locale])) {
$translation = new TranslatableItemI18n();
Expand Down
Expand Up @@ -11,18 +11,12 @@

namespace Symfony\Bridge\Propel1\Tests\Fixtures;

use PropelPDO;

class TranslatableItemI18n implements \Persistent
{
private $id;

private $locale;

private $value;

private $value2;

private $item;

public function __construct($id = null, $locale = null, $value = null)
Expand Down Expand Up @@ -84,11 +78,11 @@ public function setDeleted($b)
{
}

public function delete(PropelPDO $con = null)
public function delete(\PropelPDO $con = null)
{
}

public function save(PropelPDO $con = null)
public function save(\PropelPDO $con = null)
{
}

Expand Down
Expand Up @@ -249,14 +249,14 @@ public function testDontAllowInvalidChoiceValues()
*/
public function testEmptyClass()
{
$choiceList = new ModelChoiceList('');
new ModelChoiceList('');
}

/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testInvalidClass()
{
$choiceList = new ModelChoiceList('Foo\Bar\DoesNotExistClass');
new ModelChoiceList('Foo\Bar\DoesNotExistClass');
}
}

0 comments on commit 6d9d460

Please sign in to comment.