Skip to content

Commit

Permalink
Added the Features syntax for accessing configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
fulopattila122 committed Sep 7, 2023
1 parent e53d4b3 commit 326c5df
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- Added the `Channelable` behavior to Foundation Product, MasterProduct and Taxonomy classes
- Added and extended Foundation Channel model that contains the known relationships to the "channelable" models
- Added the `withinChannel[s]` methods to the ProductSearch class
- Added the `Features` accessor class, which is a syntactic sugar for areas of the configuration

## 3.x Series

Expand Down
24 changes: 24 additions & 0 deletions src/Foundation/Contracts/Feature.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

/**
* Contains the Feature interface.
*
* @copyright Copyright (c) 2023 Vanilo UG
* @author Attila Fulop
* @license MIT
* @since 2023-09-07
*
*/

namespace Vanilo\Foundation\Contracts;

interface Feature
{
public function isEnabled(): bool;

public function isDisabled(): bool;

public function configuration(): array;
}
37 changes: 37 additions & 0 deletions src/Foundation/Features.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

/**
* Contains the Features class.
*
* @copyright Copyright (c) 2023 Vanilo UG
* @author Attila Fulop
* @license MIT
* @since 2023-09-07
*
*/

namespace Vanilo\Foundation;

use Vanilo\Foundation\Features\MultiChannel;

class Features
{
private static ?MultiChannel $multiChannel = null;

public static function multichannel(): MultiChannel
{
return self::$multiChannel ?: (self::$multiChannel = new MultiChannel());
}

public static function isMultiChannelEnabled(): bool
{
return self::multichannel()->isEnabled();
}

public static function isMultiChannelDisabled(): bool
{
return self::multichannel()->isDisabled();
}
}
35 changes: 35 additions & 0 deletions src/Foundation/Features/MultiChannel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

/**
* Contains the MultiChannel class.
*
* @copyright Copyright (c) 2023 Vanilo UG
* @author Attila Fulop
* @license MIT
* @since 2023-09-07
*
*/

namespace Vanilo\Foundation\Features;

use Vanilo\Foundation\Contracts\Feature;

class MultiChannel implements Feature
{
public function isEnabled(): bool
{
return (bool) config('vanilo.foundation.features.multi_channel.is_enabled', false);
}

public function isDisabled(): bool
{
return !$this->isEnabled();
}

public function configuration(): array
{
return config('vanilo.foundation.features.multi_channel', []);
}
}
7 changes: 6 additions & 1 deletion src/Foundation/resources/config/box.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,10 @@
'sign' => '',
'format' => '%1$g%2$s'
*/
]
],
'features' => [
'multi_channel' => [
'is_enabled' => false,
],
],
];

0 comments on commit 326c5df

Please sign in to comment.