index.rst 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. Introduction
  2. ============
  3. The Doctrine Reflection project is a simple library used by the various Doctrine projects which adds some additional
  4. functionality on top of the reflection functionality that comes with PHP. It allows you to get the reflection information
  5. about classes, methods and properties statically.
  6. Installation
  7. ============
  8. The library can easily be installed with composer.
  9. .. code-block:: sh
  10. $ composer require doctrine/reflection
  11. Setup
  12. =====
  13. .. code-block:: php
  14. use Doctrine\Common\Reflection\Psr0FindFile;
  15. use Doctrine\Common\Reflection\StaticReflectionParser;
  16. use App\Model\User;
  17. $finder = new Psr0FindFile(['App' => [
  18. '/path/to/project/src/App'
  19. ]]);
  20. $staticReflectionParser = new StaticReflectionParser(User::class, $finder);
  21. Usage
  22. =====
  23. .. code-block:: php
  24. echo $staticReflectionParser->getClassName();
  25. echo $staticReflectionParser->getNamespaceName();
  26. StaticReflectionClass
  27. =====================
  28. .. code-block:: php
  29. $staticReflectionClass = $staticReflectionParser->getReflectionClass();
  30. echo $staticReflectionClass->getName();
  31. echo $staticReflectionClass->getDocComment();
  32. echo $staticReflectionClass->getNamespaceName();
  33. print_r($staticReflectionClass->getUseStatements());
  34. StaticReflectionMethod
  35. ======================
  36. .. code-block:: php
  37. $staticReflectionMethod = $staticReflectionParser->getReflectionMethod('getSomething');
  38. echo $staticReflectionMethod->getName();
  39. echo $staticReflectionMethod->getDeclaringClass();
  40. echo $staticReflectionMethod->getNamespaceName();
  41. echo $staticReflectionMethod->getDocComment();
  42. print_r($staticReflectionMethod->getUseStatements());
  43. StaticReflectionProperty
  44. ========================
  45. .. code-block:: php
  46. $staticReflectionProperty = $staticReflectionParser->getReflectionProperty('something');
  47. echo $staticReflectionProperty->getName();
  48. echo $staticReflectionProperty->getDeclaringClass();
  49. echo $staticReflectionProperty->getDocComment();
  50. print_r($staticReflectionProperty->getUseStatements());