protected function _processData(array &$data, $parentGroupName = false) { $result = array(); foreach ($data as $v) { if ($v['type'] == 'file' && !$this->_defined) { $this->file = true; break; } } if ($this->file && !$this->_defined) { $this->setAttr('method', 'post'); $this->setAttr('enctype', 'multipart/form-data'); $this->_defined = true; require_once 'Oops/Utils.php'; $max_file_size = min(Oops_Utils::toBytes(ini_get('upload_max_filesize')), Oops_Utils::toBytes(ini_get('post_max_size'))); array_unshift($data, array('type' => 'hidden', 'name' => 'MAX_FILE_SIZE', 'value' => $max_file_size)); } foreach ($data as $v) { if (!isset($v['text'])) { $v['text'] = ''; } if ($v['type'] === 'group' && isset($v['items']) && !empty($v['items'])) { if (isset($this->_params[$v['name']])) { foreach ($this->_params[$v['name']] as $paramKey => $paramVal) { $v[$paramKey] = $paramVal; } } if ($this->groupNames && $parentGroupName) { $newName = $parentGroupName . '[' . $v['name'] . ']'; } elseif ($this->groupNames && !$parentGroupName) { $newName = $v['name']; } else { $newName = false; } $result[] = array('name' => $v['name'], 'text' => $v['text'], 'items' => $this->_processData($v['items'], $newName)); } else { if (isset($this->_params[$v['name']]['display']) && $this->_params[$v['name']]['display'] == false) { continue; } if (isset($this->_params[$v['name']])) { foreach ($this->_params[$v['name']] as $paramKey => $paramVal) { $v[$paramKey] = $paramVal; } } if ($this->groupNames && $parentGroupName) { $v['name'] = $parentGroupName . '[' . $v['name'] . ']'; } $html = $this->_makeField($v); $result[] = array('name' => $v['name'], 'text' => $v['text'], 'html' => $html); } } return $result; }
public function test_toBytes() { $this->assertEquals(1024, Oops_Utils::toBytes('1K')); $this->assertEquals(2 * 1024, Oops_Utils::toBytes(' 2K ')); $this->assertEquals(8 * 1024 * 1024, Oops_Utils::toBytes('8M')); }