Skip to content

Commit

Permalink
Merge pull request #447 from KnpLabs/custom-pointable
Browse files Browse the repository at this point in the history
add default location provider
  • Loading branch information
TomasVotruba authored Dec 12, 2019
2 parents 17b34b7 + 691b2a5 commit e6f362f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ parameters:
- '#Method Knp\\DoctrineBehaviors\\Tests\\Fixtures\\ORM\\GeocodableEntityRepository\:\:findOneByTitle\(\) should return Knp\\DoctrineBehaviors\\Contract\\Entity\\GeocodableInterface but returns object\|null#'

- '#Method Knp\\DoctrineBehaviors\\Tests\\Fixtures\\ORM\\TreeNodeEntityRepository\:\:getTree\(\) should return array<Knp\\DoctrineBehaviors\\Model\\Tree\\NodeInterface\>\|ArrayAccess\|null but returns ArrayAccess\|Knp\\DoctrineBehaviors\\Model\\Tree\\NodeInterface\|null#'

-
message: '#Property Knp\\DoctrineBehaviors\\Tests\\ORM\\GeocodableTest\:\:\$geocodableEntityRepository \(Knp\\DoctrineBehaviors\\Tests\\Fixtures\\ORM\\GeocodableEntityRepository\) does not accept Doctrine\\Persistence\\ObjectRepository#'
path: tests/ORM/GeocodableTest.php

- '#Parameter \#1 \$argument of class ReflectionClass constructor expects class\-string<T of object\>\|T of object, string given#'
8 changes: 3 additions & 5 deletions src/Bundle/DependencyInjection/DoctrineBehaviorsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

final class DoctrineBehaviorsExtension extends Extension
{
/**
* @param string[] $configs
*/
public function load(array $configs, ContainerBuilder $containerBuilder): void
{
$loader = new YamlFileLoader($containerBuilder, new FileLocator(__DIR__ . '/../../../config'));
Expand All @@ -21,9 +24,4 @@ public function load(array $configs, ContainerBuilder $containerBuilder): void
$containerBuilder->registerForAutoconfiguration(EventSubscriber::class)
->addTag('doctrine.event_subscriber');
}

public function getAlias(): string
{
return 'knp_doctrine_behaviors';
}
}
10 changes: 10 additions & 0 deletions src/Model/Translatable/TranslatableMethodsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface;
use Knp\DoctrineBehaviors\Exception\ShouldNotHappenException;
use ReflectionClass;

trait TranslatableMethodsTrait
{
Expand Down Expand Up @@ -138,6 +140,14 @@ protected function doTranslate(?string $locale = null, bool $fallbackToDefault =

$class = static::getTranslationEntityClass();

$reflectionClass = new ReflectionClass($class);
if ($reflectionClass->isAbstract()) {
throw new ShouldNotHappenException(sprintf(
'Abstract class "%s" cannot be Translatable, use child class instead.',
self::class
));
}

/** @var TranslationInterface $translation */
$translation = new $class();
$translation->setLocale($locale);
Expand Down
16 changes: 16 additions & 0 deletions src/Provider/LocationProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Knp\DoctrineBehaviors\Provider;

use Knp\DoctrineBehaviors\Contract\Provider\LocationProviderInterface;
use Knp\DoctrineBehaviors\ORM\Geocodable\Type\Point;

final class LocationProvider implements LocationProviderInterface
{
public function providePoint(): ?Point
{
return null;
}
}

0 comments on commit e6f362f

Please sign in to comment.