@@ -8,21 +8,21 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | abstract class Utils { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * Retorna o SQL Formatado e Destacado |
|
| 13 | - * |
|
| 14 | - * @param String $query |
|
| 15 | - */ |
|
| 16 | - public static function dump_sql($query) { |
|
| 11 | + /** |
|
| 12 | + * Retorna o SQL Formatado e Destacado |
|
| 13 | + * |
|
| 14 | + * @param String $query |
|
| 15 | + */ |
|
| 16 | + public static function dump_sql($query) { |
|
| 17 | 17 | echo SqlFormatter::format($query); |
| 18 | - } |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - public static function kill() { |
|
| 20 | + public static function kill() { |
|
| 21 | 21 | call_user_func_array("dump", func_get_args()); |
| 22 | 22 | die("\nFIM\n"); |
| 23 | - } |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - public static function dump() { |
|
| 25 | + public static function dump() { |
|
| 26 | 26 | return call_user_func_array("dump", func_get_args()); |
| 27 | - } |
|
| 27 | + } |
|
| 28 | 28 | } |
@@ -3,26 +3,26 @@ |
||
| 3 | 3 | |
| 4 | 4 | class Log { |
| 5 | 5 | |
| 6 | - private static $oInstance; |
|
| 6 | + private static $oInstance; |
|
| 7 | 7 | |
| 8 | - private $oLogger; |
|
| 8 | + private $oLogger; |
|
| 9 | 9 | |
| 10 | - private function __construct() { |
|
| 10 | + private function __construct() { |
|
| 11 | 11 | |
| 12 | 12 | $this->oLogger = new \Monolog\Logger("PHPUtils"); |
| 13 | 13 | $this->oLogger->pushHandler( new \Monolog\Handler\StreamHandler("/tmp/PHPUtils.log") ); |
| 14 | 14 | $this->oLogger->pushHandler( new \Monolog\Handler\ChromePHPHandler() ); |
| 15 | 15 | $this->oLogger->pushHandler( new \Monolog\Handler\FirePHPHandler() ); |
| 16 | - } |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - public function log() {} |
|
| 18 | + public function log() {} |
|
| 19 | 19 | |
| 20 | - public function debug() { } |
|
| 20 | + public function debug() { } |
|
| 21 | 21 | |
| 22 | - public function warn() { } |
|
| 22 | + public function warn() { } |
|
| 23 | 23 | |
| 24 | - public function info() { } |
|
| 24 | + public function info() { } |
|
| 25 | 25 | |
| 26 | - public function error() { } |
|
| 26 | + public function error() { } |
|
| 27 | 27 | |
| 28 | 28 | } |
@@ -10,9 +10,9 @@ |
||
| 10 | 10 | private function __construct() { |
| 11 | 11 | |
| 12 | 12 | $this->oLogger = new \Monolog\Logger("PHPUtils"); |
| 13 | - $this->oLogger->pushHandler( new \Monolog\Handler\StreamHandler("/tmp/PHPUtils.log") ); |
|
| 14 | - $this->oLogger->pushHandler( new \Monolog\Handler\ChromePHPHandler() ); |
|
| 15 | - $this->oLogger->pushHandler( new \Monolog\Handler\FirePHPHandler() ); |
|
| 13 | + $this->oLogger->pushHandler(new \Monolog\Handler\StreamHandler("/tmp/PHPUtils.log")); |
|
| 14 | + $this->oLogger->pushHandler(new \Monolog\Handler\ChromePHPHandler()); |
|
| 15 | + $this->oLogger->pushHandler(new \Monolog\Handler\FirePHPHandler()); |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | public function log() {} |
@@ -19,7 +19,7 @@ |
||
| 19 | 19 | return call_user_func_array('parent::__construct', func_get_args()); |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | - public function sendLog($type, $key, $value = null, array $backtrace ) { |
|
| 22 | + public function sendLog($type, $key, $value = null, array $backtrace) { |
|
| 23 | 23 | |
| 24 | 24 | $logger = $this->logger; |
| 25 | 25 | $retorno['type'] = $type; |
@@ -3,31 +3,31 @@ discard block |
||
| 3 | 3 | |
| 4 | 4 | class ArrayDebugger extends \ArrayObject { |
| 5 | 5 | |
| 6 | - const TYPE_GET = 'GET'; |
|
| 7 | - const TYPE_SET = 'SET'; |
|
| 8 | - const TYPE_EXISTS = 'EXISTS'; |
|
| 9 | - const TYPE_UNSET = 'UNSET'; |
|
| 6 | + const TYPE_GET = 'GET'; |
|
| 7 | + const TYPE_SET = 'SET'; |
|
| 8 | + const TYPE_EXISTS = 'EXISTS'; |
|
| 9 | + const TYPE_UNSET = 'UNSET'; |
|
| 10 | 10 | |
| 11 | - private $logger; |
|
| 11 | + private $logger; |
|
| 12 | 12 | |
| 13 | - public function __construct() { |
|
| 13 | + public function __construct() { |
|
| 14 | 14 | |
| 15 | 15 | $this->logger = function($data_log) { |
| 16 | - return dump($data_log); |
|
| 16 | + return dump($data_log); |
|
| 17 | 17 | }; |
| 18 | 18 | |
| 19 | 19 | return call_user_func_array('parent::__construct', func_get_args()); |
| 20 | - } |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Write log |
|
| 24 | - * |
|
| 25 | - * @param string $type |
|
| 26 | - * @param string $key |
|
| 27 | - * @param string $value |
|
| 28 | - * @param array $backtrace |
|
| 29 | - */ |
|
| 30 | - public function sendLog($type, $key, $value = null, array $backtrace ) { |
|
| 20 | + } |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Write log |
|
| 24 | + * |
|
| 25 | + * @param string $type |
|
| 26 | + * @param string $key |
|
| 27 | + * @param string $value |
|
| 28 | + * @param array $backtrace |
|
| 29 | + */ |
|
| 30 | + public function sendLog($type, $key, $value = null, array $backtrace ) { |
|
| 31 | 31 | |
| 32 | 32 | $logger = $this->logger; |
| 33 | 33 | $retorno['type'] = $type; |
@@ -36,59 +36,59 @@ discard block |
||
| 36 | 36 | $retorno['file'] = $backtrace[0]['file']; |
| 37 | 37 | $retorno['line'] = $backtrace[0]['line']; |
| 38 | 38 | return $logger($retorno); |
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Defines logger |
|
| 43 | - * |
|
| 44 | - * @param \Closure $logger |
|
| 45 | - */ |
|
| 46 | - public function setLogger(\Closure $logger) { |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Defines logger |
|
| 43 | + * |
|
| 44 | + * @param \Closure $logger |
|
| 45 | + */ |
|
| 46 | + public function setLogger(\Closure $logger) { |
|
| 47 | 47 | $this->logger = $logger; |
| 48 | - } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Called when getting a value from array |
|
| 52 | - * |
|
| 53 | - * @param mixed $name |
|
| 54 | - */ |
|
| 55 | - public function offsetGet($name) { |
|
| 50 | + /** |
|
| 51 | + * Called when getting a value from array |
|
| 52 | + * |
|
| 53 | + * @param mixed $name |
|
| 54 | + */ |
|
| 55 | + public function offsetGet($name) { |
|
| 56 | 56 | |
| 57 | 57 | $this->sendLog(static::TYPE_GET, $name, null, debug_backtrace()); |
| 58 | 58 | return call_user_func_array('parent::offsetGet', func_get_args()); |
| 59 | - } |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Called when setting a value from array |
|
| 63 | - * |
|
| 64 | - * @param mixed $name |
|
| 65 | - * @param mixed $value |
|
| 66 | - */ |
|
| 67 | - public function offsetSet($name, $value) { |
|
| 61 | + /** |
|
| 62 | + * Called when setting a value from array |
|
| 63 | + * |
|
| 64 | + * @param mixed $name |
|
| 65 | + * @param mixed $value |
|
| 66 | + */ |
|
| 67 | + public function offsetSet($name, $value) { |
|
| 68 | 68 | |
| 69 | 69 | $this->sendLog(static::TYPE_SET, $name, $value, debug_backtrace()); |
| 70 | 70 | return call_user_func_array('parent::offsetSet', func_get_args()); |
| 71 | - } |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Called when checking a value from array |
|
| 75 | - * |
|
| 76 | - * @param mixed $name |
|
| 77 | - */ |
|
| 78 | - public function offsetExists($name) { |
|
| 73 | + /** |
|
| 74 | + * Called when checking a value from array |
|
| 75 | + * |
|
| 76 | + * @param mixed $name |
|
| 77 | + */ |
|
| 78 | + public function offsetExists($name) { |
|
| 79 | 79 | |
| 80 | 80 | $this->sendLog(static::TYPE_EXISTS, $name, null, debug_backtrace()); |
| 81 | 81 | return call_user_func_array('parent::offsetExists', func_get_args()); |
| 82 | - } |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Called when removing a value from array |
|
| 86 | - * |
|
| 87 | - * @param mixed $name |
|
| 88 | - */ |
|
| 89 | - public function offsetUnset($name) { |
|
| 84 | + /** |
|
| 85 | + * Called when removing a value from array |
|
| 86 | + * |
|
| 87 | + * @param mixed $name |
|
| 88 | + */ |
|
| 89 | + public function offsetUnset($name) { |
|
| 90 | 90 | |
| 91 | 91 | $this->sendLog(static::TYPE_UNSET, $name, null, debug_backtrace()); |
| 92 | 92 | return call_user_func_array('parent::offsetUnset', func_get_args()); |
| 93 | - } |
|
| 93 | + } |
|
| 94 | 94 | } |
@@ -1,19 +1,19 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | function kill() { |
| 4 | - return call_user_func_array("\\PHP\\Utils::kill", func_get_args()); |
|
| 4 | + return call_user_func_array("\\PHP\\Utils::kill", func_get_args()); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | function dump_sql($sSql) { |
| 8 | - return \PHP\Utils::dump_sql($sSql); |
|
| 8 | + return \PHP\Utils::dump_sql($sSql); |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | function kill_sql($sSql) { |
| 12 | 12 | |
| 13 | - \PHP\Utils::dump_sql($sSql); |
|
| 14 | - die("FIM SQL"); |
|
| 13 | + \PHP\Utils::dump_sql($sSql); |
|
| 14 | + die("FIM SQL"); |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function debug_array(&$array) { |
| 18 | - return new \PHP\ArrayDebugger($array); |
|
| 18 | + return new \PHP\ArrayDebugger($array); |
|
| 19 | 19 | } |
@@ -5,25 +5,25 @@ discard block |
||
| 5 | 5 | class ArrayDebuggerTest extends \PHPUnit_Framework_TestCase |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - public $base = array( |
|
| 8 | + public $base = array( |
|
| 9 | 9 | 'hum' => 1, |
| 10 | 10 | 'dois' => 2, |
| 11 | 11 | 'tres' => 3 |
| 12 | - ); |
|
| 12 | + ); |
|
| 13 | 13 | |
| 14 | - public function testGetter() { |
|
| 14 | + public function testGetter() { |
|
| 15 | 15 | |
| 16 | 16 | $array = new ArrayDebugger($this->base); |
| 17 | 17 | $t = $this; |
| 18 | 18 | |
| 19 | 19 | $array->setLogger(function($retorno) use($t) { |
| 20 | - $t->assertEquals($retorno['type'], ArrayDebugger::TYPE_GET); |
|
| 20 | + $t->assertEquals($retorno['type'], ArrayDebugger::TYPE_GET); |
|
| 21 | 21 | }); |
| 22 | 22 | |
| 23 | 23 | $teste = $array['hum']; |
| 24 | 24 | |
| 25 | 25 | $array->setLogger(function($retorno) use($t) { |
| 26 | - $t->assertNotEquals($retorno['type'], ArrayDebugger::TYPE_GET); |
|
| 26 | + $t->assertNotEquals($retorno['type'], ArrayDebugger::TYPE_GET); |
|
| 27 | 27 | }); |
| 28 | 28 | |
| 29 | 29 | $array['quatro'] = 4; |
@@ -36,21 +36,21 @@ discard block |
||
| 36 | 36 | * offsetUnset |
| 37 | 37 | */ |
| 38 | 38 | unset($array['quatro']); |
| 39 | - } |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - public function testSetter() { |
|
| 41 | + public function testSetter() { |
|
| 42 | 42 | |
| 43 | 43 | $array = new ArrayDebugger($this->base); |
| 44 | 44 | |
| 45 | 45 | $t = $this; |
| 46 | 46 | $array->setLogger(function($retorno) use($t) { |
| 47 | - $t->assertEquals($retorno['type'], ArrayDebugger::TYPE_SET); |
|
| 47 | + $t->assertEquals($retorno['type'], ArrayDebugger::TYPE_SET); |
|
| 48 | 48 | }); |
| 49 | 49 | |
| 50 | 50 | $array['quatro'] = 4; |
| 51 | 51 | |
| 52 | 52 | $array->setLogger(function($retorno) use($t) { |
| 53 | - $t->assertNotEquals($retorno['type'], ArrayDebugger::TYPE_SET); |
|
| 53 | + $t->assertNotEquals($retorno['type'], ArrayDebugger::TYPE_SET); |
|
| 54 | 54 | }); |
| 55 | 55 | |
| 56 | 56 | $teste = $array['hum']; |
@@ -63,15 +63,15 @@ discard block |
||
| 63 | 63 | * offsetUnset |
| 64 | 64 | */ |
| 65 | 65 | unset($array['quatro']); |
| 66 | - } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - public function testIsset() { |
|
| 68 | + public function testIsset() { |
|
| 69 | 69 | |
| 70 | 70 | $array = new ArrayDebugger($this->base); |
| 71 | 71 | |
| 72 | 72 | $t = $this; |
| 73 | 73 | $array->setLogger(function($retorno) use($t) { |
| 74 | - $t->assertEquals($retorno['type'], ArrayDebugger::TYPE_EXISTS); |
|
| 74 | + $t->assertEquals($retorno['type'], ArrayDebugger::TYPE_EXISTS); |
|
| 75 | 75 | }); |
| 76 | 76 | |
| 77 | 77 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | isset($array['hum']); |
| 82 | 82 | |
| 83 | 83 | $array->setLogger(function($retorno) use($t) { |
| 84 | - $t->assertNotEquals($retorno['type'], ArrayDebugger::TYPE_EXISTS); |
|
| 84 | + $t->assertNotEquals($retorno['type'], ArrayDebugger::TYPE_EXISTS); |
|
| 85 | 85 | }); |
| 86 | 86 | |
| 87 | 87 | $array['quatro'] = 4; |
@@ -92,15 +92,15 @@ discard block |
||
| 92 | 92 | * offsetUnset |
| 93 | 93 | */ |
| 94 | 94 | unset($array['quatro']); |
| 95 | - } |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - public function testUnset() { |
|
| 97 | + public function testUnset() { |
|
| 98 | 98 | |
| 99 | 99 | $array = new ArrayDebugger($this->base); |
| 100 | 100 | $t = $this; |
| 101 | 101 | |
| 102 | 102 | $array->setLogger(function($retorno) use($t) { |
| 103 | - $t->assertEquals($retorno['type'], ArrayDebugger::TYPE_UNSET); |
|
| 103 | + $t->assertEquals($retorno['type'], ArrayDebugger::TYPE_UNSET); |
|
| 104 | 104 | }); |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | unset($array['dois']); |
| 110 | 110 | |
| 111 | 111 | $array->setLogger(function($retorno) use($t) { |
| 112 | - $t->assertNotEquals($retorno['type'], ArrayDebugger::TYPE_UNSET); |
|
| 112 | + $t->assertNotEquals($retorno['type'], ArrayDebugger::TYPE_UNSET); |
|
| 113 | 113 | }); |
| 114 | 114 | /** |
| 115 | 115 | * offsetExists |
@@ -120,5 +120,5 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | $teste = $array['hum']; |
| 122 | 122 | |
| 123 | - } |
|
| 123 | + } |
|
| 124 | 124 | } |