first commit
This commit is contained in:
@@ -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 '=>';
|
||||
}
|
||||
}
|
||||
@@ -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';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user