*
 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
 supports
                   getDocComments()phpDoc~2000                                                                         200...
                                    Annotation
 Engines
 in
 PHP
PHP
 5.1                 Reflection
 supports
                   getDocComments()phpDoc~2000                                                                         200...
                                    Annotation
 Engines
 in
 PHP
PHP
Upcoming SlideShare
Loading in...5
×

Annotating with Annotations - ForumPHP 2012

23,907

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
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
23,907
On Slideshare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
27
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Annotating with Annotations - ForumPHP 2012

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

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

×