Register trait

@param string $trait
@param string $pattern
@param float $sort

@return TraitReflection
337721
public function register($trait, $pattern = null, $sort = null)
    {
        $reflection = new TraitReflection($trait, $pattern, $sort);

        if (!$reflection->getPattern()) {
            throw new \RuntimeException("No `pattern` defined for trait '$trait'");
        }
        $this->_traits[] = $reflection;

        return $reflection;
    }
1038975
public function setPattern($pattern)
    {
        if (!is_array($pattern) && !is_string($pattern)) {
            throw new Exception\InvalidArgumentException(sprintf(
                '%s expects pattern to be array or string; received "%s"',
                __METHOD__,
                (is_object($pattern) ? get_class($pattern) : gettype($pattern))
            ));
        }

        if (is_array($pattern)) {
            foreach ($pattern as $p) {
                $this->validatePattern($p);
            }
        }

        if (is_string($pattern)) {
            $this->validatePattern($pattern);
        }

        $this->options['pattern'] = $pattern;
        return $this;
    }
242650
public function select(string $pattern = '', int $count = 100): \Iterator
    {
        $iterator = null;
        while (true) {
            $ret = $this->handle->hScan($this->name, $iterator, $pattern, $count);
            if (false === $ret) {
                break;
            }
            foreach ($ret as $k => $v) {
                yield [$k => $v];
            }
        }
    }
1326615
public function addIgnore(string $pattern): self
    {
        if (substr($pattern, 0, 2)=='./') {
            $pattern = substr($pattern, 2);
        }

        if (!in_array($pattern, $this->ignores)) {
            $this->ignores[] = $pattern;
        }

        return $this;
    }
343668
protected function writeln($pattern = null, ...$args)
    {
        if (!$this->hasOutput()) {
            return $this;
        }

        $this->getOutput()->writeln(vsprintf($pattern, $args));

        return $this;
    }
1048258
public function registerStyle($style)
    {
        $registeredStyle = parent::registerStyle($style);
        $this->registerFill($registeredStyle);
        $this->registerBorder($registeredStyle);
        return $registeredStyle;
    }
328101
public function useTrait(\ReflectionClass $trait)
    {
        $alias = 'trait' . ($this->_traitsIdx++);
        $alias .= '_' . str_replace('\\', '__', $trait->getName());

        $alias = 'Trait_' . substr(md5($alias), 0, 10) . '_' .$trait->getShortName();

        $this->addUse($trait->getName(), $alias);
        $this->addTrait($alias);

        foreach ($trait->getMethods() as $method) {
            if ($method->isAbstract()) {
                continue;
            }
            $this->registerTraitMethod($alias, $method);
        }

        return $this;
    }
939923
protected function _compilePattern($pattern)
    {
        if (strpos($pattern, '{') !== false) {
            $tr = [
                '{area}' => '{area:[a-z]\w*}',
                '{controller}' => '{controller:[a-z]\w*}',
                '{action}' => '{action:[a-z]\w*}',
                '{params}' => '{params:.*}',
                '{id}' => '{id:[^/]+}',
                ':int' => ':\d+',
            ];
            $pattern = strtr($pattern, $tr);
        }

        if (strpos($pattern, '{') !== false) {
            $need_restore_token = false;

            if (preg_match('#{\d#', $pattern) === 1) {
                $need_restore_token = true;
                $pattern = (string)preg_replace('#{([\d,]+)}#', '@\1@', $pattern);
            }

            $matches = [];
            if (preg_match_all('#{([A-Z].*)}#Ui', $pattern, $matches, PREG_SET_ORDER) > 0) {
                foreach ($matches as $match) {
                    $parts = explode(':', $match[1], 2);
                    $to = '(?<' . $parts[0] . '>' . (isset($parts[1]) ? $parts[1] : '[\w-]+') . ')';
                    $pattern = (string)str_replace($match[0], $to, $pattern);
                }
            }

            if ($need_restore_token) {
                $pattern = (string)preg_replace('#@([\d,]+)@#', '{\1}', $pattern);
            }

            return '#^' . $pattern . '$#i';
        } else {
            return $pattern;
        }
    }
81354
public function addTrait($trait) {
		if ($trait instanceof PhpTrait) {
			$name = $trait->getName();
			$qname = $trait->getQualifiedName();
			$namespace = $trait->getNamespace();

			if ($namespace != $this->getNamespace()) {
				$this->addUseStatement($qname);
			}
		} else {
			$name = $trait;
		}

		if (!in_array($name, $this->traits)) {
			$this->traits[] = $name;
		}

		return $this;
	}
913746
public function addPattern($pattern)
    {
        $this->doAddPattern($this->convertPattern($pattern));
        $this->hasPattern = true;
    }
94319
@SuppressWarnings("unchecked")
	public static void registerPattern(String id, String pattern, ParserContext parserContext) {
		if (!"".equals(id)) { // add to sitemap only if it has an id
			BeanDefinitionRegistry registry = parserContext.getRegistry();
			BeanDefinition sitemapBean;
			try {
				sitemapBean = registry.getBeanDefinition(BEAN_ID);
			} catch (NoSuchBeanDefinitionException e) {
				sitemapBean = BeanDefinitionBuilder.genericBeanDefinition(Sitemap.class)
					.addPropertyValue(BEAN_PROP_ENTRIES, new HashMap<String, String>())
					.getBeanDefinition();
				registry.registerBeanDefinition(BEAN_ID, sitemapBean);
			}
			((Map<String, String>) sitemapBean.getPropertyValues().getPropertyValue(BEAN_PROP_ENTRIES).getValue()).put(id, pattern);
		}
	}
274556
protected static function traitsOfTrait($trait)
    {
        $traits = static::traits($trait, false, false);

        foreach ($traits as $usedTrait) {
            $traits += static::traitsOfTrait($usedTrait);
        }

        return $traits;
    }
1168702
final public function createTraitFromStringArray(array $parts) : Trait_
    {
        return new Trait_(
            $this->extractClazzPart($parts),
            new Namespaze($this->extractNamespaceParts($parts))
        );
    }
747097
public function addTrait($trait)
    {
        if ($this->isTraitDefined($trait) === false) {
            throw Exception\Type::isNotDefined($trait);
        }

        $trait = new Element\ClassTrait($this, $trait);
        $this->classTraits->append($trait);

        return $trait;
    }
1015306
protected function _find($regexpPattern = null, $sort = false)
    {
        $regexpPattern = $regexpPattern ?: sprintf('[\d\w]{32}_[\d\w]{32}\.(%s)', implode('|', self::$supportedFormats));

        return (new Folder($this->getPath()))->find($regexpPattern, $sort);
    }
1085677
protected function registerTraitMethod($trait, \ReflectionMethod $method)
    {
        $name = $method->getName();
        $this->_method[$name] = $method;

        $alias = '__' . lcfirst($trait) . ucfirst($name);
        $this->addTraitAlias($trait . '::' . $name, $alias);
        $this->addTraitMethod($trait, $name);

        if (!isset($this->_traitMethodsAliases[$name])) {
            $this->_traitMethodsAliases[$name] = [];
        }
        $this->_traitMethodsAliases[$name][] = $alias;
    }
949216
public function removeTrait($trait) {
		if ($trait instanceof PhpTrait) {
			$name = $trait->getName();
		} else {
			$name = $trait;
		}

		$index = array_search($name, $this->traits);
		if ($index !== false) {
			unset($this->traits[$index]);

			if ($trait instanceof PhpTrait) {
				$qname = $trait->getQualifiedName();
				$this->removeUseStatement($qname);
			}
		}

		return $this;
	}