Merge pull request #2787 from Haendlerbund/add-option-for-set-current-channel

add option to set current channel
This commit is contained in:
Jitendra Singh 2020-04-10 11:45:04 +05:30 committed by GitHub
commit 9752f634e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 13 deletions

View File

@ -64,6 +64,9 @@ class Core
*/
protected $coreConfigRepository;
/** @var Channel */
private static $channel;
/**
* Create a new instance.
*
@ -125,23 +128,31 @@ class Core
*/
public function getCurrentChannel()
{
static $channel;
if ($channel) {
return $channel;
if (self::$channel) {
return self::$channel;
}
$channel = $this->channelRepository->findWhereIn('hostname', [
self::$channel = $this->channelRepository->findWhereIn('hostname', [
request()->getHttpHost(),
'http://' . request()->getHttpHost(),
'https://' . request()->getHttpHost(),
])->first();
if (! $channel) {
$channel = $this->channelRepository->first();
if (! self::$channel) {
self::$channel = $this->channelRepository->first();
}
return $channel;
return self::$channel;
}
/**
* Set the current channel
*
* @param Channel $channel
*/
public function setCurrentChannel(Channel $channel): void
{
self::$channel = $channel;
}
/**
@ -684,7 +695,7 @@ class Core
$fields = explode(".", $field);
array_shift($fields);
$field = implode(".", $fields);
return Config::get($field);
@ -832,9 +843,9 @@ class Core
}
/**
*
*
* @param string $date
* @param int $day
* @param int $day
* @return string
*/
public function xWeekRange($date, $day)
@ -973,7 +984,7 @@ class Core
protected function arrayMerge(array &$array1, array &$array2)
{
$merged = $array1;
foreach ($array2 as $key => &$value) {
if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
$merged[$key] = $this->arrayMerge($merged[$key], $value);
@ -1019,7 +1030,7 @@ class Core
/**
* Returns a string as selector part for identifying elements in views
*
*
* @param float $taxRate
* @return string
*/