|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Convert the cache name into the model |
|
4
|
|
|
* |
|
5
|
|
|
* @package CacheCheck\Property\TypeConverter |
|
6
|
|
|
* @author Tim Lochmüller |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace HDNET\CacheCheck\Property\TypeConverter; |
|
10
|
|
|
|
|
11
|
|
|
use HDNET\CacheCheck\Domain\Model\Cache; |
|
12
|
|
|
use TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface; |
|
13
|
|
|
use TYPO3\CMS\Extbase\Property\TypeConverter\AbstractTypeConverter; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Convert the cache name into the model |
|
17
|
|
|
* |
|
18
|
|
|
* @author Tim Lochmüller |
|
19
|
|
|
*/ |
|
20
|
|
|
class CacheConverter extends AbstractTypeConverter |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Cache repository |
|
25
|
|
|
* |
|
26
|
|
|
* @var \HDNET\CacheCheck\Domain\Repository\CacheRepository |
|
27
|
|
|
* @inject |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $cacheRepository; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* The source types this converter can convert. |
|
33
|
|
|
* |
|
34
|
|
|
* @var array<string> |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $sourceTypes = ['string']; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* The target type this converter can convert to. |
|
40
|
|
|
* |
|
41
|
|
|
* @var string |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $targetType = Cache::class; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* This implementation always returns TRUE for this method. |
|
47
|
|
|
* |
|
48
|
|
|
* @param mixed $source the source data |
|
49
|
|
|
* @param string $targetType the type to convert to. |
|
50
|
|
|
* |
|
51
|
|
|
* @return boolean TRUE if this TypeConverter can convert from $source to $targetType, FALSE otherwise. |
|
52
|
|
|
*/ |
|
53
|
|
|
public function canConvertFrom($source, $targetType) |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->cacheRepository->findByName($source) !== null; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Actually convert from $source to $targetType, taking into account the fully |
|
60
|
|
|
* built $convertedChildProperties and $configuration. |
|
61
|
|
|
* |
|
62
|
|
|
* The return value can be one of three types: |
|
63
|
|
|
* - an arbitrary object, or a simple type (which has been created while mapping). |
|
64
|
|
|
* This is the normal case. |
|
65
|
|
|
* - NULL, indicating that this object should *not* be mapped (i.e. a "File Upload" Converter could return NULL if no file has been uploaded, and a silent failure should occur. |
|
66
|
|
|
* - An instance of \TYPO3\CMS\Extbase\Error\Error -- This will be a user-visible error message later on. |
|
67
|
|
|
* Furthermore, it should throw an Exception if an unexpected failure (like a security error) occurred or a configuration issue happened. |
|
68
|
|
|
* |
|
69
|
|
|
* @param mixed $source |
|
70
|
|
|
* @param string $targetType |
|
71
|
|
|
* @param array $convertedChildProperties |
|
72
|
|
|
* @param PropertyMappingConfigurationInterface $configuration |
|
73
|
|
|
* |
|
74
|
|
|
* @return mixed|\TYPO3\CMS\Extbase\Error\Error the target type, or an error object if a user-error occurred |
|
75
|
|
|
* @throws \TYPO3\CMS\Extbase\Property\Exception\TypeConverterException thrown in case a developer error occurred |
|
76
|
|
|
* @api |
|
77
|
|
|
*/ |
|
78
|
|
|
public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null) |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->cacheRepository->findByName($source); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|