From dfee2289f80c33edae6de46b65c02ea3ae76d2c1 Mon Sep 17 00:00:00 2001 From: Guite Date: Sun, 31 May 2020 17:26:18 +0200 Subject: [PATCH] simplified project directory injection --- Bridge/ProfileModuleBridge.php | 17 ++++++++--------- Form/Type/AvatarType.php | 7 +++---- Resources/config/services.yaml | 1 + 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Bridge/ProfileModuleBridge.php b/Bridge/ProfileModuleBridge.php index 68a2fef..fa61f60 100644 --- a/Bridge/ProfileModuleBridge.php +++ b/Bridge/ProfileModuleBridge.php @@ -16,7 +16,6 @@ use InvalidArgumentException; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Routing\RouterInterface; -use Zikula\Bundle\CoreBundle\HttpKernel\ZikulaHttpKernelInterface; use Zikula\ExtensionsModule\Api\ApiInterface\VariableApiInterface; use Zikula\ProfileModule\Helper\GravatarHelper; use Zikula\ProfileModule\ProfileConstant; @@ -28,11 +27,6 @@ class ProfileModuleBridge implements ProfileModuleInterface { - /** - * @var ZikulaHttpKernelInterface - */ - private $kernel; - /** * @var RouterInterface */ @@ -63,28 +57,33 @@ class ProfileModuleBridge implements ProfileModuleInterface */ private $gravatarHelper; + /** + * @var string + */ + private $projectDir; + /** * @var string */ private $prefix; public function __construct( - ZikulaHttpKernelInterface $kernel, RouterInterface $router, RequestStack $requestStack, VariableApiInterface $variableApi, CurrentUserApiInterface $currentUser, UserRepositoryInterface $userRepository, GravatarHelper $gravatarHelper, + string $projectDir, $prefix ) { - $this->kernel = $kernel; $this->router = $router; $this->requestStack = $requestStack; $this->variableApi = $variableApi; $this->currentUser = $currentUser; $this->userRepository = $userRepository; $this->gravatarHelper = $gravatarHelper; + $this->projectDir = $projectDir; $this->prefix = $prefix; } @@ -130,7 +129,7 @@ public function getAvatar($uid = null, array $parameters = []): string $avatarUrl = ''; if (!in_array($avatar, ['blank.gif', 'blank.jpg'], true)) { - if (isset($avatar) && !empty($avatar) && $avatar !== $gravatarImage && file_exists($this->kernel->getProjectDir() . '/' . $avatarPath . '/' . $avatar)) { + if (isset($avatar) && !empty($avatar) && $avatar !== $gravatarImage && file_exists($this->projectDir . '/' . $avatarPath . '/' . $avatar)) { $request = $this->requestStack->getCurrentRequest(); if (null !== $request) { $avatarUrl = $request->getSchemeAndHttpHost() . $request->getBasePath() . '/' . $avatarPath . '/' . $avatar; diff --git a/Form/Type/AvatarType.php b/Form/Type/AvatarType.php index 4f033a5..25e314d 100644 --- a/Form/Type/AvatarType.php +++ b/Form/Type/AvatarType.php @@ -18,7 +18,6 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\FileType; use Symfony\Component\OptionsResolver\OptionsResolver; -use Zikula\Bundle\CoreBundle\HttpKernel\ZikulaHttpKernelInterface; use Zikula\ExtensionsModule\Api\ApiInterface\VariableApiInterface; use Zikula\UsersModule\Constant as UsersConstant; @@ -35,11 +34,11 @@ class AvatarType extends AbstractType private $avatarPath; public function __construct( - ZikulaHttpKernelInterface $kernel, - VariableApiInterface $variableApi + VariableApiInterface $variableApi, + string $projectDir ) { $this->modVars = $variableApi->getAll('ZikulaProfileModule'); - $this->avatarPath = $kernel->getProjectDir() . '/' . $variableApi->get(UsersConstant::MODNAME, 'avatarpath', 'public/uploads/avatar'); + $this->avatarPath = $projectDir . '/' . $variableApi->get(UsersConstant::MODNAME, 'avatarpath', 'public/uploads/avatar'); } public function configureOptions(OptionsResolver $resolver) diff --git a/Resources/config/services.yaml b/Resources/config/services.yaml index fb87de2..03a5949 100644 --- a/Resources/config/services.yaml +++ b/Resources/config/services.yaml @@ -9,6 +9,7 @@ services: bind: $extension: '@Zikula\ProfileModule\ZikulaProfileModule' $prefix: '%zikula_profile_module.property_prefix%' + $projectDir: '%kernel.project_dir%' Zikula\ProfileModule\: resource: '../../*'