PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/Nette/DI/Diagnostics/ContainerPanel.php

https://github.com/stekycz/nette
PHP | 91 lines | 49 code | 20 blank | 22 comment | 3 complexity | 6e23294383370aba5d1a5f087e391f65 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * This file is part of the Nette Framework (http://nette.org)
  4. *
  5. * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  6. *
  7. * For the full copyright and license information, please view
  8. * the file license.txt that was distributed with this source code.
  9. */
  10. namespace Nette\DI\Diagnostics;
  11. use Nette,
  12. Nette\DI\Container,
  13. Nette\Diagnostics\Dumper;
  14. /**
  15. * Dependency injection container panel for Debugger Bar.
  16. *
  17. * @author Patrik Votoček
  18. */
  19. class ContainerPanel extends Nette\Object implements Nette\Diagnostics\IBarPanel
  20. {
  21. /** @var Nette\DI\Container */
  22. private $container;
  23. public function __construct(Container $container)
  24. {
  25. if (PHP_VERSION_ID < 50300) {
  26. throw new Nette\NotSupportedException(__CLASS__ . ' requires PHP 5.3 or newer.');
  27. }
  28. $this->container = $container;
  29. }
  30. /**
  31. * Renders tab.
  32. * @return string
  33. */
  34. public function getTab()
  35. {
  36. ob_start();
  37. require __DIR__ . '/templates/ContainerPanel.tab.phtml';
  38. return ob_get_clean();
  39. }
  40. /**
  41. * Renders panel.
  42. * @return string
  43. */
  44. public function getPanel()
  45. {
  46. $services = $this->getContainerProperty('factories');
  47. $factories = array();
  48. foreach (Nette\Reflection\ClassType::from($this->container)->getMethods() as $method) {
  49. if (preg_match('#^create(Service)?(.+)\z#', $method->getName(), $m)) {
  50. if ($m[1]) {
  51. $services[str_replace('__', '.', strtolower(substr($m[2], 0, 1)) . substr($m[2], 1))] = $method->getAnnotation('return');
  52. } elseif ($method->isPublic()) {
  53. $factories['create' . $m[2]] = $method->getAnnotation('return');
  54. }
  55. }
  56. }
  57. ksort($services);
  58. ksort($factories);
  59. $container = $this->container;
  60. $registry = $this->getContainerProperty('registry');
  61. ob_start();
  62. require __DIR__ . '/templates/ContainerPanel.panel.phtml';
  63. return ob_get_clean();
  64. }
  65. private function getContainerProperty($name)
  66. {
  67. $prop = Nette\Reflection\ClassType::from('Nette\DI\Container')->getProperty($name);
  68. $prop->setAccessible(TRUE);
  69. return $prop->getValue($this->container);
  70. }
  71. }