Annotations in PHP, They Exist

Download Annotations in PHP, They Exist

Post on 15-Jan-2015

2.720 views

Category:

Technology

1 download

Embed Size (px)

DESCRIPTION

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.

TRANSCRIPT

<ul><li> 1. Annotations </li></ul> <p> 2. in 3. PHPRafael 4. Dohms@rdohmsThey 5. Exist!on 6. twitter 7. Im a Brazilian, living in Amsterdamwhich means Im probably crazy,and I speak with my hands 8. Im a developer and speaker for ever.ok its something like 14 years 9. Im a serial User Group creatorI cant help it 10. I have absolutely no solid Laravel experience 11. I have absolutely no solid Laravel experienceIm sorry. 12. I have absolutely no solid Laravel experienceIm sorry. 13. I have absolutely no solid Laravel experienceIm sorry.Dont throw tomatoesphoto by araswami 14. I have absolutely no solid Laravel experienceIm sorry.Dont throw tomatoesIm allergic.photo by araswami 15. existing 16. usesWhat? Why? Where?How?a 17. little 18. historyImplementing 19. custom 20. annotationsbased 21. on 22. DMSFiltershow 23. me 24. the 25. code! 26. what?What 27. are 28. annotations?http://ecdesignrebels.blogspot.com 29. -- In English --"An annotation is a note that is made whilereading any form of text." 30. something 31. that 32. describes 33. an 34. aspect 35. of 36. the 37. subject-- In English --"An annotation is a note that is made whilereading any form of text." 38. -- In Code Speak --An annotation is metadata attached to yourcode, that can be read at runtime.Annotations do not directly affect programsemantics 39. -- In Code Speak --An annotation is metadata attached to yourcode, that can be read at runtime.effects 40. are 41. only 42. observed 43. atAnnotations do not directly affect programsemantics 44. -- In Code Speak --An annotation is metadata attached to yourcode, that can be read at runtime.effects 45. are 46. only 47. observed 48. atAnnotations do not directly affect programsemanticsjust 49. like 50. your 51. notes 52. Annotations in the wildC# 53. Annotations in the wildannotationsC#attributes 54. Annotations in the wildannotationsC#attributes@Entity!@Table(name = "people")!class Person implements Serializable {!@Id !@GeneratedValue(strategy = GenerationType.AUTO) !private Integer id; 55. Annotations in the wildannotationsC#attributes@Entity!@Table(name = "people")!class Person implements Serializable {!@Id !@GeneratedValue(strategy = GenerationType.AUTO) !private Integer id;public class Customer!{![Required]![StringLength(50)]!public string Prename { get; set; }!![Column(TypeName = "image")]!public byte[] Image { get; set; } 56. Annotations in the wildannotationsafter 57. v1.5C#attributes@Entity!@Table(name = "people")!class Person implements Serializable {!@Id !@GeneratedValue(strategy = GenerationType.AUTO) !private Integer id;public class Customer!{![Required]![StringLength(50)]!public string Prename { get; set; }!![Column(TypeName = "image")]!public byte[] Image { get; set; } 58. Annotations in the wildannotationsafter 59. v1.5C#attributessince 60. first 61. release@Entity!@Table(name = "people")!class Person implements Serializable {!@Id !@GeneratedValue(strategy = GenerationType.AUTO) !private Integer id;public class Customer!{![Required]![StringLength(50)]!public string Prename { get; set; }!![Column(TypeName = "image")]!public byte[] Image { get; set; } 62. No 63. core 64. 65. annotation 66. support 67. Questions? 68. Questions?Im 69. kidding! 70. phpDoc~2000 71. phpDocPHP 72. 5.1Reflection 73. supports 74. getDocComments()~2000 2005 75. Reflection 76. supports 77. getDocComments()phpDocPHP 78. 5.1~2000 2005First 79. Annotation 80. 81. Engines 82. in 83. PHP 84. Reflection 85. supports 86. getDocComments()phpDocPHP 87. 5.1~2000 2005 2008First 88. Annotation 89. 90. Engines 91. in 92. PHP 93. Reflection 94. supports 95. getDocComments()phpDocPHP 96. 5.1~2000 2005 2008First 97. Annotation 98. 99. Engines 100. in 101. PHPDoctrine 102. 2 103. Annotation 104. Engine 105. Reflection 106. supports 107. getDocComments()phpDocPHP 108. 5.1RFC: 109. Annotations 110. in 111. core 112. w/ 113. custom 114. ~2000 2005 2008First 115. Annotation 116. 117. Engines 118. in 119. PHPsyntax2010Doctrine 120. 2 121. Annotation 122. Engine 123. Reflection 124. supports 125. getDocComments()phpDocPHP 126. 5.1syntax REJECTEDRFC: 127. Annotations 128. in 129. core 130. w/ 131. custom 132. ~2000 2005 2008First 133. Annotation 134. 135. Engines 136. in 137. PHP2010Doctrine 138. 2 139. Annotation 140. Engine 141. Reflection 142. supports 143. getDocComments()phpDocPHP 144. 5.1RFC: 145. DocBlock 146. Annotations 147. in 148. discussionREJECTEDRFC: 149. Annotations 150. in 151. core 152. w/ 153. custom 154. ~2000 2005 2008First 155. Annotation 156. 157. Engines 158. in 159. PHPsyntax2010Doctrine 160. 2 161. 2011Annotation 162. Engine 163. Reflection 164. supports 165. getDocComments()phpDocPHP 166. 5.1RFC: 167. DocBlock 168. Annotations 169. in 170. discussionREJECTEDRFC: 171. Annotations 172. in 173. core 174. w/ 175. custom 176. ~2000 2005 2008First 177. Annotation 178. 179. Engines 180. in 181. PHPsyntax2010Doctrine 182. 2 183. 2011Annotation 184. Enginediscussion 185. sparks 186. up 187. again2013 188. Reflection 189. supports 190. getDocComments()phpDocPHP 191. 5.1RFC: 192. DocBlock 193. Annotations 194. in 195. discussionREJECTEDRFC: 196. Annotations 197. in 198. core 199. w/ 200. custom 201. ~2000 2005 2008First 202. Annotation 203. 204. Engines 205. in 206. PHPsyntax2010Doctrine 207. 2 208. 2011Annotation 209. Enginediscussion 210. sparks 211. up 212. again? 2013 213. Current situation in php-internals 214. Current situation in php-internals 215. annotations 216. annotations/** !* EntityReward !* !* @ORMTable("reward") !* @ORMEntity(repositoryClass="RewardRepository") !*/ !class Reward !{ !/** !* @var integer $id !* !* @ORMColumn(name="id", type="integer") !* @ORMId !* @ORMGeneratedValue(strategy="AUTO") !*/ !protected $id; !!/** !* @var string $title !* !* @ORMColumn(name="title", type="string", length=150, nullable=true) !* !* @AssertMaxLength(150) !*/ !protected $title; 217. annotationsre-use 218. of 219. docblocks/** !* EntityReward !* !* @ORMTable("reward") !* @ORMEntity(repositoryClass="RewardRepository") !*/ !class Reward !{ !/** !* @var integer $id !* !* @ORMColumn(name="id", type="integer") !* @ORMId !* @ORMGeneratedValue(strategy="AUTO") !*/ !protected $id; !!/** !* @var string $title !* !* @ORMColumn(name="title", type="string", length=150, nullable=true) !* !* @AssertMaxLength(150) !*/ !protected $title; 220. On docblocks vs. comments 221. On docblocks vs. comments// this is a comment/* This is a multiline comment */T_COMMENT 222. On docblocks vs. comments// this is a comment/* This is a multiline comment */T_COMMENT/** !* this is a docblock!*/T_DOC_COMMENT 223. On docblocks vs. commentsignored 224. by 225. opcode 226. cache// this is a comment/* This is a multiline comment */T_COMMENT/** !* this is a docblock!*/T_DOC_COMMENT 227. On docblocks vs. commentsignored 228. by 229. opcode 230. cache// this is a comment/* This is a multiline comment */T_COMMENTcached 231. by 232. opcode 233. cache/** !* this is a docblock!*/T_DOC_COMMENT 234. class Reward !{ !/** !* @var integer $id !* @deprecated!* @ORMColumn(name="id", type="integer") !* @ORMId !*/ !protected $id;@Entity!@Table(name = "people")!class Person implements Serializable {!@Id !@GeneratedValue(strategy = GenerationType.AUTO) !private Integer id;public class Customer!{![Required]![StringLength(50)]!public string Prename { get; set; }!![Column(TypeName = "image")]!public byte[] Image { get; set; } 235. class Reward !{ !/** !* @var integer $id !* @deprecated!* @ORMColumn(name="id", type="integer") !* @ORMId !*/ !protected $id;@Entity!@Table(name = "people")!class Person implements Serializable {!@Id !@GeneratedValue(strategy = GenerationType.AUTO) !private Integer id;public class Customer!{![Required]![StringLength(50)]!public string Prename { get; set; }!![Column(TypeName = "image")]!public byte[] Image { get; set; }marker 236. class Reward !{ !/** !* @var integer $id !* @deprecated!* @ORMColumn(name="id", type="integer") !* @ORMId !*/ !protected $id;@Entity!@Table(name = "people")!class Person implements Serializable {!@Id !@GeneratedValue(strategy = GenerationType.AUTO) !private Integer id;public class Customer!{![Required]![StringLength(50)]!public string Prename { get; set; }!![Column(TypeName = "image")]!public byte[] Image { get; set; }markerparameterized 237. Why?Why 238. should 239. I 240. use 241. annotations?http://ecdesignrebels.blogspot.comAre 242. annotations 243. for 244. you? 245. I dont know. 246. hate 247. annotations 248. hate 249. annotationslove 250. annotations 251. hate 252. annotationslove 253. annotationsnever 254. used 255. annotations 256. Lets have an argumentphoto by Adam Arroyo 257. photo by Adam Arroyo 258. its code and its in mycomment blocksphoto by Adam Arroyo 259. its code and its in mycomment blocksthey are docblocksphoto by Adam Arroyo 260. its code and its in mycomment blocksthey are docblocksdocblocks are first-classcitizensphoto by Adam Arroyo 261. photo by Adam Arroyo 262. Annotations and comments are like water and oil,just because they are in the same container, doesnot mean they mix!- @rosstuckphoto by Adam Arroyo 263. photo by Adam Arroyo 264. its impossible to testor debugphoto by Adam Arroyo 265. its impossible to testor debugannotations aretags and configphoto by Adam Arroyo 266. its impossible to testor debugannotations aretags and configdont test theannotation, test theobject that uses itphoto by Adam Arroyo 267. photo by Adam Arroyo 268. all that parsing, itcant perform!photo by Adam Arroyo 269. all that parsing, itcant perform!caching!photo by Adam Arroyo 270. I Annotations 271. I AnnotationsContextualizes 272. behavior/config 273. in 274. the 275. object 276. I AnnotationsContextualizes 277. behavior/config 278. in 279. the 280. objectIn 281. object 282. vs. 283. external 284. configuration 285. file 286. I AnnotationsContextualizes 287. behavior/config 288. in 289. the 290. objectIn 291. object 292. vs. 293. external 294. configuration 295. fileIts 296. documented/stored 297. by 298. phpDocumentor 299. I AnnotationsContextualizes 300. behavior/config 301. in 302. the 303. objectIn 304. object 305. vs. 306. external 307. configuration 308. fileIts 309. documented/stored 310. by 311. phpDocumentorIts 312. in 313. docblocks, 314. so 315. its 316. parsed 317.</p>