Skip to content
This repository has been archived by the owner on May 27, 2023. It is now read-only.

Commit

Permalink
simplified project directory injection
Browse files Browse the repository at this point in the history
  • Loading branch information
Guite committed May 31, 2020
1 parent 03d3caa commit dfee228
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
17 changes: 8 additions & 9 deletions Bridge/ProfileModuleBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,11 +27,6 @@

class ProfileModuleBridge implements ProfileModuleInterface
{
/**
* @var ZikulaHttpKernelInterface
*/
private $kernel;

/**
* @var RouterInterface
*/
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions Form/Type/AvatarType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ services:
bind:
$extension: '@Zikula\ProfileModule\ZikulaProfileModule'
$prefix: '%zikula_profile_module.property_prefix%'
$projectDir: '%kernel.project_dir%'

Zikula\ProfileModule\:
resource: '../../*'
Expand Down

0 comments on commit dfee228

Please sign in to comment.