PHP code example of hvolschenk / compose
1. Go to this page and download the library: Download hvolschenk/compose 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/ */
hvolschenk / compose example snippets
namespace Test\Test;
g) {
return "{$string}a";
}
function addB(string $string) {
return "{$string}b";
}
function addC(string $string) {
return "{$string}c";
}
echo Hvolschenk\Utils\Compose\Compose::compose('Value',
['addA', 'addB', 'addC']); // ValueABC
class StringAdder {
use \Hvolschenk\Traits\Compose;
private $value;
public function __construct(string $value) {
$this->setValue($value);
}
public function getValue(): string {
return $this->value;
}
private function setValue(string $value) {
$this->value = self::composeValue($value);
}
private static function composeValue(string $value): string {
return self::compose($value, ['addA', 'addB', 'addC']);
}
private static function addA(string $string) {
return "{$string}a";
}
private static function addB(string $string) {
return "{$string}b";
}
private static function addC(string $string) {
return "{$string}c";
}
}
$stringAdder = new StringAdder('Value');
echo $stringAdder->getValue(); // ValueABC
class StringAdder {
use \Hvolschenk\Traits\Compose;
private $value;
private $separator = '.';
public function __construct(string $value) {
$this->setValue($value);
}
public function getValue(): string {
return $this->value;
}
private function setValue(string $value) {
$this->value = self::composeValue($value);
}
private function composeValue(string $value): string {
return $this->composeNonStatic($value, ['addA', 'addB', 'addC']);
}
private function addA(string $string) {
return "{$string}a{$this->separator}";
}
private function addB(string $string) {
return "{$string}b{$this->separator}";
}
private function addC(string $string) {
return "{$string}c{$this->separator}";
}
}
$stringAdder = new StringAdder('Value');
echo $stringAdder->getValue(); // ValueA.B.C.
class StringAdder {
use \Hvolschenk\Traits\Compose;
private $value;
private $separator = '.';
public function __construct(string $value) {
$this->setValue($value);
}
public function getValue(): string {
return $this->value;
}
private function setValue(string $value) {
$this->value = self::composeValue($value);
}
private function composeValue(string $value): string {
return $this->composeMixed($value, [['self', 'addA'], ['self', 'addB'],
[$this, 'addC']]);
}
private static function addA(string $string) {
return "{$string}a";
}
private static function addB(string $string) {
return "{$string}b";
}
private function addC(string $string) {
return "{$string}c{$this->separator}";
}
}
$stringAdder = new StringAdder('Value');
echo $stringAdder->getValue(); // ValueABC.