This repository has been archived by the owner on Apr 18, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
abr4xas
committed
Jun 18, 2017
1 parent
ecca9ff
commit 39e2312
Showing
4 changed files
with
196 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/** | ||
* The MIT License (MIT) | ||
* Copyright (c) 2017 Angel Cruz <me@abr4xas.org> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the “Software”), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
* @author Angel Cruz <me@abr4xas.org> | ||
* @license MIT License | ||
* @copyright 2017 Angel Cruz | ||
*/ | ||
|
||
namespace Abr4xas\Utils; | ||
|
||
class Debug | ||
{ | ||
public static function dd() | ||
{ | ||
array_map(function($x) { print("<script src=\"https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shCore.min.js\"></script><script src=\"https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shBrushPhp.min.js\"></script><link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/styles/shCoreFadeToGrey.min.css\" /><pre class=\"brush: php\">".print_r($x,true)."</pre><script>SyntaxHighlighter.all()</script>"); }, func_get_args()); | ||
die; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
/** | ||
* The MIT License (MIT) | ||
* Copyright (c) 2017 Angel Cruz <me@abr4xas.org> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the “Software”), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
* @author Angel Cruz <me@abr4xas.org> | ||
* @license MIT License | ||
* @copyright 2017 Angel Cruz | ||
*/ | ||
|
||
namespace Abr4xas\Utils; | ||
|
||
class Hash | ||
{ | ||
|
||
const ALGO = PASSWORD_BCRYPT; | ||
const COST = 10; | ||
|
||
public function __construct() | ||
{ | ||
$this->algo = self::ALGO; | ||
$this->cost = self::COST; | ||
} //End constructor | ||
|
||
/** | ||
* Hash a plain text password. | ||
* | ||
* @param string $password The plain text password to hash. | ||
* @return string The hashed $password parameter. | ||
*/ | ||
public function password($password) | ||
{ | ||
return password_hash($password, $this->algo, ['cost' => $this->cost]); | ||
} //End password | ||
|
||
/** | ||
* Check a password against it's hash. | ||
* | ||
* @param string $password Plain text password. | ||
* @param string $hash Hashed password. | ||
* @return bool True if they match, false otherwise. | ||
*/ | ||
public function passwordCheck($password, $hash) | ||
{ | ||
return password_verify($password, $hash); | ||
} //End password | ||
|
||
/** | ||
* Use sha256 to hash an input string. | ||
* | ||
* @param string $input Plain text string to be hashed. | ||
* @return string The hashed version of the $input string. | ||
*/ | ||
public function hash($input) | ||
{ | ||
return hash('sha256', $input); | ||
} //End hash | ||
|
||
/** | ||
* Check a hash against another. | ||
* | ||
* @param string $know The hash we know is correct. | ||
* @param string $unknown The hash we want to compare with it. | ||
* @return bool True if the hashed strings match, false otherwise. | ||
*/ | ||
public function hashCheck($know, $unknown) | ||
{ | ||
return hash_equals($know, $unknown); | ||
} //End hashCheck | ||
|
||
} //End class Hash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/** | ||
* The MIT License (MIT) | ||
* Copyright (c) 2017 Angel Cruz <me@abr4xas.org> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the “Software”), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
* @author Angel Cruz <me@abr4xas.org> | ||
* @license MIT License | ||
* @copyright 2017 Angel Cruz | ||
*/ | ||
|
||
namespace Abr4xas\Utils; | ||
use Exception; | ||
|
||
class Money | ||
{ | ||
/** | ||
* Genera el formato de moneda | ||
* | ||
* @param float $valor monto a transformar | ||
* @param string $simbolo símbolo a mostrar por defecto BsF | ||
* @param int $decimal cantidad de decimales a mostrar por defecto dos | ||
* @return string valor formateado según $simbolo y $decimal | ||
* @throws Exception | ||
*/ | ||
|
||
public static function generaFormato($valor = 0, $simbolo = 'BsF', $decimal = 2) | ||
{ | ||
if (!is_numeric($valor)) | ||
throw new Exception("{$valor} debe indicar un número que sea válido"); | ||
if (!is_int($decimal)) | ||
throw new Exception("El valor {$decimal} no es válido"); | ||
|
||
return $simbolo . ' ' . number_format($valor, $decimal, '.', ''); | ||
} | ||
/** | ||
* Retira el formato generado de moneda | ||
* | ||
* @param string $str monto a transformar | ||
* @param string $simbolo | ||
* @return float | ||
*/ | ||
public static function quitarFormato($str, $simbolo = 'BsF') | ||
{ | ||
return floatval(str_replace('.', '', str_replace($simbolo, '', $str))); | ||
} | ||
} |