/** * Creates constraint object from tokens. * <p> * If parameter $constraintName is not passed then current position should point to the name of the constraint. * * @param Tokenizer $tokenizer Tokens collection. * @param string $constraintName Optional name of the constraint. * * @return Constraint */ public static function create(Tokenizer $tokenizer, $constraintName = '') { if ($constraintName === false) { $constraintName = ''; } elseif (!$constraintName) { $constraintName = $tokenizer->getCurrentToken()->text; $tokenizer->nextToken(); $tokenizer->skipWhiteSpace(); } $constraint = new self($constraintName); $token = $tokenizer->getCurrentToken(); $level = $token->level; $constraintDefinition = ''; do { if ($token->level == $level && $token->text == ',') { break; } if ($token->level < $level && $token->text == ')') { break; } $constraintDefinition .= $token->text; $token = $tokenizer->nextToken(); } while (!$tokenizer->endOfInput()); $constraint->setBody($constraintDefinition); return $constraint; }
public static function fromReflection(Zend_Reflection_Method $reflectionMethod) { $method = new self(); $method->setSourceContent($reflectionMethod->getContents(false)); $method->setSourceDirty(false); if ($reflectionMethod->getDocComment() != '') { $method->setDocblock(Zend_CodeGenerator_Php_Docblock::fromReflection($reflectionMethod->getDocblock())); } $method->setFinal($reflectionMethod->isFinal()); if ($reflectionMethod->isPrivate()) { $method->setVisibility(self::VISIBILITY_PRIVATE); } elseif ($reflectionMethod->isProtected()) { $method->setVisibility(self::VISIBILITY_PROTECTED); } else { $method->setVisibility(self::VISIBILITY_PUBLIC); } $method->setStatic($reflectionMethod->isStatic()); $method->setName($reflectionMethod->getName()); foreach ($reflectionMethod->getParameters() as $reflectionParameter) { $method->setParameter(Zend_CodeGenerator_Php_Parameter::fromReflection($reflectionParameter)); } $body = $reflectionMethod->getBody(); $body2 = str_replace("\n\n", "\n", $body); $body2 = preg_replace("|^\n\\s{4}|muU", "\n", $body2); $body2 = preg_replace("|^\\s{4}|muU", "", $body2); // $body2 = str_replace(' ', '.', $body2); //dmDebug::kill($body, "\n".$body2); $method->setBody($body2); return $method; }
public static function fromRaw($body, $headers) { $out = new self(); $out->setBody($body); $out->setHeaders($headers); $out->parseData(); return $out; }
/** * @param string $url * @param array $post * @param wfWAFHTTP $request * @return wfWAFHTTPResponse|bool * @throws wfWAFHTTPTransportException */ public static function post($url, $post = array(), $request = null) { if (!$request) { $request = new self(); } $request->setUrl($url); $request->setMethod('POST'); $request->setBody($post); $request->setTransport(wfWAFHTTPTransport::getInstance()); return $request->send(); }
/** * Creates trigger object from tokens. * <p> * Current position should point to the name of the trigger. * * @param Tokenizer $tokenizer Tokens collection. * * @return Trigger */ public static function create(Tokenizer $tokenizer) { $name = $tokenizer->getCurrentToken()->text; $trigger = new self($name); $tokenizer->resetState(); $definition = ''; while (!$tokenizer->endOfInput()) { $definition .= $tokenizer->getCurrentToken()->text; $tokenizer->nextToken(); } $trigger->setBody($definition); return $trigger; }
/** * Enter description here... * * @param ZendL_Reflection_File $reflectionFile * @return ZendL_Tool_CodeGenerator_Php_File */ public static function fromReflection(ZendL_Reflection_File $reflectionFile) { $file = new self(); $file->setSourceContent($reflectionFile->getContents()); $file->setSourceDirty(false); $body = $reflectionFile->getContents(); // @todo this whole area needs to be reworked with respect to how body lines are processed foreach ($reflectionFile->getClasses() as $class) { $file->setClass(ZendL_Tool_CodeGenerator_Php_Class::fromReflection($class)); $classStartLine = $class->getStartLine(true); $classEndLine = $class->getEndLine(); $bodyLines = explode("\n", $body); $bodyReturn = array(); for ($lineNum = 1; $lineNum <= count($bodyLines); $lineNum++) { if ($lineNum == $classStartLine) { $bodyReturn[] = str_replace('?', $class->getName(), self::$_markerClass); //'/* ZendL_Tool_CodeGenerator_Php_File-ClassMarker: {' . $class->getName() . '} */'; $lineNum = $classEndLine; } else { $bodyReturn[] = $bodyLines[$lineNum - 1]; // adjust for index -> line conversion } } $body = implode("\n", $bodyReturn); unset($bodyLines, $bodyReturn, $classStartLine, $classEndLine); } if ($docblock = $reflectionFile->getDocblock()) { $file->setDocblock(ZendL_Tool_CodeGenerator_Php_Docblock::fromReflection($docblock)); $bodyLines = explode("\n", $body); $bodyReturn = array(); for ($lineNum = 1; $lineNum <= count($bodyLines); $lineNum++) { if ($lineNum == $docblock->getStartLine()) { $bodyReturn[] = str_replace('?', $class->getName(), self::$_markerDocblock); //'/* ZendL_Tool_CodeGenerator_Php_File-ClassMarker: {' . $class->getName() . '} */'; $lineNum = $docblock->getEndLine(); } else { $bodyReturn[] = $bodyLines[$lineNum - 1]; // adjust for index -> line conversion } } $body = implode("\n", $bodyReturn); unset($bodyLines, $bodyReturn, $classStartLine, $classEndLine); } $file->setBody($body); return $file; }
/** * @param array $recipient Recipient e-mail address * @param string $subject E-mail subject * @param string $body Message body * @param bool $html - HTML mail or plain text * @param array $replyto Reply to email address * @param array $cc CC e-mail address * @param array $bcc BCC e-mail address * @param string $attachment Attachment file name * @param array $cert - pem certificate * @param array $from - array( from, fromname ) * @internal param array $replytoname Reply to name * @return boolean True on success */ public static function SpSendMail($recipient, $subject, $body, $html = false, $replyto = null, $cc = null, $bcc = null, $attachment = null, $cert = null, $from = null) { $from = is_array($from) ? $from : array(Sobi::Cfg('mail.from'), Sobi::Cfg('mail.fromname')); $mail = new self(); $mail->setSender($from); $mail->setSubject($subject); $mail->setBody($body); if ($html) { $mail->IsHTML(true); } if ($cert) { $mail->Sign($cert['certificate'], $cert['key'], $cert['password']); } $mail->addRecipient($recipient); $mail->addCC($cc); $mail->addBCC($bcc); $mail->addAttachment($attachment); $mail->addReplyTo($replyto); return $mail->Send(); }
/** * Creates stored procedure object from tokens. * <p> * Current position should point to the type of the stored procedure (PROCEDURE, FUNCTION or TYPE). * <p> * Name may consist of two parts divided by '.'. * * @param Tokenizer $tokenizer Tokens collection. * * @return Procedure */ public static function create(Tokenizer $tokenizer) { $type = $tokenizer->getCurrentToken()->text; $tokenizer->nextToken(); $tokenizer->skipWhiteSpace(); $name = $tokenizer->getCurrentToken()->text; $token = $tokenizer->nextToken(); if ($token->text === '.') { $token = $tokenizer->nextToken(); $name .= '.' . $token->text; } $procedure = new self($name, $type); $tokenizer->resetState(); $definition = ''; while (!$tokenizer->endOfInput()) { $definition .= $tokenizer->getCurrentToken()->text; $tokenizer->nextToken(); } $procedure->setBody($definition); return $procedure; }
/** * @return Request */ public static function fromInput() { global $module; $model = new self(); $model->setMethod(self::getMethodFromInput()); if (isset($module)) { $model->setPath($module); $input = explode('/', $module); $model->setSegments($input); } $model->setBody(InputStream::getInput()); $model->setHeaders(self::getHeadersFromInput()); $model->setParameters($_GET); $model->setCookies($_COOKIE); $model->setPost($_POST); $model->setEnvironment($_SERVER); $model->setStatus(http_response_code()); $model->setUrl(self::getCurrentUri()); $model->parseData(); return $model; }
/** */ public static function createFromRawResponse($rawResponse) { $response = new self($rawResponse); $lines = preg_split('/(\\r?\\n)/', $rawResponse); for ($i = 0; $i < count($lines); $i++) { if (0 == $i) { preg_match('/^HTTP\\/(\\d\\.\\d)\\s(\\d+)\\s(.+)/', $lines[$i], $statusLine); $response->setStatusCode($statusCode = $statusLine[2]); continue; } if (empty($lines[$i])) { $body = array_slice($lines, $i + 1); $response->setBody(implode("\n", $body)); break; } if (strpos($lines[$i], ':')) { $headerParts = explode(':', $lines[$i]); $response->setHeader($headerParts[0], $headerParts[1]); } } return $response; }
/** * fromReflection() * * @param Zend_Reflection_Method $reflectionMethod * @return Zend_CodeGenerator_Php_Method */ public static function fromReflection(Zend_Reflection_Method $reflectionMethod) { $method = new self(); $method->setSourceContent($reflectionMethod->getContents(false)); $method->setSourceDirty(false); if ($reflectionMethod->getDocComment() != '') { $method->setDocblock(Zend_CodeGenerator_Php_Docblock::fromReflection($reflectionMethod->getDocblock())); } $method->setFinal($reflectionMethod->isFinal()); if ($reflectionMethod->isPrivate()) { $method->setVisibility(self::VISIBILITY_PRIVATE); } elseif ($reflectionMethod->isProtected()) { $method->setVisibility(self::VISIBILITY_PROTECTED); } else { $method->setVisibility(self::VISIBILITY_PUBLIC); } $method->setStatic($reflectionMethod->isStatic()); $method->setName($reflectionMethod->getName()); foreach ($reflectionMethod->getParameters() as $reflectionParameter) { $method->setParameter(Zend_CodeGenerator_Php_Parameter::fromReflection($reflectionParameter)); } $method->setBody($reflectionMethod->getBody()); return $method; }
public static function sendMailS($sender, $receiver, $subject, $body, $html = false, $resendCheck = false) { $mail = new self(); $mail->setSender($sender); $mail->setReceiver($receiver); $mail->setSubject($subject); $mail->setBody($body); $mail->setResendCheck($resendCheck); return false === $html ? $mail->sendAsText() : $mail->sendAsHTML(); }
/** * Create an instance from an input string. * @param string $str the stringified response * @return \vakata\http\Response the response instance * @codeCoverageIgnore */ public static function fromString($str) { $res = new self(); $break = strpos($str, "\r\n\r\n") === false ? "\n" : "\r\n"; // just in case someone breaks RFC 2616 list($headers, $message) = explode($break . $break, (string) $str, 2); $headers = explode($break, preg_replace("(" . $break . "\\s+)", " ", $headers)); if (isset($headers[0]) && substr($headers[0], 0, 5) === 'HTTP/') { $temp = explode(' ', substr($headers[0], 5)); $res->setProtocolVersion($temp[0]); $res->setStatusCode((int) $temp[1]); unset($headers[0]); $headers = array_values($headers); } foreach (array_filter($headers) as $v) { $v = explode(':', $v, 2); $res->setHeader(trim($v[0]), trim($v[1])); } $res->setBody($message); $res->removeHeader('Content-Length'); $res->removeHeader('Transfer-Encoding'); return $res; }
/** * Create an instance from a stringified request. * @param string $str the stringified request * @return \vakata\http\Request the request instance * @codeCoverageIgnore */ public static function fromString($str) { $req = new self(); $break = strpos($str, "\r\n\r\n") === false ? "\n" : "\r\n"; // just in case someone breaks RFC 2616 list($headers, $message) = explode($break . $break, $str, 2); $headers = explode($break, preg_replace("(" . $break . "\\s+)", " ", $headers)); if (isset($headers[0]) && strlen($headers[0])) { $temp = explode(' ', $headers[0]); if (in_array($temp[0], ['GET', 'POST', 'HEAD', 'PATCH', 'PUT', 'OPTIONS', 'TRACE', 'DELETE'])) { $req->setMethod($temp[0]); $req->setUrl($temp[1]); if (isset($temp[2])) { $req->setProtocolVersion(substr($temp[2], 5)); } unset($headers[0]); $headers = array_values($headers); } } foreach (array_filter($headers) as $v) { $v = explode(':', $v, 2); $req->setHeader(trim($v[0]), trim($v[1])); } if ($req->hasHeader('Host')) { $host = explode(':', $req->getHeader('Host'), 2); $req->getUrl()->setHost($host[0]); if (isset($host[1]) && (int) $host[1]) { $req->getUrl()->setPort($host[1]); } } if (strpos($req->getHeader('Content-Type'), 'multipart') !== false) { $bndr = trim(explode(' boundary=', $req->getHeader('Content-Type'))[1], '"'); $parts = explode($break . '--' . $bndr, $break . $message); array_pop($parts); array_shift($parts); $post = []; foreach ($parts as $item) { list($head, $body) = explode($break . $break, $item, 2); $head = explode($break, preg_replace("(" . $break . "\\s+)", " ", $head)); foreach ($head as $h) { if (strpos(strtolower($h), 'content-disposition') === 0) { $cd = explode(';', $h); $name = ''; $file = ''; foreach ($cd as $p) { if (strpos(trim($p), 'name=') === 0) { $name = trim(explode('name=', $p)[1], ' "'); } if (strpos(trim($p), 'filename=') === 0) { $file = trim(explode('filename=', $p)[1], ' "'); } } if ($file) { $req->addUpload($name, $body, $file); } else { $post[$name] = $body; } } } } $req->setBody(http_build_query($post)); } elseif (strlen($message)) { $req->setBody($message); } $req->removeHeader('Content-Length'); $req->removeHeader('Transfer-Encoding'); return $req; }
static function send($to, $subject, $msg, $attach = '', $attachFilename = '') { $e = new self(); $e->setFrom(ini::get('email-address'), ini::get('email-name')); $e->setTo($to); $e->setSubject($subject); $e->setBody($msg); if (strlen($attach)) { $e->attach($attach, strlen($attachFilename) ? $attachFilename : 'attachment-1'); } return $e->mail(); }
/** * @param wfWAFRequest|null $request * @return wfWAFRequest */ public static function createFromGlobals($request = null) { if ($request === null) { if (version_compare(phpversion(), '5.3.0') > 0) { $class = get_called_class(); $request = new $class(); } else { $request = new self(); } } $request->setAuth(array()); $request->setCookies(array()); $request->setFileNames(array()); $request->setFiles(array()); $request->setHeaders(array()); $request->setHost(''); $request->setIP(''); $request->setMethod(''); $request->setPath(''); $request->setProtocol(''); $request->setTimestamp(''); $request->setURI(''); $request->setBody(wfWAFUtils::stripMagicQuotes($_POST)); $request->setQueryString(wfWAFUtils::stripMagicQuotes($_GET)); $request->setCookies(wfWAFUtils::stripMagicQuotes($_COOKIE)); $request->setFiles(wfWAFUtils::stripMagicQuotes($_FILES)); if (!empty($_FILES)) { $fileNames = array(); foreach ($_FILES as $input => $file) { $fileNames[$input] = wfWAFUtils::stripMagicQuotes($file['name']); } $request->setFileNames($fileNames); } if (is_array($_SERVER)) { //All of these depend on $_SERVER being non-null and an array $auth = array(); if (array_key_exists('PHP_AUTH_USER', $_SERVER)) { $auth['user'] = wfWAFUtils::stripMagicQuotes($_SERVER['PHP_AUTH_USER']); } if (array_key_exists('PHP_AUTH_PW', $_SERVER)) { $auth['password'] = wfWAFUtils::stripMagicQuotes($_SERVER['PHP_AUTH_PW']); } $request->setAuth($auth); if (array_key_exists('REQUEST_TIME_FLOAT', $_SERVER)) { $timestamp = $_SERVER['REQUEST_TIME_FLOAT']; } else { if (array_key_exists('REQUEST_TIME', $_SERVER)) { $timestamp = $_SERVER['REQUEST_TIME']; } else { $timestamp = time(); } } $request->setTimestamp($timestamp); $headers = array(); foreach ($_SERVER as $key => $value) { if (wfWAFUtils::strpos($key, 'HTTP_') === 0) { $header = wfWAFUtils::substr($key, 5); $header = str_replace(array(' ', '_'), array('', ' '), $header); $header = ucwords(wfWAFUtils::strtolower($header)); $header = str_replace(' ', '-', $header); $headers[$header] = wfWAFUtils::stripMagicQuotes($value); } } if (array_key_exists('CONTENT_TYPE', $_SERVER)) { $headers['Content-Type'] = wfWAFUtils::stripMagicQuotes($_SERVER['CONTENT_TYPE']); } if (array_key_exists('CONTENT_LENGTH', $_SERVER)) { $headers['Content-Length'] = wfWAFUtils::stripMagicQuotes($_SERVER['CONTENT_LENGTH']); } $request->setHeaders($headers); $host = ''; if (array_key_exists('Host', $headers)) { $host = $headers['Host']; } else { if (array_key_exists('SERVER_NAME', $_SERVER)) { $host = wfWAFUtils::stripMagicQuotes($_SERVER['SERVER_NAME']); } } $request->setHost($host); $request->setMethod(array_key_exists('REQUEST_METHOD', $_SERVER) ? wfWAFUtils::stripMagicQuotes($_SERVER['REQUEST_METHOD']) : 'GET'); $request->setProtocol(array_key_exists('HTTPS', $_SERVER) && $_SERVER['HTTPS'] && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http'); $request->setUri(array_key_exists('REQUEST_URI', $_SERVER) ? wfWAFUtils::stripMagicQuotes($_SERVER['REQUEST_URI']) : ''); $uri = parse_url($request->getURI()); if (is_array($uri) && array_key_exists('path', $uri)) { $path = $uri['path']; } else { $path = $request->getURI(); } $request->setPath($path); } return $request; }
/** * Creates column object from tokens. * <p> * Current position should point to the name of the column. * * @param Tokenizer $tokenizer Tokens collection. * * @return Column * @throws NotSupportedException */ public static function create(Tokenizer $tokenizer) { $columnName = $tokenizer->getCurrentToken()->text; $tokenizer->nextToken(); $tokenizer->skipWhiteSpace(); $token = $tokenizer->getCurrentToken(); $columnType = $token->upper; if (!self::checkType($columnType)) { throw new NotSupportedException("column type expected but [" . $tokenizer->getCurrentToken()->text . "] found. line: " . $tokenizer->getCurrentToken()->line); } $column = new self($columnName); $column->type = $columnType; $level = $token->level; $lengthLevel = -1; $columnDefinition = ''; do { if ($token->level == $level && $token->text == ',') { break; } if ($token->level < $level && $token->text == ')') { break; } $columnDefinition .= $token->text; if ($token->upper === 'NOT') { $column->nullable = false; } elseif ($token->upper === 'DEFAULT') { $column->default = false; } elseif ($column->default === false) { if ($token->type !== Token::T_WHITESPACE && $token->type !== Token::T_COMMENT) { $column->default = $token->text; } } $token = $tokenizer->nextToken(); //parentheses after type if ($lengthLevel == -1) { if ($token->text == '(') { $lengthLevel = $token->level; $column->length = ''; while (!$tokenizer->endOfInput()) { $columnDefinition .= $token->text; $token = $tokenizer->nextToken(); if ($token->level == $lengthLevel && $token->text == ')') { break; } $column->length .= $token->text; } } elseif ($token->type !== Token::T_WHITESPACE && $token->type !== Token::T_COMMENT) { $lengthLevel = 0; } } } while (!$tokenizer->endOfInput()); $column->setBody($columnDefinition); return $column; }