} $methods = ''; $properties = ''; foreach ($xml->children() as $child) { print_line($child->getName()); $name = $child->getName(); $camelName = $name; $camelName[0] = strtolower($camelName[0]); if (count($child->children())) { $variableType = 'array'; } else { $value = (string) $child->__toString(); if ($value == 'Yes' || $value == 'No') { $variableType = 'boolean'; } else { if (is_float($value)) { $variableType = 'float'; } else { if (is_numeric($value)) { $variableType = 'int'; } else { $variableType = 'string'; } } } } $methods .= generate_method($name, $camelName, $variableType); $properties .= generate_property($camelName, $variableType); } $template = replace_template(dirname(__FILE__) . '/generate_class_from_xml_fragment_class_template.php.template', array('{name}' => $targetClass, '{properties}' => $properties, '{methods}' => $methods, '{example_xml}' => $xml->saveXML())); file_put_contents($targetDir . '/' . $targetClass . '.php', $template);
* @author Gassan Idriss <*****@*****.**> */ require_once dirname(__FILE__) . '/functions.php'; if (!isset($argv[1]) || !isset($argv[2])) { print_line(PHP_EOL . 'Usage:'); print_line("\t" . 'php ' . $_SERVER['SCRIPT_NAME'] . ' /path/to/fragment.xml ClassName [/out/dir]'); print_line("\t" . 'php ' . $_SERVER['SCRIPT_NAME'] . ' "<XML></XML>" ClassName [/out/dir]', true); } $sourceXml = $argv[1]; $targetClass = $argv[2]; $targetDir = isset($argv[3]) && is_dir($argv[3]) ? $argv[3] : dirname(__FILE__); if (!is_dir($targetDir)) { print_line(spritnf('Dir %s Not Found', $targetDir), true); } if (file_exists($sourceXml)) { $xml = new \SimpleXMLElement(file_get_contents($sourceXml)); } else { $xml = new \SimpleXMLElement($sourceXml); } $setters = ''; $assertions = ''; foreach ($xml->children() as $child) { print_line($child->getName()); $name = $child->getName(); $camelName = $name; $camelName[0] = strtolower($camelName[0]); $setters .= generate_setter($name, $camelName); $assertions .= generate_assertion($name, $camelName); } $template = replace_template(dirname(__FILE__) . '/generate_class_from_xml_fragment_class_template.php.template', array('{name}' => $targetClass, '{setters}' => $setters, '{assertions}' => $assertions, '{expected_xml}' => $xml->saveXML(), '{xml_assertions}' => null)); file_put_contents($targetDir . '/' . $targetClass . 'Test.php', $template);
static function submitNewUser($username, $password, $email, $password2 = null) { if (!registerUsers()) { return 5; } // admin has disabled registering new users $email = filter_var($email, FILTER_SANITIZE_EMAIL); $username = validateUserName($username) ? $username : false; $password = validatePassword($password) ? $password : false; if (!$username || !$password) { return 1; // username or password does not meet the requirements } if (isset($password2)) { $password2 = validatePassword($password2) ? $password2 : false; if ($password2 != false) { //$password2 = passwordHash($password2); if ($password2 != $password) { return 4; // passwords do not match } } else { return 4; } } $password = passwordHash($password); $current_datetime = jDateTime::gdate('Y-m-d H:i:s'); if (Users::userExists($username)) { return 2; // username already exist } $activate = md5($email . time()); $conn = MySQL::open_conn(); $query = "INSERT INTO c_users (user_login, user_pass, user_email, user_registered, activate) "; $query .= "VALUES ('{$username}', '{$password}', '{$email}', '{$current_datetime}', '{$activate}')"; $res = $conn->query($query); if (!$res) { return 3; } // unknown error while creating new user $row = $conn->query("SELECT MAX(ID) AS max FROM c_users")->fetch_array(); if ($row) { $id = $row['max']; } if (shouldConfMail()) { $mail_content = replace_template(getDefaultEmailTemplateContent(), getConfEmailTemplateVars($id)); Email::sendMail($email, $username, getConfMailSubject(), $mail_content); } return 0; }