*
 TrueNorthPHP
 -
 Toronto/2012 Annotating
 with
    Annotations         A
 look
 into
 Annotations
 in
 PHP                                                                                                                      ...
 twitter                                 Rafael
 Dohms                                                                                                                    ...
*
 TrueNorthPHP
 -
 Toronto/2012 Annotating
 with
    Annotations         A
 look
 into
 Annotations
 in
 PHP                                                                                                                      ...
 twitter                                 Rafael
 Dohms                                                                                                                    ...
Rafael Dohms                           photo credit: Eli White       @rdohms Evangelist, Speaker and      Contributor.Deve...
a
 little
 history                                                                                                                  ...
 uses                                                                                     What?                           ...
 ann otations                                                                                     Impl ementing
 c DMSFilter                                                                                             based
 on
                                                                                                                          ...
 me
 the
 code!
http://ecdesignrebels.blogspot.com   w h a t?                                                                           ta...
 an noW ha t
 a
-- In English --An annotation is a note that is made  while reading any form of text.
something
 that
 describes
 an
 aspect
 of
 the
 subject          -- In English --An annotation is a note that is made  while reading any form of text.
-- In Code Speak --“An annotation describes behavior of code and affects your application in              runtime.” “Annot...
-- In Code Speak --“An annotation describes behavior of code and affects your application in              runtime.” “Annot...
 like
 your
 notes
In
 2004:
 Metadata
 or
 “General
 purpose
 Annotations”
In
 2004:
 Metadata
 or
 “General
 purpose
 Annotations”                                                                       available
 at
 Runtime
 using
 Reflection
In
 2004:
 Metadata
 or
 “General
 purpose
 Annotations”                    @Entity                      @Table(name = people)                      class Person impl...
 at
 Runtime
 using
 Reflection
In
 2004:
 Metadata
 or
 “General
 purpose
 Annotations”                                                                                                             ...
 syntax                    @Entity                      @Table(name = people)                      class Person implements...
 at
 Runtime
 using
 Reflection
No
 core
 annotation
 support
Questions?
Questions?I’m
 kidding!
phpDoc~2000
PHP
 5.1  Reflection
 supports
    getDocComments()phpDoc~2000                              2005
PHP
 5.1                 Reflection
 supports
                   getDocComments()phpDoc~2000                                                                         200...
                                    Annotation
 Engines
 in
 PHP
PHP
Upcoming SlideShare
Loading in...5
×

Annotating with Annotations

5,413

Published on

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.

