Creates a `use` definition.

@param  array  $uses An array of traits.
@return string       The generated `use` definition.
182837
protected static function _generateUses($uses)
    {
        if (!$uses) {
            return '';
        }
        $traits = [];
        foreach ((array) $uses as $use) {
            if (!trait_exists($use)) {
                throw new MissingImplementationException("Unexisting trait `{$use}`");
            }
            $traits[] = '\\' . ltrim($use, '\\');
        }
        return '    use ' . join(', ', $traits) . ';';
    }
434217
protected static function fromClassMethodString($uses)
    {
        [$class, $method] = Str::parseCallback($uses);

        if (! method_exists($class, $method) && is_callable($class, $method)) {
            return [];
        }

        return (new ReflectionMethod($class, $method))->getParameters();
    }
1217967
protected static function _generateMethodStubs($methods, $defaults = true)
    {
        $result = [];
        $methods = $methods !== null ? (array) $methods : [];

        if ($defaults) {
            $methods = array_merge($methods, array_keys(static::_getMagicMethods()));
        }
        $methods = array_unique($methods);

        $magicMethods = static::_getMagicMethods();

        foreach ($methods as $name) {
            if (isset($magicMethods[$name])) {
                $result[$name] = $magicMethods[$name];
            } else {
                $static = $return = '';
                if ($name[0] === '&') {
                    $return = '$r = null; return $r;';
                }
                if (preg_match('/^&?::.*/', $name)) {
                    $static = 'static ';
                    $name = substr($name, 2);
                }
                $result[$name] = "public {$static}function {$name}() {{$return}}";
            }
        }

        return $result;
    }
1298324
protected function parse($usage)
	{
		$tag    = new Tag;
		$bbcode = new BBCode;

		// This is the config we will return
		$config = [
			'tag'              => $tag,
			'bbcode'           => $bbcode,
			'passthroughToken' => null
		];

		// Encode maps to avoid special characters to interfere with definitions
		$usage = preg_replace_callback(
			'#(\\{(?>HASH)?MAP=)([^:]+:[^,;}]+(?>,[^:]+:[^,;}]+)*)(?=[;}])#',
			function ($m)
			{
				return $m[1] . base64_encode($m[2]);
			},
			$usage
		);

		// Encode regexps to avoid special characters to interfere with definitions
		$usage = preg_replace_callback(
			'#(\\{(?:PARSE|REGEXP)=)(' . self::REGEXP . '(?:,' . self::REGEXP . ')*)#',
			function ($m)
			{
				return $m[1] . base64_encode($m[2]);
			},
			$usage
		);

		$regexp = '(^'
		        // [BBCODE
		        . '\\[(?<bbcodeName>\\S+?)'
		        // ={TOKEN}
		        . '(?<defaultAttribute>=.+?)?'
		        // foo={TOKEN} bar={TOKEN1},{TOKEN2}
		        . '(?<attributes>(?:\\s+[^=]+=\\S+?)*?)?'
		        // ] or /] or ]{TOKEN}[/BBCODE]
		        . '\\s*(?:/?\\]|\\]\\s*(?<content>.*?)\\s*(?<endTag>\\[/\\1]))'
		        . '$)i';

		if (!preg_match($regexp, trim($usage), $m))
		{
			throw new InvalidArgumentException('Cannot interpret the BBCode definition');
		}

		// Save the BBCode's name
		$config['bbcodeName'] = BBCode::normalizeName($m['bbcodeName']);

		// Prepare the attributes definition, e.g. "foo={BAR}"
		$definitions = preg_split('#\\s+#', trim($m['attributes']), -1, PREG_SPLIT_NO_EMPTY);

		// If there's a default attribute, we prepend it to the list using the BBCode's name as
		// attribute name
		if (!empty($m['defaultAttribute']))
		{
			array_unshift($definitions, $m['bbcodeName'] . $m['defaultAttribute']);
		}

		// Append the content token to the attributes list under the name "content" if it's anything
		// but raw {TEXT} (or other unfiltered tokens)
		if (!empty($m['content']))
		{
			$regexp = '#^\\{' . RegexpBuilder::fromList($this->unfilteredTokens) . '[0-9]*\\}$#D';

			if (preg_match($regexp, $m['content']))
			{
				$config['passthroughToken'] = substr($m['content'], 1, -1);
			}
			else
			{
				$definitions[] = 'content=' . $m['content'];
				$bbcode->contentAttributes[] = 'content';
			}
		}

		// Separate the attribute definitions from the BBCode options
		$attributeDefinitions = [];
		foreach ($definitions as $definition)
		{
			$pos   = strpos($definition, '=');
			$name  = substr($definition, 0, $pos);
			$value = preg_replace('(^"(.*?)")s', '$1', substr($definition, 1 + $pos));

			// Decode base64-encoded tokens
			$value = preg_replace_callback(
				'#(\\{(?>HASHMAP|MAP|PARSE|REGEXP)=)([A-Za-z0-9+/]+=*)#',
				function ($m)
				{
					return $m[1] . base64_decode($m[2]);
				},
				$value
			);

			// If name starts with $ then it's a BBCode/tag option. If it starts with # it's a rule.
			// Otherwise, it's an attribute definition
			if ($name[0] === '$')
			{
				$optionName = substr($name, 1);

				// Allow nestingLimit and tagLimit to be set on the tag itself. We don't necessarily
				// want every other tag property to be modifiable this way, though
				$object = ($optionName === 'nestingLimit' || $optionName === 'tagLimit') ? $tag : $bbcode;

				$object->$optionName = $this->convertValue($value);
			}
			elseif ($name[0] === '#')
			{
				$ruleName = substr($name, 1);

				// Supports #denyChild=foo,bar
				foreach (explode(',', $value) as $value)
				{
					$tag->rules->$ruleName($this->convertValue($value));
				}
			}
			else
			{
				$attrName = strtolower(trim($name));
				$attributeDefinitions[] = [$attrName, $value];
			}
		}

		// Add the attributes and get the token translation table
		$tokens = $this->addAttributes($attributeDefinitions, $bbcode, $tag);

		// Test whether the passthrough token is used for something else, in which case we need
		// to unset it
		if (isset($tokens[$config['passthroughToken']]))
		{
			$config['passthroughToken'] = null;
		}

		// Add the list of known (and only the known) tokens to the config
		$config['tokens'] = array_filter($tokens);

		return $config;
	}
