Traits.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace catcher\generate\build\classes;
  3. use PhpParser\BuilderFactory;
  4. class Traits
  5. {
  6. protected $traitBuild;
  7. protected $build;
  8. public function use(...$names)
  9. {
  10. $this->build = new BuilderFactory;
  11. $this->traitBuild = call_user_func_array([$this->build, 'useTrait'], $names);
  12. return $this;
  13. }
  14. public function and($name)
  15. {
  16. $this->traitBuild->and($name);
  17. return $this;
  18. }
  19. /**
  20. * with
  21. *
  22. * @time 2020年11月19日
  23. * @param \Closure|null $closure
  24. * @return $this
  25. */
  26. public function with(\Closure $closure = null)
  27. {
  28. if ($closure instanceof \Closure) {
  29. $this->traitBuild->withe($closure($this));
  30. return $this;
  31. }
  32. return $this;
  33. }
  34. /**
  35. * @time 2020年11月19日
  36. * @param $name
  37. * @param null $method
  38. * @return $this
  39. */
  40. public function adaptation($name, $method = null)
  41. {
  42. $this->build = $this->build->traitUseAdaptation($name. $method);
  43. return $this;
  44. }
  45. /**
  46. * @time 2020年11月19日
  47. * @param $name
  48. * @return $this
  49. */
  50. public function as($name)
  51. {
  52. $this->build->as($name);
  53. return $this;
  54. }
  55. /**
  56. * @time 2020年11月19日
  57. * @param $name
  58. * @return $this
  59. */
  60. public function insteadof($name)
  61. {
  62. $this->build->insteadof($name);
  63. return $this;
  64. }
  65. public function build()
  66. {
  67. return $this->traitBuild;
  68. }
  69. }