Published in: Technology
0 Comments
11 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,413
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
210
Comments
0
Likes
11
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • Overview of how annotations are just descriptions of static resources. Like HTML syntax can describe text with bold, italic\n
  • Overview of how annotations are just descriptions of static resources. Like HTML syntax can describe text with bold, italic\n
  • phpDoc vs. Annotation: docs do not have influence in how a app runs.\nAnnotation by itself does not “act” its used to be acted on by another class.\n\nJust putting an annotation is not going to work, you need someone to act on it.\n
  • phpDoc vs. Annotation: docs do not have influence in how a app runs.\nAnnotation by itself does not “act” its used to be acted on by another class.\n\nJust putting an annotation is not going to work, you need someone to act on it.\n
  • Java: annotations since 2004, same syntax for javadocs and annotations\nRuntime uses reflection to read annnotations\nJavadoc Vs. Annotations: same as PHPDoc mentioned before\n
  • Java: annotations since 2004, same syntax for javadocs and annotations\nRuntime uses reflection to read annnotations\nJavadoc Vs. Annotations: same as PHPDoc mentioned before\n
  • Java: annotations since 2004, same syntax for javadocs and annotations\nRuntime uses reflection to read annnotations\nJavadoc Vs. Annotations: same as PHPDoc mentioned before\n
  • Java: annotations since 2004, same syntax for javadocs and annotations\nRuntime uses reflection to read annnotations\nJavadoc Vs. Annotations: same as PHPDoc mentioned before\n
  • Java: annotations since 2004, same syntax for javadocs and annotations\nRuntime uses reflection to read annnotations\nJavadoc Vs. Annotations: same as PHPDoc mentioned before\n
  • Java: annotations since 2004, same syntax for javadocs and annotations\nRuntime uses reflection to read annnotations\nJavadoc Vs. Annotations: same as PHPDoc mentioned before\n
  • Java: annotations since 2004, same syntax for javadocs and annotations\nRuntime uses reflection to read annnotations\nJavadoc Vs. Annotations: same as PHPDoc mentioned before\n
  • PHP has no support for Annotations.\n
  • PHP has no support for Annotations.\n
  • Pretend its the end of the talk.\n
  • Mentions stubbles and other engines.\nTie in D2 Annotation Engine and Gulherme as the author of both.\n
  • Mentions stubbles and other engines.\nTie in D2 Annotation Engine and Gulherme as the author of both.\n
  • Mentions stubbles and other engines.\nTie in D2 Annotation Engine and Gulherme as the author of both.\n
  • Mentions stubbles and other engines.\nTie in D2 Annotation Engine and Gulherme as the author of both.\n
  • Mentions stubbles and other engines.\nTie in D2 Annotation Engine and Gulherme as the author of both.\n
  • Mentions stubbles and other engines.\nTie in D2 Annotation Engine and Gulherme as the author of both.\n
  • Mentions stubbles and other engines.\nTie in D2 Annotation Engine and Gulherme as the author of both.\n
  • Mentions stubbles and other engines.\nTie in D2 Annotation Engine and Gulherme as the author of both.\n
  • Mentions stubbles and other engines.\nTie in D2 Annotation Engine and Gulherme as the author of both.\n
  • Mentions stubbles and other engines.\nTie in D2 Annotation Engine and Gulherme as the author of both.\n
  • Mentions stubbles and other engines.\nTie in D2 Annotation Engine and Gulherme as the author of both.\n
  • Mentions stubbles and other engines.\nTie in D2 Annotation Engine and Gulherme as the author of both.\n
  • Mentions stubbles and other engines.\nTie in D2 Annotation Engine and Gulherme as the author of both.\n
  • Mentions stubbles and other engines.\nTie in D2 Annotation Engine and Gulherme as the author of both.\n
  • Mentions stubbles and other engines.\nTie in D2 Annotation Engine and Gulherme as the author of both.\n
  • Mentions stubbles and other engines.\nTie in D2 Annotation Engine and Gulherme as the author of both.\n
  • Mentions stubbles and other engines.\nTie in D2 Annotation Engine and Gulherme as the author of both.\n
  • Mentions stubbles and other engines.\nTie in D2 Annotation Engine and Gulherme as the author of both.\n
  • Mentions stubbles and other engines.\nTie in D2 Annotation Engine and Gulherme as the author of both.\n
  • Mentions stubbles and other engines.\nTie in D2 Annotation Engine and Gulherme as the author of both.\n
  • Mentions stubbles and other engines.\nTie in D2 Annotation Engine and Gulherme as the author of both.\n
  • Mentions stubbles and other engines.\nTie in D2 Annotation Engine and Gulherme as the author of both.\n
  • Make a note that PHP does have a custom token for DOCBLOCKS so annotations are not in “documents” and docblocks are even stored in opcode caches.\n
  • Make a note that PHP does have a custom token for DOCBLOCKS so annotations are not in “documents” and docblocks are even stored in opcode caches.\n
  • Make a note that PHP does have a custom token for DOCBLOCKS so annotations are not in “documents” and docblocks are even stored in opcode caches.\n
  • Make a note that PHP does have a custom token for DOCBLOCKS so annotations are not in “documents” and docblocks are even stored in opcode caches.\n
  • Make a note that PHP does have a custom token for DOCBLOCKS so annotations are not in “documents” and docblocks are even stored in opcode caches.\n
  • Diferentiate between Marker Type and Parametrized type\n\nParameterized has more details and complex syntax , marker has no content or simple string syntax\n
  • Diferentiate between Marker Type and Parametrized type\n\nParameterized has more details and complex syntax , marker has no content or simple string syntax\n
  • Diferentiate between Marker Type and Parametrized type\n\nParameterized has more details and complex syntax , marker has no content or simple string syntax\n
  • Diferentiate between Marker Type and Parametrized type\n\nParameterized has more details and complex syntax , marker has no content or simple string syntax\n
  • \n
  • T_DOC_COMMENTS since PHP 5.3 - APC support\n\nDebugging is harder but really a problem.\nPerformance is much better with cache\n\nTesting: can be done by feeding annotation “action” service with populated entities for example\n
  • T_DOC_COMMENTS since PHP 5.3 - APC support\n\nDebugging is harder but really a problem.\nPerformance is much better with cache\n\nTesting: can be done by feeding annotation “action” service with populated entities for example\n
  • T_DOC_COMMENTS since PHP 5.3 - APC support\n\nDebugging is harder but really a problem.\nPerformance is much better with cache\n\nTesting: can be done by feeding annotation “action” service with populated entities for example\n
  • Pros:\n- Compare D1 to D2, you no longer need to extend an object to have persistence behaviour\n- 1 config file with 1000 objects vs. 1000 objects with all their own config\n
  • Pros:\n- Compare D1 to D2, you no longer need to extend an object to have persistence behaviour\n- 1 config file with 1000 objects vs. 1000 objects with all their own config\n
  • Pros:\n- Compare D1 to D2, you no longer need to extend an object to have persistence behaviour\n- 1 config file with 1000 objects vs. 1000 objects with all their own config\n
  • Pros:\n- Compare D1 to D2, you no longer need to extend an object to have persistence behaviour\n- 1 config file with 1000 objects vs. 1000 objects with all their own config\n
  • Pros:\n- Compare D1 to D2, you no longer need to extend an object to have persistence behaviour\n- 1 config file with 1000 objects vs. 1000 objects with all their own config\n
  • Pros:\n- Compare D1 to D2, you no longer need to extend an object to have persistence behaviour\n- 1 config file with 1000 objects vs. 1000 objects with all their own config\n
  • \n
  • \n
  • \n
  • So imagine you are planning a new entity, your mind usually puts a post it on it with all this information\nYou would then have to put persistance in one config, validation in another...\n\nNote how all validations rules are now in a single place.\nEasier to maintain, since its easier to analyse all aspects\n
  • So imagine you are planning a new entity, your mind usually puts a post it on it with all this information\nYou would then have to put persistance in one config, validation in another...\n\nNote how all validations rules are now in a single place.\nEasier to maintain, since its easier to analyse all aspects\n
  • So imagine you are planning a new entity, your mind usually puts a post it on it with all this information\nYou would then have to put persistance in one config, validation in another...\n\nNote how all validations rules are now in a single place.\nEasier to maintain, since its easier to analyse all aspects\n
  • So imagine you are planning a new entity, your mind usually puts a post it on it with all this information\nYou would then have to put persistance in one config, validation in another...\n\nNote how all validations rules are now in a single place.\nEasier to maintain, since its easier to analyse all aspects\n
  • So imagine you are planning a new entity, your mind usually puts a post it on it with all this information\nYou would then have to put persistance in one config, validation in another...\n\nNote how all validations rules are now in a single place.\nEasier to maintain, since its easier to analyse all aspects\n
  • So imagine you are planning a new entity, your mind usually puts a post it on it with all this information\nYou would then have to put persistance in one config, validation in another...\n\nNote how all validations rules are now in a single place.\nEasier to maintain, since its easier to analyse all aspects\n
  • So imagine you are planning a new entity, your mind usually puts a post it on it with all this information\nYou would then have to put persistance in one config, validation in another...\n\nNote how all validations rules are now in a single place.\nEasier to maintain, since its easier to analyse all aspects\n
  • So imagine you are planning a new entity, your mind usually puts a post it on it with all this information\nYou would then have to put persistance in one config, validation in another...\n\nNote how all validations rules are now in a single place.\nEasier to maintain, since its easier to analyse all aspects\n
  • So imagine you are planning a new entity, your imnd usually puts a post it on it with all this information\nYou would then have to put persistance in one config, validation in another...\n\nNote how all validations rules are now in a single place.\nEasier to maintain, since its easier to analyse all aspects\n
  • \n
  • Common uses for annotations in PHP\n\nPersistence, grouping, routing, docs, validation, filtering, expectations, API Generation\n
  • phpDoc uses just marker annotations which arguably are not annotations\nPHPUnit uses it for a long time\nnew frameworks have their own engines and D2 was Hibernate based.\n
  • Example from PHPUnit\n
  • Example from D2\n
  • Example from SF2\n
  • Example in Typo3\n
  • \n
  • So what do you need to have annotations in you application?\n
  • So what do you need to have annotations in you application?\n
  • So what do you need to have annotations in you application?\n
  • How annotations (text) become actual rules/objects.\nReflection to read, and annotation engine to parse and instantiate.\nNOTE: from here another service will use these annotations to “act” upon the code.\n
  • How annotations (text) become actual rules/objects.\nReflection to read, and annotation engine to parse and instantiate.\nNOTE: from here another service will use these annotations to “act” upon the code.\n
  • How annotations (text) become actual rules/objects.\nReflection to read, and annotation engine to parse and instantiate.\nNOTE: from here another service will use these annotations to “act” upon the code.\n
  • How annotations (text) become actual rules/objects.\nReflection to read, and annotation engine to parse and instantiate.\nNOTE: from here another service will use these annotations to “act” upon the code.\n
  • How annotations (text) become actual rules/objects.\nReflection to read, and annotation engine to parse and instantiate.\nNOTE: from here another service will use these annotations to “act” upon the code.\n
  • How annotations (text) become actual rules/objects.\nReflection to read, and annotation engine to parse and instantiate.\nNOTE: from here another service will use these annotations to “act” upon the code.\n
  • How annotations (text) become actual rules/objects.\nReflection to read, and annotation engine to parse and instantiate.\nNOTE: from here another service will use these annotations to “act” upon the code.\n
  • How annotations (text) become actual rules/objects.\nReflection to read, and annotation engine to parse and instantiate.\nNOTE: from here another service will use these annotations to “act” upon the code.\n
  • How annotations (text) become actual rules/objects.\nReflection to read, and annotation engine to parse and instantiate.\nNOTE: from here another service will use these annotations to “act” upon the code.\n
  • How annotations (text) become actual rules/objects.\nReflection to read, and annotation engine to parse and instantiate.\nNOTE: from here another service will use these annotations to “act” upon the code.\n
  • How annotations (text) become actual rules/objects.\nReflection to read, and annotation engine to parse and instantiate.\nNOTE: from here another service will use these annotations to “act” upon the code.\n
  • How annotations (text) become actual rules/objects.\nReflection to read, and annotation engine to parse and instantiate.\nNOTE: from here another service will use these annotations to “act” upon the code.\n
  • How annotations (text) become actual rules/objects.\nReflection to read, and annotation engine to parse and instantiate.\nNOTE: from here another service will use these annotations to “act” upon the code.\n
  • Some of the engines out there.\nZF2 has no docs or use yet.\nNotoj by Cesar Rodas is very new\nphpDocumentor has a new engine\nphp-annotations by Rasmus Schultz\n\n\nSome were abandoned along the way\n
  • No dependencies on any\nNotoj is very “microPHP”\nReming people of parameterized vs. marker\n\nD2 is the best support right now. With caching and the whole load\n
  • How the D2 Engine works .. a high overview.\nThe Reader gets the data from the class which is the parsed by the lexer and finally becomes instances. Which are cached and passed in the format of Metadata classes to your walker/action class\n\n
  • How the D2 Engine works .. a high overview.\nThe Reader gets the data from the class which is the parsed by the lexer and finally becomes instances. Which are cached and passed in the format of Metadata classes to your walker/action class\n\n
  • How the D2 Engine works .. a high overview.\nThe Reader gets the data from the class which is the parsed by the lexer and finally becomes instances. Which are cached and passed in the format of Metadata classes to your walker/action class\n\n
  • How the D2 Engine works .. a high overview.\nThe Reader gets the data from the class which is the parsed by the lexer and finally becomes instances. Which are cached and passed in the format of Metadata classes to your walker/action class\n\n
  • How the D2 Engine works .. a high overview.\nThe Reader gets the data from the class which is the parsed by the lexer and finally becomes instances. Which are cached and passed in the format of Metadata classes to your walker/action class\n\n
  • How the D2 Engine works .. a high overview.\nThe Reader gets the data from the class which is the parsed by the lexer and finally becomes instances. Which are cached and passed in the format of Metadata classes to your walker/action class\n\n
  • How the D2 Engine works .. a high overview.\nThe Reader gets the data from the class which is the parsed by the lexer and finally becomes instances. Which are cached and passed in the format of Metadata classes to your walker/action class\n\n
  • How the D2 Engine works .. a high overview.\nThe Reader gets the data from the class which is the parsed by the lexer and finally becomes instances. Which are cached and passed in the format of Metadata classes to your walker/action class\n\n
  • How the D2 Engine works .. a high overview.\nThe Reader gets the data from the class which is the parsed by the lexer and finally becomes instances. Which are cached and passed in the format of Metadata classes to your walker/action class\n\n
  • How the D2 Engine works .. a high overview.\nThe Reader gets the data from the class which is the parsed by the lexer and finally becomes instances. Which are cached and passed in the format of Metadata classes to your walker/action class\n\n
  • How the D2 Engine works .. a high overview.\nThe Reader gets the data from the class which is the parsed by the lexer and finally becomes instances. Which are cached and passed in the format of Metadata classes to your walker/action class\n\n
  • All examples are going to be from DMS\\Filter\n
  • All you really need is to implement a “Annotation” class and a Enforcer, a class that will be able to get an annotation and know what to do. i.e. call the “filterValue” method with the value from the object and replace the original value with the clean one.\n
  • All you really need is to implement a “Annotation” class and a Enforcer, a class that will be able to get an annotation and know what to do. i.e. call the “filterValue” method with the value from the object and replace the original value with the clean one.\n
  • All you really need is to implement a “Annotation” class and a Enforcer, a class that will be able to get an annotation and know what to do. i.e. call the “filterValue” method with the value from the object and replace the original value with the clean one.\n
  • All you really need is to implement a “Annotation” class and a Enforcer, a class that will be able to get an annotation and know what to do. i.e. call the “filterValue” method with the value from the object and replace the original value with the clean one.\n
  • All you really need is to implement a “Annotation” class and a Enforcer, a class that will be able to get an annotation and know what to do. i.e. call the “filterValue” method with the value from the object and replace the original value with the clean one.\n
  • All you really need is to implement a “Annotation” class and a Enforcer, a class that will be able to get an annotation and know what to do. i.e. call the “filterValue” method with the value from the object and replace the original value with the clean one.\n
  • All you really need is to implement a “Annotation” class and a Enforcer, a class that will be able to get an annotation and know what to do. i.e. call the “filterValue” method with the value from the object and replace the original value with the clean one.\n
  • All you really need is to implement a “Annotation” class and a Enforcer, a class that will be able to get an annotation and know what to do. i.e. call the “filterValue” method with the value from the object and replace the original value with the clean one.\n
  • All you really need is to implement a “Annotation” class and a Enforcer, a class that will be able to get an annotation and know what to do. i.e. call the “filterValue” method with the value from the object and replace the original value with the clean one.\n
  • All you really need is to implement a “Annotation” class and a Enforcer, a class that will be able to get an annotation and know what to do. i.e. call the “filterValue” method with the value from the object and replace the original value with the clean one.\n
  • All you really need is to implement a “Annotation” class and a Enforcer, a class that will be able to get an annotation and know what to do. i.e. call the “filterValue” method with the value from the object and replace the original value with the clean one.\n
  • All you really need is to implement a “Annotation” class and a Enforcer, a class that will be able to get an annotation and know what to do. i.e. call the “filterValue” method with the value from the object and replace the original value with the clean one.\n
  • All you really need is to implement a “Annotation” class and a Enforcer, a class that will be able to get an annotation and know what to do. i.e. call the “filterValue” method with the value from the object and replace the original value with the clean one.\n
  • All you really need is to implement a “Annotation” class and a Enforcer, a class that will be able to get an annotation and know what to do. i.e. call the “filterValue” method with the value from the object and replace the original value with the clean one.\n
  • All you really need is to implement a “Annotation” class and a Enforcer, a class that will be able to get an annotation and know what to do. i.e. call the “filterValue” method with the value from the object and replace the original value with the clean one.\n
  • All you really need is to implement a “Annotation” class and a Enforcer, a class that will be able to get an annotation and know what to do. i.e. call the “filterValue” method with the value from the object and replace the original value with the clean one.\n
  • Simple Annotation that needs no parameters (made simple on purpose)\nMention that parameters come in an array but we will explain later\nShow method of “action” in this case just a filter, could be any action or data\n
  • Simple Annotation that needs no parameters (made simple on purpose)\nMention that parameters come in an array but we will explain later\nShow method of “action” in this case just a filter, could be any action or data\n
  • Simple Annotation that needs no parameters (made simple on purpose)\nMention that parameters come in an array but we will explain later\nShow method of “action” in this case just a filter, could be any action or data\n
  • Simple Annotation that needs no parameters (made simple on purpose)\nMention that parameters come in an array but we will explain later\nShow method of “action” in this case just a filter, could be any action or data\n
  • Simple Annotation that needs no parameters (made simple on purpose)\nMention that parameters come in an array but we will explain later\nShow method of “action” in this case just a filter, could be any action or data\n
  • Simple Annotation that needs no parameters (made simple on purpose)\nMention that parameters come in an array but we will explain later\nShow method of “action” in this case just a filter, could be any action or data\n
  • Explain this simple “Enforcer” class\nIt only gets a single annotation from the reader\nIt makes the action described by the annotation happen.\n\n
  • Explain this simple “Enforcer” class\nIt only gets a single annotation from the reader\nIt makes the action described by the annotation happen.\n\n
  • Explain this simple “Enforcer” class\nIt only gets a single annotation from the reader\nIt makes the action described by the annotation happen.\n\n
  • Explain this simple “Enforcer” class\nIt only gets a single annotation from the reader\nIt makes the action described by the annotation happen.\n\n
  • DMS implements a Loader that loads all annotations and filters for “filter rules” since we have multiple classes\nDMS implements a walker that abstracts away reflection->makeAccessible and knows where to fin annotations (method/properties/etc..)\nFilter becomes a simple service that delegates actions.\n
  • DMS implements a Loader that loads all annotations and filters for “filter rules” since we have multiple classes\nDMS implements a walker that abstracts away reflection->makeAccessible and knows where to fin annotations (method/properties/etc..)\nFilter becomes a simple service that delegates actions.\n
  • DMS implements a Loader that loads all annotations and filters for “filter rules” since we have multiple classes\nDMS implements a walker that abstracts away reflection->makeAccessible and knows where to fin annotations (method/properties/etc..)\nFilter becomes a simple service that delegates actions.\n
  • DMS implements a Loader that loads all annotations and filters for “filter rules” since we have multiple classes\nDMS implements a walker that abstracts away reflection->makeAccessible and knows where to fin annotations (method/properties/etc..)\nFilter becomes a simple service that delegates actions.\n
  • DMS implements a Loader that loads all annotations and filters for “filter rules” since we have multiple classes\nDMS implements a walker that abstracts away reflection->makeAccessible and knows where to fin annotations (method/properties/etc..)\nFilter becomes a simple service that delegates actions.\n
  • DMS implements a Loader that loads all annotations and filters for “filter rules” since we have multiple classes\nDMS implements a walker that abstracts away reflection->makeAccessible and knows where to fin annotations (method/properties/etc..)\nFilter becomes a simple service that delegates actions.\n
  • DMS implements a Loader that loads all annotations and filters for “filter rules” since we have multiple classes\nDMS implements a walker that abstracts away reflection->makeAccessible and knows where to fin annotations (method/properties/etc..)\nFilter becomes a simple service that delegates actions.\n
  • DMS implements a Loader that loads all annotations and filters for “filter rules” since we have multiple classes\nDMS implements a walker that abstracts away reflection->makeAccessible and knows where to fin annotations (method/properties/etc..)\nFilter becomes a simple service that delegates actions.\n
  • DMS implements a Loader that loads all annotations and filters for “filter rules” since we have multiple classes\nDMS implements a walker that abstracts away reflection->makeAccessible and knows where to fin annotations (method/properties/etc..)\nFilter becomes a simple service that delegates actions.\n
  • DMS implements a Loader that loads all annotations and filters for “filter rules” since we have multiple classes\nDMS implements a walker that abstracts away reflection->makeAccessible and knows where to fin annotations (method/properties/etc..)\nFilter becomes a simple service that delegates actions.\n
  • DMS implements a Loader that loads all annotations and filters for “filter rules” since we have multiple classes\nDMS implements a walker that abstracts away reflection->makeAccessible and knows where to fin annotations (method/properties/etc..)\nFilter becomes a simple service that delegates actions.\n
  • DMS implements a Loader that loads all annotations and filters for “filter rules” since we have multiple classes\nDMS implements a walker that abstracts away reflection->makeAccessible and knows where to fin annotations (method/properties/etc..)\nFilter becomes a simple service that delegates actions.\n
  • DMS implements a Loader that loads all annotations and filters for “filter rules” since we have multiple classes\nDMS implements a walker that abstracts away reflection->makeAccessible and knows where to fin annotations (method/properties/etc..)\nFilter becomes a simple service that delegates actions.\n
  • DMS implements a Loader that loads all annotations and filters for “filter rules” since we have multiple classes\nDMS implements a walker that abstracts away reflection->makeAccessible and knows where to fin annotations (method/properties/etc..)\nFilter becomes a simple service that delegates actions.\n
  • DMS implements a Loader that loads all annotations and filters for “filter rules” since we have multiple classes\nDMS implements a walker that abstracts away reflection->makeAccessible and knows where to fin annotations (method/properties/etc..)\nFilter becomes a simple service that delegates actions.\n
  • DMS implements a Loader that loads all annotations and filters for “filter rules” since we have multiple classes\nDMS implements a walker that abstracts away reflection->makeAccessible and knows where to fin annotations (method/properties/etc..)\nFilter becomes a simple service that delegates actions.\n
  • DMS implements a Loader that loads all annotations and filters for “filter rules” since we have multiple classes\nDMS implements a walker that abstracts away reflection->makeAccessible and knows where to fin annotations (method/properties/etc..)\nFilter becomes a simple service that delegates actions.\n
  • the key is assumed to be the “defaultProperty”\n
  • the key is assumed to be the “defaultProperty”\n
  • the key is assumed to be the “defaultProperty”\n
  • the key is assumed to be the “defaultProperty”\n
  • the key is assumed to be the “defaultProperty”\n
  • the key is assumed to be the “defaultProperty”\n
  • the key is assumed to be the “defaultProperty”\n
  • the key is assumed to be the “defaultProperty”\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Annotating with Annotations

    1. 1. *
    2. 2.  TrueNorthPHP
    3. 3.  -
    4. 4.  Toronto/2012 Annotating
    5. 5.  with
    6. 6.   Annotations A
    7. 7.  look
    8. 8.  into
    9. 9.  Annotations
    10. 10.  in
    11. 11.  PHP on
    12. 12.  twitter Rafael
    13. 13.  Dohms @rdohms
    14. 14. *
    15. 15.  TrueNorthPHP
    16. 16.  -
    17. 17.  Toronto/2012 Annotating
    18. 18.  with
    19. 19.   Annotations A
    20. 20.  look
    21. 21.  into
    22. 22.  Annotations
    23. 23.  in
    24. 24.  PHP on
    25. 25.  twitter Rafael
    26. 26.  Dohms @rdohms
    27. 27. Rafael Dohms photo credit: Eli White @rdohms Evangelist, Speaker and Contributor.Developer at WEBclusive.Enabler at AmsterdamPHP.
    28. 28. a
    29. 29.  little
    30. 30.  history existing
    31. 31.  uses What? Why? Where? How? ustom
    32. 32.  ann otations Impl ementing
    33. 33.  c DMSFilter based
    34. 34.  on
    35. 35.   show
    36. 36.  me
    37. 37.  the
    38. 38.  code!
    39. 39. http://ecdesignrebels.blogspot.com w h a t? ta tio ns? re
    40. 40.  an noW ha t
    41. 41.  a
    42. 42. -- In English --An annotation is a note that is made while reading any form of text.
    43. 43. something
    44. 44.  that
    45. 45.  describes
    46. 46.  an
    47. 47.  aspect
    48. 48.  of
    49. 49.  the
    50. 50.  subject -- In English --An annotation is a note that is made while reading any form of text.
    51. 51. -- In Code Speak --“An annotation describes behavior of code and affects your application in runtime.” “Annotations do not directly affect program semantics”
    52. 52. -- In Code Speak --“An annotation describes behavior of code and affects your application in runtime.” “Annotations do not directly affect program semantics” just
    53. 53.  like
    54. 54.  your
    55. 55.  notes
    56. 56. In
    57. 57.  2004:
    58. 58.  Metadata
    59. 59.  or
    60. 60.  “General
    61. 61.  purpose
    62. 62.  Annotations”
    63. 63. In
    64. 64.  2004:
    65. 65.  Metadata
    66. 66.  or
    67. 67.  “General
    68. 68.  purpose
    69. 69.  Annotations” available
    70. 70.  at
    71. 71.  Runtime
    72. 72.  using
    73. 73.  Reflection
    74. 74. In
    75. 75.  2004:
    76. 76.  Metadata
    77. 77.  or
    78. 78.  “General
    79. 79.  purpose
    80. 80.  Annotations” @Entity @Table(name = people) class Person implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; @Column(length = 32) private String name; available
    81. 81.  at
    82. 82.  Runtime
    83. 83.  using
    84. 84.  Reflection
    85. 85. In
    86. 86.  2004:
    87. 87.  Metadata
    88. 88.  or
    89. 89.  “General
    90. 90.  purpose
    91. 91.  Annotations” specific
    92. 92.  syntax @Entity @Table(name = people) class Person implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; @Column(length = 32) private String name; available
    93. 93.  at
    94. 94.  Runtime
    95. 95.  using
    96. 96.  Reflection
    97. 97. No
    98. 98.  core
    99. 99.  annotation
    100. 100.  support
    101. 101. Questions?
    102. 102. Questions?I’m
    103. 103.  kidding!
    104. 104. phpDoc~2000
    105. 105. PHP
    106. 106.  5.1 Reflection
    107. 107.  supports
    108. 108.   getDocComments()phpDoc~2000 2005
    109. 109. PHP
    110. 110.  5.1 Reflection
    111. 111.  supports
    112. 112.   getDocComments()phpDoc~2000 2005 First
    113. 113.   Annotation
    114. 114.  Engines
    115. 115.  in
    116. 116.  PHP
    117. 117. PHP
    118. 118.  5.1 Reflection
    119. 119.  supports
    120. 120.   getDocComments()phpDoc~2000 2005 2008 First
    121. 121.   Annotation
    122. 122.  Engines
    123. 123.  in
    124. 124.  PHP
    125. 125. PHP
    126. 126.  5.1 Reflection
    127. 127.  supports
    128. 128.   getDocComments()phpDoc~2000 2005 2008 First
    129. 129.   Doctrine
    130. 130.  2
    131. 131.   Annotation Annotation
    132. 132.  Engine
    133. 133.  Engines
    134. 134.  in
    135. 135.  PHP
    136. 136. PHP
    137. 137.  5.1 Reflection
    138. 138.  supports
    139. 139.   getDocComments() RFC:
    140. 140.  Annotations
    141. 141.   in
    142. 142.  core
    143. 143.  w/
    144. 144.  custom
    145. 145.  phpDoc syntax~2000 2005 2008 2010 First
    146. 146.   Doctrine
    147. 147.  2
    148. 148.   Annotation Annotation
    149. 149.  Engine
    150. 150.  Engines
    151. 151.  in
    152. 152.  PHP
    153. 153. PHP
    154. 154.  5.1 Reflection
    155. 155.  supports
    156. 156.   getDocComments() RFC:
    157. 157.  Annotations
    158. 158.   ED CTustom
    159. 159.   in
    160. 160.  core
    161. 161.  JE/
    162. 162.  c wphpDoc E Rsyntax~2000 2005 2008 2010 First
    163. 163.   Doctrine
    164. 164.  2
    165. 165.   Annotation Annotation
    166. 166.  Engine
    167. 167.  Engines
    168. 168.  in
    169. 169.  PHP
    170. 170. PHP
    171. 171.  5.1 RFC:
    172. 172.  DocBlock
    173. 173.   Reflection
    174. 174.  supports
    175. 175.   Annotations getDocComments() “in
    176. 176.  discussion” RFC:
    177. 177.  Annotations
    178. 178.   ED CTustom
    179. 179.   in
    180. 180.  core
    181. 181.  JE/
    182. 182.  c wphpDoc E Rsyntax~2000 2005 2008 2010 2011 First
    183. 183.   Doctrine
    184. 184.  2
    185. 185.   Annotation Annotation
    186. 186.  Engine
    187. 187.  Engines
    188. 188.  in
    189. 189.  PHP
    190. 190. PHP
    191. 191.  5.1 RFC:
    192. 192.  DocBlock
    193. 193.   Reflection
    194. 194.  supports
    195. 195.   Annotations getDocComments() “in
    196. 196.  discussion” RFC:
    197. 197.  Annotations
    198. 198.   ED CTustom
    199. 199.   in
    200. 200.  core
    201. 201.  JE/
    202. 202.  c wphpDoc E Rsyntax~2000 2005 2008 2010 2011 ? First
    203. 203.   Doctrine
    204. 204.  2
    205. 205.   Annotation Annotation
    206. 206.  Engine
    207. 207.  Engines
    208. 208.  in
    209. 209.  PHP
    210. 210. PHP
    211. 211.  5.1 RFC:
    212. 212.  DocBlock
    213. 213.   Reflection
    214. 214.  supports
    215. 215.   Annotations getDocComments() /** * CaasBundleFundingBundleEntityReward “in
    216. 216.  discussion” * RFC:
    217. 217.  Annotations
    218. 218.   ED * @ORMTable(reward) CTustom
    219. 219.   * @ORMEntity(repositoryClass=CaasBundleFundingBundleEntityRewardRepository) */ class Reward in
    220. 220.  core
    221. 221.  JE/
    222. 222.  c w E {phpDoc /** Rsyntax ? * @var integer $id * * @ORMColumn(name=id, type=integer) * @ORMId * @ORMGeneratedValue(strategy=AUTO)~2000 */ protected $id; 2005 2008 2010 2011 /** * @var string $title * * @ORMColumn(name=title, type=string, length=150, nullable=true) * First
    223. 223.   * @AssertMaxLength(150) */ protected $title; Doctrine
    224. 224.  2
    225. 225.   Annotation Annotation
    226. 226.  Engine
    227. 227.  Engines
    228. 228.  in
    229. 229.  PHP
    230. 230. Note:
    231. 231. Note://
    232. 232.  This
    233. 233.  is
    234. 234.  a
    235. 235.  comment T_COMMENT/*
    236. 236.  This
    237. 237.  is
    238. 238.  a
    239. 239.  multiline
    240. 240.  comment
    241. 241.  */
    242. 242. Note://
    243. 243.  This
    244. 244.  is
    245. 245.  a
    246. 246.  comment T_COMMENT/*
    247. 247.  This
    248. 248.  is
    249. 249.  a
    250. 250.  multiline
    251. 251.  comment
    252. 252.  *//**
    253. 253.  
    254. 254.  *
    255. 255.  This
    256. 256.  is
    257. 257.  a
    258. 258.  doc
    259. 259.  block T_DOC_COMMENT
    260. 260.  */
    261. 261. /** * @deprecated * * @ORMColumn(‘string’, length=255) */public function method()
    262. 262. marker/** * @deprecated * * @ORMColumn(‘string’, length=255) */public function method()
    263. 263. marker parameterized/** * @deprecated * * @ORMColumn(‘string’, length=255) */public function method()
    264. 264. http://ecdesignrebels.blogspot.com Wh y ?
    265. 265.  an no tatio ns? uld
    266. 266.  I
    267. 267.   use /co ns? hy
    268. 268.   sho e
    269. 269.  p rosW t
    270. 270.   are
    271. 271.  th w ha
    272. 272. -
    273. 273. Harder
    274. 274.  to
    275. 275.  debug
    276. 276.  (dynamic
    277. 277.  code)-
    278. 278. Harder
    279. 279.  to
    280. 280.  debug
    281. 281.  (dynamic
    282. 282.  code)- Performance
    283. 283.  hit
    284. 284.  (non-native
    285. 285.  code)
    286. 286. Harder
    287. 287.  to
    288. 288.  debug
    289. 289.  (dynamic
    290. 290.  code)- Performance
    291. 291.  hit
    292. 292.  (non-native
    293. 293.  code) Its
    294. 294.  implemented
    295. 295.  in
    296. 296.  comments
    297. 297.  docblocks!
    298. 298. +
    299. 299. Easier
    300. 300.  to
    301. 301.  inject
    302. 302.  behavior
    303. 303.  without
    304. 304.  extending+
    305. 305. Easier
    306. 306.  to
    307. 307.  inject
    308. 308.  behavior
    309. 309.  without
    310. 310.  extending Doctrine
    311. 311.  1
    312. 312.  vs
    313. 313.  Doctrine
    314. 314.  2+
    315. 315. Easier
    316. 316.  to
    317. 317.  inject
    318. 318.  behavior
    319. 319.  without
    320. 320.  extending Doctrine
    321. 321.  1
    322. 322.  vs
    323. 323.  Doctrine
    324. 324.  2 Contextualizes
    325. 325.  behavior/config
    326. 326.  in
    327. 327.  the
    328. 328.  object+
    329. 329. Easier
    330. 330.  to
    331. 331.  inject
    332. 332.  behavior
    333. 333.  without
    334. 334.  extending Doctrine
    335. 335.  1
    336. 336.  vs
    337. 337.  Doctrine
    338. 338.  2 Contextualizes
    339. 339.  behavior/config
    340. 340.  in
    341. 341.  the
    342. 342.  object+ In
    343. 343.  object
    344. 344.  vs.
    345. 345.  external
    346. 346.  configuration
    347. 347.  file
    348. 348. Easier
    349. 349.  to
    350. 350.  inject
    351. 351.  behavior
    352. 352.  without
    353. 353.  extending Doctrine
    354. 354.  1
    355. 355.  vs
    356. 356.  Doctrine
    357. 357.  2 Contextualizes
    358. 358.  behavior/config
    359. 359.  in
    360. 360.  the
    361. 361.  object+ In
    362. 362.  object
    363. 363.  vs.
    364. 364.  external
    365. 365.  configuration
    366. 366.  file Its
    367. 367.  documented/stored
    368. 368.  by
    369. 369.  phpDocumentor
    370. 370. Easier
    371. 371.  to
    372. 372.  inject
    373. 373.  behavior
    374. 374.  without
    375. 375.  extending Doctrine
    376. 376.  1
    377. 377.  vs
    378. 378.  Doctrine
    379. 379.  2 Contextualizes
    380. 380.  behavior/config
    381. 381.  in
    382. 382.  the
    383. 383.  object+ In
    384. 384.  object
    385. 385.  vs.
    386. 386.  external
    387. 387.  configuration
    388. 388.  file Its
    389. 389.  documented/stored
    390. 390.  by
    391. 391.  phpDocumentor Its
    392. 392.  in
    393. 393.  docblocks,
    394. 394.  so
    395. 395.  its
    396. 396.  parsed
    397. 397. ?phpclass User{ protected $name ...}
    398. 398. ?php -
    399. 399.  persist
    400. 400.  as
    401. 401.  varchar length
    402. 402.  should
    403. 403.  not
    404. 404.  be
    405. 405.  class User{ -
    406. 406.   more
    407. 407.  then
    408. 408.  255 -
    409. 409.  should
    410. 410.  not
    411. 411.  be
    412. 412.  blank -
    413. 413.  only
    414. 414.  letters protected $name ...}
    415. 415. persistence DoctrineTestsORMMappingUser: type: entity table: cms_users?php id: id: -
    416. 416.  persist
    417. 417.  as
    418. 418.  varchar type: integer length
    419. 419.  should
    420. 420.  not
    421. 421.  be
    422. 422.  class User generator:{ -
    423. 423.   strategy: AUTO more
    424. 424.  then
    425. 425.  255 fields: name: -
    426. 426.  should
    427. 427.  not
    428. 428.  be
    429. 429.  blank type: string -
    430. 430.  only
    431. 431.  letters length: 255 protected $name Validation AcmeBlogBundleEntityAuthor: properties: name: ... - NotBlank: ~ - MaxLength: 255 filter AcmeBlogBundleEntityAuthor:} filters: name: - alpha
    432. 432. persistence Validation?phpclass User filter{ /** * @ORMColumn(‘string’, length=255) * @AssertNotBlank() * @AssertMaxLength(255) * @FilterAlpha() */ protected $name ...}
    433. 433. ? http://ecdesignrebels.blogspot.comW h e r e tions
    434. 434.  used?
    435. 435.  ann ota er e
    436. 436.   areWh
    437. 437. class DataTest extends PHPUnit_Framework_TestCase{ /** * @dataProvider provider repetition * * @expectedException InvalidArgumentException * @expectedExceptionMessage Right Message */ public function testAdd($a, $b, $c) expectations { /* Test code */ } public function provider() { return array( array(0, 0, 0), ); }}
    438. 438. /** * @ORMTable(myentity) * @ORMEntity(repositoryClass=MyEntityRepository) */class MyEntity{ /** * @var integer $id * * @ORMColumn(name=id, type=integer) * @ORMId * @ORMGeneratedValue(strategy=AUTO) persistance */ protected $id; /** * @var string $title * * @ORMColumn(name=title, type=string, length=255) association * @AssertMaxLength(255) * @AssertNotBlank() */ protected $title; /** * @var DoctrineCommonCollectionsArrayCollection $users * * @ORMOneToMany(targetEntity=OtherEntity, mappedBy=myEntity, cascade={persist,remove}) */ protected $otherEntities;}
    439. 439. /** * @Route(/myaction/{id}, name=myaction) * @Method(POST) * * @Template(MyBundle:MyController:my.html.twig) * * @param int $id * @return array routing */public function myAction($id){ /* Controller Logic */ templating return array(data = $data);}class MyEntity{ /** * @var string $title * * @ORMColumn(name=title, type=string, length=255) * @AssertMaxLength(255) * @AssertNotBlank() */ protected $title;} Validation
    440. 440. /** Dependency
    441. 441.  Injection * @FLOW3Aspect */class LoggingAspect { /** * @FLOW3Inject * @var ExamplesForumLoggerApplicationLoggerInterface AOP */ protected $applicationLogger; /** * Log a message if a post is deleted * * @param TYPO3FLOW3AOPJoinPointInterface $joinPoint * @FLOW3Before(method(ExamplesForumDomainModelForum-deletePost())) * @return void */ public function logDeletePost(TYPO3FLOW3AOPJoinPointInterface $joinPoint) { $post = $joinPoint-getMethodArgument(post); $this-applicationLogger-log(Removing post . $post-getTitle(), LOG_INFO); }}
    442. 442. http://ecdesignrebels.blogspot.comH o w ? e
    443. 443.   my
    444. 444.  ow n
    445. 445.   rit
    446. 446.  i
    447. 447.  w ns?How
    448. 448.   can tio a nno ta
    449. 449. My
    450. 450.  ProjectAnnotations
    451. 451. Annotation
    452. 452.   Engine My
    453. 453.  ProjectAnnotations
    454. 454. /** * @tag parameters */public function method() Code
    455. 455. /**ReflectionClass-getDocComment() * @tag parameters */ public function method() Code
    456. 456. /** ReflectionClass-getDocComment() * @tag parameters */ public function method() Code/** * @tag parameters */DOCBlock
    457. 457. /** ReflectionClass-getDocComment() * @tag parameters */ public function method() Code/** * @tag parameters */DOCBlock
    458. 458. /** ReflectionClass-getDocComment() * @tag parameters */ public function method() Code/** * @tag parameters */DOCBlock Tag() + parameters Annotation
    459. 459.  Instances
    460. 460. Annotation Engines Doctrine
    461. 461.  Commons ZF2
    462. 462.  Annotations phpDocumentor
    463. 463.  2 Notoj abandoned? addendum php-annotations Stubble
    464. 464. Annotation Engines Notoj 2.3 2.0
    465. 465.  -
    466. 466.  alpha ?Parameterized marker parameterizedvery
    467. 467.  mature maturing new
    468. 468. Annotation Engines Notoj 2.3 2.0
    469. 469.  -
    470. 470.  alpha ?Parameterized marker parameterizedvery
    471. 471.  mature maturing new
    472. 472. How
    473. 473.  it
    474. 474.  Works ?php use DoctrineORMMapping as ORM; use SymfonyComponentValidator Constraints as Assert; /** * @ORMColumn(‘string’) * @AssertNotBlank() */
    475. 475. How
    476. 476.  it
    477. 477.  Works Declare
    478. 478.  which
    479. 479.  Annotations
    480. 480.   you
    481. 481.  will
    482. 482.  use ?php use DoctrineORMMapping as ORM; use SymfonyComponentValidator Constraints as Assert; /** * @ORMColumn(‘string’) * @AssertNotBlank() */
    483. 483. How
    484. 484.  it
    485. 485.  Works Declare
    486. 486.  which
    487. 487.  Annotations
    488. 488.   you
    489. 489.  will
    490. 490.  useAnnotationReader ?php use DoctrineORMMapping as ORM; use SymfonyComponentValidator Constraints as Assert; /** * @ORMColumn(‘string’) * @AssertNotBlank() */
    491. 491. How
    492. 492.  it
    493. 493.  Works Declare
    494. 494.  which
    495. 495.  Annotations
    496. 496.   you
    497. 497.  will
    498. 498.  useAnnotationReader ?php use DoctrineORMMapping as ORM; use SymfonyComponentValidator Constraints as Assert; /** * @ORMColumn(‘string’) * @AssertNotBlank() “metadata” */new ORMColumn(‘string’)new AssertNotBlank()
    499. 499. How
    500. 500.  it
    501. 501.  Works Declare
    502. 502.  which
    503. 503.  Annotations
    504. 504.   you
    505. 505.  will
    506. 506.  useAnnotationReader ?php use DoctrineORMMapping as ORM; use SymfonyComponentValidator Constraints as Assert; /** * @ORMColumn(‘string’) * @AssertNotBlank() “metadata” */new ORMColumn(‘string’)new AssertNotBlank() Walker
    507. 507.  /
    508. 508.  code Cache
    509. 509. DMSFilterhttps://github.com/rdohms/DMS
    510. 510. The
    511. 511.  Gears
    512. 512. The
    513. 513.  Gears YourApp DoctrineCommons
    514. 514. The
    515. 515.  Gears Reader YourApp DoctrineCommons
    516. 516. The
    517. 517.  Gears Parsing Reader YourApp DoctrineCommons
    518. 518. The
    519. 519.  Gears Parsing Filter Reader YourApp DoctrineCommons
    520. 520. The
    521. 521.  Gears “Enforcing” Parsing Filter Reader YourApp DoctrineCommons
    522. 522. The
    523. 523.  Gears “Enforcing” Parsing Filter ReaderAnnotatedObject YourApp DoctrineCommons
    524. 524. The
    525. 525.  Gears “Enforcing” Parsing Filter ReaderAnnotatedObject MyAnnotation YourApp DoctrineCommons
    526. 526. The
    527. 527.  Gears “Enforcing” Parsing Filter ReaderAnnotatedObject filter() MyAnnotation YourApp DoctrineCommons
    528. 528. The
    529. 529.  Gears “Enforcing” Parsing Filter ReaderAnnotatedObject filter() getMethodAnnotation() MyAnnotation YourApp DoctrineCommons
    530. 530. The
    531. 531.  Gears “Enforcing” Parsing Filter ReaderAnnotatedObject filter() getMethodAnnotation() MyAnnotation YourApp DoctrineCommons
    532. 532. The
    533. 533.  Gears “Enforcing” Parsing Filter ReaderAnnotatedObject filter() getMethodAnnotation() filtered value MyAnnotation YourApp DoctrineCommons
    534. 534. Usage:
    535. 535.  @FilterNoDogs()namespace FilterRule;/** * @Annotation */class NoDogs{ public function __construct($options) { /* no options */ } public function filter($value) { return str_replace(dogs, , (string) $value); }}
    536. 536. Usage:
    537. 537.  @FilterNoDogs()namespace FilterRule;/** * @Annotation tell
    538. 538.  doctrine
    539. 539.  this
    540. 540.   */class NoDogs is
    541. 541.  an
    542. 542.  annotation{ public function __construct($options) { /* no options */ } public function filter($value) { return str_replace(dogs, , (string) $value); }}
    543. 543. Usage:
    544. 544.  @FilterNoDogs()namespace FilterRule;/** * @Annotation tell
    545. 545.  doctrine
    546. 546.  this
    547. 547.   */class NoDogs is
    548. 548.  an
    549. 549.  annotation{ public function __construct($options) { /* no options */ } array
    550. 550.  of
    551. 551.  the
    552. 552.  parameters public function filter($value) { return str_replace(dogs, , (string) $value); }}
    553. 553. Usage:
    554. 554.  @FilterNoDogs()namespace FilterRule;/** * @Annotation tell
    555. 555.  doctrine
    556. 556.  this
    557. 557.   */class NoDogs is
    558. 558.  an
    559. 559.  annotation{ public function __construct($options) { /* no options */ } array
    560. 560.  of
    561. 561.  the
    562. 562.  parameters public function filter($value) { return str_replace(dogs, , (string) $value); }} this
    563. 563.  is
    564. 564.  the
    565. 565.  effect
    566. 566.  of
    567. 567.   our
    568. 568.  annotation
    569. 569. namespace Filter;class Filter{ private $reader; public function __construct(DoctrineCommonAnnotationsReader $reader) { $this-reader = $reader; } public function filter($object) { $reflectionObject = new ReflectionObject($object); foreach ($reflectionObject-getProperties() as $reflectionProperty) { $this-filterProperty($object, $reflectionProperty); } } public function filterProperty($object, $reflectionProperty) { // fetch the @NoDog annotation from the annotation reader $annotation = $this-reader-getMethodAnnotation( $reflectionProperty, FilterRuleNoDog); if (null === $annotation) { return; } $reflectionProperty-setAccessible(true); $value = $reflectionProperty-getValue($object); $filteredValue = $annotation-filter($value); $reflectionProperty-setValue( $filteredValue ); }}
    570. 570. namespace Filter;class Filter{ private $reader; public function __construct(DoctrineCommonAnnotationsReader $reader) { $this-reader = $reader; } public function filter($object) { $reflectionObject = new ReflectionObject($object); foreach ($reflectionObject-getProperties() as $reflectionProperty) { $this-filterProperty($object, $reflectionProperty); } } Get
    571. 571.  only
    572. 572.  our
    573. 573.   annotation public function filterProperty($object, $reflectionProperty) { // fetch the @NoDog annotation from the annotation reader $annotation = $this-reader-getMethodAnnotation( $reflectionProperty, FilterRuleNoDog); if (null === $annotation) { return; } $reflectionProperty-setAccessible(true); $value = $reflectionProperty-getValue($object); $filteredValue = $annotation-filter($value); $reflectionProperty-setValue( $filteredValue ); }}
    574. 574. namespace Filter;class Filter{ private $reader; public function __construct(DoctrineCommonAnnotationsReader $reader) { $this-reader = $reader; } public function filter($object) { $reflectionObject = new ReflectionObject($object); foreach ($reflectionObject-getProperties() as $reflectionProperty) { $this-filterProperty($object, $reflectionProperty); } } Get
    575. 575.  only
    576. 576.  our
    577. 577.   annotation public function filterProperty($object, $reflectionProperty) { // fetch the @NoDog annotation from the annotation reader $annotation = $this-reader-getMethodAnnotation( $reflectionProperty, FilterRuleNoDog); if (null === $annotation) { return; } $reflectionProperty-setAccessible(true); $value = $reflectionProperty-getValue($object); Make
    578. 578.  Annotation
    579. 579.   $filteredValue = $annotation-filter($value); $reflectionProperty-setValue( $filteredValue );} } affect
    580. 580.  application
    581. 581. Taking
    582. 582.  it
    583. 583.  up
    584. 584.  a
    585. 585.  notch
    586. 586. Taking
    587. 587.  it
    588. 588.  up
    589. 589.  a
    590. 590.  notch Filter Reader
    591. 591. Taking
    592. 592.  it
    593. 593.  up
    594. 594.  a
    595. 595.  notch Filter Reader Walker Loader
    596. 596. Taking
    597. 597.  it
    598. 598.  up
    599. 599.  a
    600. 600.  notch Filter Parsing Using/Walking Reader Walker Loading Loader
    601. 601. Taking
    602. 602.  it
    603. 603.  up
    604. 604.  a
    605. 605.  notch Filter Parsing Using/Walking Reader Walker Loading Loader Filters
    606. 606.  Annotations
    607. 607. Taking
    608. 608.  it
    609. 609.  up
    610. 610.  a
    611. 611.  notch Filter Parsing Using/Walking Reader Walker Loading Loader navigates
    612. 612.  object,
    613. 613.   Filters
    614. 614.  Annotations reflects
    615. 615.  and
    616. 616.  filters
    617. 617. Taking
    618. 618.  it
    619. 619.  up
    620. 620.  a
    621. 621.  notch Filter Parsing Using/Walking Reader Walker Loading Loader navigates
    622. 622.  object,
    623. 623.   Filters
    624. 624.  Annotations reflects
    625. 625.  and
    626. 626.  filters
    627. 627. Taking
    628. 628.  it
    629. 629.  up
    630. 630.  a
    631. 631.  notch Filter Parsing Using/Walking Reader Walker Loading Loader annotations navigates
    632. 632.  object,
    633. 633.   Filters
    634. 634.  Annotations reflects
    635. 635.  and
    636. 636.  filters
    637. 637. Taking
    638. 638.  it
    639. 639.  up
    640. 640.  a
    641. 641.  notch Filter Parsing Using/Walking Reader Walker Loading Loader annotations metadata navigates
    642. 642.  object,
    643. 643.   Filters
    644. 644.  Annotations reflects
    645. 645.  and
    646. 646.  filters
    647. 647. /** * @MyAnnotation(“name”, nullable=true) */
    648. 648. defaultProperty/** * @MyAnnotation(“name”, nullable=true) */
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×