@@ -22,19 +22,19 @@ discard block |
||
| 22 | 22 | { |
| 23 | 23 | const ERROR_NO_BOUNDARIES_SPECIFIED = 44401; |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var RequestHelper |
|
| 27 | - */ |
|
| 25 | + /** |
|
| 26 | + * @var RequestHelper |
|
| 27 | + */ |
|
| 28 | 28 | protected $helper; |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var RequestHelper_Boundaries_Boundary[] |
|
| 32 | - */ |
|
| 30 | + /** |
|
| 31 | + * @var RequestHelper_Boundaries_Boundary[] |
|
| 32 | + */ |
|
| 33 | 33 | protected $boundaries = array(); |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var integer |
|
| 37 | - */ |
|
| 35 | + /** |
|
| 36 | + * @var integer |
|
| 37 | + */ |
|
| 38 | 38 | protected $contentLength = 0; |
| 39 | 39 | |
| 40 | 40 | public function __construct(RequestHelper $helper) |
@@ -42,45 +42,45 @@ discard block |
||
| 42 | 42 | $this->helper = $helper; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Retrieves the string that is used to separate mime boundaries in the body. |
|
| 47 | - * |
|
| 48 | - * @return string |
|
| 49 | - */ |
|
| 45 | + /** |
|
| 46 | + * Retrieves the string that is used to separate mime boundaries in the body. |
|
| 47 | + * |
|
| 48 | + * @return string |
|
| 49 | + */ |
|
| 50 | 50 | public function getMimeBoundary() : string |
| 51 | 51 | { |
| 52 | 52 | return $this->helper->getMimeBoundary(); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Retrieves the end of line character(s) used in the body. |
|
| 57 | - * |
|
| 58 | - * @return string |
|
| 59 | - */ |
|
| 55 | + /** |
|
| 56 | + * Retrieves the end of line character(s) used in the body. |
|
| 57 | + * |
|
| 58 | + * @return string |
|
| 59 | + */ |
|
| 60 | 60 | public function getEOL() : string |
| 61 | 61 | { |
| 62 | 62 | return $this->helper->getEOL(); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Retrieves the total content length of all boundary contents. |
|
| 67 | - * |
|
| 68 | - * @return int |
|
| 69 | - */ |
|
| 65 | + /** |
|
| 66 | + * Retrieves the total content length of all boundary contents. |
|
| 67 | + * |
|
| 68 | + * @return int |
|
| 69 | + */ |
|
| 70 | 70 | public function getContentLength() : int |
| 71 | 71 | { |
| 72 | 72 | return $this->contentLength; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Adds a file to be sent with the request. |
|
| 77 | - * |
|
| 78 | - * @param string $varName The variable name to send the file in |
|
| 79 | - * @param string $fileName The name of the file as it should be received at the destination |
|
| 80 | - * @param string $content The raw content of the file |
|
| 81 | - * @param string $contentType The content type, use the constants to specify this |
|
| 82 | - * @param string $encoding The encoding of the file, use the constants to specify this |
|
| 83 | - */ |
|
| 75 | + /** |
|
| 76 | + * Adds a file to be sent with the request. |
|
| 77 | + * |
|
| 78 | + * @param string $varName The variable name to send the file in |
|
| 79 | + * @param string $fileName The name of the file as it should be received at the destination |
|
| 80 | + * @param string $content The raw content of the file |
|
| 81 | + * @param string $contentType The content type, use the constants to specify this |
|
| 82 | + * @param string $encoding The encoding of the file, use the constants to specify this |
|
| 83 | + */ |
|
| 84 | 84 | public function addFile(string $varName, string $fileName, string $content, string $contentType = RequestHelper::FILETYPE_TEXT, string $encoding = RequestHelper::ENCODING_UTF8) : RequestHelper_Boundaries |
| 85 | 85 | { |
| 86 | 86 | $boundary = $this->createBoundary(chunk_split(base64_encode($content))) |
@@ -92,13 +92,13 @@ discard block |
||
| 92 | 92 | return $this->addBoundary($boundary); |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Adds arbitrary content. |
|
| 97 | - * |
|
| 98 | - * @param string $varName |
|
| 99 | - * @param string $content |
|
| 100 | - * @param string $contentType |
|
| 101 | - */ |
|
| 95 | + /** |
|
| 96 | + * Adds arbitrary content. |
|
| 97 | + * |
|
| 98 | + * @param string $varName |
|
| 99 | + * @param string $content |
|
| 100 | + * @param string $contentType |
|
| 101 | + */ |
|
| 102 | 102 | public function addContent(string $varName, string $content, string $contentType) : RequestHelper_Boundaries |
| 103 | 103 | { |
| 104 | 104 | $boundary = $this->createBoundary($content) |
@@ -109,13 +109,13 @@ discard block |
||
| 109 | 109 | return $this->addBoundary($boundary); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Adds a variable to be sent with the request. If it |
|
| 114 | - * already exists, its value is overwritten. |
|
| 115 | - * |
|
| 116 | - * @param string $name |
|
| 117 | - * @param string $value |
|
| 118 | - */ |
|
| 112 | + /** |
|
| 113 | + * Adds a variable to be sent with the request. If it |
|
| 114 | + * already exists, its value is overwritten. |
|
| 115 | + * |
|
| 116 | + * @param string $name |
|
| 117 | + * @param string $value |
|
| 118 | + */ |
|
| 119 | 119 | public function addVariable(string $name, string $value) : RequestHelper_Boundaries |
| 120 | 120 | { |
| 121 | 121 | $boundary = $this->createBoundary($value) |
@@ -132,11 +132,11 @@ discard block |
||
| 132 | 132 | return $this; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * Renders the response body with all mime boundaries. |
|
| 137 | - * |
|
| 138 | - * @return string |
|
| 139 | - */ |
|
| 135 | + /** |
|
| 136 | + * Renders the response body with all mime boundaries. |
|
| 137 | + * |
|
| 138 | + * @return string |
|
| 139 | + */ |
|
| 140 | 140 | public function render() : string |
| 141 | 141 | { |
| 142 | 142 | if(empty($this->boundaries)) |
@@ -19,29 +19,29 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | class RequestHelper_Boundaries_Boundary |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 22 | + /** |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | 25 | protected $content; |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var array |
|
| 29 | - */ |
|
| 27 | + /** |
|
| 28 | + * @var array |
|
| 29 | + */ |
|
| 30 | 30 | protected $dispositionParams = array(); |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 32 | + /** |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | 35 | protected $contentType = ''; |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var string |
|
| 39 | - */ |
|
| 37 | + /** |
|
| 38 | + * @var string |
|
| 39 | + */ |
|
| 40 | 40 | protected $contentEncoding = ''; |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var RequestHelper_Boundaries |
|
| 44 | - */ |
|
| 42 | + /** |
|
| 43 | + * @var RequestHelper_Boundaries |
|
| 44 | + */ |
|
| 45 | 45 | protected $boundaries; |
| 46 | 46 | |
| 47 | 47 | public function __construct(RequestHelper_Boundaries $boundaries, string $content) |
@@ -55,46 +55,46 @@ discard block |
||
| 55 | 55 | return strlen($this->content); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Sets the name of the request parameter. |
|
| 60 | - * |
|
| 61 | - * @param string $name |
|
| 62 | - * @return RequestHelper_Boundaries_Boundary |
|
| 63 | - */ |
|
| 58 | + /** |
|
| 59 | + * Sets the name of the request parameter. |
|
| 60 | + * |
|
| 61 | + * @param string $name |
|
| 62 | + * @return RequestHelper_Boundaries_Boundary |
|
| 63 | + */ |
|
| 64 | 64 | public function setName(string $name) : RequestHelper_Boundaries_Boundary |
| 65 | 65 | { |
| 66 | 66 | return $this->setDispositionParam('name', $name); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Sets the filename to use for the content, if applicable. |
|
| 71 | - * |
|
| 72 | - * @param string $fileName |
|
| 73 | - * @return RequestHelper_Boundaries_Boundary |
|
| 74 | - */ |
|
| 69 | + /** |
|
| 70 | + * Sets the filename to use for the content, if applicable. |
|
| 71 | + * |
|
| 72 | + * @param string $fileName |
|
| 73 | + * @return RequestHelper_Boundaries_Boundary |
|
| 74 | + */ |
|
| 75 | 75 | public function setFileName(string $fileName) : RequestHelper_Boundaries_Boundary |
| 76 | 76 | { |
| 77 | 77 | return $this->setDispositionParam('filename', $fileName); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Sets the content type to use for the content. |
|
| 82 | - * |
|
| 83 | - * @param string $contentType |
|
| 84 | - * @return RequestHelper_Boundaries_Boundary |
|
| 85 | - */ |
|
| 80 | + /** |
|
| 81 | + * Sets the content type to use for the content. |
|
| 82 | + * |
|
| 83 | + * @param string $contentType |
|
| 84 | + * @return RequestHelper_Boundaries_Boundary |
|
| 85 | + */ |
|
| 86 | 86 | public function setContentType(string $contentType) : RequestHelper_Boundaries_Boundary |
| 87 | 87 | { |
| 88 | 88 | $this->contentType = $contentType; |
| 89 | 89 | return $this; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Sets the encoding to specify for the content. |
|
| 94 | - * |
|
| 95 | - * @param string $encoding An encoding string, e.g. "UTF-8", "ASCII" |
|
| 96 | - * @return RequestHelper_Boundaries_Boundary |
|
| 97 | - */ |
|
| 92 | + /** |
|
| 93 | + * Sets the encoding to specify for the content. |
|
| 94 | + * |
|
| 95 | + * @param string $encoding An encoding string, e.g. "UTF-8", "ASCII" |
|
| 96 | + * @return RequestHelper_Boundaries_Boundary |
|
| 97 | + */ |
|
| 98 | 98 | public function setContentEncoding(string $encoding) : RequestHelper_Boundaries_Boundary |
| 99 | 99 | { |
| 100 | 100 | $this->contentEncoding = $encoding; |
@@ -107,11 +107,11 @@ discard block |
||
| 107 | 107 | return $this; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Renders the mime boundary text. |
|
| 112 | - * |
|
| 113 | - * @return string |
|
| 114 | - */ |
|
| 110 | + /** |
|
| 111 | + * Renders the mime boundary text. |
|
| 112 | + * |
|
| 113 | + * @return string |
|
| 114 | + */ |
|
| 115 | 115 | public function render() |
| 116 | 116 | { |
| 117 | 117 | $eol = $this->boundaries->getEOL(); |
@@ -19,51 +19,51 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | class RequestHelper_Response |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * @var RequestHelper |
|
| 24 | - */ |
|
| 22 | + /** |
|
| 23 | + * @var RequestHelper |
|
| 24 | + */ |
|
| 25 | 25 | protected $request; |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 27 | + /** |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | 30 | protected $body = ''; |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var array |
|
| 34 | - */ |
|
| 32 | + /** |
|
| 33 | + * @var array |
|
| 34 | + */ |
|
| 35 | 35 | protected $info; |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var bool |
|
| 39 | - */ |
|
| 37 | + /** |
|
| 38 | + * @var bool |
|
| 39 | + */ |
|
| 40 | 40 | protected $isError = false; |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 42 | + /** |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | 45 | protected $errorMessage = ''; |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @var integer |
|
| 49 | - */ |
|
| 47 | + /** |
|
| 48 | + * @var integer |
|
| 49 | + */ |
|
| 50 | 50 | protected $errorCode = 0; |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @param RequestHelper $helper |
|
| 54 | - * @param array $info The CURL info array from curl_getinfo(). |
|
| 55 | - */ |
|
| 52 | + /** |
|
| 53 | + * @param RequestHelper $helper |
|
| 54 | + * @param array $info The CURL info array from curl_getinfo(). |
|
| 55 | + */ |
|
| 56 | 56 | public function __construct(RequestHelper $helper, array $info) |
| 57 | 57 | { |
| 58 | 58 | $this->request = $helper; |
| 59 | 59 | $this->info = $info; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Retrieves the request instance that initiated the request. |
|
| 64 | - * |
|
| 65 | - * @return RequestHelper |
|
| 66 | - */ |
|
| 62 | + /** |
|
| 63 | + * Retrieves the request instance that initiated the request. |
|
| 64 | + * |
|
| 65 | + * @return RequestHelper |
|
| 66 | + */ |
|
| 67 | 67 | public function getRequest() : RequestHelper |
| 68 | 68 | { |
| 69 | 69 | return $this->request; |
@@ -84,70 +84,70 @@ discard block |
||
| 84 | 84 | return $this; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Whether an error occurred in the request. |
|
| 89 | - * @return bool |
|
| 90 | - */ |
|
| 87 | + /** |
|
| 88 | + * Whether an error occurred in the request. |
|
| 89 | + * @return bool |
|
| 90 | + */ |
|
| 91 | 91 | public function isError() : bool |
| 92 | 92 | { |
| 93 | 93 | return $this->isError; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Retrieves the native error message, if an error occurred. |
|
| 98 | - * @return string |
|
| 99 | - */ |
|
| 96 | + /** |
|
| 97 | + * Retrieves the native error message, if an error occurred. |
|
| 98 | + * @return string |
|
| 99 | + */ |
|
| 100 | 100 | public function getErrorMessage() : string |
| 101 | 101 | { |
| 102 | 102 | return $this->errorMessage; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Retrieves the native error code, if an error occurred. |
|
| 107 | - * @return int |
|
| 108 | - */ |
|
| 105 | + /** |
|
| 106 | + * Retrieves the native error code, if an error occurred. |
|
| 107 | + * @return int |
|
| 108 | + */ |
|
| 109 | 109 | public function getErrorCode() : int |
| 110 | 110 | { |
| 111 | 111 | return $this->errorCode; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Retrieves the full body of the request. |
|
| 117 | - * |
|
| 118 | - * @return string |
|
| 119 | - */ |
|
| 115 | + /** |
|
| 116 | + * Retrieves the full body of the request. |
|
| 117 | + * |
|
| 118 | + * @return string |
|
| 119 | + */ |
|
| 120 | 120 | public function getRequestBody() : string |
| 121 | 121 | { |
| 122 | 122 | return $this->request->getBody(); |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * Retrieves the body of the response, if any. |
|
| 127 | - * |
|
| 128 | - * @return string |
|
| 129 | - */ |
|
| 125 | + /** |
|
| 126 | + * Retrieves the body of the response, if any. |
|
| 127 | + * |
|
| 128 | + * @return string |
|
| 129 | + */ |
|
| 130 | 130 | public function getResponseBody() : string |
| 131 | 131 | { |
| 132 | 132 | return $this->body; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * The response HTTP code. |
|
| 137 | - * |
|
| 138 | - * @return int The code, or 0 if none was sent (on error). |
|
| 139 | - */ |
|
| 135 | + /** |
|
| 136 | + * The response HTTP code. |
|
| 137 | + * |
|
| 138 | + * @return int The code, or 0 if none was sent (on error). |
|
| 139 | + */ |
|
| 140 | 140 | public function getCode() : int |
| 141 | 141 | { |
| 142 | 142 | return intval($this->getInfoKey('http_code')); |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * Retrieves the actual headers that were sent in the request: |
|
| 147 | - * one header by entry in the indexed array. |
|
| 148 | - * |
|
| 149 | - * @return array |
|
| 150 | - */ |
|
| 145 | + /** |
|
| 146 | + * Retrieves the actual headers that were sent in the request: |
|
| 147 | + * one header by entry in the indexed array. |
|
| 148 | + * |
|
| 149 | + * @return array |
|
| 150 | + */ |
|
| 151 | 151 | public function getHeaders() : array |
| 152 | 152 | { |
| 153 | 153 | return ConvertHelper::explodeTrim("\n", $this->getInfoKey('request_header')); |
@@ -32,23 +32,23 @@ |
||
| 32 | 32 | $this->info = $info; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Enables the authentication information in the URL, |
|
| 37 | - * if a username and password are present. |
|
| 38 | - * |
|
| 39 | - * @param bool $enable Whether to turn it on or off. |
|
| 40 | - * @return URLInfo_Normalizer |
|
| 41 | - */ |
|
| 35 | + /** |
|
| 36 | + * Enables the authentication information in the URL, |
|
| 37 | + * if a username and password are present. |
|
| 38 | + * |
|
| 39 | + * @param bool $enable Whether to turn it on or off. |
|
| 40 | + * @return URLInfo_Normalizer |
|
| 41 | + */ |
|
| 42 | 42 | public function enableAuth(bool $enable=true) : URLInfo_Normalizer |
| 43 | 43 | { |
| 44 | 44 | $this->auth = $enable; |
| 45 | 45 | return $this; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Retrieves the normalized URL. |
|
| 50 | - * @return string |
|
| 51 | - */ |
|
| 48 | + /** |
|
| 49 | + * Retrieves the normalized URL. |
|
| 50 | + * @return string |
|
| 51 | + */ |
|
| 52 | 52 | public function normalize() : string |
| 53 | 53 | { |
| 54 | 54 | $method = 'normalize_'.$this->info->getType(); |
@@ -17,21 +17,20 @@ discard block |
||
| 17 | 17 | * @package Application Utils |
| 18 | 18 | * @subpackage ConvertHelper |
| 19 | 19 | * @author Sebastian Mordziol <[email protected]> |
| 20 | - |
|
| 21 | 20 | * @see ConvertHelper::interval2string() |
| 22 | 21 | */ |
| 23 | 22 | class ConvertHelper_IntervalConverter |
| 24 | 23 | { |
| 25 | 24 | const ERROR_MISSING_TRANSLATION = 43501; |
| 26 | 25 | |
| 27 | - /** |
|
| 28 | - * @var array|NULL |
|
| 29 | - */ |
|
| 26 | + /** |
|
| 27 | + * @var array|NULL |
|
| 28 | + */ |
|
| 30 | 29 | protected static $texts = null; |
| 31 | 30 | |
| 32 | - /** |
|
| 33 | - * @var array |
|
| 34 | - */ |
|
| 31 | + /** |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 35 | 34 | protected $tokens = array('y', 'm', 'd', 'h', 'i', 's'); |
| 36 | 35 | |
| 37 | 36 | public function __construct() |
@@ -41,25 +40,25 @@ discard block |
||
| 41 | 40 | } |
| 42 | 41 | } |
| 43 | 42 | |
| 44 | - /** |
|
| 45 | - * Called whenever the application locale has changed, |
|
| 46 | - * to reset the internal translation cache. |
|
| 47 | - */ |
|
| 43 | + /** |
|
| 44 | + * Called whenever the application locale has changed, |
|
| 45 | + * to reset the internal translation cache. |
|
| 46 | + */ |
|
| 48 | 47 | public function handle_localeChanged() |
| 49 | 48 | { |
| 50 | 49 | self::$texts = null; |
| 51 | 50 | } |
| 52 | 51 | |
| 53 | - /** |
|
| 54 | - * Converts the specified interval to a human readable |
|
| 55 | - * string, e.g. "2 hours and 4 minutes". |
|
| 56 | - * |
|
| 57 | - * @param \DateInterval $interval |
|
| 58 | - * @return string |
|
| 59 | - * @throws ConvertHelper_Exception |
|
| 60 | - * |
|
| 61 | - * @see ConvertHelper_IntervalConverter::ERROR_MISSING_TRANSLATION |
|
| 62 | - */ |
|
| 52 | + /** |
|
| 53 | + * Converts the specified interval to a human readable |
|
| 54 | + * string, e.g. "2 hours and 4 minutes". |
|
| 55 | + * |
|
| 56 | + * @param \DateInterval $interval |
|
| 57 | + * @return string |
|
| 58 | + * @throws ConvertHelper_Exception |
|
| 59 | + * |
|
| 60 | + * @see ConvertHelper_IntervalConverter::ERROR_MISSING_TRANSLATION |
|
| 61 | + */ |
|
| 63 | 62 | public function toString(\DateInterval $interval) : string |
| 64 | 63 | { |
| 65 | 64 | $this->initTexts(); |
@@ -88,14 +87,14 @@ discard block |
||
| 88 | 87 | return t('%1$s and %2$s', implode(', ', $parts), $last); |
| 89 | 88 | } |
| 90 | 89 | |
| 91 | - /** |
|
| 92 | - * Translates the selected time token, e.g. "y" (for year). |
|
| 93 | - * |
|
| 94 | - * @param string $token |
|
| 95 | - * @param ConvertHelper_DateInterval $interval |
|
| 96 | - * @throws ConvertHelper_Exception |
|
| 97 | - * @return string |
|
| 98 | - */ |
|
| 90 | + /** |
|
| 91 | + * Translates the selected time token, e.g. "y" (for year). |
|
| 92 | + * |
|
| 93 | + * @param string $token |
|
| 94 | + * @param ConvertHelper_DateInterval $interval |
|
| 95 | + * @throws ConvertHelper_Exception |
|
| 96 | + * @return string |
|
| 97 | + */ |
|
| 99 | 98 | protected function translateToken(string $token, ConvertHelper_DateInterval $interval) : string |
| 100 | 99 | { |
| 101 | 100 | $value = $interval->getToken($token); |
@@ -123,13 +122,13 @@ discard block |
||
| 123 | 122 | ); |
| 124 | 123 | } |
| 125 | 124 | |
| 126 | - /** |
|
| 127 | - * Resolves all time tokens that need to be translated in |
|
| 128 | - * the subject interval, depending on its length. |
|
| 129 | - * |
|
| 130 | - * @param ConvertHelper_DateInterval $interval |
|
| 131 | - * @return array |
|
| 132 | - */ |
|
| 125 | + /** |
|
| 126 | + * Resolves all time tokens that need to be translated in |
|
| 127 | + * the subject interval, depending on its length. |
|
| 128 | + * |
|
| 129 | + * @param ConvertHelper_DateInterval $interval |
|
| 130 | + * @return array |
|
| 131 | + */ |
|
| 133 | 132 | protected function resolveTokens(ConvertHelper_DateInterval $interval) : array |
| 134 | 133 | { |
| 135 | 134 | $offset = 0; |
@@ -147,9 +146,9 @@ discard block |
||
| 147 | 146 | return array(); |
| 148 | 147 | } |
| 149 | 148 | |
| 150 | - /** |
|
| 151 | - * Initializes the translateable strings. |
|
| 152 | - */ |
|
| 149 | + /** |
|
| 150 | + * Initializes the translateable strings. |
|
| 151 | + */ |
|
| 153 | 152 | protected function initTexts() : void |
| 154 | 153 | { |
| 155 | 154 | if(isset(self::$texts)) { |
@@ -39,42 +39,42 @@ discard block |
||
| 39 | 39 | const TYPE_PHONE = 'phone'; |
| 40 | 40 | const TYPE_URL = 'url'; |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * The original URL that was passed to the constructor. |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 42 | + /** |
|
| 43 | + * The original URL that was passed to the constructor. |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | 46 | protected $rawURL; |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @var array |
|
| 50 | - */ |
|
| 48 | + /** |
|
| 49 | + * @var array |
|
| 50 | + */ |
|
| 51 | 51 | protected $info; |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @var string[] |
|
| 55 | - */ |
|
| 53 | + /** |
|
| 54 | + * @var string[] |
|
| 55 | + */ |
|
| 56 | 56 | protected $excludedParams = array(); |
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @var bool |
|
| 60 | - * @see URLInfo::setParamExclusion() |
|
| 61 | - */ |
|
| 58 | + /** |
|
| 59 | + * @var bool |
|
| 60 | + * @see URLInfo::setParamExclusion() |
|
| 61 | + */ |
|
| 62 | 62 | protected $paramExclusion = false; |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @var array |
|
| 66 | - * @see URLInfo::getTypeLabel() |
|
| 67 | - */ |
|
| 64 | + /** |
|
| 65 | + * @var array |
|
| 66 | + * @see URLInfo::getTypeLabel() |
|
| 67 | + */ |
|
| 68 | 68 | protected static $typeLabels; |
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @var bool |
|
| 72 | - */ |
|
| 70 | + /** |
|
| 71 | + * @var bool |
|
| 72 | + */ |
|
| 73 | 73 | protected $highlightExcluded = false; |
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @var array |
|
| 77 | - */ |
|
| 75 | + /** |
|
| 76 | + * @var array |
|
| 77 | + */ |
|
| 78 | 78 | protected $infoKeys = array( |
| 79 | 79 | 'scheme', |
| 80 | 80 | 'host', |
@@ -86,19 +86,19 @@ discard block |
||
| 86 | 86 | 'fragment' |
| 87 | 87 | ); |
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * @var string |
|
| 91 | - */ |
|
| 89 | + /** |
|
| 90 | + * @var string |
|
| 91 | + */ |
|
| 92 | 92 | protected $url; |
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * @var URLInfo_Parser |
|
| 96 | - */ |
|
| 94 | + /** |
|
| 95 | + * @var URLInfo_Parser |
|
| 96 | + */ |
|
| 97 | 97 | protected $parser; |
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * @var URLInfo_Normalizer |
|
| 101 | - */ |
|
| 99 | + /** |
|
| 100 | + * @var URLInfo_Normalizer |
|
| 101 | + */ |
|
| 102 | 102 | protected $normalizer; |
| 103 | 103 | |
| 104 | 104 | public function __construct(string $url) |
@@ -110,13 +110,13 @@ discard block |
||
| 110 | 110 | $this->info = $this->parser->getInfo(); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * Filters an URL: removes control characters and the |
|
| 115 | - * like to have a clean URL to work with. |
|
| 116 | - * |
|
| 117 | - * @param string $url |
|
| 118 | - * @return string |
|
| 119 | - */ |
|
| 113 | + /** |
|
| 114 | + * Filters an URL: removes control characters and the |
|
| 115 | + * like to have a clean URL to work with. |
|
| 116 | + * |
|
| 117 | + * @param string $url |
|
| 118 | + * @return string |
|
| 119 | + */ |
|
| 120 | 120 | public static function filterURL(string $url) |
| 121 | 121 | { |
| 122 | 122 | return URLInfo_Filter::filter($url); |
@@ -146,12 +146,12 @@ discard block |
||
| 146 | 146 | return $this->info['type'] === self::TYPE_PHONE; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * Whether the URL is a regular URL, not one of the |
|
| 151 | - * other types like a phone number or email address. |
|
| 152 | - * |
|
| 153 | - * @return bool |
|
| 154 | - */ |
|
| 149 | + /** |
|
| 150 | + * Whether the URL is a regular URL, not one of the |
|
| 151 | + * other types like a phone number or email address. |
|
| 152 | + * |
|
| 153 | + * @return bool |
|
| 154 | + */ |
|
| 155 | 155 | public function isURL() : bool |
| 156 | 156 | { |
| 157 | 157 | $host = $this->getHost(); |
@@ -163,20 +163,20 @@ discard block |
||
| 163 | 163 | return $this->parser->isValid(); |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * Retrieves the host name, or an empty string if none is present. |
|
| 168 | - * |
|
| 169 | - * @return string |
|
| 170 | - */ |
|
| 166 | + /** |
|
| 167 | + * Retrieves the host name, or an empty string if none is present. |
|
| 168 | + * |
|
| 169 | + * @return string |
|
| 170 | + */ |
|
| 171 | 171 | public function getHost() : string |
| 172 | 172 | { |
| 173 | 173 | return $this->getInfoKey('host'); |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * Retrieves the path, or an empty string if none is present. |
|
| 178 | - * @return string |
|
| 179 | - */ |
|
| 176 | + /** |
|
| 177 | + * Retrieves the path, or an empty string if none is present. |
|
| 178 | + * @return string |
|
| 179 | + */ |
|
| 180 | 180 | public function getPath() : string |
| 181 | 181 | { |
| 182 | 182 | return $this->getInfoKey('path'); |
@@ -192,10 +192,10 @@ discard block |
||
| 192 | 192 | return $this->getInfoKey('scheme'); |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
| 197 | - * @return int |
|
| 198 | - */ |
|
| 195 | + /** |
|
| 196 | + * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
| 197 | + * @return int |
|
| 198 | + */ |
|
| 199 | 199 | public function getPort() : int |
| 200 | 200 | { |
| 201 | 201 | $port = $this->getInfoKey('port'); |
@@ -207,13 +207,13 @@ discard block |
||
| 207 | 207 | return -1; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * Retrieves the raw query string, or an empty string if none is present. |
|
| 212 | - * |
|
| 213 | - * @return string |
|
| 214 | - * |
|
| 215 | - * @see URLInfo::getParams() |
|
| 216 | - */ |
|
| 210 | + /** |
|
| 211 | + * Retrieves the raw query string, or an empty string if none is present. |
|
| 212 | + * |
|
| 213 | + * @return string |
|
| 214 | + * |
|
| 215 | + * @see URLInfo::getParams() |
|
| 216 | + */ |
|
| 217 | 217 | public function getQuery() : string |
| 218 | 218 | { |
| 219 | 219 | return $this->getInfoKey('query'); |
@@ -229,20 +229,20 @@ discard block |
||
| 229 | 229 | return $this->getInfoKey('pass'); |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - /** |
|
| 233 | - * Whether the URL contains a port number. |
|
| 234 | - * @return bool |
|
| 235 | - */ |
|
| 232 | + /** |
|
| 233 | + * Whether the URL contains a port number. |
|
| 234 | + * @return bool |
|
| 235 | + */ |
|
| 236 | 236 | public function hasPort() : bool |
| 237 | 237 | { |
| 238 | 238 | return $this->getPort() !== -1; |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - /** |
|
| 242 | - * Alias for the hasParams() method. |
|
| 243 | - * @return bool |
|
| 244 | - * @see URLInfo::hasParams() |
|
| 245 | - */ |
|
| 241 | + /** |
|
| 242 | + * Alias for the hasParams() method. |
|
| 243 | + * @return bool |
|
| 244 | + * @see URLInfo::hasParams() |
|
| 245 | + */ |
|
| 246 | 246 | public function hasQuery() : bool |
| 247 | 247 | { |
| 248 | 248 | return $this->hasParams(); |
@@ -287,23 +287,23 @@ discard block |
||
| 287 | 287 | return ''; |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - /** |
|
| 291 | - * Retrieves a normalized URL: this ensures that all parameters |
|
| 292 | - * in the URL are always in the same order. |
|
| 293 | - * |
|
| 294 | - * @return string |
|
| 295 | - */ |
|
| 290 | + /** |
|
| 291 | + * Retrieves a normalized URL: this ensures that all parameters |
|
| 292 | + * in the URL are always in the same order. |
|
| 293 | + * |
|
| 294 | + * @return string |
|
| 295 | + */ |
|
| 296 | 296 | public function getNormalized() : string |
| 297 | 297 | { |
| 298 | 298 | return $this->normalize(true); |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - /** |
|
| 302 | - * Like getNormalized(), but if a username and password are present |
|
| 303 | - * in the URL, returns the URL without them. |
|
| 304 | - * |
|
| 305 | - * @return string |
|
| 306 | - */ |
|
| 301 | + /** |
|
| 302 | + * Like getNormalized(), but if a username and password are present |
|
| 303 | + * in the URL, returns the URL without them. |
|
| 304 | + * |
|
| 305 | + * @return string |
|
| 306 | + */ |
|
| 307 | 307 | public function getNormalizedWithoutAuth() : string |
| 308 | 308 | { |
| 309 | 309 | return $this->normalize(false); |
@@ -324,25 +324,25 @@ discard block |
||
| 324 | 324 | return $this->normalizer->normalize(); |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | - /** |
|
| 328 | - * Creates a hash of the URL, which can be used for comparisons. |
|
| 329 | - * Since any parameters in the URL's query are sorted alphabetically, |
|
| 330 | - * the same links with a different parameter order will have the |
|
| 331 | - * same hash. |
|
| 332 | - * |
|
| 333 | - * @return string |
|
| 334 | - */ |
|
| 327 | + /** |
|
| 328 | + * Creates a hash of the URL, which can be used for comparisons. |
|
| 329 | + * Since any parameters in the URL's query are sorted alphabetically, |
|
| 330 | + * the same links with a different parameter order will have the |
|
| 331 | + * same hash. |
|
| 332 | + * |
|
| 333 | + * @return string |
|
| 334 | + */ |
|
| 335 | 335 | public function getHash() |
| 336 | 336 | { |
| 337 | 337 | return \AppUtils\ConvertHelper::string2shortHash($this->getNormalized()); |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | - /** |
|
| 341 | - * Highlights the URL using HTML tags with specific highlighting |
|
| 342 | - * class names. |
|
| 343 | - * |
|
| 344 | - * @return string Will return an empty string if the URL is not valid. |
|
| 345 | - */ |
|
| 340 | + /** |
|
| 341 | + * Highlights the URL using HTML tags with specific highlighting |
|
| 342 | + * class names. |
|
| 343 | + * |
|
| 344 | + * @return string Will return an empty string if the URL is not valid. |
|
| 345 | + */ |
|
| 346 | 346 | public function getHighlighted() : string |
| 347 | 347 | { |
| 348 | 348 | if(!$this->isValid()) { |
@@ -376,15 +376,15 @@ discard block |
||
| 376 | 376 | return count($params); |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - /** |
|
| 380 | - * Retrieves all parameters specified in the url, |
|
| 381 | - * if any, as an associative array. |
|
| 382 | - * |
|
| 383 | - * NOTE: Ignores parameters that have been added |
|
| 384 | - * to the excluded parameters list. |
|
| 385 | - * |
|
| 386 | - * @return array |
|
| 387 | - */ |
|
| 379 | + /** |
|
| 380 | + * Retrieves all parameters specified in the url, |
|
| 381 | + * if any, as an associative array. |
|
| 382 | + * |
|
| 383 | + * NOTE: Ignores parameters that have been added |
|
| 384 | + * to the excluded parameters list. |
|
| 385 | + * |
|
| 386 | + * @return array |
|
| 387 | + */ |
|
| 388 | 388 | public function getParams() : array |
| 389 | 389 | { |
| 390 | 390 | if(!$this->paramExclusion || empty($this->excludedParams)) { |
@@ -402,22 +402,22 @@ discard block |
||
| 402 | 402 | return $keep; |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | - /** |
|
| 406 | - * Retrieves the names of all parameters present in the URL, if any. |
|
| 407 | - * @return string[] |
|
| 408 | - */ |
|
| 405 | + /** |
|
| 406 | + * Retrieves the names of all parameters present in the URL, if any. |
|
| 407 | + * @return string[] |
|
| 408 | + */ |
|
| 409 | 409 | public function getParamNames() : array |
| 410 | 410 | { |
| 411 | 411 | $params = $this->getParams(); |
| 412 | 412 | return array_keys($params); |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | - /** |
|
| 416 | - * Retrieves a specific parameter value from the URL. |
|
| 417 | - * |
|
| 418 | - * @param string $name |
|
| 419 | - * @return string The parameter value, or an empty string if it does not exist. |
|
| 420 | - */ |
|
| 415 | + /** |
|
| 416 | + * Retrieves a specific parameter value from the URL. |
|
| 417 | + * |
|
| 418 | + * @param string $name |
|
| 419 | + * @return string The parameter value, or an empty string if it does not exist. |
|
| 420 | + */ |
|
| 421 | 421 | public function getParam(string $name) : string |
| 422 | 422 | { |
| 423 | 423 | if(isset($this->info['params'][$name])) { |
@@ -427,16 +427,16 @@ discard block |
||
| 427 | 427 | return ''; |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | - /** |
|
| 431 | - * Excludes an URL parameter entirely if present: |
|
| 432 | - * the parser will act as if the parameter was not |
|
| 433 | - * even present in the source URL, effectively |
|
| 434 | - * stripping it. |
|
| 435 | - * |
|
| 436 | - * @param string $name |
|
| 437 | - * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
| 438 | - * @return URLInfo |
|
| 439 | - */ |
|
| 430 | + /** |
|
| 431 | + * Excludes an URL parameter entirely if present: |
|
| 432 | + * the parser will act as if the parameter was not |
|
| 433 | + * even present in the source URL, effectively |
|
| 434 | + * stripping it. |
|
| 435 | + * |
|
| 436 | + * @param string $name |
|
| 437 | + * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
| 438 | + * @return URLInfo |
|
| 439 | + */ |
|
| 440 | 440 | public function excludeParam(string $name, string $reason) : URLInfo |
| 441 | 441 | { |
| 442 | 442 | if(!isset($this->excludedParams[$name])) |
@@ -489,25 +489,25 @@ discard block |
||
| 489 | 489 | return self::$typeLabels[$this->getType()]; |
| 490 | 490 | } |
| 491 | 491 | |
| 492 | - /** |
|
| 493 | - * Whether excluded parameters should be highlighted in |
|
| 494 | - * a different color in the URL when using the |
|
| 495 | - * {@link URLInfo::getHighlighted()} method. |
|
| 496 | - * |
|
| 497 | - * @param bool $highlight |
|
| 498 | - * @return URLInfo |
|
| 499 | - */ |
|
| 492 | + /** |
|
| 493 | + * Whether excluded parameters should be highlighted in |
|
| 494 | + * a different color in the URL when using the |
|
| 495 | + * {@link URLInfo::getHighlighted()} method. |
|
| 496 | + * |
|
| 497 | + * @param bool $highlight |
|
| 498 | + * @return URLInfo |
|
| 499 | + */ |
|
| 500 | 500 | public function setHighlightExcluded(bool $highlight=true) : URLInfo |
| 501 | 501 | { |
| 502 | 502 | $this->highlightExcluded = $highlight; |
| 503 | 503 | return $this; |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | - /** |
|
| 507 | - * Returns an array with all relevant URL information. |
|
| 508 | - * |
|
| 509 | - * @return array |
|
| 510 | - */ |
|
| 506 | + /** |
|
| 507 | + * Returns an array with all relevant URL information. |
|
| 508 | + * |
|
| 509 | + * @return array |
|
| 510 | + */ |
|
| 511 | 511 | public function toArray() : array |
| 512 | 512 | { |
| 513 | 513 | return array( |
@@ -551,24 +551,24 @@ discard block |
||
| 551 | 551 | return $this; |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | - /** |
|
| 555 | - * Whether the parameter exclusion mode is enabled: |
|
| 556 | - * In this case, if any parameters have been added to the |
|
| 557 | - * exclusion list, all relevant methods will exclude these. |
|
| 558 | - * |
|
| 559 | - * @return bool |
|
| 560 | - */ |
|
| 554 | + /** |
|
| 555 | + * Whether the parameter exclusion mode is enabled: |
|
| 556 | + * In this case, if any parameters have been added to the |
|
| 557 | + * exclusion list, all relevant methods will exclude these. |
|
| 558 | + * |
|
| 559 | + * @return bool |
|
| 560 | + */ |
|
| 561 | 561 | public function isParamExclusionEnabled() : bool |
| 562 | 562 | { |
| 563 | 563 | return $this->paramExclusion; |
| 564 | 564 | } |
| 565 | 565 | |
| 566 | - /** |
|
| 567 | - * Checks whether the link contains any parameters that |
|
| 568 | - * are on the list of excluded parameters. |
|
| 569 | - * |
|
| 570 | - * @return bool |
|
| 571 | - */ |
|
| 566 | + /** |
|
| 567 | + * Checks whether the link contains any parameters that |
|
| 568 | + * are on the list of excluded parameters. |
|
| 569 | + * |
|
| 570 | + * @return bool |
|
| 571 | + */ |
|
| 572 | 572 | public function containsExcludedParams() : bool |
| 573 | 573 | { |
| 574 | 574 | if(empty($this->excludedParams)) { |
@@ -636,16 +636,16 @@ discard block |
||
| 636 | 636 | return $this->highlightExcluded; |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | - /** |
|
| 640 | - * Checks if the URL exists, i.e. can be connected to. Will return |
|
| 641 | - * true if the returned HTTP status code is `200` or `302`. |
|
| 642 | - * |
|
| 643 | - * NOTE: If the target URL requires HTTP authentication, the username |
|
| 644 | - * and password should be integrated into the URL. |
|
| 645 | - * |
|
| 646 | - * @return bool |
|
| 647 | - * @throws BaseException |
|
| 648 | - */ |
|
| 639 | + /** |
|
| 640 | + * Checks if the URL exists, i.e. can be connected to. Will return |
|
| 641 | + * true if the returned HTTP status code is `200` or `302`. |
|
| 642 | + * |
|
| 643 | + * NOTE: If the target URL requires HTTP authentication, the username |
|
| 644 | + * and password should be integrated into the URL. |
|
| 645 | + * |
|
| 646 | + * @return bool |
|
| 647 | + * @throws BaseException |
|
| 648 | + */ |
|
| 649 | 649 | public function tryConnect(bool $verifySSL=true) : bool |
| 650 | 650 | { |
| 651 | 651 | requireCURL(); |
@@ -29,56 +29,56 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | const ERROR_CURL_INIT_FAILED = 17903; |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 32 | + /** |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | 35 | protected $eol = "\r\n"; |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var string |
|
| 39 | - */ |
|
| 37 | + /** |
|
| 38 | + * @var string |
|
| 39 | + */ |
|
| 40 | 40 | protected $mimeBoundary; |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 42 | + /** |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | 45 | protected $data = ''; |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @var string |
|
| 49 | - */ |
|
| 47 | + /** |
|
| 48 | + * @var string |
|
| 49 | + */ |
|
| 50 | 50 | protected $destination; |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 52 | + /** |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | 55 | protected $headers = array(); |
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Whether to verify SSL certificates. |
|
| 59 | - * @var bool |
|
| 60 | - */ |
|
| 57 | + /** |
|
| 58 | + * Whether to verify SSL certificates. |
|
| 59 | + * @var bool |
|
| 60 | + */ |
|
| 61 | 61 | protected $verifySSL = true; |
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @var RequestHelper_Boundaries |
|
| 65 | - */ |
|
| 63 | + /** |
|
| 64 | + * @var RequestHelper_Boundaries |
|
| 65 | + */ |
|
| 66 | 66 | protected $boundaries; |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @var RequestHelper_Response|NULL |
|
| 70 | - */ |
|
| 68 | + /** |
|
| 69 | + * @var RequestHelper_Response|NULL |
|
| 70 | + */ |
|
| 71 | 71 | protected $response; |
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @var integer |
|
| 75 | - */ |
|
| 73 | + /** |
|
| 74 | + * @var integer |
|
| 75 | + */ |
|
| 76 | 76 | protected $timeout = 30; |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Creates a new request helper to send POST data to the specified destination URL. |
|
| 80 | - * @param string $destinationURL |
|
| 81 | - */ |
|
| 78 | + /** |
|
| 79 | + * Creates a new request helper to send POST data to the specified destination URL. |
|
| 80 | + * @param string $destinationURL |
|
| 81 | + */ |
|
| 82 | 82 | public function __construct(string $destinationURL) |
| 83 | 83 | { |
| 84 | 84 | $this->destination = $destinationURL; |
@@ -105,15 +105,15 @@ discard block |
||
| 105 | 105 | return $this; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Adds a file to be sent with the request. |
|
| 110 | - * |
|
| 111 | - * @param string $varName The variable name to send the file in |
|
| 112 | - * @param string $fileName The name of the file as it should be received at the destination |
|
| 113 | - * @param string $content The raw content of the file |
|
| 114 | - * @param string $contentType The content type, use the constants to specify this |
|
| 115 | - * @param string $encoding The encoding of the file, use the constants to specify this |
|
| 116 | - */ |
|
| 108 | + /** |
|
| 109 | + * Adds a file to be sent with the request. |
|
| 110 | + * |
|
| 111 | + * @param string $varName The variable name to send the file in |
|
| 112 | + * @param string $fileName The name of the file as it should be received at the destination |
|
| 113 | + * @param string $content The raw content of the file |
|
| 114 | + * @param string $contentType The content type, use the constants to specify this |
|
| 115 | + * @param string $encoding The encoding of the file, use the constants to specify this |
|
| 116 | + */ |
|
| 117 | 117 | public function addFile(string $varName, string $fileName, string $content, string $contentType = self::FILETYPE_TEXT, string $encoding = self::ENCODING_UTF8) : RequestHelper |
| 118 | 118 | { |
| 119 | 119 | $this->boundaries->addFile($varName, $fileName, $content, $contentType, $encoding); |
@@ -121,13 +121,13 @@ discard block |
||
| 121 | 121 | return $this; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * Adds arbitrary content. |
|
| 126 | - * |
|
| 127 | - * @param string $varName The variable name to send the content in. |
|
| 128 | - * @param string $content |
|
| 129 | - * @param string $contentType |
|
| 130 | - */ |
|
| 124 | + /** |
|
| 125 | + * Adds arbitrary content. |
|
| 126 | + * |
|
| 127 | + * @param string $varName The variable name to send the content in. |
|
| 128 | + * @param string $content |
|
| 129 | + * @param string $contentType |
|
| 130 | + */ |
|
| 131 | 131 | public function addContent(string $varName, string $content, string $contentType) : RequestHelper |
| 132 | 132 | { |
| 133 | 133 | $this->boundaries->addContent($varName, $content, $contentType); |
@@ -149,13 +149,13 @@ discard block |
||
| 149 | 149 | return $this; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * Sets an HTTP header to include in the request. |
|
| 154 | - * |
|
| 155 | - * @param string $name |
|
| 156 | - * @param string $value |
|
| 157 | - * @return RequestHelper |
|
| 158 | - */ |
|
| 152 | + /** |
|
| 153 | + * Sets an HTTP header to include in the request. |
|
| 154 | + * |
|
| 155 | + * @param string $name |
|
| 156 | + * @param string $value |
|
| 157 | + * @return RequestHelper |
|
| 158 | + */ |
|
| 159 | 159 | public function setHeader(string $name, string $value) : RequestHelper |
| 160 | 160 | { |
| 161 | 161 | $this->headers[$name] = $value; |
@@ -163,36 +163,36 @@ discard block |
||
| 163 | 163 | return $this; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * Disables SSL certificate checking. |
|
| 168 | - * |
|
| 169 | - * @return RequestHelper |
|
| 170 | - */ |
|
| 166 | + /** |
|
| 167 | + * Disables SSL certificate checking. |
|
| 168 | + * |
|
| 169 | + * @return RequestHelper |
|
| 170 | + */ |
|
| 171 | 171 | public function disableSSLChecks() : RequestHelper |
| 172 | 172 | { |
| 173 | 173 | $this->verifySSL = false; |
| 174 | 174 | return $this; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * @var integer |
|
| 179 | - */ |
|
| 177 | + /** |
|
| 178 | + * @var integer |
|
| 179 | + */ |
|
| 180 | 180 | protected $contentLength = 0; |
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * Sends the POST request to the destination, and returns |
|
| 184 | - * the response text. |
|
| 185 | - * |
|
| 186 | - * The response object is stored internally, so after calling |
|
| 187 | - * this method it may be retrieved at any moment using the |
|
| 188 | - * {@link getResponse()} method. |
|
| 189 | - * |
|
| 190 | - * @return string |
|
| 191 | - * @see RequestHelper::getResponse() |
|
| 192 | - * @throws RequestHelper_Exception |
|
| 193 | - * |
|
| 194 | - * @see RequestHelper::ERROR_REQUEST_FAILED |
|
| 195 | - */ |
|
| 182 | + /** |
|
| 183 | + * Sends the POST request to the destination, and returns |
|
| 184 | + * the response text. |
|
| 185 | + * |
|
| 186 | + * The response object is stored internally, so after calling |
|
| 187 | + * this method it may be retrieved at any moment using the |
|
| 188 | + * {@link getResponse()} method. |
|
| 189 | + * |
|
| 190 | + * @return string |
|
| 191 | + * @see RequestHelper::getResponse() |
|
| 192 | + * @throws RequestHelper_Exception |
|
| 193 | + * |
|
| 194 | + * @see RequestHelper::ERROR_REQUEST_FAILED |
|
| 195 | + */ |
|
| 196 | 196 | public function send() : string |
| 197 | 197 | { |
| 198 | 198 | $this->data = $this->boundaries->render(); |
@@ -232,14 +232,14 @@ discard block |
||
| 232 | 232 | return $this->data; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - /** |
|
| 236 | - * Creates a new CURL resource configured according to the |
|
| 237 | - * request's settings. |
|
| 238 | - * |
|
| 239 | - * @param URLInfo $url |
|
| 240 | - * @throws RequestHelper_Exception |
|
| 241 | - * @return resource |
|
| 242 | - */ |
|
| 235 | + /** |
|
| 236 | + * Creates a new CURL resource configured according to the |
|
| 237 | + * request's settings. |
|
| 238 | + * |
|
| 239 | + * @param URLInfo $url |
|
| 240 | + * @throws RequestHelper_Exception |
|
| 241 | + * @return resource |
|
| 242 | + */ |
|
| 243 | 243 | protected function createCURL(URLInfo $url) |
| 244 | 244 | { |
| 245 | 245 | $ch = curl_init(); |
@@ -279,13 +279,13 @@ discard block |
||
| 279 | 279 | return $ch; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - /** |
|
| 283 | - * Compiles the associative headers array into |
|
| 284 | - * the format understood by CURL, namely an indexed |
|
| 285 | - * array with one header string per entry. |
|
| 286 | - * |
|
| 287 | - * @return array |
|
| 288 | - */ |
|
| 282 | + /** |
|
| 283 | + * Compiles the associative headers array into |
|
| 284 | + * the format understood by CURL, namely an indexed |
|
| 285 | + * array with one header string per entry. |
|
| 286 | + * |
|
| 287 | + * @return array |
|
| 288 | + */ |
|
| 289 | 289 | protected function renderHeaders() : array |
| 290 | 290 | { |
| 291 | 291 | $result = array(); |
@@ -297,10 +297,10 @@ discard block |
||
| 297 | 297 | return $result; |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - /** |
|
| 301 | - * Retrieves the raw response header, in the form of an indexed |
|
| 302 | - * array containing all response header lines, for example: |
|
| 303 | - */ |
|
| 300 | + /** |
|
| 301 | + * Retrieves the raw response header, in the form of an indexed |
|
| 302 | + * array containing all response header lines, for example: |
|
| 303 | + */ |
|
| 304 | 304 | public function getResponseHeader() : array |
| 305 | 305 | { |
| 306 | 306 | if(isset($this->response)) { |
@@ -162,41 +162,41 @@ discard block |
||
| 162 | 162 | return implode(', ', $tokens) . ' ' . t('and') . ' ' . $last; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * Converts a timestamp into an easily understandable |
|
| 167 | - * format, e.g. "2 hours", "1 day", "3 months" |
|
| 168 | - * |
|
| 169 | - * If you set the date to parameter, the difference |
|
| 170 | - * will be calculated between the two dates and not |
|
| 171 | - * the current time. |
|
| 172 | - * |
|
| 173 | - * @param integer|\DateTime $datefrom |
|
| 174 | - * @param integer|\DateTime $dateto |
|
| 175 | - * @return string |
|
| 176 | - */ |
|
| 165 | + /** |
|
| 166 | + * Converts a timestamp into an easily understandable |
|
| 167 | + * format, e.g. "2 hours", "1 day", "3 months" |
|
| 168 | + * |
|
| 169 | + * If you set the date to parameter, the difference |
|
| 170 | + * will be calculated between the two dates and not |
|
| 171 | + * the current time. |
|
| 172 | + * |
|
| 173 | + * @param integer|\DateTime $datefrom |
|
| 174 | + * @param integer|\DateTime $dateto |
|
| 175 | + * @return string |
|
| 176 | + */ |
|
| 177 | 177 | public static function duration2string($datefrom, $dateto = -1) : string |
| 178 | 178 | { |
| 179 | - $converter = new ConvertHelper_DurationConverter(); |
|
| 179 | + $converter = new ConvertHelper_DurationConverter(); |
|
| 180 | 180 | |
| 181 | - if($datefrom instanceof \DateTime) |
|
| 182 | - { |
|
| 183 | - $converter->setDateFrom($datefrom); |
|
| 184 | - } |
|
| 185 | - else |
|
| 186 | - { |
|
| 187 | - $converter->setDateFrom(self::timestamp2date($datefrom)); |
|
| 188 | - } |
|
| 181 | + if($datefrom instanceof \DateTime) |
|
| 182 | + { |
|
| 183 | + $converter->setDateFrom($datefrom); |
|
| 184 | + } |
|
| 185 | + else |
|
| 186 | + { |
|
| 187 | + $converter->setDateFrom(self::timestamp2date($datefrom)); |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - if($dateto instanceof \DateTime) |
|
| 191 | - { |
|
| 192 | - $converter->setDateTo($dateto); |
|
| 193 | - } |
|
| 194 | - else if($dateto > 0) |
|
| 195 | - { |
|
| 196 | - $converter->setDateTo(self::timestamp2date($dateto)); |
|
| 197 | - } |
|
| 190 | + if($dateto instanceof \DateTime) |
|
| 191 | + { |
|
| 192 | + $converter->setDateTo($dateto); |
|
| 193 | + } |
|
| 194 | + else if($dateto > 0) |
|
| 195 | + { |
|
| 196 | + $converter->setDateTo(self::timestamp2date($dateto)); |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - return $converter->convert(); |
|
| 199 | + return $converter->convert(); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -235,44 +235,44 @@ discard block |
||
| 235 | 235 | return $geshi->parse_code(); |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - /** |
|
| 239 | - * Converts a number of bytes to a human readable form, |
|
| 240 | - * e.g. xx Kb / xx Mb / xx Gb |
|
| 241 | - * |
|
| 242 | - * @param int $bytes The amount of bytes to convert. |
|
| 243 | - * @param int $precision The amount of decimals |
|
| 244 | - * @param int $base The base to calculate with: Base 10 is default (=1000 Bytes in a KB), Base 2 is mainly used for Windows memory (=1024 Bytes in a KB). |
|
| 245 | - * @return string |
|
| 246 | - * |
|
| 247 | - * @see https://en.m.wikipedia.org/wiki/Megabyte#Definitions |
|
| 248 | - */ |
|
| 238 | + /** |
|
| 239 | + * Converts a number of bytes to a human readable form, |
|
| 240 | + * e.g. xx Kb / xx Mb / xx Gb |
|
| 241 | + * |
|
| 242 | + * @param int $bytes The amount of bytes to convert. |
|
| 243 | + * @param int $precision The amount of decimals |
|
| 244 | + * @param int $base The base to calculate with: Base 10 is default (=1000 Bytes in a KB), Base 2 is mainly used for Windows memory (=1024 Bytes in a KB). |
|
| 245 | + * @return string |
|
| 246 | + * |
|
| 247 | + * @see https://en.m.wikipedia.org/wiki/Megabyte#Definitions |
|
| 248 | + */ |
|
| 249 | 249 | public static function bytes2readable(int $bytes, int $precision = 1, int $base = ConvertHelper_StorageSizeEnum::BASE_10) : string |
| 250 | 250 | { |
| 251 | 251 | return self::parseBytes($bytes)->toString($precision, $base); |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - /** |
|
| 255 | - * Parses a number of bytes, and creates a converter instance which |
|
| 256 | - * allows doing common operations with it. |
|
| 257 | - * |
|
| 258 | - * @param int $bytes |
|
| 259 | - * @return ConvertHelper_ByteConverter |
|
| 260 | - */ |
|
| 254 | + /** |
|
| 255 | + * Parses a number of bytes, and creates a converter instance which |
|
| 256 | + * allows doing common operations with it. |
|
| 257 | + * |
|
| 258 | + * @param int $bytes |
|
| 259 | + * @return ConvertHelper_ByteConverter |
|
| 260 | + */ |
|
| 261 | 261 | public static function parseBytes(int $bytes) : ConvertHelper_ByteConverter |
| 262 | 262 | { |
| 263 | 263 | return new ConvertHelper_ByteConverter($bytes); |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - /** |
|
| 267 | - * Cuts a text to the specified length if it is longer than the |
|
| 268 | - * target length. Appends a text to signify it has been cut at |
|
| 269 | - * the end of the string. |
|
| 270 | - * |
|
| 271 | - * @param string $text |
|
| 272 | - * @param int $targetLength |
|
| 273 | - * @param string $append |
|
| 274 | - * @return string |
|
| 275 | - */ |
|
| 266 | + /** |
|
| 267 | + * Cuts a text to the specified length if it is longer than the |
|
| 268 | + * target length. Appends a text to signify it has been cut at |
|
| 269 | + * the end of the string. |
|
| 270 | + * |
|
| 271 | + * @param string $text |
|
| 272 | + * @param int $targetLength |
|
| 273 | + * @param string $append |
|
| 274 | + * @return string |
|
| 275 | + */ |
|
| 276 | 276 | public static function text_cut(string $text, int $targetLength, string $append = '...') : string |
| 277 | 277 | { |
| 278 | 278 | $length = mb_strlen($text); |
@@ -296,14 +296,14 @@ discard block |
||
| 296 | 296 | return $info->toString(); |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - /** |
|
| 300 | - * Pretty print_r. |
|
| 301 | - * |
|
| 302 | - * @param mixed $var The variable to dump. |
|
| 303 | - * @param bool $return Whether to return the dumped code. |
|
| 304 | - * @param bool $html Whether to style the dump as HTML. |
|
| 305 | - * @return string |
|
| 306 | - */ |
|
| 299 | + /** |
|
| 300 | + * Pretty print_r. |
|
| 301 | + * |
|
| 302 | + * @param mixed $var The variable to dump. |
|
| 303 | + * @param bool $return Whether to return the dumped code. |
|
| 304 | + * @param bool $html Whether to style the dump as HTML. |
|
| 305 | + * @return string |
|
| 306 | + */ |
|
| 307 | 307 | public static function print_r($var, bool $return=false, bool $html=true) : string |
| 308 | 308 | { |
| 309 | 309 | $result = parseVariable($var)->enableType()->toString(); |
@@ -333,15 +333,15 @@ discard block |
||
| 333 | 333 | 'no' => false |
| 334 | 334 | ); |
| 335 | 335 | |
| 336 | - /** |
|
| 337 | - * Converts a string, number or boolean value to a boolean value. |
|
| 338 | - * |
|
| 339 | - * @param mixed $string |
|
| 340 | - * @throws ConvertHelper_Exception |
|
| 341 | - * @return bool |
|
| 342 | - * |
|
| 343 | - * @see ConvertHelper::ERROR_INVALID_BOOLEAN_STRING |
|
| 344 | - */ |
|
| 336 | + /** |
|
| 337 | + * Converts a string, number or boolean value to a boolean value. |
|
| 338 | + * |
|
| 339 | + * @param mixed $string |
|
| 340 | + * @throws ConvertHelper_Exception |
|
| 341 | + * @return bool |
|
| 342 | + * |
|
| 343 | + * @see ConvertHelper::ERROR_INVALID_BOOLEAN_STRING |
|
| 344 | + */ |
|
| 345 | 345 | public static function string2bool($string) : bool |
| 346 | 346 | { |
| 347 | 347 | if($string === '' || $string === null || !is_scalar($string)) |
@@ -369,27 +369,27 @@ discard block |
||
| 369 | 369 | ); |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | - /** |
|
| 373 | - * Whether the specified string is a boolean string or boolean value. |
|
| 374 | - * Alias for {@link ConvertHelper::isBoolean()}. |
|
| 375 | - * |
|
| 376 | - * @param mixed $string |
|
| 377 | - * @return bool |
|
| 378 | - * @deprecated |
|
| 379 | - * @see ConvertHelper::isBoolean() |
|
| 380 | - */ |
|
| 372 | + /** |
|
| 373 | + * Whether the specified string is a boolean string or boolean value. |
|
| 374 | + * Alias for {@link ConvertHelper::isBoolean()}. |
|
| 375 | + * |
|
| 376 | + * @param mixed $string |
|
| 377 | + * @return bool |
|
| 378 | + * @deprecated |
|
| 379 | + * @see ConvertHelper::isBoolean() |
|
| 380 | + */ |
|
| 381 | 381 | public static function isBooleanString($string) : bool |
| 382 | 382 | { |
| 383 | 383 | return self::isBoolean($string); |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | - /** |
|
| 387 | - * Alias for the {@\AppUtils\XMLHelper::string2xml()} method. |
|
| 388 | - * |
|
| 389 | - * @param string $text |
|
| 390 | - * @return string |
|
| 391 | - * @deprecated |
|
| 392 | - */ |
|
| 386 | + /** |
|
| 387 | + * Alias for the {@\AppUtils\XMLHelper::string2xml()} method. |
|
| 388 | + * |
|
| 389 | + * @param string $text |
|
| 390 | + * @return string |
|
| 391 | + * @deprecated |
|
| 392 | + */ |
|
| 393 | 393 | public static function text_makeXMLCompliant($text) |
| 394 | 394 | { |
| 395 | 395 | return XMLHelper::string2xml($text); |
@@ -491,13 +491,13 @@ discard block |
||
| 491 | 491 | return $translit->convert($string); |
| 492 | 492 | } |
| 493 | 493 | |
| 494 | - /** |
|
| 495 | - * Retrieves the HEX character codes for all control |
|
| 496 | - * characters that the {@link stripControlCharacters()} |
|
| 497 | - * method will remove. |
|
| 498 | - * |
|
| 499 | - * @return string[] |
|
| 500 | - */ |
|
| 494 | + /** |
|
| 495 | + * Retrieves the HEX character codes for all control |
|
| 496 | + * characters that the {@link stripControlCharacters()} |
|
| 497 | + * method will remove. |
|
| 498 | + * |
|
| 499 | + * @return string[] |
|
| 500 | + */ |
|
| 501 | 501 | public static function getControlCharactersAsHex() |
| 502 | 502 | { |
| 503 | 503 | $hexAlphabet = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
@@ -533,13 +533,13 @@ discard block |
||
| 533 | 533 | return $stack; |
| 534 | 534 | } |
| 535 | 535 | |
| 536 | - /** |
|
| 537 | - * Retrieves an array of all control characters that |
|
| 538 | - * the {@link stripControlCharacters()} method will |
|
| 539 | - * remove, as the actual UTF-8 characters. |
|
| 540 | - * |
|
| 541 | - * @return string[] |
|
| 542 | - */ |
|
| 536 | + /** |
|
| 537 | + * Retrieves an array of all control characters that |
|
| 538 | + * the {@link stripControlCharacters()} method will |
|
| 539 | + * remove, as the actual UTF-8 characters. |
|
| 540 | + * |
|
| 541 | + * @return string[] |
|
| 542 | + */ |
|
| 543 | 543 | public static function getControlCharactersAsUTF8() |
| 544 | 544 | { |
| 545 | 545 | $chars = self::getControlCharactersAsHex(); |
@@ -552,12 +552,12 @@ discard block |
||
| 552 | 552 | return $result; |
| 553 | 553 | } |
| 554 | 554 | |
| 555 | - /** |
|
| 556 | - * Retrieves all control characters as JSON encoded |
|
| 557 | - * characters, e.g. "\u200b". |
|
| 558 | - * |
|
| 559 | - * @return string[] |
|
| 560 | - */ |
|
| 555 | + /** |
|
| 556 | + * Retrieves all control characters as JSON encoded |
|
| 557 | + * characters, e.g. "\u200b". |
|
| 558 | + * |
|
| 559 | + * @return string[] |
|
| 560 | + */ |
|
| 561 | 561 | public static function getControlCharactersAsJSON() |
| 562 | 562 | { |
| 563 | 563 | $chars = self::getControlCharactersAsHex(); |
@@ -614,20 +614,20 @@ discard block |
||
| 614 | 614 | return preg_replace(self::$controlCharsRegex, '', $string); |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | - /** |
|
| 618 | - * Converts a unicode character to the PHPO notation. |
|
| 619 | - * |
|
| 620 | - * Example: |
|
| 621 | - * |
|
| 622 | - * <pre>unicodeChar2php('"\u0000"')</pre> |
|
| 623 | - * |
|
| 624 | - * Returns |
|
| 625 | - * |
|
| 626 | - * <pre>\x0</pre> |
|
| 627 | - * |
|
| 628 | - * @param string $unicodeChar |
|
| 629 | - * @return string |
|
| 630 | - */ |
|
| 617 | + /** |
|
| 618 | + * Converts a unicode character to the PHPO notation. |
|
| 619 | + * |
|
| 620 | + * Example: |
|
| 621 | + * |
|
| 622 | + * <pre>unicodeChar2php('"\u0000"')</pre> |
|
| 623 | + * |
|
| 624 | + * Returns |
|
| 625 | + * |
|
| 626 | + * <pre>\x0</pre> |
|
| 627 | + * |
|
| 628 | + * @param string $unicodeChar |
|
| 629 | + * @return string |
|
| 630 | + */ |
|
| 631 | 631 | public static function unicodeChar2php(string $unicodeChar) : string |
| 632 | 632 | { |
| 633 | 633 | $unicodeChar = json_decode($unicodeChar); |
@@ -753,25 +753,25 @@ discard block |
||
| 753 | 753 | return 'false'; |
| 754 | 754 | } |
| 755 | 755 | |
| 756 | - /** |
|
| 757 | - * Converts an associative array with attribute name > value pairs |
|
| 758 | - * to an attribute string that can be used in an HTML tag. Empty |
|
| 759 | - * attribute values are ignored. |
|
| 760 | - * |
|
| 761 | - * Example: |
|
| 762 | - * |
|
| 763 | - * array2attributeString(array( |
|
| 764 | - * 'id' => 45, |
|
| 765 | - * 'href' => 'http://www.mistralys.com' |
|
| 766 | - * )); |
|
| 767 | - * |
|
| 768 | - * Result: |
|
| 769 | - * |
|
| 770 | - * id="45" href="http://www.mistralys.com" |
|
| 771 | - * |
|
| 772 | - * @param array $array |
|
| 773 | - * @return string |
|
| 774 | - */ |
|
| 756 | + /** |
|
| 757 | + * Converts an associative array with attribute name > value pairs |
|
| 758 | + * to an attribute string that can be used in an HTML tag. Empty |
|
| 759 | + * attribute values are ignored. |
|
| 760 | + * |
|
| 761 | + * Example: |
|
| 762 | + * |
|
| 763 | + * array2attributeString(array( |
|
| 764 | + * 'id' => 45, |
|
| 765 | + * 'href' => 'http://www.mistralys.com' |
|
| 766 | + * )); |
|
| 767 | + * |
|
| 768 | + * Result: |
|
| 769 | + * |
|
| 770 | + * id="45" href="http://www.mistralys.com" |
|
| 771 | + * |
|
| 772 | + * @param array $array |
|
| 773 | + * @return string |
|
| 774 | + */ |
|
| 775 | 775 | public static function array2attributeString($array) |
| 776 | 776 | { |
| 777 | 777 | $tokens = array(); |
@@ -790,14 +790,14 @@ discard block |
||
| 790 | 790 | return ' '.implode(' ', $tokens); |
| 791 | 791 | } |
| 792 | 792 | |
| 793 | - /** |
|
| 794 | - * Converts a string so it can safely be used in a javascript |
|
| 795 | - * statement in an HTML tag: uses single quotes around the string |
|
| 796 | - * and encodes all special characters as needed. |
|
| 797 | - * |
|
| 798 | - * @param string $string |
|
| 799 | - * @return string |
|
| 800 | - */ |
|
| 793 | + /** |
|
| 794 | + * Converts a string so it can safely be used in a javascript |
|
| 795 | + * statement in an HTML tag: uses single quotes around the string |
|
| 796 | + * and encodes all special characters as needed. |
|
| 797 | + * |
|
| 798 | + * @param string $string |
|
| 799 | + * @return string |
|
| 800 | + */ |
|
| 801 | 801 | public static function string2attributeJS($string, $quoted=true) |
| 802 | 802 | { |
| 803 | 803 | $converted = addslashes(htmlspecialchars(strip_tags($string), ENT_QUOTES, 'UTF-8')); |
@@ -808,15 +808,15 @@ discard block |
||
| 808 | 808 | return $converted; |
| 809 | 809 | } |
| 810 | 810 | |
| 811 | - /** |
|
| 812 | - * Checks if the specified string is a boolean value, which |
|
| 813 | - * includes string representations of boolean values, like |
|
| 814 | - * <code>yes</code> or <code>no</code>, and <code>true</code> |
|
| 815 | - * or <code>false</code>. |
|
| 816 | - * |
|
| 817 | - * @param mixed $value |
|
| 818 | - * @return boolean |
|
| 819 | - */ |
|
| 811 | + /** |
|
| 812 | + * Checks if the specified string is a boolean value, which |
|
| 813 | + * includes string representations of boolean values, like |
|
| 814 | + * <code>yes</code> or <code>no</code>, and <code>true</code> |
|
| 815 | + * or <code>false</code>. |
|
| 816 | + * |
|
| 817 | + * @param mixed $value |
|
| 818 | + * @return boolean |
|
| 819 | + */ |
|
| 820 | 820 | public static function isBoolean($value) : bool |
| 821 | 821 | { |
| 822 | 822 | if(is_bool($value)) { |
@@ -830,12 +830,12 @@ discard block |
||
| 830 | 830 | return array_key_exists($value, self::$booleanStrings); |
| 831 | 831 | } |
| 832 | 832 | |
| 833 | - /** |
|
| 834 | - * Converts an associative array to an HTML style attribute value string. |
|
| 835 | - * |
|
| 836 | - * @param array $subject |
|
| 837 | - * @return string |
|
| 838 | - */ |
|
| 833 | + /** |
|
| 834 | + * Converts an associative array to an HTML style attribute value string. |
|
| 835 | + * |
|
| 836 | + * @param array $subject |
|
| 837 | + * @return string |
|
| 838 | + */ |
|
| 839 | 839 | public static function array2styleString(array $subject) : string |
| 840 | 840 | { |
| 841 | 841 | $tokens = array(); |
@@ -846,23 +846,23 @@ discard block |
||
| 846 | 846 | return implode(';', $tokens); |
| 847 | 847 | } |
| 848 | 848 | |
| 849 | - /** |
|
| 850 | - * Converts a DateTime object to a timestamp, which |
|
| 851 | - * is PHP 5.2 compatible. |
|
| 852 | - * |
|
| 853 | - * @param \DateTime $date |
|
| 854 | - * @return integer |
|
| 855 | - */ |
|
| 849 | + /** |
|
| 850 | + * Converts a DateTime object to a timestamp, which |
|
| 851 | + * is PHP 5.2 compatible. |
|
| 852 | + * |
|
| 853 | + * @param \DateTime $date |
|
| 854 | + * @return integer |
|
| 855 | + */ |
|
| 856 | 856 | public static function date2timestamp(\DateTime $date) : int |
| 857 | 857 | { |
| 858 | 858 | return (int)$date->format('U'); |
| 859 | 859 | } |
| 860 | 860 | |
| 861 | - /** |
|
| 862 | - * Converts a timestamp into a DateTime instance. |
|
| 863 | - * @param int $timestamp |
|
| 864 | - * @return \DateTime |
|
| 865 | - */ |
|
| 861 | + /** |
|
| 862 | + * Converts a timestamp into a DateTime instance. |
|
| 863 | + * @param int $timestamp |
|
| 864 | + * @return \DateTime |
|
| 865 | + */ |
|
| 866 | 866 | public static function timestamp2date(int $timestamp) : \DateTime |
| 867 | 867 | { |
| 868 | 868 | $date = new \DateTime(); |
@@ -870,50 +870,50 @@ discard block |
||
| 870 | 870 | return $date; |
| 871 | 871 | } |
| 872 | 872 | |
| 873 | - /** |
|
| 874 | - * Strips an absolute path to a file within the application |
|
| 875 | - * to make the path relative to the application root path. |
|
| 876 | - * |
|
| 877 | - * @param string $path |
|
| 878 | - * @return string |
|
| 879 | - * |
|
| 880 | - * @see FileHelper::relativizePath() |
|
| 881 | - * @see FileHelper::relativizePathByDepth() |
|
| 882 | - */ |
|
| 873 | + /** |
|
| 874 | + * Strips an absolute path to a file within the application |
|
| 875 | + * to make the path relative to the application root path. |
|
| 876 | + * |
|
| 877 | + * @param string $path |
|
| 878 | + * @return string |
|
| 879 | + * |
|
| 880 | + * @see FileHelper::relativizePath() |
|
| 881 | + * @see FileHelper::relativizePathByDepth() |
|
| 882 | + */ |
|
| 883 | 883 | public static function fileRelativize(string $path) : string |
| 884 | 884 | { |
| 885 | 885 | return FileHelper::relativizePathByDepth($path); |
| 886 | 886 | } |
| 887 | 887 | |
| 888 | 888 | /** |
| 889 | - * Converts a PHP regex to a javascript RegExp object statement. |
|
| 890 | - * |
|
| 891 | - * NOTE: This is an alias for the JSHelper's `convertRegex` method. |
|
| 892 | - * More details are available on its usage there. |
|
| 893 | - * |
|
| 894 | - * @param string $regex A PHP preg regex |
|
| 895 | - * @param string $statementType The type of statement to return: Defaults to a statement to create a RegExp object. |
|
| 896 | - * @return array|string Depending on the specified return type. |
|
| 897 | - * |
|
| 898 | - * @see JSHelper::buildRegexStatement() |
|
| 899 | - */ |
|
| 889 | + * Converts a PHP regex to a javascript RegExp object statement. |
|
| 890 | + * |
|
| 891 | + * NOTE: This is an alias for the JSHelper's `convertRegex` method. |
|
| 892 | + * More details are available on its usage there. |
|
| 893 | + * |
|
| 894 | + * @param string $regex A PHP preg regex |
|
| 895 | + * @param string $statementType The type of statement to return: Defaults to a statement to create a RegExp object. |
|
| 896 | + * @return array|string Depending on the specified return type. |
|
| 897 | + * |
|
| 898 | + * @see JSHelper::buildRegexStatement() |
|
| 899 | + */ |
|
| 900 | 900 | public static function regex2js(string $regex, string $statementType=JSHelper::JS_REGEX_OBJECT) |
| 901 | 901 | { |
| 902 | 902 | return JSHelper::buildRegexStatement($regex, $statementType); |
| 903 | 903 | } |
| 904 | 904 | |
| 905 | - /** |
|
| 906 | - * Converts the specified variable to JSON. Works just |
|
| 907 | - * like the native `json_encode` method, except that it |
|
| 908 | - * will trigger an exception on failure, which has the |
|
| 909 | - * json error details included in its developer details. |
|
| 910 | - * |
|
| 911 | - * @param mixed $variable |
|
| 912 | - * @param int $options JSON encode options. |
|
| 913 | - * @param int $depth |
|
| 914 | - * @throws ConvertHelper_Exception |
|
| 915 | - * @return string |
|
| 916 | - */ |
|
| 905 | + /** |
|
| 906 | + * Converts the specified variable to JSON. Works just |
|
| 907 | + * like the native `json_encode` method, except that it |
|
| 908 | + * will trigger an exception on failure, which has the |
|
| 909 | + * json error details included in its developer details. |
|
| 910 | + * |
|
| 911 | + * @param mixed $variable |
|
| 912 | + * @param int $options JSON encode options. |
|
| 913 | + * @param int $depth |
|
| 914 | + * @throws ConvertHelper_Exception |
|
| 915 | + * @return string |
|
| 916 | + */ |
|
| 917 | 917 | public static function var2json($variable, int $options=0, int $depth=512) : string |
| 918 | 918 | { |
| 919 | 919 | $result = json_encode($variable, $options, $depth); |
@@ -934,12 +934,12 @@ discard block |
||
| 934 | 934 | ); |
| 935 | 935 | } |
| 936 | 936 | |
| 937 | - /** |
|
| 938 | - * Strips all known UTF byte order marks from the specified string. |
|
| 939 | - * |
|
| 940 | - * @param string $string |
|
| 941 | - * @return string |
|
| 942 | - */ |
|
| 937 | + /** |
|
| 938 | + * Strips all known UTF byte order marks from the specified string. |
|
| 939 | + * |
|
| 940 | + * @param string $string |
|
| 941 | + * @return string |
|
| 942 | + */ |
|
| 943 | 943 | public static function stripUTFBom($string) |
| 944 | 944 | { |
| 945 | 945 | $boms = FileHelper::getUTFBOMs(); |
@@ -954,13 +954,13 @@ discard block |
||
| 954 | 954 | return $string; |
| 955 | 955 | } |
| 956 | 956 | |
| 957 | - /** |
|
| 958 | - * Converts a string to valid utf8, regardless |
|
| 959 | - * of the string's encoding(s). |
|
| 960 | - * |
|
| 961 | - * @param string $string |
|
| 962 | - * @return string |
|
| 963 | - */ |
|
| 957 | + /** |
|
| 958 | + * Converts a string to valid utf8, regardless |
|
| 959 | + * of the string's encoding(s). |
|
| 960 | + * |
|
| 961 | + * @param string $string |
|
| 962 | + * @return string |
|
| 963 | + */ |
|
| 964 | 964 | public static function string2utf8($string) |
| 965 | 965 | { |
| 966 | 966 | if(!self::isStringASCII($string)) { |
@@ -970,15 +970,15 @@ discard block |
||
| 970 | 970 | return $string; |
| 971 | 971 | } |
| 972 | 972 | |
| 973 | - /** |
|
| 974 | - * Checks whether the specified string is an ASCII |
|
| 975 | - * string, without any special or UTF8 characters. |
|
| 976 | - * Note: empty strings and NULL are considered ASCII. |
|
| 977 | - * Any variable types other than strings are not. |
|
| 978 | - * |
|
| 979 | - * @param mixed $string |
|
| 980 | - * @return boolean |
|
| 981 | - */ |
|
| 973 | + /** |
|
| 974 | + * Checks whether the specified string is an ASCII |
|
| 975 | + * string, without any special or UTF8 characters. |
|
| 976 | + * Note: empty strings and NULL are considered ASCII. |
|
| 977 | + * Any variable types other than strings are not. |
|
| 978 | + * |
|
| 979 | + * @param mixed $string |
|
| 980 | + * @return boolean |
|
| 981 | + */ |
|
| 982 | 982 | public static function isStringASCII($string) : bool |
| 983 | 983 | { |
| 984 | 984 | if($string === '' || $string === NULL) { |
@@ -1003,22 +1003,22 @@ discard block |
||
| 1003 | 1003 | return $url; |
| 1004 | 1004 | } |
| 1005 | 1005 | |
| 1006 | - /** |
|
| 1007 | - * Calculates a percentage match of the source string with the target string. |
|
| 1008 | - * |
|
| 1009 | - * Options are: |
|
| 1010 | - * |
|
| 1011 | - * - maxLevenshtein, default: 10 |
|
| 1012 | - * Any levenshtein results above this value are ignored. |
|
| 1013 | - * |
|
| 1014 | - * - precision, default: 1 |
|
| 1015 | - * The precision of the percentage float value |
|
| 1016 | - * |
|
| 1017 | - * @param string $source |
|
| 1018 | - * @param string $target |
|
| 1019 | - * @param array $options |
|
| 1020 | - * @return float |
|
| 1021 | - */ |
|
| 1006 | + /** |
|
| 1007 | + * Calculates a percentage match of the source string with the target string. |
|
| 1008 | + * |
|
| 1009 | + * Options are: |
|
| 1010 | + * |
|
| 1011 | + * - maxLevenshtein, default: 10 |
|
| 1012 | + * Any levenshtein results above this value are ignored. |
|
| 1013 | + * |
|
| 1014 | + * - precision, default: 1 |
|
| 1015 | + * The precision of the percentage float value |
|
| 1016 | + * |
|
| 1017 | + * @param string $source |
|
| 1018 | + * @param string $target |
|
| 1019 | + * @param array $options |
|
| 1020 | + * @return float |
|
| 1021 | + */ |
|
| 1022 | 1022 | public static function matchString($source, $target, $options=array()) |
| 1023 | 1023 | { |
| 1024 | 1024 | $defaults = array( |
@@ -1042,14 +1042,14 @@ discard block |
||
| 1042 | 1042 | return round(100 - $percent, $options['precision']); |
| 1043 | 1043 | } |
| 1044 | 1044 | |
| 1045 | - /** |
|
| 1046 | - * Converts a date interval to a human readable string with |
|
| 1047 | - * all necessary time components, e.g. "1 year, 2 months and 4 days". |
|
| 1048 | - * |
|
| 1049 | - * @param \DateInterval $interval |
|
| 1050 | - * @return string |
|
| 1051 | - * @see ConvertHelper_IntervalConverter |
|
| 1052 | - */ |
|
| 1045 | + /** |
|
| 1046 | + * Converts a date interval to a human readable string with |
|
| 1047 | + * all necessary time components, e.g. "1 year, 2 months and 4 days". |
|
| 1048 | + * |
|
| 1049 | + * @param \DateInterval $interval |
|
| 1050 | + * @return string |
|
| 1051 | + * @see ConvertHelper_IntervalConverter |
|
| 1052 | + */ |
|
| 1053 | 1053 | public static function interval2string(\DateInterval $interval) : string |
| 1054 | 1054 | { |
| 1055 | 1055 | $converter = new ConvertHelper_IntervalConverter(); |
@@ -1064,60 +1064,60 @@ discard block |
||
| 1064 | 1064 | |
| 1065 | 1065 | const INTERVAL_SECONDS = 'seconds'; |
| 1066 | 1066 | |
| 1067 | - /** |
|
| 1068 | - * Converts an interval to its total amount of days. |
|
| 1069 | - * @param \DateInterval $interval |
|
| 1070 | - * @return int |
|
| 1071 | - */ |
|
| 1067 | + /** |
|
| 1068 | + * Converts an interval to its total amount of days. |
|
| 1069 | + * @param \DateInterval $interval |
|
| 1070 | + * @return int |
|
| 1071 | + */ |
|
| 1072 | 1072 | public static function interval2days(\DateInterval $interval) : int |
| 1073 | 1073 | { |
| 1074 | 1074 | return self::interval2total($interval, self::INTERVAL_DAYS); |
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | - /** |
|
| 1078 | - * Converts an interval to its total amount of hours. |
|
| 1079 | - * @param \DateInterval $interval |
|
| 1080 | - * @return int |
|
| 1081 | - */ |
|
| 1077 | + /** |
|
| 1078 | + * Converts an interval to its total amount of hours. |
|
| 1079 | + * @param \DateInterval $interval |
|
| 1080 | + * @return int |
|
| 1081 | + */ |
|
| 1082 | 1082 | public static function interval2hours(\DateInterval $interval) : int |
| 1083 | 1083 | { |
| 1084 | 1084 | return self::interval2total($interval, self::INTERVAL_HOURS); |
| 1085 | 1085 | } |
| 1086 | 1086 | |
| 1087 | - /** |
|
| 1088 | - * Converts an interval to its total amount of minutes. |
|
| 1089 | - * @param \DateInterval $interval |
|
| 1090 | - * @return int |
|
| 1091 | - */ |
|
| 1087 | + /** |
|
| 1088 | + * Converts an interval to its total amount of minutes. |
|
| 1089 | + * @param \DateInterval $interval |
|
| 1090 | + * @return int |
|
| 1091 | + */ |
|
| 1092 | 1092 | public static function interval2minutes(\DateInterval $interval) : int |
| 1093 | 1093 | { |
| 1094 | 1094 | return self::interval2total($interval, self::INTERVAL_MINUTES); |
| 1095 | 1095 | } |
| 1096 | 1096 | |
| 1097 | - /** |
|
| 1098 | - * Converts an interval to its total amount of seconds. |
|
| 1099 | - * @param \DateInterval $interval |
|
| 1100 | - * @return int |
|
| 1101 | - */ |
|
| 1097 | + /** |
|
| 1098 | + * Converts an interval to its total amount of seconds. |
|
| 1099 | + * @param \DateInterval $interval |
|
| 1100 | + * @return int |
|
| 1101 | + */ |
|
| 1102 | 1102 | public static function interval2seconds(\DateInterval $interval) : int |
| 1103 | 1103 | { |
| 1104 | 1104 | return self::interval2total($interval, self::INTERVAL_SECONDS); |
| 1105 | 1105 | } |
| 1106 | 1106 | |
| 1107 | - /** |
|
| 1108 | - * Calculates the total amount of days / hours / minutes or seconds |
|
| 1109 | - * of a date interval object (depending in the specified units), and |
|
| 1110 | - * returns the total amount. |
|
| 1111 | - * |
|
| 1112 | - * @param \DateInterval $interval |
|
| 1113 | - * @param string $unit What total value to calculate. |
|
| 1114 | - * @return integer |
|
| 1115 | - * |
|
| 1116 | - * @see ConvertHelper::INTERVAL_SECONDS |
|
| 1117 | - * @see ConvertHelper::INTERVAL_MINUTES |
|
| 1118 | - * @see ConvertHelper::INTERVAL_HOURS |
|
| 1119 | - * @see ConvertHelper::INTERVAL_DAYS |
|
| 1120 | - */ |
|
| 1107 | + /** |
|
| 1108 | + * Calculates the total amount of days / hours / minutes or seconds |
|
| 1109 | + * of a date interval object (depending in the specified units), and |
|
| 1110 | + * returns the total amount. |
|
| 1111 | + * |
|
| 1112 | + * @param \DateInterval $interval |
|
| 1113 | + * @param string $unit What total value to calculate. |
|
| 1114 | + * @return integer |
|
| 1115 | + * |
|
| 1116 | + * @see ConvertHelper::INTERVAL_SECONDS |
|
| 1117 | + * @see ConvertHelper::INTERVAL_MINUTES |
|
| 1118 | + * @see ConvertHelper::INTERVAL_HOURS |
|
| 1119 | + * @see ConvertHelper::INTERVAL_DAYS |
|
| 1120 | + */ |
|
| 1121 | 1121 | public static function interval2total(\DateInterval $interval, $unit=self::INTERVAL_SECONDS) : int |
| 1122 | 1122 | { |
| 1123 | 1123 | $total = (int)$interval->format('%a'); |
@@ -1157,13 +1157,13 @@ discard block |
||
| 1157 | 1157 | 'Sunday' |
| 1158 | 1158 | ); |
| 1159 | 1159 | |
| 1160 | - /** |
|
| 1161 | - * Converts a date to the corresponding day name. |
|
| 1162 | - * |
|
| 1163 | - * @param \DateTime $date |
|
| 1164 | - * @param bool $short |
|
| 1165 | - * @return string|NULL |
|
| 1166 | - */ |
|
| 1160 | + /** |
|
| 1161 | + * Converts a date to the corresponding day name. |
|
| 1162 | + * |
|
| 1163 | + * @param \DateTime $date |
|
| 1164 | + * @param bool $short |
|
| 1165 | + * @return string|NULL |
|
| 1166 | + */ |
|
| 1167 | 1167 | public static function date2dayName(\DateTime $date, bool $short=false) |
| 1168 | 1168 | { |
| 1169 | 1169 | $day = $date->format('l'); |
@@ -1178,21 +1178,21 @@ discard block |
||
| 1178 | 1178 | return null; |
| 1179 | 1179 | } |
| 1180 | 1180 | |
| 1181 | - /** |
|
| 1182 | - * Retrieves a list of english day names. |
|
| 1183 | - * @return string[] |
|
| 1184 | - */ |
|
| 1181 | + /** |
|
| 1182 | + * Retrieves a list of english day names. |
|
| 1183 | + * @return string[] |
|
| 1184 | + */ |
|
| 1185 | 1185 | public static function getDayNamesInvariant() |
| 1186 | 1186 | { |
| 1187 | 1187 | return self::$daysInvariant; |
| 1188 | 1188 | } |
| 1189 | 1189 | |
| 1190 | - /** |
|
| 1191 | - * Retrieves the day names list for the current locale. |
|
| 1192 | - * |
|
| 1193 | - * @param bool $short |
|
| 1194 | - * @return array |
|
| 1195 | - */ |
|
| 1190 | + /** |
|
| 1191 | + * Retrieves the day names list for the current locale. |
|
| 1192 | + * |
|
| 1193 | + * @param bool $short |
|
| 1194 | + * @return array |
|
| 1195 | + */ |
|
| 1196 | 1196 | public static function getDayNames(bool $short=false) : array |
| 1197 | 1197 | { |
| 1198 | 1198 | if($short) { |
@@ -1252,16 +1252,16 @@ discard block |
||
| 1252 | 1252 | return $last; |
| 1253 | 1253 | } |
| 1254 | 1254 | |
| 1255 | - /** |
|
| 1256 | - * Splits a string into an array of all characters it is composed of. |
|
| 1257 | - * Unicode character safe. |
|
| 1258 | - * |
|
| 1259 | - * NOTE: Spaces and newlines (both \r and \n) are also considered single |
|
| 1260 | - * characters. |
|
| 1261 | - * |
|
| 1262 | - * @param string $string |
|
| 1263 | - * @return array |
|
| 1264 | - */ |
|
| 1255 | + /** |
|
| 1256 | + * Splits a string into an array of all characters it is composed of. |
|
| 1257 | + * Unicode character safe. |
|
| 1258 | + * |
|
| 1259 | + * NOTE: Spaces and newlines (both \r and \n) are also considered single |
|
| 1260 | + * characters. |
|
| 1261 | + * |
|
| 1262 | + * @param string $string |
|
| 1263 | + * @return array |
|
| 1264 | + */ |
|
| 1265 | 1265 | public static function string2array(string $string) : array |
| 1266 | 1266 | { |
| 1267 | 1267 | $result = preg_split('//u', $string, null, PREG_SPLIT_NO_EMPTY); |
@@ -1272,12 +1272,12 @@ discard block |
||
| 1272 | 1272 | return array(); |
| 1273 | 1273 | } |
| 1274 | 1274 | |
| 1275 | - /** |
|
| 1276 | - * Checks whether the specified string contains HTML code. |
|
| 1277 | - * |
|
| 1278 | - * @param string $string |
|
| 1279 | - * @return boolean |
|
| 1280 | - */ |
|
| 1275 | + /** |
|
| 1276 | + * Checks whether the specified string contains HTML code. |
|
| 1277 | + * |
|
| 1278 | + * @param string $string |
|
| 1279 | + * @return boolean |
|
| 1280 | + */ |
|
| 1281 | 1281 | public static function isStringHTML(string $string) : bool |
| 1282 | 1282 | { |
| 1283 | 1283 | if(preg_match('%<[a-z/][\s\S]*>%siU', $string)) { |
@@ -1292,17 +1292,17 @@ discard block |
||
| 1292 | 1292 | return false; |
| 1293 | 1293 | } |
| 1294 | 1294 | |
| 1295 | - /** |
|
| 1296 | - * UTF8-safe wordwrap method: works like the regular wordwrap |
|
| 1297 | - * PHP function but compatible with UTF8. Otherwise the lengths |
|
| 1298 | - * are not calculated correctly. |
|
| 1299 | - * |
|
| 1300 | - * @param string $str |
|
| 1301 | - * @param int $width |
|
| 1302 | - * @param string $break |
|
| 1303 | - * @param bool $cut |
|
| 1304 | - * @return string |
|
| 1305 | - */ |
|
| 1295 | + /** |
|
| 1296 | + * UTF8-safe wordwrap method: works like the regular wordwrap |
|
| 1297 | + * PHP function but compatible with UTF8. Otherwise the lengths |
|
| 1298 | + * are not calculated correctly. |
|
| 1299 | + * |
|
| 1300 | + * @param string $str |
|
| 1301 | + * @param int $width |
|
| 1302 | + * @param string $break |
|
| 1303 | + * @param bool $cut |
|
| 1304 | + * @return string |
|
| 1305 | + */ |
|
| 1306 | 1306 | public static function wordwrap(string $str, int $width = 75, string $break = "\n", bool $cut = false) : string |
| 1307 | 1307 | { |
| 1308 | 1308 | $wrapper = new ConvertHelper_WordWrapper(); |
@@ -1314,27 +1314,27 @@ discard block |
||
| 1314 | 1314 | ->wrapText($str); |
| 1315 | 1315 | } |
| 1316 | 1316 | |
| 1317 | - /** |
|
| 1318 | - * Calculates the byte length of a string, taking into |
|
| 1319 | - * account any unicode characters. |
|
| 1320 | - * |
|
| 1321 | - * @param string $string |
|
| 1322 | - * @return int |
|
| 1323 | - * @see https://stackoverflow.com/a/9718273/2298192 |
|
| 1324 | - */ |
|
| 1317 | + /** |
|
| 1318 | + * Calculates the byte length of a string, taking into |
|
| 1319 | + * account any unicode characters. |
|
| 1320 | + * |
|
| 1321 | + * @param string $string |
|
| 1322 | + * @return int |
|
| 1323 | + * @see https://stackoverflow.com/a/9718273/2298192 |
|
| 1324 | + */ |
|
| 1325 | 1325 | public static function string2bytes($string) |
| 1326 | 1326 | { |
| 1327 | 1327 | return mb_strlen($string, '8bit'); |
| 1328 | 1328 | } |
| 1329 | 1329 | |
| 1330 | - /** |
|
| 1331 | - * Creates a short, 8-character long hash for the specified string. |
|
| 1332 | - * |
|
| 1333 | - * WARNING: Not cryptographically safe. |
|
| 1334 | - * |
|
| 1335 | - * @param string $string |
|
| 1336 | - * @return string |
|
| 1337 | - */ |
|
| 1330 | + /** |
|
| 1331 | + * Creates a short, 8-character long hash for the specified string. |
|
| 1332 | + * |
|
| 1333 | + * WARNING: Not cryptographically safe. |
|
| 1334 | + * |
|
| 1335 | + * @param string $string |
|
| 1336 | + * @return string |
|
| 1337 | + */ |
|
| 1338 | 1338 | public static function string2shortHash($string) |
| 1339 | 1339 | { |
| 1340 | 1340 | return hash('crc32', $string, false); |
@@ -1360,40 +1360,40 @@ discard block |
||
| 1360 | 1360 | return ConvertHelper_ThrowableInfo::fromThrowable($e); |
| 1361 | 1361 | } |
| 1362 | 1362 | |
| 1363 | - /** |
|
| 1364 | - * Parses the specified query string like the native |
|
| 1365 | - * function <code>parse_str</code>, without the key |
|
| 1366 | - * naming limitations. |
|
| 1367 | - * |
|
| 1368 | - * Using parse_str, dots or spaces in key names are |
|
| 1369 | - * replaced by underscores. This method keeps all names |
|
| 1370 | - * intact. |
|
| 1371 | - * |
|
| 1372 | - * It still uses the parse_str implementation as it |
|
| 1373 | - * is tested and tried, but fixes the parameter names |
|
| 1374 | - * after parsing, as needed. |
|
| 1375 | - * |
|
| 1376 | - * @param string $queryString |
|
| 1377 | - * @return array |
|
| 1378 | - * @see ConvertHelper_QueryParser |
|
| 1379 | - */ |
|
| 1363 | + /** |
|
| 1364 | + * Parses the specified query string like the native |
|
| 1365 | + * function <code>parse_str</code>, without the key |
|
| 1366 | + * naming limitations. |
|
| 1367 | + * |
|
| 1368 | + * Using parse_str, dots or spaces in key names are |
|
| 1369 | + * replaced by underscores. This method keeps all names |
|
| 1370 | + * intact. |
|
| 1371 | + * |
|
| 1372 | + * It still uses the parse_str implementation as it |
|
| 1373 | + * is tested and tried, but fixes the parameter names |
|
| 1374 | + * after parsing, as needed. |
|
| 1375 | + * |
|
| 1376 | + * @param string $queryString |
|
| 1377 | + * @return array |
|
| 1378 | + * @see ConvertHelper_QueryParser |
|
| 1379 | + */ |
|
| 1380 | 1380 | public static function parseQueryString(string $queryString) : array |
| 1381 | 1381 | { |
| 1382 | 1382 | $parser = new ConvertHelper_QueryParser(); |
| 1383 | 1383 | return $parser->parse($queryString); |
| 1384 | 1384 | } |
| 1385 | 1385 | |
| 1386 | - /** |
|
| 1387 | - * Searches for needle in the specified string, and returns a list |
|
| 1388 | - * of all occurrences, including the matched string. The matched |
|
| 1389 | - * string is useful when doing a case insensitive search, as it |
|
| 1390 | - * shows the exact matched case of needle. |
|
| 1391 | - * |
|
| 1392 | - * @param string $needle |
|
| 1393 | - * @param string $haystack |
|
| 1394 | - * @param bool $caseInsensitive |
|
| 1395 | - * @return ConvertHelper_StringMatch[] |
|
| 1396 | - */ |
|
| 1386 | + /** |
|
| 1387 | + * Searches for needle in the specified string, and returns a list |
|
| 1388 | + * of all occurrences, including the matched string. The matched |
|
| 1389 | + * string is useful when doing a case insensitive search, as it |
|
| 1390 | + * shows the exact matched case of needle. |
|
| 1391 | + * |
|
| 1392 | + * @param string $needle |
|
| 1393 | + * @param string $haystack |
|
| 1394 | + * @param bool $caseInsensitive |
|
| 1395 | + * @return ConvertHelper_StringMatch[] |
|
| 1396 | + */ |
|
| 1397 | 1397 | public static function findString(string $needle, string $haystack, bool $caseInsensitive=false) |
| 1398 | 1398 | { |
| 1399 | 1399 | if($needle === '') { |
@@ -1419,14 +1419,14 @@ discard block |
||
| 1419 | 1419 | return $positions; |
| 1420 | 1420 | } |
| 1421 | 1421 | |
| 1422 | - /** |
|
| 1423 | - * Like explode, but trims all entries, and removes |
|
| 1424 | - * empty entries from the resulting array. |
|
| 1425 | - * |
|
| 1426 | - * @param string $delimiter |
|
| 1427 | - * @param string $string |
|
| 1428 | - * @return string[] |
|
| 1429 | - */ |
|
| 1422 | + /** |
|
| 1423 | + * Like explode, but trims all entries, and removes |
|
| 1424 | + * empty entries from the resulting array. |
|
| 1425 | + * |
|
| 1426 | + * @param string $delimiter |
|
| 1427 | + * @param string $string |
|
| 1428 | + * @return string[] |
|
| 1429 | + */ |
|
| 1430 | 1430 | public static function explodeTrim(string $delimiter, string $string) : array |
| 1431 | 1431 | { |
| 1432 | 1432 | if(empty($string) || empty($delimiter)) { |
@@ -1448,12 +1448,12 @@ discard block |
||
| 1448 | 1448 | |
| 1449 | 1449 | protected static $eolChars; |
| 1450 | 1450 | |
| 1451 | - /** |
|
| 1452 | - * Detects the most used end-of-line character in the subject string. |
|
| 1453 | - * |
|
| 1454 | - * @param string $subjectString The string to check. |
|
| 1455 | - * @return NULL|ConvertHelper_EOL The detected EOL instance, or NULL if none has been detected. |
|
| 1456 | - */ |
|
| 1451 | + /** |
|
| 1452 | + * Detects the most used end-of-line character in the subject string. |
|
| 1453 | + * |
|
| 1454 | + * @param string $subjectString The string to check. |
|
| 1455 | + * @return NULL|ConvertHelper_EOL The detected EOL instance, or NULL if none has been detected. |
|
| 1456 | + */ |
|
| 1457 | 1457 | public static function detectEOLCharacter(string $subjectString) : ?ConvertHelper_EOL |
| 1458 | 1458 | { |
| 1459 | 1459 | if(empty($subjectString)) { |
@@ -1465,27 +1465,27 @@ discard block |
||
| 1465 | 1465 | $cr = chr((int)hexdec('0d')); |
| 1466 | 1466 | $lf = chr((int)hexdec('0a')); |
| 1467 | 1467 | |
| 1468 | - self::$eolChars = array( |
|
| 1469 | - array( |
|
| 1470 | - 'char' => $cr.$lf, |
|
| 1471 | - 'type' => ConvertHelper_EOL::TYPE_CRLF, |
|
| 1472 | - 'description' => t('Carriage return followed by a line feed'), |
|
| 1473 | - ), |
|
| 1474 | - array( |
|
| 1475 | - 'char' => $lf.$cr, |
|
| 1476 | - 'type' => ConvertHelper_EOL::TYPE_LFCR, |
|
| 1477 | - 'description' => t('Line feed followed by a carriage return'), |
|
| 1478 | - ), |
|
| 1479 | - array( |
|
| 1480 | - 'char' => $lf, |
|
| 1481 | - 'type' => ConvertHelper_EOL::TYPE_LF, |
|
| 1482 | - 'description' => t('Line feed'), |
|
| 1483 | - ), |
|
| 1484 | - array( |
|
| 1485 | - 'char' => $cr, |
|
| 1486 | - 'type' => ConvertHelper_EOL::TYPE_CR, |
|
| 1487 | - 'description' => t('Carriage Return'), |
|
| 1488 | - ), |
|
| 1468 | + self::$eolChars = array( |
|
| 1469 | + array( |
|
| 1470 | + 'char' => $cr.$lf, |
|
| 1471 | + 'type' => ConvertHelper_EOL::TYPE_CRLF, |
|
| 1472 | + 'description' => t('Carriage return followed by a line feed'), |
|
| 1473 | + ), |
|
| 1474 | + array( |
|
| 1475 | + 'char' => $lf.$cr, |
|
| 1476 | + 'type' => ConvertHelper_EOL::TYPE_LFCR, |
|
| 1477 | + 'description' => t('Line feed followed by a carriage return'), |
|
| 1478 | + ), |
|
| 1479 | + array( |
|
| 1480 | + 'char' => $lf, |
|
| 1481 | + 'type' => ConvertHelper_EOL::TYPE_LF, |
|
| 1482 | + 'description' => t('Line feed'), |
|
| 1483 | + ), |
|
| 1484 | + array( |
|
| 1485 | + 'char' => $cr, |
|
| 1486 | + 'type' => ConvertHelper_EOL::TYPE_CR, |
|
| 1487 | + 'description' => t('Carriage Return'), |
|
| 1488 | + ), |
|
| 1489 | 1489 | ); |
| 1490 | 1490 | } |
| 1491 | 1491 | |
@@ -1513,13 +1513,13 @@ discard block |
||
| 1513 | 1513 | ); |
| 1514 | 1514 | } |
| 1515 | 1515 | |
| 1516 | - /** |
|
| 1517 | - * Removes the specified keys from the target array, |
|
| 1518 | - * if they exist. |
|
| 1519 | - * |
|
| 1520 | - * @param array $array |
|
| 1521 | - * @param array $keys |
|
| 1522 | - */ |
|
| 1516 | + /** |
|
| 1517 | + * Removes the specified keys from the target array, |
|
| 1518 | + * if they exist. |
|
| 1519 | + * |
|
| 1520 | + * @param array $array |
|
| 1521 | + * @param array $keys |
|
| 1522 | + */ |
|
| 1523 | 1523 | public static function arrayRemoveKeys(array &$array, array $keys) : void |
| 1524 | 1524 | { |
| 1525 | 1525 | foreach($keys as $key) |
@@ -1530,13 +1530,13 @@ discard block |
||
| 1530 | 1530 | } |
| 1531 | 1531 | } |
| 1532 | 1532 | |
| 1533 | - /** |
|
| 1534 | - * Checks if the specified variable is an integer or a string containing an integer. |
|
| 1535 | - * Accepts both positive and negative integers. |
|
| 1536 | - * |
|
| 1537 | - * @param mixed $value |
|
| 1538 | - * @return bool |
|
| 1539 | - */ |
|
| 1533 | + /** |
|
| 1534 | + * Checks if the specified variable is an integer or a string containing an integer. |
|
| 1535 | + * Accepts both positive and negative integers. |
|
| 1536 | + * |
|
| 1537 | + * @param mixed $value |
|
| 1538 | + * @return bool |
|
| 1539 | + */ |
|
| 1540 | 1540 | public static function isInteger($value) : bool |
| 1541 | 1541 | { |
| 1542 | 1542 | if(is_int($value)) { |
@@ -1556,40 +1556,40 @@ discard block |
||
| 1556 | 1556 | return false; |
| 1557 | 1557 | } |
| 1558 | 1558 | |
| 1559 | - /** |
|
| 1560 | - * Converts an amount of seconds to a DateInterval object. |
|
| 1561 | - * |
|
| 1562 | - * @param int $seconds |
|
| 1563 | - * @return \DateInterval |
|
| 1564 | - * @throws ConvertHelper_Exception If the date interval cannot be created. |
|
| 1565 | - * |
|
| 1566 | - * @see ConvertHelper::ERROR_CANNOT_GET_DATE_DIFF |
|
| 1567 | - */ |
|
| 1559 | + /** |
|
| 1560 | + * Converts an amount of seconds to a DateInterval object. |
|
| 1561 | + * |
|
| 1562 | + * @param int $seconds |
|
| 1563 | + * @return \DateInterval |
|
| 1564 | + * @throws ConvertHelper_Exception If the date interval cannot be created. |
|
| 1565 | + * |
|
| 1566 | + * @see ConvertHelper::ERROR_CANNOT_GET_DATE_DIFF |
|
| 1567 | + */ |
|
| 1568 | 1568 | public static function seconds2interval(int $seconds) : \DateInterval |
| 1569 | 1569 | { |
| 1570 | 1570 | return ConvertHelper_DateInterval::fromSeconds($seconds)->getInterval(); |
| 1571 | 1571 | } |
| 1572 | 1572 | |
| 1573 | - /** |
|
| 1574 | - * Converts a size string like "50 MB" to the corresponding byte size. |
|
| 1575 | - * It is case insensitive, ignores spaces, and supports both traditional |
|
| 1576 | - * "MB" and "MiB" notations. |
|
| 1577 | - * |
|
| 1578 | - * @param string $size |
|
| 1579 | - * @return int |
|
| 1580 | - */ |
|
| 1573 | + /** |
|
| 1574 | + * Converts a size string like "50 MB" to the corresponding byte size. |
|
| 1575 | + * It is case insensitive, ignores spaces, and supports both traditional |
|
| 1576 | + * "MB" and "MiB" notations. |
|
| 1577 | + * |
|
| 1578 | + * @param string $size |
|
| 1579 | + * @return int |
|
| 1580 | + */ |
|
| 1581 | 1581 | public static function size2bytes(string $size) : int |
| 1582 | 1582 | { |
| 1583 | 1583 | return self::parseSize($size)->toBytes(); |
| 1584 | 1584 | } |
| 1585 | 1585 | |
| 1586 | - /** |
|
| 1587 | - * Parses a size string like "50 MB" and returns a size notation instance |
|
| 1588 | - * that has utility methods to access information on it, and convert it. |
|
| 1589 | - * |
|
| 1590 | - * @param string $size |
|
| 1591 | - * @return ConvertHelper_SizeNotation |
|
| 1592 | - */ |
|
| 1586 | + /** |
|
| 1587 | + * Parses a size string like "50 MB" and returns a size notation instance |
|
| 1588 | + * that has utility methods to access information on it, and convert it. |
|
| 1589 | + * |
|
| 1590 | + * @param string $size |
|
| 1591 | + * @return ConvertHelper_SizeNotation |
|
| 1592 | + */ |
|
| 1593 | 1593 | public static function parseSize(string $size) : ConvertHelper_SizeNotation |
| 1594 | 1594 | { |
| 1595 | 1595 | return new ConvertHelper_SizeNotation($size); |