From 2a3a21144111edd4f0b0175a7e36db1e43f2d98d Mon Sep 17 00:00:00 2001 From: bkrukowski Date: Sun, 14 Jan 2018 11:23:59 +0100 Subject: [PATCH 1/7] v0.12.0 - removed deprecated method ValueInterface::getDump --- CHANGELOG.md | 4 ++++ src/Arguments/Values/DeserializedValue.php | 5 ----- src/Arguments/Values/Value.php | 5 ----- src/Arguments/Values/ValueInterface.php | 7 ------- src/StackTrace.php | 4 ++-- tests/Arguments/Values/DeserializedValueTest.php | 1 - tests/Arguments/Values/ValueTest.php | 5 ----- 7 files changed, 6 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c5c969..f0abc55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.12.0 (????-??-??) + +* Removed deprecated method `Awesomite\StackTrace\Arguments\Values\ValueInterface::getDump` + ## 0.11.0 (????-??-??) * Updated `awesomite/var-dumper` diff --git a/src/Arguments/Values/DeserializedValue.php b/src/Arguments/Values/DeserializedValue.php index a4e9651..08a55aa 100644 --- a/src/Arguments/Values/DeserializedValue.php +++ b/src/Arguments/Values/DeserializedValue.php @@ -41,11 +41,6 @@ public function dumpAsString() return $this->dumpedVariable; } - public function getDump() - { - return $this->dumpAsString(); - } - public function getRealValue() { throw new CannotRestoreValueException('Cannot restore value!'); diff --git a/src/Arguments/Values/Value.php b/src/Arguments/Values/Value.php index 67709d8..b622b5b 100644 --- a/src/Arguments/Values/Value.php +++ b/src/Arguments/Values/Value.php @@ -71,11 +71,6 @@ public function dumpAsString() return $result; } - public function getDump() - { - return $this->dumpAsString(); - } - public function isRealValueReadable() { return true; diff --git a/src/Arguments/Values/ValueInterface.php b/src/Arguments/Values/ValueInterface.php index ce945b4..6b9c3d0 100644 --- a/src/Arguments/Values/ValueInterface.php +++ b/src/Arguments/Values/ValueInterface.php @@ -32,12 +32,5 @@ public function dump(); */ public function dumpAsString(); - /** - * @deprecated - * - * @return mixed - */ - public function getDump(); - public function __toString(); } diff --git a/src/StackTrace.php b/src/StackTrace.php index 4fa620c..8424d23 100644 --- a/src/StackTrace.php +++ b/src/StackTrace.php @@ -27,8 +27,8 @@ */ class StackTrace implements StackTraceInterface { - const VERSION = '0.11.0'; - const CONSTRAINTS_VERSION = '^0.11.0'; + const VERSION = '0.12.0'; + const CONSTRAINTS_VERSION = '^0.12.0'; private $arrayStackTrace; diff --git a/tests/Arguments/Values/DeserializedValueTest.php b/tests/Arguments/Values/DeserializedValueTest.php index 847b8c5..47ed7c9 100644 --- a/tests/Arguments/Values/DeserializedValueTest.php +++ b/tests/Arguments/Values/DeserializedValueTest.php @@ -25,7 +25,6 @@ public function testAll($dump) $value = new DeserializedValue($dump); $this->assertSame($dump, (string)$value); $this->assertSame($dump, $value->dumpAsString()); - $this->assertSame($dump, $value->getDump()); $this->assertFalse($value->isRealValueReadable()); $this->expectOutputString($dump); $value->dump(); diff --git a/tests/Arguments/Values/ValueTest.php b/tests/Arguments/Values/ValueTest.php index b9a15e8..3f5518e 100644 --- a/tests/Arguments/Values/ValueTest.php +++ b/tests/Arguments/Values/ValueTest.php @@ -29,7 +29,6 @@ public function testAll(Value $value, $expectedRealValue) $this->assertTrue($value->isRealValueReadable()); $this->assertSame($expectedRealValue, $value->getRealValue()); $this->assertSame($value->dumpAsString(), (string)$value); - $this->assertSame($value->getDump(), (string)$value); $this->expectOutputString($value->dumpAsString()); $value->dump(); } @@ -65,10 +64,6 @@ public function testSerialize(Value $value) /** @var Value $restored */ $restored = \unserialize(\serialize($value)); $this->assertSame($value->dumpAsString(), $restored->dumpAsString()); - - $this->assertSame($value->dumpAsString(), $restored->getDump()); - $this->assertSame($value->getDump(), $restored->dumpAsString()); - $this->assertSame((string)$value, $restored->dumpAsString()); $this->assertSame($value->getRealValue(), $restored->getRealValue()); } From b788c40e48d4e6621bded749f8727214246c8b6a Mon Sep 17 00:00:00 2001 From: bkrukowski Date: Sun, 14 Jan 2018 11:31:00 +0100 Subject: [PATCH 2/7] * removed useless documentation * removed *.sh files, each test is executed on Travis on supported versions --- README.md | 4 -- bin/fix-phpunit.php | 11 ---- bin/hhvm-tests.sh | 8 --- bin/hhvm.sh | 3 - bin/install-composer.php | 13 ---- bin/install-local-env.sh | 5 -- bin/local-tests-docker.sh | 121 -------------------------------------- docs/TESTS.md | 68 --------------------- 8 files changed, 233 deletions(-) delete mode 100755 bin/fix-phpunit.php delete mode 100755 bin/hhvm-tests.sh delete mode 100755 bin/hhvm.sh delete mode 100755 bin/install-composer.php delete mode 100755 bin/install-local-env.sh delete mode 100755 bin/local-tests-docker.sh delete mode 100644 docs/TESTS.md diff --git a/README.md b/README.md index 1ec37f0..da12489 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,3 @@ foreach ($stackTrace as $step) { The version numbers follow the [Semantic Versioning 2.0.0](http://semver.org/) scheme. [Read more](docs/DOCUMENTATION.md#backward-compatibility) about backward compatibility. - -## Running tests - -See [documentation](docs/TESTS.md) for tests. diff --git a/bin/fix-phpunit.php b/bin/fix-phpunit.php deleted file mode 100755 index 1673020..0000000 --- a/bin/fix-phpunit.php +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env php -getFileName(); -$contents = \file_get_contents($file); - -$contents = \str_replace('= each(', '= awesomite_each(', $contents); -\file_put_contents($file, $contents); diff --git a/bin/hhvm-tests.sh b/bin/hhvm-tests.sh deleted file mode 100755 index 3f21092..0000000 --- a/bin/hhvm-tests.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -set -e - -BIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_DIR=$(dirname ${BIN_DIR}) - -docker run -it --rm --name my-running-script -v "$PROJECT_DIR":/usr/src/myapp -w /usr/src/myapp diegomarangoni/hhvm:cli hhvm vendor/bin/phpunit ${@} diff --git a/bin/hhvm.sh b/bin/hhvm.sh deleted file mode 100755 index 41ed8d3..0000000 --- a/bin/hhvm.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp diegomarangoni/hhvm:cli hhvm ${@} diff --git a/bin/install-composer.php b/bin/install-composer.php deleted file mode 100755 index 15c029a..0000000 --- a/bin/install-composer.php +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env php - Date: Sun, 14 Jan 2018 11:33:11 +0100 Subject: [PATCH 3/7] LICENCE has been formatted --- LICENSE | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/LICENSE b/LICENSE index f6d82ae..b6bf2b4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,19 @@ Copyright (c) 2016 - 2018 Bartłomiej Krukowski -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: +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 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. +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. From 1925239f8ef5dc82a0001221e3ab09c995cdfa4b Mon Sep 17 00:00:00 2001 From: bkrukowski Date: Sun, 14 Jan 2018 11:46:48 +0100 Subject: [PATCH 4/7] Allow failures on nightly and hhvm-nightly --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index e7af6d9..feee9ce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,10 +19,6 @@ php: - hhvm-3.15 - hhvm-3.18 - hhvm-nightly - -allow_failures: - - php: nightly - - php: hhvm-nightly env: matrix: @@ -30,6 +26,10 @@ env: - DEPENDENCIES="low" matrix: + allow_failures: + - php: nightly + - php: hhvm-nightly + include: - php: 5.3 dist: precise From d63c86172e64522271f40a96ecc0bc281d78f0eb Mon Sep 17 00:00:00 2001 From: bkrukowski Date: Sun, 14 Jan 2018 11:53:10 +0100 Subject: [PATCH 5/7] Added keywords --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3ed1ce3..344a2c7 100644 --- a/composer.json +++ b/composer.json @@ -30,5 +30,6 @@ "sebastian/comparator": ">=1.2.3", "symfony/console": "^2.7 || ^3.0", "awesomite/phpunit-4.8-fixer": "^1.0" - } + }, + "keywords": ["debug", "debug_backtrace"] } From d80dfbe1cb98bbbebc3d5f9385d18287e85e4b93 Mon Sep 17 00:00:00 2001 From: bkrukowski Date: Sun, 14 Jan 2018 12:04:56 +0100 Subject: [PATCH 6/7] Updated README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index da12489..215a7c8 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ use Awesomite\StackTrace\StackTraceFactory; $factory = new StackTraceFactory(); $stackTrace = $factory->create(); foreach ($stackTrace as $step) { + /** @var StepInterface $step */ $placeInCode = $step->getPlaceInCode(); $line = $placeInCode->getLineNumber(); $fileName = $placeInCode->getFileName(); From 3aacc77a05b37eea0e083dfa7b060d8034277995 Mon Sep 17 00:00:00 2001 From: bkrukowski Date: Sun, 14 Jan 2018 12:59:10 +0100 Subject: [PATCH 7/7] * added examples * updated readme --- .gitattributes | 1 + .php_cs.dist | 2 +- .travis.yml | 1 + README.md | 34 +++++++++-- examples/StackTracePrinter.php | 104 +++++++++++++++++++++++++++++++++ examples/read-arguments.php | 83 ++++++++++++++++++++++++++ src/Functions/AFunction.php | 4 +- 7 files changed, 222 insertions(+), 7 deletions(-) create mode 100644 examples/StackTracePrinter.php create mode 100644 examples/read-arguments.php diff --git a/.gitattributes b/.gitattributes index 8e184d6..a66312a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,6 @@ /bin export-ignore /dev-tools export-ignore +/examples export-ignore /tests export-ignore /.coveralls.yml export-ignore /.gitattributes export-ignore diff --git a/.php_cs.dist b/.php_cs.dist index de8e005..be9eaca 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -2,6 +2,7 @@ $finder = PhpCsFixer\Finder::create() ->in(__DIR__ . DIRECTORY_SEPARATOR . 'bin') + ->in(__DIR__ . DIRECTORY_SEPARATOR . 'examples') ->in(__DIR__ . DIRECTORY_SEPARATOR . 'src') ->in(__DIR__ . DIRECTORY_SEPARATOR . 'tests') ->notName('StackTraceTest.php') @@ -23,7 +24,6 @@ return PhpCsFixer\Config::create() 'no_unused_imports' => true, 'yoda_style' => true, 'new_with_braces' => true, - 'mb_str_functions' => true, 'native_function_invocation' => true, 'header_comment' => array('header' => $header), 'phpdoc_align' => true, diff --git a/.travis.yml b/.travis.yml index feee9ce..23acdb9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -74,6 +74,7 @@ before_script: script: - if [[ "$RUN_CS_FIXER" = "true" ]]; then php -n ${PHP_CS_FIXER} --diff --dry-run -v --allow-risky=yes fix; fi - php ${PHP_ARGS} vendor/bin/phpunit + - php ${PHP_ARGS} examples/read-arguments.php after_script: - mv ~.git .git diff --git a/README.md b/README.md index 215a7c8..26cf06a 100644 --- a/README.md +++ b/README.md @@ -5,24 +5,42 @@ [![Build Status](https://travis-ci.org/awesomite/stack-trace.svg?branch=master)](https://travis-ci.org/awesomite/stack-trace) Abstract layer for [`debug_backtrace()`](http://php.net/manual/en/function.debug-backtrace.php) function. +This library allows you to serialize whole stack trace including variables. +It handles all types of data, including resources. ## Usage See [documentation](docs/DOCUMENTATION.md). ```php +create(); foreach ($stackTrace as $step) { /** @var StepInterface $step */ - $placeInCode = $step->getPlaceInCode(); - $line = $placeInCode->getLineNumber(); - $fileName = $placeInCode->getFileName(); + $function = $step->getCalledFunction()->getName(); - echo "Function {$function} is called from {$fileName}:{$line}\n"; + echo "Function {$function}"; + + if ($step->hasPlaceInCode()) { + /** @var PlaceInCodeInterface $placeInCode */ + $placeInCode = $step->getPlaceInCode(); + $fileName = $placeInCode->getFileName(); + $line = $placeInCode->getLineNumber(); + $function = $step->getCalledFunction()->getName(); + echo " is called from {$fileName}:{$line}"; + } + + echo "\n"; } + +$data = serialize($stackTrace); +$unserializedStackTrace = unserialize($data); ``` ## Installation @@ -33,3 +51,11 @@ foreach ($stackTrace as $step) { The version numbers follow the [Semantic Versioning 2.0.0](http://semver.org/) scheme. [Read more](docs/DOCUMENTATION.md#backward-compatibility) about backward compatibility. + +## Examples + +[See](examples) more examples. + +## License + +This library is released under the [MIT license](LICENSE). diff --git a/examples/StackTracePrinter.php b/examples/StackTracePrinter.php new file mode 100644 index 0000000..433d381 --- /dev/null +++ b/examples/StackTracePrinter.php @@ -0,0 +1,104 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Awesomite\StackTrace\Arguments\ArgumentInterface; +use Awesomite\StackTrace\Arguments\ArgumentsInterface; +use Awesomite\StackTrace\StackTraceFactory; +use Awesomite\StackTrace\Steps\StepInterface; + +/** + * @internal + */ +class StackTracePrinter +{ + public function printStackTrace() + { + $factory = new StackTraceFactory(); + $stackTrace = $factory->create(); + $i = 0; + foreach ($stackTrace as $step) { + $this->printStep($step, ++$i); + } + } + + private function printStep(StepInterface $step, $i) + { + $function = $step->getCalledFunction()->getName(); + + echo "#{$i} {$function}("; + $arguments = $step->getArguments(); + $first = true; + foreach ($arguments as $argument) { + if ($argument->hasDeclaration()) { + if ($first) { + $first = false; + } else { + echo ', '; + } + + echo '$' . $argument->getDeclaration()->getName(); + } else { + break; + } + } + echo ")\n"; + + if ($step->hasPlaceInCode()) { + echo " Place in code:\n"; + $placeInCode = $step->getPlaceInCode(); + $fileName = $this->shortFileName($placeInCode->getFileName()); + echo " {$fileName}:{$placeInCode->getLineNumber()}\n"; + } + + $this->printArguments($step->getArguments()); + } + + /** + * @param ArgumentsInterface|ArgumentInterface[] $arguments + */ + private function printArguments($arguments) + { + if (!\count($arguments)) { + return; + } + + echo " Arguments:\n"; + + foreach ($arguments as $argument) { + $dump = $argument->hasValue() + ? $argument->getValue()->dumpAsString() + : "undefined\n"; + + $tabs = " "; + + $dump = \substr($dump, 0, -1); + $dump = $tabs . \str_replace("\n", "\n", $dump) . "\n"; + echo $dump; + } + } + + private function shortFileName($file) + { + $exploded = \explode(DIRECTORY_SEPARATOR, $file); + $shifted = false; + while (\count($exploded) > 3) { + \array_shift($exploded); + $shifted = true; + } + + if ($shifted) { + \array_unshift($exploded, '(...)'); + } + + + return \implode(DIRECTORY_SEPARATOR, $exploded); + } +} diff --git a/examples/read-arguments.php b/examples/read-arguments.php new file mode 100644 index 0000000..76c4abd --- /dev/null +++ b/examples/read-arguments.php @@ -0,0 +1,83 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +require \implode(DIRECTORY_SEPARATOR, array(__DIR__, '..', 'vendor', 'autoload.php')); +require __DIR__ . DIRECTORY_SEPARATOR . 'StackTracePrinter.php'; + +/** + * @internal + * + * @param $arg1 + * @param $arg2 + */ +function myFirstFunction($arg1, $arg2) +{ + mySecondFunction('foo', 'bar'); +} + +/** + * @internal + * + * @param $foo + * @param $bar + */ +function mySecondFunction($foo, $bar) +{ + myThirdFunction(\tmpfile(), M_PI); +} + +/** + * @internal + * + * @param $argument1 + * @param $argument2 + */ +function myThirdFunction($argument1, $argument2) +{ + $printer = new StackTracePrinter(); + $printer->printStackTrace(); +} + +myFirstFunction('hello', 'world'); + +/* + +Output: + +#1 Awesomite\StackTrace\StackTraceFactory->create($stepLimit, $ignoreArgs) + Place in code: + (...)/stack-trace/examples/StackTracePrinter.php:25 + Arguments: + undefined + undefined +#2 StackTracePrinter->printStackTrace() + Place in code: + (...)/stack-trace/examples/read-arguments.php:46 +#3 myThirdFunction($argument1, $argument2) + Place in code: + (...)/stack-trace/examples/read-arguments.php:34 + Arguments: + resource #10 of type stream + M_PI +#4 mySecondFunction($foo, $bar) + Place in code: + (...)/stack-trace/examples/read-arguments.php:23 + Arguments: + “foo” + “bar” +#5 myFirstFunction($arg1, $arg2) + Place in code: + (...)/stack-trace/examples/read-arguments.php:49 + Arguments: + “hello” + “world” + +*/ diff --git a/src/Functions/AFunction.php b/src/Functions/AFunction.php index f567c34..a3bec3e 100644 --- a/src/Functions/AFunction.php +++ b/src/Functions/AFunction.php @@ -48,7 +48,7 @@ public function getName() public function isClosure() { - return false !== \mb_strpos($this->arrayStep['function'], '{closure}'); + return false !== \strpos($this->arrayStep['function'], '{closure}'); } public function isInClass() @@ -108,7 +108,7 @@ private function hasDeprecatedTag(\ReflectionFunctionAbstract $function) { $comment = $function->getDocComment(); - return false !== $comment && false !== \mb_strpos($comment, '@deprecated'); + return false !== $comment && false !== \strpos($comment, '@deprecated'); } private function createReflection()