One Hat Cyber Team
Your IP:
216.73.216.102
Server IP:
198.54.114.155
Server:
Linux server71.web-hosting.com 4.18.0-513.18.1.lve.el8.x86_64 #1 SMP Thu Feb 22 12:55:50 UTC 2024 x86_64
Server Software:
LiteSpeed
PHP Version:
5.6.40
Create File
|
Create Folder
Execute
Dir :
~
/
home
/
fluxyjvi
/
www
/
assets
/
images
/
Edit File:
Node.tar
RawMarkupContainerInterface.php 0000644 00000000721 15107423602 0012652 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of the league/commonmark package. * * (c) Colin O'Dell <colinodell@gmail.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Node; /** * Interface for a node which contains raw, unprocessed markup (like HTML) */ interface RawMarkupContainerInterface extends StringContainerInterface { } StringContainerHelper.php 0000644 00000002514 15107423602 0011530 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of the league/commonmark package. * * (c) Colin O'Dell <colinodell@gmail.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Node; final class StringContainerHelper { /** * Extract text literals from all descendant nodes * * @param Node $node Parent node * @param array<string> $excludeTypes Optional list of node class types to exclude * * @return string Concatenated literals */ public static function getChildText(Node $node, array $excludeTypes = []): string { $text = ''; foreach ($node->iterator() as $child) { if ($child instanceof StringContainerInterface && ! self::isOneOf($child, $excludeTypes)) { $text .= $child->getLiteral(); } } return $text; } /** * @param string[] $classesOrInterfacesToCheck * * @psalm-pure */ private static function isOneOf(object $object, array $classesOrInterfacesToCheck): bool { foreach ($classesOrInterfacesToCheck as $type) { if ($object instanceof $type) { return true; } } return false; } } Node.php 0000644 00000014502 15107423602 0006144 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of the league/commonmark package. * * (c) Colin O'Dell <colinodell@gmail.com> * * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) * - (c) John MacFarlane * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Node; use Dflydev\DotAccessData\Data; use League\CommonMark\Exception\InvalidArgumentException; abstract class Node { /** @psalm-readonly */ public Data $data; /** @psalm-readonly-allow-private-mutation */ protected int $depth = 0; /** @psalm-readonly-allow-private-mutation */ protected ?Node $parent = null; /** @psalm-readonly-allow-private-mutation */ protected ?Node $previous = null; /** @psalm-readonly-allow-private-mutation */ protected ?Node $next = null; /** @psalm-readonly-allow-private-mutation */ protected ?Node $firstChild = null; /** @psalm-readonly-allow-private-mutation */ protected ?Node $lastChild = null; public function __construct() { $this->data = new Data([ 'attributes' => [], ]); } public function previous(): ?Node { return $this->previous; } public function next(): ?Node { return $this->next; } public function parent(): ?Node { return $this->parent; } protected function setParent(?Node $node = null): void { $this->parent = $node; $this->depth = $node === null ? 0 : $node->depth + 1; } /** * Inserts the $sibling node after $this */ public function insertAfter(Node $sibling): void { $sibling->detach(); $sibling->next = $this->next; if ($sibling->next) { $sibling->next->previous = $sibling; } $sibling->previous = $this; $this->next = $sibling; $sibling->setParent($this->parent); if (! $sibling->next && $sibling->parent) { $sibling->parent->lastChild = $sibling; } } /** * Inserts the $sibling node before $this */ public function insertBefore(Node $sibling): void { $sibling->detach(); $sibling->previous = $this->previous; if ($sibling->previous) { $sibling->previous->next = $sibling; } $sibling->next = $this; $this->previous = $sibling; $sibling->setParent($this->parent); if (! $sibling->previous && $sibling->parent) { $sibling->parent->firstChild = $sibling; } } public function replaceWith(Node $replacement): void { $replacement->detach(); $this->insertAfter($replacement); $this->detach(); } public function detach(): void { if ($this->previous) { $this->previous->next = $this->next; } elseif ($this->parent) { $this->parent->firstChild = $this->next; } if ($this->next) { $this->next->previous = $this->previous; } elseif ($this->parent) { $this->parent->lastChild = $this->previous; } $this->parent = null; $this->next = null; $this->previous = null; $this->depth = 0; } public function hasChildren(): bool { return $this->firstChild !== null; } public function firstChild(): ?Node { return $this->firstChild; } public function lastChild(): ?Node { return $this->lastChild; } /** * @return Node[] */ public function children(): iterable { $children = []; for ($current = $this->firstChild; $current !== null; $current = $current->next) { $children[] = $current; } return $children; } public function appendChild(Node $child): void { if ($this->lastChild) { $this->lastChild->insertAfter($child); } else { $child->detach(); $child->setParent($this); $this->lastChild = $this->firstChild = $child; } } /** * Adds $child as the very first child of $this */ public function prependChild(Node $child): void { if ($this->firstChild) { $this->firstChild->insertBefore($child); } else { $child->detach(); $child->setParent($this); $this->lastChild = $this->firstChild = $child; } } /** * Detaches all child nodes of given node */ public function detachChildren(): void { foreach ($this->children() as $children) { $children->setParent(null); } $this->firstChild = $this->lastChild = null; } /** * Replace all children of given node with collection of another * * @param iterable<Node> $children */ public function replaceChildren(iterable $children): void { $this->detachChildren(); foreach ($children as $item) { $this->appendChild($item); } } public function getDepth(): int { return $this->depth; } public function walker(): NodeWalker { return new NodeWalker($this); } public function iterator(int $flags = 0): NodeIterator { return new NodeIterator($this, $flags); } /** * Clone the current node and its children * * WARNING: This is a recursive function and should not be called on deeply-nested node trees! */ public function __clone() { // Cloned nodes are detached from their parents, siblings, and children $this->parent = null; $this->previous = null; $this->next = null; // But save a copy of the children since we'll need that in a moment $children = $this->children(); $this->detachChildren(); // The original children get cloned and re-added foreach ($children as $child) { $this->appendChild(clone $child); } } public static function assertInstanceOf(Node $node): void { if (! $node instanceof static) { throw new InvalidArgumentException(\sprintf('Incompatible node type: expected %s, got %s', static::class, \get_class($node))); } } } NodeIterator.php 0000644 00000002542 15107423602 0007657 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of the league/commonmark package. * * (c) Colin O'Dell <colinodell@gmail.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Node; use League\CommonMark\Node\Block\AbstractBlock; /** * @implements \IteratorAggregate<int, Node> */ final class NodeIterator implements \IteratorAggregate { public const FLAG_BLOCKS_ONLY = 1; private Node $node; private bool $blocksOnly; public function __construct(Node $node, int $flags = 0) { $this->node = $node; $this->blocksOnly = ($flags & self::FLAG_BLOCKS_ONLY) === self::FLAG_BLOCKS_ONLY; } /** * @return \Generator<int, Node> */ public function getIterator(): \Generator { $stack = [$this->node]; $index = 0; while ($stack) { $node = \array_pop($stack); yield $index++ => $node; // Push all children onto the stack in reverse order $child = $node->lastChild(); while ($child !== null) { if (! $this->blocksOnly || $child instanceof AbstractBlock) { $stack[] = $child; } $child = $child->previous(); } } } } Query.php 0000644 00000006360 15107423602 0006367 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of the league/commonmark package. * * (c) Colin O'Dell <colinodell@gmail.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Node; use League\CommonMark\Node\Query\AndExpr; use League\CommonMark\Node\Query\OrExpr; final class Query { /** @var callable(Node): bool $condition */ private $condition; public function __construct() { $this->condition = new AndExpr(); } public function where(callable ...$conditions): self { return $this->andWhere(...$conditions); } public function andWhere(callable ...$conditions): self { if ($this->condition instanceof AndExpr) { foreach ($conditions as $condition) { $this->condition->add($condition); } } else { $this->condition = new AndExpr($this->condition, ...$conditions); } return $this; } public function orWhere(callable ...$conditions): self { if ($this->condition instanceof OrExpr) { foreach ($conditions as $condition) { $this->condition->add($condition); } } else { $this->condition = new OrExpr($this->condition, ...$conditions); } return $this; } public function findOne(Node $node): ?Node { foreach ($node->iterator() as $n) { if (\call_user_func($this->condition, $n)) { return $n; } } return null; } /** * @return iterable<Node> */ public function findAll(Node $node, ?int $limit = PHP_INT_MAX): iterable { $resultCount = 0; foreach ($node->iterator() as $n) { if ($resultCount >= $limit) { break; } if (! \call_user_func($this->condition, $n)) { continue; } ++$resultCount; yield $n; } } /** * @return callable(Node): bool */ public static function type(string $class): callable { return static fn (Node $node): bool => $node instanceof $class; } /** * @psalm-param ?callable(Node): bool $condition * * @return callable(Node): bool */ public static function hasChild(?callable $condition = null): callable { return static function (Node $node) use ($condition): bool { foreach ($node->children() as $child) { if ($condition === null || $condition($child)) { return true; } } return false; }; } /** * @psalm-param ?callable(Node): bool $condition * * @return callable(Node): bool */ public static function hasParent(?callable $condition = null): callable { return static function (Node $node) use ($condition): bool { $parent = $node->parent(); if ($parent === null) { return false; } if ($condition === null) { return true; } return $condition($parent); }; } } StringContainerInterface.php 0000644 00000001200 15107423602 0012200 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of the league/commonmark package. * * (c) Colin O'Dell <colinodell@gmail.com> * * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) * - (c) John MacFarlane * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Node; /** * Interface for a node which directly contains line(s) of text */ interface StringContainerInterface { public function setLiteral(string $literal): void; public function getLiteral(): string; } Inline/AbstractStringContainer.php 0000644 00000002127 15107423602 0013272 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of the league/commonmark package. * * (c) Colin O'Dell <colinodell@gmail.com> * * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) * - (c) John MacFarlane * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Node\Inline; use League\CommonMark\Node\StringContainerInterface; abstract class AbstractStringContainer extends AbstractInline implements StringContainerInterface { protected string $literal = ''; /** * @param array<string, mixed> $data */ public function __construct(string $contents = '', array $data = []) { parent::__construct(); $this->literal = $contents; if (\count($data) > 0) { $this->data->import($data); } } public function getLiteral(): string { return $this->literal; } public function setLiteral(string $literal): void { $this->literal = $literal; } } Inline/DelimitedInterface.php 0000644 00000000702 15107423602 0012213 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of the league/commonmark package. * * (c) Colin O'Dell <colinodell@gmail.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Node\Inline; interface DelimitedInterface { public function getOpeningDelimiter(): string; public function getClosingDelimiter(): string; } Inline/AbstractInline.php 0000644 00000001007 15107423602 0011373 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of the league/commonmark package. * * (c) Colin O'Dell <colinodell@gmail.com> * * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) * - (c) John MacFarlane * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Node\Inline; use League\CommonMark\Node\Node; abstract class AbstractInline extends Node { } Inline/Newline.php 0000644 00000001641 15107423602 0010076 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of the league/commonmark package. * * (c) Colin O'Dell <colinodell@gmail.com> * * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) * - (c) John MacFarlane * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Node\Inline; final class Newline extends AbstractInline { // Any changes to these constants should be reflected in .phpstorm.meta.php public const HARDBREAK = 0; public const SOFTBREAK = 1; /** @psalm-readonly */ private int $type; public function __construct(int $breakType = self::HARDBREAK) { parent::__construct(); $this->type = $breakType; } /** @psalm-immutable */ public function getType(): int { return $this->type; } } Inline/Text.php 0000644 00000001115 15107423602 0007415 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of the league/commonmark package. * * (c) Colin O'Dell <colinodell@gmail.com> * * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) * - (c) John MacFarlane * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Node\Inline; final class Text extends AbstractStringContainer { public function append(string $literal): void { $this->literal .= $literal; } } Inline/AdjacentTextMerger.php 0000644 00000005604 15107423602 0012220 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of the league/commonmark package. * * (c) Colin O'Dell <colinodell@gmail.com> * * Additional emphasis processing code based on commonmark-java (https://github.com/atlassian/commonmark-java) * - (c) Atlassian Pty Ltd * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Node\Inline; use League\CommonMark\Node\Node; /** * @internal */ final class AdjacentTextMerger { public static function mergeChildNodes(Node $node): void { // No children or just one child node, no need for merging if ($node->firstChild() === $node->lastChild() || $node->firstChild() === null || $node->lastChild() === null) { return; } /** @psalm-suppress PossiblyNullArgument */ self::mergeTextNodesInclusive($node->firstChild(), $node->lastChild()); } public static function mergeTextNodesBetweenExclusive(Node $fromNode, Node $toNode): void { // No nodes between them if ($fromNode === $toNode || $fromNode->next() === $toNode || $fromNode->next() === null || $toNode->previous() === null) { return; } /** @psalm-suppress PossiblyNullArgument */ self::mergeTextNodesInclusive($fromNode->next(), $toNode->previous()); } public static function mergeWithDirectlyAdjacentNodes(Text $node): void { $start = ($previous = $node->previous()) instanceof Text ? $previous : $node; $end = ($next = $node->next()) instanceof Text ? $next : $node; self::mergeIfNeeded($start, $end); } private static function mergeTextNodesInclusive(Node $fromNode, Node $toNode): void { $first = null; $last = null; $node = $fromNode; while ($node !== null) { if ($node instanceof Text) { if ($first === null) { $first = $node; } $last = $node; } else { self::mergeIfNeeded($first, $last); $first = null; $last = null; } if ($node === $toNode) { break; } $node = $node->next(); } self::mergeIfNeeded($first, $last); } private static function mergeIfNeeded(?Text $first, ?Text $last): void { if ($first === null || $last === null || $first === $last) { // No merging needed return; } $s = $first->getLiteral(); $node = $first->next(); $stop = $last->next(); while ($node !== $stop && $node instanceof Text) { $s .= $node->getLiteral(); $unlink = $node; $node = $node->next(); $unlink->detach(); } $first->setLiteral($s); } } NodeWalker.php 0000644 00000004231 15107423602 0007310 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of the league/commonmark package. * * (c) Colin O'Dell <colinodell@gmail.com> * * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) * - (c) John MacFarlane * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Node; use League\CommonMark\Node\Block\AbstractBlock; final class NodeWalker { /** @psalm-readonly */ private Node $root; /** @psalm-readonly-allow-private-mutation */ private ?Node $current = null; /** @psalm-readonly-allow-private-mutation */ private bool $entering; public function __construct(Node $root) { $this->root = $root; $this->current = $this->root; $this->entering = true; } /** * Returns an event which contains node and entering flag * (entering is true when we enter a Node from a parent or sibling, * and false when we reenter it from child) */ public function next(): ?NodeWalkerEvent { $current = $this->current; $entering = $this->entering; if ($current === null) { return null; } if ($entering && ($current instanceof AbstractBlock || $current->hasChildren())) { if ($current->firstChild()) { $this->current = $current->firstChild(); $this->entering = true; } else { $this->entering = false; } } elseif ($current === $this->root) { $this->current = null; } elseif ($current->next() === null) { $this->current = $current->parent(); $this->entering = false; } else { $this->current = $current->next(); $this->entering = true; } return new NodeWalkerEvent($current, $entering); } /** * Resets the iterator to resume at the specified node */ public function resumeAt(Node $node, bool $entering = true): void { $this->current = $node; $this->entering = $entering; } } Query/AndExpr.php 0000644 00000002156 15107423602 0007727 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of the league/commonmark package. * * (c) Colin O'Dell <colinodell@gmail.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Node\Query; use League\CommonMark\Node\Node; /** * @internal */ final class AndExpr implements ExpressionInterface { /** * @var callable[] * @psalm-var list<callable(Node): bool> */ private array $conditions; /** * @psalm-param callable(Node): bool $expressions */ public function __construct(callable ...$expressions) { $this->conditions = \array_values($expressions); } /** * @param callable(Node): bool $expression */ public function add(callable $expression): void { $this->conditions[] = $expression; } public function __invoke(Node $node): bool { foreach ($this->conditions as $condition) { if (! $condition($node)) { return false; } } return true; } } Query/ExpressionInterface.php 0000644 00000000655 15107423602 0012350 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of the league/commonmark package. * * (c) Colin O'Dell <colinodell@gmail.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Node\Query; use League\CommonMark\Node\Node; interface ExpressionInterface { public function __invoke(Node $node): bool; } Query/OrExpr.php 0000644 00000002153 15107423602 0007602 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of the league/commonmark package. * * (c) Colin O'Dell <colinodell@gmail.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Node\Query; use League\CommonMark\Node\Node; /** * @internal */ final class OrExpr implements ExpressionInterface { /** * @var callable[] * @psalm-var list<callable(Node): bool> */ private array $conditions; /** * @psalm-param callable(Node): bool $expressions */ public function __construct(callable ...$expressions) { $this->conditions = \array_values($expressions); } /** * @param callable(Node): bool $expression */ public function add(callable $expression): void { $this->conditions[] = $expression; } public function __invoke(Node $node): bool { foreach ($this->conditions as $condition) { if ($condition($node)) { return true; } } return false; } } Block/Paragraph.php 0000644 00000000737 15107423602 0010223 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of the league/commonmark package. * * (c) Colin O'Dell <colinodell@gmail.com> * * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) * - (c) John MacFarlane * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Node\Block; class Paragraph extends AbstractBlock { } Block/AbstractBlock.php 0000644 00000002661 15107423602 0011032 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of the league/commonmark package. * * (c) Colin O'Dell <colinodell@gmail.com> * * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) * - (c) John MacFarlane * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Node\Block; use League\CommonMark\Exception\InvalidArgumentException; use League\CommonMark\Node\Node; /** * Block-level element * * @method parent() ?AbstractBlock */ abstract class AbstractBlock extends Node { protected ?int $startLine = null; protected ?int $endLine = null; protected function setParent(?Node $node = null): void { if ($node && ! $node instanceof self) { throw new InvalidArgumentException('Parent of block must also be block (cannot be inline)'); } parent::setParent($node); } public function setStartLine(?int $startLine): void { $this->startLine = $startLine; if ($this->endLine === null) { $this->endLine = $startLine; } } public function getStartLine(): ?int { return $this->startLine; } public function setEndLine(?int $endLine): void { $this->endLine = $endLine; } public function getEndLine(): ?int { return $this->endLine; } } Block/TightBlockInterface.php 0000644 00000000662 15107423602 0012166 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of the league/commonmark package. * * (c) Colin O'Dell <colinodell@gmail.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Node\Block; interface TightBlockInterface { public function isTight(): bool; public function setTight(bool $tight): void; } Block/Document.php 0000644 00000002402 15107423602 0010063 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of the league/commonmark package. * * (c) Colin O'Dell <colinodell@gmail.com> * * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) * - (c) John MacFarlane * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Node\Block; use League\CommonMark\Parser\Cursor; use League\CommonMark\Reference\ReferenceMap; use League\CommonMark\Reference\ReferenceMapInterface; class Document extends AbstractBlock { /** @psalm-readonly */ protected ReferenceMapInterface $referenceMap; public function __construct(?ReferenceMapInterface $referenceMap = null) { parent::__construct(); $this->setStartLine(1); $this->referenceMap = $referenceMap ?? new ReferenceMap(); } public function getReferenceMap(): ReferenceMapInterface { return $this->referenceMap; } public function canContain(AbstractBlock $block): bool { return true; } public function isCode(): bool { return false; } public function matchesNextLine(Cursor $cursor): bool { return true; } } NodeWalkerEvent.php 0000644 00000001575 15107423602 0010322 0 ustar 00 <?php declare(strict_types=1); /* * This file is part of the league/commonmark package. * * (c) Colin O'Dell <colinodell@gmail.com> * * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) * - (c) John MacFarlane * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace League\CommonMark\Node; final class NodeWalkerEvent { /** @psalm-readonly */ private Node $node; /** @psalm-readonly */ private bool $isEntering; public function __construct(Node $node, bool $isEntering = true) { $this->node = $node; $this->isEntering = $isEntering; } public function getNode(): Node { return $this->node; } public function isEntering(): bool { return $this->isEntering; } } RandomNodeProvider.php 0000644 00000003427 15107447363 0011036 0 ustar 00 <?php /** * This file is part of the ramsey/uuid library * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> * @license http://opensource.org/licenses/MIT MIT */ declare(strict_types=1); namespace Ramsey\Uuid\Provider\Node; use Ramsey\Uuid\Exception\RandomSourceException; use Ramsey\Uuid\Provider\NodeProviderInterface; use Ramsey\Uuid\Type\Hexadecimal; use Throwable; use function bin2hex; use function dechex; use function hex2bin; use function hexdec; use function str_pad; use function substr; use const STR_PAD_LEFT; /** * RandomNodeProvider generates a random node ID * * @link http://tools.ietf.org/html/rfc4122#section-4.5 RFC 4122, § 4.5: Node IDs that Do Not Identify the Host */ class RandomNodeProvider implements NodeProviderInterface { public function getNode(): Hexadecimal { try { $nodeBytes = random_bytes(6); } catch (Throwable $exception) { throw new RandomSourceException( $exception->getMessage(), (int) $exception->getCode(), $exception ); } // Split the node bytes for math on 32-bit systems. $nodeMsb = substr($nodeBytes, 0, 3); $nodeLsb = substr($nodeBytes, 3); // Set the multicast bit; see RFC 4122, section 4.5. $nodeMsb = hex2bin( str_pad( dechex(hexdec(bin2hex($nodeMsb)) | 0x010000), 6, '0', STR_PAD_LEFT ) ); // Recombine the node bytes. $node = $nodeMsb . $nodeLsb; return new Hexadecimal(str_pad(bin2hex($node), 12, '0', STR_PAD_LEFT)); } } StaticNodeProvider.php 0000644 00000003530 15107447363 0011040 0 ustar 00 <?php /** * This file is part of the ramsey/uuid library * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> * @license http://opensource.org/licenses/MIT MIT */ declare(strict_types=1); namespace Ramsey\Uuid\Provider\Node; use Ramsey\Uuid\Exception\InvalidArgumentException; use Ramsey\Uuid\Provider\NodeProviderInterface; use Ramsey\Uuid\Type\Hexadecimal; use function dechex; use function hexdec; use function str_pad; use function substr; use const STR_PAD_LEFT; /** * StaticNodeProvider provides a static node value with the multicast bit set * * @link http://tools.ietf.org/html/rfc4122#section-4.5 RFC 4122, § 4.5: Node IDs that Do Not Identify the Host */ class StaticNodeProvider implements NodeProviderInterface { private Hexadecimal $node; /** * @param Hexadecimal $node The static node value to use */ public function __construct(Hexadecimal $node) { if (strlen($node->toString()) > 12) { throw new InvalidArgumentException( 'Static node value cannot be greater than 12 hexadecimal characters' ); } $this->node = $this->setMulticastBit($node); } public function getNode(): Hexadecimal { return $this->node; } /** * Set the multicast bit for the static node value */ private function setMulticastBit(Hexadecimal $node): Hexadecimal { $nodeHex = str_pad($node->toString(), 12, '0', STR_PAD_LEFT); $firstOctet = substr($nodeHex, 0, 2); $firstOctet = str_pad( dechex(hexdec($firstOctet) | 0x01), 2, '0', STR_PAD_LEFT ); return new Hexadecimal($firstOctet . substr($nodeHex, 2)); } } FallbackNodeProvider.php 0000644 00000002541 15107447363 0011311 0 ustar 00 <?php /** * This file is part of the ramsey/uuid library * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> * @license http://opensource.org/licenses/MIT MIT */ declare(strict_types=1); namespace Ramsey\Uuid\Provider\Node; use Ramsey\Uuid\Exception\NodeException; use Ramsey\Uuid\Provider\NodeProviderInterface; use Ramsey\Uuid\Type\Hexadecimal; /** * FallbackNodeProvider retrieves the system node ID by stepping through a list * of providers until a node ID can be obtained */ class FallbackNodeProvider implements NodeProviderInterface { /** * @param iterable<NodeProviderInterface> $providers Array of node providers */ public function __construct(private iterable $providers) { } public function getNode(): Hexadecimal { $lastProviderException = null; foreach ($this->providers as $provider) { try { return $provider->getNode(); } catch (NodeException $exception) { $lastProviderException = $exception; continue; } } throw new NodeException( 'Unable to find a suitable node provider', 0, $lastProviderException ); } } NodeProviderCollection.php 0000644 00000004132 15107447363 0011703 0 ustar 00 <?php /** * This file is part of the ramsey/uuid library * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> * @license http://opensource.org/licenses/MIT MIT */ declare(strict_types=1); namespace Ramsey\Uuid\Provider\Node; use Ramsey\Collection\AbstractCollection; use Ramsey\Uuid\Provider\NodeProviderInterface; use Ramsey\Uuid\Type\Hexadecimal; /** * A collection of NodeProviderInterface objects * * @deprecated this class has been deprecated, and will be removed in 5.0.0. The use-case for this class comes from * a pre-`phpstan/phpstan` and pre-`vimeo/psalm` ecosystem, in which type safety had to be mostly enforced * at runtime: that is no longer necessary, now that you can safely verify your code to be correct, and use * more generic types like `iterable<T>` instead. * * @extends AbstractCollection<NodeProviderInterface> */ class NodeProviderCollection extends AbstractCollection { public function getType(): string { return NodeProviderInterface::class; } /** * Re-constructs the object from its serialized form * * @param string $serialized The serialized PHP string to unserialize into * a UuidInterface instance * * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint * @psalm-suppress RedundantConditionGivenDocblockType */ public function unserialize($serialized): void { /** @var array<array-key, NodeProviderInterface> $data */ $data = unserialize($serialized, [ 'allowed_classes' => [ Hexadecimal::class, RandomNodeProvider::class, StaticNodeProvider::class, SystemNodeProvider::class, ], ]); $this->data = array_filter( $data, function ($unserialized): bool { return $unserialized instanceof NodeProviderInterface; } ); } } SystemNodeProvider.php 0000644 00000011620 15107447363 0011074 0 ustar 00 <?php /** * This file is part of the ramsey/uuid library * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> * @license http://opensource.org/licenses/MIT MIT */ declare(strict_types=1); namespace Ramsey\Uuid\Provider\Node; use Ramsey\Uuid\Exception\NodeException; use Ramsey\Uuid\Provider\NodeProviderInterface; use Ramsey\Uuid\Type\Hexadecimal; use function array_filter; use function array_map; use function array_walk; use function count; use function ob_get_clean; use function ob_start; use function preg_match; use function preg_match_all; use function reset; use function str_contains; use function str_replace; use function strtolower; use function strtoupper; use function substr; use const GLOB_NOSORT; use const PREG_PATTERN_ORDER; /** * SystemNodeProvider retrieves the system node ID, if possible * * The system node ID, or host ID, is often the same as the MAC address for a * network interface on the host. */ class SystemNodeProvider implements NodeProviderInterface { /** * Pattern to match nodes in ifconfig and ipconfig output. */ private const IFCONFIG_PATTERN = '/[^:]([0-9a-f]{2}([:-])[0-9a-f]{2}(\2[0-9a-f]{2}){4})[^:]/i'; /** * Pattern to match nodes in sysfs stream output. */ private const SYSFS_PATTERN = '/^([0-9a-f]{2}:){5}[0-9a-f]{2}$/i'; public function getNode(): Hexadecimal { $node = $this->getNodeFromSystem(); if ($node === '') { throw new NodeException( 'Unable to fetch a node for this system' ); } return new Hexadecimal($node); } /** * Returns the system node, if it can find it */ protected function getNodeFromSystem(): string { static $node = null; if ($node !== null) { return (string) $node; } // First, try a Linux-specific approach. $node = $this->getSysfs(); if ($node === '') { // Search ifconfig output for MAC addresses & return the first one. $node = $this->getIfconfig(); } $node = str_replace([':', '-'], '', $node); return $node; } /** * Returns the network interface configuration for the system * * @codeCoverageIgnore */ protected function getIfconfig(): string { $disabledFunctions = strtolower((string) ini_get('disable_functions')); if (str_contains($disabledFunctions, 'passthru')) { return ''; } /** * @psalm-suppress UnnecessaryVarAnnotation * @var string $phpOs */ $phpOs = constant('PHP_OS'); ob_start(); switch (strtoupper(substr($phpOs, 0, 3))) { case 'WIN': passthru('ipconfig /all 2>&1'); break; case 'DAR': passthru('ifconfig 2>&1'); break; case 'FRE': passthru('netstat -i -f link 2>&1'); break; case 'LIN': default: passthru('netstat -ie 2>&1'); break; } $ifconfig = (string) ob_get_clean(); if (preg_match_all(self::IFCONFIG_PATTERN, $ifconfig, $matches, PREG_PATTERN_ORDER)) { foreach ($matches[1] as $iface) { if ($iface !== '00:00:00:00:00:00' && $iface !== '00-00-00-00-00-00') { return $iface; } } } return ''; } /** * Returns MAC address from the first system interface via the sysfs interface */ protected function getSysfs(): string { $mac = ''; /** * @psalm-suppress UnnecessaryVarAnnotation * @var string $phpOs */ $phpOs = constant('PHP_OS'); if (strtoupper($phpOs) === 'LINUX') { $addressPaths = glob('/sys/class/net/*/address', GLOB_NOSORT); if ($addressPaths === false || count($addressPaths) === 0) { return ''; } /** @var array<array-key, string> $macs */ $macs = []; array_walk($addressPaths, function (string $addressPath) use (&$macs): void { if (is_readable($addressPath)) { $macs[] = file_get_contents($addressPath); } }); /** @var callable $trim */ $trim = 'trim'; $macs = array_map($trim, $macs); // Remove invalid entries. $macs = array_filter($macs, function (string $address) { return $address !== '00:00:00:00:00:00' && preg_match(self::SYSFS_PATTERN, $address); }); /** @var string|bool $mac */ $mac = reset($macs); } return (string) $mac; } }
Simpan