Skip to content

Commit 53be99c

Browse files
committed
Improve documentation for Proxy annotation
1 parent 28ee545 commit 53be99c

File tree

1 file changed

+56
-21
lines changed

1 file changed

+56
-21
lines changed

Neos.Flow/Classes/Annotations/Proxy.php

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@
1515
use Neos\Flow\ObjectManagement\Exception\ProxyCompilerException;
1616

1717
/**
18-
* Used to disable proxy building for an object.
18+
* Controls proxy class generation behavior for a class.
1919
*
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.
2229
*
2330
* @Annotation
2431
* @NamedArgumentConstructor
@@ -28,28 +35,56 @@
2835
final class Proxy
2936
{
3037
/**
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.)
3350
*/
34-
public $enabled = true;
51+
public bool $enabled = true;
3552

3653
/**
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
5186
*/
52-
public $forceSerializationCode = false;
87+
public bool $forceSerializationCode = false;
5388

5489
public function __construct(bool $enabled = true, bool $forceSerializationCode = false)
5590
{

0 commit comments

Comments
 (0)