repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
sequencelengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
nguyenanhung/nusoap
src-fix/nusoap.php
nusoap_server.verify_method
function verify_method($operation, $request) { if (isset($this->wsdl) && is_object($this->wsdl)) { if ($this->wsdl->getOperationData($operation)) { return TRUE; } } elseif (isset($this->operations[$operation])) { return TRUE; } return FALSE; }
php
function verify_method($operation, $request) { if (isset($this->wsdl) && is_object($this->wsdl)) { if ($this->wsdl->getOperationData($operation)) { return TRUE; } } elseif (isset($this->operations[$operation])) { return TRUE; } return FALSE; }
[ "function", "verify_method", "(", "$", "operation", ",", "$", "request", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "wsdl", ")", "&&", "is_object", "(", "$", "this", "->", "wsdl", ")", ")", "{", "if", "(", "$", "this", "->", "wsdl", "->", "getOperationData", "(", "$", "operation", ")", ")", "{", "return", "TRUE", ";", "}", "}", "elseif", "(", "isset", "(", "$", "this", "->", "operations", "[", "$", "operation", "]", ")", ")", "{", "return", "TRUE", ";", "}", "return", "FALSE", ";", "}" ]
takes the value that was created by parsing the request and compares to the method's signature, if available. @param string $operation The operation to be invoked @param array $request The array of parameter values @return boolean Whether the operation was found @access private
[ "takes", "the", "value", "that", "was", "created", "by", "parsing", "the", "request", "and", "compares", "to", "the", "method", "s", "signature", "if", "available", "." ]
train
https://github.com/nguyenanhung/nusoap/blob/a9b4d98f4f3fe748f8e5d9f8091dfc53585d2556/src-fix/nusoap.php#L4548-L4559
nguyenanhung/nusoap
src-fix/nusoap.php
nusoap_server.parseRequest
function parseRequest($headers, $data) { $this->debug('Entering parseRequest() for data of length ' . strlen($data) . ' headers:'); $this->appendDebug($this->varDump($headers)); if (!isset($headers['content-type'])) { $this->setError('Request not of type text/xml (no content-type header)'); return FALSE; } if (!strstr($headers['content-type'], 'text/xml')) { $this->setError('Request not of type text/xml'); return FALSE; } if (strpos($headers['content-type'], '=')) { $enc = str_replace('"', '', substr(strstr($headers["content-type"], '='), 1)); $this->debug('Got response encoding: ' . $enc); if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) { $this->xml_encoding = strtoupper($enc); } else { $this->xml_encoding = 'US-ASCII'; } } else { // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1 $this->xml_encoding = 'ISO-8859-1'; } $this->debug('Use encoding: ' . $this->xml_encoding . ' when creating nusoap_parser'); // parse response, get soap parser obj $parser = new nusoap_parser($data, $this->xml_encoding, '', $this->decode_utf8); // parser debug $this->debug("parser debug: \n" . $parser->getDebug()); // if fault occurred during message parsing if ($err = $parser->getError()) { $this->result = 'fault: error in msg parsing: ' . $err; $this->fault('SOAP-ENV:Client', "error in msg parsing:\n" . $err); // else successfully parsed request into soapval object } else { // get/set methodname $this->methodURI = $parser->root_struct_namespace; $this->methodname = $parser->root_struct_name; $this->debug('methodname: ' . $this->methodname . ' methodURI: ' . $this->methodURI); $this->debug('calling parser->get_soapbody()'); $this->methodparams = $parser->get_soapbody(); // get SOAP headers $this->requestHeaders = $parser->getHeaders(); // get SOAP Header $this->requestHeader = $parser->get_soapheader(); // add document for doclit support $this->document = $parser->document; } }
php
function parseRequest($headers, $data) { $this->debug('Entering parseRequest() for data of length ' . strlen($data) . ' headers:'); $this->appendDebug($this->varDump($headers)); if (!isset($headers['content-type'])) { $this->setError('Request not of type text/xml (no content-type header)'); return FALSE; } if (!strstr($headers['content-type'], 'text/xml')) { $this->setError('Request not of type text/xml'); return FALSE; } if (strpos($headers['content-type'], '=')) { $enc = str_replace('"', '', substr(strstr($headers["content-type"], '='), 1)); $this->debug('Got response encoding: ' . $enc); if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) { $this->xml_encoding = strtoupper($enc); } else { $this->xml_encoding = 'US-ASCII'; } } else { // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1 $this->xml_encoding = 'ISO-8859-1'; } $this->debug('Use encoding: ' . $this->xml_encoding . ' when creating nusoap_parser'); // parse response, get soap parser obj $parser = new nusoap_parser($data, $this->xml_encoding, '', $this->decode_utf8); // parser debug $this->debug("parser debug: \n" . $parser->getDebug()); // if fault occurred during message parsing if ($err = $parser->getError()) { $this->result = 'fault: error in msg parsing: ' . $err; $this->fault('SOAP-ENV:Client', "error in msg parsing:\n" . $err); // else successfully parsed request into soapval object } else { // get/set methodname $this->methodURI = $parser->root_struct_namespace; $this->methodname = $parser->root_struct_name; $this->debug('methodname: ' . $this->methodname . ' methodURI: ' . $this->methodURI); $this->debug('calling parser->get_soapbody()'); $this->methodparams = $parser->get_soapbody(); // get SOAP headers $this->requestHeaders = $parser->getHeaders(); // get SOAP Header $this->requestHeader = $parser->get_soapheader(); // add document for doclit support $this->document = $parser->document; } }
[ "function", "parseRequest", "(", "$", "headers", ",", "$", "data", ")", "{", "$", "this", "->", "debug", "(", "'Entering parseRequest() for data of length '", ".", "strlen", "(", "$", "data", ")", ".", "' headers:'", ")", ";", "$", "this", "->", "appendDebug", "(", "$", "this", "->", "varDump", "(", "$", "headers", ")", ")", ";", "if", "(", "!", "isset", "(", "$", "headers", "[", "'content-type'", "]", ")", ")", "{", "$", "this", "->", "setError", "(", "'Request not of type text/xml (no content-type header)'", ")", ";", "return", "FALSE", ";", "}", "if", "(", "!", "strstr", "(", "$", "headers", "[", "'content-type'", "]", ",", "'text/xml'", ")", ")", "{", "$", "this", "->", "setError", "(", "'Request not of type text/xml'", ")", ";", "return", "FALSE", ";", "}", "if", "(", "strpos", "(", "$", "headers", "[", "'content-type'", "]", ",", "'='", ")", ")", "{", "$", "enc", "=", "str_replace", "(", "'\"'", ",", "''", ",", "substr", "(", "strstr", "(", "$", "headers", "[", "\"content-type\"", "]", ",", "'='", ")", ",", "1", ")", ")", ";", "$", "this", "->", "debug", "(", "'Got response encoding: '", ".", "$", "enc", ")", ";", "if", "(", "preg_match", "(", "'/^(ISO-8859-1|US-ASCII|UTF-8)$/i'", ",", "$", "enc", ")", ")", "{", "$", "this", "->", "xml_encoding", "=", "strtoupper", "(", "$", "enc", ")", ";", "}", "else", "{", "$", "this", "->", "xml_encoding", "=", "'US-ASCII'", ";", "}", "}", "else", "{", "// should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1", "$", "this", "->", "xml_encoding", "=", "'ISO-8859-1'", ";", "}", "$", "this", "->", "debug", "(", "'Use encoding: '", ".", "$", "this", "->", "xml_encoding", ".", "' when creating nusoap_parser'", ")", ";", "// parse response, get soap parser obj", "$", "parser", "=", "new", "nusoap_parser", "(", "$", "data", ",", "$", "this", "->", "xml_encoding", ",", "''", ",", "$", "this", "->", "decode_utf8", ")", ";", "// parser debug", "$", "this", "->", "debug", "(", "\"parser debug: \\n\"", ".", "$", "parser", "->", "getDebug", "(", ")", ")", ";", "// if fault occurred during message parsing", "if", "(", "$", "err", "=", "$", "parser", "->", "getError", "(", ")", ")", "{", "$", "this", "->", "result", "=", "'fault: error in msg parsing: '", ".", "$", "err", ";", "$", "this", "->", "fault", "(", "'SOAP-ENV:Client'", ",", "\"error in msg parsing:\\n\"", ".", "$", "err", ")", ";", "// else successfully parsed request into soapval object", "}", "else", "{", "// get/set methodname", "$", "this", "->", "methodURI", "=", "$", "parser", "->", "root_struct_namespace", ";", "$", "this", "->", "methodname", "=", "$", "parser", "->", "root_struct_name", ";", "$", "this", "->", "debug", "(", "'methodname: '", ".", "$", "this", "->", "methodname", ".", "' methodURI: '", ".", "$", "this", "->", "methodURI", ")", ";", "$", "this", "->", "debug", "(", "'calling parser->get_soapbody()'", ")", ";", "$", "this", "->", "methodparams", "=", "$", "parser", "->", "get_soapbody", "(", ")", ";", "// get SOAP headers", "$", "this", "->", "requestHeaders", "=", "$", "parser", "->", "getHeaders", "(", ")", ";", "// get SOAP Header", "$", "this", "->", "requestHeader", "=", "$", "parser", "->", "get_soapheader", "(", ")", ";", "// add document for doclit support", "$", "this", "->", "document", "=", "$", "parser", "->", "document", ";", "}", "}" ]
processes SOAP message received from client @param array $headers The HTTP headers @param string $data unprocessed request data from client @return mixed value of the message, decoded into a PHP type @access private
[ "processes", "SOAP", "message", "received", "from", "client" ]
train
https://github.com/nguyenanhung/nusoap/blob/a9b4d98f4f3fe748f8e5d9f8091dfc53585d2556/src-fix/nusoap.php#L4570-L4620
nguyenanhung/nusoap
src-fix/nusoap.php
nusoap_server.add_to_map
function add_to_map($methodname, $in, $out) { $this->operations[$methodname] = ['name' => $methodname, 'in' => $in, 'out' => $out]; }
php
function add_to_map($methodname, $in, $out) { $this->operations[$methodname] = ['name' => $methodname, 'in' => $in, 'out' => $out]; }
[ "function", "add_to_map", "(", "$", "methodname", ",", "$", "in", ",", "$", "out", ")", "{", "$", "this", "->", "operations", "[", "$", "methodname", "]", "=", "[", "'name'", "=>", "$", "methodname", ",", "'in'", "=>", "$", "in", ",", "'out'", "=>", "$", "out", "]", ";", "}" ]
add a method to the dispatch map (this has been replaced by the register method) @param string $methodname @param string $in array of input values @param string $out array of output values @access public @deprecated
[ "add", "a", "method", "to", "the", "dispatch", "map", "(", "this", "has", "been", "replaced", "by", "the", "register", "method", ")" ]
train
https://github.com/nguyenanhung/nusoap/blob/a9b4d98f4f3fe748f8e5d9f8091dfc53585d2556/src-fix/nusoap.php#L4672-L4675
nguyenanhung/nusoap
src-fix/nusoap.php
nusoap_server.register
function register( $name, $in = [], $out = [], $namespace = FALSE, $soapaction = FALSE, $style = FALSE, $use = FALSE, $documentation = '', $encodingStyle = '' ) { global $HTTP_SERVER_VARS; if ($this->externalWSDLURL) { die('You cannot bind to an external WSDL file, and register methods outside of it! Please choose either WSDL or no WSDL.'); } if (!$name) { die('You must specify a name when you register an operation'); } if (!is_array($in)) { die('You must provide an array for operation inputs'); } if (!is_array($out)) { die('You must provide an array for operation outputs'); } if (FALSE == $namespace) { } if (FALSE == $soapaction) { if (isset($_SERVER)) { $SERVER_NAME = $_SERVER['SERVER_NAME']; $SCRIPT_NAME = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME']; $HTTPS = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : (isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off'); } elseif (isset($HTTP_SERVER_VARS)) { $SERVER_NAME = $HTTP_SERVER_VARS['SERVER_NAME']; $SCRIPT_NAME = isset($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : $HTTP_SERVER_VARS['SCRIPT_NAME']; $HTTPS = isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off'; } else { $this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available"); } if ($HTTPS == '1' || $HTTPS == 'on') { $SCHEME = 'https'; } else { $SCHEME = 'http'; } $soapaction = "$SCHEME://$SERVER_NAME$SCRIPT_NAME/$name"; } if (FALSE == $style) { $style = "rpc"; } if (FALSE == $use) { $use = "encoded"; } if ($use == 'encoded' && $encodingStyle == '') { $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/'; } $this->operations[$name] = [ 'name' => $name, 'in' => $in, 'out' => $out, 'namespace' => $namespace, 'soapaction' => $soapaction, 'style' => $style]; if ($this->wsdl) { $this->wsdl->addOperation($name, $in, $out, $namespace, $soapaction, $style, $use, $documentation, $encodingStyle); } return TRUE; }
php
function register( $name, $in = [], $out = [], $namespace = FALSE, $soapaction = FALSE, $style = FALSE, $use = FALSE, $documentation = '', $encodingStyle = '' ) { global $HTTP_SERVER_VARS; if ($this->externalWSDLURL) { die('You cannot bind to an external WSDL file, and register methods outside of it! Please choose either WSDL or no WSDL.'); } if (!$name) { die('You must specify a name when you register an operation'); } if (!is_array($in)) { die('You must provide an array for operation inputs'); } if (!is_array($out)) { die('You must provide an array for operation outputs'); } if (FALSE == $namespace) { } if (FALSE == $soapaction) { if (isset($_SERVER)) { $SERVER_NAME = $_SERVER['SERVER_NAME']; $SCRIPT_NAME = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME']; $HTTPS = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : (isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off'); } elseif (isset($HTTP_SERVER_VARS)) { $SERVER_NAME = $HTTP_SERVER_VARS['SERVER_NAME']; $SCRIPT_NAME = isset($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : $HTTP_SERVER_VARS['SCRIPT_NAME']; $HTTPS = isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off'; } else { $this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available"); } if ($HTTPS == '1' || $HTTPS == 'on') { $SCHEME = 'https'; } else { $SCHEME = 'http'; } $soapaction = "$SCHEME://$SERVER_NAME$SCRIPT_NAME/$name"; } if (FALSE == $style) { $style = "rpc"; } if (FALSE == $use) { $use = "encoded"; } if ($use == 'encoded' && $encodingStyle == '') { $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/'; } $this->operations[$name] = [ 'name' => $name, 'in' => $in, 'out' => $out, 'namespace' => $namespace, 'soapaction' => $soapaction, 'style' => $style]; if ($this->wsdl) { $this->wsdl->addOperation($name, $in, $out, $namespace, $soapaction, $style, $use, $documentation, $encodingStyle); } return TRUE; }
[ "function", "register", "(", "$", "name", ",", "$", "in", "=", "[", "]", ",", "$", "out", "=", "[", "]", ",", "$", "namespace", "=", "FALSE", ",", "$", "soapaction", "=", "FALSE", ",", "$", "style", "=", "FALSE", ",", "$", "use", "=", "FALSE", ",", "$", "documentation", "=", "''", ",", "$", "encodingStyle", "=", "''", ")", "{", "global", "$", "HTTP_SERVER_VARS", ";", "if", "(", "$", "this", "->", "externalWSDLURL", ")", "{", "die", "(", "'You cannot bind to an external WSDL file, and register methods outside of it! Please choose either WSDL or no WSDL.'", ")", ";", "}", "if", "(", "!", "$", "name", ")", "{", "die", "(", "'You must specify a name when you register an operation'", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "in", ")", ")", "{", "die", "(", "'You must provide an array for operation inputs'", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "out", ")", ")", "{", "die", "(", "'You must provide an array for operation outputs'", ")", ";", "}", "if", "(", "FALSE", "==", "$", "namespace", ")", "{", "}", "if", "(", "FALSE", "==", "$", "soapaction", ")", "{", "if", "(", "isset", "(", "$", "_SERVER", ")", ")", "{", "$", "SERVER_NAME", "=", "$", "_SERVER", "[", "'SERVER_NAME'", "]", ";", "$", "SCRIPT_NAME", "=", "isset", "(", "$", "_SERVER", "[", "'PHP_SELF'", "]", ")", "?", "$", "_SERVER", "[", "'PHP_SELF'", "]", ":", "$", "_SERVER", "[", "'SCRIPT_NAME'", "]", ";", "$", "HTTPS", "=", "isset", "(", "$", "_SERVER", "[", "'HTTPS'", "]", ")", "?", "$", "_SERVER", "[", "'HTTPS'", "]", ":", "(", "isset", "(", "$", "HTTP_SERVER_VARS", "[", "'HTTPS'", "]", ")", "?", "$", "HTTP_SERVER_VARS", "[", "'HTTPS'", "]", ":", "'off'", ")", ";", "}", "elseif", "(", "isset", "(", "$", "HTTP_SERVER_VARS", ")", ")", "{", "$", "SERVER_NAME", "=", "$", "HTTP_SERVER_VARS", "[", "'SERVER_NAME'", "]", ";", "$", "SCRIPT_NAME", "=", "isset", "(", "$", "HTTP_SERVER_VARS", "[", "'PHP_SELF'", "]", ")", "?", "$", "HTTP_SERVER_VARS", "[", "'PHP_SELF'", "]", ":", "$", "HTTP_SERVER_VARS", "[", "'SCRIPT_NAME'", "]", ";", "$", "HTTPS", "=", "isset", "(", "$", "HTTP_SERVER_VARS", "[", "'HTTPS'", "]", ")", "?", "$", "HTTP_SERVER_VARS", "[", "'HTTPS'", "]", ":", "'off'", ";", "}", "else", "{", "$", "this", "->", "setError", "(", "\"Neither _SERVER nor HTTP_SERVER_VARS is available\"", ")", ";", "}", "if", "(", "$", "HTTPS", "==", "'1'", "||", "$", "HTTPS", "==", "'on'", ")", "{", "$", "SCHEME", "=", "'https'", ";", "}", "else", "{", "$", "SCHEME", "=", "'http'", ";", "}", "$", "soapaction", "=", "\"$SCHEME://$SERVER_NAME$SCRIPT_NAME/$name\"", ";", "}", "if", "(", "FALSE", "==", "$", "style", ")", "{", "$", "style", "=", "\"rpc\"", ";", "}", "if", "(", "FALSE", "==", "$", "use", ")", "{", "$", "use", "=", "\"encoded\"", ";", "}", "if", "(", "$", "use", "==", "'encoded'", "&&", "$", "encodingStyle", "==", "''", ")", "{", "$", "encodingStyle", "=", "'http://schemas.xmlsoap.org/soap/encoding/'", ";", "}", "$", "this", "->", "operations", "[", "$", "name", "]", "=", "[", "'name'", "=>", "$", "name", ",", "'in'", "=>", "$", "in", ",", "'out'", "=>", "$", "out", ",", "'namespace'", "=>", "$", "namespace", ",", "'soapaction'", "=>", "$", "soapaction", ",", "'style'", "=>", "$", "style", "]", ";", "if", "(", "$", "this", "->", "wsdl", ")", "{", "$", "this", "->", "wsdl", "->", "addOperation", "(", "$", "name", ",", "$", "in", ",", "$", "out", ",", "$", "namespace", ",", "$", "soapaction", ",", "$", "style", ",", "$", "use", ",", "$", "documentation", ",", "$", "encodingStyle", ")", ";", "}", "return", "TRUE", ";", "}" ]
register a service function with the server @param string $name the name of the PHP function, class.method or class..method @param array $in assoc array of input values: key = param name, value = param type @param array $out assoc array of output values: key = param name, value = param type @param mixed $namespace the element namespace for the method or false @param mixed $soapaction the soapaction for the method or false @param mixed $style optional (rpc|document) or false Note: when 'document' is specified, parameter and return wrappers are created for you automatically @param mixed $use optional (encoded|literal) or false @param string $documentation optional Description to include in WSDL @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded) @access public
[ "register", "a", "service", "function", "with", "the", "server" ]
train
https://github.com/nguyenanhung/nusoap/blob/a9b4d98f4f3fe748f8e5d9f8091dfc53585d2556/src-fix/nusoap.php#L4693-L4754
nguyenanhung/nusoap
src-fix/nusoap.php
nusoap_server.configureWSDL
function configureWSDL( $serviceName, $namespace = FALSE, $endpoint = FALSE, $style = 'rpc', $transport = 'http://schemas.xmlsoap.org/soap/http', $schemaTargetNamespace = FALSE ) { global $HTTP_SERVER_VARS; if (isset($_SERVER)) { $SERVER_NAME = $_SERVER['SERVER_NAME']; $SERVER_PORT = $_SERVER['SERVER_PORT']; $SCRIPT_NAME = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME']; $HTTPS = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : (isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off'); } elseif (isset($HTTP_SERVER_VARS)) { $SERVER_NAME = $HTTP_SERVER_VARS['SERVER_NAME']; $SERVER_PORT = $HTTP_SERVER_VARS['SERVER_PORT']; $SCRIPT_NAME = isset($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : $HTTP_SERVER_VARS['SCRIPT_NAME']; $HTTPS = isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off'; } else { $this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available"); } // If server name has port number attached then strip it (else port number gets duplicated in WSDL output) (occurred using lighttpd and FastCGI) $colon = strpos($SERVER_NAME, ":"); if ($colon) { $SERVER_NAME = substr($SERVER_NAME, 0, $colon); } if ($SERVER_PORT == 80) { $SERVER_PORT = ''; } else { $SERVER_PORT = ':' . $SERVER_PORT; } if (FALSE == $namespace) { $namespace = "http://$SERVER_NAME/soap/$serviceName"; } if (FALSE == $endpoint) { if ($HTTPS == '1' || $HTTPS == 'on') { $SCHEME = 'https'; } else { $SCHEME = 'http'; } $endpoint = "$SCHEME://$SERVER_NAME$SERVER_PORT$SCRIPT_NAME"; } if (FALSE == $schemaTargetNamespace) { $schemaTargetNamespace = $namespace; } $this->wsdl = new wsdl; $this->wsdl->serviceName = $serviceName; $this->wsdl->endpoint = $endpoint; $this->wsdl->namespaces['tns'] = $namespace; $this->wsdl->namespaces['soap'] = 'http://schemas.xmlsoap.org/wsdl/soap/'; $this->wsdl->namespaces['wsdl'] = 'http://schemas.xmlsoap.org/wsdl/'; if ($schemaTargetNamespace != $namespace) { $this->wsdl->namespaces['types'] = $schemaTargetNamespace; } $this->wsdl->schemas[$schemaTargetNamespace][0] = new nusoap_xmlschema('', '', $this->wsdl->namespaces); if ($style == 'document') { $this->wsdl->schemas[$schemaTargetNamespace][0]->schemaInfo['elementFormDefault'] = 'qualified'; } $this->wsdl->schemas[$schemaTargetNamespace][0]->schemaTargetNamespace = $schemaTargetNamespace; $this->wsdl->schemas[$schemaTargetNamespace][0]->imports['http://schemas.xmlsoap.org/soap/encoding/'][0] = ['location' => '', 'loaded' => TRUE]; $this->wsdl->schemas[$schemaTargetNamespace][0]->imports['http://schemas.xmlsoap.org/wsdl/'][0] = ['location' => '', 'loaded' => TRUE]; $this->wsdl->bindings[$serviceName . 'Binding'] = [ 'name' => $serviceName . 'Binding', 'style' => $style, 'transport' => $transport, 'portType' => $serviceName . 'PortType']; $this->wsdl->ports[$serviceName . 'Port'] = [ 'binding' => $serviceName . 'Binding', 'location' => $endpoint, 'bindingType' => 'http://schemas.xmlsoap.org/wsdl/soap/']; }
php
function configureWSDL( $serviceName, $namespace = FALSE, $endpoint = FALSE, $style = 'rpc', $transport = 'http://schemas.xmlsoap.org/soap/http', $schemaTargetNamespace = FALSE ) { global $HTTP_SERVER_VARS; if (isset($_SERVER)) { $SERVER_NAME = $_SERVER['SERVER_NAME']; $SERVER_PORT = $_SERVER['SERVER_PORT']; $SCRIPT_NAME = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME']; $HTTPS = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : (isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off'); } elseif (isset($HTTP_SERVER_VARS)) { $SERVER_NAME = $HTTP_SERVER_VARS['SERVER_NAME']; $SERVER_PORT = $HTTP_SERVER_VARS['SERVER_PORT']; $SCRIPT_NAME = isset($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : $HTTP_SERVER_VARS['SCRIPT_NAME']; $HTTPS = isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off'; } else { $this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available"); } // If server name has port number attached then strip it (else port number gets duplicated in WSDL output) (occurred using lighttpd and FastCGI) $colon = strpos($SERVER_NAME, ":"); if ($colon) { $SERVER_NAME = substr($SERVER_NAME, 0, $colon); } if ($SERVER_PORT == 80) { $SERVER_PORT = ''; } else { $SERVER_PORT = ':' . $SERVER_PORT; } if (FALSE == $namespace) { $namespace = "http://$SERVER_NAME/soap/$serviceName"; } if (FALSE == $endpoint) { if ($HTTPS == '1' || $HTTPS == 'on') { $SCHEME = 'https'; } else { $SCHEME = 'http'; } $endpoint = "$SCHEME://$SERVER_NAME$SERVER_PORT$SCRIPT_NAME"; } if (FALSE == $schemaTargetNamespace) { $schemaTargetNamespace = $namespace; } $this->wsdl = new wsdl; $this->wsdl->serviceName = $serviceName; $this->wsdl->endpoint = $endpoint; $this->wsdl->namespaces['tns'] = $namespace; $this->wsdl->namespaces['soap'] = 'http://schemas.xmlsoap.org/wsdl/soap/'; $this->wsdl->namespaces['wsdl'] = 'http://schemas.xmlsoap.org/wsdl/'; if ($schemaTargetNamespace != $namespace) { $this->wsdl->namespaces['types'] = $schemaTargetNamespace; } $this->wsdl->schemas[$schemaTargetNamespace][0] = new nusoap_xmlschema('', '', $this->wsdl->namespaces); if ($style == 'document') { $this->wsdl->schemas[$schemaTargetNamespace][0]->schemaInfo['elementFormDefault'] = 'qualified'; } $this->wsdl->schemas[$schemaTargetNamespace][0]->schemaTargetNamespace = $schemaTargetNamespace; $this->wsdl->schemas[$schemaTargetNamespace][0]->imports['http://schemas.xmlsoap.org/soap/encoding/'][0] = ['location' => '', 'loaded' => TRUE]; $this->wsdl->schemas[$schemaTargetNamespace][0]->imports['http://schemas.xmlsoap.org/wsdl/'][0] = ['location' => '', 'loaded' => TRUE]; $this->wsdl->bindings[$serviceName . 'Binding'] = [ 'name' => $serviceName . 'Binding', 'style' => $style, 'transport' => $transport, 'portType' => $serviceName . 'PortType']; $this->wsdl->ports[$serviceName . 'Port'] = [ 'binding' => $serviceName . 'Binding', 'location' => $endpoint, 'bindingType' => 'http://schemas.xmlsoap.org/wsdl/soap/']; }
[ "function", "configureWSDL", "(", "$", "serviceName", ",", "$", "namespace", "=", "FALSE", ",", "$", "endpoint", "=", "FALSE", ",", "$", "style", "=", "'rpc'", ",", "$", "transport", "=", "'http://schemas.xmlsoap.org/soap/http'", ",", "$", "schemaTargetNamespace", "=", "FALSE", ")", "{", "global", "$", "HTTP_SERVER_VARS", ";", "if", "(", "isset", "(", "$", "_SERVER", ")", ")", "{", "$", "SERVER_NAME", "=", "$", "_SERVER", "[", "'SERVER_NAME'", "]", ";", "$", "SERVER_PORT", "=", "$", "_SERVER", "[", "'SERVER_PORT'", "]", ";", "$", "SCRIPT_NAME", "=", "isset", "(", "$", "_SERVER", "[", "'PHP_SELF'", "]", ")", "?", "$", "_SERVER", "[", "'PHP_SELF'", "]", ":", "$", "_SERVER", "[", "'SCRIPT_NAME'", "]", ";", "$", "HTTPS", "=", "isset", "(", "$", "_SERVER", "[", "'HTTPS'", "]", ")", "?", "$", "_SERVER", "[", "'HTTPS'", "]", ":", "(", "isset", "(", "$", "HTTP_SERVER_VARS", "[", "'HTTPS'", "]", ")", "?", "$", "HTTP_SERVER_VARS", "[", "'HTTPS'", "]", ":", "'off'", ")", ";", "}", "elseif", "(", "isset", "(", "$", "HTTP_SERVER_VARS", ")", ")", "{", "$", "SERVER_NAME", "=", "$", "HTTP_SERVER_VARS", "[", "'SERVER_NAME'", "]", ";", "$", "SERVER_PORT", "=", "$", "HTTP_SERVER_VARS", "[", "'SERVER_PORT'", "]", ";", "$", "SCRIPT_NAME", "=", "isset", "(", "$", "HTTP_SERVER_VARS", "[", "'PHP_SELF'", "]", ")", "?", "$", "HTTP_SERVER_VARS", "[", "'PHP_SELF'", "]", ":", "$", "HTTP_SERVER_VARS", "[", "'SCRIPT_NAME'", "]", ";", "$", "HTTPS", "=", "isset", "(", "$", "HTTP_SERVER_VARS", "[", "'HTTPS'", "]", ")", "?", "$", "HTTP_SERVER_VARS", "[", "'HTTPS'", "]", ":", "'off'", ";", "}", "else", "{", "$", "this", "->", "setError", "(", "\"Neither _SERVER nor HTTP_SERVER_VARS is available\"", ")", ";", "}", "// If server name has port number attached then strip it (else port number gets duplicated in WSDL output) (occurred using lighttpd and FastCGI)", "$", "colon", "=", "strpos", "(", "$", "SERVER_NAME", ",", "\":\"", ")", ";", "if", "(", "$", "colon", ")", "{", "$", "SERVER_NAME", "=", "substr", "(", "$", "SERVER_NAME", ",", "0", ",", "$", "colon", ")", ";", "}", "if", "(", "$", "SERVER_PORT", "==", "80", ")", "{", "$", "SERVER_PORT", "=", "''", ";", "}", "else", "{", "$", "SERVER_PORT", "=", "':'", ".", "$", "SERVER_PORT", ";", "}", "if", "(", "FALSE", "==", "$", "namespace", ")", "{", "$", "namespace", "=", "\"http://$SERVER_NAME/soap/$serviceName\"", ";", "}", "if", "(", "FALSE", "==", "$", "endpoint", ")", "{", "if", "(", "$", "HTTPS", "==", "'1'", "||", "$", "HTTPS", "==", "'on'", ")", "{", "$", "SCHEME", "=", "'https'", ";", "}", "else", "{", "$", "SCHEME", "=", "'http'", ";", "}", "$", "endpoint", "=", "\"$SCHEME://$SERVER_NAME$SERVER_PORT$SCRIPT_NAME\"", ";", "}", "if", "(", "FALSE", "==", "$", "schemaTargetNamespace", ")", "{", "$", "schemaTargetNamespace", "=", "$", "namespace", ";", "}", "$", "this", "->", "wsdl", "=", "new", "wsdl", ";", "$", "this", "->", "wsdl", "->", "serviceName", "=", "$", "serviceName", ";", "$", "this", "->", "wsdl", "->", "endpoint", "=", "$", "endpoint", ";", "$", "this", "->", "wsdl", "->", "namespaces", "[", "'tns'", "]", "=", "$", "namespace", ";", "$", "this", "->", "wsdl", "->", "namespaces", "[", "'soap'", "]", "=", "'http://schemas.xmlsoap.org/wsdl/soap/'", ";", "$", "this", "->", "wsdl", "->", "namespaces", "[", "'wsdl'", "]", "=", "'http://schemas.xmlsoap.org/wsdl/'", ";", "if", "(", "$", "schemaTargetNamespace", "!=", "$", "namespace", ")", "{", "$", "this", "->", "wsdl", "->", "namespaces", "[", "'types'", "]", "=", "$", "schemaTargetNamespace", ";", "}", "$", "this", "->", "wsdl", "->", "schemas", "[", "$", "schemaTargetNamespace", "]", "[", "0", "]", "=", "new", "nusoap_xmlschema", "(", "''", ",", "''", ",", "$", "this", "->", "wsdl", "->", "namespaces", ")", ";", "if", "(", "$", "style", "==", "'document'", ")", "{", "$", "this", "->", "wsdl", "->", "schemas", "[", "$", "schemaTargetNamespace", "]", "[", "0", "]", "->", "schemaInfo", "[", "'elementFormDefault'", "]", "=", "'qualified'", ";", "}", "$", "this", "->", "wsdl", "->", "schemas", "[", "$", "schemaTargetNamespace", "]", "[", "0", "]", "->", "schemaTargetNamespace", "=", "$", "schemaTargetNamespace", ";", "$", "this", "->", "wsdl", "->", "schemas", "[", "$", "schemaTargetNamespace", "]", "[", "0", "]", "->", "imports", "[", "'http://schemas.xmlsoap.org/soap/encoding/'", "]", "[", "0", "]", "=", "[", "'location'", "=>", "''", ",", "'loaded'", "=>", "TRUE", "]", ";", "$", "this", "->", "wsdl", "->", "schemas", "[", "$", "schemaTargetNamespace", "]", "[", "0", "]", "->", "imports", "[", "'http://schemas.xmlsoap.org/wsdl/'", "]", "[", "0", "]", "=", "[", "'location'", "=>", "''", ",", "'loaded'", "=>", "TRUE", "]", ";", "$", "this", "->", "wsdl", "->", "bindings", "[", "$", "serviceName", ".", "'Binding'", "]", "=", "[", "'name'", "=>", "$", "serviceName", ".", "'Binding'", ",", "'style'", "=>", "$", "style", ",", "'transport'", "=>", "$", "transport", ",", "'portType'", "=>", "$", "serviceName", ".", "'PortType'", "]", ";", "$", "this", "->", "wsdl", "->", "ports", "[", "$", "serviceName", ".", "'Port'", "]", "=", "[", "'binding'", "=>", "$", "serviceName", ".", "'Binding'", ",", "'location'", "=>", "$", "endpoint", ",", "'bindingType'", "=>", "'http://schemas.xmlsoap.org/wsdl/soap/'", "]", ";", "}" ]
Sets up wsdl object. Acts as a flag to enable internal WSDL generation @param string $serviceName , name of the service @param mixed $namespace optional 'tns' service namespace or false @param mixed $endpoint optional URL of service endpoint or false @param string $style optional (rpc|document) WSDL style (also specified by operation) @param string $transport optional SOAP transport @param mixed $schemaTargetNamespace optional 'types' targetNamespace for service schema or false
[ "Sets", "up", "wsdl", "object", ".", "Acts", "as", "a", "flag", "to", "enable", "internal", "WSDL", "generation" ]
train
https://github.com/nguyenanhung/nusoap/blob/a9b4d98f4f3fe748f8e5d9f8091dfc53585d2556/src-fix/nusoap.php#L4787-L4860
nguyenanhung/nusoap
src-fix/nusoap.php
wsdl.getOperations
function getOperations($portName = '', $bindingType = 'soap') { $ops = []; if ($bindingType == 'soap') { $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/'; } elseif ($bindingType == 'soap12') { $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/'; } else { $this->debug("getOperations bindingType $bindingType may not be supported"); } $this->debug("getOperations for port '$portName' bindingType $bindingType"); // loop thru ports foreach ($this->ports as $port => $portData) { $this->debug("getOperations checking port $port bindingType " . $portData['bindingType']); if ($portName == '' || $port == $portName) { // binding type of port matches parameter if ($portData['bindingType'] == $bindingType) { $this->debug("getOperations found port $port bindingType $bindingType"); //$this->debug("port data: " . $this->varDump($portData)); //$this->debug("bindings: " . $this->varDump($this->bindings[ $portData['binding'] ])); // merge bindings if (isset($this->bindings[$portData['binding']]['operations'])) { $ops = array_merge($ops, $this->bindings[$portData['binding']]['operations']); } } } } if (count($ops) == 0) { $this->debug("getOperations found no operations for port '$portName' bindingType $bindingType"); } return $ops; }
php
function getOperations($portName = '', $bindingType = 'soap') { $ops = []; if ($bindingType == 'soap') { $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/'; } elseif ($bindingType == 'soap12') { $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/'; } else { $this->debug("getOperations bindingType $bindingType may not be supported"); } $this->debug("getOperations for port '$portName' bindingType $bindingType"); // loop thru ports foreach ($this->ports as $port => $portData) { $this->debug("getOperations checking port $port bindingType " . $portData['bindingType']); if ($portName == '' || $port == $portName) { // binding type of port matches parameter if ($portData['bindingType'] == $bindingType) { $this->debug("getOperations found port $port bindingType $bindingType"); //$this->debug("port data: " . $this->varDump($portData)); //$this->debug("bindings: " . $this->varDump($this->bindings[ $portData['binding'] ])); // merge bindings if (isset($this->bindings[$portData['binding']]['operations'])) { $ops = array_merge($ops, $this->bindings[$portData['binding']]['operations']); } } } } if (count($ops) == 0) { $this->debug("getOperations found no operations for port '$portName' bindingType $bindingType"); } return $ops; }
[ "function", "getOperations", "(", "$", "portName", "=", "''", ",", "$", "bindingType", "=", "'soap'", ")", "{", "$", "ops", "=", "[", "]", ";", "if", "(", "$", "bindingType", "==", "'soap'", ")", "{", "$", "bindingType", "=", "'http://schemas.xmlsoap.org/wsdl/soap/'", ";", "}", "elseif", "(", "$", "bindingType", "==", "'soap12'", ")", "{", "$", "bindingType", "=", "'http://schemas.xmlsoap.org/wsdl/soap12/'", ";", "}", "else", "{", "$", "this", "->", "debug", "(", "\"getOperations bindingType $bindingType may not be supported\"", ")", ";", "}", "$", "this", "->", "debug", "(", "\"getOperations for port '$portName' bindingType $bindingType\"", ")", ";", "// loop thru ports", "foreach", "(", "$", "this", "->", "ports", "as", "$", "port", "=>", "$", "portData", ")", "{", "$", "this", "->", "debug", "(", "\"getOperations checking port $port bindingType \"", ".", "$", "portData", "[", "'bindingType'", "]", ")", ";", "if", "(", "$", "portName", "==", "''", "||", "$", "port", "==", "$", "portName", ")", "{", "// binding type of port matches parameter", "if", "(", "$", "portData", "[", "'bindingType'", "]", "==", "$", "bindingType", ")", "{", "$", "this", "->", "debug", "(", "\"getOperations found port $port bindingType $bindingType\"", ")", ";", "//$this->debug(\"port data: \" . $this->varDump($portData));", "//$this->debug(\"bindings: \" . $this->varDump($this->bindings[ $portData['binding'] ]));", "// merge bindings", "if", "(", "isset", "(", "$", "this", "->", "bindings", "[", "$", "portData", "[", "'binding'", "]", "]", "[", "'operations'", "]", ")", ")", "{", "$", "ops", "=", "array_merge", "(", "$", "ops", ",", "$", "this", "->", "bindings", "[", "$", "portData", "[", "'binding'", "]", "]", "[", "'operations'", "]", ")", ";", "}", "}", "}", "}", "if", "(", "count", "(", "$", "ops", ")", "==", "0", ")", "{", "$", "this", "->", "debug", "(", "\"getOperations found no operations for port '$portName' bindingType $bindingType\"", ")", ";", "}", "return", "$", "ops", ";", "}" ]
returns an assoc array of operation names => operation data @param string $portName WSDL port name @param string $bindingType eg: soap, smtp, dime (only soap and soap12 are currently supported) @return array @access public
[ "returns", "an", "assoc", "array", "of", "operation", "names", "=", ">", "operation", "data" ]
train
https://github.com/nguyenanhung/nusoap/blob/a9b4d98f4f3fe748f8e5d9f8091dfc53585d2556/src-fix/nusoap.php#L5481-L5513
nguyenanhung/nusoap
src-fix/nusoap.php
wsdl.getOperationData
function getOperationData($operation, $bindingType = 'soap') { if ($bindingType == 'soap') { $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/'; } elseif ($bindingType == 'soap12') { $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/'; } // loop thru ports foreach ($this->ports as $port => $portData) { // binding type of port matches parameter if ($portData['bindingType'] == $bindingType) { // get binding //foreach($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) { foreach (array_keys($this->bindings[$portData['binding']]['operations']) as $bOperation) { // note that we could/should also check the namespace here if ($operation == $bOperation) { $opData = $this->bindings[$portData['binding']]['operations'][$operation]; return $opData; } } } } }
php
function getOperationData($operation, $bindingType = 'soap') { if ($bindingType == 'soap') { $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/'; } elseif ($bindingType == 'soap12') { $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/'; } // loop thru ports foreach ($this->ports as $port => $portData) { // binding type of port matches parameter if ($portData['bindingType'] == $bindingType) { // get binding //foreach($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) { foreach (array_keys($this->bindings[$portData['binding']]['operations']) as $bOperation) { // note that we could/should also check the namespace here if ($operation == $bOperation) { $opData = $this->bindings[$portData['binding']]['operations'][$operation]; return $opData; } } } } }
[ "function", "getOperationData", "(", "$", "operation", ",", "$", "bindingType", "=", "'soap'", ")", "{", "if", "(", "$", "bindingType", "==", "'soap'", ")", "{", "$", "bindingType", "=", "'http://schemas.xmlsoap.org/wsdl/soap/'", ";", "}", "elseif", "(", "$", "bindingType", "==", "'soap12'", ")", "{", "$", "bindingType", "=", "'http://schemas.xmlsoap.org/wsdl/soap12/'", ";", "}", "// loop thru ports", "foreach", "(", "$", "this", "->", "ports", "as", "$", "port", "=>", "$", "portData", ")", "{", "// binding type of port matches parameter", "if", "(", "$", "portData", "[", "'bindingType'", "]", "==", "$", "bindingType", ")", "{", "// get binding", "//foreach($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) {", "foreach", "(", "array_keys", "(", "$", "this", "->", "bindings", "[", "$", "portData", "[", "'binding'", "]", "]", "[", "'operations'", "]", ")", "as", "$", "bOperation", ")", "{", "// note that we could/should also check the namespace here", "if", "(", "$", "operation", "==", "$", "bOperation", ")", "{", "$", "opData", "=", "$", "this", "->", "bindings", "[", "$", "portData", "[", "'binding'", "]", "]", "[", "'operations'", "]", "[", "$", "operation", "]", ";", "return", "$", "opData", ";", "}", "}", "}", "}", "}" ]
returns an associative array of data necessary for calling an operation @param string $operation name of operation @param string $bindingType type of binding eg: soap, soap12 @return array @access public
[ "returns", "an", "associative", "array", "of", "data", "necessary", "for", "calling", "an", "operation" ]
train
https://github.com/nguyenanhung/nusoap/blob/a9b4d98f4f3fe748f8e5d9f8091dfc53585d2556/src-fix/nusoap.php#L5524-L5547
nguyenanhung/nusoap
src-fix/nusoap.php
wsdl.serializeParameters
function serializeParameters($operation, $direction, $parameters) { $this->debug("in serializeParameters: operation=$operation, direction=$direction, XMLSchemaVersion=$this->XMLSchemaVersion"); $this->appendDebug('parameters=' . $this->varDump($parameters)); if ($direction != 'input' && $direction != 'output') { $this->debug('The value of the \$direction argument needs to be either "input" or "output"'); $this->setError('The value of the \$direction argument needs to be either "input" or "output"'); return FALSE; } if (!$opData = $this->getOperationData($operation)) { $this->debug('Unable to retrieve WSDL data for operation: ' . $operation); $this->setError('Unable to retrieve WSDL data for operation: ' . $operation); return FALSE; } $this->debug('opData:'); $this->appendDebug($this->varDump($opData)); // Get encoding style for output and set to current $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/'; if (($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) { $encodingStyle = $opData['output']['encodingStyle']; $enc_style = $encodingStyle; } // set input params $xml = ''; if (isset($opData[$direction]['parts']) && sizeof($opData[$direction]['parts']) > 0) { $use = $opData[$direction]['use']; $this->debug("use=$use"); $this->debug('got ' . count($opData[$direction]['parts']) . ' part(s)'); if (is_array($parameters)) { $parametersArrayType = $this->isArraySimpleOrStruct($parameters); $this->debug('have ' . $parametersArrayType . ' parameters'); foreach ($opData[$direction]['parts'] as $name => $type) { $this->debug('serializing part "' . $name . '" of type "' . $type . '"'); // Track encoding style if (isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) { $encodingStyle = $opData[$direction]['encodingStyle']; $enc_style = $encodingStyle; } else { $enc_style = FALSE; } // NOTE: add error handling here // if serializeType returns false, then catch global error and fault if ($parametersArrayType == 'arraySimple') { $p = array_shift($parameters); $this->debug('calling serializeType w/indexed param'); $xml .= $this->serializeType($name, $type, $p, $use, $enc_style); } elseif (isset($parameters[$name])) { $this->debug('calling serializeType w/named param'); $xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style); } else { // TODO: only send nillable $this->debug('calling serializeType w/null param'); $xml .= $this->serializeType($name, $type, NULL, $use, $enc_style); } } } else { $this->debug('no parameters passed.'); } } $this->debug("serializeParameters returning: $xml"); return $xml; }
php
function serializeParameters($operation, $direction, $parameters) { $this->debug("in serializeParameters: operation=$operation, direction=$direction, XMLSchemaVersion=$this->XMLSchemaVersion"); $this->appendDebug('parameters=' . $this->varDump($parameters)); if ($direction != 'input' && $direction != 'output') { $this->debug('The value of the \$direction argument needs to be either "input" or "output"'); $this->setError('The value of the \$direction argument needs to be either "input" or "output"'); return FALSE; } if (!$opData = $this->getOperationData($operation)) { $this->debug('Unable to retrieve WSDL data for operation: ' . $operation); $this->setError('Unable to retrieve WSDL data for operation: ' . $operation); return FALSE; } $this->debug('opData:'); $this->appendDebug($this->varDump($opData)); // Get encoding style for output and set to current $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/'; if (($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) { $encodingStyle = $opData['output']['encodingStyle']; $enc_style = $encodingStyle; } // set input params $xml = ''; if (isset($opData[$direction]['parts']) && sizeof($opData[$direction]['parts']) > 0) { $use = $opData[$direction]['use']; $this->debug("use=$use"); $this->debug('got ' . count($opData[$direction]['parts']) . ' part(s)'); if (is_array($parameters)) { $parametersArrayType = $this->isArraySimpleOrStruct($parameters); $this->debug('have ' . $parametersArrayType . ' parameters'); foreach ($opData[$direction]['parts'] as $name => $type) { $this->debug('serializing part "' . $name . '" of type "' . $type . '"'); // Track encoding style if (isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) { $encodingStyle = $opData[$direction]['encodingStyle']; $enc_style = $encodingStyle; } else { $enc_style = FALSE; } // NOTE: add error handling here // if serializeType returns false, then catch global error and fault if ($parametersArrayType == 'arraySimple') { $p = array_shift($parameters); $this->debug('calling serializeType w/indexed param'); $xml .= $this->serializeType($name, $type, $p, $use, $enc_style); } elseif (isset($parameters[$name])) { $this->debug('calling serializeType w/named param'); $xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style); } else { // TODO: only send nillable $this->debug('calling serializeType w/null param'); $xml .= $this->serializeType($name, $type, NULL, $use, $enc_style); } } } else { $this->debug('no parameters passed.'); } } $this->debug("serializeParameters returning: $xml"); return $xml; }
[ "function", "serializeParameters", "(", "$", "operation", ",", "$", "direction", ",", "$", "parameters", ")", "{", "$", "this", "->", "debug", "(", "\"in serializeParameters: operation=$operation, direction=$direction, XMLSchemaVersion=$this->XMLSchemaVersion\"", ")", ";", "$", "this", "->", "appendDebug", "(", "'parameters='", ".", "$", "this", "->", "varDump", "(", "$", "parameters", ")", ")", ";", "if", "(", "$", "direction", "!=", "'input'", "&&", "$", "direction", "!=", "'output'", ")", "{", "$", "this", "->", "debug", "(", "'The value of the \\$direction argument needs to be either \"input\" or \"output\"'", ")", ";", "$", "this", "->", "setError", "(", "'The value of the \\$direction argument needs to be either \"input\" or \"output\"'", ")", ";", "return", "FALSE", ";", "}", "if", "(", "!", "$", "opData", "=", "$", "this", "->", "getOperationData", "(", "$", "operation", ")", ")", "{", "$", "this", "->", "debug", "(", "'Unable to retrieve WSDL data for operation: '", ".", "$", "operation", ")", ";", "$", "this", "->", "setError", "(", "'Unable to retrieve WSDL data for operation: '", ".", "$", "operation", ")", ";", "return", "FALSE", ";", "}", "$", "this", "->", "debug", "(", "'opData:'", ")", ";", "$", "this", "->", "appendDebug", "(", "$", "this", "->", "varDump", "(", "$", "opData", ")", ")", ";", "// Get encoding style for output and set to current", "$", "encodingStyle", "=", "'http://schemas.xmlsoap.org/soap/encoding/'", ";", "if", "(", "(", "$", "direction", "==", "'input'", ")", "&&", "isset", "(", "$", "opData", "[", "'output'", "]", "[", "'encodingStyle'", "]", ")", "&&", "(", "$", "opData", "[", "'output'", "]", "[", "'encodingStyle'", "]", "!=", "$", "encodingStyle", ")", ")", "{", "$", "encodingStyle", "=", "$", "opData", "[", "'output'", "]", "[", "'encodingStyle'", "]", ";", "$", "enc_style", "=", "$", "encodingStyle", ";", "}", "// set input params", "$", "xml", "=", "''", ";", "if", "(", "isset", "(", "$", "opData", "[", "$", "direction", "]", "[", "'parts'", "]", ")", "&&", "sizeof", "(", "$", "opData", "[", "$", "direction", "]", "[", "'parts'", "]", ")", ">", "0", ")", "{", "$", "use", "=", "$", "opData", "[", "$", "direction", "]", "[", "'use'", "]", ";", "$", "this", "->", "debug", "(", "\"use=$use\"", ")", ";", "$", "this", "->", "debug", "(", "'got '", ".", "count", "(", "$", "opData", "[", "$", "direction", "]", "[", "'parts'", "]", ")", ".", "' part(s)'", ")", ";", "if", "(", "is_array", "(", "$", "parameters", ")", ")", "{", "$", "parametersArrayType", "=", "$", "this", "->", "isArraySimpleOrStruct", "(", "$", "parameters", ")", ";", "$", "this", "->", "debug", "(", "'have '", ".", "$", "parametersArrayType", ".", "' parameters'", ")", ";", "foreach", "(", "$", "opData", "[", "$", "direction", "]", "[", "'parts'", "]", "as", "$", "name", "=>", "$", "type", ")", "{", "$", "this", "->", "debug", "(", "'serializing part \"'", ".", "$", "name", ".", "'\" of type \"'", ".", "$", "type", ".", "'\"'", ")", ";", "// Track encoding style", "if", "(", "isset", "(", "$", "opData", "[", "$", "direction", "]", "[", "'encodingStyle'", "]", ")", "&&", "$", "encodingStyle", "!=", "$", "opData", "[", "$", "direction", "]", "[", "'encodingStyle'", "]", ")", "{", "$", "encodingStyle", "=", "$", "opData", "[", "$", "direction", "]", "[", "'encodingStyle'", "]", ";", "$", "enc_style", "=", "$", "encodingStyle", ";", "}", "else", "{", "$", "enc_style", "=", "FALSE", ";", "}", "// NOTE: add error handling here", "// if serializeType returns false, then catch global error and fault", "if", "(", "$", "parametersArrayType", "==", "'arraySimple'", ")", "{", "$", "p", "=", "array_shift", "(", "$", "parameters", ")", ";", "$", "this", "->", "debug", "(", "'calling serializeType w/indexed param'", ")", ";", "$", "xml", ".=", "$", "this", "->", "serializeType", "(", "$", "name", ",", "$", "type", ",", "$", "p", ",", "$", "use", ",", "$", "enc_style", ")", ";", "}", "elseif", "(", "isset", "(", "$", "parameters", "[", "$", "name", "]", ")", ")", "{", "$", "this", "->", "debug", "(", "'calling serializeType w/named param'", ")", ";", "$", "xml", ".=", "$", "this", "->", "serializeType", "(", "$", "name", ",", "$", "type", ",", "$", "parameters", "[", "$", "name", "]", ",", "$", "use", ",", "$", "enc_style", ")", ";", "}", "else", "{", "// TODO: only send nillable", "$", "this", "->", "debug", "(", "'calling serializeType w/null param'", ")", ";", "$", "xml", ".=", "$", "this", "->", "serializeType", "(", "$", "name", ",", "$", "type", ",", "NULL", ",", "$", "use", ",", "$", "enc_style", ")", ";", "}", "}", "}", "else", "{", "$", "this", "->", "debug", "(", "'no parameters passed.'", ")", ";", "}", "}", "$", "this", "->", "debug", "(", "\"serializeParameters returning: $xml\"", ")", ";", "return", "$", "xml", ";", "}" ]
serialize a PHP value according to a WSDL message definition TODO - multi-ref serialization - validate PHP values against type definitions, return errors if invalid @param string $operation operation name @param string $direction (input|output) @param mixed $parameters parameter value(s) @return mixed parameters serialized as XML or false on error (e.g. operation not found) @access public @deprecated
[ "serialize", "a", "PHP", "value", "according", "to", "a", "WSDL", "message", "definition" ]
train
https://github.com/nguyenanhung/nusoap/blob/a9b4d98f4f3fe748f8e5d9f8091dfc53585d2556/src-fix/nusoap.php#L6134-L6202
nguyenanhung/nusoap
src-fix/nusoap.php
wsdl.serializeType
function serializeType($name, $type, $value, $use = 'encoded', $encodingStyle = FALSE, $unqualified = FALSE) { $this->debug("in serializeType: name=$name, type=$type, use=$use, encodingStyle=$encodingStyle, unqualified=" . ($unqualified ? "unqualified" : "qualified")); $this->appendDebug("value=" . $this->varDump($value)); if ($use == 'encoded' && $encodingStyle) { $encodingStyle = ' SOAP-ENV:encodingStyle="' . $encodingStyle . '"'; } // if a soapval has been supplied, let its type override the WSDL if (is_object($value) && get_class($value) == 'soapval') { if ($value->type_ns) { $type = $value->type_ns . ':' . $value->type; $forceType = TRUE; $this->debug("in serializeType: soapval overrides type to $type"); } elseif ($value->type) { $type = $value->type; $forceType = TRUE; $this->debug("in serializeType: soapval overrides type to $type"); } else { $forceType = FALSE; $this->debug("in serializeType: soapval does not override type"); } $attrs = $value->attributes; $value = $value->value; $this->debug("in serializeType: soapval overrides value to $value"); if ($attrs) { if (!is_array($value)) { $value['!'] = $value; } foreach ($attrs as $n => $v) { $value['!' . $n] = $v; } $this->debug("in serializeType: soapval provides attributes"); } } else { $forceType = FALSE; } $xml = ''; if (strpos($type, ':')) { $uqType = substr($type, strrpos($type, ':') + 1); $ns = substr($type, 0, strrpos($type, ':')); $this->debug("in serializeType: got a prefixed type: $uqType, $ns"); if ($this->getNamespaceFromPrefix($ns)) { $ns = $this->getNamespaceFromPrefix($ns); $this->debug("in serializeType: expanded prefixed type: $uqType, $ns"); } if ($ns == $this->XMLSchemaVersion || $ns == 'http://schemas.xmlsoap.org/soap/encoding/') { $this->debug('in serializeType: type namespace indicates XML Schema or SOAP Encoding type'); if ($unqualified && $use == 'literal') { $elementNS = " xmlns=\"\""; } else { $elementNS = ''; } if (is_null($value)) { if ($use == 'literal') { // TODO: depends on minOccurs $xml = "<$name$elementNS/>"; } else { // TODO: depends on nillable, which should be checked before calling this method $xml = "<$name$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>"; } $this->debug("in serializeType: returning: $xml"); return $xml; } if ($uqType == 'Array') { // JBoss/Axis does this sometimes return $this->serialize_val($value, $name, FALSE, FALSE, FALSE, FALSE, $use); } if ($uqType == 'boolean') { if ((is_string($value) && $value == 'false') || (!$value)) { $value = 'false'; } else { $value = 'true'; } } if ($uqType == 'string' && gettype($value) == 'string') { $value = $this->expandEntities($value); } if (($uqType == 'long' || $uqType == 'unsignedLong') && gettype($value) == 'double') { $value = sprintf("%.0lf", $value); } // it's a scalar // TODO: what about null/nil values? // check type isn't a custom type extending xmlschema namespace if (!$this->getTypeDef($uqType, $ns)) { if ($use == 'literal') { if ($forceType) { $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>"; } else { $xml = "<$name$elementNS>$value</$name>"; } } else { $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>"; } $this->debug("in serializeType: returning: $xml"); return $xml; } $this->debug('custom type extends XML Schema or SOAP Encoding namespace (yuck)'); } elseif ($ns == 'http://xml.apache.org/xml-soap') { $this->debug('in serializeType: appears to be Apache SOAP type'); if ($uqType == 'Map') { $tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap'); if (!$tt_prefix) { $this->debug('in serializeType: Add namespace for Apache SOAP type'); $tt_prefix = 'ns' . rand(1000, 9999); $this->namespaces[$tt_prefix] = 'http://xml.apache.org/xml-soap'; // force this to be added to usedNamespaces $tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap'); } $contents = ''; foreach ($value as $k => $v) { $this->debug("serializing map element: key $k, value $v"); $contents .= '<item>'; $contents .= $this->serialize_val($k, 'key', FALSE, FALSE, FALSE, FALSE, $use); $contents .= $this->serialize_val($v, 'value', FALSE, FALSE, FALSE, FALSE, $use); $contents .= '</item>'; } if ($use == 'literal') { if ($forceType) { $xml = "<$name xsi:type=\"" . $tt_prefix . ":$uqType\">$contents</$name>"; } else { $xml = "<$name>$contents</$name>"; } } else { $xml = "<$name xsi:type=\"" . $tt_prefix . ":$uqType\"$encodingStyle>$contents</$name>"; } $this->debug("in serializeType: returning: $xml"); return $xml; } $this->debug('in serializeType: Apache SOAP type, but only support Map'); } } else { // TODO: should the type be compared to types in XSD, and the namespace // set to XSD if the type matches? $this->debug("in serializeType: No namespace for type $type"); $ns = ''; $uqType = $type; } if (!$typeDef = $this->getTypeDef($uqType, $ns)) { $this->setError("$type ($uqType) is not a supported type."); $this->debug("in serializeType: $type ($uqType) is not a supported type."); return FALSE; } else { $this->debug("in serializeType: found typeDef"); $this->appendDebug('typeDef=' . $this->varDump($typeDef)); if (substr($uqType, -1) == '^') { $uqType = substr($uqType, 0, -1); } } if (!isset($typeDef['phpType'])) { $this->setError("$type ($uqType) has no phpType."); $this->debug("in serializeType: $type ($uqType) has no phpType."); return FALSE; } $phpType = $typeDef['phpType']; $this->debug("in serializeType: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: " . (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : '')); // if php type == struct, map value to the <all> element names if ($phpType == 'struct') { if (isset($typeDef['typeClass']) && $typeDef['typeClass'] == 'element') { $elementName = $uqType; if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) { $elementNS = " xmlns=\"$ns\""; } else { $elementNS = " xmlns=\"\""; } } else { $elementName = $name; if ($unqualified) { $elementNS = " xmlns=\"\""; } else { $elementNS = ''; } } if (is_null($value)) { if ($use == 'literal') { // TODO: depends on minOccurs and nillable $xml = "<$elementName$elementNS/>"; } else { $xml = "<$elementName$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>"; } $this->debug("in serializeType: returning: $xml"); return $xml; } if (is_object($value)) { $value = get_object_vars($value); } if (is_array($value)) { $elementAttrs = $this->serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType); if ($use == 'literal') { if ($forceType) { $xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">"; } else { $xml = "<$elementName$elementNS$elementAttrs>"; } } else { $xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>"; } if (isset($typeDef['simpleContent']) && $typeDef['simpleContent'] == 'true') { if (isset($value['!'])) { $xml .= $value['!']; $this->debug("in serializeType: serialized simpleContent for type $type"); } else { $this->debug("in serializeType: no simpleContent to serialize for type $type"); } } else { // complexContent $xml .= $this->serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use, $encodingStyle); } $xml .= "</$elementName>"; } else { $this->debug("in serializeType: phpType is struct, but value is not an array"); $this->setError("phpType is struct, but value is not an array: see debug output for details"); $xml = ''; } } elseif ($phpType == 'array') { if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) { $elementNS = " xmlns=\"$ns\""; } else { if ($unqualified) { $elementNS = " xmlns=\"\""; } else { $elementNS = ''; } } if (is_null($value)) { if ($use == 'literal') { // TODO: depends on minOccurs $xml = "<$name$elementNS/>"; } else { $xml = "<$name$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') . ":Array\" " . $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') . ':arrayType="' . $this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType'])) . ':' . $this->getLocalPart($typeDef['arrayType']) . "[0]\"/>"; } $this->debug("in serializeType: returning: $xml"); return $xml; } if (isset($typeDef['multidimensional'])) { $nv = []; foreach ($value as $v) { $cols = ',' . sizeof($v); $nv = array_merge($nv, $v); } $value = $nv; } else { $cols = ''; } if (is_array($value) && sizeof($value) >= 1) { $rows = sizeof($value); $contents = ''; foreach ($value as $k => $v) { $this->debug("serializing array element: $k, " . (is_array($v) ? "array" : $v) . " of type: $typeDef[arrayType]"); //if (strpos($typeDef['arrayType'], ':') ) { if (!in_array($typeDef['arrayType'], $this->typemap['http://www.w3.org/2001/XMLSchema'])) { $contents .= $this->serializeType('item', $typeDef['arrayType'], $v, $use); } else { $contents .= $this->serialize_val($v, 'item', $typeDef['arrayType'], NULL, $this->XMLSchemaVersion, FALSE, $use); } } } else { $rows = 0; $contents = NULL; } // TODO: for now, an empty value will be serialized as a zero element // array. Revisit this when coding the handling of null/nil values. if ($use == 'literal') { $xml = "<$name$elementNS>" . $contents . "</$name>"; } else { $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') . ':Array" ' . $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') . ':arrayType="' . $this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType'])) . ":" . $this->getLocalPart($typeDef['arrayType']) . "[$rows$cols]\">" . $contents . "</$name>"; } } elseif ($phpType == 'scalar') { if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) { $elementNS = " xmlns=\"$ns\""; } else { if ($unqualified) { $elementNS = " xmlns=\"\""; } else { $elementNS = ''; } } if ($use == 'literal') { if ($forceType) { $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>"; } else { $xml = "<$name$elementNS>$value</$name>"; } } else { $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>"; } } $this->debug("in serializeType: returning: $xml"); return $xml; }
php
function serializeType($name, $type, $value, $use = 'encoded', $encodingStyle = FALSE, $unqualified = FALSE) { $this->debug("in serializeType: name=$name, type=$type, use=$use, encodingStyle=$encodingStyle, unqualified=" . ($unqualified ? "unqualified" : "qualified")); $this->appendDebug("value=" . $this->varDump($value)); if ($use == 'encoded' && $encodingStyle) { $encodingStyle = ' SOAP-ENV:encodingStyle="' . $encodingStyle . '"'; } // if a soapval has been supplied, let its type override the WSDL if (is_object($value) && get_class($value) == 'soapval') { if ($value->type_ns) { $type = $value->type_ns . ':' . $value->type; $forceType = TRUE; $this->debug("in serializeType: soapval overrides type to $type"); } elseif ($value->type) { $type = $value->type; $forceType = TRUE; $this->debug("in serializeType: soapval overrides type to $type"); } else { $forceType = FALSE; $this->debug("in serializeType: soapval does not override type"); } $attrs = $value->attributes; $value = $value->value; $this->debug("in serializeType: soapval overrides value to $value"); if ($attrs) { if (!is_array($value)) { $value['!'] = $value; } foreach ($attrs as $n => $v) { $value['!' . $n] = $v; } $this->debug("in serializeType: soapval provides attributes"); } } else { $forceType = FALSE; } $xml = ''; if (strpos($type, ':')) { $uqType = substr($type, strrpos($type, ':') + 1); $ns = substr($type, 0, strrpos($type, ':')); $this->debug("in serializeType: got a prefixed type: $uqType, $ns"); if ($this->getNamespaceFromPrefix($ns)) { $ns = $this->getNamespaceFromPrefix($ns); $this->debug("in serializeType: expanded prefixed type: $uqType, $ns"); } if ($ns == $this->XMLSchemaVersion || $ns == 'http://schemas.xmlsoap.org/soap/encoding/') { $this->debug('in serializeType: type namespace indicates XML Schema or SOAP Encoding type'); if ($unqualified && $use == 'literal') { $elementNS = " xmlns=\"\""; } else { $elementNS = ''; } if (is_null($value)) { if ($use == 'literal') { // TODO: depends on minOccurs $xml = "<$name$elementNS/>"; } else { // TODO: depends on nillable, which should be checked before calling this method $xml = "<$name$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>"; } $this->debug("in serializeType: returning: $xml"); return $xml; } if ($uqType == 'Array') { // JBoss/Axis does this sometimes return $this->serialize_val($value, $name, FALSE, FALSE, FALSE, FALSE, $use); } if ($uqType == 'boolean') { if ((is_string($value) && $value == 'false') || (!$value)) { $value = 'false'; } else { $value = 'true'; } } if ($uqType == 'string' && gettype($value) == 'string') { $value = $this->expandEntities($value); } if (($uqType == 'long' || $uqType == 'unsignedLong') && gettype($value) == 'double') { $value = sprintf("%.0lf", $value); } // it's a scalar // TODO: what about null/nil values? // check type isn't a custom type extending xmlschema namespace if (!$this->getTypeDef($uqType, $ns)) { if ($use == 'literal') { if ($forceType) { $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>"; } else { $xml = "<$name$elementNS>$value</$name>"; } } else { $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>"; } $this->debug("in serializeType: returning: $xml"); return $xml; } $this->debug('custom type extends XML Schema or SOAP Encoding namespace (yuck)'); } elseif ($ns == 'http://xml.apache.org/xml-soap') { $this->debug('in serializeType: appears to be Apache SOAP type'); if ($uqType == 'Map') { $tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap'); if (!$tt_prefix) { $this->debug('in serializeType: Add namespace for Apache SOAP type'); $tt_prefix = 'ns' . rand(1000, 9999); $this->namespaces[$tt_prefix] = 'http://xml.apache.org/xml-soap'; // force this to be added to usedNamespaces $tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap'); } $contents = ''; foreach ($value as $k => $v) { $this->debug("serializing map element: key $k, value $v"); $contents .= '<item>'; $contents .= $this->serialize_val($k, 'key', FALSE, FALSE, FALSE, FALSE, $use); $contents .= $this->serialize_val($v, 'value', FALSE, FALSE, FALSE, FALSE, $use); $contents .= '</item>'; } if ($use == 'literal') { if ($forceType) { $xml = "<$name xsi:type=\"" . $tt_prefix . ":$uqType\">$contents</$name>"; } else { $xml = "<$name>$contents</$name>"; } } else { $xml = "<$name xsi:type=\"" . $tt_prefix . ":$uqType\"$encodingStyle>$contents</$name>"; } $this->debug("in serializeType: returning: $xml"); return $xml; } $this->debug('in serializeType: Apache SOAP type, but only support Map'); } } else { // TODO: should the type be compared to types in XSD, and the namespace // set to XSD if the type matches? $this->debug("in serializeType: No namespace for type $type"); $ns = ''; $uqType = $type; } if (!$typeDef = $this->getTypeDef($uqType, $ns)) { $this->setError("$type ($uqType) is not a supported type."); $this->debug("in serializeType: $type ($uqType) is not a supported type."); return FALSE; } else { $this->debug("in serializeType: found typeDef"); $this->appendDebug('typeDef=' . $this->varDump($typeDef)); if (substr($uqType, -1) == '^') { $uqType = substr($uqType, 0, -1); } } if (!isset($typeDef['phpType'])) { $this->setError("$type ($uqType) has no phpType."); $this->debug("in serializeType: $type ($uqType) has no phpType."); return FALSE; } $phpType = $typeDef['phpType']; $this->debug("in serializeType: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: " . (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : '')); // if php type == struct, map value to the <all> element names if ($phpType == 'struct') { if (isset($typeDef['typeClass']) && $typeDef['typeClass'] == 'element') { $elementName = $uqType; if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) { $elementNS = " xmlns=\"$ns\""; } else { $elementNS = " xmlns=\"\""; } } else { $elementName = $name; if ($unqualified) { $elementNS = " xmlns=\"\""; } else { $elementNS = ''; } } if (is_null($value)) { if ($use == 'literal') { // TODO: depends on minOccurs and nillable $xml = "<$elementName$elementNS/>"; } else { $xml = "<$elementName$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>"; } $this->debug("in serializeType: returning: $xml"); return $xml; } if (is_object($value)) { $value = get_object_vars($value); } if (is_array($value)) { $elementAttrs = $this->serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType); if ($use == 'literal') { if ($forceType) { $xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">"; } else { $xml = "<$elementName$elementNS$elementAttrs>"; } } else { $xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>"; } if (isset($typeDef['simpleContent']) && $typeDef['simpleContent'] == 'true') { if (isset($value['!'])) { $xml .= $value['!']; $this->debug("in serializeType: serialized simpleContent for type $type"); } else { $this->debug("in serializeType: no simpleContent to serialize for type $type"); } } else { // complexContent $xml .= $this->serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use, $encodingStyle); } $xml .= "</$elementName>"; } else { $this->debug("in serializeType: phpType is struct, but value is not an array"); $this->setError("phpType is struct, but value is not an array: see debug output for details"); $xml = ''; } } elseif ($phpType == 'array') { if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) { $elementNS = " xmlns=\"$ns\""; } else { if ($unqualified) { $elementNS = " xmlns=\"\""; } else { $elementNS = ''; } } if (is_null($value)) { if ($use == 'literal') { // TODO: depends on minOccurs $xml = "<$name$elementNS/>"; } else { $xml = "<$name$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') . ":Array\" " . $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') . ':arrayType="' . $this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType'])) . ':' . $this->getLocalPart($typeDef['arrayType']) . "[0]\"/>"; } $this->debug("in serializeType: returning: $xml"); return $xml; } if (isset($typeDef['multidimensional'])) { $nv = []; foreach ($value as $v) { $cols = ',' . sizeof($v); $nv = array_merge($nv, $v); } $value = $nv; } else { $cols = ''; } if (is_array($value) && sizeof($value) >= 1) { $rows = sizeof($value); $contents = ''; foreach ($value as $k => $v) { $this->debug("serializing array element: $k, " . (is_array($v) ? "array" : $v) . " of type: $typeDef[arrayType]"); //if (strpos($typeDef['arrayType'], ':') ) { if (!in_array($typeDef['arrayType'], $this->typemap['http://www.w3.org/2001/XMLSchema'])) { $contents .= $this->serializeType('item', $typeDef['arrayType'], $v, $use); } else { $contents .= $this->serialize_val($v, 'item', $typeDef['arrayType'], NULL, $this->XMLSchemaVersion, FALSE, $use); } } } else { $rows = 0; $contents = NULL; } // TODO: for now, an empty value will be serialized as a zero element // array. Revisit this when coding the handling of null/nil values. if ($use == 'literal') { $xml = "<$name$elementNS>" . $contents . "</$name>"; } else { $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') . ':Array" ' . $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') . ':arrayType="' . $this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType'])) . ":" . $this->getLocalPart($typeDef['arrayType']) . "[$rows$cols]\">" . $contents . "</$name>"; } } elseif ($phpType == 'scalar') { if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) { $elementNS = " xmlns=\"$ns\""; } else { if ($unqualified) { $elementNS = " xmlns=\"\""; } else { $elementNS = ''; } } if ($use == 'literal') { if ($forceType) { $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>"; } else { $xml = "<$name$elementNS>$value</$name>"; } } else { $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>"; } } $this->debug("in serializeType: returning: $xml"); return $xml; }
[ "function", "serializeType", "(", "$", "name", ",", "$", "type", ",", "$", "value", ",", "$", "use", "=", "'encoded'", ",", "$", "encodingStyle", "=", "FALSE", ",", "$", "unqualified", "=", "FALSE", ")", "{", "$", "this", "->", "debug", "(", "\"in serializeType: name=$name, type=$type, use=$use, encodingStyle=$encodingStyle, unqualified=\"", ".", "(", "$", "unqualified", "?", "\"unqualified\"", ":", "\"qualified\"", ")", ")", ";", "$", "this", "->", "appendDebug", "(", "\"value=\"", ".", "$", "this", "->", "varDump", "(", "$", "value", ")", ")", ";", "if", "(", "$", "use", "==", "'encoded'", "&&", "$", "encodingStyle", ")", "{", "$", "encodingStyle", "=", "' SOAP-ENV:encodingStyle=\"'", ".", "$", "encodingStyle", ".", "'\"'", ";", "}", "// if a soapval has been supplied, let its type override the WSDL", "if", "(", "is_object", "(", "$", "value", ")", "&&", "get_class", "(", "$", "value", ")", "==", "'soapval'", ")", "{", "if", "(", "$", "value", "->", "type_ns", ")", "{", "$", "type", "=", "$", "value", "->", "type_ns", ".", "':'", ".", "$", "value", "->", "type", ";", "$", "forceType", "=", "TRUE", ";", "$", "this", "->", "debug", "(", "\"in serializeType: soapval overrides type to $type\"", ")", ";", "}", "elseif", "(", "$", "value", "->", "type", ")", "{", "$", "type", "=", "$", "value", "->", "type", ";", "$", "forceType", "=", "TRUE", ";", "$", "this", "->", "debug", "(", "\"in serializeType: soapval overrides type to $type\"", ")", ";", "}", "else", "{", "$", "forceType", "=", "FALSE", ";", "$", "this", "->", "debug", "(", "\"in serializeType: soapval does not override type\"", ")", ";", "}", "$", "attrs", "=", "$", "value", "->", "attributes", ";", "$", "value", "=", "$", "value", "->", "value", ";", "$", "this", "->", "debug", "(", "\"in serializeType: soapval overrides value to $value\"", ")", ";", "if", "(", "$", "attrs", ")", "{", "if", "(", "!", "is_array", "(", "$", "value", ")", ")", "{", "$", "value", "[", "'!'", "]", "=", "$", "value", ";", "}", "foreach", "(", "$", "attrs", "as", "$", "n", "=>", "$", "v", ")", "{", "$", "value", "[", "'!'", ".", "$", "n", "]", "=", "$", "v", ";", "}", "$", "this", "->", "debug", "(", "\"in serializeType: soapval provides attributes\"", ")", ";", "}", "}", "else", "{", "$", "forceType", "=", "FALSE", ";", "}", "$", "xml", "=", "''", ";", "if", "(", "strpos", "(", "$", "type", ",", "':'", ")", ")", "{", "$", "uqType", "=", "substr", "(", "$", "type", ",", "strrpos", "(", "$", "type", ",", "':'", ")", "+", "1", ")", ";", "$", "ns", "=", "substr", "(", "$", "type", ",", "0", ",", "strrpos", "(", "$", "type", ",", "':'", ")", ")", ";", "$", "this", "->", "debug", "(", "\"in serializeType: got a prefixed type: $uqType, $ns\"", ")", ";", "if", "(", "$", "this", "->", "getNamespaceFromPrefix", "(", "$", "ns", ")", ")", "{", "$", "ns", "=", "$", "this", "->", "getNamespaceFromPrefix", "(", "$", "ns", ")", ";", "$", "this", "->", "debug", "(", "\"in serializeType: expanded prefixed type: $uqType, $ns\"", ")", ";", "}", "if", "(", "$", "ns", "==", "$", "this", "->", "XMLSchemaVersion", "||", "$", "ns", "==", "'http://schemas.xmlsoap.org/soap/encoding/'", ")", "{", "$", "this", "->", "debug", "(", "'in serializeType: type namespace indicates XML Schema or SOAP Encoding type'", ")", ";", "if", "(", "$", "unqualified", "&&", "$", "use", "==", "'literal'", ")", "{", "$", "elementNS", "=", "\" xmlns=\\\"\\\"\"", ";", "}", "else", "{", "$", "elementNS", "=", "''", ";", "}", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "if", "(", "$", "use", "==", "'literal'", ")", "{", "// TODO: depends on minOccurs", "$", "xml", "=", "\"<$name$elementNS/>\"", ";", "}", "else", "{", "// TODO: depends on nillable, which should be checked before calling this method", "$", "xml", "=", "\"<$name$elementNS xsi:nil=\\\"true\\\" xsi:type=\\\"\"", ".", "$", "this", "->", "getPrefixFromNamespace", "(", "$", "ns", ")", ".", "\":$uqType\\\"/>\"", ";", "}", "$", "this", "->", "debug", "(", "\"in serializeType: returning: $xml\"", ")", ";", "return", "$", "xml", ";", "}", "if", "(", "$", "uqType", "==", "'Array'", ")", "{", "// JBoss/Axis does this sometimes", "return", "$", "this", "->", "serialize_val", "(", "$", "value", ",", "$", "name", ",", "FALSE", ",", "FALSE", ",", "FALSE", ",", "FALSE", ",", "$", "use", ")", ";", "}", "if", "(", "$", "uqType", "==", "'boolean'", ")", "{", "if", "(", "(", "is_string", "(", "$", "value", ")", "&&", "$", "value", "==", "'false'", ")", "||", "(", "!", "$", "value", ")", ")", "{", "$", "value", "=", "'false'", ";", "}", "else", "{", "$", "value", "=", "'true'", ";", "}", "}", "if", "(", "$", "uqType", "==", "'string'", "&&", "gettype", "(", "$", "value", ")", "==", "'string'", ")", "{", "$", "value", "=", "$", "this", "->", "expandEntities", "(", "$", "value", ")", ";", "}", "if", "(", "(", "$", "uqType", "==", "'long'", "||", "$", "uqType", "==", "'unsignedLong'", ")", "&&", "gettype", "(", "$", "value", ")", "==", "'double'", ")", "{", "$", "value", "=", "sprintf", "(", "\"%.0lf\"", ",", "$", "value", ")", ";", "}", "// it's a scalar", "// TODO: what about null/nil values?", "// check type isn't a custom type extending xmlschema namespace", "if", "(", "!", "$", "this", "->", "getTypeDef", "(", "$", "uqType", ",", "$", "ns", ")", ")", "{", "if", "(", "$", "use", "==", "'literal'", ")", "{", "if", "(", "$", "forceType", ")", "{", "$", "xml", "=", "\"<$name$elementNS xsi:type=\\\"\"", ".", "$", "this", "->", "getPrefixFromNamespace", "(", "$", "ns", ")", ".", "\":$uqType\\\">$value</$name>\"", ";", "}", "else", "{", "$", "xml", "=", "\"<$name$elementNS>$value</$name>\"", ";", "}", "}", "else", "{", "$", "xml", "=", "\"<$name$elementNS xsi:type=\\\"\"", ".", "$", "this", "->", "getPrefixFromNamespace", "(", "$", "ns", ")", ".", "\":$uqType\\\"$encodingStyle>$value</$name>\"", ";", "}", "$", "this", "->", "debug", "(", "\"in serializeType: returning: $xml\"", ")", ";", "return", "$", "xml", ";", "}", "$", "this", "->", "debug", "(", "'custom type extends XML Schema or SOAP Encoding namespace (yuck)'", ")", ";", "}", "elseif", "(", "$", "ns", "==", "'http://xml.apache.org/xml-soap'", ")", "{", "$", "this", "->", "debug", "(", "'in serializeType: appears to be Apache SOAP type'", ")", ";", "if", "(", "$", "uqType", "==", "'Map'", ")", "{", "$", "tt_prefix", "=", "$", "this", "->", "getPrefixFromNamespace", "(", "'http://xml.apache.org/xml-soap'", ")", ";", "if", "(", "!", "$", "tt_prefix", ")", "{", "$", "this", "->", "debug", "(", "'in serializeType: Add namespace for Apache SOAP type'", ")", ";", "$", "tt_prefix", "=", "'ns'", ".", "rand", "(", "1000", ",", "9999", ")", ";", "$", "this", "->", "namespaces", "[", "$", "tt_prefix", "]", "=", "'http://xml.apache.org/xml-soap'", ";", "// force this to be added to usedNamespaces", "$", "tt_prefix", "=", "$", "this", "->", "getPrefixFromNamespace", "(", "'http://xml.apache.org/xml-soap'", ")", ";", "}", "$", "contents", "=", "''", ";", "foreach", "(", "$", "value", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "this", "->", "debug", "(", "\"serializing map element: key $k, value $v\"", ")", ";", "$", "contents", ".=", "'<item>'", ";", "$", "contents", ".=", "$", "this", "->", "serialize_val", "(", "$", "k", ",", "'key'", ",", "FALSE", ",", "FALSE", ",", "FALSE", ",", "FALSE", ",", "$", "use", ")", ";", "$", "contents", ".=", "$", "this", "->", "serialize_val", "(", "$", "v", ",", "'value'", ",", "FALSE", ",", "FALSE", ",", "FALSE", ",", "FALSE", ",", "$", "use", ")", ";", "$", "contents", ".=", "'</item>'", ";", "}", "if", "(", "$", "use", "==", "'literal'", ")", "{", "if", "(", "$", "forceType", ")", "{", "$", "xml", "=", "\"<$name xsi:type=\\\"\"", ".", "$", "tt_prefix", ".", "\":$uqType\\\">$contents</$name>\"", ";", "}", "else", "{", "$", "xml", "=", "\"<$name>$contents</$name>\"", ";", "}", "}", "else", "{", "$", "xml", "=", "\"<$name xsi:type=\\\"\"", ".", "$", "tt_prefix", ".", "\":$uqType\\\"$encodingStyle>$contents</$name>\"", ";", "}", "$", "this", "->", "debug", "(", "\"in serializeType: returning: $xml\"", ")", ";", "return", "$", "xml", ";", "}", "$", "this", "->", "debug", "(", "'in serializeType: Apache SOAP type, but only support Map'", ")", ";", "}", "}", "else", "{", "// TODO: should the type be compared to types in XSD, and the namespace", "// set to XSD if the type matches?", "$", "this", "->", "debug", "(", "\"in serializeType: No namespace for type $type\"", ")", ";", "$", "ns", "=", "''", ";", "$", "uqType", "=", "$", "type", ";", "}", "if", "(", "!", "$", "typeDef", "=", "$", "this", "->", "getTypeDef", "(", "$", "uqType", ",", "$", "ns", ")", ")", "{", "$", "this", "->", "setError", "(", "\"$type ($uqType) is not a supported type.\"", ")", ";", "$", "this", "->", "debug", "(", "\"in serializeType: $type ($uqType) is not a supported type.\"", ")", ";", "return", "FALSE", ";", "}", "else", "{", "$", "this", "->", "debug", "(", "\"in serializeType: found typeDef\"", ")", ";", "$", "this", "->", "appendDebug", "(", "'typeDef='", ".", "$", "this", "->", "varDump", "(", "$", "typeDef", ")", ")", ";", "if", "(", "substr", "(", "$", "uqType", ",", "-", "1", ")", "==", "'^'", ")", "{", "$", "uqType", "=", "substr", "(", "$", "uqType", ",", "0", ",", "-", "1", ")", ";", "}", "}", "if", "(", "!", "isset", "(", "$", "typeDef", "[", "'phpType'", "]", ")", ")", "{", "$", "this", "->", "setError", "(", "\"$type ($uqType) has no phpType.\"", ")", ";", "$", "this", "->", "debug", "(", "\"in serializeType: $type ($uqType) has no phpType.\"", ")", ";", "return", "FALSE", ";", "}", "$", "phpType", "=", "$", "typeDef", "[", "'phpType'", "]", ";", "$", "this", "->", "debug", "(", "\"in serializeType: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: \"", ".", "(", "isset", "(", "$", "typeDef", "[", "'arrayType'", "]", ")", "?", "$", "typeDef", "[", "'arrayType'", "]", ":", "''", ")", ")", ";", "// if php type == struct, map value to the <all> element names", "if", "(", "$", "phpType", "==", "'struct'", ")", "{", "if", "(", "isset", "(", "$", "typeDef", "[", "'typeClass'", "]", ")", "&&", "$", "typeDef", "[", "'typeClass'", "]", "==", "'element'", ")", "{", "$", "elementName", "=", "$", "uqType", ";", "if", "(", "isset", "(", "$", "typeDef", "[", "'form'", "]", ")", "&&", "(", "$", "typeDef", "[", "'form'", "]", "==", "'qualified'", ")", ")", "{", "$", "elementNS", "=", "\" xmlns=\\\"$ns\\\"\"", ";", "}", "else", "{", "$", "elementNS", "=", "\" xmlns=\\\"\\\"\"", ";", "}", "}", "else", "{", "$", "elementName", "=", "$", "name", ";", "if", "(", "$", "unqualified", ")", "{", "$", "elementNS", "=", "\" xmlns=\\\"\\\"\"", ";", "}", "else", "{", "$", "elementNS", "=", "''", ";", "}", "}", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "if", "(", "$", "use", "==", "'literal'", ")", "{", "// TODO: depends on minOccurs and nillable", "$", "xml", "=", "\"<$elementName$elementNS/>\"", ";", "}", "else", "{", "$", "xml", "=", "\"<$elementName$elementNS xsi:nil=\\\"true\\\" xsi:type=\\\"\"", ".", "$", "this", "->", "getPrefixFromNamespace", "(", "$", "ns", ")", ".", "\":$uqType\\\"/>\"", ";", "}", "$", "this", "->", "debug", "(", "\"in serializeType: returning: $xml\"", ")", ";", "return", "$", "xml", ";", "}", "if", "(", "is_object", "(", "$", "value", ")", ")", "{", "$", "value", "=", "get_object_vars", "(", "$", "value", ")", ";", "}", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "elementAttrs", "=", "$", "this", "->", "serializeComplexTypeAttributes", "(", "$", "typeDef", ",", "$", "value", ",", "$", "ns", ",", "$", "uqType", ")", ";", "if", "(", "$", "use", "==", "'literal'", ")", "{", "if", "(", "$", "forceType", ")", "{", "$", "xml", "=", "\"<$elementName$elementNS$elementAttrs xsi:type=\\\"\"", ".", "$", "this", "->", "getPrefixFromNamespace", "(", "$", "ns", ")", ".", "\":$uqType\\\">\"", ";", "}", "else", "{", "$", "xml", "=", "\"<$elementName$elementNS$elementAttrs>\"", ";", "}", "}", "else", "{", "$", "xml", "=", "\"<$elementName$elementNS$elementAttrs xsi:type=\\\"\"", ".", "$", "this", "->", "getPrefixFromNamespace", "(", "$", "ns", ")", ".", "\":$uqType\\\"$encodingStyle>\"", ";", "}", "if", "(", "isset", "(", "$", "typeDef", "[", "'simpleContent'", "]", ")", "&&", "$", "typeDef", "[", "'simpleContent'", "]", "==", "'true'", ")", "{", "if", "(", "isset", "(", "$", "value", "[", "'!'", "]", ")", ")", "{", "$", "xml", ".=", "$", "value", "[", "'!'", "]", ";", "$", "this", "->", "debug", "(", "\"in serializeType: serialized simpleContent for type $type\"", ")", ";", "}", "else", "{", "$", "this", "->", "debug", "(", "\"in serializeType: no simpleContent to serialize for type $type\"", ")", ";", "}", "}", "else", "{", "// complexContent", "$", "xml", ".=", "$", "this", "->", "serializeComplexTypeElements", "(", "$", "typeDef", ",", "$", "value", ",", "$", "ns", ",", "$", "uqType", ",", "$", "use", ",", "$", "encodingStyle", ")", ";", "}", "$", "xml", ".=", "\"</$elementName>\"", ";", "}", "else", "{", "$", "this", "->", "debug", "(", "\"in serializeType: phpType is struct, but value is not an array\"", ")", ";", "$", "this", "->", "setError", "(", "\"phpType is struct, but value is not an array: see debug output for details\"", ")", ";", "$", "xml", "=", "''", ";", "}", "}", "elseif", "(", "$", "phpType", "==", "'array'", ")", "{", "if", "(", "isset", "(", "$", "typeDef", "[", "'form'", "]", ")", "&&", "(", "$", "typeDef", "[", "'form'", "]", "==", "'qualified'", ")", ")", "{", "$", "elementNS", "=", "\" xmlns=\\\"$ns\\\"\"", ";", "}", "else", "{", "if", "(", "$", "unqualified", ")", "{", "$", "elementNS", "=", "\" xmlns=\\\"\\\"\"", ";", "}", "else", "{", "$", "elementNS", "=", "''", ";", "}", "}", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "if", "(", "$", "use", "==", "'literal'", ")", "{", "// TODO: depends on minOccurs", "$", "xml", "=", "\"<$name$elementNS/>\"", ";", "}", "else", "{", "$", "xml", "=", "\"<$name$elementNS xsi:nil=\\\"true\\\" xsi:type=\\\"\"", ".", "$", "this", "->", "getPrefixFromNamespace", "(", "'http://schemas.xmlsoap.org/soap/encoding/'", ")", ".", "\":Array\\\" \"", ".", "$", "this", "->", "getPrefixFromNamespace", "(", "'http://schemas.xmlsoap.org/soap/encoding/'", ")", ".", "':arrayType=\"'", ".", "$", "this", "->", "getPrefixFromNamespace", "(", "$", "this", "->", "getPrefix", "(", "$", "typeDef", "[", "'arrayType'", "]", ")", ")", ".", "':'", ".", "$", "this", "->", "getLocalPart", "(", "$", "typeDef", "[", "'arrayType'", "]", ")", ".", "\"[0]\\\"/>\"", ";", "}", "$", "this", "->", "debug", "(", "\"in serializeType: returning: $xml\"", ")", ";", "return", "$", "xml", ";", "}", "if", "(", "isset", "(", "$", "typeDef", "[", "'multidimensional'", "]", ")", ")", "{", "$", "nv", "=", "[", "]", ";", "foreach", "(", "$", "value", "as", "$", "v", ")", "{", "$", "cols", "=", "','", ".", "sizeof", "(", "$", "v", ")", ";", "$", "nv", "=", "array_merge", "(", "$", "nv", ",", "$", "v", ")", ";", "}", "$", "value", "=", "$", "nv", ";", "}", "else", "{", "$", "cols", "=", "''", ";", "}", "if", "(", "is_array", "(", "$", "value", ")", "&&", "sizeof", "(", "$", "value", ")", ">=", "1", ")", "{", "$", "rows", "=", "sizeof", "(", "$", "value", ")", ";", "$", "contents", "=", "''", ";", "foreach", "(", "$", "value", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "this", "->", "debug", "(", "\"serializing array element: $k, \"", ".", "(", "is_array", "(", "$", "v", ")", "?", "\"array\"", ":", "$", "v", ")", ".", "\" of type: $typeDef[arrayType]\"", ")", ";", "//if (strpos($typeDef['arrayType'], ':') ) {", "if", "(", "!", "in_array", "(", "$", "typeDef", "[", "'arrayType'", "]", ",", "$", "this", "->", "typemap", "[", "'http://www.w3.org/2001/XMLSchema'", "]", ")", ")", "{", "$", "contents", ".=", "$", "this", "->", "serializeType", "(", "'item'", ",", "$", "typeDef", "[", "'arrayType'", "]", ",", "$", "v", ",", "$", "use", ")", ";", "}", "else", "{", "$", "contents", ".=", "$", "this", "->", "serialize_val", "(", "$", "v", ",", "'item'", ",", "$", "typeDef", "[", "'arrayType'", "]", ",", "NULL", ",", "$", "this", "->", "XMLSchemaVersion", ",", "FALSE", ",", "$", "use", ")", ";", "}", "}", "}", "else", "{", "$", "rows", "=", "0", ";", "$", "contents", "=", "NULL", ";", "}", "// TODO: for now, an empty value will be serialized as a zero element", "// array. Revisit this when coding the handling of null/nil values.", "if", "(", "$", "use", "==", "'literal'", ")", "{", "$", "xml", "=", "\"<$name$elementNS>\"", ".", "$", "contents", ".", "\"</$name>\"", ";", "}", "else", "{", "$", "xml", "=", "\"<$name$elementNS xsi:type=\\\"\"", ".", "$", "this", "->", "getPrefixFromNamespace", "(", "'http://schemas.xmlsoap.org/soap/encoding/'", ")", ".", "':Array\" '", ".", "$", "this", "->", "getPrefixFromNamespace", "(", "'http://schemas.xmlsoap.org/soap/encoding/'", ")", ".", "':arrayType=\"'", ".", "$", "this", "->", "getPrefixFromNamespace", "(", "$", "this", "->", "getPrefix", "(", "$", "typeDef", "[", "'arrayType'", "]", ")", ")", ".", "\":\"", ".", "$", "this", "->", "getLocalPart", "(", "$", "typeDef", "[", "'arrayType'", "]", ")", ".", "\"[$rows$cols]\\\">\"", ".", "$", "contents", ".", "\"</$name>\"", ";", "}", "}", "elseif", "(", "$", "phpType", "==", "'scalar'", ")", "{", "if", "(", "isset", "(", "$", "typeDef", "[", "'form'", "]", ")", "&&", "(", "$", "typeDef", "[", "'form'", "]", "==", "'qualified'", ")", ")", "{", "$", "elementNS", "=", "\" xmlns=\\\"$ns\\\"\"", ";", "}", "else", "{", "if", "(", "$", "unqualified", ")", "{", "$", "elementNS", "=", "\" xmlns=\\\"\\\"\"", ";", "}", "else", "{", "$", "elementNS", "=", "''", ";", "}", "}", "if", "(", "$", "use", "==", "'literal'", ")", "{", "if", "(", "$", "forceType", ")", "{", "$", "xml", "=", "\"<$name$elementNS xsi:type=\\\"\"", ".", "$", "this", "->", "getPrefixFromNamespace", "(", "$", "ns", ")", ".", "\":$uqType\\\">$value</$name>\"", ";", "}", "else", "{", "$", "xml", "=", "\"<$name$elementNS>$value</$name>\"", ";", "}", "}", "else", "{", "$", "xml", "=", "\"<$name$elementNS xsi:type=\\\"\"", ".", "$", "this", "->", "getPrefixFromNamespace", "(", "$", "ns", ")", ".", "\":$uqType\\\"$encodingStyle>$value</$name>\"", ";", "}", "}", "$", "this", "->", "debug", "(", "\"in serializeType: returning: $xml\"", ")", ";", "return", "$", "xml", ";", "}" ]
serializes a PHP value according a given type definition @param string $name name of value (part or element) @param string $type XML schema type of value (type or element) @param mixed $value a native PHP value (parameter value) @param string $use use for part (encoded|literal) @param string $encodingStyle SOAP encoding style for the value (if different than the enclosing style) @param boolean $unqualified a kludge for what should be XML namespace form handling @return string value serialized as an XML string @access private
[ "serializes", "a", "PHP", "value", "according", "a", "given", "type", "definition" ]
train
https://github.com/nguyenanhung/nusoap/blob/a9b4d98f4f3fe748f8e5d9f8091dfc53585d2556/src-fix/nusoap.php#L6217-L6532
nguyenanhung/nusoap
src-fix/nusoap.php
nusoap_parser.end_element
function end_element($parser, $name) { // position of current element is equal to the last value left in depth_array for my depth $pos = $this->depth_array[$this->depth--]; // get element prefix if (strpos($name, ':')) { // get ns prefix $prefix = substr($name, 0, strpos($name, ':')); // get unqualified name $name = substr(strstr($name, ':'), 1); } // build to native type if (isset($this->body_position) && $pos > $this->body_position) { // deal w/ multirefs if (isset($this->message[$pos]['attrs']['href'])) { // get id $id = substr($this->message[$pos]['attrs']['href'], 1); // add placeholder to href array $this->multirefs[$id][$pos] = 'placeholder'; // add set a reference to it as the result value $this->message[$pos]['result'] =& $this->multirefs[$id][$pos]; // build complexType values } elseif ($this->message[$pos]['children'] != '') { // if result has already been generated (struct/array) if (!isset($this->message[$pos]['result'])) { $this->message[$pos]['result'] = $this->buildVal($pos); } // build complexType values of attributes and possibly simpleContent } elseif (isset($this->message[$pos]['xattrs'])) { if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) { $this->message[$pos]['xattrs']['!'] = NULL; } elseif (isset($this->message[$pos]['cdata']) && trim($this->message[$pos]['cdata']) != '') { if (isset($this->message[$pos]['type'])) { $this->message[$pos]['xattrs']['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : ''); } else { $parent = $this->message[$pos]['parent']; if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) { $this->message[$pos]['xattrs']['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : ''); } else { $this->message[$pos]['xattrs']['!'] = $this->message[$pos]['cdata']; } } } $this->message[$pos]['result'] = $this->message[$pos]['xattrs']; // set value of simpleType (or nil complexType) } else { //$this->debug('adding data for scalar value '.$this->message[$pos]['name'].' of value '.$this->message[$pos]['cdata']); if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) { $this->message[$pos]['xattrs']['!'] = NULL; } elseif (isset($this->message[$pos]['type'])) { $this->message[$pos]['result'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : ''); } else { $parent = $this->message[$pos]['parent']; if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) { $this->message[$pos]['result'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : ''); } else { $this->message[$pos]['result'] = $this->message[$pos]['cdata']; } } /* add value to parent's result, if parent is struct/array $parent = $this->message[$pos]['parent']; if($this->message[$parent]['type'] != 'map'){ if(strtolower($this->message[$parent]['type']) == 'array'){ $this->message[$parent]['result'][] = $this->message[$pos]['result']; } else { $this->message[$parent]['result'][$this->message[$pos]['name']] = $this->message[$pos]['result']; } } */ } } // for doclit if ($this->status == 'header') { if ($this->root_header != $pos) { $this->responseHeaders .= "</" . (isset($prefix) ? $prefix . ':' : '') . "$name>"; } } elseif ($pos >= $this->root_struct) { $this->document .= "</" . (isset($prefix) ? $prefix . ':' : '') . "$name>"; } // switch status if ($pos == $this->root_struct) { $this->status = 'body'; $this->root_struct_namespace = $this->message[$pos]['namespace']; } elseif ($pos == $this->root_header) { $this->status = 'envelope'; } elseif ($name == 'Body' && $this->status == 'body') { $this->status = 'envelope'; } elseif ($name == 'Header' && $this->status == 'header') { // will never happen $this->status = 'envelope'; } elseif ($name == 'Envelope' && $this->status == 'envelope') { $this->status = ''; } // set parent back to my parent $this->parent = $this->message[$pos]['parent']; }
php
function end_element($parser, $name) { // position of current element is equal to the last value left in depth_array for my depth $pos = $this->depth_array[$this->depth--]; // get element prefix if (strpos($name, ':')) { // get ns prefix $prefix = substr($name, 0, strpos($name, ':')); // get unqualified name $name = substr(strstr($name, ':'), 1); } // build to native type if (isset($this->body_position) && $pos > $this->body_position) { // deal w/ multirefs if (isset($this->message[$pos]['attrs']['href'])) { // get id $id = substr($this->message[$pos]['attrs']['href'], 1); // add placeholder to href array $this->multirefs[$id][$pos] = 'placeholder'; // add set a reference to it as the result value $this->message[$pos]['result'] =& $this->multirefs[$id][$pos]; // build complexType values } elseif ($this->message[$pos]['children'] != '') { // if result has already been generated (struct/array) if (!isset($this->message[$pos]['result'])) { $this->message[$pos]['result'] = $this->buildVal($pos); } // build complexType values of attributes and possibly simpleContent } elseif (isset($this->message[$pos]['xattrs'])) { if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) { $this->message[$pos]['xattrs']['!'] = NULL; } elseif (isset($this->message[$pos]['cdata']) && trim($this->message[$pos]['cdata']) != '') { if (isset($this->message[$pos]['type'])) { $this->message[$pos]['xattrs']['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : ''); } else { $parent = $this->message[$pos]['parent']; if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) { $this->message[$pos]['xattrs']['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : ''); } else { $this->message[$pos]['xattrs']['!'] = $this->message[$pos]['cdata']; } } } $this->message[$pos]['result'] = $this->message[$pos]['xattrs']; // set value of simpleType (or nil complexType) } else { //$this->debug('adding data for scalar value '.$this->message[$pos]['name'].' of value '.$this->message[$pos]['cdata']); if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) { $this->message[$pos]['xattrs']['!'] = NULL; } elseif (isset($this->message[$pos]['type'])) { $this->message[$pos]['result'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : ''); } else { $parent = $this->message[$pos]['parent']; if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) { $this->message[$pos]['result'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : ''); } else { $this->message[$pos]['result'] = $this->message[$pos]['cdata']; } } /* add value to parent's result, if parent is struct/array $parent = $this->message[$pos]['parent']; if($this->message[$parent]['type'] != 'map'){ if(strtolower($this->message[$parent]['type']) == 'array'){ $this->message[$parent]['result'][] = $this->message[$pos]['result']; } else { $this->message[$parent]['result'][$this->message[$pos]['name']] = $this->message[$pos]['result']; } } */ } } // for doclit if ($this->status == 'header') { if ($this->root_header != $pos) { $this->responseHeaders .= "</" . (isset($prefix) ? $prefix . ':' : '') . "$name>"; } } elseif ($pos >= $this->root_struct) { $this->document .= "</" . (isset($prefix) ? $prefix . ':' : '') . "$name>"; } // switch status if ($pos == $this->root_struct) { $this->status = 'body'; $this->root_struct_namespace = $this->message[$pos]['namespace']; } elseif ($pos == $this->root_header) { $this->status = 'envelope'; } elseif ($name == 'Body' && $this->status == 'body') { $this->status = 'envelope'; } elseif ($name == 'Header' && $this->status == 'header') { // will never happen $this->status = 'envelope'; } elseif ($name == 'Envelope' && $this->status == 'envelope') { $this->status = ''; } // set parent back to my parent $this->parent = $this->message[$pos]['parent']; }
[ "function", "end_element", "(", "$", "parser", ",", "$", "name", ")", "{", "// position of current element is equal to the last value left in depth_array for my depth", "$", "pos", "=", "$", "this", "->", "depth_array", "[", "$", "this", "->", "depth", "--", "]", ";", "// get element prefix", "if", "(", "strpos", "(", "$", "name", ",", "':'", ")", ")", "{", "// get ns prefix", "$", "prefix", "=", "substr", "(", "$", "name", ",", "0", ",", "strpos", "(", "$", "name", ",", "':'", ")", ")", ";", "// get unqualified name", "$", "name", "=", "substr", "(", "strstr", "(", "$", "name", ",", "':'", ")", ",", "1", ")", ";", "}", "// build to native type", "if", "(", "isset", "(", "$", "this", "->", "body_position", ")", "&&", "$", "pos", ">", "$", "this", "->", "body_position", ")", "{", "// deal w/ multirefs", "if", "(", "isset", "(", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'attrs'", "]", "[", "'href'", "]", ")", ")", "{", "// get id", "$", "id", "=", "substr", "(", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'attrs'", "]", "[", "'href'", "]", ",", "1", ")", ";", "// add placeholder to href array", "$", "this", "->", "multirefs", "[", "$", "id", "]", "[", "$", "pos", "]", "=", "'placeholder'", ";", "// add set a reference to it as the result value", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'result'", "]", "=", "&", "$", "this", "->", "multirefs", "[", "$", "id", "]", "[", "$", "pos", "]", ";", "// build complexType values", "}", "elseif", "(", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'children'", "]", "!=", "''", ")", "{", "// if result has already been generated (struct/array)", "if", "(", "!", "isset", "(", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'result'", "]", ")", ")", "{", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'result'", "]", "=", "$", "this", "->", "buildVal", "(", "$", "pos", ")", ";", "}", "// build complexType values of attributes and possibly simpleContent", "}", "elseif", "(", "isset", "(", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'xattrs'", "]", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'nil'", "]", ")", "&&", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'nil'", "]", ")", "{", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'xattrs'", "]", "[", "'!'", "]", "=", "NULL", ";", "}", "elseif", "(", "isset", "(", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'cdata'", "]", ")", "&&", "trim", "(", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'cdata'", "]", ")", "!=", "''", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'type'", "]", ")", ")", "{", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'xattrs'", "]", "[", "'!'", "]", "=", "$", "this", "->", "decodeSimple", "(", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'cdata'", "]", ",", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'type'", "]", ",", "isset", "(", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'type_namespace'", "]", ")", "?", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'type_namespace'", "]", ":", "''", ")", ";", "}", "else", "{", "$", "parent", "=", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'parent'", "]", ";", "if", "(", "isset", "(", "$", "this", "->", "message", "[", "$", "parent", "]", "[", "'type'", "]", ")", "&&", "(", "$", "this", "->", "message", "[", "$", "parent", "]", "[", "'type'", "]", "==", "'array'", ")", "&&", "isset", "(", "$", "this", "->", "message", "[", "$", "parent", "]", "[", "'arrayType'", "]", ")", ")", "{", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'xattrs'", "]", "[", "'!'", "]", "=", "$", "this", "->", "decodeSimple", "(", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'cdata'", "]", ",", "$", "this", "->", "message", "[", "$", "parent", "]", "[", "'arrayType'", "]", ",", "isset", "(", "$", "this", "->", "message", "[", "$", "parent", "]", "[", "'arrayTypeNamespace'", "]", ")", "?", "$", "this", "->", "message", "[", "$", "parent", "]", "[", "'arrayTypeNamespace'", "]", ":", "''", ")", ";", "}", "else", "{", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'xattrs'", "]", "[", "'!'", "]", "=", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'cdata'", "]", ";", "}", "}", "}", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'result'", "]", "=", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'xattrs'", "]", ";", "// set value of simpleType (or nil complexType)", "}", "else", "{", "//$this->debug('adding data for scalar value '.$this->message[$pos]['name'].' of value '.$this->message[$pos]['cdata']);", "if", "(", "isset", "(", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'nil'", "]", ")", "&&", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'nil'", "]", ")", "{", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'xattrs'", "]", "[", "'!'", "]", "=", "NULL", ";", "}", "elseif", "(", "isset", "(", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'type'", "]", ")", ")", "{", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'result'", "]", "=", "$", "this", "->", "decodeSimple", "(", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'cdata'", "]", ",", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'type'", "]", ",", "isset", "(", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'type_namespace'", "]", ")", "?", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'type_namespace'", "]", ":", "''", ")", ";", "}", "else", "{", "$", "parent", "=", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'parent'", "]", ";", "if", "(", "isset", "(", "$", "this", "->", "message", "[", "$", "parent", "]", "[", "'type'", "]", ")", "&&", "(", "$", "this", "->", "message", "[", "$", "parent", "]", "[", "'type'", "]", "==", "'array'", ")", "&&", "isset", "(", "$", "this", "->", "message", "[", "$", "parent", "]", "[", "'arrayType'", "]", ")", ")", "{", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'result'", "]", "=", "$", "this", "->", "decodeSimple", "(", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'cdata'", "]", ",", "$", "this", "->", "message", "[", "$", "parent", "]", "[", "'arrayType'", "]", ",", "isset", "(", "$", "this", "->", "message", "[", "$", "parent", "]", "[", "'arrayTypeNamespace'", "]", ")", "?", "$", "this", "->", "message", "[", "$", "parent", "]", "[", "'arrayTypeNamespace'", "]", ":", "''", ")", ";", "}", "else", "{", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'result'", "]", "=", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'cdata'", "]", ";", "}", "}", "/* add value to parent's result, if parent is struct/array\n\t\t\t\t$parent = $this->message[$pos]['parent'];\n\t\t\t\tif($this->message[$parent]['type'] != 'map'){\n\t\t\t\t\tif(strtolower($this->message[$parent]['type']) == 'array'){\n\t\t\t\t\t\t$this->message[$parent]['result'][] = $this->message[$pos]['result'];\n\t\t\t\t\t} else {\n\t\t\t\t\t\t$this->message[$parent]['result'][$this->message[$pos]['name']] = $this->message[$pos]['result'];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t*/", "}", "}", "// for doclit", "if", "(", "$", "this", "->", "status", "==", "'header'", ")", "{", "if", "(", "$", "this", "->", "root_header", "!=", "$", "pos", ")", "{", "$", "this", "->", "responseHeaders", ".=", "\"</\"", ".", "(", "isset", "(", "$", "prefix", ")", "?", "$", "prefix", ".", "':'", ":", "''", ")", ".", "\"$name>\"", ";", "}", "}", "elseif", "(", "$", "pos", ">=", "$", "this", "->", "root_struct", ")", "{", "$", "this", "->", "document", ".=", "\"</\"", ".", "(", "isset", "(", "$", "prefix", ")", "?", "$", "prefix", ".", "':'", ":", "''", ")", ".", "\"$name>\"", ";", "}", "// switch status", "if", "(", "$", "pos", "==", "$", "this", "->", "root_struct", ")", "{", "$", "this", "->", "status", "=", "'body'", ";", "$", "this", "->", "root_struct_namespace", "=", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'namespace'", "]", ";", "}", "elseif", "(", "$", "pos", "==", "$", "this", "->", "root_header", ")", "{", "$", "this", "->", "status", "=", "'envelope'", ";", "}", "elseif", "(", "$", "name", "==", "'Body'", "&&", "$", "this", "->", "status", "==", "'body'", ")", "{", "$", "this", "->", "status", "=", "'envelope'", ";", "}", "elseif", "(", "$", "name", "==", "'Header'", "&&", "$", "this", "->", "status", "==", "'header'", ")", "{", "// will never happen", "$", "this", "->", "status", "=", "'envelope'", ";", "}", "elseif", "(", "$", "name", "==", "'Envelope'", "&&", "$", "this", "->", "status", "==", "'envelope'", ")", "{", "$", "this", "->", "status", "=", "''", ";", "}", "// set parent back to my parent", "$", "this", "->", "parent", "=", "$", "this", "->", "message", "[", "$", "pos", "]", "[", "'parent'", "]", ";", "}" ]
end-element handler @param resource $parser XML parser object @param string $name element name @access private
[ "end", "-", "element", "handler" ]
train
https://github.com/nguyenanhung/nusoap/blob/a9b4d98f4f3fe748f8e5d9f8091dfc53585d2556/src-fix/nusoap.php#L7198-L7296
nguyenanhung/nusoap
src-fix/nusoap.php
nusoap_client.call
function call( $operation, $params = [], $namespace = 'http://tempuri.org', $soapAction = '', $headers = FALSE, $rpcParams = NULL, $style = 'rpc', $use = 'encoded' ) { $this->operation = $operation; $this->fault = FALSE; $this->setError(''); $this->request = ''; $this->response = ''; $this->responseData = ''; $this->faultstring = ''; $this->faultcode = ''; $this->opData = []; $this->debug("call: operation=$operation, namespace=$namespace, soapAction=$soapAction, rpcParams=$rpcParams, style=$style, use=$use, endpointType=$this->endpointType"); $this->appendDebug('params=' . $this->varDump($params)); $this->appendDebug('headers=' . $this->varDump($headers)); if ($headers) { $this->requestHeaders = $headers; } if ($this->endpointType == 'wsdl' && is_null($this->wsdl)) { $this->loadWSDL(); if ($this->getError()) { return FALSE; } } // serialize parameters if ($this->endpointType == 'wsdl' && $opData = $this->getOperationData($operation)) { // use WSDL for operation $this->opData = $opData; $this->debug("found operation"); $this->appendDebug('opData=' . $this->varDump($opData)); if (isset($opData['soapAction'])) { $soapAction = $opData['soapAction']; } if (!$this->forceEndpoint) { $this->endpoint = $opData['endpoint']; } else { $this->endpoint = $this->forceEndpoint; } $namespace = isset($opData['input']['namespace']) ? $opData['input']['namespace'] : $namespace; $style = $opData['style']; $use = $opData['input']['use']; // add ns to ns array if ($namespace != '' && !isset($this->wsdl->namespaces[$namespace])) { $nsPrefix = 'ns' . rand(1000, 9999); $this->wsdl->namespaces[$nsPrefix] = $namespace; } $nsPrefix = $this->wsdl->getPrefixFromNamespace($namespace); // serialize payload if (is_string($params)) { $this->debug("serializing param string for WSDL operation $operation"); $payload = $params; } elseif (is_array($params)) { $this->debug("serializing param array for WSDL operation $operation"); $payload = $this->wsdl->serializeRPCParameters($operation, 'input', $params, $this->bindingType); } else { $this->debug('params must be array or string'); $this->setError('params must be array or string'); return FALSE; } $usedNamespaces = $this->wsdl->usedNamespaces; if (isset($opData['input']['encodingStyle'])) { $encodingStyle = $opData['input']['encodingStyle']; } else { $encodingStyle = ''; } $this->appendDebug($this->wsdl->getDebug()); $this->wsdl->clearDebug(); if ($errstr = $this->wsdl->getError()) { $this->debug('got wsdl error: ' . $errstr); $this->setError('wsdl error: ' . $errstr); return FALSE; } } elseif ($this->endpointType == 'wsdl') { // operation not in WSDL $this->appendDebug($this->wsdl->getDebug()); $this->wsdl->clearDebug(); $this->setError('operation ' . $operation . ' not present in WSDL.'); $this->debug("operation '$operation' not present in WSDL."); return FALSE; } else { // no WSDL //$this->namespaces['ns1'] = $namespace; $nsPrefix = 'ns' . rand(1000, 9999); // serialize $payload = ''; if (is_string($params)) { $this->debug("serializing param string for operation $operation"); $payload = $params; } elseif (is_array($params)) { $this->debug("serializing param array for operation $operation"); foreach ($params as $k => $v) { $payload .= $this->serialize_val($v, $k, FALSE, FALSE, FALSE, FALSE, $use); } } else { $this->debug('params must be array or string'); $this->setError('params must be array or string'); return FALSE; } $usedNamespaces = []; if ($use == 'encoded') { $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/'; } else { $encodingStyle = ''; } } // wrap RPC calls with method element if ($style == 'rpc') { if ($use == 'literal') { $this->debug("wrapping RPC request with literal method element"); if ($namespace) { // http://www.ws-i.org/Profiles/BasicProfile-1.1-2004-08-24.html R2735 says rpc/literal accessor elements should not be in a namespace $payload = "<$nsPrefix:$operation xmlns:$nsPrefix=\"$namespace\">" . $payload . "</$nsPrefix:$operation>"; } else { $payload = "<$operation>" . $payload . "</$operation>"; } } else { $this->debug("wrapping RPC request with encoded method element"); if ($namespace) { $payload = "<$nsPrefix:$operation xmlns:$nsPrefix=\"$namespace\">" . $payload . "</$nsPrefix:$operation>"; } else { $payload = "<$operation>" . $payload . "</$operation>"; } } } // serialize envelope $soapmsg = $this->serializeEnvelope($payload, $this->requestHeaders, $usedNamespaces, $style, $use, $encodingStyle); $this->debug("endpoint=$this->endpoint, soapAction=$soapAction, namespace=$namespace, style=$style, use=$use, encodingStyle=$encodingStyle"); $this->debug('SOAP message length=' . strlen($soapmsg) . ' contents (max 1000 bytes)=' . substr($soapmsg, 0, 1000)); // send $return = $this->send($this->getHTTPBody($soapmsg), $soapAction, $this->timeout, $this->response_timeout); if ($errstr = $this->getError()) { $this->debug('Error: ' . $errstr); return FALSE; } else { $this->return = $return; $this->debug('sent message successfully and got a(n) ' . gettype($return)); $this->appendDebug('return=' . $this->varDump($return)); // fault? if (is_array($return) && isset($return['faultcode'])) { $this->debug('got fault'); $this->setError($return['faultcode'] . ': ' . $return['faultstring']); $this->fault = TRUE; foreach ($return as $k => $v) { $this->$k = $v; if (is_array($v)) { $this->debug("$k = " . json_encode($v)); } else { $this->debug("$k = $v<br>"); } } return $return; } elseif ($style == 'document') { // NOTE: if the response is defined to have multiple parts (i.e. unwrapped), // we are only going to return the first part here...sorry about that return $return; } else { // array of return values if (is_array($return)) { // multiple 'out' parameters, which we return wrapped up // in the array if (sizeof($return) > 1) { return $return; } // single 'out' parameter (normally the return value) $return = array_shift($return); $this->debug('return shifted value: '); $this->appendDebug($this->varDump($return)); return $return; // nothing returned (ie, echoVoid) } else { return ""; } } } }
php
function call( $operation, $params = [], $namespace = 'http://tempuri.org', $soapAction = '', $headers = FALSE, $rpcParams = NULL, $style = 'rpc', $use = 'encoded' ) { $this->operation = $operation; $this->fault = FALSE; $this->setError(''); $this->request = ''; $this->response = ''; $this->responseData = ''; $this->faultstring = ''; $this->faultcode = ''; $this->opData = []; $this->debug("call: operation=$operation, namespace=$namespace, soapAction=$soapAction, rpcParams=$rpcParams, style=$style, use=$use, endpointType=$this->endpointType"); $this->appendDebug('params=' . $this->varDump($params)); $this->appendDebug('headers=' . $this->varDump($headers)); if ($headers) { $this->requestHeaders = $headers; } if ($this->endpointType == 'wsdl' && is_null($this->wsdl)) { $this->loadWSDL(); if ($this->getError()) { return FALSE; } } // serialize parameters if ($this->endpointType == 'wsdl' && $opData = $this->getOperationData($operation)) { // use WSDL for operation $this->opData = $opData; $this->debug("found operation"); $this->appendDebug('opData=' . $this->varDump($opData)); if (isset($opData['soapAction'])) { $soapAction = $opData['soapAction']; } if (!$this->forceEndpoint) { $this->endpoint = $opData['endpoint']; } else { $this->endpoint = $this->forceEndpoint; } $namespace = isset($opData['input']['namespace']) ? $opData['input']['namespace'] : $namespace; $style = $opData['style']; $use = $opData['input']['use']; // add ns to ns array if ($namespace != '' && !isset($this->wsdl->namespaces[$namespace])) { $nsPrefix = 'ns' . rand(1000, 9999); $this->wsdl->namespaces[$nsPrefix] = $namespace; } $nsPrefix = $this->wsdl->getPrefixFromNamespace($namespace); // serialize payload if (is_string($params)) { $this->debug("serializing param string for WSDL operation $operation"); $payload = $params; } elseif (is_array($params)) { $this->debug("serializing param array for WSDL operation $operation"); $payload = $this->wsdl->serializeRPCParameters($operation, 'input', $params, $this->bindingType); } else { $this->debug('params must be array or string'); $this->setError('params must be array or string'); return FALSE; } $usedNamespaces = $this->wsdl->usedNamespaces; if (isset($opData['input']['encodingStyle'])) { $encodingStyle = $opData['input']['encodingStyle']; } else { $encodingStyle = ''; } $this->appendDebug($this->wsdl->getDebug()); $this->wsdl->clearDebug(); if ($errstr = $this->wsdl->getError()) { $this->debug('got wsdl error: ' . $errstr); $this->setError('wsdl error: ' . $errstr); return FALSE; } } elseif ($this->endpointType == 'wsdl') { // operation not in WSDL $this->appendDebug($this->wsdl->getDebug()); $this->wsdl->clearDebug(); $this->setError('operation ' . $operation . ' not present in WSDL.'); $this->debug("operation '$operation' not present in WSDL."); return FALSE; } else { // no WSDL //$this->namespaces['ns1'] = $namespace; $nsPrefix = 'ns' . rand(1000, 9999); // serialize $payload = ''; if (is_string($params)) { $this->debug("serializing param string for operation $operation"); $payload = $params; } elseif (is_array($params)) { $this->debug("serializing param array for operation $operation"); foreach ($params as $k => $v) { $payload .= $this->serialize_val($v, $k, FALSE, FALSE, FALSE, FALSE, $use); } } else { $this->debug('params must be array or string'); $this->setError('params must be array or string'); return FALSE; } $usedNamespaces = []; if ($use == 'encoded') { $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/'; } else { $encodingStyle = ''; } } // wrap RPC calls with method element if ($style == 'rpc') { if ($use == 'literal') { $this->debug("wrapping RPC request with literal method element"); if ($namespace) { // http://www.ws-i.org/Profiles/BasicProfile-1.1-2004-08-24.html R2735 says rpc/literal accessor elements should not be in a namespace $payload = "<$nsPrefix:$operation xmlns:$nsPrefix=\"$namespace\">" . $payload . "</$nsPrefix:$operation>"; } else { $payload = "<$operation>" . $payload . "</$operation>"; } } else { $this->debug("wrapping RPC request with encoded method element"); if ($namespace) { $payload = "<$nsPrefix:$operation xmlns:$nsPrefix=\"$namespace\">" . $payload . "</$nsPrefix:$operation>"; } else { $payload = "<$operation>" . $payload . "</$operation>"; } } } // serialize envelope $soapmsg = $this->serializeEnvelope($payload, $this->requestHeaders, $usedNamespaces, $style, $use, $encodingStyle); $this->debug("endpoint=$this->endpoint, soapAction=$soapAction, namespace=$namespace, style=$style, use=$use, encodingStyle=$encodingStyle"); $this->debug('SOAP message length=' . strlen($soapmsg) . ' contents (max 1000 bytes)=' . substr($soapmsg, 0, 1000)); // send $return = $this->send($this->getHTTPBody($soapmsg), $soapAction, $this->timeout, $this->response_timeout); if ($errstr = $this->getError()) { $this->debug('Error: ' . $errstr); return FALSE; } else { $this->return = $return; $this->debug('sent message successfully and got a(n) ' . gettype($return)); $this->appendDebug('return=' . $this->varDump($return)); // fault? if (is_array($return) && isset($return['faultcode'])) { $this->debug('got fault'); $this->setError($return['faultcode'] . ': ' . $return['faultstring']); $this->fault = TRUE; foreach ($return as $k => $v) { $this->$k = $v; if (is_array($v)) { $this->debug("$k = " . json_encode($v)); } else { $this->debug("$k = $v<br>"); } } return $return; } elseif ($style == 'document') { // NOTE: if the response is defined to have multiple parts (i.e. unwrapped), // we are only going to return the first part here...sorry about that return $return; } else { // array of return values if (is_array($return)) { // multiple 'out' parameters, which we return wrapped up // in the array if (sizeof($return) > 1) { return $return; } // single 'out' parameter (normally the return value) $return = array_shift($return); $this->debug('return shifted value: '); $this->appendDebug($this->varDump($return)); return $return; // nothing returned (ie, echoVoid) } else { return ""; } } } }
[ "function", "call", "(", "$", "operation", ",", "$", "params", "=", "[", "]", ",", "$", "namespace", "=", "'http://tempuri.org'", ",", "$", "soapAction", "=", "''", ",", "$", "headers", "=", "FALSE", ",", "$", "rpcParams", "=", "NULL", ",", "$", "style", "=", "'rpc'", ",", "$", "use", "=", "'encoded'", ")", "{", "$", "this", "->", "operation", "=", "$", "operation", ";", "$", "this", "->", "fault", "=", "FALSE", ";", "$", "this", "->", "setError", "(", "''", ")", ";", "$", "this", "->", "request", "=", "''", ";", "$", "this", "->", "response", "=", "''", ";", "$", "this", "->", "responseData", "=", "''", ";", "$", "this", "->", "faultstring", "=", "''", ";", "$", "this", "->", "faultcode", "=", "''", ";", "$", "this", "->", "opData", "=", "[", "]", ";", "$", "this", "->", "debug", "(", "\"call: operation=$operation, namespace=$namespace, soapAction=$soapAction, rpcParams=$rpcParams, style=$style, use=$use, endpointType=$this->endpointType\"", ")", ";", "$", "this", "->", "appendDebug", "(", "'params='", ".", "$", "this", "->", "varDump", "(", "$", "params", ")", ")", ";", "$", "this", "->", "appendDebug", "(", "'headers='", ".", "$", "this", "->", "varDump", "(", "$", "headers", ")", ")", ";", "if", "(", "$", "headers", ")", "{", "$", "this", "->", "requestHeaders", "=", "$", "headers", ";", "}", "if", "(", "$", "this", "->", "endpointType", "==", "'wsdl'", "&&", "is_null", "(", "$", "this", "->", "wsdl", ")", ")", "{", "$", "this", "->", "loadWSDL", "(", ")", ";", "if", "(", "$", "this", "->", "getError", "(", ")", ")", "{", "return", "FALSE", ";", "}", "}", "// serialize parameters", "if", "(", "$", "this", "->", "endpointType", "==", "'wsdl'", "&&", "$", "opData", "=", "$", "this", "->", "getOperationData", "(", "$", "operation", ")", ")", "{", "// use WSDL for operation", "$", "this", "->", "opData", "=", "$", "opData", ";", "$", "this", "->", "debug", "(", "\"found operation\"", ")", ";", "$", "this", "->", "appendDebug", "(", "'opData='", ".", "$", "this", "->", "varDump", "(", "$", "opData", ")", ")", ";", "if", "(", "isset", "(", "$", "opData", "[", "'soapAction'", "]", ")", ")", "{", "$", "soapAction", "=", "$", "opData", "[", "'soapAction'", "]", ";", "}", "if", "(", "!", "$", "this", "->", "forceEndpoint", ")", "{", "$", "this", "->", "endpoint", "=", "$", "opData", "[", "'endpoint'", "]", ";", "}", "else", "{", "$", "this", "->", "endpoint", "=", "$", "this", "->", "forceEndpoint", ";", "}", "$", "namespace", "=", "isset", "(", "$", "opData", "[", "'input'", "]", "[", "'namespace'", "]", ")", "?", "$", "opData", "[", "'input'", "]", "[", "'namespace'", "]", ":", "$", "namespace", ";", "$", "style", "=", "$", "opData", "[", "'style'", "]", ";", "$", "use", "=", "$", "opData", "[", "'input'", "]", "[", "'use'", "]", ";", "// add ns to ns array", "if", "(", "$", "namespace", "!=", "''", "&&", "!", "isset", "(", "$", "this", "->", "wsdl", "->", "namespaces", "[", "$", "namespace", "]", ")", ")", "{", "$", "nsPrefix", "=", "'ns'", ".", "rand", "(", "1000", ",", "9999", ")", ";", "$", "this", "->", "wsdl", "->", "namespaces", "[", "$", "nsPrefix", "]", "=", "$", "namespace", ";", "}", "$", "nsPrefix", "=", "$", "this", "->", "wsdl", "->", "getPrefixFromNamespace", "(", "$", "namespace", ")", ";", "// serialize payload", "if", "(", "is_string", "(", "$", "params", ")", ")", "{", "$", "this", "->", "debug", "(", "\"serializing param string for WSDL operation $operation\"", ")", ";", "$", "payload", "=", "$", "params", ";", "}", "elseif", "(", "is_array", "(", "$", "params", ")", ")", "{", "$", "this", "->", "debug", "(", "\"serializing param array for WSDL operation $operation\"", ")", ";", "$", "payload", "=", "$", "this", "->", "wsdl", "->", "serializeRPCParameters", "(", "$", "operation", ",", "'input'", ",", "$", "params", ",", "$", "this", "->", "bindingType", ")", ";", "}", "else", "{", "$", "this", "->", "debug", "(", "'params must be array or string'", ")", ";", "$", "this", "->", "setError", "(", "'params must be array or string'", ")", ";", "return", "FALSE", ";", "}", "$", "usedNamespaces", "=", "$", "this", "->", "wsdl", "->", "usedNamespaces", ";", "if", "(", "isset", "(", "$", "opData", "[", "'input'", "]", "[", "'encodingStyle'", "]", ")", ")", "{", "$", "encodingStyle", "=", "$", "opData", "[", "'input'", "]", "[", "'encodingStyle'", "]", ";", "}", "else", "{", "$", "encodingStyle", "=", "''", ";", "}", "$", "this", "->", "appendDebug", "(", "$", "this", "->", "wsdl", "->", "getDebug", "(", ")", ")", ";", "$", "this", "->", "wsdl", "->", "clearDebug", "(", ")", ";", "if", "(", "$", "errstr", "=", "$", "this", "->", "wsdl", "->", "getError", "(", ")", ")", "{", "$", "this", "->", "debug", "(", "'got wsdl error: '", ".", "$", "errstr", ")", ";", "$", "this", "->", "setError", "(", "'wsdl error: '", ".", "$", "errstr", ")", ";", "return", "FALSE", ";", "}", "}", "elseif", "(", "$", "this", "->", "endpointType", "==", "'wsdl'", ")", "{", "// operation not in WSDL", "$", "this", "->", "appendDebug", "(", "$", "this", "->", "wsdl", "->", "getDebug", "(", ")", ")", ";", "$", "this", "->", "wsdl", "->", "clearDebug", "(", ")", ";", "$", "this", "->", "setError", "(", "'operation '", ".", "$", "operation", ".", "' not present in WSDL.'", ")", ";", "$", "this", "->", "debug", "(", "\"operation '$operation' not present in WSDL.\"", ")", ";", "return", "FALSE", ";", "}", "else", "{", "// no WSDL", "//$this->namespaces['ns1'] = $namespace;", "$", "nsPrefix", "=", "'ns'", ".", "rand", "(", "1000", ",", "9999", ")", ";", "// serialize", "$", "payload", "=", "''", ";", "if", "(", "is_string", "(", "$", "params", ")", ")", "{", "$", "this", "->", "debug", "(", "\"serializing param string for operation $operation\"", ")", ";", "$", "payload", "=", "$", "params", ";", "}", "elseif", "(", "is_array", "(", "$", "params", ")", ")", "{", "$", "this", "->", "debug", "(", "\"serializing param array for operation $operation\"", ")", ";", "foreach", "(", "$", "params", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "payload", ".=", "$", "this", "->", "serialize_val", "(", "$", "v", ",", "$", "k", ",", "FALSE", ",", "FALSE", ",", "FALSE", ",", "FALSE", ",", "$", "use", ")", ";", "}", "}", "else", "{", "$", "this", "->", "debug", "(", "'params must be array or string'", ")", ";", "$", "this", "->", "setError", "(", "'params must be array or string'", ")", ";", "return", "FALSE", ";", "}", "$", "usedNamespaces", "=", "[", "]", ";", "if", "(", "$", "use", "==", "'encoded'", ")", "{", "$", "encodingStyle", "=", "'http://schemas.xmlsoap.org/soap/encoding/'", ";", "}", "else", "{", "$", "encodingStyle", "=", "''", ";", "}", "}", "// wrap RPC calls with method element", "if", "(", "$", "style", "==", "'rpc'", ")", "{", "if", "(", "$", "use", "==", "'literal'", ")", "{", "$", "this", "->", "debug", "(", "\"wrapping RPC request with literal method element\"", ")", ";", "if", "(", "$", "namespace", ")", "{", "// http://www.ws-i.org/Profiles/BasicProfile-1.1-2004-08-24.html R2735 says rpc/literal accessor elements should not be in a namespace", "$", "payload", "=", "\"<$nsPrefix:$operation xmlns:$nsPrefix=\\\"$namespace\\\">\"", ".", "$", "payload", ".", "\"</$nsPrefix:$operation>\"", ";", "}", "else", "{", "$", "payload", "=", "\"<$operation>\"", ".", "$", "payload", ".", "\"</$operation>\"", ";", "}", "}", "else", "{", "$", "this", "->", "debug", "(", "\"wrapping RPC request with encoded method element\"", ")", ";", "if", "(", "$", "namespace", ")", "{", "$", "payload", "=", "\"<$nsPrefix:$operation xmlns:$nsPrefix=\\\"$namespace\\\">\"", ".", "$", "payload", ".", "\"</$nsPrefix:$operation>\"", ";", "}", "else", "{", "$", "payload", "=", "\"<$operation>\"", ".", "$", "payload", ".", "\"</$operation>\"", ";", "}", "}", "}", "// serialize envelope", "$", "soapmsg", "=", "$", "this", "->", "serializeEnvelope", "(", "$", "payload", ",", "$", "this", "->", "requestHeaders", ",", "$", "usedNamespaces", ",", "$", "style", ",", "$", "use", ",", "$", "encodingStyle", ")", ";", "$", "this", "->", "debug", "(", "\"endpoint=$this->endpoint, soapAction=$soapAction, namespace=$namespace, style=$style, use=$use, encodingStyle=$encodingStyle\"", ")", ";", "$", "this", "->", "debug", "(", "'SOAP message length='", ".", "strlen", "(", "$", "soapmsg", ")", ".", "' contents (max 1000 bytes)='", ".", "substr", "(", "$", "soapmsg", ",", "0", ",", "1000", ")", ")", ";", "// send", "$", "return", "=", "$", "this", "->", "send", "(", "$", "this", "->", "getHTTPBody", "(", "$", "soapmsg", ")", ",", "$", "soapAction", ",", "$", "this", "->", "timeout", ",", "$", "this", "->", "response_timeout", ")", ";", "if", "(", "$", "errstr", "=", "$", "this", "->", "getError", "(", ")", ")", "{", "$", "this", "->", "debug", "(", "'Error: '", ".", "$", "errstr", ")", ";", "return", "FALSE", ";", "}", "else", "{", "$", "this", "->", "return", "=", "$", "return", ";", "$", "this", "->", "debug", "(", "'sent message successfully and got a(n) '", ".", "gettype", "(", "$", "return", ")", ")", ";", "$", "this", "->", "appendDebug", "(", "'return='", ".", "$", "this", "->", "varDump", "(", "$", "return", ")", ")", ";", "// fault?", "if", "(", "is_array", "(", "$", "return", ")", "&&", "isset", "(", "$", "return", "[", "'faultcode'", "]", ")", ")", "{", "$", "this", "->", "debug", "(", "'got fault'", ")", ";", "$", "this", "->", "setError", "(", "$", "return", "[", "'faultcode'", "]", ".", "': '", ".", "$", "return", "[", "'faultstring'", "]", ")", ";", "$", "this", "->", "fault", "=", "TRUE", ";", "foreach", "(", "$", "return", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "this", "->", "$", "k", "=", "$", "v", ";", "if", "(", "is_array", "(", "$", "v", ")", ")", "{", "$", "this", "->", "debug", "(", "\"$k = \"", ".", "json_encode", "(", "$", "v", ")", ")", ";", "}", "else", "{", "$", "this", "->", "debug", "(", "\"$k = $v<br>\"", ")", ";", "}", "}", "return", "$", "return", ";", "}", "elseif", "(", "$", "style", "==", "'document'", ")", "{", "// NOTE: if the response is defined to have multiple parts (i.e. unwrapped),", "// we are only going to return the first part here...sorry about that", "return", "$", "return", ";", "}", "else", "{", "// array of return values", "if", "(", "is_array", "(", "$", "return", ")", ")", "{", "// multiple 'out' parameters, which we return wrapped up", "// in the array", "if", "(", "sizeof", "(", "$", "return", ")", ">", "1", ")", "{", "return", "$", "return", ";", "}", "// single 'out' parameter (normally the return value)", "$", "return", "=", "array_shift", "(", "$", "return", ")", ";", "$", "this", "->", "debug", "(", "'return shifted value: '", ")", ";", "$", "this", "->", "appendDebug", "(", "$", "this", "->", "varDump", "(", "$", "return", ")", ")", ";", "return", "$", "return", ";", "// nothing returned (ie, echoVoid)", "}", "else", "{", "return", "\"\"", ";", "}", "}", "}", "}" ]
calls method, returns PHP native type @param string $operation SOAP server URL or path @param mixed $params An array, associative or simple, of the parameters for the method call, or a string that is the XML for the call. For rpc style, this call will wrap the XML in a tag named after the method, as well as the SOAP Envelope and Body. For document style, this will only wrap with the Envelope and Body. IMPORTANT: when using an array with document style, in which case there is really one parameter, the root of the fragment used in the call, which encloses what programmers normally think of parameters. A parameter array *must* include the wrapper. @param string $namespace optional method namespace (WSDL can override) @param string $soapAction optional SOAPAction value (WSDL can override) @param mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array @param boolean $rpcParams optional (no longer used) @param string $style optional (rpc|document) the style to use when serializing parameters (WSDL can override) @param string $use optional (encoded|literal) the use when serializing parameters (WSDL can override) @return mixed response from SOAP call, normally an associative array mirroring the structure of the XML response, false for certain fatal errors @access public
[ "calls", "method", "returns", "PHP", "native", "type" ]
train
https://github.com/nguyenanhung/nusoap/blob/a9b4d98f4f3fe748f8e5d9f8091dfc53585d2556/src-fix/nusoap.php#L7710-L7900
nguyenanhung/nusoap
src-fix/nusoap.php
nusoap_client.parseResponse
function parseResponse($headers, $data) { $this->debug('Entering parseResponse() for data of length ' . strlen($data) . ' headers:'); $this->appendDebug($this->varDump($headers)); if (!isset($headers['content-type'])) { $this->setError('Response not of type text/xml (no content-type header)'); return FALSE; } if (!strstr($headers['content-type'], 'text/xml')) { $this->setError('Response not of type text/xml: ' . $headers['content-type']); return FALSE; } if (strpos($headers['content-type'], '=')) { $enc = str_replace('"', '', substr(strstr($headers["content-type"], '='), 1)); $this->debug('Got response encoding: ' . $enc); if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) { $this->xml_encoding = strtoupper($enc); } else { $this->xml_encoding = 'US-ASCII'; } } else { // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1 $this->xml_encoding = 'ISO-8859-1'; } $this->debug('Use encoding: ' . $this->xml_encoding . ' when creating nusoap_parser'); $parser = new nusoap_parser($data, $this->xml_encoding, $this->operations, $this->decode_utf8); // add parser debug data to our debug $this->appendDebug($parser->getDebug()); // if parse errors if ($errstr = $parser->getError()) { $this->setError($errstr); // destroy the parser object unset($parser); return FALSE; } else { // get SOAP headers $this->responseHeaders = $parser->getHeaders(); // get SOAP headers $this->responseHeader = $parser->get_soapheader(); // get decoded message $return = $parser->get_soapbody(); // add document for doclit support $this->document = $parser->document; // destroy the parser object unset($parser); // return decode message return $return; } }
php
function parseResponse($headers, $data) { $this->debug('Entering parseResponse() for data of length ' . strlen($data) . ' headers:'); $this->appendDebug($this->varDump($headers)); if (!isset($headers['content-type'])) { $this->setError('Response not of type text/xml (no content-type header)'); return FALSE; } if (!strstr($headers['content-type'], 'text/xml')) { $this->setError('Response not of type text/xml: ' . $headers['content-type']); return FALSE; } if (strpos($headers['content-type'], '=')) { $enc = str_replace('"', '', substr(strstr($headers["content-type"], '='), 1)); $this->debug('Got response encoding: ' . $enc); if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) { $this->xml_encoding = strtoupper($enc); } else { $this->xml_encoding = 'US-ASCII'; } } else { // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1 $this->xml_encoding = 'ISO-8859-1'; } $this->debug('Use encoding: ' . $this->xml_encoding . ' when creating nusoap_parser'); $parser = new nusoap_parser($data, $this->xml_encoding, $this->operations, $this->decode_utf8); // add parser debug data to our debug $this->appendDebug($parser->getDebug()); // if parse errors if ($errstr = $parser->getError()) { $this->setError($errstr); // destroy the parser object unset($parser); return FALSE; } else { // get SOAP headers $this->responseHeaders = $parser->getHeaders(); // get SOAP headers $this->responseHeader = $parser->get_soapheader(); // get decoded message $return = $parser->get_soapbody(); // add document for doclit support $this->document = $parser->document; // destroy the parser object unset($parser); // return decode message return $return; } }
[ "function", "parseResponse", "(", "$", "headers", ",", "$", "data", ")", "{", "$", "this", "->", "debug", "(", "'Entering parseResponse() for data of length '", ".", "strlen", "(", "$", "data", ")", ".", "' headers:'", ")", ";", "$", "this", "->", "appendDebug", "(", "$", "this", "->", "varDump", "(", "$", "headers", ")", ")", ";", "if", "(", "!", "isset", "(", "$", "headers", "[", "'content-type'", "]", ")", ")", "{", "$", "this", "->", "setError", "(", "'Response not of type text/xml (no content-type header)'", ")", ";", "return", "FALSE", ";", "}", "if", "(", "!", "strstr", "(", "$", "headers", "[", "'content-type'", "]", ",", "'text/xml'", ")", ")", "{", "$", "this", "->", "setError", "(", "'Response not of type text/xml: '", ".", "$", "headers", "[", "'content-type'", "]", ")", ";", "return", "FALSE", ";", "}", "if", "(", "strpos", "(", "$", "headers", "[", "'content-type'", "]", ",", "'='", ")", ")", "{", "$", "enc", "=", "str_replace", "(", "'\"'", ",", "''", ",", "substr", "(", "strstr", "(", "$", "headers", "[", "\"content-type\"", "]", ",", "'='", ")", ",", "1", ")", ")", ";", "$", "this", "->", "debug", "(", "'Got response encoding: '", ".", "$", "enc", ")", ";", "if", "(", "preg_match", "(", "'/^(ISO-8859-1|US-ASCII|UTF-8)$/i'", ",", "$", "enc", ")", ")", "{", "$", "this", "->", "xml_encoding", "=", "strtoupper", "(", "$", "enc", ")", ";", "}", "else", "{", "$", "this", "->", "xml_encoding", "=", "'US-ASCII'", ";", "}", "}", "else", "{", "// should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1", "$", "this", "->", "xml_encoding", "=", "'ISO-8859-1'", ";", "}", "$", "this", "->", "debug", "(", "'Use encoding: '", ".", "$", "this", "->", "xml_encoding", ".", "' when creating nusoap_parser'", ")", ";", "$", "parser", "=", "new", "nusoap_parser", "(", "$", "data", ",", "$", "this", "->", "xml_encoding", ",", "$", "this", "->", "operations", ",", "$", "this", "->", "decode_utf8", ")", ";", "// add parser debug data to our debug", "$", "this", "->", "appendDebug", "(", "$", "parser", "->", "getDebug", "(", ")", ")", ";", "// if parse errors", "if", "(", "$", "errstr", "=", "$", "parser", "->", "getError", "(", ")", ")", "{", "$", "this", "->", "setError", "(", "$", "errstr", ")", ";", "// destroy the parser object", "unset", "(", "$", "parser", ")", ";", "return", "FALSE", ";", "}", "else", "{", "// get SOAP headers", "$", "this", "->", "responseHeaders", "=", "$", "parser", "->", "getHeaders", "(", ")", ";", "// get SOAP headers", "$", "this", "->", "responseHeader", "=", "$", "parser", "->", "get_soapheader", "(", ")", ";", "// get decoded message", "$", "return", "=", "$", "parser", "->", "get_soapbody", "(", ")", ";", "// add document for doclit support", "$", "this", "->", "document", "=", "$", "parser", "->", "document", ";", "// destroy the parser object", "unset", "(", "$", "parser", ")", ";", "// return decode message", "return", "$", "return", ";", "}", "}" ]
processes SOAP message returned from server @param array $headers The HTTP headers @param string $data unprocessed response data from server @return mixed value of the message, decoded into a PHP type @access private
[ "processes", "SOAP", "message", "returned", "from", "server" ]
train
https://github.com/nguyenanhung/nusoap/blob/a9b4d98f4f3fe748f8e5d9f8091dfc53585d2556/src-fix/nusoap.php#L8072-L8124
nguyenanhung/nusoap
src-fix/nusoap.php
nusoap_client.getProxy
function getProxy() { $r = rand(); $evalStr = $this->_getProxyClassCode($r); //$this->debug("proxy class: $evalStr"); if ($this->getError()) { $this->debug("Error from _getProxyClassCode, so return null"); return NULL; } // eval the class eval($evalStr); // instantiate proxy object eval("\$proxy = new nusoap_proxy_$r('');"); // transfer current wsdl data to the proxy thereby avoiding parsing the wsdl twice $proxy->endpointType = 'wsdl'; $proxy->wsdlFile = $this->wsdlFile; $proxy->wsdl = $this->wsdl; $proxy->operations = $this->operations; $proxy->defaultRpcParams = $this->defaultRpcParams; // transfer other state $proxy->soap_defencoding = $this->soap_defencoding; $proxy->username = $this->username; $proxy->password = $this->password; $proxy->authtype = $this->authtype; $proxy->certRequest = $this->certRequest; $proxy->requestHeaders = $this->requestHeaders; $proxy->endpoint = $this->endpoint; $proxy->forceEndpoint = $this->forceEndpoint; $proxy->proxyhost = $this->proxyhost; $proxy->proxyport = $this->proxyport; $proxy->proxyusername = $this->proxyusername; $proxy->proxypassword = $this->proxypassword; $proxy->http_encoding = $this->http_encoding; $proxy->timeout = $this->timeout; $proxy->response_timeout = $this->response_timeout; $proxy->persistentConnection = &$this->persistentConnection; $proxy->decode_utf8 = $this->decode_utf8; $proxy->curl_options = $this->curl_options; $proxy->bindingType = $this->bindingType; $proxy->use_curl = $this->use_curl; return $proxy; }
php
function getProxy() { $r = rand(); $evalStr = $this->_getProxyClassCode($r); //$this->debug("proxy class: $evalStr"); if ($this->getError()) { $this->debug("Error from _getProxyClassCode, so return null"); return NULL; } // eval the class eval($evalStr); // instantiate proxy object eval("\$proxy = new nusoap_proxy_$r('');"); // transfer current wsdl data to the proxy thereby avoiding parsing the wsdl twice $proxy->endpointType = 'wsdl'; $proxy->wsdlFile = $this->wsdlFile; $proxy->wsdl = $this->wsdl; $proxy->operations = $this->operations; $proxy->defaultRpcParams = $this->defaultRpcParams; // transfer other state $proxy->soap_defencoding = $this->soap_defencoding; $proxy->username = $this->username; $proxy->password = $this->password; $proxy->authtype = $this->authtype; $proxy->certRequest = $this->certRequest; $proxy->requestHeaders = $this->requestHeaders; $proxy->endpoint = $this->endpoint; $proxy->forceEndpoint = $this->forceEndpoint; $proxy->proxyhost = $this->proxyhost; $proxy->proxyport = $this->proxyport; $proxy->proxyusername = $this->proxyusername; $proxy->proxypassword = $this->proxypassword; $proxy->http_encoding = $this->http_encoding; $proxy->timeout = $this->timeout; $proxy->response_timeout = $this->response_timeout; $proxy->persistentConnection = &$this->persistentConnection; $proxy->decode_utf8 = $this->decode_utf8; $proxy->curl_options = $this->curl_options; $proxy->bindingType = $this->bindingType; $proxy->use_curl = $this->use_curl; return $proxy; }
[ "function", "getProxy", "(", ")", "{", "$", "r", "=", "rand", "(", ")", ";", "$", "evalStr", "=", "$", "this", "->", "_getProxyClassCode", "(", "$", "r", ")", ";", "//$this->debug(\"proxy class: $evalStr\");", "if", "(", "$", "this", "->", "getError", "(", ")", ")", "{", "$", "this", "->", "debug", "(", "\"Error from _getProxyClassCode, so return null\"", ")", ";", "return", "NULL", ";", "}", "// eval the class", "eval", "(", "$", "evalStr", ")", ";", "// instantiate proxy object", "eval", "(", "\"\\$proxy = new nusoap_proxy_$r('');\"", ")", ";", "// transfer current wsdl data to the proxy thereby avoiding parsing the wsdl twice", "$", "proxy", "->", "endpointType", "=", "'wsdl'", ";", "$", "proxy", "->", "wsdlFile", "=", "$", "this", "->", "wsdlFile", ";", "$", "proxy", "->", "wsdl", "=", "$", "this", "->", "wsdl", ";", "$", "proxy", "->", "operations", "=", "$", "this", "->", "operations", ";", "$", "proxy", "->", "defaultRpcParams", "=", "$", "this", "->", "defaultRpcParams", ";", "// transfer other state", "$", "proxy", "->", "soap_defencoding", "=", "$", "this", "->", "soap_defencoding", ";", "$", "proxy", "->", "username", "=", "$", "this", "->", "username", ";", "$", "proxy", "->", "password", "=", "$", "this", "->", "password", ";", "$", "proxy", "->", "authtype", "=", "$", "this", "->", "authtype", ";", "$", "proxy", "->", "certRequest", "=", "$", "this", "->", "certRequest", ";", "$", "proxy", "->", "requestHeaders", "=", "$", "this", "->", "requestHeaders", ";", "$", "proxy", "->", "endpoint", "=", "$", "this", "->", "endpoint", ";", "$", "proxy", "->", "forceEndpoint", "=", "$", "this", "->", "forceEndpoint", ";", "$", "proxy", "->", "proxyhost", "=", "$", "this", "->", "proxyhost", ";", "$", "proxy", "->", "proxyport", "=", "$", "this", "->", "proxyport", ";", "$", "proxy", "->", "proxyusername", "=", "$", "this", "->", "proxyusername", ";", "$", "proxy", "->", "proxypassword", "=", "$", "this", "->", "proxypassword", ";", "$", "proxy", "->", "http_encoding", "=", "$", "this", "->", "http_encoding", ";", "$", "proxy", "->", "timeout", "=", "$", "this", "->", "timeout", ";", "$", "proxy", "->", "response_timeout", "=", "$", "this", "->", "response_timeout", ";", "$", "proxy", "->", "persistentConnection", "=", "&", "$", "this", "->", "persistentConnection", ";", "$", "proxy", "->", "decode_utf8", "=", "$", "this", "->", "decode_utf8", ";", "$", "proxy", "->", "curl_options", "=", "$", "this", "->", "curl_options", ";", "$", "proxy", "->", "bindingType", "=", "$", "this", "->", "bindingType", ";", "$", "proxy", "->", "use_curl", "=", "$", "this", "->", "use_curl", ";", "return", "$", "proxy", ";", "}" ]
dynamically creates an instance of a proxy class, allowing user to directly call methods from wsdl @return object soap_proxy object @access public
[ "dynamically", "creates", "an", "instance", "of", "a", "proxy", "class", "allowing", "user", "to", "directly", "call", "methods", "from", "wsdl" ]
train
https://github.com/nguyenanhung/nusoap/blob/a9b4d98f4f3fe748f8e5d9f8091dfc53585d2556/src-fix/nusoap.php#L8306-L8349
nguyenanhung/nusoap
src-fix/nusoap.php
nusoap_client._getProxyClassCode
function _getProxyClassCode($r) { $this->debug("in getProxy endpointType=$this->endpointType"); $this->appendDebug("wsdl=" . $this->varDump($this->wsdl)); if ($this->endpointType != 'wsdl') { $evalStr = 'A proxy can only be created for a WSDL client'; $this->setError($evalStr); $evalStr = "echo \"$evalStr\";"; return $evalStr; } if ($this->endpointType == 'wsdl' && is_null($this->wsdl)) { $this->loadWSDL(); if ($this->getError()) { return "echo \"" . $this->getError() . "\";"; } } $evalStr = ''; foreach ($this->operations as $operation => $opData) { if ($operation != '') { // create param string and param comment string if (sizeof($opData['input']['parts']) > 0) { $paramStr = ''; $paramArrayStr = ''; $paramCommentStr = ''; foreach ($opData['input']['parts'] as $name => $type) { $paramStr .= "\$$name, "; $paramArrayStr .= "'$name' => \$$name, "; $paramCommentStr .= "$type \$$name, "; } $paramStr = substr($paramStr, 0, strlen($paramStr) - 2); $paramArrayStr = substr($paramArrayStr, 0, strlen($paramArrayStr) - 2); $paramCommentStr = substr($paramCommentStr, 0, strlen($paramCommentStr) - 2); } else { $paramStr = ''; $paramArrayStr = ''; $paramCommentStr = 'void'; } $opData['namespace'] = !isset($opData['namespace']) ? 'http://testuri.com' : $opData['namespace']; $evalStr .= "// $paramCommentStr function " . str_replace('.', '__', $operation) . "($paramStr) { \$params = array($paramArrayStr); return \$this->call('$operation', \$params, '" . $opData['namespace'] . "', '" . (isset($opData['soapAction']) ? $opData['soapAction'] : '') . "'); } "; unset($paramStr); unset($paramCommentStr); } } $evalStr = 'class nusoap_proxy_' . $r . ' extends nusoap_client { ' . $evalStr . ' }'; return $evalStr; }
php
function _getProxyClassCode($r) { $this->debug("in getProxy endpointType=$this->endpointType"); $this->appendDebug("wsdl=" . $this->varDump($this->wsdl)); if ($this->endpointType != 'wsdl') { $evalStr = 'A proxy can only be created for a WSDL client'; $this->setError($evalStr); $evalStr = "echo \"$evalStr\";"; return $evalStr; } if ($this->endpointType == 'wsdl' && is_null($this->wsdl)) { $this->loadWSDL(); if ($this->getError()) { return "echo \"" . $this->getError() . "\";"; } } $evalStr = ''; foreach ($this->operations as $operation => $opData) { if ($operation != '') { // create param string and param comment string if (sizeof($opData['input']['parts']) > 0) { $paramStr = ''; $paramArrayStr = ''; $paramCommentStr = ''; foreach ($opData['input']['parts'] as $name => $type) { $paramStr .= "\$$name, "; $paramArrayStr .= "'$name' => \$$name, "; $paramCommentStr .= "$type \$$name, "; } $paramStr = substr($paramStr, 0, strlen($paramStr) - 2); $paramArrayStr = substr($paramArrayStr, 0, strlen($paramArrayStr) - 2); $paramCommentStr = substr($paramCommentStr, 0, strlen($paramCommentStr) - 2); } else { $paramStr = ''; $paramArrayStr = ''; $paramCommentStr = 'void'; } $opData['namespace'] = !isset($opData['namespace']) ? 'http://testuri.com' : $opData['namespace']; $evalStr .= "// $paramCommentStr function " . str_replace('.', '__', $operation) . "($paramStr) { \$params = array($paramArrayStr); return \$this->call('$operation', \$params, '" . $opData['namespace'] . "', '" . (isset($opData['soapAction']) ? $opData['soapAction'] : '') . "'); } "; unset($paramStr); unset($paramCommentStr); } } $evalStr = 'class nusoap_proxy_' . $r . ' extends nusoap_client { ' . $evalStr . ' }'; return $evalStr; }
[ "function", "_getProxyClassCode", "(", "$", "r", ")", "{", "$", "this", "->", "debug", "(", "\"in getProxy endpointType=$this->endpointType\"", ")", ";", "$", "this", "->", "appendDebug", "(", "\"wsdl=\"", ".", "$", "this", "->", "varDump", "(", "$", "this", "->", "wsdl", ")", ")", ";", "if", "(", "$", "this", "->", "endpointType", "!=", "'wsdl'", ")", "{", "$", "evalStr", "=", "'A proxy can only be created for a WSDL client'", ";", "$", "this", "->", "setError", "(", "$", "evalStr", ")", ";", "$", "evalStr", "=", "\"echo \\\"$evalStr\\\";\"", ";", "return", "$", "evalStr", ";", "}", "if", "(", "$", "this", "->", "endpointType", "==", "'wsdl'", "&&", "is_null", "(", "$", "this", "->", "wsdl", ")", ")", "{", "$", "this", "->", "loadWSDL", "(", ")", ";", "if", "(", "$", "this", "->", "getError", "(", ")", ")", "{", "return", "\"echo \\\"\"", ".", "$", "this", "->", "getError", "(", ")", ".", "\"\\\";\"", ";", "}", "}", "$", "evalStr", "=", "''", ";", "foreach", "(", "$", "this", "->", "operations", "as", "$", "operation", "=>", "$", "opData", ")", "{", "if", "(", "$", "operation", "!=", "''", ")", "{", "// create param string and param comment string", "if", "(", "sizeof", "(", "$", "opData", "[", "'input'", "]", "[", "'parts'", "]", ")", ">", "0", ")", "{", "$", "paramStr", "=", "''", ";", "$", "paramArrayStr", "=", "''", ";", "$", "paramCommentStr", "=", "''", ";", "foreach", "(", "$", "opData", "[", "'input'", "]", "[", "'parts'", "]", "as", "$", "name", "=>", "$", "type", ")", "{", "$", "paramStr", ".=", "\"\\$$name, \"", ";", "$", "paramArrayStr", ".=", "\"'$name' => \\$$name, \"", ";", "$", "paramCommentStr", ".=", "\"$type \\$$name, \"", ";", "}", "$", "paramStr", "=", "substr", "(", "$", "paramStr", ",", "0", ",", "strlen", "(", "$", "paramStr", ")", "-", "2", ")", ";", "$", "paramArrayStr", "=", "substr", "(", "$", "paramArrayStr", ",", "0", ",", "strlen", "(", "$", "paramArrayStr", ")", "-", "2", ")", ";", "$", "paramCommentStr", "=", "substr", "(", "$", "paramCommentStr", ",", "0", ",", "strlen", "(", "$", "paramCommentStr", ")", "-", "2", ")", ";", "}", "else", "{", "$", "paramStr", "=", "''", ";", "$", "paramArrayStr", "=", "''", ";", "$", "paramCommentStr", "=", "'void'", ";", "}", "$", "opData", "[", "'namespace'", "]", "=", "!", "isset", "(", "$", "opData", "[", "'namespace'", "]", ")", "?", "'http://testuri.com'", ":", "$", "opData", "[", "'namespace'", "]", ";", "$", "evalStr", ".=", "\"// $paramCommentStr\n\tfunction \"", ".", "str_replace", "(", "'.'", ",", "'__'", ",", "$", "operation", ")", ".", "\"($paramStr) {\n\t\t\\$params = array($paramArrayStr);\n\t\treturn \\$this->call('$operation', \\$params, '\"", ".", "$", "opData", "[", "'namespace'", "]", ".", "\"', '\"", ".", "(", "isset", "(", "$", "opData", "[", "'soapAction'", "]", ")", "?", "$", "opData", "[", "'soapAction'", "]", ":", "''", ")", ".", "\"');\n\t}\n\t\"", ";", "unset", "(", "$", "paramStr", ")", ";", "unset", "(", "$", "paramCommentStr", ")", ";", "}", "}", "$", "evalStr", "=", "'class nusoap_proxy_'", ".", "$", "r", ".", "' extends nusoap_client {\n\t'", ".", "$", "evalStr", ".", "'\n}'", ";", "return", "$", "evalStr", ";", "}" ]
dynamically creates proxy class code @return string PHP/NuSOAP code for the proxy class @access private
[ "dynamically", "creates", "proxy", "class", "code" ]
train
https://github.com/nguyenanhung/nusoap/blob/a9b4d98f4f3fe748f8e5d9f8091dfc53585d2556/src-fix/nusoap.php#L8357-L8411
ruvents/ruwork-upload-bundle
Form/Type/UploadType.php
UploadType.buildForm
public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add(self::FILE, $options['file_type'], ['mapped' => false] + $options['file_options']) ->setDataMapper(new UploadMapper( $this->manager, $this->savers, self::FILE, self::PATH, $options['factory'], $options['finder'], $options['saver'], $builder->getDataMapper() )) ->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void { $this->addPath($event->getForm(), $event->getData()); }) ->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) use ($options): void { $form = $event->getForm()->remove(self::PATH); $this->addPath($form, $event->getData()); }); }
php
public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add(self::FILE, $options['file_type'], ['mapped' => false] + $options['file_options']) ->setDataMapper(new UploadMapper( $this->manager, $this->savers, self::FILE, self::PATH, $options['factory'], $options['finder'], $options['saver'], $builder->getDataMapper() )) ->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void { $this->addPath($event->getForm(), $event->getData()); }) ->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) use ($options): void { $form = $event->getForm()->remove(self::PATH); $this->addPath($form, $event->getData()); }); }
[ "public", "function", "buildForm", "(", "FormBuilderInterface", "$", "builder", ",", "array", "$", "options", ")", "{", "$", "builder", "->", "add", "(", "self", "::", "FILE", ",", "$", "options", "[", "'file_type'", "]", ",", "[", "'mapped'", "=>", "false", "]", "+", "$", "options", "[", "'file_options'", "]", ")", "->", "setDataMapper", "(", "new", "UploadMapper", "(", "$", "this", "->", "manager", ",", "$", "this", "->", "savers", ",", "self", "::", "FILE", ",", "self", "::", "PATH", ",", "$", "options", "[", "'factory'", "]", ",", "$", "options", "[", "'finder'", "]", ",", "$", "options", "[", "'saver'", "]", ",", "$", "builder", "->", "getDataMapper", "(", ")", ")", ")", "->", "addEventListener", "(", "FormEvents", "::", "PRE_SET_DATA", ",", "function", "(", "FormEvent", "$", "event", ")", ":", "void", "{", "$", "this", "->", "addPath", "(", "$", "event", "->", "getForm", "(", ")", ",", "$", "event", "->", "getData", "(", ")", ")", ";", "}", ")", "->", "addEventListener", "(", "FormEvents", "::", "SUBMIT", ",", "function", "(", "FormEvent", "$", "event", ")", "use", "(", "$", "options", ")", ":", "void", "{", "$", "form", "=", "$", "event", "->", "getForm", "(", ")", "->", "remove", "(", "self", "::", "PATH", ")", ";", "$", "this", "->", "addPath", "(", "$", "form", ",", "$", "event", "->", "getData", "(", ")", ")", ";", "}", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/ruvents/ruwork-upload-bundle/blob/8ad09cc2dce6ab389105c440d791346696da43af/Form/Type/UploadType.php#L37-L58
ruvents/ruwork-upload-bundle
Form/Type/UploadType.php
UploadType.configureOptions
public function configureOptions(OptionsResolver $resolver): void { $resolver ->setRequired([ 'class', 'finder', ]) ->setDefaults([ 'empty_data' => null, 'error_bubbling' => false, 'factory' => function (Options $options): callable { $class = $options['class']; return function () use ($class) { return new $class(); }; }, 'file_type' => FileType::class, 'file_options' => [], 'saver' => null, ]) ->setAllowedTypes('class', 'string') ->setAllowedTypes('factory', 'callable') ->setAllowedTypes('file_options', 'array') ->setAllowedTypes('file_type', 'string') ->setAllowedTypes('finder', 'callable') ->setAllowedTypes('saver', ['null', 'callable']); }
php
public function configureOptions(OptionsResolver $resolver): void { $resolver ->setRequired([ 'class', 'finder', ]) ->setDefaults([ 'empty_data' => null, 'error_bubbling' => false, 'factory' => function (Options $options): callable { $class = $options['class']; return function () use ($class) { return new $class(); }; }, 'file_type' => FileType::class, 'file_options' => [], 'saver' => null, ]) ->setAllowedTypes('class', 'string') ->setAllowedTypes('factory', 'callable') ->setAllowedTypes('file_options', 'array') ->setAllowedTypes('file_type', 'string') ->setAllowedTypes('finder', 'callable') ->setAllowedTypes('saver', ['null', 'callable']); }
[ "public", "function", "configureOptions", "(", "OptionsResolver", "$", "resolver", ")", ":", "void", "{", "$", "resolver", "->", "setRequired", "(", "[", "'class'", ",", "'finder'", ",", "]", ")", "->", "setDefaults", "(", "[", "'empty_data'", "=>", "null", ",", "'error_bubbling'", "=>", "false", ",", "'factory'", "=>", "function", "(", "Options", "$", "options", ")", ":", "callable", "{", "$", "class", "=", "$", "options", "[", "'class'", "]", ";", "return", "function", "(", ")", "use", "(", "$", "class", ")", "{", "return", "new", "$", "class", "(", ")", ";", "}", ";", "}", ",", "'file_type'", "=>", "FileType", "::", "class", ",", "'file_options'", "=>", "[", "]", ",", "'saver'", "=>", "null", ",", "]", ")", "->", "setAllowedTypes", "(", "'class'", ",", "'string'", ")", "->", "setAllowedTypes", "(", "'factory'", ",", "'callable'", ")", "->", "setAllowedTypes", "(", "'file_options'", ",", "'array'", ")", "->", "setAllowedTypes", "(", "'file_type'", ",", "'string'", ")", "->", "setAllowedTypes", "(", "'finder'", ",", "'callable'", ")", "->", "setAllowedTypes", "(", "'saver'", ",", "[", "'null'", ",", "'callable'", "]", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/ruvents/ruwork-upload-bundle/blob/8ad09cc2dce6ab389105c440d791346696da43af/Form/Type/UploadType.php#L63-L90
yuncms/framework
src/user/migrations/m180411_035330_create_rbac_table.php
m180411_035330_create_rbac_table.safeUp
public function safeUp() { $tableOptions = null; if ($this->db->driverName === 'mysql') { // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB'; } $this->createTable('{{%user_auth_rule}}', [ 'name' => $this->string(64)->notNull()->unique(), 'data' => $this->text(), 'created_at' => $this->unixTimestamp(), 'updated_at' => $this->unixTimestamp() ], $tableOptions); $this->createTable('{{%user_auth_item}}', [ 'name' => $this->string(64)->notNull()->unique(), 'type' => $this->integer()->notNull(), 'description' => $this->text(), 'rule_name' => $this->string(64), 'data' => $this->text(), 'created_at' => $this->unixTimestamp(), 'updated_at' => $this->unixTimestamp(), ], $tableOptions); $this->createIndex('idx-auth_item-type', '{{%user_auth_item}}', 'type'); $this->addForeignKey('user_auth_item_fk_1', '{{%user_auth_item}}', 'rule_name', '{{%user_auth_rule}}', 'name', 'SET NULL', 'CASCADE'); $this->createTable('{{%user_auth_item_child}}', [ 'parent' => $this->string(64)->notNull(), 'child' => $this->string(64)->notNull(), ], $tableOptions); $this->addPrimaryKey('user_auth_item_child_pk', '{{%user_auth_item_child}}', ['parent', 'child']); $this->addForeignKey('user_auth_item_child_fk_1', '{{%user_auth_item_child}}', 'parent', '{{%user_auth_item}}', 'name', 'CASCADE', 'CASCADE'); $this->addForeignKey('user_auth_item_child_fk_2', '{{%user_auth_item_child}}', 'child', '{{%user_auth_item}}', 'name', 'CASCADE', 'CASCADE'); $this->createTable('{{%user_auth_assignment}}', [ 'item_name' => $this->string(64)->notNull(), 'user_id' => $this->string(64)->notNull(), 'created_at' => $this->unixTimestamp(), ], $tableOptions); $this->addPrimaryKey('', '{{%user_auth_assignment}}', ['item_name', 'user_id']); $this->addForeignKey('user_auth_assignment_fk_1', '{{%user_auth_assignment}}', 'item_name', '{{%user_auth_item}}', 'name', 'CASCADE', 'CASCADE'); $time = time(); $this->batchInsert('{{%user_auth_item}}', ['name', 'type', 'created_at', 'updated_at'], [ ['受限会员', 1, $time, $time], ['注册会员', 1, $time, $time], ]); }
php
public function safeUp() { $tableOptions = null; if ($this->db->driverName === 'mysql') { // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB'; } $this->createTable('{{%user_auth_rule}}', [ 'name' => $this->string(64)->notNull()->unique(), 'data' => $this->text(), 'created_at' => $this->unixTimestamp(), 'updated_at' => $this->unixTimestamp() ], $tableOptions); $this->createTable('{{%user_auth_item}}', [ 'name' => $this->string(64)->notNull()->unique(), 'type' => $this->integer()->notNull(), 'description' => $this->text(), 'rule_name' => $this->string(64), 'data' => $this->text(), 'created_at' => $this->unixTimestamp(), 'updated_at' => $this->unixTimestamp(), ], $tableOptions); $this->createIndex('idx-auth_item-type', '{{%user_auth_item}}', 'type'); $this->addForeignKey('user_auth_item_fk_1', '{{%user_auth_item}}', 'rule_name', '{{%user_auth_rule}}', 'name', 'SET NULL', 'CASCADE'); $this->createTable('{{%user_auth_item_child}}', [ 'parent' => $this->string(64)->notNull(), 'child' => $this->string(64)->notNull(), ], $tableOptions); $this->addPrimaryKey('user_auth_item_child_pk', '{{%user_auth_item_child}}', ['parent', 'child']); $this->addForeignKey('user_auth_item_child_fk_1', '{{%user_auth_item_child}}', 'parent', '{{%user_auth_item}}', 'name', 'CASCADE', 'CASCADE'); $this->addForeignKey('user_auth_item_child_fk_2', '{{%user_auth_item_child}}', 'child', '{{%user_auth_item}}', 'name', 'CASCADE', 'CASCADE'); $this->createTable('{{%user_auth_assignment}}', [ 'item_name' => $this->string(64)->notNull(), 'user_id' => $this->string(64)->notNull(), 'created_at' => $this->unixTimestamp(), ], $tableOptions); $this->addPrimaryKey('', '{{%user_auth_assignment}}', ['item_name', 'user_id']); $this->addForeignKey('user_auth_assignment_fk_1', '{{%user_auth_assignment}}', 'item_name', '{{%user_auth_item}}', 'name', 'CASCADE', 'CASCADE'); $time = time(); $this->batchInsert('{{%user_auth_item}}', ['name', 'type', 'created_at', 'updated_at'], [ ['受限会员', 1, $time, $time], ['注册会员', 1, $time, $time], ]); }
[ "public", "function", "safeUp", "(", ")", "{", "$", "tableOptions", "=", "null", ";", "if", "(", "$", "this", "->", "db", "->", "driverName", "===", "'mysql'", ")", "{", "// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci", "$", "tableOptions", "=", "'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB'", ";", "}", "$", "this", "->", "createTable", "(", "'{{%user_auth_rule}}'", ",", "[", "'name'", "=>", "$", "this", "->", "string", "(", "64", ")", "->", "notNull", "(", ")", "->", "unique", "(", ")", ",", "'data'", "=>", "$", "this", "->", "text", "(", ")", ",", "'created_at'", "=>", "$", "this", "->", "unixTimestamp", "(", ")", ",", "'updated_at'", "=>", "$", "this", "->", "unixTimestamp", "(", ")", "]", ",", "$", "tableOptions", ")", ";", "$", "this", "->", "createTable", "(", "'{{%user_auth_item}}'", ",", "[", "'name'", "=>", "$", "this", "->", "string", "(", "64", ")", "->", "notNull", "(", ")", "->", "unique", "(", ")", ",", "'type'", "=>", "$", "this", "->", "integer", "(", ")", "->", "notNull", "(", ")", ",", "'description'", "=>", "$", "this", "->", "text", "(", ")", ",", "'rule_name'", "=>", "$", "this", "->", "string", "(", "64", ")", ",", "'data'", "=>", "$", "this", "->", "text", "(", ")", ",", "'created_at'", "=>", "$", "this", "->", "unixTimestamp", "(", ")", ",", "'updated_at'", "=>", "$", "this", "->", "unixTimestamp", "(", ")", ",", "]", ",", "$", "tableOptions", ")", ";", "$", "this", "->", "createIndex", "(", "'idx-auth_item-type'", ",", "'{{%user_auth_item}}'", ",", "'type'", ")", ";", "$", "this", "->", "addForeignKey", "(", "'user_auth_item_fk_1'", ",", "'{{%user_auth_item}}'", ",", "'rule_name'", ",", "'{{%user_auth_rule}}'", ",", "'name'", ",", "'SET NULL'", ",", "'CASCADE'", ")", ";", "$", "this", "->", "createTable", "(", "'{{%user_auth_item_child}}'", ",", "[", "'parent'", "=>", "$", "this", "->", "string", "(", "64", ")", "->", "notNull", "(", ")", ",", "'child'", "=>", "$", "this", "->", "string", "(", "64", ")", "->", "notNull", "(", ")", ",", "]", ",", "$", "tableOptions", ")", ";", "$", "this", "->", "addPrimaryKey", "(", "'user_auth_item_child_pk'", ",", "'{{%user_auth_item_child}}'", ",", "[", "'parent'", ",", "'child'", "]", ")", ";", "$", "this", "->", "addForeignKey", "(", "'user_auth_item_child_fk_1'", ",", "'{{%user_auth_item_child}}'", ",", "'parent'", ",", "'{{%user_auth_item}}'", ",", "'name'", ",", "'CASCADE'", ",", "'CASCADE'", ")", ";", "$", "this", "->", "addForeignKey", "(", "'user_auth_item_child_fk_2'", ",", "'{{%user_auth_item_child}}'", ",", "'child'", ",", "'{{%user_auth_item}}'", ",", "'name'", ",", "'CASCADE'", ",", "'CASCADE'", ")", ";", "$", "this", "->", "createTable", "(", "'{{%user_auth_assignment}}'", ",", "[", "'item_name'", "=>", "$", "this", "->", "string", "(", "64", ")", "->", "notNull", "(", ")", ",", "'user_id'", "=>", "$", "this", "->", "string", "(", "64", ")", "->", "notNull", "(", ")", ",", "'created_at'", "=>", "$", "this", "->", "unixTimestamp", "(", ")", ",", "]", ",", "$", "tableOptions", ")", ";", "$", "this", "->", "addPrimaryKey", "(", "''", ",", "'{{%user_auth_assignment}}'", ",", "[", "'item_name'", ",", "'user_id'", "]", ")", ";", "$", "this", "->", "addForeignKey", "(", "'user_auth_assignment_fk_1'", ",", "'{{%user_auth_assignment}}'", ",", "'item_name'", ",", "'{{%user_auth_item}}'", ",", "'name'", ",", "'CASCADE'", ",", "'CASCADE'", ")", ";", "$", "time", "=", "time", "(", ")", ";", "$", "this", "->", "batchInsert", "(", "'{{%user_auth_item}}'", ",", "[", "'name'", ",", "'type'", ",", "'created_at'", ",", "'updated_at'", "]", ",", "[", "[", "'受限会员', 1, $ti", "m", ",", " ", "t", "ime]", ",", "", "", "", "", "[", "'注册会员', 1, $ti", "m", ",", " ", "t", "ime]", ",", "", "", "", "", "]", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/user/migrations/m180411_035330_create_rbac_table.php#L13-L60
webforge-labs/psc-cms
lib/Psc/Form/ComponentsValidator.php
ComponentsValidator.validateSet
public function validateSet() { $this->validatedComponents = array(); // jede Componente nur einmal validieren, wir führen buch $exceptions = array(); foreach ($this->components as $component) { try { $this->validateComponent($component); } catch (ValidatorException $e) { if ($this->exceptionList) { $exceptions[] = $e; } else { throw $e; } } } if ($this->exceptionList && count($exceptions) > 0) { throw new ValidatorExceptionList($exceptions); } $this->postValidation(); return $this; }
php
public function validateSet() { $this->validatedComponents = array(); // jede Componente nur einmal validieren, wir führen buch $exceptions = array(); foreach ($this->components as $component) { try { $this->validateComponent($component); } catch (ValidatorException $e) { if ($this->exceptionList) { $exceptions[] = $e; } else { throw $e; } } } if ($this->exceptionList && count($exceptions) > 0) { throw new ValidatorExceptionList($exceptions); } $this->postValidation(); return $this; }
[ "public", "function", "validateSet", "(", ")", "{", "$", "this", "->", "validatedComponents", "=", "array", "(", ")", ";", "// jede Componente nur einmal validieren, wir führen buch", "$", "exceptions", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "components", "as", "$", "component", ")", "{", "try", "{", "$", "this", "->", "validateComponent", "(", "$", "component", ")", ";", "}", "catch", "(", "ValidatorException", "$", "e", ")", "{", "if", "(", "$", "this", "->", "exceptionList", ")", "{", "$", "exceptions", "[", "]", "=", "$", "e", ";", "}", "else", "{", "throw", "$", "e", ";", "}", "}", "}", "if", "(", "$", "this", "->", "exceptionList", "&&", "count", "(", "$", "exceptions", ")", ">", "0", ")", "{", "throw", "new", "ValidatorExceptionList", "(", "$", "exceptions", ")", ";", "}", "$", "this", "->", "postValidation", "(", ")", ";", "return", "$", "this", ";", "}" ]
Validiert alle Daten anhand der Meta-Daten von den FormDaten optionals müssen hiervor gesetzt werden wenn $this->exceptionList TRUE ist werden die ValidationExceptions gesammelt und dann eine ValidatorExceptionList geworfen wenn FALSE wird direkt die erste ValidatorException geworfen
[ "Validiert", "alle", "Daten", "anhand", "der", "Meta", "-", "Daten", "von", "den", "FormDaten" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Form/ComponentsValidator.php#L67-L89
PortaText/php-sdk
src/PortaText/Command/Base.php
Base.getBody
protected function getBody($method) { $file = $this->getArgument("file"); if (!is_null($file)) { return "file:$file"; } if (count($this->getArguments($method)) > 0) { return json_encode($this->getArguments($method)); } return ""; }
php
protected function getBody($method) { $file = $this->getArgument("file"); if (!is_null($file)) { return "file:$file"; } if (count($this->getArguments($method)) > 0) { return json_encode($this->getArguments($method)); } return ""; }
[ "protected", "function", "getBody", "(", "$", "method", ")", "{", "$", "file", "=", "$", "this", "->", "getArgument", "(", "\"file\"", ")", ";", "if", "(", "!", "is_null", "(", "$", "file", ")", ")", "{", "return", "\"file:$file\"", ";", "}", "if", "(", "count", "(", "$", "this", "->", "getArguments", "(", "$", "method", ")", ")", ">", "0", ")", "{", "return", "json_encode", "(", "$", "this", "->", "getArguments", "(", "$", "method", ")", ")", ";", "}", "return", "\"\"", ";", "}" ]
Returns the body for this endpoint. @param string $method Method for this command. @return string
[ "Returns", "the", "body", "for", "this", "endpoint", "." ]
train
https://github.com/PortaText/php-sdk/blob/dbe04ef043db5b251953f9de57aa4d0f1785dfcc/src/PortaText/Command/Base.php#L96-L106
PortaText/php-sdk
src/PortaText/Command/Base.php
Base.getContentType
protected function getContentType($method) { // Just to make PHPMD happy. $method = null; $file = $this->getArgument("file"); if (!is_null($file)) { return "text/csv"; } $soundFile = $this->getArgument("sound_file"); if (!is_null($soundFile)) { return "audio/mpeg"; } return 'application/json'; }
php
protected function getContentType($method) { // Just to make PHPMD happy. $method = null; $file = $this->getArgument("file"); if (!is_null($file)) { return "text/csv"; } $soundFile = $this->getArgument("sound_file"); if (!is_null($soundFile)) { return "audio/mpeg"; } return 'application/json'; }
[ "protected", "function", "getContentType", "(", "$", "method", ")", "{", "// Just to make PHPMD happy.", "$", "method", "=", "null", ";", "$", "file", "=", "$", "this", "->", "getArgument", "(", "\"file\"", ")", ";", "if", "(", "!", "is_null", "(", "$", "file", ")", ")", "{", "return", "\"text/csv\"", ";", "}", "$", "soundFile", "=", "$", "this", "->", "getArgument", "(", "\"sound_file\"", ")", ";", "if", "(", "!", "is_null", "(", "$", "soundFile", ")", ")", "{", "return", "\"audio/mpeg\"", ";", "}", "return", "'application/json'", ";", "}" ]
Returns the content type for this endpoint. @param string $method Method for this command. @return string
[ "Returns", "the", "content", "type", "for", "this", "endpoint", "." ]
train
https://github.com/PortaText/php-sdk/blob/dbe04ef043db5b251953f9de57aa4d0f1785dfcc/src/PortaText/Command/Base.php#L115-L128
PortaText/php-sdk
src/PortaText/Command/Base.php
Base.getAcceptContentType
protected function getAcceptContentType($method) { // Just to make PHPMD happy. $method = null; $acceptFile = $this->getArgument("accept_file"); if (!is_null($acceptFile)) { return "text/csv"; } $acceptAnyFile = $this->getArgument("accept_any_file"); if (!is_null($acceptAnyFile)) { return "*/*"; } $acceptSoundFile = $this->getArgument("accept_sound_file"); if (!is_null($acceptSoundFile)) { return "audio/mpeg"; } return 'application/json'; }
php
protected function getAcceptContentType($method) { // Just to make PHPMD happy. $method = null; $acceptFile = $this->getArgument("accept_file"); if (!is_null($acceptFile)) { return "text/csv"; } $acceptAnyFile = $this->getArgument("accept_any_file"); if (!is_null($acceptAnyFile)) { return "*/*"; } $acceptSoundFile = $this->getArgument("accept_sound_file"); if (!is_null($acceptSoundFile)) { return "audio/mpeg"; } return 'application/json'; }
[ "protected", "function", "getAcceptContentType", "(", "$", "method", ")", "{", "// Just to make PHPMD happy.", "$", "method", "=", "null", ";", "$", "acceptFile", "=", "$", "this", "->", "getArgument", "(", "\"accept_file\"", ")", ";", "if", "(", "!", "is_null", "(", "$", "acceptFile", ")", ")", "{", "return", "\"text/csv\"", ";", "}", "$", "acceptAnyFile", "=", "$", "this", "->", "getArgument", "(", "\"accept_any_file\"", ")", ";", "if", "(", "!", "is_null", "(", "$", "acceptAnyFile", ")", ")", "{", "return", "\"*/*\"", ";", "}", "$", "acceptSoundFile", "=", "$", "this", "->", "getArgument", "(", "\"accept_sound_file\"", ")", ";", "if", "(", "!", "is_null", "(", "$", "acceptSoundFile", ")", ")", "{", "return", "\"audio/mpeg\"", ";", "}", "return", "'application/json'", ";", "}" ]
Returns the accepted content type for this endpoint. @param string $method Method for this command. @return string
[ "Returns", "the", "accepted", "content", "type", "for", "this", "endpoint", "." ]
train
https://github.com/PortaText/php-sdk/blob/dbe04ef043db5b251953f9de57aa4d0f1785dfcc/src/PortaText/Command/Base.php#L137-L154
PortaText/php-sdk
src/PortaText/Command/Base.php
Base.run
protected function run($method) { $endpoint = $this->getEndpoint($method); $outputFile = $this->getArgument('accept_file'); if (is_null($outputFile)) { $outputFile = $this->getArgument('accept_any_file'); } if (is_null($outputFile)) { $outputFile = $this->getArgument('accept_sound_file'); } $cType = $this->getContentType($method); $aCType = $this->getAcceptContentType($method); $this->delArgument('accept_file'); $this->delArgument('accept_any_file'); $this->delArgument('accept_sound_file'); $body = $this->getBody($method); return $this->client->run( $endpoint, $method, $cType, $aCType, $body, $outputFile ); }
php
protected function run($method) { $endpoint = $this->getEndpoint($method); $outputFile = $this->getArgument('accept_file'); if (is_null($outputFile)) { $outputFile = $this->getArgument('accept_any_file'); } if (is_null($outputFile)) { $outputFile = $this->getArgument('accept_sound_file'); } $cType = $this->getContentType($method); $aCType = $this->getAcceptContentType($method); $this->delArgument('accept_file'); $this->delArgument('accept_any_file'); $this->delArgument('accept_sound_file'); $body = $this->getBody($method); return $this->client->run( $endpoint, $method, $cType, $aCType, $body, $outputFile ); }
[ "protected", "function", "run", "(", "$", "method", ")", "{", "$", "endpoint", "=", "$", "this", "->", "getEndpoint", "(", "$", "method", ")", ";", "$", "outputFile", "=", "$", "this", "->", "getArgument", "(", "'accept_file'", ")", ";", "if", "(", "is_null", "(", "$", "outputFile", ")", ")", "{", "$", "outputFile", "=", "$", "this", "->", "getArgument", "(", "'accept_any_file'", ")", ";", "}", "if", "(", "is_null", "(", "$", "outputFile", ")", ")", "{", "$", "outputFile", "=", "$", "this", "->", "getArgument", "(", "'accept_sound_file'", ")", ";", "}", "$", "cType", "=", "$", "this", "->", "getContentType", "(", "$", "method", ")", ";", "$", "aCType", "=", "$", "this", "->", "getAcceptContentType", "(", "$", "method", ")", ";", "$", "this", "->", "delArgument", "(", "'accept_file'", ")", ";", "$", "this", "->", "delArgument", "(", "'accept_any_file'", ")", ";", "$", "this", "->", "delArgument", "(", "'accept_sound_file'", ")", ";", "$", "body", "=", "$", "this", "->", "getBody", "(", "$", "method", ")", ";", "return", "$", "this", "->", "client", "->", "run", "(", "$", "endpoint", ",", "$", "method", ",", "$", "cType", ",", "$", "aCType", ",", "$", "body", ",", "$", "outputFile", ")", ";", "}" ]
Runs this command with the given method and returns the result. @param string $method HTTP Method to use. @return PortaText\Command\ICommand @throws PortaText\Exception\RequestError
[ "Runs", "this", "command", "with", "the", "given", "method", "and", "returns", "the", "result", "." ]
train
https://github.com/PortaText/php-sdk/blob/dbe04ef043db5b251953f9de57aa4d0f1785dfcc/src/PortaText/Command/Base.php#L219-L243
seeruo/framework
src/Service/GitService.php
Git._cmd
private function _cmd($cmd) { $path = str_replace("\\","/\\", $this->_path); $cmd = "cd ".$path." && ".$cmd; $last_line = system($cmd, $retval); $this->_writeLog( $retval ); return $last_line; }
php
private function _cmd($cmd) { $path = str_replace("\\","/\\", $this->_path); $cmd = "cd ".$path." && ".$cmd; $last_line = system($cmd, $retval); $this->_writeLog( $retval ); return $last_line; }
[ "private", "function", "_cmd", "(", "$", "cmd", ")", "{", "$", "path", "=", "str_replace", "(", "\"\\\\\"", ",", "\"/\\\\\"", ",", "$", "this", "->", "_path", ")", ";", "$", "cmd", "=", "\"cd \"", ".", "$", "path", ".", "\" && \"", ".", "$", "cmd", ";", "$", "last_line", "=", "system", "(", "$", "cmd", ",", "$", "retval", ")", ";", "$", "this", "->", "_writeLog", "(", "$", "retval", ")", ";", "return", "$", "last_line", ";", "}" ]
/* 运行命令行 该方法可以运行命令行, 并会自动记录命令行日志 @param string $cmd 要运行的命令行 @return boolen
[ "/", "*", "运行命令行", "该方法可以运行命令行", "并会自动记录命令行日志" ]
train
https://github.com/seeruo/framework/blob/689c6e95bc95fe2ae037e056d8228820dd08d7e9/src/Service/GitService.php#L67-L73
seeruo/framework
src/Service/GitService.php
Git._writeLog
private function _writeLog($msg) { $log = "-------------------------------------\n"; $log .= date('Y-m-d H:i:s') . ":\n"; $log .= $msg."\n"; $log .= "-------------------------------------\n"; file_put_contents($this->_output, $log, FILE_APPEND | LOCK_EX); }
php
private function _writeLog($msg) { $log = "-------------------------------------\n"; $log .= date('Y-m-d H:i:s') . ":\n"; $log .= $msg."\n"; $log .= "-------------------------------------\n"; file_put_contents($this->_output, $log, FILE_APPEND | LOCK_EX); }
[ "private", "function", "_writeLog", "(", "$", "msg", ")", "{", "$", "log", "=", "\"-------------------------------------\\n\"", ";", "$", "log", ".=", "date", "(", "'Y-m-d H:i:s'", ")", ".", "\":\\n\"", ";", "$", "log", ".=", "$", "msg", ".", "\"\\n\"", ";", "$", "log", ".=", "\"-------------------------------------\\n\"", ";", "file_put_contents", "(", "$", "this", "->", "_output", ",", "$", "log", ",", "FILE_APPEND", "|", "LOCK_EX", ")", ";", "}" ]
记录日志 @param string $string [日志内容] @return [type] [description]
[ "记录日志" ]
train
https://github.com/seeruo/framework/blob/689c6e95bc95fe2ae037e056d8228820dd08d7e9/src/Service/GitService.php#L79-L85
onigoetz/imagecache
src/Manager.php
Manager.getOriginalFile
public function getOriginalFile($source_file) { $original_file = $this->options['path_local'] . '/' . $source_file; if (!is_file($original_file)) { throw new Exceptions\NotFoundException('File not found'); } return $original_file; }
php
public function getOriginalFile($source_file) { $original_file = $this->options['path_local'] . '/' . $source_file; if (!is_file($original_file)) { throw new Exceptions\NotFoundException('File not found'); } return $original_file; }
[ "public", "function", "getOriginalFile", "(", "$", "source_file", ")", "{", "$", "original_file", "=", "$", "this", "->", "options", "[", "'path_local'", "]", ".", "'/'", ".", "$", "source_file", ";", "if", "(", "!", "is_file", "(", "$", "original_file", ")", ")", "{", "throw", "new", "Exceptions", "\\", "NotFoundException", "(", "'File not found'", ")", ";", "}", "return", "$", "original_file", ";", "}" ]
The path to the original file @param $source_file @return string @throws Exceptions\NotFoundException
[ "The", "path", "to", "the", "original", "file" ]
train
https://github.com/onigoetz/imagecache/blob/8e22c11def1733819183e8296bab3c8a4ffc1d9c/src/Manager.php#L128-L136
onigoetz/imagecache
src/Manager.php
Manager.handleRequest
public function handleRequest($preset_key, $file) { //do it at the beginning for early validation $preset = $this->getPresetActions($preset_key, $file); $source_file = $this->getOriginalFilename($file); $original_file = $this->getOriginalFile($source_file); $final_file = $this->localUrl($preset_key, $file); $this->verifyDirectoryExistence($this->options['path_local'], dirname($final_file)); $final_file = $this->options['path_local'] . '/' . $final_file; if (file_exists($final_file)) { return $final_file; } $image = $this->loadImage($original_file); return $this->buildImage($preset, $image, $final_file)->source; }
php
public function handleRequest($preset_key, $file) { //do it at the beginning for early validation $preset = $this->getPresetActions($preset_key, $file); $source_file = $this->getOriginalFilename($file); $original_file = $this->getOriginalFile($source_file); $final_file = $this->localUrl($preset_key, $file); $this->verifyDirectoryExistence($this->options['path_local'], dirname($final_file)); $final_file = $this->options['path_local'] . '/' . $final_file; if (file_exists($final_file)) { return $final_file; } $image = $this->loadImage($original_file); return $this->buildImage($preset, $image, $final_file)->source; }
[ "public", "function", "handleRequest", "(", "$", "preset_key", ",", "$", "file", ")", "{", "//do it at the beginning for early validation", "$", "preset", "=", "$", "this", "->", "getPresetActions", "(", "$", "preset_key", ",", "$", "file", ")", ";", "$", "source_file", "=", "$", "this", "->", "getOriginalFilename", "(", "$", "file", ")", ";", "$", "original_file", "=", "$", "this", "->", "getOriginalFile", "(", "$", "source_file", ")", ";", "$", "final_file", "=", "$", "this", "->", "localUrl", "(", "$", "preset_key", ",", "$", "file", ")", ";", "$", "this", "->", "verifyDirectoryExistence", "(", "$", "this", "->", "options", "[", "'path_local'", "]", ",", "dirname", "(", "$", "final_file", ")", ")", ";", "$", "final_file", "=", "$", "this", "->", "options", "[", "'path_local'", "]", ".", "'/'", ".", "$", "final_file", ";", "if", "(", "file_exists", "(", "$", "final_file", ")", ")", "{", "return", "$", "final_file", ";", "}", "$", "image", "=", "$", "this", "->", "loadImage", "(", "$", "original_file", ")", ";", "return", "$", "this", "->", "buildImage", "(", "$", "preset", ",", "$", "image", ",", "$", "final_file", ")", "->", "source", ";", "}" ]
Take a preset and a file and return a transformed image @param $preset_key string @param $file string @throws Exceptions\InvalidPresetException @throws Exceptions\NotFoundException @throws \RuntimeException @return string
[ "Take", "a", "preset", "and", "a", "file", "and", "return", "a", "transformed", "image" ]
train
https://github.com/onigoetz/imagecache/blob/8e22c11def1733819183e8296bab3c8a4ffc1d9c/src/Manager.php#L148-L170
onigoetz/imagecache
src/Manager.php
Manager.verifyDirectoryExistence
protected function verifyDirectoryExistence($base, $cacheDir) { if (is_dir("$base/$cacheDir")) { return; } $folder_path = explode('/', $cacheDir); foreach ($folder_path as $element) { $base .= '/' . $element; if (!is_dir($base)) { mkdir($base, 0755, true); chmod($base, 0755); } } }
php
protected function verifyDirectoryExistence($base, $cacheDir) { if (is_dir("$base/$cacheDir")) { return; } $folder_path = explode('/', $cacheDir); foreach ($folder_path as $element) { $base .= '/' . $element; if (!is_dir($base)) { mkdir($base, 0755, true); chmod($base, 0755); } } }
[ "protected", "function", "verifyDirectoryExistence", "(", "$", "base", ",", "$", "cacheDir", ")", "{", "if", "(", "is_dir", "(", "\"$base/$cacheDir\"", ")", ")", "{", "return", ";", "}", "$", "folder_path", "=", "explode", "(", "'/'", ",", "$", "cacheDir", ")", ";", "foreach", "(", "$", "folder_path", "as", "$", "element", ")", "{", "$", "base", ".=", "'/'", ".", "$", "element", ";", "if", "(", "!", "is_dir", "(", "$", "base", ")", ")", "{", "mkdir", "(", "$", "base", ",", "0755", ",", "true", ")", ";", "chmod", "(", "$", "base", ",", "0755", ")", ";", "}", "}", "}" ]
Create the folder containing the cached images if it doesn't exist @param $base @param $cacheDir
[ "Create", "the", "folder", "containing", "the", "cached", "images", "if", "it", "doesn", "t", "exist" ]
train
https://github.com/onigoetz/imagecache/blob/8e22c11def1733819183e8296bab3c8a4ffc1d9c/src/Manager.php#L178-L192
onigoetz/imagecache
src/Manager.php
Manager.buildImage
protected function buildImage($actions, Image $image, $dst) { foreach ($actions as $action) { // Make sure the width and height are computed first so they can be used // in relative x/yoffsets like 'center' or 'bottom'. if (isset($action['width'])) { $action['width'] = $this->percent($action['width'], $image->getWidth()); } if (isset($action['height'])) { $action['height'] = $this->percent($action['height'], $image->getHeight()); } if (isset($action['xoffset'])) { $action['xoffset'] = $this->keywords($action['xoffset'], $image->getWidth(), $action['width']); } if (isset($action['yoffset'])) { $action['yoffset'] = $this->keywords($action['yoffset'], $image->getHeight(), $action['height']); } $this->getMethodCaller()->call($image, $action['action'], $action); } return $image->save($dst); }
php
protected function buildImage($actions, Image $image, $dst) { foreach ($actions as $action) { // Make sure the width and height are computed first so they can be used // in relative x/yoffsets like 'center' or 'bottom'. if (isset($action['width'])) { $action['width'] = $this->percent($action['width'], $image->getWidth()); } if (isset($action['height'])) { $action['height'] = $this->percent($action['height'], $image->getHeight()); } if (isset($action['xoffset'])) { $action['xoffset'] = $this->keywords($action['xoffset'], $image->getWidth(), $action['width']); } if (isset($action['yoffset'])) { $action['yoffset'] = $this->keywords($action['yoffset'], $image->getHeight(), $action['height']); } $this->getMethodCaller()->call($image, $action['action'], $action); } return $image->save($dst); }
[ "protected", "function", "buildImage", "(", "$", "actions", ",", "Image", "$", "image", ",", "$", "dst", ")", "{", "foreach", "(", "$", "actions", "as", "$", "action", ")", "{", "// Make sure the width and height are computed first so they can be used", "// in relative x/yoffsets like 'center' or 'bottom'.", "if", "(", "isset", "(", "$", "action", "[", "'width'", "]", ")", ")", "{", "$", "action", "[", "'width'", "]", "=", "$", "this", "->", "percent", "(", "$", "action", "[", "'width'", "]", ",", "$", "image", "->", "getWidth", "(", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "action", "[", "'height'", "]", ")", ")", "{", "$", "action", "[", "'height'", "]", "=", "$", "this", "->", "percent", "(", "$", "action", "[", "'height'", "]", ",", "$", "image", "->", "getHeight", "(", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "action", "[", "'xoffset'", "]", ")", ")", "{", "$", "action", "[", "'xoffset'", "]", "=", "$", "this", "->", "keywords", "(", "$", "action", "[", "'xoffset'", "]", ",", "$", "image", "->", "getWidth", "(", ")", ",", "$", "action", "[", "'width'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "action", "[", "'yoffset'", "]", ")", ")", "{", "$", "action", "[", "'yoffset'", "]", "=", "$", "this", "->", "keywords", "(", "$", "action", "[", "'yoffset'", "]", ",", "$", "image", "->", "getHeight", "(", ")", ",", "$", "action", "[", "'height'", "]", ")", ";", "}", "$", "this", "->", "getMethodCaller", "(", ")", "->", "call", "(", "$", "image", ",", "$", "action", "[", "'action'", "]", ",", "$", "action", ")", ";", "}", "return", "$", "image", "->", "save", "(", "$", "dst", ")", ";", "}" ]
Create a new image based on an image preset. @param array $actions An image preset array. @param Image $image Path of the source file. @param string $dst Path of the destination file. @throws \RuntimeException @return Image
[ "Create", "a", "new", "image", "based", "on", "an", "image", "preset", "." ]
train
https://github.com/onigoetz/imagecache/blob/8e22c11def1733819183e8296bab3c8a4ffc1d9c/src/Manager.php#L208-L233
onigoetz/imagecache
src/Manager.php
Manager.percent
public function percent($value, $current_pixels) { if (strpos($value, '%') !== false) { $value = str_replace('%', '', $value) * 0.01 * $current_pixels; } return $value; }
php
public function percent($value, $current_pixels) { if (strpos($value, '%') !== false) { $value = str_replace('%', '', $value) * 0.01 * $current_pixels; } return $value; }
[ "public", "function", "percent", "(", "$", "value", ",", "$", "current_pixels", ")", "{", "if", "(", "strpos", "(", "$", "value", ",", "'%'", ")", "!==", "false", ")", "{", "$", "value", "=", "str_replace", "(", "'%'", ",", "''", ",", "$", "value", ")", "*", "0.01", "*", "$", "current_pixels", ";", "}", "return", "$", "value", ";", "}" ]
Accept a percentage and return it in pixels. @param string $value @param int $current_pixels @return mixed
[ "Accept", "a", "percentage", "and", "return", "it", "in", "pixels", "." ]
train
https://github.com/onigoetz/imagecache/blob/8e22c11def1733819183e8296bab3c8a4ffc1d9c/src/Manager.php#L242-L249
onigoetz/imagecache
src/Manager.php
Manager.keywords
public function keywords($value, $current_pixels, $new_pixels) { switch ($value) { case 'top': case 'left': $value = 0; break; case 'bottom': case 'right': $value = $current_pixels - $new_pixels; break; case 'center': $value = $current_pixels / 2 - $new_pixels / 2; break; } return $value; }
php
public function keywords($value, $current_pixels, $new_pixels) { switch ($value) { case 'top': case 'left': $value = 0; break; case 'bottom': case 'right': $value = $current_pixels - $new_pixels; break; case 'center': $value = $current_pixels / 2 - $new_pixels / 2; break; } return $value; }
[ "public", "function", "keywords", "(", "$", "value", ",", "$", "current_pixels", ",", "$", "new_pixels", ")", "{", "switch", "(", "$", "value", ")", "{", "case", "'top'", ":", "case", "'left'", ":", "$", "value", "=", "0", ";", "break", ";", "case", "'bottom'", ":", "case", "'right'", ":", "$", "value", "=", "$", "current_pixels", "-", "$", "new_pixels", ";", "break", ";", "case", "'center'", ":", "$", "value", "=", "$", "current_pixels", "/", "2", "-", "$", "new_pixels", "/", "2", ";", "break", ";", "}", "return", "$", "value", ";", "}" ]
Accept a keyword (center, top, left, etc) and return it as an offset in pixels. @param $value @param $current_pixels @param $new_pixels @return float|int
[ "Accept", "a", "keyword", "(", "center", "top", "left", "etc", ")", "and", "return", "it", "as", "an", "offset", "in", "pixels", "." ]
train
https://github.com/onigoetz/imagecache/blob/8e22c11def1733819183e8296bab3c8a4ffc1d9c/src/Manager.php#L259-L276
CakeCMS/Core
src/ORM/Behavior/ProcessBehavior.php
ProcessBehavior.process
public function process($name, array $ids = []) { $allowActions = $this->getConfig('actions'); if (!Arr::key($name, $allowActions)) { throw new \InvalidArgumentException(__d('core', 'Invalid action to perform')); } $action = $allowActions[$name]; if ($action === false) { throw new \InvalidArgumentException(__d('core', 'Action "{0}" is disabled', $name)); } if (Arr::in($action, get_class_methods($this->_table))) { return $this->_table->{$action}($ids); } return $this->{$action}($ids); }
php
public function process($name, array $ids = []) { $allowActions = $this->getConfig('actions'); if (!Arr::key($name, $allowActions)) { throw new \InvalidArgumentException(__d('core', 'Invalid action to perform')); } $action = $allowActions[$name]; if ($action === false) { throw new \InvalidArgumentException(__d('core', 'Action "{0}" is disabled', $name)); } if (Arr::in($action, get_class_methods($this->_table))) { return $this->_table->{$action}($ids); } return $this->{$action}($ids); }
[ "public", "function", "process", "(", "$", "name", ",", "array", "$", "ids", "=", "[", "]", ")", "{", "$", "allowActions", "=", "$", "this", "->", "getConfig", "(", "'actions'", ")", ";", "if", "(", "!", "Arr", "::", "key", "(", "$", "name", ",", "$", "allowActions", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "__d", "(", "'core'", ",", "'Invalid action to perform'", ")", ")", ";", "}", "$", "action", "=", "$", "allowActions", "[", "$", "name", "]", ";", "if", "(", "$", "action", "===", "false", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "__d", "(", "'core'", ",", "'Action \"{0}\" is disabled'", ",", "$", "name", ")", ")", ";", "}", "if", "(", "Arr", "::", "in", "(", "$", "action", ",", "get_class_methods", "(", "$", "this", "->", "_table", ")", ")", ")", "{", "return", "$", "this", "->", "_table", "->", "{", "$", "action", "}", "(", "$", "ids", ")", ";", "}", "return", "$", "this", "->", "{", "$", "action", "}", "(", "$", "ids", ")", ";", "}" ]
Process table method. @param string $name @param array $ids @return mixed
[ "Process", "table", "method", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/ORM/Behavior/ProcessBehavior.php#L49-L67
CakeCMS/Core
src/ORM/Behavior/ProcessBehavior.php
ProcessBehavior.processDelete
public function processDelete(array $ids) { return $this->_table->deleteAll([ $this->_table->getPrimaryKey() . ' IN (' . implode(',', $ids) . ')' ]); }
php
public function processDelete(array $ids) { return $this->_table->deleteAll([ $this->_table->getPrimaryKey() . ' IN (' . implode(',', $ids) . ')' ]); }
[ "public", "function", "processDelete", "(", "array", "$", "ids", ")", "{", "return", "$", "this", "->", "_table", "->", "deleteAll", "(", "[", "$", "this", "->", "_table", "->", "getPrimaryKey", "(", ")", ".", "' IN ('", ".", "implode", "(", "','", ",", "$", "ids", ")", ".", "')'", "]", ")", ";", "}" ]
Process delete method. @param array $ids @return int
[ "Process", "delete", "method", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/ORM/Behavior/ProcessBehavior.php#L75-L80
CakeCMS/Core
src/ORM/Behavior/ProcessBehavior.php
ProcessBehavior._toggleField
protected function _toggleField(array $ids, $value = STATUS_UN_PUBLISH) { return $this->_table->updateAll([ $this->_configRead('field') => $value, ], [ $this->_table->getPrimaryKey() . ' IN (' . implode(',', $ids) . ')' ]); }
php
protected function _toggleField(array $ids, $value = STATUS_UN_PUBLISH) { return $this->_table->updateAll([ $this->_configRead('field') => $value, ], [ $this->_table->getPrimaryKey() . ' IN (' . implode(',', $ids) . ')' ]); }
[ "protected", "function", "_toggleField", "(", "array", "$", "ids", ",", "$", "value", "=", "STATUS_UN_PUBLISH", ")", "{", "return", "$", "this", "->", "_table", "->", "updateAll", "(", "[", "$", "this", "->", "_configRead", "(", "'field'", ")", "=>", "$", "value", ",", "]", ",", "[", "$", "this", "->", "_table", "->", "getPrimaryKey", "(", ")", ".", "' IN ('", ".", "implode", "(", "','", ",", "$", "ids", ")", ".", "')'", "]", ")", ";", "}" ]
Toggle table field. @param array $ids @param int $value @return int
[ "Toggle", "table", "field", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/ORM/Behavior/ProcessBehavior.php#L111-L118
redaigbaria/oauth2
src/Entity/AbstractTokenEntity.php
AbstractTokenEntity.setId
public function setId($id = null) { $this->id = ($id !== null) ? $id : SecureKey::generate(); return $this; }
php
public function setId($id = null) { $this->id = ($id !== null) ? $id : SecureKey::generate(); return $this; }
[ "public", "function", "setId", "(", "$", "id", "=", "null", ")", "{", "$", "this", "->", "id", "=", "(", "$", "id", "!==", "null", ")", "?", "$", "id", ":", "SecureKey", "::", "generate", "(", ")", ";", "return", "$", "this", ";", "}" ]
Set token ID @param string $id Token ID @return self
[ "Set", "token", "ID" ]
train
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/Entity/AbstractTokenEntity.php#L131-L136
redaigbaria/oauth2
src/Entity/AbstractTokenEntity.php
AbstractTokenEntity.setSessionId
public function setSessionId($session_id=null) { $this->session_id= ($session_id!== null) ? $session_id : null; return $this; }
php
public function setSessionId($session_id=null) { $this->session_id= ($session_id!== null) ? $session_id : null; return $this; }
[ "public", "function", "setSessionId", "(", "$", "session_id", "=", "null", ")", "{", "$", "this", "->", "session_id", "=", "(", "$", "session_id", "!==", "null", ")", "?", "$", "session_id", ":", "null", ";", "return", "$", "this", ";", "}" ]
Set the session id that this token is associated to .. @param string $session_id Session id
[ "Set", "the", "session", "id", "that", "this", "token", "is", "associated", "to", ".." ]
train
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/Entity/AbstractTokenEntity.php#L142-L147
redaigbaria/oauth2
src/Entity/AbstractTokenEntity.php
AbstractTokenEntity.formatScopes
protected function formatScopes($unformatted = []) { if (is_null($unformatted)) { return []; } $scopes = []; foreach ($unformatted as $scope) { if ($scope instanceof ScopeEntity) { $scopes[$scope->getId()] = $scope; } } return $scopes; }
php
protected function formatScopes($unformatted = []) { if (is_null($unformatted)) { return []; } $scopes = []; foreach ($unformatted as $scope) { if ($scope instanceof ScopeEntity) { $scopes[$scope->getId()] = $scope; } } return $scopes; }
[ "protected", "function", "formatScopes", "(", "$", "unformatted", "=", "[", "]", ")", "{", "if", "(", "is_null", "(", "$", "unformatted", ")", ")", "{", "return", "[", "]", ";", "}", "$", "scopes", "=", "[", "]", ";", "foreach", "(", "$", "unformatted", "as", "$", "scope", ")", "{", "if", "(", "$", "scope", "instanceof", "ScopeEntity", ")", "{", "$", "scopes", "[", "$", "scope", "->", "getId", "(", ")", "]", "=", "$", "scope", ";", "}", "}", "return", "$", "scopes", ";", "}" ]
Format the local scopes array @param \League\OAuth2\Server\Entity\ScopeEntity[] @return array
[ "Format", "the", "local", "scopes", "array" ]
train
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/Entity/AbstractTokenEntity.php#L189-L203
userfriendly/SocialUserBundle
OAuth/UserProvider.php
UserProvider.connect
public function connect( $user, UserResponseInterface $response ) { $existingIdentity = $this->getExistingIdentity( $response ); if ( $existingIdentity ) { // $previousUser = $existingIdentity->getUser(); // $event = new UserAccountMergedEvent( 'User accounts merged' ); // $event->setMergedUser( $previousUser ); // $event->setMergingUser( $user ); // $this->eventDispatcher->dispatch( UserAccountMergedEvent::ID, $event ); $existingIdentity->setUser( $user ); $existingIdentity->setAccessToken( $this->getAccessToken( $response )); $this->om->flush(); } else { $this->createIdentity( $user, $response ); } }
php
public function connect( $user, UserResponseInterface $response ) { $existingIdentity = $this->getExistingIdentity( $response ); if ( $existingIdentity ) { // $previousUser = $existingIdentity->getUser(); // $event = new UserAccountMergedEvent( 'User accounts merged' ); // $event->setMergedUser( $previousUser ); // $event->setMergingUser( $user ); // $this->eventDispatcher->dispatch( UserAccountMergedEvent::ID, $event ); $existingIdentity->setUser( $user ); $existingIdentity->setAccessToken( $this->getAccessToken( $response )); $this->om->flush(); } else { $this->createIdentity( $user, $response ); } }
[ "public", "function", "connect", "(", "$", "user", ",", "UserResponseInterface", "$", "response", ")", "{", "$", "existingIdentity", "=", "$", "this", "->", "getExistingIdentity", "(", "$", "response", ")", ";", "if", "(", "$", "existingIdentity", ")", "{", "// $previousUser = $existingIdentity->getUser();", "// $event = new UserAccountMergedEvent( 'User accounts merged' );", "// $event->setMergedUser( $previousUser );", "// $event->setMergingUser( $user );", "// $this->eventDispatcher->dispatch( UserAccountMergedEvent::ID, $event );", "$", "existingIdentity", "->", "setUser", "(", "$", "user", ")", ";", "$", "existingIdentity", "->", "setAccessToken", "(", "$", "this", "->", "getAccessToken", "(", "$", "response", ")", ")", ";", "$", "this", "->", "om", "->", "flush", "(", ")", ";", "}", "else", "{", "$", "this", "->", "createIdentity", "(", "$", "user", ",", "$", "response", ")", ";", "}", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/userfriendly/SocialUserBundle/blob/1dfcf76af2bc639901c471e6f28b04d73fb65452/OAuth/UserProvider.php#L47-L65
userfriendly/SocialUserBundle
OAuth/UserProvider.php
UserProvider.loadUserByOAuthUserResponse
public function loadUserByOAuthUserResponse( UserResponseInterface $response ) { $existingIdentity = $this->getExistingIdentity( $response ); if ( $existingIdentity ) { $existingIdentity->setAccessToken( $this->getAccessToken( $response )); return $existingIdentity->getUser(); } return $this->createUser( $response ); }
php
public function loadUserByOAuthUserResponse( UserResponseInterface $response ) { $existingIdentity = $this->getExistingIdentity( $response ); if ( $existingIdentity ) { $existingIdentity->setAccessToken( $this->getAccessToken( $response )); return $existingIdentity->getUser(); } return $this->createUser( $response ); }
[ "public", "function", "loadUserByOAuthUserResponse", "(", "UserResponseInterface", "$", "response", ")", "{", "$", "existingIdentity", "=", "$", "this", "->", "getExistingIdentity", "(", "$", "response", ")", ";", "if", "(", "$", "existingIdentity", ")", "{", "$", "existingIdentity", "->", "setAccessToken", "(", "$", "this", "->", "getAccessToken", "(", "$", "response", ")", ")", ";", "return", "$", "existingIdentity", "->", "getUser", "(", ")", ";", "}", "return", "$", "this", "->", "createUser", "(", "$", "response", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/userfriendly/SocialUserBundle/blob/1dfcf76af2bc639901c471e6f28b04d73fb65452/OAuth/UserProvider.php#L81-L90
userfriendly/SocialUserBundle
OAuth/UserProvider.php
UserProvider.getExistingIdentity
protected function getExistingIdentity( UserResponseInterface $response ) { $repo = $this->om->getRepository( $this->userIdentityClass ); // wrong class return $repo->findOneBy( array( 'identifier' => $response->getUsername(), 'type' => $response->getResourceOwner()->getName(), )); }
php
protected function getExistingIdentity( UserResponseInterface $response ) { $repo = $this->om->getRepository( $this->userIdentityClass ); // wrong class return $repo->findOneBy( array( 'identifier' => $response->getUsername(), 'type' => $response->getResourceOwner()->getName(), )); }
[ "protected", "function", "getExistingIdentity", "(", "UserResponseInterface", "$", "response", ")", "{", "$", "repo", "=", "$", "this", "->", "om", "->", "getRepository", "(", "$", "this", "->", "userIdentityClass", ")", ";", "// wrong class", "return", "$", "repo", "->", "findOneBy", "(", "array", "(", "'identifier'", "=>", "$", "response", "->", "getUsername", "(", ")", ",", "'type'", "=>", "$", "response", "->", "getResourceOwner", "(", ")", "->", "getName", "(", ")", ",", ")", ")", ";", "}" ]
Checks whether the authenticating Identity already exists @param \HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface $response @return \Userfriendly\Bundle\SocialUserBundle\Model\UserIdentity
[ "Checks", "whether", "the", "authenticating", "Identity", "already", "exists" ]
train
https://github.com/userfriendly/SocialUserBundle/blob/1dfcf76af2bc639901c471e6f28b04d73fb65452/OAuth/UserProvider.php#L98-L105
userfriendly/SocialUserBundle
OAuth/UserProvider.php
UserProvider.createUser
protected function createUser( UserResponseInterface $response ) { $user = $this->userManager->createUser(); $user->setUsername( $this->createUniqueUsername( $this->getRealName( $response ))); $user->setEmail( $this->getEmail( $response ) ); $user->setPassword( '' ); $user->setEnabled( true ); $this->userManager->updateUser( $user ); $this->createIdentity( $user, $response ); return $user; }
php
protected function createUser( UserResponseInterface $response ) { $user = $this->userManager->createUser(); $user->setUsername( $this->createUniqueUsername( $this->getRealName( $response ))); $user->setEmail( $this->getEmail( $response ) ); $user->setPassword( '' ); $user->setEnabled( true ); $this->userManager->updateUser( $user ); $this->createIdentity( $user, $response ); return $user; }
[ "protected", "function", "createUser", "(", "UserResponseInterface", "$", "response", ")", "{", "$", "user", "=", "$", "this", "->", "userManager", "->", "createUser", "(", ")", ";", "$", "user", "->", "setUsername", "(", "$", "this", "->", "createUniqueUsername", "(", "$", "this", "->", "getRealName", "(", "$", "response", ")", ")", ")", ";", "$", "user", "->", "setEmail", "(", "$", "this", "->", "getEmail", "(", "$", "response", ")", ")", ";", "$", "user", "->", "setPassword", "(", "''", ")", ";", "$", "user", "->", "setEnabled", "(", "true", ")", ";", "$", "this", "->", "userManager", "->", "updateUser", "(", "$", "user", ")", ";", "$", "this", "->", "createIdentity", "(", "$", "user", ",", "$", "response", ")", ";", "return", "$", "user", ";", "}" ]
Creates new User @param \HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface $response @return \Userfriendly\Bundle\SocialUserBundle\Model\User
[ "Creates", "new", "User" ]
train
https://github.com/userfriendly/SocialUserBundle/blob/1dfcf76af2bc639901c471e6f28b04d73fb65452/OAuth/UserProvider.php#L113-L123
userfriendly/SocialUserBundle
OAuth/UserProvider.php
UserProvider.createIdentity
protected function createIdentity( User $user, UserResponseInterface $response ) { $identity = new $this->userIdentityClass; $identity->setAccessToken( $this->getAccessToken( $response )); $identity->setIdentifier( $response->getUsername() ); $identity->setType( $response->getResourceOwner()->getName() ); $identity->setUser( $user ); $identity->setName( $this->getRealName( $response )); $identity->setEmail( $this->getEmail( $response )); $this->om->persist( $identity ); $this->om->flush(); return $identity; }
php
protected function createIdentity( User $user, UserResponseInterface $response ) { $identity = new $this->userIdentityClass; $identity->setAccessToken( $this->getAccessToken( $response )); $identity->setIdentifier( $response->getUsername() ); $identity->setType( $response->getResourceOwner()->getName() ); $identity->setUser( $user ); $identity->setName( $this->getRealName( $response )); $identity->setEmail( $this->getEmail( $response )); $this->om->persist( $identity ); $this->om->flush(); return $identity; }
[ "protected", "function", "createIdentity", "(", "User", "$", "user", ",", "UserResponseInterface", "$", "response", ")", "{", "$", "identity", "=", "new", "$", "this", "->", "userIdentityClass", ";", "$", "identity", "->", "setAccessToken", "(", "$", "this", "->", "getAccessToken", "(", "$", "response", ")", ")", ";", "$", "identity", "->", "setIdentifier", "(", "$", "response", "->", "getUsername", "(", ")", ")", ";", "$", "identity", "->", "setType", "(", "$", "response", "->", "getResourceOwner", "(", ")", "->", "getName", "(", ")", ")", ";", "$", "identity", "->", "setUser", "(", "$", "user", ")", ";", "$", "identity", "->", "setName", "(", "$", "this", "->", "getRealName", "(", "$", "response", ")", ")", ";", "$", "identity", "->", "setEmail", "(", "$", "this", "->", "getEmail", "(", "$", "response", ")", ")", ";", "$", "this", "->", "om", "->", "persist", "(", "$", "identity", ")", ";", "$", "this", "->", "om", "->", "flush", "(", ")", ";", "return", "$", "identity", ";", "}" ]
Creates new Identity @param \HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface $response @param \Userfriendly\Bundle\SocialUserBundle\Model\User $user @return \Userfriendly\Bundle\SocialUserBundle\Model\UserIdentity
[ "Creates", "new", "Identity" ]
train
https://github.com/userfriendly/SocialUserBundle/blob/1dfcf76af2bc639901c471e6f28b04d73fb65452/OAuth/UserProvider.php#L132-L144
userfriendly/SocialUserBundle
OAuth/UserProvider.php
UserProvider.createUniqueUsername
protected function createUniqueUsername( $username ) { $originalName = $username; $existingUser = $this->userManager->findUserByUsername( $username ); $suffix = 0; while ( $existingUser ) { $suffix++; $username = $originalName . $suffix; $existingUser = $this->userManager->findUserByUsername( $username ); } return $username; }
php
protected function createUniqueUsername( $username ) { $originalName = $username; $existingUser = $this->userManager->findUserByUsername( $username ); $suffix = 0; while ( $existingUser ) { $suffix++; $username = $originalName . $suffix; $existingUser = $this->userManager->findUserByUsername( $username ); } return $username; }
[ "protected", "function", "createUniqueUsername", "(", "$", "username", ")", "{", "$", "originalName", "=", "$", "username", ";", "$", "existingUser", "=", "$", "this", "->", "userManager", "->", "findUserByUsername", "(", "$", "username", ")", ";", "$", "suffix", "=", "0", ";", "while", "(", "$", "existingUser", ")", "{", "$", "suffix", "++", ";", "$", "username", "=", "$", "originalName", ".", "$", "suffix", ";", "$", "existingUser", "=", "$", "this", "->", "userManager", "->", "findUserByUsername", "(", "$", "username", ")", ";", "}", "return", "$", "username", ";", "}" ]
Ensures uniqueness of username @param string $username @return string
[ "Ensures", "uniqueness", "of", "username" ]
train
https://github.com/userfriendly/SocialUserBundle/blob/1dfcf76af2bc639901c471e6f28b04d73fb65452/OAuth/UserProvider.php#L152-L164
userfriendly/SocialUserBundle
OAuth/UserProvider.php
UserProvider.getAccessToken
protected function getAccessToken( UserResponseInterface $response ) { $accessToken = $response->getAccessToken(); switch ( $response->getResourceOwner()->getName() ) { //case UserIdentity::getReadableType( UserIdentity::TYPE_TWITTER ): case UserIdentity::getReadableType( UserIdentity::TYPE_YAHOO ): return $accessToken['oauth_token']; default: return $accessToken; } }
php
protected function getAccessToken( UserResponseInterface $response ) { $accessToken = $response->getAccessToken(); switch ( $response->getResourceOwner()->getName() ) { //case UserIdentity::getReadableType( UserIdentity::TYPE_TWITTER ): case UserIdentity::getReadableType( UserIdentity::TYPE_YAHOO ): return $accessToken['oauth_token']; default: return $accessToken; } }
[ "protected", "function", "getAccessToken", "(", "UserResponseInterface", "$", "response", ")", "{", "$", "accessToken", "=", "$", "response", "->", "getAccessToken", "(", ")", ";", "switch", "(", "$", "response", "->", "getResourceOwner", "(", ")", "->", "getName", "(", ")", ")", "{", "//case UserIdentity::getReadableType( UserIdentity::TYPE_TWITTER ):", "case", "UserIdentity", "::", "getReadableType", "(", "UserIdentity", "::", "TYPE_YAHOO", ")", ":", "return", "$", "accessToken", "[", "'oauth_token'", "]", ";", "default", ":", "return", "$", "accessToken", ";", "}", "}" ]
Workaround method for HWIOAuthBundle issue Waiting for this issue to be fixed upstream @param \HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface $response @return string
[ "Workaround", "method", "for", "HWIOAuthBundle", "issue" ]
train
https://github.com/userfriendly/SocialUserBundle/blob/1dfcf76af2bc639901c471e6f28b04d73fb65452/OAuth/UserProvider.php#L174-L185
userfriendly/SocialUserBundle
OAuth/UserProvider.php
UserProvider.getRealName
protected function getRealName( UserResponseInterface $response ) { switch ( $response->getResourceOwner()->getName() ) { case UserIdentity::getReadableType( UserIdentity::TYPE_YAHOO ): $responseArray = $response->getResponse(); $name = trim( $responseArray['profile']['givenName'] . ' ' . $responseArray['profile']['familyName'] ); return $name; // case UserIdentity::getReadableType( UserIdentity::TYPE_TWITTER ): // $responseArray = $response->getResponse(); // echo '<pre>'; // print_r( $response ); // echo '</pre>'; // die(); exit; // return 'twit'; default: return $response->getRealName(); } }
php
protected function getRealName( UserResponseInterface $response ) { switch ( $response->getResourceOwner()->getName() ) { case UserIdentity::getReadableType( UserIdentity::TYPE_YAHOO ): $responseArray = $response->getResponse(); $name = trim( $responseArray['profile']['givenName'] . ' ' . $responseArray['profile']['familyName'] ); return $name; // case UserIdentity::getReadableType( UserIdentity::TYPE_TWITTER ): // $responseArray = $response->getResponse(); // echo '<pre>'; // print_r( $response ); // echo '</pre>'; // die(); exit; // return 'twit'; default: return $response->getRealName(); } }
[ "protected", "function", "getRealName", "(", "UserResponseInterface", "$", "response", ")", "{", "switch", "(", "$", "response", "->", "getResourceOwner", "(", ")", "->", "getName", "(", ")", ")", "{", "case", "UserIdentity", "::", "getReadableType", "(", "UserIdentity", "::", "TYPE_YAHOO", ")", ":", "$", "responseArray", "=", "$", "response", "->", "getResponse", "(", ")", ";", "$", "name", "=", "trim", "(", "$", "responseArray", "[", "'profile'", "]", "[", "'givenName'", "]", ".", "' '", ".", "$", "responseArray", "[", "'profile'", "]", "[", "'familyName'", "]", ")", ";", "return", "$", "name", ";", "// case UserIdentity::getReadableType( UserIdentity::TYPE_TWITTER ):", "// $responseArray = $response->getResponse();", "// echo '<pre>';", "// print_r( $response );", "// echo '</pre>';", "// die(); exit;", "// return 'twit';", "default", ":", "return", "$", "response", "->", "getRealName", "(", ")", ";", "}", "}" ]
Workaround method for HWIOAuthBundle issue Waiting for this issue to be fixed upstream @param \HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface $response @return string
[ "Workaround", "method", "for", "HWIOAuthBundle", "issue" ]
train
https://github.com/userfriendly/SocialUserBundle/blob/1dfcf76af2bc639901c471e6f28b04d73fb65452/OAuth/UserProvider.php#L195-L213
userfriendly/SocialUserBundle
OAuth/UserProvider.php
UserProvider.getEmail
protected function getEmail( UserResponseInterface $response ) { $responseArray = $response->getResponse(); switch ( $response->getResourceOwner()->getName() ) { case UserIdentity::getReadableType( UserIdentity::TYPE_TWITTER ): return NULL; case UserIdentity::getReadableType( UserIdentity::TYPE_YAHOO ): if ( array_key_exists( 'emails', $responseArray['profile'] )) { if ( count( $responseArray['profile']['emails'] ) > 0 ) { return $responseArray['profile']['emails'][0]['handle']; } } default: if ( array_key_exists( 'email', $responseArray )) { return $responseArray['email']; } } }
php
protected function getEmail( UserResponseInterface $response ) { $responseArray = $response->getResponse(); switch ( $response->getResourceOwner()->getName() ) { case UserIdentity::getReadableType( UserIdentity::TYPE_TWITTER ): return NULL; case UserIdentity::getReadableType( UserIdentity::TYPE_YAHOO ): if ( array_key_exists( 'emails', $responseArray['profile'] )) { if ( count( $responseArray['profile']['emails'] ) > 0 ) { return $responseArray['profile']['emails'][0]['handle']; } } default: if ( array_key_exists( 'email', $responseArray )) { return $responseArray['email']; } } }
[ "protected", "function", "getEmail", "(", "UserResponseInterface", "$", "response", ")", "{", "$", "responseArray", "=", "$", "response", "->", "getResponse", "(", ")", ";", "switch", "(", "$", "response", "->", "getResourceOwner", "(", ")", "->", "getName", "(", ")", ")", "{", "case", "UserIdentity", "::", "getReadableType", "(", "UserIdentity", "::", "TYPE_TWITTER", ")", ":", "return", "NULL", ";", "case", "UserIdentity", "::", "getReadableType", "(", "UserIdentity", "::", "TYPE_YAHOO", ")", ":", "if", "(", "array_key_exists", "(", "'emails'", ",", "$", "responseArray", "[", "'profile'", "]", ")", ")", "{", "if", "(", "count", "(", "$", "responseArray", "[", "'profile'", "]", "[", "'emails'", "]", ")", ">", "0", ")", "{", "return", "$", "responseArray", "[", "'profile'", "]", "[", "'emails'", "]", "[", "0", "]", "[", "'handle'", "]", ";", "}", "}", "default", ":", "if", "(", "array_key_exists", "(", "'email'", ",", "$", "responseArray", ")", ")", "{", "return", "$", "responseArray", "[", "'email'", "]", ";", "}", "}", "}" ]
Workaround method for HWIOAuthBundle issue Waiting for this issue to be fixed upstream @param \HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface $response @return string
[ "Workaround", "method", "for", "HWIOAuthBundle", "issue" ]
train
https://github.com/userfriendly/SocialUserBundle/blob/1dfcf76af2bc639901c471e6f28b04d73fb65452/OAuth/UserProvider.php#L223-L244
fsi-open/doctrine-extensions-bundle
DependencyInjection/Compiler/GaufretteFilesystemsPass.php
GaufretteFilesystemsPass.process
public function process(ContainerBuilder $container) { $configuration = new Configuration(); $processor = new Processor(); $config = $processor->processConfiguration($configuration, $container->getExtensionConfig('fsi_doctrine_extensions')); foreach ($config['uploadable_filesystems'] as $filesystem => $filesystemConfig) { $filesystemService = $container->findDefinition(sprintf('gaufrette.%s_filesystem', $filesystem)); $filesystemService->addMethodCall('setBaseUrl', [$filesystemConfig['base_url']]); } }
php
public function process(ContainerBuilder $container) { $configuration = new Configuration(); $processor = new Processor(); $config = $processor->processConfiguration($configuration, $container->getExtensionConfig('fsi_doctrine_extensions')); foreach ($config['uploadable_filesystems'] as $filesystem => $filesystemConfig) { $filesystemService = $container->findDefinition(sprintf('gaufrette.%s_filesystem', $filesystem)); $filesystemService->addMethodCall('setBaseUrl', [$filesystemConfig['base_url']]); } }
[ "public", "function", "process", "(", "ContainerBuilder", "$", "container", ")", "{", "$", "configuration", "=", "new", "Configuration", "(", ")", ";", "$", "processor", "=", "new", "Processor", "(", ")", ";", "$", "config", "=", "$", "processor", "->", "processConfiguration", "(", "$", "configuration", ",", "$", "container", "->", "getExtensionConfig", "(", "'fsi_doctrine_extensions'", ")", ")", ";", "foreach", "(", "$", "config", "[", "'uploadable_filesystems'", "]", "as", "$", "filesystem", "=>", "$", "filesystemConfig", ")", "{", "$", "filesystemService", "=", "$", "container", "->", "findDefinition", "(", "sprintf", "(", "'gaufrette.%s_filesystem'", ",", "$", "filesystem", ")", ")", ";", "$", "filesystemService", "->", "addMethodCall", "(", "'setBaseUrl'", ",", "[", "$", "filesystemConfig", "[", "'base_url'", "]", "]", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/fsi-open/doctrine-extensions-bundle/blob/1b9c01e0b216b2c1b2af087de233abbf3c84b9fe/DependencyInjection/Compiler/GaufretteFilesystemsPass.php#L24-L34
SachaMorard/phalcon-console
Library/Phalcon/Commands/Builtin/ClearCache.php
ClearCache.run
public function run(array $parameters) { print Color::colorize('Clear File Cache:', Color::FG_BROWN) . PHP_EOL; $cacheDir = $this->getConfig()->application->cacheDir; $directories = scandir($cacheDir); foreach ($directories as $dir) { if ($dir !== "." && $dir !== ".." && $dir !== ".gitignore") { print Color::colorize(' Empty cache for ' . $dir, Color::FG_LIGHT_PURPLE) . PHP_EOL; $thisCacheDir = $cacheDir . $dir . '/'; $files = scandir($thisCacheDir); foreach ($files as $file) { if ($file !== "." && $file !== ".." && $file !== ".gitignore") { unlink($thisCacheDir . $file); print Color::colorize(' Erase ' . $thisCacheDir . $file, Color::FG_LIGHT_GRAY, Color::AT_ITALIC) . PHP_EOL; } } } } print PHP_EOL; }
php
public function run(array $parameters) { print Color::colorize('Clear File Cache:', Color::FG_BROWN) . PHP_EOL; $cacheDir = $this->getConfig()->application->cacheDir; $directories = scandir($cacheDir); foreach ($directories as $dir) { if ($dir !== "." && $dir !== ".." && $dir !== ".gitignore") { print Color::colorize(' Empty cache for ' . $dir, Color::FG_LIGHT_PURPLE) . PHP_EOL; $thisCacheDir = $cacheDir . $dir . '/'; $files = scandir($thisCacheDir); foreach ($files as $file) { if ($file !== "." && $file !== ".." && $file !== ".gitignore") { unlink($thisCacheDir . $file); print Color::colorize(' Erase ' . $thisCacheDir . $file, Color::FG_LIGHT_GRAY, Color::AT_ITALIC) . PHP_EOL; } } } } print PHP_EOL; }
[ "public", "function", "run", "(", "array", "$", "parameters", ")", "{", "print", "Color", "::", "colorize", "(", "'Clear File Cache:'", ",", "Color", "::", "FG_BROWN", ")", ".", "PHP_EOL", ";", "$", "cacheDir", "=", "$", "this", "->", "getConfig", "(", ")", "->", "application", "->", "cacheDir", ";", "$", "directories", "=", "scandir", "(", "$", "cacheDir", ")", ";", "foreach", "(", "$", "directories", "as", "$", "dir", ")", "{", "if", "(", "$", "dir", "!==", "\".\"", "&&", "$", "dir", "!==", "\"..\"", "&&", "$", "dir", "!==", "\".gitignore\"", ")", "{", "print", "Color", "::", "colorize", "(", "' Empty cache for '", ".", "$", "dir", ",", "Color", "::", "FG_LIGHT_PURPLE", ")", ".", "PHP_EOL", ";", "$", "thisCacheDir", "=", "$", "cacheDir", ".", "$", "dir", ".", "'/'", ";", "$", "files", "=", "scandir", "(", "$", "thisCacheDir", ")", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "if", "(", "$", "file", "!==", "\".\"", "&&", "$", "file", "!==", "\"..\"", "&&", "$", "file", "!==", "\".gitignore\"", ")", "{", "unlink", "(", "$", "thisCacheDir", ".", "$", "file", ")", ";", "print", "Color", "::", "colorize", "(", "' Erase '", ".", "$", "thisCacheDir", ".", "$", "file", ",", "Color", "::", "FG_LIGHT_GRAY", ",", "Color", "::", "AT_ITALIC", ")", ".", "PHP_EOL", ";", "}", "}", "}", "}", "print", "PHP_EOL", ";", "}" ]
{@inheritdoc} @param array $parameters @return mixed
[ "{", "@inheritdoc", "}" ]
train
https://github.com/SachaMorard/phalcon-console/blob/a7922e4c488ea19bc0ecce793e6f01cf9cf3c0c3/Library/Phalcon/Commands/Builtin/ClearCache.php#L33-L54
transfer-framework/ezplatform
src/Transfer/EzPlatform/Repository/Manager/LanguageManager.php
LanguageManager.find
public function find(ValueObject $object) { try { if (isset($object->data['code'])) { $language = $this->languageService->loadLanguage($object->data['code']); } } catch (NotFoundException $notFoundException) { // We'll throw our own exception later instead. } if (!isset($language)) { throw new ObjectNotFoundException(Language::class, array('code')); } return $language; }
php
public function find(ValueObject $object) { try { if (isset($object->data['code'])) { $language = $this->languageService->loadLanguage($object->data['code']); } } catch (NotFoundException $notFoundException) { // We'll throw our own exception later instead. } if (!isset($language)) { throw new ObjectNotFoundException(Language::class, array('code')); } return $language; }
[ "public", "function", "find", "(", "ValueObject", "$", "object", ")", "{", "try", "{", "if", "(", "isset", "(", "$", "object", "->", "data", "[", "'code'", "]", ")", ")", "{", "$", "language", "=", "$", "this", "->", "languageService", "->", "loadLanguage", "(", "$", "object", "->", "data", "[", "'code'", "]", ")", ";", "}", "}", "catch", "(", "NotFoundException", "$", "notFoundException", ")", "{", "// We'll throw our own exception later instead.", "}", "if", "(", "!", "isset", "(", "$", "language", ")", ")", "{", "throw", "new", "ObjectNotFoundException", "(", "Language", "::", "class", ",", "array", "(", "'code'", ")", ")", ";", "}", "return", "$", "language", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/transfer-framework/ezplatform/blob/1b2d87caa1a6b79fd8fc78109c26a2d1d6359c2f/src/Transfer/EzPlatform/Repository/Manager/LanguageManager.php#L66-L81
transfer-framework/ezplatform
src/Transfer/EzPlatform/Repository/Manager/LanguageManager.php
LanguageManager.create
public function create(ObjectInterface $object) { if (!$object instanceof LanguageObject) { throw new UnsupportedObjectOperationException(LanguageObject::class, get_class($object)); } try { $language = $this->find($object); $this->languageService->enableLanguage($language); } catch (NotFoundException $notFoundException) { $languageCreateStruct = $this->languageService->newLanguageCreateStruct(); $object->getMapper()->mapObjectToCreateStruct($languageCreateStruct); $language = $this->languageService->createLanguage($languageCreateStruct); } $object->getMapper()->languageToObject($language); return $object; }
php
public function create(ObjectInterface $object) { if (!$object instanceof LanguageObject) { throw new UnsupportedObjectOperationException(LanguageObject::class, get_class($object)); } try { $language = $this->find($object); $this->languageService->enableLanguage($language); } catch (NotFoundException $notFoundException) { $languageCreateStruct = $this->languageService->newLanguageCreateStruct(); $object->getMapper()->mapObjectToCreateStruct($languageCreateStruct); $language = $this->languageService->createLanguage($languageCreateStruct); } $object->getMapper()->languageToObject($language); return $object; }
[ "public", "function", "create", "(", "ObjectInterface", "$", "object", ")", "{", "if", "(", "!", "$", "object", "instanceof", "LanguageObject", ")", "{", "throw", "new", "UnsupportedObjectOperationException", "(", "LanguageObject", "::", "class", ",", "get_class", "(", "$", "object", ")", ")", ";", "}", "try", "{", "$", "language", "=", "$", "this", "->", "find", "(", "$", "object", ")", ";", "$", "this", "->", "languageService", "->", "enableLanguage", "(", "$", "language", ")", ";", "}", "catch", "(", "NotFoundException", "$", "notFoundException", ")", "{", "$", "languageCreateStruct", "=", "$", "this", "->", "languageService", "->", "newLanguageCreateStruct", "(", ")", ";", "$", "object", "->", "getMapper", "(", ")", "->", "mapObjectToCreateStruct", "(", "$", "languageCreateStruct", ")", ";", "$", "language", "=", "$", "this", "->", "languageService", "->", "createLanguage", "(", "$", "languageCreateStruct", ")", ";", "}", "$", "object", "->", "getMapper", "(", ")", "->", "languageToObject", "(", "$", "language", ")", ";", "return", "$", "object", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/transfer-framework/ezplatform/blob/1b2d87caa1a6b79fd8fc78109c26a2d1d6359c2f/src/Transfer/EzPlatform/Repository/Manager/LanguageManager.php#L86-L104
transfer-framework/ezplatform
src/Transfer/EzPlatform/Repository/Manager/LanguageManager.php
LanguageManager.update
public function update(ObjectInterface $object) { if (!$object instanceof LanguageObject) { throw new UnsupportedObjectOperationException(LanguageObject::class, get_class($object)); } $language = $this->find($object); $language = $this->languageService->updateLanguageName($language, $object->data['name']); $object->getMapper()->languageToObject($language); return $object; }
php
public function update(ObjectInterface $object) { if (!$object instanceof LanguageObject) { throw new UnsupportedObjectOperationException(LanguageObject::class, get_class($object)); } $language = $this->find($object); $language = $this->languageService->updateLanguageName($language, $object->data['name']); $object->getMapper()->languageToObject($language); return $object; }
[ "public", "function", "update", "(", "ObjectInterface", "$", "object", ")", "{", "if", "(", "!", "$", "object", "instanceof", "LanguageObject", ")", "{", "throw", "new", "UnsupportedObjectOperationException", "(", "LanguageObject", "::", "class", ",", "get_class", "(", "$", "object", ")", ")", ";", "}", "$", "language", "=", "$", "this", "->", "find", "(", "$", "object", ")", ";", "$", "language", "=", "$", "this", "->", "languageService", "->", "updateLanguageName", "(", "$", "language", ",", "$", "object", "->", "data", "[", "'name'", "]", ")", ";", "$", "object", "->", "getMapper", "(", ")", "->", "languageToObject", "(", "$", "language", ")", ";", "return", "$", "object", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/transfer-framework/ezplatform/blob/1b2d87caa1a6b79fd8fc78109c26a2d1d6359c2f/src/Transfer/EzPlatform/Repository/Manager/LanguageManager.php#L109-L121
transfer-framework/ezplatform
src/Transfer/EzPlatform/Repository/Manager/LanguageManager.php
LanguageManager.createOrUpdate
public function createOrUpdate(ObjectInterface $object) { if (!$object instanceof LanguageObject) { throw new UnsupportedObjectOperationException(LanguageObject::class, get_class($object)); } try { $this->find($object); return $this->update($object); } catch (ObjectNotFoundException $notFound) { return $this->create($object); } }
php
public function createOrUpdate(ObjectInterface $object) { if (!$object instanceof LanguageObject) { throw new UnsupportedObjectOperationException(LanguageObject::class, get_class($object)); } try { $this->find($object); return $this->update($object); } catch (ObjectNotFoundException $notFound) { return $this->create($object); } }
[ "public", "function", "createOrUpdate", "(", "ObjectInterface", "$", "object", ")", "{", "if", "(", "!", "$", "object", "instanceof", "LanguageObject", ")", "{", "throw", "new", "UnsupportedObjectOperationException", "(", "LanguageObject", "::", "class", ",", "get_class", "(", "$", "object", ")", ")", ";", "}", "try", "{", "$", "this", "->", "find", "(", "$", "object", ")", ";", "return", "$", "this", "->", "update", "(", "$", "object", ")", ";", "}", "catch", "(", "ObjectNotFoundException", "$", "notFound", ")", "{", "return", "$", "this", "->", "create", "(", "$", "object", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/transfer-framework/ezplatform/blob/1b2d87caa1a6b79fd8fc78109c26a2d1d6359c2f/src/Transfer/EzPlatform/Repository/Manager/LanguageManager.php#L126-L139
transfer-framework/ezplatform
src/Transfer/EzPlatform/Repository/Manager/LanguageManager.php
LanguageManager.remove
public function remove(ObjectInterface $object) { if (!$object instanceof LanguageObject) { throw new UnsupportedObjectOperationException(LanguageObject::class, get_class($object)); } try { $language = $this->find($object); $this->languageService->deleteLanguage($language); } catch (NotFoundException $e) { return true; } catch (InvalidArgumentException $ee) { if ($this->logger) { $this->logger->warning('Tried to delete the main language, or a language that still has existing translations (is in use).'); } return false; } return true; }
php
public function remove(ObjectInterface $object) { if (!$object instanceof LanguageObject) { throw new UnsupportedObjectOperationException(LanguageObject::class, get_class($object)); } try { $language = $this->find($object); $this->languageService->deleteLanguage($language); } catch (NotFoundException $e) { return true; } catch (InvalidArgumentException $ee) { if ($this->logger) { $this->logger->warning('Tried to delete the main language, or a language that still has existing translations (is in use).'); } return false; } return true; }
[ "public", "function", "remove", "(", "ObjectInterface", "$", "object", ")", "{", "if", "(", "!", "$", "object", "instanceof", "LanguageObject", ")", "{", "throw", "new", "UnsupportedObjectOperationException", "(", "LanguageObject", "::", "class", ",", "get_class", "(", "$", "object", ")", ")", ";", "}", "try", "{", "$", "language", "=", "$", "this", "->", "find", "(", "$", "object", ")", ";", "$", "this", "->", "languageService", "->", "deleteLanguage", "(", "$", "language", ")", ";", "}", "catch", "(", "NotFoundException", "$", "e", ")", "{", "return", "true", ";", "}", "catch", "(", "InvalidArgumentException", "$", "ee", ")", "{", "if", "(", "$", "this", "->", "logger", ")", "{", "$", "this", "->", "logger", "->", "warning", "(", "'Tried to delete the main language, or a language that still has existing translations (is in use).'", ")", ";", "}", "return", "false", ";", "}", "return", "true", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/transfer-framework/ezplatform/blob/1b2d87caa1a6b79fd8fc78109c26a2d1d6359c2f/src/Transfer/EzPlatform/Repository/Manager/LanguageManager.php#L144-L164
webforge-labs/psc-cms
lib/Psc/Doctrine/EventCollectionSynchronizer.php
EventCollectionSynchronizer.dispatchInsert
protected function dispatchInsert($item, $eventData = array()) { return $this->manager->dispatchEvent(self::EVENT_INSERT, array_merge(array('item'=>$item), $eventData), $this); }
php
protected function dispatchInsert($item, $eventData = array()) { return $this->manager->dispatchEvent(self::EVENT_INSERT, array_merge(array('item'=>$item), $eventData), $this); }
[ "protected", "function", "dispatchInsert", "(", "$", "item", ",", "$", "eventData", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "manager", "->", "dispatchEvent", "(", "self", "::", "EVENT_INSERT", ",", "array_merge", "(", "array", "(", "'item'", "=>", "$", "item", ")", ",", "$", "eventData", ")", ",", "$", "this", ")", ";", "}" ]
/* Hilfsfunktionen für ableitende Klassen
[ "/", "*", "Hilfsfunktionen", "für", "ableitende", "Klassen" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/EventCollectionSynchronizer.php#L75-L77
simple-php-mvc/simple-php-mvc
src/MVC/DataBase/PdoProvider.php
PdoProvider.register
public function register(MVC $mvc) { $this->pdo = new PDO($this->options['dsn'], $this->options['user'], $this->options['passwd'], $this->options['driverOptions']); if (!$mvc->hasCvpp('pdo')) { $mvc->setCvpp('pdo', $this->pdo); } }
php
public function register(MVC $mvc) { $this->pdo = new PDO($this->options['dsn'], $this->options['user'], $this->options['passwd'], $this->options['driverOptions']); if (!$mvc->hasCvpp('pdo')) { $mvc->setCvpp('pdo', $this->pdo); } }
[ "public", "function", "register", "(", "MVC", "$", "mvc", ")", "{", "$", "this", "->", "pdo", "=", "new", "PDO", "(", "$", "this", "->", "options", "[", "'dsn'", "]", ",", "$", "this", "->", "options", "[", "'user'", "]", ",", "$", "this", "->", "options", "[", "'passwd'", "]", ",", "$", "this", "->", "options", "[", "'driverOptions'", "]", ")", ";", "if", "(", "!", "$", "mvc", "->", "hasCvpp", "(", "'pdo'", ")", ")", "{", "$", "mvc", "->", "setCvpp", "(", "'pdo'", ",", "$", "this", "->", "pdo", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/DataBase/PdoProvider.php#L91-L98
yuncms/framework
src/web/Response.php
Response.getContentType
public function getContentType(): string { // If the response hasn't been prepared yet, go with what the formatter is going to set if (!$this->_isPrepared) { switch ($this->format) { case self::FORMAT_HTML: return 'text/html'; case self::FORMAT_XML: return 'application/xml'; case self::FORMAT_JSON: return 'application/json'; case self::FORMAT_JSONP: return 'application/javascript'; } } // Otherwise check the Content-Type header if (($header = $this->getHeaders()->get('content-type')) === null) { return null; } if (($pos = strpos($header, ';')) !== false) { $header = substr($header, 0, $pos); } return strtolower(trim($header)); }
php
public function getContentType(): string { // If the response hasn't been prepared yet, go with what the formatter is going to set if (!$this->_isPrepared) { switch ($this->format) { case self::FORMAT_HTML: return 'text/html'; case self::FORMAT_XML: return 'application/xml'; case self::FORMAT_JSON: return 'application/json'; case self::FORMAT_JSONP: return 'application/javascript'; } } // Otherwise check the Content-Type header if (($header = $this->getHeaders()->get('content-type')) === null) { return null; } if (($pos = strpos($header, ';')) !== false) { $header = substr($header, 0, $pos); } return strtolower(trim($header)); }
[ "public", "function", "getContentType", "(", ")", ":", "string", "{", "// If the response hasn't been prepared yet, go with what the formatter is going to set", "if", "(", "!", "$", "this", "->", "_isPrepared", ")", "{", "switch", "(", "$", "this", "->", "format", ")", "{", "case", "self", "::", "FORMAT_HTML", ":", "return", "'text/html'", ";", "case", "self", "::", "FORMAT_XML", ":", "return", "'application/xml'", ";", "case", "self", "::", "FORMAT_JSON", ":", "return", "'application/json'", ";", "case", "self", "::", "FORMAT_JSONP", ":", "return", "'application/javascript'", ";", "}", "}", "// Otherwise check the Content-Type header", "if", "(", "(", "$", "header", "=", "$", "this", "->", "getHeaders", "(", ")", "->", "get", "(", "'content-type'", ")", ")", "===", "null", ")", "{", "return", "null", ";", "}", "if", "(", "(", "$", "pos", "=", "strpos", "(", "$", "header", ",", "';'", ")", ")", "!==", "false", ")", "{", "$", "header", "=", "substr", "(", "$", "header", ",", "0", ",", "$", "pos", ")", ";", "}", "return", "strtolower", "(", "trim", "(", "$", "header", ")", ")", ";", "}" ]
Returns the Content-Type header (sans `charset=X`) that the response will most likely include. @return string|null
[ "Returns", "the", "Content", "-", "Type", "header", "(", "sans", "charset", "=", "X", ")", "that", "the", "response", "will", "most", "likely", "include", "." ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/web/Response.php#L30-L56
yuncms/framework
src/web/Response.php
Response.setCacheHeaders
public function setCacheHeaders() { $cacheTime = 31536000; // 1 year $this->getHeaders() ->set('Expires', gmdate('D, d M Y H:i:s', time() + $cacheTime) . ' GMT') ->set('Pragma', 'cache') ->set('Cache-Control', 'max-age=' . $cacheTime); return $this; }
php
public function setCacheHeaders() { $cacheTime = 31536000; // 1 year $this->getHeaders() ->set('Expires', gmdate('D, d M Y H:i:s', time() + $cacheTime) . ' GMT') ->set('Pragma', 'cache') ->set('Cache-Control', 'max-age=' . $cacheTime); return $this; }
[ "public", "function", "setCacheHeaders", "(", ")", "{", "$", "cacheTime", "=", "31536000", ";", "// 1 year", "$", "this", "->", "getHeaders", "(", ")", "->", "set", "(", "'Expires'", ",", "gmdate", "(", "'D, d M Y H:i:s'", ",", "time", "(", ")", "+", "$", "cacheTime", ")", ".", "' GMT'", ")", "->", "set", "(", "'Pragma'", ",", "'cache'", ")", "->", "set", "(", "'Cache-Control'", ",", "'max-age='", ".", "$", "cacheTime", ")", ";", "return", "$", "this", ";", "}" ]
Sets headers that will instruct the client to cache this response. @return static self reference
[ "Sets", "headers", "that", "will", "instruct", "the", "client", "to", "cache", "this", "response", "." ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/web/Response.php#L63-L72
yuncms/framework
src/web/Response.php
Response.setLastModifiedHeader
public function setLastModifiedHeader(string $path) { $modifiedTime = filemtime($path); if ($modifiedTime) { $this->getHeaders()->set('Last-Modified', gmdate('D, d M Y H:i:s', $modifiedTime) . ' GMT'); } return $this; }
php
public function setLastModifiedHeader(string $path) { $modifiedTime = filemtime($path); if ($modifiedTime) { $this->getHeaders()->set('Last-Modified', gmdate('D, d M Y H:i:s', $modifiedTime) . ' GMT'); } return $this; }
[ "public", "function", "setLastModifiedHeader", "(", "string", "$", "path", ")", "{", "$", "modifiedTime", "=", "filemtime", "(", "$", "path", ")", ";", "if", "(", "$", "modifiedTime", ")", "{", "$", "this", "->", "getHeaders", "(", ")", "->", "set", "(", "'Last-Modified'", ",", "gmdate", "(", "'D, d M Y H:i:s'", ",", "$", "modifiedTime", ")", ".", "' GMT'", ")", ";", "}", "return", "$", "this", ";", "}" ]
Sets a Last-Modified header based on a given file path. @param string $path The file to read the last modified date from. @return static self reference
[ "Sets", "a", "Last", "-", "Modified", "header", "based", "on", "a", "given", "file", "path", "." ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/web/Response.php#L80-L89
yuncms/framework
src/web/Response.php
Response.startBuffering
public function startBuffering($content) { $this->getHeaders() ->set('Surrogate-Control','BigPipe/1.0') ->set('X-Accel-Buffering', 'no'); $this->data = $content; $this->send(); }
php
public function startBuffering($content) { $this->getHeaders() ->set('Surrogate-Control','BigPipe/1.0') ->set('X-Accel-Buffering', 'no'); $this->data = $content; $this->send(); }
[ "public", "function", "startBuffering", "(", "$", "content", ")", "{", "$", "this", "->", "getHeaders", "(", ")", "->", "set", "(", "'Surrogate-Control'", ",", "'BigPipe/1.0'", ")", "->", "set", "(", "'X-Accel-Buffering'", ",", "'no'", ")", ";", "$", "this", "->", "data", "=", "$", "content", ";", "$", "this", "->", "send", "(", ")", ";", "}" ]
开始分片输出 @param string $content
[ "开始分片输出" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/web/Response.php#L95-L102
php-rise/rise
src/Response.php
Response.send
public function send($content = null) { if ($this->sent) { return $this; } if ($this->request->isMethod('HEAD')) { $this->setMode(self::MODE_STRING); $this->unsetHeader('Content-Length'); $this->setBody(''); } switch ($this->mode) { case self::MODE_STRING: if ($content !== null) { $this->setBody($content); } break; case self::MODE_FILE: if (is_file($content)) { if (!$this->hasHeader('Content-Type')) { $this->setHeader('Content-Type', 'application/octet-stream '); } $this->setHeader('Content-Length', filesize($content)); $this->setBody($content); } else { $this->setMode(self::MODE_STRING); $this->setStatusCode(404); $this->unsetHeader('Content-Length'); $this->setBody(''); } break; case self::MODE_STREAM: $this->setBody($content); break; } $this->sendHeaders(); $this->sendBody(); switch ($this->mode) { case self::MODE_STRING: case self::MODE_FILE: $this->end(); break; } return $this; }
php
public function send($content = null) { if ($this->sent) { return $this; } if ($this->request->isMethod('HEAD')) { $this->setMode(self::MODE_STRING); $this->unsetHeader('Content-Length'); $this->setBody(''); } switch ($this->mode) { case self::MODE_STRING: if ($content !== null) { $this->setBody($content); } break; case self::MODE_FILE: if (is_file($content)) { if (!$this->hasHeader('Content-Type')) { $this->setHeader('Content-Type', 'application/octet-stream '); } $this->setHeader('Content-Length', filesize($content)); $this->setBody($content); } else { $this->setMode(self::MODE_STRING); $this->setStatusCode(404); $this->unsetHeader('Content-Length'); $this->setBody(''); } break; case self::MODE_STREAM: $this->setBody($content); break; } $this->sendHeaders(); $this->sendBody(); switch ($this->mode) { case self::MODE_STRING: case self::MODE_FILE: $this->end(); break; } return $this; }
[ "public", "function", "send", "(", "$", "content", "=", "null", ")", "{", "if", "(", "$", "this", "->", "sent", ")", "{", "return", "$", "this", ";", "}", "if", "(", "$", "this", "->", "request", "->", "isMethod", "(", "'HEAD'", ")", ")", "{", "$", "this", "->", "setMode", "(", "self", "::", "MODE_STRING", ")", ";", "$", "this", "->", "unsetHeader", "(", "'Content-Length'", ")", ";", "$", "this", "->", "setBody", "(", "''", ")", ";", "}", "switch", "(", "$", "this", "->", "mode", ")", "{", "case", "self", "::", "MODE_STRING", ":", "if", "(", "$", "content", "!==", "null", ")", "{", "$", "this", "->", "setBody", "(", "$", "content", ")", ";", "}", "break", ";", "case", "self", "::", "MODE_FILE", ":", "if", "(", "is_file", "(", "$", "content", ")", ")", "{", "if", "(", "!", "$", "this", "->", "hasHeader", "(", "'Content-Type'", ")", ")", "{", "$", "this", "->", "setHeader", "(", "'Content-Type'", ",", "'application/octet-stream '", ")", ";", "}", "$", "this", "->", "setHeader", "(", "'Content-Length'", ",", "filesize", "(", "$", "content", ")", ")", ";", "$", "this", "->", "setBody", "(", "$", "content", ")", ";", "}", "else", "{", "$", "this", "->", "setMode", "(", "self", "::", "MODE_STRING", ")", ";", "$", "this", "->", "setStatusCode", "(", "404", ")", ";", "$", "this", "->", "unsetHeader", "(", "'Content-Length'", ")", ";", "$", "this", "->", "setBody", "(", "''", ")", ";", "}", "break", ";", "case", "self", "::", "MODE_STREAM", ":", "$", "this", "->", "setBody", "(", "$", "content", ")", ";", "break", ";", "}", "$", "this", "->", "sendHeaders", "(", ")", ";", "$", "this", "->", "sendBody", "(", ")", ";", "switch", "(", "$", "this", "->", "mode", ")", "{", "case", "self", "::", "MODE_STRING", ":", "case", "self", "::", "MODE_FILE", ":", "$", "this", "->", "end", "(", ")", ";", "break", ";", "}", "return", "$", "this", ";", "}" ]
Send response. @param mixed $content @return self
[ "Send", "response", "." ]
train
https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Response.php#L218-L268
php-rise/rise
src/Response.php
Response.sendFile
public function sendFile($file) { if ($this->sent) { return $this; } $this->setMode(self::MODE_FILE); $this->send($file); return $this; }
php
public function sendFile($file) { if ($this->sent) { return $this; } $this->setMode(self::MODE_FILE); $this->send($file); return $this; }
[ "public", "function", "sendFile", "(", "$", "file", ")", "{", "if", "(", "$", "this", "->", "sent", ")", "{", "return", "$", "this", ";", "}", "$", "this", "->", "setMode", "(", "self", "::", "MODE_FILE", ")", ";", "$", "this", "->", "send", "(", "$", "file", ")", ";", "return", "$", "this", ";", "}" ]
Send a file. @param string $file @return self
[ "Send", "a", "file", "." ]
train
https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Response.php#L295-L304
php-rise/rise
src/Response.php
Response.redirect
public function redirect($url, $statusCode = 302) { $this->setStatusCode($statusCode) ->setHeader('Location', $url) ->setBody(sprintf('<!DOCTYPE html> <meta charset="UTF-8"> <meta http-equiv="refresh" content="1;url=%1$s"> <title>Redirecting to %1$s</title> Redirecting to <a href="%1$s">%1$s</a>', htmlspecialchars($url, ENT_QUOTES, 'UTF-8'))); return $this; }
php
public function redirect($url, $statusCode = 302) { $this->setStatusCode($statusCode) ->setHeader('Location', $url) ->setBody(sprintf('<!DOCTYPE html> <meta charset="UTF-8"> <meta http-equiv="refresh" content="1;url=%1$s"> <title>Redirecting to %1$s</title> Redirecting to <a href="%1$s">%1$s</a>', htmlspecialchars($url, ENT_QUOTES, 'UTF-8'))); return $this; }
[ "public", "function", "redirect", "(", "$", "url", ",", "$", "statusCode", "=", "302", ")", "{", "$", "this", "->", "setStatusCode", "(", "$", "statusCode", ")", "->", "setHeader", "(", "'Location'", ",", "$", "url", ")", "->", "setBody", "(", "sprintf", "(", "'<!DOCTYPE html>\n<meta charset=\"UTF-8\">\n<meta http-equiv=\"refresh\" content=\"1;url=%1$s\">\n<title>Redirecting to %1$s</title>\nRedirecting to <a href=\"%1$s\">%1$s</a>'", ",", "htmlspecialchars", "(", "$", "url", ",", "ENT_QUOTES", ",", "'UTF-8'", ")", ")", ")", ";", "return", "$", "this", ";", "}" ]
Setup HTTP redirect. @param string $url @param int $statusCode Optional @return self
[ "Setup", "HTTP", "redirect", "." ]
train
https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Response.php#L313-L323
php-rise/rise
src/Response.php
Response.redirectRoute
public function redirectRoute($name, $params = [], $statusCode = 302) { $this->redirect($this->urlGenerator->generate($name, $params), $statusCode); return $this; }
php
public function redirectRoute($name, $params = [], $statusCode = 302) { $this->redirect($this->urlGenerator->generate($name, $params), $statusCode); return $this; }
[ "public", "function", "redirectRoute", "(", "$", "name", ",", "$", "params", "=", "[", "]", ",", "$", "statusCode", "=", "302", ")", "{", "$", "this", "->", "redirect", "(", "$", "this", "->", "urlGenerator", "->", "generate", "(", "$", "name", ",", "$", "params", ")", ",", "$", "statusCode", ")", ";", "return", "$", "this", ";", "}" ]
HTTP redirect to a named route. @param string $routeName @param array $params @param int $statusCode Optional @return self
[ "HTTP", "redirect", "to", "a", "named", "route", "." ]
train
https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Response.php#L333-L336
php-rise/rise
src/Response.php
Response.closeOutputBuffers
public static function closeOutputBuffers($targetLevel, $flush) { $status = ob_get_status(true); $level = count($status); while ($level-- > $targetLevel && (!empty($status[$level]['del']) || (isset($status[$level]['flags']) && ($status[$level]['flags'] & PHP_OUTPUT_HANDLER_REMOVABLE) && ($status[$level]['flags'] & ($flush ? PHP_OUTPUT_HANDLER_FLUSHABLE : PHP_OUTPUT_HANDLER_CLEANABLE)) ) ) ) { if ($flush) { ob_end_flush(); } else { ob_end_clean(); } } }
php
public static function closeOutputBuffers($targetLevel, $flush) { $status = ob_get_status(true); $level = count($status); while ($level-- > $targetLevel && (!empty($status[$level]['del']) || (isset($status[$level]['flags']) && ($status[$level]['flags'] & PHP_OUTPUT_HANDLER_REMOVABLE) && ($status[$level]['flags'] & ($flush ? PHP_OUTPUT_HANDLER_FLUSHABLE : PHP_OUTPUT_HANDLER_CLEANABLE)) ) ) ) { if ($flush) { ob_end_flush(); } else { ob_end_clean(); } } }
[ "public", "static", "function", "closeOutputBuffers", "(", "$", "targetLevel", ",", "$", "flush", ")", "{", "$", "status", "=", "ob_get_status", "(", "true", ")", ";", "$", "level", "=", "count", "(", "$", "status", ")", ";", "while", "(", "$", "level", "--", ">", "$", "targetLevel", "&&", "(", "!", "empty", "(", "$", "status", "[", "$", "level", "]", "[", "'del'", "]", ")", "||", "(", "isset", "(", "$", "status", "[", "$", "level", "]", "[", "'flags'", "]", ")", "&&", "(", "$", "status", "[", "$", "level", "]", "[", "'flags'", "]", "&", "PHP_OUTPUT_HANDLER_REMOVABLE", ")", "&&", "(", "$", "status", "[", "$", "level", "]", "[", "'flags'", "]", "&", "(", "$", "flush", "?", "PHP_OUTPUT_HANDLER_FLUSHABLE", ":", "PHP_OUTPUT_HANDLER_CLEANABLE", ")", ")", ")", ")", ")", "{", "if", "(", "$", "flush", ")", "{", "ob_end_flush", "(", ")", ";", "}", "else", "{", "ob_end_clean", "(", ")", ";", "}", "}", "}" ]
Cleans or flushes output buffers up to target level. @NOTE Function from Symfony\Component\HttpFoundation\Response Resulting level can be greater than target level if a non-removable buffer has been encountered. @param int $targetLevel The target output buffering level @param bool $flush Whether to flush or clean the buffers
[ "Cleans", "or", "flushes", "output", "buffers", "up", "to", "target", "level", "." ]
train
https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Response.php#L561-L579
creonit-dev/PageBundle
Admin/PageTable.php
PageTable.schema
public function schema() { $this->setHandler('synchronize', function($request, $response) { $page = $this->container->get('creonit_page'); $page->synchronizeRoutePages(); $page->clearCache(); }); $this->setHandler('copy', function(ComponentRequest $request, ComponentResponse $response) { $page = PageQuery::create()->findPk($request->query->get('page_id')) or $response->flushError('Страница не найдена'); $unicalCounterName = PageQuery::create()->filterByName("%" . $page->getName() . "%", Criteria::LIKE)->count(); $unicalCounterSlug = PageQuery::create()->filterBySlug("%" . $page->getSlug() . "%", Criteria::LIKE)->count(); $content = $page->getContent(); $newContentId = null; if ($content) { $newContent = new Content(); $newContent ->save(); $newContent ->setText($content->getText()) ->setCompleted($content->getCompleted()) ->setCreatedAt($content->getCreatedAt()) ->setUpdatedAt($content->getUpdatedAt()); $newContent->setNew(false); foreach ($content->getContentBlocks() as $relObj) { if ($relObj !== $content) { $newContent->addContentBlock($relObj->copy(true)); } } $newContent ->save(); $newContentId = $newContent->getId(); } $pageClone = $page->copy(); $pageClone ->insertAtRank($page->getRank() + 1) ->setContentId($newContentId) ->setName($page->getName() . ($page->getName() ? ($unicalCounterName == 1 ? '_copy' : '_copy' . $unicalCounterName) : '')) ->setSlug($page->getSlug() . ($page->getSlug() ? ($unicalCounterSlug == 1 ? '_copy' : '_copy' . $unicalCounterSlug) : '')) ->setUri(preg_replace('/\\/$/', '_copy/', $page->getUri())) ->setVisible(false) ->setTitle($page->getTitle() . ' (Копия)') ->save(); $page = $this->container->get('creonit_page'); $page->synchronizeRoutePages(); $page->clearCache(); }); }
php
public function schema() { $this->setHandler('synchronize', function($request, $response) { $page = $this->container->get('creonit_page'); $page->synchronizeRoutePages(); $page->clearCache(); }); $this->setHandler('copy', function(ComponentRequest $request, ComponentResponse $response) { $page = PageQuery::create()->findPk($request->query->get('page_id')) or $response->flushError('Страница не найдена'); $unicalCounterName = PageQuery::create()->filterByName("%" . $page->getName() . "%", Criteria::LIKE)->count(); $unicalCounterSlug = PageQuery::create()->filterBySlug("%" . $page->getSlug() . "%", Criteria::LIKE)->count(); $content = $page->getContent(); $newContentId = null; if ($content) { $newContent = new Content(); $newContent ->save(); $newContent ->setText($content->getText()) ->setCompleted($content->getCompleted()) ->setCreatedAt($content->getCreatedAt()) ->setUpdatedAt($content->getUpdatedAt()); $newContent->setNew(false); foreach ($content->getContentBlocks() as $relObj) { if ($relObj !== $content) { $newContent->addContentBlock($relObj->copy(true)); } } $newContent ->save(); $newContentId = $newContent->getId(); } $pageClone = $page->copy(); $pageClone ->insertAtRank($page->getRank() + 1) ->setContentId($newContentId) ->setName($page->getName() . ($page->getName() ? ($unicalCounterName == 1 ? '_copy' : '_copy' . $unicalCounterName) : '')) ->setSlug($page->getSlug() . ($page->getSlug() ? ($unicalCounterSlug == 1 ? '_copy' : '_copy' . $unicalCounterSlug) : '')) ->setUri(preg_replace('/\\/$/', '_copy/', $page->getUri())) ->setVisible(false) ->setTitle($page->getTitle() . ' (Копия)') ->save(); $page = $this->container->get('creonit_page'); $page->synchronizeRoutePages(); $page->clearCache(); }); }
[ "public", "function", "schema", "(", ")", "{", "$", "this", "->", "setHandler", "(", "'synchronize'", ",", "function", "(", "$", "request", ",", "$", "response", ")", "{", "$", "page", "=", "$", "this", "->", "container", "->", "get", "(", "'creonit_page'", ")", ";", "$", "page", "->", "synchronizeRoutePages", "(", ")", ";", "$", "page", "->", "clearCache", "(", ")", ";", "}", ")", ";", "$", "this", "->", "setHandler", "(", "'copy'", ",", "function", "(", "ComponentRequest", "$", "request", ",", "ComponentResponse", "$", "response", ")", "{", "$", "page", "=", "PageQuery", "::", "create", "(", ")", "->", "findPk", "(", "$", "request", "->", "query", "->", "get", "(", "'page_id'", ")", ")", "or", "$", "response", "->", "flushError", "(", "'Страница не найдена');", "", "", "$", "unicalCounterName", "=", "PageQuery", "::", "create", "(", ")", "->", "filterByName", "(", "\"%\"", ".", "$", "page", "->", "getName", "(", ")", ".", "\"%\"", ",", "Criteria", "::", "LIKE", ")", "->", "count", "(", ")", ";", "$", "unicalCounterSlug", "=", "PageQuery", "::", "create", "(", ")", "->", "filterBySlug", "(", "\"%\"", ".", "$", "page", "->", "getSlug", "(", ")", ".", "\"%\"", ",", "Criteria", "::", "LIKE", ")", "->", "count", "(", ")", ";", "$", "content", "=", "$", "page", "->", "getContent", "(", ")", ";", "$", "newContentId", "=", "null", ";", "if", "(", "$", "content", ")", "{", "$", "newContent", "=", "new", "Content", "(", ")", ";", "$", "newContent", "->", "save", "(", ")", ";", "$", "newContent", "->", "setText", "(", "$", "content", "->", "getText", "(", ")", ")", "->", "setCompleted", "(", "$", "content", "->", "getCompleted", "(", ")", ")", "->", "setCreatedAt", "(", "$", "content", "->", "getCreatedAt", "(", ")", ")", "->", "setUpdatedAt", "(", "$", "content", "->", "getUpdatedAt", "(", ")", ")", ";", "$", "newContent", "->", "setNew", "(", "false", ")", ";", "foreach", "(", "$", "content", "->", "getContentBlocks", "(", ")", "as", "$", "relObj", ")", "{", "if", "(", "$", "relObj", "!==", "$", "content", ")", "{", "$", "newContent", "->", "addContentBlock", "(", "$", "relObj", "->", "copy", "(", "true", ")", ")", ";", "}", "}", "$", "newContent", "->", "save", "(", ")", ";", "$", "newContentId", "=", "$", "newContent", "->", "getId", "(", ")", ";", "}", "$", "pageClone", "=", "$", "page", "->", "copy", "(", ")", ";", "$", "pageClone", "->", "insertAtRank", "(", "$", "page", "->", "getRank", "(", ")", "+", "1", ")", "->", "setContentId", "(", "$", "newContentId", ")", "->", "setName", "(", "$", "page", "->", "getName", "(", ")", ".", "(", "$", "page", "->", "getName", "(", ")", "?", "(", "$", "unicalCounterName", "==", "1", "?", "'_copy'", ":", "'_copy'", ".", "$", "unicalCounterName", ")", ":", "''", ")", ")", "->", "setSlug", "(", "$", "page", "->", "getSlug", "(", ")", ".", "(", "$", "page", "->", "getSlug", "(", ")", "?", "(", "$", "unicalCounterSlug", "==", "1", "?", "'_copy'", ":", "'_copy'", ".", "$", "unicalCounterSlug", ")", ":", "''", ")", ")", "->", "setUri", "(", "preg_replace", "(", "'/\\\\/$/'", ",", "'_copy/'", ",", "$", "page", "->", "getUri", "(", ")", ")", ")", "->", "setVisible", "(", "false", ")", "->", "setTitle", "(", "$", "page", "->", "getTitle", "(", ")", ".", "' (Копия)')", "", "->", "save", "(", ")", ";", "$", "page", "=", "$", "this", "->", "container", "->", "get", "(", "'creonit_page'", ")", ";", "$", "page", "->", "synchronizeRoutePages", "(", ")", ";", "$", "page", "->", "clearCache", "(", ")", ";", "}", ")", ";", "}" ]
@title Список страниц @header {{ button('Добавить страницу', {size: 'sm', icon: 'file-text-o', type: 'success'}) | open('Page.PageEditor') }} {{ button('Синхронизировать', {size: 'sm', icon: 'refresh'}) | action('synchronize') }} @cols Заголовок, Идентификатор, URL, . @action synchronize(){ this.request('synchronize', {}, {}, function(){ alert('Синхронизация прошла успешно'); }); this.loadData(); } @action copy(options){ var $row = this.findRowById(options.rowId); this.request('copy', $.extend({page_id: options.key}, this.getQuery()), {state: $row.hasClass('success')}); this.loadData(); } \Page @entity Creonit\PageBundle\Model\Page @relation parent_id > Page.id @sortable true @field id @field parent_id @field title @field type @col {% if type == 3 %} {% set icon = 'bars' %} {% elseif type == 2 %} {% set icon = 'share' %} {% elseif type == 1 %} {% set icon = 'file-text-o' %} {% else %} {% set icon = 'cog' %} {% endif %} {{ title | icon(icon) | open('Page.PageEditor', {key: _key}) | controls( (type != 2 ? button('', {size: 'xs', icon: 'file-text-o'}) | tooltip('Добавить страницу') | open('Page.PageEditor', {relation: _key}) : '') ~ ' ' ~ (type == 1 ? button('', {size: 'xs', icon: 'copy'}) | tooltip('Клонировать') | action('copy', {key: _key, rowId: _row_id}) : '') ) }} @col {{ name }} @col {{ url | raw }} @col {% if type %} {{ buttons(_visible() ~ _delete() ) }} {% else %} {{ buttons(_visible() ~ button('', {icon: 'remove', size: 'xs', disabled: true}) ) }} {% endif %}
[ "@title", "Список", "страниц", "@header", "{{", "button", "(", "Добавить", "страницу", "{", "size", ":", "sm", "icon", ":", "file", "-", "text", "-", "o", "type", ":", "success", "}", ")", "|", "open", "(", "Page", ".", "PageEditor", ")", "}}", "{{", "button", "(", "Синхронизировать", "{", "size", ":", "sm", "icon", ":", "refresh", "}", ")", "|", "action", "(", "synchronize", ")", "}}", "@cols", "Заголовок", "Идентификатор", "URL", "." ]
train
https://github.com/creonit-dev/PageBundle/blob/05aee8f91772aceaea6e688ac4e0593ca98d7884/Admin/PageTable.php#L74-L128
barebone-php/barebone-core
lib/LogTrait.php
LogTrait.log
public function log($text, $severity = 'info') { if ($severity === 'warn' || $severity === 'warning') { return Log::warning($text); } if ($severity === 'err' || $severity === 'error') { return Log::error($text); } return Log::info($text); }
php
public function log($text, $severity = 'info') { if ($severity === 'warn' || $severity === 'warning') { return Log::warning($text); } if ($severity === 'err' || $severity === 'error') { return Log::error($text); } return Log::info($text); }
[ "public", "function", "log", "(", "$", "text", ",", "$", "severity", "=", "'info'", ")", "{", "if", "(", "$", "severity", "===", "'warn'", "||", "$", "severity", "===", "'warning'", ")", "{", "return", "Log", "::", "warning", "(", "$", "text", ")", ";", "}", "if", "(", "$", "severity", "===", "'err'", "||", "$", "severity", "===", "'error'", ")", "{", "return", "Log", "::", "error", "(", "$", "text", ")", ";", "}", "return", "Log", "::", "info", "(", "$", "text", ")", ";", "}" ]
Write to application log @param string $text message @param string $severity Either 'info', 'warn' or 'error' @return Boolean Whether the record has been processed
[ "Write", "to", "application", "log" ]
train
https://github.com/barebone-php/barebone-core/blob/7fda3a62d5fa103cdc4d2d34e1adf8f3ccbfe2bc/lib/LogTrait.php#L38-L49
jfusion/org.jfusion.framework
src/User/Userinfo.php
Userinfo.getAnonymizeed
public function getAnonymizeed() { $userinfo = $this->toObject(); $userinfo->password_clear = '******'; if (isset($userinfo->password)) { $userinfo->password = substr($userinfo->password, 0, 6) . '********'; } if (isset($userinfo->password_salt)) { $userinfo->password_salt = substr($userinfo->password_salt, 0, 4) . '*****'; } return $userinfo; }
php
public function getAnonymizeed() { $userinfo = $this->toObject(); $userinfo->password_clear = '******'; if (isset($userinfo->password)) { $userinfo->password = substr($userinfo->password, 0, 6) . '********'; } if (isset($userinfo->password_salt)) { $userinfo->password_salt = substr($userinfo->password_salt, 0, 4) . '*****'; } return $userinfo; }
[ "public", "function", "getAnonymizeed", "(", ")", "{", "$", "userinfo", "=", "$", "this", "->", "toObject", "(", ")", ";", "$", "userinfo", "->", "password_clear", "=", "'******'", ";", "if", "(", "isset", "(", "$", "userinfo", "->", "password", ")", ")", "{", "$", "userinfo", "->", "password", "=", "substr", "(", "$", "userinfo", "->", "password", ",", "0", ",", "6", ")", ".", "'********'", ";", "}", "if", "(", "isset", "(", "$", "userinfo", "->", "password_salt", ")", ")", "{", "$", "userinfo", "->", "password_salt", "=", "substr", "(", "$", "userinfo", "->", "password_salt", ",", "0", ",", "4", ")", ".", "'*****'", ";", "}", "return", "$", "userinfo", ";", "}" ]
hides sensitive information @return stdClass parsed userinfo object
[ "hides", "sensitive", "information" ]
train
https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/User/Userinfo.php#L210-L221
netgen/metadata-bundle
bundle/Form/Type/FieldType/FieldValueTransformer.php
FieldValueTransformer.transform
public function transform($value) { if (!$value instanceof Value) { return null; } return array( 'title' => $value->title, 'description' => $value->description, 'keywords' => implode(',', $value->keywords), 'priority' => $value->priority, 'change' => $value->change, 'sitemap_use' => !empty($value->sitemap_use), ); }
php
public function transform($value) { if (!$value instanceof Value) { return null; } return array( 'title' => $value->title, 'description' => $value->description, 'keywords' => implode(',', $value->keywords), 'priority' => $value->priority, 'change' => $value->change, 'sitemap_use' => !empty($value->sitemap_use), ); }
[ "public", "function", "transform", "(", "$", "value", ")", "{", "if", "(", "!", "$", "value", "instanceof", "Value", ")", "{", "return", "null", ";", "}", "return", "array", "(", "'title'", "=>", "$", "value", "->", "title", ",", "'description'", "=>", "$", "value", "->", "description", ",", "'keywords'", "=>", "implode", "(", "','", ",", "$", "value", "->", "keywords", ")", ",", "'priority'", "=>", "$", "value", "->", "priority", ",", "'change'", "=>", "$", "value", "->", "change", ",", "'sitemap_use'", "=>", "!", "empty", "(", "$", "value", "->", "sitemap_use", ")", ",", ")", ";", "}" ]
@param \Netgen\Bundle\MetadataBundle\Core\FieldType\Metadata\Value $value @return array
[ "@param", "\\", "Netgen", "\\", "Bundle", "\\", "MetadataBundle", "\\", "Core", "\\", "FieldType", "\\", "Metadata", "\\", "Value", "$value" ]
train
https://github.com/netgen/metadata-bundle/blob/12bfca68e8e8f4be409c7151f99dff665c53755b/bundle/Form/Type/FieldType/FieldValueTransformer.php#L26-L40
dburkart/scurvy
Scurvy.php
Scurvy.render
private function render() { $strings = implode($this->strings); // Render includes foreach ($this->incTemplates as $path => $include) { $incOutput = $include->render(); $path = preg_replace("/\//", "\/", $path); $strings = preg_replace("/\{include\s$path\}/", $incOutput, $strings); } // Render if-statements foreach ($this->ifTemplates as $key => $sub) { foreach ($sub as $iKey => $instance) { $str = ''; if ($this->expressions[$key]->evaluate($this->vars)) { $str = $instance->render(); } $pregKey = preg_quote($key, '/'); $strings = preg_replace("/\{if:$pregKey:$iKey\}/", $str, $strings); } } // Render foreach-loops foreach ($this->forTemplates as $key => $sub) { foreach ($sub as $iKey => $instance) { $tmplGen = ''; if (isset($this->vars[$key]) && is_array($this->vars[$key])) { foreach ($this->vars[$key] as $assocArray) { foreach ($assocArray as $k => $v) $instance->set($k, $v); $tmplGen .= $instance->render(); } } $pregKey = preg_quote($key, '/'); $strings = preg_replace("/\{for:$pregKey:$iKey\}/", $tmplGen, $strings); } } // Render plain old variables foreach ($this->vars as $key => $val) { if (!is_array($val)) $strings = preg_replace("/\{$key\}/", $val, $strings); } // Render expressions foreach ($this->expressions as $key => $expr) { $eval = $expr->evaluate($this->vars); // If we're an array, lets insert the number of items in the array. if ( is_array( $eval ) ) { $eval = count( $eval ); } $pregKey = preg_quote($key, '/'); $strings = preg_replace('/\{'.$pregKey.'\}/', $eval, $strings); } $strings = preg_replace("/\\\{/", '{', $strings); $strings = preg_replace("/\\\}/", '}', $strings); return $strings; }
php
private function render() { $strings = implode($this->strings); // Render includes foreach ($this->incTemplates as $path => $include) { $incOutput = $include->render(); $path = preg_replace("/\//", "\/", $path); $strings = preg_replace("/\{include\s$path\}/", $incOutput, $strings); } // Render if-statements foreach ($this->ifTemplates as $key => $sub) { foreach ($sub as $iKey => $instance) { $str = ''; if ($this->expressions[$key]->evaluate($this->vars)) { $str = $instance->render(); } $pregKey = preg_quote($key, '/'); $strings = preg_replace("/\{if:$pregKey:$iKey\}/", $str, $strings); } } // Render foreach-loops foreach ($this->forTemplates as $key => $sub) { foreach ($sub as $iKey => $instance) { $tmplGen = ''; if (isset($this->vars[$key]) && is_array($this->vars[$key])) { foreach ($this->vars[$key] as $assocArray) { foreach ($assocArray as $k => $v) $instance->set($k, $v); $tmplGen .= $instance->render(); } } $pregKey = preg_quote($key, '/'); $strings = preg_replace("/\{for:$pregKey:$iKey\}/", $tmplGen, $strings); } } // Render plain old variables foreach ($this->vars as $key => $val) { if (!is_array($val)) $strings = preg_replace("/\{$key\}/", $val, $strings); } // Render expressions foreach ($this->expressions as $key => $expr) { $eval = $expr->evaluate($this->vars); // If we're an array, lets insert the number of items in the array. if ( is_array( $eval ) ) { $eval = count( $eval ); } $pregKey = preg_quote($key, '/'); $strings = preg_replace('/\{'.$pregKey.'\}/', $eval, $strings); } $strings = preg_replace("/\\\{/", '{', $strings); $strings = preg_replace("/\\\}/", '}', $strings); return $strings; }
[ "private", "function", "render", "(", ")", "{", "$", "strings", "=", "implode", "(", "$", "this", "->", "strings", ")", ";", "// Render includes", "foreach", "(", "$", "this", "->", "incTemplates", "as", "$", "path", "=>", "$", "include", ")", "{", "$", "incOutput", "=", "$", "include", "->", "render", "(", ")", ";", "$", "path", "=", "preg_replace", "(", "\"/\\//\"", ",", "\"\\/\"", ",", "$", "path", ")", ";", "$", "strings", "=", "preg_replace", "(", "\"/\\{include\\s$path\\}/\"", ",", "$", "incOutput", ",", "$", "strings", ")", ";", "}", "// Render if-statements", "foreach", "(", "$", "this", "->", "ifTemplates", "as", "$", "key", "=>", "$", "sub", ")", "{", "foreach", "(", "$", "sub", "as", "$", "iKey", "=>", "$", "instance", ")", "{", "$", "str", "=", "''", ";", "if", "(", "$", "this", "->", "expressions", "[", "$", "key", "]", "->", "evaluate", "(", "$", "this", "->", "vars", ")", ")", "{", "$", "str", "=", "$", "instance", "->", "render", "(", ")", ";", "}", "$", "pregKey", "=", "preg_quote", "(", "$", "key", ",", "'/'", ")", ";", "$", "strings", "=", "preg_replace", "(", "\"/\\{if:$pregKey:$iKey\\}/\"", ",", "$", "str", ",", "$", "strings", ")", ";", "}", "}", "// Render foreach-loops", "foreach", "(", "$", "this", "->", "forTemplates", "as", "$", "key", "=>", "$", "sub", ")", "{", "foreach", "(", "$", "sub", "as", "$", "iKey", "=>", "$", "instance", ")", "{", "$", "tmplGen", "=", "''", ";", "if", "(", "isset", "(", "$", "this", "->", "vars", "[", "$", "key", "]", ")", "&&", "is_array", "(", "$", "this", "->", "vars", "[", "$", "key", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "vars", "[", "$", "key", "]", "as", "$", "assocArray", ")", "{", "foreach", "(", "$", "assocArray", "as", "$", "k", "=>", "$", "v", ")", "$", "instance", "->", "set", "(", "$", "k", ",", "$", "v", ")", ";", "$", "tmplGen", ".=", "$", "instance", "->", "render", "(", ")", ";", "}", "}", "$", "pregKey", "=", "preg_quote", "(", "$", "key", ",", "'/'", ")", ";", "$", "strings", "=", "preg_replace", "(", "\"/\\{for:$pregKey:$iKey\\}/\"", ",", "$", "tmplGen", ",", "$", "strings", ")", ";", "}", "}", "// Render plain old variables", "foreach", "(", "$", "this", "->", "vars", "as", "$", "key", "=>", "$", "val", ")", "{", "if", "(", "!", "is_array", "(", "$", "val", ")", ")", "$", "strings", "=", "preg_replace", "(", "\"/\\{$key\\}/\"", ",", "$", "val", ",", "$", "strings", ")", ";", "}", "// Render expressions", "foreach", "(", "$", "this", "->", "expressions", "as", "$", "key", "=>", "$", "expr", ")", "{", "$", "eval", "=", "$", "expr", "->", "evaluate", "(", "$", "this", "->", "vars", ")", ";", "// If we're an array, lets insert the number of items in the array.", "if", "(", "is_array", "(", "$", "eval", ")", ")", "{", "$", "eval", "=", "count", "(", "$", "eval", ")", ";", "}", "$", "pregKey", "=", "preg_quote", "(", "$", "key", ",", "'/'", ")", ";", "$", "strings", "=", "preg_replace", "(", "'/\\{'", ".", "$", "pregKey", ".", "'\\}/'", ",", "$", "eval", ",", "$", "strings", ")", ";", "}", "$", "strings", "=", "preg_replace", "(", "\"/\\\\\\{/\"", ",", "'{'", ",", "$", "strings", ")", ";", "$", "strings", "=", "preg_replace", "(", "\"/\\\\\\}/\"", ",", "'}'", ",", "$", "strings", ")", ";", "return", "$", "strings", ";", "}" ]
The render function goes through and renders the parsed document. @return string containing the rendered output.
[ "The", "render", "function", "goes", "through", "and", "renders", "the", "parsed", "document", "." ]
train
https://github.com/dburkart/scurvy/blob/990a7c4f0517298de304438cf9cd95a303a231fb/Scurvy.php#L102-L168
dburkart/scurvy
Scurvy.php
Scurvy.set
private function set($var, $val) { $this->vars[$var] = $val; // We also need to set $var on each sub-template. So recursively do that foreach($this->forTemplates as $templateBunch) foreach($templateBunch as $sub) $sub->set($var, $val); foreach($this->ifTemplates as $templateBunch) foreach($templateBunch as $sub) $sub->set($var, $val); foreach($this->incTemplates as $sub) $sub->set($var, $val); }
php
private function set($var, $val) { $this->vars[$var] = $val; // We also need to set $var on each sub-template. So recursively do that foreach($this->forTemplates as $templateBunch) foreach($templateBunch as $sub) $sub->set($var, $val); foreach($this->ifTemplates as $templateBunch) foreach($templateBunch as $sub) $sub->set($var, $val); foreach($this->incTemplates as $sub) $sub->set($var, $val); }
[ "private", "function", "set", "(", "$", "var", ",", "$", "val", ")", "{", "$", "this", "->", "vars", "[", "$", "var", "]", "=", "$", "val", ";", "// We also need to set $var on each sub-template. So recursively do that", "foreach", "(", "$", "this", "->", "forTemplates", "as", "$", "templateBunch", ")", "foreach", "(", "$", "templateBunch", "as", "$", "sub", ")", "$", "sub", "->", "set", "(", "$", "var", ",", "$", "val", ")", ";", "foreach", "(", "$", "this", "->", "ifTemplates", "as", "$", "templateBunch", ")", "foreach", "(", "$", "templateBunch", "as", "$", "sub", ")", "$", "sub", "->", "set", "(", "$", "var", ",", "$", "val", ")", ";", "foreach", "(", "$", "this", "->", "incTemplates", "as", "$", "sub", ")", "$", "sub", "->", "set", "(", "$", "var", ",", "$", "val", ")", ";", "}" ]
Sets the value of a variable. @param string $var variable to set @param mixed $val value to set var to
[ "Sets", "the", "value", "of", "a", "variable", "." ]
train
https://github.com/dburkart/scurvy/blob/990a7c4f0517298de304438cf9cd95a303a231fb/Scurvy.php#L176-L190
dburkart/scurvy
Scurvy.php
Scurvy.require_file
protected function require_file($file) { if (file_exists($this->template_dir . $file)) { require_once $this->template_dir . $file; return true; } return false; }
php
protected function require_file($file) { if (file_exists($this->template_dir . $file)) { require_once $this->template_dir . $file; return true; } return false; }
[ "protected", "function", "require_file", "(", "$", "file", ")", "{", "if", "(", "file_exists", "(", "$", "this", "->", "template_dir", ".", "$", "file", ")", ")", "{", "require_once", "$", "this", "->", "template_dir", ".", "$", "file", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
--- Protected functions ------------------------------------------------//
[ "---", "Protected", "functions", "------------------------------------------------", "//" ]
train
https://github.com/dburkart/scurvy/blob/990a7c4f0517298de304438cf9cd95a303a231fb/Scurvy.php#L194-L200
dburkart/scurvy
Scurvy.php
Scurvy.parse
private function parse() { if ($this->cache) { $this->cacheFile = $this->CACHE_DIR.'/'.$this->name.$this->checksum(); // Make sure we have a cache directory to write to if (!is_dir($this->CACHE_DIR)) { mkdir($this->CACHE_DIR); } // If our cache file already exists, load it up if (file_exists($this->cacheFile)) { $this->cacheTemplate = unserialize(file_get_contents($this->cacheFile)); return; } } $count = count($this->strings); for ($i = 0; $i < $count; $i++) { $matches = null; // Remove all comments $n = preg_match(self::RE_COM_BEG, $this->strings[$i], $matches); if ($n > 0) { $this->parseRecursive($i, array(self::RE_COM_BEG, self::RE_COM_END), 'comment'); $this->strings[$i] = ''; } // Find all the variables. If the variable doesn't exist in our // dictionary, stub it out. preg_match_all(self::RE_VAR, $this->strings[$i], $matches); if (!empty($matches[0])) { foreach ($matches[1] as $match) { if (!isset($this->vars[$match])) $this->vars[$match] = ''; } } // Find all foreach-loops. Every time we find one, make a new // template with the contents of that loop, and put a placeholder // where it used to be. $n = preg_match(self::RE_FOR_BEG, $this->strings[$i], $matches); if ($n > 0) { $forName = $matches[1]; if (!isset($this->forTemplates[$forName])) $this->forTemplates[$forName] = array(); $n = count($this->forTemplates[$forName]); $this->forTemplates[$forName][$n] = $this->parseRecursive($i, array(self::RE_FOR_BEG, self::RE_FOR_END), "{$this->name}_for_{$forName}_$n"); $this->strings[$i] = '{for:'.$forName.':'.$n.'}'; } // Do the same general process for our if statement. $n = preg_match(self::RE_IF_BEG, $this->strings[$i], $matches); if ($n > 0) { $ifExpr = new expression($matches[1]); $exprId = $ifExpr->getExpressionId(); if (!isset($this->expressions[$exprId])) $this->expressions[$exprId] = $ifExpr; if (!isset($this->ifTemplates[$exprId])) $this->ifTemplates[$exprId] = array(); $n = count($this->ifTemplates[$exprId]); $this->ifTemplates[$exprId][$n] = $this->parseRecursive($i, array(self::RE_IF_BEG, self::RE_IF_END), "{$this->name}_if_{$exprId}_$n"); $this->strings[$i] = '{if:'.$exprId.':'.$n.'}'; } // Currently, we have the same general process for includes. But.. // there are problems with this approach. In the future, this could // be refactored. // // TODO: Move this block of code to the beginning, and instead of // creating a template, just replace the include statement with // the file contents of the include. preg_match_all(self::RE_INC, $this->strings[$i], $matches); if (!empty($matches[0])) { foreach($matches[1] as $match) { if (!isset($this->incTemplates[$match])) { $info = pathinfo($match); if ($info['extension'] == 'php') { ob_start(); $this->require_file($match); $output = array(ob_get_clean()); $this->incTemplates[$match] = new Scurvy($output, $this->template_dir, false, $this->name); } else { $this->incTemplates[$match] = new Scurvy($match, $this->template_dir, false, $this->name); } } } } // Find all expressions. We could probably get rid of this feature // because expressions probably won't be used outside of // if-statements. preg_match_all(self::RE_EXPR, $this->strings[$i], $matches); if (!empty($matches[0])) { foreach ($matches[1] as $match) { $expr = new Expression($match); $exprId = $expr->getExpressionId(); if (!isset($this->expressions[$exprId])) $this->expressions[$exprId] = $expr; $this->strings[$i] = preg_replace('/\{'.preg_quote($expr->getExpression(), '/').'\}/', '{'.$exprId.'}', $this->strings[$i]); } } } // If we've gotten here, we must need to cache this file if ($this->cache) { file_put_contents($this->cacheFile, serialize($this)); $this->cacheTemplate = $this; } }
php
private function parse() { if ($this->cache) { $this->cacheFile = $this->CACHE_DIR.'/'.$this->name.$this->checksum(); // Make sure we have a cache directory to write to if (!is_dir($this->CACHE_DIR)) { mkdir($this->CACHE_DIR); } // If our cache file already exists, load it up if (file_exists($this->cacheFile)) { $this->cacheTemplate = unserialize(file_get_contents($this->cacheFile)); return; } } $count = count($this->strings); for ($i = 0; $i < $count; $i++) { $matches = null; // Remove all comments $n = preg_match(self::RE_COM_BEG, $this->strings[$i], $matches); if ($n > 0) { $this->parseRecursive($i, array(self::RE_COM_BEG, self::RE_COM_END), 'comment'); $this->strings[$i] = ''; } // Find all the variables. If the variable doesn't exist in our // dictionary, stub it out. preg_match_all(self::RE_VAR, $this->strings[$i], $matches); if (!empty($matches[0])) { foreach ($matches[1] as $match) { if (!isset($this->vars[$match])) $this->vars[$match] = ''; } } // Find all foreach-loops. Every time we find one, make a new // template with the contents of that loop, and put a placeholder // where it used to be. $n = preg_match(self::RE_FOR_BEG, $this->strings[$i], $matches); if ($n > 0) { $forName = $matches[1]; if (!isset($this->forTemplates[$forName])) $this->forTemplates[$forName] = array(); $n = count($this->forTemplates[$forName]); $this->forTemplates[$forName][$n] = $this->parseRecursive($i, array(self::RE_FOR_BEG, self::RE_FOR_END), "{$this->name}_for_{$forName}_$n"); $this->strings[$i] = '{for:'.$forName.':'.$n.'}'; } // Do the same general process for our if statement. $n = preg_match(self::RE_IF_BEG, $this->strings[$i], $matches); if ($n > 0) { $ifExpr = new expression($matches[1]); $exprId = $ifExpr->getExpressionId(); if (!isset($this->expressions[$exprId])) $this->expressions[$exprId] = $ifExpr; if (!isset($this->ifTemplates[$exprId])) $this->ifTemplates[$exprId] = array(); $n = count($this->ifTemplates[$exprId]); $this->ifTemplates[$exprId][$n] = $this->parseRecursive($i, array(self::RE_IF_BEG, self::RE_IF_END), "{$this->name}_if_{$exprId}_$n"); $this->strings[$i] = '{if:'.$exprId.':'.$n.'}'; } // Currently, we have the same general process for includes. But.. // there are problems with this approach. In the future, this could // be refactored. // // TODO: Move this block of code to the beginning, and instead of // creating a template, just replace the include statement with // the file contents of the include. preg_match_all(self::RE_INC, $this->strings[$i], $matches); if (!empty($matches[0])) { foreach($matches[1] as $match) { if (!isset($this->incTemplates[$match])) { $info = pathinfo($match); if ($info['extension'] == 'php') { ob_start(); $this->require_file($match); $output = array(ob_get_clean()); $this->incTemplates[$match] = new Scurvy($output, $this->template_dir, false, $this->name); } else { $this->incTemplates[$match] = new Scurvy($match, $this->template_dir, false, $this->name); } } } } // Find all expressions. We could probably get rid of this feature // because expressions probably won't be used outside of // if-statements. preg_match_all(self::RE_EXPR, $this->strings[$i], $matches); if (!empty($matches[0])) { foreach ($matches[1] as $match) { $expr = new Expression($match); $exprId = $expr->getExpressionId(); if (!isset($this->expressions[$exprId])) $this->expressions[$exprId] = $expr; $this->strings[$i] = preg_replace('/\{'.preg_quote($expr->getExpression(), '/').'\}/', '{'.$exprId.'}', $this->strings[$i]); } } } // If we've gotten here, we must need to cache this file if ($this->cache) { file_put_contents($this->cacheFile, serialize($this)); $this->cacheTemplate = $this; } }
[ "private", "function", "parse", "(", ")", "{", "if", "(", "$", "this", "->", "cache", ")", "{", "$", "this", "->", "cacheFile", "=", "$", "this", "->", "CACHE_DIR", ".", "'/'", ".", "$", "this", "->", "name", ".", "$", "this", "->", "checksum", "(", ")", ";", "// Make sure we have a cache directory to write to", "if", "(", "!", "is_dir", "(", "$", "this", "->", "CACHE_DIR", ")", ")", "{", "mkdir", "(", "$", "this", "->", "CACHE_DIR", ")", ";", "}", "// If our cache file already exists, load it up", "if", "(", "file_exists", "(", "$", "this", "->", "cacheFile", ")", ")", "{", "$", "this", "->", "cacheTemplate", "=", "unserialize", "(", "file_get_contents", "(", "$", "this", "->", "cacheFile", ")", ")", ";", "return", ";", "}", "}", "$", "count", "=", "count", "(", "$", "this", "->", "strings", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "$", "matches", "=", "null", ";", "// Remove all comments", "$", "n", "=", "preg_match", "(", "self", "::", "RE_COM_BEG", ",", "$", "this", "->", "strings", "[", "$", "i", "]", ",", "$", "matches", ")", ";", "if", "(", "$", "n", ">", "0", ")", "{", "$", "this", "->", "parseRecursive", "(", "$", "i", ",", "array", "(", "self", "::", "RE_COM_BEG", ",", "self", "::", "RE_COM_END", ")", ",", "'comment'", ")", ";", "$", "this", "->", "strings", "[", "$", "i", "]", "=", "''", ";", "}", "// Find all the variables. If the variable doesn't exist in our", "// dictionary, stub it out.", "preg_match_all", "(", "self", "::", "RE_VAR", ",", "$", "this", "->", "strings", "[", "$", "i", "]", ",", "$", "matches", ")", ";", "if", "(", "!", "empty", "(", "$", "matches", "[", "0", "]", ")", ")", "{", "foreach", "(", "$", "matches", "[", "1", "]", "as", "$", "match", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "vars", "[", "$", "match", "]", ")", ")", "$", "this", "->", "vars", "[", "$", "match", "]", "=", "''", ";", "}", "}", "// Find all foreach-loops. Every time we find one, make a new", "// template with the contents of that loop, and put a placeholder", "// where it used to be.", "$", "n", "=", "preg_match", "(", "self", "::", "RE_FOR_BEG", ",", "$", "this", "->", "strings", "[", "$", "i", "]", ",", "$", "matches", ")", ";", "if", "(", "$", "n", ">", "0", ")", "{", "$", "forName", "=", "$", "matches", "[", "1", "]", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "forTemplates", "[", "$", "forName", "]", ")", ")", "$", "this", "->", "forTemplates", "[", "$", "forName", "]", "=", "array", "(", ")", ";", "$", "n", "=", "count", "(", "$", "this", "->", "forTemplates", "[", "$", "forName", "]", ")", ";", "$", "this", "->", "forTemplates", "[", "$", "forName", "]", "[", "$", "n", "]", "=", "$", "this", "->", "parseRecursive", "(", "$", "i", ",", "array", "(", "self", "::", "RE_FOR_BEG", ",", "self", "::", "RE_FOR_END", ")", ",", "\"{$this->name}_for_{$forName}_$n\"", ")", ";", "$", "this", "->", "strings", "[", "$", "i", "]", "=", "'{for:'", ".", "$", "forName", ".", "':'", ".", "$", "n", ".", "'}'", ";", "}", "// Do the same general process for our if statement.", "$", "n", "=", "preg_match", "(", "self", "::", "RE_IF_BEG", ",", "$", "this", "->", "strings", "[", "$", "i", "]", ",", "$", "matches", ")", ";", "if", "(", "$", "n", ">", "0", ")", "{", "$", "ifExpr", "=", "new", "expression", "(", "$", "matches", "[", "1", "]", ")", ";", "$", "exprId", "=", "$", "ifExpr", "->", "getExpressionId", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "expressions", "[", "$", "exprId", "]", ")", ")", "$", "this", "->", "expressions", "[", "$", "exprId", "]", "=", "$", "ifExpr", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "ifTemplates", "[", "$", "exprId", "]", ")", ")", "$", "this", "->", "ifTemplates", "[", "$", "exprId", "]", "=", "array", "(", ")", ";", "$", "n", "=", "count", "(", "$", "this", "->", "ifTemplates", "[", "$", "exprId", "]", ")", ";", "$", "this", "->", "ifTemplates", "[", "$", "exprId", "]", "[", "$", "n", "]", "=", "$", "this", "->", "parseRecursive", "(", "$", "i", ",", "array", "(", "self", "::", "RE_IF_BEG", ",", "self", "::", "RE_IF_END", ")", ",", "\"{$this->name}_if_{$exprId}_$n\"", ")", ";", "$", "this", "->", "strings", "[", "$", "i", "]", "=", "'{if:'", ".", "$", "exprId", ".", "':'", ".", "$", "n", ".", "'}'", ";", "}", "// Currently, we have the same general process for includes. But..", "// there are problems with this approach. In the future, this could", "// be refactored.", "//", "// TODO: Move this block of code to the beginning, and instead of", "// creating a template, just replace the include statement with", "// the file contents of the include.", "preg_match_all", "(", "self", "::", "RE_INC", ",", "$", "this", "->", "strings", "[", "$", "i", "]", ",", "$", "matches", ")", ";", "if", "(", "!", "empty", "(", "$", "matches", "[", "0", "]", ")", ")", "{", "foreach", "(", "$", "matches", "[", "1", "]", "as", "$", "match", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "incTemplates", "[", "$", "match", "]", ")", ")", "{", "$", "info", "=", "pathinfo", "(", "$", "match", ")", ";", "if", "(", "$", "info", "[", "'extension'", "]", "==", "'php'", ")", "{", "ob_start", "(", ")", ";", "$", "this", "->", "require_file", "(", "$", "match", ")", ";", "$", "output", "=", "array", "(", "ob_get_clean", "(", ")", ")", ";", "$", "this", "->", "incTemplates", "[", "$", "match", "]", "=", "new", "Scurvy", "(", "$", "output", ",", "$", "this", "->", "template_dir", ",", "false", ",", "$", "this", "->", "name", ")", ";", "}", "else", "{", "$", "this", "->", "incTemplates", "[", "$", "match", "]", "=", "new", "Scurvy", "(", "$", "match", ",", "$", "this", "->", "template_dir", ",", "false", ",", "$", "this", "->", "name", ")", ";", "}", "}", "}", "}", "// Find all expressions. We could probably get rid of this feature", "// because expressions probably won't be used outside of", "// if-statements.", "preg_match_all", "(", "self", "::", "RE_EXPR", ",", "$", "this", "->", "strings", "[", "$", "i", "]", ",", "$", "matches", ")", ";", "if", "(", "!", "empty", "(", "$", "matches", "[", "0", "]", ")", ")", "{", "foreach", "(", "$", "matches", "[", "1", "]", "as", "$", "match", ")", "{", "$", "expr", "=", "new", "Expression", "(", "$", "match", ")", ";", "$", "exprId", "=", "$", "expr", "->", "getExpressionId", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "expressions", "[", "$", "exprId", "]", ")", ")", "$", "this", "->", "expressions", "[", "$", "exprId", "]", "=", "$", "expr", ";", "$", "this", "->", "strings", "[", "$", "i", "]", "=", "preg_replace", "(", "'/\\{'", ".", "preg_quote", "(", "$", "expr", "->", "getExpression", "(", ")", ",", "'/'", ")", ".", "'\\}/'", ",", "'{'", ".", "$", "exprId", ".", "'}'", ",", "$", "this", "->", "strings", "[", "$", "i", "]", ")", ";", "}", "}", "}", "// If we've gotten here, we must need to cache this file", "if", "(", "$", "this", "->", "cache", ")", "{", "file_put_contents", "(", "$", "this", "->", "cacheFile", ",", "serialize", "(", "$", "this", ")", ")", ";", "$", "this", "->", "cacheTemplate", "=", "$", "this", ";", "}", "}" ]
Parse the template. The process here is basically to create sub-templates for some of the language constructs, and tie them in with placeholders in their parent template. Later, when we call render(), we can put the output of sub-templates back into their parents.
[ "Parse", "the", "template", ".", "The", "process", "here", "is", "basically", "to", "create", "sub", "-", "templates", "for", "some", "of", "the", "language", "constructs", "and", "tie", "them", "in", "with", "placeholders", "in", "their", "parent", "template", ".", "Later", "when", "we", "call", "render", "()", "we", "can", "put", "the", "output", "of", "sub", "-", "templates", "back", "into", "their", "parents", "." ]
train
https://github.com/dburkart/scurvy/blob/990a7c4f0517298de304438cf9cd95a303a231fb/Scurvy.php#L210-L328
dburkart/scurvy
Scurvy.php
Scurvy.parseRecursive
private function parseRecursive($start, $regex, $subName = 'template') { $re_beg = $regex[0]; $re_end = $regex[1]; $numLines = count($this->strings); $i = $start; $n = 0; $line = 0; for ($i; $i < $numLines; $i++) { $match = preg_match($re_beg, $this->strings[$i]); if ($match) $n += 1; $match = preg_match($re_end, $this->strings[$i]); if ($match) { $n -= 1; if ($n == 0) break; } $line++; } if ($n > 0) { echo "Opening brace on line $line of {$subName} has no closing brace\n<br />"; } // Deal with edge-cases // // - {block}TEXT{/block} // - {block} // TEXT{/block} if ($start == $i) { $subTmpl = $this->strings[$start]; $beg = strpos($subTmpl, '}') + 1; $subTmpl = array( substr($subTmpl, $beg, strrpos($subTmpl, '{') - $beg) ); } else if ($i == ($start + 1)) { $subTmpl = $this->strings[$i]; $subTmpl = array( substr($subTmpl, 0, strrpos($subTmpl, '{'))); } else { $subTmpl = array_slice($this->strings, $start + 1, $i - ($start + 1)); } for ($j = $start; $j <= $i; $j++) { //-- Just set the string to empty. Don't worry about removing it //-- from the array $this->strings[$j] = ''; } if ($subName != 'comment') return new Scurvy($subTmpl, $this->template_dir, false, $subName); }
php
private function parseRecursive($start, $regex, $subName = 'template') { $re_beg = $regex[0]; $re_end = $regex[1]; $numLines = count($this->strings); $i = $start; $n = 0; $line = 0; for ($i; $i < $numLines; $i++) { $match = preg_match($re_beg, $this->strings[$i]); if ($match) $n += 1; $match = preg_match($re_end, $this->strings[$i]); if ($match) { $n -= 1; if ($n == 0) break; } $line++; } if ($n > 0) { echo "Opening brace on line $line of {$subName} has no closing brace\n<br />"; } // Deal with edge-cases // // - {block}TEXT{/block} // - {block} // TEXT{/block} if ($start == $i) { $subTmpl = $this->strings[$start]; $beg = strpos($subTmpl, '}') + 1; $subTmpl = array( substr($subTmpl, $beg, strrpos($subTmpl, '{') - $beg) ); } else if ($i == ($start + 1)) { $subTmpl = $this->strings[$i]; $subTmpl = array( substr($subTmpl, 0, strrpos($subTmpl, '{'))); } else { $subTmpl = array_slice($this->strings, $start + 1, $i - ($start + 1)); } for ($j = $start; $j <= $i; $j++) { //-- Just set the string to empty. Don't worry about removing it //-- from the array $this->strings[$j] = ''; } if ($subName != 'comment') return new Scurvy($subTmpl, $this->template_dir, false, $subName); }
[ "private", "function", "parseRecursive", "(", "$", "start", ",", "$", "regex", ",", "$", "subName", "=", "'template'", ")", "{", "$", "re_beg", "=", "$", "regex", "[", "0", "]", ";", "$", "re_end", "=", "$", "regex", "[", "1", "]", ";", "$", "numLines", "=", "count", "(", "$", "this", "->", "strings", ")", ";", "$", "i", "=", "$", "start", ";", "$", "n", "=", "0", ";", "$", "line", "=", "0", ";", "for", "(", "$", "i", ";", "$", "i", "<", "$", "numLines", ";", "$", "i", "++", ")", "{", "$", "match", "=", "preg_match", "(", "$", "re_beg", ",", "$", "this", "->", "strings", "[", "$", "i", "]", ")", ";", "if", "(", "$", "match", ")", "$", "n", "+=", "1", ";", "$", "match", "=", "preg_match", "(", "$", "re_end", ",", "$", "this", "->", "strings", "[", "$", "i", "]", ")", ";", "if", "(", "$", "match", ")", "{", "$", "n", "-=", "1", ";", "if", "(", "$", "n", "==", "0", ")", "break", ";", "}", "$", "line", "++", ";", "}", "if", "(", "$", "n", ">", "0", ")", "{", "echo", "\"Opening brace on line $line of {$subName} has no closing brace\\n<br />\"", ";", "}", "// Deal with edge-cases", "// ", "// - {block}TEXT{/block}", "// - {block}", "// TEXT{/block}", "if", "(", "$", "start", "==", "$", "i", ")", "{", "$", "subTmpl", "=", "$", "this", "->", "strings", "[", "$", "start", "]", ";", "$", "beg", "=", "strpos", "(", "$", "subTmpl", ",", "'}'", ")", "+", "1", ";", "$", "subTmpl", "=", "array", "(", "substr", "(", "$", "subTmpl", ",", "$", "beg", ",", "strrpos", "(", "$", "subTmpl", ",", "'{'", ")", "-", "$", "beg", ")", ")", ";", "}", "else", "if", "(", "$", "i", "==", "(", "$", "start", "+", "1", ")", ")", "{", "$", "subTmpl", "=", "$", "this", "->", "strings", "[", "$", "i", "]", ";", "$", "subTmpl", "=", "array", "(", "substr", "(", "$", "subTmpl", ",", "0", ",", "strrpos", "(", "$", "subTmpl", ",", "'{'", ")", ")", ")", ";", "}", "else", "{", "$", "subTmpl", "=", "array_slice", "(", "$", "this", "->", "strings", ",", "$", "start", "+", "1", ",", "$", "i", "-", "(", "$", "start", "+", "1", ")", ")", ";", "}", "for", "(", "$", "j", "=", "$", "start", ";", "$", "j", "<=", "$", "i", ";", "$", "j", "++", ")", "{", "//-- Just set the string to empty. Don't worry about removing it", "//-- from the array", "$", "this", "->", "strings", "[", "$", "j", "]", "=", "''", ";", "}", "if", "(", "$", "subName", "!=", "'comment'", ")", "return", "new", "Scurvy", "(", "$", "subTmpl", ",", "$", "this", "->", "template_dir", ",", "false", ",", "$", "subName", ")", ";", "}" ]
This function is used by the parse function to grab the contents of scurvy block statements. @param start the start index into $this->strings @param regex the regular expression for the block statement @param subName the name of the subTemplate (for debugging purposes) @return a new template with the contents of the block statement
[ "This", "function", "is", "used", "by", "the", "parse", "function", "to", "grab", "the", "contents", "of", "scurvy", "block", "statements", "." ]
train
https://github.com/dburkart/scurvy/blob/990a7c4f0517298de304438cf9cd95a303a231fb/Scurvy.php#L339-L389
webforge-labs/psc-cms
lib/Psc/CMS/User.php
User.setPassword
public function setPassword($password) { if (is_array($password)) { if ($password['password'] == NULL) return $this; $this->hashPassword($password['password']); } else { if ($password == NULL) return $this; $this->password = $password; } return $this; }
php
public function setPassword($password) { if (is_array($password)) { if ($password['password'] == NULL) return $this; $this->hashPassword($password['password']); } else { if ($password == NULL) return $this; $this->password = $password; } return $this; }
[ "public", "function", "setPassword", "(", "$", "password", ")", "{", "if", "(", "is_array", "(", "$", "password", ")", ")", "{", "if", "(", "$", "password", "[", "'password'", "]", "==", "NULL", ")", "return", "$", "this", ";", "$", "this", "->", "hashPassword", "(", "$", "password", "[", "'password'", "]", ")", ";", "}", "else", "{", "if", "(", "$", "password", "==", "NULL", ")", "return", "$", "this", ";", "$", "this", "->", "password", "=", "$", "password", ";", "}", "return", "$", "this", ";", "}" ]
Das setzt das gehashte Passwort und sollte nur intern benutzt werden um das Passwort zu setzen hashPassword benutzen! diese Funktion wird intern vom AbstractEntityController benutzt der Parameter ist dann ein array mit confirmation und password wir könnten auch im validator mit postValidation() arbeiten, aber so ist es mehr convenient für das user objekt an sich @param string $password @chainable @access protected
[ "Das", "setzt", "das", "gehashte", "Passwort", "und", "sollte", "nur", "intern", "benutzt", "werden" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/CMS/User.php#L118-L127
shinjin/freezer
src/Storage/Pdo.php
Pdo.doStore
protected function doStore(array $frozenObject) { foreach (array_reverse($frozenObject['objects']) as $id => $object) { if ($object['isDirty'] === true) { $payload = array( 'class' => $object['class'], 'state' => $object['state'] ); $this->db->insert( $this->table, array('id' => $id, 'body' => json_encode($payload)), 'id' ); } } return $id; }
php
protected function doStore(array $frozenObject) { foreach (array_reverse($frozenObject['objects']) as $id => $object) { if ($object['isDirty'] === true) { $payload = array( 'class' => $object['class'], 'state' => $object['state'] ); $this->db->insert( $this->table, array('id' => $id, 'body' => json_encode($payload)), 'id' ); } } return $id; }
[ "protected", "function", "doStore", "(", "array", "$", "frozenObject", ")", "{", "foreach", "(", "array_reverse", "(", "$", "frozenObject", "[", "'objects'", "]", ")", "as", "$", "id", "=>", "$", "object", ")", "{", "if", "(", "$", "object", "[", "'isDirty'", "]", "===", "true", ")", "{", "$", "payload", "=", "array", "(", "'class'", "=>", "$", "object", "[", "'class'", "]", ",", "'state'", "=>", "$", "object", "[", "'state'", "]", ")", ";", "$", "this", "->", "db", "->", "insert", "(", "$", "this", "->", "table", ",", "array", "(", "'id'", "=>", "$", "id", ",", "'body'", "=>", "json_encode", "(", "$", "payload", ")", ")", ",", "'id'", ")", ";", "}", "}", "return", "$", "id", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/shinjin/freezer/blob/f5955fb5476fa8ac456e27c0edafaae331d02cd3/src/Storage/Pdo.php#L60-L78
shinjin/freezer
src/Storage/Pdo.php
Pdo.doFetch
protected function doFetch($id, array &$objects = array()) { $isRoot = empty($objects); if (!isset($objects[$id])) { $stmt = sprintf('SELECT * FROM %s WHERE id = ?', $this->table); $stmt = $this->db->query($stmt, array($id)); if (($result = $stmt->fetch(\PDO::FETCH_ASSOC)) !== false) { $object = json_decode($result['body'], true); } else { return false; } $object['isDirty'] = false; $objects[$id] = $object; if (!$this->useLazyLoad) { $this->fetchArray($object['state'], $objects); } } if ($isRoot) { return array('root' => $id, 'objects' => $objects); } }
php
protected function doFetch($id, array &$objects = array()) { $isRoot = empty($objects); if (!isset($objects[$id])) { $stmt = sprintf('SELECT * FROM %s WHERE id = ?', $this->table); $stmt = $this->db->query($stmt, array($id)); if (($result = $stmt->fetch(\PDO::FETCH_ASSOC)) !== false) { $object = json_decode($result['body'], true); } else { return false; } $object['isDirty'] = false; $objects[$id] = $object; if (!$this->useLazyLoad) { $this->fetchArray($object['state'], $objects); } } if ($isRoot) { return array('root' => $id, 'objects' => $objects); } }
[ "protected", "function", "doFetch", "(", "$", "id", ",", "array", "&", "$", "objects", "=", "array", "(", ")", ")", "{", "$", "isRoot", "=", "empty", "(", "$", "objects", ")", ";", "if", "(", "!", "isset", "(", "$", "objects", "[", "$", "id", "]", ")", ")", "{", "$", "stmt", "=", "sprintf", "(", "'SELECT * FROM %s WHERE id = ?'", ",", "$", "this", "->", "table", ")", ";", "$", "stmt", "=", "$", "this", "->", "db", "->", "query", "(", "$", "stmt", ",", "array", "(", "$", "id", ")", ")", ";", "if", "(", "(", "$", "result", "=", "$", "stmt", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ")", "!==", "false", ")", "{", "$", "object", "=", "json_decode", "(", "$", "result", "[", "'body'", "]", ",", "true", ")", ";", "}", "else", "{", "return", "false", ";", "}", "$", "object", "[", "'isDirty'", "]", "=", "false", ";", "$", "objects", "[", "$", "id", "]", "=", "$", "object", ";", "if", "(", "!", "$", "this", "->", "useLazyLoad", ")", "{", "$", "this", "->", "fetchArray", "(", "$", "object", "[", "'state'", "]", ",", "$", "objects", ")", ";", "}", "}", "if", "(", "$", "isRoot", ")", "{", "return", "array", "(", "'root'", "=>", "$", "id", ",", "'objects'", "=>", "$", "objects", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/shinjin/freezer/blob/f5955fb5476fa8ac456e27c0edafaae331d02cd3/src/Storage/Pdo.php#L83-L108
Chill-project/Main
Controller/ExportController.php
ExportController.indexAction
public function indexAction(Request $request) { $exportManager = $this->get('chill.main.export_manager'); $exports = $exportManager->getExports(true); return $this->render('ChillMainBundle:Export:layout.html.twig', array( 'exports' => $exports )); }
php
public function indexAction(Request $request) { $exportManager = $this->get('chill.main.export_manager'); $exports = $exportManager->getExports(true); return $this->render('ChillMainBundle:Export:layout.html.twig', array( 'exports' => $exports )); }
[ "public", "function", "indexAction", "(", "Request", "$", "request", ")", "{", "$", "exportManager", "=", "$", "this", "->", "get", "(", "'chill.main.export_manager'", ")", ";", "$", "exports", "=", "$", "exportManager", "->", "getExports", "(", "true", ")", ";", "return", "$", "this", "->", "render", "(", "'ChillMainBundle:Export:layout.html.twig'", ",", "array", "(", "'exports'", "=>", "$", "exports", ")", ")", ";", "}" ]
Render the list of available exports @param Request $request @return \Symfony\Component\HttpFoundation\Response
[ "Render", "the", "list", "of", "available", "exports" ]
train
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Controller/ExportController.php#L46-L55
Chill-project/Main
Controller/ExportController.php
ExportController.newAction
public function newAction(Request $request, $alias) { // first check for ACL $exportManager = $this->get('chill.main.export_manager'); $export = $exportManager->getExport($alias); if ($exportManager->isGrantedForElement($export) === FALSE) { throw $this->createAccessDeniedException('The user does not have access to this export'); } $step = $request->query->getAlpha('step', 'centers'); switch ($step) { case 'centers': return $this->selectCentersStep($request, $alias); case 'export': return $this->exportFormStep($request, $alias); break; case 'formatter': return $this->formatterFormStep($request, $alias); break; case 'generate': return $this->forwardToGenerate($request, $alias); break; default: throw $this->createNotFoundException("The given step '$step' is invalid"); } }
php
public function newAction(Request $request, $alias) { // first check for ACL $exportManager = $this->get('chill.main.export_manager'); $export = $exportManager->getExport($alias); if ($exportManager->isGrantedForElement($export) === FALSE) { throw $this->createAccessDeniedException('The user does not have access to this export'); } $step = $request->query->getAlpha('step', 'centers'); switch ($step) { case 'centers': return $this->selectCentersStep($request, $alias); case 'export': return $this->exportFormStep($request, $alias); break; case 'formatter': return $this->formatterFormStep($request, $alias); break; case 'generate': return $this->forwardToGenerate($request, $alias); break; default: throw $this->createNotFoundException("The given step '$step' is invalid"); } }
[ "public", "function", "newAction", "(", "Request", "$", "request", ",", "$", "alias", ")", "{", "// first check for ACL", "$", "exportManager", "=", "$", "this", "->", "get", "(", "'chill.main.export_manager'", ")", ";", "$", "export", "=", "$", "exportManager", "->", "getExport", "(", "$", "alias", ")", ";", "if", "(", "$", "exportManager", "->", "isGrantedForElement", "(", "$", "export", ")", "===", "FALSE", ")", "{", "throw", "$", "this", "->", "createAccessDeniedException", "(", "'The user does not have access to this export'", ")", ";", "}", "$", "step", "=", "$", "request", "->", "query", "->", "getAlpha", "(", "'step'", ",", "'centers'", ")", ";", "switch", "(", "$", "step", ")", "{", "case", "'centers'", ":", "return", "$", "this", "->", "selectCentersStep", "(", "$", "request", ",", "$", "alias", ")", ";", "case", "'export'", ":", "return", "$", "this", "->", "exportFormStep", "(", "$", "request", ",", "$", "alias", ")", ";", "break", ";", "case", "'formatter'", ":", "return", "$", "this", "->", "formatterFormStep", "(", "$", "request", ",", "$", "alias", ")", ";", "break", ";", "case", "'generate'", ":", "return", "$", "this", "->", "forwardToGenerate", "(", "$", "request", ",", "$", "alias", ")", ";", "break", ";", "default", ":", "throw", "$", "this", "->", "createNotFoundException", "(", "\"The given step '$step' is invalid\"", ")", ";", "}", "}" ]
handle the step to build a query for an export This action has three steps : 1.'export', the export form. When the form is posted, the data is stored in the session (if valid), and then a redirection is done to next step. 2. 'formatter', the formatter form. When the form is posted, the data is stored in the session (if valid), and then a redirection is done to next step. 3. 'generate': gather data from session from the previous steps, and make a redirection to the "generate" action with data in query (HTTP GET) @param string $request @param Request $alias @return \Symfony\Component\HttpFoundation\Response
[ "handle", "the", "step", "to", "build", "a", "query", "for", "an", "export" ]
train
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Controller/ExportController.php#L73-L100
Chill-project/Main
Controller/ExportController.php
ExportController.exportFormStep
protected function exportFormStep(Request $request, $alias) { $exportManager = $this->get('chill.main.export_manager'); // check we have data from the previous step (export step) $data = $this->get('session')->get('centers_step', null); if ($data === null) { return $this->redirectToRoute('chill_main_export_new', array( 'step' => $this->getNextStep('export', true), 'alias' => $alias )); } $export = $exportManager->getExport($alias); $form = $this->createCreateFormExport($alias, 'export', $data); if ($request->getMethod() === 'POST') { $form->handleRequest($request); if ($form->isValid()) { $this->get('logger')->debug('form export is valid', array( 'location' => __METHOD__)); // store data for reusing in next steps $data = $form->getData(); $this->get('session')->set('export_step_raw', $request->request->all()); $this->get('session')->set('export_step', $data); //redirect to next step return $this->redirect( $this->generateUrl('chill_main_export_new', array( 'step' => $this->getNextStep('export'), 'alias' => $alias ))); } else { $this->get('logger')->debug('form export is invalid', array( 'location' => __METHOD__)); } } return $this->render('ChillMainBundle:Export:new.html.twig', array( 'form' => $form->createView(), 'export_alias' => $alias, 'export' => $export )); }
php
protected function exportFormStep(Request $request, $alias) { $exportManager = $this->get('chill.main.export_manager'); // check we have data from the previous step (export step) $data = $this->get('session')->get('centers_step', null); if ($data === null) { return $this->redirectToRoute('chill_main_export_new', array( 'step' => $this->getNextStep('export', true), 'alias' => $alias )); } $export = $exportManager->getExport($alias); $form = $this->createCreateFormExport($alias, 'export', $data); if ($request->getMethod() === 'POST') { $form->handleRequest($request); if ($form->isValid()) { $this->get('logger')->debug('form export is valid', array( 'location' => __METHOD__)); // store data for reusing in next steps $data = $form->getData(); $this->get('session')->set('export_step_raw', $request->request->all()); $this->get('session')->set('export_step', $data); //redirect to next step return $this->redirect( $this->generateUrl('chill_main_export_new', array( 'step' => $this->getNextStep('export'), 'alias' => $alias ))); } else { $this->get('logger')->debug('form export is invalid', array( 'location' => __METHOD__)); } } return $this->render('ChillMainBundle:Export:new.html.twig', array( 'form' => $form->createView(), 'export_alias' => $alias, 'export' => $export )); }
[ "protected", "function", "exportFormStep", "(", "Request", "$", "request", ",", "$", "alias", ")", "{", "$", "exportManager", "=", "$", "this", "->", "get", "(", "'chill.main.export_manager'", ")", ";", "// check we have data from the previous step (export step)", "$", "data", "=", "$", "this", "->", "get", "(", "'session'", ")", "->", "get", "(", "'centers_step'", ",", "null", ")", ";", "if", "(", "$", "data", "===", "null", ")", "{", "return", "$", "this", "->", "redirectToRoute", "(", "'chill_main_export_new'", ",", "array", "(", "'step'", "=>", "$", "this", "->", "getNextStep", "(", "'export'", ",", "true", ")", ",", "'alias'", "=>", "$", "alias", ")", ")", ";", "}", "$", "export", "=", "$", "exportManager", "->", "getExport", "(", "$", "alias", ")", ";", "$", "form", "=", "$", "this", "->", "createCreateFormExport", "(", "$", "alias", ",", "'export'", ",", "$", "data", ")", ";", "if", "(", "$", "request", "->", "getMethod", "(", ")", "===", "'POST'", ")", "{", "$", "form", "->", "handleRequest", "(", "$", "request", ")", ";", "if", "(", "$", "form", "->", "isValid", "(", ")", ")", "{", "$", "this", "->", "get", "(", "'logger'", ")", "->", "debug", "(", "'form export is valid'", ",", "array", "(", "'location'", "=>", "__METHOD__", ")", ")", ";", "// store data for reusing in next steps", "$", "data", "=", "$", "form", "->", "getData", "(", ")", ";", "$", "this", "->", "get", "(", "'session'", ")", "->", "set", "(", "'export_step_raw'", ",", "$", "request", "->", "request", "->", "all", "(", ")", ")", ";", "$", "this", "->", "get", "(", "'session'", ")", "->", "set", "(", "'export_step'", ",", "$", "data", ")", ";", "//redirect to next step", "return", "$", "this", "->", "redirect", "(", "$", "this", "->", "generateUrl", "(", "'chill_main_export_new'", ",", "array", "(", "'step'", "=>", "$", "this", "->", "getNextStep", "(", "'export'", ")", ",", "'alias'", "=>", "$", "alias", ")", ")", ")", ";", "}", "else", "{", "$", "this", "->", "get", "(", "'logger'", ")", "->", "debug", "(", "'form export is invalid'", ",", "array", "(", "'location'", "=>", "__METHOD__", ")", ")", ";", "}", "}", "return", "$", "this", "->", "render", "(", "'ChillMainBundle:Export:new.html.twig'", ",", "array", "(", "'form'", "=>", "$", "form", "->", "createView", "(", ")", ",", "'export_alias'", "=>", "$", "alias", ",", "'export'", "=>", "$", "export", ")", ")", ";", "}" ]
Render the export form When the method is POST, the form is stored if valid, and a redirection is done to next step. @param string $alias @return \Symfony\Component\HttpFoundation\Response
[ "Render", "the", "export", "form" ]
train
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Controller/ExportController.php#L154-L203
Chill-project/Main
Controller/ExportController.php
ExportController.createCreateFormExport
protected function createCreateFormExport($alias, $step, $data = array()) { /* @var $exportManager \Chill\MainBundle\Export\ExportManager */ $exportManager = $this->get('chill.main.export_manager'); $isGenerate = strpos($step, 'generate_') === 0; $builder = $this->get('form.factory') ->createNamedBuilder(null, FormType::class, array(), array( 'method' => $isGenerate ? 'GET' : 'POST', 'csrf_protection' => $isGenerate ? false : true, )); if ($step === 'centers' or $step === 'generate_centers') { $builder->add('centers', PickCenterType::class, array( 'export_alias' => $alias )); } if ($step === 'export' or $step === 'generate_export') { $builder->add('export', ExportType::class, array( 'export_alias' => $alias, 'picked_centers' => $exportManager->getPickedCenters($data['centers']) )); } if ($step === 'formatter' or $step === 'generate_formatter') { $builder->add('formatter', FormatterType::class, array( 'formatter_alias' => $exportManager ->getFormatterAlias($data['export']), 'export_alias' => $alias, 'aggregator_aliases' => $exportManager ->getUsedAggregatorsAliases($data['export']) )); } $builder->add('submit', 'submit', array( 'label' => 'Generate' )); return $builder->getForm(); }
php
protected function createCreateFormExport($alias, $step, $data = array()) { /* @var $exportManager \Chill\MainBundle\Export\ExportManager */ $exportManager = $this->get('chill.main.export_manager'); $isGenerate = strpos($step, 'generate_') === 0; $builder = $this->get('form.factory') ->createNamedBuilder(null, FormType::class, array(), array( 'method' => $isGenerate ? 'GET' : 'POST', 'csrf_protection' => $isGenerate ? false : true, )); if ($step === 'centers' or $step === 'generate_centers') { $builder->add('centers', PickCenterType::class, array( 'export_alias' => $alias )); } if ($step === 'export' or $step === 'generate_export') { $builder->add('export', ExportType::class, array( 'export_alias' => $alias, 'picked_centers' => $exportManager->getPickedCenters($data['centers']) )); } if ($step === 'formatter' or $step === 'generate_formatter') { $builder->add('formatter', FormatterType::class, array( 'formatter_alias' => $exportManager ->getFormatterAlias($data['export']), 'export_alias' => $alias, 'aggregator_aliases' => $exportManager ->getUsedAggregatorsAliases($data['export']) )); } $builder->add('submit', 'submit', array( 'label' => 'Generate' )); return $builder->getForm(); }
[ "protected", "function", "createCreateFormExport", "(", "$", "alias", ",", "$", "step", ",", "$", "data", "=", "array", "(", ")", ")", "{", "/* @var $exportManager \\Chill\\MainBundle\\Export\\ExportManager */", "$", "exportManager", "=", "$", "this", "->", "get", "(", "'chill.main.export_manager'", ")", ";", "$", "isGenerate", "=", "strpos", "(", "$", "step", ",", "'generate_'", ")", "===", "0", ";", "$", "builder", "=", "$", "this", "->", "get", "(", "'form.factory'", ")", "->", "createNamedBuilder", "(", "null", ",", "FormType", "::", "class", ",", "array", "(", ")", ",", "array", "(", "'method'", "=>", "$", "isGenerate", "?", "'GET'", ":", "'POST'", ",", "'csrf_protection'", "=>", "$", "isGenerate", "?", "false", ":", "true", ",", ")", ")", ";", "if", "(", "$", "step", "===", "'centers'", "or", "$", "step", "===", "'generate_centers'", ")", "{", "$", "builder", "->", "add", "(", "'centers'", ",", "PickCenterType", "::", "class", ",", "array", "(", "'export_alias'", "=>", "$", "alias", ")", ")", ";", "}", "if", "(", "$", "step", "===", "'export'", "or", "$", "step", "===", "'generate_export'", ")", "{", "$", "builder", "->", "add", "(", "'export'", ",", "ExportType", "::", "class", ",", "array", "(", "'export_alias'", "=>", "$", "alias", ",", "'picked_centers'", "=>", "$", "exportManager", "->", "getPickedCenters", "(", "$", "data", "[", "'centers'", "]", ")", ")", ")", ";", "}", "if", "(", "$", "step", "===", "'formatter'", "or", "$", "step", "===", "'generate_formatter'", ")", "{", "$", "builder", "->", "add", "(", "'formatter'", ",", "FormatterType", "::", "class", ",", "array", "(", "'formatter_alias'", "=>", "$", "exportManager", "->", "getFormatterAlias", "(", "$", "data", "[", "'export'", "]", ")", ",", "'export_alias'", "=>", "$", "alias", ",", "'aggregator_aliases'", "=>", "$", "exportManager", "->", "getUsedAggregatorsAliases", "(", "$", "data", "[", "'export'", "]", ")", ")", ")", ";", "}", "$", "builder", "->", "add", "(", "'submit'", ",", "'submit'", ",", "array", "(", "'label'", "=>", "'Generate'", ")", ")", ";", "return", "$", "builder", "->", "getForm", "(", ")", ";", "}" ]
create a form to show on different steps. @param string $alias @param string $step, can either be 'export', 'formatter', 'generate_export' or 'generate_formatter' (last two are used by generate action) @param array $data the data from previous step. Required for steps 'formatter' and 'generate_formatter' @return \Symfony\Component\Form\Form
[ "create", "a", "form", "to", "show", "on", "different", "steps", "." ]
train
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Controller/ExportController.php#L213-L253
Chill-project/Main
Controller/ExportController.php
ExportController.getNextStep
private function getNextStep($step, $reverse = false) { switch($step) { case 'centers': if ($reverse !== false) { throw new \LogicException("there is no step before 'export'"); } return 'export'; case 'export': return $reverse ? 'centers' : 'formatter'; case 'formatter' : return $reverse ? 'export' : 'generate'; case 'generate' : if ($reverse === false) { throw new \LogicException("there is no step after 'generate'"); } return 'formatter'; default: throw new \LogicException("the step $step is not defined."); } }
php
private function getNextStep($step, $reverse = false) { switch($step) { case 'centers': if ($reverse !== false) { throw new \LogicException("there is no step before 'export'"); } return 'export'; case 'export': return $reverse ? 'centers' : 'formatter'; case 'formatter' : return $reverse ? 'export' : 'generate'; case 'generate' : if ($reverse === false) { throw new \LogicException("there is no step after 'generate'"); } return 'formatter'; default: throw new \LogicException("the step $step is not defined."); } }
[ "private", "function", "getNextStep", "(", "$", "step", ",", "$", "reverse", "=", "false", ")", "{", "switch", "(", "$", "step", ")", "{", "case", "'centers'", ":", "if", "(", "$", "reverse", "!==", "false", ")", "{", "throw", "new", "\\", "LogicException", "(", "\"there is no step before 'export'\"", ")", ";", "}", "return", "'export'", ";", "case", "'export'", ":", "return", "$", "reverse", "?", "'centers'", ":", "'formatter'", ";", "case", "'formatter'", ":", "return", "$", "reverse", "?", "'export'", ":", "'generate'", ";", "case", "'generate'", ":", "if", "(", "$", "reverse", "===", "false", ")", "{", "throw", "new", "\\", "LogicException", "(", "\"there is no step after 'generate'\"", ")", ";", "}", "return", "'formatter'", ";", "default", ":", "throw", "new", "\\", "LogicException", "(", "\"the step $step is not defined.\"", ")", ";", "}", "}" ]
get the next step. If $reverse === true, the previous step is returned. This method provides a centralized way of handling next/previous step. @param string $step the current step @param boolean $reverse set to true to get the previous step @return string the next/current step @throws \LogicException if there is no step before or after the given step
[ "get", "the", "next", "step", ".", "If", "$reverse", "===", "true", "the", "previous", "step", "is", "returned", "." ]
train
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Controller/ExportController.php#L265-L286
Chill-project/Main
Controller/ExportController.php
ExportController.forwardToGenerate
protected function forwardToGenerate(Request $request, $alias) { $dataCenters = $this->get('session')->get('centers_step_raw', null); $dataFormatter = $this->get('session')->get('formatter_step_raw', null); $dataExport = $this->get('session')->get('export_step_raw', null); if ($dataFormatter === NULL) { return $this->redirectToRoute('chill_main_export_new', array( 'alias' => $alias, 'step' => $this->getNextStep('generate', true) )); } // remove data from session $this->get('session')->remove('export_step_raw'); $this->get('session')->remove('export_step'); $this->get('session')->remove('formatter_step_raw'); $this->get('session')->remove('formatter_step'); $redirectParameters = array_merge( $dataFormatter, $dataExport, $dataCenters, array('alias' => $alias) ); unset($redirectParameters['_token']); return $this->redirectToRoute('chill_main_export_generate', $redirectParameters); }
php
protected function forwardToGenerate(Request $request, $alias) { $dataCenters = $this->get('session')->get('centers_step_raw', null); $dataFormatter = $this->get('session')->get('formatter_step_raw', null); $dataExport = $this->get('session')->get('export_step_raw', null); if ($dataFormatter === NULL) { return $this->redirectToRoute('chill_main_export_new', array( 'alias' => $alias, 'step' => $this->getNextStep('generate', true) )); } // remove data from session $this->get('session')->remove('export_step_raw'); $this->get('session')->remove('export_step'); $this->get('session')->remove('formatter_step_raw'); $this->get('session')->remove('formatter_step'); $redirectParameters = array_merge( $dataFormatter, $dataExport, $dataCenters, array('alias' => $alias) ); unset($redirectParameters['_token']); return $this->redirectToRoute('chill_main_export_generate', $redirectParameters); }
[ "protected", "function", "forwardToGenerate", "(", "Request", "$", "request", ",", "$", "alias", ")", "{", "$", "dataCenters", "=", "$", "this", "->", "get", "(", "'session'", ")", "->", "get", "(", "'centers_step_raw'", ",", "null", ")", ";", "$", "dataFormatter", "=", "$", "this", "->", "get", "(", "'session'", ")", "->", "get", "(", "'formatter_step_raw'", ",", "null", ")", ";", "$", "dataExport", "=", "$", "this", "->", "get", "(", "'session'", ")", "->", "get", "(", "'export_step_raw'", ",", "null", ")", ";", "if", "(", "$", "dataFormatter", "===", "NULL", ")", "{", "return", "$", "this", "->", "redirectToRoute", "(", "'chill_main_export_new'", ",", "array", "(", "'alias'", "=>", "$", "alias", ",", "'step'", "=>", "$", "this", "->", "getNextStep", "(", "'generate'", ",", "true", ")", ")", ")", ";", "}", "// remove data from session", "$", "this", "->", "get", "(", "'session'", ")", "->", "remove", "(", "'export_step_raw'", ")", ";", "$", "this", "->", "get", "(", "'session'", ")", "->", "remove", "(", "'export_step'", ")", ";", "$", "this", "->", "get", "(", "'session'", ")", "->", "remove", "(", "'formatter_step_raw'", ")", ";", "$", "this", "->", "get", "(", "'session'", ")", "->", "remove", "(", "'formatter_step'", ")", ";", "$", "redirectParameters", "=", "array_merge", "(", "$", "dataFormatter", ",", "$", "dataExport", ",", "$", "dataCenters", ",", "array", "(", "'alias'", "=>", "$", "alias", ")", ")", ";", "unset", "(", "$", "redirectParameters", "[", "'_token'", "]", ")", ";", "return", "$", "this", "->", "redirectToRoute", "(", "'chill_main_export_generate'", ",", "$", "redirectParameters", ")", ";", "}" ]
Gather data stored in session from previous steps, and redirect to the `generate` action, compiling data from previous step in the URL (to obtain a GET HTTP query). The data from previous steps is removed from session. @param Request $request @param string $alias @return \Symfony\Component\HttpFoundation\RedirectResponse
[ "Gather", "data", "stored", "in", "session", "from", "previous", "steps", "and", "redirect", "to", "the", "generate", "action", "compiling", "data", "from", "previous", "step", "in", "the", "URL", "(", "to", "obtain", "a", "GET", "HTTP", "query", ")", "." ]
train
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Controller/ExportController.php#L351-L379
Chill-project/Main
Controller/ExportController.php
ExportController.generateAction
public function generateAction(Request $request, $alias) { /* @var $exportManager \Chill\MainBundle\Export\ExportManager */ $exportManager = $this->get('chill.main.export_manager'); $formCenters = $this->createCreateFormExport($alias, 'generate_centers'); $formCenters->handleRequest($request); $dataCenters = $formCenters->getData(); $formExport = $this->createCreateFormExport($alias, 'generate_export', $dataCenters); $formExport->handleRequest($request); $dataExport = $formExport->getData(); $formFormatter = $this->createCreateFormExport($alias, 'generate_formatter', $dataExport); $formFormatter->handleRequest($request); $dataFormatter = $formFormatter->getData(); // temporary hack due to bug with fputcsv and header_get header('Content-Type: text/csv'); $r = $exportManager->generate($alias, $dataCenters['centers'], $dataExport['export'], $dataFormatter['formatter']); return $r; }
php
public function generateAction(Request $request, $alias) { /* @var $exportManager \Chill\MainBundle\Export\ExportManager */ $exportManager = $this->get('chill.main.export_manager'); $formCenters = $this->createCreateFormExport($alias, 'generate_centers'); $formCenters->handleRequest($request); $dataCenters = $formCenters->getData(); $formExport = $this->createCreateFormExport($alias, 'generate_export', $dataCenters); $formExport->handleRequest($request); $dataExport = $formExport->getData(); $formFormatter = $this->createCreateFormExport($alias, 'generate_formatter', $dataExport); $formFormatter->handleRequest($request); $dataFormatter = $formFormatter->getData(); // temporary hack due to bug with fputcsv and header_get header('Content-Type: text/csv'); $r = $exportManager->generate($alias, $dataCenters['centers'], $dataExport['export'], $dataFormatter['formatter']); return $r; }
[ "public", "function", "generateAction", "(", "Request", "$", "request", ",", "$", "alias", ")", "{", "/* @var $exportManager \\Chill\\MainBundle\\Export\\ExportManager */", "$", "exportManager", "=", "$", "this", "->", "get", "(", "'chill.main.export_manager'", ")", ";", "$", "formCenters", "=", "$", "this", "->", "createCreateFormExport", "(", "$", "alias", ",", "'generate_centers'", ")", ";", "$", "formCenters", "->", "handleRequest", "(", "$", "request", ")", ";", "$", "dataCenters", "=", "$", "formCenters", "->", "getData", "(", ")", ";", "$", "formExport", "=", "$", "this", "->", "createCreateFormExport", "(", "$", "alias", ",", "'generate_export'", ",", "$", "dataCenters", ")", ";", "$", "formExport", "->", "handleRequest", "(", "$", "request", ")", ";", "$", "dataExport", "=", "$", "formExport", "->", "getData", "(", ")", ";", "$", "formFormatter", "=", "$", "this", "->", "createCreateFormExport", "(", "$", "alias", ",", "'generate_formatter'", ",", "$", "dataExport", ")", ";", "$", "formFormatter", "->", "handleRequest", "(", "$", "request", ")", ";", "$", "dataFormatter", "=", "$", "formFormatter", "->", "getData", "(", ")", ";", "// temporary hack due to bug with fputcsv and header_get", "header", "(", "'Content-Type: text/csv'", ")", ";", "$", "r", "=", "$", "exportManager", "->", "generate", "(", "$", "alias", ",", "$", "dataCenters", "[", "'centers'", "]", ",", "$", "dataExport", "[", "'export'", "]", ",", "$", "dataFormatter", "[", "'formatter'", "]", ")", ";", "return", "$", "r", ";", "}" ]
Generate a report. This action must work with GET queries. @param Request $request @param string $alias @return \Symfony\Component\HttpFoundation\Response
[ "Generate", "a", "report", "." ]
train
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Controller/ExportController.php#L390-L415
hendrikmaus/reynaldo
src/Parser/RefractParser.php
RefractParser.iterate
private function iterate(array $content, $parent = null) { foreach ($content as $element) { $this->process($element, $parent); } }
php
private function iterate(array $content, $parent = null) { foreach ($content as $element) { $this->process($element, $parent); } }
[ "private", "function", "iterate", "(", "array", "$", "content", ",", "$", "parent", "=", "null", ")", "{", "foreach", "(", "$", "content", "as", "$", "element", ")", "{", "$", "this", "->", "process", "(", "$", "element", ",", "$", "parent", ")", ";", "}", "}" ]
Iterate given content array and call `process` for every element inside @param array $content @param null|BaseElement $parent
[ "Iterate", "given", "content", "array", "and", "call", "process", "for", "every", "element", "inside" ]
train
https://github.com/hendrikmaus/reynaldo/blob/be100f56e8f39d86d16ce9222838d20f462e8678/src/Parser/RefractParser.php#L60-L65
hendrikmaus/reynaldo
src/Parser/RefractParser.php
RefractParser.process
private function process(array $element, $parent = null) { $apiElement = $element['element']; if (isset($this->elementMap[$apiElement])) { $this->processElement( $element, $this->elementMap[$apiElement], $parent ); } if ($element['element'] === 'category') { // todo extend the element map to check for classes, then merge processCategory into processElement $this->processCategory($element, $parent); } }
php
private function process(array $element, $parent = null) { $apiElement = $element['element']; if (isset($this->elementMap[$apiElement])) { $this->processElement( $element, $this->elementMap[$apiElement], $parent ); } if ($element['element'] === 'category') { // todo extend the element map to check for classes, then merge processCategory into processElement $this->processCategory($element, $parent); } }
[ "private", "function", "process", "(", "array", "$", "element", ",", "$", "parent", "=", "null", ")", "{", "$", "apiElement", "=", "$", "element", "[", "'element'", "]", ";", "if", "(", "isset", "(", "$", "this", "->", "elementMap", "[", "$", "apiElement", "]", ")", ")", "{", "$", "this", "->", "processElement", "(", "$", "element", ",", "$", "this", "->", "elementMap", "[", "$", "apiElement", "]", ",", "$", "parent", ")", ";", "}", "if", "(", "$", "element", "[", "'element'", "]", "===", "'category'", ")", "{", "// todo extend the element map to check for classes, then merge processCategory into processElement", "$", "this", "->", "processCategory", "(", "$", "element", ",", "$", "parent", ")", ";", "}", "}" ]
Create php classes using raw element data; called recursively @param array $element @param null|BaseElement $parent
[ "Create", "php", "classes", "using", "raw", "element", "data", ";", "called", "recursively" ]
train
https://github.com/hendrikmaus/reynaldo/blob/be100f56e8f39d86d16ce9222838d20f462e8678/src/Parser/RefractParser.php#L73-L89
hendrikmaus/reynaldo
src/Parser/RefractParser.php
RefractParser.processElement
private function processElement(array $element, $class, BaseElement $parent, $replaceAttribute = null) { $apiElement = new $class($element); if (!$replaceAttribute) { $parent->addContentElement($apiElement); } else { $parent->replaceAttributeWithElement($replaceAttribute, $apiElement); } if (isset($element['attributes'])) { foreach ($element['attributes'] as $attributeName => $attributeValue) { if (!isset($this->elementMap[$attributeName])) { continue; } $this->processElement( $attributeValue, $this->elementMap[$attributeName], $apiElement, $attributeName ); } } if (!isset($element['content'])) { return; } if (!is_array($element['content'])) { return; } $this->iterate($element['content'], $apiElement); }
php
private function processElement(array $element, $class, BaseElement $parent, $replaceAttribute = null) { $apiElement = new $class($element); if (!$replaceAttribute) { $parent->addContentElement($apiElement); } else { $parent->replaceAttributeWithElement($replaceAttribute, $apiElement); } if (isset($element['attributes'])) { foreach ($element['attributes'] as $attributeName => $attributeValue) { if (!isset($this->elementMap[$attributeName])) { continue; } $this->processElement( $attributeValue, $this->elementMap[$attributeName], $apiElement, $attributeName ); } } if (!isset($element['content'])) { return; } if (!is_array($element['content'])) { return; } $this->iterate($element['content'], $apiElement); }
[ "private", "function", "processElement", "(", "array", "$", "element", ",", "$", "class", ",", "BaseElement", "$", "parent", ",", "$", "replaceAttribute", "=", "null", ")", "{", "$", "apiElement", "=", "new", "$", "class", "(", "$", "element", ")", ";", "if", "(", "!", "$", "replaceAttribute", ")", "{", "$", "parent", "->", "addContentElement", "(", "$", "apiElement", ")", ";", "}", "else", "{", "$", "parent", "->", "replaceAttributeWithElement", "(", "$", "replaceAttribute", ",", "$", "apiElement", ")", ";", "}", "if", "(", "isset", "(", "$", "element", "[", "'attributes'", "]", ")", ")", "{", "foreach", "(", "$", "element", "[", "'attributes'", "]", "as", "$", "attributeName", "=>", "$", "attributeValue", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "elementMap", "[", "$", "attributeName", "]", ")", ")", "{", "continue", ";", "}", "$", "this", "->", "processElement", "(", "$", "attributeValue", ",", "$", "this", "->", "elementMap", "[", "$", "attributeName", "]", ",", "$", "apiElement", ",", "$", "attributeName", ")", ";", "}", "}", "if", "(", "!", "isset", "(", "$", "element", "[", "'content'", "]", ")", ")", "{", "return", ";", "}", "if", "(", "!", "is_array", "(", "$", "element", "[", "'content'", "]", ")", ")", "{", "return", ";", "}", "$", "this", "->", "iterate", "(", "$", "element", "[", "'content'", "]", ",", "$", "apiElement", ")", ";", "}" ]
Create new element from raw data and add it to its parent @param array $element Raw element data @param string $class FQCN to use for creating an element @param BaseElement $parent parent element to add the newly created one to @param null|string $replaceAttribute usually, the new element will be added to the content of the given parent. There are some cases, hrefVariables for example, where the attributes actually contain elements as well. To add the new element to the attributes, pass the name of the key inside of attributes that should be replaced
[ "Create", "new", "element", "from", "raw", "data", "and", "add", "it", "to", "its", "parent" ]
train
https://github.com/hendrikmaus/reynaldo/blob/be100f56e8f39d86d16ce9222838d20f462e8678/src/Parser/RefractParser.php#L103-L137
hendrikmaus/reynaldo
src/Parser/RefractParser.php
RefractParser.processCategory
private function processCategory(array $element, $parent = null) { if ($this->isMasterCategory($element)) { $this->createCategory($element, MasterCategoryElement::class, $this->parseResult); } if ($this->isResourceGroup($element)) { $this->createCategory($element, ResourceGroupElement::class, $parent); } if ($this->isDataStructureCategory($element)) { $this->createCategory($element, DataStructureCategoryElement::class, $parent); } }
php
private function processCategory(array $element, $parent = null) { if ($this->isMasterCategory($element)) { $this->createCategory($element, MasterCategoryElement::class, $this->parseResult); } if ($this->isResourceGroup($element)) { $this->createCategory($element, ResourceGroupElement::class, $parent); } if ($this->isDataStructureCategory($element)) { $this->createCategory($element, DataStructureCategoryElement::class, $parent); } }
[ "private", "function", "processCategory", "(", "array", "$", "element", ",", "$", "parent", "=", "null", ")", "{", "if", "(", "$", "this", "->", "isMasterCategory", "(", "$", "element", ")", ")", "{", "$", "this", "->", "createCategory", "(", "$", "element", ",", "MasterCategoryElement", "::", "class", ",", "$", "this", "->", "parseResult", ")", ";", "}", "if", "(", "$", "this", "->", "isResourceGroup", "(", "$", "element", ")", ")", "{", "$", "this", "->", "createCategory", "(", "$", "element", ",", "ResourceGroupElement", "::", "class", ",", "$", "parent", ")", ";", "}", "if", "(", "$", "this", "->", "isDataStructureCategory", "(", "$", "element", ")", ")", "{", "$", "this", "->", "createCategory", "(", "$", "element", ",", "DataStructureCategoryElement", "::", "class", ",", "$", "parent", ")", ";", "}", "}" ]
Helper to create different php classes from element `category` which carries its actual meaning in its classes @param array $element @param null|BaseElement $parent
[ "Helper", "to", "create", "different", "php", "classes", "from", "element", "category", "which", "carries", "its", "actual", "meaning", "in", "its", "classes" ]
train
https://github.com/hendrikmaus/reynaldo/blob/be100f56e8f39d86d16ce9222838d20f462e8678/src/Parser/RefractParser.php#L145-L158
hendrikmaus/reynaldo
src/Parser/RefractParser.php
RefractParser.createCategory
private function createCategory(array $element, $className, BaseElement $parent) { $newElement = new $className($element); $parent->addContentElement($newElement); $this->iterate($element['content'], $newElement); }
php
private function createCategory(array $element, $className, BaseElement $parent) { $newElement = new $className($element); $parent->addContentElement($newElement); $this->iterate($element['content'], $newElement); }
[ "private", "function", "createCategory", "(", "array", "$", "element", ",", "$", "className", ",", "BaseElement", "$", "parent", ")", "{", "$", "newElement", "=", "new", "$", "className", "(", "$", "element", ")", ";", "$", "parent", "->", "addContentElement", "(", "$", "newElement", ")", ";", "$", "this", "->", "iterate", "(", "$", "element", "[", "'content'", "]", ",", "$", "newElement", ")", ";", "}" ]
Sub-helper for `processCategory` @param array $element @param string $className @param BaseElement $parent
[ "Sub", "-", "helper", "for", "processCategory" ]
train
https://github.com/hendrikmaus/reynaldo/blob/be100f56e8f39d86d16ce9222838d20f462e8678/src/Parser/RefractParser.php#L190-L195
simple-php-mvc/simple-php-mvc
src/MVC/Controller/Controller.php
Controller.call
final public function call(MVC $mvc, $method, $fileView = null) { if (!method_exists($this, $method)) { throw new \LogicException(sprintf('Method "s" don\'t exists.', $method)); } # Replace the view object $this->view = $mvc->view(); # Arguments of method $arguments = array(); # Create a reflection method $reflectionMethod = new \ReflectionMethod(get_class($this), $method); $reflectionParams = $reflectionMethod->getParameters(); foreach ($reflectionParams as $param) { if ($paramClass = $param->getClass()) { $className = $paramClass->name; if ($className === 'MVC\\MVC' || $className === '\\MVC\\MVC') { $arguments[] = $mvc; } elseif ($className === 'MVC\\Server\\HttpRequest' || $className === '\\MVC\\Server\\HttpRequest') { $arguments[] = $mvc->request(); } } else { foreach ($mvc->request()->params as $keyReqParam => $valueReqParam) { if ($param->name === $keyReqParam) { $arguments[] = $valueReqParam; break; } } } } $response = call_user_func_array($reflectionMethod->getClosure($this), $arguments); if (empty($response)) { throw new \LogicException('Response null returned.'); } if (is_string($response)) { $this->response['body'] = $response; } elseif ($mvc->request()->isAjax()) { $this->response['body'] = $this->renderJson($response); } elseif(is_array($response)) { if (!$fileView) { throw new \LogicException('File view is null.'); } $class = explode("\\", get_called_class()); $classname = end($class); // Class without Controller $classname = str_replace('Controller', '', $classname); $file = $classname . "/{$fileView}"; $this->response['body'] = $this->renderHtml($file, $response); } return $this->response; }
php
final public function call(MVC $mvc, $method, $fileView = null) { if (!method_exists($this, $method)) { throw new \LogicException(sprintf('Method "s" don\'t exists.', $method)); } # Replace the view object $this->view = $mvc->view(); # Arguments of method $arguments = array(); # Create a reflection method $reflectionMethod = new \ReflectionMethod(get_class($this), $method); $reflectionParams = $reflectionMethod->getParameters(); foreach ($reflectionParams as $param) { if ($paramClass = $param->getClass()) { $className = $paramClass->name; if ($className === 'MVC\\MVC' || $className === '\\MVC\\MVC') { $arguments[] = $mvc; } elseif ($className === 'MVC\\Server\\HttpRequest' || $className === '\\MVC\\Server\\HttpRequest') { $arguments[] = $mvc->request(); } } else { foreach ($mvc->request()->params as $keyReqParam => $valueReqParam) { if ($param->name === $keyReqParam) { $arguments[] = $valueReqParam; break; } } } } $response = call_user_func_array($reflectionMethod->getClosure($this), $arguments); if (empty($response)) { throw new \LogicException('Response null returned.'); } if (is_string($response)) { $this->response['body'] = $response; } elseif ($mvc->request()->isAjax()) { $this->response['body'] = $this->renderJson($response); } elseif(is_array($response)) { if (!$fileView) { throw new \LogicException('File view is null.'); } $class = explode("\\", get_called_class()); $classname = end($class); // Class without Controller $classname = str_replace('Controller', '', $classname); $file = $classname . "/{$fileView}"; $this->response['body'] = $this->renderHtml($file, $response); } return $this->response; }
[ "final", "public", "function", "call", "(", "MVC", "$", "mvc", ",", "$", "method", ",", "$", "fileView", "=", "null", ")", "{", "if", "(", "!", "method_exists", "(", "$", "this", ",", "$", "method", ")", ")", "{", "throw", "new", "\\", "LogicException", "(", "sprintf", "(", "'Method \"s\" don\\'t exists.'", ",", "$", "method", ")", ")", ";", "}", "# Replace the view object", "$", "this", "->", "view", "=", "$", "mvc", "->", "view", "(", ")", ";", "# Arguments of method", "$", "arguments", "=", "array", "(", ")", ";", "# Create a reflection method", "$", "reflectionMethod", "=", "new", "\\", "ReflectionMethod", "(", "get_class", "(", "$", "this", ")", ",", "$", "method", ")", ";", "$", "reflectionParams", "=", "$", "reflectionMethod", "->", "getParameters", "(", ")", ";", "foreach", "(", "$", "reflectionParams", "as", "$", "param", ")", "{", "if", "(", "$", "paramClass", "=", "$", "param", "->", "getClass", "(", ")", ")", "{", "$", "className", "=", "$", "paramClass", "->", "name", ";", "if", "(", "$", "className", "===", "'MVC\\\\MVC'", "||", "$", "className", "===", "'\\\\MVC\\\\MVC'", ")", "{", "$", "arguments", "[", "]", "=", "$", "mvc", ";", "}", "elseif", "(", "$", "className", "===", "'MVC\\\\Server\\\\HttpRequest'", "||", "$", "className", "===", "'\\\\MVC\\\\Server\\\\HttpRequest'", ")", "{", "$", "arguments", "[", "]", "=", "$", "mvc", "->", "request", "(", ")", ";", "}", "}", "else", "{", "foreach", "(", "$", "mvc", "->", "request", "(", ")", "->", "params", "as", "$", "keyReqParam", "=>", "$", "valueReqParam", ")", "{", "if", "(", "$", "param", "->", "name", "===", "$", "keyReqParam", ")", "{", "$", "arguments", "[", "]", "=", "$", "valueReqParam", ";", "break", ";", "}", "}", "}", "}", "$", "response", "=", "call_user_func_array", "(", "$", "reflectionMethod", "->", "getClosure", "(", "$", "this", ")", ",", "$", "arguments", ")", ";", "if", "(", "empty", "(", "$", "response", ")", ")", "{", "throw", "new", "\\", "LogicException", "(", "'Response null returned.'", ")", ";", "}", "if", "(", "is_string", "(", "$", "response", ")", ")", "{", "$", "this", "->", "response", "[", "'body'", "]", "=", "$", "response", ";", "}", "elseif", "(", "$", "mvc", "->", "request", "(", ")", "->", "isAjax", "(", ")", ")", "{", "$", "this", "->", "response", "[", "'body'", "]", "=", "$", "this", "->", "renderJson", "(", "$", "response", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "response", ")", ")", "{", "if", "(", "!", "$", "fileView", ")", "{", "throw", "new", "\\", "LogicException", "(", "'File view is null.'", ")", ";", "}", "$", "class", "=", "explode", "(", "\"\\\\\"", ",", "get_called_class", "(", ")", ")", ";", "$", "classname", "=", "end", "(", "$", "class", ")", ";", "// Class without Controller", "$", "classname", "=", "str_replace", "(", "'Controller'", ",", "''", ",", "$", "classname", ")", ";", "$", "file", "=", "$", "classname", ".", "\"/{$fileView}\"", ";", "$", "this", "->", "response", "[", "'body'", "]", "=", "$", "this", "->", "renderHtml", "(", "$", "file", ",", "$", "response", ")", ";", "}", "return", "$", "this", "->", "response", ";", "}" ]
Call a action of controller @access public @param MVC $mvc MVC Application object @param string $method Method or Function of the Class Controller @param string $fileView String of the view file @return array Response array @throws \LogicException
[ "Call", "a", "action", "of", "controller" ]
train
https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/Controller/Controller.php#L56-L110
simple-php-mvc/simple-php-mvc
src/MVC/Controller/Controller.php
Controller.renderJson
public function renderJson($value) { $options = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP; return json_encode($value, $options); }
php
public function renderJson($value) { $options = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP; return json_encode($value, $options); }
[ "public", "function", "renderJson", "(", "$", "value", ")", "{", "$", "options", "=", "JSON_HEX_TAG", "|", "JSON_HEX_APOS", "|", "JSON_HEX_QUOT", "|", "JSON_HEX_AMP", ";", "return", "json_encode", "(", "$", "value", ",", "$", "options", ")", ";", "}" ]
Converts the supplied value to JSON. @access public @param mixed $value The value to encode. @return string
[ "Converts", "the", "supplied", "value", "to", "JSON", "." ]
train
https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/Controller/Controller.php#L128-L132
shrink0r/workflux
src/StateMachine.php
StateMachine.execute
public function execute(InputInterface $input, string $start_state = null): OutputInterface { $execution_tracker = new ExecutionTracker($this); $next_state = $this->determineStartState($input, $start_state); do { $cur_cycle = $execution_tracker->track($next_state); $output = $next_state->execute($input); if ($next_state->isInteractive()) { break; } $next_state = $this->activateTransition($input, $output); $input = Input::fromOutput($output); } while ($next_state && $cur_cycle < self::MAX_CYCLES); if ($next_state && $cur_cycle === self::MAX_CYCLES) { throw CorruptExecutionFlow::fromExecutionTracker($execution_tracker, self::MAX_CYCLES); } return $output; }
php
public function execute(InputInterface $input, string $start_state = null): OutputInterface { $execution_tracker = new ExecutionTracker($this); $next_state = $this->determineStartState($input, $start_state); do { $cur_cycle = $execution_tracker->track($next_state); $output = $next_state->execute($input); if ($next_state->isInteractive()) { break; } $next_state = $this->activateTransition($input, $output); $input = Input::fromOutput($output); } while ($next_state && $cur_cycle < self::MAX_CYCLES); if ($next_state && $cur_cycle === self::MAX_CYCLES) { throw CorruptExecutionFlow::fromExecutionTracker($execution_tracker, self::MAX_CYCLES); } return $output; }
[ "public", "function", "execute", "(", "InputInterface", "$", "input", ",", "string", "$", "start_state", "=", "null", ")", ":", "OutputInterface", "{", "$", "execution_tracker", "=", "new", "ExecutionTracker", "(", "$", "this", ")", ";", "$", "next_state", "=", "$", "this", "->", "determineStartState", "(", "$", "input", ",", "$", "start_state", ")", ";", "do", "{", "$", "cur_cycle", "=", "$", "execution_tracker", "->", "track", "(", "$", "next_state", ")", ";", "$", "output", "=", "$", "next_state", "->", "execute", "(", "$", "input", ")", ";", "if", "(", "$", "next_state", "->", "isInteractive", "(", ")", ")", "{", "break", ";", "}", "$", "next_state", "=", "$", "this", "->", "activateTransition", "(", "$", "input", ",", "$", "output", ")", ";", "$", "input", "=", "Input", "::", "fromOutput", "(", "$", "output", ")", ";", "}", "while", "(", "$", "next_state", "&&", "$", "cur_cycle", "<", "self", "::", "MAX_CYCLES", ")", ";", "if", "(", "$", "next_state", "&&", "$", "cur_cycle", "===", "self", "::", "MAX_CYCLES", ")", "{", "throw", "CorruptExecutionFlow", "::", "fromExecutionTracker", "(", "$", "execution_tracker", ",", "self", "::", "MAX_CYCLES", ")", ";", "}", "return", "$", "output", ";", "}" ]
@param InputInterface $input @param string $start_state @return OutputInterface
[ "@param", "InputInterface", "$input", "@param", "string", "$start_state" ]
train
https://github.com/shrink0r/workflux/blob/008f45c64f52b1f795ab7f6ddbfc1a55580254d9/src/StateMachine.php#L69-L87
shrink0r/workflux
src/StateMachine.php
StateMachine.determineStartState
private function determineStartState(InputInterface $input, string $state_name = null): StateInterface { if (!$state_name) { return $this->getInitialState(); } if (!$this->states->has($state_name)) { throw new ExecutionError("Trying to start statemachine execution at unknown state: ".$state_name); } $start_state = $this->states->get($state_name); if ($start_state->isFinal()) { throw new ExecutionError("Trying to (re)execute statemachine at final state: ".$state_name); } if ($start_state->isInteractive() && !$input->hasEvent()) { throw new ExecutionError("Trying to resume statemachine executing without providing an event/signal."); } return $start_state->isInteractive() ? $this->activateTransition($input, Output::fromInput($start_state->getName(), $input)) : $start_state; }
php
private function determineStartState(InputInterface $input, string $state_name = null): StateInterface { if (!$state_name) { return $this->getInitialState(); } if (!$this->states->has($state_name)) { throw new ExecutionError("Trying to start statemachine execution at unknown state: ".$state_name); } $start_state = $this->states->get($state_name); if ($start_state->isFinal()) { throw new ExecutionError("Trying to (re)execute statemachine at final state: ".$state_name); } if ($start_state->isInteractive() && !$input->hasEvent()) { throw new ExecutionError("Trying to resume statemachine executing without providing an event/signal."); } return $start_state->isInteractive() ? $this->activateTransition($input, Output::fromInput($start_state->getName(), $input)) : $start_state; }
[ "private", "function", "determineStartState", "(", "InputInterface", "$", "input", ",", "string", "$", "state_name", "=", "null", ")", ":", "StateInterface", "{", "if", "(", "!", "$", "state_name", ")", "{", "return", "$", "this", "->", "getInitialState", "(", ")", ";", "}", "if", "(", "!", "$", "this", "->", "states", "->", "has", "(", "$", "state_name", ")", ")", "{", "throw", "new", "ExecutionError", "(", "\"Trying to start statemachine execution at unknown state: \"", ".", "$", "state_name", ")", ";", "}", "$", "start_state", "=", "$", "this", "->", "states", "->", "get", "(", "$", "state_name", ")", ";", "if", "(", "$", "start_state", "->", "isFinal", "(", ")", ")", "{", "throw", "new", "ExecutionError", "(", "\"Trying to (re)execute statemachine at final state: \"", ".", "$", "state_name", ")", ";", "}", "if", "(", "$", "start_state", "->", "isInteractive", "(", ")", "&&", "!", "$", "input", "->", "hasEvent", "(", ")", ")", "{", "throw", "new", "ExecutionError", "(", "\"Trying to resume statemachine executing without providing an event/signal.\"", ")", ";", "}", "return", "$", "start_state", "->", "isInteractive", "(", ")", "?", "$", "this", "->", "activateTransition", "(", "$", "input", ",", "Output", "::", "fromInput", "(", "$", "start_state", "->", "getName", "(", ")", ",", "$", "input", ")", ")", ":", "$", "start_state", ";", "}" ]
@param InputInterface $input @param string $state_name @return StateInterface
[ "@param", "InputInterface", "$input", "@param", "string", "$state_name" ]
train
https://github.com/shrink0r/workflux/blob/008f45c64f52b1f795ab7f6ddbfc1a55580254d9/src/StateMachine.php#L135-L153
shrink0r/workflux
src/StateMachine.php
StateMachine.activateTransition
private function activateTransition(InputInterface $input, OutputInterface $output) { $next_state = null; foreach ($this->state_transitions->get($output->getCurrentState()) as $transition) { if ($transition->isActivatedBy($input, $output)) { if (is_null($next_state)) { $next_state = $this->states->get($transition->getTo()); continue; } throw new ExecutionError( 'Trying to activate more than one transition at a time. Transition: '. $output->getCurrentState().' -> '.$next_state->getName().' was activated first. '. 'Now '.$transition->getFrom().' -> '.$transition->getTo().' is being activated too.' ); } } return $next_state; }
php
private function activateTransition(InputInterface $input, OutputInterface $output) { $next_state = null; foreach ($this->state_transitions->get($output->getCurrentState()) as $transition) { if ($transition->isActivatedBy($input, $output)) { if (is_null($next_state)) { $next_state = $this->states->get($transition->getTo()); continue; } throw new ExecutionError( 'Trying to activate more than one transition at a time. Transition: '. $output->getCurrentState().' -> '.$next_state->getName().' was activated first. '. 'Now '.$transition->getFrom().' -> '.$transition->getTo().' is being activated too.' ); } } return $next_state; }
[ "private", "function", "activateTransition", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "$", "next_state", "=", "null", ";", "foreach", "(", "$", "this", "->", "state_transitions", "->", "get", "(", "$", "output", "->", "getCurrentState", "(", ")", ")", "as", "$", "transition", ")", "{", "if", "(", "$", "transition", "->", "isActivatedBy", "(", "$", "input", ",", "$", "output", ")", ")", "{", "if", "(", "is_null", "(", "$", "next_state", ")", ")", "{", "$", "next_state", "=", "$", "this", "->", "states", "->", "get", "(", "$", "transition", "->", "getTo", "(", ")", ")", ";", "continue", ";", "}", "throw", "new", "ExecutionError", "(", "'Trying to activate more than one transition at a time. Transition: '", ".", "$", "output", "->", "getCurrentState", "(", ")", ".", "' -> '", ".", "$", "next_state", "->", "getName", "(", ")", ".", "' was activated first. '", ".", "'Now '", ".", "$", "transition", "->", "getFrom", "(", ")", ".", "' -> '", ".", "$", "transition", "->", "getTo", "(", ")", ".", "' is being activated too.'", ")", ";", "}", "}", "return", "$", "next_state", ";", "}" ]
@param InputInterface $input @param OutputInterface $output @return StateInterface|null
[ "@param", "InputInterface", "$input", "@param", "OutputInterface", "$output" ]
train
https://github.com/shrink0r/workflux/blob/008f45c64f52b1f795ab7f6ddbfc1a55580254d9/src/StateMachine.php#L161-L178
4devs/ElfinderPhpConnector
Driver/AbstractDriver.php
AbstractDriver.addDisabledCmd
public function addDisabledCmd($cmd) { if (!isset($this->options['disabled'])) { $this->options['disabled'] = []; } if (array_search($cmd, $this->options['disabled']) === false) { $this->options['disabled'][] = $cmd; } return $this; }
php
public function addDisabledCmd($cmd) { if (!isset($this->options['disabled'])) { $this->options['disabled'] = []; } if (array_search($cmd, $this->options['disabled']) === false) { $this->options['disabled'][] = $cmd; } return $this; }
[ "public", "function", "addDisabledCmd", "(", "$", "cmd", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "options", "[", "'disabled'", "]", ")", ")", "{", "$", "this", "->", "options", "[", "'disabled'", "]", "=", "[", "]", ";", "}", "if", "(", "array_search", "(", "$", "cmd", ",", "$", "this", "->", "options", "[", "'disabled'", "]", ")", "===", "false", ")", "{", "$", "this", "->", "options", "[", "'disabled'", "]", "[", "]", "=", "$", "cmd", ";", "}", "return", "$", "this", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/4devs/ElfinderPhpConnector/blob/510e295dcafeaa0f796986ad87b3ed5f6b0d9338/Driver/AbstractDriver.php#L97-L107
Craftsware/scissor
src/Lib/Time.php
Time.offset
public function offset($timezone) { $timeOffset = (new \DateTimeZone($timezone))->getOffset(new \DateTime('now', new \DateTimeZone('UTC'))); if($timeOffset < 0) { return 'UTC -'. gmdate('H:i', -$timeOffset); } else { return 'UTC +'. gmdate('H:i', $timeOffset); } }
php
public function offset($timezone) { $timeOffset = (new \DateTimeZone($timezone))->getOffset(new \DateTime('now', new \DateTimeZone('UTC'))); if($timeOffset < 0) { return 'UTC -'. gmdate('H:i', -$timeOffset); } else { return 'UTC +'. gmdate('H:i', $timeOffset); } }
[ "public", "function", "offset", "(", "$", "timezone", ")", "{", "$", "timeOffset", "=", "(", "new", "\\", "DateTimeZone", "(", "$", "timezone", ")", ")", "->", "getOffset", "(", "new", "\\", "DateTime", "(", "'now'", ",", "new", "\\", "DateTimeZone", "(", "'UTC'", ")", ")", ")", ";", "if", "(", "$", "timeOffset", "<", "0", ")", "{", "return", "'UTC -'", ".", "gmdate", "(", "'H:i'", ",", "-", "$", "timeOffset", ")", ";", "}", "else", "{", "return", "'UTC +'", ".", "gmdate", "(", "'H:i'", ",", "$", "timeOffset", ")", ";", "}", "}" ]
Get Time Offset
[ "Get", "Time", "Offset" ]
train
https://github.com/Craftsware/scissor/blob/644e4a8ea9859fc30fee36705e54784acd8d43e2/src/Lib/Time.php#L52-L64
Craftsware/scissor
src/Lib/Time.php
Time.datetime
public function datetime($datetime, $timezone = null, $format = 'M/d/Y - h:i:s A') { $datetime = new \DateTime($datetime); if($timezone) { $datetime->setTimezone(new \DateTimeZone($timezone)); } return $datetime->format($format); }
php
public function datetime($datetime, $timezone = null, $format = 'M/d/Y - h:i:s A') { $datetime = new \DateTime($datetime); if($timezone) { $datetime->setTimezone(new \DateTimeZone($timezone)); } return $datetime->format($format); }
[ "public", "function", "datetime", "(", "$", "datetime", ",", "$", "timezone", "=", "null", ",", "$", "format", "=", "'M/d/Y - h:i:s A'", ")", "{", "$", "datetime", "=", "new", "\\", "DateTime", "(", "$", "datetime", ")", ";", "if", "(", "$", "timezone", ")", "{", "$", "datetime", "->", "setTimezone", "(", "new", "\\", "DateTimeZone", "(", "$", "timezone", ")", ")", ";", "}", "return", "$", "datetime", "->", "format", "(", "$", "format", ")", ";", "}" ]
Set Date and Time
[ "Set", "Date", "and", "Time" ]
train
https://github.com/Craftsware/scissor/blob/644e4a8ea9859fc30fee36705e54784acd8d43e2/src/Lib/Time.php#L70-L80
Craftsware/scissor
src/Lib/Time.php
Time.timezones
public function timezones() { $timezone = []; foreach(timezone_identifiers_list() as $key => $value) { $timezone[$key] = [ 'timezone' => $value, 'offset' => $this->offset($value) ]; } return $timezone; }
php
public function timezones() { $timezone = []; foreach(timezone_identifiers_list() as $key => $value) { $timezone[$key] = [ 'timezone' => $value, 'offset' => $this->offset($value) ]; } return $timezone; }
[ "public", "function", "timezones", "(", ")", "{", "$", "timezone", "=", "[", "]", ";", "foreach", "(", "timezone_identifiers_list", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "timezone", "[", "$", "key", "]", "=", "[", "'timezone'", "=>", "$", "value", ",", "'offset'", "=>", "$", "this", "->", "offset", "(", "$", "value", ")", "]", ";", "}", "return", "$", "timezone", ";", "}" ]
Get Timezone
[ "Get", "Timezone" ]
train
https://github.com/Craftsware/scissor/blob/644e4a8ea9859fc30fee36705e54784acd8d43e2/src/Lib/Time.php#L87-L100
webforge-labs/psc-cms
lib/Psc/System/Deploy/Deployer.php
Deployer.createTask
public function createTask($name) { $this->init(); $class = Code::expandNamespace(\Webforge\Common\String::expand($name, 'Task'), 'Psc\System\Deploy'); $gClass = GClass::factory($class); $params = array(); if ($gClass->hasMethod('__construct')) { $constructor = $gClass->getMethod('__construct'); foreach ($constructor->getParameters() as $parameter) { $params[] = $this->resolveTaskDependency($parameter, $gClass); } } return $gClass->newInstance($params); }
php
public function createTask($name) { $this->init(); $class = Code::expandNamespace(\Webforge\Common\String::expand($name, 'Task'), 'Psc\System\Deploy'); $gClass = GClass::factory($class); $params = array(); if ($gClass->hasMethod('__construct')) { $constructor = $gClass->getMethod('__construct'); foreach ($constructor->getParameters() as $parameter) { $params[] = $this->resolveTaskDependency($parameter, $gClass); } } return $gClass->newInstance($params); }
[ "public", "function", "createTask", "(", "$", "name", ")", "{", "$", "this", "->", "init", "(", ")", ";", "$", "class", "=", "Code", "::", "expandNamespace", "(", "\\", "Webforge", "\\", "Common", "\\", "String", "::", "expand", "(", "$", "name", ",", "'Task'", ")", ",", "'Psc\\System\\Deploy'", ")", ";", "$", "gClass", "=", "GClass", "::", "factory", "(", "$", "class", ")", ";", "$", "params", "=", "array", "(", ")", ";", "if", "(", "$", "gClass", "->", "hasMethod", "(", "'__construct'", ")", ")", "{", "$", "constructor", "=", "$", "gClass", "->", "getMethod", "(", "'__construct'", ")", ";", "foreach", "(", "$", "constructor", "->", "getParameters", "(", ")", "as", "$", "parameter", ")", "{", "$", "params", "[", "]", "=", "$", "this", "->", "resolveTaskDependency", "(", "$", "parameter", ",", "$", "gClass", ")", ";", "}", "}", "return", "$", "gClass", "->", "newInstance", "(", "$", "params", ")", ";", "}" ]
wird automatisch mit dependencies erstellt @param string $name der Name des Tasks ohne Namespace und "Task" dahinter
[ "wird", "automatisch", "mit", "dependencies", "erstellt" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/System/Deploy/Deployer.php#L130-L144
VincentChalnot/SidusAdminBundle
DependencyInjection/Configuration.php
Configuration.getConfigTreeBuilder
public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root($this->root); $rootNode ->children() ->scalarNode('admin_class')->defaultValue(Admin::class)->end() ->scalarNode('action_class')->defaultValue(Action::class)->end() ->scalarNode('fallback_template_directory')->defaultNull()->end() ->append($this->getAdminConfigTreeBuilder()) ->end(); return $treeBuilder; }
php
public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root($this->root); $rootNode ->children() ->scalarNode('admin_class')->defaultValue(Admin::class)->end() ->scalarNode('action_class')->defaultValue(Action::class)->end() ->scalarNode('fallback_template_directory')->defaultNull()->end() ->append($this->getAdminConfigTreeBuilder()) ->end(); return $treeBuilder; }
[ "public", "function", "getConfigTreeBuilder", "(", ")", ":", "TreeBuilder", "{", "$", "treeBuilder", "=", "new", "TreeBuilder", "(", ")", ";", "$", "rootNode", "=", "$", "treeBuilder", "->", "root", "(", "$", "this", "->", "root", ")", ";", "$", "rootNode", "->", "children", "(", ")", "->", "scalarNode", "(", "'admin_class'", ")", "->", "defaultValue", "(", "Admin", "::", "class", ")", "->", "end", "(", ")", "->", "scalarNode", "(", "'action_class'", ")", "->", "defaultValue", "(", "Action", "::", "class", ")", "->", "end", "(", ")", "->", "scalarNode", "(", "'fallback_template_directory'", ")", "->", "defaultNull", "(", ")", "->", "end", "(", ")", "->", "append", "(", "$", "this", "->", "getAdminConfigTreeBuilder", "(", ")", ")", "->", "end", "(", ")", ";", "return", "$", "treeBuilder", ";", "}" ]
{@inheritdoc} @throws \RuntimeException
[ "{" ]
train
https://github.com/VincentChalnot/SidusAdminBundle/blob/3366f3f1525435860cf275ed2f1f0b58cf6eea18/DependencyInjection/Configuration.php#L44-L58
VincentChalnot/SidusAdminBundle
DependencyInjection/Configuration.php
Configuration.getAdminConfigTreeBuilder
protected function getAdminConfigTreeBuilder(): NodeDefinition { $builder = new TreeBuilder(); $node = $builder->root('configurations'); $adminDefinition = $node ->useAttributeAsKey('code') ->prototype('array') ->performNoDeepMerging() ->children(); $this->appendAdminDefinition($adminDefinition); $adminDefinition->end() ->end() ->end(); return $node; }
php
protected function getAdminConfigTreeBuilder(): NodeDefinition { $builder = new TreeBuilder(); $node = $builder->root('configurations'); $adminDefinition = $node ->useAttributeAsKey('code') ->prototype('array') ->performNoDeepMerging() ->children(); $this->appendAdminDefinition($adminDefinition); $adminDefinition->end() ->end() ->end(); return $node; }
[ "protected", "function", "getAdminConfigTreeBuilder", "(", ")", ":", "NodeDefinition", "{", "$", "builder", "=", "new", "TreeBuilder", "(", ")", ";", "$", "node", "=", "$", "builder", "->", "root", "(", "'configurations'", ")", ";", "$", "adminDefinition", "=", "$", "node", "->", "useAttributeAsKey", "(", "'code'", ")", "->", "prototype", "(", "'array'", ")", "->", "performNoDeepMerging", "(", ")", "->", "children", "(", ")", ";", "$", "this", "->", "appendAdminDefinition", "(", "$", "adminDefinition", ")", ";", "$", "adminDefinition", "->", "end", "(", ")", "->", "end", "(", ")", "->", "end", "(", ")", ";", "return", "$", "node", ";", "}" ]
@throws \RuntimeException @return NodeDefinition
[ "@throws", "\\", "RuntimeException" ]
train
https://github.com/VincentChalnot/SidusAdminBundle/blob/3366f3f1525435860cf275ed2f1f0b58cf6eea18/DependencyInjection/Configuration.php#L65-L82
yuncms/framework
src/admin/models/TaskSearch.php
TaskSearch.search
public function search($params) { $query = Task::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider([ 'query' => $query, 'sort' => [ 'defaultOrder' => [ 'id' => SORT_ASC, ] ], ]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere([ 'id' => $this->id, 'switch' => $this->switch, 'status' => $this->status, 'last_rundate' => $this->last_rundate, 'next_rundate' => $this->next_rundate, 'execmemory' => $this->execmemory, 'exectime' => $this->exectime, ]); $query->andFilterWhere(['like', 'name', $this->name]) ->andFilterWhere(['like', 'route', $this->route]) ->andFilterWhere(['like', 'crontab_str', $this->crontab_str]); return $dataProvider; }
php
public function search($params) { $query = Task::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider([ 'query' => $query, 'sort' => [ 'defaultOrder' => [ 'id' => SORT_ASC, ] ], ]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere([ 'id' => $this->id, 'switch' => $this->switch, 'status' => $this->status, 'last_rundate' => $this->last_rundate, 'next_rundate' => $this->next_rundate, 'execmemory' => $this->execmemory, 'exectime' => $this->exectime, ]); $query->andFilterWhere(['like', 'name', $this->name]) ->andFilterWhere(['like', 'route', $this->route]) ->andFilterWhere(['like', 'crontab_str', $this->crontab_str]); return $dataProvider; }
[ "public", "function", "search", "(", "$", "params", ")", "{", "$", "query", "=", "Task", "::", "find", "(", ")", ";", "// add conditions that should always apply here", "$", "dataProvider", "=", "new", "ActiveDataProvider", "(", "[", "'query'", "=>", "$", "query", ",", "'sort'", "=>", "[", "'defaultOrder'", "=>", "[", "'id'", "=>", "SORT_ASC", ",", "]", "]", ",", "]", ")", ";", "$", "this", "->", "load", "(", "$", "params", ")", ";", "if", "(", "!", "$", "this", "->", "validate", "(", ")", ")", "{", "// uncomment the following line if you do not want to return any records when validation fails", "// $query->where('0=1');", "return", "$", "dataProvider", ";", "}", "// grid filtering conditions", "$", "query", "->", "andFilterWhere", "(", "[", "'id'", "=>", "$", "this", "->", "id", ",", "'switch'", "=>", "$", "this", "->", "switch", ",", "'status'", "=>", "$", "this", "->", "status", ",", "'last_rundate'", "=>", "$", "this", "->", "last_rundate", ",", "'next_rundate'", "=>", "$", "this", "->", "next_rundate", ",", "'execmemory'", "=>", "$", "this", "->", "execmemory", ",", "'exectime'", "=>", "$", "this", "->", "exectime", ",", "]", ")", ";", "$", "query", "->", "andFilterWhere", "(", "[", "'like'", ",", "'name'", ",", "$", "this", "->", "name", "]", ")", "->", "andFilterWhere", "(", "[", "'like'", ",", "'route'", ",", "$", "this", "->", "route", "]", ")", "->", "andFilterWhere", "(", "[", "'like'", ",", "'crontab_str'", ",", "$", "this", "->", "crontab_str", "]", ")", ";", "return", "$", "dataProvider", ";", "}" ]
Creates data provider instance with search query applied @param array $params @return ActiveDataProvider
[ "Creates", "data", "provider", "instance", "with", "search", "query", "applied" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/admin/models/TaskSearch.php#L43-L82