{"id":18772445,"url":"https://github.com/eftec/mapache-commons","last_synced_at":"2025-04-13T08:30:58.786Z","repository":{"id":56975554,"uuid":"149287239","full_name":"EFTEC/mapache-commons","owner":"EFTEC","description":"It is a library","archived":false,"fork":false,"pushed_at":"2024-08-25T00:44:51.000Z","size":180,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-25T16:15:21.221Z","etag":null,"topics":["collection","debug","php","php-library","text"],"latest_commit_sha":null,"homepage":"https://www.eftec.cl","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EFTEC.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-09-18T12:48:13.000Z","updated_at":"2024-09-23T21:03:45.000Z","dependencies_parsed_at":"2024-01-28T12:47:06.139Z","dependency_job_id":null,"html_url":"https://github.com/EFTEC/mapache-commons","commit_stats":{"total_commits":43,"total_committers":3,"mean_commits":"14.333333333333334","dds":0.09302325581395354,"last_synced_commit":"6398c82ff752fa3e33026a09eb52e20f3e9c00e8"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EFTEC%2Fmapache-commons","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EFTEC%2Fmapache-commons/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EFTEC%2Fmapache-commons/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EFTEC%2Fmapache-commons/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EFTEC","download_url":"https://codeload.github.com/EFTEC/mapache-commons/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223576427,"owners_count":17167866,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["collection","debug","php","php-library","text"],"created_at":"2024-11-07T19:29:09.510Z","updated_at":"2024-11-07T19:29:10.249Z","avatar_url":"https://github.com/EFTEC.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mapache Commons\r\nIt's a set of useful functions for PHP. The name is a pun (Mapache in spanish is \"raccoon\")\r\n\r\n[![Packagist](https://img.shields.io/packagist/v/eftec/mapache-commons.svg)](https://packagist.org/packages/eftec/mapache-commons)\r\n[![Maintenance](https://img.shields.io/maintenance/yes/2024.svg)]()\r\n[![composer](https://img.shields.io/badge/composer-%3E1.6-blue.svg)]()\r\n[![php](https://img.shields.io/badge/php-7.4-green.svg)]()\r\n[![php](https://img.shields.io/badge/php-8.*-green.svg)]()\r\n[![CocoaPods](https://img.shields.io/badge/docs-70%25-yellow.svg)]()\r\n\r\n\u003c!-- TOC --\u003e\r\n* [Mapache Commons](#mapache-commons)\r\n  * [Goals](#goals)\r\n  * [Families](#families)\r\n  * [CollectionLib](#collectionlib)\r\n    * [Method isAssoc()](#method-isassoc)\r\n      * [Parameters:](#parameters)\r\n    * [Method first()](#method-first)\r\n      * [Parameters:](#parameters-1)\r\n    * [Method firstKey()](#method-firstkey)\r\n      * [Parameters:](#parameters-2)\r\n    * [Method arrayKeyLower()](#method-arraykeylower)\r\n      * [Parameters:](#parameters-3)\r\n    * [Method arrayKeyUpper()](#method-arraykeyupper)\r\n      * [Parameters:](#parameters-4)\r\n    * [Method generateTable()](#method-generatetable)\r\n      * [Parameters:](#parameters-5)\r\n    * [Method splitOpeningClosing()](#method-splitopeningclosing)\r\n      * [Parameters:](#parameters-6)\r\n    * [Method splitNotString()](#method-splitnotstring)\r\n      * [Parameters:](#parameters-7)\r\n    * [Method arrayChangeKeyCaseRecursive()](#method-arraychangekeycaserecursive)\r\n      * [Parameters:](#parameters-8)\r\n    * [Method arraySearchField()](#method-arraysearchfield)\r\n      * [Parameters:](#parameters-9)\r\n    * [Method xmlToString()](#method-xmltostring)\r\n      * [Parameters:](#parameters-10)\r\n    * [Method arrayToXML()](#method-arraytoxml)\r\n      * [Parameters:](#parameters-11)\r\n    * [Method stringToXML()](#method-stringtoxml)\r\n      * [Parameters:](#parameters-12)\r\n    * [Method xmlToArray()](#method-xmltoarray)\r\n      * [Parameters:](#parameters-13)\r\n  * [DebugLib](#debuglib)\r\n    * [Method var_dump()](#method-var_dump)\r\n      * [Parameters:](#parameters-14)\r\n    * [Method WriteLog()](#method-writelog)\r\n      * [Parameters:](#parameters-15)\r\n  * [TextLib](#textlib)\r\n    * [Method isUpper()](#method-isupper)\r\n      * [Parameters:](#parameters-16)\r\n    * [Method isLower()](#method-islower)\r\n      * [Parameters:](#parameters-17)\r\n    * [Method between()](#method-between)\r\n      * [Parameters:](#parameters-18)\r\n    * [Method stripQuotes()](#method-stripquotes)\r\n      * [Parameters:](#parameters-19)\r\n    * [Method removeParenthesis()](#method-removeparenthesis)\r\n      * [Parameters:](#parameters-20)\r\n    * [Method replaceBetween()](#method-replacebetween)\r\n      * [Parameters:](#parameters-21)\r\n    * [Method removeFirstChars()](#method-removefirstchars)\r\n      * [Parameters:](#parameters-22)\r\n    * [Method removeLastChars()](#method-removelastchars)\r\n      * [Parameters:](#parameters-23)\r\n    * [Method getArgument()](#method-getargument)\r\n      * [Parameters:](#parameters-24)\r\n    * [Method strPosNotSpace()](#method-strposnotspace)\r\n      * [Parameters:](#parameters-25)\r\n    * [Method strposArray()](#method-strposarray)\r\n      * [Parameters:](#parameters-26)\r\n    * [Method parseArg()](#method-parsearg)\r\n      * [Parameters:](#parameters-27)\r\n    * [Method parseArg2()](#method-parsearg2)\r\n      * [Parameters:](#parameters-28)\r\n    * [Method naturalArg()](#method-naturalarg)\r\n      * [Parameters:](#parameters-29)\r\n    * [Method str_replace_ex()](#method-str_replace_ex)\r\n      * [Parameters:](#parameters-30)\r\n    * [Method wildCardComparison()](#method-wildcardcomparison)\r\n      * [Parameters:](#parameters-31)\r\n    * [Method endsWith()](#method-endswith)\r\n      * [Parameters:](#parameters-32)\r\n    * [Method replaceCurlyVariable()](#method-replacecurlyvariable)\r\n      * [Parameters:](#parameters-33)\r\n    * [Method addParenthesis()](#method-addparenthesis)\r\n      * [Parameters:](#parameters-34)\r\n    * [Method hasParenthesis()](#method-hasparenthesis)\r\n      * [Parameters:](#parameters-35)\r\n    * [Method camelCase()](#method-camelcase)\r\n      * [Parameters:](#parameters-36)\r\n  * [FileLib](#filelib)\r\n    * [Field lastError ()](#field-lasterror-)\r\n    * [Method getDirFiles()](#method-getdirfiles)\r\n      * [Parameters:](#parameters-37)\r\n    * [Method getDirFirstFile()](#method-getdirfirstfile)\r\n      * [Parameters:](#parameters-38)\r\n    * [Method getDirFolders()](#method-getdirfolders)\r\n      * [Parameters:](#parameters-39)\r\n    * [Method getExtensionPath()](#method-getextensionpath)\r\n      * [Parameters:](#parameters-40)\r\n    * [Method getFileNamePath()](#method-getfilenamepath)\r\n      * [Parameters:](#parameters-41)\r\n    * [Method getBaseNamePath()](#method-getbasenamepath)\r\n      * [Parameters:](#parameters-42)\r\n    * [Method getDirPath()](#method-getdirpath)\r\n      * [Parameters:](#parameters-43)\r\n    * [Method fixUrlSeparator()](#method-fixurlseparator)\r\n      * [Parameters:](#parameters-44)\r\n    * [Method safeFileGetContent()](#method-safefilegetcontent)\r\n      * [Parameters:](#parameters-45)\r\n    * [Method safeFilePutContent()](#method-safefileputcontent)\r\n      * [Parameters:](#parameters-46)\r\n    * [Method isAbsolutePath()](#method-isabsolutepath)\r\n      * [Parameters:](#parameters-47)\r\n  * [Version list](#version-list)\r\n  * [License](#license)\r\n\u003c!-- TOC --\u003e\r\n\r\n\r\n\r\n![Mapache Commons](docs/raccoon_small.png)  \r\n__Mapache Commons__\r\n\r\n## Goals\r\n\r\nIt's a set of useful function with the next requirements:\r\n* The function mustn't have dependencies (unless it requires a php module).  \r\n* The function must be FAST and memory friendly over the syntax sugar.\r\n* The function must be able to run statically, and it must be self-contained.\r\n* The function must be generic, and it must solve generic problems.  For example, a function that calculates the VAT of a specific country is not allowed.  \r\n\r\n## Families\r\n* CollectionLib\r\n* TextLib\r\n* DebugLib\r\n\r\n## CollectionLib\r\nClass CollectionLib\r\n\r\n### Method isAssoc()\r\nReturns true if array is an associative array, false is it's an indexed array\u003cbr\u003e\r\n**Example:**\r\n```\r\n$isAssoc=CollectionLib::isAssoc($array); // slow, more precise.\r\n$isAssoc=CollectionLib::isAssoc($array,true); // fast, less precise\r\n```\r\n#### Parameters:\r\n* **$array** input array (array)\r\n\r\n### Method first()\r\nReturns the first element of an array.\u003cbr\u003e\r\nSometimes the first element is not the index [0], for example ['key1'=\u003e1,0=2] where the first element is 'key1' and not 0.\r\nThis function always returns the right value.\r\n#### Parameters:\r\n* **$array** input array (array)\r\n\r\n### Method firstKey()\r\nReturns the first key of an array.\r\n#### Parameters:\r\n* **$array** input array (array)\r\n\r\n### Method arrayKeyLower()\r\nChange the case of the key to lowercase\r\n#### Parameters:\r\n* **$array** input array (array)\r\n\r\n### Method arrayKeyUpper()\r\nChange the case of the key to lowercase\r\n#### Parameters:\r\n* **$array** input array (array)\r\n\r\n### Method generateTable()\r\nGenerate a html table from an array\r\n#### Parameters:\r\n* **$array** input array (array|null)\r\n* **$css** if true then it uses the build in style. If false then it doesn't use style. If string then it uses as class (string|bool)\r\n\r\n### Method splitOpeningClosing()\r\nSplit a string using an opening and closing tag, by default \"(\" and \")\".\u003cbr/\u003e\r\nExample:\u003cbr/\u003e\r\n```\r\nCollectionLib::splitOpeningClosing(\"a(B,C,D)e(F,G,H)\"); // ['a','B,C,D','e','F,G,H']\r\nCollectionLib::splitOpeningClosing(\"a(B,C,D)e(F,G,H)i\"); // ['a','B,C,D','e','F,G,H','i']\r\n```\r\n#### Parameters:\r\n* **$text** input text to separated (string)\r\n* **$openingTag** Opening tag, default \"(\" (string)\r\n* **$closingTag** closing tag, default \")\" (string)\r\n* **$startPosition** start position (by default it is zero) (int)\r\n* **$excludeEmpty** if true then it excludes all empty values. (bool)\r\n* **$includeTag** if true then it includes the tag. (bool)\r\n\r\n### Method splitNotString()\r\nSplit a string by ignoring parts of string where values are between \" or '.\u003cbr\u003e\r\nExample:\u003cbr/\u003e\r\n```\r\nCollectionLib::splitNotString('a,b,\"CC,D,E\",e,f' ,\",\"); // ['a','b','CC,D,E','e','f']\r\n```\r\n#### Parameters:\r\n* **$text** input text (string)\r\n* **$separator** param string $separator (string)\r\n* **$offset** param int $offset (int)\r\n* **$excludeEmpty** param bool $excludeEmpty (bool)\r\n\r\n### Method arrayChangeKeyCaseRecursive()\r\nIt changes the case (to lower or upper case) of the keys of an array recursively\u003cbr\u003e\r\n**Example:**\r\n```\r\n$arr=['A'=\u003e'a','b'=\u003e'b'];\r\nCollectionLib::arrayChangeKeyCaseRecursive($arr);\r\n// returns ['a'=\u003e'a','b'=\u003e'b']\r\nCollectionLib::arrayChangeKeyCaseRecursive($arr,true);\r\n// returns ['A'=\u003e'a','B'=\u003e'b']\r\n```\r\n#### Parameters:\r\n* **$array** input array (array)\r\n* **$case** [optional] by default is CASE_LOWER \u003cp\u003e\r\n  Either CASE_UPPER or\r\n  CASE_LOWER (default)\u003c/p\u003e (int)\r\n\r\n### Method arraySearchField()\r\nIt returns the first (or all) key(s) inside an array/object in an array that matches the value of the field\u003cbr\u003e\r\n**Example:**\r\n```\r\n$array=[['name'=\u003e'john'],['name'=\u003e'mary']];\r\nCollectionLib::arraySearchField($array,'name','mary'); // 1\r\nCollectionLib::arraySearchField([(object)['name'=\u003e'john'],(object)['name'=\u003e'mary']],'name','mary'); // 1\r\nCollectionLib::arraySearchField([['name'=\u003e'john'],['name'=\u003e'mary'],['name'=\u003e'mary']],'name','mary',true); // returns [1,2]\r\n```\r\n#### Parameters:\r\n* **$array** input array (array)\r\n* **$fieldName** name of index of the field (string|int)\r\n* **$value** value to search (mixed)\r\n* **$returnAll** if true then it returns all matches. If false it returns the first value. (bool)\r\n\r\n### Method xmlToString()\r\nIt converts a xml (SimpleXMLElement object) into a string\u003cbr\u003e\r\n**Example:**\r\n```\r\n$string=CollectionLib::xmlToString($xml,true); // \"\u003croot\u003e...\u003c/root\u003e\"\r\n```\r\n#### Parameters:\r\n* **$xml** param SimpleXMLElement $xml (SimpleXMLElement)\r\n* **$format** if true then the result is formatted. (bool)\r\n\r\n### Method arrayToXML()\r\nIt convers an array into a xml (SimpleXMLElement object)\r\n**Example:**\r\n```\r\n$xml=CollectionLib::arrayToXML($array,'root'); // \u003croot\u003e...\u003c/root\u003e\r\n```\r\n#### Parameters:\r\n* **$data** param array $data (array)\r\n* **$rootName** The name of the root tag (default root) (string)\r\n* **$insidetag** It is used to fix a specific condition with the xml generated by PHP. (string)\r\n\r\n### Method stringToXML()\r\nIt converts a string into a xml (SimpleXMLElement object) using simplexml_load_string including a fix\u003cbr\u003e\r\n**Example:**\r\n```\r\n$xml=CollectionLib::stringToXML('\u003croot\u003e\u003citem arg=\"1\"\u003ea\u003c/item\u003e\u003citem arg=\"2\"\u003eb\u003c/item\u003e\u003c/root\u003e');\r\n```\r\n#### Parameters:\r\n* **$string** the value to convert (string)\r\n* **$className** param null $className (null)\r\n* **$options** libxml options (int)\r\n* **$insidetag** by default is 'value_inside'. In some cases, the parser fails to generate an XML\r\n  attribute when the child is empty \u003ctag a='1'\u003e2\u003c/tag\u003e. The solution is to generate\r\n  a new tag \u003ctag a='1'\u003e\u003c_value\u003e2\u003c/_value\u003e\u003c/tag\u003e (string)\r\n\r\n### Method xmlToArray()\r\nIt converts an XML class (SimpleXMLElement object) into an array.\r\n**Example:**\r\n```\r\n$array=CollectionLib::xmlToArray($xml);\r\n```\r\n#### Parameters:\r\n* **$xml** param SimpleXMLElement $xml (SimpleXMLElement)\r\n\r\n## DebugLib\r\nClass Debug\r\n\r\n### Method var_dump()\r\nAlternative to var_dump. It \"pre\" the result or it shows the result in the console of javascript.\u003cbr\u003e\r\n**Example:**\r\n```\r\nDebugLib::var_dump($value,true); // returns a var_dump visible via the console of javascript (browser)\r\n```\r\n#### Parameters:\r\n* **$value** param $value ()\r\n* **$type** : 0=normal (\u003cpre\u003e), 1=javascript console, 2=table (use future) (int)\r\n* **$returnValue** param bool $returnValue (bool)\r\n\r\n### Method WriteLog()\r\nWrite a log file. If the file is over 10mb then the file is resetted.\u003cbr\u003e\r\n```\r\nDebugLib::WriteLog('somefile.txt','warning','it is a warning');\r\nDebugLib::WriteLog('somefile.txt','it is a warning');\r\n```\r\n#### Parameters:\r\n* **$logFile** The file to write (string)\r\n* **$level** The level of the message, example \"error\", \"info\", 1, etc. (mixed)\r\n* **$txt** if txt is empty then level is defined as warning and level is used for the description (string|object|array)\r\n\r\n## TextLib\r\nClass TextLib\r\n\r\n### Method isUpper()\r\nReturns true if the str is (completelly) uppercase\r\n#### Parameters:\r\n* **$str** Input text (string)\r\n\r\n### Method isLower()\r\nReturns true if the str is (completelly) lowercase\r\n#### Parameters:\r\n* **$str** param $str ()\r\n\r\n### Method between()\r\nObtain a string between one text and other.\r\n**Example:**\r\n```\r\nTextLib::between('Hello Brave World','Hello','World');  // returns \" Brave \"\r\nTextLib::between('mary has a lamb','has','lamb') // returns ' a '\r\n```\r\n#### Parameters:\r\n* **$haystack** param string $haystack (string)\r\n* **$startNeedle** The initial text to search\u003cbr /\u003e\r\n  if empty then it starts at the start of the haystack. (string)\r\n* **$endNeedle** The end tag to search\u003cbr /\u003e\r\n  if empty then it ends at the end of the haystack (string)\r\n* **$offset** param null|int $offset (null|int)\r\n* **$ignoreCase** param bool $ignoreCase (bool)\r\n\r\n### Method stripQuotes()\r\nStrip quotes of a text \" or ' if the value in between quotes\u003cbr\u003e\r\nIf the value is not quoted then it is not touched.\u003cbr\u003e\r\nIf the value is not correctly closed (\"hello or \"hello' ), then the quota is not removed.\u003cbr\u003e\r\nThe value is trimmed '   \"hello world\"' --\u003e 'hello world'\u003cbr\u003e\r\n**Example:**\r\n```\r\nTextLib::stripQuotes('\"hello world\"');\r\n// returns hello world\r\n```\r\n#### Parameters:\r\n* **$text** param $text ()\r\n\r\n### Method removeParenthesis()\r\nRemove the initial and final parenthesis but only if both matches.\u003cbr/\u003e\r\nIf the $start and $end are arrays then both must have the same count and arrays are compared by pair of index\u003cbr\u003e\r\n**Example:**\r\n```\r\nTextLib::removeParenthesis('hello'); // return \"hello\";\r\nTextLib::removeParenthesis('(hello)'); // return \"hello\";\r\nTextLib::removeParenthesis('[hello]'\r\n,['(','{','[']\r\n,[')','}',']']); // returns \"hello\"\r\nTextLib::removeParenthesis(\"'hello'\"\r\n,\"'\"\r\n,\"'\"); // returns \"hello\"\r\n```\r\n#### Parameters:\r\n* **$txt** Input value. Example \"hello\", \"(hello)\" (string)\r\n* **$start** the open parenthesis, by default it's '('. (string|array)\r\n* **$end** the close parenthesis, by default it's ')'. (string|array)\r\n\r\n### Method replaceBetween()\r\nReplace the text between two needles\u003cbr\u003e\r\n**Example:**\r\n```\r\nTextLib::replaceBetween('Hello Brave World','Hello','World',' Wayne ') // returns \"Hello Wayne World\"\r\n```\r\n#### Parameters:\r\n* **$haystack** the input value (string)\r\n* **$startNeedle** The initial text to search\u003cbr /\u003e\r\n  if empty then it starts at the start of the haystack. (string)\r\n* **$endNeedle** The end tag to search\u003cbr /\u003e\r\n  if empty then it ends at the end of the haystack (string)\r\n* **$replaceText** Text to replace (string)\r\n* **$offset** the offset position to start the search. (null|int)\r\n* **$replaceTag** If true then it also replaces the tags (bool)\r\n\r\n### Method removeFirstChars()\r\nRemove the first character(s) for a string\u003cbr\u003e\r\n**Example:**\r\n```\r\nTextLib::removeFirstChars('Hello') // returns \"ello\"\r\n```\r\n#### Parameters:\r\n* **$str** The input text (string)\r\n* **$length** The amount of characters to remove (default 1) (int)\r\n\r\n### Method removeLastChars()\r\nRemove the last character(s) for a string\u003cbr\u003e\r\n**Example:**\r\n```\r\nTextLib::removeLastChars('Hello') // returns \"Hell\"\r\n```\r\n#### Parameters:\r\n* **$str** The input text (string)\r\n* **$length** The amount of characters to remove (default 1) (int)\r\n\r\n### Method getArgument()\r\nIt separates an argument from the value to the set value.\u003cbr\u003e\r\nReturns an array with the name of the argument and value (if any). It always returns a two dimension array\r\n**Example:**\r\n```\r\nself::getArgument(\"arg=200\"); // returns [\"arg\",\"200\"]\r\nself::getArgument(\"arg:200\",':'); // returns [\"arg\",\"200\"]\r\n```\r\n#### Parameters:\r\n* **$str** The input text (string)\r\n* **$set** The separator of operator (string)\r\n* **$trimValue** param bool $trimValue (bool)\r\n\r\n### Method strPosNotSpace()\r\nIt returns the first non-space position inside a string.\r\n**Example:**\r\n```\r\nTextLib::strPosNotSpace('   abc  def'); // returns 3\r\n```\r\n#### Parameters:\r\n* **$str** input string (string)\r\n* **$offset** offset position (int)\r\n* **$charlist** list of characters considered as space (string)\r\n\r\n### Method strposArray()\r\nIt finds the first (or last) ocurrence of a text.\u003cbr\u003e\r\nUnlikely strpos(), this method allows finding more than one neddle.\u003cbr\u003e\r\n**Example:**\r\n```\r\nTextLib::strposArray('a,b.d.e,f.g',['x','t','.']); // return 3\r\nTextLib::strposArray('a,b.d.e,f.g',['x','t',','],0,true); // return 7\r\n```\r\n#### Parameters:\r\n* **$haystack** the input value (string)\r\n* **$needles** the value (or values) to find (string|array)\r\n* **$offset** the offset position (initially it's 0) (int)\r\n* **$last** if false (default) it returns the first ocurrence. If true returns the last one (bool)\r\n\r\n### Method parseArg()\r\nIt transforms a text = 'a1=1,a2=2' into an associative array\u003cbr/\u003e\r\nIt uses the method parse_str() to do the conversion\u003cbr/\u003e\r\n**Note:** It doesn't work with quotes or double quotes. a1=\"aa,bb\",bb=30 doesn't work\r\n**Example:**\r\n```\r\nTextLib::parseArg('a=1,b=1'); // returns ['a'=\u003e'1','b'=\u003e'1']\r\n```\r\n#### Parameters:\r\n* **$text** The input string with the initial values (string)\r\n* **$separator** The separator (string)\r\n\r\n### Method parseArg2()\r\nIt's the same than parseArg() but it's x3 times slower.\u003cbr\u003e\r\nIt also considers quotes and doubles quotes.\u003cbr\u003e\r\nExample:\r\n```\r\nTextLib::parseArg2(\"a1=1,a2=2,a3=\"aa,bb\"); // [\"a1\"=\u003e1,\"a2\"=\u003e2,\"a3\"=\u003e\"\"aa,bb\"\"]\r\nTextLib::parseArg(\"a1=1,a2=2,a3=\"aa,bb\"); // [\"a1\"=\u003e1,\"a2\"=\u003e2,\"a3\"=\u003e\"\"aa\",\"bb\"\"=\u003e\"\"]\r\n```\r\n#### Parameters:\r\n* **$text** The input string with the initial values (string)\r\n* **$separator** The separator. It does not separates text inside quotes or double-quotes. (string)\r\n\r\n### Method naturalArg()\r\nIt parses a natural string and returns a declarative array\u003cbr\u003e\r\nA \"natural string\", it is a set of values or arguments separated by space\r\n, where a value is the index and the new one is the value of the index.\r\n```\r\nTextLib::naturalArg('select * from table where 1=1'\r\n,['select'=\u003e'req','from'=\u003e'req','where'=\u003e'opt']);\r\n// returns ['select'=\u003e'*','from'=\u003e'table','where'=\u003e'1=1']\r\nTextLib::naturalArg('item export table inport file'\r\n,['item'=\u003e'first','export'=\u003e'opt','inport'=\u003e'opt']);\r\n// returns: ['item' =\u003e 'item', 'export' =\u003e 'table', 'inport' =\u003e 'file']\r\n```\r\n#### Parameters:\r\n* **$txt** the input value. Example \"somevalue TYPE int LENGHT 30\" (string)\r\n* **$separators** the indicator for each field.\u003cbr\u003e\r\n  first = indicates the first element (optional)\u003cbr\u003e\r\n  opt = indicates the field is optional\u003cbr\u003e\r\n  req = indicates the field is required \u003cbr\u003e (array)\r\n\r\n### Method str_replace_ex()\r\nIt works as str_replace, but it also allows to limit the number of replacements.\r\n#### Parameters:\r\n* **$search** param string $search (string)\r\n* **$replace** param string $replace (string)\r\n* **$subject** param string $subject (string)\r\n* **$limit** param int $limit (int)\r\n\r\n### Method wildCardComparison()\r\nIt compares with wildcards (*) and returns true if both strings are equals\u003cbr\u003e\r\nThe wildcards only works at the beginning or at the end of the string.\u003cbr\u003e\r\n\u003cb\u003eExample:\u003cb\u003e\u003cbr\u003e\r\n```\r\nTextLib::wildCardComparison('abcdef','abc*'); // true\r\nTextLib::wildCardComparison('abcdef','*def'); // true\r\nTextLib::wildCardComparison('abcdef','*abc*'); // true\r\nTextLib::wildCardComparison('abcdef','*cde*'); // true\r\nTextLib::wildCardComparison('abcdef','*cde'); // false\r\n```\r\n#### Parameters:\r\n* **$text** param string $text (string)\r\n* **$textWithWildcard** param string|null $textWithWildcard (string|null)\r\n\r\n### Method endsWith()\r\nit returns true if $string ends with $endString\u003cbr\u003e\r\n\u003cb\u003eExample:\u003cb\u003e\u003cbr\u003e\r\n```\r\nTextLib::endsWidth('hello world','world'); // true\r\n```\r\n#### Parameters:\r\n* **$string** param $string ()\r\n* **$endString** param $endString ()\r\n\r\n### Method replaceCurlyVariable()\r\nReplaces all variables defined between {{ }} by a variable inside the dictionary of values.\u003cbr\u003e\r\nExample:\u003cbr\u003e\r\nreplaceCurlyVariable('hello={{var}}',['var'=\u003e'world']) // hello=world\u003cbr\u003e\r\nreplaceCurlyVariable('hello={{var}}',['varx'=\u003e'world']) // hello=\u003cbr\u003e\r\nreplaceCurlyVariable('hello={{var}}',['varx'=\u003e'world'],true) // hello={{var}}\u003cbr\u003e\r\n#### Parameters:\r\n* **$string** The input value. It could contain variables defined as {{namevar}} (string)\r\n* **$values** The dictionary of values. (array)\r\n* **$notFoundThenKeep** [false] If true and the value is not found, then it keeps the value.\r\n  Otherwise, it is replaced by an empty value (bool)\r\n\r\n### Method addParenthesis()\r\nIt adds a parenthesis (or other symbol) at the start and end of the text.\r\nIf it already has it, then it is not added.\u003cbr\u003e\r\n**Example:**\r\n```\r\nTextLib::addParenthesis('hello'); // return '(hello)';\r\nTextLib::addParenthesis('(hello)');// return '(hello)';\r\n```\r\n#### Parameters:\r\n* **$txt** Input value. Example \"hello\", \"(hello)\" (string)\r\n* **$start** the open parenthesis, by default it's '('. (string|array)\r\n* **$end** the close parenthesis, by default it's ')'. (string|array)\r\n\r\n### Method hasParenthesis()\r\nIt returns true if the text has an open and ending parenthesis (or other symbol).\u003cbr\u003e\r\n**Example:**\r\n```\r\nTextLib::hasParenthesis('hello'); // return false;\r\nTextLib::hasParenthesis('(hello)'); // return true;\r\n```\r\n#### Parameters:\r\n* **$txt** Input value. Example \"hello\", \"(hello)\" (string)\r\n* **$start** the open parenthesis, by default it's '('. (string|array)\r\n* **$end** the close parenthesis, by default it's ')'. (string|array)\r\n\r\n### Method camelCase()\r\nRetains the case minus the first letter that it's converted in lowercase\u003cbr\u003e\r\nIf the text contains the characters \"_\" or \" \", then the next character is uppercase\u003cbr\u003e\r\nIf the text does not contain any character \"_\" or \" \", then only the first character is replaced.\r\n**Example:**\r\n```\r\nTextLib::camelCase('HelloWorld'); // return \"helloWorld\";\r\nTextLib::camelCase('hello_world'); // return \"helloWorld\";\r\n```\r\n#### Parameters:\r\n* **$txt** input value (string)\r\n\r\n\r\n\r\n## FileLib\r\nClass Files\u003cbr\u003e\r\nThis class has a collection of functions to interact with files and directories.\r\n### Field lastError ()\r\n\r\n\r\n### Method getDirFiles()\r\nIt gets the content (files) of a directory. It does not include other directories.\r\n#### Parameters:\r\n* **$dir** The directory to scan. (string)\r\n* **$extensions** The extension to find (without dot). ['*'] means any extension. (array)\r\n* **$recursive** if true (default), then it scans the folders recursively. (bool)\r\n\r\n### Method getDirFirstFile()\r\nIt returns the first file (exclude directories) find in a directory that matches a specific extension(s)\u003cbr\u003e\r\nThe order of the extensions could count.\u003cbr\u003e\r\nIf there are two files with the same extension, then it returns the first one.\r\n#### Parameters:\r\n* **$dir** The directory to scan. (string)\r\n* **$extensions** The extension to find (without dot). ['*'] means any extension. (array)\r\n* **$sort** (default false), if true then it sorts the list previous the filter. (bool)\r\n* **$descending** (default false), if true then it sorts (if enable) descending. (bool)\r\n\r\n### Method getDirFolders()\r\nIt gets the content (folders) of a directory without trailing slash. It does not include files.\r\n#### Parameters:\r\n* **$dir** The directory to scan. (string)\r\n* **$recursive** if true (default), then it scans the folders recursively. (bool)\r\n\r\n### Method getExtensionPath()\r\nIt gets the extension of a file (without dot). If the file has no extension then it returns empty.\r\n#### Parameters:\r\n* **$fullPath** the path to analize. (string)\r\n\r\n### Method getFileNamePath()\r\nIt gets the filename (without extension and directory)\r\n#### Parameters:\r\n* **$fullPath** the path to analize. (string)\r\n\r\n### Method getBaseNamePath()\r\nIt gets the base name (filename with extension). It does not include the directory.\r\n#### Parameters:\r\n* **$fullPath** the path to analize. (string)\r\n\r\n### Method getDirPath()\r\nIt gets the dir from a full path (without trailing slash)\r\n#### Parameters:\r\n* **$fullPath** the path to analize. (string)\r\n\r\n### Method fixUrlSeparator()\r\nIt fixes the path by converting the slash and inverse lash into the system folder separator\r\n#### Parameters:\r\n* **$fullPath** the path to analize. (string)\r\n\r\n### Method safeFileGetContent()\r\nIt gets the content of a file. It never throws an exception\u003cbr\u003e\r\nIn case of error, it returns the default value\r\n#### Parameters:\r\n* **$filename** The filename to open. (string)\r\n* **$use_include_path** used to trigger include path search. (bool)\r\n* **$context** A valid context resource created with (null)\r\n* **$offset** The offset where the reading starts. (int)\r\n* **$length** Maximum length of data read. The default is to read until end\r\n  of file is reached. (int|null)\r\n* **$default** The value to return if it is unable to open the file (null|mixed)\r\n\r\n### Method safeFilePutContent()\r\nWrite a string to a file. This operator is safe, it never throws an exception.\r\n#### Parameters:\r\n* **$filename** Path to the file where to write the data. (string)\r\n* **$data** The data to write. Can be either a string, an array or a stream resource. (mixed)\r\n* **$flag** The value of flags can be any combination of the following flags, with some\r\n  restrictions, joined with the binary OR (|) operator. (int)\r\n* **$context** A valid context resource created with stream_context_create. (mixed)\r\n* **$tries** The number of tries (default 3). Every try has a delay of 300ms. (int)\r\n\r\n### Method isAbsolutePath()\r\nReturns true if the path is absolute, otherwise it returns false.\u003cbr\u003e\r\nThis function works in Linux and Windows (and most probably in other UNIX OS)\r\n#### Parameters:\r\n* **$fullPath** The path to analize. (string)\r\n\r\n## Version list\r\n* 1.24 \r\n  * Fixed an exception with FileLib. It also stores every error in a field.\r\n  * Completed README.md\r\n  * Cleaned PHPDocs.\r\n* 1.23 Modified .gitattributes and .gitignore to streamline the final version.\r\n* 1.22 The next classes have been renamed:\r\n  * Text (deprecated) =\u003e TextLib\r\n  * Collection (deprecated)  =\u003e CollectionLib\r\n  * Debug (deprecated) =\u003e DebugLib\r\n  * It is because there are a dozen of libraries who use the same name for the classes.   \r\n  * **You can still use the same library without changes** but for new code I suggest to use the new names.\r\n  * [new] FileLib::getDirFirstFile()\r\n* 1.21 added FileLib class\r\n  * getDirFiles()\r\n  * getDirFolders()\r\n  * getExtensionPath()\r\n  * getDirPath()\r\n  * getBaseNamePath()\r\n  * getFileNamePath()\r\n  * fixUrlSeparator()\r\n  * safeFileGetContent()\r\n  * safeFilePutContent()\r\n  * isAbsolutePath()\r\n* 1.20 New methods CollectionLib::xmlToString,CollectionLib::arrayToXML,CollectionLib::stringToXML,CollectionLib::xmlToArray\r\n* 1.17 New Method TextLib::str_replace_ex()\r\n* 1.16 New methods TextLib::wildcardComparison() and TextLib::endsWith()   \r\n* 1.15 New method TextLib::parseArg2()\r\n* 1.14 TextLib::camelCase() solved a small bug  \r\n* 1.13 TextLib::replaceCurlyVariable() updated\r\n* 1.12\r\n    * Collection:splitOpeningClosing added argument $includeTag\r\n* 1.11\r\n    * TextLib::replaceCurlyVariable Added method\r\n* 1.10\r\n    * TextLib::strPosNotSpace() added argument $charlist\r\n* 1.9 2019-12-09\r\n    * TextLib::replacetext() it does not crash if the end tag is missing.\r\n    * TextLib::replacetext() it as a new argument\r\n* 1.8 2019-12-04\r\n    * TextLib::between() now allows empty $startNeedle and $endNeedle\r\n* 1.7 2019-12-04 new methods\r\n    * TextLib::addParenthesis()\r\n    * TextLib::hasParenthesis()\r\n* 1.6 2019-12-04 new methods\r\n    * TextLib::parseArg()\r\n    * TextLib::naturalArg()\r\n    * TextLib::strposArray()\r\n    * TextLib::camelCase()\r\n    * TextLib::removeParenthesis()\r\n    * CollectionLib::arrayChangeKeyCaseRecursive()\r\n    * CollectionLib::arraySearchField()\r\n* 1.5 2019-03-10 new functions:  \r\n   Collection:splitOpeningClosing()  \r\n   TextLib::strPosNotSpace()  \r\n   TextLib::getArgument()  \r\n   CollectionLib::splitNotString()  \r\n* 1.4 2019-02-16 New functions TextLib::removeFirstChars(),TextLib::removeLastChars()\r\n* 1.3 2019-02-16 Added new methods and Unit test.\r\n* 1.2 2018-10-27 Some changes in the class collection.\r\n* 1.0 2018-09-18 First version  \r\n\r\n## License\r\n\r\nApache-2.0. \r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feftec%2Fmapache-commons","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feftec%2Fmapache-commons","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feftec%2Fmapache-commons/lists"}