generate

@param string $pattern
@param array  $data

@return  mixed|string
333480
public static function generate($pattern, array $data = [])
    {
        $route = static::replaceOptionalSegments($pattern, $data);
        $route = static::replaceWildCards($route, $data);

        return static::replaceAllSegments($route, $data);
    }
683456
public function generateMarkers($Pattern)
    {
        preg_match_all($Pattern, $this->Input, $this->Markers, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
        $Start = 0;
        $this->Working = [];
        foreach ($this->Markers as $Marker) {
            if (!is_array($Marker[0]) || !isset($Marker[0][0]) || is_array($Marker[0][0]) || !isset($Marker[0][1])) {
                break;
            }
            $this->Working[] = substr($this->Input, $Start, $Marker[0][1] - $Start);
            $Start = $Marker[0][1] + strlen($Marker[0][0]);
        }
        $this->Working[] = substr($this->Input, $Start);
    }
62103
protected function parsePattern($pattern)
    {
        $patterns = explode(';', $pattern);
        if (!isset($patterns[1])) {
            // No explicit negative pattern was provided, construct it.
            $patterns[1] = '-' . $patterns[0];
        }
        return $patterns;
    }
180689
public function generate($data){
		if($data->result){
			$bRouter=BRouter::getInstance();
			$url=$bRouter->generateURL('users',array('view'=>'registerdone'),array('usehostname'=>true));
			$this->setLocation($url,0);
			return '';
			}
		$this->email=$data->email;
		$this->name=$data->name;
		$this->errors=$data->errors;
		$this->socLoginList=BSocialFabric::getSocialList();
		$this->setTitle(BLang::_('USERS_REGISTRATION_TITLE'));
		return $this->templateLoad();
		}
559557
public function createPattern($name = 'html', $attributes = array(), $data = array())
    {
        $patternName = ucfirst($name);

        $objectName = 'Library\Pattern\\' . $patternName;
        $pattern = new $objectName($this, $attributes, $data);

        return $pattern;
    }
1108121
public function generate(array $data): string
    {
        /** @var RecordFinder $recordFinder */
        $recordFinder = GeneralUtility::makeInstance(RecordFinder::class);
        $staticDataRecords = $recordFinder->findUidsOfStaticdata();
        // Select first two
        return implode(',', array_slice($staticDataRecords, 0, 2));
    }
520047
static function compilePattern($pattern, array $options = array())
    {

        $len = strlen($pattern);
        /**
         * contains:
         *
         *   array( 'text', $text ),
         *   array( 'variable', $match[0][0][0], $regexp, $var);
         *
         */
        $tokens = array();
        $variables = array();
        $pos = 0;

        /**
         *  the path like:
         *
         *      /blog/to/:year/:month
         *
         *  will be separated like:
         *      
         *      [
         *          '/blog/to',  (text token)
         *          '/:year',    (reg exp token)
         *          '/:month',   (reg exp token)
         *      ]
         */
        $matches = self::splitTokens($pattern);


        // build tokens
        foreach ($matches as $matchIdx => $match) {
            // match[0][1] // matched position for pattern.

            /*
             * Split tokens from abstract pattern
             * to rebuild regexp pattern.
             */
            if ($text = substr($pattern, $pos, $match[0][1] - $pos)) {
                $tokens[] = array( self::TOKEN_TYPE_TEXT, $text);
            }

            // the first char from pattern (which is the seperater)
            // and the first char from the next match pattern
            $seps = array($pattern[$pos]);


            // collect the separator tokens from the next matched pattern
            if (isset($matches[$matchIdx + 1])) {
                $nextMatch = $matches[$matchIdx + 1];

                // check if the next pattern is an optional pattern
                if ($nextMatch[0][0][0] === '(') {

                    $r = self::compilePattern($nextMatch[2][0] ,array());
                    if (isset($r['tokens'][0][1])) {
                        $seps[] = $r['tokens'][0][1][0];
                    }

                } else if ($nextMatch[0][0][0] === ':') { // variable token

                } else {
                    $seps[] = $nextMatch[0][0][0];
                }
            }


            $pos = $match[0][1] + strlen($match[0][0]);


            // generate optional pattern recursively
            if ($match[0][0][0] == '(' ){
                $optional = $match[2][0];
                $subroute = self::compilePattern($optional ,array(
                    'default'   => isset($options['default']) ? $options['default'] : null,
                    'require'   => isset($options['require']) ? $options['require'] : null,
                    'variables' => isset($options['variables']) ? $options['variables'] : null,
                ));

                $tokens[] = array( 
                    self::TOKEN_TYPE_OPTIONAL,
                    $optional[0],
                    $subroute['regex'],
                );
                foreach( $subroute['variables'] as $var ) {
                    $variables[] = $var;
                }
            } else {
                // generate a variable token 
                $varName = $match[1][0];

                // if we defined a pattern for this variable, we should use the given pattern..
                if ( isset( $options['require'][$varName] ) && $req = $options['require'][$varName]) {
                    $regexp = $req;
                } else {
                    if ($pos !== $len) {
                        $seps[] = $pattern[$pos];
                    }
                    // use the default pattern (which is based on the separater charactors we got)
                    $regexp = sprintf('[^%s]+', preg_quote(implode('', array_unique($seps)), '#'));
                }

                // append token item
                $tokens[] = array(self::TOKEN_TYPE_VARIABLE, 
                    $match[0][0][0], 
                    $regexp, 
                    $varName);

                // append variable name
                $variables[] = $varName;
            }
        }

        if ($pos < $len) {
            $tokens[] = array(self::TOKEN_TYPE_TEXT, substr($pattern, $pos));
        }

        // find the first optional token
        $firstOptional = INF;
        for ($i = count($tokens) - 1; $i >= 0; $i--) {
            if ( self::TOKEN_TYPE_VARIABLE === $tokens[$i][0] 
                && isset($options['default'][ $tokens[$i][3] ]) )
            {
                $firstOptional = $i;
            } 
            else 
            {
                break;
            }
        }

        // compute the matching regexp
        $regex = '';

        // indentation level
        $indent = 1;


        // token item structure:
        //   [0] => token type,
        //   [1] => separator
        //   [2] => pattern
        //   [3] => name, 

        // first optional token and only one token.
        if (1 === count($tokens) && 0 === $firstOptional) {
            $token = $tokens[0];
            ++$indent;

            // output regexp with separator and
            $regex .= str_repeat(' ', $indent * 4) . sprintf("%s(?:\n", preg_quote($token[1], '#'));

            // regular expression with place holder name. (?P<name>pattern)
            $regex .= str_repeat(' ', $indent * 4) . sprintf("(?P<%s>%s)\n", $token[3], $token[2]);

        } else {
            foreach ($tokens as $i => $token) {

                switch ( $token[0] ) {
                case self::TOKEN_TYPE_TEXT:
                    $regex .= str_repeat(' ', $indent * 4) . preg_quote($token[1], '#')."\n";
                    break;
                case self::TOKEN_TYPE_OPTIONAL:
                    // the question mark is for optional, the optional item may contains multiple tokens and patterns
                    $regex .= str_repeat(' ', $indent * 4) . "(?:\n" . $token[2] . str_repeat(' ', $indent * 4) . ")?\n";
                    break;
                default:
                    // append new pattern group for the optional pattern
                    if ($i >= $firstOptional) {
                        $regex .= str_repeat(' ', $indent * 4) . "(?:\n";
                        ++$indent;
                    }
                    $regex .= str_repeat(' ', $indent * 4). sprintf("%s(?P<%s>%s)\n", preg_quote($token[1], '#'), $token[3], $token[2]);
                    break;
                }
            }
        }

        // close groups
        while (--$indent) {
            $regex .= str_repeat(' ', $indent * 4).")?\n";
        }

        // save variables
        $options['variables'] = $variables;
        $options['regex'] = $regex;
        $options['tokens'] = $tokens;
        return $options;
    }
343668
protected function writeln($pattern = null, ...$args)
    {
        if (!$this->hasOutput()) {
            return $this;
        }

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

        return $this;
    }
615614
protected function getFilesByPattern($pattern)
    {
        $iterator = Injector::inst()->create('GreenFinder')
            ->in($this->getPath())
            ->name($pattern);
        $files = [];

        foreach ($iterator as $file) {
            $files[] = $this->getRelativePath() . '/' . $file->getRelativePathname();
        }

        return $files;
    }
1212397
protected function createRegexPattern($path, array $patterns = []) {
        $pattern = $this->applyCustomRegexPatterns($path, $patterns);
        $pattern = $this->applyStandardRegexPatterns($pattern);
        $pattern = s('#%s#', $pattern);

        return $pattern;
    }
452268
private function generateResult($format, $data, $trigger = true) {
        $etime = time();
        if ($trigger) {
            if (isset($data['error'])) {
                if ($this->api) {
                    fire('restful\errApi', $this->api, $etime, $data);
                }
                fire('restful\callError', $etime, $data);
            }
            fire('restful\endCall', $etime, $data);
        }
        if ($format == 'json') {
            return new JsonView(['response' => $data]);
        } else {
            return new XmlView($data, 'response');
        }
    }
1104436
public function generate($pattern, array $options = array())
    {
        $options += array('store_id' => null, 'placeholders' => array());

        $result = null;
        $this->hook->attach('sku.generate.before', $pattern, $options, $result);

        if (isset($result)) {
            return (string) $result;
        }

        $sku = $pattern;
        if (!empty($options['placeholders'])) {
            $sku = gplcart_string_replace($pattern, $options['placeholders'], $options);
        }

        $result = $this->getUnique(mb_strimwidth($sku, 0, 200, ''), $options['store_id']);
        $this->hook->attach('sku.generate.after', $pattern, $options, $result);
        return $result;
    }
798345
protected static function key_matcher(array $pattern)
    {
        $keys = [];
        foreach ($pattern as $k => $v) {
            $chars = ['?' => [0, 1], '*' => [0, PHP_INT_MAX], '!' => [1, 1]];
            if (isset($chars[$last = substr($k, -1)])) {
                $keys[$k = substr($k, 0, -1)] = $chars[$last];
            } elseif ($last == '}') {
                list($k, $range) = explode('{', $k);
                $range = explode(',', rtrim($range, '}'));
                $keys[$k] = count($range) == 1
                    ? [$range[0], $range[0]]
                    : [$range[0] === '' ? 0 : $range[0], $range[1] === '' ? PHP_INT_MAX : $range[1]];
            } else {
                $keys[$k] = $chars[$k[0] == ':' ? '*' : '!'];
            }
            array_push($keys[$k], $v, 0);
        }

        return function ($key = null, $value = null) use (&$keys) {
            if (is_null($key)) foreach ($keys as $count) {
                if ($count[3] < $count[0] || $count[3] > $count[1]) return false;
            } else foreach ($keys as $k => &$count) if (self::matcher($key, $k)) {
                if (!self::matches($value, $count[2])) return false;
                $count[3]++;
            }
            return true;
        };
    }
1110472
public function generate(array $data): string
    {
        /** @var RecordFinder $recordFinder */
        $recordFinder = GeneralUtility::makeInstance(RecordFinder::class);
        $staticdataUids = $recordFinder->findUidsOfStaticdata();
        // Return only one element
        return (string)current($staticdataUids);
    }
447516
public function pattern($pattern = null)
        {
            if ($pattern === null) return $this->rulePattern;

            $this->rulePattern = $pattern;

            return $this;
        }
1186701
public function generate($data)
	{
		$result = [];

		foreach ($data as $config)
		{
			$type = 'text';

			if (array_key_exists('type', $config))
			{
				$type = $config['type'];
			}

			$generateFunction = 'generate' . ucfirst($type);

			if (method_exists($this, $generateFunction))
			{
				$result[] = $this->$generateFunction($config);
			}
			else
			{
				$result[] = $this->generateInput($type, $config);
			}
		}

		return $result;
	}
499533
private function generateImageLine(array $data): string
    {
        $images = '';

        if (\count($data['images']) > 1000) {
            $data['images'] = array_splice($data['images'], 1000);
        }

        $builder = [
            'url' => 'loc',
            'location' => 'geo_location',
        ];

        foreach ($data['images'] as $image) {
            $images .= '<image:image>';

            foreach ($image as $key => $element) {
                $images .= sprintf('<image:%1$s>%2$s</image:%1$s>', ($builder[$key] ?? $key), $element);
            }

            $images .= '</image:image>';
        }

        return sprintf('    '.'<url><loc>%s</loc>%s</url>'."\n", $data['url'], $images);
    }