*
 PHPBenelux
 -
 June
 MeetingAnnotating
 with
   Annotations   A
 look
 into
 Annotations
 in
 PHP                                                                                                                      ...
 twitter                                 Rafael
 Dohms                                                                                                                    ...
*
 PHPBenelux
 -
 June
 MeetingAnnotating
 with
   Annotations   A
 look
 into
 Annotations
 in
 PHP                                                                                                                      ...
 twitter                                 Rafael
 Dohms                                                                                                                    ...
Rafael Dohms                           photo credit: Eli White        @rdohms Evangelist, Speaker and      Contributor.Dev...
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
 supports
                   getDocComments()phpDoc~2000                                                                         200...
                                    Annotation
 Engines
 in
Upcoming SlideShare
Loading in...5
×

Annotating with Annotations - PHPBenelux June/2012

1,874

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, Education
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,874
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
28
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Annotating with Annotations - PHPBenelux June/2012

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

×