*
 ConFoo
 -
 Montreal/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 - ConFoo 2013

6,493

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
2 Comments
13 Likes
Statistics
Notes
No Downloads
Views
Total Views
6,493
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
38
Comments
2
Likes
13
Embeds 0
No embeds

No notes for slide

Annotations in PHP - ConFoo 2013

  1. 1. *
  2. 2.  ConFoo
  3. 3.  -
  4. 4.  Montreal/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. Current situation in php-internals
  203. 203. annotations
  204. 204. /** * 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;
  205. 205. re-use
  206. 206.  of
  207. 207.  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;
  208. 208. On docblocks vs. comments
  209. 209. On docblocks vs. comments // this is a comment /* This is a multiline comment */ T_COMMENT
  210. 210. On docblocks vs. comments // this is a comment /* This is a multiline comment */ T_COMMENT /** * this is a docblock */ T_DOC_COMMENT
  211. 211. On docblocks vs. comments ignored
  212. 212.  by
  213. 213.  opcode
  214. 214.  cache // this is a comment /* This is a multiline comment */ T_COMMENT /** * this is a docblock */ T_DOC_COMMENT
  215. 215. On docblocks vs. comments ignored
  216. 216.  by
  217. 217.  opcode
  218. 218.  cache // this is a comment /* This is a multiline comment */ T_COMMENT cached
  219. 219.  by
  220. 220.  opcode
  221. 221.  cache /** * this is a docblock */ T_DOC_COMMENT
  222. 222. 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; }
  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;public class Customer{ [Required] [StringLength(50)] public string Prename { get; set; } [Column(TypeName = image)] public byte[] Image { get; set; }
  224. 224. 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; }
  225. 225. http://ecdesignrebels.blogspot.comWh y ?
  226. 226.  an no tatio ns? ld
  227. 227.   I
  228. 228.  use hy
  229. 229.  shouWAre
  230. 230.  annotations
  231. 231.  for
  232. 232.  you?
  233. 233. I don’t know.
  234. 234. hate
  235. 235.  annotations
  236. 236. hate
  237. 237.   love
  238. 238.  annotations annotations
  239. 239. hate
  240. 240.   love
  241. 241.  annotations annotations never
  242. 242.  used
  243. 243.  annotations
  244. 244. The downside or why not but
  245. 245.  its
  246. 246.  code,
  247. 247.  in
  248. 248.  comments! docblocksharder
  249. 249. The downside or why not but
  250. 250.  its
  251. 251.  code,
  252. 252.  in
  253. 253.  comments! docblocks harderdocblocks
  254. 254.  are
  255. 255.  first
  256. 256.  class
  257. 257.  citizens.
  258. 258. The downside or why not harderIts
  259. 259.  impossible
  260. 260.  to
  261. 261.  debug/test!
  262. 262. The downside or why not harder Test/debug
  263. 263.  Its
  264. 264.  impossible
  265. 265.   annotation
  266. 266.  to
  267. 267.  debug/test! “executor”
  268. 268. The downside or why not It
  269. 269.  does
  270. 270.  not
  271. 271.   perform!
  272. 272. The downside or why not It
  273. 273.  does
  274. 274.  not
  275. 275.  Caching
  276. 276.  FTW! perform!
  277. 277. Why I love Annotations
  278. 278. Why I love AnnotationsEasier
  279. 279.  to
  280. 280.  inject
  281. 281.  behavior
  282. 282.  without
  283. 283.  extending
  284. 284. Why I love AnnotationsEasier
  285. 285.  to
  286. 286.  inject
  287. 287.  behavior
  288. 288.  without
  289. 289.  extending Doctrine
  290. 290.  1
  291. 291.  vs
  292. 292.  Doctrine
  293. 293.  2
  294. 294. Why I love Annotations Easier
  295. 295.  to
  296. 296.  inject
  297. 297.  behavior
  298. 298.  without
  299. 299.  extending Doctrine
  300. 300.  1
  301. 301.  vs
  302. 302.  Doctrine
  303. 303.  2Contextualizes
  304. 304.  behavior/config
  305. 305.  in
  306. 306.  the
  307. 307.  object
  308. 308. Why I love Annotations Easier
  309. 309.  to
  310. 310.  inject
  311. 311.  behavior
  312. 312.  without
  313. 313.  extending Doctrine
  314. 314.  1
  315. 315.  vs
  316. 316.  Doctrine
  317. 317.  2Contextualizes
  318. 318.  behavior/config
  319. 319.  in
  320. 320.  the
  321. 321.  object In
  322. 322.  object
  323. 323.  vs.
  324. 324.  external
  325. 325.  configuration
  326. 326.  file
  327. 327. Why I love Annotations Easier
  328. 328.  to
  329. 329.  inject
  330. 330.  behavior
  331. 331.  without
  332. 332.  extending Doctrine
  333. 333.  1
  334. 334.  vs
  335. 335.  Doctrine
  336. 336.  2Contextualizes
  337. 337.  behavior/config
  338. 338.  in
  339. 339.  the
  340. 340.  object In
  341. 341.  object
  342. 342.  vs.
  343. 343.  external
  344. 344.  configuration
  345. 345.  file Its
  346. 346.  documented/stored
  347. 347.  by
  348. 348.  phpDocumentor
  349. 349. Why I love Annotations Easier
  350. 350.  to
  351. 351.  inject
  352. 352.  behavior
  353. 353.  without
  354. 354.  extending Doctrine
  355. 355.  1
  356. 356.  vs
  357. 357.  Doctrine
  358. 358.  2Contextualizes
  359. 359.  behavior/config
  360. 360.  in
  361. 361.  the
  362. 362.  object In
  363. 363.  object
  364. 364.  vs.
  365. 365.  external
  366. 366.  configuration
  367. 367.  file Its
  368. 368.  documented/stored
  369. 369.  by
  370. 370.  phpDocumentor Its
  371. 371.  in
  372. 372.  docblocks,
  373. 373.  so
  374. 374.  its
  375. 375.  parsed
  376. 376. ?phpclass User{ protected $name ...}
  377. 377. ?phpclass User -
  378. 378.  persist
  379. 379.  as
  380. 380.  varchar e
  381. 381.  { -
  382. 382.  length
  383. 383.  should
  384. 384.  not
  385. 385.  b more
  386. 386.  then
  387. 387.  255 -
  388. 388.  should
  389. 389.  not
  390. 390.  be
  391. 391.  blank -
  392. 392.  only
  393. 393.  letters protected $name ...}
  394. 394. ?php persistence -
  395. 395.  persist
  396. 396.  as
  397. 397.  varchar MyProjectUser:class User type: entity e
  398. 398.   -
  399. 399.  length
  400. 400.  should
  401. 401.  not
  402. 402.  b table: users{ fields: more
  403. 403.  then
  404. 404.  255 name: -
  405. 405.  should
  406. 406.  not
  407. 407.  be
  408. 408.  blank type: string length: 255 -
  409. 409.  only
  410. 410.  letters protected $name Validation MyProjectUser: properties: name: - NotBlank: ~ ... - MaxLength: 255 filter MyProjectUser: filters:} name: - alpha
  411. 411. ?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
  412. 412. ?phpclass User{ /** * @ORMColumn(‘string’, length=255) * @AssertNotBlank() * @AssertMaxLength(255) * @FilterAlpha() */ protected $name ...}
  413. 413. ? http://ecdesignrebels.blogspot.comW h e r e tions
  414. 414.  used?
  415. 415.  ann ota er e
  416. 416.   areWh
  417. 417. ? http://ecdesignrebels.blogspot.comW h e r e tions
  418. 418.  used?
  419. 419.  ann ota er e
  420. 420.   areWh
  421. 421. 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), ); }}
  422. 422. /** * @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;}
  423. 423. /** * @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
  424. 424. /** Dependency
  425. 425.  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); }}
  426. 426. http://ecdesignrebels.blogspot.comH o w ? e
  427. 427.   my
  428. 428.  ow n
  429. 429.   rit
  430. 430.  i
  431. 431.  w ns?How
  432. 432.   can tio a nno ta
  433. 433. My
  434. 434.  ProjectAnnotations
  435. 435. My
  436. 436.  Project Annotation
  437. 437.   EngineAnnotations
  438. 438. /** * @tag(parameters) */public function method() Code
  439. 439. /** * @tag(parameters)ReflectionClass-getDocComment() */ public function method() Code
  440. 440. /** * @tag(parameters) ReflectionClass-getDocComment() */ public function method() Code/** * @tag(parameters) */DOCBlock
  441. 441. /** * @tag(parameters) ReflectionClass-getDocComment() */ public function method() Code/** * @tag(parameters) */DOCBlock Tag() + parameters Annotation
  442. 442.  Instances
  443. 443. Annotation EnginesDoctrine
  444. 444.  Commons https://github.com/doctrine/commonphpDocumentor
  445. 445.  2 https://github.com/phpDocumentor/phpDocumentor2php-annotations https://github.com/mindplay-dk/php-annotationsNotoj https://github.com/crodas/Notoj
  446. 446. Annotation EnginesDoctrine
  447. 447.  CommonsphpDocumentor
  448. 448.  2php-annotationsNotoj
  449. 449. Annotation EnginesDoctrine
  450. 450.  Commons 2.3phpDocumentor
  451. 451.  2 2.0php-annotations 1.1Notoj -
  452. 452. Annotation EnginesDoctrine
  453. 453.  Commons 2.3phpDocumentor
  454. 454.  2 2.0php-annotations 1.1Notoj -
  455. 455. Annotation EnginesDoctrine
  456. 456.  Commons 2.3phpDocumentor
  457. 457.  2 2.0php-annotations 1.1Notoj -
  458. 458. Annotation EnginesDoctrine
  459. 459.  Commons 2.3 full
  460. 460.  supportphpDocumentor
  461. 461.  2 2.0 only
  462. 462.  string
  463. 463.  php-annotations 1.1 full
  464. 464.  supportNotoj - full
  465. 465.  support
  466. 466. Annotation EnginesDoctrine
  467. 467.  Commons 2.3 full
  468. 468.  supportphpDocumentor
  469. 469.  2 2.0 only
  470. 470.  string
  471. 471.  php-annotations 1.1 full
  472. 472.  supportNotoj - full
  473. 473.  support
  474. 474. Annotation EnginesDoctrine
  475. 475.  Commons 2.3 full
  476. 476.  supportphpDocumentor
  477. 477.  2 2.0 only
  478. 478.  string
  479. 479.  php-annotations 1.1 full
  480. 480.  supportNotoj - full
  481. 481.  support
  482. 482. ?php use DoctrineORMMapping as ORM; use SymfonyComponentValidator Constraints as Assert;/** * @ORMColumn(‘string’) * @AssertNotBlank() */ How
  483. 483.  it
  484. 484.  Works
  485. 485. Declare
  486. 486.  which
  487. 487.  Annotations
  488. 488.  ?php you
  489. 489.  will
  490. 490.  use use DoctrineORMMapping as ORM; use SymfonyComponentValidator Constraints as Assert;/** * @ORMColumn(‘string’) * @AssertNotBlank() */ How
  491. 491.  it
  492. 492.  Works
  493. 493. AnnotationReader Declare
  494. 494.  which
  495. 495.  Annotations
  496. 496.   ?php you
  497. 497.  will
  498. 498.  use use DoctrineORMMapping as ORM; use SymfonyComponentValidator Constraints as Assert; /** * @ORMColumn(‘string’) * @AssertNotBlank() */ How
  499. 499.  it
  500. 500.  Works
  501. 501. AnnotationReader Declare
  502. 502.  which
  503. 503.  Annotations
  504. 504.   ?php you
  505. 505.  will
  506. 506.  use use DoctrineORMMapping as ORM; use SymfonyComponentValidator Constraints as Assert; /** * @ORMColumn(‘string’) * @AssertNotBlank() “metadata” */new ORMColumn(‘string’)new AssertNotBlank() How
  507. 507.  it
  508. 508.  Works
  509. 509. AnnotationReader Declare
  510. 510.  which
  511. 511.  Annotations
  512. 512.   ?php you
  513. 513.  will
  514. 514.  use use DoctrineORMMapping as ORM; use SymfonyComponentValidator Constraints as Assert; /** * @ORMColumn(‘string’) * @AssertNotBlank() “metadata” */new ORMColumn(‘string’)new AssertNotBlank() Walker
  515. 515.  /
  516. 516.  code Cache How
  517. 517.  it
  518. 518.  Works
  519. 519. Input Filtering DMSFilter: https://github.com/rdohms/DMS
  520. 520. Input Filtering With
  521. 521.  Annotation
  522. 522.  Support! DMSFilter: https://github.com/rdohms/DMS
  523. 523. Ingredients:-
  524. 524.  Filter
  525. 525.  Rules the
  526. 526.  annotation
  527. 527.  /
  528. 528.  metadata,
  529. 529.  configuration-
  530. 530.  Filter
  531. 531.  Executioners applies
  532. 532.  the
  533. 533.  rules-
  534. 534.  Filter
  535. 535.  Service the
  536. 536.  middle-man-
  537. 537.  Annotation
  538. 538.  Engine gets
  539. 539.  the
  540. 540.  rules
  541. 541.  out
  542. 542.  of
  543. 543.  the
  544. 544.  docblocks-
  545. 545.  Annotated
  546. 546.  Objects defines
  547. 547.  the
  548. 548.  rules
  549. 549. annotated
  550. 550.  object “Configured”
  551. 551.  Rules@FilterStripTags(‘bi’) new RulesStripTags(‘bi’); pHello
  552. 552.  bWorld/b/p Filter
  553. 553.  Service Annotation
  554. 554.  Engine Filtered
  555. 555.  values Filter
  556. 556.  Enforcer Hello
  557. 557.  bWorld/b $executioner = new FilterStripTags(); $executioner-filter($metadata, $value);
  558. 558. The “rule”
  559. 559. ?php Usage:
  560. 560.  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; }}
  561. 561. ?php Usage:
  562. 562.  namespace DMSFilterRules; use DMSFilterRules as Filter;/** @FilterStripTags(‘bi’) * StripTags Rule * * @Annotation */class StripTags extends Rule{ /** * String of allowed tags. Ex: bia * * @var string tell
  563. 563.  doctrine
  564. 564.  this
  565. 565.   */ public $allowed = null; is
  566. 566.  an
  567. 567.  annotation /** * {@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; }} DMSFilterRulesRule: public function __construct($options = null)
  575. 575. /** * @MyAnnotation(“name”, nullable=true) */
  576. 576. defaultProperty/** * @MyAnnotation(“name”, nullable=true) */
  577. 577. defaultProperty/** * @MyAnnotation(“name”, nullable=true) */new MyAnnotation($options);
  578. 578. defaultProperty/** * @MyAnnotation(“name”, nullable=true) */ array:
  579. 579.  key
  580. 580.  =
  581. 581.  value or string:
  582. 582.  valuenew MyAnnotation($options);
  583. 583. defaultProperty/** * @MyAnnotation(“name”, nullable=true) */ array:
  584. 584.  key
  585. 585.  =
  586. 586.  value or string:
  587. 587.  valuenew MyAnnotation($options); or
  588. 588. defaultProperty/** * @MyAnnotation(“name”, nullable=true) */ array:
  589. 589.  key
  590. 590.  =
  591. 591.  value or string:
  592. 592.  valuenew MyAnnotation($options); or$a = new MyAnnotation();$a-nullable = true;$a-{$a-getDefaultProperty()} = “name”;
  593. 593. The “enforcer”
  594. 594. ?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); }}
  595. 595. ?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
  596. 596.  the
  597. 597.  filtering return strip_tags($value, $filter-allowed); }}
  598. 598. ?phpnamespace DMSFilterFilters;use DMSFilterRulesRule;/** * StripTags Rule * * @package DMS * @subpackage Filter Rule
  599. 599.  has
  600. 600.  the
  601. 601.   * * @Annotation configuration. */class StripTags extends BaseFilter{ Ex:
  602. 602.  allowed
  603. 603.  tags /** * {@inheritDoc} * * @param DMSFilterRulesStripTags $filter * @param mixed $filter */ public function apply( Rule $filter, $value) { Does
  604. 604.  the
  605. 605.  filtering return strip_tags($value, $filter-allowed); }}
  606. 606. The Filter Service
  607. 607. The
  608. 608.  Life
  609. 609.  of
  610. 610.  a
  611. 611.  Filter
  612. 612.  Service
  613. 613. The
  614. 614.  Life
  615. 615.  of
  616. 616.  a
  617. 617.  Filter
  618. 618.  Service09:00
  619. 619.  -
  620. 620.  DIC
  621. 621.  wake-up
  622. 622.  call new FilterService($reader);
  623. 623. The
  624. 624.  Life
  625. 625.  of
  626. 626.  a
  627. 627.  Filter
  628. 628.  Service09:00
  629. 629.  -
  630. 630.  DIC
  631. 631.  wake-up
  632. 632.  call new FilterService($reader);09:05
  633. 633.  -
  634. 634.  Reply
  635. 635.  to
  636. 636.  emergency
  637. 637.  filter
  638. 638.  call $service-filter($object);
  639. 639. The
  640. 640.  Life
  641. 641.  of
  642. 642.  a
  643. 643.  Filter
  644. 644.  Service09:00
  645. 645.  -
  646. 646.  DIC
  647. 647.  wake-up
  648. 648.  call new FilterService($reader);09:05
  649. 649.  -
  650. 650.  Reply
  651. 651.  to
  652. 652.  emergency
  653. 653.  filter
  654. 654.  call $service-filter($object);09:06
  655. 655.  -
  656. 656.  Get
  657. 657.  Annotations
  658. 658.  for
  659. 659.  properties $reader-getPropertyAnnotations($p); $a = array(StripTags(), Alpha());
  660. 660. The
  661. 661.  Life
  662. 662.  of
  663. 663.  a
  664. 664.  Filter
  665. 665.  Service09:00
  666. 666.  -
  667. 667.  DIC
  668. 668.  wake-up
  669. 669.  call new FilterService($reader);09:05
  670. 670.  -
  671. 671.  Reply
  672. 672.  to
  673. 673.  emergency
  674. 674.  filter
  675. 675.  call $service-filter($object);09:06
  676. 676.  -
  677. 677.  Get
  678. 678.  Annotations
  679. 679.  for
  680. 680.  properties $reader-getPropertyAnnotations($p); $a = array(StripTags(), Alpha());09:07
  681. 681.  -
  682. 682.  Track
  683. 683.  down
  684. 684.  the
  685. 685.  Filters new FiltersStripTags();
  686. 686. The
  687. 687.  Life
  688. 688.  of
  689. 689.  a
  690. 690.  Filter
  691. 691.  Service09:00
  1. A particular slide catching your eye?

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

×