| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- <?php
- include_once './common.php';
- define('TEST_PASS', 'PASS');
- define('TEST_FAIL', 'FAIL');
- define('MIN_PHP_VERSION', '5.2.11');
- define('MIN_ZF_VERSION', '1.10.0beta');
- define('SOCKET_TIMEOUT', 5); // seconds
- $failed = false;
- $counter = 1;
- // -----------------------------------------------------------------------------
- ini_set('default_socket_timeout', SOCKET_TIMEOUT);
- printf('%sZend_Service_LiveDocx Environment Checker%s%s', PHP_EOL, PHP_EOL, PHP_EOL);
- // -----------------------------------------------------------------------------
- printLine($counter, sprintf('Checking OS (%s)', PHP_OS), TEST_PASS);
- $counter ++;
- // -----------------------------------------------------------------------------
- if ('cli' === strtolower(PHP_SAPI)) {
- $result = TEST_PASS;
- } else {
- $result = TEST_FAIL;
- $failed = true;
- }
- printLine($counter, sprintf('Checking SAPI (%s)', PHP_SAPI), $result);
- $counter ++;
- // -----------------------------------------------------------------------------
- if (1 === version_compare(PHP_VERSION, MIN_PHP_VERSION)) {
- $result = TEST_PASS;
- } else {
- $result = TEST_FAIL;
- $failed = true;
- }
- printLine($counter, sprintf('Checking PHP version (%s)', PHP_VERSION), $result);
- $counter ++;
- // -----------------------------------------------------------------------------
- printLine($counter, sprintf('Checking memory limit (%s)', ini_get('memory_limit')), TEST_PASS);
- $counter ++;
- // -----------------------------------------------------------------------------
- if (in_array('http', stream_get_wrappers())) {
- $result = TEST_PASS;
- } else {
- $result = TEST_FAIL;
- $failed = true;
- }
- printLine($counter, 'Checking HTTP stream wrapper', $result);
- $counter ++;
- // -----------------------------------------------------------------------------
- if (in_array('https', stream_get_wrappers())) {
- $result = TEST_PASS;
- } else {
- $result = TEST_FAIL;
- $failed = true;
- }
- printLine($counter, 'Checking HTTPS stream wrapper', $result);
- $counter ++;
- // -----------------------------------------------------------------------------
- if (true === method_exists('Zend_Debug', 'dump')) {
- $result = TEST_PASS;
- } else {
- $result = TEST_FAIL;
- $failed = true;
- }
- printLine($counter, 'Checking Zend Framework path', $result);
- $counter ++;
- // -----------------------------------------------------------------------------
- if (1 === Zend_Version::compareVersion(PHP_VERSION, MIN_PHP_VERSION)) {
- $result = TEST_PASS;
- } else {
- $result = TEST_FAIL;
- $failed = true;
- }
- printLine($counter, sprintf('Checking Zend Framework version (%s)', Zend_Version::VERSION), $result);
- $counter ++;
- // -----------------------------------------------------------------------------
- if (extension_loaded('soap')) {
- $result = TEST_PASS;
- } else {
- $result = TEST_FAIL;
- $failed = true;
- }
- printLine($counter, 'Checking SOAP extension', $result);
- $counter ++;
- // -----------------------------------------------------------------------------
- if (extension_loaded('dom')) {
- $result = TEST_PASS;
- } else {
- $result = TEST_FAIL;
- $failed = true;
- }
- printLine($counter, 'Checking DOM extension', $result);
- $counter ++;
- // -----------------------------------------------------------------------------
- if (extension_loaded('simplexml')) {
- $result = TEST_PASS;
- } else {
- $result = TEST_FAIL;
- $failed = true;
- }
- printLine($counter, 'Checking SimpleXML extension', $result);
- $counter ++;
- // -----------------------------------------------------------------------------
- if (extension_loaded('libxml')) {
- $result = TEST_PASS;
- } else {
- $result = TEST_FAIL;
- $failed = true;
- }
- printLine($counter, 'Checking libXML extension', $result);
- $counter ++;
- // -----------------------------------------------------------------------------
- $geoData = @file_get_contents('http://api.ipinfodb.com/v2/ip_query.php?key=332bde528d94fe578455e18ad225a01cba8dd359ee915ee46b70ca5e67137252');
- $keys = array (
- 'Ip' => 'IP address',
- 'City' => 'city',
- 'RegionName' => 'region',
- 'CountryName' => 'country'
- );
- if (false !== $geoData) {
- $simplexml = new SimpleXMLElement($geoData);
- foreach ($keys as $key => $value) {
- printLine($counter, sprintf('Checking your %s (%s)', $keys[$key], $simplexml->$key), TEST_PASS);
- $counter ++;
- }
- } else {
- printLine($counter, 'Checking your geo data', TEST_FAIL);
- $failed = true;
- }
- // -----------------------------------------------------------------------------
- $microtime = microtime(true);
- if (false !== file_get_contents(Zend_Service_LiveDocx_MailMerge::WSDL)) {
- $duration = microtime(true) - $microtime;
- $result = TEST_PASS;
- } else {
- $duration = -1;
- $result = TEST_FAIL;
- $failed = true;
- }
- printLine($counter, sprintf('Checking backend WSDL (%01.2fs)', $duration), $result);
- $counter ++;
- // -----------------------------------------------------------------------------
- if (defined('DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME') &&
- defined('DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD')) {
- $result = TEST_PASS;
- } else {
- $result = TEST_FAIL;
- $failed = true;
- }
- printLine($counter, 'Checking backend credentials are defined', $result);
- $counter ++;
- // -----------------------------------------------------------------------------
- $errorMessage = null;
- try {
- $microtime = microtime(true);
- $mailMerge = new Zend_Service_LiveDocx_MailMerge(
- array (
- 'username' => DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME,
- 'password' => DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD
- )
- );
- $mailMerge->logIn();
- $duration = microtime(true) - $microtime;
- } catch (Zend_Service_LiveDocx_Exception $e) {
- $duration = -1;
- $errorMessage = $e->getMessage();
- }
- if (is_null($errorMessage)) {
- $result = TEST_PASS;
- } else {
- $result = TEST_FAIL;
- $failed = true;
- }
- printLine($counter, sprintf('Logging into backend service (%01.2fs)', $duration), $result);
- $counter ++;
- // -----------------------------------------------------------------------------
- if (true === $failed) {
- $message = 'One or more tests failed. The web server environment, in which this script is running, does not meet the requirements for Zend_Service_LiveDocx_*.';
- } else {
- $message = 'Congratulations! All tests passed. The server environment, in which this script is running, is suitable for Zend_Service_LiveDocx_*.';
- }
- print(Demos_Zend_Service_LiveDocx_Helper::wrapLine(PHP_EOL . $message . PHP_EOL . PHP_EOL));
- // -----------------------------------------------------------------------------
- /**
- * Print result line
- *
- * @param int $counter
- * @param string $testString
- * @param mixed $testResult
- * @return void
- */
- function printLine($counter, $testString, $testResult)
- {
- $lineLength = Demos_Zend_Service_LiveDocx_Helper::LINE_LENGTH;
- // counter result
- $padding = $lineLength - (4 + strlen(TEST_PASS));
- $counter = sprintf('%2s: ', $counter);
- $testString = str_pad($testString, $padding, '.', STR_PAD_RIGHT);
- printf('%s%s%s%s', $counter, $testString, $testResult, PHP_EOL);
- }
- // -----------------------------------------------------------------------------
|