Skip to content
This repository was archived by the owner on Nov 22, 2022. It is now read-only.

Commit 1ab62dc

Browse files
committed
Initial Commit
0 parents  commit 1ab62dc

30 files changed

+3051
-0
lines changed

.gitignore

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Files that might appear in the root of a volume
2+
.DocumentRevisions-V100
3+
.fseventsd
4+
.Spotlight-V100
5+
.TemporaryItems
6+
.Trashes
7+
.VolumeIcon.icns
8+
.DS_Store
9+
10+
# Windows Installer files
11+
*.cab
12+
*.msi
13+
*.msm
14+
*.msp
15+
*.exe
16+
17+
# Windows shortcuts
18+
*.lnk
19+
20+
#
21+
# =================================
22+
# Gitignore For Linux OS
23+
# =================================
24+
25+
# KDE directory preferences
26+
.directory
27+
28+
29+
#
30+
# =================================
31+
# Gitignore For Jetbrain
32+
# =================================
33+
34+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
35+
*.iml
36+
37+
# Directory-based project format:
38+
.idea/*.xml
39+
.idea/*/
40+
41+
# File-based project format:
42+
*.ipr
43+
*.iws
44+
45+
# JIRA plugin
46+
atlassian-ide-plugin.xml
47+
48+
#
49+
# =================================
50+
# Gitignore For Text Editor
51+
# =================================
52+
53+
# cache files for sublime text
54+
*.tmlanguage.cache
55+
*.tmPreferences.cache
56+
*.stTheme.cache
57+
58+
# workspace files are user-specific
59+
*.sublime-workspace
60+
61+
# project files should be checked into the repository, unless a significant
62+
# proportion of contributors will probably not be using SublimeText
63+
# *.sublime-project
64+
65+
# sftp configuration file
66+
sftp-config.json
67+
68+
# Ignore Sublime .phpintel
69+
.phpintel
70+
71+
# Ignore Visual Studio code
72+
.vscode
73+
74+
#
75+
# =================================
76+
# Gitignore For Composer & Projects
77+
# =================================
78+
79+
# ignore all lock file
80+
*.lock
81+
82+
# ignore all log file
83+
*.log
84+
85+
# ignore composer phar file
86+
composer.phar
87+
88+
# add exclude vendor
89+
vendor
90+

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 ArrayIterator
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Typed Arrays
2+
3+
PHP Implementation of [JavaScript Typed Arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays)
4+
5+
Use return value like a javascript object.
6+
7+
## OBJECT
8+
9+
### CLASS
10+
11+
- [ArrayBuffer](src/TypedArray/ArrayBuffer.php)
12+
- [Uint8Array](src/TypedArray/Uint8Array.php)
13+
- [Uint16Array](src/TypedArray/Uint16Array.php)
14+
- [Uint32Array](src/TypedArray/Uint32Array.php)
15+
- [Float32Array](src/TypedArray/Float32Array.php)
16+
- [Float64Array](src/TypedArray/Float64Array.php)
17+
- [Int8Array](src/TypedArray/Int8Array.php)
18+
- [Int16Array](src/TypedArray/Int16Array.php)
19+
- [Int32Array](src/TypedArray/Int32Array.php)
20+
21+
22+
### MOCK ABSTRACT
23+
24+
- [ArrayLike](src/TypedArray/ArrayLike.php)
25+
- [ArrayBufferAbstract](src/TypedArray/ArrayBufferAbstract.php)
26+
- [ArrayBufferLike](src/TypedArray/ArrayBufferLike.php)
27+
- [ArrayBufferView](src/TypedArray/ArrayBufferView.php)
28+
29+
30+
### INTERFACE
31+
32+
- [ArrayBufferConstructorInterface](src/TypedArray/Interfaces/ArrayBufferConstructorInterface.php)
33+
- [ArrayBufferInterface](src/TypedArray/Interfaces/ArrayBufferInterface.php)
34+
- [ArrayBufferLikeInterface](src/TypedArray/Interfaces/ArrayBufferLikeInterface.php)
35+
- [ArrayBufferViewInterface](src/TypedArray/Interfaces/ArrayBufferViewInterface.php)
36+
- [BufferInterface](src/TypedArray/Interfaces/BufferInterface.php)
37+
- [DataViewInterface](src/TypedArray/Interfaces/DataViewInterface.php)
38+
39+
40+
41+
## TODO
42+
43+
### NEXT
44+
45+
- to add `UInt8ClampedArray`
46+
- to add `DataView` object class implements of [DataViewInterface](src/TypedArray/Interfaces/DataViewInterface.php)
47+
48+
49+
### PROGRESS
50+
51+
- [Buffer](src/TypedArray/Buffer.php) `add more methods`
52+
- [ArrayBufferViewInterface](src/TypedArray/Interfaces/ArrayBufferViewInterface.php) `add more methods`
53+
54+
55+
### INTERFACE
56+
57+
- [DataViewInterface](src/TypedArray/Interfaces/Uint8ClampedArrayInterface.php)
58+
59+
60+
61+
62+
## NOTE
63+
64+
Float Precision decimal point set by `ini_set('precision', (number))` or set default on `php.ini`
65+
66+
67+
68+
## LICENSE
69+
70+
[MIT LICENSE](LICENSE)
71+

