FetchServices.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace ZendBench\ServiceManager;
  3. use Athletic\AthleticEvent;
  4. use Zend\ServiceManager\ServiceManager;
  5. use Zend\ServiceManager\Config;
  6. class FetchServices extends AthleticEvent
  7. {
  8. const NUM_SERVICES = 1000;
  9. /**
  10. * @var ServiceManager
  11. */
  12. protected $sm;
  13. protected function getConfig()
  14. {
  15. $config = [];
  16. for ($i = 0; $i <= self::NUM_SERVICES; $i++) {
  17. $config['factories']["factory_$i"] = BenchAsset\FactoryFoo::class;
  18. $config['invokables']["invokable_$i"] = BenchAsset\Foo::class;
  19. $config['services']["service_$i"] = $this;
  20. $config['aliases']["alias_$i"] = "service_$i";
  21. }
  22. $config['abstract_factories'] = [ BenchAsset\AbstractFactoryFoo::class ];
  23. return $config;
  24. }
  25. public function classSetUp()
  26. {
  27. $this->sm = new ServiceManager(new Config($this->getConfig()));
  28. }
  29. /**
  30. * Fetch the factory services
  31. *
  32. * @iterations 5000
  33. */
  34. public function fetchFactoryService()
  35. {
  36. $result = $this->sm->get('factory_' . rand(0, self::NUM_SERVICES));
  37. }
  38. /**
  39. * Fetch the invokable services
  40. *
  41. * @iterations 5000
  42. */
  43. public function fetchInvokableService()
  44. {
  45. $result = $this->sm->get('invokable_' . rand(0, self::NUM_SERVICES));
  46. }
  47. /**
  48. * Fetch the services
  49. *
  50. * @iterations 5000
  51. */
  52. public function fetchService()
  53. {
  54. $result = $this->sm->get('service_' . rand(0, self::NUM_SERVICES));
  55. }
  56. /**
  57. * Fetch the alias services
  58. *
  59. * @iterations 5000
  60. */
  61. public function fetchAliasService()
  62. {
  63. $result = $this->sm->get('alias_' . rand(0, self::NUM_SERVICES));
  64. }
  65. /**
  66. * Fetch the abstract factory services
  67. *
  68. * @iterations 5000
  69. */
  70. public function fetchAbstractFactoryService()
  71. {
  72. $result = $this->sm->get('foo');
  73. }
  74. }