Skip to content

Commit 2fa7e89

Browse files
update
1 parent b5cca72 commit 2fa7e89

30 files changed

+1184
-0
lines changed

tests/collection.php

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
<?php
2+
3+
use Tamedevelopers\Support\Collections\Collection;
4+
5+
require_once __DIR__ . '/../vendor/autoload.php';
6+
7+
8+
9+
$data = [
10+
['id' => 1, 'name' => 'John', 'age' => 28],
11+
['id' => 2, 'name' => 'Jane', 'age' => 22],
12+
['id' => 3, 'name' => 'Doe', 'age' => 31],
13+
['id' => 4, 'name' => 'Smith', 'age' => 29],
14+
['id' => 5, 'name' => 'Emily', 'age' => 25],
15+
];
16+
17+
$language = tcollect([
18+
'en' => [
19+
'lang_name' => 'English',
20+
'flag' => 'us',
21+
'locale_iso' => 'en',
22+
'locale' => 'en',
23+
'locale_allow' => 'true',
24+
'speakers' => [
25+
'first_day' => ['Rosa', 'Judith'],
26+
]
27+
],
28+
'cn' => [
29+
'lang_name' => '中文',
30+
'flag' => 'hk',
31+
'locale_iso' => 'cn',
32+
'locale' => 'zh-Hant',
33+
'locale_allow' => 'true',
34+
'speakers' => [
35+
'first_day' => ['Abigail', 'Joey'],
36+
],
37+
]
38+
]);
39+
40+
41+
dump(
42+
$language
43+
->filter(fn($value) => $value['locale_allow'] == 'true')
44+
->mapWithKeys(fn ($value) => [
45+
$value['locale_iso'] => [
46+
'name' => $value['lang_name'],
47+
'flag' => $value['flag'],
48+
'iso' => $value['locale_iso'],
49+
'locale' => $value['locale'],
50+
]
51+
])
52+
->forget(['name', 'isos'])
53+
->toArray(),
54+
);
55+
56+
57+
58+
// Create a new collection instance
59+
$collection = TameCollect($data);
60+
61+
// getIterator()
62+
$iterator = $collection->getIterator();
63+
foreach ($iterator as $item) {
64+
// Process each item
65+
}
66+
67+
68+
// has()
69+
$hasId2 = $collection->has(1); // true
70+
71+
// count()
72+
$count = $collection->count(); // 5
73+
74+
// all()
75+
$allItems = $collection->all(); // All items in the collection
76+
77+
// first()
78+
$firstItem = $collection->first(); // ['id' => 1, 'name' => 'John', 'age' => 28]
79+
80+
// last()
81+
$lastItem = $collection->last(); // ['id' => 5, 'name' => 'Emily', 'age' => 25]
82+
83+
// isNotEmpty()
84+
$isNotEmpty = $collection->isNotEmpty(); // true
85+
86+
// isEmpty()
87+
$isEmpty = $collection->isEmpty(); // false
88+
89+
// filter()
90+
$filtered = $collection->filter(fn($item) => $item['age'] > 25); // Filter items with age > 25
91+
92+
// map()
93+
$mapped = $collection->map(fn($item) => $item['name']); // ['John', 'Jane', 'Doe', 'Smith', 'Emily']
94+
95+
// reduce()
96+
$sumAge = $collection->reduce(fn($carry, $item) => $carry + $item['age'], 0); // Sum of ages
97+
98+
// reverse()
99+
$reversed = $collection->reverse(); // Reverse the collection
100+
101+
// pad()
102+
$padded = $collection->pad(7, ['id' => 0, 'name' => 'Unknown', 'age' => 0]); // Pad with default values
103+
104+
// combine()
105+
$keys = ['first', 'second', 'third', 'fourth', 'fifth'];
106+
$combined = $collection->combine($keys); // Combine with new keys
107+
108+
// collapse()
109+
$multiDimensional = new Collection([
110+
['a' => 1, 'b' => 2],
111+
['c' => 3, 'd' => 4],
112+
]);
113+
$collapsed = $multiDimensional->collapse(); // Flatten nested collections
114+
115+
// flatten()
116+
$nested = new Collection([
117+
[1, 2], [3, 4], [5, 6], ['Peterson', 39, ['name' => 'Fredrick']]
118+
]);
119+
120+
dump(
121+
'flatten',
122+
$nested->flatten(),
123+
// [1, 2, 3, 4, 5, 6, 'Peterson', 39, 'Fredrick']
124+
);
125+
126+
// zip()
127+
$additionalArray = [10, 20, 30, 40, 50];
128+
dump(
129+
'zip',
130+
$collection->zip($additionalArray)
131+
// Combine items with another array
132+
);
133+
134+
// merge()
135+
dump(
136+
'merge',
137+
$collection->merge([['id' => 6, 'name' => 'Sarah', 'age' => 30]])
138+
);
139+
140+
// chunk()
141+
$chunked = $collection->chunk(2); // Split into chunks of size 2
142+
143+
// keys()
144+
$keys = $collection->keys(); // ['id', 'name', 'age']
145+
146+
// values()
147+
$values = $collection->values(); // [1, 2, 3, 4, 5]
148+
149+
// contains()
150+
$containsAge28 = $collection->contains(['age' => 28]); // true
151+
152+
// doesntContain()
153+
$doesNotContain = $collection->doesntContain('name', 'John'); // false
154+
155+
// pluck()
156+
dump(
157+
'pluck',
158+
$language->pluck('lang_name', 'locale')->all(), // ["en" => "English", "zh-Hant" => "中文"]
159+
// $language->pluck('speakers.first_day', 'flag')->all(),
160+
// $collection->pluck('name', 'age'),
161+
);
162+
163+
// select()
164+
dump(
165+
'select[name, age] and pluck(age)',
166+
$collection->select(['name', 'age'])->all()
167+
);
168+
169+
// search()
170+
dump(
171+
'search',
172+
$collection->search('Jane')
173+
// 1
174+
);
175+
176+
// sort()
177+
$sortedByName = $collection->sort(); // Sort by values (default sorting)
178+
179+
// sortBy()
180+
$sortedByAge = $collection->sortBy('age'); // Sort by age
181+
182+
// sortByMany()
183+
dump(
184+
'sortByMany',
185+
$collection->sortByMany(['age' => SORT_DESC, 'name' => SORT_ASC])
186+
// Sort by age descending, then name ascending
187+
);
188+
189+
// unique()
190+
dump(
191+
'unique',
192+
$collection->unique()
193+
// Get unique items
194+
);

