Returns cache dir for $tag.

This method is public only for unit tests.
Use it only if you know what you are doing.

@internal

@param int $tag

@return string
555552
public function getTagPath($tag = null)
    {
        $path = $this->root . DIRECTORY_SEPARATOR . static::TAG_CACHE_DIR;
        if ($tag) {
            // Flip the tag so we put id first so it gets sliced into folders.
            // (otherwise we would easily reach inode limits on file system)
            $tag = strrev($tag);
            $path .= DIRECTORY_SEPARATOR . substr($tag, 0, 2) . DIRECTORY_SEPARATOR . substr($tag, 2, 2) . DIRECTORY_SEPARATOR . substr($tag, 4);
        }

        return $path;
    }
1035942
private function getTopicValueObject(Tag $tag)
    {
        $rootLocation = $this->loadService->loadLocation(
            $this->configResolver->getParameter('content.tree_root.location_id')
        );

        $query = new LocationQuery();
        $query->limit = 1;

        $query->filter = new Criterion\LogicalAnd(
            [
                new Criterion\Subtree($rootLocation->pathString),
                new Criterion\LogicalNot(new Criterion\LocationId($rootLocation->id)),
                new Criterion\Location\IsMainLocation(Criterion\Location\IsMainLocation::MAIN),
                new Criterion\Visibility(Criterion\Visibility::VISIBLE),
                new Criterion\ContentTypeIdentifier(['ng_topic']),
                new TagId($tag->id),
            ]
        );

        $searchResult = $this->findService->findLocations($query);

        if (!empty($searchResult->searchHits)) {
            return $searchResult->searchHits[0]->valueObject;
        }

        return $tag;
    }
141600
public function tags($tag)
    {
        return $this->model->where('is_published', 1)
            ->where('published_at', '<=', Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s'))
            ->where('tags', 'LIKE', '%'.$tag.'%')->orderBy('created_at', 'desc')
            ->paginate(config('cms.pagination', 24));
    }
659619
public function replaceTags($tag, $blnCache=true)
	{
		$parts = explode('::', $tag);

		if(method_exists($this, $parts[0]))
		{
			$method = $parts[0];
			array_shift($parts);

			return $this->$method($parts, $blnCache);
		}

		return false;
	}
1019236
public function getTagKeyword($tag)
    {
        if (!$tag instanceof Tag) {
            try {
                $tag = $this->tagsService->loadTag($tag);
            } catch (NotFoundException $e) {
                return '';
            }
        }

        return $this->translationHelper->getTranslatedByMethod($tag, 'getKeyword');
    }
972052
public function tag($tag)
    {
        $route = $this->factory->createRoute($this, null, array());

        $this->addRoute($route);

        return $route->tag($tag);
    }
409562
public function getByTag(string $tag): array
    {
        $result = [];
        if (isset($this->tags[$tag])) {
            foreach ($this->tags[$tag] as $id) {
                $result[$id] = $this->get($id);
            }
        }

        return $result;
    }
54482
public function getTag($tag) {
        if (isset($this->_tags[$tag])) {
            return $this->_tags[$tag];
        }

        throw new MissingFilterException(sprintf('No filter can be found with %s tag', $tag));
    }
180652
public function getCmd($tag)
    {
        return isset($this->_commands[$tag])
            ? $this->_commands[$tag]
            : null;
    }
165880
public function findIdentifiersByTag($tag)
    {
        $tagsFiles = \glob(GeneralUtility::getFileAbsFileName(self::RELATIVE_STORAGE_FOLDER) . '*/*/*' . self::FILE_EXTENSION_TAG);
        $identifiers = [];
        foreach ($tagsFiles as $tagsFile) {
            if (false !== \mb_strpos(\file_get_contents($tagsFile), '|' . $tag . '|')) {
                $identifiers[] = \file_get_contents(\str_replace(self::FILE_EXTENSION_TAG, self::FILE_EXTENSION_IDENTIFIER, $tagsFile));
            }
        }

        return $identifiers;
    }
1250922
protected function redirectToTag(Tag $tag = null)
    {
        if (!$tag instanceof Tag) {
            return $this->redirectToRoute('netgen_tags_admin_root');
        }

        return $this->redirectToRoute(
            'netgen_tags_admin_tag_show',
            [
                'tagId' => $tag->id,
            ]
        );
    }
712194
public function purgeUrlsByTag(string $tag)
    {
        try {
            if ($urls = $this->getTaggedUrls($tag)) {

                $this->purgeUrls(array_values($urls));
                $this->invalidateLocalCache(array_keys($urls));

                return true;
            }
        } catch (Exception $e) {
            \Craft::warning("Failed to purge '$tag'.", "upper");
        }

        return false;
    }
620061
public function flushByTag(string $tag): int
    {
        if (!$this->isValidTag($tag)) {
            throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233057359);
        }
        if ($this->backend instanceof TaggableBackendInterface) {
            return $this->backend->flushByTag($tag);
        }
        return 0;
    }
610267
public function getIcon($tag = 'i')
    {
        $icon = array_get($this->properties, 'icon', null);

        if (is_null($icon)) return '';

        return "<$tag " . MenuItemAttributes::make(['class' => $icon])->render() . "></$tag>";
    }
1056103
public function getTag($tag)
    {
        return isset($this->tags[$tag]) ? $this->tags[$tag] : null;
    }
