88
99namespace PackageFactory \AtomicFusion \PresentationObjects \Fusion ;
1010
11+ use Neos \ContentRepository \Core \Projection \ContentGraph \Node ;
1112use Neos \ContentRepositoryRegistry \ContentRepositoryRegistry ;
1213use Neos \Eel \ProtectedContextAwareInterface ;
1314use Neos \Flow \Annotations as Flow ;
@@ -29,6 +30,65 @@ abstract class AbstractComponentPresentationObjectFactory implements
2930 #[Flow \Inject]
3031 protected Translator $ translator ;
3132
33+ /**
34+ * @template T
35+ * @param class-string<T> $expectedType
36+ * @return ?T
37+ */
38+ final protected static function getObjectValue (Node $ node , string $ propertyName , string $ expectedType ): mixed
39+ {
40+ $ propertyValue = $ node ->getProperty ($ propertyName );
41+
42+ return $ propertyValue instanceof $ expectedType
43+ ? $ propertyValue
44+ : null ;
45+ }
46+
47+ /**
48+ * @template T
49+ * @param class-string<T> $expectedType
50+ * @return array<int,T>|null
51+ */
52+ final protected static function getObjectArrayValue (Node $ node , string $ propertyName , string $ expectedType ): ?array
53+ {
54+ $ propertyValue = $ node ->getProperty ($ propertyName );
55+ if (!is_array ($ propertyValue )) {
56+ return null ;
57+ }
58+ return array_filter (
59+ $ propertyValue ,
60+ fn (mixed $ item ): bool => $ item instanceof $ expectedType
61+ );
62+ }
63+
64+ final protected static function getStringValue (Node $ node , string $ propertyName ): ?string
65+ {
66+ $ propertyValue = $ node ->getProperty ($ propertyName );
67+
68+ return is_string ($ propertyValue ) ? $ propertyValue : null ;
69+ }
70+
71+ final protected static function getBoolValue (Node $ node , string $ propertyName ): ?bool
72+ {
73+ $ propertyValue = $ node ->getProperty ($ propertyName );
74+
75+ return is_bool ($ propertyValue ) ? $ propertyValue : null ;
76+ }
77+
78+ final protected static function getIntValue (Node $ node , string $ propertyName ): ?int
79+ {
80+ $ propertyValue = $ node ->getProperty ($ propertyName );
81+
82+ return is_int ($ propertyValue ) ? $ propertyValue : null ;
83+ }
84+
85+ final protected static function getFloatValue (Node $ node , string $ propertyName ): ?float
86+ {
87+ $ propertyValue = $ node ->getProperty ($ propertyName );
88+
89+ return is_float ($ propertyValue ) ? $ propertyValue : null ;
90+ }
91+
3292 /**
3393 * All methods are considered safe
3494 */
0 commit comments