first commit

This commit is contained in:
CHIEFSOFT\ameye
2025-11-22 09:54:51 -05:00
commit 07a07ab49f
722 changed files with 125787 additions and 0 deletions
+190
View File
@@ -0,0 +1,190 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use Kint\Value\Context\ContextInterface;
use Kint\Value\Representation\RepresentationInterface;
use OutOfRangeException;
/**
* @psalm-import-type ValueName from ContextInterface
*
* @psalm-type ValueFlags int-mask-of<AbstractValue::FLAG_*>
*/
abstract class AbstractValue
{
public const FLAG_NONE = 0;
public const FLAG_GENERATED = 1 << 0;
public const FLAG_BLACKLIST = 1 << 1;
public const FLAG_RECURSION = 1 << 2;
public const FLAG_DEPTH_LIMIT = 1 << 3;
public const FLAG_ARRAY_LIMIT = 1 << 4;
/** @psalm-var ValueFlags */
public int $flags = self::FLAG_NONE;
/** @psalm-readonly */
protected ContextInterface $context;
/** @psalm-readonly string */
protected string $type;
/** @psalm-var RepresentationInterface[] */
protected array $representations = [];
public function __construct(ContextInterface $context, string $type)
{
$this->context = $context;
$this->type = $type;
}
public function __clone()
{
$this->context = clone $this->context;
}
public function getContext(): ContextInterface
{
return $this->context;
}
public function getHint(): ?string
{
if (self::FLAG_NONE === $this->flags) {
return null;
}
if ($this->flags & self::FLAG_BLACKLIST) {
return 'blacklist';
}
if ($this->flags & self::FLAG_RECURSION) {
return 'recursion';
}
if ($this->flags & self::FLAG_DEPTH_LIMIT) {
return 'depth_limit';
}
if ($this->flags & self::FLAG_ARRAY_LIMIT) {
return 'array_limit';
}
return null;
}
public function getType(): string
{
return $this->type;
}
public function addRepresentation(RepresentationInterface $rep, ?int $pos = null): void
{
if (isset($this->representations[$rep->getName()])) {
throw new OutOfRangeException('Representation already exists');
}
if (null === $pos) {
$this->representations[$rep->getName()] = $rep;
} else {
$this->representations = \array_merge(
\array_slice($this->representations, 0, $pos),
[$rep->getName() => $rep],
\array_slice($this->representations, $pos)
);
}
}
public function replaceRepresentation(RepresentationInterface $rep, ?int $pos = null): void
{
if (null === $pos) {
$this->representations[$rep->getName()] = $rep;
} else {
$this->removeRepresentation($rep);
$this->addRepresentation($rep, $pos);
}
}
/**
* @param RepresentationInterface|string $rep
*/
public function removeRepresentation($rep): void
{
if ($rep instanceof RepresentationInterface) {
unset($this->representations[$rep->getName()]);
} else { // String
unset($this->representations[$rep]);
}
}
public function getRepresentation(string $name): ?RepresentationInterface
{
return $this->representations[$name] ?? null;
}
/** @psalm-return RepresentationInterface[] */
public function getRepresentations(): array
{
return $this->representations;
}
/** @psalm-param RepresentationInterface[] $reps */
public function appendRepresentations(array $reps): void
{
foreach ($reps as $rep) {
$this->addRepresentation($rep);
}
}
/** @psalm-api */
public function clearRepresentations(): void
{
$this->representations = [];
}
public function getDisplayType(): string
{
return $this->type;
}
public function getDisplayName(): string
{
return (string) $this->context->getName();
}
public function getDisplaySize(): ?string
{
return null;
}
public function getDisplayValue(): ?string
{
return null;
}
/** @psalm-return AbstractValue[] */
public function getDisplayChildren(): array
{
return [];
}
}
+71
View File
@@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use Kint\Value\Context\ContextInterface;
class ArrayValue extends AbstractValue
{
/** @psalm-readonly */
protected int $size;
/**
* @psalm-readonly
*
* @psalm-var AbstractValue[]
*/
protected array $contents;
/** @psalm-param AbstractValue[] $contents */
public function __construct(ContextInterface $context, int $size, array $contents)
{
parent::__construct($context, 'array');
$this->size = $size;
$this->contents = $contents;
}
public function getSize(): int
{
return $this->size;
}
/** @psalm-return AbstractValue[] */
public function getContents()
{
return $this->contents;
}
public function getDisplaySize(): string
{
return (string) $this->size;
}
public function getDisplayChildren(): array
{
return $this->contents;
}
}
+43
View File
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use Kint\Value\Context\ContextInterface;
class ClosedResourceValue extends AbstractValue
{
public function __construct(ContextInterface $context)
{
parent::__construct($context, 'resource (closed)');
}
public function getDisplayType(): string
{
return 'closed resource';
}
}
+120
View File
@@ -0,0 +1,120 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use Closure;
use Kint\Utils;
use Kint\Value\Context\BaseContext;
use Kint\Value\Context\ContextInterface;
use ReflectionFunction;
class ClosureValue extends InstanceValue
{
use ParameterHoldingTrait;
/** @psalm-readonly */
protected ?string $filename;
/** @psalm-readonly */
protected ?int $startline;
public function __construct(ContextInterface $context, Closure $cl)
{
parent::__construct($context, \get_class($cl), \spl_object_hash($cl), \spl_object_id($cl));
/**
* @psalm-suppress UnnecessaryVarAnnotation
*
* @psalm-var ContextInterface $this->context
* Psalm bug #11113
*/
$closure = new ReflectionFunction($cl);
if ($closure->isUserDefined()) {
$this->filename = $closure->getFileName();
$this->startline = $closure->getStartLine();
} else {
$this->filename = null;
$this->startline = null;
}
$parameters = [];
foreach ($closure->getParameters() as $param) {
$parameters[] = new ParameterBag($param);
}
$this->parameters = $parameters;
if (!$this->context instanceof BaseContext) {
return;
}
if (0 !== $this->context->getDepth()) {
return;
}
$ap = $this->context->getAccessPath();
if (null === $ap) {
return;
}
if (\preg_match('/^\\((function|fn)\\s*\\(/i', $ap, $match)) {
$this->context->name = \strtolower($match[1]);
}
}
/** @psalm-api */
public function getFileName(): ?string
{
return $this->filename;
}
/** @psalm-api */
public function getStartLine(): ?int
{
return $this->startline;
}
public function getDisplaySize(): ?string
{
return null;
}
public function getDisplayName(): string
{
return $this->context->getName().'('.$this->getParams().')';
}
public function getDisplayValue(): ?string
{
if (null !== $this->filename && null !== $this->startline) {
return Utils::shortenPath($this->filename).':'.$this->startline;
}
return parent::getDisplayValue();
}
}
+36
View File
@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
class ColorValue extends StringValue
{
public function getHint(): string
{
return parent::getHint() ?? 'color';
}
}
+36
View File
@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Context;
class ArrayContext extends BaseContext
{
public function getOperator(): ?string
{
return '=>';
}
}
+83
View File
@@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Context;
use InvalidArgumentException;
/**
* @psalm-import-type ValueName from ContextInterface
*/
class BaseContext implements ContextInterface
{
/** @psalm-var ValueName */
public $name;
public int $depth = 0;
public bool $reference = false;
public ?string $access_path = null;
/** @psalm-param mixed $name */
public function __construct($name)
{
if (!\is_string($name) && !\is_int($name)) {
throw new InvalidArgumentException('Context names must be string|int');
}
$this->name = $name;
}
public function getName()
{
return $this->name;
}
public function getDepth(): int
{
return $this->depth;
}
public function getOperator(): ?string
{
return null;
}
public function isRef(): bool
{
return $this->reference;
}
/** @psalm-param ?class-string $scope */
public function isAccessible(?string $scope): bool
{
return true;
}
public function getAccessPath(): ?string
{
return $this->access_path;
}
}
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Context;
class ClassConstContext extends ClassDeclaredContext
{
public bool $final = false;
public function getName(): string
{
return $this->owner_class.'::'.$this->name;
}
public function getOperator(): string
{
return '::';
}
public function getModifiers(): string
{
$final = $this->final ? 'final ' : '';
return $final.$this->getAccess().' const';
}
}
@@ -0,0 +1,94 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Context;
use __PHP_Incomplete_Class;
abstract class ClassDeclaredContext extends ClassOwnedContext
{
public const ACCESS_PUBLIC = 1;
public const ACCESS_PROTECTED = 2;
public const ACCESS_PRIVATE = 3;
/** @psalm-var self::ACCESS_* */
public int $access;
/**
* @psalm-param class-string $owner_class
* @psalm-param self::ACCESS_* $access
*/
public function __construct(string $name, string $owner_class, int $access)
{
parent::__construct($name, $owner_class);
$this->access = $access;
}
abstract public function getModifiers(): string;
/** @psalm-param ?class-string $scope */
public function isAccessible(?string $scope): bool
{
if (__PHP_Incomplete_Class::class === $this->owner_class) {
return false;
}
if (self::ACCESS_PUBLIC === $this->access) {
return true;
}
if (null === $scope) {
return false;
}
if (self::ACCESS_PRIVATE === $this->access) {
return $scope === $this->owner_class;
}
if (\is_a($scope, $this->owner_class, true)) {
return true;
}
if (\is_a($this->owner_class, $scope, true)) {
return true;
}
return false;
}
protected function getAccess(): string
{
switch ($this->access) {
case self::ACCESS_PUBLIC:
return 'public';
case self::ACCESS_PROTECTED:
return 'protected';
case self::ACCESS_PRIVATE:
return 'private';
}
}
}
@@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Context;
use __PHP_Incomplete_Class;
class ClassOwnedContext extends BaseContext
{
/** @psalm-var class-string */
public string $owner_class;
/** @psalm-param class-string $owner_class */
public function __construct(string $name, string $owner_class)
{
parent::__construct($name);
$this->owner_class = $owner_class;
}
public function getName(): string
{
return (string) $this->name;
}
public function getOperator(): string
{
return '->';
}
/** @psalm-param ?class-string $scope */
public function isAccessible(?string $scope): bool
{
return __PHP_Incomplete_Class::class !== $this->owner_class;
}
}
@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Context;
/**
* Contexts represent the data that has to be found out about a zval _before_
* passing it into the next parse depth. This includes the access path, whether
* it's a reference or not, and OOP related stuff like visibility.
*
* @psalm-type ValueName = string|int
*/
interface ContextInterface
{
/** @psalm-return ValueName */
public function getName();
public function getDepth(): int;
public function isRef(): bool;
/** @psalm-param ?class-string $scope */
public function isAccessible(?string $scope): bool;
public function getAccessPath(): ?string;
/** @psalm-return ?non-empty-string */
public function getOperator(): ?string;
}
@@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Context;
abstract class DoubleAccessMemberContext extends ClassDeclaredContext
{
/** @psalm-var ?self::ACCESS_* */
public ?int $access_set = null;
protected function getAccess(): string
{
switch ($this->access) {
case self::ACCESS_PUBLIC:
if (self::ACCESS_PRIVATE === $this->access_set) {
return 'private(set)';
}
if (self::ACCESS_PROTECTED === $this->access_set) {
return 'protected(set)';
}
return 'public';
case self::ACCESS_PROTECTED:
if (self::ACCESS_PRIVATE === $this->access_set) {
return 'protected private(set)';
}
return 'protected';
case self::ACCESS_PRIVATE:
return 'private';
}
}
}
+140
View File
@@ -0,0 +1,140 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Context;
use Kint\Value\InstanceValue;
use ReflectionMethod;
class MethodContext extends ClassDeclaredContext
{
public const MAGIC_NAMES = [
'__construct' => true,
'__destruct' => true,
'__call' => true,
'__callstatic' => true,
'__get' => true,
'__set' => true,
'__isset' => true,
'__unset' => true,
'__sleep' => true,
'__wakeup' => true,
'__serialize' => true,
'__unserialize' => true,
'__tostring' => true,
'__invoke' => true,
'__set_state' => true,
'__clone' => true,
'__debuginfo' => true,
];
public bool $final = false;
public bool $abstract = false;
public bool $static = false;
/**
* Whether the method was inherited from a parent class or interface.
*
* It's important to note that we never show static methods as
* "inherited" except when abstract via an interface.
*/
public bool $inherited = false;
public function __construct(ReflectionMethod $method)
{
parent::__construct(
$method->getName(),
$method->getDeclaringClass()->name,
ClassDeclaredContext::ACCESS_PUBLIC
);
$this->depth = 1;
$this->static = $method->isStatic();
$this->abstract = $method->isAbstract();
$this->final = $method->isFinal();
if ($method->isProtected()) {
$this->access = ClassDeclaredContext::ACCESS_PROTECTED;
} elseif ($method->isPrivate()) {
$this->access = ClassDeclaredContext::ACCESS_PRIVATE;
}
}
public function getOperator(): string
{
if ($this->static) {
return '::';
}
return '->';
}
public function getModifiers(): string
{
if ($this->abstract) {
$out = 'abstract ';
} elseif ($this->final) {
$out = 'final ';
} else {
$out = '';
}
$out .= $this->getAccess();
if ($this->static) {
$out .= ' static';
}
return $out;
}
public function setAccessPathFromParent(?InstanceValue $parent): void
{
$name = \strtolower($this->getName());
if ($this->static && !isset(self::MAGIC_NAMES[$name])) {
$this->access_path = '\\'.$this->owner_class.'::'.$this->name.'()';
} elseif (null === $parent) {
$this->access_path = null;
} else {
$c = $parent->getContext();
if ('__construct' === $name) {
$this->access_path = 'new \\'.$parent->getClassName().'()';
} elseif (null === $c->getAccessPath()) {
$this->access_path = null;
} elseif ('__invoke' === $name) {
$this->access_path = $c->getAccessPath().'()';
} elseif ('__clone' === $name) {
$this->access_path = 'clone '.$c->getAccessPath();
} elseif ('__tostring' === $name) {
$this->access_path = '(string) '.$c->getAccessPath();
} elseif (isset(self::MAGIC_NAMES[$name])) {
$this->access_path = null;
} else {
$this->access_path = $c->getAccessPath().'->'.$this->name.'()';
}
}
}
}
@@ -0,0 +1,78 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Context;
class PropertyContext extends DoubleAccessMemberContext
{
public const HOOK_NONE = 0;
public const HOOK_GET = 1 << 0;
public const HOOK_GET_REF = 1 << 1;
public const HOOK_SET = 1 << 2;
public const HOOK_SET_TYPE = 1 << 3;
public bool $readonly = false;
/** @psalm-var int-mask-of<self::HOOK_*> */
public int $hooks = self::HOOK_NONE;
public ?string $hook_set_type = null;
public function getModifiers(): string
{
$out = $this->getAccess();
if ($this->readonly) {
$out .= ' readonly';
}
return $out;
}
public function getHooks(): ?string
{
if (self::HOOK_NONE === $this->hooks) {
return null;
}
$out = '{ ';
if ($this->hooks & self::HOOK_GET) {
if ($this->hooks & self::HOOK_GET_REF) {
$out .= '&';
}
$out .= 'get; ';
}
if ($this->hooks & self::HOOK_SET) {
if ($this->hooks & self::HOOK_SET_TYPE && '' !== ($this->hook_set_type ?? '')) {
$out .= 'set('.$this->hook_set_type.'); ';
} else {
$out .= 'set; ';
}
}
$out .= '}';
return $out;
}
}
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Context;
class StaticPropertyContext extends DoubleAccessMemberContext
{
public bool $final = false;
public function getName(): string
{
return $this->owner_class.'::$'.$this->name;
}
public function getOperator(): string
{
return '::';
}
public function getModifiers(): string
{
$final = $this->final ? 'final ' : '';
return $final.$this->getAccess().' static';
}
}
+65
View File
@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use DateTimeInterface;
use Kint\Value\Context\ContextInterface;
class DateTimeValue extends InstanceValue
{
/** @psalm-readonly */
protected DateTimeInterface $dt;
public function __construct(ContextInterface $context, DateTimeInterface $dt)
{
parent::__construct($context, \get_class($dt), \spl_object_hash($dt), \spl_object_id($dt));
$this->dt = clone $dt;
}
public function getHint(): string
{
return parent::getHint() ?? 'datetime';
}
public function getDisplayValue(): string
{
$stamp = $this->dt->format('Y-m-d H:i:s');
if ((int) ($micro = $this->dt->format('u'))) {
$stamp .= '.'.$micro;
}
$stamp .= $this->dt->format(' P');
$tzn = $this->dt->getTimezone()->getName();
if ('+' !== $tzn[0] && '-' !== $tzn[0]) {
$stamp .= $this->dt->format(' T');
}
return $stamp;
}
}
+81
View File
@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use Kint\Utils;
use ReflectionFunctionAbstract;
/** @psalm-api */
final class DeclaredCallableBag
{
use ParameterHoldingTrait;
/** @psalm-readonly */
public bool $internal;
/** @psalm-readonly */
public ?string $filename;
/** @psalm-readonly */
public ?int $startline;
/** @psalm-readonly */
public ?int $endline;
/**
* @psalm-readonly
*
* @psalm-var ?non-empty-string
*/
public ?string $docstring;
/** @psalm-readonly */
public bool $return_reference;
/** @psalm-readonly */
public ?string $returntype = null;
public function __construct(ReflectionFunctionAbstract $callable)
{
$this->internal = $callable->isInternal();
$t = $callable->getFileName();
$this->filename = false === $t ? null : $t;
$t = $callable->getStartLine();
$this->startline = false === $t ? null : $t;
$t = $callable->getEndLine();
$this->endline = false === $t ? null : $t;
$t = $callable->getDocComment();
$this->docstring = false === $t ? null : $t;
$this->return_reference = $callable->returnsReference();
$rt = $callable->getReturnType();
if ($rt) {
$this->returntype = Utils::getTypeString($rt);
}
$parameters = [];
foreach ($callable->getParameters() as $param) {
$parameters[] = new ParameterBag($param);
}
$this->parameters = $parameters;
}
}
+57
View File
@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use Dom\NodeList;
use DOMNodeList;
use Kint\Value\Context\ContextInterface;
class DomNodeListValue extends InstanceValue
{
protected int $length;
/**
* @psalm-param DOMNodeList|NodeList $node
*/
public function __construct(ContextInterface $context, object $node)
{
parent::__construct($context, \get_class($node), \spl_object_hash($node), \spl_object_id($node));
$this->length = $node->length;
}
public function getLength(): int
{
return $this->length;
}
public function getDisplaySize(): string
{
return (string) $this->length;
}
}
+48
View File
@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use Dom\Node;
use DOMNode;
use Kint\Value\Context\ContextInterface;
class DomNodeValue extends InstanceValue
{
/**
* @psalm-param DOMNode|Node $node
*/
public function __construct(ContextInterface $context, object $node)
{
parent::__construct($context, \get_class($node), \spl_object_hash($node), \spl_object_id($node));
}
public function getDisplaySize(): ?string
{
return null;
}
}
+68
View File
@@ -0,0 +1,68 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use BackedEnum;
use Kint\Value\Context\ContextInterface;
use UnitEnum;
class EnumValue extends InstanceValue
{
/** @psalm-readonly */
protected UnitEnum $enumval;
public function __construct(ContextInterface $context, UnitEnum $enumval)
{
parent::__construct($context, \get_class($enumval), \spl_object_hash($enumval), \spl_object_id($enumval));
$this->enumval = $enumval;
}
public function getHint(): string
{
return parent::getHint() ?? 'enum';
}
public function getDisplayType(): string
{
return $this->classname.'::'.$this->enumval->name;
}
public function getDisplayValue(): ?string
{
if ($this->enumval instanceof BackedEnum) {
if (\is_string($this->enumval->value)) {
return '"'.$this->enumval->value.'"';
}
return (string) $this->enumval->value;
}
return null;
}
}
+85
View File
@@ -0,0 +1,85 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use InvalidArgumentException;
use Kint\Value\Context\ContextInterface;
/**
* @psalm-type FixedWidthType = null|boolean|integer|double
*/
class FixedWidthValue extends AbstractValue
{
/**
* @psalm-readonly
*
* @psalm-var FixedWidthType
*/
protected $value;
/** @psalm-param FixedWidthType $value */
public function __construct(ContextInterface $context, $value)
{
$type = \strtolower(\gettype($value));
if ('null' === $type || 'boolean' === $type || 'integer' === $type || 'double' === $type) {
parent::__construct($context, $type);
$this->value = $value;
} else {
throw new InvalidArgumentException('FixedWidthValue can only contain fixed width types, got '.$type);
}
}
/**
* @psalm-api
*
* @psalm-return FixedWidthType
*/
public function getValue()
{
return $this->value;
}
public function getDisplaySize(): ?string
{
return null;
}
public function getDisplayValue(): ?string
{
if ('boolean' === $this->type) {
return ((bool) $this->value) ? 'true' : 'false';
}
if ('integer' === $this->type || 'double' === $this->type) {
return (string) $this->value;
}
return null;
}
}
+98
View File
@@ -0,0 +1,98 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use Kint\Value\Context\ContextInterface;
use Kint\Value\Representation\CallableDefinitionRepresentation;
class FunctionValue extends AbstractValue
{
/** @psalm-readonly */
protected DeclaredCallableBag $callable_bag;
/** @psalm-readonly */
protected ?CallableDefinitionRepresentation $definition_rep;
public function __construct(ContextInterface $c, DeclaredCallableBag $bag)
{
parent::__construct($c, 'function');
$this->callable_bag = $bag;
if ($this->callable_bag->internal) {
$this->definition_rep = null;
return;
}
/**
* @psalm-var string $this->callable_bag->filename
* @psalm-var int $this->callable_bag->startline
* Psalm issue #11121
*/
$this->definition_rep = new CallableDefinitionRepresentation(
$this->callable_bag->filename,
$this->callable_bag->startline,
$this->callable_bag->docstring
);
$this->addRepresentation($this->definition_rep);
}
public function getCallableBag(): DeclaredCallableBag
{
return $this->callable_bag;
}
/** @psalm-api */
public function getDefinitionRepresentation(): ?CallableDefinitionRepresentation
{
return $this->definition_rep;
}
public function getDisplayName(): string
{
return $this->context->getName().'('.$this->callable_bag->getParams().')';
}
public function getDisplayValue(): ?string
{
if ($this->definition_rep instanceof CallableDefinitionRepresentation) {
return $this->definition_rep->getDocstringFirstLine();
}
return parent::getDisplayValue();
}
public function getPhpDocUrl(): ?string
{
if (!$this->callable_bag->internal) {
return null;
}
return 'https://www.php.net/function.'.\str_replace('_', '-', \strtolower((string) $this->context->getName()));
}
}
+111
View File
@@ -0,0 +1,111 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use Kint\Value\Context\ContextInterface;
class InstanceValue extends AbstractValue
{
/**
* @psalm-readonly
*
* @psalm-var class-string
*/
protected string $classname;
/** @psalm-readonly */
protected string $spl_object_hash;
/** @psalm-readonly */
protected int $spl_object_id;
/**
* The canonical children of this value, for text renderers.
*
* @psalm-var null|list<AbstractValue>
*/
protected ?array $children = null;
/** @psalm-param class-string $classname */
public function __construct(
ContextInterface $context,
string $classname,
string $spl_object_hash,
int $spl_object_id
) {
parent::__construct($context, 'object');
$this->classname = $classname;
$this->spl_object_hash = $spl_object_hash;
$this->spl_object_id = $spl_object_id;
}
/** @psalm-return class-string */
public function getClassName(): string
{
return $this->classname;
}
public function getSplObjectHash(): string
{
return $this->spl_object_hash;
}
public function getSplObjectId(): int
{
return $this->spl_object_id;
}
/** @psalm-param null|list<AbstractValue> $children */
public function setChildren(?array $children): void
{
$this->children = $children;
}
/** @psalm-return null|list<AbstractValue> */
public function getChildren(): ?array
{
return $this->children;
}
public function getDisplayType(): string
{
return $this->classname;
}
public function getDisplaySize(): ?string
{
if (null === $this->children) {
return null;
}
return (string) \count($this->children);
}
public function getDisplayChildren(): array
{
return $this->children ?? [];
}
}
+135
View File
@@ -0,0 +1,135 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use Kint\Value\Context\ClassDeclaredContext;
use Kint\Value\Context\MethodContext;
use Kint\Value\Representation\CallableDefinitionRepresentation;
class MethodValue extends AbstractValue
{
/** @psalm-readonly */
protected DeclaredCallableBag $callable_bag;
/** @psalm-readonly */
protected ?CallableDefinitionRepresentation $definition_rep;
public function __construct(MethodContext $c, DeclaredCallableBag $bag)
{
parent::__construct($c, 'method');
$this->callable_bag = $bag;
if ($this->callable_bag->internal) {
$this->definition_rep = null;
return;
}
/**
* @psalm-var string $this->callable_bag->filename
* @psalm-var int $this->callable_bag->startline
* Psalm issue #11121
*/
$this->definition_rep = new CallableDefinitionRepresentation(
$this->callable_bag->filename,
$this->callable_bag->startline,
$this->callable_bag->docstring
);
$this->addRepresentation($this->definition_rep);
}
public function getHint(): string
{
return parent::getHint() ?? 'callable';
}
public function getContext(): MethodContext
{
/**
* @psalm-var MethodContext $this->context
* Psalm discuss #11116
*/
return $this->context;
}
public function getCallableBag(): DeclaredCallableBag
{
return $this->callable_bag;
}
/** @psalm-api */
public function getDefinitionRepresentation(): ?CallableDefinitionRepresentation
{
return $this->definition_rep;
}
public function getFullyQualifiedDisplayName(): string
{
$c = $this->getContext();
return $c->owner_class.'::'.$c->getName().'('.$this->callable_bag->getParams().')';
}
public function getDisplayName(): string
{
$c = $this->getContext();
if ($c->static || (ClassDeclaredContext::ACCESS_PRIVATE === $c->access && $c->inherited)) {
return $this->getFullyQualifiedDisplayName();
}
return $c->getName().'('.$this->callable_bag->getParams().')';
}
public function getDisplayValue(): ?string
{
if ($this->definition_rep instanceof CallableDefinitionRepresentation) {
return $this->definition_rep->getDocstringFirstLine();
}
return parent::getDisplayValue();
}
public function getPhpDocUrl(): ?string
{
if (!$this->callable_bag->internal) {
return null;
}
$c = $this->getContext();
$class = \str_replace('\\', '-', \strtolower($c->owner_class));
$funcname = \str_replace('_', '-', \strtolower($c->getName()));
if (0 === \strpos($funcname, '--') && 0 !== \strpos($funcname, '-', 2)) {
$funcname = \substr($funcname, 2);
}
return 'https://www.php.net/'.$class.'.'.$funcname;
}
}
+63
View File
@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
class MicrotimeValue extends AbstractValue
{
/** @psalm-readonly */
protected AbstractValue $wrapped;
public function __construct(AbstractValue $old)
{
$this->context = $old->context;
$this->type = $old->type;
$this->flags = $old->flags;
$this->representations = $old->representations;
$this->wrapped = $old;
}
public function getHint(): string
{
return parent::getHint() ?? 'microtime';
}
public function getDisplaySize(): ?string
{
return $this->wrapped->getDisplaySize();
}
public function getDisplayValue(): ?string
{
return $this->wrapped->getDisplayValue();
}
public function getDisplayType(): string
{
return $this->wrapped->getDisplayType();
}
}
+99
View File
@@ -0,0 +1,99 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use Kint\Utils;
use ReflectionParameter;
final class ParameterBag
{
/** @psalm-readonly */
public string $name;
/** @psalm-readonly */
public int $position;
/** @psalm-readonly */
public bool $ref;
/** @psalm-readonly */
public ?string $type_hint;
/** @psalm-readonly */
public ?string $default;
public function __construct(ReflectionParameter $param)
{
$this->name = $param->getName();
$this->position = $param->getPosition();
$this->ref = $param->isPassedByReference();
$this->type_hint = ($type = $param->getType()) ? Utils::getTypeString($type) : null;
if ($param->isDefaultValueAvailable()) {
$default = $param->getDefaultValue();
switch (\gettype($default)) {
case 'NULL':
$this->default = 'null';
break;
case 'boolean':
$this->default = $default ? 'true' : 'false';
break;
case 'array':
$this->default = \count($default) ? 'array(...)' : 'array()';
break;
case 'double':
case 'integer':
case 'string':
$this->default = \var_export($default, true);
break;
case 'object':
$this->default = 'object('.\get_class($default).')';
break;
default:
$this->default = \gettype($default);
break;
}
} else {
$this->default = null;
}
}
public function __toString()
{
$type = $this->type_hint;
if (null !== $type) {
$type .= ' ';
}
$default = $this->default;
if (null !== $default) {
$default = ' = '.$default;
}
$ref = $this->ref ? '&' : '';
return $type.$ref.'$'.$this->name.$default;
}
}
+49
View File
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
trait ParameterHoldingTrait
{
/**
* @psalm-readonly
*
* @psalm-var ParameterBag[]
*/
public array $parameters = [];
public function getParams(): string
{
$out = [];
foreach ($this->parameters as $p) {
$out[] = (string) $p;
}
return \implode(', ', $out);
}
}
@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Representation;
abstract class AbstractRepresentation implements RepresentationInterface
{
/** @psalm-readonly */
protected string $label;
/** @psalm-readonly */
protected string $name;
/** @psalm-readonly */
protected bool $implicit_label;
public function __construct(string $label, ?string $name = null, bool $implicit_label = false)
{
$this->label = $label;
$this->name = \preg_replace('/[^a-z0-9]+/', '_', \strtolower($name ?? $label));
$this->implicit_label = $implicit_label;
}
public function getLabel(): string
{
return $this->label;
}
public function getName(): string
{
return $this->name;
}
public function labelIsImplicit(): bool
{
return $this->implicit_label;
}
public function getHint(): ?string
{
return null;
}
}
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Representation;
class BinaryRepresentation extends AbstractRepresentation
{
/** @psalm-readonly */
protected string $value;
public function __construct(string $value, bool $implicit = false)
{
parent::__construct('Hex dump', 'binary', $implicit);
$this->value = $value;
}
public function getHint(): string
{
return 'binary';
}
public function getValue(): string
{
return $this->value;
}
}
@@ -0,0 +1,157 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Representation;
use InvalidArgumentException;
class CallableDefinitionRepresentation extends AbstractRepresentation
{
/** @psalm-readonly */
protected string $filename;
/** @psalm-readonly */
protected int $line;
/**
* @psalm-readonly
*
* @psalm-var ?non-empty-string
*/
protected ?string $docstring;
/**
* @psalm-param ?non-empty-string $docstring
*/
public function __construct(string $filename, int $line, ?string $docstring)
{
if (null !== $docstring && !\preg_match('%^/\\*\\*.+\\*/$%s', $docstring)) {
throw new InvalidArgumentException('Docstring is invalid');
}
parent::__construct('Callable definition', null, true);
$this->filename = $filename;
$this->line = $line;
$this->docstring = $docstring;
}
public function getHint(): string
{
return 'callable';
}
public function getFileName(): string
{
return $this->filename;
}
public function getLine(): int
{
return $this->line;
}
/**
* @psalm-api
*
* @psalm-return ?non-empty-string
*/
public function getDocstring(): ?string
{
return $this->docstring;
}
/**
* Returns the representation's docstring without surrounding comments.
*
* Note that this will not work flawlessly.
*
* On comments with whitespace after the stars the lines will begin with
* whitespace, since we can't accurately guess how much of an indentation
* is required.
*
* And on lines without stars on the left this may eat bullet points.
*
* Long story short: If you want the docstring read the contents. If you
* absolutely must have it without comments (ie renderValueShort) this will
* probably do.
*/
public function getDocstringWithoutComments(): ?string
{
if (null === ($ds = $this->getDocstring())) {
return null;
}
$string = \substr($ds, 3, -2);
$string = \preg_replace('/^\\s*\\*\\s*?(\\S|$)/m', '\\1', $string);
return \trim($string);
}
public function getDocstringFirstLine(): ?string
{
$ds = $this->getDocstringWithoutComments();
if (null === $ds) {
return null;
}
$ds = \explode("\n", $ds);
$out = '';
foreach ($ds as $line) {
if (0 === \strlen(\trim($line)) || '@' === $line[0]) {
break;
}
$out .= $line.' ';
}
if (\strlen($out)) {
return \rtrim($out);
}
return null;
}
public function getDocstringTrimmed(): ?string
{
if (null === ($ds = $this->getDocstring())) {
return null;
}
$docstring = [];
foreach (\explode("\n", $ds) as $line) {
$line = \trim($line);
if (($line[0] ?? null) === '*') {
$line = ' '.$line;
}
$docstring[] = $line;
}
return \implode("\n", $docstring);
}
}
@@ -0,0 +1,594 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Representation;
use InvalidArgumentException;
use LogicException;
class ColorRepresentation extends AbstractRepresentation
{
public const COLOR_NAME = 1;
public const COLOR_HEX_3 = 2;
public const COLOR_HEX_6 = 3;
public const COLOR_RGB = 4;
public const COLOR_RGBA = 5;
public const COLOR_HSL = 6;
public const COLOR_HSLA = 7;
public const COLOR_HEX_4 = 8;
public const COLOR_HEX_8 = 9;
/** @psalm-var array<truthy-string, truthy-string> */
public static array $color_map = [
'aliceblue' => 'f0f8ff',
'antiquewhite' => 'faebd7',
'aqua' => '00ffff',
'aquamarine' => '7fffd4',
'azure' => 'f0ffff',
'beige' => 'f5f5dc',
'bisque' => 'ffe4c4',
'black' => '000000',
'blanchedalmond' => 'ffebcd',
'blue' => '0000ff',
'blueviolet' => '8a2be2',
'brown' => 'a52a2a',
'burlywood' => 'deb887',
'cadetblue' => '5f9ea0',
'chartreuse' => '7fff00',
'chocolate' => 'd2691e',
'coral' => 'ff7f50',
'cornflowerblue' => '6495ed',
'cornsilk' => 'fff8dc',
'crimson' => 'dc143c',
'cyan' => '00ffff',
'darkblue' => '00008b',
'darkcyan' => '008b8b',
'darkgoldenrod' => 'b8860b',
'darkgray' => 'a9a9a9',
'darkgreen' => '006400',
'darkgrey' => 'a9a9a9',
'darkkhaki' => 'bdb76b',
'darkmagenta' => '8b008b',
'darkolivegreen' => '556b2f',
'darkorange' => 'ff8c00',
'darkorchid' => '9932cc',
'darkred' => '8b0000',
'darksalmon' => 'e9967a',
'darkseagreen' => '8fbc8f',
'darkslateblue' => '483d8b',
'darkslategray' => '2f4f4f',
'darkslategrey' => '2f4f4f',
'darkturquoise' => '00ced1',
'darkviolet' => '9400d3',
'deeppink' => 'ff1493',
'deepskyblue' => '00bfff',
'dimgray' => '696969',
'dimgrey' => '696969',
'dodgerblue' => '1e90ff',
'firebrick' => 'b22222',
'floralwhite' => 'fffaf0',
'forestgreen' => '228b22',
'fuchsia' => 'ff00ff',
'gainsboro' => 'dcdcdc',
'ghostwhite' => 'f8f8ff',
'gold' => 'ffd700',
'goldenrod' => 'daa520',
'gray' => '808080',
'green' => '008000',
'greenyellow' => 'adff2f',
'grey' => '808080',
'honeydew' => 'f0fff0',
'hotpink' => 'ff69b4',
'indianred' => 'cd5c5c',
'indigo' => '4b0082',
'ivory' => 'fffff0',
'khaki' => 'f0e68c',
'lavender' => 'e6e6fa',
'lavenderblush' => 'fff0f5',
'lawngreen' => '7cfc00',
'lemonchiffon' => 'fffacd',
'lightblue' => 'add8e6',
'lightcoral' => 'f08080',
'lightcyan' => 'e0ffff',
'lightgoldenrodyellow' => 'fafad2',
'lightgray' => 'd3d3d3',
'lightgreen' => '90ee90',
'lightgrey' => 'd3d3d3',
'lightpink' => 'ffb6c1',
'lightsalmon' => 'ffa07a',
'lightseagreen' => '20b2aa',
'lightskyblue' => '87cefa',
'lightslategray' => '778899',
'lightslategrey' => '778899',
'lightsteelblue' => 'b0c4de',
'lightyellow' => 'ffffe0',
'lime' => '00ff00',
'limegreen' => '32cd32',
'linen' => 'faf0e6',
'magenta' => 'ff00ff',
'maroon' => '800000',
'mediumaquamarine' => '66cdaa',
'mediumblue' => '0000cd',
'mediumorchid' => 'ba55d3',
'mediumpurple' => '9370db',
'mediumseagreen' => '3cb371',
'mediumslateblue' => '7b68ee',
'mediumspringgreen' => '00fa9a',
'mediumturquoise' => '48d1cc',
'mediumvioletred' => 'c71585',
'midnightblue' => '191970',
'mintcream' => 'f5fffa',
'mistyrose' => 'ffe4e1',
'moccasin' => 'ffe4b5',
'navajowhite' => 'ffdead',
'navy' => '000080',
'oldlace' => 'fdf5e6',
'olive' => '808000',
'olivedrab' => '6b8e23',
'orange' => 'ffa500',
'orangered' => 'ff4500',
'orchid' => 'da70d6',
'palegoldenrod' => 'eee8aa',
'palegreen' => '98fb98',
'paleturquoise' => 'afeeee',
'palevioletred' => 'db7093',
'papayawhip' => 'ffefd5',
'peachpuff' => 'ffdab9',
'peru' => 'cd853f',
'pink' => 'ffc0cb',
'plum' => 'dda0dd',
'powderblue' => 'b0e0e6',
'purple' => '800080',
'rebeccapurple' => '663399',
'red' => 'ff0000',
'rosybrown' => 'bc8f8f',
'royalblue' => '4169e1',
'saddlebrown' => '8b4513',
'salmon' => 'fa8072',
'sandybrown' => 'f4a460',
'seagreen' => '2e8b57',
'seashell' => 'fff5ee',
'sienna' => 'a0522d',
'silver' => 'c0c0c0',
'skyblue' => '87ceeb',
'slateblue' => '6a5acd',
'slategray' => '708090',
'slategrey' => '708090',
'snow' => 'fffafa',
'springgreen' => '00ff7f',
'steelblue' => '4682b4',
'tan' => 'd2b48c',
'teal' => '008080',
'thistle' => 'd8bfd8',
'tomato' => 'ff6347',
// To quote MDN:
// "Technically, transparent is a shortcut for rgba(0,0,0,0)."
'transparent' => '00000000',
'turquoise' => '40e0d0',
'violet' => 'ee82ee',
'wheat' => 'f5deb3',
'white' => 'ffffff',
'whitesmoke' => 'f5f5f5',
'yellow' => 'ffff00',
'yellowgreen' => '9acd32',
];
protected int $r;
protected int $g;
protected int $b;
protected float $a;
/** @psalm-var self::COLOR_* */
protected int $variant;
public function __construct(string $value)
{
parent::__construct('Color', null, true);
$this->setValues($value);
}
public function getHint(): string
{
return 'color';
}
/**
* @psalm-api
*
* @psalm-return self::COLOR_*
*/
public function getVariant(): int
{
return $this->variant;
}
/**
* @psalm-param self::COLOR_* $variant
*
* @psalm-return ?truthy-string
*/
public function getColor(?int $variant = null): ?string
{
$variant ??= $this->variant;
switch ($variant) {
case self::COLOR_NAME:
$hex = \sprintf('%02x%02x%02x', $this->r, $this->g, $this->b);
$hex_alpha = \sprintf('%02x%02x%02x%02x', $this->r, $this->g, $this->b, \round($this->a * 0xFF));
return \array_search($hex, self::$color_map, true) ?: \array_search($hex_alpha, self::$color_map, true) ?: null;
case self::COLOR_HEX_3:
if (0 === $this->r % 0x11 && 0 === $this->g % 0x11 && 0 === $this->b % 0x11) {
/** @psalm-var truthy-string */
return \sprintf(
'#%1X%1X%1X',
\round($this->r / 0x11),
\round($this->g / 0x11),
\round($this->b / 0x11)
);
}
return null;
case self::COLOR_HEX_6:
/** @psalm-var truthy-string */
return \sprintf('#%02X%02X%02X', $this->r, $this->g, $this->b);
case self::COLOR_RGB:
if (1.0 === $this->a) {
/** @psalm-var truthy-string */
return \sprintf('rgb(%d, %d, %d)', $this->r, $this->g, $this->b);
}
/** @psalm-var truthy-string */
return \sprintf('rgb(%d, %d, %d, %s)', $this->r, $this->g, $this->b, \round($this->a, 4));
case self::COLOR_RGBA:
/** @psalm-var truthy-string */
return \sprintf('rgba(%d, %d, %d, %s)', $this->r, $this->g, $this->b, \round($this->a, 4));
case self::COLOR_HSL:
$val = self::rgbToHsl($this->r, $this->g, $this->b);
$val[1] = \round($val[1] * 100);
$val[2] = \round($val[2] * 100);
if (1.0 === $this->a) {
/** @psalm-var truthy-string */
return \vsprintf('hsl(%d, %d%%, %d%%)', $val);
}
/** @psalm-var truthy-string */
return \sprintf('hsl(%d, %d%%, %d%%, %s)', $val[0], $val[1], $val[2], \round($this->a, 4));
case self::COLOR_HSLA:
$val = self::rgbToHsl($this->r, $this->g, $this->b);
$val[1] = \round($val[1] * 100);
$val[2] = \round($val[2] * 100);
/** @psalm-var truthy-string */
return \sprintf('hsla(%d, %d%%, %d%%, %s)', $val[0], $val[1], $val[2], \round($this->a, 4));
case self::COLOR_HEX_4:
if (0 === $this->r % 0x11 && 0 === $this->g % 0x11 && 0 === $this->b % 0x11 && 0 === ((int) ($this->a * 255)) % 0x11) {
/** @psalm-var truthy-string */
return \sprintf(
'#%1X%1X%1X%1X',
\round($this->r / 0x11),
\round($this->g / 0x11),
\round($this->b / 0x11),
\round($this->a * 0xF)
);
}
return null;
case self::COLOR_HEX_8:
/** @psalm-var truthy-string */
return \sprintf('#%02X%02X%02X%02X', $this->r, $this->g, $this->b, \round($this->a * 0xFF));
}
return null;
}
public function hasAlpha(?int $variant = null): bool
{
$variant ??= $this->variant;
switch ($variant) {
case self::COLOR_NAME:
case self::COLOR_RGB:
case self::COLOR_HSL:
return \abs($this->a - 1) >= 0.0001;
case self::COLOR_RGBA:
case self::COLOR_HSLA:
case self::COLOR_HEX_4:
case self::COLOR_HEX_8:
return true;
default:
return false;
}
}
protected function setValues(string $value): void
{
$this->a = 1.0;
$value = \strtolower(\trim($value));
// Find out which variant of color input it is
if (isset(self::$color_map[$value])) {
$this->setValuesFromHex(self::$color_map[$value]);
$variant = self::COLOR_NAME;
} elseif ('#' === $value[0]) {
$variant = $this->setValuesFromHex(\substr($value, 1));
} else {
$variant = $this->setValuesFromFunction($value);
}
// If something has gone horribly wrong
if ($this->r > 0xFF || $this->g > 0xFF || $this->b > 0xFF || $this->a > 1) {
throw new LogicException('Something has gone wrong with color parsing'); // @codeCoverageIgnore
}
$this->variant = $variant;
}
/** @psalm-return self::COLOR_* */
protected function setValuesFromHex(string $hex): int
{
if (!\ctype_xdigit($hex)) {
throw new InvalidArgumentException('Hex color codes must be hexadecimal');
}
switch (\strlen($hex)) {
case 3:
$variant = self::COLOR_HEX_3;
break;
case 6:
$variant = self::COLOR_HEX_6;
break;
case 4:
$variant = self::COLOR_HEX_4;
break;
case 8:
$variant = self::COLOR_HEX_8;
break;
default:
throw new InvalidArgumentException('Hex color codes must have 3, 4, 6, or 8 characters');
}
switch ($variant) {
case self::COLOR_HEX_4:
$this->a = \hexdec($hex[3]) / 0xF;
// no break
case self::COLOR_HEX_3:
$this->r = \hexdec($hex[0]) * 0x11;
$this->g = \hexdec($hex[1]) * 0x11;
$this->b = \hexdec($hex[2]) * 0x11;
break;
case self::COLOR_HEX_8:
$this->a = \hexdec(\substr($hex, 6, 2)) / 0xFF;
// no break
case self::COLOR_HEX_6:
$hex = \str_split($hex, 2);
$this->r = \hexdec($hex[0]);
$this->g = \hexdec($hex[1]);
$this->b = \hexdec($hex[2]);
break;
}
return $variant;
}
/** @psalm-return self::COLOR_* */
protected function setValuesFromFunction(string $value): int
{
if (!\preg_match('/^((?:rgb|hsl)a?)\\s*\\(([0-9\\.%,\\s\\/\\-]+)\\)$/i', $value, $match)) {
throw new InvalidArgumentException('Couldn\'t parse color function string');
}
switch (\strtolower($match[1])) {
case 'rgb':
$variant = self::COLOR_RGB;
break;
case 'rgba':
$variant = self::COLOR_RGBA;
break;
case 'hsl':
$variant = self::COLOR_HSL;
break;
case 'hsla':
$variant = self::COLOR_HSLA;
break;
default:
// The regex should preclude this from ever happening
throw new InvalidArgumentException('Color functions must be one of rgb/rgba/hsl/hsla'); // @codeCoverageIgnore
}
$params = \preg_replace('/[,\\s\\/]+/', ',', \trim($match[2]));
$params = \explode(',', $params);
$params = \array_map('trim', $params);
if (\count($params) < 3 || \count($params) > 4) {
throw new InvalidArgumentException('Color functions must have 3 or 4 arguments');
}
foreach ($params as $i => &$color) {
if (false !== \strpos($color, '%')) {
$color = (float) \str_replace('%', '', $color);
if (\in_array($variant, [self::COLOR_RGB, self::COLOR_RGBA], true) && 3 !== $i) {
$color = \round($color / 100 * 0xFF);
} else {
$color = $color / 100;
}
}
$color = (float) $color;
if (0 === $i && \in_array($variant, [self::COLOR_HSL, self::COLOR_HSLA], true)) {
$color = \fmod(\fmod($color, 360) + 360, 360);
}
}
/**
* @psalm-var non-empty-array<array-key, float> $params
* Psalm bug #746 (wontfix)
*/
switch ($variant) {
case self::COLOR_RGBA:
case self::COLOR_RGB:
if (\min($params) < 0 || \max($params) > 0xFF) {
throw new InvalidArgumentException('RGB function arguments must be between 0 and 255');
}
break;
case self::COLOR_HSLA:
case self::COLOR_HSL:
if ($params[0] < 0 || $params[0] > 360) {
// Should be impossible because of the fmod work
throw new InvalidArgumentException('Hue must be between 0 and 360'); // @codeCoverageIgnore
}
if (\min($params) < 0 || \max($params[1], $params[2]) > 1) {
throw new InvalidArgumentException('Saturation/lightness must be between 0 and 1');
}
break;
}
if (4 === \count($params)) {
if ($params[3] > 1) {
throw new InvalidArgumentException('Alpha must be between 0 and 1');
}
$this->a = $params[3];
}
if (self::COLOR_HSLA === $variant || self::COLOR_HSL === $variant) {
$params = self::hslToRgb($params[0], $params[1], $params[2]);
}
[$this->r, $this->g, $this->b] = [(int) $params[0], (int) $params[1], (int) $params[2]];
return $variant;
}
/**
* Turns HSL color to RGB. Black magic.
*
* @param float $h Hue
* @param float $s Saturation
* @param float $l Lightness
*
* @return int[] RGB array
*/
public static function hslToRgb(float $h, float $s, float $l): array
{
if (\min($h, $s, $l) < 0) {
throw new InvalidArgumentException('The parameters for hslToRgb should be no less than 0');
}
if ($h > 360 || \max($s, $l) > 1) {
throw new InvalidArgumentException('The parameters for hslToRgb should be no more than 360, 1, and 1 respectively');
}
$h /= 360;
$m2 = ($l <= 0.5) ? $l * ($s + 1) : $l + $s - $l * $s;
$m1 = $l * 2 - $m2;
return [
(int) \round(self::hueToRgb($m1, $m2, $h + 1 / 3) * 0xFF),
(int) \round(self::hueToRgb($m1, $m2, $h) * 0xFF),
(int) \round(self::hueToRgb($m1, $m2, $h - 1 / 3) * 0xFF),
];
}
/**
* Converts RGB to HSL. Color inversion of previous black magic is white magic?
*
* @param float $red Red
* @param float $green Green
* @param float $blue Blue
*
* @return float[] HSL array
*/
public static function rgbToHsl(float $red, float $green, float $blue): array
{
if (\min($red, $green, $blue) < 0) {
throw new InvalidArgumentException('The parameters for rgbToHsl should be no less than 0');
}
if (\max($red, $green, $blue) > 0xFF) {
throw new InvalidArgumentException('The parameters for rgbToHsl should be no more than 255');
}
$clrMin = \min($red, $green, $blue);
$clrMax = \max($red, $green, $blue);
$deltaMax = $clrMax - $clrMin;
$L = ($clrMax + $clrMin) / 510;
if (0 == $deltaMax) {
$H = 0.0;
$S = 0.0;
} else {
if (0.5 > $L) {
$S = $deltaMax / ($clrMax + $clrMin);
} else {
$S = $deltaMax / (510 - $clrMax - $clrMin);
}
if ($clrMax === $red) {
$H = ($green - $blue) / (6.0 * $deltaMax);
if (0 > $H) {
$H += 1.0;
}
} elseif ($clrMax === $green) {
$H = 1 / 3 + ($blue - $red) / (6.0 * $deltaMax);
} else {
$H = 2 / 3 + ($red - $green) / (6.0 * $deltaMax);
}
}
return [
\fmod($H * 360, 360),
$S,
$L,
];
}
/**
* Helper function for hslToRgb. Even blacker magic.
*
* @return float Color value
*/
private static function hueToRgb(float $m1, float $m2, float $hue): float
{
$hue = ($hue < 0) ? $hue + 1 : (($hue > 1) ? $hue - 1 : $hue);
if ($hue * 6 < 1) {
return $m1 + ($m2 - $m1) * $hue * 6;
}
if ($hue * 2 < 1) {
return $m2;
}
if ($hue * 3 < 2) {
return $m1 + ($m2 - $m1) * (2 / 3 - $hue) * 6;
}
return $m1;
}
}
@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Representation;
use InvalidArgumentException;
use Kint\Value\AbstractValue;
class ContainerRepresentation extends AbstractRepresentation
{
/**
* @psalm-readonly
*
* @psalm-var non-empty-array<AbstractValue>
*/
protected array $contents;
/** @psalm-param non-empty-array<AbstractValue> $contents */
public function __construct(string $label, array $contents, ?string $name = null, bool $implicit_label = false)
{
if ([] === $contents) {
throw new InvalidArgumentException("ContainerRepresentation can't take empty list");
}
parent::__construct($label, $name, $implicit_label);
$this->contents = $contents;
}
/** @psalm-return non-empty-array<AbstractValue> */
public function getContents(): array
{
return $this->contents;
}
public function getLabel(): string
{
return parent::getLabel().' ('.\count($this->contents).')';
}
}
@@ -0,0 +1,125 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Representation;
use DateTimeImmutable;
use DateTimeInterface;
class MicrotimeRepresentation extends AbstractRepresentation
{
/** @psalm-readonly */
protected int $seconds;
/** @psalm-readonly */
protected int $microseconds;
/** @psalm-readonly */
protected string $group;
/** @psalm-readonly */
protected ?float $lap_time;
/** @psalm-readonly */
protected ?float $total_time;
protected ?float $avg_time = null;
/** @psalm-readonly */
protected int $mem;
/** @psalm-readonly */
protected int $mem_real;
/** @psalm-readonly */
protected int $mem_peak;
/** @psalm-readonly */
protected int $mem_peak_real;
public function __construct(int $seconds, int $microseconds, string $group, ?float $lap_time = null, ?float $total_time = null, int $i = 0)
{
parent::__construct('Microtime', null, true);
$this->seconds = $seconds;
$this->microseconds = $microseconds;
$this->group = $group;
$this->lap_time = $lap_time;
$this->total_time = $total_time;
if ($i > 0) {
$this->avg_time = $total_time / $i;
}
$this->mem = \memory_get_usage();
$this->mem_real = \memory_get_usage(true);
$this->mem_peak = \memory_get_peak_usage();
$this->mem_peak_real = \memory_get_peak_usage(true);
}
public function getHint(): string
{
return 'microtime';
}
public function getGroup(): string
{
return $this->group;
}
public function getLapTime(): ?float
{
return $this->lap_time;
}
public function getTotalTime(): ?float
{
return $this->total_time;
}
public function getAverageTime(): ?float
{
return $this->avg_time;
}
public function getMemoryUsage(): int
{
return $this->mem;
}
public function getMemoryUsageReal(): int
{
return $this->mem_real;
}
public function getMemoryPeakUsage(): int
{
return $this->mem_peak;
}
public function getMemoryPeakUsageReal(): int
{
return $this->mem_peak_real;
}
public function getDateTime(): ?DateTimeInterface
{
return DateTimeImmutable::createFromFormat('U u', $this->seconds.' '.\str_pad((string) $this->microseconds, 6, '0', STR_PAD_LEFT)) ?: null;
}
}
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Representation;
class ProfileRepresentation extends AbstractRepresentation
{
/** @psalm-readonly */
public int $complexity;
public ?int $instance_counts = null;
public ?int $instance_complexity = null;
public function __construct(int $complexity)
{
parent::__construct('Performance profile', 'profiling', false);
$this->complexity = $complexity;
}
public function getHint(): string
{
return 'profiling';
}
}
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Representation;
interface RepresentationInterface
{
public function getLabel(): string;
public function getName(): string;
public function getHint(): ?string;
public function labelIsImplicit(): bool;
}
@@ -0,0 +1,121 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Representation;
use RuntimeException;
class SourceRepresentation extends AbstractRepresentation
{
private const DEFAULT_PADDING = 7;
/**
* @psalm-readonly
*
* @psalm-var non-empty-array<string>
*/
protected array $source;
/** @psalm-readonly */
protected string $filename;
/** @psalm-readonly */
protected int $line;
/** @psalm-readonly */
protected bool $showfilename;
public function __construct(string $filename, int $line, ?int $padding = self::DEFAULT_PADDING, bool $showfilename = false)
{
parent::__construct('Source');
$this->filename = $filename;
$this->line = $line;
$this->showfilename = $showfilename;
$padding ??= self::DEFAULT_PADDING;
$start_line = \max($line - $padding, 1);
$length = $line + $padding + 1 - $start_line;
$this->source = self::readSource($filename, $start_line, $length);
}
public function getHint(): string
{
return 'source';
}
/**
* @psalm-api
*
* @psalm-return non-empty-string
*/
public function getSourceSlice(): string
{
return \implode("\n", $this->source);
}
/** @psalm-return non-empty-array<string> */
public function getSourceLines(): array
{
return $this->source;
}
public function getFileName(): string
{
return $this->filename;
}
public function getLine(): int
{
return $this->line;
}
public function showFileName(): bool
{
return $this->showfilename;
}
/**
* Gets section of source code.
*
* @psalm-return non-empty-array<string>
*/
private static function readSource(string $filename, int $start_line = 1, ?int $length = null): array
{
if (!$filename || !\file_exists($filename) || !\is_readable($filename)) {
throw new RuntimeException("Couldn't read file");
}
$source = \preg_split("/\r\n|\n|\r/", \file_get_contents($filename));
$source = \array_combine(\range(1, \count($source)), $source);
$source = \array_slice($source, $start_line - 1, $length, true);
if (0 === \count($source)) {
throw new RuntimeException('File seemed to be empty');
}
return $source;
}
}
@@ -0,0 +1,180 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Representation;
use Kint\Utils;
use RuntimeException;
use SplFileInfo;
class SplFileInfoRepresentation extends StringRepresentation
{
public function __construct(SplFileInfo $fileInfo)
{
$path = $fileInfo->getPathname();
$perms = 0;
$owner = null;
$group = null;
$mtime = null;
$realpath = null;
$linktarget = null;
$size = null;
$is_file = false;
$is_dir = false;
$is_link = false;
$typename = 'Unknown file';
try {
// SplFileInfo::getRealPath will return cwd when path is ''
if ('' !== $path && $fileInfo->getRealPath()) {
$perms = $fileInfo->getPerms();
$size = $fileInfo->getSize();
$owner = $fileInfo->getOwner();
$group = $fileInfo->getGroup();
$mtime = $fileInfo->getMTime();
$realpath = $fileInfo->getRealPath();
}
$is_dir = $fileInfo->isDir();
$is_file = $fileInfo->isFile();
$is_link = $fileInfo->isLink();
if ($is_link) {
$lt = $fileInfo->getLinkTarget();
$linktarget = false === $lt ? null : $lt;
}
} catch (RuntimeException $e) {
if (false === \strpos($e->getMessage(), ' open_basedir ')) {
throw $e; // @codeCoverageIgnore
}
}
$typeflag = '-';
switch ($perms & 0xF000) {
case 0xC000:
$typename = 'Socket';
$typeflag = 's';
break;
case 0x6000:
$typename = 'Block device';
$typeflag = 'b';
break;
case 0x2000:
$typename = 'Character device';
$typeflag = 'c';
break;
case 0x1000:
$typename = 'Named pipe';
$typeflag = 'p';
break;
default:
if ($is_file) {
if ($is_link) {
$typename = 'File symlink';
$typeflag = 'l';
} else {
$typename = 'File';
$typeflag = '-';
}
} elseif ($is_dir) {
if ($is_link) {
$typename = 'Directory symlink';
$typeflag = 'l';
} else {
$typename = 'Directory';
$typeflag = 'd';
}
}
break;
}
$flags = [$typeflag];
// User
$flags[] = (($perms & 0400) ? 'r' : '-');
$flags[] = (($perms & 0200) ? 'w' : '-');
if ($perms & 0100) {
$flags[] = ($perms & 04000) ? 's' : 'x';
} else {
$flags[] = ($perms & 04000) ? 'S' : '-';
}
// Group
$flags[] = (($perms & 0040) ? 'r' : '-');
$flags[] = (($perms & 0020) ? 'w' : '-');
if ($perms & 0010) {
$flags[] = ($perms & 02000) ? 's' : 'x';
} else {
$flags[] = ($perms & 02000) ? 'S' : '-';
}
// Other
$flags[] = (($perms & 0004) ? 'r' : '-');
$flags[] = (($perms & 0002) ? 'w' : '-');
if ($perms & 0001) {
$flags[] = ($perms & 01000) ? 's' : 'x';
} else {
$flags[] = ($perms & 01000) ? 'S' : '-';
}
$contents = \implode($flags).' '.$owner.' '.$group.' '.$size.' ';
if (null !== $mtime) {
if (\date('Y', $mtime) === \date('Y')) {
$contents .= \date('M d H:i', $mtime);
} else {
$contents .= \date('M d Y', $mtime);
}
}
$contents .= ' ';
if ($is_link && null !== $linktarget) {
$contents .= $path.' -> '.$linktarget;
} elseif (null !== $realpath && \strlen($realpath) < \strlen($path)) {
$contents .= $realpath;
} else {
$contents .= $path;
}
$label = $typename;
if (null !== $size && $is_file) {
$size = Utils::getHumanReadableBytes($size);
$label .= ' ('.$size['value'].$size['unit'].')';
}
parent::__construct($label, $contents, 'splfileinfo');
}
public function getHint(): string
{
return 'splfileinfo';
}
}
@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Representation;
use InvalidArgumentException;
class StringRepresentation extends AbstractRepresentation
{
/**
* @psalm-readonly
*
* @psalm-var non-empty-string
*/
protected string $value;
/** @psalm-assert non-empty-string $value */
public function __construct(string $label, string $value, ?string $name = null, bool $implicit = false)
{
if ('' === $value) {
throw new InvalidArgumentException("StringRepresentation can't take empty string");
}
parent::__construct($label, $name, $implicit);
$this->value = $value;
}
/** @psalm-return non-empty-string */
public function getValue(): string
{
return $this->value;
}
}
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Representation;
use Kint\Value\AbstractValue;
class TableRepresentation extends ContainerRepresentation
{
/** @psalm-param non-empty-array<AbstractValue> $contents */
public function __construct(array $contents, ?string $name = null)
{
parent::__construct('Table', $contents, $name, false);
}
public function getHint(): string
{
return 'table';
}
}
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value\Representation;
use Kint\Value\AbstractValue;
class ValueRepresentation extends AbstractRepresentation
{
/** @psalm-readonly */
protected AbstractValue $value;
public function __construct(string $label, AbstractValue $value, ?string $name = null, bool $implicit_label = false)
{
parent::__construct($label, $name, $implicit_label);
$this->value = $value;
}
public function getValue(): AbstractValue
{
return $this->value;
}
}
+47
View File
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use Kint\Value\Context\ContextInterface;
class ResourceValue extends AbstractValue
{
/** @psalm-readonly */
protected string $resource_type;
public function __construct(ContextInterface $context, string $resource_type)
{
parent::__construct($context, 'resource');
$this->resource_type = $resource_type;
}
public function getDisplayType(): string
{
return $this->resource_type.' resource';
}
}
+81
View File
@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use Kint\Value\Context\ContextInterface;
use SimpleXMLElement;
class SimpleXMLElementValue extends InstanceValue
{
/** @psalm-readonly */
protected ?string $text_content;
/** @psalm-param list<SimpleXMLElementValue> $children */
public function __construct(
ContextInterface $context,
SimpleXMLElement $element,
array $children,
?string $text_content
) {
parent::__construct($context, \get_class($element), \spl_object_hash($element), \spl_object_id($element));
$this->children = $children;
$this->text_content = $text_content;
}
public function getHint(): string
{
return parent::getHint() ?? 'simplexml_element';
}
public function getDisplaySize(): ?string
{
if ((bool) $this->children) {
return (string) \count($this->children);
}
if (null !== $this->text_content) {
return (string) \strlen($this->text_content);
}
return null;
}
public function getDisplayValue(): ?string
{
if ((bool) $this->children) {
return parent::getDisplayValue();
}
if (null !== $this->text_content) {
return '"'.$this->text_content.'"';
}
return null;
}
}
+92
View File
@@ -0,0 +1,92 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use Kint\Utils;
use Kint\Value\Context\ContextInterface;
use RuntimeException;
use SplFileInfo;
class SplFileInfoValue extends InstanceValue
{
/** @psalm-readonly */
protected string $path;
/** @psalm-readonly */
protected ?int $filesize = null;
public function __construct(ContextInterface $context, SplFileInfo $info)
{
parent::__construct($context, \get_class($info), \spl_object_hash($info), \spl_object_id($info));
$this->path = $info->getPathname();
try {
// SplFileInfo::getRealPath will return cwd when path is ''
if ('' !== $this->path && $info->getRealPath()) {
$this->filesize = $info->getSize();
}
} catch (RuntimeException $e) {
if (false === \strpos($e->getMessage(), ' open_basedir ')) {
throw $e; // @codeCoverageIgnore
}
}
}
public function getHint(): string
{
return parent::getHint() ?? 'splfileinfo';
}
/** @psalm-api */
public function getFileSize(): ?int
{
return $this->filesize;
}
public function getDisplaySize(): ?string
{
if (null === $this->filesize) {
return null;
}
$size = Utils::getHumanReadableBytes($this->filesize);
return $size['value'].$size['unit'];
}
public function getDisplayValue(): ?string
{
$shortpath = Utils::shortenPath($this->path);
if ($shortpath !== $this->path) {
return $shortpath;
}
return parent::getDisplayValue();
}
}
+79
View File
@@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use Kint\Utils;
use Kint\Value\Context\ContextInterface;
use Kint\Value\Representation\ContainerRepresentation;
class StreamValue extends ResourceValue
{
/**
* @psalm-readonly
*
* @psalm-var AbstractValue[]
*/
protected array $stream_meta;
/** @psalm-readonly */
protected ?string $uri;
/** @psalm-param AbstractValue[] $stream_meta */
public function __construct(ContextInterface $context, array $stream_meta, ?string $uri)
{
parent::__construct($context, 'stream');
$this->stream_meta = $stream_meta;
$this->uri = $uri;
if ($stream_meta) {
$this->addRepresentation(new ContainerRepresentation('Stream', $stream_meta, null, true));
}
}
public function getHint(): string
{
return parent::getHint() ?? 'stream';
}
public function getDisplayValue(): ?string
{
if (null === $this->uri) {
return null;
}
if ('/' === $this->uri[0] && \stream_is_local($this->uri)) {
return Utils::shortenPath($this->uri);
}
return $this->uri;
}
public function getDisplayChildren(): array
{
return $this->stream_meta;
}
}
+112
View File
@@ -0,0 +1,112 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use DomainException;
use Kint\Value\Context\ContextInterface;
/**
* @psalm-type Encoding = string|false
*/
class StringValue extends AbstractValue
{
/** @psalm-readonly */
protected string $value;
/**
* @psalm-readonly
*
* @psalm-var Encoding
*/
protected $encoding;
/** @psalm-readonly */
protected int $length;
/** @psalm-param Encoding $encoding */
public function __construct(ContextInterface $context, string $value, $encoding = false)
{
parent::__construct($context, 'string');
$this->value = $value;
$this->encoding = $encoding;
$this->length = \strlen($value);
}
public function getValue(): string
{
return $this->value;
}
public function getValueUtf8(): string
{
if (false === $this->encoding) {
throw new DomainException('StringValue with no encoding can\'t be converted to UTF-8');
}
if ('ASCII' === $this->encoding || 'UTF-8' === $this->encoding) {
return $this->value;
}
return \mb_convert_encoding($this->value, 'UTF-8', $this->encoding);
}
/** @psalm-api */
public function getLength(): int
{
return $this->length;
}
/** @psalm-return Encoding */
public function getEncoding()
{
return $this->encoding;
}
public function getDisplayType(): string
{
if (false === $this->encoding) {
return 'binary '.$this->type;
}
if ('ASCII' === $this->encoding) {
return $this->type;
}
return $this->encoding.' '.$this->type;
}
public function getDisplaySize(): string
{
return (string) $this->length;
}
public function getDisplayValue(): string
{
return '"'.$this->value.'"';
}
}
+49
View File
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use Kint\Value\Context\ContextInterface;
use Throwable;
class ThrowableValue extends InstanceValue
{
/** @psalm-readonly */
protected string $message;
public function __construct(ContextInterface $context, Throwable $throw)
{
parent::__construct($context, \get_class($throw), \spl_object_hash($throw), \spl_object_id($throw));
$this->message = $throw->getMessage();
}
public function getDisplayValue(): string
{
return '"'.$this->message.'"';
}
}
+184
View File
@@ -0,0 +1,184 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use InvalidArgumentException;
use Kint\Value\Context\BaseContext;
use Kint\Value\Context\MethodContext;
use ReflectionFunction;
use ReflectionMethod;
/**
* @psalm-type TraceFrame array{
* function: string,
* line?: int,
* file?: string,
* class?: class-string,
* object?: object,
* type?: string,
* args?: list<mixed>
* }
*/
class TraceFrameValue extends ArrayValue
{
/** @psalm-readonly */
protected ?string $file;
/** @psalm-readonly */
protected ?int $line;
/**
* @psalm-readonly
*
* @psalm-var null|FunctionValue|MethodValue
*/
protected $callable;
/**
* @psalm-readonly
*
* @psalm-var list<AbstractValue>
*/
protected array $args;
/** @psalm-readonly */
protected ?InstanceValue $object;
/**
* @psalm-param TraceFrame $raw_frame
*/
public function __construct(ArrayValue $old, $raw_frame)
{
parent::__construct($old->getContext(), $old->getSize(), $old->getContents());
$this->file = $raw_frame['file'] ?? null;
$this->line = $raw_frame['line'] ?? null;
if (isset($raw_frame['class']) && \method_exists($raw_frame['class'], $raw_frame['function'])) {
$func = new ReflectionMethod($raw_frame['class'], $raw_frame['function']);
$this->callable = new MethodValue(
new MethodContext($func),
new DeclaredCallableBag($func)
);
} elseif (!isset($raw_frame['class']) && \function_exists($raw_frame['function'])) {
$func = new ReflectionFunction($raw_frame['function']);
$this->callable = new FunctionValue(
new BaseContext($raw_frame['function']),
new DeclaredCallableBag($func)
);
} else {
// Mostly closures, no way to get them
$this->callable = null;
}
foreach ($this->contents as $frame_prop) {
$c = $frame_prop->getContext();
if ('object' === $c->getName()) {
if (!$frame_prop instanceof InstanceValue) {
throw new InvalidArgumentException('object key of TraceFrameValue must be parsed to InstanceValue');
}
$this->object = $frame_prop;
}
if ('args' === $c->getName()) {
if (!$frame_prop instanceof ArrayValue) {
throw new InvalidArgumentException('args key of TraceFrameValue must be parsed to ArrayValue');
}
$args = \array_values($frame_prop->getContents());
if ($this->callable) {
foreach ($this->callable->getCallableBag()->parameters as $param) {
if (!isset($args[$param->position])) {
break; // Optional args follow
}
$arg = $args[$param->position];
if ($arg->getContext() instanceof BaseContext) {
$arg = clone $arg;
$c = $arg->getContext();
if (!$c instanceof BaseContext) {
throw new InvalidArgumentException('TraceFrameValue expects arg contexts to be instanceof BaseContext');
}
$c->name = '$'.$param->name;
$args[$param->position] = $arg;
}
}
}
$this->args = $args;
}
}
/**
* @psalm-suppress DocblockTypeContradiction
* @psalm-suppress RedundantPropertyInitializationCheck
* Psalm bug #11124
*/
$this->args ??= [];
$this->object ??= null;
}
public function getHint(): string
{
return parent::getHint() ?? 'trace_frame';
}
public function getFile(): ?string
{
return $this->file;
}
public function getLine(): ?int
{
return $this->line;
}
/** @psalm-return null|FunctionValue|MethodValue */
public function getCallable()
{
return $this->callable;
}
/** @psalm-return list<AbstractValue> */
public function getArgs(): array
{
return $this->args;
}
public function getObject(): ?InstanceValue
{
return $this->object;
}
}
+50
View File
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
class TraceValue extends ArrayValue
{
public function getHint(): string
{
return parent::getHint() ?? 'trace';
}
public function getDisplayType(): string
{
return 'Debug Backtrace';
}
public function getDisplaySize(): string
{
if ($this->size > 0) {
return parent::getDisplaySize();
}
return 'empty';
}
}
+38
View File
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use Kint\Value\Context\ContextInterface;
class UninitializedValue extends AbstractValue
{
public function __construct(ContextInterface $context)
{
parent::__construct($context, 'uninitialized');
}
}
+38
View File
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use Kint\Value\Context\ContextInterface;
class UnknownValue extends AbstractValue
{
public function __construct(ContextInterface $context)
{
parent::__construct($context, 'unknown');
}
}
+38
View File
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* 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.
*/
namespace Kint\Value;
use Kint\Value\Context\ContextInterface;
class VirtualValue extends AbstractValue
{
public function __construct(ContextInterface $context)
{
parent::__construct($context, 'virtual');
}
}