Loads or creates multiples tags from a list of tag names

@param array  $names   Array of tag names
@return Tag[]
506563
public function loadOrCreateTags(array $names)
    {
        if (empty($names)) {
            return array();
        }

        $names = array_unique($names);

        $builder = $this->em->createQueryBuilder();

        $tags = $builder
            ->select('t')
            ->from($this->tagClass, 't')

            ->where($builder->expr()->in('t.name', $names))

            ->getQuery()
            ->getResult()
        ;

        $loadedNames = array();
        foreach ($tags as $tag) {
            $loadedNames[] = $tag->getName();
        }

        $missingNames = array_udiff($names, $loadedNames, 'strcasecmp');
        if (sizeof($missingNames)) {
            foreach ($missingNames as $name) {
                $tag = $this->createTag($name);
                $this->em->persist($tag);

                $tags[] = $tag;
            }

            $this->em->flush();
        }

        return $tags;
    }
124136
public function filtrateList($tags)
    {
        $validTags = array();
        foreach ($tags as $tag) {
            if ($this->isValid($tag)) {
                $validTags[] = $tag;
            }
        }

        return $validTags;
    }
1285378
public function getCacheTags($tags = null)
    {
        if ($tags !== null) {
            return (array) $tags;
        }

        $tags = (array) $this->tags;
        $tags[] = static::VERSION_TAG;
        $tags[] = static::BASE_TAG;
        $tags[] = $this->from;

        if ($this->model) {
            $tags[] = get_class($this->model);
        }

        return $tags;
    }
1051979
public function resolveTagIds($tagIds)
    {
        $resolvedTags = [];

        foreach ($tagIds as $tagId) {
            $tag = $this->findById($tagId);
            if (null !== $tag) {
                $resolvedTags[] = $tag->getName();
            }
        }

        return $resolvedTags;
    }
386360
private function createIdentifierMap(array $names) : array
    {
        $identifiers = [];

        foreach ($names as $name) {
            $identifiers[$name] = new Identifier($name);
        }

        return $identifiers;
    }
1021650
public function selectByTags(array $tags)
    {
        $result = [];
        foreach ($this->array['Key2Tags'] as $key => $keyTags) {
            $found = true;
            foreach ($tags as $t) {
                if (array_search($t, $keyTags)===false) {
                    $found = false;
                }
            }

            if ($found) {
                $result[] = $key;
            }
        }

        return $result;
    }
1041322
public function tags($names)
    {
        return new RedisTaggedCache(
            $this, new TagSet($this, is_array($names) ? $names : func_get_args())
        );
    }
539616
public function getTagsByName(string $name): array
    {
        $result = [];

        /** @var Tag $tag */
        foreach ($this->getTags() as $tag) {
            if ($tag->getName() !== $name) {
                continue;
            }

            $result[] = $tag;
        }

        return $result;
    }
1091520
public function loadOrCreateTag($name)
    {
        $tag = $this->loadTag($name);
        if (null === $tag) {
            $tag = $this->createTag($name);
        }

        return $tag;
    }
134227
private function getAllTags(): array
    {
        if ($this->tags === null) {
            $this->tags = $this->loadAllTags();
        }

        return $this->tags;
    }
760546
private function createTags(Collection $models): array
    {
        $tags = [];

        /** @var Model $model */
        foreach ($models as $model) {
            $tags[] = static::createTagFromModel($model);
        }

        return $tags;
    }
146260
protected function getTags($tag = null)
    {
        $tags = [$this->cacheKey];

        if ($tag) {
            if (! is_array($tag)) {
                $tag = [$tag];
            }

            $tags = array_merge($tags, $tag);
        }

        return $tags;
    }
185325
public function tags( $names )
	{
		if ( method_exists( $this->store, 'tags' ) )
		{
			$taggedCache = $this->store->tags( $names );
			$taggedCache->setDefaultCacheTime( $this->default );

			return $taggedCache;
		}

		throw new BadMethodCallException( 'This cache store does not support tagging.' );
	}
1266798
protected function getViewNames(array $names)
    {
        return array_map(function ($name) {
            $name = str_replace('.', '/', $name);

            return $name.$this->config->getExtension();
        }, $names);
    }
582747
private function _mangleTags($tags)
    {
        foreach ($tags as $i => $tag) {
            $tags[$i] = $this->_mangleTag($tag);
        }
        return $tags;
    }
786486
private function loadTypes(&$tags, \DOMXPath $xpath, \DOMNode $context = null)
    {
        $result = [];

        /** @var \DOMElement $node */
        foreach ($xpath->query('x:types/x:type', $context) as $node) {
            $value = $this->loadType($xpath, $node, $tags);
            $result[$value['name']] = $value;
        }

        return $result;
    }
1332949
public function findOrCreate(array $tags)
    {
        $foundTags = $this->findWhereIn(['tag', $tags]);

        $returnTags = [];

        if ($foundTags) {
            foreach ($foundTags as $tag) {
                $pos = array_search($tag->tag, $tags);

                // Add returned tags to array
                if ($pos !== false) {
                    $returnTags[] = $tag;
                    unset($tags[$pos]);
                }
            }
        }

        // Add remainings tags as new
        foreach ($tags as $tag) {
            $returnTags[] = $this->create([
                'tag' => $tag,
                'slug' => Str::slug($tag),
            ]);
        }

        return $returnTags;
    }