PageRenderTime 61ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/webcore/webcore.web.php

#
PHP | 2840 lines | 1581 code | 298 blank | 961 comment | 114 complexity | abb435e1948727a2e20de1d52ac286c2 MD5 | raw file

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

  1. <?php
  2. /**
  3. * @package WebCore
  4. * @subpackage Web
  5. *
  6. *
  7. *
  8. * @author Mario Di Vece <mario@unosquare.com>
  9. * @author Geovanni Perez <geovanni.perez@unosquare.com>
  10. * @copyright Copyright (c) 2008-2009, Author(s) above
  11. */
  12. require_once "webcore.php";
  13. require_once "webcore.imaging.php";
  14. /**
  15. * All Http handlers must implement this interface.
  16. * @package WebCore
  17. * @subpackage Web
  18. */
  19. interface IHttpHandler extends IObject
  20. {
  21. function handleRequest();
  22. }
  23. /**
  24. * Defines the methods required for a session handler.
  25. * @package WebCore
  26. * @subpackage Web
  27. */
  28. interface ISessionHandler extends ISingleton
  29. {
  30. /**
  31. * @param string $savePath
  32. * @param string $sessionName
  33. * @return bool
  34. */
  35. public static function open($savePath, $sessionName);
  36. /**
  37. * @return bool
  38. */
  39. public static function close();
  40. /**
  41. * @param string $sessionId
  42. * @return string
  43. */
  44. public static function read($sessionId);
  45. /**
  46. * @param string $sessionId
  47. * @param string $sessionData
  48. * @return bool
  49. */
  50. public static function write($sessionId, $sessionData);
  51. /**
  52. * @param string $sessionId
  53. * @return bool
  54. */
  55. public static function destroy($sessionId);
  56. /**
  57. * @param int $maxLifetime the number of seconds the session exists for
  58. * @return bool
  59. */
  60. public static function gc($maxLifetime);
  61. }
  62. /**
  63. * Cookie management singleton.
  64. * @todo Create CookieContainer class to match path and domain otherwise deleteCookie does not work!
  65. * @package WebCore
  66. * @subpackage Web
  67. */
  68. class CookieManager extends SerializableObjectBase implements ISingleton
  69. {
  70. /**
  71. * Represents the instance of the singleton object
  72. *
  73. * @var CookieManager
  74. */
  75. protected static $__instance = null;
  76. /**
  77. * @var KeyedCollection
  78. */
  79. protected static $__internalCollection;
  80. /**
  81. * Creates a new instance of this class.
  82. */
  83. protected function __construct()
  84. {
  85. self::$__internalCollection = new KeyedCollectionWrapper($_COOKIE, false);
  86. }
  87. /**
  88. * Gets a unique cookie key based on it name, path, and domain.
  89. * @param string $name
  90. * @param string $path
  91. * @param string $domain
  92. */
  93. protected static function getCookieId($name, $path, $domain)
  94. {
  95. return $domain . $path . $name;
  96. }
  97. /**
  98. * Sets or registers a cookie value given its identifier and value.
  99. * @param string $name
  100. * @param mixed $value
  101. * @param string $path Specify an empty string to make this cookie valid only for the current folder.
  102. * @param string $domain Leave empty to specify the cookie is valid for the entire domain.
  103. * @param string $expires The UNIX string representation of a time. The expiration timestamp is calculated using the strtotime function.
  104. * @param bool $secure
  105. * @param bool $httpOnly Prevents access to the cookie on the client-side (i.e. XSS attacks)
  106. * @return bool Returns true if the cookie was successfully set.
  107. */
  108. public function setCookie($name, $value, $path = '/', $domain = '', $expires = '+30 days', $secure = false, $httpOnly = false)
  109. {
  110. $cookieId = self::getCookieId($name, $path, $domain);
  111. return setcookie($cookieId, $value, strtotime($expires), $path, $domain, $secure, $httpOnly);
  112. }
  113. /**
  114. * Deletes the cookie given its name, path and domain.
  115. * Note that the path and domain must match the original intended cookie for this method to not throw an exception.
  116. * @param string $name
  117. * @param string $path
  118. * @param string $domain
  119. * @return bool Returns true if the cookie was successfully deleted (an expiration time in the past is set).
  120. */
  121. public function deleteCookie($name, $path = '/', $domain = '')
  122. {
  123. $cookieId = self::getCookieId($name, $path, $domain);
  124. if (!$this->isCookieSet($name, $path, $domain))
  125. throw new SystemException(SystemException::EX_INVALIDKEY, "Could not delete cookie with id '$cookieId'. It does not exist.");
  126. $this->getCookies()->removeItem($cookieId);
  127. return setcookie($cookieId, '', 1, $path, $domain);
  128. }
  129. /**
  130. * Gets the value stored within a cookie.
  131. * @param string $name The name of the cookie
  132. * @param string $path The path for which the cookie is valid.
  133. * @param string $domain The domain for which the cookie is available.
  134. *
  135. * @return mixed
  136. */
  137. public function getCookieValue($name, $path = '/', $domain = '')
  138. {
  139. $cookieId = self::getCookieId($name, $path, $domain);
  140. return $this->getCookies()->getValue($cookieId);
  141. }
  142. /**
  143. * Provides direct access to the cookies collection.
  144. * Use the provided cookie methods instead for better cookie management.
  145. * @return KeyedCollection
  146. */
  147. public function getCookies()
  148. {
  149. return self::$__internalCollection;
  150. }
  151. /**
  152. * Determines whether the cokkie with a given name has been set.
  153. * @return bool
  154. */
  155. public function isCookieSet($name, $path = '/', $domain = '')
  156. {
  157. $cookieId = self::getCookieId($name, $path, $domain);
  158. return $this->getCookies()->keyExists($cookieId);
  159. }
  160. /**
  161. * Creates a default instance of this class.
  162. * @return CookieManager
  163. */
  164. public static function createInstance()
  165. {
  166. return self::getInstance();
  167. }
  168. /**
  169. * Gets the singleton instance for this class
  170. *
  171. * @return CookieManager
  172. */
  173. public static function getInstance()
  174. {
  175. if (self::isLoaded() === false)
  176. self::$__instance = new CookieManager();
  177. return self::$__instance;
  178. }
  179. /**
  180. * Determines whether the singleton has loaded its instance
  181. *
  182. * @return bool
  183. */
  184. public static function isLoaded()
  185. {
  186. if (is_null(self::$__instance))
  187. return false;
  188. return true;
  189. }
  190. }
  191. /**
  192. * Provides a database-agnostic session handler.
  193. * This session ehandler expects a table structure accessible from the data context.
  194. * WARNING: If the table is not found, it will be automatically created
  195. * Tabe Name: AppSessions (use setDbTableName to change this before calling the HttpContext::initialize method)
  196. * Column: SessionId VARCHAR(255), Primary key
  197. * Column: SessionData Text
  198. * Column: SessionExpires Int32
  199. * Standard ISO SQL command
  200. * CREATE TABLE AppSessions (
  201. SessionId varchar(255) NOT NULL,
  202. SessionData text NOT NULL,
  203. SessionExpires int NOT NULL,
  204. PRIMARY KEY (SessionId)
  205. )
  206. * @package WebCore
  207. * @subpackage Web
  208. */
  209. class DatabaseSessionHandler implements ISessionHandler
  210. {
  211. const DB_TABLENAME = 'AppSessions';
  212. private static $dbTableName = self::DB_TABLENAME;
  213. /**
  214. * Gets the database table name on which sessions are stored
  215. */
  216. public static function getDbTableName()
  217. {
  218. return self::$dbTableName;
  219. }
  220. /**
  221. * Sets the database table name on which sessions are stored
  222. */
  223. public static function setDbTableName($value)
  224. {
  225. self::$dbTableName = $value;
  226. }
  227. /**
  228. * Gets whether the instance of this singleton has been loaded.
  229. * @return bool
  230. */
  231. public static function isLoaded()
  232. {
  233. return true;
  234. }
  235. /**
  236. * Gets the instance of this singleton
  237. * @return eAcceleratorSessionHandler
  238. */
  239. public static function getInstance()
  240. {
  241. return new DatabaseSessionHandler();
  242. }
  243. /**
  244. * Gets the reflectionclass for this type.
  245. * @return ReflectionClass
  246. */
  247. public function getType()
  248. {
  249. return ReflectionClass(__CLASS__);
  250. }
  251. /**
  252. * @param string $savePath
  253. * @param string $sessionName
  254. * @return bool
  255. */
  256. public static function open($savePath, $sessionName)
  257. {
  258. $originalLogLevel = LogManager::getLogLevel();
  259. LogManager::setLogLevel(LogManager::LOG_LEVEL_DISABLED);
  260. $found = false;
  261. $foundCol = new IndexedCollection();
  262. try
  263. {
  264. $sql = "SELECT * FROM information_schema.tables WHERE TABLE_NAME LIKE ?";
  265. $command = DataContext::getInstance()->getConnection()->createCommand();
  266. $command->setCommandText($sql);
  267. $command->addQuotedParam('tableName', self::getDbTableName());
  268. $foundCol = DataContext::getInstance()->executeQuery($command);
  269. }
  270. catch (Exception $ex)
  271. {
  272. $exString = "<pre>DatabseSessionHandler Exception\nA default database needs to be configured in the app.settings file.\n"
  273. . $ex->getLine() . " on '" . $ex->getFile() . "'\n"
  274. . $ex->getCode() . ": " . $ex->getMessage() . "\nStack Trace:\n" . $ex->getTraceAsString() . "</pre>";
  275. LogManager::setLogLevel($originalLogLevel);
  276. HttpResponse::write($exString);
  277. HttpResponse::end();
  278. return false;
  279. }
  280. $found = $foundCol->getCount() > 0;
  281. if (!$found)
  282. {
  283. $quotedTableName = DataContext::getInstance()->getConnection()->quoteIdentifier(self::getDbTableName());
  284. $sql = "CREATE TABLE $quotedTableName ( SessionId varchar(255) NOT NULL, SessionData text NOT NULL, SessionExpires int NOT NULL, PRIMARY KEY (SessionId) )";
  285. $command = DataContext::getInstance()->getConnection()->createCommand();
  286. $command->setCommandText($sql);
  287. $sessionData = DataContext::getInstance()->executeNonQuery($command);
  288. }
  289. LogManager::setLogLevel($originalLogLevel);
  290. return true;
  291. }
  292. /**
  293. * @return bool
  294. */
  295. public static function close()
  296. {
  297. return true;
  298. }
  299. /**
  300. * @param string $sessionId
  301. * @return string
  302. */
  303. public static function read($sessionId)
  304. {
  305. $originalLogLevel = LogManager::getLogLevel();
  306. LogManager::setLogLevel(LogManager::LOG_LEVEL_DISABLED);
  307. try
  308. {
  309. $quotedTableName = DataContext::getInstance()->getConnection()->quoteIdentifier(self::getDbTableName());
  310. $sql = "SELECT SessionData FROM $quotedTableName WHERE SessionId = ?";
  311. $command = DataContext::getInstance()->getConnection()->createCommand();
  312. $command->setCommandText($sql);
  313. $command->addQuotedParam('sessionId', $sessionId);
  314. $sessionData = DataContext::getInstance()->executeScalar($command);
  315. if (is_null($sessionData))
  316. {
  317. LogManager::setLogLevel($originalLogLevel);
  318. return '';
  319. }
  320. else
  321. {
  322. LogManager::setLogLevel($originalLogLevel);
  323. return base64_decode($sessionData);
  324. }
  325. }
  326. catch (Exception $ex)
  327. {
  328. $exString = "<pre>DatabseSessionHandler Exception\nUnable to read session record from database.\n"
  329. . $ex->getLine() . " on '" . $ex->getFile() . "'\n"
  330. . $ex->getCode() . ": " . $ex->getMessage() . "\nStack Trace:\n" . $ex->getTraceAsString() . "</pre>";
  331. LogManager::setLogLevel($originalLogLevel);
  332. HttpResponse::write($exString);
  333. HttpResponse::end();
  334. return null;
  335. }
  336. }
  337. /**
  338. * Writes session data to the database
  339. * @param string $sessionId
  340. * @param string $sessionData
  341. * @return bool
  342. */
  343. public static function write($sessionId, $sessionData)
  344. {
  345. $originalLogLevel = LogManager::getLogLevel();
  346. LogManager::setLogLevel(LogManager::LOG_LEVEL_DISABLED);
  347. try
  348. {
  349. $quotedTableName = DataContext::getInstance()->getConnection()->quoteIdentifier(self::getDbTableName());
  350. $sql = "SELECT COUNT(*) AS __COUNT__ FROM $quotedTableName WHERE SessionId = ?";
  351. $command = DataContext::getInstance()->getConnection()->createCommand();
  352. $command->setCommandText($sql);
  353. $command->addQuotedParam('sessionId', $sessionId);
  354. $foundSession = DataContext::getInstance()->executeScalar($command);
  355. $command = DataContext::getInstance()->getConnection()->createCommand();
  356. if ($foundSession == '0')
  357. {
  358. $sql = "INSERT INTO $quotedTableName (SessionId, SessionData, SessionExpires) VALUES (?, ?, ?)";
  359. $command->addQuotedParam('sessionId', $sessionId);
  360. $command->addQuotedParam('sessionData', base64_encode($sessionData));
  361. $command->addQuotedParam('sessionExpires', time());
  362. }
  363. else
  364. {
  365. $sql = "UPDATE $quotedTableName SET SessionData = ?, SessionExpires = ? WHERE SessionId = ?";
  366. $command->addQuotedParam('sessionData', base64_encode($sessionData));
  367. $command->addQuotedParam('sessionExpires', time());
  368. $command->addQuotedParam('sessionId', $sessionId);
  369. }
  370. $command->setCommandText($sql);
  371. DataContext::getInstance()->executeNonQuery($command);
  372. }
  373. catch (Exception $ex)
  374. {
  375. $exString = "<pre>DatabseSessionHandler Exception\nUnable to write session record to database.\n"
  376. . $ex->getLine() . " on '" . $ex->getFile() . "'\n"
  377. . $ex->getCode() . ": " . $ex->getMessage() . "\nStack Trace:\n" . $ex->getTraceAsString() . "</pre>";
  378. LogManager::setLogLevel($originalLogLevel);
  379. HttpResponse::write($exString);
  380. HttpResponse::end();
  381. return false;
  382. }
  383. LogManager::setLogLevel($originalLogLevel);
  384. return true;
  385. }
  386. /**
  387. * @param string $sessionId
  388. * @return bool
  389. */
  390. public static function destroy($sessionId)
  391. {
  392. $originalLogLevel = LogManager::getLogLevel();
  393. LogManager::setLogLevel(LogManager::LOG_LEVEL_DISABLED);
  394. try
  395. {
  396. $quotedTableName = DataContext::getInstance()->getConnection()->quoteIdentifier(self::getDbTableName());
  397. $sql = "DELETE FROM $quotedTableName WHERE SessionId = ?";
  398. $command = DataContext::getInstance()->getConnection()->createCommand();
  399. $command->setCommandText($sql);
  400. $command->addQuotedParam('sessionId', $sessionId);
  401. DataContext::getInstance()->executeNonQuery($command);
  402. }
  403. catch (Exception $ex)
  404. {
  405. $exString = "<pre>DatabseSessionHandler Exception\nUnable to destroy session record.\n"
  406. . $ex->getLine() . " on '" . $ex->getFile() . "'\n"
  407. . $ex->getCode() . ": " . $ex->getMessage() . "\nStack Trace:\n" . $ex->getTraceAsString() . "</pre>";
  408. LogManager::setLogLevel($originalLogLevel);
  409. HttpResponse::write($exString);
  410. HttpResponse::end();
  411. return false;
  412. }
  413. LogManager::setLogLevel($originalLogLevel);
  414. return true;
  415. }
  416. /**
  417. * @param int $maxLifetime the number of seconds the session exists for
  418. * @return bool
  419. */
  420. public static function gc($maxLifetime)
  421. {
  422. $originalLogLevel = LogManager::getLogLevel();
  423. LogManager::setLogLevel(LogManager::LOG_LEVEL_DISABLED);
  424. try
  425. {
  426. $quotedTableName = DataContext::getInstance()->getConnection()->quoteIdentifier(self::getDbTableName());
  427. $deleteFilter = time() - $maxLifetime;
  428. $sql = "DELETE FROM $quotedTableName WHERE SessionExpires < ?";
  429. $command = DataContext::getInstance()->getConnection()->createCommand();
  430. $command->setCommandText($sql);
  431. $command->addQuotedParam('sessionExpires', time());
  432. DataContext::getInstance()->executeNonQuery($command);
  433. }
  434. catch (Exception $ex)
  435. {
  436. $exString = "<pre>DatabseSessionHandler Exception\nUnable to perform session garbage collection.\n"
  437. . $ex->getLine() . " on '" . $ex->getFile() . "'\n"
  438. . $ex->getCode() . ": " . $ex->getMessage() . "\nStack Trace:\n" . $ex->getTraceAsString() . "</pre>";
  439. LogManager::setLogLevel($originalLogLevel);
  440. HttpResponse::write($exString);
  441. HttpResponse::end();
  442. return false;
  443. }
  444. LogManager::setLogLevel($originalLogLevel);
  445. return true;
  446. }
  447. }
  448. /**
  449. * Provides a session handler for eAccelerator-enabled web servers.
  450. * @package WebCore
  451. * @subpackage Web
  452. */
  453. class eAcceleratorSessionHandler implements ISessionHandler
  454. {
  455. protected static $sessionName;
  456. /**
  457. * Gets whether the instance of this singleton has been loaded.
  458. * @return bool
  459. */
  460. public static function isLoaded()
  461. {
  462. return true;
  463. }
  464. /**
  465. * Gets the instance of this singleton
  466. * @return eAcceleratorSessionHandler
  467. */
  468. public static function getInstance()
  469. {
  470. return new eAcceleratorSessionHandler();
  471. }
  472. /**
  473. * Gets the reflectionclass for this type.
  474. * @return ReflectionClass
  475. */
  476. public function getType()
  477. {
  478. return ReflectionClass(__CLASS__);
  479. }
  480. /**
  481. * @param string $savePath
  482. * @param string $sessionName
  483. * @return bool
  484. */
  485. public static function open($savePath, $sessionName)
  486. {
  487. self::$sessionName = $sessionName;
  488. return true;
  489. }
  490. /**
  491. * @return bool
  492. */
  493. public static function close()
  494. {
  495. return true;
  496. }
  497. /**
  498. * @param string $sessionId
  499. * @return string
  500. */
  501. public static function read($sessionId)
  502. {
  503. return eaccelerator_get(self::$sessionName . '_' . $sessionId);
  504. }
  505. /**
  506. * @param string $sessionId
  507. * @param string $sessionData
  508. * @return bool
  509. */
  510. public static function write($sessionId, $sessionData)
  511. {
  512. $ttl = session_cache_limiter() * 60;
  513. if ($ttl <= 0)
  514. $ttl = 30 * 60;
  515. return eaccelerator_put(self::$sessionName . '_' . $sessionId, $sessionData, $ttl);
  516. }
  517. /**
  518. * @param string $sessionId
  519. * @return bool
  520. */
  521. public static function destroy($sessionId)
  522. {
  523. return eaccelerator_rm(self::$sessionName . '_' . $sessionId);
  524. }
  525. /**
  526. * @param int $maxLifetime the number of seconds the session exists for
  527. * @return bool
  528. */
  529. public static function gc($maxLifetime)
  530. {
  531. eaccelerator_gc();
  532. return true;
  533. }
  534. }
  535. /**
  536. * Singleton class representing the current request's session state
  537. * The class should not be used on its own but rather accessed through
  538. * the HttpContext object.
  539. *
  540. * @package WebCore
  541. * @subpackage Web
  542. */
  543. class HttpSession extends KeyedCollectionBase implements ISingleton
  544. {
  545. protected function __construct()
  546. {
  547. $appSettings = Settings::getValue(Settings::SKEY_APPLICATION);
  548. $handler = isset($appSettings[Settings::KEY_APPLICATION_SESSIONHANDLER]) ? $appSettings[Settings::KEY_APPLICATION_SESSIONHANDLER] : '';
  549. if ($handler != '')
  550. {
  551. session_set_save_handler(array(
  552. $handler,
  553. 'open'
  554. ), array(
  555. $handler,
  556. 'close'
  557. ), array(
  558. $handler,
  559. 'read'
  560. ), array(
  561. $handler,
  562. 'write'
  563. ), array(
  564. $handler,
  565. 'destroy'
  566. ), array(
  567. $handler,
  568. 'gc'
  569. ));
  570. }
  571. session_start();
  572. parent::__construct($_SESSION, false);
  573. }
  574. /**
  575. * Regenerates the current session Id
  576. * Returns true is successful, false if failure.
  577. *
  578. * @return bool
  579. */
  580. public static function regenerateSessionId()
  581. {
  582. return session_regenerate_id();
  583. }
  584. /**
  585. * gets the current session identifier
  586. *
  587. * @return string
  588. */
  589. public static function getSessionId()
  590. {
  591. return session_id();
  592. }
  593. /**
  594. * Represents the instance of the singleton object
  595. *
  596. * @var HttpSession
  597. */
  598. private static $__instance = null;
  599. /**
  600. * Gets the singleton instance for this class
  601. *
  602. * @return HttpSession
  603. */
  604. public static function getInstance()
  605. {
  606. if (self::isLoaded() === false)
  607. self::$__instance = new HttpSession();
  608. return self::$__instance;
  609. }
  610. /**
  611. * Determines whether the singleton has loaded its instance
  612. *
  613. * @return bool
  614. */
  615. public static function isLoaded()
  616. {
  617. if (is_null(self::$__instance))
  618. return false;
  619. return true;
  620. }
  621. /**
  622. * Creates a default instance of this class
  623. *
  624. * @return HttpSession
  625. */
  626. public static function createInstance()
  627. {
  628. return self::getInstance();
  629. }
  630. /**
  631. * Clears all the session variables
  632. */
  633. public function clear()
  634. {
  635. session_unset();
  636. }
  637. /**
  638. * Destroys the session and all data associated with it. this is equivalent to calling session_destroy()
  639. */
  640. public function destroy()
  641. {
  642. session_destroy();
  643. }
  644. /**
  645. * Registers an object -or array- for in-session persistence.
  646. * If the key does not exist, it creates it with the passed $object
  647. * If the key already exists, then $object is set to the contents of the key
  648. * @example $obj = new StdClass(); HttpContext::getSession()->registerPersistentObject('myKey', $obj); $obj->prop1 = 'myProp1Value';
  649. * @param string $keyName
  650. * @param object $object
  651. * @return int Returns 0 if the key did not exist before. Returns 1 if the key existed before.
  652. */
  653. public static function registerPersistentObject($keyName, &$object)
  654. {
  655. if (!is_object($object) && !is_array($object))
  656. throw new SystemException(SystemException::EX_INVALIDPARAMETER, 'Parameter $object must be an instance of an object or an array.');
  657. if (!is_string($keyName))
  658. throw new SystemException(SystemException::EX_INVALIDPARAMETER, 'Parameter $keyName must be a string');
  659. $session = self::getInstance();
  660. if ($session->keyExists($keyName) === false)
  661. {
  662. $session->setValue($keyName, $object);
  663. return 0;
  664. }
  665. else
  666. {
  667. $object = HttpContext::getSession()->getValue($keyName);
  668. return 1;
  669. }
  670. }
  671. }
  672. /**
  673. * The singleton response to output headers
  674. *
  675. * @package WebCore
  676. * @subpackage Web
  677. */
  678. class HttpResponse extends ObjectBase implements ISingleton
  679. {
  680. /*
  681. @todo Add all the response codes to constants http://www.krisjordan.com/php-class-for-http-response-status-codes/
  682. */
  683. const HTTP_RESPONSE_CODE_404 = '404 Not Found';
  684. const HTTP_RESPONSE_CODE_403 = '403 Forbidden';
  685. /**
  686. * Represents the instance of the singleton object
  687. *
  688. * @var HttpResponse
  689. */
  690. private static $__instance = null;
  691. /**
  692. * Gets the singleton instance for this class.
  693. *
  694. * @return HttpResponse
  695. */
  696. public static function getInstance()
  697. {
  698. if (self::isLoaded() === false)
  699. self::$__instance = new HttpResponse();
  700. return self::$__instance;
  701. }
  702. /**
  703. * Determines whether the singleton has loaded its instance
  704. *
  705. * @return bool
  706. */
  707. public static function isLoaded()
  708. {
  709. if (is_null(self::$__instance))
  710. return false;
  711. return true;
  712. }
  713. /**
  714. * Writes content directly to the response's output stream.
  715. * Use the getMarkupWriter method to output HTML easily.
  716. */
  717. public static function write($content)
  718. {
  719. echo $content;
  720. }
  721. /**
  722. * Writes content directly to the response's output stream, appending both, a carriage return and a line feed character (CRLF).
  723. * Use the getMarkupWriter method to output HTML easily.
  724. */
  725. public static function writeLine($content)
  726. {
  727. echo $content . "\r\n";
  728. }
  729. /**
  730. * Ends the response immediately.
  731. * WARNING: If output buffering is on, you must call the outputBufferFlush method in order to produce some output.
  732. */
  733. public static function end()
  734. {
  735. exit(0);
  736. }
  737. /**
  738. * Gets the output markup writer.
  739. * @return MarkupWriter
  740. */
  741. public static function getMarkupWriter()
  742. {
  743. return HtmlWriter::getInstance();
  744. }
  745. /**
  746. * Redirects to the given URL
  747. * @param string $url
  748. * @param array $params
  749. */
  750. public static function redirect($url, $params = null)
  751. {
  752. $queryString = '';
  753. if (is_null($params) === false)
  754. {
  755. $queryString = '?';
  756. $paramNames = array_keys($params);
  757. foreach ($paramNames as $param)
  758. {
  759. $queryString .= $param . '=' . urlencode($params[$param]) . '&';
  760. }
  761. }
  762. self::appendHeader('Location', $url . $queryString);
  763. HttpResponse::end();
  764. }
  765. /**
  766. * Turns output buffering on.
  767. */
  768. public static function outputBufferStart()
  769. {
  770. ob_start();
  771. }
  772. /**
  773. * Flushes the output buffer; You must call the outputBufferstart function before you call this method.
  774. */
  775. public static function outputBufferFlush()
  776. {
  777. ob_end_flush();
  778. }
  779. /**
  780. * Gets the length in bytes of the output buffer.
  781. *
  782. * @return int
  783. */
  784. public static function outputBufferGetLength()
  785. {
  786. return ob_get_length();
  787. }
  788. /**
  789. * Clears the contents of the output buffer
  790. *
  791. */
  792. public static function clearOutputBuffer()
  793. {
  794. ob_end_clean();
  795. }
  796. /**
  797. * Returns the contents of the output buffer
  798. *
  799. * @return string
  800. */
  801. public static function getOutputBuffer()
  802. {
  803. return ob_get_contents();
  804. }
  805. /**
  806. * Adds a header to the response headers.
  807. *
  808. * @param string $headerName
  809. * @param string $headerValue
  810. */
  811. public static function appendHeader($headerName, $headerValue)
  812. {
  813. header($headerName . ': ' . $headerValue);
  814. }
  815. /**
  816. * Sets the response code for the Current HttpRequest
  817. *
  818. * @param string $responseCode. One of the HTTP_RESPONSE_CODE_* prefixes constants
  819. */
  820. public static function setResponseCode($responseCode)
  821. {
  822. header('HTTP/1.0 ' . $responseCode);
  823. }
  824. /**
  825. * Sets a Last-Modified header.
  826. * use strtotime function to obtain timestamps from ISO-compliant dates.
  827. * @param int $timestamp
  828. */
  829. public static function setLastModified($timestamp)
  830. {
  831. $timestampStr = gmdate("D, d M Y H:i:s", $timestamp);
  832. self::appendHeader('Expires', $timestampStr . ' GMT');
  833. }
  834. /**
  835. * Sets the Expires header given an offset in minutes.
  836. *
  837. * @param int $minutesFromNow The parameter can be a negative integer.
  838. */
  839. public static function setExpires($minutesFromNow = 0)
  840. {
  841. $offset = 60 * $minutesFromNow;
  842. $timestamp = gmdate("D, d M Y H:i:s", time() + $offset);
  843. self::appendHeader('Expires', $timestamp . ' GMT');
  844. }
  845. /**
  846. * Sets the Cache-Control and Expires header to control content cacheability.
  847. * If minutes is negative a no-cache, must-revalidate header is sent out. Otherwise a max-age value is sent out.
  848. *
  849. * @param int $minutes
  850. */
  851. public static function setCacheControl($minutes = 0)
  852. {
  853. if ($minutes <= 0)
  854. {
  855. self::appendHeader('Cache-Control', 'no-cache, must-revalidate');
  856. self::setExpires(times() - (60 * 24 * 365 * 10));
  857. }
  858. else
  859. {
  860. $seconds = $minutes * 60;
  861. self::appendHeader('Cache-Control', 'max-age=' . $seconds . ', must-revalidate');
  862. self::setExpires(time() + $seconds);
  863. }
  864. }
  865. /**
  866. * Sets the content-type header
  867. *
  868. * @param string $mimetype
  869. */
  870. public static function setContentType($mimetype = 'application/octet-stream')
  871. {
  872. self::appendHeader('Content-Type', $mimetype);
  873. }
  874. /**
  875. * Sets the content-disposition header.
  876. *
  877. * @param string $disposition Can be attachment or inline
  878. * @param string $filename If disposition is 'attachment' then you can specify a filename to download.
  879. */
  880. public static function setContentDisposition($disposition = 'attachment', $filename = '')
  881. {
  882. $headerValue = $disposition;
  883. if ($filename != '')
  884. $headerValue .= '; filename="' . $filename . '"';
  885. self::appendHeader('Content-Disposition', $headerValue);
  886. }
  887. /**
  888. * Sets the content-length header (in bytes).
  889. *
  890. * @param int $length
  891. */
  892. public static function setContentLength($length)
  893. {
  894. self::appendHeader('Content-Length', $length);
  895. }
  896. /**
  897. * Determines whether the headers have already been sent to the client.
  898. * @return bool
  899. */
  900. public static function hasSentHeaders()
  901. {
  902. return headers_sent();
  903. }
  904. }
  905. /**
  906. * The singleton request holding references to GET, POST, REQUEST and FILES variables.
  907. *
  908. * @package WebCore
  909. * @subpackage Web
  910. */
  911. class HttpRequest extends ObjectBase implements ISingleton
  912. {
  913. /**
  914. * Represents the instance of the singleton object
  915. *
  916. * @var HttpRequest
  917. */
  918. private static $__instance = null;
  919. /**
  920. * Gets a collection representing $_REQUEST variables.
  921. *
  922. * @var KeyedCollectionWrapper
  923. */
  924. private static $requestItems;
  925. /**
  926. * Gets a collection representing $_GET variables
  927. *
  928. * @var KeyedCollectionWrapper
  929. */
  930. private static $queryStringItems;
  931. /**
  932. * Gets a collection representing $_POST variables
  933. *
  934. * @var KeyedCollectionWrapper
  935. */
  936. private static $postedItems;
  937. /**
  938. * Gets a collection representing $_FILES variables
  939. *
  940. * @var KeyedCollection
  941. */
  942. private static $filesItems;
  943. /**
  944. * Gets the singleton instance for this class.
  945. *
  946. * @return HttpRequest
  947. */
  948. public static function getInstance()
  949. {
  950. if (self::isLoaded() === false)
  951. {
  952. self::$__instance = new HttpRequest();
  953. self::$requestItems = new KeyedCollectionWrapper($_REQUEST, true);
  954. self::$queryStringItems = new KeyedCollectionWrapper($_GET, true);
  955. self::$postedItems = new KeyedCollectionWrapper($_POST, true);
  956. self::$filesItems = new KeyedCollection();
  957. // Populate the files collection
  958. $postedFileKeys = array_keys($_FILES);
  959. foreach ($postedFileKeys as $fileKey)
  960. {
  961. $postedFile = new PostedFile($fileKey);
  962. self::$filesItems->setValue($fileKey, $postedFile);
  963. }
  964. }
  965. return self::$__instance;
  966. }
  967. /**
  968. * Determines whether the singleton has loaded its instance
  969. *
  970. * @return bool
  971. */
  972. public static function isLoaded()
  973. {
  974. if (is_null(self::$__instance))
  975. return false;
  976. return true;
  977. }
  978. /**
  979. * Gets a collection representing $_REQUEST variables (by reference)
  980. *
  981. * @return KeyedCollectionWrapper
  982. */
  983. public function &getRequestVars()
  984. {
  985. $vars = new KeyedCollection();
  986. foreach (self::$requestItems as $key => $value)
  987. {
  988. $decodedValue = utf8_decode($value);
  989. $vars->setValue($key, $decodedValue);
  990. }
  991. return $vars;
  992. }
  993. /**
  994. * Gets a collection representing $_POST variables (by reference)
  995. *
  996. * @return KeyedCollectionWrapper
  997. */
  998. public function &getPostVars()
  999. {
  1000. return self::$postedItems;
  1001. }
  1002. /**
  1003. * Gets a collection representing $_GET variables (by reference)
  1004. *
  1005. * @return KeyedCollectionWrapper
  1006. */
  1007. public function &getQueryStringVars()
  1008. {
  1009. return self::$queryStringItems;
  1010. }
  1011. /**
  1012. * Gets a KeyedCollection containing items of type PostedFile
  1013. * This is an enhanced version of the $_FILES array
  1014. *
  1015. * @return KeyedCollection
  1016. */
  1017. public function &getPostedFiles()
  1018. {
  1019. return self::$filesItems;
  1020. }
  1021. }
  1022. /**
  1023. * Wraps an item from the $_FILES array
  1024. *
  1025. * @package WebCore
  1026. * @subpackage Web
  1027. */
  1028. class PostedFile extends ObjectBase
  1029. {
  1030. private $__fileReference;
  1031. /**
  1032. * Creates a new instance of this class
  1033. *
  1034. * @param string $filesKey
  1035. */
  1036. public function __construct($filesKey)
  1037. {
  1038. if (array_key_exists($filesKey, $_FILES) === false)
  1039. throw new SystemException(SystemException::EX_INVALIDKEY, '$_FILES key ' . $filesKey . ' does not exist.');
  1040. $this->__fileReference =& $_FILES[$filesKey];
  1041. }
  1042. /**
  1043. * Gets the filename, without the path
  1044. * Example: myfile.ext
  1045. *
  1046. * @return string
  1047. */
  1048. public function getFileName()
  1049. {
  1050. return basename($this->__fileReference['name']);
  1051. }
  1052. /**
  1053. * Gets the filename, without the path or extension
  1054. * Example: myfile
  1055. *
  1056. * @return string
  1057. */
  1058. public function getFileBaseName()
  1059. {
  1060. $fileName = $this->getFileName();
  1061. $pathInfo = pathinfo($fileName);
  1062. return $pathInfo['filename'];
  1063. }
  1064. /**
  1065. * Gets the file extension of the uploaded file
  1066. * Example: ext
  1067. *
  1068. * @return string
  1069. */
  1070. public function getFileExtension()
  1071. {
  1072. $fileName = $this->getFileName();
  1073. $pathInfo = pathinfo($fileName);
  1074. return $pathInfo['extension'];
  1075. }
  1076. /**
  1077. * Gets the mime-type that the client set when the file was uploaded
  1078. * Example: image/gif
  1079. *
  1080. * @return string
  1081. */
  1082. public function getMimeType()
  1083. {
  1084. return $this->__fileReference['type'];
  1085. }
  1086. /**
  1087. * Gets the size, in bytes of the array.
  1088. *
  1089. * @return int
  1090. */
  1091. public function getSize()
  1092. {
  1093. return (int) $this->__fileReference['size'];
  1094. }
  1095. /**
  1096. * Gets the full path in the server to the uploaded file
  1097. *
  1098. * @return string
  1099. */
  1100. public function getTempFileName()
  1101. {
  1102. return $this->__fileReference['tmp_name'];
  1103. }
  1104. /**
  1105. * Gets whether file was uploaded and can be correcly found in the server.
  1106. *
  1107. * @return bool
  1108. */
  1109. public function isUploaded()
  1110. {
  1111. return is_uploaded_file($this->getTempFileName());
  1112. }
  1113. /**
  1114. * Gets the entire contents of the uploaded filed
  1115. *
  1116. * @return string
  1117. */
  1118. public function readAll()
  1119. {
  1120. $pathFileName = $this->getTempFileName();
  1121. return file_get_contents($pathFileName);
  1122. }
  1123. /**
  1124. * Gets the error code of the file upload result
  1125. *
  1126. * @return int
  1127. */
  1128. public function getErrorCode()
  1129. {
  1130. return $this->__fileReference['error'];
  1131. }
  1132. /**
  1133. * Gets a user-friendly message based on the error code
  1134. *
  1135. * @return string
  1136. */
  1137. public function getErrorMessage()
  1138. {
  1139. $errorCode = $this->getErrorCode();
  1140. switch ($errorCode)
  1141. {
  1142. case UPLOAD_ERR_CANT_WRITE:
  1143. return Resources::getValue(Resources::SRK_UPLOAD_ERR_CANT_WRITE);
  1144. break;
  1145. case UPLOAD_ERR_EXTENSION:
  1146. return Resources::getValue(Resources::SRK_UPLOAD_ERR_EXTENSION);
  1147. break;
  1148. case UPLOAD_ERR_FORM_SIZE:
  1149. return Resources::getValue(Resources::SRK_UPLOAD_ERR_FORM_SIZE);
  1150. break;
  1151. case UPLOAD_ERR_INI_SIZE:
  1152. return Resources::getValue(Resources::SRK_UPLOAD_ERR_INI_SIZE);
  1153. break;
  1154. case UPLOAD_ERR_NO_FILE:
  1155. return Resources::getValue(Resources::SRK_UPLOAD_ERR_NO_FILE);
  1156. break;
  1157. case UPLOAD_ERR_NO_TMP_DIR:
  1158. return Resources::getValue(Resources::SRK_UPLOAD_ERR_NO_TMP_DIR);
  1159. break;
  1160. case UPLOAD_ERR_OK:
  1161. return Resources::getValue(Resources::SRK_UPLOAD_ERR_OK);
  1162. break;
  1163. case UPLOAD_ERR_PARTIAL:
  1164. return Resources::getValue(Resources::SRK_UPLOAD_ERR_PARTIAL);
  1165. break;
  1166. default:
  1167. return Resources::getValue(Resources::SRK_UPLOAD_ERR_CANT_WRITE);
  1168. break;
  1169. }
  1170. return StaticResources::getMessagePostedFileErrorCode($this->getErrorCode());
  1171. }
  1172. }
  1173. /**
  1174. * Represents a typed, keyed collection wrapping the $_SERVER PHP array
  1175. *
  1176. * @package WebCore
  1177. * @subpackage Web
  1178. */
  1179. class HttpContextInfo extends KeyedCollectionBase implements ISingleton
  1180. {
  1181. const CLIENT_DESKTOP = "desktop";
  1182. const CLIENT_MOBILE = "mobile";
  1183. const CLIENT_IPHONE = "iphone";
  1184. const CLIENT_BB = "blackberry";
  1185. const CLIENT_BOT = "bot";
  1186. const INFO_HTTP_USER_AGENT = 'HTTP_USER_AGENT';
  1187. const INFO_REMOTE_ADDR = 'REMOTE_ADDR';
  1188. const INFO_REMOTE_PORT = 'REMOTE_PORT';
  1189. const INFO_HTTP_ACCEPT = 'HTTP_ACCEPT';
  1190. const INFO_HTTP_ACCEPT_ENCODING = 'HTTP_ACCEPT_ENCODING';
  1191. const INFO_HTTP_ACCEPT_LANGUAGE = 'HTTP_ACCEPT_LANGUAGE';
  1192. const INFO_GATEWAY_INTERFACE = 'GATEWAY_INTERFACE';
  1193. const INFO_SERVER_ADDR = 'SERVER_ADDR';
  1194. const INFO_SERVER_PORT = 'SERVER_PORT';
  1195. const INFO_DOCUMENT_ROOT = 'DOCUMENT_ROOT';
  1196. const INFO_SERVER_NAME = 'SERVER_NAME';
  1197. const INFO_SERVER_SOFTWARE = 'SERVER_SOFTWARE';
  1198. const INFO_SERVER_PROTOCOL = 'SERVER_PROTOCOL';
  1199. const INFO_REQUEST_URI = 'REQUEST_URI';
  1200. const INFO_QUERY_STRING = 'QUERY_STRING';
  1201. const INFO_REQUEST_METHOD = 'REQUEST_METHOD';
  1202. const INFO_REQUEST_TIME = 'REQUEST_TIME';
  1203. const INFO_HTTP_HOST = 'HTTP_HOST';
  1204. const INFO_SCRIPT_NAME = 'SCRIPT_NAME';
  1205. const INFO_HTTP_CONNECTION = 'HTTP_CONNECTION';
  1206. const INFO_PHP_SELF = 'PHP_SELF';
  1207. const INFO_SCRIPT_FILENAME = 'SCRIPT_FILENAME';
  1208. private static $clientType;
  1209. protected function __construct()
  1210. {
  1211. parent::__construct($_SERVER, true);
  1212. }
  1213. /**
  1214. * Represents the instance of the singleton object
  1215. *
  1216. * @var HttpContextInfo
  1217. */
  1218. private static $__instance = null;
  1219. /**
  1220. * Gets the singleton instance for this class.
  1221. *
  1222. * @return HttpContextInfo
  1223. */
  1224. public static function getInstance()
  1225. {
  1226. if (self::isLoaded() === false)
  1227. {
  1228. self::$__instance = new HttpContextInfo();
  1229. self::$__instance->detectClientType();
  1230. }
  1231. return self::$__instance;
  1232. }
  1233. /**
  1234. * Determines whether the singleton has loaded its instance
  1235. *
  1236. * @return bool
  1237. */
  1238. public static function isLoaded()
  1239. {
  1240. if (is_null(self::$__instance))
  1241. return false;
  1242. return true;
  1243. }
  1244. /**
  1245. * Returns client's type
  1246. *
  1247. * @return string
  1248. */
  1249. public function getClientType()
  1250. {
  1251. return self::$clientType;
  1252. }
  1253. /**
  1254. * Detects client type using User-Agent
  1255. *
  1256. */
  1257. public function detectClientType()
  1258. {
  1259. self::$clientType = self::CLIENT_DESKTOP;
  1260. $agent = self::getInstance()->getClientAgent();
  1261. $iphoneAgents = array(
  1262. "iPhone",
  1263. "iPod"
  1264. );
  1265. foreach ($iphoneAgents as $key)
  1266. {
  1267. if (preg_match("/$key/i", $agent))
  1268. {
  1269. self::$clientType = self::CLIENT_IPHONE;
  1270. return;
  1271. }
  1272. }
  1273. $botAgents = array(
  1274. "Teoma",
  1275. "alexa",
  1276. "MSNBot",
  1277. "inktomi",
  1278. "looksmart",
  1279. "Firefly",
  1280. "NationalDirectory",
  1281. "Ask Jeeves",
  1282. "TECNOSEEK",
  1283. "InfoSeek",
  1284. "WebFindBot",
  1285. "girafabot",
  1286. "crawler",
  1287. "www.galaxy.com",
  1288. "Googlebot",
  1289. "Scooter",
  1290. "Slurp",
  1291. "Yammybot",
  1292. "WebBug",
  1293. "Spade",
  1294. "ZyBorg"
  1295. );
  1296. foreach ($botAgents as $key)
  1297. {
  1298. if (preg_match("/$key/i", $agent))
  1299. {
  1300. self::$clientType = self::CLIENT_BOT;
  1301. return;
  1302. }
  1303. }
  1304. $mobileAgents = array(
  1305. "BlackBerry",
  1306. "Opera Mini",
  1307. "Windows CE",
  1308. "Symbian"
  1309. );
  1310. foreach ($mobileAgents as $key)
  1311. {
  1312. if (preg_match("/$key/i", $agent))
  1313. {
  1314. if ($key == "BlackBerry")
  1315. self::$clientType = self::CLIENT_BB;
  1316. else
  1317. self::$clientType = self::CLIENT_MOBILE;
  1318. return;
  1319. }
  1320. }
  1321. }
  1322. /**
  1323. * Returns an info value from the $_SERVER array
  1324. *
  1325. * @return string
  1326. */
  1327. protected static function getInfoValue($key)
  1328. {
  1329. return (self::getInstance()->keyExists($key) === true) ? self::getInstance()->getValue($key) : "";
  1330. }
  1331. /**
  1332. * Gets the client's browser name and version (if set in the request)
  1333. *
  1334. * @return string
  1335. */
  1336. public function getClientAgent()
  1337. {
  1338. return self::getInfoValue(self::INFO_HTTP_USER_AGENT);
  1339. }
  1340. /**
  1341. * Returns an array with client agent information such as name and version
  1342. * @return array
  1343. */
  1344. public function getClientAgentInfo()
  1345. {
  1346. return get_browser(null, true);
  1347. }
  1348. /**
  1349. * Gets the IP Address of the current request.
  1350. *
  1351. * @return string
  1352. */
  1353. public function getClientIPAddress()
  1354. {
  1355. return self::getInfoValue(self::INFO_REMOTE_ADDR);
  1356. }
  1357. /**
  1358. * Gets the TCP/IP port the client used to send the request
  1359. *
  1360. * @return int
  1361. */
  1362. public function getClientPort()
  1363. {
  1364. return self::getInfoValue(self::INFO_REMOTE_PORT);
  1365. }
  1366. /**
  1367. * Gets the comma-delimited mimetypes that the client accepts.
  1368. *
  1369. * @return string
  1370. */
  1371. public function getClientAccept()
  1372. {
  1373. return self::getInfoValue(self::INFO_HTTP_ACCEPT);
  1374. }
  1375. /**
  1376. * Gets the comma-delimieted supported stream formats that the client supports.
  1377. * For example, gzip, deflate
  1378. *
  1379. * @return string
  1380. */
  1381. public function getClientAcceptEncoding()
  1382. {
  1383. return self::getInfoValue(self::INFO_HTTP_ACCEPT_ENCODING);
  1384. }
  1385. /**
  1386. * Gets the client's language and culture code
  1387. * For example, en-us or es-mx
  1388. * @return string
  1389. */
  1390. public function getClientAcceptLanguage()
  1391. {
  1392. return self::getInfoValue(self::INFO_HTTP_ACCEPT_LANGUAGE);
  1393. }
  1394. /**
  1395. * Gets the version of the Common Gateway Interface the server is using.
  1396. * For example, CGI/1.1
  1397. *
  1398. * @return string
  1399. */
  1400. public function getServerCGI()
  1401. {
  1402. return self::getInfoValue(self::INFO_GATEWAY_INTERFACE);
  1403. }
  1404. /**
  1405. * Gets the server's IP address serving the response
  1406. *
  1407. * @return string
  1408. */
  1409. public function getServerIPAddress()
  1410. {
  1411. return self::getInfoValue(self::INFO_SERVER_ADDR);
  1412. }
  1413. /**
  1414. * Gets the TCP/IP port on which the response is returned by the server
  1415. *
  1416. * @return string
  1417. */
  1418. public function getServerPort()
  1419. {
  1420. return self::getInfoValue(self::INFO_SERVER_PORT);
  1421. }
  1422. /**
  1423. * Gets the root path in the server's file system from which all
  1424. * documents are processed and served.
  1425. *
  1426. * @return string
  1427. */
  1428. public function getServerFileSystemWebRootPath()
  1429. {
  1430. return self::getInfoValue(self::INFO_DOCUMENT_ROOT);
  1431. }
  1432. /**
  1433. * Gets the name of the server.
  1434. * For example, localhost
  1435. *
  1436. * @return string
  1437. */
  1438. public function getServerAddress()
  1439. {
  1440. return self::getInfoValue(self::INFO_SERVER_NAME);
  1441. }
  1442. /**
  1443. * Gets the name and version of the software used to process requests and responses.
  1444. *
  1445. * @return string
  1446. */
  1447. public function getServerSoftware()
  1448. {
  1449. return self::getInfoValue(self::INFO_SERVER_SOFTWARE);
  1450. }
  1451. /**
  1452. * Gets the protocol the server is using to process requests and serve response.
  1453. * For example, HTTP/1.1
  1454. *
  1455. * @return string
  1456. */
  1457. public function getServerProtocol()
  1458. {
  1459. return self::getInfoValue(self::INFO_SERVER_PROTOCOL);
  1460. }
  1461. /**
  1462. * Gets the full Uniform Resource identifier of the request.
  1463. * For example, http://localhost/test/test.php?id=6
  1464. *
  1465. * @return string
  1466. */
  1467. public function getRequestUri()
  1468. {
  1469. return self::getInfoValue(self::INFO_REQUEST_URI);
  1470. }
  1471. /**
  1472. * Gets the query string that appears after the script's name
  1473. * For example, id=6
  1474. *
  1475. * @return string
  1476. */
  1477. public function getRequestQueryString()
  1478. {
  1479. return self::getInfoValue(self::INFO_QUERY_STRING);
  1480. }
  1481. /**
  1482. * Gets the REST method for the request.
  1483. * For example, POST
  1484. *
  1485. * @return string
  1486. */
  1487. public function getRequestMethod()
  1488. {
  1489. return StringHelper::toUpper(self::getInfoValue(self::INFO_REQUEST_METHOD));
  1490. }
  1491. /**
  1492. * Gets the timestamp at which the request was made.
  1493. *
  1494. * @return int
  1495. */
  1496. public function getRequestStartTime()
  1497. {
  1498. return self::getInfoValue(self::INFO_REQUEST_TIME);
  1499. }
  1500. /**
  1501. * Gets the hostname and port at which the request is directed
  1502. * For example, localhost:88
  1503. *
  1504. * @return string
  1505. */
  1506. public function getRequestHost()
  1507. {
  1508. return self::getInfoValue(self::INFO_HTTP_HOST);
  1509. }
  1510. /**
  1511. * Gets the virtual path to the resource at which the request was created.
  1512. * For example, /test/testing.php
  1513. *
  1514. * @return string
  1515. */
  1516. public function getRequestScriptPath()
  1517. {
  1518. return self::getInfoValue(self::INFO_SCRIPT_NAME);
  1519. }
  1520. /**
  1521. * Gets the connection mode the client requests.
  1522. * For example, Keep-Alive
  1523. *
  1524. * @return string
  1525. */
  1526. public function getRequestConnectionMode()
  1527. {
  1528. return self::getInfoValue(self::INFO_HTTP_CONNECTION);
  1529. }
  1530. /**
  1531. * Gets the full path to the executing script in the file system.
  1532. * For example: c:\InetPub\wwwroot\test\testing.php
  1533. *
  1534. * @return string
  1535. */
  1536. public function getScriptFileSystemPath()
  1537. {
  1538. return self::getInfoValue(self::INFO_SCRIPT_FILENAME);
  1539. }
  1540. /**
  1541. * Gets the full virtual path to the executing script.
  1542. * for example: /test/testing.php
  1543. *
  1544. * @return string
  1545. */
  1546. public function getScriptVirtualPath()
  1547. {
  1548. return self::getInfoValue(self::INFO_PHP_SELF);
  1549. }
  1550. /**
  1551. * Creates a default instance of this class
  1552. *
  1553. * @return HttpContextInfo
  1554. */
  1555. public static function createInstance()
  1556. {
  1557. return self::getInstance();
  1558. }
  1559. }
  1560. /**
  1561. * Represents a user navigation entry holding significant request information.
  1562. * @package WebCore
  1563. * @subpackage Web
  1564. */
  1565. class NavigationEntry extends SerializableObjectBase
  1566. {
  1567. protected $postedVars;
  1568. protected $queryVars;
  1569. protected $requestUrl;
  1570. protected $requestTime;
  1571. protected $hadPostedFiles;
  1572. protected $requestMethod;
  1573. protected $scriptVirtualPath;
  1574. /** …

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