@@ -29,9 +29,11 @@ Contents
2929 1 . [ Collection] ( #collection )
3030 1 . [ Context] ( #context )
3131 1 . [ Either] ( #either )
32+ 1 . [ Exists] ( #exists )
3233 1 . [ Filter] ( #filter )
3334 1 . [ Flatten] ( #flatten )
34- 1 . [ IfExists] ( #ifexists )
35+ 1 . [ IfElse] ( #ifelse )
36+ 1 . [ IfExists] ( #ifexists ) (deprecated)
3537 1 . [ Join] ( #join )
3638 1 . [ Merge] ( #merge )
3739 1 . [ TakeFirst] ( #takefirst )
@@ -291,10 +293,12 @@ The following strategies ship with Mapper and provide a suite of commonly used f
291293 - [ Callback] ( #callback ) &ndash ; Augments data using the specified callback.
292294 - [ Collection] ( #collection ) &ndash ; Maps a collection of data by applying a transformation to each datum.
293295 - [ Context] ( #context ) &ndash ; Replaces the context for the specified expression.
296+ - [ Exists] ( #exists ) &ndash ; Returns true or false if the resolved value of the strategy or the path exists.
294297 - [ Either] ( #either ) &ndash ; Either uses the primary strategy, if it returns non-null, otherwise delegates to a fallback expression.
295298 - [ Filter] ( #filter ) &ndash ; Filters null values or values rejected by the specified callback.
296299 - [ Flatten] ( #flatten ) &ndash ; Moves all nested values to the top level.
297- - [ IfExists] ( #ifexists ) &ndash ; Delegates to one expression or another depending on whether the specified condition maps to null.
300+ - [ IfElse] ( #ifelse ) &ndash ; Delegates to one expression or another depending on whether the specified condition loosely evaluates to true.
301+ - [ IfExists] ( #ifexists ) (deprecated) &ndash ; Delegates to one expression or another depending on whether the specified condition maps to null.
298302 - [ Join] ( #join ) &ndash ; Joins sub-string expressions together with a glue string.
299303 - [ Merge] ( #merge ) &ndash ; Merges two data sets together giving precedence to the latter if keys collide.
300304 - [ TakeFirst] ( #takefirst ) &ndash ; Takes the first value from a collection one or more times.
@@ -511,6 +515,34 @@ Either(Strategy $strategy, Strategy|Mapping|array|mixed $expression)
511515
512516> 'bar'
513517
518+ ### Exists
519+
520+ Returns true or false if the resolved value of the strategy or the path exists.
521+
522+ #### Signature
523+
524+ ``` php
525+ Exists(Strategy|array|mixed $strategyOrPath)
526+ ```
527+
528+ 1 . ` $strategyOrPath ` &ndash ; Strategy, array of path components or string of ` -> ` -delimited components.
529+
530+ #### Example
531+
532+ ``` php
533+ $data = ['foo' => 'bar']
534+
535+ (new Mapper)->map($data, new Exists('foo'));
536+ ```
537+
538+ > true
539+
540+ ``` php
541+ (new Mapper)->map($data, new Exists('bar'));
542+ ```
543+
544+ > false
545+
514546### Filter
515547
516548Filters null values or values rejected by the specified callback.
@@ -577,10 +609,42 @@ $data = [
577609
578610> [ 1, 2, 3, 3, 4, 5]
579611
612+ ### IfElse
613+
614+ Delegates to one expression or another depending on whether the specified condition loosely evaluates to true.
615+
616+ #### Signature
617+
618+ ``` php
619+ IfElse(Strategy $condition, Strategy|Mapping|array|mixed $if, Strategy|Mapping|array|mixed $else = null)
620+ ```
621+
622+ 1 . ` $condition ` &ndash ; Condition.
623+ 2 . ` $if ` &ndash ; Expression used when condition loosely evaluates to true.
624+ 3 . ` $else ` &ndash ; Expression used when condition loosely evaluates to false.
625+
626+ #### Example
627+
628+ ``` php
629+ $data = ['foo' => 'bar'];
630+
631+ (new Mapper)->map($data, new IfElse(new Exists('foo'), true, false));
632+ ```
633+
634+ > true
635+
636+ ``` php
637+ (new Mapper)->map($data, new IfElse(new Exists('bar'), true, false));
638+ ```
639+
640+ > false
641+
580642### IfExists
581643
582644Delegates to one expression or another depending on whether the specified condition maps to null.
583645
646+ Deprecated. Use IfElse and Exists strategies instead.
647+
584648#### Signature
585649
586650``` php
0 commit comments