PHP code example of itscript / countdown-gif

1. Go to this page and download the library: Download itscript/countdown-gif 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/ */

    

itscript / countdown-gif example snippets




late = <<<XML
<?xml version="1.0" encoding="UTF-8" standalone="no"



$middleware = new \ITS\Countdown\GIF\FrameMiddleware\CompositeFrameMiddleware(/* ... */);

/** @var \Psr\SimpleCache\CacheInterface $cache */
$cache;

$middleware
    ->add(
        new \ITS\Countdown\GIF\FrameMiddleware\CallbackFrameMiddleware(function (\ITS\Countdown\GIF\Frame $frame, $next) use ($cache) {
            $content = $cache->get(number_format($frame->getInterval()));
            if ($content) { // exit if cache exists
                return new \ITS\Countdown\GIF\Frame\FrameInstance($content, $frame->getInterval(), $frame->getDuration());
            } elseif (is_callable($next)) {
                return $next($frame);
            } else {
                return $frame;
            }
        }),
        2 // beginning
    )
    ->add(
        new \ITS\Countdown\GIF\FrameMiddleware\CallbackFrameMiddleware(function (\ITS\Countdown\GIF\Frame $frame, $next) use ($cache) {
            $cache->set(number_format($frame->getInterval()), $frame->getContent(), 60);

            if (is_callable($next)) {
                return $next($frame);
            } else {
                return $frame;
            }
        }),
        0 // end
    );
 


namespace ITS\Countdown\GIF;

interface Frame
{
    /**
     * @return string
     */
    public function getContent();

    /**
     * @return float
     */
    public function getInterval();

    /**
     * @return float
     */
    public function getDuration();
}

interface FrameMiddleware
{
    /**
     * @param Frame         $frame
     * @param callable|null $next
     * @return Frame
     */
    public function __invoke(Frame $frame, callable $next = null);
}

interface FrameSequenceBuilder
{
    /**
     * @return \Iterator|Frame[]
     */
    public function getSequence();
}

interface FrameSequenceHandler
{
    /**
     * @param \Iterator|Frame[] $sequence
     */
    public function process(\Iterator $sequence);
}