1221480
private function getUsesDeclarations()
    {
        asort( $this->usesDeclarations );
        $output = [];
        foreach( $this->usesDeclarations as $namespace ) {
            $output[] = sprintf( 'use %s;', $namespace );
        }
        return new Format( $output );
    }
401083
public function mapped($options)
    {
        if (is_array($options)) {
            $use = $options['use'];
            unset($options['use']);
        } else {
            $use = $options;
            $options = [];
        }

        if (!isset($this->_maps[$use])) {
            return 'string';
        }

        foreach ($this->_maps[$use] as $type => $value) {
            if (!array_diff_assoc($value, $options)) {
                return $type;
            }
        }
        return 'string';
    }
457345
protected static function useStatic()
	{
		if(isset(self::$_useStatic)) {
			return self::$_useStatic;
		}

		self::$_useStatic = AssetsSettings::assetsUseStatic();

		return self::$_useStatic;
	}
156617
protected function generateUseStatement(array $useStatement): string
    {
        $alias = '';
        if (!empty($useStatement['alias'])) {
            $alias = ' as ' . $useStatement['alias'];
        }

        $content = 'use ' . $useStatement['fullName'] . $alias . ';';

        return $content;
    }
1173350
public static function make($items)
    {
        if (is_null($items)) {
            return new static;
        }

        if ($items instanceof Collection) {
            return $items;
        }

        return new static(is_array($items) ? $items : [$items]);
    }
314575
public static function groupUsesForChart($uses)
    {
        $labels = [];
        $data = [];

        ArrayHelper::multisort($uses, 'date');

        foreach ($uses as $use) {
            /** @var ServerUse $use */
            $labels[$use->date] = $use;
            $data[$use->type][] = $use->getDisplayAmount();
        }

        foreach ($labels as $date => $use) {
            $labels[$date] = $use->getDisplayDate();
        }

        return [$labels, $data];
    }
774596
public function controllersWithoutPrefix(array $controllers)
    {
        $group = new Group;
        foreach ($controllers as $controller)
            $group->set($this->controllerWithoutPrefix($controller));
        return $group;
    }
716332
protected function placeHolder(array $matches)
    {
        $placeholder = '%{{' . md5(time() . count($this->holder) . mt_rand(0, 500)) . '}}%';
        $this->holder[$placeholder] = $matches['1'];

        return $placeholder;
    }
461103
public function usage()
    {
        $name = $this->_name;
        if ($this->_choices) {
            $name = implode('|', $this->_choices);
        }
        $name = '<' . $name . '>';
        if (!$this->isRequired()) {
            $name = '[' . $name . ']';
        }

        return $name;
    }
525935
protected function _createManager(array $definitions)
    {
        $manager = new DefinitionManager();

        foreach ($definitions as $name => $definition)
        {
            if ($definition instanceof DefinitionHelperInterface) {
                /** @var DefinitionHelperInterface $definition */
                $manager->add($definition->getDefinition($name));
            } else if ($definition instanceof EntryReference) {
                /** @var EntryReference $definition */
                $manager->add(new AliasDefinition($name, $definition->getName()));
            } else {
                $manager->add(new ValueDefinition($name, $definition));
            }
        }
        return $manager;
    }
250669
public function create(array $parameters)
    {
        $supported = $this->isSupported('create');

        return (true === $supported) ? $this->makeRequest($this->endpoint.'/new', $parameters, 'POST') : $supported;
    }
1346507
private function constructString(array $components)
    {
        $formats = array_keys($components);
        $values = array_values($components);
        $keys = array_keys(array_filter($values, 'strlen'));

        return array_reduce($keys, function ($string, $key) use ($formats, $values) {
            return sprintf($formats[$key], $string, $values[$key]);
        }, '');
    }
145655
public function addUse(string $use, string $alias = null)
    {
        $this->repairUse($use);

        list($class, $namespace) = $this->extractClassNameFromUse($use);

        if ($namespace === $this->namespace) {
            return $class;
        }

        $found = array_key_exists($use, $this->uses) ? $this->uses[$use] : false;

        switch (true) {
            case $found === $alias : // already used, same alias (or no alias)
                break;
            case $found === null : // already used without alias but alias provided
                throw new DuplicateUseFirstWithoutAliasException($use, $alias);
            case $found === false : // never used
                $this->uses[$use] = ($alias !== $class) ? $alias : null;
                break;
            default : // already used with different alias
                throw new DuplicateUseWithAliasException($use, $alias, $found);
        }

        return $alias ?: $class;
    }