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", "sentry/sentry-symfony": "^2.2",
"symfony/console": "^4.1", "symfony/console": "^4.1",
"symfony/dotenv": "^4.1", "symfony/dotenv": "^4.1",
"symfony/expression-language": "^4.1",
"symfony/flex": "^1.0", "symfony/flex": "^1.0",
"symfony/form": "^4.1", "symfony/form": "^4.1",
"symfony/framework-bundle": "^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", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "9357f0481f1bae9e751158689364ba6b", "content-hash": "affcef344df6ac8f86b6f1ab41e04968",
"packages": [ "packages": [
{ {
"name": "doctrine/annotations", "name": "doctrine/annotations",
@ -2752,6 +2752,57 @@
], ],
"time": "2019-06-20T06:46:26+00:00" "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", "name": "symfony/filesystem",
"version": "v4.3.2", "version": "v4.3.2",

View file

@ -43,4 +43,4 @@ services:
# Torrent searcher # Torrent searcher
App\Search\TorrentSearcher: App\Search\TorrentSearcher:
arguments: 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; namespace App\Search;
use App\Magnetico\Entity\Torrent;
use App\Magnetico\Repository\TorrentRepository; use App\Magnetico\Repository\TorrentRepository;
use Doctrine\ORM\{EntityManagerInterface, QueryBuilder}; use Doctrine\ORM\{Mapping\ClassMetadata, QueryBuilder};
class TorrentSearcher class TorrentSearcher
{ {
@ -13,13 +12,13 @@ class TorrentSearcher
/** @var TorrentRepository */ /** @var TorrentRepository */
private $torrentRepo; private $torrentRepo;
/** @var EntityManagerInterface */ /** @var ClassMetadata */
private $em; private $classMetadata;
public function __construct(TorrentRepository $torrentRepo, EntityManagerInterface $em) public function __construct(TorrentRepository $torrentRepo, ClassMetadata $classMetadata)
{ {
$this->torrentRepo = $torrentRepo; $this->torrentRepo = $torrentRepo;
$this->em = $em; $this->classMetadata = $classMetadata;
} }
public function createSearchQueryBuilder(string $query, string $orderBy = null, string $order = 'asc'): QueryBuilder public function createSearchQueryBuilder(string $query, string $orderBy = null, string $order = 'asc'): QueryBuilder
@ -64,7 +63,7 @@ class TorrentSearcher
{ {
return ( return (
!\in_array($orderBy, self::ORDER_DISABLED_FIELDS, true) !\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); return explode(' ', $query);
} }
} }

View file

@ -158,6 +158,9 @@
"symfony/event-dispatcher-contracts": { "symfony/event-dispatcher-contracts": {
"version": "v1.1.5" "version": "v1.1.5"
}, },
"symfony/expression-language": {
"version": "v4.3.5"
},
"symfony/filesystem": { "symfony/filesystem": {
"version": "v4.1.0" "version": "v4.1.0"
}, },