PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/demos/Zend/Service/LiveDocx/check-environment.php

https://github.com/Exercise/zf2
PHP | 323 lines | 209 code | 93 blank | 21 comment | 36 complexity | cbc7cf1d8c004bdf5ff98909dc0dcc34 MD5 | raw file
  1. <?php
  2. set_time_limit(0);
  3. require_once __DIR__ . DIRECTORY_SEPARATOR . 'Bootstrap.php';
  4. use Zend\Version;
  5. use Zend\Service\LiveDocx\MailMerge;
  6. use Zend\Service\LiveDocx\Helper;
  7. define('TEST_PASS', 'PASS');
  8. define('TEST_FAIL', 'FAIL');
  9. define('MIN_PHP_VERSION', '5.3');
  10. define('MIN_ZF_VERSION', '2.0.0dev1');
  11. define('SOCKET_TIMEOUT', 5); // seconds
  12. $failed = false;
  13. $counter = 1;
  14. // -----------------------------------------------------------------------------
  15. ini_set('default_socket_timeout', SOCKET_TIMEOUT);
  16. printf('%sEnvironment Checker for Zend Framework LiveDocx Component%s%s', PHP_EOL, PHP_EOL, PHP_EOL);
  17. // -----------------------------------------------------------------------------
  18. Helper::printCheckEnvironmentLine($counter, sprintf('Checking OS (%s)', PHP_OS), TEST_PASS);
  19. $counter ++;
  20. // -----------------------------------------------------------------------------
  21. if (1 === version_compare(PHP_VERSION, MIN_PHP_VERSION)) {
  22. $result = TEST_PASS;
  23. } else {
  24. $result = TEST_FAIL;
  25. $failed = true;
  26. }
  27. Helper::printCheckEnvironmentLine($counter, sprintf('Checking PHP version (%s)', PHP_VERSION), $result);
  28. $counter ++;
  29. // -----------------------------------------------------------------------------
  30. Helper::printCheckEnvironmentLine($counter, sprintf('Checking memory limit (%s)', ini_get('memory_limit')), TEST_PASS);
  31. $counter ++;
  32. // -----------------------------------------------------------------------------
  33. if (in_array('http', stream_get_wrappers())) {
  34. $result = TEST_PASS;
  35. } else {
  36. $result = TEST_FAIL;
  37. $failed = true;
  38. }
  39. Helper::printCheckEnvironmentLine($counter, 'Checking HTTP stream wrapper', $result);
  40. $counter ++;
  41. // -----------------------------------------------------------------------------
  42. if (in_array('https', stream_get_wrappers())) {
  43. $result = TEST_PASS;
  44. } else {
  45. $result = TEST_FAIL;
  46. $failed = true;
  47. }
  48. Helper::printCheckEnvironmentLine($counter, 'Checking HTTPS stream wrapper', $result);
  49. $counter ++;
  50. // -----------------------------------------------------------------------------
  51. if (true === method_exists('\Zend\Debug', 'dump')) {
  52. $result = TEST_PASS;
  53. } else {
  54. $result = TEST_FAIL;
  55. $failed = true;
  56. }
  57. Helper::printCheckEnvironmentLine($counter, 'Checking Zend Framework path', $result);
  58. $counter ++;
  59. // -----------------------------------------------------------------------------
  60. if (1 === Version::compareVersion(PHP_VERSION, MIN_PHP_VERSION)) {
  61. $result = TEST_PASS;
  62. } else {
  63. $result = TEST_FAIL;
  64. $failed = true;
  65. }
  66. Helper::printCheckEnvironmentLine($counter, sprintf('Checking Zend Framework version (%s)', Version::VERSION), $result);
  67. $counter ++;
  68. // -----------------------------------------------------------------------------
  69. if (extension_loaded('openssl')) {
  70. $result = TEST_PASS;
  71. } else {
  72. $result = TEST_FAIL;
  73. $failed = true;
  74. }
  75. Helper::printCheckEnvironmentLine($counter, 'Checking OpenSSL extension', $result);
  76. $counter ++;
  77. // -----------------------------------------------------------------------------
  78. if (extension_loaded('soap')) {
  79. $result = TEST_PASS;
  80. } else {
  81. $result = TEST_FAIL;
  82. $failed = true;
  83. }
  84. Helper::printCheckEnvironmentLine($counter, 'Checking SOAP extension', $result);
  85. $counter ++;
  86. // -----------------------------------------------------------------------------
  87. if (extension_loaded('dom')) {
  88. $result = TEST_PASS;
  89. } else {
  90. $result = TEST_FAIL;
  91. $failed = true;
  92. }
  93. Helper::printCheckEnvironmentLine($counter, 'Checking DOM extension', $result);
  94. $counter ++;
  95. // -----------------------------------------------------------------------------
  96. if (extension_loaded('simplexml')) {
  97. $result = TEST_PASS;
  98. } else {
  99. $result = TEST_FAIL;
  100. $failed = true;
  101. }
  102. Helper::printCheckEnvironmentLine($counter, 'Checking SimpleXML extension', $result);
  103. $counter ++;
  104. // -----------------------------------------------------------------------------
  105. if (extension_loaded('libxml')) {
  106. $result = TEST_PASS;
  107. } else {
  108. $result = TEST_FAIL;
  109. $failed = true;
  110. }
  111. Helper::printCheckEnvironmentLine($counter, 'Checking libXML extension', $result);
  112. $counter ++;
  113. // -----------------------------------------------------------------------------
  114. $geoData = @file_get_contents('http://ipinfodb.com/ip_query.php');
  115. $keys = array (
  116. 'Ip' => 'IP address',
  117. 'City' => 'city',
  118. 'RegionName' => 'region',
  119. 'CountryName' => 'country'
  120. );
  121. if (false !== $geoData) {
  122. $simplexml = new SimpleXMLElement($geoData);
  123. foreach ($keys as $key => $value) {
  124. Helper::printCheckEnvironmentLine($counter, sprintf('Checking your %s (%s)', $keys[$key], $simplexml->$key), TEST_PASS);
  125. $counter ++;
  126. }
  127. } else {
  128. Helper::printCheckEnvironmentLine($counter, 'Checking your geo data', TEST_FAIL);
  129. $failed = true;
  130. }
  131. // -----------------------------------------------------------------------------
  132. $microtime = microtime(true);
  133. if (false !== file_get_contents(MailMerge::WSDL)) {
  134. $duration = microtime(true) - $microtime;
  135. $result = TEST_PASS;
  136. } else {
  137. $duration = -1;
  138. $result = TEST_FAIL;
  139. $failed = true;
  140. }
  141. Helper::printCheckEnvironmentLine($counter, sprintf('Checking backend WSDL (%01.2fs)', $duration), $result);
  142. $counter ++;
  143. // -----------------------------------------------------------------------------
  144. if (defined('DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME') &&
  145. defined('DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD')) {
  146. $result = TEST_PASS;
  147. } else {
  148. $result = TEST_FAIL;
  149. $failed = true;
  150. }
  151. Helper::printCheckEnvironmentLine($counter, 'Checking backend credentials are defined', $result);
  152. $counter ++;
  153. // -----------------------------------------------------------------------------
  154. $errorMessage = null;
  155. try {
  156. $microtime = microtime(true);
  157. $mailMerge = new Zend_Service_LiveDocx_MailMerge(
  158. array (
  159. 'username' => DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME,
  160. 'password' => DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD
  161. )
  162. );
  163. $mailMerge->logIn();
  164. $duration = microtime(true) - $microtime;
  165. unset($mailMerge);
  166. } catch (Exception $e) {
  167. $duration = -1;
  168. $errorMessage = $e->getMessage();
  169. }
  170. if (is_null($errorMessage)) {
  171. $result = TEST_PASS;
  172. } else {
  173. $result = TEST_FAIL;
  174. $failed = true;
  175. }
  176. Helper::printCheckEnvironmentLine($counter, sprintf('Logging into backend service (%01.2fs)', $duration), $result);
  177. $counter ++;
  178. // -----------------------------------------------------------------------------
  179. if (defined('DEMOS_ZEND_SERVICE_LIVEDOCX_PREMIUM_WSDL') &&
  180. false !== DEMOS_ZEND_SERVICE_LIVEDOCX_PREMIUM_WSDL) {
  181. $microtime = microtime(true);
  182. if (false !== file_get_contents(DEMOS_ZEND_SERVICE_LIVEDOCX_PREMIUM_WSDL)) {
  183. $duration = microtime(true) - $microtime;
  184. $result = TEST_PASS;
  185. } else {
  186. $duration = -1;
  187. $result = TEST_FAIL;
  188. $failed = true;
  189. }
  190. Helper::printCheckEnvironmentLine($counter, sprintf('[PREMIUM] Checking backend WSDL (%01.2fs)', $duration), $result);
  191. $counter ++;
  192. }
  193. // -----------------------------------------------------------------------------
  194. if (defined('DEMOS_ZEND_SERVICE_LIVEDOCX_PREMIUM_USERNAME') &&
  195. defined('DEMOS_ZEND_SERVICE_LIVEDOCX_PREMIUM_PASSWORD') &&
  196. defined('DEMOS_ZEND_SERVICE_LIVEDOCX_PREMIUM_WSDL') &&
  197. false !== DEMOS_ZEND_SERVICE_LIVEDOCX_PREMIUM_USERNAME &&
  198. false !== DEMOS_ZEND_SERVICE_LIVEDOCX_PREMIUM_PASSWORD &&
  199. false !== DEMOS_ZEND_SERVICE_LIVEDOCX_PREMIUM_WSDL) {
  200. $errorMessage = null;
  201. try {
  202. $microtime = microtime(true);
  203. $mailMerge = new MailMerge();
  204. $mailMerge->setWSDL(DEMOS_ZEND_SERVICE_LIVEDOCX_PREMIUM_WSDL);
  205. $mailMerge->setUsername(DEMOS_ZEND_SERVICE_LIVEDOCX_PREMIUM_USERNAME);
  206. $mailMerge->setPassword(DEMOS_ZEND_SERVICE_LIVEDOCX_PREMIUM_PASSWORD);
  207. $mailMerge->logIn();
  208. $duration = microtime(true) - $microtime;
  209. unset($mailMerge);
  210. } catch (Exception $e) {
  211. $duration = -1;
  212. $errorMessage = $e->getMessage();
  213. }
  214. if (is_null($errorMessage)) {
  215. $result = TEST_PASS;
  216. } else {
  217. $result = TEST_FAIL;
  218. $failed = true;
  219. }
  220. Helper::printCheckEnvironmentLine($counter, sprintf('[PREMIUM] Logging into backend service (%01.2fs)', $duration), $result);
  221. $counter ++;
  222. }
  223. // -----------------------------------------------------------------------------
  224. if (true === $failed) {
  225. $message = 'One or more tests failed. The web server environment, in which this script is running, does not meet the requirements for the Zend Framework LiveDocx component.';
  226. } else {
  227. $message = 'Congratulations! All tests passed. The server environment, in which this script is running, is suitable for the Zend Framework LiveDocx component.';
  228. }
  229. Helper::printLine(PHP_EOL . $message . PHP_EOL . PHP_EOL);
  230. // -----------------------------------------------------------------------------