898492
public function isCacheValid($id, $tag = null)
    {
        assert('is_string($id)');
        assert('is_null($tag) || is_string($tag)');

        $cacheFile = strval($this->cacheDirectory).'/'.$id;
        if (!file_exists($cacheFile)) {
            return false;
        }

        $expireFile = $cacheFile.'.expire';
        if (!file_exists($expireFile)) {
            return false;
        }

        $expireData = @file_get_contents($expireFile);
        if ($expireData === false) {
            return false;
        }

        $expireData = explode(':', $expireData, 2);

        $expireTime = intval($expireData[0]);
        if ($expireTime <= time()) {
            return false;
        }

        if (count($expireData) === 1) {
            $expireTag = null;
        } else {
            $expireTag = $expireData[1];
        }
        if ($expireTag !== $tag) {
            return false;
        }

        return true;
    }
824404
private function _parseTag($tag)
        {   
//          return nothing if the tag is disabled
            if(isset($tag['attributes']->disabled) === true && $tag['attributes']->disabled === 'true')
            {
                return '';
            }
            
            $tag_data = false;
            $caching_tag = isset($tag['attributes']->cache) && $tag['attributes']->cache === 'false' ? false : true;
            if($this->_options['cache_tags'] === true && $caching_tag === true)
            {
                if($this->_options['custom_cache_tag_class'] !== false)
                {
                    $tag_data = call_user_func_array(array($this->_options['custom_cache_tag_class'], 'getCache'), array($tag));
                }
                else 
                {
                    $cache_file = $this->_options['cache_directory'].md5(serialize($tag));
                    if(is_file($cache_file) === true)
                    {
                        $tag_data = file_get_contents($cache_file);
                    }
                }
                if($tag_data)
                {
                    $tag['cached'] = true;
                    return $tag_data;
                }
            }    
            
//          look for and load tag function file
            $tag_func_name = ucwords(str_replace(array('_', '-'), ' ', $tag['name']));
            $tag_func_name = strtolower(substr($tag_func_name, 0, 1)).substr($tag_func_name, 1);
            $func_name = str_replace(' ', '', $this->_options['tag_callback_prefix'].$tag_func_name);
            $tag_data = '';
            $collect_tag = false;
            $tag_order = false;
            if(function_exists($func_name) === false)
            {
                $has_resource = false;
                if(is_array($this->_options['tag_directory']) === false)
                {
                    $this->_options['tag_directory'] = array($this->_options['tag_directory']);
                }
                foreach ($this->_options['tag_directory'] as $directory)
                {
                    $tag_file = rtrim($directory, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$tag['name'].DIRECTORY_SEPARATOR.'tag.php';
                    if(is_file($tag_file) === true)
                    {
                        if(isset(self::$_required[$tag['name']]) === false)
                        {
                            self::$_required[$tag['name']] = true;
                            $collect = false;
                            if(function_exists($func_name) === false)
                            {
                                include_once $tag_file;
                            }
                            self::$_tags_to_collect[$tag['name']] = $collect;
                            if(function_exists($func_name) === false)
                            {
                                return self::throwError($tag['name'], 'tag resource "'.$directory.DIRECTORY_SEPARATOR.'tag.php" found but callback "'.$func_name.'" wasn\'t.');
                            }
                            $has_resource = true;
                        }
                    }
                }
                if($has_resource === false)
                {
                    return self::throwError($tag['name'], 'tag resource not found.');
                } 
            }
            
//          do we have to collect this tag for parsing at a later point
            if(self::$_tags_to_collect[$tag['name']] !== false)
            {
                if(isset(self::$tag_collections[$tag['name']]) === false)
                {
                    self::$tag_collections[$tag['name']] = array();
                }
                $tag['collected'] = true;
                $index = array_push(self::$tag_collections[$tag['name']], $tag)-1;
                if($tag_order !== false)
                {
                    if(isset(self::$_tag_order[$block['name']]) === false)
                    {
                        self::$_tag_order[$block['name']] = array();
                    }
                    self::$_tag_order[$block['name']] = $tag_order;
                }
                return self::$tag_collections[$tag['name']][$index]['tag'] = '------@@%'.self::$_instance.'-'.$tag['name'].'-'.$index.'-'.uniqid(time().'-').'%@@------';
            }
            
//          excecute the tag callback
            if($this->_options['tag_global_callback'] !== false)
            {
                $tag_data = trim(call_user_func($this->_options['tag_global_callback'], 'tag', $func_name, $tag));
            }
            else
            {
                $tag_data = trim(call_user_func($func_name, $tag));
            }
            
//          this is where we sniff for buried tags within the returned content
            if(empty($tag_data) === false)
            {
                if($this->_options['sniff_for_buried_tags'] === true && strpos($tag_data, self::$tag_open.$this->_options['tag_name'].':') !== false)
                {
//                  we have the possibility of buried tags so lets parse
//                  but first make sure the output isn't echoed out
                    $old_echo_value = $this->_options['echo_output'];
                    $this->_options['echo_output'] = false; 
//                  parse the tag_data 
                    $tag_data = $this->parse($tag_data, false, true);
//                  restore the echo_output value back to what it was originally
                    $this->_options['echo_output'] = $old_echo_value;
                }
                
                if($this->_options['cache_tags'] === true && $caching_tag === true)
                {
                    if($this->_options['custom_cache_tag_class'] !== false)
                    {
                        call_user_func_array(array($this->_options['custom_cache_tag_class'], 'cache'), array($tag, $tag_data));
                    }
                    else
                    {
                        file_put_contents($this->_options['cache_directory'].md5(serialize($tag)), $tag_data, LOCK_EX);
                    }
                }
            }
            return $tag_data;
        }