diff --git a/composer.json b/composer.json index f9f9f64..d754da4 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,7 @@ "sentry/sentry-symfony": "^2.2", "symfony/console": "^4.1", "symfony/dotenv": "^4.1", + "symfony/expression-language": "^4.1", "symfony/flex": "^1.0", "symfony/form": "^4.1", "symfony/framework-bundle": "^4.1", diff --git a/composer.lock b/composer.lock index 89a65a1..280c9e7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9357f0481f1bae9e751158689364ba6b", + "content-hash": "affcef344df6ac8f86b6f1ab41e04968", "packages": [ { "name": "doctrine/annotations", @@ -2752,6 +2752,57 @@ ], "time": "2019-06-20T06:46:26+00:00" }, + { + "name": "symfony/expression-language", + "version": "v4.3.5", + "source": { + "type": "git", + "url": "https://github.com/symfony/expression-language.git", + "reference": "c8b47d8820d3bf75f757eec8a2647584c14cf0c6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/expression-language/zipball/c8b47d8820d3bf75f757eec8a2647584c14cf0c6", + "reference": "c8b47d8820d3bf75f757eec8a2647584c14cf0c6", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "symfony/cache": "~3.4|~4.0", + "symfony/service-contracts": "^1.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\ExpressionLanguage\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony ExpressionLanguage Component", + "homepage": "https://symfony.com", + "time": "2019-08-08T09:29:19+00:00" + }, { "name": "symfony/filesystem", "version": "v4.3.2", diff --git a/config/services.yaml b/config/services.yaml index b09b9e5..ec9b802 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -43,4 +43,4 @@ services: # Torrent searcher App\Search\TorrentSearcher: arguments: - $em: '@doctrine.orm.magneticod_entity_manager' + $classMetadata: '@=service(''doctrine.orm.magneticod_entity_manager'').getClassMetadata(''App\\Magnetico\\Entity\\Torrent'')' diff --git a/src/Search/TorrentSearcher.php b/src/Search/TorrentSearcher.php index d4dac98..09fe611 100644 --- a/src/Search/TorrentSearcher.php +++ b/src/Search/TorrentSearcher.php @@ -2,9 +2,8 @@ namespace App\Search; -use App\Magnetico\Entity\Torrent; use App\Magnetico\Repository\TorrentRepository; -use Doctrine\ORM\{EntityManagerInterface, QueryBuilder}; +use Doctrine\ORM\{Mapping\ClassMetadata, QueryBuilder}; class TorrentSearcher { @@ -13,13 +12,13 @@ class TorrentSearcher /** @var TorrentRepository */ private $torrentRepo; - /** @var EntityManagerInterface */ - private $em; + /** @var ClassMetadata */ + private $classMetadata; - public function __construct(TorrentRepository $torrentRepo, EntityManagerInterface $em) + public function __construct(TorrentRepository $torrentRepo, ClassMetadata $classMetadata) { $this->torrentRepo = $torrentRepo; - $this->em = $em; + $this->classMetadata = $classMetadata; } public function createSearchQueryBuilder(string $query, string $orderBy = null, string $order = 'asc'): QueryBuilder @@ -64,7 +63,7 @@ class TorrentSearcher { return ( !\in_array($orderBy, self::ORDER_DISABLED_FIELDS, true) - && $this->em->getClassMetadata(Torrent::class)->hasField($orderBy) + && $this->classMetadata->hasField($orderBy) ); } @@ -76,4 +75,4 @@ class TorrentSearcher return explode(' ', $query); } -} \ No newline at end of file +} diff --git a/symfony.lock b/symfony.lock index eaaf80a..e969a4b 100644 --- a/symfony.lock +++ b/symfony.lock @@ -158,6 +158,9 @@ "symfony/event-dispatcher-contracts": { "version": "v1.1.5" }, + "symfony/expression-language": { + "version": "v4.3.5" + }, "symfony/filesystem": { "version": "v4.1.0" },