Skip to content

Commit be5f45f

Browse files
committed
update docs
1 parent 76fdf2f commit be5f45f

2 files changed

Lines changed: 188 additions & 9 deletions

File tree

v5/extension-seo.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ The SEO extension comes with several hooks.
8080
2. Filter - `typerocket_seo_meta` - Used to filter the meta data used for meta tags.
8181
3. Action - `typerocket_seo_fields` - Used to add custom fields to the general tab of the SEO meta box.
8282
4. Filter - `typerocket_seo_post_types` - Used to control which post types have the SEO meta box.
83-
6. Filter - `typerocket_seo_url` - Used to control the URL used for OG.
83+
6. Filter - `typerocket_seo_url` - Used to control the URL used for OG.
84+
7. Filter - `typerocket_view_document_title` - Used to control the document title text.
8485

8586
### typerocket_seo_post_types
8687

@@ -111,4 +112,14 @@ add_action('typerocket_seo_meta', function($seo) {
111112
$keywords = esc_attr($seo->meta['basic']['keywords'] ?? '')
112113
echo "<meta name=\"keywords\" content"{$keywords}">";
113114
});
115+
```
116+
117+
### typerocket_view_document_title
118+
119+
You can use the `typerocket_view_document_title` to set a view's document title text. This can be helpful when an SEO plugin overrides the document title text, and you want to set the view's title.
120+
121+
```php
122+
add_filter('typerocket_view_document_title', function($title, $view) {
123+
return $title
124+
}, 10, 2);
114125
```

v5/utilities.md

Lines changed: 176 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@ Arr::divide($array);
2020
// [ ['one', 'two'],[1,2] ]
2121
```
2222

23+
## Arr:exists
24+
25+
The `Arr::exists()` method check if a key exists for the given `array` or `ArrayAccess` object:
26+
27+
```php
28+
use \TypeRocket\Utility\Arr;
29+
30+
$array = ['one' => 1];
31+
32+
Arr::exists($array, 'one');
33+
// true
34+
35+
$array = new \ArrayObject();
36+
$array['one'] = 1;
37+
38+
Arr::exists($array, 'one');
39+
// true
40+
```
41+
2342
### Arr::filterNull
2443

2544
The `Arr::filterNull()` method removes all `null` values from the given array:
@@ -33,6 +52,45 @@ Arr::filterNull($array);
3352
// [0 => 0]
3453
```
3554

55+
### Arr::first
56+
57+
The `Arr::first()` method returns the first element of an array:
58+
59+
```php
60+
use \TypeRocket\Utility\Arr;
61+
62+
$array = [1, 2, 3];
63+
64+
Arr::first($array);
65+
// 1
66+
```
67+
68+
As the second parameter a callback may be passed to the method. When the callback returns `true` the first element passing a given truth test is returned:
69+
70+
```php
71+
use \TypeRocket\Utility\Arr;
72+
$array = [1, 2, 3];
73+
74+
Arr::first($array, function ($value, $key) {
75+
return $value === 2;
76+
});
77+
// 2
78+
```
79+
80+
A default value may also be passed as the third parameter to the method. This value will be returned if no value passes the truth test:
81+
82+
```php
83+
use \TypeRocket\Utility\Arr;
84+
85+
$array = [1, 2, 3];
86+
$default = 4;
87+
88+
Arr::first($array, function ($value, $key) {
89+
return $value > 3;
90+
}, $default);
91+
// 4
92+
```
93+
3694
### Arr::format
3795

3896
The `Arr::format()` method applies a callback to an arrays a values using dot notation. The returned value is the endpoint of the dot notation lookup. The array is mutated by reference.
@@ -97,7 +155,7 @@ $price = Arr::get($array, 'product.name', 10);
97155

98156
### Arr::has
99157

100-
The `Arr::has()` method checks if a given item exists in an array using dot notation:
158+
The `Arr::has()` method checks if a given key exists in an array using dot notation:
101159

102160
```php
103161
use \TypeRocket\Utility\Arr;
@@ -111,6 +169,17 @@ $price = Arr::has($array, 'product.tax');
111169
// false
112170
```
113171

172+
You can also check for multiple keys:
173+
174+
```php
175+
use \TypeRocket\Utility\Arr;
176+
177+
$array = ['product' => ['name' => null, 'price' => 99]];
178+
179+
$price = Arr::has($array, ['product.name', 'product.price']);
180+
// true
181+
```
182+
114183
### Arr::indexBy
115184

116185
The `Arr::indexBy()` method indexes a sequential array by a key when all keyed values are unique:
@@ -205,6 +274,45 @@ Arr::isAssociative(['tax'], $array);
205274
// false
206275
```
207276

277+
### Arr::last
278+
279+
The `Arr::last()` method returns the first element of an array:
280+
281+
```php
282+
use \TypeRocket\Utility\Arr;
283+
284+
$array = [1, 2, 3];
285+
286+
Arr::last($array);
287+
// 3
288+
```
289+
290+
As the second parameter a callback may be passed to the method. When the callback returns `true` the last element passing a given truth test is returned:
291+
292+
```php
293+
use \TypeRocket\Utility\Arr;
294+
$array = [1, 2, 3];
295+
296+
Arr::last($array, function ($value, $key) {
297+
return $value === 2;
298+
});
299+
// 2
300+
```
301+
302+
A default value may also be passed as the third parameter to the method. This value will be returned if no value passes the truth test:
303+
304+
```php
305+
use \TypeRocket\Utility\Arr;
306+
307+
$array = [1, 2, 3];
308+
$default = 4;
309+
310+
Arr::last($array, function ($value, $key) {
311+
return $value > 3;
312+
}, $default);
313+
// 4
314+
```
315+
208316
### Arr::meld
209317