composer.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "arrayiterator/typed-array",
3+
"license": "MIT",
4+
"description": "Typed Array",
5+
"authors": [
6+
{
7+
"name": "ArrayIterator",
8+
"role": "Developer",
9+
"email": "ArrayIterator@gmail.com"
10+
}
11+
],
12+
"require": {
13+
"php": ">= 7.1",
14+
"ext-iconv": "*"
15+
},
16+
"require-dev": {
17+
"squizlabs/php_codesniffer": "3.*"
18+
},
19+
"config": {
20+
"optimize-autoloader": true
21+
},
22+
"autoload": {
23+
"psr-4": {
24+
"ArrayIterator\\TypedArray\\" : "src/TypedArray/"
25+
}
26+
}
27+
}

phpcs.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ MIT License
4+
~
5+
~ Copyright (c) 2018
6+
~
7+
~ Permission is hereby granted, free of charge, to any person obtaining a copy
8+
~ of this software and associated documentation files (the "Software"), to deal
9+
~ in the Software without restriction, including without limitation the rights
10+
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
~ copies of the Software, and to permit persons to whom the Software is
12+
~ furnished to do so, subject to the following conditions:
13+
~
14+
~ The above copyright notice and this permission notice shall be included in all
15+
~ copies or substantial portions of the Software.
16+
~
17+
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
~ FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
20+
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
~ SOFTWARE.
24+
-->
25+
26+
<ruleset name="Coding Standard">
27+
<description>Coding Standard</description>
28+
<!-- Display Progress -->
29+
<arg value="p"/>
30+
<!-- Use Colorized Output -->
31+
<arg name="colors"/>
32+
<!-- Rule Set -->
33+
<rule ref="PSR2"/>
34+
<!-- preventing duplicate class name -->
35+
<rule ref="Generic.Classes.DuplicateClassName"/>
36+
<!-- must be have line ending -->
37+
<rule ref="Generic.Files.LineEndings"/>
38+
<!-- array must be use short syntax array() == [] -->
39+
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
40+
<!-- Path To Check -->
41+
<file>src/</file>
42+
</ruleset>

src/TypedArray/ArrayBuffer.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* MIT License
4+
*
5+
* Copyright (c) 2018 ArrayIterator
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
* SOFTWARE.
24+
*/
25+
26+
declare(strict_types=1);
27+
28+
namespace ArrayIterator\TypedArray;
29+
30+
use ArrayIterator\TypedArray\Interfaces\ArrayBufferInterface;
31+
use ArrayIterator\TypedArray\Interfaces\ArrayBufferViewInterface;
32+
use ArrayIterator\TypedArray\Interfaces\BufferInterface;
33+
34+
/**
35+
* Class ArrayBuffer
36+
* @package ArrayIterator\TypedArray
37+
*/
38+
class ArrayBuffer extends ArrayBufferAbstract
39+
{
40+
/**
41+
* ArrayBuffer constructor.
42+
* @param int $byteLength
43+
*/
44+
public function __construct(int $byteLength = 0)
45+
{
46+
parent::__construct($byteLength);
47+
}
48+
49+
/**
50+
* {@inheritdoc}
51+
*/
52+
public static function isView($any) : bool
53+
{
54+
if (!is_object($any)) {
55+
return false;
56+
}
57+
58+
return $any instanceof ArrayBufferViewInterface || $any instanceof BufferInterface;
59+
}
60+
61+
/**
62+
* {@inheritdoc}
63+
*/
64+
public function slice(int $begin = null, int $end = null) : ArrayBufferInterface
65+
{
66+
$max = $this->getByteLength();
67+
$begin = $begin?: 0;
68+
$begin = $begin < -$max ? -$max : $begin;
69+
$end = $end === null || $end > $max ? $max : $end;
70+
if ($max < $begin || $begin >= $end || $end <= -$max) {
71+
return new static();
72+
}
73+
74+
return new static($end - $begin);
75+
}
76+
77+
/**
78+
* @return \ArrayIterator|\Traversable
79+
*/
80+
public function getIterator() : \Traversable
81+
{
82+
return new \ArrayIterator(get_object_vars($this));
83+
}
84+
}

0 commit comments

Comments
 (0)