示例#1
0
    /**
     * Returns available definitions in string.
     *
     * @param   string  $search         search string
     * @param   string  $language       default definitions language
     * @param   Boolean $shortNotation  show short notation instead of full one
     *
     * @return  string
     */
    private function getDefinitionsForPrint($search = null, $language = 'en', $shortNotation = true)
    {
        if ($shortNotation) {
            $template = '<info>{type}</info> <comment>{regex}</comment>';
        } else {
            $template = <<<TPL
<info>{type}</info> <comment>{regex}</comment>
    {description}<path># {path}</path>

TPL;
        }
        $definitions = array();
        foreach ($this->dispatcher->getDefinitions() as $regex => $definition) {
            $regex = $this->dispatcher->translateDefinitionRegex($regex, $language);
            if ($search && !preg_match('/' . str_replace(' ', '.*', preg_quote($search, '/') . '/'), $regex)) {
                continue;
            }
            $regex = preg_replace_callback('/\\([^\\)]*\\)/', function ($capture) {
                return "</comment><capture>{$capture[0]}</capture><comment>";
            }, $regex);
            $definitions[] = strtr($template, array('{regex}' => $regex, '{type}' => str_pad($definition->getType(), 5, ' ', STR_PAD_LEFT), '{description}' => $definition->getDescription() ? '- ' . $definition->getDescription() . "\n    " : '', '{path}' => $definition->getPath()));
        }
        return implode("\n", $definitions);
    }