forked from hyva-themes/magento2-hyva-admin
-
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.
Merge DataTypeGuesser and DataTypeToString into one to avoid duplication
- Loading branch information
Showing
20 changed files
with
105 additions
and
133 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,8 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Hyva\Admin\Api; | ||
|
||
interface DataTypeInterface extends DataTypeGuesserInterface, DataTypeValueToStringConverterInterface | ||
{ | ||
|
||
} |
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 was deleted.
Oops, something went wrong.
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,48 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Hyva\Admin\Model\DataType; | ||
|
||
use Hyva\Admin\Api\DataTypeGuesserInterface as TypeGuesser; | ||
use Hyva\Admin\Api\DataTypeValueToStringConverterInterface; | ||
|
||
use function array_reduce as reduce; | ||
|
||
class DataTypeFacade implements TypeGuesser, DataTypeToStringConverterLocatorInterface | ||
{ | ||
private array $dataTypeClassMap; | ||
|
||
private DataTypeGuesserFactory $dataTypeGuesserFactory; | ||
|
||
private DataTypeValueToStringConverterFactory $dataTypeValueToStringConverterFactory; | ||
|
||
public function __construct( | ||
array $dataTypeClassMap, | ||
DataTypeGuesserFactory $dataTypeGuesserFactory, | ||
DataTypeValueToStringConverterFactory $dataTypeValueToStringConverterFactory | ||
) { | ||
$this->dataTypeClassMap = $dataTypeClassMap; | ||
$this->dataTypeGuesserFactory = $dataTypeGuesserFactory; | ||
$this->dataTypeValueToStringConverterFactory = $dataTypeValueToStringConverterFactory; | ||
} | ||
|
||
public function valueToTypeCode($value): ?string | ||
{ | ||
return reduce($this->dataTypeClassMap, function (?string $type, string $class) use ($value): ?string { | ||
return $type ?? $this->dataTypeGuesserFactory->get($class)->valueToTypeCode($value); | ||
}, null); | ||
} | ||
|
||
public function typeToTypeCode(string $type): ?string | ||
{ | ||
return reduce($this->dataTypeClassMap, function (?string $typeCode, string $class) use ($type): ?string { | ||
return $typeCode ?? $this->dataTypeGuesserFactory->get($class)->typeToTypeCode($type); | ||
}, null); | ||
} | ||
|
||
public function forTypeCode(string $typeCode): ?DataTypeValueToStringConverterInterface | ||
{ | ||
return isset($this->dataTypeClassMap[$typeCode]) | ||
? $this->dataTypeValueToStringConverterFactory->get($this->dataTypeClassMap[$typeCode]) | ||
: 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 was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
Model/DataType/DataTypeToStringConverterLocatorInterface.php
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,10 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Hyva\Admin\Model\DataType; | ||
|
||
use Hyva\Admin\Api\DataTypeValueToStringConverterInterface; | ||
|
||
interface DataTypeToStringConverterLocatorInterface | ||
{ | ||
public function forTypeCode(string $typeCode): ?DataTypeValueToStringConverterInterface; | ||
} |
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
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.