0
*
 Dutch
 PHP
 Conference
 2012
 -
 UnCon                                      Annotating
 with
                                         Annotations                                                   A
 look
 into
 Annotations
 in
 PHP                                                                                                                      ...
 twitter                              Rafael
 Dohms                                                                                                                    ...
*
 Forum
 PHP
 Paris
 2012Annotating
 with
   Annotations   A
 look
 into
 Annotations
 in
 PHP                                                                                                                      ...
 twitter                          Rafael
 Dohms                                                                                                                    ...
Rafael Dohms                           photo credit: Eli White        @rdohms Evangelist, Speaker and      Contributor. Po...
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.” “Annotations do...
-- In Code Speak --“An annotation describes behavior of code and     affects your application in runtime.” “Annotations do...
 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
Upcoming SlideShare
Loading in...5
×

Annotating with Annotations - DPC UnCon

2,167

Published on

What exactly are annotations? How can they change the way you code and make life simpler? Annotations allow you to implement new functionality into code using "notes" this allows you to easily maintain your own architecture but benefit from external tools. Let's look at how annotations are used today in PHP and how we can develop our own solutions based on the existing libraries.

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

No Downloads
Views
Total Views
2,167
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
20
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Annotating with Annotations - DPC UnCon"

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

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

×