PageRenderTime 79ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 2ms

/libs/Nette/loader.php

https://github.com/Edke/Nette-addDynamic
PHP | 19983 lines | 16680 code | 3295 blank | 8 comment | 1933 complexity | 760910a90a941effafb0a54c47873564 MD5 | raw file
Possible License(s): BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. <?php //netteloader=Nette\Framework
  2. namespace {
  3. /**
  4. * Nette Framework (version 2.0-dev released on 2011-06-13, http://nette.org)
  5. *
  6. * Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
  7. *
  8. * For the full copyright and license information, please view
  9. * the file license.txt that was distributed with this source code.
  10. */
  11. error_reporting(E_ALL | E_STRICT);
  12. @set_magic_quotes_runtime(FALSE);
  13. iconv_set_encoding('internal_encoding', 'UTF-8');
  14. extension_loaded('mbstring') && mb_internal_encoding('UTF-8');
  15. @header('X-Powered-By: Nette Framework');
  16. define('NETTE', TRUE);
  17. define('NETTE_DIR', __DIR__);
  18. define('NETTE_VERSION_ID', 20000);
  19. define('NETTE_PACKAGE', '5.3');
  20. }
  21. namespace Nette\Diagnostics {
  22. use Nette;
  23. interface IBarPanel
  24. {
  25. function getTab();
  26. function getPanel();
  27. }
  28. }
  29. namespace Nette\Application {
  30. use Nette;
  31. interface IPresenter
  32. {
  33. function run(Request $request);
  34. }
  35. interface IPresenterFactory
  36. {
  37. function getPresenterClass(& $name);
  38. function createPresenter($name);
  39. }
  40. interface IResponse
  41. {
  42. function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse);
  43. }
  44. interface IRouter
  45. {
  46. const ONE_WAY = 1;
  47. const SECURED = 2;
  48. function match(Nette\Http\IRequest $httpRequest);
  49. function constructUrl(Request $appRequest, Nette\Http\Url $refUrl);
  50. }
  51. }
  52. namespace Nette {
  53. use Nette;
  54. interface IFreezable
  55. {
  56. function freeze();
  57. function isFrozen();
  58. }
  59. }
  60. namespace Nette\ComponentModel {
  61. use Nette;
  62. interface IComponent
  63. {
  64. const NAME_SEPARATOR = '-';
  65. function getName();
  66. function getParent();
  67. function setParent(IContainer $parent = NULL, $name = NULL);
  68. }
  69. interface IContainer extends IComponent
  70. {
  71. function addComponent(IComponent $component, $name);
  72. function removeComponent(IComponent $component);
  73. function getComponent($name);
  74. function getComponents($deep = FALSE, $filterType = NULL);
  75. }
  76. }
  77. namespace Nette\Application\UI {
  78. use Nette;
  79. interface ISignalReceiver
  80. {
  81. function signalReceived($signal);
  82. }
  83. interface IStatePersistent
  84. {
  85. function loadState(array $params);
  86. function saveState(array & $params);
  87. }
  88. interface IPartiallyRenderable extends IRenderable
  89. {
  90. }
  91. interface IRenderable
  92. {
  93. function invalidateControl();
  94. function isControlInvalid();
  95. }
  96. }
  97. namespace Nette\Caching {
  98. use Nette;
  99. interface IStorage
  100. {
  101. function read($key);
  102. function write($key, $data, array $dependencies);
  103. function remove($key);
  104. function clean(array $conds);
  105. }
  106. }
  107. namespace Nette\Caching\Storages {
  108. use Nette;
  109. interface IJournal
  110. {
  111. function write($key, array $dependencies);
  112. function clean(array $conditions);
  113. }
  114. }
  115. namespace Nette\Config {
  116. use Nette;
  117. interface IAdapter
  118. {
  119. static function load($file);
  120. static function save($config, $file);
  121. }
  122. }
  123. namespace Nette\Database {
  124. use Nette;
  125. interface ISupplementalDriver
  126. {
  127. function delimite($name);
  128. function formatDateTime(\DateTime $value);
  129. function formatLike($value, $pos);
  130. function applyLimit(&$sql, $limit, $offset);
  131. function normalizeRow($row, $statement);
  132. }
  133. }
  134. namespace Nette\DI {
  135. use Nette;
  136. interface IContainer
  137. {
  138. function addService($name, $service);
  139. function getService($name);
  140. function removeService($name);
  141. function hasService($name);
  142. }
  143. interface IServiceBuilder
  144. {
  145. function createService(IContainer $container);
  146. }
  147. }
  148. namespace Nette\Forms {
  149. use Nette;
  150. interface IControl
  151. {
  152. function loadHttpData();
  153. function setValue($value);
  154. function getValue();
  155. function getRules();
  156. function getErrors();
  157. function isDisabled();
  158. function translate($s, $count = NULL);
  159. }
  160. interface ISubmitterControl extends IControl
  161. {
  162. function isSubmittedBy();
  163. function getValidationScope();
  164. }
  165. interface IFormRenderer
  166. {
  167. function render(Form $form);
  168. }
  169. }
  170. namespace Nette\Http {
  171. use Nette;
  172. interface IRequest
  173. {
  174. const
  175. GET = 'GET',
  176. POST = 'POST',
  177. HEAD = 'HEAD',
  178. PUT = 'PUT',
  179. DELETE = 'DELETE';
  180. function getUrl();
  181. function getQuery($key = NULL, $default = NULL);
  182. function getPost($key = NULL, $default = NULL);
  183. function getFile($key);
  184. function getFiles();
  185. function getCookie($key, $default = NULL);
  186. function getCookies();
  187. function getMethod();
  188. function isMethod($method);
  189. function getHeader($header, $default = NULL);
  190. function getHeaders();
  191. function isSecured();
  192. function isAjax();
  193. function getRemoteAddress();
  194. function getRemoteHost();
  195. }
  196. interface IResponse
  197. {
  198. const PERMANENT = 2116333333;
  199. const BROWSER = 0;
  200. const
  201. S200_OK = 200,
  202. S204_NO_CONTENT = 204,
  203. S300_MULTIPLE_CHOICES = 300,
  204. S301_MOVED_PERMANENTLY = 301,
  205. S302_FOUND = 302,
  206. S303_SEE_OTHER = 303,
  207. S303_POST_GET = 303,
  208. S304_NOT_MODIFIED = 304,
  209. S307_TEMPORARY_REDIRECT= 307,
  210. S400_BAD_REQUEST = 400,
  211. S401_UNAUTHORIZED = 401,
  212. S403_FORBIDDEN = 403,
  213. S404_NOT_FOUND = 404,
  214. S405_METHOD_NOT_ALLOWED = 405,
  215. S410_GONE = 410,
  216. S500_INTERNAL_SERVER_ERROR = 500,
  217. S501_NOT_IMPLEMENTED = 501,
  218. S503_SERVICE_UNAVAILABLE = 503;
  219. function setCode($code);
  220. function getCode();
  221. function setHeader($name, $value);
  222. function addHeader($name, $value);
  223. function setContentType($type, $charset = NULL);
  224. function redirect($url, $code = self::S302_FOUND);
  225. function setExpiration($seconds);
  226. function isSent();
  227. function getHeaders();
  228. function setCookie($name, $value, $expire, $path = NULL, $domain = NULL, $secure = NULL, $httpOnly = NULL);
  229. function deleteCookie($name, $path = NULL, $domain = NULL, $secure = NULL);
  230. }
  231. interface ISessionStorage
  232. {
  233. function open($savePath, $sessionName);
  234. function close();
  235. function read($id);
  236. function write($id, $data);
  237. function remove($id);
  238. function clean($maxlifetime);
  239. }
  240. interface IUser
  241. {
  242. function login();
  243. function logout($clearIdentity = FALSE);
  244. function isLoggedIn();
  245. function getIdentity();
  246. function setAuthenticator(Nette\Security\IAuthenticator $handler);
  247. function getAuthenticator();
  248. function setNamespace($namespace);
  249. function getNamespace();
  250. function getRoles();
  251. function isInRole($role);
  252. function isAllowed();
  253. function setAuthorizator(Nette\Security\IAuthorizator $handler);
  254. function getAuthorizator();
  255. }
  256. }
  257. namespace Nette\Latte {
  258. use Nette;
  259. interface IMacro
  260. {
  261. function initialize();
  262. function finalize();
  263. function nodeOpened(MacroNode $node);
  264. function nodeClosed(MacroNode $node);
  265. }
  266. }
  267. namespace Nette\Localization {
  268. use Nette;
  269. interface ITranslator
  270. {
  271. function translate($message, $count = NULL);
  272. }
  273. }
  274. namespace Nette\Mail {
  275. use Nette;
  276. interface IMailer
  277. {
  278. function send(Message $mail);
  279. }
  280. }
  281. namespace Nette\Reflection {
  282. use Nette;
  283. interface IAnnotation
  284. {
  285. function __construct(array $values);
  286. }
  287. }
  288. namespace Nette\Security {
  289. use Nette;
  290. interface IAuthenticator
  291. {
  292. const USERNAME = 0,
  293. PASSWORD = 1;
  294. const IDENTITY_NOT_FOUND = 1,
  295. INVALID_CREDENTIAL = 2,
  296. FAILURE = 3,
  297. NOT_APPROVED = 4;
  298. function authenticate(array $credentials);
  299. }
  300. interface IAuthorizator
  301. {
  302. const ALL = NULL;
  303. const ALLOW = TRUE;
  304. const DENY = FALSE;
  305. function isAllowed($role, $resource, $privilege);
  306. }
  307. interface IIdentity
  308. {
  309. function getId();
  310. function getRoles();
  311. }
  312. interface IResource
  313. {
  314. function getResourceId();
  315. }
  316. interface IRole
  317. {
  318. function getRoleId();
  319. }
  320. }
  321. namespace Nette\Templating {
  322. use Nette;
  323. interface ITemplate
  324. {
  325. function render();
  326. }
  327. interface IFileTemplate extends ITemplate
  328. {
  329. function setFile($file);
  330. function getFile();
  331. }
  332. }
  333. namespace Nette {
  334. use Nette;
  335. class ArgumentOutOfRangeException extends \InvalidArgumentException
  336. {
  337. }
  338. class InvalidStateException extends \RuntimeException
  339. {
  340. }
  341. class NotImplementedException extends \LogicException
  342. {
  343. }
  344. class NotSupportedException extends \LogicException
  345. {
  346. }
  347. class DeprecatedException extends NotSupportedException
  348. {
  349. }
  350. class MemberAccessException extends \LogicException
  351. {
  352. }
  353. class IOException extends \RuntimeException
  354. {
  355. }
  356. class FileNotFoundException extends IOException
  357. {
  358. }
  359. class DirectoryNotFoundException extends IOException
  360. {
  361. }
  362. class InvalidArgumentException extends \InvalidArgumentException
  363. {
  364. }
  365. class OutOfRangeException extends \OutOfRangeException
  366. {
  367. }
  368. class UnexpectedValueException extends \UnexpectedValueException
  369. {
  370. }
  371. class StaticClassException extends \LogicException
  372. {
  373. }
  374. class FatalErrorException extends \ErrorException
  375. {
  376. function __construct($message, $code, $severity, $file, $line, $context)
  377. {
  378. parent::__construct($message, $code, $severity, $file, $line);
  379. $this->context = $context;
  380. }
  381. }
  382. abstract class Object
  383. {
  384. static function getReflection()
  385. {
  386. return new Reflection\ClassType(get_called_class());
  387. }
  388. function __call($name, $args)
  389. {
  390. return ObjectMixin::call($this, $name, $args);
  391. }
  392. static function __callStatic($name, $args)
  393. {
  394. return ObjectMixin::callStatic(get_called_class(), $name, $args);
  395. }
  396. static function extensionMethod($name, $callback = NULL)
  397. {
  398. if (strpos($name, '::') === FALSE) {
  399. $class = get_called_class();
  400. } else {
  401. list($class, $name) = explode('::', $name);
  402. }
  403. $class = new Reflection\ClassType($class);
  404. if ($callback === NULL) {
  405. return $class->getExtensionMethod($name);
  406. } else {
  407. $class->setExtensionMethod($name, $callback);
  408. }
  409. }
  410. function &__get($name)
  411. {
  412. return ObjectMixin::get($this, $name);
  413. }
  414. function __set($name, $value)
  415. {
  416. return ObjectMixin::set($this, $name, $value);
  417. }
  418. function __isset($name)
  419. {
  420. return ObjectMixin::has($this, $name);
  421. }
  422. function __unset($name)
  423. {
  424. ObjectMixin::remove($this, $name);
  425. }
  426. }
  427. }
  428. namespace Nette\Utils {
  429. use Nette;
  430. final class LimitedScope
  431. {
  432. private static $vars;
  433. final function __construct()
  434. {
  435. throw new Nette\StaticClassException;
  436. }
  437. static function evaluate()
  438. {
  439. if (func_num_args() > 1) {
  440. self::$vars = func_get_arg(1);
  441. extract(self::$vars);
  442. }
  443. $res = eval('?>' . func_get_arg(0));
  444. if ($res === FALSE && ($error = error_get_last()) && $error['type'] === E_PARSE) {
  445. throw new Nette\FatalErrorException($error['message'], 0, $error['type'], $error['file'], $error['line'], NULL);
  446. }
  447. return $res;
  448. }
  449. static function load()
  450. {
  451. if (func_num_args() > 1) {
  452. self::$vars = func_get_arg(1);
  453. extract(self::$vars);
  454. }
  455. return include func_get_arg(0);
  456. }
  457. }
  458. }
  459. namespace Nette\Loaders {
  460. use Nette;
  461. abstract class AutoLoader extends Nette\Object
  462. {
  463. static private $loaders = array();
  464. public static $count = 0;
  465. final static function load($type)
  466. {
  467. foreach (func_get_args() as $type) {
  468. if (!class_exists($type)) {
  469. throw new Nette\InvalidStateException("Unable to load class or interface '$type'.");
  470. }
  471. }
  472. }
  473. final static function getLoaders()
  474. {
  475. return array_values(self::$loaders);
  476. }
  477. function register()
  478. {
  479. if (!function_exists('spl_autoload_register')) {
  480. throw new Nette\NotSupportedException('spl_autoload does not exist in this PHP installation.');
  481. }
  482. spl_autoload_register(array($this, 'tryLoad'));
  483. self::$loaders[spl_object_hash($this)] = $this;
  484. }
  485. function unregister()
  486. {
  487. unset(self::$loaders[spl_object_hash($this)]);
  488. return spl_autoload_unregister(array($this, 'tryLoad'));
  489. }
  490. abstract function tryLoad($type);
  491. }
  492. }
  493. namespace Nette\Diagnostics {
  494. use Nette;
  495. final class Debugger
  496. {
  497. public static $productionMode;
  498. public static $consoleMode;
  499. public static $time;
  500. private static $ajaxDetected;
  501. public static $source;
  502. public static $editor = 'editor://open/?file=%file&line=%line';
  503. public static $maxDepth = 3;
  504. public static $maxLen = 150;
  505. public static $showLocation = FALSE;
  506. const DEVELOPMENT = FALSE,
  507. PRODUCTION = TRUE,
  508. DETECT = NULL;
  509. public static $blueScreen;
  510. public static $strictMode = FALSE;
  511. public static $scream = FALSE;
  512. public static $onFatalError = array();
  513. private static $enabled = FALSE;
  514. private static $lastError = FALSE;
  515. public static $logger;
  516. public static $fireLogger;
  517. public static $logDirectory;
  518. public static $email;
  519. public static $mailer;
  520. public static $emailSnooze;
  521. public static $bar;
  522. private static $errorPanel;
  523. private static $dumpPanel;
  524. const DEBUG = 'debug',
  525. INFO = 'info',
  526. WARNING = 'warning',
  527. ERROR = 'error',
  528. CRITICAL = 'critical';
  529. final function __construct()
  530. {
  531. throw new Nette\StaticClassException;
  532. }
  533. static function _init()
  534. {
  535. self::$time = microtime(TRUE);
  536. self::$consoleMode = PHP_SAPI === 'cli';
  537. self::$productionMode = self::DETECT;
  538. if (self::$consoleMode) {
  539. self::$source = empty($_SERVER['argv']) ? 'cli' : 'cli: ' . implode(' ', $_SERVER['argv']);
  540. } else {
  541. self::$ajaxDetected = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest';
  542. if (isset($_SERVER['REQUEST_URI'])) {
  543. self::$source = (isset($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off') ? 'https://' : 'http://')
  544. . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : ''))
  545. . $_SERVER['REQUEST_URI'];
  546. }
  547. }
  548. self::$logger = new Logger;
  549. self::$logDirectory = & self::$logger->directory;
  550. self::$email = & self::$logger->email;
  551. self::$mailer = & self::$logger->mailer;
  552. self::$emailSnooze = & Logger::$emailSnooze;
  553. self::$fireLogger = new FireLogger;
  554. self::$blueScreen = new BlueScreen;
  555. self::$blueScreen->addPanel(function($e) {
  556. if ($e instanceof Nette\Templating\FilterException) {
  557. return array(
  558. 'tab' => 'Template',
  559. 'panel' => '<p><b>File:</b> ' . Helpers::editorLink($e->sourceFile, $e->sourceLine)
  560. . '&nbsp; <b>Line:</b> ' . ($e->sourceLine ? $e->sourceLine : 'n/a') . '</p>'
  561. . ($e->sourceLine ? '<pre>' . BlueScreen::highlightFile($e->sourceFile, $e->sourceLine) . '</pre>' : '')
  562. );
  563. }
  564. });
  565. self::$bar = new Bar;
  566. self::$bar->addPanel(new DefaultBarPanel('time'));
  567. self::$bar->addPanel(new DefaultBarPanel('memory'));
  568. self::$bar->addPanel(self::$errorPanel = new DefaultBarPanel('errors'));
  569. self::$bar->addPanel(self::$dumpPanel = new DefaultBarPanel('dumps'));
  570. }
  571. static function enable($mode = NULL, $logDirectory = NULL, $email = NULL)
  572. {
  573. error_reporting(E_ALL | E_STRICT);
  574. if (is_bool($mode)) {
  575. self::$productionMode = $mode;
  576. } elseif (is_string($mode)) {
  577. $mode = preg_split('#[,\s]+#', "$mode 127.0.0.1 ::1");
  578. }
  579. if (is_array($mode)) {
  580. self::$productionMode = !isset($_SERVER['REMOTE_ADDR']) || !in_array($_SERVER['REMOTE_ADDR'], $mode, TRUE);
  581. }
  582. if (self::$productionMode === self::DETECT) {
  583. if (class_exists('Nette\Environment')) {
  584. self::$productionMode = Nette\Environment::isProduction();
  585. } elseif (isset($_SERVER['SERVER_ADDR']) || isset($_SERVER['LOCAL_ADDR'])) {
  586. $addrs = array();
  587. if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  588. $addrs = preg_split('#,\s*#', $_SERVER['HTTP_X_FORWARDED_FOR']);
  589. }
  590. if (isset($_SERVER['REMOTE_ADDR'])) {
  591. $addrs[] = $_SERVER['REMOTE_ADDR'];
  592. }
  593. $addrs[] = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR'];
  594. self::$productionMode = FALSE;
  595. foreach ($addrs as $addr) {
  596. $oct = explode('.', $addr);
  597. if ($addr !== '::1' && (count($oct) !== 4 || ($oct[0] !== '10' && $oct[0] !== '127' && ($oct[0] !== '172' || $oct[1] < 16 || $oct[1] > 31)
  598. && ($oct[0] !== '169' || $oct[1] !== '254') && ($oct[0] !== '192' || $oct[1] !== '168')))
  599. ) {
  600. self::$productionMode = TRUE;
  601. break;
  602. }
  603. }
  604. } else {
  605. self::$productionMode = !self::$consoleMode;
  606. }
  607. }
  608. if (is_string($logDirectory)) {
  609. self::$logDirectory = realpath($logDirectory);
  610. if (self::$logDirectory === FALSE) {
  611. throw new Nette\DirectoryNotFoundException("Directory '$logDirectory' is not found.");
  612. }
  613. } elseif ($logDirectory === FALSE) {
  614. self::$logDirectory = FALSE;
  615. } elseif (self::$logDirectory === NULL) {
  616. self::$logDirectory = defined('APP_DIR') ? APP_DIR . '/../log' : getcwd() . '/log';
  617. }
  618. if (self::$logDirectory) {
  619. ini_set('error_log', self::$logDirectory . '/php_error.log');
  620. }
  621. if (function_exists('ini_set')) {
  622. ini_set('display_errors', !self::$productionMode);
  623. ini_set('html_errors', FALSE);
  624. ini_set('log_errors', FALSE);
  625. } elseif (ini_get('display_errors') != !self::$productionMode && ini_get('display_errors') !== (self::$productionMode ? 'stderr' : 'stdout')) {
  626. throw new Nette\NotSupportedException('Function ini_set() must be enabled.');
  627. }
  628. if ($email) {
  629. if (!is_string($email)) {
  630. throw new Nette\InvalidArgumentException('Email address must be a string.');
  631. }
  632. self::$email = $email;
  633. }
  634. if (!defined('E_DEPRECATED')) {
  635. define('E_DEPRECATED', 8192);
  636. }
  637. if (!defined('E_USER_DEPRECATED')) {
  638. define('E_USER_DEPRECATED', 16384);
  639. }
  640. if (!self::$enabled) {
  641. register_shutdown_function(array(__CLASS__, '_shutdownHandler'));
  642. set_exception_handler(array(__CLASS__, '_exceptionHandler'));
  643. set_error_handler(array(__CLASS__, '_errorHandler'));
  644. self::$enabled = TRUE;
  645. }
  646. }
  647. static function isEnabled()
  648. {
  649. return self::$enabled;
  650. }
  651. static function log($message, $priority = self::INFO)
  652. {
  653. if (self::$logDirectory === FALSE) {
  654. return;
  655. } elseif (!self::$logDirectory) {
  656. throw new Nette\InvalidStateException('Logging directory is not specified in Nette\Diagnostics\Debugger::$logDirectory.');
  657. }
  658. if ($message instanceof \Exception) {
  659. $exception = $message;
  660. $message = "PHP Fatal error: "
  661. . ($message instanceof Nette\FatalErrorException
  662. ? $exception->getMessage()
  663. : "Uncaught exception " . get_class($exception) . " with message '" . $exception->getMessage() . "'")
  664. . " in " . $exception->getFile() . ":" . $exception->getLine();
  665. $hash = md5($exception );
  666. $exceptionFilename = "exception " . @date('Y-m-d H-i-s') . " $hash.html";
  667. foreach (new \DirectoryIterator(self::$logDirectory) as $entry) {
  668. if (strpos($entry, $hash)) {
  669. $exceptionFilename = NULL; break;
  670. }
  671. }
  672. }
  673. self::$logger->log(array(
  674. @date('[Y-m-d H-i-s]'),
  675. $message,
  676. self::$source ? ' @ ' . self::$source : NULL,
  677. !empty($exceptionFilename) ? ' @@ ' . $exceptionFilename : NULL
  678. ), $priority);
  679. if (!empty($exceptionFilename) && $logHandle = @fopen(self::$logDirectory . '/'. $exceptionFilename, 'w')) {
  680. ob_start();
  681. ob_start(function($buffer) use($logHandle) { fwrite($logHandle, $buffer); }, 1);
  682. self::$blueScreen->render($exception);
  683. ob_end_flush();
  684. ob_end_clean();
  685. fclose($logHandle);
  686. }
  687. }
  688. static function _shutdownHandler()
  689. {
  690. if (!self::$enabled) {
  691. return;
  692. }
  693. static $types = array(
  694. E_ERROR => 1,
  695. E_CORE_ERROR => 1,
  696. E_COMPILE_ERROR => 1,
  697. E_PARSE => 1,
  698. );
  699. $error = error_get_last();
  700. if (isset($types[$error['type']])) {
  701. self::_exceptionHandler(new Nette\FatalErrorException($error['message'], 0, $error['type'], $error['file'], $error['line'], NULL));
  702. }
  703. if (self::$bar && !self::$productionMode && !self::$ajaxDetected && !self::$consoleMode
  704. && !preg_match('#^Content-Type: (?!text/html)#im', implode("\n", headers_list()))
  705. ) {
  706. self::$bar->render();
  707. }
  708. }
  709. static function _exceptionHandler(\Exception $exception)
  710. {
  711. if (!headers_sent()) {
  712. header('HTTP/1.1 500 Internal Server Error');
  713. }
  714. $htmlMode = !self::$ajaxDetected && !preg_match('#^Content-Type: (?!text/html)#im', implode("\n", headers_list()));
  715. try {
  716. if (self::$productionMode) {
  717. self::log($exception, self::ERROR);
  718. if (self::$consoleMode) {
  719. echo "ERROR: the server encountered an internal error and was unable to complete your request.\n";
  720. } elseif ($htmlMode) {
  721. ?>
  722. <!DOCTYPE html>
  723. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  724. <meta name=robots content=noindex><meta name=generator content="Nette Framework">
  725. <style>body{color:#333;background:white;width:500px;margin:100px auto}h1{font:bold 47px/1.5 sans-serif;margin:.6em 0}p{font:21px/1.5 Georgia,serif;margin:1.5em 0}small{font-size:70%;color:gray}</style>
  726. <title>Server Error</title>
  727. <h1>Server Error</h1>
  728. <p>We're sorry! The server encountered an internal error and was unable to complete your request. Please try again later.</p>
  729. <p><small>error 500</small></p>
  730. <?php
  731. }
  732. } else {
  733. if (self::$consoleMode) {
  734. echo "$exception\n";
  735. } elseif ($htmlMode) {
  736. self::$blueScreen->render($exception);
  737. if (self::$bar) {
  738. self::$bar->render();
  739. }
  740. } elseif (!self::fireLog($exception, self::ERROR)) {
  741. self::log($exception);
  742. }
  743. }
  744. foreach (self::$onFatalError as $handler) {
  745. call_user_func($handler, $exception);
  746. }
  747. } catch (\Exception $e) {
  748. echo "\nNette\\Debug FATAL ERROR: thrown ", get_class($e), ': ', $e->getMessage(),
  749. "\nwhile processing ", get_class($exception), ': ', $exception->getMessage(), "\n";
  750. }
  751. self::$enabled = FALSE;
  752. exit(255);
  753. }
  754. static function _errorHandler($severity, $message, $file, $line, $context)
  755. {
  756. if (self::$scream) {
  757. error_reporting(E_ALL | E_STRICT);
  758. }
  759. if (self::$lastError !== FALSE && ($severity & error_reporting()) === $severity) {
  760. self::$lastError = new \ErrorException($message, 0, $severity, $file, $line);
  761. return NULL;
  762. }
  763. if ($severity === E_RECOVERABLE_ERROR || $severity === E_USER_ERROR) {
  764. throw new Nette\FatalErrorException($message, 0, $severity, $file, $line, $context);
  765. } elseif (($severity & error_reporting()) !== $severity) {
  766. return FALSE;
  767. } elseif (self::$strictMode && !self::$productionMode) {
  768. self::_exceptionHandler(new Nette\FatalErrorException($message, 0, $severity, $file, $line, $context));
  769. }
  770. static $types = array(
  771. E_WARNING => 'Warning',
  772. E_COMPILE_WARNING => 'Warning',
  773. E_USER_WARNING => 'Warning',
  774. E_NOTICE => 'Notice',
  775. E_USER_NOTICE => 'Notice',
  776. E_STRICT => 'Strict standards',
  777. E_DEPRECATED => 'Deprecated',
  778. E_USER_DEPRECATED => 'Deprecated',
  779. );
  780. $message = 'PHP ' . (isset($types[$severity]) ? $types[$severity] : 'Unknown error') . ": $message";
  781. $count = & self::$errorPanel->data["$message|$file|$line"];
  782. if ($count++) {
  783. return NULL;
  784. } elseif (self::$productionMode) {
  785. self::log("$message in $file:$line", self::ERROR);
  786. return NULL;
  787. } else {
  788. $ok = self::fireLog(new \ErrorException($message, 0, $severity, $file, $line), self::WARNING);
  789. return self::$consoleMode || (!self::$bar && !$ok) ? FALSE : NULL;
  790. }
  791. return FALSE;
  792. }
  793. static function toStringException(\Exception $exception)
  794. {
  795. if (self::$enabled) {
  796. self::_exceptionHandler($exception);
  797. } else {
  798. trigger_error($exception->getMessage(), E_USER_ERROR);
  799. }
  800. }
  801. static function tryError()
  802. {
  803. if (!self::$enabled && self::$lastError === FALSE) {
  804. set_error_handler(array(__CLASS__, '_errorHandler'));
  805. }
  806. self::$lastError = NULL;
  807. }
  808. static function catchError(& $error)
  809. {
  810. if (!self::$enabled && self::$lastError !== FALSE) {
  811. restore_error_handler();
  812. }
  813. $error = self::$lastError;
  814. self::$lastError = FALSE;
  815. return (bool) $error;
  816. }
  817. static function dump($var, $return = FALSE)
  818. {
  819. if (!$return && self::$productionMode) {
  820. return $var;
  821. }
  822. $output = "<pre class=\"nette-dump\">" . Helpers::htmlDump($var) . "</pre>\n";
  823. if (!$return) {
  824. $trace = debug_backtrace();
  825. $i = !isset($trace[1]['class']) && isset($trace[1]['function']) && $trace[1]['function'] === 'dump' ? 1 : 0;
  826. if (isset($trace[$i]['file'], $trace[$i]['line']) && is_file($trace[$i]['file'])) {
  827. $lines = file($trace[$i]['file']);
  828. preg_match('#dump\((.*)\)#', $lines[$trace[$i]['line'] - 1], $m);
  829. $output = substr_replace(
  830. $output,
  831. ' title="' . htmlspecialchars((isset($m[0]) ? "$m[0] \n" : '') . "in file {$trace[$i]['file']} on line {$trace[$i]['line']}") . '"',
  832. 4, 0);
  833. if (self::$showLocation) {
  834. $output = substr_replace(
  835. $output,
  836. ' <small>in ' . Helpers::editorLink($trace[$i]['file'], $trace[$i]['line']) . ":{$trace[$i]['line']}</small>",
  837. -8, 0);
  838. }
  839. }
  840. }
  841. if (self::$consoleMode) {
  842. $output = htmlspecialchars_decode(strip_tags($output), ENT_NOQUOTES);
  843. }
  844. if ($return) {
  845. return $output;
  846. } else {
  847. echo $output;
  848. return $var;
  849. }
  850. }
  851. static function timer($name = NULL)
  852. {
  853. static $time = array();
  854. $now = microtime(TRUE);
  855. $delta = isset($time[$name]) ? $now - $time[$name] : 0;
  856. $time[$name] = $now;
  857. return $delta;
  858. }
  859. static function barDump($var, $title = NULL)
  860. {
  861. if (!self::$productionMode) {
  862. $dump = array();
  863. foreach ((is_array($var) ? $var : array('' => $var)) as $key => $val) {
  864. $dump[$key] = Helpers::clickableDump($val);
  865. }
  866. self::$dumpPanel->data[] = array('title' => $title, 'dump' => $dump);
  867. }
  868. return $var;
  869. }
  870. static function fireLog($message)
  871. {
  872. if (!self::$productionMode) {
  873. return self::$fireLogger->log($message);
  874. }
  875. }
  876. static function addPanel(IBarPanel $panel, $id = NULL)
  877. {
  878. self::$bar->addPanel($panel, $id);
  879. }
  880. }
  881. class Logger extends Nette\Object
  882. {
  883. const DEBUG = 'debug',
  884. INFO = 'info',
  885. WARNING = 'warning',
  886. ERROR = 'error',
  887. CRITICAL = 'critical';
  888. public static $emailSnooze = 172800;
  889. public $mailer = array(__CLASS__, 'defaultMailer');
  890. public $directory;
  891. public $email;
  892. function log($message, $priority = self::INFO)
  893. {
  894. if (!is_dir($this->directory)) {
  895. throw new Nette\DirectoryNotFoundException("Directory '$this->directory' is not found or is not directory.");
  896. }
  897. if (is_array($message)) {
  898. $message = implode(' ', $message);
  899. }
  900. $res = error_log(trim($message) . PHP_EOL, 3, $this->directory . '/' . strtolower($priority) . '.log');
  901. if (($priority === self::ERROR || $priority === self::CRITICAL) && $this->email && $this->mailer
  902. && @filemtime($this->directory . '/email-sent') + self::$emailSnooze < time()
  903. && @file_put_contents($this->directory . '/email-sent', 'sent')
  904. ) {
  905. call_user_func($this->mailer, $message, $this->email);
  906. }
  907. return $res;
  908. }
  909. private static function defaultMailer($message, $email)
  910. {
  911. $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] :
  912. (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '');
  913. $parts = str_replace(
  914. array("\r\n", "\n"),
  915. array("\n", PHP_EOL),
  916. array(
  917. 'headers' => "From: noreply@$host\nX-Mailer: Nette Framework\n",
  918. 'subject' => "PHP: An error occurred on the server $host",
  919. 'body' => "[" . @date('Y-m-d H:i:s') . "] $message",
  920. )
  921. );
  922. mail($email, $parts['subject'], $parts['body'], $parts['headers']);
  923. }
  924. }
  925. class FireLogger extends Nette\Object
  926. {
  927. const DEBUG = 'debug',
  928. INFO = 'info',
  929. WARNING = 'warning',
  930. ERROR = 'error',
  931. CRITICAL = 'critical';
  932. private static $payload = array('logs' => array());
  933. static function log($message, $priority = self::DEBUG)
  934. {
  935. if (!isset($_SERVER['HTTP_X_FIRELOGGER']) || headers_sent()) {
  936. return FALSE;
  937. }
  938. $item = array(
  939. 'name' => 'PHP',
  940. 'level' => $priority,
  941. 'order' => count(self::$payload['logs']),
  942. 'time' => str_pad(number_format((microtime(TRUE) - Debugger::$time) * 1000, 1, '.', ' '), 8, '0', STR_PAD_LEFT) . ' ms',
  943. 'template' => '',
  944. 'message' => '',
  945. 'style' => 'background:#767ab6',
  946. );
  947. $args = func_get_args();
  948. if (isset($args[0]) && is_string($args[0])) {
  949. $item['template'] = array_shift($args);
  950. }
  951. if (isset($args[0]) && $args[0] instanceof \Exception) {
  952. $e = array_shift($args);
  953. $trace = $e->getTrace();
  954. if (isset($trace[0]['class']) && $trace[0]['class'] === 'Nette\Diagnostics\Debugger'
  955. && ($trace[0]['function'] === '_shutdownHandler' || $trace[0]['function'] === '_errorHandler')
  956. ) {
  957. unset($trace[0]);
  958. }
  959. $file = str_replace(dirname(dirname(dirname($e->getFile()))), "\xE2\x80\xA6", $e->getFile());
  960. $item['template'] = ($e instanceof \ErrorException ? '' : get_class($e) . ': ')
  961. . $e->getMessage() . ($e->getCode() ? ' #' . $e->getCode() : '') . ' in ' . $file . ':' . $e->getLine();
  962. $item['pathname'] = $e->getFile();
  963. $item['lineno'] = $e->getLine();
  964. } else {
  965. $trace = debug_backtrace();
  966. if (isset($trace[1]['class']) && $trace[1]['class'] === 'Nette\Diagnostics\Debugger'
  967. && ($trace[1]['function'] === 'fireLog')
  968. ) {
  969. unset($trace[0]);
  970. }
  971. foreach ($trace as $frame) {
  972. if (isset($frame['file']) && is_file($frame['file'])) {
  973. $item['pathname'] = $frame['file'];
  974. $item['lineno'] = $frame['line'];
  975. break;
  976. }
  977. }
  978. }
  979. $item['exc_info'] = array('', '', array());
  980. $item['exc_frames'] = array();
  981. foreach ($trace as $frame) {
  982. $frame += array('file' => NULL, 'line' => NULL, 'class' => NULL, 'type' => NULL, 'function' => NULL, 'object' => NULL, 'args' => NULL);
  983. $item['exc_info'][2][] = array($frame['file'], $frame['line'], "$frame[class]$frame[type]$frame[function]", $frame['object']);
  984. $item['exc_frames'][] = $frame['args'];
  985. }
  986. if (isset($args[0]) && in_array($args[0], array(self::DEBUG, self::INFO, self::WARNING, self::ERROR, self::CRITICAL), TRUE)) {
  987. $item['level'] = array_shift($args);
  988. }
  989. $item['args'] = $args;
  990. self::$payload['logs'][] = self::jsonDump($item, -1);
  991. foreach (str_split(base64_encode(@json_encode(self::$payload)), 4990) as $k => $v) {
  992. header("FireLogger-de11e-$k:$v");
  993. }
  994. return TRUE;
  995. }
  996. private static function jsonDump(&$var, $level = 0)
  997. {
  998. if (is_bool($var) || is_null($var) || is_int($var) || is_float($var)) {
  999. return $var;
  1000. } elseif (is_string($var)) {
  1001. if (Debugger::$maxLen && strlen($var) > Debugger::$maxLen) {
  1002. $var = substr($var, 0, Debugger::$maxLen) . " \xE2\x80\xA6 ";
  1003. }
  1004. return Nette\Utils\Strings::fixEncoding($var);
  1005. } elseif (is_array($var)) {
  1006. static $marker;
  1007. if ($marker === NULL) {
  1008. $marker = uniqid("\x00", TRUE);
  1009. }
  1010. if (isset($var[$marker])) {
  1011. return "\xE2\x80\xA6RECURSION\xE2\x80\xA6";
  1012. } elseif ($level < Debugger::$maxDepth || !Debugger::$maxDepth) {
  1013. $var[$marker] = TRUE;
  1014. $res = array();
  1015. foreach ($var as $k => &$v) {
  1016. if ($k !== $marker) {
  1017. $res[self::jsonDump($k)] = self::jsonDump($v, $level + 1);
  1018. }
  1019. }
  1020. unset($var[$marker]);
  1021. return $res;
  1022. } else {
  1023. return " \xE2\x80\xA6 ";
  1024. }
  1025. } elseif (is_object($var)) {
  1026. $arr = (array) $var;
  1027. static $list = array();
  1028. if (in_array($var, $list, TRUE)) {
  1029. return "\xE2\x80\xA6RECURSION\xE2\x80\xA6";
  1030. } elseif ($level < Debugger::$maxDepth || !Debugger::$maxDepth) {
  1031. $list[] = $var;
  1032. $res = array("\x00" => '(object) ' . get_class($var));
  1033. foreach ($arr as $k => &$v) {
  1034. if ($k[0] === "\x00") {
  1035. $k = substr($k, strrpos($k, "\x00") + 1);
  1036. }
  1037. $res[self::jsonDump($k)] = self::jsonDump($v, $level + 1);
  1038. }
  1039. array_pop($list);
  1040. return $res;
  1041. } else {
  1042. return " \xE2\x80\xA6 ";
  1043. }
  1044. } elseif (is_resource($var)) {
  1045. return "resource " . get_resource_type($var);
  1046. } else {
  1047. return "unknown type";
  1048. }
  1049. }
  1050. }
  1051. class BlueScreen extends Nette\Object
  1052. {
  1053. private $panels = array();
  1054. function addPanel($panel, $id = NULL)
  1055. {
  1056. if ($id === NULL) {
  1057. $this->panels[] = $panel;
  1058. } else {
  1059. $this->panels[$id] = $panel;
  1060. }
  1061. }
  1062. function render(\Exception $exception)
  1063. {
  1064. $panels = $this->panels;
  1065. static $errorTypes = array(
  1066. E_ERROR => 'Fatal Error',
  1067. E_USER_ERROR => 'User Error',
  1068. E_RECOVERABLE_ERROR => 'Recoverable Error',
  1069. E_CORE_ERROR => 'Core Error',
  1070. E_COMPILE_ERROR => 'Compile Error',
  1071. E_PARSE => 'Parse Error',
  1072. E_WARNING => 'Warning',
  1073. E_CORE_WARNING => 'Core Warning',
  1074. E_COMPILE_WARNING => 'Compile Warning',
  1075. E_USER_WARNING => 'User Warning',
  1076. E_NOTICE => 'Notice',
  1077. E_USER_NOTICE => 'User Notice',
  1078. E_STRICT => 'Strict',
  1079. E_DEPRECATED => 'Deprecated',
  1080. E_USER_DEPRECATED => 'User Deprecated',
  1081. );
  1082. $title = ($exception instanceof Nette\FatalErrorException && isset($errorTypes[$exception->getSeverity()])) ? $errorTypes[$exception->getSeverity()] : get_class($exception);
  1083. $expandPath = NETTE_DIR . DIRECTORY_SEPARATOR;
  1084. $counter = 0;
  1085. ?><!-- "' --></script></style></pre></xmp></table>
  1086. <!DOCTYPE html>
  1087. <html>
  1088. <head>
  1089. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  1090. <meta name="robots" content="noindex,noarchive">
  1091. <meta name="generator" content="Nette Framework">
  1092. <title><?php echo htmlspecialchars($title) ?></title><!-- <?php
  1093. $ex = $exception; echo $ex->getMessage(), ($ex->getCode() ? ' #' . $ex->getCode() : '');
  1094. while ((method_exists($ex, 'getPrevious') && $ex = $ex->getPrevious()) || (isset($ex->previous) && $ex = $ex->previous)) echo '; caused by ', get_class($ex), ' ', $ex->getMessage(), ($ex->getCode() ? ' #' . $ex->getCode() : '');
  1095. ?> -->
  1096. <style type="text/css" class="nette">html{overflow-y:scroll}body{margin:0 0 2em;padding:0}#netteBluescreen{font:9pt/1.5 Verdana,sans-serif;background:white;color:#333;position:absolute;left:0;top:0;width:100%;z-index:23178;text-align:left}#netteBluescreen *{font:inherit;color:inherit;background:transparent;border:none;margin:0;padding:0;text-align:inherit;text-indent:0}#netteBluescreen b{font-weight:bold}#netteBluescreen i{font-style:italic}#netteBluescreen a{text-decoration:none;color:#328ADC;padding:2px 4px;margin:-2px -4px}#netteBluescreen a:hover,#netteBluescreen a:active,#netteBluescreen a:focus{color:#085AA3}#netteBluescreen a abbr{font-family:sans-serif;color:#BBB}#netteBluescreenIcon{position:absolute;right:.5em;top:.5em;z-index:23179;text-decoration:none;background:#CD1818;padding:3px}#netteBluescreenError{background:#CD1818;color:white;font:13pt/1.5 Verdana,sans-serif!important;display:block}#netteBluescreenError #netteBsSearch{color:#CD1818;font-size:.7em}#netteBluescreenError:hover #netteBsSearch{color:#ED8383}#netteBluescreen h1{font-size:18pt;font-weight:normal;text-shadow:1px 1px 0 rgba(0,0,0,.4);margin:.7em 0}#netteBluescreen h2{font:14pt/1.5 sans-serif!important;color:#888;margin:.6em 0}#netteBluescreen h3{font:bold 10pt/1.5 Verdana,sans-serif!important;margin:1em 0;padding:0}#netteBluescreen p,#netteBluescreen pre{margin:.8em 0}#netteBluescreen pre,#netteBluescreen code,#netteBluescreen table{font:9pt/1.5 Consolas,monospace!important}#netteBluescreen pre,#netteBluescreen table{background:#FDF5CE;padding:.4em .7em;border:1px dotted silver;overflow:auto}#netteBluescreen table pre{padding:0;margin:0;border:none}#netteBluescreen pre.nette-dump span{color:#C22}#netteBluescreen pre.nette-dump a{color:#333}#netteBluescreen div.panel{padding:1px 25px}#netteBluescreen div.inner{background:#F4F3F1;padding:.1em 1em 1em;border-radius:8px;-moz-border-radius:8px;-webkit-border-radius:8px}#netteBluescreen table{border-collapse:collapse;width:100%}#netteBluescreen .outer{overflow:auto}#netteBluescreen td,#netteBluescreen th{vertical-align:top;text-align:left;padding:2px 6px;border:1px solid #e6dfbf}#netteBluescreen th{width:10%;font-weight:bold}#netteBluescreen tr:nth-child(2n),#netteBluescreen tr:nth-child(2n) pre{background-color:#F7F0CB}#netteBluescreen ol{margin:1em 0;padding-left:2.5em}#netteBluescreen ul{font:7pt/1.5 Verdana,sans-serif!important;padding:2em 4em;margin:1em 0 0;color:#777;background:#F6F5F3 url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFEAAAAjCAMAAADbuxbOAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADBQTFRF/fz24d7Y7Onj5uLd9vPu3drUzMvG09LN39zW8e7o2NbQ3NnT29jS0M7J1tXQAAAApvmsFgAAABB0Uk5T////////////////////AOAjXRkAAAKlSURBVHja7FbbsqQgDAwENEgc//9vN+SCWDtbtXPmZR/Wc6o02mlC58LA9ckFAOszvMV8xNgyUjyXhojfMVKvRL0ZHavxXYy5JrmchMdzou8YlTClxajtK8ZGGpWRoBr1+gFjKfHkJPbizabLgzE3pH7Iu4K980xgFvlrVzMZoVBWhtvouCDdcTDmTgMCJdVxJ9MKO6XxnliM7hxi5lbj2ZVM4l8DqYyKoNLYcfqBB1/LpHYxEcfVG6ZpMDgyFUVWY/Q1sSYPpIdSAKWqLWL0XqWiMWc4hpH0OQOMOAgdycY4N9Sb7wWANQs3rsDSdLAYiuxi5siVfOhBWIrtH0G3kNaF/8Q4kCPE1kMucG/ZMUBUCOgiKJkPuWWTLGVgLGpwns1DraUayCtoBqERyaYtVsm85NActRooezvSLO/sKZP/nq8n4+xcyjNsRu8zW6KWpdb7wjiQd4WrtFZYFiKHENSmWp6xshh96c2RQ+c7Lt+qbijyEjHWUJ/pZsy8MGIUuzNiPySK2Gqoh6ZTRF6ko6q3nVTkaA//itIrDpW6l3SLo8juOmqMXkYknu5FdQxWbhCfKHEGDhxxyTVaXJF3ZjSl3jMksjSOOKmne9pI+mcG5QvaUJhI9HpkmRo2NpCrDJvsktRhRE2MM6F2n7dt4OaMUq8bCctk0+PoMRzL+1l5PZ2eyM/Owr86gf8z/tOM53lom5+nVcFuB+eJVzlXwAYy9TZ9s537tfqcsJWbEU4nBngZo6FfO9T9CdhfBtmk2dLiAy8uS4zwOpMx2HqYbTC+amNeAYTpsP4SIgvWfUBWXxn3CMHW3ffd7k3+YIkx7w0t/CVGvcPejoeOlzOWzeGbawOHqXQGUTMZRcfj4XPCgW9y/fuvVn8zD9P1QHzv80uAAQA0i3Jer7Jr7gAAAABJRU5ErkJggg==') 99% 10px no-repeat;border-top:1px solid #DDD}#netteBluescreen .highlight{background:#CD1818;color:white;font-weight:bold;font-style:normal;display:table;padding:0 .4em;margin:0 -.4em}#netteBluescreen .line{color:#9F9C7F;font-weight:normal;font-style:normal}#netteBluescreen a[href^=editor\:]{color:inherit;border-bottom:1px dotted #C1D2E1}</style>
  1097. </head>
  1098. <body>
  1099. <div id="netteBluescreen">
  1100. <a id="netteBluescreenIcon" href="#" rel="next"><abbr>&#x25bc;</abbr></a
  1101. ><div>
  1102. <div id="netteBluescreenError" class="panel">
  1103. <h1><?php echo htmlspecialchars($title), ($exception->getCode() ? ' #' . $exception->getCode() : '') ?></h1>
  1104. <p><?php echo htmlspecialchars($exception->getMessage()) ?> <a href="http://www.google.cz/search?sourceid=nette&amp;q=<?php echo urlencode($title . ' ' . preg_replace('#\'.*\'|".*"#Us', '', $exception->getMessage())) ?>" id="netteBsSearch">search&#x25ba;</a></p>
  1105. </div>
  1106. <?php $ex = $exception; $level = 0; ?>
  1107. <?php do { ?>
  1108. <?php if ($level++): ?>
  1109. <div class="panel">
  1110. <h2><a href="#" rel="netteBsPnl<?php echo ++$counter ?>">Caused by <abbr><?php echo ($collapsed = $level > 2) ? '&#x25ba;' : '&#x25bc;' ?></abbr></a></h2>
  1111. <div id="netteBsPnl<?php echo $counter ?>" class="<?php echo $collapsed ? 'nette-collapsed ' : '' ?>inner">
  1112. <div class="panel">
  1113. <h1><?php echo htmlspecialchars(get_class($ex)), ($ex->getCode() ? ' #' . $ex->getCode() : '') ?></h1>
  1114. <p><b><?php echo htmlspecialchars($ex->getMessage()) ?></b></p>
  1115. </div>
  1116. <?php endif ?>
  1117. <?php foreach ($panels as $panel): ?>
  1118. <?php $panel = call_user_func($panel, $ex); if (empty($panel['tab']) || empty($panel['panel'])) continue; ?>
  1119. <div class="panel">
  1120. <h2><a href="#" rel="netteBsPnl<?php echo ++$counter ?>"><?php echo htmlSpecialChars($panel['tab']) ?> <abbr>&#x25bc;</abbr></a></h2>
  1121. <div id="netteBsPnl<?php echo $counter ?>" class="inner">
  1122. <?php echo $panel['panel'] ?>
  1123. </div></div>
  1124. <?php endforeach ?>
  1125. <?php $stack = $ex->getTrace(); $expanded = NULL ?>
  1126. <?php if (strpos($ex->getFile(), $expandPath) === 0) {
  1127. foreach ($stack as $key => $row) {
  1128. if (isset($row['file']) && strpos($row['file'], $expandPath) !== 0) { $expanded = $key; break; }
  1129. }
  1130. } ?>
  1131. <div class="panel">
  1132. <h2><a href="#" rel="netteBsPnl<?php echo ++$counter ?>">Source file <abbr><?php echo ($collapsed = $expanded !== NULL) ? '&#x25ba;' : '&#x25bc;' ?></abbr></a></h2>
  1133. <div id="netteBsPnl<?php echo $counter ?>" class="<?php echo $collapsed ? 'nette-collapsed ' : '' ?>inner">
  1134. <p><b>File:</b> <?php echo Helpers::editorLink($ex->getFile(), $ex->getLine()) ?> &nbsp; <b>Line:</b> <?php echo $ex->getLine() ?></p>
  1135. <?php if (is_file($ex->getFile())): ?><pre><?php echo self::highlightFile($ex->getFile(), $ex->getLine(), 15, isset($ex->context) ? $ex->context : NULL) ?></pre><?php endif ?>
  1136. </div></div>
  1137. <?php if (isset($stack[0]['class']) && $stack[0]['class'] === 'Nette\Diagnostics\Debugger' && ($stack[0]['function'] === '_shutdownHandler' || $stack[0]['function'] === '_errorHandler')) unset($stack[0]) ?>
  1138. <?php if ($stack): ?>
  1139. <div class="panel">
  1140. <h2><a href="#" rel="netteBsPnl<?php echo ++$counter ?>">Call stack <abbr>&#x25bc;</abbr></a></h2>
  1141. <div id="netteBsPnl<?php echo $counter ?>" class="inner">
  1142. <ol>
  1143. <?php foreach ($stack as $key => $row): ?>
  1144. <li><p>
  1145. <?php if (isset($row['file']) && is_file($row['file'])): ?>
  1146. <?php echo Helpers::editorLink($row['file'], $row['line']), ':', $row['line'] ?>
  1147. <?php else: ?>
  1148. <i>inner-code</i><?php if (isset($row['line'])) echo ':', $row['line'] ?>
  1149. <?php endif ?>
  1150. <?php if (isset($row['file']) && is_file($row['file'])): ?><a href="#" rel="netteBsSrc<?php echo "$level-$key" ?>">source <abbr>&#x25ba;</abbr></a>&nbsp; <?php endif ?>
  1151. <?php if (isset($row['class'])) echo $row['class'] . $row['type'] ?>
  1152. <?php echo $row['function'] ?>
  1153. (<?php if (!empty($row['args'])): ?><a href="#" rel="netteBsArgs<?php echo "$level-$key" ?>">arguments <abbr>&#x25ba;</abbr></a><?php endif ?>)
  1154. </p>
  1155. <?php if (!empty($row['args'])): ?>
  1156. <div class="nette-collapsed outer" id="netteBsArgs<?php echo "$level-$key" ?>">
  1157. <table>
  1158. <?php
  1159. try {
  1160. $r = isset($row['class']) ? new \ReflectionMethod($row['class'], $row['function']) : new \ReflectionFunction($row['function']);
  1161. $params = $r->getParameters();
  1162. } catch (\Exception $e) {
  1163. $params = array();
  1164. }
  1165. foreach ($row['args'] as $k => $v) {
  1166. echo '<tr><th>', (isset($params[$k]) ? '$' . $params[$k]->name : "#$k"), '</th><td>';
  1167. echo Helpers::clickableDump($v);
  1168. echo "</td></tr>\n";
  1169. }
  1170. ?>
  1171. </table>
  1172. </div>
  1173. <?php endif ?>
  1174. <?php if (isset($row['file']) && is_file($row['file'])): ?>
  1175. <pre <?php if ($expanded !== $key) echo 'class="nette-collapsed"'; ?> id="netteBsSrc<?php echo "$level-$key" ?>"><?php echo self::highlightFile($row['file'], $row['line']) ?></pre>
  1176. <?php endif ?>
  1177. </li>
  1178. <?php endforeach ?>
  1179. </ol>
  1180. </div></div>
  1181. <?php endif ?>
  1182. <?php if (isset($ex->context) && is_array($ex->context)):?>
  1183. <div class="panel">
  1184. <h2><a href="#" rel="netteBsPnl<?php echo ++$counter ?>">Variables <abbr>&#x25ba;</abbr></a></h2>
  1185. <div id="netteBsPnl<?php echo $counter ?>" class="nette-collapsed inner">
  1186. <div class="outer">
  1187. <table>
  1188. <?php
  1189. foreach ($ex->context as $k => $v) {
  1190. echo '<tr><th>$', htmlspecialchars($k), '</th><td>', Helpers::clickableDump($v), "</td></tr>\n";
  1191. }
  1192. ?>
  1193. </table>
  1194. </div>
  1195. </div></div>
  1196. <?php endif ?>
  1197. <?php } while ((method_exists($ex, 'getPrevious') && $ex = $ex->getPrevious()) || (isset($ex->previous) && $ex = $ex->previous)); ?>
  1198. <?php while (--$level) echo '</div></div>' ?>
  1199. <?php foreach ($panels as $panel): ?>
  1200. <?php $panel = call_user_func($panel, NULL); if (empty($panel['tab']) || empty($panel['panel'])) continue; ?>
  1201. <div class="panel">
  1202. <h2><a href="#" rel="netteBsPnl<?php echo ++$counter ?>"><?php echo htmlSpecialChars($panel['tab']) ?> <abbr>&#x25ba;</abbr></a></h2>
  1203. <div id="netteBsPnl<?php echo $counter ?>" class="nette-collapsed inner">
  1204. <?php echo $panel['panel'] ?>
  1205. </div></div>
  1206. <?php endforeach ?>
  1207. <div class="panel">
  1208. <h2><a href="#" rel="netteBsPnl<?php echo ++$counter ?>">Environment <abbr>&#x25ba;</abbr></a></h2>
  1209. <div id="netteBsPnl<?php echo $counter ?>" class="nette-collapsed inner">
  1210. <?php
  1211. $list = get_defined_constants(TRUE);
  1212. if (!empty($list['user'])):?>
  1213. <h3><a href="#" rel="netteBsPnl-env-const">Constants <abbr>&#x25bc;</abbr></a></h3>
  1214. <div class="outer">
  1215. <table id="netteBsPnl-env-const">
  1216. <?php
  1217. foreach ($list['user'] as $k => $v) {
  1218. echo '<tr><th>', htmlspecialchars($k), '</th>';
  1219. echo '<td>', Helpers::clickableDump($v), "</td></tr>\n";
  1220. }
  1221. ?>
  1222. </table>
  1223. </div>
  1224. <?php endif ?>
  1225. <h3><a href="#" rel="netteBsPnl-env-files">Included files <abbr>&#x25ba;</abbr></a> (<?php echo count(get_included_files()) ?>)</h3>
  1226. <div class="outer">
  1227. <table id="netteBsPnl-env-files" class="nette-collapsed">
  1228. <?php
  1229. foreach (get_included_files() as $v) {
  1230. echo '<tr><td>', htmlspecialchars($v), "</td></tr>\n";
  1231. }
  1232. ?>
  1233. </table>
  1234. </div>
  1235. <h3>$_SERVER</h3>
  1236. <?php if (empty($_SERVER)):?>
  1237. <p><i>empty</i></p>
  1238. <?php else: ?>
  1239. <div class="outer">
  1240. <table>
  1241. <?php
  1242. foreach ($_SERVER as $k => $v) echo '<tr><th>', htmlspecialchars($k), '</th><td>', Helpers::clickableDump($v), "</td></tr>\n";
  1243. ?>
  1244. </table>
  1245. </div>
  1246. <?php endif ?>
  1247. </div></div>
  1248. <div class="panel">
  1249. <h2><a href="#" rel="netteBsPnl<?php echo ++$counter ?>">HTTP request <abbr>&#x25ba;</abbr></a></h2>
  1250. <div id="netteBsPnl<?php echo $counter ?>" class="nette-collapsed inner">
  1251. <?php if (function_exists('apache_request_headers')): ?>
  1252. <h3>Headers</h3>
  1253. <div class="outer">
  1254. <table>
  1255. <?php
  1256. foreach (apache_request_headers() as $k => $v) echo '<tr><th>', htmlspecialchars($k), '</th><td>', htmlspecialchars($v), "</td></tr>\n";
  1257. ?>
  1258. </table>
  1259. </div>
  1260. <?php endif ?>
  1261. <?php foreach (array('_GET', '_POST', '_COOKIE') as $name): ?>
  1262. <h3>$<?php echo $name ?></h3>
  1263. <?php if (empty($GLOBALS[$name])):?>
  1264. <p><i>empty</i></p>
  1265. <?php else: ?>
  1266. <div class="outer">
  1267. <table>
  1268. <?php
  1269. foreach ($GLOBALS[$name] as $k => $v) echo '<tr><th>', htmlspecialchars($k), '</th><td>', Helpers::clickableDump($v), "</td></tr>\n";
  1270. ?>
  1271. </table>
  1272. </div>
  1273. <?php endif ?>
  1274. <?php endforeach ?>
  1275. </div></div>
  1276. <div class="panel">
  1277. <h2><a href="#" rel="netteBsPnl<?php echo ++$counter ?>">HTTP response <abbr>&#x25ba;</abbr></a></h2>
  1278. <div id="netteBsPnl<?php echo $counter ?>" class="nette-collapsed inner">
  1279. <h3>Headers</h3>
  1280. <?php if (headers_list()): ?>
  1281. <pre><?php
  1282. foreach (headers_list() as $s) echo htmlspecialchars($s), '<br>';
  1283. ?></pre>
  1284. <?php else: ?>
  1285. <p><i>no headers</i></p>
  1286. <?php endif ?>
  1287. </div></div>
  1288. <ul>
  1289. <li>Report generated at <?php echo @date('Y/m/d H:i:s', Debugger::$time) ?></li>
  1290. <?php if (preg_match('#^https?://#', Debugger::$source)): ?>
  1291. <li><a href="<?php echo htmlSpecialChars(Debugger::$source) ?>"><?php echo htmlSpecialChars(Debugger::$source) ?></a></li>
  1292. <?php elseif (Debugger::$source): ?>
  1293. <li><?php echo htmlSpecialChars(Debugger::$source) ?></li>
  1294. <?php endif ?>
  1295. <li>PHP <?php echo htmlSpecialChars(PHP_VERSION) ?></li>
  1296. <?php if (isset($_SERVER['SERVER_SOFTWARE'])): ?><li><?php echo htmlSpecialChars($_SERVER['SERVER_SOFTWARE']) ?></li><?php endif ?>
  1297. <?php if (class_exists('Nette\Framework')): ?><li><?php echo htmlSpecialChars('Nette Framework ' . Nette\Framework::VERSION) ?> <i>(revision <?php echo htmlSpecialChars(Nette\Framework::REVISION) ?>)</i></li><?php endif ?>
  1298. </ul>
  1299. </div>
  1300. </div>
  1301. <script type="text/javascript">/*<![CDATA[*/var bs=document.getElementById("netteBluescreen");document.body.appendChild(bs);document.onkeyup=function(b){b=b||window.event;b.keyCode==27&&!b.shiftKey&&!b.altKey&&!b.ctrlKey&&!b.metaKey&&bs.onclick({target:document.getElementById("netteBluescreenIcon")})};
  1302. for(var i=0,styles=document.styleSheets;i<styles.length;i++)if((styles[i].owningElement||styles[i].ownerNode).className!=="nette"){styles[i].oldDisabled=styles[i].disabled;styles[i].disabled=true}else styles[i].addRule?styles[i].addRule(".nette-collapsed","display: none"):styles[i].insertRule(".nette-collapsed { display: none }",0);
  1303. bs.onclick=function(b){b=b||window.event;for(var a=b.target||b.srcElement;a&&a.tagName&&a.tagName.toLowerCase()!=="a";)a=a.parentNode;if(!a||!a.rel)return true;for(var d=a.getElementsByTagName("abbr")[0],c=a.rel==="next"?a.nextSibling:document.getElementById(a.rel);c.nodeType!==1;)c=c.nextSibling;b=c.currentStyle?c.currentStyle.display=="none":getComputedStyle(c,null).display=="none";try{d.innerHTML=String.fromCharCode(b?9660:9658)}catch(e){}c.style.display=b?c.tagName.toLowerCase()==="code"?"inline":
  1304. "block":"none";if(a.id==="netteBluescreenIcon"){a=0;for(d=document.styleSheets;a<d.length;a++)if((d[a].owningElement||d[a].ownerNode).className!=="nette")d[a].disabled=b?true:d[a].oldDisabled}return false};/*]]>*/</script>
  1305. </body>
  1306. </html>
  1307. <?php
  1308. }
  1309. static function highlightFile($file, $line, $count = 15, $vars = array())
  1310. {
  1311. if (function_exists('ini_set')) {
  1312. ini_set('highlight.comment', '#999; font-style: italic');
  1313. ini_set('highlight.default', '#000');
  1314. ini_set('highlight.html', '#06B');
  1315. ini_set('highlight.keyword', '#D24; font-weight: bold');
  1316. ini_set('highlight.string', '#080');
  1317. }
  1318. $start = max(1, $line - floor($count / 2));
  1319. $source = @file_get_contents($file);
  1320. if (!$source) {
  1321. return;
  1322. }
  1323. $source = explode("\n", highlight_string($source, TRUE));
  1324. $spans = 1;
  1325. $out = $source[0];
  1326. $source = explode('<br />', $source[1]);
  1327. array_unshift($source, NULL);
  1328. $i = $start;
  1329. while (--$i >= 1) {
  1330. if (preg_match('#.*(</?span[^>]*>)#', $source[$i], $m)) {
  1331. if ($m[1] !== '</span>') {
  1332. $spans++; $out .= $m[1];
  1333. }
  1334. break;
  1335. }
  1336. }
  1337. $source = array_slice($source, $start, $count, TRUE);
  1338. end($source);
  1339. $numWidth = strlen((string) key($source));
  1340. foreach ($source as $n => $s) {
  1341. $spans += substr_count($s, '<span') - substr_count($s, '</span');
  1342. $s = str_replace(array("\r", "\n"), array('', ''), $s);
  1343. preg_match_all('#<[^>]+>#', $s, $tags);
  1344. if ($n === $line) {
  1345. $out .= sprintf(
  1346. "<span class='highlight'>%{$numWidth}s: %s\n</span>%s",
  1347. $n,
  1348. strip_tags($s),
  1349. implode('', $tags[0])
  1350. );
  1351. } else {
  1352. $out .= sprintf("<span class='line'>%{$numWidth}s:</span> %s\n", $n, $s);
  1353. }
  1354. }
  1355. $out .= str_repeat('</span>', $spans) . '</code>';
  1356. $out = preg_replace_callback('#">\$(\w+)(&nbsp;)?</span>#', function($m) use($vars) {
  1357. return isset($vars[$m[1]])
  1358. ? '" title="' . str_replace('"', '&quot;', strip_tags(Helpers::htmlDump($vars[$m[1]]))) . $m[0]
  1359. : $m[0];
  1360. }, $out);
  1361. return $out;
  1362. }
  1363. }
  1364. class Bar extends Nette\Object
  1365. {
  1366. private $panels = array();
  1367. function addPanel(IBarPanel $panel, $id = NULL)
  1368. {
  1369. if ($id === NULL) {
  1370. $c = 0;
  1371. do {
  1372. $id = get_class($panel) . ($c++ ? "-$c" : '');
  1373. } while (isset($this->panels[$id]));
  1374. }
  1375. $this->panels[$id] = $panel;
  1376. }
  1377. function render()
  1378. {
  1379. $panels = array();
  1380. foreach ($this->panels as $id => $panel) {
  1381. try {
  1382. $panels[] = array(
  1383. 'id' => preg_replace('#[^a-z0-9]+#i', '-', $id),
  1384. 'tab' => $tab = (string) $panel->getTab(),
  1385. 'panel' => $tab ? (string) $panel->getPanel() : NULL,
  1386. );
  1387. } catch (\Exception $e) {
  1388. $panels[] = array(
  1389. 'id' => "error-$id",
  1390. 'tab' => "Error: $id",
  1391. 'panel' => nl2br(htmlSpecialChars((string) $e)),
  1392. );
  1393. }
  1394. }
  1395. ?>
  1396. <!-- Nette Debug Bar -->
  1397. <?php ob_start() ?>
  1398. &nbsp;
  1399. <style id="nette-debug-style" class="nette">#nette-debug{display:none;position:fixed}body#nette-debug{margin:5px 5px 0;display:block}#nette-debug *{font:inherit;color:inherit;background:transparent;margin:0;padding:0;border:none

Large files files are truncated, but you can click here to view the full file