Skip to content

Commit c201604

Browse files
committed
update the rest of functionality
1 parent d493d0f commit c201604

File tree

2 files changed

+64
-12
lines changed

2 files changed

+64
-12
lines changed

index.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@ public function __construct()
3939
// Scalar Types
4040
$this->account_balance = float32(1234.56);
4141
$this->investment_amount = float64(78910.12345);
42-
$this->grade = new Char('A');
43-
$this->age = new Byte(25);
42+
$this->grade = char('A');
43+
$this->age = byte(25);
4444

4545
// Composite Types (Arrays)
46-
$this->names = new StringArray(['John', 'Jane', 'Doe']);
47-
$this->scores = new IntArray([100, 95, 87]);
48-
$this->weights = new FloatArray([60.5, 72.3, 88.9]);
49-
$this->data = new ByteSlice([255, 128, 0]);
46+
$this->names = stringArray(['John', 'Jane', 'Doe']);
47+
$this->scores = intArray([100, 95, 87]);
48+
$this->weights = floatArray([60.5, 72.3, 88.9]);
49+
$this->data = byteSlice([255, 128, 0]);
5050

51-
$this->listData = new ListData(['apple', 'banana', 'orange']);
52-
$this->dictionary = new Dictionary(['name' => 'Nejc', 'age' => 99, 'country' => 'Slovenia']);
51+
$this->listData = listData(['apple', 'banana', 'orange']);
52+
$this->dictionary = dictionary(['name' => 'Nejc', 'age' => 99, 'country' => 'Slovenia']);
5353

54-
$this->struct = new Struct([
54+
$this->struct =struct([
5555
'name' => 'string',
5656
'age' => 'int',
5757
'balance' => 'float'

src/helpers.php

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
<?php
22
declare(strict_types=1);
33

4-
use Nejcc\PhpDatatypes\Floats\Float128;
5-
use Nejcc\PhpDatatypes\Floats\Float16;
6-
use Nejcc\PhpDatatypes\Floats\Float8;
4+
use Nejcc\PhpDatatypes\Composite\Arrays\ByteSlice;
5+
use Nejcc\PhpDatatypes\Composite\Arrays\FloatArray;
6+
use Nejcc\PhpDatatypes\Composite\Arrays\IntArray;
7+
use Nejcc\PhpDatatypes\Composite\Arrays\StringArray;
8+
use Nejcc\PhpDatatypes\Composite\Dictionary;
9+
use Nejcc\PhpDatatypes\Composite\ListData;
10+
use Nejcc\PhpDatatypes\Composite\Struct\Struct;
11+
use Nejcc\PhpDatatypes\Scalar\Byte;
12+
use Nejcc\PhpDatatypes\Scalar\Char;
713
use Nejcc\PhpDatatypes\Scalar\FloatingPoints\Float32;
814
use Nejcc\PhpDatatypes\Scalar\FloatingPoints\Float64;
915
use Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int128;
@@ -75,3 +81,49 @@ function float64(float $value): Float64
7581
{
7682
return new Float64($value);
7783
}
84+
85+
function char(string $value): Char
86+
{
87+
return new Char($value);
88+
}
89+
90+
function byte(string|int $value): Byte
91+
{
92+
return new Byte($value);
93+
}
94+
95+
function stringArray(array $value): StringArray
96+
{
97+
return new StringArray($value);
98+
}
99+
100+
function intArray(array $value): IntArray
101+
{
102+
return new IntArray($value);
103+
}
104+
105+
function floatArray(array $value): FloatArray
106+
{
107+
return new FloatArray($value);
108+
}
109+
110+
function byteSlice(array $value): ByteSlice
111+
{
112+
return new ByteSlice($value);
113+
}
114+
115+
function listData(array $value): ListData
116+
{
117+
return new ListData($value);
118+
}
119+
120+
function dictionary(array $value): Dictionary
121+
{
122+
return new Dictionary($value);
123+
}
124+
125+
function struct(array $fields): Struct
126+
{
127+
return new Struct($fields);
128+
}
129+

0 commit comments

Comments
 (0)