<?php
    
    namespace common\models;
    
    use artbox\core\models\interfaces\RedirectInterface;
    use yii\base\BaseObject;
    
    class SlashRedirect extends BaseObject implements RedirectInterface
    {
        /**
         * @var string
         */
        protected $link;
        
        /**
         * @param string $url
         *
         * @return bool
         */
        public function doRedirect(string $url): bool
        {
            if (substr($url, -1) === '/') {
                $this->link = trim($url, '/');
                return true;
            }
            return false;
        }
        
        /**
         * @return string
         */
        public function getLink(): string
        {
            return $this->link;
        }
    }