示例#1
0
 public static function buildVariableValue(&$data = [])
 {
     if (is_array($data)) {
         if (count($data) == 0) {
             return '[]';
         } else {
             $results = '';
             foreach ($data as $key => &$dataElement) {
                 $results .= K_Library::buildVariableValue($key) . '=>' . K_Library::buildVariableValue($dataElement);
                 if (end($data) !== $dataElement) {
                     $results .= ',';
                 }
             }
             return '[' . $results . ']';
         }
     } else {
         if (is_string($data)) {
             return '\'' . addcslashes($data, '\'') . '\'';
         } elseif (is_numeric($data)) {
             return (string) $data;
         } elseif (is_bool($data)) {
             return $data ? 'true' : 'false';
         } elseif (is_null($data) || empty($data)) {
             return 'null';
         } else {
             return var_export($data);
         }
     }
 }
 public function renderElement($name, &$info)
 {
     $elementData = $info;
     if (isset($elementData['form'], $elementData['form']['type']) && array_key_exists($elementData['form']['type'], $this->rules)) {
         $elementData['form'] = array_merge_recursive($this->rules[$elementData['form']['type']], $elementData['form']);
     } else {
         throw new Exception('FormDecorator -> renderElement -> data is undefined');
         return;
     }
     if (isset($elementData['visible']) && $elementData['visible'] == false) {
         return;
     }
     $elementData['form']['attr']['name'] = $name;
     $elementName = $name;
     $elementData['value'] = isset($_POST[$name]) ? $_POST[$name] : null;
     if (isset($elementData['editable']) && $elementData['editable'] == false) {
         // @TODO RENDER AS HIDDEN ELEMENTS
         $elementData['render']['html'] = isset($_POST[$elementName]) ? $_POST[$elementName] : '';
     }
     // search variables
     $searchPatches = ['form/render/html', 'form/attr/class', 'form/view/default', 'form/view/error'];
     $searchString = '';
     foreach ($searchPatches as $path) {
         $searchString .= K_Library::arrayPathSearch($elementData, $path, true);
     }
     $vars = [];
     $matches = [];
     if (preg_match_all('/(?<name>\\{(?<var>[a-z0-9\\_\\-\\/\\*]+)(?<method>[\\:][sn*])?\\})/is', $searchString, $matches) && count($matches['var'])) {
         for ($i = 0; $i < count($matches['var']); $i++) {
             $varValue = K_Library::arrayPathSearch($elementData, $matches['var'][$i], $matches['method'][$i] == ':s' ? true : false);
             if (empty($varValue)) {
                 if ($matches['method'][$i] === ':n') {
                     // show 'null' on null ;)
                     $varValue = 'null';
                 } else {
                     $varValue = '';
                 }
             }
             $vars[$matches['name'][$i]] = $varValue;
         }
         foreach ($vars as &$varValue) {
             if (is_string($varValue)) {
                 $varValue = strtr($varValue, $vars);
             } else {
                 $varValue = strtr(K_Library::buildVariableValue($varValue, true), $vars);
             }
         }
     }
     var_dump($vars);
     echo '<br><br><br>';
     var_dump($elementData);
     //K_Library::arrayPathSearch();
 }
示例#3
0
 public function buildVariable($varName, &$varInfo)
 {
     $type = 'var';
     if (isset($varInfo['type']) && in_array($varInfo['type'], $this->variableTypes)) {
         $type = $varInfo['type'];
     }
     $isStatic = false;
     if (isset($varInfo['static']) && $varInfo['static']) {
         $isStatic = true;
     }
     $value = '';
     if (isset($varInfo['value'])) {
         $value = K_Library::buildVariableValue($varInfo['value']);
         // (string)$varInfo['value'];
     }
     $useQuotes = false;
     if (isset($varInfo['value']) && is_string($varInfo['value']) && isset($varInfo['quotes']) && $varInfo['quotes'] == true) {
         $useQuotes = true;
     }
     $phpString = $type . ' ' . ($isStatic ? 'static ' : '') . '$' . $varName . (!empty($value) ? ' = ' . ($useQuotes ? '\'' . addslashes($value) . '\'' : $value) : '') . ';';
     return $phpString;
 }