Annotations are more than phpdoc comments, they're a fully-featured way of including additional information alongside your code. We might have rejected an RFC to add support into the PHP core, but the community has embraced this tool anyway! This session shows you who is doing what with annotations, and will give you some ideas on how to use the existing tools in your own projects to keep life simple. Developers, architects and anyone responsible for the technical direction of an application should attend this session.
38. subject
-- In English --
An annotation is a note that is made while
reading any form of text.
39. -- In Code Speak --
“An annotation is metadata attached to your
code, that can be read at runtime.”
“Annotations do not directly affect program
semantics”
40. -- In Code Speak --
“An annotation is metadata attached to your
code, that can be read at runtime.”
effects
269. “Annotations and comments are like water and oil,
just because they are in the same container, does
not mean they mix”
!
—- @rosstuck
photo by Adam Arroyo
447. Works
?php
use DoctrineORMMapping as ORM;!
use SymfonyComponentValidator!
Constraints as Assert;
/**!
* @ORMColumn(‘string’)!
* @AssertNotBlank()!
*/
453. Works
?php
use DoctrineORMMapping as ORM;!
use SymfonyComponentValidator!
Constraints as Assert;
/**!
* @ORMColumn(‘string’)!
* @AssertNotBlank()!
*/
you
461. Works
AnnotationReader
?php
use DoctrineORMMapping as ORM;!
use SymfonyComponentValidator!
Constraints as Assert;
/**!
* @ORMColumn(‘string’)!
* @AssertNotBlank()!
*/
you
466. Works
AnnotationReader
?php
/**!
* @ORMColumn(‘string’)!
* @AssertNotBlank()!
*/
“metadata”
new ORMColumn(‘string’)!
new AssertNotBlank()
use DoctrineORMMapping as ORM;!
use SymfonyComponentValidator!
Constraints as Assert;
Declare
477. Works
AnnotationReader
?php
use DoctrineORMMapping as ORM;!
use SymfonyComponentValidator!
Constraints as Assert;
/**!
* @ORMColumn(‘string’)!
* @AssertNotBlank()!
*/
new ORMColumn(‘string’)!
new AssertNotBlank()
Cache
“metadata”
Walker
488. Rules:
Rules are objects that represent the annotations
new RulesStripTags(‘bi’);
489. Filters:
Filters are the executioners, they apply the effect of a rule
$executioner = new FilterStripTags();!
$executioner-filter($metadata, $value);
490. Filter
Service
Filter Service:
Orchestrates the process of extracting values, filtering and replacing
original values
491. Annotation
Engine
Annotation Engine:
Extracts string values into instances of rules for the Filter Service to
parse
555. $service = new FilterService($reader);
Instantiate the service (DIC)
556. $service = new FilterService($reader);
Instantiate the service (DIC)
$service-filter($object);
Call for an object to be filtered
557. $service = new FilterService($reader);
Instantiate the service (DIC)
$service-filter($object);
Call for an object to be filtered
$reader-getPropertyAnnotations($object);
//$a = array(RuleStripTags(), RuleAlpha());
The service uses the reader to read annotations and get
the rule objects
558. $service = new FilterService($reader);
Instantiate the service (DIC)
$service-filter($object);
Call for an object to be filtered
$reader-getPropertyAnnotations($object);
//$a = array(RuleStripTags(), RuleAlpha());
The service uses the reader to read annotations and get
the rule objects
//new FiltersStripTags();
$object-prop = $filter-apply($rule, $object-prop);
Service resolves Rules into Filter objects, applies and
overrides object
559. //Iterate over all annotations !
foreach($this-reader-getPropertyAnnotations($property) as $rule) { !
!
//Skip is its not a rule !
if ( ! $rule instanceof RulesRule ) continue; !
!
//Add Rule !
$metadata-addPropertyRule($property-getName(), $rule); !
!
}
560. //Iterate over all annotations !
foreach($this-reader-getPropertyAnnotations($property) as $rule) { !
!
//Skip is its not a rule !
if ( ! $rule instanceof RulesRule ) continue; !
!
//Add Rule !
$metadata-addPropertyRule($property-getName(), $rule); !
!
}
get
564. //Iterate over all annotations !
foreach($this-reader-getPropertyAnnotations($property) as $rule) { !
!
//Skip is its not a rule !
if ( ! $rule instanceof RulesRule ) continue; !
!
//Add Rule !
$metadata-addPropertyRule($property-getName(), $rule); !
!
}
get
571. //Iterate over all annotations !
foreach($this-reader-getPropertyAnnotations($property) as $rule) { !
!
//Skip is its not a rule !
if ( ! $rule instanceof RulesRule ) continue; !
!
//Add Rule !
$metadata-addPropertyRule($property-getName(), $rule); !
!
}
glorified