Skip to content

Commit ec9a67f

Browse files
Update README.md
1 parent 9a053ba commit ec9a67f

65 files changed

Lines changed: 1704 additions & 1429 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,92 @@ ascending order:
143143
3 - 5 - 1 - 2 - 4
144144
```
145145

146+
### Custom Column
147+
148+
When working with an array of objects, you can specify which value can be used for sorting.
149+
150+
```php
151+
use DragonCode\SizeSorter\SizeSorter;
152+
153+
return new SizeSorter($items)
154+
->column('foo')
155+
->sort();
156+
```
157+
158+
You can also use "dotted" notation:
159+
160+
```php
161+
use DragonCode\SizeSorter\SizeSorter;
162+
163+
$items = [
164+
[
165+
'foo' => [
166+
'bar' => [
167+
'baz' => 'Some value',
168+
]
169+
]
170+
]
171+
];
172+
173+
return new SizeSorter($items)
174+
->column('foo.bar.baz')
175+
->sort();
176+
```
177+
178+
And you can use the callback function in the same way:
179+
180+
```php
181+
use DragonCode\SizeSorter\SizeSorter;
182+
183+
class Foo
184+
{
185+
public function __construct(
186+
public int $number,
187+
public string $value1,
188+
public string $value2,
189+
) {}
190+
}
191+
192+
$items = [
193+
new Foo(1, 'first 1', 'first 2'),
194+
new Foo(2, 'second 1', 'second 2'),
195+
];
196+
197+
return new SizeSorter($items)
198+
->column(function (Foo $item) {
199+
return $item->number % 2 === 0
200+
? $item->value1
201+
: $item->value2;
202+
})
203+
->sort();
204+
```
205+
206+
And this is also possible:
207+
208+
```php
209+
use DragonCode\SizeSorter\SizeSorter;
210+
211+
$items = [
212+
['foo' => 'XS'],
213+
['foo' => '2XS'],
214+
['foo' => '3XL'],
215+
];
216+
217+
return new SizeSorter($items)
218+
->column(function (array $item) {
219+
return match ($item['foo']) {
220+
'2XS' => 'XXS',
221+
'3XL' => 'XXXL',
222+
default => $item['foo']
223+
};
224+
})
225+
->sort();
226+
```
227+
228+
## Upgrade Guide
229+
230+
You can find the upgrade documentation [here](UPGRADE.md).
231+
146232
## License
147233

148234
This package is licensed under the [MIT License](LICENSE).

UPGRADE.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Upgrade Guide
2+
3+
## To 2.x from 1.0
4+
5+
### Updating Dependencies
6+
7+
You should update the following dependencies in your application's `composer.json` file:
8+
9+
- `dragon-code/size-sorter` to `^2.0`
10+
11+
### Changing Namespace
12+
13+
Namespace should be changed:
14+
15+
You should update the namespace and method name to call:
16+
17+
```diff
18+
-DragonCode\SizeSorter\Sorter::sort()
19+
+DragonCode\SizeSorter\SizeSorter::items()
20+
21+
-use DragonCode\SizeSorter\Enum\Group;
22+
+use DragonCode\SizeSorter\Enums\GroupEnum;
23+
```
24+
25+
### Changing parameters and call methods
26+
27+
```diff
28+
-use DragonCode\SizeSorter\Sorter;
29+
-use DragonCode\SizeSorter\Enum\Group;
30+
+use DragonCode\SizeSorter\SizeSorter;
31+
+use DragonCode\SizeSorter\Enums\GroupEnum;
32+
33+
-$sort1 = Sorter::sort($items, 'column.name', [1, 2]);
34+
-$sort2 = Sorter::sort($items, 'column.name', [Group::GROUP_1, Group::GROUP_2]);
35+
+
36+
+$sort = SizeSorter::items($items)
37+
+ ->column('column.name')
38+
+ ->orderBy([
39+
+ GroupEnum::LetterClothingSize,
40+
+ GroupEnum::ClothesAndShoes,
41+
+ ])
42+
+ ->sort();
43+
```
44+
45+
### Groups
46+
47+
> [!WARNING]
48+
>
49+
> The array to sort must now consist of GroupEnum objects.
50+
> Integers are no longer accepted.
51+
52+
'Group::GROUP_1' replaced by `GroupEnum::LetterClothingSize`
53+
'Group::GROUP_2' replaced by `GroupEnum::ClothesAndShoes`
54+
'Group::GROUP_3' replaced by `GroupEnum::BraSize`
55+
'Group::GROUP_4' replaced by `GroupEnum::OverallDimensions`
56+
'Group::GROUP_5' replaced by `GroupEnum::OtherSizes`
57+
58+
```php
59+
enum GroupEnum: int
60+
{
61+
case LetterClothingSize = 1;
62+
case ClothesAndShoes = 2;
63+
case BraSize = 3;
64+
case OverallDimensions = 4;
65+
case OtherSizes = 5;
66+
}
67+
```

src/Contracts/Detector.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Contracts/Normalizer.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Contracts/Sorter.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Detectors/BaseDetector.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/Detectors/BraSizeDetector.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/Detectors/ClothesAndShoesDetector.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/Detectors/LetterClothingSizeDetector.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Detectors/OverallDimensionsDetector.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)