Bug #37257 » IntegerConverter.php

Carsten Bleicker, 2012-05-18 14:20

 
1
<?php
2
namespace BLEICKER\FLOW3\Property\TypeConverter;
3

    
4
/*                                                                        *
5
 * This script belongs to the FLOW3 framework.                            *
6
 *                                                                        *
7
 * It is free software; you can redistribute it and/or modify it under    *
8
 * the terms of the GNU Lesser General Public License, either version 3   *
9
 * of the License, or (at your option) any later version.                 *
10
 *                                                                        *
11
 * The TYPO3 project - inspiring people to share!                         *
12
 *                                                                        */
13

    
14
use TYPO3\FLOW3\Annotations as FLOW3;
15

    
16
/**
17
 * Converter which transforms a simple type to an integer, by simply casting it.
18
 *
19
 * @api
20
 * @FLOW3\Scope("singleton")
21
 */
22
class IntegerConverter extends \TYPO3\FLOW3\Property\TypeConverter\AbstractTypeConverter {
23

    
24
	/**
25
	 * @var array<string>
26
	 */
27
	protected $sourceTypes = array('integer', 'string');
28

    
29
	/**
30
	 * @var string
31
	 */
32
	protected $targetType = 'integer';
33

    
34
	/**
35
	 * @var integer
36
	 */
37
	protected $priority = -111112;
38

    
39
	/**
40
	 * Actually convert from $source to $targetType, in fact a noop here.
41
	 *
42
	 * @param integer $source
43
	 * @param string $targetType
44
	 * @param array $convertedChildProperties
45
	 * @param \TYPO3\FLOW3\Property\PropertyMappingConfigurationInterface $configuration
46
	 * @return integer
47
	 * @api
48
	 */
49
	public function convertFrom($source, $targetType, array $convertedChildProperties = array(), \TYPO3\FLOW3\Property\PropertyMappingConfigurationInterface $configuration = NULL) {
50
		if($source==='' || $source === NULL)
51
			return 'NULL';
52
		else
53
			return (integer)$source;
54
	}
55
}
56
?>
(1-1/3)