Replacing TorrentSearcher dependency on EntityManager with dependency on ClassMetadata of the Torrent class.

This commit is contained in:
Alexey Skobkin 2019-10-20 23:00:36 +03:00
parent 5a87ae6476
commit 63811e10e3
No known key found for this signature in database
GPG Key ID: 5D5CEF6F221278E7
5 changed files with 64 additions and 10 deletions

View File

@ -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",

53
composer.lock generated
View File

@ -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",

View File

@ -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'')'

View File

@ -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);
}
}
}

View File

@ -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"
},