Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class controller_base extends base{
- function __construct(){
- parent::__construct();
- }
- protected function generate_password($number){
- $arr = array('a','b','c','d','e','f',
- 'g','h','i','j','k','l',
- 'm','n','o','q','p','r','s',
- 't','u','v','w','x','y','z',
- 'A','B','C','D','E','F',
- 'G','H','I','J','K','L',
- 'M','N','O','Q','P','R','S',
- 'T','U','V','W','X','Y','Z',
- '1','2','3','4','5','6',
- '7','8','9','0');
- // Генерируем пароль
- $pass = "";
- for($i = 0; $i < $number; $i++){
- // Вычисляем случайный индекс массива
- $index = rand(0, 61);
- $pass .= $arr[$index];
- }
- return $pass;
- }
- private function add_child($dom,$root,$child_name,$child_value='',$array_attr=''){
- if (empty($root)) throw new XML_Exception("Не установлен root параметр",0);
- if (empty($child_name)) throw new XML_Exception("Не установлен child_name параметр",1);
- $child=$dom->createElement($child_name);
- if (isset($child_value)) {
- if (is_array($child_value)) {
- $array_attr=$child_value;
- } else {
- $child->appendChild($dom->createTextNode($child_value));
- }
- }
- if (is_array($array_attr)){
- foreach ($array_attr as $attr_name => $attr_value){
- $child->setAttribute($attr_name,$attr_value);
- }
- }
- return $root->appendChild($child);
- }
- private function addch_fr_arr($dom,$root,$parametrs){
- foreach ($parametrs as $key=>$value){
- $child_name=$key;
- if (empty($value)) {
- $child=$this->add_child($dom,$root,$child_name,$child_value,$array_attr);
- //throw new Exception("Пустой xml",2);
- } else {
- foreach ($value as $key=>$value){
- if ($key===0){
- $child_value=$value;
- } elseif ($key=="attr"){
- $array_attr = $value;
- } elseif ($key=="child"){
- $child_array=$value;
- } else {
- $child_value=$value;
- }
- }
- $child=$this->add_child($dom,$root,$child_name,$child_value,$array_attr);
- unset($child_value);
- if (is_array($child_array)) $this->addch_fr_arr($dom,$child,$child_array);
- }
- }
- }
- public function arr2xml($charset,$parametrs){
- $dom = new DOMDocument('1.0', $charset);
- $this->addch_fr_arr($dom,$dom,$parametrs);
- return $dom->saveXML();
- }
- }
Add Comment
Please, Sign In to add comment