PageRenderTime 26ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/application/Bootstrap.php

http://github.com/AntonShevchuk/Bluz
PHP | 141 lines | 69 code | 14 blank | 58 comment | 4 complexity | b51cc209a1dda99af036dc9d98d51a8d MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright (c) 2012 by Bluz PHP Team
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. * THE SOFTWARE.
  22. */
  23. /**
  24. * @namespace
  25. */
  26. namespace Application;
  27. use Bluz\Application;
  28. use Application\Exception;
  29. /**
  30. * Bootstrap
  31. *
  32. * @category Application
  33. * @package Bootstrap
  34. *
  35. * @author Anton Shevchuk
  36. * @created 20.07.11 17:38
  37. */
  38. class Bootstrap extends Application
  39. {
  40. /**
  41. * initial environment
  42. *
  43. * @param string $environment
  44. * @return \Bluz\Application
  45. */
  46. public function init($environment = ENVIRONMENT_PRODUCTION)
  47. {
  48. // Profiler hooks
  49. if (constant('DEBUG') && DEBUG) {
  50. $this->getEventManager()->attach('log', function($event){
  51. /* @var \Bluz\EventManager\Event $event */
  52. \Bluz\Profiler::log($event->getTarget());
  53. });
  54. $this->getEventManager()->attach('layout:header', function($event){
  55. $layout = $event->getParam('layout');
  56. // add debug.css
  57. $layout->link($layout->baseUrl('/css/debug.css'));
  58. echo $layout->link();
  59. /* @var \Bluz\EventManager\Event $event */
  60. \Bluz\Profiler::log('layout:header');
  61. });
  62. $this->getEventManager()->attach('layout:content', function($event){
  63. /* @var \Bluz\EventManager\Event $event */
  64. \Bluz\Profiler::log('layout:content');
  65. });
  66. $this->getEventManager()->attach('layout:footer', function($event){
  67. /* @var \Bluz\EventManager\Event $event */
  68. \Bluz\Profiler::log('layout:footer');
  69. $version = null;
  70. $comment = null;
  71. /*$version = shell_exec('hg tip --style compact');
  72. if ($version) {
  73. list($version, $comment) = explode("\n", $version, 2);
  74. $comment = trim($comment);
  75. }*/
  76. ?>
  77. <section class="debug-panel">
  78. <section class="debug-panel-header">
  79. <h3 class="debug-panel-title">
  80. Debug Panel
  81. <span class="badge pull-right"><?php printf("%f :: %s kb", microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'], ceil((memory_get_usage()/1024)))?></span>
  82. </h3>
  83. <?php if ($version) :?>
  84. <code class="debug-panel-version">
  85. <?= $this->getLayout()->ahref(
  86. $version, ['index', 'changelog', array()],
  87. array('title' => $comment)
  88. )
  89. ?>
  90. </code>
  91. <?php endif ?>
  92. </section>
  93. <section class="debug-panel-content">
  94. <pre><?php print_r(\Bluz\Profiler::data());?></pre>
  95. </section>
  96. </section>
  97. <?php
  98. });
  99. }
  100. // dispatch hook for acl realization
  101. $this->getEventManager()->attach('dispatch', function($event) {
  102. $eventParams = $event->getParams();
  103. \Bluz\Profiler::log('bootstrap:dispatch: '.$eventParams['module'].'/'.$eventParams['controller']);
  104. });
  105. // widget hook for acl realization
  106. $this->getEventManager()->attach('widget', function($event) {
  107. $eventParams = $event->getParams();
  108. \Bluz\Profiler::log('bootstrap:widget: '.$eventParams['module'].'/'.$eventParams['widget']);
  109. });
  110. $res = parent::init($environment);
  111. $this->getLayout()->title("Dark Side");
  112. return $res;
  113. }
  114. /**
  115. * getRcl
  116. *
  117. * @return \Bluz\Rcl\Rcl
  118. */
  119. public function getRcl()
  120. {
  121. if (!$this->rcl) {
  122. $this->rcl = parent::getRcl();
  123. //$this->rcl->addAssertion(\Application\UserToResourceToPrivilege\Table::getInstance());
  124. }
  125. return $this->rcl;
  126. }
  127. }