210318
The `Arr::meld()` method reduces a deeply nested array into a dot notation keyed flat array:
@@ -366,9 +474,23 @@ $price = Arr::set('product.name', $array, 'mic');
366474

367475
The functions of the `\TypeRocket\Utility\Str` class are all UTF8 enabled and can work with Unicode characters.
368476

477+
### Str::blank
478+
479+
The `Str::blank()` method checks if a given value is an empty string or not set:
480+
481+
```php
482+
use \TypeRocket\Utility\Str;
483+
484+
Str::blank('');
485+
// true
486+
487+
Str::blank(null);
488+
// true
489+
```
490+
369491
### Str::camelize
370492

371-
Use the method `Str::camelize()` to camel case a string.
493+
The `Str::camelize()` method camel cases a string:
372494

373495
```php
374496
use \TypeRocket\Utility\Str;
@@ -378,6 +500,9 @@ $capitalize_first_char = true;
378500

379501
Str::camelize($name, '_', $capitalize_first_char);
380502
// 'HiThere'
503+
504+
Str::camelize($name, '', $capitalize_first_char);
505+
// 'Hi_There'
381506
```
382507

383508
### Str::classNames
@@ -435,7 +560,7 @@ Str::classNames($base, $array, $fallback);
435560

436561
### Str::contains
437562

438-
Use the method `Str::contains()` to test if a string contains a value.
563+
The `Str::contains()` method tests if a string contains a value:
439564

440565
```php
441566
use \TypeRocket\Utility\Str;
@@ -446,7 +571,7 @@ Str::contains('it', 'Name it!');
446571

447572
### Str::ends
448573

449-
Use the method `Str::ends()` to test if a string ends with a value.
574+
The `Str::ends()` method tests if a string ends with a value:
450575

451576
```php
452577
use \TypeRocket\Utility\Str;
@@ -457,7 +582,7 @@ Str::ends('it!', 'Names it!');
457582

458583
### Str::explodeFromRight
459584

460-
Use the method `Str::explodeFromRight()` to test if a string contains a value.
585+
The `Str::explodeFromRight()` method tests if a string contains a value:
461586

462587
```php
463588
use \TypeRocket\Utility\Str;
@@ -616,7 +741,7 @@ Str::snake('foo bar');
616741

617742
### Str::starts
618743

619-
Use the method `Str::starts()` to test if a string starts with a value.
744+
The `Str::starts()` method tests if a string starts with a value:
620745

621746
```php
622747
use \TypeRocket\Utility\Str;
@@ -627,7 +752,7 @@ Str::starts('Name', 'Name it!');
627752

628753
### Str::trimStart
629754

630-
Use the method `Str::trimStart()` to trim the start of a string.
755+
The `Str::trimStart()` method trims the start of a string:
631756

632757
```php
633758
use \TypeRocket\Utility\Str;
@@ -638,7 +763,7 @@ Str::trimStart('hi_there', 'hi_');
638763

639764
### Str::uppercaseWords
640765

641-
Use the method `Str::uppercaseWords()` to apply `MB_CASE_TITLE` to a string.
766+
The `Str::uppercaseWords()` method applies `MB_CASE_TITLE` to a string:
642767

643768
```php
644769
use \TypeRocket\Utility\Str;
@@ -873,6 +998,49 @@ Data::isJson('""');
873998
// false
874999
```
8751000

1001+
### Data::map
1002+
1003+
The `Data::map()` method maps a function to a value, or when an array or an object all iterable values:
1004+
1005+
```php
1006+
use TypeRocket\Utility\Data;
1007+
1008+
$object = new \stdClass();
1009+
$object->one = 1;
1010+
1011+
Data::map(function($value) {
1012+
return $value * 4;
1013+
}, $object);
1014+
// $object->one = 4
1015+
1016+
$array = ['one' => 1];
1017+
1018+
Data::map(function($value) {
1019+
return $value * 4;
1020+
}, $array);
1021+
// ['one' => 4]
1022+
1023+
$int = 1;
1024+
1025+
Data::map(function($value) {
1026+
return $value * 4;
1027+
}, $int);
1028+
// 4
1029+
```
1030+
1031+
### Data::mapDeep
1032+
1033+
The `Data::mapDeep()` method maps a function to all non-iterable elements of an array or an object. This is similar to `array_walk_recursive()` but acts upon objects too:
1034+
1035+
```php
1036+
use TypeRocket\Utility\Data;
1037+
1038+
Data::mapDeep(function($value) {
1039+
return $value * 4;
1040+
}, [[2],[2], 2]);
1041+
// [ [8], [8], 8 ]
1042+
```
1043+
8761044
### Data::nil
8771045

8781046
The `Data::nil()` method allows for chaining a number of property lookups without throwing an error. It does not provide access to object functions.

0 commit comments

Comments
 (0)