/**
  * @param string $name
  *
  * @return string
  */
 protected function getPropertyName($name)
 {
     if (in_array($name, $this->translatableFields)) {
         return 'translations.' . $this->localeProvider->getCurrentLocale() . '.' . $name;
     }
     return $name;
 }
 public function it_sets_current_locale_on_created_object(LocaleProviderInterface $localeProvider)
 {
     $localeProvider->getCurrentLocale()->willReturn('en_US');
     $localeProvider->getFallbackLocale()->willReturn('en_US');
     $this->setLocaleProvider($localeProvider);
     $this->createNew()->getCurrentLocale()->shouldReturn('en_US');
     $this->createNew()->getFallbackLocale()->shouldReturn('en_US');
 }
Ejemplo n.º 3
0
 function it_creates_translatable_and_sets_locales(FactoryInterface $factory, LocaleProviderInterface $localeProvider, SampleTranslatableResource $resource)
 {
     $localeProvider->getCurrentLocale()->willReturn('pl_PL');
     $localeProvider->getFallbackLocale()->willReturn('en_GB');
     $factory->createNew()->willReturn($resource);
     $resource->setCurrentLocale('pl_PL')->shouldBeCalled();
     $resource->setFallbackLocale('en_GB')->shouldBeCalled();
     $this->createNew()->shouldReturn($resource);
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function createNew()
 {
     $resource = $this->factory->createNew();
     if (!$resource instanceof TranslatableInterface) {
         throw new UnexpectedTypeException($resource, TranslatableInterface::class);
     }
     $resource->setCurrentLocale($this->localeProvider->getCurrentLocale());
     $resource->setFallbackLocale($this->localeProvider->getFallbackLocale());
     return $resource;
 }
 /**
  * {@inheritdoc}
  */
 public function createNew()
 {
     $resource = parent::createNew();
     if (!$resource instanceof TranslatableInterface) {
         throw new \InvalidArgumentException('Resource must implement TranslatableInterface.');
     }
     $resource->setCurrentLocale($this->localeProvider->getCurrentLocale());
     $resource->setFallbackLocale($this->localeProvider->getFallbackLocale());
     return $resource;
 }
 function it_applies_criteria_when_finding_by_array($queryBuilder, LocaleProviderInterface $localeProvider)
 {
     $localeProvider->getCurrentLocale()->willReturn('en_US');
     $this->setLocaleProvider($localeProvider);
     $translatableFields = array('foo');
     $this->setTranslatableFields($translatableFields);
     $criteria = array('baz' => array('foo', 'bar'));
     foreach ($criteria as $property => $value) {
         $queryBuilder->field($property)->willReturn($queryBuilder);
         $queryBuilder->in($value)->willReturn($queryBuilder);
     }
     $this->findBy($criteria)->shouldReturn(null);
 }