1. Go to this page and download the library: Download eloquent/confetti 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/ */
eloquent / confetti example snippets
use Eloquent\Confetti\TransformStream;
$stream = new TransformStream(new Base64DecodeTransform);
$stream->on(
'data',
function ($data, $stream) {
echo $data;
}
);
$stream->on(
'error',
function ($error, $stream) {
throw $error;
}
);
try {
$stream->write('Zm9v'); // outputs 'foo'
$stream->end('YmFy'); // outputs 'bar'
} catch (Exception $e) {
// unable to decode
}
$stream->on(
'success',
function ($stream) {
echo get_class($stream->transform());
}
);
use Eloquent\Confetti\CompoundTransform;
use Eloquent\Confetti\TransformStream;
$stream = new TransformStream(
new CompoundTransform(array(new Rot13Transform, new Base64DecodeTransform))
);
$stream->on(
'data',
function ($data, $stream) {
echo $data;
}
);
$stream->write('Mz9i'); // outputs 'foo'
$stream->end('LzSl'); // outputs 'bar'
use Eloquent\Confetti\TransformInterface;
class Rot13Transform implements TransformInterface
{
public function transform($data, &$context, $isEnd = false)
{
return array(str_rot13($data), strlen($data), null);
}
}
use Eloquent\Confetti\TransformStream;
$stream = new TransformStream(new Rot13Transform);
$stream->on(
'data',
function ($data, $stream) {
echo $data;
}
);
$stream->end('foobar'); // outputs 'sbbone'
use Eloquent\Confetti\AbstractNativeStreamFilter;
class Rot13NativeStreamFilter extends AbstractNativeStreamFilter
{
protected function createTransform()
{
return new Rot13Transform;
}
}