PHP code example of danielefavi / fluent-api
1. Go to this page and download the library: Download danielefavi/fluent-api library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
danielefavi / fluent-api example snippets
use DanieleFavi\FluentApi\FluentApi;
class FluentMath extends FluentApi
{
}
class FluentMath extends FluentApi
{
private $result = 0;
protected function _add($num)
{
$this->result += $num;
return $this;
}
protected function _subtract($num)
{
$this->result -= $num;
return $this;
}
public function result()
{
return $this->result;
}
}
$res1 = FluentMath::add(5)
->add(3)
->subtract(2)
->add(8)
->result();
$res2 = FluentMath::subtract(1)
->add(10)
->result();
// $res1 equals to 14
// $res2 equals to 9