Skip to main content

Annotating Properties

You can determine in various ways which properties should be "managed".

AnnoDispProperties​

By default, all properties that are public or protected are recognized as "managed". With the annotation n2n\dispatch\annotation\AnnoDispProperties you can prevent this and determine yourself which properties should be "managed". For this, these properties do not necessarily have to be declared in the class of the form model. Suitable getter and setter methods are sufficient. This is for example useful if these properties are not declared in the form model, but in another object (e.g. an entity).

class ExampleForm implements Dispatchable {
private static function _annos(AnnoInit $ai) {
$ai->c(new AnnoDispProperties('foos', 'bar'));
}

private $foos;
private $someObject;
protected $baz;

public function __construct(SomeObject $someObject) {
$this->someObject = $someObject;
}

public function setFoos(array $foos) {
$this->foos = $foos;
}

public function getFoos() {
return $this->foos;
}

public function setBar($bar) {
$this->someObject->setBar($bar);
}

public function getBar() {
return $this->someObject->getBar();
}

private function _validation(BindingDefinition $bd) {
}
}

In this example the properties $foos and "bar" are "managed". The property $baz, on the other hand, is not "managed", although it is protected.

Undeclared Properties​

If properties that are not declared in the class of the form model have to be configured via annotations, the corresponding setter or getter method can be annotated instead of the declared property.

class ExampleForm implements Dispatchable {
private static function _annos(AnnoInit $ai) {
$ai->m('setFoo', new AnnoDispDateTime(DateTimeFormat::STYLE_SHORT));
}

private $someObject;

public function __construct(SomeObject $someObject) {
$this->someObject = $someObject;
}

public function setFoo(\DateTime $foo) {
$this->someObject->setFoo($foo);
}

public function getFoo() {
return $this->someObject->getFoo();
}

private function _validation(BindingDefinition $bd) {
}
}