-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eccc835
commit b364197
Showing
23 changed files
with
453 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
/** | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade Gally to newer versions in the future. | ||
* | ||
* @package Gally | ||
* @author Gally Team <[email protected]> | ||
* @copyright 2024-present Smile | ||
* @license Open Software License v. 3.0 (OSL-3.0) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Gally\OroPlugin\Config; | ||
|
||
use Doctrine\Persistence\ManagerRegistry; | ||
use Gally\OroPlugin\Search\SearchEngine; | ||
use Oro\Bundle\ConfigBundle\Config\ConfigManager as OroConfigManager; | ||
use Oro\Bundle\SecurityBundle\Encoder\SymmetricCrypterInterface; | ||
use Oro\Bundle\WebsiteBundle\Entity\Website; | ||
|
||
class ConfigManager | ||
{ | ||
public function __construct( | ||
private ManagerRegistry $registry, | ||
private OroConfigManager $configManager, | ||
private SymmetricCrypterInterface $crypter, | ||
) { | ||
} | ||
|
||
public function getConfigValue(string $key, int $websiteId = null) | ||
{ | ||
if ($websiteId) { | ||
$website = $this->registry | ||
->getManagerForClass(Website::class) | ||
->getRepository(Website::class) | ||
->find($websiteId); | ||
|
||
return $this->configManager->get($key, false, false, $website); | ||
} | ||
|
||
return $this->configManager->get($key); | ||
} | ||
|
||
public function isGallyEnabled(int $websiteId = null): bool | ||
{ | ||
return (bool) $this->getConfigValue('gally_oro.enabled', $websiteId); | ||
} | ||
|
||
public function getGallyUrl(): string | ||
{ | ||
return $this->getConfigValue('gally_oro.url') ?? ''; | ||
} | ||
|
||
public function getGallyEmail(): string | ||
{ | ||
return $this->getConfigValue('gally_oro.email') ?? ''; | ||
} | ||
|
||
public function getGallyPassword(): string | ||
{ | ||
$encryptedPassword = $this->getConfigValue('gally_oro.password') ?? ''; | ||
$decryptedPassword = $this->crypter->decryptData($encryptedPassword); | ||
|
||
return $decryptedPassword ?: $encryptedPassword; | ||
} | ||
|
||
public function getDsn(): string | ||
{ | ||
$url = parse_url($this->getGallyUrl()); | ||
|
||
return sprintf( | ||
'%s://%s:%s@%s:%s', | ||
SearchEngine::ENGINE_NAME, | ||
rawurlencode($this->getGallyEmail()), | ||
rawurlencode($this->getGallyPassword()), | ||
$url['host'], | ||
$url['port'] ?? ('https' === $url['scheme'] ? 443 : 80) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade Gally to newer versions in the future. | ||
* | ||
* @package Gally | ||
* @author Gally Team <[email protected]> | ||
* @copyright 2024-present Smile | ||
* @license Open Software License v. 3.0 (OSL-3.0) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Gally\OroPlugin\DependencyInjection; | ||
|
||
use Oro\Bundle\ConfigBundle\DependencyInjection\SettingsBuilder; | ||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
class Configuration implements ConfigurationInterface | ||
{ | ||
public const ROOT_NODE = 'gally_oro'; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getConfigTreeBuilder(): TreeBuilder | ||
{ | ||
$treeBuilder = new TreeBuilder(self::ROOT_NODE); | ||
/** @var ArrayNodeDefinition $rootNode */ | ||
$rootNode = $treeBuilder->getRootNode(); | ||
|
||
SettingsBuilder::append( | ||
$rootNode, | ||
[ | ||
'enabled' => ['type' => 'boolean', 'value' => false], | ||
'url' => ['type' => 'string', 'value' => ''], | ||
'email' => ['type' => 'string', 'value' => ''], | ||
'password' => ['type' => 'string', 'value' => ''], | ||
] | ||
); | ||
|
||
return $treeBuilder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.