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

/kernel/private/classes/ezpkernel.php

http://github.com/ezsystems/ezpublish
PHP | 151 lines | 66 code | 14 blank | 71 comment | 3 complexity | 97dbfb988e8181ae02ef07425d9f6169 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * File containing the ezpKernel class.
  4. *
  5. * @copyright Copyright (C) eZ Systems AS. All rights reserved.
  6. * @license For full copyright and license information view LICENSE file distributed with this source code.
  7. * @version //autogentag//
  8. */
  9. /**
  10. * Base eZ Publish kernel class.
  11. * Wraps a "kernel handler" and forwards calls to it.
  12. * This allows to have different kernel handlers depending on the context (i.e. "web" or "cli")
  13. */
  14. class ezpKernel implements ezpWebBasedKernelHandler
  15. {
  16. /**
  17. * @var ezpKernelHandler
  18. */
  19. private $kernelHandler;
  20. /**
  21. * @var ezpKernel
  22. */
  23. protected static $instance = null;
  24. public function __construct( ezpKernelHandler $kernelHandler )
  25. {
  26. /**
  27. * PHP 5.3.3 is our hard requirement
  28. */
  29. if ( version_compare( PHP_VERSION, '5.3.3' ) < 0 )
  30. {
  31. echo "<h1>Unsupported PHP version " . PHP_VERSION . "</h1>",
  32. "<p>eZ Publish 5.x does not run with PHP version lower than 5.3.3.</p>",
  33. "<p>For more information about supported software please visit ",
  34. "<a href=\"http://ez.no/\" >us, eZ Systems, on http://ez.no</a>. See you there :-)</p>";
  35. exit;
  36. }
  37. $this->kernelHandler = $kernelHandler;
  38. self::$instance = $this;
  39. }
  40. /**
  41. * Execution point for controller actions.
  42. * Returns false if not supported
  43. *
  44. * @return ezpKernelResult|false
  45. */
  46. public function run()
  47. {
  48. return $this->kernelHandler->run();
  49. }
  50. /**
  51. * Runs a callback function in the kernel environment.
  52. * This is useful to run eZ Publish 4.x code from a non-related context (like eZ Publish 5)
  53. *
  54. * @param \Closure $callback
  55. * @param bool $postReinitialize Default is true.
  56. * If set to false, the kernel environment will not be reinitialized.
  57. * This can be useful to optimize several calls to the kernel within the same context.
  58. * @return mixed The result of the callback
  59. */
  60. public function runCallback( \Closure $callback, $postReinitialize = true )
  61. {
  62. return $this->kernelHandler->runCallback( $callback, $postReinitialize );
  63. }
  64. /**
  65. * Sets whether to use exceptions inside the kernel.
  66. *
  67. * @param bool $useExceptions
  68. */
  69. public function setUseExceptions( $useExceptions )
  70. {
  71. $this->kernelHandler->setUseExceptions( $useExceptions );
  72. }
  73. /**
  74. * @param bool $usePagelayout
  75. */
  76. public function setUsePagelayout( $usePagelayout )
  77. {
  78. if ( $this->kernelHandler instanceof ezpWebBasedKernelHandler )
  79. {
  80. $this->kernelHandler->setUsePagelayout( $usePagelayout );
  81. }
  82. }
  83. /**
  84. * Reinitializes the kernel environment.
  85. */
  86. public function reInitialize()
  87. {
  88. $this->kernelHandler->reInitialize();
  89. }
  90. /**
  91. * Checks whether the kernel handler has the Symfony service container
  92. * container or not.
  93. *
  94. * @return bool
  95. */
  96. public function hasServiceContainer()
  97. {
  98. return $this->kernelHandler->hasServiceContainer();
  99. }
  100. /**
  101. * Returns the Symfony service container if it has been injected,
  102. * otherwise returns null.
  103. *
  104. * @return \Symfony\Component\DependencyInjection\ContainerInterface|null
  105. */
  106. public function getServiceContainer()
  107. {
  108. return $this->kernelHandler->getServiceContainer();
  109. }
  110. /**
  111. * Checks if the kernel has already been instantiated.
  112. *
  113. * @return bool
  114. */
  115. public static function hasInstance()
  116. {
  117. return self::$instance !== null;
  118. }
  119. /**
  120. * Returns the current instance of ezpKernel.
  121. *
  122. * @throws LogicException if no instance of ezpKernel has been instantiated
  123. * @return ezpKernel
  124. */
  125. public static function instance()
  126. {
  127. if ( !self::hasInstance() )
  128. {
  129. throw new LogicException(
  130. 'Cannot return the instance of '
  131. . __CLASS__
  132. . ', it has not been instantiated'
  133. );
  134. }
  135. return self::$instance;
  136. }
  137. }