0
*
 PHPBenelux
 -
 Antwerp/2013Annotations
 in
 PHP        y
 E xist!   T he                                                                             on
 twitter                           Rafael
 Dohms                                                                                                                    ...
Rafael Dohms                                                                                                              ...
 make
 awesome
 crowd-funding
 software!
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 is metadata attached to your     code, that can be read at runtime.”“Annotations do not ...
-- In Code Speak --“An annotation is metadata attached to your     code, that can be read at runtime.”   effects
 are
 only
 observed
 at“Annotations do not directly affect program               semantics”
-- In Code Speak --“An annotation is metadata attached to your     code, that can be read at runtime.”   effects
 are
 only
 observed
 at“Annotations do not directly affect program               semantics”                                                   ...
 like
 your
 notes
Annotations in the wild                          C#
annotations              Annotations in the wild                                         C#                               ...
@Entity                   @Table(name = people)                   class Person implements Serializable {                  ...
@Entity                           @Table(name = people)                           class Person implements Serializable {  ...
@Entity                           @Table(name = people)                           class Person implements Serializable {  ...
 v1.5                  Annotations in the wild public class Customer                                                      ...
@Entity                                                                                           @Table(name = people)   ...
 v1.5                                                                   Annotations in the wild    public class Customer  ...
 first
 release
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
 5.1                 Reflection
 supports
                   getDocComments()phpDoc~2000                                                                         200...
                                    Annotation
 Engines
 in
 PHP
PHP
 5.1                 Reflection
 supports
                   getDocComments()phpDoc~2000                                                                         200...
                                                                                                                          ...
 2
                                    Annotation                                                                            ...
 Engine
 Engines
 in
 PHP
PHP
 5.1                 Reflection
 supports
                   getDocComments()                                                                                       ...
 Annotations
                                                                                                                      in
 core
 w/
 custom
 phpDoc                                                                                                                   ...
                                                                                                                          ...
 2
                                    Annotation                                                                            ...
 Engine
 Engines
 in
 PHP
PHP
 5.1                 Reflection
 supports
                   getDocComments()                                                                                       ...
 Annotations
                             ED                                                                                           ...
                                                                                                                      in
 core
 JE/
 c                                                                                                                        ...
                                                                                                                          ...
 2
                                    Annotation                                                                            ...
 Engine
 Engines
 in
 PHP
PHP
 5.1                                                                                                                      ...
 DocBlock
                  Reflection
Upcoming SlideShare
Loading in...5
×

Annotations in PHP: They Exist

59,652

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
4 Comments
101 Likes
Statistics
Notes
  • Thanks, you have made a small mistake on page 86. The last two links point to phpDocumentor2.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • PHP annotations are awesome! Thanks to them, and in particular Doctrine 2, I quit the PHP world and became a full time Python developer. My only regret, is that I wish PHP annotations had existed before :(
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • there is a 'typo' on slide 52, you should change:
    'but Its code ...'
    for
    'but it's code ...'
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Slide #53.

    It claims docblocks are first class citizens. Could you back that up?

    A first class citizen is a structure, data, whatever that can be passed to a function, assigned to a variable, returned from a function, etc. A docblock enters in that definition?
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
59,652
On Slideshare
0
From Embeds
0
Number of Embeds
15
Actions
Shares
0
Downloads
304
Comments
4
Likes
101
Embeds 0
No embeds

No notes for slide

Transcript of "Annotations in PHP: They Exist"

  1. 1. *
  2. 2.  PHPBenelux
  3. 3.  -
  4. 4.  Antwerp/2013Annotations
  5. 5.  in
  6. 6.  PHP y
  7. 7.  E xist! T he on
  8. 8.  twitter Rafael
  9. 9.  Dohms @rdohms
  10. 10. Rafael Dohms photo credit: Eli White @rdohms Evangelist, Speaker and Contributor.Developer at WEBclusive.Enabler at AmsterdamPHP. we
  11. 11.  make
  12. 12.  awesome
  13. 13.  crowd-funding
  14. 14.  software!
  15. 15. a
  16. 16.  little
  17. 17.  history existing
  18. 18.  uses What? Why? Where? How? ustom
  19. 19.  ann otations Impl ementing
  20. 20.  c DMSFilter based
  21. 21.  on
  22. 22.   show
  23. 23.  me
  24. 24.  the
  25. 25.  code!
  26. 26. http://ecdesignrebels.blogspot.com w h a t? ta tio ns? re
  27. 27.  an noW ha t
  28. 28.  a
  29. 29. -- In English --An annotation is a note that is made while reading any form of text.
  30. 30. something
  31. 31.  that
  32. 32.  describes
  33. 33.  an
  34. 34.  aspect
  35. 35.  of
  36. 36.  the
  37. 37.  subject -- In English --An annotation is a note that is made while reading any form of text.
  38. 38. -- In Code Speak --“An annotation is metadata attached to your code, that can be read at runtime.”“Annotations do not directly affect program semantics”
  39. 39. -- In Code Speak --“An annotation is metadata attached to your code, that can be read at runtime.” effects
  40. 40.  are
  41. 41.  only
  42. 42.  observed
  43. 43.  at“Annotations do not directly affect program semantics”
  44. 44. -- In Code Speak --“An annotation is metadata attached to your code, that can be read at runtime.” effects
  45. 45.  are
  46. 46.  only
  47. 47.  observed
  48. 48.  at“Annotations do not directly affect program semantics” just
  49. 49.  like
  50. 50.  your
  51. 51.  notes
  52. 52. Annotations in the wild C#
  53. 53. annotations Annotations in the wild C# attributes
  54. 54. @Entity @Table(name = people) class Person implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id;annotations Annotations in the wild C# attributes
  55. 55. @Entity @Table(name = people) class Person implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id;annotations Annotations in the wild public class Customer C# { [Required] [StringLength(50)] public string Prename { get; set; } [Column(TypeName = image)] public byte[] Image { get; set; } attributes
  56. 56. @Entity @Table(name = people) class Person implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id;annotations after
  57. 57.  v1.5 Annotations in the wild public class Customer C# { [Required] [StringLength(50)] public string Prename { get; set; } [Column(TypeName = image)] public byte[] Image { get; set; } attributes
  58. 58. @Entity @Table(name = people) class Person implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id;annotations after
  59. 59.  v1.5 Annotations in the wild public class Customer C# { [Required] [StringLength(50)] public string Prename { get; set; } [Column(TypeName = image)] public byte[] Image { get; set; } attributes since
  60. 60.  first
  61. 61.  release
  62. 62. No
  63. 63.  core
  64. 64.  annotation
  65. 65.  support
  66. 66. Questions?
  67. 67. Questions?I’m
  68. 68.  kidding!
  69. 69. phpDoc~2000
  70. 70. PHP
  71. 71.  5.1 Reflection
  72. 72.  supports
  73. 73.   getDocComments()phpDoc~2000 2005
  74. 74. PHP
  75. 75.  5.1 Reflection
  76. 76.  supports
  77. 77.   getDocComments()phpDoc~2000 2005 First
  78. 78.   Annotation
  79. 79.  Engines
  80. 80.  in
  81. 81.  PHP
  82. 82. PHP
  83. 83.  5.1 Reflection
  84. 84.  supports
  85. 85.   getDocComments()phpDoc~2000 2005 2008 First
  86. 86.   Annotation
  87. 87.  Engines
  88. 88.  in
  89. 89.  PHP
  90. 90. PHP
  91. 91.  5.1 Reflection
  92. 92.  supports
  93. 93.   getDocComments()phpDoc~2000 2005 2008 First
  94. 94.   Doctrine
  95. 95.  2
  96. 96.   Annotation Annotation
  97. 97.  Engine
  98. 98.  Engines
  99. 99.  in
  100. 100.  PHP
  101. 101. PHP
  102. 102.  5.1 Reflection
  103. 103.  supports
  104. 104.   getDocComments() RFC:
  105. 105.  Annotations
  106. 106.   in
  107. 107.  core
  108. 108.  w/
  109. 109.  custom
  110. 110.  phpDoc syntax~2000 2005 2008 2010 First
  111. 111.   Doctrine
  112. 112.  2
  113. 113.   Annotation Annotation
  114. 114.  Engine
  115. 115.  Engines
  116. 116.  in
  117. 117.  PHP
  118. 118. PHP
  119. 119.  5.1 Reflection
  120. 120.  supports
  121. 121.   getDocComments() RFC:
  122. 122.  Annotations
  123. 123.   ED CTustom
  124. 124.   in
  125. 125.  core
  126. 126.  JE/
  127. 127.  c wphpDoc E Rsyntax~2000 2005 2008 2010 First
  128. 128.   Doctrine
  129. 129.  2
  130. 130.   Annotation Annotation
  131. 131.  Engine
  132. 132.  Engines
  133. 133.  in
  134. 134.  PHP
  135. 135. PHP
  136. 136.  5.1 RFC:
  137. 137.  DocBlock
  138. 138.   Reflection
  139. 139.  supports
  140. 140.   Annotations getDocComments() “in
  141. 141.  discussion” RFC:
  142. 142.  Annotations
  143. 143.   ED CTustom
  144. 144.   in
  145. 145.  core
  146. 146.  JE/
  147. 147.  c wphpDoc E Rsyntax~2000 2005 2008 2010 2011 First
  148. 148.   Doctrine
  149. 149.  2
  150. 150.   Annotation Annotation
  151. 151.  Engine
  152. 152.  Engines
  153. 153.  in
  154. 154.  PHP
  155. 155. PHP
  156. 156.  5.1 RFC:
  157. 157.  DocBlock
  158. 158.   Reflection
  159. 159.  supports
  160. 160.   Annotations getDocComments() “in
  161. 161.  discussion” RFC:
  162. 162.  Annotations
  163. 163.   ED Tustom
  164. 164.   discussion
  165. 165.   wC in
  166. 166.  core
  167. 167.  JE/
  168. 168.  c sparks
  169. 169.  up
  170. 170.  againphpDoc E Rsyntax~2000 2005 2008 2010 2011 2013 First
  171. 171.   Doctrine
  172. 172.  2
  173. 173.   Annotation Annotation
  174. 174.  Engine
  175. 175.  Engines
  176. 176.  in
  177. 177.  PHP
  178. 178. PHP
  179. 179.  5.1 RFC:
  180. 180.  DocBlock
  181. 181.   Reflection
  182. 182.  supports
  183. 183.   Annotations getDocComments() “in
  184. 184.  discussion” RFC:
  185. 185.  Annotations
  186. 186.   ED Tustom
  187. 187.   discussion
  188. 188.   wC in
  189. 189.  core
  190. 190.  JE/
  191. 191.  c sparks
  192. 192.  up
  193. 193.  againphpDoc E Rsyntax~2000 2005 2008 2010 2011 2013 ? First
  194. 194.   Doctrine
  195. 195.  2
  196. 196.   Annotation Annotation
  197. 197.  Engine
  198. 198.  Engines
  199. 199.  in
  200. 200.  PHP
  201. 201. Current situation in php-internals
  202. 202. annotations
  203. 203. /** * EntityReward * * @ORMTable(reward) * @ORMEntity(repositoryClass=RewardRepository) */ class Reward { /** * @var integer $id * * @ORMColumn(name=id, type=integer) * @ORMId * @ORMGeneratedValue(strategy=AUTO) */annotations protected $id; /** * @var string $title * * @ORMColumn(name=title, type=string, length=150, nullable=true) * * @AssertMaxLength(150) */ protected $title;
  204. 204. re-use
  205. 205.  of
  206. 206.  docblocks /** * EntityReward * * @ORMTable(reward) * @ORMEntity(repositoryClass=RewardRepository) */ class Reward { /** * @var integer $id * * @ORMColumn(name=id, type=integer) * @ORMId * @ORMGeneratedValue(strategy=AUTO) */annotations protected $id; /** * @var string $title * * @ORMColumn(name=title, type=string, length=150, nullable=true) * * @AssertMaxLength(150) */ protected $title;
  207. 207. On docblocks vs. comments
  208. 208. On docblocks vs. comments // this is a comment /* This is a multiline comment */ T_COMMENT
  209. 209. On docblocks vs. comments // this is a comment /* This is a multiline comment */ T_COMMENT /** * this is a docblock */ T_DOC_COMMENT
  210. 210. On docblocks vs. comments ignored
  211. 211.  by
  212. 212.  opcode
  213. 213.  cache // this is a comment /* This is a multiline comment */ T_COMMENT /** * this is a docblock */ T_DOC_COMMENT
  214. 214. On docblocks vs. comments ignored
  215. 215.  by
  216. 216.  opcode
  217. 217.  cache // this is a comment /* This is a multiline comment */ T_COMMENT cached
  218. 218.  by
  219. 219.  opcode
  220. 220.  cache /** * this is a docblock */ T_DOC_COMMENT
  221. 221. 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; }
  222. 222. class Reward{ /** * @var integer $id marker * @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; }
  223. 223. class Reward{ /** * @var integer $id marker * @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; parameterizedpublic class Customer{ [Required] [StringLength(50)] public string Prename { get; set; } [Column(TypeName = image)] public byte[] Image { get; set; }
  224. 224. http://ecdesignrebels.blogspot.comWh y ?
  225. 225.  an no tatio ns? ld
  226. 226.   I
  227. 227.  use hy
  228. 228.  shouWAre
  229. 229.  annotations
  230. 230.  for
  231. 231.  you?
  232. 232. I don’t know.
  233. 233. hate
  234. 234.  annotations
  235. 235. hate
  236. 236.   love
  237. 237.  annotations annotations
  238. 238. hate
  239. 239.   love
  240. 240.  annotations annotations never
  241. 241.  used
  242. 242.  annotations
  243. 243. The downside or why not but
  244. 244.  its
  245. 245.  code,
  246. 246.  in
  247. 247.  comments! docblocksharder
  248. 248. The downside or why not but
  249. 249.  its
  250. 250.  code,
  251. 251.  in
  252. 252.  comments! docblocks harderdocblocks
  253. 253.  are
  254. 254.  first
  255. 255.  class
  256. 256.  citizens.
  257. 257. The downside or why not harderIts
  258. 258.  impossible
  259. 259.  to
  260. 260.  debug/test!
  261. 261. The downside or why not harder Test/debug
  262. 262.  Its
  263. 263.  impossible
  264. 264.   annotation
  265. 265.  to
  266. 266.  debug/test! “executor”
  267. 267. The downside or why not It
  268. 268.  does
  269. 269.  not
  270. 270.   perform!
  271. 271. The downside or why not It
  272. 272.  does
  273. 273.  not
  274. 274.  Caching
  275. 275.  FTW! perform!
  276. 276. Why I love Annotations
  277. 277. Why I love AnnotationsEasier
  278. 278.  to
  279. 279.  inject
  280. 280.  behavior
  281. 281.  without
  282. 282.  extending
  283. 283. Why I love AnnotationsEasier
  284. 284.  to
  285. 285.  inject
  286. 286.  behavior
  287. 287.  without
  288. 288.  extending Doctrine
  289. 289.  1
  290. 290.  vs
  291. 291.  Doctrine
  292. 292.  2
  293. 293. Why I love Annotations Easier
  294. 294.  to
  295. 295.  inject
  296. 296.  behavior
  297. 297.  without
  298. 298.  extending Doctrine
  299. 299.  1
  300. 300.  vs
  301. 301.  Doctrine
  302. 302.  2Contextualizes
  303. 303.  behavior/config
  304. 304.  in
  305. 305.  the
  306. 306.  object
  307. 307. Why I love Annotations Easier
  308. 308.  to
  309. 309.  inject
  310. 310.  behavior
  311. 311.  without
  312. 312.  extending Doctrine
  313. 313.  1
  314. 314.  vs
  315. 315.  Doctrine
  316. 316.  2Contextualizes
  317. 317.  behavior/config
  318. 318.  in
  319. 319.  the
  320. 320.  object In
  321. 321.  object
  322. 322.  vs.
  323. 323.  external
  324. 324.  configuration
  325. 325.  file
  326. 326. Why I love Annotations Easier
  327. 327.  to
  328. 328.  inject
  329. 329.  behavior
  330. 330.  without
  331. 331.  extending Doctrine
  332. 332.  1
  333. 333.  vs
  334. 334.  Doctrine
  335. 335.  2Contextualizes
  336. 336.  behavior/config
  337. 337.  in
  338. 338.  the
  339. 339.  object In
  340. 340.  object
  341. 341.  vs.
  342. 342.  external
  343. 343.  configuration
  344. 344.  file Its
  345. 345.  documented/stored
  346. 346.  by
  347. 347.  phpDocumentor
  348. 348. Why I love Annotations 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.  2Contextualizes
  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 Its
  370. 370.  in
  371. 371.  docblocks,
  372. 372.  so
  373. 373.  its
  374. 374.  parsed
  375. 375. ?phpclass User{ protected $name ...}
  376. 376. ?phpclass User -
  377. 377.  persist
  378. 378.  as
  379. 379.  varchar e
  380. 380.  { -
  381. 381.  length
  382. 382.  should
  383. 383.  not
  384. 384.  b more
  385. 385.  then
  386. 386.  255 -
  387. 387.  should
  388. 388.  not
  389. 389.  be
  390. 390.  blank -
  391. 391.  only
  392. 392.  letters protected $name ...}
  393. 393. ?php persistence -
  394. 394.  persist
  395. 395.  as
  396. 396.  varchar MyProjectUser:class User type: entity e
  397. 397.   -
  398. 398.  length
  399. 399.  should
  400. 400.  not
  401. 401.  b table: users{ fields: more
  402. 402.  then
  403. 403.  255 name: -
  404. 404.  should
  405. 405.  not
  406. 406.  be
  407. 407.  blank type: string length: 255 -
  408. 408.  only
  409. 409.  letters protected $name Validation MyProjectUser: properties: name: - NotBlank: ~ ... - MaxLength: 255 filter MyProjectUser: filters:} name: - alpha
  410. 410. ?php persistence MyProjectUser:class User type: entity table: users{ fields: name: /** type: string * @ORMColumn(‘string’, length=255) length: 255 * @AssertNotBlank() * @AssertMaxLength(255) * @FilterAlpha() */ protected $name Validation MyProjectUser: properties: name: - NotBlank: ~ ... - MaxLength: 255 filter MyProjectUser: filters:} name: - alpha
  411. 411. ?phpclass User{ /** * @ORMColumn(‘string’, length=255) * @AssertNotBlank() * @AssertMaxLength(255) * @FilterAlpha() */ protected $name ...}
  412. 412. ? http://ecdesignrebels.blogspot.comW h e r e tions
  413. 413.  used?
  414. 414.  ann ota er e
  415. 415.   areWh
  416. 416. ? http://ecdesignrebels.blogspot.comW h e r e tions
  417. 417.  used?
  418. 418.  ann ota er e
  419. 419.   areWh
  420. 420. 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), ); }}
  421. 421. /** * @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;}
  422. 422. /** * @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
  423. 423. /** Dependency
  424. 424.  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); }}
  425. 425. http://ecdesignrebels.blogspot.comH o w ? e
  426. 426.   my
  427. 427.  ow n
  428. 428.   rit
  429. 429.  i
  430. 430.  w ns?How
  431. 431.   can tio a nno ta
  432. 432. My
  433. 433.  ProjectAnnotations
  434. 434. My
  435. 435.  Project Annotation
  436. 436.   EngineAnnotations
  437. 437. /** * @tag(parameters) */public function method() Code
  438. 438. /** * @tag(parameters)ReflectionClass-getDocComment() */ public function method() Code
  439. 439. /** * @tag(parameters) ReflectionClass-getDocComment() */ public function method() Code/** * @tag(parameters) */DOCBlock
  440. 440. /** * @tag(parameters) ReflectionClass-getDocComment() */ public function method() Code/** * @tag(parameters) */DOCBlock Tag() + parameters Annotation
  441. 441.  Instances
  442. 442. Annotation EnginesDoctrine
  443. 443.  Commons https://github.com/doctrine/commonphpDocumentor
  444. 444.  2 https://github.com/phpDocumentor/phpDocumentor2php-annotations https://github.com/mindplay-dk/php-annotationsNotoj https://github.com/crodas/Notoj
  445. 445. Annotation EnginesDoctrine
  446. 446.  CommonsphpDocumentor
  447. 447.  2php-annotationsNotoj
  448. 448. Annotation EnginesDoctrine
  449. 449.  Commons 2.3phpDocumentor
  450. 450.  2 2.0php-annotations 1.1Notoj -
  451. 451. Annotation EnginesDoctrine
  452. 452.  Commons 2.3phpDocumentor
  453. 453.  2 2.0php-annotations 1.1Notoj -
  454. 454. Annotation EnginesDoctrine
  455. 455.  Commons 2.3phpDocumentor
  456. 456.  2 2.0php-annotations 1.1Notoj -
  457. 457. Annotation EnginesDoctrine
  458. 458.  Commons 2.3 full
  459. 459.  supportphpDocumentor
  460. 460.  2 2.0 only
  461. 461.  string
  462. 462.  php-annotations 1.1 full
  463. 463.  supportNotoj - full
  464. 464.  support
  465. 465. Annotation EnginesDoctrine
  466. 466.  Commons 2.3 full
  467. 467.  supportphpDocumentor
  468. 468.  2 2.0 only
  469. 469.  string
  470. 470.  php-annotations 1.1 full
  471. 471.  supportNotoj - full
  472. 472.  support
  473. 473. Annotation EnginesDoctrine
  474. 474.  Commons 2.3 full
  475. 475.  supportphpDocumentor
  476. 476.  2 2.0 only
  477. 477.  string
  478. 478.  php-annotations 1.1 full
  479. 479.  supportNotoj - full
  480. 480.  support
  481. 481. Annotation EnginesDoctrine
  482. 482.  Commons 2.3 full
  483. 483.  supportphpDocumentor
  484. 484.  2 2.0 only
  485. 485.  string
  486. 486.  php-annotations 1.1 full
  487. 487.  supportNotoj - full
  488. 488.  support
  489. 489. ?php use DoctrineORMMapping as ORM; use SymfonyComponentValidator Constraints as Assert;/** * @ORMColumn(‘string’) * @AssertNotBlank() */ How
  490. 490.  it
  491. 491.  Works
  492. 492. Declare
  493. 493.  which
  494. 494.  Annotations
  495. 495.  ?php you
  496. 496.  will
  497. 497.  use use DoctrineORMMapping as ORM; use SymfonyComponentValidator Constraints as Assert;/** * @ORMColumn(‘string’) * @AssertNotBlank() */ How
  498. 498.  it
  499. 499.  Works
  500. 500. AnnotationReader Declare
  501. 501.  which
  502. 502.  Annotations
  503. 503.   ?php you
  504. 504.  will
  505. 505.  use use DoctrineORMMapping as ORM; use SymfonyComponentValidator Constraints as Assert; /** * @ORMColumn(‘string’) * @AssertNotBlank() */ How
  506. 506.  it
  507. 507.  Works
  508. 508. AnnotationReader Declare
  509. 509.  which
  510. 510.  Annotations
  511. 511.   ?php you
  512. 512.  will
  513. 513.  use use DoctrineORMMapping as ORM; use SymfonyComponentValidator Constraints as Assert; /** * @ORMColumn(‘string’) * @AssertNotBlank() “metadata” */new ORMColumn(‘string’)new AssertNotBlank() How
  514. 514.  it
  515. 515.  Works
  516. 516. AnnotationReader Declare
  517. 517.  which
  518. 518.  Annotations
  519. 519.   ?php you
  520. 520.  will
  521. 521.  use use DoctrineORMMapping as ORM; use SymfonyComponentValidator Constraints as Assert; /** * @ORMColumn(‘string’) * @AssertNotBlank() “metadata” */new ORMColumn(‘string’)new AssertNotBlank() Walker
  522. 522.  /
  523. 523.  code Cache How
  524. 524.  it
  525. 525.  Works
  526. 526. Input Filtering DMSFilter: https://github.com/rdohms/DMS
  527. 527. Input Filtering With
  528. 528.  Annotation
  529. 529.  Support! DMSFilter: https://github.com/rdohms/DMS
  530. 530. Ingredients:-
  531. 531.  Filter
  532. 532.  Rules the
  533. 533.  annotation
  534. 534.  /
  535. 535.  metadata,
  536. 536.  configuration-
  537. 537.  Filter
  538. 538.  Executioners applies
  539. 539.  the
  540. 540.  rules-
  541. 541.  Filter
  542. 542.  Service the
  543. 543.  middle-man-
  544. 544.  Annotation
  545. 545.  Engine gets
  546. 546.  the
  547. 547.  rules
  548. 548.  out
  549. 549.  of
  550. 550.  the
  551. 551.  docblocks-
  552. 552.  Annotated
  553. 553.  Objects defines
  554. 554.  the
  555. 555.  rules
  556. 556. annotated
  557. 557.  object “Configured”
  558. 558.  Rules@FilterStripTags(‘bi’) new RulesStripTags(‘bi’); pHello
  559. 559.  bWorld/b/p Filter
  560. 560.  Service Annotation
  561. 561.  Engine Filtered
  562. 562.  values Filter
  563. 563.  Enforcer Hello
  564. 564.  bWorld/b $executioner = new FilterStripTags(); $executioner-filter($metadata, $value);
  565. 565. The “rule”
  566. 566. ?php Usage:
  567. 567.  namespace DMSFilterRules; use DMSFilterRules as Filter;/** @FilterStripTags(‘bi’) * StripTags Rule * * @Annotation */class StripTags extends Rule{ /** * String of allowed tags. Ex: bia * * @var string */ public $allowed = null; /** * {@inheritDoc} */ public function getDefaultOption() { return allowed; }}
  568. 568. ?php Usage:
  569. 569.  namespace DMSFilterRules; use DMSFilterRules as Filter;/** @FilterStripTags(‘bi’) * StripTags Rule * * @Annotation */class StripTags extends Rule{ /** * String of allowed tags. Ex: bia * * @var string tell
  570. 570.  doctrine
  571. 571.  this
  572. 572.   */ public $allowed = null; is
  573. 573.  an
  574. 574.  annotation /** * {@inheritDoc} */ public function getDefaultOption() { return allowed; }}
  575. 575. ?php Usage:
  576. 576.  namespace DMSFilterRules; use DMSFilterRules as Filter;/** @FilterStripTags(‘bi’) * StripTags Rule * * @Annotation */class StripTags extends Rule{ /** * String of allowed tags. Ex: bia * * @var string tell
  577. 577.  doctrine
  578. 578.  this
  579. 579.   */ public $allowed = null; is
  580. 580.  an
  581. 581.  annotation /** * {@inheritDoc} */ public function getDefaultOption() { return allowed; }} DMSFilterRulesRule: public function __construct($options = null)
  582. 582. /** * @MyAnnotation(“name”, nullable=true) */
  583. 583. defaultProperty/** * @MyAnnotation(“name”, nullable=true) */
  584. 584. defaultProperty/** * @MyAnnotation(“name”, nullable=true) */new MyAnnotation($options);
  585. 585. defaultProperty/** * @MyAnnotation(“name”, nullable=true) */ array:
  586. 586.  key
  587. 587.  =
  588. 588.  value or string:
  589. 589.  valuenew MyAnnotation($options);
  590. 590. defaultProperty/** * @MyAnnotation(“name”, nullable=true) */ array:
  591. 591.  key
  592. 592.  =
  593. 593.  value or string:
  594. 594.  valuenew MyAnnotation($options); or
  595. 595. defaultProperty/** * @MyAnnotation(“name”, nullable=true) */ array:
  596. 596.  key
  597. 597.  =
  598. 598.  value or string:
  599. 599.  valuenew MyAnnotation($options); or$a = new MyAnnotation();$a-nullable = true;$a-{$a-getDefaultProperty()} = “name”;
  600. 600. The “enforcer”
  601. 601. ?phpnamespace DMSFilterFilters;use DMSFilterRulesRule;/** * StripTags Rule * * @package DMS * @subpackage Filter * * @Annotation */class StripTags extends BaseFilter{ /** * {@inheritDoc} * * @param DMSFilterRulesStripTags $filter * @param mixed $filter */ public function apply( Rule $filter, $value) { return strip_tags($value, $filter-allowed); }}
  602. 602. ?phpnamespace DMSFilterFilters;use DMSFilterRulesRule;/** * StripTags Rule * * @package DMS * @subpackage Filter * * @Annotation */class StripTags extends BaseFilter{ /** * {@inheritDoc} * * @param DMSFilterRulesStripTags $filter * @param mixed $filter */ public function apply( Rule $filter, $value) { Does
  603. 603.  the
  604. 604.  filtering return strip_tags($value, $filter-allowed); }}
  605. 605. ?phpnamespace DMSFilterFilters;use DMSFilterRulesRule;/** * StripTags Rule * * @package DMS * @subpackage Filter Rule
  606. 606.  has
  607. 607.  the
  608. 608.   * * @Annotation configuration. */class StripTags extends BaseFilter{ Ex:
  609. 609.  allowed
  610. 610.  tags /** * {@inheritDoc} * * @param DMSFilterRulesStripTags $filter * @param mixed $filter */ public function apply( Rule $filter, $value) { Does
  611. 611.  the
  612. 612.  filtering return strip_tags($value, $filter-allowed); }}
  613. 613. The Filter Service
  614. 614. The
  615. 615.  Life
  616. 616.  of
  617. 617.  a
  618. 618.  Filter
  619. 619.  Service
  620. 620. The
  621. 621.  Life
  622. 622.  of
  623. 623.  a
  624. 624.  Filter
  625. 625.  Service09:00
  626. 626.  -
  627. 627.  DIC
  628. 628.  wake-up
  629. 629.  call new FilterService($reader);
  630. 630. The
  631. 631.  Life
  632. 632.  of
  633. 633.  a
  634. 634.  Filter
  635. 635.  Service09:00
  636. 636.  -
  637. 637.  DIC
  638. 638.  wake-up
  639. 639.  call new FilterService($reader);09:05
  640. 640.  -
  641. 641.  Reply
  642. 642.  to
  643. 643.  emergency
  644. 644.  filter
  645. 645.  call $service-filter($object);
  646. 646. The
  647. 647.  Life
  648. 648.  of
  649. 649.  a
  650. 650.  Filter
  651. 651.  Service09:00
  652. 652.  -
  653. 653.  DIC
  654. 654.  wake-up
  655. 655.  call new FilterService($reader);09:05
  656. 656.  -
  657. 657.  Reply
  658. 658.  to
  659. 659.  emergency
  660. 660.  filter
  661. 661.  call $service-filter($object);09:06
  662. 662.  -
  663. 663.  Get
  664. 664.  Annotations
  665. 665.  for
  666. 666.  properties $reader-getPropertyAnnotations($p); $a = array(StripTags(), Alpha());
  667. 667. The
  668. 668.  Life
  669. 669.  of
  670. 670.  a
  671. 671.  Filter
  672. 672.  Service09:00
  673. 673.  -
  674. 674.  DIC
  675. 675.  wake-up
  676. 676.  call new FilterService($reader);09:05
  677. 677.  -
  678. 678.  Reply
  679. 679.  to
  680. 680.  emergency
  681. 681.  filter
  682. 682.  call $service-filter($object);09:06
  683. 683.  -
  684. 684.  Get
  685. 685.  Annotations
  686. 686.  for
  687. 687.  properties $reader-getPropertyAnnotations($p); $a = array(StripTags(), Alpha());09:07
  688. 688.  -
  689. 689.  Track
  690. 690.  down
  691. 691.  the
  1. A particular slide catching your eye?

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

×