@@ 30-92 (lines=63) @@ | ||
27 | /** |
|
28 | * Custom Type for the ShowRaaContactInformationOption Value Object |
|
29 | */ |
|
30 | class ShowRaaContactInformationOptionType extends Type |
|
31 | { |
|
32 | const NAME = 'stepup_show_raa_contact_information_option'; |
|
33 | ||
34 | public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) |
|
35 | { |
|
36 | return $platform->getBooleanTypeDeclarationSQL($fieldDeclaration); |
|
37 | } |
|
38 | ||
39 | public function convertToDatabaseValue($value, AbstractPlatform $platform) |
|
40 | { |
|
41 | if (is_null($value)) { |
|
42 | return $value; |
|
43 | } |
|
44 | ||
45 | if (!$value instanceof ShowRaaContactInformationOption) { |
|
46 | throw new ConversionException( |
|
47 | sprintf( |
|
48 | "Encountered illegal location of type %s '%s', expected a ShowRaaContactInformationOption instance", |
|
49 | is_object($value) ? get_class($value) : gettype($value), |
|
50 | is_scalar($value) ? (string) $value : '' |
|
51 | ) |
|
52 | ); |
|
53 | } |
|
54 | ||
55 | return $value->isEnabled(); |
|
56 | } |
|
57 | ||
58 | public function convertToPHPValue($value, AbstractPlatform $platform) |
|
59 | { |
|
60 | if (is_null($value)) { |
|
61 | return $value; |
|
62 | } |
|
63 | ||
64 | // Prevent a too lenient boolean conversion on non-postgresql platforms |
|
65 | if ($platform->getName() !== 'postgresql') { |
|
66 | if ($value !== 1 && $value !== 0 && $value !== '1' && $value !== '0' && !is_bool($value)) { |
|
67 | throw ConversionException::conversionFailed($value, $this->getName()); |
|
68 | } |
|
69 | } |
|
70 | ||
71 | try { |
|
72 | $showRaaContactInformationOption = new ShowRaaContactInformationOption( |
|
73 | $platform->convertFromBoolean($value) |
|
74 | ); |
|
75 | } catch (InvalidArgumentException $e) { |
|
76 | // get nice standard message, so we can throw it keeping the exception chain |
|
77 | $doctrineExceptionMessage = ConversionException::conversionFailed( |
|
78 | $value, |
|
79 | $this->getName() |
|
80 | )->getMessage(); |
|
81 | ||
82 | throw new ConversionException($doctrineExceptionMessage, 0, $e); |
|
83 | } |
|
84 | ||
85 | return $showRaaContactInformationOption; |
|
86 | } |
|
87 | ||
88 | public function getName() |
|
89 | { |
|
90 | return self::NAME; |
|
91 | } |
|
92 | } |
|
93 |
@@ 30-90 (lines=61) @@ | ||
27 | /** |
|
28 | * Custom Type for the UseRaLocationsOption Value Object |
|
29 | */ |
|
30 | class UseRaLocationsOptionType extends Type |
|
31 | { |
|
32 | const NAME = 'stepup_use_ra_locations_option'; |
|
33 | ||
34 | public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) |
|
35 | { |
|
36 | return $platform->getBooleanTypeDeclarationSQL($fieldDeclaration); |
|
37 | } |
|
38 | ||
39 | public function convertToDatabaseValue($value, AbstractPlatform $platform) |
|
40 | { |
|
41 | if (is_null($value)) { |
|
42 | return $value; |
|
43 | } |
|
44 | ||
45 | if (!$value instanceof UseRaLocationsOption) { |
|
46 | throw new ConversionException( |
|
47 | sprintf( |
|
48 | "Encountered illegal location of type %s '%s', expected a UseRaLocationsOption instance", |
|
49 | is_object($value) ? get_class($value) : gettype($value), |
|
50 | is_scalar($value) ? (string) $value : '' |
|
51 | ) |
|
52 | ); |
|
53 | } |
|
54 | ||
55 | return $value->isEnabled(); |
|
56 | } |
|
57 | ||
58 | public function convertToPHPValue($value, AbstractPlatform $platform) |
|
59 | { |
|
60 | if (is_null($value)) { |
|
61 | return $value; |
|
62 | } |
|
63 | ||
64 | // Prevent a too lenient boolean conversion on non-postgresql platforms |
|
65 | if ($platform->getName() !== 'postgresql') { |
|
66 | if ($value !== 1 && $value !== 0 && $value !== '1' && $value !== '0' && !is_bool($value)) { |
|
67 | throw ConversionException::conversionFailed($value, $this->getName()); |
|
68 | } |
|
69 | } |
|
70 | ||
71 | try { |
|
72 | $useRaLocationsOption = new UseRaLocationsOption($platform->convertFromBoolean($value)); |
|
73 | } catch (InvalidArgumentException $e) { |
|
74 | // get nice standard message, so we can throw it keeping the exception chain |
|
75 | $doctrineExceptionMessage = ConversionException::conversionFailed( |
|
76 | $value, |
|
77 | $this->getName() |
|
78 | )->getMessage(); |
|
79 | ||
80 | throw new ConversionException($doctrineExceptionMessage, 0, $e); |
|
81 | } |
|
82 | ||
83 | return $useRaLocationsOption; |
|
84 | } |
|
85 | ||
86 | public function getName() |
|
87 | { |
|
88 | return self::NAME; |
|
89 | } |
|
90 | } |
|
91 |