-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
AdjusterAliases
+ mapping of adjuster FQCN <-> aliases at adj…
…ustment creation
- Loading branch information
1 parent
92ca08a
commit d251577
Showing
7 changed files
with
104 additions
and
3 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
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,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Contains the AdjusterAliases class. | ||
* | ||
* @copyright Copyright (c) 2024 Vanilo UG | ||
* @author Attila Fulop | ||
* @license MIT | ||
* @since 2024-03-05 | ||
* | ||
*/ | ||
|
||
namespace Vanilo\Adjustments\Adjusters; | ||
|
||
final class AdjusterAliases | ||
{ | ||
private static array $map = [ | ||
'discount' => SimpleDiscount::class, | ||
'fee' => SimpleFee::class, | ||
'shipping_fee' => SimpleShippingFee::class, | ||
'tax' => SimpleTax::class, | ||
]; | ||
|
||
public static function add(string $alias, string $fqcn): void | ||
{ | ||
self::$map[$alias] = $fqcn; | ||
} | ||
|
||
public static function isAnAlias(string $value): bool | ||
{ | ||
return isset(self::$map[$value]); | ||
} | ||
|
||
public static function isNotAnAlias(string $value): bool | ||
{ | ||
return !self::isAnAlias($value); | ||
} | ||
|
||
public static function aliasByClass(string $fqcn): ?string | ||
{ | ||
foreach (self::$map as $alias => $class) { | ||
if ($class === $fqcn) { | ||
return $alias; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static function classByAlias(string $alias): ?string | ||
{ | ||
return self::$map[$alias] ?? null; | ||
} | ||
} |
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