004_name_resolution.phpt 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. --TEST--
  2. Resolve attribute names
  3. --FILE--
  4. <?php
  5. namespace {
  6. function dump_attributes($attributes) {
  7. $arr = [];
  8. foreach ($attributes as $attribute) {
  9. $arr[] = ['name' => $attribute->getName(), 'args' => $attribute->getArguments()];
  10. }
  11. var_dump($arr);
  12. }
  13. }
  14. namespace Doctrine\ORM\Mapping {
  15. class Entity {
  16. }
  17. }
  18. namespace Doctrine\ORM\Attributes {
  19. class Table {
  20. }
  21. }
  22. namespace Foo {
  23. use Doctrine\ORM\Mapping\Entity;
  24. use Doctrine\ORM\Mapping as ORM;
  25. use Doctrine\ORM\Attributes;
  26. #[Entity("imported class")]
  27. #[ORM\Entity("imported namespace")]
  28. #[\Doctrine\ORM\Mapping\Entity("absolute from namespace")]
  29. #[\Entity("import absolute from global")]
  30. #[Attributes\Table()]
  31. function foo() {
  32. }
  33. }
  34. namespace {
  35. class Entity {}
  36. dump_attributes((new ReflectionFunction('Foo\foo'))->getAttributes());
  37. }
  38. ?>
  39. --EXPECT--
  40. array(5) {
  41. [0]=>
  42. array(2) {
  43. ["name"]=>
  44. string(27) "Doctrine\ORM\Mapping\Entity"
  45. ["args"]=>
  46. array(1) {
  47. [0]=>
  48. string(14) "imported class"
  49. }
  50. }
  51. [1]=>
  52. array(2) {
  53. ["name"]=>
  54. string(27) "Doctrine\ORM\Mapping\Entity"
  55. ["args"]=>
  56. array(1) {
  57. [0]=>
  58. string(18) "imported namespace"
  59. }
  60. }
  61. [2]=>
  62. array(2) {
  63. ["name"]=>
  64. string(27) "Doctrine\ORM\Mapping\Entity"
  65. ["args"]=>
  66. array(1) {
  67. [0]=>
  68. string(23) "absolute from namespace"
  69. }
  70. }
  71. [3]=>
  72. array(2) {
  73. ["name"]=>
  74. string(6) "Entity"
  75. ["args"]=>
  76. array(1) {
  77. [0]=>
  78. string(27) "import absolute from global"
  79. }
  80. }
  81. [4]=>
  82. array(2) {
  83. ["name"]=>
  84. string(29) "Doctrine\ORM\Attributes\Table"
  85. ["args"]=>
  86. array(0) {
  87. }
  88. }
  89. }