PHP code example of jeyroik / extas-player-current

1. Go to this page and download the library: Download jeyroik/extas-player-current 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/ */

    

jeyroik / extas-player-current example snippets


namespace my\extas\plugins;

use \extas\components\plugins\Plugin;
use \extas\interfaces\players\IPlayer;
use \extas\interfaces\players\IPlayerRepository;

class PluginCookieCurrentPlayer extends Plugin
{
    public function __invoke(IPlayer &$player)
    {
        if (isset($_COOKIE['extas.player'])) {
            $playerName = $_COOKIE['extas.player'];
            /**
             * var $playerRepo IPlayerRepository
             */
            $playerRepo = SystemContainer::getItem(IPlayerRepository::class);
            $currentPlayer = $playerRepo->one([IPlayer::FIELD__NAME => $playerName]);
            $currentPlayer && ($player = $currentPlayer);
        }
    }
}

setcookie('extas.player', 'jeyroik', time() + 3000, '/');

use \extas\components\players\Current;

echo Current::player()->getName(); // jeyroik