Skip to content

Commit

Permalink
1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecc committed Oct 27, 2018
1 parent 392f39f commit ffaed8d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 23 deletions.
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/examples export-ignore
/vendor export-ignore
/docs export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml export-ignore
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.idea
composer.lock
vendor/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Returns true if the str is (completelly) uppercase
Returns true if the str is (completelly) lowercase
## Version list

* 1.2 2018-10-27 Some changes in the class collection.
* 1.0 2018-09-18 First version

## License
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "eftec/mapache-commons",
"description": "It's a set of useful functions for PHP. The name is a pun.",
"version": "1.0",
"version": "1.2",
"type": "library",
"keywords": [
"collection",
Expand All @@ -16,7 +16,6 @@
"homepage": "https://github.com/EFTEC/mapache-commons"
}
],
"minimum-stability": "beta",
"license": "Apache-2.0",
"autoload": {
"psr-4": {
Expand Down
15 changes: 10 additions & 5 deletions lib/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Class Collection
* @package mapache_commons
* @version 1.0 2018-09-18
* @version 1.2 2018-oct-27
* @copyright Jorge Castro Castillo
* @license Apache-2.0
* @see https://github.com/EFTEC/mapache-commons
Expand Down Expand Up @@ -43,7 +43,7 @@ public static function firstKey($array) {
}

/**
* Change the case of all the keys to lowercase
* Change the case of the key to lowercase
* @param $arr
* @return array
* @see https://stackoverflow.com/questions/1444484/how-to-convert-all-keys-in-a-multi-dimenional-array-to-snake-case
Expand All @@ -58,7 +58,7 @@ public static function arrayKeyLower($arr)
},array_change_key_case($arr,CASE_LOWER));
}
/**
* Change the case of all the keys to lowercase
* Change the case of the key to lowercase
* @param $arr
* @return array
* @see https://stackoverflow.com/questions/1444484/how-to-convert-all-keys-in-a-multi-dimenional-array-to-snake-case
Expand All @@ -74,7 +74,7 @@ public static function arrayKeyUpper($arr)
}

/**
* Generate a html table from an array
* Generate a table from an array
* @param array|null $array
* @param string|bool $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
* @return string
Expand Down Expand Up @@ -124,7 +124,12 @@ public static function generateTable($array,$css=true){
foreach( $array as $key=>$value){
$html .= '<tr >';
foreach($value as $key2=>$value2){
$html .= '<td >' . htmlspecialchars($value2) . '</td>';
if (is_array($value2)) {
$html .= '<td >' . self::generateTable($value2). '</td>';
} else {
$html .= '<td >' . htmlspecialchars($value2) . '</td>';
}

}
$html .= '</tr>';
}
Expand Down
44 changes: 28 additions & 16 deletions lib/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,53 @@
/**
* Class Debug
* @package mapache_commons
* @version 1.0 2018-09-18
* @version 1.1 2018-09-19
* @copyright Jorge Castro Castillo
* @license Apache-2.0
* @see https://github.com/EFTEC/mapache-commons
*/
class Debug
{
/**
* Alternative to var_dump. It <pre> the result or it shows the result in the console of javascript.
* @param $value
* @param bool $console true if you want to return the values in the javascript-console.
* @param int $type: 0=normal (<pre>), 1=javascript console, 2=table (use future)
* @see https://stackoverflow.com/questions/10116063/making-php-var-dump-values-display-one-line-per-value
*/
public static function var_dump($value,$console=false) {
if ($console) {
echo "<script>console.log(".json_encode($value).");</script>";
} else {
echo "<pre>";
var_dump($value);
echo "</pre>";
public static function var_dump($value,$type=1) {
switch ($type) {
case 1:
echo "<script>console.log(".json_encode($value).");</script>";
break;
case 2:
echo "<pre>";
var_dump($value);
echo "</pre>";
break;
default:
trigger_error("var_dump method not yet defined");
}
}

/**
* Write a log file. If the file is over 10mb then the file is resetted.
* @param $logFile
* @param $txt
* Write a log file. If the file is over 10mb then the file is resetted.<br>
* <code>
* Debug::WriteLog('somefile.txt','warning','it is a warning');
* Debug::WriteLog('somefile.txt','it is a warning');
* </code>
* @param mixed $logFile
* @param mixed $level
* @param string $txt if txt is empty then level is defined as warning and level is used for the description
*/
public static function WriteLog($logFile,$txt)
public static function WriteLog($logFile,$level,$txt='')
{
if ($logFile == '') {
return;
}
$fz = @filesize($logFile);

if (empty($txt)) {
$txt=$level;
$level='WARNING';
}
if (is_object($txt) || is_array($txt)) {
$txtW = print_r($txt, true);
} else {
Expand All @@ -55,7 +67,7 @@ public static function WriteLog($logFile,$txt)
$txtW = str_replace("\r\n", " ", $txtW);
$txtW = str_replace("\n", " ", $txtW);
$now = new DateTime();
@fwrite($fp, $now->format('c') . "\t" . $txtW . "\n");
@fwrite($fp, $now->format('Y-m-d H:i:s') . "\t".$level."\t". $txtW . "\n");
@fclose($fp);
}
}

0 comments on commit ffaed8d

Please sign in to comment.