tests/configuration/banners.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Template File Lines
8+
|--------------------------------------------------------------------------
9+
|
10+
| The following template lines are used during text formatting for various
11+
| messages that we need to display to the user. You are free to modify
12+
| these template lines according to your application's requirements.
13+
|
14+
*/
15+
16+
0 =>
17+
array (
18+
'id' => '1',
19+
'image' => '1641091145e5b7a7e1d49ea7c.jpg',
20+
'active' => '1',
21+
'created_at' => NULL,
22+
'updated_at' => NULL,
23+
),
24+
1 =>
25+
array (
26+
'id' => '2',
27+
'image' => '1664740030ecbe7957d14eaa7.jpg',
28+
'active' => '1',
29+
'created_at' => NULL,
30+
'updated_at' => NULL,
31+
),
32+
2 =>
33+
array (
34+
'id' => '3',
35+
'image' => '165353683347c9eea1a5bd77e.jpg',
36+
'active' => '1',
37+
'created_at' => NULL,
38+
'updated_at' => NULL,
39+
),
40+
];

tests/cookie.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use Tamedevelopers\Support\Cookie;
4+
5+
require_once __DIR__ . '/../vendor/autoload.php';
6+
7+
8+
9+
// this will return instance of a Cookie
10+
// since by default the function name cookie already exists
11+
// so we can't be able to create helper function with that name
12+
// TameCookie()
13+
14+
15+
TameCookie()->set('cookie_name', 'value');
16+
17+
// Cookie::set('cookie_name', 'value');
18+
19+
20+
dd(
21+
22+
Cookie::all(),
23+
24+
TameCookie()->get('cookie_name'),
25+
26+
Cookie::forget('cookie_name2'),
27+
28+
Cookie::expire('cookie_name2'),
29+
);

tests/country.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
use Tamedevelopers\Support\Country;
4+
5+
require_once __DIR__ . '/../vendor/autoload.php';
6+
7+
8+
// helper function
9+
// TameCountry();
10+
11+
// Country::countryIso3()
12+
13+
dd(
14+
15+
TameCountry()->getTimeZone("Africa/Addis_Ababa"),
16+
17+
TameCountry()->getCaptchaLocale('ar'),
18+
19+
Country::getCountryIso3('NGA')
20+
);

tests/icons.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
use Tamedevelopers\Support\Time;
4+
5+
require_once __DIR__ . '/../vendor/autoload.php';
6+
7+
8+
$platform = Tame()->platformIcon('windows');
9+
$payment = Tame()->paymentIcon('payment-wallet');
10+
11+
12+
dump(
13+
$platform,
14+
$payment,
15+
);
16+
?>
17+
18+
<!DOCTYPE html>
19+
<html lang="en">
20+
<head>
21+
<meta charset="UTF-8">
22+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
23+
<title>Document</title>
24+
<style>
25+
svg{
26+
width: 2rem;
27+
height: 2rem;
28+
object-fit: contain;
29+
30+
}
31+
section{
32+
display: flex;
33+
gap: .5rem;
34+
}
35+
</style>
36+
</head>
37+
<body>
38+
39+
<section>
40+
<div>
41+
<?php Tame()->include($platform);?>
42+
</div>
43+
44+
<div>
45+
<?php Tame()->include(Tame()->platformIcon('ios'));?>
46+
</div>
47+
48+
<div>
49+
<?php Tame()->include($payment);?>
50+
</div>
51+
</section>
52+
53+
</body>
54+
</html>
55+
56+

tests/layout/home.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>{{ $title }}</title>
5+
</head>
6+
<body>
7+
8+
{{ $appName }}
9+
<!-- {{ $header['title'] }} -->
10+
11+
@section('title', 'Homepage')
12+
13+
<main>
14+
@yield('content')
15+
</main>
16+
17+
@include('layout.partials.footer', ['year2' => $header['year']])
18+
19+
</body>
20+
</html>

tests/layout/home2.blade.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
<!-- tests/layout/partials/app.blade.php -->
3+
@extends('layout.partials.app')
4+
5+
@section('title', 'Homepage')
6+
7+
@section('content')
8+
<h1>Welcome to the Homepage!</h1>
9+
<p>This is the @\section('content') of the homepage.</p>
10+
11+
@include('layout.partials.footer', ['year2' => $header['year']])
12+
@endsection

0 commit comments

Comments
 (0)