Skip to content

Commit d8a3079

Browse files
committed
maybe nullable
1 parent 2ad50f9 commit d8a3079

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

view/overview/index.phtml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,38 @@ new Invoke(function() { var_dump(func_get_args()); }),
802802

803803
<p>A <a href="https://github.com/mvc5/mvc5/blob/master/src/Plugin/Link.php">link</a> plugin is <a href="https://github.com/mvc5/mvc5/blob/master/src/Resolver/Resolver.php#L217">used</a> to return the current service object. It can also be used as a <a href="https://github.com/mvc5/mvc5/blob/master/src/Config/Config.php">configuration</a> object to delay the <a href="https://github.com/mvc5/mvc5/blob/master/src/Resolver/Container.php#L70">creation</a> of a particular value until it is required.</p>
804804

805+
<h3 id="maybe"><a href="https://github.com/mvc5/mvc5/blob/master/src/Plugin/Maybe.php">Maybe</a></h3>
806+
<div class="language-php highlighter-rouge"><pre class="highlight"><code>new Maybe($value = null, $default = null)
807+
</code></pre>
808+
</div>
809+
810+
<p>The <a href="https://github.com/mvc5/mvc5/blob/master/src/Plugin/Maybe.php">maybe</a> plugin returns a resolved value. When the resolved value is null, the default value is returned if it is not null, otherwise <a href="https://github.com/mvc5/mvc5/blob/master/src/Plugin/Nothing.php">Nothing</a> is returned. The value can be <a href="#shared">shared</a> and then retrieved with the <a href="#nullable">nullable</a> plugin; which returns null when the value is <a href="https://github.com/mvc5/mvc5/blob/master/src/Plugin/Nothing.php">Nothing</a>.</p>
811+
<div class="language-php highlighter-rouge"><pre class="highlight"><code>(new Maybe)(); //Nothing
812+
(new Maybe)('foo'); //foo
813+
(new Maybe)(new Nothing); //Nothing
814+
(new Maybe(null, new Value('bar')))(); //new Value('bar')
815+
(new App)(new Maybe); //Nothing
816+
(new App)(new Maybe(new Value('foo'))); //foo
817+
(new App)(new Maybe(null, new Value('bar'))); //bar
818+
</code></pre>
819+
</div>
820+
821+
<h3 id="nullable"><a href="https://github.com/mvc5/mvc5/blob/master/src/Plugin/Nullable.php">Nullable</a></h3>
822+
<div class="language-php highlighter-rouge"><pre class="highlight"><code>new Nullable($value = null, $default = null)
823+
</code></pre>
824+
</div>
825+
826+
<p>The <a href="https://github.com/mvc5/mvc5/blob/master/src/Plugin/Nullable.php">nullable</a> plugin returns a resolved value. When the value is <a href="https://github.com/mvc5/mvc5/blob/master/src/Plugin/Nothing.php">Nothing</a>, the default value is returned.</p>
827+
<div class="language-php highlighter-rouge"><pre class="highlight"><code>(new Nullable)(); //null
828+
(new Nullable)('foo'); //foo
829+
(new Nullable)(new Nothing); //null
830+
(new Nullable(new Nothing, new Value('bar')))(new Nothing); //new Value('bar')
831+
(new App)(new Nullable); //null
832+
(new App)(new Nullable(new Value('foo')); //foo
833+
(new App)(new Nullable(new Nothing, new Value('bar'))); //bar
834+
</code></pre>
835+
</div>
836+
805837
<h3 id="nullvalue"><a href="https://github.com/mvc5/mvc5/blob/master/src/Plugin/NullValue.php">NullValue</a></h3>
806838
<div class="language-php highlighter-rouge"><pre class="highlight"><code>new NullValue
807839
</code></pre>

0 commit comments

Comments
 (0)