@@ -61,6 +61,10 @@ |
||
| 61 | 61 | * @throws Exception|PagSeguroServiceException |
| 62 | 62 | * @throws Exception |
| 63 | 63 | */ |
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @param boolean $onlyCheckoutCode |
|
| 67 | + */ |
|
| 64 | 68 | public static function createCheckoutRequest( |
| 65 | 69 | PagSeguroCredentials $credentials, |
| 66 | 70 | PagSeguroPaymentRequest $paymentRequest, |
@@ -27,107 +27,107 @@ |
||
| 27 | 27 | class PagSeguroPaymentService |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /*** |
|
| 30 | + /*** |
|
| 31 | 31 | * |
| 32 | 32 | */ |
| 33 | - const SERVICE_NAME = 'paymentService'; |
|
| 33 | + const SERVICE_NAME = 'paymentService'; |
|
| 34 | 34 | |
| 35 | - /*** |
|
| 35 | + /*** |
|
| 36 | 36 | * @param PagSeguroConnectionData $connectionData |
| 37 | 37 | * @return string |
| 38 | 38 | */ |
| 39 | - private static function buildCheckoutRequestUrl(PagSeguroConnectionData $connectionData) |
|
| 40 | - { |
|
| 41 | - return $connectionData->getServiceUrl() . '/?' . $connectionData->getCredentialsUrlQuery(); |
|
| 42 | - } |
|
| 39 | + private static function buildCheckoutRequestUrl(PagSeguroConnectionData $connectionData) |
|
| 40 | + { |
|
| 41 | + return $connectionData->getServiceUrl() . '/?' . $connectionData->getCredentialsUrlQuery(); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /*** |
|
| 44 | + /*** |
|
| 45 | 45 | * @param PagSeguroConnectionData $connectionData |
| 46 | 46 | * @param $code |
| 47 | 47 | * @return string |
| 48 | 48 | */ |
| 49 | - private static function buildCheckoutUrl(PagSeguroConnectionData $connectionData, $code) |
|
| 50 | - { |
|
| 51 | - return $connectionData->getPaymentUrl() . $connectionData->getResource('checkoutUrl') . "?code=$code"; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - // createCheckoutRequest is the actual implementation of the Register method |
|
| 55 | - // This separation serves as test hook to validate the Uri |
|
| 56 | - // against the code returned by the service |
|
| 57 | - /*** |
|
| 49 | + private static function buildCheckoutUrl(PagSeguroConnectionData $connectionData, $code) |
|
| 50 | + { |
|
| 51 | + return $connectionData->getPaymentUrl() . $connectionData->getResource('checkoutUrl') . "?code=$code"; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + // createCheckoutRequest is the actual implementation of the Register method |
|
| 55 | + // This separation serves as test hook to validate the Uri |
|
| 56 | + // against the code returned by the service |
|
| 57 | + /*** |
|
| 58 | 58 | * @param PagSeguroCredentials $credentials |
| 59 | 59 | * @param PagSeguroPaymentRequest $paymentRequest |
| 60 | 60 | * @return bool|string |
| 61 | 61 | * @throws Exception|PagSeguroServiceException |
| 62 | 62 | * @throws Exception |
| 63 | 63 | */ |
| 64 | - public static function createCheckoutRequest( |
|
| 65 | - PagSeguroCredentials $credentials, |
|
| 66 | - PagSeguroPaymentRequest $paymentRequest, |
|
| 67 | - $onlyCheckoutCode |
|
| 68 | - ) { |
|
| 69 | - |
|
| 70 | - LogPagSeguro::info("PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - begin"); |
|
| 71 | - |
|
| 72 | - $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 73 | - |
|
| 74 | - try { |
|
| 75 | - |
|
| 76 | - $connection = new PagSeguroHttpConnection(); |
|
| 77 | - $connection->post( |
|
| 78 | - self::buildCheckoutRequestUrl($connectionData), |
|
| 79 | - PagSeguroPaymentParser::getData($paymentRequest), |
|
| 80 | - $connectionData->getServiceTimeout(), |
|
| 81 | - $connectionData->getCharset() |
|
| 82 | - ); |
|
| 83 | - |
|
| 84 | - $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
| 85 | - |
|
| 86 | - switch ($httpStatus->getType()) { |
|
| 87 | - |
|
| 88 | - case 'OK': |
|
| 89 | - $PaymentParserData = PagSeguroPaymentParser::readSuccessXml($connection->getResponse()); |
|
| 90 | - |
|
| 91 | - if ($onlyCheckoutCode) { |
|
| 92 | - $paymentReturn = $PaymentParserData->getCode(); |
|
| 93 | - } else { |
|
| 94 | - $paymentReturn = self::buildCheckoutUrl($connectionData, $PaymentParserData->getCode()); |
|
| 95 | - } |
|
| 96 | - LogPagSeguro::info( |
|
| 97 | - "PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - end {1}" . |
|
| 98 | - $PaymentParserData->getCode() |
|
| 99 | - ); |
|
| 100 | - break; |
|
| 101 | - |
|
| 102 | - case 'BAD_REQUEST': |
|
| 103 | - $errors = PagSeguroPaymentParser::readErrors($connection->getResponse()); |
|
| 104 | - $e = new PagSeguroServiceException($httpStatus, $errors); |
|
| 105 | - LogPagSeguro::error( |
|
| 106 | - "PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - error " . |
|
| 107 | - $e->getOneLineMessage() |
|
| 108 | - ); |
|
| 109 | - throw $e; |
|
| 110 | - break; |
|
| 111 | - |
|
| 112 | - default: |
|
| 113 | - $e = new PagSeguroServiceException($httpStatus); |
|
| 114 | - LogPagSeguro::error( |
|
| 115 | - "PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - error " . |
|
| 116 | - $e->getOneLineMessage() |
|
| 117 | - ); |
|
| 118 | - throw $e; |
|
| 119 | - break; |
|
| 120 | - |
|
| 121 | - } |
|
| 122 | - return (isset($paymentReturn) ? $paymentReturn : false); |
|
| 123 | - |
|
| 124 | - } catch (PagSeguroServiceException $e) { |
|
| 125 | - throw $e; |
|
| 126 | - } |
|
| 127 | - catch (Exception $e) { |
|
| 128 | - LogPagSeguro::error("Exception: " . $e->getMessage()); |
|
| 129 | - throw $e; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - } |
|
| 64 | + public static function createCheckoutRequest( |
|
| 65 | + PagSeguroCredentials $credentials, |
|
| 66 | + PagSeguroPaymentRequest $paymentRequest, |
|
| 67 | + $onlyCheckoutCode |
|
| 68 | + ) { |
|
| 69 | + |
|
| 70 | + LogPagSeguro::info("PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - begin"); |
|
| 71 | + |
|
| 72 | + $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 73 | + |
|
| 74 | + try { |
|
| 75 | + |
|
| 76 | + $connection = new PagSeguroHttpConnection(); |
|
| 77 | + $connection->post( |
|
| 78 | + self::buildCheckoutRequestUrl($connectionData), |
|
| 79 | + PagSeguroPaymentParser::getData($paymentRequest), |
|
| 80 | + $connectionData->getServiceTimeout(), |
|
| 81 | + $connectionData->getCharset() |
|
| 82 | + ); |
|
| 83 | + |
|
| 84 | + $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
| 85 | + |
|
| 86 | + switch ($httpStatus->getType()) { |
|
| 87 | + |
|
| 88 | + case 'OK': |
|
| 89 | + $PaymentParserData = PagSeguroPaymentParser::readSuccessXml($connection->getResponse()); |
|
| 90 | + |
|
| 91 | + if ($onlyCheckoutCode) { |
|
| 92 | + $paymentReturn = $PaymentParserData->getCode(); |
|
| 93 | + } else { |
|
| 94 | + $paymentReturn = self::buildCheckoutUrl($connectionData, $PaymentParserData->getCode()); |
|
| 95 | + } |
|
| 96 | + LogPagSeguro::info( |
|
| 97 | + "PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - end {1}" . |
|
| 98 | + $PaymentParserData->getCode() |
|
| 99 | + ); |
|
| 100 | + break; |
|
| 101 | + |
|
| 102 | + case 'BAD_REQUEST': |
|
| 103 | + $errors = PagSeguroPaymentParser::readErrors($connection->getResponse()); |
|
| 104 | + $e = new PagSeguroServiceException($httpStatus, $errors); |
|
| 105 | + LogPagSeguro::error( |
|
| 106 | + "PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - error " . |
|
| 107 | + $e->getOneLineMessage() |
|
| 108 | + ); |
|
| 109 | + throw $e; |
|
| 110 | + break; |
|
| 111 | + |
|
| 112 | + default: |
|
| 113 | + $e = new PagSeguroServiceException($httpStatus); |
|
| 114 | + LogPagSeguro::error( |
|
| 115 | + "PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - error " . |
|
| 116 | + $e->getOneLineMessage() |
|
| 117 | + ); |
|
| 118 | + throw $e; |
|
| 119 | + break; |
|
| 120 | + |
|
| 121 | + } |
|
| 122 | + return (isset($paymentReturn) ? $paymentReturn : false); |
|
| 123 | + |
|
| 124 | + } catch (PagSeguroServiceException $e) { |
|
| 125 | + throw $e; |
|
| 126 | + } |
|
| 127 | + catch (Exception $e) { |
|
| 128 | + LogPagSeguro::error("Exception: " . $e->getMessage()); |
|
| 129 | + throw $e; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + } |
|
| 133 | 133 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | private static function buildCheckoutRequestUrl(PagSeguroConnectionData $connectionData) |
| 40 | 40 | { |
| 41 | - return $connectionData->getServiceUrl() . '/?' . $connectionData->getCredentialsUrlQuery(); |
|
| 41 | + return $connectionData->getServiceUrl().'/?'.$connectionData->getCredentialsUrlQuery(); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /*** |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | private static function buildCheckoutUrl(PagSeguroConnectionData $connectionData, $code) |
| 50 | 50 | { |
| 51 | - return $connectionData->getPaymentUrl() . $connectionData->getResource('checkoutUrl') . "?code=$code"; |
|
| 51 | + return $connectionData->getPaymentUrl().$connectionData->getResource('checkoutUrl')."?code=$code"; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | // createCheckoutRequest is the actual implementation of the Register method |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $onlyCheckoutCode |
| 68 | 68 | ) { |
| 69 | 69 | |
| 70 | - LogPagSeguro::info("PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - begin"); |
|
| 70 | + LogPagSeguro::info("PagSeguroPaymentService.Register(".$paymentRequest->toString().") - begin"); |
|
| 71 | 71 | |
| 72 | 72 | $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
| 73 | 73 | |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | $paymentReturn = self::buildCheckoutUrl($connectionData, $PaymentParserData->getCode()); |
| 95 | 95 | } |
| 96 | 96 | LogPagSeguro::info( |
| 97 | - "PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - end {1}" . |
|
| 97 | + "PagSeguroPaymentService.Register(".$paymentRequest->toString().") - end {1}". |
|
| 98 | 98 | $PaymentParserData->getCode() |
| 99 | 99 | ); |
| 100 | 100 | break; |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | $errors = PagSeguroPaymentParser::readErrors($connection->getResponse()); |
| 104 | 104 | $e = new PagSeguroServiceException($httpStatus, $errors); |
| 105 | 105 | LogPagSeguro::error( |
| 106 | - "PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - error " . |
|
| 106 | + "PagSeguroPaymentService.Register(".$paymentRequest->toString().") - error ". |
|
| 107 | 107 | $e->getOneLineMessage() |
| 108 | 108 | ); |
| 109 | 109 | throw $e; |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | default: |
| 113 | 113 | $e = new PagSeguroServiceException($httpStatus); |
| 114 | 114 | LogPagSeguro::error( |
| 115 | - "PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - error " . |
|
| 115 | + "PagSeguroPaymentService.Register(".$paymentRequest->toString().") - error ". |
|
| 116 | 116 | $e->getOneLineMessage() |
| 117 | 117 | ); |
| 118 | 118 | throw $e; |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | throw $e; |
| 126 | 126 | } |
| 127 | 127 | catch (Exception $e) { |
| 128 | - LogPagSeguro::error("Exception: " . $e->getMessage()); |
|
| 128 | + LogPagSeguro::error("Exception: ".$e->getMessage()); |
|
| 129 | 129 | throw $e; |
| 130 | 130 | } |
| 131 | 131 | |
@@ -123,8 +123,7 @@ |
||
| 123 | 123 | |
| 124 | 124 | } catch (PagSeguroServiceException $e) { |
| 125 | 125 | throw $e; |
| 126 | - } |
|
| 127 | - catch (Exception $e) { |
|
| 126 | + } catch (Exception $e) { |
|
| 128 | 127 | LogPagSeguro::error("Exception: " . $e->getMessage()); |
| 129 | 128 | throw $e; |
| 130 | 129 | } |
@@ -29,6 +29,9 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | const SERVICE_NAME = 'refundService'; |
| 31 | 31 | |
| 32 | + /** |
|
| 33 | + * @param PagSeguroConnectionData $connectionData |
|
| 34 | + */ |
|
| 32 | 35 | private static function buildRefundURL($connectionData, $transactionCode, $refundValue = null) |
| 33 | 36 | { |
| 34 | 37 | if (is_null($refundValue)) { |
@@ -40,6 +43,10 @@ discard block |
||
| 40 | 43 | } |
| 41 | 44 | } |
| 42 | 45 | |
| 46 | + /** |
|
| 47 | + * @param string $transactionCode |
|
| 48 | + * @param string $refundValue |
|
| 49 | + */ |
|
| 43 | 50 | public static function createRefundRequest( |
| 44 | 51 | PagSeguroCredentials $credentials, |
| 45 | 52 | $transactionCode, |
@@ -32,11 +32,11 @@ discard block |
||
| 32 | 32 | private static function buildRefundURL($connectionData, $transactionCode, $refundValue = null) |
| 33 | 33 | { |
| 34 | 34 | if (is_null($refundValue)) { |
| 35 | - return $connectionData->getServiceUrl() . '?' . $connectionData->getCredentialsUrlQuery() |
|
| 36 | - . "&transactionCode=" . $transactionCode; |
|
| 35 | + return $connectionData->getServiceUrl().'?'.$connectionData->getCredentialsUrlQuery() |
|
| 36 | + . "&transactionCode=".$transactionCode; |
|
| 37 | 37 | } else { |
| 38 | - return $connectionData->getServiceUrl() . '?' . $connectionData->getCredentialsUrlQuery() |
|
| 39 | - . "&transactionCode=" . $transactionCode . "&refundValue=" . $refundValue; |
|
| 38 | + return $connectionData->getServiceUrl().'?'.$connectionData->getCredentialsUrlQuery() |
|
| 39 | + . "&transactionCode=".$transactionCode."&refundValue=".$refundValue; |
|
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | 42 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | PagSeguroCredentials $credentials, |
| 45 | 45 | $transactionCode, |
| 46 | 46 | $refundValue = null |
| 47 | - ){ |
|
| 47 | + ) { |
|
| 48 | 48 | |
| 49 | 49 | LogPagSeguro::info("PagSeguroRefundService.Register(".$transactionCode.") - begin"); |
| 50 | 50 | $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $errors = PagSeguroRefundParser::readErrors($connection->getResponse()); |
| 80 | 80 | $err = new PagSeguroServiceException($httpStatus, $errors); |
| 81 | 81 | LogPagSeguro::error( |
| 82 | - "PagSeguroRefundService.createRefundRequest() - error " . |
|
| 82 | + "PagSeguroRefundService.createRefundRequest() - error ". |
|
| 83 | 83 | $err->getOneLineMessage() |
| 84 | 84 | ); |
| 85 | 85 | throw $err; |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | default: |
| 88 | 88 | $err = new PagSeguroServiceException($httpStatus); |
| 89 | 89 | LogPagSeguro::error( |
| 90 | - "PagSeguroRefundService.createRefundRequest() - error " . |
|
| 90 | + "PagSeguroRefundService.createRefundRequest() - error ". |
|
| 91 | 91 | $err->getOneLineMessage() |
| 92 | 92 | ); |
| 93 | 93 | throw $err; |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | } catch (PagSeguroServiceException $err) { |
| 99 | 99 | throw $err; |
| 100 | 100 | } catch (Exception $err) { |
| 101 | - LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 101 | + LogPagSeguro::error("Exception: ".$err->getMessage()); |
|
| 102 | 102 | throw $err; |
| 103 | 103 | } |
| 104 | 104 | } |
@@ -27,79 +27,79 @@ |
||
| 27 | 27 | class PagSeguroRefundService |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - const SERVICE_NAME = 'refundService'; |
|
| 30 | + const SERVICE_NAME = 'refundService'; |
|
| 31 | 31 | |
| 32 | - private static function buildRefundURL($connectionData, $transactionCode, $refundValue = null) |
|
| 33 | - { |
|
| 34 | - if (is_null($refundValue)) { |
|
| 35 | - return $connectionData->getServiceUrl() . '?' . $connectionData->getCredentialsUrlQuery() |
|
| 36 | - . "&transactionCode=" . $transactionCode; |
|
| 37 | - } else { |
|
| 38 | - return $connectionData->getServiceUrl() . '?' . $connectionData->getCredentialsUrlQuery() |
|
| 39 | - . "&transactionCode=" . $transactionCode . "&refundValue=" . $refundValue; |
|
| 40 | - } |
|
| 41 | - } |
|
| 32 | + private static function buildRefundURL($connectionData, $transactionCode, $refundValue = null) |
|
| 33 | + { |
|
| 34 | + if (is_null($refundValue)) { |
|
| 35 | + return $connectionData->getServiceUrl() . '?' . $connectionData->getCredentialsUrlQuery() |
|
| 36 | + . "&transactionCode=" . $transactionCode; |
|
| 37 | + } else { |
|
| 38 | + return $connectionData->getServiceUrl() . '?' . $connectionData->getCredentialsUrlQuery() |
|
| 39 | + . "&transactionCode=" . $transactionCode . "&refundValue=" . $refundValue; |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public static function createRefundRequest( |
|
| 44 | - PagSeguroCredentials $credentials, |
|
| 45 | - $transactionCode, |
|
| 46 | - $refundValue = null |
|
| 47 | - ){ |
|
| 43 | + public static function createRefundRequest( |
|
| 44 | + PagSeguroCredentials $credentials, |
|
| 45 | + $transactionCode, |
|
| 46 | + $refundValue = null |
|
| 47 | + ){ |
|
| 48 | 48 | |
| 49 | - LogPagSeguro::info("PagSeguroRefundService.Register(".$transactionCode.") - begin"); |
|
| 50 | - $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 49 | + LogPagSeguro::info("PagSeguroRefundService.Register(".$transactionCode.") - begin"); |
|
| 50 | + $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 51 | 51 | |
| 52 | - if (is_null($refundValue)) { |
|
| 53 | - $url = self::buildRefundURL($connectionData, $transactionCode); |
|
| 54 | - } else { |
|
| 55 | - $url = self::buildRefundURL($connectionData, $transactionCode, $refundValue); |
|
| 56 | - } |
|
| 52 | + if (is_null($refundValue)) { |
|
| 53 | + $url = self::buildRefundURL($connectionData, $transactionCode); |
|
| 54 | + } else { |
|
| 55 | + $url = self::buildRefundURL($connectionData, $transactionCode, $refundValue); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - try { |
|
| 58 | + try { |
|
| 59 | 59 | |
| 60 | - $connection = new PagSeguroHttpConnection(); |
|
| 61 | - $connection->post( |
|
| 62 | - $url, |
|
| 63 | - array(), |
|
| 64 | - $connectionData->getServiceTimeout(), |
|
| 65 | - $connectionData->getCharset() |
|
| 66 | - ); |
|
| 60 | + $connection = new PagSeguroHttpConnection(); |
|
| 61 | + $connection->post( |
|
| 62 | + $url, |
|
| 63 | + array(), |
|
| 64 | + $connectionData->getServiceTimeout(), |
|
| 65 | + $connectionData->getCharset() |
|
| 66 | + ); |
|
| 67 | 67 | |
| 68 | - $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
| 68 | + $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
| 69 | 69 | |
| 70 | - switch ($httpStatus->getType()) { |
|
| 71 | - case 'OK': |
|
| 70 | + switch ($httpStatus->getType()) { |
|
| 71 | + case 'OK': |
|
| 72 | 72 | |
| 73 | - $result = PagSeguroRefundParser::readSuccessXml($connection->getResponse()); |
|
| 74 | - LogPagSeguro::info( |
|
| 75 | - "PagSeguroRefundService.createRefundRequest(".$result.") - end " |
|
| 76 | - ); |
|
| 77 | - break; |
|
| 78 | - case 'BAD_REQUEST': |
|
| 79 | - $errors = PagSeguroRefundParser::readErrors($connection->getResponse()); |
|
| 80 | - $err = new PagSeguroServiceException($httpStatus, $errors); |
|
| 81 | - LogPagSeguro::error( |
|
| 82 | - "PagSeguroRefundService.createRefundRequest() - error " . |
|
| 83 | - $err->getOneLineMessage() |
|
| 84 | - ); |
|
| 85 | - throw $err; |
|
| 86 | - break; |
|
| 87 | - default: |
|
| 88 | - $err = new PagSeguroServiceException($httpStatus); |
|
| 89 | - LogPagSeguro::error( |
|
| 90 | - "PagSeguroRefundService.createRefundRequest() - error " . |
|
| 91 | - $err->getOneLineMessage() |
|
| 92 | - ); |
|
| 93 | - throw $err; |
|
| 94 | - break; |
|
| 95 | - } |
|
| 96 | - return isset($result) ? $result : false; |
|
| 73 | + $result = PagSeguroRefundParser::readSuccessXml($connection->getResponse()); |
|
| 74 | + LogPagSeguro::info( |
|
| 75 | + "PagSeguroRefundService.createRefundRequest(".$result.") - end " |
|
| 76 | + ); |
|
| 77 | + break; |
|
| 78 | + case 'BAD_REQUEST': |
|
| 79 | + $errors = PagSeguroRefundParser::readErrors($connection->getResponse()); |
|
| 80 | + $err = new PagSeguroServiceException($httpStatus, $errors); |
|
| 81 | + LogPagSeguro::error( |
|
| 82 | + "PagSeguroRefundService.createRefundRequest() - error " . |
|
| 83 | + $err->getOneLineMessage() |
|
| 84 | + ); |
|
| 85 | + throw $err; |
|
| 86 | + break; |
|
| 87 | + default: |
|
| 88 | + $err = new PagSeguroServiceException($httpStatus); |
|
| 89 | + LogPagSeguro::error( |
|
| 90 | + "PagSeguroRefundService.createRefundRequest() - error " . |
|
| 91 | + $err->getOneLineMessage() |
|
| 92 | + ); |
|
| 93 | + throw $err; |
|
| 94 | + break; |
|
| 95 | + } |
|
| 96 | + return isset($result) ? $result : false; |
|
| 97 | 97 | |
| 98 | - } catch (PagSeguroServiceException $err) { |
|
| 99 | - throw $err; |
|
| 100 | - } catch (Exception $err) { |
|
| 101 | - LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 102 | - throw $err; |
|
| 103 | - } |
|
| 104 | - } |
|
| 98 | + } catch (PagSeguroServiceException $err) { |
|
| 99 | + throw $err; |
|
| 100 | + } catch (Exception $err) { |
|
| 101 | + LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 102 | + throw $err; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | 105 | } |
| 106 | 106 | \ No newline at end of file |
@@ -44,6 +44,10 @@ |
||
| 44 | 44 | * @throws Exception|PagSeguroServiceException |
| 45 | 45 | * @throws Exception |
| 46 | 46 | */ |
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @param PagSeguroAccountCredentials $credentials |
|
| 50 | + */ |
|
| 47 | 51 | public static function getSession($credentials) |
| 48 | 52 | { |
| 49 | 53 | $connectionData = new PagSeguroConnectionData($credentials, 'sessionService'); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | private static function buildSessionURL($connectionData) |
| 36 | 36 | { |
| 37 | - return $connectionData->getWebserviceUrl() . $connectionData->getSessionUrl(); |
|
| 37 | + return $connectionData->getWebserviceUrl().$connectionData->getSessionUrl(); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /*** |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | { |
| 49 | 49 | $connectionData = new PagSeguroConnectionData($credentials, 'sessionService'); |
| 50 | 50 | |
| 51 | - $url = self::buildSessionURL($connectionData) . "?" . $connectionData->getCredentialsUrlQuery(); |
|
| 51 | + $url = self::buildSessionURL($connectionData)."?".$connectionData->getCredentialsUrlQuery(); |
|
| 52 | 52 | |
| 53 | 53 | try { |
| 54 | 54 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | return $session->getId(); |
| 72 | 72 | |
| 73 | 73 | LogPagSeguro::info( |
| 74 | - "PagSeguroSessionService.getSession()(" . $session->toString() . ") - end {1}" |
|
| 74 | + "PagSeguroSessionService.getSession()(".$session->toString().") - end {1}" |
|
| 75 | 75 | ); |
| 76 | 76 | break; |
| 77 | 77 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $errors = PagSeguroSessionParser::readErrors($connection->getStatus()); |
| 80 | 80 | $e = new PagSeguroServiceException($httpStatus, $errors); |
| 81 | 81 | LogPagSeguro::error( |
| 82 | - "PagSeguroSessionService.getSession() - error " . |
|
| 82 | + "PagSeguroSessionService.getSession() - error ". |
|
| 83 | 83 | $e->getOneLineMessage() |
| 84 | 84 | ); |
| 85 | 85 | throw $e; |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | $e = new PagSeguroServiceException($httpStatus); |
| 91 | 91 | LogPagSeguro::error( |
| 92 | - "PagSeguroSessionService.getSession() - error " . |
|
| 92 | + "PagSeguroSessionService.getSession() - error ". |
|
| 93 | 93 | $e->getOneLineMessage() |
| 94 | 94 | ); |
| 95 | 95 | throw $e; |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | } catch (PagSeguroServiceException $e) { |
| 99 | 99 | throw $e; |
| 100 | 100 | } catch (Exception $e) { |
| 101 | - LogPagSeguro::error("Exception: " . $e->getMessage()); |
|
| 101 | + LogPagSeguro::error("Exception: ".$e->getMessage()); |
|
| 102 | 102 | throw $e; |
| 103 | 103 | } |
| 104 | 104 | } |
@@ -27,80 +27,80 @@ |
||
| 27 | 27 | class PagSeguroSessionService |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /*** |
|
| 30 | + /*** |
|
| 31 | 31 | * Build URL for get session. |
| 32 | 32 | * @param PagSeguroConnectionData $connectionData |
| 33 | 33 | * @return string session URL |
| 34 | 34 | */ |
| 35 | - private static function buildSessionURL($connectionData) |
|
| 36 | - { |
|
| 37 | - return $connectionData->getWebserviceUrl() . $connectionData->getSessionUrl(); |
|
| 38 | - } |
|
| 35 | + private static function buildSessionURL($connectionData) |
|
| 36 | + { |
|
| 37 | + return $connectionData->getWebserviceUrl() . $connectionData->getSessionUrl(); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /*** |
|
| 40 | + /*** |
|
| 41 | 41 | * Get session for direct payment from webservice |
| 42 | 42 | * @param $credentials PagSeguroAccountCredentials |
| 43 | 43 | * @return bool|string |
| 44 | 44 | * @throws Exception|PagSeguroServiceException |
| 45 | 45 | * @throws Exception |
| 46 | 46 | */ |
| 47 | - public static function getSession($credentials) |
|
| 48 | - { |
|
| 49 | - $connectionData = new PagSeguroConnectionData($credentials, 'sessionService'); |
|
| 47 | + public static function getSession($credentials) |
|
| 48 | + { |
|
| 49 | + $connectionData = new PagSeguroConnectionData($credentials, 'sessionService'); |
|
| 50 | 50 | |
| 51 | - $url = self::buildSessionURL($connectionData) . "?" . $connectionData->getCredentialsUrlQuery(); |
|
| 51 | + $url = self::buildSessionURL($connectionData) . "?" . $connectionData->getCredentialsUrlQuery(); |
|
| 52 | 52 | |
| 53 | - try { |
|
| 53 | + try { |
|
| 54 | 54 | |
| 55 | - $connection = new PagSeguroHttpConnection(); |
|
| 56 | - $connection->post( |
|
| 57 | - $url, |
|
| 58 | - array(), |
|
| 59 | - $connectionData->getServiceTimeout(), |
|
| 60 | - $connectionData->getCharset() |
|
| 61 | - ); |
|
| 55 | + $connection = new PagSeguroHttpConnection(); |
|
| 56 | + $connection->post( |
|
| 57 | + $url, |
|
| 58 | + array(), |
|
| 59 | + $connectionData->getServiceTimeout(), |
|
| 60 | + $connectionData->getCharset() |
|
| 61 | + ); |
|
| 62 | 62 | |
| 63 | - $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
| 63 | + $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
| 64 | 64 | |
| 65 | - switch ($httpStatus->getType()) { |
|
| 65 | + switch ($httpStatus->getType()) { |
|
| 66 | 66 | |
| 67 | - case 'OK': |
|
| 67 | + case 'OK': |
|
| 68 | 68 | |
| 69 | - $session = PagSeguroSessionParser::readResult($connection->getResponse()); |
|
| 69 | + $session = PagSeguroSessionParser::readResult($connection->getResponse()); |
|
| 70 | 70 | |
| 71 | - return $session->getId(); |
|
| 71 | + return $session->getId(); |
|
| 72 | 72 | |
| 73 | - LogPagSeguro::info( |
|
| 74 | - "PagSeguroSessionService.getSession()(" . $session->toString() . ") - end {1}" |
|
| 75 | - ); |
|
| 76 | - break; |
|
| 73 | + LogPagSeguro::info( |
|
| 74 | + "PagSeguroSessionService.getSession()(" . $session->toString() . ") - end {1}" |
|
| 75 | + ); |
|
| 76 | + break; |
|
| 77 | 77 | |
| 78 | - case 'BAD_REQUEST': |
|
| 79 | - $errors = PagSeguroSessionParser::readErrors($connection->getStatus()); |
|
| 80 | - $e = new PagSeguroServiceException($httpStatus, $errors); |
|
| 81 | - LogPagSeguro::error( |
|
| 82 | - "PagSeguroSessionService.getSession() - error " . |
|
| 83 | - $e->getOneLineMessage() |
|
| 84 | - ); |
|
| 85 | - throw $e; |
|
| 86 | - break; |
|
| 78 | + case 'BAD_REQUEST': |
|
| 79 | + $errors = PagSeguroSessionParser::readErrors($connection->getStatus()); |
|
| 80 | + $e = new PagSeguroServiceException($httpStatus, $errors); |
|
| 81 | + LogPagSeguro::error( |
|
| 82 | + "PagSeguroSessionService.getSession() - error " . |
|
| 83 | + $e->getOneLineMessage() |
|
| 84 | + ); |
|
| 85 | + throw $e; |
|
| 86 | + break; |
|
| 87 | 87 | |
| 88 | - default: |
|
| 88 | + default: |
|
| 89 | 89 | |
| 90 | - $e = new PagSeguroServiceException($httpStatus); |
|
| 91 | - LogPagSeguro::error( |
|
| 92 | - "PagSeguroSessionService.getSession() - error " . |
|
| 93 | - $e->getOneLineMessage() |
|
| 94 | - ); |
|
| 95 | - throw $e; |
|
| 96 | - break; |
|
| 97 | - } |
|
| 98 | - } catch (PagSeguroServiceException $e) { |
|
| 99 | - throw $e; |
|
| 100 | - } catch (Exception $e) { |
|
| 101 | - LogPagSeguro::error("Exception: " . $e->getMessage()); |
|
| 102 | - throw $e; |
|
| 103 | - } |
|
| 104 | - } |
|
| 90 | + $e = new PagSeguroServiceException($httpStatus); |
|
| 91 | + LogPagSeguro::error( |
|
| 92 | + "PagSeguroSessionService.getSession() - error " . |
|
| 93 | + $e->getOneLineMessage() |
|
| 94 | + ); |
|
| 95 | + throw $e; |
|
| 96 | + break; |
|
| 97 | + } |
|
| 98 | + } catch (PagSeguroServiceException $e) { |
|
| 99 | + throw $e; |
|
| 100 | + } catch (Exception $e) { |
|
| 101 | + LogPagSeguro::error("Exception: " . $e->getMessage()); |
|
| 102 | + throw $e; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | 106 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * @param PagSeguroConnectionData $connectionData |
| 39 | - * @param $transactionCode |
|
| 39 | + * @param string $transactionCode |
|
| 40 | 40 | * @return string |
| 41 | 41 | */ |
| 42 | 42 | private static function buildSearchUrlByCode(PagSeguroConnectionData $connectionData, $transactionCode) |
@@ -260,11 +260,11 @@ discard block |
||
| 260 | 260 | |
| 261 | 261 | /** |
| 262 | 262 | * @param PagSeguroCredentials $credentials |
| 263 | - * @param $reference |
|
| 264 | - * @param null $initialDate |
|
| 265 | - * @param null $finalDate |
|
| 266 | - * @param null $pageNumber |
|
| 267 | - * @param null $maxPageResults |
|
| 263 | + * @param string $reference |
|
| 264 | + * @param string $initialDate |
|
| 265 | + * @param string $finalDate |
|
| 266 | + * @param integer $pageNumber |
|
| 267 | + * @param integer $maxPageResults |
|
| 268 | 268 | * @throws Exception |
| 269 | 269 | * @throws PagSeguroServiceException |
| 270 | 270 | */ |
@@ -314,10 +314,10 @@ discard block |
||
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
| 317 | - * @param $pageNumber |
|
| 318 | - * @param $maxPageResults |
|
| 319 | - * @param $initialDate |
|
| 320 | - * @param null $finalDate |
|
| 317 | + * @param integer|null $pageNumber |
|
| 318 | + * @param integer|null $maxPageResults |
|
| 319 | + * @param string $initialDate |
|
| 320 | + * @param string|null $finalDate |
|
| 321 | 321 | * @return array |
| 322 | 322 | */ |
| 323 | 323 | private function buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate = null) |
@@ -334,8 +334,8 @@ discard block |
||
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | /** |
| 337 | - * @param $connection |
|
| 338 | - * @param $code |
|
| 337 | + * @param PagSeguroHttpConnection $connection |
|
| 338 | + * @param string $code |
|
| 339 | 339 | * @return bool|PagSeguroTransaction |
| 340 | 340 | * @throws PagSeguroServiceException |
| 341 | 341 | */ |
@@ -376,9 +376,9 @@ discard block |
||
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | /** |
| 379 | - * @param $connection |
|
| 380 | - * @param null $initialDate |
|
| 381 | - * @param null $finalDate |
|
| 379 | + * @param PagSeguroHttpConnection $connection |
|
| 380 | + * @param string $initialDate |
|
| 381 | + * @param string|null $finalDate |
|
| 382 | 382 | * @return bool|PagSeguroTransactionSearchResult |
| 383 | 383 | * @throws PagSeguroServiceException |
| 384 | 384 | */ |
@@ -27,96 +27,96 @@ discard block |
||
| 27 | 27 | class PagSeguroTransactionSearchService |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * |
|
| 32 | - */ |
|
| 33 | - const SERVICE_NAME = 'transactionSearchService'; |
|
| 34 | - |
|
| 35 | - private static $logService; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @param PagSeguroConnectionData $connectionData |
|
| 39 | - * @param $transactionCode |
|
| 40 | - * @return string |
|
| 41 | - */ |
|
| 42 | - private static function buildSearchUrlByCode(PagSeguroConnectionData $connectionData, $transactionCode) |
|
| 43 | - { |
|
| 44 | - $url = $connectionData->getServiceUrl('v3'); |
|
| 45 | - return "{$url}/{$transactionCode}/?" . $connectionData->getCredentialsUrlQuery(); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @param PagSeguroConnectionData $connectionData |
|
| 50 | - * @param array $searchParams |
|
| 51 | - * @return string |
|
| 52 | - */ |
|
| 53 | - private static function buildSearchUrlByDate(PagSeguroConnectionData $connectionData, array $searchParams) |
|
| 54 | - { |
|
| 55 | - $url = $connectionData->getServiceUrl('v2'); |
|
| 56 | - $initialDate = $searchParams['initialDate'] != null ? $searchParams['initialDate'] : ""; |
|
| 57 | - $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=" . $searchParams['finalDate']) : ""; |
|
| 58 | - if ($searchParams['pageNumber'] != null) { |
|
| 59 | - $page = "&page=" . $searchParams['pageNumber']; |
|
| 60 | - } |
|
| 61 | - if ($searchParams['maxPageResults'] != null) { |
|
| 62 | - $maxPageResults = "&maxPageResults=" . $searchParams['maxPageResults']; |
|
| 63 | - } |
|
| 64 | - return "{$url}/?" . $connectionData->getCredentialsUrlQuery() . |
|
| 65 | - "&initialDate={$initialDate}{$finalDate}{$page}{$maxPageResults}"; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @param PagSeguroConnectionData $connectionData |
|
| 70 | - * @param array $searchParams |
|
| 71 | - * @return string |
|
| 72 | - */ |
|
| 73 | - private static function buildSearchUrlAbandoned(PagSeguroConnectionData $connectionData, array $searchParams) |
|
| 74 | - { |
|
| 75 | - $url = $connectionData->getServiceUrl('v2'); |
|
| 76 | - |
|
| 77 | - $initialDate = $searchParams['initialDate'] != null ? $searchParams['initialDate'] : ""; |
|
| 78 | - $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=" . $searchParams['finalDate']) : ""; |
|
| 79 | - if ($searchParams['pageNumber'] != null) { |
|
| 80 | - $page = "&page=" . $searchParams['pageNumber']; |
|
| 81 | - } |
|
| 82 | - if ($searchParams['maxPageResults'] != null) { |
|
| 83 | - $maxPageResults = "&maxPageResults=" . $searchParams['maxPageResults']; |
|
| 84 | - } |
|
| 85 | - return "{$url}/abandoned/?" . $connectionData->getCredentialsUrlQuery() . |
|
| 86 | - "&initialDate={$initialDate}&finalDate={$finalDate}{$page}{$maxPageResults}"; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @param PagSeguroConnectionData $connectionData |
|
| 91 | - * @param $reference |
|
| 92 | - * @param null $searchParams |
|
| 93 | - * @return string |
|
| 94 | - */ |
|
| 95 | - private static function buildSearchUrlByReference( |
|
| 96 | - PagSeguroConnectionData $connectionData, |
|
| 97 | - $reference, |
|
| 98 | - $searchParams = null |
|
| 99 | - ){ |
|
| 100 | - $url = $connectionData->getServiceUrl('v2'); |
|
| 101 | - if ($searchParams == null) { |
|
| 102 | - return "{$url}?" . $connectionData->getCredentialsUrlQuery() . "&reference=" . $reference; |
|
| 103 | - } else { |
|
| 104 | - |
|
| 105 | - $initialDate = $searchParams['initialDate'] != null ? $searchParams['initialDate'] : ""; |
|
| 106 | - $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=" . $searchParams['finalDate']) : ""; |
|
| 107 | - if ($searchParams['pageNumber'] != null) { |
|
| 108 | - $page = "&page=" . $searchParams['pageNumber']; |
|
| 109 | - } |
|
| 110 | - if ($searchParams['maxPageResults'] != null) { |
|
| 111 | - $maxPageResults = "&maxPageResults=" . $searchParams['maxPageResults']; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - return "{$url}?" . $connectionData->getCredentialsUrlQuery() . "&reference=" . $reference |
|
| 115 | - . "&initialDate={$initialDate}&finalDate={$finalDate}{$page}{$maxPageResults}"; |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /*** |
|
| 30 | + /** |
|
| 31 | + * |
|
| 32 | + */ |
|
| 33 | + const SERVICE_NAME = 'transactionSearchService'; |
|
| 34 | + |
|
| 35 | + private static $logService; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @param PagSeguroConnectionData $connectionData |
|
| 39 | + * @param $transactionCode |
|
| 40 | + * @return string |
|
| 41 | + */ |
|
| 42 | + private static function buildSearchUrlByCode(PagSeguroConnectionData $connectionData, $transactionCode) |
|
| 43 | + { |
|
| 44 | + $url = $connectionData->getServiceUrl('v3'); |
|
| 45 | + return "{$url}/{$transactionCode}/?" . $connectionData->getCredentialsUrlQuery(); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @param PagSeguroConnectionData $connectionData |
|
| 50 | + * @param array $searchParams |
|
| 51 | + * @return string |
|
| 52 | + */ |
|
| 53 | + private static function buildSearchUrlByDate(PagSeguroConnectionData $connectionData, array $searchParams) |
|
| 54 | + { |
|
| 55 | + $url = $connectionData->getServiceUrl('v2'); |
|
| 56 | + $initialDate = $searchParams['initialDate'] != null ? $searchParams['initialDate'] : ""; |
|
| 57 | + $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=" . $searchParams['finalDate']) : ""; |
|
| 58 | + if ($searchParams['pageNumber'] != null) { |
|
| 59 | + $page = "&page=" . $searchParams['pageNumber']; |
|
| 60 | + } |
|
| 61 | + if ($searchParams['maxPageResults'] != null) { |
|
| 62 | + $maxPageResults = "&maxPageResults=" . $searchParams['maxPageResults']; |
|
| 63 | + } |
|
| 64 | + return "{$url}/?" . $connectionData->getCredentialsUrlQuery() . |
|
| 65 | + "&initialDate={$initialDate}{$finalDate}{$page}{$maxPageResults}"; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @param PagSeguroConnectionData $connectionData |
|
| 70 | + * @param array $searchParams |
|
| 71 | + * @return string |
|
| 72 | + */ |
|
| 73 | + private static function buildSearchUrlAbandoned(PagSeguroConnectionData $connectionData, array $searchParams) |
|
| 74 | + { |
|
| 75 | + $url = $connectionData->getServiceUrl('v2'); |
|
| 76 | + |
|
| 77 | + $initialDate = $searchParams['initialDate'] != null ? $searchParams['initialDate'] : ""; |
|
| 78 | + $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=" . $searchParams['finalDate']) : ""; |
|
| 79 | + if ($searchParams['pageNumber'] != null) { |
|
| 80 | + $page = "&page=" . $searchParams['pageNumber']; |
|
| 81 | + } |
|
| 82 | + if ($searchParams['maxPageResults'] != null) { |
|
| 83 | + $maxPageResults = "&maxPageResults=" . $searchParams['maxPageResults']; |
|
| 84 | + } |
|
| 85 | + return "{$url}/abandoned/?" . $connectionData->getCredentialsUrlQuery() . |
|
| 86 | + "&initialDate={$initialDate}&finalDate={$finalDate}{$page}{$maxPageResults}"; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @param PagSeguroConnectionData $connectionData |
|
| 91 | + * @param $reference |
|
| 92 | + * @param null $searchParams |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 95 | + private static function buildSearchUrlByReference( |
|
| 96 | + PagSeguroConnectionData $connectionData, |
|
| 97 | + $reference, |
|
| 98 | + $searchParams = null |
|
| 99 | + ){ |
|
| 100 | + $url = $connectionData->getServiceUrl('v2'); |
|
| 101 | + if ($searchParams == null) { |
|
| 102 | + return "{$url}?" . $connectionData->getCredentialsUrlQuery() . "&reference=" . $reference; |
|
| 103 | + } else { |
|
| 104 | + |
|
| 105 | + $initialDate = $searchParams['initialDate'] != null ? $searchParams['initialDate'] : ""; |
|
| 106 | + $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=" . $searchParams['finalDate']) : ""; |
|
| 107 | + if ($searchParams['pageNumber'] != null) { |
|
| 108 | + $page = "&page=" . $searchParams['pageNumber']; |
|
| 109 | + } |
|
| 110 | + if ($searchParams['maxPageResults'] != null) { |
|
| 111 | + $maxPageResults = "&maxPageResults=" . $searchParams['maxPageResults']; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + return "{$url}?" . $connectionData->getCredentialsUrlQuery() . "&reference=" . $reference |
|
| 115 | + . "&initialDate={$initialDate}&finalDate={$finalDate}{$page}{$maxPageResults}"; |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /*** |
|
| 120 | 120 | * Finds a transaction with a matching transaction code |
| 121 | 121 | * |
| 122 | 122 | * @param PagSeguroCredentials $credentials |
@@ -126,35 +126,35 @@ discard block |
||
| 126 | 126 | * @throws PagSeguroServiceException |
| 127 | 127 | * @throws Exception |
| 128 | 128 | */ |
| 129 | - public static function searchByCode(PagSeguroCredentials $credentials, $transactionCode) |
|
| 130 | - { |
|
| 129 | + public static function searchByCode(PagSeguroCredentials $credentials, $transactionCode) |
|
| 130 | + { |
|
| 131 | 131 | |
| 132 | - LogPagSeguro::info("PagSeguroTransactionSearchService.SearchByCode($transactionCode) - begin"); |
|
| 132 | + LogPagSeguro::info("PagSeguroTransactionSearchService.SearchByCode($transactionCode) - begin"); |
|
| 133 | 133 | |
| 134 | - $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 134 | + $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 135 | 135 | |
| 136 | - try { |
|
| 136 | + try { |
|
| 137 | 137 | |
| 138 | - $connection = new PagSeguroHttpConnection(); |
|
| 139 | - $connection->get( |
|
| 140 | - self::buildSearchUrlByCode($connectionData, $transactionCode), |
|
| 141 | - $connectionData->getServiceTimeout(), |
|
| 142 | - $connectionData->getCharset() |
|
| 143 | - ); |
|
| 138 | + $connection = new PagSeguroHttpConnection(); |
|
| 139 | + $connection->get( |
|
| 140 | + self::buildSearchUrlByCode($connectionData, $transactionCode), |
|
| 141 | + $connectionData->getServiceTimeout(), |
|
| 142 | + $connectionData->getCharset() |
|
| 143 | + ); |
|
| 144 | 144 | |
| 145 | - return self::searchByCodeResult($connection, $transactionCode); |
|
| 145 | + return self::searchByCodeResult($connection, $transactionCode); |
|
| 146 | 146 | |
| 147 | - } catch (PagSeguroServiceException $err) { |
|
| 148 | - throw $err; |
|
| 149 | - } |
|
| 150 | - catch (Exception $err) { |
|
| 151 | - LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 152 | - throw $err; |
|
| 153 | - } |
|
| 147 | + } catch (PagSeguroServiceException $err) { |
|
| 148 | + throw $err; |
|
| 149 | + } |
|
| 150 | + catch (Exception $err) { |
|
| 151 | + LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 152 | + throw $err; |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - } |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - /*** |
|
| 157 | + /*** |
|
| 158 | 158 | * Search transactions associated with this set of credentials within a date range |
| 159 | 159 | * |
| 160 | 160 | * @param PagSeguroCredentials $credentials |
@@ -167,45 +167,45 @@ discard block |
||
| 167 | 167 | * @throws PagSeguroServiceException |
| 168 | 168 | * @throws Exception |
| 169 | 169 | */ |
| 170 | - public static function searchByDate( |
|
| 171 | - PagSeguroCredentials $credentials, |
|
| 172 | - $pageNumber, |
|
| 173 | - $maxPageResults, |
|
| 174 | - $initialDate, |
|
| 175 | - $finalDate = null |
|
| 176 | - ) { |
|
| 170 | + public static function searchByDate( |
|
| 171 | + PagSeguroCredentials $credentials, |
|
| 172 | + $pageNumber, |
|
| 173 | + $maxPageResults, |
|
| 174 | + $initialDate, |
|
| 175 | + $finalDate = null |
|
| 176 | + ) { |
|
| 177 | 177 | |
| 178 | - LogPagSeguro::info( |
|
| 179 | - "PagSeguroTransactionSearchService.SearchByDate(initialDate=" . PagSeguroHelper::formatDate($initialDate) . |
|
| 180 | - ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - begin" |
|
| 181 | - ); |
|
| 178 | + LogPagSeguro::info( |
|
| 179 | + "PagSeguroTransactionSearchService.SearchByDate(initialDate=" . PagSeguroHelper::formatDate($initialDate) . |
|
| 180 | + ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - begin" |
|
| 181 | + ); |
|
| 182 | 182 | |
| 183 | - $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 183 | + $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 184 | 184 | |
| 185 | - $searchParams = self::buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate); |
|
| 185 | + $searchParams = self::buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate); |
|
| 186 | 186 | |
| 187 | - try { |
|
| 187 | + try { |
|
| 188 | 188 | |
| 189 | - $connection = new PagSeguroHttpConnection(); |
|
| 190 | - $connection->get( |
|
| 191 | - self::buildSearchUrlByDate($connectionData, $searchParams), |
|
| 192 | - $connectionData->getServiceTimeout(), |
|
| 193 | - $connectionData->getCharset() |
|
| 194 | - ); |
|
| 189 | + $connection = new PagSeguroHttpConnection(); |
|
| 190 | + $connection->get( |
|
| 191 | + self::buildSearchUrlByDate($connectionData, $searchParams), |
|
| 192 | + $connectionData->getServiceTimeout(), |
|
| 193 | + $connectionData->getCharset() |
|
| 194 | + ); |
|
| 195 | 195 | |
| 196 | - self::$logService = "SearchByDate"; |
|
| 197 | - return self::searchResult($connection, $initialDate, $finalDate); |
|
| 196 | + self::$logService = "SearchByDate"; |
|
| 197 | + return self::searchResult($connection, $initialDate, $finalDate); |
|
| 198 | 198 | |
| 199 | - } catch (PagSeguroServiceException $err) { |
|
| 200 | - throw $err; |
|
| 201 | - } catch (Exception $err) { |
|
| 202 | - LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 203 | - throw $err; |
|
| 204 | - } |
|
| 199 | + } catch (PagSeguroServiceException $err) { |
|
| 200 | + throw $err; |
|
| 201 | + } catch (Exception $err) { |
|
| 202 | + LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 203 | + throw $err; |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - /*** |
|
| 208 | + /*** |
|
| 209 | 209 | * Search transactions abandoned associated with this set of credentials within a date range |
| 210 | 210 | * |
| 211 | 211 | * @param PagSeguroCredentials $credentials |
@@ -218,211 +218,211 @@ discard block |
||
| 218 | 218 | * @throws PagSeguroServiceException |
| 219 | 219 | * @throws Exception |
| 220 | 220 | */ |
| 221 | - public static function searchAbandoned( |
|
| 222 | - PagSeguroCredentials $credentials, |
|
| 223 | - $pageNumber, |
|
| 224 | - $maxPageResults, |
|
| 225 | - $initialDate, |
|
| 226 | - $finalDate = null |
|
| 227 | - ) { |
|
| 228 | - |
|
| 229 | - LogPagSeguro::info( |
|
| 230 | - "PagSeguroTransactionSearchService.searchAbandoned(initialDate=" . |
|
| 231 | - PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 232 | - PagSeguroHelper::formatDate($finalDate) . ") - begin" |
|
| 233 | - ); |
|
| 234 | - |
|
| 235 | - $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 236 | - |
|
| 237 | - $searchParams = self::buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate); |
|
| 238 | - |
|
| 239 | - try { |
|
| 240 | - |
|
| 241 | - $connection = new PagSeguroHttpConnection(); |
|
| 242 | - $connection->get( |
|
| 243 | - self::buildSearchUrlAbandoned($connectionData, $searchParams), |
|
| 244 | - $connectionData->getServiceTimeout(), |
|
| 245 | - $connectionData->getCharset() |
|
| 246 | - ); |
|
| 247 | - |
|
| 248 | - self::$logService = "searchAbandoned"; |
|
| 249 | - return self::searchResult($connection, $initialDate, $finalDate); |
|
| 250 | - |
|
| 251 | - } catch (PagSeguroServiceException $err) { |
|
| 252 | - throw $err; |
|
| 253 | - } |
|
| 254 | - catch (Exception $err) { |
|
| 255 | - LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 256 | - throw $err; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * @param PagSeguroCredentials $credentials |
|
| 263 | - * @param $reference |
|
| 264 | - * @param null $initialDate |
|
| 265 | - * @param null $finalDate |
|
| 266 | - * @param null $pageNumber |
|
| 267 | - * @param null $maxPageResults |
|
| 268 | - * @throws Exception |
|
| 269 | - * @throws PagSeguroServiceException |
|
| 270 | - */ |
|
| 271 | - public static function searchByReference( |
|
| 272 | - PagSeguroCredentials $credentials, |
|
| 273 | - $reference, |
|
| 274 | - $initialDate = null, |
|
| 275 | - $finalDate = null, |
|
| 276 | - $pageNumber = null, |
|
| 277 | - $maxPageResults = null |
|
| 278 | - ) { |
|
| 279 | - |
|
| 280 | - LogPagSeguro::info( |
|
| 281 | - "PagSeguroTransactionSearchService.SearchByReference(reference=".$reference.") - begin" |
|
| 282 | - ); |
|
| 283 | - |
|
| 284 | - $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 285 | - |
|
| 286 | - if ($initialDate) |
|
| 287 | - $searchParams = self::buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate); |
|
| 288 | - else |
|
| 289 | - $searchParams = null; |
|
| 290 | - |
|
| 291 | - try { |
|
| 292 | - |
|
| 293 | - $connection = new PagSeguroHttpConnection(); |
|
| 294 | - $connection->get( |
|
| 295 | - self::buildSearchUrlByReference( |
|
| 296 | - $connectionData, |
|
| 297 | - $reference, |
|
| 298 | - $searchParams |
|
| 299 | - ), |
|
| 300 | - $connectionData->getServiceTimeout(), |
|
| 301 | - $connectionData->getCharset() |
|
| 302 | - ); |
|
| 303 | - |
|
| 304 | - self::$logService = "SearchByReference"; |
|
| 305 | - return self::searchResult($connection); |
|
| 306 | - |
|
| 307 | - } catch (PagSeguroServiceException $err) { |
|
| 308 | - throw $err; |
|
| 309 | - } catch (Exception $err) { |
|
| 310 | - LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 311 | - throw $err; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * @param $pageNumber |
|
| 318 | - * @param $maxPageResults |
|
| 319 | - * @param $initialDate |
|
| 320 | - * @param null $finalDate |
|
| 321 | - * @return array |
|
| 322 | - */ |
|
| 323 | - private function buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate = null) |
|
| 324 | - { |
|
| 325 | - $searchParams = array( |
|
| 326 | - 'initialDate' => PagSeguroHelper::formatDate($initialDate), |
|
| 327 | - 'pageNumber' => $pageNumber, |
|
| 328 | - 'maxPageResults' => $maxPageResults |
|
| 329 | - ); |
|
| 330 | - |
|
| 331 | - $searchParams['finalDate'] = $finalDate ? PagSeguroHelper::formatDate($finalDate) : null; |
|
| 332 | - |
|
| 333 | - return $searchParams; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * @param $connection |
|
| 338 | - * @param $code |
|
| 339 | - * @return bool|PagSeguroTransaction |
|
| 340 | - * @throws PagSeguroServiceException |
|
| 341 | - */ |
|
| 342 | - private function searchByCodeResult($connection, $code) |
|
| 343 | - { |
|
| 344 | - $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
| 345 | - |
|
| 346 | - switch ($httpStatus->getType()) { |
|
| 347 | - |
|
| 348 | - case 'OK': |
|
| 349 | - $transaction = PagSeguroTransactionParser::readTransaction($connection->getResponse()); |
|
| 350 | - LogPagSeguro::info( |
|
| 351 | - "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - end " . |
|
| 352 | - $transaction->toString() |
|
| 353 | - ); |
|
| 354 | - break; |
|
| 355 | - |
|
| 356 | - case 'BAD_REQUEST': |
|
| 357 | - $errors = PagSeguroTransactionParser::readErrors($connection->getResponse()); |
|
| 358 | - $err = new PagSeguroServiceException($httpStatus, $errors); |
|
| 359 | - LogPagSeguro::error( |
|
| 360 | - "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - error " . |
|
| 361 | - $err->getOneLineMessage() |
|
| 362 | - ); |
|
| 363 | - throw $err; |
|
| 364 | - break; |
|
| 365 | - |
|
| 366 | - default: |
|
| 367 | - $err = new PagSeguroServiceException($httpStatus); |
|
| 368 | - LogPagSeguro::error( |
|
| 369 | - "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - error " . |
|
| 370 | - $err->getOneLineMessage() |
|
| 371 | - ); |
|
| 372 | - throw $err; |
|
| 373 | - break; |
|
| 374 | - } |
|
| 375 | - return isset($transaction) ? $transaction : false; |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * @param $connection |
|
| 380 | - * @param null $initialDate |
|
| 381 | - * @param null $finalDate |
|
| 382 | - * @return bool|PagSeguroTransactionSearchResult |
|
| 383 | - * @throws PagSeguroServiceException |
|
| 384 | - */ |
|
| 385 | - private function searchResult($connection, $initialDate = null, $finalDate = null) |
|
| 386 | - { |
|
| 387 | - |
|
| 388 | - $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
| 389 | - |
|
| 390 | - switch ($httpStatus->getType()) { |
|
| 391 | - |
|
| 392 | - case 'OK': |
|
| 393 | - |
|
| 394 | - $searchResult = PagSeguroTransactionParser::readSearchResult($connection->getResponse()); |
|
| 395 | - |
|
| 396 | - LogPagSeguro::info( |
|
| 397 | - sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . |
|
| 398 | - PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 399 | - PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $searchResult->toString() |
|
| 400 | - ); |
|
| 401 | - break; |
|
| 402 | - |
|
| 403 | - case 'BAD_REQUEST': |
|
| 404 | - $errors = PagSeguroTransactionParser::readErrors($connection->getResponse()); |
|
| 405 | - $err = new PagSeguroServiceException($httpStatus, $errors); |
|
| 406 | - LogPagSeguro::error( |
|
| 407 | - sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . |
|
| 408 | - PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 409 | - PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $err->getOneLineMessage() |
|
| 410 | - ); |
|
| 411 | - throw $err; |
|
| 412 | - break; |
|
| 413 | - |
|
| 414 | - default: |
|
| 415 | - $err = new PagSeguroServiceException($httpStatus); |
|
| 416 | - LogPagSeguro::error( |
|
| 417 | - sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . |
|
| 418 | - PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 419 | - PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $err->getOneLineMessage() |
|
| 420 | - ); |
|
| 421 | - throw $err; |
|
| 422 | - break; |
|
| 423 | - |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - return isset($searchResult) ? $searchResult : false; |
|
| 427 | - } |
|
| 221 | + public static function searchAbandoned( |
|
| 222 | + PagSeguroCredentials $credentials, |
|
| 223 | + $pageNumber, |
|
| 224 | + $maxPageResults, |
|
| 225 | + $initialDate, |
|
| 226 | + $finalDate = null |
|
| 227 | + ) { |
|
| 228 | + |
|
| 229 | + LogPagSeguro::info( |
|
| 230 | + "PagSeguroTransactionSearchService.searchAbandoned(initialDate=" . |
|
| 231 | + PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 232 | + PagSeguroHelper::formatDate($finalDate) . ") - begin" |
|
| 233 | + ); |
|
| 234 | + |
|
| 235 | + $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 236 | + |
|
| 237 | + $searchParams = self::buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate); |
|
| 238 | + |
|
| 239 | + try { |
|
| 240 | + |
|
| 241 | + $connection = new PagSeguroHttpConnection(); |
|
| 242 | + $connection->get( |
|
| 243 | + self::buildSearchUrlAbandoned($connectionData, $searchParams), |
|
| 244 | + $connectionData->getServiceTimeout(), |
|
| 245 | + $connectionData->getCharset() |
|
| 246 | + ); |
|
| 247 | + |
|
| 248 | + self::$logService = "searchAbandoned"; |
|
| 249 | + return self::searchResult($connection, $initialDate, $finalDate); |
|
| 250 | + |
|
| 251 | + } catch (PagSeguroServiceException $err) { |
|
| 252 | + throw $err; |
|
| 253 | + } |
|
| 254 | + catch (Exception $err) { |
|
| 255 | + LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 256 | + throw $err; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * @param PagSeguroCredentials $credentials |
|
| 263 | + * @param $reference |
|
| 264 | + * @param null $initialDate |
|
| 265 | + * @param null $finalDate |
|
| 266 | + * @param null $pageNumber |
|
| 267 | + * @param null $maxPageResults |
|
| 268 | + * @throws Exception |
|
| 269 | + * @throws PagSeguroServiceException |
|
| 270 | + */ |
|
| 271 | + public static function searchByReference( |
|
| 272 | + PagSeguroCredentials $credentials, |
|
| 273 | + $reference, |
|
| 274 | + $initialDate = null, |
|
| 275 | + $finalDate = null, |
|
| 276 | + $pageNumber = null, |
|
| 277 | + $maxPageResults = null |
|
| 278 | + ) { |
|
| 279 | + |
|
| 280 | + LogPagSeguro::info( |
|
| 281 | + "PagSeguroTransactionSearchService.SearchByReference(reference=".$reference.") - begin" |
|
| 282 | + ); |
|
| 283 | + |
|
| 284 | + $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 285 | + |
|
| 286 | + if ($initialDate) |
|
| 287 | + $searchParams = self::buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate); |
|
| 288 | + else |
|
| 289 | + $searchParams = null; |
|
| 290 | + |
|
| 291 | + try { |
|
| 292 | + |
|
| 293 | + $connection = new PagSeguroHttpConnection(); |
|
| 294 | + $connection->get( |
|
| 295 | + self::buildSearchUrlByReference( |
|
| 296 | + $connectionData, |
|
| 297 | + $reference, |
|
| 298 | + $searchParams |
|
| 299 | + ), |
|
| 300 | + $connectionData->getServiceTimeout(), |
|
| 301 | + $connectionData->getCharset() |
|
| 302 | + ); |
|
| 303 | + |
|
| 304 | + self::$logService = "SearchByReference"; |
|
| 305 | + return self::searchResult($connection); |
|
| 306 | + |
|
| 307 | + } catch (PagSeguroServiceException $err) { |
|
| 308 | + throw $err; |
|
| 309 | + } catch (Exception $err) { |
|
| 310 | + LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 311 | + throw $err; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * @param $pageNumber |
|
| 318 | + * @param $maxPageResults |
|
| 319 | + * @param $initialDate |
|
| 320 | + * @param null $finalDate |
|
| 321 | + * @return array |
|
| 322 | + */ |
|
| 323 | + private function buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate = null) |
|
| 324 | + { |
|
| 325 | + $searchParams = array( |
|
| 326 | + 'initialDate' => PagSeguroHelper::formatDate($initialDate), |
|
| 327 | + 'pageNumber' => $pageNumber, |
|
| 328 | + 'maxPageResults' => $maxPageResults |
|
| 329 | + ); |
|
| 330 | + |
|
| 331 | + $searchParams['finalDate'] = $finalDate ? PagSeguroHelper::formatDate($finalDate) : null; |
|
| 332 | + |
|
| 333 | + return $searchParams; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * @param $connection |
|
| 338 | + * @param $code |
|
| 339 | + * @return bool|PagSeguroTransaction |
|
| 340 | + * @throws PagSeguroServiceException |
|
| 341 | + */ |
|
| 342 | + private function searchByCodeResult($connection, $code) |
|
| 343 | + { |
|
| 344 | + $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
| 345 | + |
|
| 346 | + switch ($httpStatus->getType()) { |
|
| 347 | + |
|
| 348 | + case 'OK': |
|
| 349 | + $transaction = PagSeguroTransactionParser::readTransaction($connection->getResponse()); |
|
| 350 | + LogPagSeguro::info( |
|
| 351 | + "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - end " . |
|
| 352 | + $transaction->toString() |
|
| 353 | + ); |
|
| 354 | + break; |
|
| 355 | + |
|
| 356 | + case 'BAD_REQUEST': |
|
| 357 | + $errors = PagSeguroTransactionParser::readErrors($connection->getResponse()); |
|
| 358 | + $err = new PagSeguroServiceException($httpStatus, $errors); |
|
| 359 | + LogPagSeguro::error( |
|
| 360 | + "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - error " . |
|
| 361 | + $err->getOneLineMessage() |
|
| 362 | + ); |
|
| 363 | + throw $err; |
|
| 364 | + break; |
|
| 365 | + |
|
| 366 | + default: |
|
| 367 | + $err = new PagSeguroServiceException($httpStatus); |
|
| 368 | + LogPagSeguro::error( |
|
| 369 | + "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - error " . |
|
| 370 | + $err->getOneLineMessage() |
|
| 371 | + ); |
|
| 372 | + throw $err; |
|
| 373 | + break; |
|
| 374 | + } |
|
| 375 | + return isset($transaction) ? $transaction : false; |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * @param $connection |
|
| 380 | + * @param null $initialDate |
|
| 381 | + * @param null $finalDate |
|
| 382 | + * @return bool|PagSeguroTransactionSearchResult |
|
| 383 | + * @throws PagSeguroServiceException |
|
| 384 | + */ |
|
| 385 | + private function searchResult($connection, $initialDate = null, $finalDate = null) |
|
| 386 | + { |
|
| 387 | + |
|
| 388 | + $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
| 389 | + |
|
| 390 | + switch ($httpStatus->getType()) { |
|
| 391 | + |
|
| 392 | + case 'OK': |
|
| 393 | + |
|
| 394 | + $searchResult = PagSeguroTransactionParser::readSearchResult($connection->getResponse()); |
|
| 395 | + |
|
| 396 | + LogPagSeguro::info( |
|
| 397 | + sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . |
|
| 398 | + PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 399 | + PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $searchResult->toString() |
|
| 400 | + ); |
|
| 401 | + break; |
|
| 402 | + |
|
| 403 | + case 'BAD_REQUEST': |
|
| 404 | + $errors = PagSeguroTransactionParser::readErrors($connection->getResponse()); |
|
| 405 | + $err = new PagSeguroServiceException($httpStatus, $errors); |
|
| 406 | + LogPagSeguro::error( |
|
| 407 | + sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . |
|
| 408 | + PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 409 | + PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $err->getOneLineMessage() |
|
| 410 | + ); |
|
| 411 | + throw $err; |
|
| 412 | + break; |
|
| 413 | + |
|
| 414 | + default: |
|
| 415 | + $err = new PagSeguroServiceException($httpStatus); |
|
| 416 | + LogPagSeguro::error( |
|
| 417 | + sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . |
|
| 418 | + PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 419 | + PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $err->getOneLineMessage() |
|
| 420 | + ); |
|
| 421 | + throw $err; |
|
| 422 | + break; |
|
| 423 | + |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + return isset($searchResult) ? $searchResult : false; |
|
| 427 | + } |
|
| 428 | 428 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | private static function buildSearchUrlByCode(PagSeguroConnectionData $connectionData, $transactionCode) |
| 43 | 43 | { |
| 44 | 44 | $url = $connectionData->getServiceUrl('v3'); |
| 45 | - return "{$url}/{$transactionCode}/?" . $connectionData->getCredentialsUrlQuery(); |
|
| 45 | + return "{$url}/{$transactionCode}/?".$connectionData->getCredentialsUrlQuery(); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -54,14 +54,14 @@ discard block |
||
| 54 | 54 | { |
| 55 | 55 | $url = $connectionData->getServiceUrl('v2'); |
| 56 | 56 | $initialDate = $searchParams['initialDate'] != null ? $searchParams['initialDate'] : ""; |
| 57 | - $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=" . $searchParams['finalDate']) : ""; |
|
| 57 | + $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=".$searchParams['finalDate']) : ""; |
|
| 58 | 58 | if ($searchParams['pageNumber'] != null) { |
| 59 | - $page = "&page=" . $searchParams['pageNumber']; |
|
| 59 | + $page = "&page=".$searchParams['pageNumber']; |
|
| 60 | 60 | } |
| 61 | 61 | if ($searchParams['maxPageResults'] != null) { |
| 62 | - $maxPageResults = "&maxPageResults=" . $searchParams['maxPageResults']; |
|
| 62 | + $maxPageResults = "&maxPageResults=".$searchParams['maxPageResults']; |
|
| 63 | 63 | } |
| 64 | - return "{$url}/?" . $connectionData->getCredentialsUrlQuery() . |
|
| 64 | + return "{$url}/?".$connectionData->getCredentialsUrlQuery(). |
|
| 65 | 65 | "&initialDate={$initialDate}{$finalDate}{$page}{$maxPageResults}"; |
| 66 | 66 | } |
| 67 | 67 | |
@@ -75,14 +75,14 @@ discard block |
||
| 75 | 75 | $url = $connectionData->getServiceUrl('v2'); |
| 76 | 76 | |
| 77 | 77 | $initialDate = $searchParams['initialDate'] != null ? $searchParams['initialDate'] : ""; |
| 78 | - $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=" . $searchParams['finalDate']) : ""; |
|
| 78 | + $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=".$searchParams['finalDate']) : ""; |
|
| 79 | 79 | if ($searchParams['pageNumber'] != null) { |
| 80 | - $page = "&page=" . $searchParams['pageNumber']; |
|
| 80 | + $page = "&page=".$searchParams['pageNumber']; |
|
| 81 | 81 | } |
| 82 | 82 | if ($searchParams['maxPageResults'] != null) { |
| 83 | - $maxPageResults = "&maxPageResults=" . $searchParams['maxPageResults']; |
|
| 83 | + $maxPageResults = "&maxPageResults=".$searchParams['maxPageResults']; |
|
| 84 | 84 | } |
| 85 | - return "{$url}/abandoned/?" . $connectionData->getCredentialsUrlQuery() . |
|
| 85 | + return "{$url}/abandoned/?".$connectionData->getCredentialsUrlQuery(). |
|
| 86 | 86 | "&initialDate={$initialDate}&finalDate={$finalDate}{$page}{$maxPageResults}"; |
| 87 | 87 | } |
| 88 | 88 | |
@@ -96,22 +96,22 @@ discard block |
||
| 96 | 96 | PagSeguroConnectionData $connectionData, |
| 97 | 97 | $reference, |
| 98 | 98 | $searchParams = null |
| 99 | - ){ |
|
| 99 | + ) { |
|
| 100 | 100 | $url = $connectionData->getServiceUrl('v2'); |
| 101 | 101 | if ($searchParams == null) { |
| 102 | - return "{$url}?" . $connectionData->getCredentialsUrlQuery() . "&reference=" . $reference; |
|
| 102 | + return "{$url}?".$connectionData->getCredentialsUrlQuery()."&reference=".$reference; |
|
| 103 | 103 | } else { |
| 104 | 104 | |
| 105 | 105 | $initialDate = $searchParams['initialDate'] != null ? $searchParams['initialDate'] : ""; |
| 106 | - $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=" . $searchParams['finalDate']) : ""; |
|
| 106 | + $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=".$searchParams['finalDate']) : ""; |
|
| 107 | 107 | if ($searchParams['pageNumber'] != null) { |
| 108 | - $page = "&page=" . $searchParams['pageNumber']; |
|
| 108 | + $page = "&page=".$searchParams['pageNumber']; |
|
| 109 | 109 | } |
| 110 | 110 | if ($searchParams['maxPageResults'] != null) { |
| 111 | - $maxPageResults = "&maxPageResults=" . $searchParams['maxPageResults']; |
|
| 111 | + $maxPageResults = "&maxPageResults=".$searchParams['maxPageResults']; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - return "{$url}?" . $connectionData->getCredentialsUrlQuery() . "&reference=" . $reference |
|
| 114 | + return "{$url}?".$connectionData->getCredentialsUrlQuery()."&reference=".$reference |
|
| 115 | 115 | . "&initialDate={$initialDate}&finalDate={$finalDate}{$page}{$maxPageResults}"; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | throw $err; |
| 149 | 149 | } |
| 150 | 150 | catch (Exception $err) { |
| 151 | - LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 151 | + LogPagSeguro::error("Exception: ".$err->getMessage()); |
|
| 152 | 152 | throw $err; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -176,8 +176,8 @@ discard block |
||
| 176 | 176 | ) { |
| 177 | 177 | |
| 178 | 178 | LogPagSeguro::info( |
| 179 | - "PagSeguroTransactionSearchService.SearchByDate(initialDate=" . PagSeguroHelper::formatDate($initialDate) . |
|
| 180 | - ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - begin" |
|
| 179 | + "PagSeguroTransactionSearchService.SearchByDate(initialDate=".PagSeguroHelper::formatDate($initialDate). |
|
| 180 | + ", finalDate=".PagSeguroHelper::formatDate($finalDate).") - begin" |
|
| 181 | 181 | ); |
| 182 | 182 | |
| 183 | 183 | $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | } catch (PagSeguroServiceException $err) { |
| 200 | 200 | throw $err; |
| 201 | 201 | } catch (Exception $err) { |
| 202 | - LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 202 | + LogPagSeguro::error("Exception: ".$err->getMessage()); |
|
| 203 | 203 | throw $err; |
| 204 | 204 | } |
| 205 | 205 | |
@@ -227,9 +227,9 @@ discard block |
||
| 227 | 227 | ) { |
| 228 | 228 | |
| 229 | 229 | LogPagSeguro::info( |
| 230 | - "PagSeguroTransactionSearchService.searchAbandoned(initialDate=" . |
|
| 231 | - PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 232 | - PagSeguroHelper::formatDate($finalDate) . ") - begin" |
|
| 230 | + "PagSeguroTransactionSearchService.searchAbandoned(initialDate=". |
|
| 231 | + PagSeguroHelper::formatDate($initialDate).", finalDate=". |
|
| 232 | + PagSeguroHelper::formatDate($finalDate).") - begin" |
|
| 233 | 233 | ); |
| 234 | 234 | |
| 235 | 235 | $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | throw $err; |
| 253 | 253 | } |
| 254 | 254 | catch (Exception $err) { |
| 255 | - LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 255 | + LogPagSeguro::error("Exception: ".$err->getMessage()); |
|
| 256 | 256 | throw $err; |
| 257 | 257 | } |
| 258 | 258 | |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | } catch (PagSeguroServiceException $err) { |
| 308 | 308 | throw $err; |
| 309 | 309 | } catch (Exception $err) { |
| 310 | - LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 310 | + LogPagSeguro::error("Exception: ".$err->getMessage()); |
|
| 311 | 311 | throw $err; |
| 312 | 312 | } |
| 313 | 313 | |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | case 'OK': |
| 349 | 349 | $transaction = PagSeguroTransactionParser::readTransaction($connection->getResponse()); |
| 350 | 350 | LogPagSeguro::info( |
| 351 | - "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - end " . |
|
| 351 | + "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - end ". |
|
| 352 | 352 | $transaction->toString() |
| 353 | 353 | ); |
| 354 | 354 | break; |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | $errors = PagSeguroTransactionParser::readErrors($connection->getResponse()); |
| 358 | 358 | $err = new PagSeguroServiceException($httpStatus, $errors); |
| 359 | 359 | LogPagSeguro::error( |
| 360 | - "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - error " . |
|
| 360 | + "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - error ". |
|
| 361 | 361 | $err->getOneLineMessage() |
| 362 | 362 | ); |
| 363 | 363 | throw $err; |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | default: |
| 367 | 367 | $err = new PagSeguroServiceException($httpStatus); |
| 368 | 368 | LogPagSeguro::error( |
| 369 | - "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - error " . |
|
| 369 | + "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - error ". |
|
| 370 | 370 | $err->getOneLineMessage() |
| 371 | 371 | ); |
| 372 | 372 | throw $err; |
@@ -394,9 +394,9 @@ discard block |
||
| 394 | 394 | $searchResult = PagSeguroTransactionParser::readSearchResult($connection->getResponse()); |
| 395 | 395 | |
| 396 | 396 | LogPagSeguro::info( |
| 397 | - sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . |
|
| 398 | - PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 399 | - PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $searchResult->toString() |
|
| 397 | + sprintf("PagSeguroTransactionSearchService.%s(initialDate=". |
|
| 398 | + PagSeguroHelper::formatDate($initialDate).", finalDate=". |
|
| 399 | + PagSeguroHelper::formatDate($finalDate).") - end ", self::$logService).$searchResult->toString() |
|
| 400 | 400 | ); |
| 401 | 401 | break; |
| 402 | 402 | |
@@ -404,9 +404,9 @@ discard block |
||
| 404 | 404 | $errors = PagSeguroTransactionParser::readErrors($connection->getResponse()); |
| 405 | 405 | $err = new PagSeguroServiceException($httpStatus, $errors); |
| 406 | 406 | LogPagSeguro::error( |
| 407 | - sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . |
|
| 408 | - PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 409 | - PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $err->getOneLineMessage() |
|
| 407 | + sprintf("PagSeguroTransactionSearchService.%s(initialDate=". |
|
| 408 | + PagSeguroHelper::formatDate($initialDate).", finalDate=". |
|
| 409 | + PagSeguroHelper::formatDate($finalDate).") - end ", self::$logService).$err->getOneLineMessage() |
|
| 410 | 410 | ); |
| 411 | 411 | throw $err; |
| 412 | 412 | break; |
@@ -414,9 +414,9 @@ discard block |
||
| 414 | 414 | default: |
| 415 | 415 | $err = new PagSeguroServiceException($httpStatus); |
| 416 | 416 | LogPagSeguro::error( |
| 417 | - sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . |
|
| 418 | - PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 419 | - PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $err->getOneLineMessage() |
|
| 417 | + sprintf("PagSeguroTransactionSearchService.%s(initialDate=". |
|
| 418 | + PagSeguroHelper::formatDate($initialDate).", finalDate=". |
|
| 419 | + PagSeguroHelper::formatDate($finalDate).") - end ", self::$logService).$err->getOneLineMessage() |
|
| 420 | 420 | ); |
| 421 | 421 | throw $err; |
| 422 | 422 | break; |
@@ -146,8 +146,7 @@ discard block |
||
| 146 | 146 | |
| 147 | 147 | } catch (PagSeguroServiceException $err) { |
| 148 | 148 | throw $err; |
| 149 | - } |
|
| 150 | - catch (Exception $err) { |
|
| 149 | + } catch (Exception $err) { |
|
| 151 | 150 | LogPagSeguro::error("Exception: " . $err->getMessage()); |
| 152 | 151 | throw $err; |
| 153 | 152 | } |
@@ -250,8 +249,7 @@ discard block |
||
| 250 | 249 | |
| 251 | 250 | } catch (PagSeguroServiceException $err) { |
| 252 | 251 | throw $err; |
| 253 | - } |
|
| 254 | - catch (Exception $err) { |
|
| 252 | + } catch (Exception $err) { |
|
| 255 | 253 | LogPagSeguro::error("Exception: " . $err->getMessage()); |
| 256 | 254 | throw $err; |
| 257 | 255 | } |
@@ -283,10 +281,11 @@ discard block |
||
| 283 | 281 | |
| 284 | 282 | $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
| 285 | 283 | |
| 286 | - if ($initialDate) |
|
| 287 | - $searchParams = self::buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate); |
|
| 288 | - else |
|
| 289 | - $searchParams = null; |
|
| 284 | + if ($initialDate) { |
|
| 285 | + $searchParams = self::buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate); |
|
| 286 | + } else { |
|
| 287 | + $searchParams = null; |
|
| 288 | + } |
|
| 290 | 289 | |
| 291 | 290 | try { |
| 292 | 291 | |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | * Get index for sheet |
| 305 | 305 | * |
| 306 | 306 | * @param PHPExcel_Worksheet $pSheet |
| 307 | - * @return Sheet index |
|
| 307 | + * @return integer|null index |
|
| 308 | 308 | * @throws Exception |
| 309 | 309 | */ |
| 310 | 310 | public function getIndex(PHPExcel_Worksheet $pSheet) |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | * |
| 322 | 322 | * @param string $sheetName Sheet name to modify index for |
| 323 | 323 | * @param int $newIndex New index for the sheet |
| 324 | - * @return New sheet index |
|
| 324 | + * @return integer sheet index |
|
| 325 | 325 | * @throws Exception |
| 326 | 326 | */ |
| 327 | 327 | public function setIndexByName($sheetName, $newIndex) |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | * Add named range |
| 458 | 458 | * |
| 459 | 459 | * @param PHPExcel_NamedRange $namedRange |
| 460 | - * @return PHPExcel |
|
| 460 | + * @return boolean |
|
| 461 | 461 | */ |
| 462 | 462 | public function addNamedRange(PHPExcel_NamedRange $namedRange) { |
| 463 | 463 | if ($namedRange->getScope() == null) { |
@@ -27,9 +27,9 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | /** PHPExcel root directory */ |
| 30 | -if (!defined('PHPEXCEL_ROOT')) { |
|
| 31 | - define('PHPEXCEL_ROOT', dirname(__FILE__) . '/'); |
|
| 32 | - require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); |
|
| 30 | +if ( ! defined('PHPEXCEL_ROOT')) { |
|
| 31 | + define('PHPEXCEL_ROOT', dirname(__FILE__).'/'); |
|
| 32 | + require(PHPEXCEL_ROOT.'PHPExcel/Autoloader.php'); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | * |
| 134 | 134 | */ |
| 135 | 135 | public function disconnectWorksheets() { |
| 136 | - foreach($this->_workSheetCollection as $k => &$worksheet) { |
|
| 136 | + foreach ($this->_workSheetCollection as $k => &$worksheet) { |
|
| 137 | 137 | $worksheet->disconnectCells(); |
| 138 | 138 | $this->_workSheetCollection[$k] = null; |
| 139 | 139 | } |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | */ |
| 216 | 216 | public function addSheet(PHPExcel_Worksheet $pSheet = null, $iSheetIndex = null) |
| 217 | 217 | { |
| 218 | - if($iSheetIndex === NULL) { |
|
| 218 | + if ($iSheetIndex === NULL) { |
|
| 219 | 219 | $this->_workSheetCollection[] = $pSheet; |
| 220 | 220 | } else { |
| 221 | 221 | // Insert the sheet at the requested index |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | return $worksheet; |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - throw new Exception('Workbook does not contain sheet:' . $pValue); |
|
| 395 | + throw new Exception('Workbook does not contain sheet:'.$pValue); |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | /** |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | // update the cellXfs |
| 439 | 439 | foreach ($pSheet->getCellCollection(false) as $cellID) { |
| 440 | 440 | $cell = $pSheet->getCell($cellID); |
| 441 | - $cell->setXfIndex( $cell->getXfIndex() + $countCellXfs ); |
|
| 441 | + $cell->setXfIndex($cell->getXfIndex() + $countCellXfs); |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | return $this->addSheet($pSheet, $iSheetIndex); |
@@ -487,8 +487,8 @@ discard block |
||
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | // then look for local defined name (has priority over global defined name if both names exist) |
| 490 | - if (($pSheet !== NULL) && isset($this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange])) { |
|
| 491 | - $returnValue = $this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange]; |
|
| 490 | + if (($pSheet !== NULL) && isset($this->_namedRanges[$pSheet->getTitle().'!'.$namedRange])) { |
|
| 491 | + $returnValue = $this->_namedRanges[$pSheet->getTitle().'!'.$namedRange]; |
|
| 492 | 492 | } |
| 493 | 493 | } |
| 494 | 494 | |
@@ -508,8 +508,8 @@ discard block |
||
| 508 | 508 | unset($this->_namedRanges[$namedRange]); |
| 509 | 509 | } |
| 510 | 510 | } else { |
| 511 | - if (isset($this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange])) { |
|
| 512 | - unset($this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange]); |
|
| 511 | + if (isset($this->_namedRanges[$pSheet->getTitle().'!'.$namedRange])) { |
|
| 512 | + unset($this->_namedRanges[$pSheet->getTitle().'!'.$namedRange]); |
|
| 513 | 513 | } |
| 514 | 514 | } |
| 515 | 515 | return $this; |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | * Implement PHP __clone to create a deep clone, not just a shallow copy. |
| 546 | 546 | */ |
| 547 | 547 | public function __clone() { |
| 548 | - foreach($this as $key => $val) { |
|
| 548 | + foreach ($this as $key => $val) { |
|
| 549 | 549 | if (is_object($val) || (is_array($val))) { |
| 550 | 550 | $this->{$key} = unserialize(serialize($val)); |
| 551 | 551 | } |
@@ -633,7 +633,7 @@ discard block |
||
| 633 | 633 | foreach ($worksheet->getCellCollection(false) as $cellID) { |
| 634 | 634 | $cell = $worksheet->getCell($cellID); |
| 635 | 635 | $xfIndex = $cell->getXfIndex(); |
| 636 | - if ($xfIndex > $pIndex ) { |
|
| 636 | + if ($xfIndex > $pIndex) { |
|
| 637 | 637 | // decrease xf index by 1 |
| 638 | 638 | $cell->setXfIndex($xfIndex - 1); |
| 639 | 639 | } else if ($xfIndex == $pIndex) { |
@@ -780,19 +780,19 @@ discard block |
||
| 780 | 780 | // for all cells |
| 781 | 781 | foreach ($sheet->getCellCollection(false) as $cellID) { |
| 782 | 782 | $cell = $sheet->getCell($cellID); |
| 783 | - $cell->setXfIndex( $map[$cell->getXfIndex()] ); |
|
| 783 | + $cell->setXfIndex($map[$cell->getXfIndex()]); |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | // for all row dimensions |
| 787 | 787 | foreach ($sheet->getRowDimensions() as $rowDimension) { |
| 788 | 788 | if ($rowDimension->getXfIndex() !== null) { |
| 789 | - $rowDimension->setXfIndex( $map[$rowDimension->getXfIndex()] ); |
|
| 789 | + $rowDimension->setXfIndex($map[$rowDimension->getXfIndex()]); |
|
| 790 | 790 | } |
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | // for all column dimensions |
| 794 | 794 | foreach ($sheet->getColumnDimensions() as $columnDimension) { |
| 795 | - $columnDimension->setXfIndex( $map[$columnDimension->getXfIndex()] ); |
|
| 795 | + $columnDimension->setXfIndex($map[$columnDimension->getXfIndex()]); |
|
| 796 | 796 | } |
| 797 | 797 | } |
| 798 | 798 | |
@@ -191,48 +191,48 @@ discard block |
||
| 191 | 191 | return $this->_workSheetCollection[$this->_activeSheetIndex]; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - /** |
|
| 195 | - * Create sheet and add it to this workbook |
|
| 196 | - * |
|
| 194 | + /** |
|
| 195 | + * Create sheet and add it to this workbook |
|
| 196 | + * |
|
| 197 | 197 | * @param int|null $iSheetIndex Index where sheet should go (0,1,..., or null for last) |
| 198 | - * @return PHPExcel_Worksheet |
|
| 199 | - * @throws Exception |
|
| 200 | - */ |
|
| 201 | - public function createSheet($iSheetIndex = null) |
|
| 202 | - { |
|
| 203 | - $newSheet = new PHPExcel_Worksheet($this); |
|
| 204 | - $this->addSheet($newSheet, $iSheetIndex); |
|
| 205 | - return $newSheet; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Add sheet |
|
| 210 | - * |
|
| 211 | - * @param PHPExcel_Worksheet $pSheet |
|
| 198 | + * @return PHPExcel_Worksheet |
|
| 199 | + * @throws Exception |
|
| 200 | + */ |
|
| 201 | + public function createSheet($iSheetIndex = null) |
|
| 202 | + { |
|
| 203 | + $newSheet = new PHPExcel_Worksheet($this); |
|
| 204 | + $this->addSheet($newSheet, $iSheetIndex); |
|
| 205 | + return $newSheet; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Add sheet |
|
| 210 | + * |
|
| 211 | + * @param PHPExcel_Worksheet $pSheet |
|
| 212 | 212 | * @param int|null $iSheetIndex Index where sheet should go (0,1,..., or null for last) |
| 213 | - * @return PHPExcel_Worksheet |
|
| 214 | - * @throws Exception |
|
| 215 | - */ |
|
| 216 | - public function addSheet(PHPExcel_Worksheet $pSheet = null, $iSheetIndex = null) |
|
| 217 | - { |
|
| 218 | - if($iSheetIndex === NULL) { |
|
| 219 | - $this->_workSheetCollection[] = $pSheet; |
|
| 220 | - } else { |
|
| 221 | - // Insert the sheet at the requested index |
|
| 222 | - array_splice( |
|
| 223 | - $this->_workSheetCollection, |
|
| 224 | - $iSheetIndex, |
|
| 225 | - 0, |
|
| 226 | - array($pSheet) |
|
| 227 | - ); |
|
| 213 | + * @return PHPExcel_Worksheet |
|
| 214 | + * @throws Exception |
|
| 215 | + */ |
|
| 216 | + public function addSheet(PHPExcel_Worksheet $pSheet = null, $iSheetIndex = null) |
|
| 217 | + { |
|
| 218 | + if($iSheetIndex === NULL) { |
|
| 219 | + $this->_workSheetCollection[] = $pSheet; |
|
| 220 | + } else { |
|
| 221 | + // Insert the sheet at the requested index |
|
| 222 | + array_splice( |
|
| 223 | + $this->_workSheetCollection, |
|
| 224 | + $iSheetIndex, |
|
| 225 | + 0, |
|
| 226 | + array($pSheet) |
|
| 227 | + ); |
|
| 228 | 228 | |
| 229 | 229 | // Adjust active sheet index if necessary |
| 230 | 230 | if ($this->_activeSheetIndex >= $iSheetIndex) { |
| 231 | 231 | ++$this->_activeSheetIndex; |
| 232 | 232 | } |
| 233 | - } |
|
| 233 | + } |
|
| 234 | 234 | return $pSheet; |
| 235 | - } |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | 237 | /** |
| 238 | 238 | * Remove sheet by index |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | } |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - /** |
|
| 319 | + /** |
|
| 320 | 320 | * Set index for sheet by sheet name. |
| 321 | 321 | * |
| 322 | 322 | * @param string $sheetName Sheet name to modify index for |
@@ -324,22 +324,22 @@ discard block |
||
| 324 | 324 | * @return New sheet index |
| 325 | 325 | * @throws Exception |
| 326 | 326 | */ |
| 327 | - public function setIndexByName($sheetName, $newIndex) |
|
| 328 | - { |
|
| 329 | - $oldIndex = $this->getIndex($this->getSheetByName($sheetName)); |
|
| 330 | - $pSheet = array_splice( |
|
| 331 | - $this->_workSheetCollection, |
|
| 332 | - $oldIndex, |
|
| 333 | - 1 |
|
| 334 | - ); |
|
| 335 | - array_splice( |
|
| 336 | - $this->_workSheetCollection, |
|
| 337 | - $newIndex, |
|
| 338 | - 0, |
|
| 339 | - $pSheet |
|
| 340 | - ); |
|
| 341 | - return $newIndex; |
|
| 342 | - } |
|
| 327 | + public function setIndexByName($sheetName, $newIndex) |
|
| 328 | + { |
|
| 329 | + $oldIndex = $this->getIndex($this->getSheetByName($sheetName)); |
|
| 330 | + $pSheet = array_splice( |
|
| 331 | + $this->_workSheetCollection, |
|
| 332 | + $oldIndex, |
|
| 333 | + 1 |
|
| 334 | + ); |
|
| 335 | + array_splice( |
|
| 336 | + $this->_workSheetCollection, |
|
| 337 | + $newIndex, |
|
| 338 | + 0, |
|
| 339 | + $pSheet |
|
| 340 | + ); |
|
| 341 | + return $newIndex; |
|
| 342 | + } |
|
| 343 | 343 | |
| 344 | 344 | /** |
| 345 | 345 | * Get sheet count |
@@ -724,7 +724,7 @@ discard block |
||
| 724 | 724 | */ |
| 725 | 725 | public function garbageCollect() |
| 726 | 726 | { |
| 727 | - // how many references are there to each cellXf ? |
|
| 727 | + // how many references are there to each cellXf ? |
|
| 728 | 728 | $countReferencesCellXf = array(); |
| 729 | 729 | foreach ($this->_cellXfCollection as $index => $cellXf) { |
| 730 | 730 | $countReferencesCellXf[$index] = 0; |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * @access public |
| 81 | 81 | * @param string $pCoord Coordinate address of the cell to update |
| 82 | 82 | * @param PHPExcel_Cell $cell Cell to update |
| 83 | - * @return void |
|
| 83 | + * @return PHPExcel_Cell |
|
| 84 | 84 | * @throws Exception |
| 85 | 85 | */ |
| 86 | 86 | public function addCacheData($pCoord, PHPExcel_Cell $cell) { |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | * @access public |
| 104 | 104 | * @param string $pCoord Coordinate address of the cell to check |
| 105 | - * @return void |
|
| 105 | + * @return boolean |
|
| 106 | 106 | * @return boolean |
| 107 | 107 | */ |
| 108 | 108 | public function isDataSet($pCoord) { |
@@ -52,14 +52,14 @@ discard block |
||
| 52 | 52 | private $_cacheTime = 600; |
| 53 | 53 | |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Store cell data in cache for the current cell object if it's "dirty", |
|
| 57 | - * and the 'nullify' the current cell object |
|
| 58 | - * |
|
| 55 | + /** |
|
| 56 | + * Store cell data in cache for the current cell object if it's "dirty", |
|
| 57 | + * and the 'nullify' the current cell object |
|
| 58 | + * |
|
| 59 | 59 | * @access private |
| 60 | 60 | * @return void |
| 61 | - * @throws Exception |
|
| 62 | - */ |
|
| 61 | + * @throws Exception |
|
| 62 | + */ |
|
| 63 | 63 | private function _storeData() { |
| 64 | 64 | if ($this->_currentCellIsDirty) { |
| 65 | 65 | $this->_currentObject->detach(); |
@@ -74,15 +74,15 @@ discard block |
||
| 74 | 74 | } // function _storeData() |
| 75 | 75 | |
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Add or Update a cell in cache identified by coordinate address |
|
| 79 | - * |
|
| 77 | + /** |
|
| 78 | + * Add or Update a cell in cache identified by coordinate address |
|
| 79 | + * |
|
| 80 | 80 | * @access public |
| 81 | - * @param string $pCoord Coordinate address of the cell to update |
|
| 82 | - * @param PHPExcel_Cell $cell Cell to update |
|
| 81 | + * @param string $pCoord Coordinate address of the cell to update |
|
| 82 | + * @param PHPExcel_Cell $cell Cell to update |
|
| 83 | 83 | * @return void |
| 84 | - * @throws Exception |
|
| 85 | - */ |
|
| 84 | + * @throws Exception |
|
| 85 | + */ |
|
| 86 | 86 | public function addCacheData($pCoord, PHPExcel_Cell $cell) { |
| 87 | 87 | if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { |
| 88 | 88 | $this->_storeData(); |
@@ -124,14 +124,14 @@ discard block |
||
| 124 | 124 | } // function isDataSet() |
| 125 | 125 | |
| 126 | 126 | |
| 127 | - /** |
|
| 128 | - * Get cell at a specific coordinate |
|
| 129 | - * |
|
| 127 | + /** |
|
| 128 | + * Get cell at a specific coordinate |
|
| 129 | + * |
|
| 130 | 130 | * @access public |
| 131 | - * @param string $pCoord Coordinate of the cell |
|
| 132 | - * @throws Exception |
|
| 133 | - * @return PHPExcel_Cell Cell that was found, or null if not found |
|
| 134 | - */ |
|
| 131 | + * @param string $pCoord Coordinate of the cell |
|
| 132 | + * @throws Exception |
|
| 133 | + * @return PHPExcel_Cell Cell that was found, or null if not found |
|
| 134 | + */ |
|
| 135 | 135 | public function getCacheData($pCoord) { |
| 136 | 136 | if ($pCoord === $this->_currentObjectID) { |
| 137 | 137 | return $this->_currentObject; |
@@ -162,13 +162,13 @@ discard block |
||
| 162 | 162 | } // function getCacheData() |
| 163 | 163 | |
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * Delete a cell in cache identified by coordinate address |
|
| 167 | - * |
|
| 165 | + /** |
|
| 166 | + * Delete a cell in cache identified by coordinate address |
|
| 167 | + * |
|
| 168 | 168 | * @access public |
| 169 | - * @param string $pCoord Coordinate address of the cell to delete |
|
| 170 | - * @throws Exception |
|
| 171 | - */ |
|
| 169 | + * @param string $pCoord Coordinate address of the cell to delete |
|
| 170 | + * @throws Exception |
|
| 171 | + */ |
|
| 172 | 172 | public function deleteCacheData($pCoord) { |
| 173 | 173 | // Delete the entry from APC |
| 174 | 174 | apc_delete($this->_cachePrefix.$pCoord.'.cache'); |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | if ($this->_currentCellIsDirty) { |
| 65 | 65 | $this->_currentObject->detach(); |
| 66 | 66 | |
| 67 | - if (!apc_store($this->_cachePrefix.$this->_currentObjectID.'.cache',serialize($this->_currentObject),$this->_cacheTime)) { |
|
| 67 | + if ( ! apc_store($this->_cachePrefix.$this->_currentObjectID.'.cache', serialize($this->_currentObject), $this->_cacheTime)) { |
|
| 68 | 68 | $this->__destruct(); |
| 69 | 69 | throw new Exception('Failed to store cell '.$this->_currentObjectID.' in APC'); |
| 70 | 70 | } |
@@ -189,9 +189,9 @@ discard block |
||
| 189 | 189 | parent::copyCellCollection($parent); |
| 190 | 190 | // Get a new id for the new file name |
| 191 | 191 | $baseUnique = $this->_getUniqueID(); |
| 192 | - $newCachePrefix = substr(md5($baseUnique),0,8).'.'; |
|
| 192 | + $newCachePrefix = substr(md5($baseUnique), 0, 8).'.'; |
|
| 193 | 193 | $cacheList = $this->getCellList(); |
| 194 | - foreach($cacheList as $cellID) { |
|
| 194 | + foreach ($cacheList as $cellID) { |
|
| 195 | 195 | if ($cellID != $this->_currentObjectID) { |
| 196 | 196 | $obj = apc_fetch($this->_cachePrefix.$cellID.'.cache'); |
| 197 | 197 | if ($obj === false) { |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | parent::deleteCacheData($cellID); |
| 200 | 200 | throw new Exception('Cell entry '.$cellID.' no longer exists in APC'); |
| 201 | 201 | } |
| 202 | - if (!apc_store($newCachePrefix.$cellID.'.cache',$obj,$this->_cacheTime)) { |
|
| 202 | + if ( ! apc_store($newCachePrefix.$cellID.'.cache', $obj, $this->_cacheTime)) { |
|
| 203 | 203 | $this->__destruct(); |
| 204 | 204 | throw new Exception('Failed to store cell '.$cellID.' in APC'); |
| 205 | 205 | } |
@@ -239,11 +239,11 @@ discard block |
||
| 239 | 239 | * @param array of mixed $arguments Additional initialisation arguments |
| 240 | 240 | */ |
| 241 | 241 | public function __construct(PHPExcel_Worksheet $parent, $arguments) { |
| 242 | - $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600; |
|
| 242 | + $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600; |
|
| 243 | 243 | |
| 244 | 244 | if ($this->_cachePrefix === NULL) { |
| 245 | 245 | $baseUnique = $this->_getUniqueID(); |
| 246 | - $this->_cachePrefix = substr(md5($baseUnique),0,8).'.'; |
|
| 246 | + $this->_cachePrefix = substr(md5($baseUnique), 0, 8).'.'; |
|
| 247 | 247 | $this->_cacheTime = $cacheTime; |
| 248 | 248 | |
| 249 | 249 | parent::__construct($parent); |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | */ |
| 259 | 259 | public function __destruct() { |
| 260 | 260 | $cacheList = $this->getCellList(); |
| 261 | - foreach($cacheList as $cellID) { |
|
| 261 | + foreach ($cacheList as $cellID) { |
|
| 262 | 262 | apc_delete($this->_cachePrefix.$cellID.'.cache'); |
| 263 | 263 | } |
| 264 | 264 | } // function __destruct() |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | * @return boolean |
| 273 | 273 | */ |
| 274 | 274 | public static function cacheMethodIsAvailable() { |
| 275 | - if (!function_exists('apc_store')) { |
|
| 275 | + if ( ! function_exists('apc_store')) { |
|
| 276 | 276 | return false; |
| 277 | 277 | } |
| 278 | 278 | if (apc_sma_info() === false) { |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * @param string $pCoord Coordinate address of the cell to update |
| 88 | 88 | * @param PHPExcel_Cell $cell Cell to update |
| 89 | - * @return void |
|
| 89 | + * @return PHPExcel_Cell |
|
| 90 | 90 | * @throws Exception |
| 91 | 91 | */ |
| 92 | 92 | public function addCacheData($pCoord, PHPExcel_Cell $cell) { |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell? |
| 108 | 108 | * |
| 109 | 109 | * @param string $pCoord Coordinate address of the cell to check |
| 110 | - * @return void |
|
| 110 | + * @return boolean |
|
| 111 | 111 | * @return boolean |
| 112 | 112 | */ |
| 113 | 113 | public function isDataSet($pCoord) { |
@@ -57,13 +57,13 @@ discard block |
||
| 57 | 57 | private $_memcache = null; |
| 58 | 58 | |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Store cell data in cache for the current cell object if it's "dirty", |
|
| 62 | - * and the 'nullify' the current cell object |
|
| 63 | - * |
|
| 60 | + /** |
|
| 61 | + * Store cell data in cache for the current cell object if it's "dirty", |
|
| 62 | + * and the 'nullify' the current cell object |
|
| 63 | + * |
|
| 64 | 64 | * @return void |
| 65 | - * @throws Exception |
|
| 66 | - */ |
|
| 65 | + * @throws Exception |
|
| 66 | + */ |
|
| 67 | 67 | private function _storeData() { |
| 68 | 68 | if ($this->_currentCellIsDirty) { |
| 69 | 69 | $this->_currentObject->detach(); |
@@ -81,14 +81,14 @@ discard block |
||
| 81 | 81 | } // function _storeData() |
| 82 | 82 | |
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Add or Update a cell in cache identified by coordinate address |
|
| 86 | - * |
|
| 87 | - * @param string $pCoord Coordinate address of the cell to update |
|
| 88 | - * @param PHPExcel_Cell $cell Cell to update |
|
| 84 | + /** |
|
| 85 | + * Add or Update a cell in cache identified by coordinate address |
|
| 86 | + * |
|
| 87 | + * @param string $pCoord Coordinate address of the cell to update |
|
| 88 | + * @param PHPExcel_Cell $cell Cell to update |
|
| 89 | 89 | * @return void |
| 90 | - * @throws Exception |
|
| 91 | - */ |
|
| 90 | + * @throws Exception |
|
| 91 | + */ |
|
| 92 | 92 | public function addCacheData($pCoord, PHPExcel_Cell $cell) { |
| 93 | 93 | if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { |
| 94 | 94 | $this->_storeData(); |
@@ -130,12 +130,12 @@ discard block |
||
| 130 | 130 | |
| 131 | 131 | |
| 132 | 132 | /** |
| 133 | - * Get cell at a specific coordinate |
|
| 134 | - * |
|
| 135 | - * @param string $pCoord Coordinate of the cell |
|
| 136 | - * @throws Exception |
|
| 137 | - * @return PHPExcel_Cell Cell that was found, or null if not found |
|
| 138 | - */ |
|
| 133 | + * Get cell at a specific coordinate |
|
| 134 | + * |
|
| 135 | + * @param string $pCoord Coordinate of the cell |
|
| 136 | + * @throws Exception |
|
| 137 | + * @return PHPExcel_Cell Cell that was found, or null if not found |
|
| 138 | + */ |
|
| 139 | 139 | public function getCacheData($pCoord) { |
| 140 | 140 | if ($pCoord === $this->_currentObjectID) { |
| 141 | 141 | return $this->_currentObject; |
@@ -166,12 +166,12 @@ discard block |
||
| 166 | 166 | } // function getCacheData() |
| 167 | 167 | |
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * Delete a cell in cache identified by coordinate address |
|
| 171 | - * |
|
| 172 | - * @param string $pCoord Coordinate address of the cell to delete |
|
| 173 | - * @throws Exception |
|
| 174 | - */ |
|
| 169 | + /** |
|
| 170 | + * Delete a cell in cache identified by coordinate address |
|
| 171 | + * |
|
| 172 | + * @param string $pCoord Coordinate address of the cell to delete |
|
| 173 | + * @throws Exception |
|
| 174 | + */ |
|
| 175 | 175 | public function deleteCacheData($pCoord) { |
| 176 | 176 | // Delete the entry from Memcache |
| 177 | 177 | $this->_memcache->delete($this->_cachePrefix.$pCoord.'.cache'); |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | * |
| 265 | 265 | * @param string $host Memcache server |
| 266 | 266 | * @param integer $port Memcache port |
| 267 | - * @throws Exception |
|
| 267 | + * @throws Exception |
|
| 268 | 268 | */ |
| 269 | 269 | public function failureCallback($host, $port) { |
| 270 | 270 | throw new Exception('memcache '.$host.':'.$port.' failed'); |
@@ -69,8 +69,8 @@ discard block |
||
| 69 | 69 | $this->_currentObject->detach(); |
| 70 | 70 | |
| 71 | 71 | $obj = serialize($this->_currentObject); |
| 72 | - if (!$this->_memcache->replace($this->_cachePrefix.$this->_currentObjectID.'.cache',$obj,NULL,$this->_cacheTime)) { |
|
| 73 | - if (!$this->_memcache->add($this->_cachePrefix.$this->_currentObjectID.'.cache',$obj,NULL,$this->_cacheTime)) { |
|
| 72 | + if ( ! $this->_memcache->replace($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, NULL, $this->_cacheTime)) { |
|
| 73 | + if ( ! $this->_memcache->add($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, NULL, $this->_cacheTime)) { |
|
| 74 | 74 | $this->__destruct(); |
| 75 | 75 | throw new Exception('Failed to store cell '.$this->_currentObjectID.' in MemCache'); |
| 76 | 76 | } |
@@ -191,9 +191,9 @@ discard block |
||
| 191 | 191 | parent::copyCellCollection($parent); |
| 192 | 192 | // Get a new id for the new file name |
| 193 | 193 | $baseUnique = $this->_getUniqueID(); |
| 194 | - $newCachePrefix = substr(md5($baseUnique),0,8).'.'; |
|
| 194 | + $newCachePrefix = substr(md5($baseUnique), 0, 8).'.'; |
|
| 195 | 195 | $cacheList = $this->getCellList(); |
| 196 | - foreach($cacheList as $cellID) { |
|
| 196 | + foreach ($cacheList as $cellID) { |
|
| 197 | 197 | if ($cellID != $this->_currentObjectID) { |
| 198 | 198 | $obj = $this->_memcache->get($this->_cachePrefix.$cellID.'.cache'); |
| 199 | 199 | if ($obj === false) { |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | parent::deleteCacheData($cellID); |
| 202 | 202 | throw new Exception('Cell entry '.$cellID.' no longer exists in MemCache'); |
| 203 | 203 | } |
| 204 | - if (!$this->_memcache->add($newCachePrefix.$cellID.'.cache',$obj,NULL,$this->_cacheTime)) { |
|
| 204 | + if ( ! $this->_memcache->add($newCachePrefix.$cellID.'.cache', $obj, NULL, $this->_cacheTime)) { |
|
| 205 | 205 | $this->__destruct(); |
| 206 | 206 | throw new Exception('Failed to store cell '.$cellID.' in MemCache'); |
| 207 | 207 | } |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * @return void |
| 218 | 218 | */ |
| 219 | 219 | public function unsetWorksheetCells() { |
| 220 | - if(!is_null($this->_currentObject)) { |
|
| 220 | + if ( ! is_null($this->_currentObject)) { |
|
| 221 | 221 | $this->_currentObject->detach(); |
| 222 | 222 | $this->_currentObject = $this->_currentObjectID = null; |
| 223 | 223 | } |
@@ -239,17 +239,17 @@ discard block |
||
| 239 | 239 | * @param array of mixed $arguments Additional initialisation arguments |
| 240 | 240 | */ |
| 241 | 241 | public function __construct(PHPExcel_Worksheet $parent, $arguments) { |
| 242 | - $memcacheServer = (isset($arguments['memcacheServer'])) ? $arguments['memcacheServer'] : 'localhost'; |
|
| 243 | - $memcachePort = (isset($arguments['memcachePort'])) ? $arguments['memcachePort'] : 11211; |
|
| 244 | - $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600; |
|
| 242 | + $memcacheServer = (isset($arguments['memcacheServer'])) ? $arguments['memcacheServer'] : 'localhost'; |
|
| 243 | + $memcachePort = (isset($arguments['memcachePort'])) ? $arguments['memcachePort'] : 11211; |
|
| 244 | + $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600; |
|
| 245 | 245 | |
| 246 | 246 | if (is_null($this->_cachePrefix)) { |
| 247 | 247 | $baseUnique = $this->_getUniqueID(); |
| 248 | - $this->_cachePrefix = substr(md5($baseUnique),0,8).'.'; |
|
| 248 | + $this->_cachePrefix = substr(md5($baseUnique), 0, 8).'.'; |
|
| 249 | 249 | |
| 250 | 250 | // Set a new Memcache object and connect to the Memcache server |
| 251 | 251 | $this->_memcache = new Memcache(); |
| 252 | - if (!$this->_memcache->addServer($memcacheServer, $memcachePort, false, 50, 5, 5, true, array($this, 'failureCallback'))) { |
|
| 252 | + if ( ! $this->_memcache->addServer($memcacheServer, $memcachePort, false, 50, 5, 5, true, array($this, 'failureCallback'))) { |
|
| 253 | 253 | throw new Exception('Could not connect to MemCache server at '.$memcacheServer.':'.$memcachePort); |
| 254 | 254 | } |
| 255 | 255 | $this->_cacheTime = $cacheTime; |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | */ |
| 277 | 277 | public function __destruct() { |
| 278 | 278 | $cacheList = $this->getCellList(); |
| 279 | - foreach($cacheList as $cellID) { |
|
| 279 | + foreach ($cacheList as $cellID) { |
|
| 280 | 280 | $this->_memcache->delete($this->_cachePrefix.$cellID.'.cache'); |
| 281 | 281 | } |
| 282 | 282 | } // function __destruct() |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | * @return boolean |
| 289 | 289 | */ |
| 290 | 290 | public static function cacheMethodIsAvailable() { |
| 291 | - if (!function_exists('memcache_add')) { |
|
| 291 | + if ( ! function_exists('memcache_add')) { |
|
| 292 | 292 | return false; |
| 293 | 293 | } |
| 294 | 294 | |
@@ -77,7 +77,7 @@ |
||
| 77 | 77 | * |
| 78 | 78 | * @param string $pCoord Coordinate address of the cell to update |
| 79 | 79 | * @param PHPExcel_Cell $cell Cell to update |
| 80 | - * @return void |
|
| 80 | + * @return PHPExcel_Cell |
|
| 81 | 81 | * @throws Exception |
| 82 | 82 | */ |
| 83 | 83 | public function addCacheData($pCoord, PHPExcel_Cell $cell) { |
@@ -49,13 +49,13 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | private $_memoryCacheSize = null; |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Store cell data in cache for the current cell object if it's "dirty", |
|
| 54 | - * and the 'nullify' the current cell object |
|
| 55 | - * |
|
| 52 | + /** |
|
| 53 | + * Store cell data in cache for the current cell object if it's "dirty", |
|
| 54 | + * and the 'nullify' the current cell object |
|
| 55 | + * |
|
| 56 | 56 | * @return void |
| 57 | - * @throws Exception |
|
| 58 | - */ |
|
| 57 | + * @throws Exception |
|
| 58 | + */ |
|
| 59 | 59 | private function _storeData() { |
| 60 | 60 | if ($this->_currentCellIsDirty) { |
| 61 | 61 | $this->_currentObject->detach(); |
@@ -72,14 +72,14 @@ discard block |
||
| 72 | 72 | } // function _storeData() |
| 73 | 73 | |
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Add or Update a cell in cache identified by coordinate address |
|
| 77 | - * |
|
| 78 | - * @param string $pCoord Coordinate address of the cell to update |
|
| 79 | - * @param PHPExcel_Cell $cell Cell to update |
|
| 75 | + /** |
|
| 76 | + * Add or Update a cell in cache identified by coordinate address |
|
| 77 | + * |
|
| 78 | + * @param string $pCoord Coordinate address of the cell to update |
|
| 79 | + * @param PHPExcel_Cell $cell Cell to update |
|
| 80 | 80 | * @return void |
| 81 | - * @throws Exception |
|
| 82 | - */ |
|
| 81 | + * @throws Exception |
|
| 82 | + */ |
|
| 83 | 83 | public function addCacheData($pCoord, PHPExcel_Cell $cell) { |
| 84 | 84 | if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { |
| 85 | 85 | $this->_storeData(); |
@@ -93,13 +93,13 @@ discard block |
||
| 93 | 93 | } // function addCacheData() |
| 94 | 94 | |
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Get cell at a specific coordinate |
|
| 98 | - * |
|
| 99 | - * @param string $pCoord Coordinate of the cell |
|
| 100 | - * @throws Exception |
|
| 101 | - * @return PHPExcel_Cell Cell that was found, or null if not found |
|
| 102 | - */ |
|
| 96 | + /** |
|
| 97 | + * Get cell at a specific coordinate |
|
| 98 | + * |
|
| 99 | + * @param string $pCoord Coordinate of the cell |
|
| 100 | + * @throws Exception |
|
| 101 | + * @return PHPExcel_Cell Cell that was found, or null if not found |
|
| 102 | + */ |
|
| 103 | 103 | public function getCacheData($pCoord) { |
| 104 | 104 | if ($pCoord === $this->_currentObjectID) { |
| 105 | 105 | return $this->_currentObject; |
@@ -60,10 +60,10 @@ discard block |
||
| 60 | 60 | if ($this->_currentCellIsDirty) { |
| 61 | 61 | $this->_currentObject->detach(); |
| 62 | 62 | |
| 63 | - fseek($this->_fileHandle,0,SEEK_END); |
|
| 63 | + fseek($this->_fileHandle, 0, SEEK_END); |
|
| 64 | 64 | $offset = ftell($this->_fileHandle); |
| 65 | 65 | fwrite($this->_fileHandle, serialize($this->_currentObject)); |
| 66 | - $this->_cellCache[$this->_currentObjectID] = array('ptr' => $offset, |
|
| 66 | + $this->_cellCache[$this->_currentObjectID] = array('ptr' => $offset, |
|
| 67 | 67 | 'sz' => ftell($this->_fileHandle) - $offset |
| 68 | 68 | ); |
| 69 | 69 | $this->_currentCellIsDirty = false; |
@@ -107,15 +107,15 @@ discard block |
||
| 107 | 107 | $this->_storeData(); |
| 108 | 108 | |
| 109 | 109 | // Check if the entry that has been requested actually exists |
| 110 | - if (!isset($this->_cellCache[$pCoord])) { |
|
| 110 | + if ( ! isset($this->_cellCache[$pCoord])) { |
|
| 111 | 111 | // Return null if requested entry doesn't exist in cache |
| 112 | 112 | return null; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | // Set current entry to the requested entry |
| 116 | 116 | $this->_currentObjectID = $pCoord; |
| 117 | - fseek($this->_fileHandle,$this->_cellCache[$pCoord]['ptr']); |
|
| 118 | - $this->_currentObject = unserialize(fread($this->_fileHandle,$this->_cellCache[$pCoord]['sz'])); |
|
| 117 | + fseek($this->_fileHandle, $this->_cellCache[$pCoord]['ptr']); |
|
| 118 | + $this->_currentObject = unserialize(fread($this->_fileHandle, $this->_cellCache[$pCoord]['sz'])); |
|
| 119 | 119 | // Re-attach the parent worksheet |
| 120 | 120 | $this->_currentObject->attach($this->_parent); |
| 121 | 121 | |
@@ -133,11 +133,11 @@ discard block |
||
| 133 | 133 | public function copyCellCollection(PHPExcel_Worksheet $parent) { |
| 134 | 134 | parent::copyCellCollection($parent); |
| 135 | 135 | // Open a new stream for the cell cache data |
| 136 | - $newFileHandle = fopen('php://temp/maxmemory:'.$this->_memoryCacheSize,'a+'); |
|
| 136 | + $newFileHandle = fopen('php://temp/maxmemory:'.$this->_memoryCacheSize, 'a+'); |
|
| 137 | 137 | // Copy the existing cell cache data to the new stream |
| 138 | - fseek($this->_fileHandle,0); |
|
| 139 | - while (!feof($this->_fileHandle)) { |
|
| 140 | - fwrite($newFileHandle,fread($this->_fileHandle, 1024)); |
|
| 138 | + fseek($this->_fileHandle, 0); |
|
| 139 | + while ( ! feof($this->_fileHandle)) { |
|
| 140 | + fwrite($newFileHandle, fread($this->_fileHandle, 1024)); |
|
| 141 | 141 | } |
| 142 | 142 | $this->_fileHandle = $newFileHandle; |
| 143 | 143 | } // function copyCellCollection() |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | * @return void |
| 150 | 150 | */ |
| 151 | 151 | public function unsetWorksheetCells() { |
| 152 | - if(!is_null($this->_currentObject)) { |
|
| 152 | + if ( ! is_null($this->_currentObject)) { |
|
| 153 | 153 | $this->_currentObject->detach(); |
| 154 | 154 | $this->_currentObject = $this->_currentObjectID = null; |
| 155 | 155 | } |
@@ -170,11 +170,11 @@ discard block |
||
| 170 | 170 | * @param array of mixed $arguments Additional initialisation arguments |
| 171 | 171 | */ |
| 172 | 172 | public function __construct(PHPExcel_Worksheet $parent, $arguments) { |
| 173 | - $this->_memoryCacheSize = (isset($arguments['memoryCacheSize'])) ? $arguments['memoryCacheSize'] : '1MB'; |
|
| 173 | + $this->_memoryCacheSize = (isset($arguments['memoryCacheSize'])) ? $arguments['memoryCacheSize'] : '1MB'; |
|
| 174 | 174 | |
| 175 | 175 | parent::__construct($parent); |
| 176 | 176 | if (is_null($this->_fileHandle)) { |
| 177 | - $this->_fileHandle = fopen('php://temp/maxmemory:'.$this->_memoryCacheSize,'a+'); |
|
| 177 | + $this->_fileHandle = fopen('php://temp/maxmemory:'.$this->_memoryCacheSize, 'a+'); |
|
| 178 | 178 | } |
| 179 | 179 | } // function __construct() |
| 180 | 180 | |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | * Destroy this cell collection |
| 184 | 184 | */ |
| 185 | 185 | public function __destruct() { |
| 186 | - if (!is_null($this->_fileHandle)) { |
|
| 186 | + if ( ! is_null($this->_fileHandle)) { |
|
| 187 | 187 | fclose($this->_fileHandle); |
| 188 | 188 | } |
| 189 | 189 | $this->_fileHandle = null; |
@@ -85,7 +85,7 @@ |
||
| 85 | 85 | * |
| 86 | 86 | * @param string $pCoord Coordinate address of the cell to update |
| 87 | 87 | * @param PHPExcel_Cell $cell Cell to update |
| 88 | - * @return void |
|
| 88 | + * @return PHPExcel_Cell |
|
| 89 | 89 | * @throws Exception |
| 90 | 90 | */ |
| 91 | 91 | public function addCacheData($pCoord, PHPExcel_Cell $cell) { |
@@ -50,13 +50,13 @@ |
||
| 50 | 50 | private $_cacheTime = 600; |
| 51 | 51 | |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Store cell data in cache for the current cell object if it's "dirty", |
|
| 55 | - * and the 'nullify' the current cell object |
|
| 56 | - * |
|
| 53 | + /** |
|
| 54 | + * Store cell data in cache for the current cell object if it's "dirty", |
|
| 55 | + * and the 'nullify' the current cell object |
|
| 56 | + * |
|
| 57 | 57 | * @return void |
| 58 | - * @throws Exception |
|
| 59 | - */ |
|
| 58 | + * @throws Exception |
|
| 59 | + */ |
|
| 60 | 60 | private function _storeData() { |
| 61 | 61 | if ($this->_currentCellIsDirty) { |
| 62 | 62 | $this->_currentObject->detach(); |
@@ -63,12 +63,12 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | $obj = serialize($this->_currentObject); |
| 65 | 65 | if (wincache_ucache_exists($this->_cachePrefix.$this->_currentObjectID.'.cache')) { |
| 66 | - if (!wincache_ucache_set($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime)) { |
|
| 66 | + if ( ! wincache_ucache_set($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime)) { |
|
| 67 | 67 | $this->__destruct(); |
| 68 | 68 | throw new Exception('Failed to store cell '.$this->_currentObjectID.' in WinCache'); |
| 69 | 69 | } |
| 70 | 70 | } else { |
| 71 | - if (!wincache_ucache_add($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime)) { |
|
| 71 | + if ( ! wincache_ucache_add($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime)) { |
|
| 72 | 72 | $this->__destruct(); |
| 73 | 73 | throw new Exception('Failed to store cell '.$this->_currentObjectID.' in WinCache'); |
| 74 | 74 | } |
@@ -191,9 +191,9 @@ discard block |
||
| 191 | 191 | parent::copyCellCollection($parent); |
| 192 | 192 | // Get a new id for the new file name |
| 193 | 193 | $baseUnique = $this->_getUniqueID(); |
| 194 | - $newCachePrefix = substr(md5($baseUnique),0,8).'.'; |
|
| 194 | + $newCachePrefix = substr(md5($baseUnique), 0, 8).'.'; |
|
| 195 | 195 | $cacheList = $this->getCellList(); |
| 196 | - foreach($cacheList as $cellID) { |
|
| 196 | + foreach ($cacheList as $cellID) { |
|
| 197 | 197 | if ($cellID != $this->_currentObjectID) { |
| 198 | 198 | $success = false; |
| 199 | 199 | $obj = wincache_ucache_get($this->_cachePrefix.$cellID.'.cache', $success); |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | parent::deleteCacheData($cellID); |
| 203 | 203 | throw new Exception('Cell entry '.$cellID.' no longer exists in Wincache'); |
| 204 | 204 | } |
| 205 | - if (!wincache_ucache_add($newCachePrefix.$cellID.'.cache', $obj, $this->_cacheTime)) { |
|
| 205 | + if ( ! wincache_ucache_add($newCachePrefix.$cellID.'.cache', $obj, $this->_cacheTime)) { |
|
| 206 | 206 | $this->__destruct(); |
| 207 | 207 | throw new Exception('Failed to store cell '.$cellID.' in Wincache'); |
| 208 | 208 | } |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | * @return void |
| 219 | 219 | */ |
| 220 | 220 | public function unsetWorksheetCells() { |
| 221 | - if(!is_null($this->_currentObject)) { |
|
| 221 | + if ( ! is_null($this->_currentObject)) { |
|
| 222 | 222 | $this->_currentObject->detach(); |
| 223 | 223 | $this->_currentObject = $this->_currentObjectID = null; |
| 224 | 224 | } |
@@ -240,11 +240,11 @@ discard block |
||
| 240 | 240 | * @param array of mixed $arguments Additional initialisation arguments |
| 241 | 241 | */ |
| 242 | 242 | public function __construct(PHPExcel_Worksheet $parent, $arguments) { |
| 243 | - $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600; |
|
| 243 | + $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600; |
|
| 244 | 244 | |
| 245 | 245 | if (is_null($this->_cachePrefix)) { |
| 246 | 246 | $baseUnique = $this->_getUniqueID(); |
| 247 | - $this->_cachePrefix = substr(md5($baseUnique),0,8).'.'; |
|
| 247 | + $this->_cachePrefix = substr(md5($baseUnique), 0, 8).'.'; |
|
| 248 | 248 | $this->_cacheTime = $cacheTime; |
| 249 | 249 | |
| 250 | 250 | parent::__construct($parent); |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | public function __destruct() { |
| 259 | 259 | $cacheList = $this->getCellList(); |
| 260 | - foreach($cacheList as $cellID) { |
|
| 260 | + foreach ($cacheList as $cellID) { |
|
| 261 | 261 | wincache_ucache_delete($this->_cachePrefix.$cellID.'.cache'); |
| 262 | 262 | } |
| 263 | 263 | } // function __destruct() |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * @return boolean |
| 271 | 271 | */ |
| 272 | 272 | public static function cacheMethodIsAvailable() { |
| 273 | - if (!function_exists('wincache_ucache_add')) { |
|
| 273 | + if ( ! function_exists('wincache_ucache_add')) { |
|
| 274 | 274 | return false; |
| 275 | 275 | } |
| 276 | 276 | |