private function tag($tags)
    {
        $this->initialize();

        if (!is_array($tags)) {
            $tags = [$tags];
        }
        foreach ($tags as $tag) {
            if (!is_string($tag)) {
                throw new InvalidArgumentException(sprintf('Cache tag must be string, "%s" given', is_object($tag) ? get_class($tag) : gettype($tag)));
            }
            if (isset($this->tags[$tag])) {
                continue;
            }
            if (!isset($tag[0])) {
                throw new InvalidArgumentException('Cache tag length must be greater than zero');
            }
            if (isset($tag[strcspn($tag, '{}()/\@:')])) {
                throw new InvalidArgumentException(sprintf('Cache tag "%s" contains reserved characters {}()/\@:', $tag));
            }
            $this->tags[$tag] = $tag;
        }

        return $this;
    }
private function tag($tags)
    {
        $this->initialize();

        if (!is_array($tags)) {
            $tags = [$tags];
        }
        foreach ($tags as $tag) {
            if (!is_string($tag)) {
                throw new InvalidArgumentException(sprintf('Cache tag must be string, "%s" given', is_object($tag) ? get_class($tag) : gettype($tag)));
            }
            if (isset($this->tags[$tag])) {
                continue;
            }
            if (!isset($tag[0])) {
                throw new InvalidArgumentException('Cache tag length must be greater than zero');
            }
            if (isset($tag[strcspn($tag, '{}()/\@:')])) {
                throw new InvalidArgumentException(sprintf('Cache tag "%s" contains reserved characters {}()/\@:', $tag));
            }
            $this->tags[$tag] = $tag;
        }

        return $this;
    }
private function tag ( $ tags ) { $ this -> initialize ( ) ; if ( ! is_array ( $ tags ) ) { $ tags = [ $ tags ] ; } foreach ( $ tags as $ tag ) { if ( ! is_string ( $ tag ) ) { throw new InvalidArgumentException ( sprintf ( 'Cache tag must be string, "%s" given' , is_object ( $ tag ) ? get_class ( $ tag ) : gettype ( $ tag ) ) ) ; } if ( isset ( $ this -> tags [ $ tag ] ) ) { continue ; } if ( ! isset ( $ tag [ 0 ] ) ) { throw new InvalidArgumentException ( 'Cache tag length must be greater than zero' ) ; } if ( isset ( $ tag [ strcspn ( $ tag , '{}()/\@:' ) ] ) ) { throw new InvalidArgumentException ( sprintf ( 'Cache tag "%s" contains reserved characters {}()/\@:' , $ tag ) ) ; } $ this -> tags [ $ tag ] = $ tag ; } return $ this ; }
Adds a tag to a cache item.

@param string|string[] $tags A tag or array of tags

@throws InvalidArgumentException When $tag is not valid.

@return TaggableCacheItemInterface
Adds a tag to a cache item .