Skip to content
This repository has been archived by the owner on Jun 2, 2020. It is now read-only.

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierstoval committed Mar 15, 2015
1 parent b1d5adf commit 5680239
Show file tree
Hide file tree
Showing 17 changed files with 156 additions and 95 deletions.
34 changes: 18 additions & 16 deletions Admin/TranslationAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,35 @@
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery;

class TranslationAdmin extends Admin {
class TranslationAdmin extends Admin
{

protected function configureRoutes(RouteCollection $collection)
{
$collection->clearExcept(array('list','edit'));
$collection->clearExcept(array('list', 'edit'));
}

protected function configureFormFields(FormMapper $formMapper) {
protected function configureFormFields(FormMapper $formMapper)
{

$subject = $this->getSubject();

/** @var EntityManager $em */

$likes = $this->modelManager->getEntityManager($subject)->getRepository(get_class($subject))->findOneLikes($subject);

$help = $this->getConfigurationPool()->getContainer()->get('templating')->render('OrbitaleTranslationBundle:Translation:sonata_translations_like_help.html.twig', array('translations' => $likes));
$help = $this->getConfigurationPool()->getContainer()->get('templating')->render('OrbitaleTranslationBundle:Translation:sonata_translations_like_help.html.twig',
array('translations' => $likes));

$formMapper
->add('locale', 'text', array('disabled'=>true))
->add('domain', 'text', array('disabled'=>true))
->add('source', 'text', array('disabled'=>true))
->add('translation', 'text', array('required'=>false, 'sonata_help' => $help))
;
->add('locale', 'text', array('disabled' => true))
->add('domain', 'text', array('disabled' => true))
->add('source', 'text', array('disabled' => true))
->add('translation', 'text', array('required' => false, 'sonata_help' => $help));
}

protected function configureDatagridFilters(DatagridMapper $datagridMapper) {
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{

$domains = $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository('Orbitale\Bundle\TranslationBundle\Entity\Translation')->getDomains();
$domains = array_combine($domains, $domains);
Expand All @@ -57,24 +60,23 @@ protected function configureDatagridFilters(DatagridMapper $datagridMapper) {
->add('domain', 'doctrine_orm_string', array('field_type' => 'choice'), null, array('choices' => $domains))
->add('locale', 'doctrine_orm_string', array('field_type' => 'choice'), null, array('choices' => $locales))
->add('translation_empty', 'doctrine_orm_callback', array(
'callback' => function(ProxyQuery $queryBuilder, $alias, $field, $value) {
'callback' => function (ProxyQuery $queryBuilder, $alias, $field, $value) {
if (!$value['value']) {
return;
}
$queryBuilder->andWhere($alias.'.translation IS NULL');
},
'field_type' => 'checkbox'
))
;
));
}

protected function configureListFields(ListMapper $listMapper) {
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->add('locale', 'text')
->addIdentifier('source', 'text')
->addIdentifier('translation', 'text')
->add('domain', 'text')
;
->add('domain', 'text');

}

Expand Down
4 changes: 2 additions & 2 deletions Command/TranslationExtractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

use Orbitale\Bundle\TranslationBundle\Translation\Extractor;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* This command extracts translation elements from database to files.
Expand Down
10 changes: 5 additions & 5 deletions DependencyInjection/OrbitaleTranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function load(array $configs, ContainerBuilder $container)
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('parameters.yml');
$loader->load('default_locales.yml');

Expand All @@ -46,7 +46,7 @@ public function load(array $configs, ContainerBuilder $container)
}

foreach ($config as $key => $value) {
$container->setParameter('orbitale_translation.' . $key, $value);
$container->setParameter('orbitale_translation.'.$key, $value);
}

$container->setParameter('locales', $config['locales']);
Expand Down Expand Up @@ -80,9 +80,9 @@ private function processLocales(ContainerBuilder $container, $locales)
(!is_numeric($locale) && !in_array($locale, array_keys($baseLocales)))
|| (is_numeric($locale) && !in_array($publicName, array_keys($baseLocales)))
) {
$msg = 'An error occured when parsing configuration for Translation locales.' . "\n"
. 'You specified a locale named "' . (is_numeric($locale) ? $publicName : $locale) . '" which is not registered in our supported locales.' . "\n"
. 'Locale format must be the shortest, for example, you should use "en" instead of "en_US".';
$msg = 'An error occured when parsing configuration for Translation locales.'."\n"
.'You specified a locale named "'.(is_numeric($locale) ? $publicName : $locale).'" which is not registered in our supported locales.'."\n"
.'Locale format must be the shortest, for example, you should use "en" instead of "en_US".';
throw new InvalidArgumentException($msg);
} else {
if (is_numeric($locale)) {
Expand Down
18 changes: 10 additions & 8 deletions Doctrine/TranslationLikeHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@
namespace Orbitale\Bundle\TranslationBundle\Doctrine;

use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
use PDO;
use Orbitale\Bundle\TranslationBundle\Entity\Translation;
use PDO;

class TranslationLikeHydrator extends AbstractHydrator {
class TranslationLikeHydrator extends AbstractHydrator
{

/**
* @var array
*/
protected $initializedCollections;

function hydrateAllData() {
function hydrateAllData()
{
$results = array();

$owners = $this->_rsm->columnOwnerMap;
Expand All @@ -36,18 +38,18 @@ function hydrateAllData() {
$value = $row[$dqlAlias];
$fieldName = $mapping_fields[$dqlAlias];

if ( $fieldName !== 'id' || ($fieldName == 'id' && $value) ) {
if ($fieldName !== 'id' || ($fieldName == 'id' && $value)) {

if ($element === 'translationsLike') {
// Hydrates a translation-like
$refObject = new \ReflectionObject( $like );
$refProperty = $refObject->getProperty( $fieldName );
$refObject = new \ReflectionObject($like);
$refProperty = $refObject->getProperty($fieldName);
$refProperty->setAccessible(true);
$refProperty->setValue($like, $value);
} else {
// Hydrates a "master" translation
$refObject = new \ReflectionObject( $result );
$refProperty = $refObject->getProperty( $fieldName );
$refObject = new \ReflectionObject($result);
$refProperty = $refObject->getProperty($fieldName);
$refProperty->setAccessible(true);
$refProperty->setValue($result, $value);
}
Expand Down
16 changes: 11 additions & 5 deletions Entity/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

namespace Orbitale\Bundle\TranslationBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Table(name="orbitale_translations")
Expand Down Expand Up @@ -72,7 +72,8 @@ public function __toString()
return $this->source;
}

function __construct() {
function __construct()
{
$this->translationsLike = new ArrayCollection();
}

Expand Down Expand Up @@ -206,8 +207,10 @@ public function getTranslation()
* @param Translation $translation
* @return $this
*/
public function addTranslationLike(Translation $translation) {
public function addTranslationLike(Translation $translation)
{
$this->translationsLike->add($translation);

return $this;
}

Expand All @@ -216,16 +219,19 @@ public function addTranslationLike(Translation $translation) {
* @param Translation $translation
* @return $this
*/
public function removeTranslationLike(Translation $translation) {
public function removeTranslationLike(Translation $translation)
{
$this->translationsLike->removeElement($translation);

return $this;
}

/**
* Get translations like
* @return Translation[]
*/
public function getTranslationsLike(){
public function getTranslationsLike()
{
return $this->translationsLike;
}
}
9 changes: 6 additions & 3 deletions Listeners/FlushTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;

class FlushTranslations implements EventSubscriberInterface {
class FlushTranslations implements EventSubscriberInterface
{

protected $translator;

function __construct(Translator $translator) {
function __construct(Translator $translator)
{
$this->translator = $translator;
}

function flushTranslations(){
function flushTranslations()
{
$this->translator->flushTranslations();
}

Expand Down
9 changes: 6 additions & 3 deletions Repository/TranslationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
use Doctrine\ORM\EntityRepository;
use Orbitale\Bundle\TranslationBundle\Entity\Translation;

class TranslationRepository extends EntityRepository {
class TranslationRepository extends EntityRepository
{

/**
* Get all translations with mentioned tokens
* @param array $tokens
* @return array
*/
public function findByTokens($tokens = array()) {
public function findByTokens($tokens = array())
{
return $this->findBy(array('token' => $tokens));
}

Expand Down Expand Up @@ -112,7 +114,8 @@ public function findOneLikes(Translation $translation)
* @return Translation[]
* @see Orbitale\Bundle\TranslationBundle\Doctrine\TranslationLikeHydrator
*/
public function findLikes($locale = null, $domain = null) {
public function findLikes($locale = null, $domain = null)
{

$em = $this->_em;
$dql = "
Expand Down
3 changes: 2 additions & 1 deletion Tests/Controller/TranslationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
use Symfony\Component\Routing\Generator\UrlGenerator;
use Symfony\Component\Routing\Router;

class TranslationControllerTest extends AbstractTestCase {
class TranslationControllerTest extends AbstractTestCase
{

public function testAdminAndExport()
{
Expand Down
1 change: 1 addition & 0 deletions Tests/Fixtures/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ protected function getKernel(array $options = array())
if (!static::$kernel) {
static::bootKernel($options);
}

return static::$kernel;
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/Fixtures/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
* file that was distributed with this source code.
*/

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;

class AppKernel extends Kernel
{
Expand Down
9 changes: 6 additions & 3 deletions Tests/Translator/ExtractionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
namespace Orbitale\Bundle\TranslationBundle\Tests\Translator;

use Doctrine\ORM\EntityManager;
use Orbitale\Bundle\TranslationBundle\Command\TranslationExtractCommand;
use Orbitale\Bundle\TranslationBundle\Entity\Translation;
use Orbitale\Bundle\TranslationBundle\Tests\Fixtures\AbstractTestCase;
use Orbitale\Bundle\TranslationBundle\Command\TranslationExtractCommand;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Yaml;

class ExtractionTest extends AbstractTestCase {
class ExtractionTest extends AbstractTestCase
{

/**
* @var EntityManager
Expand Down Expand Up @@ -49,7 +50,8 @@ protected function setUp()
/**
* @return Translation[]
*/
private function processDummyDatas(){
private function processDummyDatas()
{
$translationsToAdd = array(
array('first.element', 'Premier élément', 'fr', 'messages'),
array('first.element', 'First Element', 'en', 'messages'),
Expand All @@ -69,6 +71,7 @@ private function processDummyDatas(){
$finalTranslations[$obj->getToken()] = $obj;
}
$this->em->flush();

return $finalTranslations;
}

Expand Down
16 changes: 11 additions & 5 deletions Tests/Translator/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,13 @@ public function testGetLocalesInDb()

public function testDomainsInDb()
{
$domainsToSave = array('messages', 'garbage_domain', 'another_creepy_domain', 'hey_what_about', 'FOSUserBundle');
$domainsToSave = array(
'messages',
'garbage_domain',
'another_creepy_domain',
'hey_what_about',
'FOSUserBundle'
);

/** @var Translation[] $translations */
$translations = array();
Expand Down Expand Up @@ -305,10 +311,10 @@ public function testTranslationsLikeOne()
$this->assertCount(2, $likes);
$number = 0;
foreach ($likes as $like) {
$number += preg_match('~'.$like->getSource().'~isUu', $translation1->getSource());
$number += preg_match('~'.$like->getTranslation().'~isUu', $translation1->getSource());
$number += preg_match('~'.$like->getSource().'~isUu', $translation1->getTranslation());
$number += preg_match('~'.$like->getTranslation().'~isUu', $translation1->getTranslation());
$number += preg_match('~'.$like->getSource().'~isUu', $translation1->getSource());
$number += preg_match('~'.$like->getTranslation().'~isUu', $translation1->getSource());
$number += preg_match('~'.$like->getSource().'~isUu', $translation1->getTranslation());
$number += preg_match('~'.$like->getTranslation().'~isUu', $translation1->getTranslation());
}
$this->assertGreaterThan(0, $number);
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;

$file = __DIR__ . '/../vendor/autoload.php';
$file = __DIR__.'/../vendor/autoload.php';
if (!file_exists($file)) {
throw new RuntimeException('Install dependencies to run test suite.');
}
Expand Down
Loading

0 comments on commit 5680239

Please sign in to comment.