|
15 | 15 | use Neos\Flow\ObjectManagement\Exception\ProxyCompilerException; |
16 | 16 |
|
17 | 17 | /** |
18 | | - * Used to disable proxy building for an object. |
| 18 | + * Controls proxy class generation behavior for a class. |
19 | 19 | * |
20 | | - * If disabled, neither Dependency Injection nor AOP can be used |
21 | | - * on the object. |
| 20 | + * This annotation allows you to: |
| 21 | + * - Disable proxy building entirely (enabled=false) - useful for value objects, DTOs, |
| 22 | + * or classes that should not use Dependency Injection or AOP |
| 23 | + * - Force generation of serialization code (forceSerializationCode=true) - rarely needed |
| 24 | + * escape hatch for edge cases where automatic detection of entity relationships fails |
| 25 | + * |
| 26 | + * When proxy building is disabled (enabled=false), neither Dependency Injection nor AOP |
| 27 | + * can be used on the object. The class will be instantiated directly without any |
| 28 | + * framework enhancements. |
22 | 29 | * |
23 | 30 | * @Annotation |
24 | 31 | * @NamedArgumentConstructor |
|
28 | 35 | final class Proxy |
29 | 36 | { |
30 | 37 | /** |
31 | | - * Whether proxy building for the target is disabled. (Can be given as anonymous argument.) |
32 | | - * @var boolean |
| 38 | + * Whether proxy building is enabled for this class. |
| 39 | + * |
| 40 | + * When set to false, Flow will not generate a proxy class, meaning: |
| 41 | + * - No Dependency Injection (no @Flow\Inject annotations) |
| 42 | + * - No Aspect-Oriented Programming (no AOP advices) |
| 43 | + * - No automatic serialization handling |
| 44 | + * - The class is instantiated directly without any framework enhancements |
| 45 | + * |
| 46 | + * This is useful for simple value objects, DTOs, or utility classes that don't need |
| 47 | + * framework features and where you want to avoid the minimal overhead of proxy classes. |
| 48 | + * |
| 49 | + * (Can be given as anonymous argument.) |
33 | 50 | */ |
34 | | - public $enabled = true; |
| 51 | + public bool $enabled = true; |
35 | 52 |
|
36 | 53 | /** |
37 | | - * Whether you need serialization code build in the proxy, this might be needed if you |
38 | | - * build a PHP object you need to serialize that includes entities for example, as in that |
39 | | - * case the entities should be converted to metadata (class & persistence identifier) before |
40 | | - * serialization. |
41 | | - * The serialization code also removes injected/otherwise internal framework properties |
42 | | - * introduced by the proxy building but these situations should be correctly detected by |
43 | | - * proxy building and create the serialization code anyway so you should never have to |
44 | | - * set this for these cases and it would be a bug if you have to. |
45 | | - * |
46 | | - * At this point it wouldn't make much sense to allow a forced disabling of the serialization |
47 | | - * code as that would most certainly run into problems if there was AOP, injections or other reasons. |
48 | | - * Rather disable the proxy completely then. |
49 | | - * |
50 | | - * @var bool |
| 54 | + * Force the generation of serialization code (__sleep/__wakeup methods) in the proxy class. |
| 55 | + * |
| 56 | + * Flow automatically detects when serialization code is needed (e.g., when a class has entity |
| 57 | + * properties, injected dependencies, or transient properties) and generates the appropriate |
| 58 | + * __sleep() and __wakeup() methods. These methods handle: |
| 59 | + * - Converting entity references to metadata (class name + persistence identifier) |
| 60 | + * - Removing injected and framework-internal properties before serialization |
| 61 | + * - Restoring entity references and re-injecting dependencies after deserialization |
| 62 | + * |
| 63 | + * This flag serves as an **escape hatch for rare edge cases** where automatic detection fails, |
| 64 | + * such as: |
| 65 | + * - Complex generic/template types that aren't fully parsed (e.g., ComplexType<Entity>) |
| 66 | + * - Deeply nested entity structures where type hints don't reveal the entity relationship |
| 67 | + * - Union or intersection types with entities that the reflection system cannot fully analyze |
| 68 | + * - Properties with dynamic types where documentation hints are non-standard |
| 69 | + * |
| 70 | + * IMPORTANT: You should rarely need this flag. Flow's automatic detection handles: |
| 71 | + * - Properties typed with @Flow\Entity classes |
| 72 | + * - Properties with @Flow\Inject annotations |
| 73 | + * - Properties with @Flow\Transient annotations |
| 74 | + * - Classes with AOP advices |
| 75 | + * - Session-scoped objects |
| 76 | + * |
| 77 | + * If you find yourself needing this flag for standard entity properties, injected dependencies, |
| 78 | + * or other common cases, this indicates a bug in Flow's detection logic that should be reported |
| 79 | + * at https://github.com/neos/flow-development-collection/issues |
| 80 | + * |
| 81 | + * Note: Disabling serialization code (not possible via this flag) would break classes with |
| 82 | + * AOP, injections, or entity relationships. To completely opt out of proxy features, use |
| 83 | + * enabled=false instead. |
| 84 | + * |
| 85 | + * @see https://flowframework.readthedocs.io/ for more information on object serialization |
51 | 86 | */ |
52 | | - public $forceSerializationCode = false; |
| 87 | + public bool $forceSerializationCode = false; |
53 | 88 |
|
54 | 89 | public function __construct(bool $enabled = true, bool $forceSerializationCode = false) |
55 | 90 | { |
|
0 commit comments