10000 TypedArray/src/TypedArray/ArrayBufferView.php at master · ArrayIterator/TypedArray · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Nov 22, 2022. It is now read-only.
{"payload":{"allShortcutsEnabled":false,"fileTree":{"src/TypedArray":{"items":[{"name":"Interfaces","path":"src/TypedArray/Interfaces","contentType":"directory"},{"name":"Traits","path":"src/TypedArray/Traits","contentType":"directory"},{"name":"Util","path":"src/TypedArray/Util","contentType":"directory"},{"name":"ArrayBuffer.php","path":"src/TypedArray/ArrayBuffer.php","contentType":"file"},{"name":"ArrayBufferAbstract.php","path":"src/TypedArray/ArrayBufferAbstract.php","contentType":"file"},{"name":"ArrayBufferLike.php","path":"src/TypedArray/ArrayBufferLike.php","contentType":"file"},{"name":"ArrayBufferView.php","path":"src/TypedArray/ArrayBufferView.php","contentType":"file"},{"name":"ArrayLike.php","path":"src/TypedArray/ArrayLike.php","contentType":"file"},{"name":"Buffer.php","path":"src/TypedArray/Buffer.php","contentType":"file"},{"name":"Float32Array.php","path":"src/TypedArray/Float32Array.php","contentType":"file"},{"name":"Float64Array.php","path":"src/TypedArray/Float64Array.php","contentType":"file"},{"name":"Int16Array.php","path":"src/TypedArray/Int16Array.php","contentType":"file"},{"name":"Int32Array.php","path":"src/TypedArray/Int32Array.php","contentType":"file"},{"name":"Int8Array.php","path":"src/TypedArray/Int8Array.php","contentType":"file"},{"name":"Uint16Array.php","path":"src/TypedArray/Uint16Array.php","contentType":"file"},{"name":"Uint32Array.php","path":"src/TypedArray/Uint32Array.php","contentType":"file"},{"name":"Uint8Array.php","path":"src/TypedArray/Uint8Array.php","contentType":"file"}],"totalCount":17},"src":{"items":[{"name":"TypedArray","path":"src/TypedArray","contentType":"directory"}],"totalCount":1},"":{"items":[{"name":"src","path":"src","contentType":"directory"},{"name":".gitignore","path":".gitignore","contentType":"file"},{"name":"LICENSE","path":"LICENSE","contentType":"file"},{"name":"README.md","path":"README.md","contentType":"file"},{"name":"composer.json","path":"composer.json","contentType":"file"},{"name":"phpcs.xml","path":"phpcs.xml","contentType":"file"}],"totalCount":6}},"fileTreeProcessingTime":20.990857000000002,"foldersToFetch":[],"incompleteFileTree":false,"repo":{"id":128374968,"defaultBranch":"master","name":"TypedArray","ownerLogin":"ArrayIterator","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2018-04-06T09:25:54.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/37867551?v=4","public":true,"private":false,"isOrgOwned":false},"codeLineWrapEnabled":false,"symbolsExpanded":false,"treeExpanded":true,"refInfo":{"name":"master","listCacheKey":"v0:1523006783.0","canEdit":false,"refType":"branch","currentOid":"1ab62dc90af1013a1759db541b71c36a472ea0af"},"path":"src/TypedArray/ArrayBufferView.php","currentUser":null,"blob":{"rawLines":["\u003c?php","/**"," * MIT License"," *"," * Copyright (c) 2018 ArrayIterator"," *"," * 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 NON INFRINGEMENT. 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."," */","","declare(strict_types=1);","","namespace ArrayIterator\\TypedArray;","","use ArrayIterator\\TypedArray\\Interfaces\\ArrayBufferLikeInterface;","use ArrayIterator\\TypedArray\\Interfaces\\ArrayBufferViewInterface;","use ArrayIterator\\TypedArray\\Traits\\FloatArrayTrait;","use ArrayIterator\\TypedArray\\Traits\\UintArrayTrait;","use ArrayIterator\\TypedArray\\Util\\TypeArg;","","/**"," * Class ArrayBufferView"," * @package ArrayIterator\\TypedArray"," *"," * @property-read int $length"," * @property-read int $byteLength"," * @property-read int $byteOffset"," * @property-read ArrayBufferLikeInterface $buffer"," */","abstract class ArrayBufferView extends ArrayBufferLike implements ArrayBufferViewInterface","{"," /**"," * @var int"," */"," const BYTES_PER_ELEMENT = 0x1;",""," /**"," * Bits unit"," * @var int"," */"," const BITS_UNIT = 0x100;",""," /**"," * @var int The length in of the array count"," */"," protected $length = 0;",""," /**"," * @var int The length in bytes of the array."," */"," protected $byteLength = 0;",""," /**"," * The ArrayBuffer instance referenced by the array."," * @var ArrayBufferLikeInterface"," */"," protected $buffer;",""," /**"," * @var int The offset in bytes of the array."," */"," protected $byteOffset = 0;",""," /**"," * @var int"," */"," protected $bytesElement = 0x100;",""," /** @noinspection PhpMissingParentConstructorInspection */",""," /**"," * ArrayBufferLike constructor."," * @param null $arrayOrBuffer"," */"," public function __construct($arrayOrBuffer = null)"," {"," // reset byte length"," $this-\u003ebyteLength = 0x0;"," $this-\u003elength = 0x0;"," // Calculate Total Bytes Element"," // pow(static::BITS_UNIT, static::BYTES_PER_ELEMENT);"," $this-\u003ebytesElement = static::BITS_UNIT ** static::BYTES_PER_ELEMENT;"," // if array buffer is null create empty ArrayBufer"," if ($arrayOrBuffer === null) {"," $this-\u003ebuffer = new ArrayBuffer();"," return;"," }",""," if (is_string($arrayOrBuffer) \u0026\u0026 is_numeric(trim($arrayOrBuffer))) {"," $arrayOrBuffer = intval(trim($arrayOrBuffer));"," }",""," if (is_int($arrayOrBuffer)) {"," if ($arrayOrBuffer \u003c 0) {"," throw new \\RangeException("," sprintf("," 'Byte length must not to be negative : %d',"," $arrayOrBuffer"," )"," );"," }",""," $this-\u003ebyteLength = $arrayOrBuffer;"," $this-\u003elength = $arrayOrBuffer;"," $this-\u003ebuffer = new ArrayBuffer($arrayOrBuffer);"," parent::exchangeArray($this-\u003ecreateArrayFill($arrayOrBuffer));"," return;"," }",""," if (is_iterable($arrayOrBuffer) \u0026\u0026 count($arrayOrBuffer) \u003e 0) {"," $c = 0;"," $this-\u003ebyteLength = count($arrayOrBuffer);"," foreach ($arrayOrBuffer as $key =\u003e $value) {"," if (!is_int($key) || $key \u003c 0) {"," continue;"," }",""," $this[$c++] = $value;"," }",""," unset($arrayOrBuffer);"," $this-\u003ebyteLength = $c;"," }",""," $this-\u003elength = $this-\u003ebyteLength;"," $this-\u003ebuffer = new ArrayBuffer($this-\u003ebyteLength);"," }",""," /**"," * {@inheritdoc}"," *"," public function copyWithin(int $target, int $start = 0, int $end = null) : ArrayBufferViewInterface"," {"," $length = $this-\u003egetLength();",""," if ($target \u003c 0) {"," $target = $target + $length;"," }"," if ($start \u003c 0) {"," $start = $target + $length;"," }",""," return $this-\u003eslice($start, $end);"," }*/",""," /**"," * @param mixed $value if not as numeric return 0x0 = 0"," * or NAN if it was float / double array"," *"," * @see UintArrayTrait for override Uint(8|16|32)Array"," * @see FloatArrayTrait for override Float(32|64)Array"," *"," * @return int|float"," */"," abstract protected function dataBufferFor($value);",""," /**"," * Create Array Fill"," *"," * @param int $count"," * @return array|int[]|float[]"," */"," protected function createArrayFill(int $count) : array"," {"," return array_fill(0, $count, 0x0);"," }",""," /**"," * @return int"," */"," public function getByteOffset() : int"," {"," return $this-\u003ebyteOffset;"," }",""," /**"," * @return ArrayBufferLikeInterface"," */"," public function getBuffer() : ArrayBufferLikeInterface"," {"," return $this-\u003ebuffer;"," }",""," /**"," * {@inheritdoc}"," */"," public function asort()"," {"," parent::asort();"," $this-\u003eexchangeArray($this-\u003egetArrayCopy());"," }",""," /**"," * {@inheritdoc}"," */"," public function ksort()"," {"," parent::ksort();"," $this-\u003eexchangeArray($this-\u003egetArrayCopy());"," }",""," /**"," * {@inheritdoc}"," */"," public function natsort()"," {"," parent::natsort();"," $this-\u003eexchangeArray($this-\u003egetArrayCopy());"," }",""," /**"," * {@inheritdoc}"," */"," public function natcasesort()"," {"," parent::natcasesort();"," $this-\u003eexchangeArray($this-\u003egetArrayCopy());"," }",""," /**"," * {@inheritdoc}"," */"," public function uksort($cmp_function)"," {"," parent::uksort($cmp_function);"," $this-\u003eexchangeArray($this-\u003egetArrayCopy());"," }",""," /**"," * {@inheritdoc}"," */"," public function uasort($cmp_function)"," {"," parent::uasort($cmp_function);"," $this-\u003eexchangeArray($this-\u003egetArrayCopy());"," }",""," /**"," * {@inheritdoc}"," */"," public function offsetSet($offset, $value)"," {"," if (is_numeric($offset)) {"," if ($offset \u003c 0x0"," || ! is_int(($offset = abs($offset)))"," || abs($offset) \u003e= $this-\u003ebyteLength"," ) {"," return;"," }",""," $value = $this-\u003edataBufferFor($value);"," }",""," parent::offsetSet($offset, $value);"," }",""," /**"," * {@inheritdoc}"," */"," public function offsetUnset($offset)"," {"," if (is_numeric($offset)"," \u0026\u0026 is_int(abs($offset))"," \u0026\u0026 $offset \u003e -1 \u0026\u0026 abs($offset) \u003c $this-\u003ebyteLength"," ) {"," return;"," }",""," parent::offsetUnset($offset);"," }",""," /**"," * @return int get count of byte length"," */"," public function count() : int"," {"," return $this-\u003elength;"," }",""," /**"," * {@inheritdoc}"," */"," public function exchangeArray($input)"," {"," $copy = $this-\u003egetArrayCopy();"," if (is_iterable($input)) {"," parent::exchangeArray($this-\u003egetBytesLengthArray());"," foreach ($input as $key =\u003e $value) {"," $this[$key] = $value;"," }"," unset($input);"," }",""," return $copy;"," }",""," /**"," * {@inheritdoc}"," * pass append"," */"," public function append($value)"," {"," // pass"," }",""," /**"," * {@inheritdoc}"," */"," public static function of(...$items) : ArrayBufferViewInterface"," {"," return new static($items);"," }",""," /**"," * {@inheritdoc}"," */"," public static function from("," iterable $arrayLike,"," callable $mapFn = null,"," $thisArg = null"," ) : ArrayBufferViewInterface {"," $obj = new static($arrayLike);"," if ($mapFn) {"," $obj-\u003emap($mapFn, $thisArg);"," }"," return $obj;"," }",""," /**"," * @param callable $callback"," * @param mixed $thisArgs"," * @return ArrayLike"," */"," public function map(callable $callback, $thisArgs = null) : ArrayLike"," {"," $object = clone $this;"," if ($callback instanceof \\Closure) {"," $thisArgs = is_object($thisArgs) \u0026\u0026 ! $this instanceof \\Closure"," ? $thisArgs"," : new TypeArg($thisArgs);"," } else {"," $thisArgs = $object;"," }",""," foreach ($this-\u003egetBytesLengthArray() as $key =\u003e $value) {"," $callback($value, $key, $thisArgs);"," }",""," return $object;"," }",""," /**"," * Slice array like an array_slice uses"," *"," * @param int|null $start"," * @param int|null $length"," * @return ArrayBufferViewInterface"," */"," public function sliceLength(int $start = null, int $length = null) : ArrayBufferViewInterface"," {"," return parent::slice($start, $length);"," }",""," /**"," * {@inheritdoc}"," */"," public function subArray(int $begin, int $end = null): ArrayBufferViewInterface"," {"," return clone $this-\u003eslice($begin, $end);"," }",""," /**"," * @param callable $callbackFn"," * @return ArrayBufferViewInterface"," */"," public function sort(callable $callbackFn = null): ArrayBufferViewInterface"," {"," $arr = $this-\u003egetArrayCopy();"," if ($callbackFn) {"," uasort($arr, $callbackFn);"," } else {"," sort($arr);"," }",""," $this-\u003eexchangeArray($arr);"," return $this;"," }",""," /**"," * {@inheritdoc}"," */"," public function fill(int $value, int $start = null, int $end = null) : ArrayBufferViewInterface"," {"," $max = $this-\u003egetByteLength();"," if ($max === 0 || $end \u003c $start) {"," return $this;"," }",""," $start = $start \u003c 0 ? $max + $start : $start;"," $end = $end \u003c 0 ? $max + $end : $end;",""," return array_fill($start, $end, $value);"," }",""," /**"," * @return string"," */"," public function __toString() : string"," {"," return implode(',', $this-\u003egetBytesLengthArray());"," }","}"],"stylingDirectives":null,"colorizedLines":null,"csv":null,"csvError":null,"dependabotInfo":{"showConfigurationBanner":false,"configFilePath":null,"networkDependabotPath":"/ArrayIterator/TypedArray/network/updates","dismissConfigurationNoticePath":"/settings/dismiss-notice/dependabot_configuration_notice","configurationNoticeDismissed":null},"displayName":"ArrayBufferView.php","displayUrl":"https://github.com/ArrayIterator/TypedArray/blob/master/src/TypedArray/ArrayBufferView.php?raw=true","headerInfo":{"blobSize":"10.3 KB","deleteTooltip":"You must be signed in to make or propose changes","editTooltip":"You must be signed in to make or propose changes","ghDesktopPath":"https://desktop.github.com","isGitLfs":false,"onBranch":true,"shortPath":"4fd7b89","siteNavLoginPath":"/login?return_to=https%3A%2F%2Fgithub.com%2FArrayIterator%2FTypedArray%2Fblob%2Fmaster%2Fsrc%2FTypedArray%2FArrayBufferView.php","isCSV":false,"isRichtext":false,"toc":null,"lineInfo":{"truncatedLoc":"427","truncatedSloc":"373"},"mode":"file"},"image":false,"isCodeownersFile":null,"isPlain":false,"isValidLegacyIssueTemplate":false,"issueTemplate":null,"discussionTemplate":null,"language":"PHP","languageID":272,"large":false,"planSupportInfo":{"repoIsFork":null,"repoOwnedByCurrentUser":null,"requestFullPath":"/ArrayIterator/TypedArray/blob/master/src/TypedArray/ArrayBufferView.php","showFreeOrgGatedFeatureMessage":null,"showPlanSupportBanner":null,"upgradeDataAttributes":null,"upgradePath":null},"publishBannersInfo":{"dismissActionNoticePath":"/settings/dismiss-notice/publish_action_from_dockerfile","releasePath":"/ArrayIterator/TypedArray/releases/new?marketplace=true","showPublishActionBanner":false},"rawBlobUrl":"https://github.com/ArrayIterator/TypedArray/raw/refs/heads/master/src/TypedArray/ArrayBufferView.php","renderImageOrRaw":false,"richText":null,"renderedFileInfo":null,"shortPath":null,"symbolsEnabled":true,"tabSize":8,"topBannersInfo":{"overridingGlobalFundingFile":false,"globalPreferredFundingPath":null,"showInvalidCitationWarning":false,"citationHelpUrl":"https://docs.github.com/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-citation-files","actionsOnboardingTip":null},"truncated":false,"viewable":true,"workflowRedirectUrl":null,"symbols":null},"copilotInfo":null,"copilotAccessAllowed":false,"modelsAccessAllowed":false,"modelsRepoIntegrationEnabled":false,"csrf_tokens":{"/ArrayIterator/TypedArray/branches":{"post":"uHXNn5AClynN2JvK7XSj8nn6t3qRKQ6Os3Re-E6wKXRutQ_e1Pu9vMQDDX7N8xntJx7pKfpVo4hmjJtxyfKEVA"},"/repos/preferences":{"post":"6jZeL-Rs7uv4EJxWXUDfyKBg63RHnzLfnUKm8K56NFS-L4kv1Gx33T6jKkf-t7axWPzBuMQEnASi4wtEfFhXQQ"}}},"title":"TypedArray/src/TypedArray/ArrayBufferView.php at master · ArrayIterator/TypedArray","appPayload":{"helpUrl":"https://docs.github.com","findFileWorkerPath":"/assets-cdn/worker/find-file-worker-263cab1760dd.js","findInFileWorkerPath":"/assets-cdn/worker/find-in-file-worker-b84e9496fc59.js","githubDevUrl":null,"enabled_features":{"code_nav_ui_events":false,"react_blob_overlay":false,"accessible_code_button":true}}}
0