'], ['{[', '{[', ']}']); } /** * Get data. * * @param string $string * @param array $data = [] * @param array $config = [] * * @return string */ public static function data(string $string, array $data = [], array $config = []) : string { self::$config = $config ?: Config::get('ViewObjects', 'wizard'); $code = self::convertWizardContent($string); $code = Buffering::code($code, $data); $code = self::phpClean($code); return $code; } /** * Protected convert wizard content */ protected static function convertWizardContent($string) { self::textControl($string, $jsData); # 5.4.6[added] $string = self::encodeParenthesis($string); $string = self::decodeParenthesisIntoCallable($string); $pattern = array_merge ( self::callableJS(), self::tags(), $jsData, self::changeVariables(), self::symbolsHeader(), self::keywords(), self::printable(), self::functions(), self::symbolsFooter(), self::comments(), self::html() ); $string = self::replace($pattern, $string); $string = self::decodeParenthesis($string); return $string; } /** * protected functions * * @param void * * @return array */ protected static function callableJS() { $array = []; if( self::$config['callableJS'] ?? true ) { $array = [ '/\[\<(\s*(\$\w+\,*\s*){1,}\s*)\>\](\s*\{\<)/s' => 'function() use($1)$3', # Use '/(function\((.*?)\)\s*)*(use\(.*?(\)|' . self::PARENTHESIS_PATTERN . ')\s*)*\{\<(\s)/s' => 'function($2)$3{$5?>', # Function '/(\s)\>\}/s' => '$1 '', '/\{\{\s*/' => ' ' ?>', '/\{\[\=(.*?)\]\}/' => '', '/(\s*\]\}|@endphp'.self::END.')/' => ' ?>', '/(\{\[\s*|@php'.self::END.')/' => ' '{{', '/\s*\}\]/' => '}}', '/\/\{\/\{/' => '{{', '/\/\}\/\}/' => '}}' ]; } return $array; } /** * Protected change variables */ protected static function changeVariables() { return [ '/\$this(\,|\-\>|\))/' => '$getZNClassInstance$1' ]; } /** * protected symbols header * * @param void * * @return array */ protected static function symbolsHeader() { $symbolHeader = []; if(self::$config['html'] === false ) { $symbolHeader['/\/#/'] = '+[symbol??dies]+'; } return $symbolHeader + [ '/\/@/' => '+[symbol??at]+', '/::/' => '+[symbol??static]+', '/\/:/' => '+[symbol??colon]+' ]; } /** * protected symbols footer * * @param void * * @return array */ protected static function symbolsFooter() { $symbolFooter = []; if(self::$config['html'] === false ) { $symbolFooter['/\+\[symbol\?\?dies\]\+/'] = '#'; } return $symbolFooter + [ '/\+\[symbol\?\?at\]\+/' => '@', '/\+\[symbol\?\?static\]\+/' => '::', '/\+\[symbol\?\?colon\]\+/' => ':' ]; } /** * protected keywords * * @param void * * @return array */ protected static function keywords() { $array = []; if( self::$config['keywords'] ?? true ) { $array = [ '/@selector\s*\((.*?)\)/' => 'selector($1)', '/@ajax\s*\((.*?)\)/' => ' '$4', '/@endform'.self::CRLF.'/sm' => '$2', '/@form\s*\((.*?)\)'.self::CRLF.'/sm' => '$3', '/@(hidden|textarea|text|checkbox|radio|file|email|submit|button|multiselect|select|password)\s*\((.*?)\)'.self::CRLF.'/sm' => '$4', '/@(anchor|mailto|image)\s*\((.*?)\)'.self::CRLF.'/sm' => '$4', '/@container'.self::END.'/sm' => '$2', '/@containerFluid'.self::END.'/sm' => '$2', '/@row'.self::END.'/sm' => '$2', '/@col(([a-zA-Z]{2})([0-9]{1,2}))'.self::END.'/sm' => '$5', '/@end(col|row|container)'.self::END.'/sm' => '$3', '/@endperm'.self::CRLF.'/sm' => '$2', '/@perm\s*\((.*?)\)'.self::CRLF.'/sm' => '$3', '/@login\s*\((.*?)\)'.self::CRLF.'/sm' => '$3', '/@view'.self::CRLF.'/sm' => '$2', '/@(endforelse|endlogin|endvalid)'.self::CRLF.'*/m' => '$3', '/@invalid\s*\((.*?)\)'.self::CRLF.'/sm' => '$3', '/@valid\s*\((.*?)\)'.self::CRLF.'/sm' => '$3', '/@forelse\s*\((\s*(.*?)\s+as\s+(.*?))\)'.self::CRLF.'/sm' => '$5', '/@empty'.self::CRLF.'/m' => '$2', '/@loop\s*\((.*?)\)'.self::CRLF.'/sm' => ' $value):?>$3', '/@endloop'.self::CRLF.'/m' => '$2', '/@(endif|endforeach|endfor|endwhile|break|continue)'.self::CRLF.'*/m' => '$3', '/@(elseif|if|foreach|for|while)\s*\((.*?)\)'.self::CRLF.'/sm' => '$4', '/@(else|not)'.self::CRLF.'*/m' => '$3', ]; } return $array; } /** * protected printable * * @param void * * @return array */ protected static function printable() { $array = []; if( self::$config['printable'] ?? true ) { $suffix = self::CRLF.'/sm'; $coalesce = '\?'; $constant = '((\w+)(\[(\'|\")*.*?(\'|\")*\])*)'; $variable = '/@\$(\w+.*?)'; $start = '((\W)@|^@)'; $outputVariableCoalesce = '$4'; $outputVariable = '$4'; $outputCosntantCoalesce = '$2$10'; $outputCosntant = '$2$10'; $array = [ $variable . $coalesce . $suffix => $outputVariableCoalesce, # Variable $variable . $suffix => $outputVariable, # Variable '/' . $start . $constant . $coalesce . $suffix => $outputCosntantCoalesce, # Constant '/' . $start . $constant . $suffix => $outputCosntant # Constant ]; } return $array; } /** * protected functions * * @param void * * @return array */ protected static function functions() { $array = []; if( self::$config['functions'] ?? true ) { $array = [ '/((\W)@|^@)(\w+)/' => '$2 ') ?>$1', '/\)\s*(?!\s*(\-\>|' . self::STATIC_PATTERN . '|\)|\{|\?\>))(\n|'.PHP_EOL.'|$)/sm' => ') ?>$1$2$3' ]; } return $array; } /** * protected comments * * @param void * * @return array */ protected static function comments() { $array = []; if( self::$config['comments'] ?? true ) { $array = [ '/\{\-\-\s*/' => '' ]; } return $array; } /** * protected html * * @param void * * @return array */ protected static function html() { $array = []; $htmlAttributesTag = '(^|\s)(>*)\#(!*\w+)\s*(\[(.*?)\])*'; if( self::$config['html'] ?? true ) { $array = [ '/\/#/' => '+[symbol??dies]+', '/\s+\#\#(\w+)/' => '', '/'.$htmlAttributesTag.self::CRLF.'/m' => '$2<$3 $5>', '/'.$htmlAttributesTag.'\s+/' => '$2<$3 $5>', '/'.$htmlAttributesTag.'\s*/' => '$2<$3 $5>', '/\<(\w+)\s+\>/' => '<$1>', '/\+\[symbol\?\?dies\]\+/' => '#' ]; } return $array; } /** * protected text control. * * [changed]5.7.5.1 * [fixed ]5.7.5.6|5.7.5.7 * * @param string &$string * * @return void */ protected static function textControl(&$string, &$jsData) { self::internalTextControl('style' , ['#' => '/#', '@' => '/@', ':' => '/:'], $string); $convertScriptChars['#'] = '/#'; if( $jsData = self::jsdata() ) { $convertScriptChars['[{'] = '[ {'; $convertScriptChars['}]'] = '} ]'; } self::internalTextControl('script', $convertScriptChars, $string); } /** * Protected internal text control * * [added]5.7.5.7 */ protected static function internalTextControl($type, $controls, &$string) { # If the use of custom html is obvious or if the page uses an internal style or code preg_match_all('/(\<|\#)'.$type.'(?.*?)(\<\/|\#\#)'.$type.'/si', $string, $standart); $patterns = $standart['data']; if( ! empty($patterns) ) { $changes = []; $keys = array_keys($controls); $values = array_values($controls); foreach( $patterns as $pattern ) { $changes[] = str_replace($keys, $values, $pattern); } $string = str_replace($patterns, $changes, $string); } } /** * protected replace. * * @param array $pattern * @param string $string * * @return string */ protected static function replace($pattern, $string) { return preg_replace(array_keys($pattern), array_values($pattern), $string); } /** * Protected php clean */ protected static function phpClean($string) { return str_replace('?>', '', $string); } /** * Protected encode parenthesis */ protected static function encodeParenthesis($string) { return preg_replace_callback('/(?\{\-\-|@php'.self::END.'|\{\{|\{\[|\[\{)(?.*?)(?\}\}|\]\}|@endphp'.self::END.'|\}\]|\-\-\})/s', function($data) { return $data['open'] . preg_replace('/\)\s*(\n|'.PHP_EOL.'|$)/m', '+[symbol??parenthesis]+', $data['content']) . $data['close']; }, $string); } /** * Protected decode parenthesis */ protected static function decodeParenthesis($string) { return preg_replace('/' . self::PARENTHESIS_PATTERN . '/', ')' . PHP_EOL, $string); } /** * Protected decode parenthesis into callable */ protected static function decodeParenthesisIntoCallable($string) { return preg_replace_callback('/{<.*?>}/s', function($data) { return preg_replace('/' . self::PARENTHESIS_PATTERN . '/', ')' . PHP_EOL, $data[0]); }, $string); } }