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
barebone-php/barebone-core
lib/Controller.php
Controller.setRequest
public function setRequest(Request $request) { $this->request = $request; $parsedBody = $this->request->getParsedBody(); if (!empty($parsedBody)) { if (is_array($parsedBody)) { $this->data = array_map('trim', (array)$parsedBody); } else { $this->data = $parsedBody; } } return $this; }
php
public function setRequest(Request $request) { $this->request = $request; $parsedBody = $this->request->getParsedBody(); if (!empty($parsedBody)) { if (is_array($parsedBody)) { $this->data = array_map('trim', (array)$parsedBody); } else { $this->data = $parsedBody; } } return $this; }
[ "public", "function", "setRequest", "(", "Request", "$", "request", ")", "{", "$", "this", "->", "request", "=", "$", "request", ";", "$", "parsedBody", "=", "$", "this", "->", "request", "->", "getParsedBody", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "parsedBody", ")", ")", "{", "if", "(", "is_array", "(", "$", "parsedBody", ")", ")", "{", "$", "this", "->", "data", "=", "array_map", "(", "'trim'", ",", "(", "array", ")", "$", "parsedBody", ")", ";", "}", "else", "{", "$", "this", "->", "data", "=", "$", "parsedBody", ";", "}", "}", "return", "$", "this", ";", "}" ]
Assign a request object @param Request $request FIG-7 Request Interface @return self
[ "Assign", "a", "request", "object" ]
train
https://github.com/barebone-php/barebone-core/blob/7fda3a62d5fa103cdc4d2d34e1adf8f3ccbfe2bc/lib/Controller.php#L278-L293
steeffeen/FancyManiaLinks
FML/Controls/Frame3d.php
Frame3d.setStyle3dId
public function setStyle3dId($style3dId) { $this->style3dId = (string)$style3dId; $this->style3d = null; return $this; }
php
public function setStyle3dId($style3dId) { $this->style3dId = (string)$style3dId; $this->style3d = null; return $this; }
[ "public", "function", "setStyle3dId", "(", "$", "style3dId", ")", "{", "$", "this", "->", "style3dId", "=", "(", "string", ")", "$", "style3dId", ";", "$", "this", "->", "style3d", "=", "null", ";", "return", "$", "this", ";", "}" ]
Set the Style3d id @api @param string $style3dId Style3d id @return static
[ "Set", "the", "Style3d", "id" ]
train
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Controls/Frame3d.php#L81-L86
steeffeen/FancyManiaLinks
FML/Controls/Frame3d.php
Frame3d.setStyle3d
public function setStyle3d(Style3d $style3d) { $this->style3dId = null; $this->style3d = $style3d; return $this; }
php
public function setStyle3d(Style3d $style3d) { $this->style3dId = null; $this->style3d = $style3d; return $this; }
[ "public", "function", "setStyle3d", "(", "Style3d", "$", "style3d", ")", "{", "$", "this", "->", "style3dId", "=", "null", ";", "$", "this", "->", "style3d", "=", "$", "style3d", ";", "return", "$", "this", ";", "}" ]
Set the Style3d @api @param Style3d $style3d Style3d @return static
[ "Set", "the", "Style3d" ]
train
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Controls/Frame3d.php#L106-L111
ClanCats/Core
src/bundles/Mail/PHPMailer/class.smtp.php
SMTP.edebug
protected function edebug($str) { switch ($this->Debugoutput) { case 'error_log': //Don't output, just log error_log($str); break; case 'html': //Cleans up output a bit for a better looking, HTML-safe output echo htmlentities( preg_replace('/[\r\n]+/', '', $str), ENT_QUOTES, 'UTF-8' ) . "<br>\n"; break; case 'echo': default: echo gmdate('Y-m-d H:i:s')."\t".trim($str)."\n"; } }
php
protected function edebug($str) { switch ($this->Debugoutput) { case 'error_log': //Don't output, just log error_log($str); break; case 'html': //Cleans up output a bit for a better looking, HTML-safe output echo htmlentities( preg_replace('/[\r\n]+/', '', $str), ENT_QUOTES, 'UTF-8' ) . "<br>\n"; break; case 'echo': default: echo gmdate('Y-m-d H:i:s')."\t".trim($str)."\n"; } }
[ "protected", "function", "edebug", "(", "$", "str", ")", "{", "switch", "(", "$", "this", "->", "Debugoutput", ")", "{", "case", "'error_log'", ":", "//Don't output, just log", "error_log", "(", "$", "str", ")", ";", "break", ";", "case", "'html'", ":", "//Cleans up output a bit for a better looking, HTML-safe output", "echo", "htmlentities", "(", "preg_replace", "(", "'/[\\r\\n]+/'", ",", "''", ",", "$", "str", ")", ",", "ENT_QUOTES", ",", "'UTF-8'", ")", ".", "\"<br>\\n\"", ";", "break", ";", "case", "'echo'", ":", "default", ":", "echo", "gmdate", "(", "'Y-m-d H:i:s'", ")", ".", "\"\\t\"", ".", "trim", "(", "$", "str", ")", ".", "\"\\n\"", ";", "}", "}" ]
Output debugging info via a user-selected method. @param string $str Debug string to output @return void
[ "Output", "debugging", "info", "via", "a", "user", "-", "selected", "method", "." ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Mail/PHPMailer/class.smtp.php#L152-L172
ClanCats/Core
src/bundles/Mail/PHPMailer/class.smtp.php
SMTP.authenticate
public function authenticate( $username, $password, $authtype = 'LOGIN', $realm = '', $workstation = '' ) { if (empty($authtype)) { $authtype = 'LOGIN'; } switch ($authtype) { case 'PLAIN': // Start authentication if (!$this->sendCommand('AUTH', 'AUTH PLAIN', 334)) { return false; } // Send encoded username and password if (!$this->sendCommand( 'User & Password', base64_encode("\0" . $username . "\0" . $password), 235 ) ) { return false; } break; case 'LOGIN': // Start authentication if (!$this->sendCommand('AUTH', 'AUTH LOGIN', 334)) { return false; } if (!$this->sendCommand("Username", base64_encode($username), 334)) { return false; } if (!$this->sendCommand("Password", base64_encode($password), 235)) { return false; } break; case 'NTLM': /* * ntlm_sasl_client.php * Bundled with Permission * * How to telnet in windows: * http://technet.microsoft.com/en-us/library/aa995718%28EXCHG.65%29.aspx * PROTOCOL Docs http://curl.haxx.se/rfc/ntlm.html#ntlmSmtpAuthentication */ require_once 'extras/ntlm_sasl_client.php'; $temp = new stdClass(); $ntlm_client = new ntlm_sasl_client_class; //Check that functions are available if (!$ntlm_client->Initialize($temp)) { $this->error = array('error' => $temp->error); if ($this->do_debug >= 1) { $this->edebug( 'You need to enable some modules in your php.ini file: ' . $this->error['error'] ); } return false; } //msg1 $msg1 = $ntlm_client->TypeMsg1($realm, $workstation); //msg1 if (!$this->sendCommand( 'AUTH NTLM', 'AUTH NTLM ' . base64_encode($msg1), 334 ) ) { return false; } //Though 0 based, there is a white space after the 3 digit number //msg2 $challenge = substr($this->last_reply, 3); $challenge = base64_decode($challenge); $ntlm_res = $ntlm_client->NTLMResponse( substr($challenge, 24, 8), $password ); //msg3 $msg3 = $ntlm_client->TypeMsg3( $ntlm_res, $username, $realm, $workstation ); // send encoded username return $this->sendCommand('Username', base64_encode($msg3), 235); case 'CRAM-MD5': // Start authentication if (!$this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) { return false; } // Get the challenge $challenge = base64_decode(substr($this->last_reply, 4)); // Build the response $response = $username . ' ' . $this->hmac($challenge, $password); // send encoded credentials return $this->sendCommand('Username', base64_encode($response), 235); } return true; }
php
public function authenticate( $username, $password, $authtype = 'LOGIN', $realm = '', $workstation = '' ) { if (empty($authtype)) { $authtype = 'LOGIN'; } switch ($authtype) { case 'PLAIN': // Start authentication if (!$this->sendCommand('AUTH', 'AUTH PLAIN', 334)) { return false; } // Send encoded username and password if (!$this->sendCommand( 'User & Password', base64_encode("\0" . $username . "\0" . $password), 235 ) ) { return false; } break; case 'LOGIN': // Start authentication if (!$this->sendCommand('AUTH', 'AUTH LOGIN', 334)) { return false; } if (!$this->sendCommand("Username", base64_encode($username), 334)) { return false; } if (!$this->sendCommand("Password", base64_encode($password), 235)) { return false; } break; case 'NTLM': /* * ntlm_sasl_client.php * Bundled with Permission * * How to telnet in windows: * http://technet.microsoft.com/en-us/library/aa995718%28EXCHG.65%29.aspx * PROTOCOL Docs http://curl.haxx.se/rfc/ntlm.html#ntlmSmtpAuthentication */ require_once 'extras/ntlm_sasl_client.php'; $temp = new stdClass(); $ntlm_client = new ntlm_sasl_client_class; //Check that functions are available if (!$ntlm_client->Initialize($temp)) { $this->error = array('error' => $temp->error); if ($this->do_debug >= 1) { $this->edebug( 'You need to enable some modules in your php.ini file: ' . $this->error['error'] ); } return false; } //msg1 $msg1 = $ntlm_client->TypeMsg1($realm, $workstation); //msg1 if (!$this->sendCommand( 'AUTH NTLM', 'AUTH NTLM ' . base64_encode($msg1), 334 ) ) { return false; } //Though 0 based, there is a white space after the 3 digit number //msg2 $challenge = substr($this->last_reply, 3); $challenge = base64_decode($challenge); $ntlm_res = $ntlm_client->NTLMResponse( substr($challenge, 24, 8), $password ); //msg3 $msg3 = $ntlm_client->TypeMsg3( $ntlm_res, $username, $realm, $workstation ); // send encoded username return $this->sendCommand('Username', base64_encode($msg3), 235); case 'CRAM-MD5': // Start authentication if (!$this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) { return false; } // Get the challenge $challenge = base64_decode(substr($this->last_reply, 4)); // Build the response $response = $username . ' ' . $this->hmac($challenge, $password); // send encoded credentials return $this->sendCommand('Username', base64_encode($response), 235); } return true; }
[ "public", "function", "authenticate", "(", "$", "username", ",", "$", "password", ",", "$", "authtype", "=", "'LOGIN'", ",", "$", "realm", "=", "''", ",", "$", "workstation", "=", "''", ")", "{", "if", "(", "empty", "(", "$", "authtype", ")", ")", "{", "$", "authtype", "=", "'LOGIN'", ";", "}", "switch", "(", "$", "authtype", ")", "{", "case", "'PLAIN'", ":", "// Start authentication", "if", "(", "!", "$", "this", "->", "sendCommand", "(", "'AUTH'", ",", "'AUTH PLAIN'", ",", "334", ")", ")", "{", "return", "false", ";", "}", "// Send encoded username and password", "if", "(", "!", "$", "this", "->", "sendCommand", "(", "'User & Password'", ",", "base64_encode", "(", "\"\\0\"", ".", "$", "username", ".", "\"\\0\"", ".", "$", "password", ")", ",", "235", ")", ")", "{", "return", "false", ";", "}", "break", ";", "case", "'LOGIN'", ":", "// Start authentication", "if", "(", "!", "$", "this", "->", "sendCommand", "(", "'AUTH'", ",", "'AUTH LOGIN'", ",", "334", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "$", "this", "->", "sendCommand", "(", "\"Username\"", ",", "base64_encode", "(", "$", "username", ")", ",", "334", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "$", "this", "->", "sendCommand", "(", "\"Password\"", ",", "base64_encode", "(", "$", "password", ")", ",", "235", ")", ")", "{", "return", "false", ";", "}", "break", ";", "case", "'NTLM'", ":", "/*\n * ntlm_sasl_client.php\n * Bundled with Permission\n *\n * How to telnet in windows:\n * http://technet.microsoft.com/en-us/library/aa995718%28EXCHG.65%29.aspx\n * PROTOCOL Docs http://curl.haxx.se/rfc/ntlm.html#ntlmSmtpAuthentication\n */", "require_once", "'extras/ntlm_sasl_client.php'", ";", "$", "temp", "=", "new", "stdClass", "(", ")", ";", "$", "ntlm_client", "=", "new", "ntlm_sasl_client_class", ";", "//Check that functions are available", "if", "(", "!", "$", "ntlm_client", "->", "Initialize", "(", "$", "temp", ")", ")", "{", "$", "this", "->", "error", "=", "array", "(", "'error'", "=>", "$", "temp", "->", "error", ")", ";", "if", "(", "$", "this", "->", "do_debug", ">=", "1", ")", "{", "$", "this", "->", "edebug", "(", "'You need to enable some modules in your php.ini file: '", ".", "$", "this", "->", "error", "[", "'error'", "]", ")", ";", "}", "return", "false", ";", "}", "//msg1", "$", "msg1", "=", "$", "ntlm_client", "->", "TypeMsg1", "(", "$", "realm", ",", "$", "workstation", ")", ";", "//msg1", "if", "(", "!", "$", "this", "->", "sendCommand", "(", "'AUTH NTLM'", ",", "'AUTH NTLM '", ".", "base64_encode", "(", "$", "msg1", ")", ",", "334", ")", ")", "{", "return", "false", ";", "}", "//Though 0 based, there is a white space after the 3 digit number", "//msg2", "$", "challenge", "=", "substr", "(", "$", "this", "->", "last_reply", ",", "3", ")", ";", "$", "challenge", "=", "base64_decode", "(", "$", "challenge", ")", ";", "$", "ntlm_res", "=", "$", "ntlm_client", "->", "NTLMResponse", "(", "substr", "(", "$", "challenge", ",", "24", ",", "8", ")", ",", "$", "password", ")", ";", "//msg3", "$", "msg3", "=", "$", "ntlm_client", "->", "TypeMsg3", "(", "$", "ntlm_res", ",", "$", "username", ",", "$", "realm", ",", "$", "workstation", ")", ";", "// send encoded username", "return", "$", "this", "->", "sendCommand", "(", "'Username'", ",", "base64_encode", "(", "$", "msg3", ")", ",", "235", ")", ";", "case", "'CRAM-MD5'", ":", "// Start authentication", "if", "(", "!", "$", "this", "->", "sendCommand", "(", "'AUTH CRAM-MD5'", ",", "'AUTH CRAM-MD5'", ",", "334", ")", ")", "{", "return", "false", ";", "}", "// Get the challenge", "$", "challenge", "=", "base64_decode", "(", "substr", "(", "$", "this", "->", "last_reply", ",", "4", ")", ")", ";", "// Build the response", "$", "response", "=", "$", "username", ".", "' '", ".", "$", "this", "->", "hmac", "(", "$", "challenge", ",", "$", "password", ")", ";", "// send encoded credentials", "return", "$", "this", "->", "sendCommand", "(", "'Username'", ",", "base64_encode", "(", "$", "response", ")", ",", "235", ")", ";", "}", "return", "true", ";", "}" ]
Perform SMTP authentication. Must be run after hello(). @see hello() @param string $username The user name @param string $password The password @param string $authtype The auth type (PLAIN, LOGIN, NTLM, CRAM-MD5) @param string $realm The auth realm for NTLM @param string $workstation The auth workstation for NTLM @access public @return boolean True if successfully authenticated.
[ "Perform", "SMTP", "authentication", ".", "Must", "be", "run", "after", "hello", "()", "." ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Mail/PHPMailer/class.smtp.php#L300-L404
ClanCats/Core
src/bundles/Mail/PHPMailer/class.smtp.php
SMTP.connected
public function connected() { if (is_resource($this->smtp_conn)) { $sock_status = stream_get_meta_data($this->smtp_conn); if ($sock_status['eof']) { // the socket is valid but we are not connected if ($this->do_debug >= 1) { $this->edebug( 'SMTP NOTICE: EOF caught while checking if connected' ); } $this->close(); return false; } return true; // everything looks good } return false; }
php
public function connected() { if (is_resource($this->smtp_conn)) { $sock_status = stream_get_meta_data($this->smtp_conn); if ($sock_status['eof']) { // the socket is valid but we are not connected if ($this->do_debug >= 1) { $this->edebug( 'SMTP NOTICE: EOF caught while checking if connected' ); } $this->close(); return false; } return true; // everything looks good } return false; }
[ "public", "function", "connected", "(", ")", "{", "if", "(", "is_resource", "(", "$", "this", "->", "smtp_conn", ")", ")", "{", "$", "sock_status", "=", "stream_get_meta_data", "(", "$", "this", "->", "smtp_conn", ")", ";", "if", "(", "$", "sock_status", "[", "'eof'", "]", ")", "{", "// the socket is valid but we are not connected", "if", "(", "$", "this", "->", "do_debug", ">=", "1", ")", "{", "$", "this", "->", "edebug", "(", "'SMTP NOTICE: EOF caught while checking if connected'", ")", ";", "}", "$", "this", "->", "close", "(", ")", ";", "return", "false", ";", "}", "return", "true", ";", "// everything looks good", "}", "return", "false", ";", "}" ]
Check connection state. @access public @return boolean True if connected.
[ "Check", "connection", "state", "." ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Mail/PHPMailer/class.smtp.php#L447-L464
ClanCats/Core
src/bundles/Mail/PHPMailer/class.smtp.php
SMTP.close
public function close() { $this->error = array(); $this->helo_rply = null; if (is_resource($this->smtp_conn)) { // close the connection and cleanup fclose($this->smtp_conn); if ($this->do_debug >= 3) { $this->edebug('Connection: closed'); } } }
php
public function close() { $this->error = array(); $this->helo_rply = null; if (is_resource($this->smtp_conn)) { // close the connection and cleanup fclose($this->smtp_conn); if ($this->do_debug >= 3) { $this->edebug('Connection: closed'); } } }
[ "public", "function", "close", "(", ")", "{", "$", "this", "->", "error", "=", "array", "(", ")", ";", "$", "this", "->", "helo_rply", "=", "null", ";", "if", "(", "is_resource", "(", "$", "this", "->", "smtp_conn", ")", ")", "{", "// close the connection and cleanup", "fclose", "(", "$", "this", "->", "smtp_conn", ")", ";", "if", "(", "$", "this", "->", "do_debug", ">=", "3", ")", "{", "$", "this", "->", "edebug", "(", "'Connection: closed'", ")", ";", "}", "}", "}" ]
Close the socket and clean up the state of the class. Don't use this function without first trying to use QUIT. @see quit() @access public @return void
[ "Close", "the", "socket", "and", "clean", "up", "the", "state", "of", "the", "class", ".", "Don", "t", "use", "this", "function", "without", "first", "trying", "to", "use", "QUIT", "." ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Mail/PHPMailer/class.smtp.php#L473-L484
ClanCats/Core
src/bundles/Mail/PHPMailer/class.smtp.php
SMTP.data
public function data($msg_data) { if (!$this->sendCommand('DATA', 'DATA', 354)) { return false; } /* The server is ready to accept data! * According to rfc821 we should not send more than 1000 characters on a single line (including the CRLF) * so we will break the data up into lines by \r and/or \n then if needed we will break each of those into * smaller lines to fit within the limit. * We will also look for lines that start with a '.' and prepend an additional '.'. * NOTE: this does not count towards line-length limit. */ // Normalize line breaks before exploding $lines = explode("\n", str_replace(array("\r\n", "\r"), "\n", $msg_data)); /* To distinguish between a complete RFC822 message and a plain message body, we check if the first field * of the first line (':' separated) does not contain a space then it _should_ be a header and we will * process all lines before a blank line as headers. */ $field = substr($lines[0], 0, strpos($lines[0], ':')); $in_headers = false; if (!empty($field) && strpos($field, ' ') === false) { $in_headers = true; } foreach ($lines as $line) { $lines_out = array(); if ($in_headers and $line == '') { $in_headers = false; } // ok we need to break this line up into several smaller lines //This is a small micro-optimisation: isset($str[$len]) is equivalent to (strlen($str) > $len) while (isset($line[self::MAX_LINE_LENGTH])) { //Working backwards, try to find a space within the last MAX_LINE_LENGTH chars of the line to break on //so as to avoid breaking in the middle of a word $pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' '); if (!$pos) { //Deliberately matches both false and 0 //No nice break found, add a hard break $pos = self::MAX_LINE_LENGTH - 1; $lines_out[] = substr($line, 0, $pos); $line = substr($line, $pos); } else { //Break at the found point $lines_out[] = substr($line, 0, $pos); //Move along by the amount we dealt with $line = substr($line, $pos + 1); } /* If processing headers add a LWSP-char to the front of new line * RFC822 section 3.1.1 */ if ($in_headers) { $line = "\t" . $line; } } $lines_out[] = $line; // Send the lines to the server foreach ($lines_out as $line_out) { //RFC2821 section 4.5.2 if (!empty($line_out) and $line_out[0] == '.') { $line_out = '.' . $line_out; } $this->client_send($line_out . self::CRLF); } } // Message data has been sent, complete the command return $this->sendCommand('DATA END', '.', 250); }
php
public function data($msg_data) { if (!$this->sendCommand('DATA', 'DATA', 354)) { return false; } /* The server is ready to accept data! * According to rfc821 we should not send more than 1000 characters on a single line (including the CRLF) * so we will break the data up into lines by \r and/or \n then if needed we will break each of those into * smaller lines to fit within the limit. * We will also look for lines that start with a '.' and prepend an additional '.'. * NOTE: this does not count towards line-length limit. */ // Normalize line breaks before exploding $lines = explode("\n", str_replace(array("\r\n", "\r"), "\n", $msg_data)); /* To distinguish between a complete RFC822 message and a plain message body, we check if the first field * of the first line (':' separated) does not contain a space then it _should_ be a header and we will * process all lines before a blank line as headers. */ $field = substr($lines[0], 0, strpos($lines[0], ':')); $in_headers = false; if (!empty($field) && strpos($field, ' ') === false) { $in_headers = true; } foreach ($lines as $line) { $lines_out = array(); if ($in_headers and $line == '') { $in_headers = false; } // ok we need to break this line up into several smaller lines //This is a small micro-optimisation: isset($str[$len]) is equivalent to (strlen($str) > $len) while (isset($line[self::MAX_LINE_LENGTH])) { //Working backwards, try to find a space within the last MAX_LINE_LENGTH chars of the line to break on //so as to avoid breaking in the middle of a word $pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' '); if (!$pos) { //Deliberately matches both false and 0 //No nice break found, add a hard break $pos = self::MAX_LINE_LENGTH - 1; $lines_out[] = substr($line, 0, $pos); $line = substr($line, $pos); } else { //Break at the found point $lines_out[] = substr($line, 0, $pos); //Move along by the amount we dealt with $line = substr($line, $pos + 1); } /* If processing headers add a LWSP-char to the front of new line * RFC822 section 3.1.1 */ if ($in_headers) { $line = "\t" . $line; } } $lines_out[] = $line; // Send the lines to the server foreach ($lines_out as $line_out) { //RFC2821 section 4.5.2 if (!empty($line_out) and $line_out[0] == '.') { $line_out = '.' . $line_out; } $this->client_send($line_out . self::CRLF); } } // Message data has been sent, complete the command return $this->sendCommand('DATA END', '.', 250); }
[ "public", "function", "data", "(", "$", "msg_data", ")", "{", "if", "(", "!", "$", "this", "->", "sendCommand", "(", "'DATA'", ",", "'DATA'", ",", "354", ")", ")", "{", "return", "false", ";", "}", "/* The server is ready to accept data!\n * According to rfc821 we should not send more than 1000 characters on a single line (including the CRLF)\n * so we will break the data up into lines by \\r and/or \\n then if needed we will break each of those into\n * smaller lines to fit within the limit.\n * We will also look for lines that start with a '.' and prepend an additional '.'.\n * NOTE: this does not count towards line-length limit.\n */", "// Normalize line breaks before exploding", "$", "lines", "=", "explode", "(", "\"\\n\"", ",", "str_replace", "(", "array", "(", "\"\\r\\n\"", ",", "\"\\r\"", ")", ",", "\"\\n\"", ",", "$", "msg_data", ")", ")", ";", "/* To distinguish between a complete RFC822 message and a plain message body, we check if the first field\n * of the first line (':' separated) does not contain a space then it _should_ be a header and we will\n * process all lines before a blank line as headers.\n */", "$", "field", "=", "substr", "(", "$", "lines", "[", "0", "]", ",", "0", ",", "strpos", "(", "$", "lines", "[", "0", "]", ",", "':'", ")", ")", ";", "$", "in_headers", "=", "false", ";", "if", "(", "!", "empty", "(", "$", "field", ")", "&&", "strpos", "(", "$", "field", ",", "' '", ")", "===", "false", ")", "{", "$", "in_headers", "=", "true", ";", "}", "foreach", "(", "$", "lines", "as", "$", "line", ")", "{", "$", "lines_out", "=", "array", "(", ")", ";", "if", "(", "$", "in_headers", "and", "$", "line", "==", "''", ")", "{", "$", "in_headers", "=", "false", ";", "}", "// ok we need to break this line up into several smaller lines", "//This is a small micro-optimisation: isset($str[$len]) is equivalent to (strlen($str) > $len)", "while", "(", "isset", "(", "$", "line", "[", "self", "::", "MAX_LINE_LENGTH", "]", ")", ")", "{", "//Working backwards, try to find a space within the last MAX_LINE_LENGTH chars of the line to break on", "//so as to avoid breaking in the middle of a word", "$", "pos", "=", "strrpos", "(", "substr", "(", "$", "line", ",", "0", ",", "self", "::", "MAX_LINE_LENGTH", ")", ",", "' '", ")", ";", "if", "(", "!", "$", "pos", ")", "{", "//Deliberately matches both false and 0", "//No nice break found, add a hard break", "$", "pos", "=", "self", "::", "MAX_LINE_LENGTH", "-", "1", ";", "$", "lines_out", "[", "]", "=", "substr", "(", "$", "line", ",", "0", ",", "$", "pos", ")", ";", "$", "line", "=", "substr", "(", "$", "line", ",", "$", "pos", ")", ";", "}", "else", "{", "//Break at the found point", "$", "lines_out", "[", "]", "=", "substr", "(", "$", "line", ",", "0", ",", "$", "pos", ")", ";", "//Move along by the amount we dealt with", "$", "line", "=", "substr", "(", "$", "line", ",", "$", "pos", "+", "1", ")", ";", "}", "/* If processing headers add a LWSP-char to the front of new line\n * RFC822 section 3.1.1\n */", "if", "(", "$", "in_headers", ")", "{", "$", "line", "=", "\"\\t\"", ".", "$", "line", ";", "}", "}", "$", "lines_out", "[", "]", "=", "$", "line", ";", "// Send the lines to the server", "foreach", "(", "$", "lines_out", "as", "$", "line_out", ")", "{", "//RFC2821 section 4.5.2", "if", "(", "!", "empty", "(", "$", "line_out", ")", "and", "$", "line_out", "[", "0", "]", "==", "'.'", ")", "{", "$", "line_out", "=", "'.'", ".", "$", "line_out", ";", "}", "$", "this", "->", "client_send", "(", "$", "line_out", ".", "self", "::", "CRLF", ")", ";", "}", "}", "// Message data has been sent, complete the command", "return", "$", "this", "->", "sendCommand", "(", "'DATA END'", ",", "'.'", ",", "250", ")", ";", "}" ]
Send an SMTP DATA command. Issues a data command and sends the msg_data to the server, finializing the mail transaction. $msg_data is the message that is to be send with the headers. Each header needs to be on a single line followed by a <CRLF> with the message headers and the message body being separated by and additional <CRLF>. Implements rfc 821: DATA <CRLF> @param string $msg_data Message data to send @access public @return boolean
[ "Send", "an", "SMTP", "DATA", "command", ".", "Issues", "a", "data", "command", "and", "sends", "the", "msg_data", "to", "the", "server", "finializing", "the", "mail", "transaction", ".", "$msg_data", "is", "the", "message", "that", "is", "to", "be", "send", "with", "the", "headers", ".", "Each", "header", "needs", "to", "be", "on", "a", "single", "line", "followed", "by", "a", "<CRLF", ">", "with", "the", "message", "headers", "and", "the", "message", "body", "being", "separated", "by", "and", "additional", "<CRLF", ">", ".", "Implements", "rfc", "821", ":", "DATA", "<CRLF", ">" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Mail/PHPMailer/class.smtp.php#L498-L568
ClanCats/Core
src/bundles/Mail/PHPMailer/class.smtp.php
SMTP.sendHello
protected function sendHello($hello, $host) { $noerror = $this->sendCommand($hello, $hello . ' ' . $host, 250); $this->helo_rply = $this->last_reply; return $noerror; }
php
protected function sendHello($hello, $host) { $noerror = $this->sendCommand($hello, $hello . ' ' . $host, 250); $this->helo_rply = $this->last_reply; return $noerror; }
[ "protected", "function", "sendHello", "(", "$", "hello", ",", "$", "host", ")", "{", "$", "noerror", "=", "$", "this", "->", "sendCommand", "(", "$", "hello", ",", "$", "hello", ".", "' '", ".", "$", "host", ",", "250", ")", ";", "$", "this", "->", "helo_rply", "=", "$", "this", "->", "last_reply", ";", "return", "$", "noerror", ";", "}" ]
Send an SMTP HELO or EHLO command. Low-level implementation used by hello() @see hello() @param string $hello The HELO string @param string $host The hostname to say we are @access protected @return boolean
[ "Send", "an", "SMTP", "HELO", "or", "EHLO", "command", ".", "Low", "-", "level", "implementation", "used", "by", "hello", "()" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Mail/PHPMailer/class.smtp.php#L595-L600
ClanCats/Core
src/bundles/Mail/PHPMailer/class.smtp.php
SMTP.sendCommand
protected function sendCommand($command, $commandstring, $expect) { if (!$this->connected()) { $this->error = array( 'error' => "Called $command without being connected" ); return false; } $this->client_send($commandstring . self::CRLF); $reply = $this->get_lines(); $code = substr($reply, 0, 3); if ($this->do_debug >= 2) { $this->edebug('SERVER -> CLIENT: ' . $reply); } if (!in_array($code, (array)$expect)) { $this->last_reply = null; $this->error = array( 'error' => "$command command failed", 'smtp_code' => $code, 'detail' => substr($reply, 4) ); if ($this->do_debug >= 1) { $this->edebug( 'SMTP ERROR: ' . $this->error['error'] . ': ' . $reply ); } return false; } $this->last_reply = $reply; $this->error = array(); return true; }
php
protected function sendCommand($command, $commandstring, $expect) { if (!$this->connected()) { $this->error = array( 'error' => "Called $command without being connected" ); return false; } $this->client_send($commandstring . self::CRLF); $reply = $this->get_lines(); $code = substr($reply, 0, 3); if ($this->do_debug >= 2) { $this->edebug('SERVER -> CLIENT: ' . $reply); } if (!in_array($code, (array)$expect)) { $this->last_reply = null; $this->error = array( 'error' => "$command command failed", 'smtp_code' => $code, 'detail' => substr($reply, 4) ); if ($this->do_debug >= 1) { $this->edebug( 'SMTP ERROR: ' . $this->error['error'] . ': ' . $reply ); } return false; } $this->last_reply = $reply; $this->error = array(); return true; }
[ "protected", "function", "sendCommand", "(", "$", "command", ",", "$", "commandstring", ",", "$", "expect", ")", "{", "if", "(", "!", "$", "this", "->", "connected", "(", ")", ")", "{", "$", "this", "->", "error", "=", "array", "(", "'error'", "=>", "\"Called $command without being connected\"", ")", ";", "return", "false", ";", "}", "$", "this", "->", "client_send", "(", "$", "commandstring", ".", "self", "::", "CRLF", ")", ";", "$", "reply", "=", "$", "this", "->", "get_lines", "(", ")", ";", "$", "code", "=", "substr", "(", "$", "reply", ",", "0", ",", "3", ")", ";", "if", "(", "$", "this", "->", "do_debug", ">=", "2", ")", "{", "$", "this", "->", "edebug", "(", "'SERVER -> CLIENT: '", ".", "$", "reply", ")", ";", "}", "if", "(", "!", "in_array", "(", "$", "code", ",", "(", "array", ")", "$", "expect", ")", ")", "{", "$", "this", "->", "last_reply", "=", "null", ";", "$", "this", "->", "error", "=", "array", "(", "'error'", "=>", "\"$command command failed\"", ",", "'smtp_code'", "=>", "$", "code", ",", "'detail'", "=>", "substr", "(", "$", "reply", ",", "4", ")", ")", ";", "if", "(", "$", "this", "->", "do_debug", ">=", "1", ")", "{", "$", "this", "->", "edebug", "(", "'SMTP ERROR: '", ".", "$", "this", "->", "error", "[", "'error'", "]", ".", "': '", ".", "$", "reply", ")", ";", "}", "return", "false", ";", "}", "$", "this", "->", "last_reply", "=", "$", "reply", ";", "$", "this", "->", "error", "=", "array", "(", ")", ";", "return", "true", ";", "}" ]
Send a command to an SMTP server and check its return code. @param string $command The command name - not sent to the server @param string $commandstring The actual command to send @param integer|array $expect One or more expected integer success codes @access protected @return boolean True on success.
[ "Send", "a", "command", "to", "an", "SMTP", "server", "and", "check", "its", "return", "code", "." ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Mail/PHPMailer/class.smtp.php#L680-L715
ClanCats/Core
src/bundles/Mail/PHPMailer/class.smtp.php
SMTP.turn
public function turn() { $this->error = array( 'error' => 'The SMTP TURN command is not implemented' ); if ($this->do_debug >= 1) { $this->edebug('SMTP NOTICE: ' . $this->error['error']); } return false; }
php
public function turn() { $this->error = array( 'error' => 'The SMTP TURN command is not implemented' ); if ($this->do_debug >= 1) { $this->edebug('SMTP NOTICE: ' . $this->error['error']); } return false; }
[ "public", "function", "turn", "(", ")", "{", "$", "this", "->", "error", "=", "array", "(", "'error'", "=>", "'The SMTP TURN command is not implemented'", ")", ";", "if", "(", "$", "this", "->", "do_debug", ">=", "1", ")", "{", "$", "this", "->", "edebug", "(", "'SMTP NOTICE: '", ".", "$", "this", "->", "error", "[", "'error'", "]", ")", ";", "}", "return", "false", ";", "}" ]
Send an SMTP TURN command. This is an optional command for SMTP that this class does not support. This method is here to make the RFC821 Definition complete for this class and _may_ be implemented in future Implements from rfc 821: TURN <CRLF> @access public @return boolean
[ "Send", "an", "SMTP", "TURN", "command", ".", "This", "is", "an", "optional", "command", "for", "SMTP", "that", "this", "class", "does", "not", "support", ".", "This", "method", "is", "here", "to", "make", "the", "RFC821", "Definition", "complete", "for", "this", "class", "and", "_may_", "be", "implemented", "in", "future", "Implements", "from", "rfc", "821", ":", "TURN", "<CRLF", ">" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Mail/PHPMailer/class.smtp.php#L766-L775
ClanCats/Core
src/bundles/Mail/PHPMailer/class.smtp.php
SMTP.client_send
public function client_send($data) { if ($this->do_debug >= 1) { $this->edebug("CLIENT -> SERVER: $data"); } return fwrite($this->smtp_conn, $data); }
php
public function client_send($data) { if ($this->do_debug >= 1) { $this->edebug("CLIENT -> SERVER: $data"); } return fwrite($this->smtp_conn, $data); }
[ "public", "function", "client_send", "(", "$", "data", ")", "{", "if", "(", "$", "this", "->", "do_debug", ">=", "1", ")", "{", "$", "this", "->", "edebug", "(", "\"CLIENT -> SERVER: $data\"", ")", ";", "}", "return", "fwrite", "(", "$", "this", "->", "smtp_conn", ",", "$", "data", ")", ";", "}" ]
Send raw data to the server. @param string $data The data to send @access public @return integer|boolean The number of bytes sent to the server or false on error
[ "Send", "raw", "data", "to", "the", "server", "." ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Mail/PHPMailer/class.smtp.php#L783-L789
SignpostMarv/daft-object
src/AbstractArrayBackedDaftObject.php
AbstractArrayBackedDaftObject.RetrievePropertyValueFromData
protected function RetrievePropertyValueFromData(string $property) { $isNullable = in_array( $property, static::DaftObjectNullableProperties(), DefinitionAssistant::IN_ARRAY_STRICT_MODE ); if ( ! array_key_exists($property, $this->data) && ! $isNullable) { throw Exceptions\Factory::PropertyNotNullableException(static::class, $property); } elseif ($isNullable) { return $this->data[$property] ?? null; } return $this->data[$property]; }
php
protected function RetrievePropertyValueFromData(string $property) { $isNullable = in_array( $property, static::DaftObjectNullableProperties(), DefinitionAssistant::IN_ARRAY_STRICT_MODE ); if ( ! array_key_exists($property, $this->data) && ! $isNullable) { throw Exceptions\Factory::PropertyNotNullableException(static::class, $property); } elseif ($isNullable) { return $this->data[$property] ?? null; } return $this->data[$property]; }
[ "protected", "function", "RetrievePropertyValueFromData", "(", "string", "$", "property", ")", "{", "$", "isNullable", "=", "in_array", "(", "$", "property", ",", "static", "::", "DaftObjectNullableProperties", "(", ")", ",", "DefinitionAssistant", "::", "IN_ARRAY_STRICT_MODE", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "property", ",", "$", "this", "->", "data", ")", "&&", "!", "$", "isNullable", ")", "{", "throw", "Exceptions", "\\", "Factory", "::", "PropertyNotNullableException", "(", "static", "::", "class", ",", "$", "property", ")", ";", "}", "elseif", "(", "$", "isNullable", ")", "{", "return", "$", "this", "->", "data", "[", "$", "property", "]", "??", "null", ";", "}", "return", "$", "this", "->", "data", "[", "$", "property", "]", ";", "}" ]
Retrieve a property from data. @param string $property the property being retrieved @throws Exceptions\PropertyNotNullableException if value is not set and $property is not listed as nullabe @return scalar|array|object|null the property value
[ "Retrieve", "a", "property", "from", "data", "." ]
train
https://github.com/SignpostMarv/daft-object/blob/514886592b64986cc637040045f098335e27c037/src/AbstractArrayBackedDaftObject.php#L180-L195
SignpostMarv/daft-object
src/AbstractArrayBackedDaftObject.php
AbstractArrayBackedDaftObject.MaybeModifyValueBeforeNudge
private function MaybeModifyValueBeforeNudge( string $property, $value, bool $autoTrimStrings = self::BOOL_DEFAULT_AUTOTRIMSTRINGS, bool $throwIfNotUnique = self::BOOL_DEFAULT_THROWIFNOTUNIQUE ) { $spec = null; if ( is_a( static::class, DaftObjectHasPropertiesWithMultiTypedArraysOfUniqueValues::class, true ) ) { $spec = ( static::DaftObjectPropertiesWithMultiTypedArraysOfUniqueValues()[$property] ?? null ); } if (is_array($spec)) { $value = DefinitionAssistant::MaybeThrowIfValueDoesNotMatchMultiTypedArray( $autoTrimStrings, $throwIfNotUnique, $value, ...$spec ); } if (is_string($value) && $autoTrimStrings) { $value = trim($value); } return $value; }
php
private function MaybeModifyValueBeforeNudge( string $property, $value, bool $autoTrimStrings = self::BOOL_DEFAULT_AUTOTRIMSTRINGS, bool $throwIfNotUnique = self::BOOL_DEFAULT_THROWIFNOTUNIQUE ) { $spec = null; if ( is_a( static::class, DaftObjectHasPropertiesWithMultiTypedArraysOfUniqueValues::class, true ) ) { $spec = ( static::DaftObjectPropertiesWithMultiTypedArraysOfUniqueValues()[$property] ?? null ); } if (is_array($spec)) { $value = DefinitionAssistant::MaybeThrowIfValueDoesNotMatchMultiTypedArray( $autoTrimStrings, $throwIfNotUnique, $value, ...$spec ); } if (is_string($value) && $autoTrimStrings) { $value = trim($value); } return $value; }
[ "private", "function", "MaybeModifyValueBeforeNudge", "(", "string", "$", "property", ",", "$", "value", ",", "bool", "$", "autoTrimStrings", "=", "self", "::", "BOOL_DEFAULT_AUTOTRIMSTRINGS", ",", "bool", "$", "throwIfNotUnique", "=", "self", "::", "BOOL_DEFAULT_THROWIFNOTUNIQUE", ")", "{", "$", "spec", "=", "null", ";", "if", "(", "is_a", "(", "static", "::", "class", ",", "DaftObjectHasPropertiesWithMultiTypedArraysOfUniqueValues", "::", "class", ",", "true", ")", ")", "{", "$", "spec", "=", "(", "static", "::", "DaftObjectPropertiesWithMultiTypedArraysOfUniqueValues", "(", ")", "[", "$", "property", "]", "??", "null", ")", ";", "}", "if", "(", "is_array", "(", "$", "spec", ")", ")", "{", "$", "value", "=", "DefinitionAssistant", "::", "MaybeThrowIfValueDoesNotMatchMultiTypedArray", "(", "$", "autoTrimStrings", ",", "$", "throwIfNotUnique", ",", "$", "value", ",", "...", "$", "spec", ")", ";", "}", "if", "(", "is_string", "(", "$", "value", ")", "&&", "$", "autoTrimStrings", ")", "{", "$", "value", "=", "trim", "(", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
@param scalar|array|object|null $value @return scalar|array|object|null
[ "@param", "scalar|array|object|null", "$value" ]
train
https://github.com/SignpostMarv/daft-object/blob/514886592b64986cc637040045f098335e27c037/src/AbstractArrayBackedDaftObject.php#L291-L325
inpsyde/inpsyde-filter
src/WordPress/EscUrlRaw.php
EscUrlRaw.filter
public function filter( $value ) { if ( ! is_scalar( $value ) || empty( $value ) ) { do_action( 'inpsyde.filter.error', 'The given value is not scalar or empty.', [ 'method' => __METHOD__, 'value' => $value ] ); return $value; } return esc_url_raw( (string) $value, $this->options[ 'protocols' ] ); }
php
public function filter( $value ) { if ( ! is_scalar( $value ) || empty( $value ) ) { do_action( 'inpsyde.filter.error', 'The given value is not scalar or empty.', [ 'method' => __METHOD__, 'value' => $value ] ); return $value; } return esc_url_raw( (string) $value, $this->options[ 'protocols' ] ); }
[ "public", "function", "filter", "(", "$", "value", ")", "{", "if", "(", "!", "is_scalar", "(", "$", "value", ")", "||", "empty", "(", "$", "value", ")", ")", "{", "do_action", "(", "'inpsyde.filter.error'", ",", "'The given value is not scalar or empty.'", ",", "[", "'method'", "=>", "__METHOD__", ",", "'value'", "=>", "$", "value", "]", ")", ";", "return", "$", "value", ";", "}", "return", "esc_url_raw", "(", "(", "string", ")", "$", "value", ",", "$", "this", "->", "options", "[", "'protocols'", "]", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/inpsyde/inpsyde-filter/blob/777a6208ea4dfbeed89e6d0712a35dc25eab498b/src/WordPress/EscUrlRaw.php#L24-L33
egeloen/IvorySerializerBundle
DependencyInjection/Compiler/RegisterVisitorPass.php
RegisterVisitorPass.process
public function process(ContainerBuilder $container) { $mapping = [ 'serialization' => Direction::SERIALIZATION, 'deserialization' => Direction::DESERIALIZATION, ]; $typeRegistry = $container->getDefinition('ivory.serializer.registry.visitor'); foreach ($container->findTaggedServiceIds($tag = 'ivory.serializer.visitor') as $id => $attributes) { foreach ($attributes as $attribute) { if (!isset($attribute['direction'])) { throw new \RuntimeException(sprintf( 'No "direction" attribute found for the tag "%s" on the service "%s".', $tag, $id )); } if (!isset($mapping[$attribute['direction']])) { throw new \RuntimeException(sprintf( 'The "direction" attribute (%s) found for the tag "%s" on the service "%s" is not valid (Supported: %s).', $attribute['direction'], $tag, $id, implode(', ', array_keys($mapping)) )); } if (!isset($attribute['format'])) { throw new \RuntimeException(sprintf( 'No "format" attribute found for the tag "%s" on the service "%s".', $tag, $id )); } $typeRegistry->addMethodCall( 'registerVisitor', [$mapping[$attribute['direction']], $attribute['format'], new Reference($id)] ); } } }
php
public function process(ContainerBuilder $container) { $mapping = [ 'serialization' => Direction::SERIALIZATION, 'deserialization' => Direction::DESERIALIZATION, ]; $typeRegistry = $container->getDefinition('ivory.serializer.registry.visitor'); foreach ($container->findTaggedServiceIds($tag = 'ivory.serializer.visitor') as $id => $attributes) { foreach ($attributes as $attribute) { if (!isset($attribute['direction'])) { throw new \RuntimeException(sprintf( 'No "direction" attribute found for the tag "%s" on the service "%s".', $tag, $id )); } if (!isset($mapping[$attribute['direction']])) { throw new \RuntimeException(sprintf( 'The "direction" attribute (%s) found for the tag "%s" on the service "%s" is not valid (Supported: %s).', $attribute['direction'], $tag, $id, implode(', ', array_keys($mapping)) )); } if (!isset($attribute['format'])) { throw new \RuntimeException(sprintf( 'No "format" attribute found for the tag "%s" on the service "%s".', $tag, $id )); } $typeRegistry->addMethodCall( 'registerVisitor', [$mapping[$attribute['direction']], $attribute['format'], new Reference($id)] ); } } }
[ "public", "function", "process", "(", "ContainerBuilder", "$", "container", ")", "{", "$", "mapping", "=", "[", "'serialization'", "=>", "Direction", "::", "SERIALIZATION", ",", "'deserialization'", "=>", "Direction", "::", "DESERIALIZATION", ",", "]", ";", "$", "typeRegistry", "=", "$", "container", "->", "getDefinition", "(", "'ivory.serializer.registry.visitor'", ")", ";", "foreach", "(", "$", "container", "->", "findTaggedServiceIds", "(", "$", "tag", "=", "'ivory.serializer.visitor'", ")", "as", "$", "id", "=>", "$", "attributes", ")", "{", "foreach", "(", "$", "attributes", "as", "$", "attribute", ")", "{", "if", "(", "!", "isset", "(", "$", "attribute", "[", "'direction'", "]", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'No \"direction\" attribute found for the tag \"%s\" on the service \"%s\".'", ",", "$", "tag", ",", "$", "id", ")", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "mapping", "[", "$", "attribute", "[", "'direction'", "]", "]", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'The \"direction\" attribute (%s) found for the tag \"%s\" on the service \"%s\" is not valid (Supported: %s).'", ",", "$", "attribute", "[", "'direction'", "]", ",", "$", "tag", ",", "$", "id", ",", "implode", "(", "', '", ",", "array_keys", "(", "$", "mapping", ")", ")", ")", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "attribute", "[", "'format'", "]", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'No \"format\" attribute found for the tag \"%s\" on the service \"%s\".'", ",", "$", "tag", ",", "$", "id", ")", ")", ";", "}", "$", "typeRegistry", "->", "addMethodCall", "(", "'registerVisitor'", ",", "[", "$", "mapping", "[", "$", "attribute", "[", "'direction'", "]", "]", ",", "$", "attribute", "[", "'format'", "]", ",", "new", "Reference", "(", "$", "id", ")", "]", ")", ";", "}", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/egeloen/IvorySerializerBundle/blob/a2bdd912bf715c61b823cf7257ee232d5c823dd3/DependencyInjection/Compiler/RegisterVisitorPass.php#L27-L70
haldayne/boost
src/MapOfCollections.php
MapOfCollections.pluck
public function pluck($key_for_value, $key_for_key = null) { $map = new Map; $this->walk(function ($v) use ($key_for_value, $key_for_key, $map) { // get the key to use if (null === $key_for_key) { $key = null; } else if ($v->has($key_for_key)) { $key = $v->get($key_for_key); } else { throw new \OutOfBoundsException(); } // add the value at that key, provided we have one if ($v->has($key_for_value)) { $map[$key] = $v->get($key_for_value); } else { throw new \OutOfBoundsException(); } }); return $map; }
php
public function pluck($key_for_value, $key_for_key = null) { $map = new Map; $this->walk(function ($v) use ($key_for_value, $key_for_key, $map) { // get the key to use if (null === $key_for_key) { $key = null; } else if ($v->has($key_for_key)) { $key = $v->get($key_for_key); } else { throw new \OutOfBoundsException(); } // add the value at that key, provided we have one if ($v->has($key_for_value)) { $map[$key] = $v->get($key_for_value); } else { throw new \OutOfBoundsException(); } }); return $map; }
[ "public", "function", "pluck", "(", "$", "key_for_value", ",", "$", "key_for_key", "=", "null", ")", "{", "$", "map", "=", "new", "Map", ";", "$", "this", "->", "walk", "(", "function", "(", "$", "v", ")", "use", "(", "$", "key_for_value", ",", "$", "key_for_key", ",", "$", "map", ")", "{", "// get the key to use", "if", "(", "null", "===", "$", "key_for_key", ")", "{", "$", "key", "=", "null", ";", "}", "else", "if", "(", "$", "v", "->", "has", "(", "$", "key_for_key", ")", ")", "{", "$", "key", "=", "$", "v", "->", "get", "(", "$", "key_for_key", ")", ";", "}", "else", "{", "throw", "new", "\\", "OutOfBoundsException", "(", ")", ";", "}", "// add the value at that key, provided we have one", "if", "(", "$", "v", "->", "has", "(", "$", "key_for_value", ")", ")", "{", "$", "map", "[", "$", "key", "]", "=", "$", "v", "->", "get", "(", "$", "key_for_value", ")", ";", "}", "else", "{", "throw", "new", "\\", "OutOfBoundsException", "(", ")", ";", "}", "}", ")", ";", "return", "$", "map", ";", "}" ]
Create a new map by pulling the given key out of all contained maps. Thinking of a Map of Collections as a two-dimensional array, this method slices a column out: ``` use Haldayne\Boost\MapOfCollections; $map = new MapOfCollections; $map->push([ 'id' => 5, 'name' => 'Ada', 'age' => 16 ]); $map->push([ 'id' => 6, 'name' => 'Bee', 'age' => 12 ]); $map->push([ 'id' => 7, 'name' => 'Cam', 'age' => 37 ]); var_dump( $map->pluck('name')->toArray(); // [ 'Ada', 'Bee', 'Cam' ] $map->pluck('name', 'id')->toArray(); // [ 5=>'Ada', 6=>'Bee', 7=>'Cam' ] ); ``` @param $mixed $key_for_value The key holding the new value. @param $mixed $key_for_key The key holding the new value's key. @return \Haldayne\Boost\Map @api
[ "Create", "a", "new", "map", "by", "pulling", "the", "given", "key", "out", "of", "all", "contained", "maps", "." ]
train
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/MapOfCollections.php#L40-L61
Ocramius/OcraDiCompiler
src/OcraDiCompiler/Mvc/Service/DiFactory.php
DiFactory.createService
public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('Config'); ErrorHandler::start(); $compiledInstantiators = include $config['ocra_di_compiler']['compiled_di_instantiator_filename']; ErrorHandler::stop(); if (!is_array($compiledInstantiators)) { $di = $this->createDi($config); $this->compileDi($di, $config); $this->getDiDefinitions($config, $di); $compiledInstantiators = include $config['ocra_di_compiler']['compiled_di_instantiator_filename']; } $di = new CompiledInstantiatorsDi(); $this->configureDi($di, $config); $di->setCompiledInstantiators($compiledInstantiators); $this->registerAbstractFactory($serviceLocator, $di); return $di; }
php
public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('Config'); ErrorHandler::start(); $compiledInstantiators = include $config['ocra_di_compiler']['compiled_di_instantiator_filename']; ErrorHandler::stop(); if (!is_array($compiledInstantiators)) { $di = $this->createDi($config); $this->compileDi($di, $config); $this->getDiDefinitions($config, $di); $compiledInstantiators = include $config['ocra_di_compiler']['compiled_di_instantiator_filename']; } $di = new CompiledInstantiatorsDi(); $this->configureDi($di, $config); $di->setCompiledInstantiators($compiledInstantiators); $this->registerAbstractFactory($serviceLocator, $di); return $di; }
[ "public", "function", "createService", "(", "ServiceLocatorInterface", "$", "serviceLocator", ")", "{", "$", "config", "=", "$", "serviceLocator", "->", "get", "(", "'Config'", ")", ";", "ErrorHandler", "::", "start", "(", ")", ";", "$", "compiledInstantiators", "=", "include", "$", "config", "[", "'ocra_di_compiler'", "]", "[", "'compiled_di_instantiator_filename'", "]", ";", "ErrorHandler", "::", "stop", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "compiledInstantiators", ")", ")", "{", "$", "di", "=", "$", "this", "->", "createDi", "(", "$", "config", ")", ";", "$", "this", "->", "compileDi", "(", "$", "di", ",", "$", "config", ")", ";", "$", "this", "->", "getDiDefinitions", "(", "$", "config", ",", "$", "di", ")", ";", "$", "compiledInstantiators", "=", "include", "$", "config", "[", "'ocra_di_compiler'", "]", "[", "'compiled_di_instantiator_filename'", "]", ";", "}", "$", "di", "=", "new", "CompiledInstantiatorsDi", "(", ")", ";", "$", "this", "->", "configureDi", "(", "$", "di", ",", "$", "config", ")", ";", "$", "di", "->", "setCompiledInstantiators", "(", "$", "compiledInstantiators", ")", ";", "$", "this", "->", "registerAbstractFactory", "(", "$", "serviceLocator", ",", "$", "di", ")", ";", "return", "$", "di", ";", "}" ]
Generates a compiled Di proxy to be used as a replacement for \Zend\Di\Di @param ServiceLocatorInterface $serviceLocator @return Di
[ "Generates", "a", "compiled", "Di", "proxy", "to", "be", "used", "as", "a", "replacement", "for", "\\", "Zend", "\\", "Di", "\\", "Di" ]
train
https://github.com/Ocramius/OcraDiCompiler/blob/667f4b24771f27fb9c8d6c38ffaf72d9cd55ca4a/src/OcraDiCompiler/Mvc/Service/DiFactory.php#L55-L77
kherge-abandoned/php-wise
src/lib/Herrera/Wise/Util/ArrayUtil.php
ArrayUtil.flatten
public static function flatten(array $array, $prefix = '', $join = '.') { $flat = array(); foreach ($array as $key => $value) { $key = $prefix ? $prefix . $join . $key : $key; if (is_array($value)) { $flat = array_merge( $flat, self::flatten($value, $key, $join) ); } else { $flat[$key] = $value; } } return $flat; }
php
public static function flatten(array $array, $prefix = '', $join = '.') { $flat = array(); foreach ($array as $key => $value) { $key = $prefix ? $prefix . $join . $key : $key; if (is_array($value)) { $flat = array_merge( $flat, self::flatten($value, $key, $join) ); } else { $flat[$key] = $value; } } return $flat; }
[ "public", "static", "function", "flatten", "(", "array", "$", "array", ",", "$", "prefix", "=", "''", ",", "$", "join", "=", "'.'", ")", "{", "$", "flat", "=", "array", "(", ")", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "key", "=", "$", "prefix", "?", "$", "prefix", ".", "$", "join", ".", "$", "key", ":", "$", "key", ";", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "flat", "=", "array_merge", "(", "$", "flat", ",", "self", "::", "flatten", "(", "$", "value", ",", "$", "key", ",", "$", "join", ")", ")", ";", "}", "else", "{", "$", "flat", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "flat", ";", "}" ]
Flattens an associative array. @param array $array An array. @param string $prefix A key prefix. @param string $join The key join character. @return array The flattened array.
[ "Flattens", "an", "associative", "array", "." ]
train
https://github.com/kherge-abandoned/php-wise/blob/7621e0be7dbb2a015d68197d290fe8469f539a4d/src/lib/Herrera/Wise/Util/ArrayUtil.php#L21-L39
kherge-abandoned/php-wise
src/lib/Herrera/Wise/Util/ArrayUtil.php
ArrayUtil.walkRecursive
public static function walkRecursive(&$array, $callback, $data = null) { foreach ($array as $key => &$value) { if (is_array($value)) { self::walkRecursive($value, $callback, $data); } else { $callback($value, $key, $array, $data); } } }
php
public static function walkRecursive(&$array, $callback, $data = null) { foreach ($array as $key => &$value) { if (is_array($value)) { self::walkRecursive($value, $callback, $data); } else { $callback($value, $key, $array, $data); } } }
[ "public", "static", "function", "walkRecursive", "(", "&", "$", "array", ",", "$", "callback", ",", "$", "data", "=", "null", ")", "{", "foreach", "(", "$", "array", "as", "$", "key", "=>", "&", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "self", "::", "walkRecursive", "(", "$", "value", ",", "$", "callback", ",", "$", "data", ")", ";", "}", "else", "{", "$", "callback", "(", "$", "value", ",", "$", "key", ",", "$", "array", ",", "$", "data", ")", ";", "}", "}", "}" ]
Similar to `array_walk_recursive()`, but passes the current array too. @param array &$array An array. @param callable $callback The callable. @param mixed $data The user data.
[ "Similar", "to", "array_walk_recursive", "()", "but", "passes", "the", "current", "array", "too", "." ]
train
https://github.com/kherge-abandoned/php-wise/blob/7621e0be7dbb2a015d68197d290fe8469f539a4d/src/lib/Herrera/Wise/Util/ArrayUtil.php#L48-L57
webforge-labs/psc-cms
lib/Psc/HTML/WidgetBase.php
WidgetBase.doInit
protected function doInit() { if ($this->loadWith === self::JAVASCRIPT) { jQuery::widget($this->html, $this->widgetName, (array) $this->widgetOptions); } else { $this->html ->setAttribute('data-widget', $this->widgetName) ->setAttribute('data-widget-options', $this->getJSONConverter()->stringify((object) $this->widgetOptions)) ->addClass('widget-not-initialized') ; } }
php
protected function doInit() { if ($this->loadWith === self::JAVASCRIPT) { jQuery::widget($this->html, $this->widgetName, (array) $this->widgetOptions); } else { $this->html ->setAttribute('data-widget', $this->widgetName) ->setAttribute('data-widget-options', $this->getJSONConverter()->stringify((object) $this->widgetOptions)) ->addClass('widget-not-initialized') ; } }
[ "protected", "function", "doInit", "(", ")", "{", "if", "(", "$", "this", "->", "loadWith", "===", "self", "::", "JAVASCRIPT", ")", "{", "jQuery", "::", "widget", "(", "$", "this", "->", "html", ",", "$", "this", "->", "widgetName", ",", "(", "array", ")", "$", "this", "->", "widgetOptions", ")", ";", "}", "else", "{", "$", "this", "->", "html", "->", "setAttribute", "(", "'data-widget'", ",", "$", "this", "->", "widgetName", ")", "->", "setAttribute", "(", "'data-widget-options'", ",", "$", "this", "->", "getJSONConverter", "(", ")", "->", "stringify", "(", "(", "object", ")", "$", "this", "->", "widgetOptions", ")", ")", "->", "addClass", "(", "'widget-not-initialized'", ")", ";", "}", "}" ]
Initialisiert das Widget des objektes wenn loadWith === self::JAVASCRIPT ist an das Element wird inline Javascript angehängt welcher jQuery( elementSelector ).$widgetName.({ $options}) aufruft ansonsten wird im Element die attribute data-widget und data-widget-options (ein JSON string) gesetzt
[ "Initialisiert", "das", "Widget", "des", "objektes" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/HTML/WidgetBase.php#L40-L50
freyo/flysystem-qcloud-cos-v3
src/ServiceProvider.php
ServiceProvider.boot
public function boot() { if ($this->app instanceof LumenApplication) { $this->app->configure('filesystems'); } $this->app->make('filesystem') ->extend('cosv3', function ($app, $config) { $flysystem = new Filesystem(new Adapter($config)); $flysystem->addPlugin(new PutRemoteFile()); $flysystem->addPlugin(new PutRemoteFileAs()); $flysystem->addPlugin(new GetUrl()); return $flysystem; }); }
php
public function boot() { if ($this->app instanceof LumenApplication) { $this->app->configure('filesystems'); } $this->app->make('filesystem') ->extend('cosv3', function ($app, $config) { $flysystem = new Filesystem(new Adapter($config)); $flysystem->addPlugin(new PutRemoteFile()); $flysystem->addPlugin(new PutRemoteFileAs()); $flysystem->addPlugin(new GetUrl()); return $flysystem; }); }
[ "public", "function", "boot", "(", ")", "{", "if", "(", "$", "this", "->", "app", "instanceof", "LumenApplication", ")", "{", "$", "this", "->", "app", "->", "configure", "(", "'filesystems'", ")", ";", "}", "$", "this", "->", "app", "->", "make", "(", "'filesystem'", ")", "->", "extend", "(", "'cosv3'", ",", "function", "(", "$", "app", ",", "$", "config", ")", "{", "$", "flysystem", "=", "new", "Filesystem", "(", "new", "Adapter", "(", "$", "config", ")", ")", ";", "$", "flysystem", "->", "addPlugin", "(", "new", "PutRemoteFile", "(", ")", ")", ";", "$", "flysystem", "->", "addPlugin", "(", "new", "PutRemoteFileAs", "(", ")", ")", ";", "$", "flysystem", "->", "addPlugin", "(", "new", "GetUrl", "(", ")", ")", ";", "return", "$", "flysystem", ";", "}", ")", ";", "}" ]
Bootstrap any application services. @return void
[ "Bootstrap", "any", "application", "services", "." ]
train
https://github.com/freyo/flysystem-qcloud-cos-v3/blob/6bddbc22396aa1228942ec4c0ce46935d415f3b4/src/ServiceProvider.php#L22-L36
anime-db/app-bundle
src/Event/Listener/Project.php
Project.onUpdatedProposeUpdateTask
public function onUpdatedProposeUpdateTask() { /* @var $task Task */ $task = $this->em ->getRepository('AnimeDbAppBundle:Task') ->findOneBy(['command' => 'animedb:propose-update']); $next_run = new \DateTime(); $next_run->modify(sprintf('+%s seconds 01:00:00', ProposeUpdateCommand::INERVAL_UPDATE)); $this->em->persist($task->setNextRun($next_run)); $this->em->flush(); }
php
public function onUpdatedProposeUpdateTask() { /* @var $task Task */ $task = $this->em ->getRepository('AnimeDbAppBundle:Task') ->findOneBy(['command' => 'animedb:propose-update']); $next_run = new \DateTime(); $next_run->modify(sprintf('+%s seconds 01:00:00', ProposeUpdateCommand::INERVAL_UPDATE)); $this->em->persist($task->setNextRun($next_run)); $this->em->flush(); }
[ "public", "function", "onUpdatedProposeUpdateTask", "(", ")", "{", "/* @var $task Task */", "$", "task", "=", "$", "this", "->", "em", "->", "getRepository", "(", "'AnimeDbAppBundle:Task'", ")", "->", "findOneBy", "(", "[", "'command'", "=>", "'animedb:propose-update'", "]", ")", ";", "$", "next_run", "=", "new", "\\", "DateTime", "(", ")", ";", "$", "next_run", "->", "modify", "(", "sprintf", "(", "'+%s seconds 01:00:00'", ",", "ProposeUpdateCommand", "::", "INERVAL_UPDATE", ")", ")", ";", "$", "this", "->", "em", "->", "persist", "(", "$", "task", "->", "setNextRun", "(", "$", "next_run", ")", ")", ";", "$", "this", "->", "em", "->", "flush", "(", ")", ";", "}" ]
Update next run date for the propose update task.
[ "Update", "next", "run", "date", "for", "the", "propose", "update", "task", "." ]
train
https://github.com/anime-db/app-bundle/blob/ca3b342081719d41ba018792a75970cbb1f1fe22/src/Event/Listener/Project.php#L52-L64
stanislav-web/phalcon-ulogin
src/ULogin/Init.php
Init.setProviders
public function setProviders($providers) { $array = Parser::map($providers); // collection data if (empty($array['required']) === false) { $this->requiredProviders = implode(',', $array['required']); } if (empty($array['hidden']) === false) { $this->hiddenProviders = implode(',', $array['hidden']); } return $this; }
php
public function setProviders($providers) { $array = Parser::map($providers); // collection data if (empty($array['required']) === false) { $this->requiredProviders = implode(',', $array['required']); } if (empty($array['hidden']) === false) { $this->hiddenProviders = implode(',', $array['hidden']); } return $this; }
[ "public", "function", "setProviders", "(", "$", "providers", ")", "{", "$", "array", "=", "Parser", "::", "map", "(", "$", "providers", ")", ";", "// collection data", "if", "(", "empty", "(", "$", "array", "[", "'required'", "]", ")", "===", "false", ")", "{", "$", "this", "->", "requiredProviders", "=", "implode", "(", "','", ",", "$", "array", "[", "'required'", "]", ")", ";", "}", "if", "(", "empty", "(", "$", "array", "[", "'hidden'", "]", ")", "===", "false", ")", "{", "$", "this", "->", "hiddenProviders", "=", "implode", "(", "','", ",", "$", "array", "[", "'hidden'", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Allows you to add authentication providers in the list of available. @param mixed $providers as ('provider' => true, 'provider' => false) or string separated by comma @example <code> $this->setProviders([ 'vkontakte' => true, 'odnoklassniki' => true, 'mailru' => true, 'facebook' => true, 'twitter' => false, // in drop down 'google' => false, // in drop down 'yandex' => false, // in drop down 'livejournal' => false, // in drop down 'openid' => false // in drop down ]); $this->setProviders('vkontakte=true,odnoklassniki=true,mailru=true,openid=false'); </code> @return Init
[ "Allows", "you", "to", "add", "authentication", "providers", "in", "the", "list", "of", "available", "." ]
train
https://github.com/stanislav-web/phalcon-ulogin/blob/0cea8510a244ebb9b1333085b325a283e4fb9f2f/src/ULogin/Init.php#L129-L143
stanislav-web/phalcon-ulogin
src/ULogin/Init.php
Init.setFields
public function setFields($fields) { if (empty($fields) === false) { if (is_array($fields) === true) { $this->requiredFields = implode(',', $fields); } else { $this->requiredFields = $fields; } } return $this; }
php
public function setFields($fields) { if (empty($fields) === false) { if (is_array($fields) === true) { $this->requiredFields = implode(',', $fields); } else { $this->requiredFields = $fields; } } return $this; }
[ "public", "function", "setFields", "(", "$", "fields", ")", "{", "if", "(", "empty", "(", "$", "fields", ")", "===", "false", ")", "{", "if", "(", "is_array", "(", "$", "fields", ")", "===", "true", ")", "{", "$", "this", "->", "requiredFields", "=", "implode", "(", "','", ",", "$", "fields", ")", ";", "}", "else", "{", "$", "this", "->", "requiredFields", "=", "$", "fields", ";", "}", "}", "return", "$", "this", ";", "}" ]
Allows you to add to the list of fields requested for the provider's authorization. @param mixed $fields as ('field1', 'field2', ...) or string separated by comma @example <code> $this->setFields([ 'first_name', 'last_name', 'photo' ]); $this->setFields('first_name,last_name,photo'); </code> @return Init
[ "Allows", "you", "to", "add", "to", "the", "list", "of", "fields", "requested", "for", "the", "provider", "s", "authorization", "." ]
train
https://github.com/stanislav-web/phalcon-ulogin/blob/0cea8510a244ebb9b1333085b325a283e4fb9f2f/src/ULogin/Init.php#L160-L174
stanislav-web/phalcon-ulogin
src/ULogin/Init.php
Init.setOptional
public function setOptional($fields) { if (empty($fields) === false) { if (is_array($fields) === true) { $this->optionalFields = implode(',', $fields); } else { $this->optionalFields = $fields; } } return $this; }
php
public function setOptional($fields) { if (empty($fields) === false) { if (is_array($fields) === true) { $this->optionalFields = implode(',', $fields); } else { $this->optionalFields = $fields; } } return $this; }
[ "public", "function", "setOptional", "(", "$", "fields", ")", "{", "if", "(", "empty", "(", "$", "fields", ")", "===", "false", ")", "{", "if", "(", "is_array", "(", "$", "fields", ")", "===", "true", ")", "{", "$", "this", "->", "optionalFields", "=", "implode", "(", "','", ",", "$", "fields", ")", ";", "}", "else", "{", "$", "this", "->", "optionalFields", "=", "$", "fields", ";", "}", "}", "return", "$", "this", ";", "}" ]
Allows you to add to the list of optionals fields. @param mixed $fields as ('field1', 'field2', ...) or string separated by comma @example <code> $this->setOptional([ 'bday', 'city', 'sex' ]); $this->setOptional('bday,city,sex'); </code> @return Init
[ "Allows", "you", "to", "add", "to", "the", "list", "of", "optionals", "fields", "." ]
train
https://github.com/stanislav-web/phalcon-ulogin/blob/0cea8510a244ebb9b1333085b325a283e4fb9f2f/src/ULogin/Init.php#L191-L206
stanislav-web/phalcon-ulogin
src/ULogin/Init.php
Init.setType
public function setType($type) { if(is_array($type) === true) { $type = $type[key($type)]; } $this->types = array_flip($this->types); if (isset($this->types[$type]) === true) { $this->widget = $type; } return $this; }
php
public function setType($type) { if(is_array($type) === true) { $type = $type[key($type)]; } $this->types = array_flip($this->types); if (isset($this->types[$type]) === true) { $this->widget = $type; } return $this; }
[ "public", "function", "setType", "(", "$", "type", ")", "{", "if", "(", "is_array", "(", "$", "type", ")", "===", "true", ")", "{", "$", "type", "=", "$", "type", "[", "key", "(", "$", "type", ")", "]", ";", "}", "$", "this", "->", "types", "=", "array_flip", "(", "$", "this", "->", "types", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "types", "[", "$", "type", "]", ")", "===", "true", ")", "{", "$", "this", "->", "widget", "=", "$", "type", ";", "}", "return", "$", "this", ";", "}" ]
Lets you specify the widget type. Must match the variable `types` @param $type @example <code> $this->setType('small'); </code> @return Init
[ "Lets", "you", "specify", "the", "widget", "type", ".", "Must", "match", "the", "variable", "types" ]
train
https://github.com/stanislav-web/phalcon-ulogin/blob/0cea8510a244ebb9b1333085b325a283e4fb9f2f/src/ULogin/Init.php#L217-L231
stanislav-web/phalcon-ulogin
src/ULogin/Init.php
Init.setUrl
public function setUrl($url = '') { if(is_array($url) === true) { $url = $url[key($url)]; } $request = new Request(); if (empty($url) === true) { $this->url = $request->getScheme() . '://' . $request->getHttpHost() . (new Router())->getRewriteUri(); } else { $this->url = $request->getScheme() . '://' . $request->getHttpHost() . $url; } return $this; }
php
public function setUrl($url = '') { if(is_array($url) === true) { $url = $url[key($url)]; } $request = new Request(); if (empty($url) === true) { $this->url = $request->getScheme() . '://' . $request->getHttpHost() . (new Router())->getRewriteUri(); } else { $this->url = $request->getScheme() . '://' . $request->getHttpHost() . $url; } return $this; }
[ "public", "function", "setUrl", "(", "$", "url", "=", "''", ")", "{", "if", "(", "is_array", "(", "$", "url", ")", "===", "true", ")", "{", "$", "url", "=", "$", "url", "[", "key", "(", "$", "url", ")", "]", ";", "}", "$", "request", "=", "new", "Request", "(", ")", ";", "if", "(", "empty", "(", "$", "url", ")", "===", "true", ")", "{", "$", "this", "->", "url", "=", "$", "request", "->", "getScheme", "(", ")", ".", "'://'", ".", "$", "request", "->", "getHttpHost", "(", ")", ".", "(", "new", "Router", "(", ")", ")", "->", "getRewriteUri", "(", ")", ";", "}", "else", "{", "$", "this", "->", "url", "=", "$", "request", "->", "getScheme", "(", ")", ".", "'://'", ".", "$", "request", "->", "getHttpHost", "(", ")", ".", "$", "url", ";", "}", "return", "$", "this", ";", "}" ]
Lets you specify the callback url to redirect to when authorizing the page is reloaded. If the url is not specified and is used to redirect the authorization, the authorization after the current page just updated @param string $url page that will be implemented to redirect after login (accept QUERY_STRING) @return $this
[ "Lets", "you", "specify", "the", "callback", "url", "to", "redirect", "to", "when", "authorizing", "the", "page", "is", "reloaded", ".", "If", "the", "url", "is", "not", "specified", "and", "is", "used", "to", "redirect", "the", "authorization", "the", "authorization", "after", "the", "current", "page", "just", "updated" ]
train
https://github.com/stanislav-web/phalcon-ulogin/blob/0cea8510a244ebb9b1333085b325a283e4fb9f2f/src/ULogin/Init.php#L241-L257
stanislav-web/phalcon-ulogin
src/ULogin/Init.php
Init.destroyUserData
private function destroyUserData() { if (is_array($this->user) === true && isset($this->user["error"]) === true ) { $this->user = false; return true; } return false; }
php
private function destroyUserData() { if (is_array($this->user) === true && isset($this->user["error"]) === true ) { $this->user = false; return true; } return false; }
[ "private", "function", "destroyUserData", "(", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "user", ")", "===", "true", "&&", "isset", "(", "$", "this", "->", "user", "[", "\"error\"", "]", ")", "===", "true", ")", "{", "$", "this", "->", "user", "=", "false", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Destroy user data @return bool
[ "Destroy", "user", "data" ]
train
https://github.com/stanislav-web/phalcon-ulogin/blob/0cea8510a244ebb9b1333085b325a283e4fb9f2f/src/ULogin/Init.php#L264-L274
stanislav-web/phalcon-ulogin
src/ULogin/Init.php
Init.getToken
public function getToken() { $request = new Request(); if ($request->isPost() === true) { $this->token = $request->getPost('token', null, false); } else { $this->token = $request->getQuery('token', null, false); } return $this->token; }
php
public function getToken() { $request = new Request(); if ($request->isPost() === true) { $this->token = $request->getPost('token', null, false); } else { $this->token = $request->getQuery('token', null, false); } return $this->token; }
[ "public", "function", "getToken", "(", ")", "{", "$", "request", "=", "new", "Request", "(", ")", ";", "if", "(", "$", "request", "->", "isPost", "(", ")", "===", "true", ")", "{", "$", "this", "->", "token", "=", "$", "request", "->", "getPost", "(", "'token'", ",", "null", ",", "false", ")", ";", "}", "else", "{", "$", "this", "->", "token", "=", "$", "request", "->", "getQuery", "(", "'token'", ",", "null", ",", "false", ")", ";", "}", "return", "$", "this", "->", "token", ";", "}" ]
Reads the parameters passed to the script, and selects the authorization key ULogin @return bool|mixed
[ "Reads", "the", "parameters", "passed", "to", "the", "script", "and", "selects", "the", "authorization", "key", "ULogin" ]
train
https://github.com/stanislav-web/phalcon-ulogin/blob/0cea8510a244ebb9b1333085b325a283e4fb9f2f/src/ULogin/Init.php#L281-L293
stanislav-web/phalcon-ulogin
src/ULogin/Init.php
Init.getUser
public function getUser() { // destroy previous content $this->destroyUserData(); if ($this->user === false) { // get user $url = 'http://ulogin.ru/token.php?token=' . $this->getToken() . '&host=' . (new Request())->getHttpHost(); $content = file_get_contents($url); $this->user = json_decode($content, true); // if use has error , destroy user data if ($this->destroyUserData() === true) { $this->logout(); } } return $this->user; }
php
public function getUser() { // destroy previous content $this->destroyUserData(); if ($this->user === false) { // get user $url = 'http://ulogin.ru/token.php?token=' . $this->getToken() . '&host=' . (new Request())->getHttpHost(); $content = file_get_contents($url); $this->user = json_decode($content, true); // if use has error , destroy user data if ($this->destroyUserData() === true) { $this->logout(); } } return $this->user; }
[ "public", "function", "getUser", "(", ")", "{", "// destroy previous content", "$", "this", "->", "destroyUserData", "(", ")", ";", "if", "(", "$", "this", "->", "user", "===", "false", ")", "{", "// get user", "$", "url", "=", "'http://ulogin.ru/token.php?token='", ".", "$", "this", "->", "getToken", "(", ")", ".", "'&host='", ".", "(", "new", "Request", "(", ")", ")", "->", "getHttpHost", "(", ")", ";", "$", "content", "=", "file_get_contents", "(", "$", "url", ")", ";", "$", "this", "->", "user", "=", "json_decode", "(", "$", "content", ",", "true", ")", ";", "// if use has error , destroy user data", "if", "(", "$", "this", "->", "destroyUserData", "(", ")", "===", "true", ")", "{", "$", "this", "->", "logout", "(", ")", ";", "}", "}", "return", "$", "this", "->", "user", ";", "}" ]
Returns an associative array with the data about the user. Fields array described in the method setFields @example <code> $this->getUser(); </code> @return array|bool|mixed data provided by the ISP login
[ "Returns", "an", "associative", "array", "with", "the", "data", "about", "the", "user", ".", "Fields", "array", "described", "in", "the", "method", "setFields" ]
train
https://github.com/stanislav-web/phalcon-ulogin/blob/0cea8510a244ebb9b1333085b325a283e4fb9f2f/src/ULogin/Init.php#L305-L326
stanislav-web/phalcon-ulogin
src/ULogin/Init.php
Init.isAuthorised
public function isAuthorised() { if (is_array($this->user) === true && isset($this->user['error']) === false ) { return true; } return $this->getUser(); }
php
public function isAuthorised() { if (is_array($this->user) === true && isset($this->user['error']) === false ) { return true; } return $this->getUser(); }
[ "public", "function", "isAuthorised", "(", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "user", ")", "===", "true", "&&", "isset", "(", "$", "this", "->", "user", "[", "'error'", "]", ")", "===", "false", ")", "{", "return", "true", ";", "}", "return", "$", "this", "->", "getUser", "(", ")", ";", "}" ]
Checks whether logon @return array|bool|mixed
[ "Checks", "whether", "logon" ]
train
https://github.com/stanislav-web/phalcon-ulogin/blob/0cea8510a244ebb9b1333085b325a283e4fb9f2f/src/ULogin/Init.php#L333-L344
stanislav-web/phalcon-ulogin
src/ULogin/Init.php
Init.getForm
public function getForm() { $view = new View(); return $view->render(__DIR__ . '/../views/ulogin', [ 'widget' => $this->widget, 'fields' => $this->requiredFields, 'optional' => $this->optionalFields, 'providers' => $this->requiredProviders, 'hidden' => $this->hiddenProviders, 'url' => $this->url ]); }
php
public function getForm() { $view = new View(); return $view->render(__DIR__ . '/../views/ulogin', [ 'widget' => $this->widget, 'fields' => $this->requiredFields, 'optional' => $this->optionalFields, 'providers' => $this->requiredProviders, 'hidden' => $this->hiddenProviders, 'url' => $this->url ]); }
[ "public", "function", "getForm", "(", ")", "{", "$", "view", "=", "new", "View", "(", ")", ";", "return", "$", "view", "->", "render", "(", "__DIR__", ".", "'/../views/ulogin'", ",", "[", "'widget'", "=>", "$", "this", "->", "widget", ",", "'fields'", "=>", "$", "this", "->", "requiredFields", ",", "'optional'", "=>", "$", "this", "->", "optionalFields", ",", "'providers'", "=>", "$", "this", "->", "requiredProviders", ",", "'hidden'", "=>", "$", "this", "->", "hiddenProviders", ",", "'url'", "=>", "$", "this", "->", "url", "]", ")", ";", "}" ]
Returns the html-form widget @return View
[ "Returns", "the", "html", "-", "form", "widget" ]
train
https://github.com/stanislav-web/phalcon-ulogin/blob/0cea8510a244ebb9b1333085b325a283e4fb9f2f/src/ULogin/Init.php#L366-L380
jfusion/org.jfusion.framework
src/Installer/Installer.php
Installer.setOverwrite
public function setOverwrite($state = false) { $tmp = $this->overwrite; if ($state) { $this->overwrite = true; } else { $this->overwrite = false; } return $tmp; }
php
public function setOverwrite($state = false) { $tmp = $this->overwrite; if ($state) { $this->overwrite = true; } else { $this->overwrite = false; } return $tmp; }
[ "public", "function", "setOverwrite", "(", "$", "state", "=", "false", ")", "{", "$", "tmp", "=", "$", "this", "->", "overwrite", ";", "if", "(", "$", "state", ")", "{", "$", "this", "->", "overwrite", "=", "true", ";", "}", "else", "{", "$", "this", "->", "overwrite", "=", "false", ";", "}", "return", "$", "tmp", ";", "}" ]
Set the allow overwrite switch @param boolean $state Overwrite switch state @return boolean True it state is set, false if it is not @since 3.1
[ "Set", "the", "allow", "overwrite", "switch" ]
train
https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Installer/Installer.php#L125-L139
jfusion/org.jfusion.framework
src/Installer/Installer.php
Installer.setUpgrade
public function setUpgrade($state = false) { $tmp = $this->upgrade; if ($state) { $this->upgrade = true; } else { $this->upgrade = false; } return $tmp; }
php
public function setUpgrade($state = false) { $tmp = $this->upgrade; if ($state) { $this->upgrade = true; } else { $this->upgrade = false; } return $tmp; }
[ "public", "function", "setUpgrade", "(", "$", "state", "=", "false", ")", "{", "$", "tmp", "=", "$", "this", "->", "upgrade", ";", "if", "(", "$", "state", ")", "{", "$", "this", "->", "upgrade", "=", "true", ";", "}", "else", "{", "$", "this", "->", "upgrade", "=", "false", ";", "}", "return", "$", "tmp", ";", "}" ]
Set the upgrade switch @param boolean $state Upgrade switch state @return boolean True if upgrade, false otherwise @since 3.1
[ "Set", "the", "upgrade", "switch" ]
train
https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Installer/Installer.php#L162-L176
jfusion/org.jfusion.framework
src/Installer/Installer.php
Installer.getPath
public function getPath($name, $default = null) { return (!empty($this->paths[$name])) ? $this->paths[$name] : $default; }
php
public function getPath($name, $default = null) { return (!empty($this->paths[$name])) ? $this->paths[$name] : $default; }
[ "public", "function", "getPath", "(", "$", "name", ",", "$", "default", "=", "null", ")", "{", "return", "(", "!", "empty", "(", "$", "this", "->", "paths", "[", "$", "name", "]", ")", ")", "?", "$", "this", "->", "paths", "[", "$", "name", "]", ":", "$", "default", ";", "}" ]
Get an installer path by name @param string $name Path name @param string $default Default value @return string Path @since 3.1
[ "Get", "an", "installer", "path", "by", "name" ]
train
https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Installer/Installer.php#L188-L191
jfusion/org.jfusion.framework
src/Installer/Installer.php
Installer.abort
public function abort($msg = null, $type = null) { $retval = true; $step = array_pop($this->stepStack); // Raise abort warning if ($msg) { $this->log(LogLevel::WARNING, $msg); } while ($step != null) { switch ($step['type']) { case 'file': // Remove the file $stepval = File::delete($step['path']); break; case 'folder': // Remove the folder $stepval = File::delete($step['path']); break; default: $stepval = false; break; } // Only set the return value if it is false if ($stepval === false) { $retval = false; } // Get the next step and continue $step = array_pop($this->stepStack); } $debug = Config::get()->get('debug'); if ($debug) { throw new RuntimeException('Installation unexpectedly terminated: ' . $msg, 500); } return $retval; }
php
public function abort($msg = null, $type = null) { $retval = true; $step = array_pop($this->stepStack); // Raise abort warning if ($msg) { $this->log(LogLevel::WARNING, $msg); } while ($step != null) { switch ($step['type']) { case 'file': // Remove the file $stepval = File::delete($step['path']); break; case 'folder': // Remove the folder $stepval = File::delete($step['path']); break; default: $stepval = false; break; } // Only set the return value if it is false if ($stepval === false) { $retval = false; } // Get the next step and continue $step = array_pop($this->stepStack); } $debug = Config::get()->get('debug'); if ($debug) { throw new RuntimeException('Installation unexpectedly terminated: ' . $msg, 500); } return $retval; }
[ "public", "function", "abort", "(", "$", "msg", "=", "null", ",", "$", "type", "=", "null", ")", "{", "$", "retval", "=", "true", ";", "$", "step", "=", "array_pop", "(", "$", "this", "->", "stepStack", ")", ";", "// Raise abort warning", "if", "(", "$", "msg", ")", "{", "$", "this", "->", "log", "(", "LogLevel", "::", "WARNING", ",", "$", "msg", ")", ";", "}", "while", "(", "$", "step", "!=", "null", ")", "{", "switch", "(", "$", "step", "[", "'type'", "]", ")", "{", "case", "'file'", ":", "// Remove the file", "$", "stepval", "=", "File", "::", "delete", "(", "$", "step", "[", "'path'", "]", ")", ";", "break", ";", "case", "'folder'", ":", "// Remove the folder", "$", "stepval", "=", "File", "::", "delete", "(", "$", "step", "[", "'path'", "]", ")", ";", "break", ";", "default", ":", "$", "stepval", "=", "false", ";", "break", ";", "}", "// Only set the return value if it is false", "if", "(", "$", "stepval", "===", "false", ")", "{", "$", "retval", "=", "false", ";", "}", "// Get the next step and continue", "$", "step", "=", "array_pop", "(", "$", "this", "->", "stepStack", ")", ";", "}", "$", "debug", "=", "Config", "::", "get", "(", ")", "->", "get", "(", "'debug'", ")", ";", "if", "(", "$", "debug", ")", "{", "throw", "new", "RuntimeException", "(", "'Installation unexpectedly terminated: '", ".", "$", "msg", ",", "500", ")", ";", "}", "return", "$", "retval", ";", "}" ]
Installation abort method @param string $msg Abort message from the installer @param string $type Package type if defined @return boolean True if successful @since 3.1 @throws RuntimeException
[ "Installation", "abort", "method" ]
train
https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Installer/Installer.php#L233-L279
jfusion/org.jfusion.framework
src/Installer/Installer.php
Installer.parseFiles
public function parseFiles(SimpleXMLElement $element, $cid = 0, $oldFiles = null, $oldMD5 = null) { // Get the array of file nodes to process; we checked whether this had children above. if (!$element || !$element->children()->count()) { // Either the tag does not exist or has no children (hence no files to process) therefore we return zero files processed. return 0; } $copyfiles = array(); /* * Here we set the folder we are going to remove the files from. */ $pathname = 'extension_root'; $destination = $this->getPath($pathname); /* * Here we set the folder we are going to copy the files from. * * Does the element have a folder attribute? * * If so this indicates that the files are in a subdirectory of the source * folder and we should append the folder attribute to the source path when * copying files. */ $folder = (string) $element->attributes()->folder; if ($folder && file_exists($this->getPath('source') . '/' . $folder)) { $source = $this->getPath('source') . '/' . $folder; } else { $source = $this->getPath('source'); } // Work out what files have been deleted if ($oldFiles && ($oldFiles instanceof SimpleXMLElement)) { $oldEntries = $oldFiles->children(); if ($oldEntries->count()) { $deletions = $this->findDeletedFiles($oldEntries, $element->children()); foreach ($deletions['folders'] as $deleted_folder) { Folder::delete($destination . '/' . $deleted_folder); } foreach ($deletions['files'] as $deleted_file) { File::delete($destination . '/' . $deleted_file); } } } $path = array(); // Copy the MD5SUMS file if it exists if (file_exists($source . '/MD5SUMS')) { $path['src'] = $source . '/MD5SUMS'; $path['dest'] = $destination . '/MD5SUMS'; $path['type'] = 'file'; $copyfiles[] = $path; } // Process each file in the $files array (children of $tagName). /** * @ignore * @var SimpleXMLElement $file */ foreach ($element->children() as $file) { $path['src'] = $source . '/' . $file; $path['dest'] = $destination . '/' . $file; // Is this path a file or folder? $path['type'] = ($file->getName() == 'folder') ? 'folder' : 'file'; /* * Before we can add a file to the copyfiles array we need to ensure * that the folder we are copying our file to exits and if it doesn't, * we need to create it. */ if (basename($path['dest']) != $path['dest']) { $newdir = dirname($path['dest']); if (!Folder::create($newdir)) { $this->log(LogLevel::WARNING, Text::sprintf('JLIB_INSTALLER_ERROR_CREATE_DIRECTORY', $newdir)); return false; } } // Add the file to the copyfiles array $copyfiles[] = $path; } return $this->copyFiles($copyfiles); }
php
public function parseFiles(SimpleXMLElement $element, $cid = 0, $oldFiles = null, $oldMD5 = null) { // Get the array of file nodes to process; we checked whether this had children above. if (!$element || !$element->children()->count()) { // Either the tag does not exist or has no children (hence no files to process) therefore we return zero files processed. return 0; } $copyfiles = array(); /* * Here we set the folder we are going to remove the files from. */ $pathname = 'extension_root'; $destination = $this->getPath($pathname); /* * Here we set the folder we are going to copy the files from. * * Does the element have a folder attribute? * * If so this indicates that the files are in a subdirectory of the source * folder and we should append the folder attribute to the source path when * copying files. */ $folder = (string) $element->attributes()->folder; if ($folder && file_exists($this->getPath('source') . '/' . $folder)) { $source = $this->getPath('source') . '/' . $folder; } else { $source = $this->getPath('source'); } // Work out what files have been deleted if ($oldFiles && ($oldFiles instanceof SimpleXMLElement)) { $oldEntries = $oldFiles->children(); if ($oldEntries->count()) { $deletions = $this->findDeletedFiles($oldEntries, $element->children()); foreach ($deletions['folders'] as $deleted_folder) { Folder::delete($destination . '/' . $deleted_folder); } foreach ($deletions['files'] as $deleted_file) { File::delete($destination . '/' . $deleted_file); } } } $path = array(); // Copy the MD5SUMS file if it exists if (file_exists($source . '/MD5SUMS')) { $path['src'] = $source . '/MD5SUMS'; $path['dest'] = $destination . '/MD5SUMS'; $path['type'] = 'file'; $copyfiles[] = $path; } // Process each file in the $files array (children of $tagName). /** * @ignore * @var SimpleXMLElement $file */ foreach ($element->children() as $file) { $path['src'] = $source . '/' . $file; $path['dest'] = $destination . '/' . $file; // Is this path a file or folder? $path['type'] = ($file->getName() == 'folder') ? 'folder' : 'file'; /* * Before we can add a file to the copyfiles array we need to ensure * that the folder we are copying our file to exits and if it doesn't, * we need to create it. */ if (basename($path['dest']) != $path['dest']) { $newdir = dirname($path['dest']); if (!Folder::create($newdir)) { $this->log(LogLevel::WARNING, Text::sprintf('JLIB_INSTALLER_ERROR_CREATE_DIRECTORY', $newdir)); return false; } } // Add the file to the copyfiles array $copyfiles[] = $path; } return $this->copyFiles($copyfiles); }
[ "public", "function", "parseFiles", "(", "SimpleXMLElement", "$", "element", ",", "$", "cid", "=", "0", ",", "$", "oldFiles", "=", "null", ",", "$", "oldMD5", "=", "null", ")", "{", "// Get the array of file nodes to process; we checked whether this had children above.", "if", "(", "!", "$", "element", "||", "!", "$", "element", "->", "children", "(", ")", "->", "count", "(", ")", ")", "{", "// Either the tag does not exist or has no children (hence no files to process) therefore we return zero files processed.", "return", "0", ";", "}", "$", "copyfiles", "=", "array", "(", ")", ";", "/*\n\t\t * Here we set the folder we are going to remove the files from.\n\t\t */", "$", "pathname", "=", "'extension_root'", ";", "$", "destination", "=", "$", "this", "->", "getPath", "(", "$", "pathname", ")", ";", "/*\n\t\t * Here we set the folder we are going to copy the files from.\n\t\t *\n\t\t * Does the element have a folder attribute?\n\t\t *\n\t\t * If so this indicates that the files are in a subdirectory of the source\n\t\t * folder and we should append the folder attribute to the source path when\n\t\t * copying files.\n\t\t */", "$", "folder", "=", "(", "string", ")", "$", "element", "->", "attributes", "(", ")", "->", "folder", ";", "if", "(", "$", "folder", "&&", "file_exists", "(", "$", "this", "->", "getPath", "(", "'source'", ")", ".", "'/'", ".", "$", "folder", ")", ")", "{", "$", "source", "=", "$", "this", "->", "getPath", "(", "'source'", ")", ".", "'/'", ".", "$", "folder", ";", "}", "else", "{", "$", "source", "=", "$", "this", "->", "getPath", "(", "'source'", ")", ";", "}", "// Work out what files have been deleted", "if", "(", "$", "oldFiles", "&&", "(", "$", "oldFiles", "instanceof", "SimpleXMLElement", ")", ")", "{", "$", "oldEntries", "=", "$", "oldFiles", "->", "children", "(", ")", ";", "if", "(", "$", "oldEntries", "->", "count", "(", ")", ")", "{", "$", "deletions", "=", "$", "this", "->", "findDeletedFiles", "(", "$", "oldEntries", ",", "$", "element", "->", "children", "(", ")", ")", ";", "foreach", "(", "$", "deletions", "[", "'folders'", "]", "as", "$", "deleted_folder", ")", "{", "Folder", "::", "delete", "(", "$", "destination", ".", "'/'", ".", "$", "deleted_folder", ")", ";", "}", "foreach", "(", "$", "deletions", "[", "'files'", "]", "as", "$", "deleted_file", ")", "{", "File", "::", "delete", "(", "$", "destination", ".", "'/'", ".", "$", "deleted_file", ")", ";", "}", "}", "}", "$", "path", "=", "array", "(", ")", ";", "// Copy the MD5SUMS file if it exists", "if", "(", "file_exists", "(", "$", "source", ".", "'/MD5SUMS'", ")", ")", "{", "$", "path", "[", "'src'", "]", "=", "$", "source", ".", "'/MD5SUMS'", ";", "$", "path", "[", "'dest'", "]", "=", "$", "destination", ".", "'/MD5SUMS'", ";", "$", "path", "[", "'type'", "]", "=", "'file'", ";", "$", "copyfiles", "[", "]", "=", "$", "path", ";", "}", "// Process each file in the $files array (children of $tagName).", "/**\n\t\t * @ignore\n\t\t * @var SimpleXMLElement $file\n\t\t */", "foreach", "(", "$", "element", "->", "children", "(", ")", "as", "$", "file", ")", "{", "$", "path", "[", "'src'", "]", "=", "$", "source", ".", "'/'", ".", "$", "file", ";", "$", "path", "[", "'dest'", "]", "=", "$", "destination", ".", "'/'", ".", "$", "file", ";", "// Is this path a file or folder?", "$", "path", "[", "'type'", "]", "=", "(", "$", "file", "->", "getName", "(", ")", "==", "'folder'", ")", "?", "'folder'", ":", "'file'", ";", "/*\n\t\t\t * Before we can add a file to the copyfiles array we need to ensure\n\t\t\t * that the folder we are copying our file to exits and if it doesn't,\n\t\t\t * we need to create it.\n\t\t\t */", "if", "(", "basename", "(", "$", "path", "[", "'dest'", "]", ")", "!=", "$", "path", "[", "'dest'", "]", ")", "{", "$", "newdir", "=", "dirname", "(", "$", "path", "[", "'dest'", "]", ")", ";", "if", "(", "!", "Folder", "::", "create", "(", "$", "newdir", ")", ")", "{", "$", "this", "->", "log", "(", "LogLevel", "::", "WARNING", ",", "Text", "::", "sprintf", "(", "'JLIB_INSTALLER_ERROR_CREATE_DIRECTORY'", ",", "$", "newdir", ")", ")", ";", "return", "false", ";", "}", "}", "// Add the file to the copyfiles array", "$", "copyfiles", "[", "]", "=", "$", "path", ";", "}", "return", "$", "this", "->", "copyFiles", "(", "$", "copyfiles", ")", ";", "}" ]
Method to parse through a files element of the installation manifest and take appropriate action. @param SimpleXMLElement $element The XML node to process @param integer $cid Application ID of application to install to @param array $oldFiles List of old files (SimpleXMLElement's) @param array $oldMD5 List of old MD5 sums (indexed by filename with value as MD5) @return boolean True on success @since 3.1
[ "Method", "to", "parse", "through", "a", "files", "element", "of", "the", "installation", "manifest", "and", "take", "appropriate", "action", "." ]
train
https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Installer/Installer.php#L295-L400
jfusion/org.jfusion.framework
src/Installer/Installer.php
Installer.copyFiles
public function copyFiles($files, $overwrite = null) { /* * To allow for manual override on the overwriting flag, we check to see if * the $overwrite flag was set and is a boolean value. If not, use the object * allowOverwrite flag. */ if (is_null($overwrite) || !is_bool($overwrite)) { $overwrite = $this->overwrite; } /* * $files must be an array of filenames. Verify that it is an array with * at least one file to copy. */ if (is_array($files) && count($files) > 0) { foreach ($files as $file) { // Get the source and destination paths $filesource = Path::clean($file['src']); $filedest = Path::clean($file['dest']); $filetype = array_key_exists('type', $file) ? $file['type'] : 'file'; if (!file_exists($filesource)) { /* * The source file does not exist. Nothing to copy so set an error * and return false. */ $this->log(LogLevel::WARNING, Text::sprintf('JLIB_INSTALLER_ERROR_NO_FILE', $filesource)); return false; } elseif (($exists = file_exists($filedest)) && !$overwrite) { // It's okay if the manifest already exists if ($this->getPath('manifest') == $filesource) { continue; } // The destination file already exists and the overwrite flag is false. // Set an error and return false. $this->log(LogLevel::WARNING, Text::sprintf('JLIB_INSTALLER_ERROR_FILE_EXISTS', $filedest)); return false; } else { // Copy the folder or file to the new location. if ($filetype == 'folder') { if (!(Folder::copy($filesource, $filedest, null, $overwrite))) { $this->log(LogLevel::WARNING, Text::sprintf('JLIB_INSTALLER_ERROR_FAIL_COPY_FOLDER', $filesource, $filedest)); return false; } $step = array('type' => 'folder', 'path' => $filedest); } else { if (!(File::copy($filesource, $filedest, null))) { $this->log(LogLevel::WARNING, Text::sprintf('JLIB_INSTALLER_ERROR_FAIL_COPY_FILE', $filesource, $filedest)); // In 3.2, TinyMCE language handling changed. Display a special notice in case an older language pack is installed. if (strpos($filedest, 'media/editors/tinymce/jscripts/tiny_mce/langs')) { $this->log(LogLevel::WARNING, Text::_('JLIB_INSTALLER_NOT_ERROR')); } return false; } $step = array('type' => 'file', 'path' => $filedest); } /* * Since we copied a file/folder, we want to add it to the installation step stack so that * in case we have to roll back the installation we can remove the files copied. */ if (!$exists) { $this->stepStack[] = $step; } } } } else { // The $files variable was either not an array or an empty array return false; } return count($files); }
php
public function copyFiles($files, $overwrite = null) { /* * To allow for manual override on the overwriting flag, we check to see if * the $overwrite flag was set and is a boolean value. If not, use the object * allowOverwrite flag. */ if (is_null($overwrite) || !is_bool($overwrite)) { $overwrite = $this->overwrite; } /* * $files must be an array of filenames. Verify that it is an array with * at least one file to copy. */ if (is_array($files) && count($files) > 0) { foreach ($files as $file) { // Get the source and destination paths $filesource = Path::clean($file['src']); $filedest = Path::clean($file['dest']); $filetype = array_key_exists('type', $file) ? $file['type'] : 'file'; if (!file_exists($filesource)) { /* * The source file does not exist. Nothing to copy so set an error * and return false. */ $this->log(LogLevel::WARNING, Text::sprintf('JLIB_INSTALLER_ERROR_NO_FILE', $filesource)); return false; } elseif (($exists = file_exists($filedest)) && !$overwrite) { // It's okay if the manifest already exists if ($this->getPath('manifest') == $filesource) { continue; } // The destination file already exists and the overwrite flag is false. // Set an error and return false. $this->log(LogLevel::WARNING, Text::sprintf('JLIB_INSTALLER_ERROR_FILE_EXISTS', $filedest)); return false; } else { // Copy the folder or file to the new location. if ($filetype == 'folder') { if (!(Folder::copy($filesource, $filedest, null, $overwrite))) { $this->log(LogLevel::WARNING, Text::sprintf('JLIB_INSTALLER_ERROR_FAIL_COPY_FOLDER', $filesource, $filedest)); return false; } $step = array('type' => 'folder', 'path' => $filedest); } else { if (!(File::copy($filesource, $filedest, null))) { $this->log(LogLevel::WARNING, Text::sprintf('JLIB_INSTALLER_ERROR_FAIL_COPY_FILE', $filesource, $filedest)); // In 3.2, TinyMCE language handling changed. Display a special notice in case an older language pack is installed. if (strpos($filedest, 'media/editors/tinymce/jscripts/tiny_mce/langs')) { $this->log(LogLevel::WARNING, Text::_('JLIB_INSTALLER_NOT_ERROR')); } return false; } $step = array('type' => 'file', 'path' => $filedest); } /* * Since we copied a file/folder, we want to add it to the installation step stack so that * in case we have to roll back the installation we can remove the files copied. */ if (!$exists) { $this->stepStack[] = $step; } } } } else { // The $files variable was either not an array or an empty array return false; } return count($files); }
[ "public", "function", "copyFiles", "(", "$", "files", ",", "$", "overwrite", "=", "null", ")", "{", "/*\n\t\t * To allow for manual override on the overwriting flag, we check to see if\n\t\t * the $overwrite flag was set and is a boolean value. If not, use the object\n\t\t * allowOverwrite flag.\n\t\t */", "if", "(", "is_null", "(", "$", "overwrite", ")", "||", "!", "is_bool", "(", "$", "overwrite", ")", ")", "{", "$", "overwrite", "=", "$", "this", "->", "overwrite", ";", "}", "/*\n\t\t * $files must be an array of filenames. Verify that it is an array with\n\t\t * at least one file to copy.\n\t\t */", "if", "(", "is_array", "(", "$", "files", ")", "&&", "count", "(", "$", "files", ")", ">", "0", ")", "{", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "// Get the source and destination paths", "$", "filesource", "=", "Path", "::", "clean", "(", "$", "file", "[", "'src'", "]", ")", ";", "$", "filedest", "=", "Path", "::", "clean", "(", "$", "file", "[", "'dest'", "]", ")", ";", "$", "filetype", "=", "array_key_exists", "(", "'type'", ",", "$", "file", ")", "?", "$", "file", "[", "'type'", "]", ":", "'file'", ";", "if", "(", "!", "file_exists", "(", "$", "filesource", ")", ")", "{", "/*\n\t\t\t\t\t * The source file does not exist. Nothing to copy so set an error\n\t\t\t\t\t * and return false.\n\t\t\t\t\t */", "$", "this", "->", "log", "(", "LogLevel", "::", "WARNING", ",", "Text", "::", "sprintf", "(", "'JLIB_INSTALLER_ERROR_NO_FILE'", ",", "$", "filesource", ")", ")", ";", "return", "false", ";", "}", "elseif", "(", "(", "$", "exists", "=", "file_exists", "(", "$", "filedest", ")", ")", "&&", "!", "$", "overwrite", ")", "{", "// It's okay if the manifest already exists", "if", "(", "$", "this", "->", "getPath", "(", "'manifest'", ")", "==", "$", "filesource", ")", "{", "continue", ";", "}", "// The destination file already exists and the overwrite flag is false.", "// Set an error and return false.", "$", "this", "->", "log", "(", "LogLevel", "::", "WARNING", ",", "Text", "::", "sprintf", "(", "'JLIB_INSTALLER_ERROR_FILE_EXISTS'", ",", "$", "filedest", ")", ")", ";", "return", "false", ";", "}", "else", "{", "// Copy the folder or file to the new location.", "if", "(", "$", "filetype", "==", "'folder'", ")", "{", "if", "(", "!", "(", "Folder", "::", "copy", "(", "$", "filesource", ",", "$", "filedest", ",", "null", ",", "$", "overwrite", ")", ")", ")", "{", "$", "this", "->", "log", "(", "LogLevel", "::", "WARNING", ",", "Text", "::", "sprintf", "(", "'JLIB_INSTALLER_ERROR_FAIL_COPY_FOLDER'", ",", "$", "filesource", ",", "$", "filedest", ")", ")", ";", "return", "false", ";", "}", "$", "step", "=", "array", "(", "'type'", "=>", "'folder'", ",", "'path'", "=>", "$", "filedest", ")", ";", "}", "else", "{", "if", "(", "!", "(", "File", "::", "copy", "(", "$", "filesource", ",", "$", "filedest", ",", "null", ")", ")", ")", "{", "$", "this", "->", "log", "(", "LogLevel", "::", "WARNING", ",", "Text", "::", "sprintf", "(", "'JLIB_INSTALLER_ERROR_FAIL_COPY_FILE'", ",", "$", "filesource", ",", "$", "filedest", ")", ")", ";", "// In 3.2, TinyMCE language handling changed. Display a special notice in case an older language pack is installed.", "if", "(", "strpos", "(", "$", "filedest", ",", "'media/editors/tinymce/jscripts/tiny_mce/langs'", ")", ")", "{", "$", "this", "->", "log", "(", "LogLevel", "::", "WARNING", ",", "Text", "::", "_", "(", "'JLIB_INSTALLER_NOT_ERROR'", ")", ")", ";", "}", "return", "false", ";", "}", "$", "step", "=", "array", "(", "'type'", "=>", "'file'", ",", "'path'", "=>", "$", "filedest", ")", ";", "}", "/*\n\t\t\t\t\t * Since we copied a file/folder, we want to add it to the installation step stack so that\n\t\t\t\t\t * in case we have to roll back the installation we can remove the files copied.\n\t\t\t\t\t */", "if", "(", "!", "$", "exists", ")", "{", "$", "this", "->", "stepStack", "[", "]", "=", "$", "step", ";", "}", "}", "}", "}", "else", "{", "// The $files variable was either not an array or an empty array", "return", "false", ";", "}", "return", "count", "(", "$", "files", ")", ";", "}" ]
Copyfiles Copy files from source directory to the target directory @param array $files Array with filenames @param boolean $overwrite True if existing files can be replaced @return boolean True on success @since 3.1
[ "Copyfiles" ]
train
https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Installer/Installer.php#L414-L516
jfusion/org.jfusion.framework
src/Installer/Installer.php
Installer.findDeletedFiles
public function findDeletedFiles($old_files, $new_files) { // The magic find deleted files function! // The files that are new $files = array(); // The folders that are new $folders = array(); // The folders of the files that are new $containers = array(); // A list of files to delete $files_deleted = array(); // A list of folders to delete $folders_deleted = array(); /** * @ignore * @var SimpleXMLElement $file */ foreach ($new_files as $file) { switch ($file->getName()) { case 'folder': // Add any folders to the list $folders[] = (string) $file; // add any folders to the list break; case 'file': default: // Add any files to the list $files[] = (string) $file; // Now handle the folder part of the file to ensure we get any containers // Break up the parts of the directory $container_parts = explode('/', dirname((string) $file)); // Make sure this is clean and empty $container = ''; foreach ($container_parts as $part) { // Iterate through each part // Add a slash if its not empty if (!empty($container)) { $container .= '/'; } // Aappend the folder part $container .= $part; if (!in_array($container, $containers)) { // Add the container if it doesn't already exist $containers[] = $container; } } break; } } foreach ($old_files as $file) { switch ($file->getName()) { case 'folder': if (!in_array((string) $file, $folders)) { // See whether the folder exists in the new list if (!in_array((string) $file, $containers)) { // Check if the folder exists as a container in the new list // If it's not in the new list or a container then delete it $folders_deleted[] = (string) $file; } } break; case 'file': default: if (!in_array((string) $file, $files)) { // Look if the file exists in the new list if (!in_array(dirname((string) $file), $folders)) { // Look if the file is now potentially in a folder $files_deleted[] = (string) $file; // not in a folder, doesn't exist, wipe it out! } } break; } } return array('files' => $files_deleted, 'folders' => $folders_deleted); }
php
public function findDeletedFiles($old_files, $new_files) { // The magic find deleted files function! // The files that are new $files = array(); // The folders that are new $folders = array(); // The folders of the files that are new $containers = array(); // A list of files to delete $files_deleted = array(); // A list of folders to delete $folders_deleted = array(); /** * @ignore * @var SimpleXMLElement $file */ foreach ($new_files as $file) { switch ($file->getName()) { case 'folder': // Add any folders to the list $folders[] = (string) $file; // add any folders to the list break; case 'file': default: // Add any files to the list $files[] = (string) $file; // Now handle the folder part of the file to ensure we get any containers // Break up the parts of the directory $container_parts = explode('/', dirname((string) $file)); // Make sure this is clean and empty $container = ''; foreach ($container_parts as $part) { // Iterate through each part // Add a slash if its not empty if (!empty($container)) { $container .= '/'; } // Aappend the folder part $container .= $part; if (!in_array($container, $containers)) { // Add the container if it doesn't already exist $containers[] = $container; } } break; } } foreach ($old_files as $file) { switch ($file->getName()) { case 'folder': if (!in_array((string) $file, $folders)) { // See whether the folder exists in the new list if (!in_array((string) $file, $containers)) { // Check if the folder exists as a container in the new list // If it's not in the new list or a container then delete it $folders_deleted[] = (string) $file; } } break; case 'file': default: if (!in_array((string) $file, $files)) { // Look if the file exists in the new list if (!in_array(dirname((string) $file), $folders)) { // Look if the file is now potentially in a folder $files_deleted[] = (string) $file; // not in a folder, doesn't exist, wipe it out! } } break; } } return array('files' => $files_deleted, 'folders' => $folders_deleted); }
[ "public", "function", "findDeletedFiles", "(", "$", "old_files", ",", "$", "new_files", ")", "{", "// The magic find deleted files function!", "// The files that are new", "$", "files", "=", "array", "(", ")", ";", "// The folders that are new", "$", "folders", "=", "array", "(", ")", ";", "// The folders of the files that are new", "$", "containers", "=", "array", "(", ")", ";", "// A list of files to delete", "$", "files_deleted", "=", "array", "(", ")", ";", "// A list of folders to delete", "$", "folders_deleted", "=", "array", "(", ")", ";", "/**\n\t\t * @ignore\n\t\t * @var SimpleXMLElement $file\n\t\t */", "foreach", "(", "$", "new_files", "as", "$", "file", ")", "{", "switch", "(", "$", "file", "->", "getName", "(", ")", ")", "{", "case", "'folder'", ":", "// Add any folders to the list", "$", "folders", "[", "]", "=", "(", "string", ")", "$", "file", ";", "// add any folders to the list", "break", ";", "case", "'file'", ":", "default", ":", "// Add any files to the list", "$", "files", "[", "]", "=", "(", "string", ")", "$", "file", ";", "// Now handle the folder part of the file to ensure we get any containers", "// Break up the parts of the directory", "$", "container_parts", "=", "explode", "(", "'/'", ",", "dirname", "(", "(", "string", ")", "$", "file", ")", ")", ";", "// Make sure this is clean and empty", "$", "container", "=", "''", ";", "foreach", "(", "$", "container_parts", "as", "$", "part", ")", "{", "// Iterate through each part", "// Add a slash if its not empty", "if", "(", "!", "empty", "(", "$", "container", ")", ")", "{", "$", "container", ".=", "'/'", ";", "}", "// Aappend the folder part", "$", "container", ".=", "$", "part", ";", "if", "(", "!", "in_array", "(", "$", "container", ",", "$", "containers", ")", ")", "{", "// Add the container if it doesn't already exist", "$", "containers", "[", "]", "=", "$", "container", ";", "}", "}", "break", ";", "}", "}", "foreach", "(", "$", "old_files", "as", "$", "file", ")", "{", "switch", "(", "$", "file", "->", "getName", "(", ")", ")", "{", "case", "'folder'", ":", "if", "(", "!", "in_array", "(", "(", "string", ")", "$", "file", ",", "$", "folders", ")", ")", "{", "// See whether the folder exists in the new list", "if", "(", "!", "in_array", "(", "(", "string", ")", "$", "file", ",", "$", "containers", ")", ")", "{", "// Check if the folder exists as a container in the new list", "// If it's not in the new list or a container then delete it", "$", "folders_deleted", "[", "]", "=", "(", "string", ")", "$", "file", ";", "}", "}", "break", ";", "case", "'file'", ":", "default", ":", "if", "(", "!", "in_array", "(", "(", "string", ")", "$", "file", ",", "$", "files", ")", ")", "{", "// Look if the file exists in the new list", "if", "(", "!", "in_array", "(", "dirname", "(", "(", "string", ")", "$", "file", ")", ",", "$", "folders", ")", ")", "{", "// Look if the file is now potentially in a folder", "$", "files_deleted", "[", "]", "=", "(", "string", ")", "$", "file", ";", "// not in a folder, doesn't exist, wipe it out!", "}", "}", "break", ";", "}", "}", "return", "array", "(", "'files'", "=>", "$", "files_deleted", ",", "'folders'", "=>", "$", "folders_deleted", ")", ";", "}" ]
Compares two "files" entries to find deleted files/folders @param array[SimpleXMLElement] $old_files An array of SimpleXMLElement objects that are the old files @param array[SimpleXMLElement] $new_files An array of SimpleXMLElement objects that are the new files @return array An array with the delete files and folders in findDeletedFiles[files] and findDeletedFiles[folders] respectively @since 3.1
[ "Compares", "two", "files", "entries", "to", "find", "deleted", "files", "/", "folders" ]
train
https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Installer/Installer.php#L528-L626
Lansoweb/LosReCaptcha
src/Service/Request/ZendHttpClient.php
ZendHttpClient.send
public function send(Parameters $params) { $this->client->setUri(ReCaptcha::VERIFY_SERVER); $this->client->setRawBody($params->toQueryString()); $this->client->setEncType('application/x-www-form-urlencoded'); $result = $this->client->setMethod('POST')->send(); return $result ? $result->getBody() : null; }
php
public function send(Parameters $params) { $this->client->setUri(ReCaptcha::VERIFY_SERVER); $this->client->setRawBody($params->toQueryString()); $this->client->setEncType('application/x-www-form-urlencoded'); $result = $this->client->setMethod('POST')->send(); return $result ? $result->getBody() : null; }
[ "public", "function", "send", "(", "Parameters", "$", "params", ")", "{", "$", "this", "->", "client", "->", "setUri", "(", "ReCaptcha", "::", "VERIFY_SERVER", ")", ";", "$", "this", "->", "client", "->", "setRawBody", "(", "$", "params", "->", "toQueryString", "(", ")", ")", ";", "$", "this", "->", "client", "->", "setEncType", "(", "'application/x-www-form-urlencoded'", ")", ";", "$", "result", "=", "$", "this", "->", "client", "->", "setMethod", "(", "'POST'", ")", "->", "send", "(", ")", ";", "return", "$", "result", "?", "$", "result", "->", "getBody", "(", ")", ":", "null", ";", "}" ]
Submit ReCaptcha API request, return response body. @param Parameters $params ReCaptcha parameters @return string
[ "Submit", "ReCaptcha", "API", "request", "return", "response", "body", "." ]
train
https://github.com/Lansoweb/LosReCaptcha/blob/8df866995501db087c3850f97fd2b6547632e6ed/src/Service/Request/ZendHttpClient.php#L33-L40
Chill-project/Main
Entity/Address.php
Address.setPostcode
public function setPostcode(\Chill\MainBundle\Entity\PostalCode $postcode = null) { $this->postcode = $postcode; return $this; }
php
public function setPostcode(\Chill\MainBundle\Entity\PostalCode $postcode = null) { $this->postcode = $postcode; return $this; }
[ "public", "function", "setPostcode", "(", "\\", "Chill", "\\", "MainBundle", "\\", "Entity", "\\", "PostalCode", "$", "postcode", "=", "null", ")", "{", "$", "this", "->", "postcode", "=", "$", "postcode", ";", "return", "$", "this", ";", "}" ]
Set postcode @param \Chill\MainBundle\Entity\PostalCode $postcode @return Address
[ "Set", "postcode" ]
train
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Entity/Address.php#L107-L112
windwork/wf-mailer
lib/adapter/SMTP.php
SMTP.send
public function send($to, $subject, $message, $from = '', $cc = '', $bcc = '') { // 端口 $this->cfg['port'] = empty($this->cfg['port']) ? 25 : $this->cfg['port']; // SMTP发送邮件账号必须与发件人一致 $from = $this->cfg['user']; $to = \wf\mailer\Helper::emailEncode($to); $from = \wf\mailer\Helper::emailEncode($from); $subject = \wf\mailer\Helper::encode($subject); $message = chunk_split(base64_encode(str_replace("\n", "\r\n", str_replace("\r", "\n", str_replace("\r\n", "\n", str_replace("\n\r", "\r", $message)))))); $headers = "From: {$from}\r\n"; // 抄送 if($cc) { $cc = \wf\mailer\Helper::emailEncode($cc); $headers .= "Cc: {$cc}\r\n"; } // 密送 if($bcc) { $bcc = \wf\mailer\Helper::emailEncode($bcc); $headers .= "Bcc: {$bcc}\r\n"; } $headers .= "X-Priority: 3\r\n" . "X-Mailer: Windwork\r\n" . "MIME-Version: 1.0\r\n" . "Content-type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: base64\r\n"; if(!$fp = fsockopen($this->cfg['host'], $this->cfg['port'], $errno, $errstr, 30)) { throw new Exception("SMTP ({$this->cfg['host']}:{$this->cfg['port']}) CONNECT - Unable to connect to the SMTP server"); } stream_set_blocking($fp, true); $lastMessage = fgets($fp, 512); if(substr($lastMessage, 0, 3) != '220') { throw new Exception("SMTP {$this->cfg['host']}:{$this->cfg['port']} CONNECT - $lastMessage"); } fputs($fp, ($this->cfg['auth'] ? 'EHLO' : 'HELO')." windwork\r\n"); $lastMessage = fgets($fp, 512); if(substr($lastMessage, 0, 3) != 220 && substr($lastMessage, 0, 3) != 250) { throw new Exception("SMTP ({$this->cfg['host']}:{$this->cfg['port']}) HELO/EHLO - $lastMessage", 0); } while(1) { if(substr($lastMessage, 3, 1) != '-' || empty($lastMessage)) { break; } $lastMessage = fgets($fp, 512); } if($this->cfg['auth']) { fputs($fp, "AUTH LOGIN\r\n"); $lastMessage = fgets($fp, 512); if(substr($lastMessage, 0, 3) != 334) { throw new Exception("SMTP ({$this->cfg['host']}:{$this->cfg['port']}) AUTH LOGIN - $lastMessage", 0); } fputs($fp, base64_encode($this->cfg['user'])."\r\n"); $lastMessage = fgets($fp, 512); if(substr($lastMessage, 0, 3) != 334) { throw new Exception("SMTP ({$this->cfg['host']}:{$this->cfg['port']}) USERNAME - $lastMessage", 0); } fputs($fp, base64_encode($this->cfg['pass'])."\r\n"); $lastMessage = fgets($fp, 512); if(substr($lastMessage, 0, 3) != 235) { throw new Exception("SMTP ({$this->cfg['host']}:{$this->cfg['port']}) PASSWORD - $lastMessage", 0); } $emailFrom = $from; } fputs($fp, "MAIL FROM: <".preg_replace("/.*\\<(.+?)\\>.*/", "\\1", $from).">\r\n"); $lastMessage = fgets($fp, 512); if(substr($lastMessage, 0, 3) != 250) { fputs($fp, "MAIL FROM: <".preg_replace("/.*\\<(.+?)\\>.*/", "\\1", $from).">\r\n"); $lastMessage = fgets($fp, 512); if(substr($lastMessage, 0, 3) != 250) { throw new Exception("SMTP ({$this->cfg['host']}:{$this->cfg['port']}) MAIL FROM - $lastMessage", 0); } } fputs($fp, "RCPT TO: <".preg_replace("/.*\\<(.+?)\\>.*/", "\\1", $to).">\r\n"); $lastMessage = fgets($fp, 512); if(substr($lastMessage, 0, 3) != 250) { fputs($fp, "RCPT TO: <".preg_replace("/.*\\<(.+?)\\>.*/", "\\1", $to).">\r\n"); $lastMessage = fgets($fp, 512); throw new Exception("SMTP ({$this->cfg['host']}:{$this->cfg['port']}) RCPT TO - $lastMessage", 0); } fputs($fp, "DATA\r\n"); $lastMessage = fgets($fp, 512); if(substr($lastMessage, 0, 3) != 354) { throw new Exception("SMTP ({$this->cfg['host']}:{$this->cfg['port']}) DATA - $lastMessage", 0); } $headers .= 'Message-ID: <'.date('YmdHs').'.'.substr(md5($message.microtime()), 0, 6).rand(100000, 999999).'@'.@$_SERVER['HTTP_HOST'].">\r\n"; fputs($fp, "Date: ".date('r')."\r\n"); fputs($fp, "To: {$to}\r\n"); fputs($fp, "Subject: {$subject}\r\n"); fputs($fp, "{$headers}\r\n"); fputs($fp, "\r\n\r\n"); fputs($fp, "{$message}\r\n.\r\n"); $lastMessage = fgets($fp, 512); if(substr($lastMessage, 0, 3) != 250) { throw new Exception("SMTP ({$this->cfg['host']}:{$this->cfg['port']}) END - {$lastMessage}", 0); } fputs($fp, "QUIT\r\n"); return true; }
php
public function send($to, $subject, $message, $from = '', $cc = '', $bcc = '') { // 端口 $this->cfg['port'] = empty($this->cfg['port']) ? 25 : $this->cfg['port']; // SMTP发送邮件账号必须与发件人一致 $from = $this->cfg['user']; $to = \wf\mailer\Helper::emailEncode($to); $from = \wf\mailer\Helper::emailEncode($from); $subject = \wf\mailer\Helper::encode($subject); $message = chunk_split(base64_encode(str_replace("\n", "\r\n", str_replace("\r", "\n", str_replace("\r\n", "\n", str_replace("\n\r", "\r", $message)))))); $headers = "From: {$from}\r\n"; // 抄送 if($cc) { $cc = \wf\mailer\Helper::emailEncode($cc); $headers .= "Cc: {$cc}\r\n"; } // 密送 if($bcc) { $bcc = \wf\mailer\Helper::emailEncode($bcc); $headers .= "Bcc: {$bcc}\r\n"; } $headers .= "X-Priority: 3\r\n" . "X-Mailer: Windwork\r\n" . "MIME-Version: 1.0\r\n" . "Content-type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: base64\r\n"; if(!$fp = fsockopen($this->cfg['host'], $this->cfg['port'], $errno, $errstr, 30)) { throw new Exception("SMTP ({$this->cfg['host']}:{$this->cfg['port']}) CONNECT - Unable to connect to the SMTP server"); } stream_set_blocking($fp, true); $lastMessage = fgets($fp, 512); if(substr($lastMessage, 0, 3) != '220') { throw new Exception("SMTP {$this->cfg['host']}:{$this->cfg['port']} CONNECT - $lastMessage"); } fputs($fp, ($this->cfg['auth'] ? 'EHLO' : 'HELO')." windwork\r\n"); $lastMessage = fgets($fp, 512); if(substr($lastMessage, 0, 3) != 220 && substr($lastMessage, 0, 3) != 250) { throw new Exception("SMTP ({$this->cfg['host']}:{$this->cfg['port']}) HELO/EHLO - $lastMessage", 0); } while(1) { if(substr($lastMessage, 3, 1) != '-' || empty($lastMessage)) { break; } $lastMessage = fgets($fp, 512); } if($this->cfg['auth']) { fputs($fp, "AUTH LOGIN\r\n"); $lastMessage = fgets($fp, 512); if(substr($lastMessage, 0, 3) != 334) { throw new Exception("SMTP ({$this->cfg['host']}:{$this->cfg['port']}) AUTH LOGIN - $lastMessage", 0); } fputs($fp, base64_encode($this->cfg['user'])."\r\n"); $lastMessage = fgets($fp, 512); if(substr($lastMessage, 0, 3) != 334) { throw new Exception("SMTP ({$this->cfg['host']}:{$this->cfg['port']}) USERNAME - $lastMessage", 0); } fputs($fp, base64_encode($this->cfg['pass'])."\r\n"); $lastMessage = fgets($fp, 512); if(substr($lastMessage, 0, 3) != 235) { throw new Exception("SMTP ({$this->cfg['host']}:{$this->cfg['port']}) PASSWORD - $lastMessage", 0); } $emailFrom = $from; } fputs($fp, "MAIL FROM: <".preg_replace("/.*\\<(.+?)\\>.*/", "\\1", $from).">\r\n"); $lastMessage = fgets($fp, 512); if(substr($lastMessage, 0, 3) != 250) { fputs($fp, "MAIL FROM: <".preg_replace("/.*\\<(.+?)\\>.*/", "\\1", $from).">\r\n"); $lastMessage = fgets($fp, 512); if(substr($lastMessage, 0, 3) != 250) { throw new Exception("SMTP ({$this->cfg['host']}:{$this->cfg['port']}) MAIL FROM - $lastMessage", 0); } } fputs($fp, "RCPT TO: <".preg_replace("/.*\\<(.+?)\\>.*/", "\\1", $to).">\r\n"); $lastMessage = fgets($fp, 512); if(substr($lastMessage, 0, 3) != 250) { fputs($fp, "RCPT TO: <".preg_replace("/.*\\<(.+?)\\>.*/", "\\1", $to).">\r\n"); $lastMessage = fgets($fp, 512); throw new Exception("SMTP ({$this->cfg['host']}:{$this->cfg['port']}) RCPT TO - $lastMessage", 0); } fputs($fp, "DATA\r\n"); $lastMessage = fgets($fp, 512); if(substr($lastMessage, 0, 3) != 354) { throw new Exception("SMTP ({$this->cfg['host']}:{$this->cfg['port']}) DATA - $lastMessage", 0); } $headers .= 'Message-ID: <'.date('YmdHs').'.'.substr(md5($message.microtime()), 0, 6).rand(100000, 999999).'@'.@$_SERVER['HTTP_HOST'].">\r\n"; fputs($fp, "Date: ".date('r')."\r\n"); fputs($fp, "To: {$to}\r\n"); fputs($fp, "Subject: {$subject}\r\n"); fputs($fp, "{$headers}\r\n"); fputs($fp, "\r\n\r\n"); fputs($fp, "{$message}\r\n.\r\n"); $lastMessage = fgets($fp, 512); if(substr($lastMessage, 0, 3) != 250) { throw new Exception("SMTP ({$this->cfg['host']}:{$this->cfg['port']}) END - {$lastMessage}", 0); } fputs($fp, "QUIT\r\n"); return true; }
[ "public", "function", "send", "(", "$", "to", ",", "$", "subject", ",", "$", "message", ",", "$", "from", "=", "''", ",", "$", "cc", "=", "''", ",", "$", "bcc", "=", "''", ")", "{", "// 端口", "$", "this", "->", "cfg", "[", "'port'", "]", "=", "empty", "(", "$", "this", "->", "cfg", "[", "'port'", "]", ")", "?", "25", ":", "$", "this", "->", "cfg", "[", "'port'", "]", ";", "// SMTP发送邮件账号必须与发件人一致", "$", "from", "=", "$", "this", "->", "cfg", "[", "'user'", "]", ";", "$", "to", "=", "\\", "wf", "\\", "mailer", "\\", "Helper", "::", "emailEncode", "(", "$", "to", ")", ";", "$", "from", "=", "\\", "wf", "\\", "mailer", "\\", "Helper", "::", "emailEncode", "(", "$", "from", ")", ";", "$", "subject", "=", "\\", "wf", "\\", "mailer", "\\", "Helper", "::", "encode", "(", "$", "subject", ")", ";", "$", "message", "=", "chunk_split", "(", "base64_encode", "(", "str_replace", "(", "\"\\n\"", ",", "\"\\r\\n\"", ",", "str_replace", "(", "\"\\r\"", ",", "\"\\n\"", ",", "str_replace", "(", "\"\\r\\n\"", ",", "\"\\n\"", ",", "str_replace", "(", "\"\\n\\r\"", ",", "\"\\r\"", ",", "$", "message", ")", ")", ")", ")", ")", ")", ";", "$", "headers", "=", "\"From: {$from}\\r\\n\"", ";", "// 抄送", "if", "(", "$", "cc", ")", "{", "$", "cc", "=", "\\", "wf", "\\", "mailer", "\\", "Helper", "::", "emailEncode", "(", "$", "cc", ")", ";", "$", "headers", ".=", "\"Cc: {$cc}\\r\\n\"", ";", "}", "// 密送", "if", "(", "$", "bcc", ")", "{", "$", "bcc", "=", "\\", "wf", "\\", "mailer", "\\", "Helper", "::", "emailEncode", "(", "$", "bcc", ")", ";", "$", "headers", ".=", "\"Bcc: {$bcc}\\r\\n\"", ";", "}", "$", "headers", ".=", "\"X-Priority: 3\\r\\n\"", ".", "\"X-Mailer: Windwork\\r\\n\"", ".", "\"MIME-Version: 1.0\\r\\n\"", ".", "\"Content-type: text/html; charset=utf-8\\r\\n\"", ".", "\"Content-Transfer-Encoding: base64\\r\\n\"", ";", "if", "(", "!", "$", "fp", "=", "fsockopen", "(", "$", "this", "->", "cfg", "[", "'host'", "]", ",", "$", "this", "->", "cfg", "[", "'port'", "]", ",", "$", "errno", ",", "$", "errstr", ",", "30", ")", ")", "{", "throw", "new", "Exception", "(", "\"SMTP ({$this->cfg['host']}:{$this->cfg['port']}) CONNECT - Unable to connect to the SMTP server\"", ")", ";", "}", "stream_set_blocking", "(", "$", "fp", ",", "true", ")", ";", "$", "lastMessage", "=", "fgets", "(", "$", "fp", ",", "512", ")", ";", "if", "(", "substr", "(", "$", "lastMessage", ",", "0", ",", "3", ")", "!=", "'220'", ")", "{", "throw", "new", "Exception", "(", "\"SMTP {$this->cfg['host']}:{$this->cfg['port']} CONNECT - $lastMessage\"", ")", ";", "}", "fputs", "(", "$", "fp", ",", "(", "$", "this", "->", "cfg", "[", "'auth'", "]", "?", "'EHLO'", ":", "'HELO'", ")", ".", "\" windwork\\r\\n\"", ")", ";", "$", "lastMessage", "=", "fgets", "(", "$", "fp", ",", "512", ")", ";", "if", "(", "substr", "(", "$", "lastMessage", ",", "0", ",", "3", ")", "!=", "220", "&&", "substr", "(", "$", "lastMessage", ",", "0", ",", "3", ")", "!=", "250", ")", "{", "throw", "new", "Exception", "(", "\"SMTP ({$this->cfg['host']}:{$this->cfg['port']}) HELO/EHLO - $lastMessage\"", ",", "0", ")", ";", "}", "while", "(", "1", ")", "{", "if", "(", "substr", "(", "$", "lastMessage", ",", "3", ",", "1", ")", "!=", "'-'", "||", "empty", "(", "$", "lastMessage", ")", ")", "{", "break", ";", "}", "$", "lastMessage", "=", "fgets", "(", "$", "fp", ",", "512", ")", ";", "}", "if", "(", "$", "this", "->", "cfg", "[", "'auth'", "]", ")", "{", "fputs", "(", "$", "fp", ",", "\"AUTH LOGIN\\r\\n\"", ")", ";", "$", "lastMessage", "=", "fgets", "(", "$", "fp", ",", "512", ")", ";", "if", "(", "substr", "(", "$", "lastMessage", ",", "0", ",", "3", ")", "!=", "334", ")", "{", "throw", "new", "Exception", "(", "\"SMTP ({$this->cfg['host']}:{$this->cfg['port']}) AUTH LOGIN - $lastMessage\"", ",", "0", ")", ";", "}", "fputs", "(", "$", "fp", ",", "base64_encode", "(", "$", "this", "->", "cfg", "[", "'user'", "]", ")", ".", "\"\\r\\n\"", ")", ";", "$", "lastMessage", "=", "fgets", "(", "$", "fp", ",", "512", ")", ";", "if", "(", "substr", "(", "$", "lastMessage", ",", "0", ",", "3", ")", "!=", "334", ")", "{", "throw", "new", "Exception", "(", "\"SMTP ({$this->cfg['host']}:{$this->cfg['port']}) USERNAME - $lastMessage\"", ",", "0", ")", ";", "}", "fputs", "(", "$", "fp", ",", "base64_encode", "(", "$", "this", "->", "cfg", "[", "'pass'", "]", ")", ".", "\"\\r\\n\"", ")", ";", "$", "lastMessage", "=", "fgets", "(", "$", "fp", ",", "512", ")", ";", "if", "(", "substr", "(", "$", "lastMessage", ",", "0", ",", "3", ")", "!=", "235", ")", "{", "throw", "new", "Exception", "(", "\"SMTP ({$this->cfg['host']}:{$this->cfg['port']}) PASSWORD - $lastMessage\"", ",", "0", ")", ";", "}", "$", "emailFrom", "=", "$", "from", ";", "}", "fputs", "(", "$", "fp", ",", "\"MAIL FROM: <\"", ".", "preg_replace", "(", "\"/.*\\\\<(.+?)\\\\>.*/\"", ",", "\"\\\\1\"", ",", "$", "from", ")", ".", "\">\\r\\n\"", ")", ";", "$", "lastMessage", "=", "fgets", "(", "$", "fp", ",", "512", ")", ";", "if", "(", "substr", "(", "$", "lastMessage", ",", "0", ",", "3", ")", "!=", "250", ")", "{", "fputs", "(", "$", "fp", ",", "\"MAIL FROM: <\"", ".", "preg_replace", "(", "\"/.*\\\\<(.+?)\\\\>.*/\"", ",", "\"\\\\1\"", ",", "$", "from", ")", ".", "\">\\r\\n\"", ")", ";", "$", "lastMessage", "=", "fgets", "(", "$", "fp", ",", "512", ")", ";", "if", "(", "substr", "(", "$", "lastMessage", ",", "0", ",", "3", ")", "!=", "250", ")", "{", "throw", "new", "Exception", "(", "\"SMTP ({$this->cfg['host']}:{$this->cfg['port']}) MAIL FROM - $lastMessage\"", ",", "0", ")", ";", "}", "}", "fputs", "(", "$", "fp", ",", "\"RCPT TO: <\"", ".", "preg_replace", "(", "\"/.*\\\\<(.+?)\\\\>.*/\"", ",", "\"\\\\1\"", ",", "$", "to", ")", ".", "\">\\r\\n\"", ")", ";", "$", "lastMessage", "=", "fgets", "(", "$", "fp", ",", "512", ")", ";", "if", "(", "substr", "(", "$", "lastMessage", ",", "0", ",", "3", ")", "!=", "250", ")", "{", "fputs", "(", "$", "fp", ",", "\"RCPT TO: <\"", ".", "preg_replace", "(", "\"/.*\\\\<(.+?)\\\\>.*/\"", ",", "\"\\\\1\"", ",", "$", "to", ")", ".", "\">\\r\\n\"", ")", ";", "$", "lastMessage", "=", "fgets", "(", "$", "fp", ",", "512", ")", ";", "throw", "new", "Exception", "(", "\"SMTP ({$this->cfg['host']}:{$this->cfg['port']}) RCPT TO - $lastMessage\"", ",", "0", ")", ";", "}", "fputs", "(", "$", "fp", ",", "\"DATA\\r\\n\"", ")", ";", "$", "lastMessage", "=", "fgets", "(", "$", "fp", ",", "512", ")", ";", "if", "(", "substr", "(", "$", "lastMessage", ",", "0", ",", "3", ")", "!=", "354", ")", "{", "throw", "new", "Exception", "(", "\"SMTP ({$this->cfg['host']}:{$this->cfg['port']}) DATA - $lastMessage\"", ",", "0", ")", ";", "}", "$", "headers", ".=", "'Message-ID: <'", ".", "date", "(", "'YmdHs'", ")", ".", "'.'", ".", "substr", "(", "md5", "(", "$", "message", ".", "microtime", "(", ")", ")", ",", "0", ",", "6", ")", ".", "rand", "(", "100000", ",", "999999", ")", ".", "'@'", ".", "@", "$", "_SERVER", "[", "'HTTP_HOST'", "]", ".", "\">\\r\\n\"", ";", "fputs", "(", "$", "fp", ",", "\"Date: \"", ".", "date", "(", "'r'", ")", ".", "\"\\r\\n\"", ")", ";", "fputs", "(", "$", "fp", ",", "\"To: {$to}\\r\\n\"", ")", ";", "fputs", "(", "$", "fp", ",", "\"Subject: {$subject}\\r\\n\"", ")", ";", "fputs", "(", "$", "fp", ",", "\"{$headers}\\r\\n\"", ")", ";", "fputs", "(", "$", "fp", ",", "\"\\r\\n\\r\\n\"", ")", ";", "fputs", "(", "$", "fp", ",", "\"{$message}\\r\\n.\\r\\n\"", ")", ";", "$", "lastMessage", "=", "fgets", "(", "$", "fp", ",", "512", ")", ";", "if", "(", "substr", "(", "$", "lastMessage", ",", "0", ",", "3", ")", "!=", "250", ")", "{", "throw", "new", "Exception", "(", "\"SMTP ({$this->cfg['host']}:{$this->cfg['port']}) END - {$lastMessage}\"", ",", "0", ")", ";", "}", "fputs", "(", "$", "fp", ",", "\"QUIT\\r\\n\"", ")", ";", "return", "true", ";", "}" ]
{@inheritDoc} @see \wf\mailer\MailerInterface::send()
[ "{" ]
train
https://github.com/windwork/wf-mailer/blob/71fbdb3bcb5bdc0a53fa8b4433c446828e205d22/lib/adapter/SMTP.php#L42-L160
wikimedia/CLDRPluralRuleParser
src/Converter/Operator.php
Operator.operate
public function operate( Expression $left, Expression $right ) { $typeSpec = self::$opTypes[$this->name]; $leftType = self::$typeSpecMap[$typeSpec[0]]; $rightType = self::$typeSpecMap[$typeSpec[1]]; $resultType = self::$typeSpecMap[$typeSpec[2]]; $start = min( $this->pos, $left->pos, $right->pos ); $end = max( $this->end, $left->end, $right->end ); $length = $end - $start; $newExpr = new Expression( $this->parser, $resultType, "{$left->rpn} {$right->rpn} {$this->name}", $start, $length ); if ( !$left->isType( $leftType ) ) { $newExpr->error( "invalid type for left operand: expected $leftType, got {$left->type}" ); } if ( !$right->isType( $rightType ) ) { $newExpr->error( "invalid type for right operand: expected $rightType, got {$right->type}" ); } return $newExpr; }
php
public function operate( Expression $left, Expression $right ) { $typeSpec = self::$opTypes[$this->name]; $leftType = self::$typeSpecMap[$typeSpec[0]]; $rightType = self::$typeSpecMap[$typeSpec[1]]; $resultType = self::$typeSpecMap[$typeSpec[2]]; $start = min( $this->pos, $left->pos, $right->pos ); $end = max( $this->end, $left->end, $right->end ); $length = $end - $start; $newExpr = new Expression( $this->parser, $resultType, "{$left->rpn} {$right->rpn} {$this->name}", $start, $length ); if ( !$left->isType( $leftType ) ) { $newExpr->error( "invalid type for left operand: expected $leftType, got {$left->type}" ); } if ( !$right->isType( $rightType ) ) { $newExpr->error( "invalid type for right operand: expected $rightType, got {$right->type}" ); } return $newExpr; }
[ "public", "function", "operate", "(", "Expression", "$", "left", ",", "Expression", "$", "right", ")", "{", "$", "typeSpec", "=", "self", "::", "$", "opTypes", "[", "$", "this", "->", "name", "]", ";", "$", "leftType", "=", "self", "::", "$", "typeSpecMap", "[", "$", "typeSpec", "[", "0", "]", "]", ";", "$", "rightType", "=", "self", "::", "$", "typeSpecMap", "[", "$", "typeSpec", "[", "1", "]", "]", ";", "$", "resultType", "=", "self", "::", "$", "typeSpecMap", "[", "$", "typeSpec", "[", "2", "]", "]", ";", "$", "start", "=", "min", "(", "$", "this", "->", "pos", ",", "$", "left", "->", "pos", ",", "$", "right", "->", "pos", ")", ";", "$", "end", "=", "max", "(", "$", "this", "->", "end", ",", "$", "left", "->", "end", ",", "$", "right", "->", "end", ")", ";", "$", "length", "=", "$", "end", "-", "$", "start", ";", "$", "newExpr", "=", "new", "Expression", "(", "$", "this", "->", "parser", ",", "$", "resultType", ",", "\"{$left->rpn} {$right->rpn} {$this->name}\"", ",", "$", "start", ",", "$", "length", ")", ";", "if", "(", "!", "$", "left", "->", "isType", "(", "$", "leftType", ")", ")", "{", "$", "newExpr", "->", "error", "(", "\"invalid type for left operand: expected $leftType, got {$left->type}\"", ")", ";", "}", "if", "(", "!", "$", "right", "->", "isType", "(", "$", "rightType", ")", ")", "{", "$", "newExpr", "->", "error", "(", "\"invalid type for right operand: expected $rightType, got {$right->type}\"", ")", ";", "}", "return", "$", "newExpr", ";", "}" ]
Compute the operation @param Expression $left The left part of the expression @param Expression $right The right part of the expression @return Expression The result of the operation
[ "Compute", "the", "operation" ]
train
https://github.com/wikimedia/CLDRPluralRuleParser/blob/4c5d71a3fd62a75871da8562310ca2258647ee6d/src/Converter/Operator.php#L89-L113
GrahamDeprecated/CMS-Core
src/Seeds/GroupsTableSeeder.php
GroupsTableSeeder.run
public function run() { DB::table('groups')->delete(); // users $permissions = array('user' => 1, 'edit' => 0, 'blog' => 0, 'mod' => 0, 'admin' => 0); $group = array('name' => 'Users', 'permissions' => $permissions); Credentials::getGroupProvider()->create($group); // editors $permissions = array('user' => 1, 'edit' => 1, 'blog' => 0, 'mod' => 0, 'admin' => 0); $group = array('name' => 'Editors', 'permissions' => $permissions); Credentials::getGroupProvider()->create($group); // bloggers $permissions = array('user' => 1, 'edit' => 0, 'blog' => 1, 'mod' => 0, 'admin' => 0); $group = array('name' => 'Bloggers', 'permissions' => $permissions); Credentials::getGroupProvider()->create($group); // moderators $permissions = array('user' => 1, 'edit' => 0, 'blog' => 0, 'mod' => 1, 'admin' => 0); $group = array('name' => 'Moderators', 'permissions' => $permissions); Credentials::getGroupProvider()->create($group); // admins $permissions = array('user' => 1, 'edit' => 1, 'blog' => 1, 'mod' => 1, 'admin' => 1); $group = array('name' => 'Admins', 'permissions' => $permissions); Credentials::getGroupProvider()->create($group); }
php
public function run() { DB::table('groups')->delete(); // users $permissions = array('user' => 1, 'edit' => 0, 'blog' => 0, 'mod' => 0, 'admin' => 0); $group = array('name' => 'Users', 'permissions' => $permissions); Credentials::getGroupProvider()->create($group); // editors $permissions = array('user' => 1, 'edit' => 1, 'blog' => 0, 'mod' => 0, 'admin' => 0); $group = array('name' => 'Editors', 'permissions' => $permissions); Credentials::getGroupProvider()->create($group); // bloggers $permissions = array('user' => 1, 'edit' => 0, 'blog' => 1, 'mod' => 0, 'admin' => 0); $group = array('name' => 'Bloggers', 'permissions' => $permissions); Credentials::getGroupProvider()->create($group); // moderators $permissions = array('user' => 1, 'edit' => 0, 'blog' => 0, 'mod' => 1, 'admin' => 0); $group = array('name' => 'Moderators', 'permissions' => $permissions); Credentials::getGroupProvider()->create($group); // admins $permissions = array('user' => 1, 'edit' => 1, 'blog' => 1, 'mod' => 1, 'admin' => 1); $group = array('name' => 'Admins', 'permissions' => $permissions); Credentials::getGroupProvider()->create($group); }
[ "public", "function", "run", "(", ")", "{", "DB", "::", "table", "(", "'groups'", ")", "->", "delete", "(", ")", ";", "// users", "$", "permissions", "=", "array", "(", "'user'", "=>", "1", ",", "'edit'", "=>", "0", ",", "'blog'", "=>", "0", ",", "'mod'", "=>", "0", ",", "'admin'", "=>", "0", ")", ";", "$", "group", "=", "array", "(", "'name'", "=>", "'Users'", ",", "'permissions'", "=>", "$", "permissions", ")", ";", "Credentials", "::", "getGroupProvider", "(", ")", "->", "create", "(", "$", "group", ")", ";", "// editors", "$", "permissions", "=", "array", "(", "'user'", "=>", "1", ",", "'edit'", "=>", "1", ",", "'blog'", "=>", "0", ",", "'mod'", "=>", "0", ",", "'admin'", "=>", "0", ")", ";", "$", "group", "=", "array", "(", "'name'", "=>", "'Editors'", ",", "'permissions'", "=>", "$", "permissions", ")", ";", "Credentials", "::", "getGroupProvider", "(", ")", "->", "create", "(", "$", "group", ")", ";", "// bloggers", "$", "permissions", "=", "array", "(", "'user'", "=>", "1", ",", "'edit'", "=>", "0", ",", "'blog'", "=>", "1", ",", "'mod'", "=>", "0", ",", "'admin'", "=>", "0", ")", ";", "$", "group", "=", "array", "(", "'name'", "=>", "'Bloggers'", ",", "'permissions'", "=>", "$", "permissions", ")", ";", "Credentials", "::", "getGroupProvider", "(", ")", "->", "create", "(", "$", "group", ")", ";", "// moderators", "$", "permissions", "=", "array", "(", "'user'", "=>", "1", ",", "'edit'", "=>", "0", ",", "'blog'", "=>", "0", ",", "'mod'", "=>", "1", ",", "'admin'", "=>", "0", ")", ";", "$", "group", "=", "array", "(", "'name'", "=>", "'Moderators'", ",", "'permissions'", "=>", "$", "permissions", ")", ";", "Credentials", "::", "getGroupProvider", "(", ")", "->", "create", "(", "$", "group", ")", ";", "// admins", "$", "permissions", "=", "array", "(", "'user'", "=>", "1", ",", "'edit'", "=>", "1", ",", "'blog'", "=>", "1", ",", "'mod'", "=>", "1", ",", "'admin'", "=>", "1", ")", ";", "$", "group", "=", "array", "(", "'name'", "=>", "'Admins'", ",", "'permissions'", "=>", "$", "permissions", ")", ";", "Credentials", "::", "getGroupProvider", "(", ")", "->", "create", "(", "$", "group", ")", ";", "}" ]
Run the database seeding. @return void
[ "Run", "the", "database", "seeding", "." ]
train
https://github.com/GrahamDeprecated/CMS-Core/blob/5603e2bfa2fac6cf46ca3ed62d21518f2f653675/src/Seeds/GroupsTableSeeder.php#L39-L67
steeffeen/FancyManiaLinks
FML/Script/Features/Paging.php
Paging.addPageControl
public function addPageControl(Control $pageControl, $pageNumber = null) { if ($pageNumber === null) { $pageNumber = count($this->pages) + 1; } $page = new PagingPage($pageControl, $pageNumber); return $this->addPage($page); }
php
public function addPageControl(Control $pageControl, $pageNumber = null) { if ($pageNumber === null) { $pageNumber = count($this->pages) + 1; } $page = new PagingPage($pageControl, $pageNumber); return $this->addPage($page); }
[ "public", "function", "addPageControl", "(", "Control", "$", "pageControl", ",", "$", "pageNumber", "=", "null", ")", "{", "if", "(", "$", "pageNumber", "===", "null", ")", "{", "$", "pageNumber", "=", "count", "(", "$", "this", "->", "pages", ")", "+", "1", ";", "}", "$", "page", "=", "new", "PagingPage", "(", "$", "pageControl", ",", "$", "pageNumber", ")", ";", "return", "$", "this", "->", "addPage", "(", "$", "page", ")", ";", "}" ]
Add a new Page Control @api @param Control $pageControl Page Control @param string $pageNumber (optional) Page number @return static
[ "Add", "a", "new", "Page", "Control" ]
train
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/Paging.php#L133-L140
steeffeen/FancyManiaLinks
FML/Script/Features/Paging.php
Paging.addPage
public function addPage(PagingPage $page) { if (!in_array($page, $this->pages, true)) { array_push($this->pages, $page); } return $this; }
php
public function addPage(PagingPage $page) { if (!in_array($page, $this->pages, true)) { array_push($this->pages, $page); } return $this; }
[ "public", "function", "addPage", "(", "PagingPage", "$", "page", ")", "{", "if", "(", "!", "in_array", "(", "$", "page", ",", "$", "this", "->", "pages", ",", "true", ")", ")", "{", "array_push", "(", "$", "this", "->", "pages", ",", "$", "page", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add a new Page @api @param PagingPage $page Page @return static
[ "Add", "a", "new", "Page" ]
train
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/Paging.php#L149-L155
steeffeen/FancyManiaLinks
FML/Script/Features/Paging.php
Paging.setPages
public function setPages(array $pages) { $this->pages = array(); foreach ($pages as $page) { $this->addPage($page); } return $this; }
php
public function setPages(array $pages) { $this->pages = array(); foreach ($pages as $page) { $this->addPage($page); } return $this; }
[ "public", "function", "setPages", "(", "array", "$", "pages", ")", "{", "$", "this", "->", "pages", "=", "array", "(", ")", ";", "foreach", "(", "$", "pages", "as", "$", "page", ")", "{", "$", "this", "->", "addPage", "(", "$", "page", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add new Pages @api @param PagingPage[] $pages Pages @return static
[ "Add", "new", "Pages" ]
train
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/Paging.php#L164-L171
steeffeen/FancyManiaLinks
FML/Script/Features/Paging.php
Paging.addButtonControl
public function addButtonControl(Control $buttonControl, $browseAction = null) { if ($browseAction === null) { $buttonCount = count($this->buttons); if ($buttonCount % 2 === 0) { $browseAction = $buttonCount / 2 + 1; } else { $browseAction = $buttonCount / -2 - 1; } } $button = new PagingButton($buttonControl, $browseAction); return $this->addButton($button); }
php
public function addButtonControl(Control $buttonControl, $browseAction = null) { if ($browseAction === null) { $buttonCount = count($this->buttons); if ($buttonCount % 2 === 0) { $browseAction = $buttonCount / 2 + 1; } else { $browseAction = $buttonCount / -2 - 1; } } $button = new PagingButton($buttonControl, $browseAction); return $this->addButton($button); }
[ "public", "function", "addButtonControl", "(", "Control", "$", "buttonControl", ",", "$", "browseAction", "=", "null", ")", "{", "if", "(", "$", "browseAction", "===", "null", ")", "{", "$", "buttonCount", "=", "count", "(", "$", "this", "->", "buttons", ")", ";", "if", "(", "$", "buttonCount", "%", "2", "===", "0", ")", "{", "$", "browseAction", "=", "$", "buttonCount", "/", "2", "+", "1", ";", "}", "else", "{", "$", "browseAction", "=", "$", "buttonCount", "/", "-", "2", "-", "1", ";", "}", "}", "$", "button", "=", "new", "PagingButton", "(", "$", "buttonControl", ",", "$", "browseAction", ")", ";", "return", "$", "this", "->", "addButton", "(", "$", "button", ")", ";", "}" ]
Add a new Button Control to browse through the Pages @api @param Control $buttonControl Button used for browsing @param int $browseAction (optional) Number of browsed Pages per click @return static
[ "Add", "a", "new", "Button", "Control", "to", "browse", "through", "the", "Pages" ]
train
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/Paging.php#L192-L204
steeffeen/FancyManiaLinks
FML/Script/Features/Paging.php
Paging.addButton
public function addButton(PagingButton $button) { if (!in_array($button, $this->buttons, true)) { array_push($this->buttons, $button); } return $this; }
php
public function addButton(PagingButton $button) { if (!in_array($button, $this->buttons, true)) { array_push($this->buttons, $button); } return $this; }
[ "public", "function", "addButton", "(", "PagingButton", "$", "button", ")", "{", "if", "(", "!", "in_array", "(", "$", "button", ",", "$", "this", "->", "buttons", ",", "true", ")", ")", "{", "array_push", "(", "$", "this", "->", "buttons", ",", "$", "button", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add a new Button to browse through Pages @api @param PagingButton $button Paging Button @return static
[ "Add", "a", "new", "Button", "to", "browse", "through", "Pages" ]
train
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/Paging.php#L213-L219
steeffeen/FancyManiaLinks
FML/Script/Features/Paging.php
Paging.setButtons
public function setButtons(array $buttons) { $this->buttons = array(); foreach ($buttons as $button) { $this->addButton($button); } return $this; }
php
public function setButtons(array $buttons) { $this->buttons = array(); foreach ($buttons as $button) { $this->addButton($button); } return $this; }
[ "public", "function", "setButtons", "(", "array", "$", "buttons", ")", "{", "$", "this", "->", "buttons", "=", "array", "(", ")", ";", "foreach", "(", "$", "buttons", "as", "$", "button", ")", "{", "$", "this", "->", "addButton", "(", "$", "button", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the Paging Buttons @api @param PagingButton[] $buttons Paging Buttons @return static
[ "Set", "the", "Paging", "Buttons" ]
train
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/Paging.php#L228-L235
steeffeen/FancyManiaLinks
FML/Script/Features/Paging.php
Paging.getMinPage
protected function getMinPage() { $minPageNumber = null; $minPage = null; foreach ($this->pages as $page) { $pageNumber = $page->getPageNumber(); if ($minPageNumber === null || $pageNumber < $minPageNumber) { $minPageNumber = $pageNumber; $minPage = $page; } } return $minPage; }
php
protected function getMinPage() { $minPageNumber = null; $minPage = null; foreach ($this->pages as $page) { $pageNumber = $page->getPageNumber(); if ($minPageNumber === null || $pageNumber < $minPageNumber) { $minPageNumber = $pageNumber; $minPage = $page; } } return $minPage; }
[ "protected", "function", "getMinPage", "(", ")", "{", "$", "minPageNumber", "=", "null", ";", "$", "minPage", "=", "null", ";", "foreach", "(", "$", "this", "->", "pages", "as", "$", "page", ")", "{", "$", "pageNumber", "=", "$", "page", "->", "getPageNumber", "(", ")", ";", "if", "(", "$", "minPageNumber", "===", "null", "||", "$", "pageNumber", "<", "$", "minPageNumber", ")", "{", "$", "minPageNumber", "=", "$", "pageNumber", ";", "$", "minPage", "=", "$", "page", ";", "}", "}", "return", "$", "minPage", ";", "}" ]
Get the minimum Page @return PagingPage
[ "Get", "the", "minimum", "Page" ]
train
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/Paging.php#L466-L478
steeffeen/FancyManiaLinks
FML/Script/Features/Paging.php
Paging.getMaxPage
protected function getMaxPage() { $maxPageNumber = null; $maxPage = null; foreach ($this->pages as $page) { $pageNumber = $page->getPageNumber(); if ($maxPageNumber === null || $pageNumber > $maxPageNumber) { $maxPageNumber = $pageNumber; $maxPage = $page; } } return $maxPage; }
php
protected function getMaxPage() { $maxPageNumber = null; $maxPage = null; foreach ($this->pages as $page) { $pageNumber = $page->getPageNumber(); if ($maxPageNumber === null || $pageNumber > $maxPageNumber) { $maxPageNumber = $pageNumber; $maxPage = $page; } } return $maxPage; }
[ "protected", "function", "getMaxPage", "(", ")", "{", "$", "maxPageNumber", "=", "null", ";", "$", "maxPage", "=", "null", ";", "foreach", "(", "$", "this", "->", "pages", "as", "$", "page", ")", "{", "$", "pageNumber", "=", "$", "page", "->", "getPageNumber", "(", ")", ";", "if", "(", "$", "maxPageNumber", "===", "null", "||", "$", "pageNumber", ">", "$", "maxPageNumber", ")", "{", "$", "maxPageNumber", "=", "$", "pageNumber", ";", "$", "maxPage", "=", "$", "page", ";", "}", "}", "return", "$", "maxPage", ";", "}" ]
Get the maximum Page @return PagingPage
[ "Get", "the", "maximum", "Page" ]
train
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/Paging.php#L485-L497
steeffeen/FancyManiaLinks
FML/Script/Features/Paging.php
Paging.getPagesArrayText
protected function getPagesArrayText() { if (empty($this->pages)) { return Builder::getArray(array(0 => ''), true); } $pages = array(); foreach ($this->pages as $page) { $pages[$page->getPageNumber()] = $page->getControl() ->getId(); } return Builder::getArray($pages, true); }
php
protected function getPagesArrayText() { if (empty($this->pages)) { return Builder::getArray(array(0 => ''), true); } $pages = array(); foreach ($this->pages as $page) { $pages[$page->getPageNumber()] = $page->getControl() ->getId(); } return Builder::getArray($pages, true); }
[ "protected", "function", "getPagesArrayText", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "pages", ")", ")", "{", "return", "Builder", "::", "getArray", "(", "array", "(", "0", "=>", "''", ")", ",", "true", ")", ";", "}", "$", "pages", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "pages", "as", "$", "page", ")", "{", "$", "pages", "[", "$", "page", "->", "getPageNumber", "(", ")", "]", "=", "$", "page", "->", "getControl", "(", ")", "->", "getId", "(", ")", ";", "}", "return", "Builder", "::", "getArray", "(", "$", "pages", ",", "true", ")", ";", "}" ]
Build the array text for the Pages @return string
[ "Build", "the", "array", "text", "for", "the", "Pages" ]
train
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/Paging.php#L504-L515
steeffeen/FancyManiaLinks
FML/Script/Features/Paging.php
Paging.getPageButtonsArrayText
protected function getPageButtonsArrayText() { if (empty($this->buttons)) { return Builder::getArray(array('' => 0), true); } $pageButtons = array(); foreach ($this->buttons as $pageButton) { $pageButtons[$pageButton->getControl() ->getId()] = $pageButton->getPagingCount(); } return Builder::getArray($pageButtons, true); }
php
protected function getPageButtonsArrayText() { if (empty($this->buttons)) { return Builder::getArray(array('' => 0), true); } $pageButtons = array(); foreach ($this->buttons as $pageButton) { $pageButtons[$pageButton->getControl() ->getId()] = $pageButton->getPagingCount(); } return Builder::getArray($pageButtons, true); }
[ "protected", "function", "getPageButtonsArrayText", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "buttons", ")", ")", "{", "return", "Builder", "::", "getArray", "(", "array", "(", "''", "=>", "0", ")", ",", "true", ")", ";", "}", "$", "pageButtons", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "buttons", "as", "$", "pageButton", ")", "{", "$", "pageButtons", "[", "$", "pageButton", "->", "getControl", "(", ")", "->", "getId", "(", ")", "]", "=", "$", "pageButton", "->", "getPagingCount", "(", ")", ";", "}", "return", "Builder", "::", "getArray", "(", "$", "pageButtons", ",", "true", ")", ";", "}" ]
Build the array text for the Page Buttons @return string
[ "Build", "the", "array", "text", "for", "the", "Page", "Buttons" ]
train
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/Paging.php#L522-L533
digitalkaoz/versioneye-php
src/Http/ClientFactory.php
ClientFactory.create
public static function create($url, $token) { $plugins = [ new Plugin\RedirectPlugin(), new Plugin\RetryPlugin(['retries' => 5]), new Plugin\DecoderPlugin(), new Plugin\ErrorPlugin(), ]; if ($token) { $plugins[] = new Plugin\AuthenticationPlugin(new QueryParam([ 'api_key' => $token, ])); } $client = new PluginClient(Discovery\HttpClientDiscovery::find(), $plugins); $streamFactory = Discovery\StreamFactoryDiscovery::find(); $builder = new MultipartStreamBuilder($streamFactory); return new HttpPlugHttpAdapterClient($client, $url, Discovery\MessageFactoryDiscovery::find(), $builder); }
php
public static function create($url, $token) { $plugins = [ new Plugin\RedirectPlugin(), new Plugin\RetryPlugin(['retries' => 5]), new Plugin\DecoderPlugin(), new Plugin\ErrorPlugin(), ]; if ($token) { $plugins[] = new Plugin\AuthenticationPlugin(new QueryParam([ 'api_key' => $token, ])); } $client = new PluginClient(Discovery\HttpClientDiscovery::find(), $plugins); $streamFactory = Discovery\StreamFactoryDiscovery::find(); $builder = new MultipartStreamBuilder($streamFactory); return new HttpPlugHttpAdapterClient($client, $url, Discovery\MessageFactoryDiscovery::find(), $builder); }
[ "public", "static", "function", "create", "(", "$", "url", ",", "$", "token", ")", "{", "$", "plugins", "=", "[", "new", "Plugin", "\\", "RedirectPlugin", "(", ")", ",", "new", "Plugin", "\\", "RetryPlugin", "(", "[", "'retries'", "=>", "5", "]", ")", ",", "new", "Plugin", "\\", "DecoderPlugin", "(", ")", ",", "new", "Plugin", "\\", "ErrorPlugin", "(", ")", ",", "]", ";", "if", "(", "$", "token", ")", "{", "$", "plugins", "[", "]", "=", "new", "Plugin", "\\", "AuthenticationPlugin", "(", "new", "QueryParam", "(", "[", "'api_key'", "=>", "$", "token", ",", "]", ")", ")", ";", "}", "$", "client", "=", "new", "PluginClient", "(", "Discovery", "\\", "HttpClientDiscovery", "::", "find", "(", ")", ",", "$", "plugins", ")", ";", "$", "streamFactory", "=", "Discovery", "\\", "StreamFactoryDiscovery", "::", "find", "(", ")", ";", "$", "builder", "=", "new", "MultipartStreamBuilder", "(", "$", "streamFactory", ")", ";", "return", "new", "HttpPlugHttpAdapterClient", "(", "$", "client", ",", "$", "url", ",", "Discovery", "\\", "MessageFactoryDiscovery", "::", "find", "(", ")", ",", "$", "builder", ")", ";", "}" ]
@param string $url @param string $token @return HttpClient
[ "@param", "string", "$url", "@param", "string", "$token" ]
train
https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Http/ClientFactory.php#L24-L44
guillermoandrae/php-repository
src/Repositories/RepositoryFactory.php
RepositoryFactory.factory
public static function factory(string $name, $options = null): RepositoryInterface { try { $className = sprintf( '%s\%sRepository', self::getNamespace(), ucfirst(strtolower($name)) ); $reflectionClass = new \ReflectionClass($className); if (is_null($options)) { return $reflectionClass->newInstance(); } return $reflectionClass->newInstance($options); } catch (\ReflectionException $ex) { throw new InvalidRepositoryException( sprintf('The %s repository does not exist.', $name) ); } }
php
public static function factory(string $name, $options = null): RepositoryInterface { try { $className = sprintf( '%s\%sRepository', self::getNamespace(), ucfirst(strtolower($name)) ); $reflectionClass = new \ReflectionClass($className); if (is_null($options)) { return $reflectionClass->newInstance(); } return $reflectionClass->newInstance($options); } catch (\ReflectionException $ex) { throw new InvalidRepositoryException( sprintf('The %s repository does not exist.', $name) ); } }
[ "public", "static", "function", "factory", "(", "string", "$", "name", ",", "$", "options", "=", "null", ")", ":", "RepositoryInterface", "{", "try", "{", "$", "className", "=", "sprintf", "(", "'%s\\%sRepository'", ",", "self", "::", "getNamespace", "(", ")", ",", "ucfirst", "(", "strtolower", "(", "$", "name", ")", ")", ")", ";", "$", "reflectionClass", "=", "new", "\\", "ReflectionClass", "(", "$", "className", ")", ";", "if", "(", "is_null", "(", "$", "options", ")", ")", "{", "return", "$", "reflectionClass", "->", "newInstance", "(", ")", ";", "}", "return", "$", "reflectionClass", "->", "newInstance", "(", "$", "options", ")", ";", "}", "catch", "(", "\\", "ReflectionException", "$", "ex", ")", "{", "throw", "new", "InvalidRepositoryException", "(", "sprintf", "(", "'The %s repository does not exist.'", ",", "$", "name", ")", ")", ";", "}", "}" ]
Returns the desired repository using the provided data. @param string $name The name of the desired repository. @param mixed|null $options The data needed to build the repository. @return RepositoryInterface @throws InvalidRepositoryException Thrown when an invalid repository is requested.
[ "Returns", "the", "desired", "repository", "using", "the", "provided", "data", "." ]
train
https://github.com/guillermoandrae/php-repository/blob/8cf9c50c7c7f4c08190b3232df77e21e706e7a2a/src/Repositories/RepositoryFactory.php#L53-L71
xinix-technology/norm
src/Norm/Type/Object.php
Object.toObject
public function toObject() { $obj = new stdClass(); if (! empty($this->attributes)) { foreach ($this->attributes as $key => $value) { $obj->$key = $value; } } return $obj; }
php
public function toObject() { $obj = new stdClass(); if (! empty($this->attributes)) { foreach ($this->attributes as $key => $value) { $obj->$key = $value; } } return $obj; }
[ "public", "function", "toObject", "(", ")", "{", "$", "obj", "=", "new", "stdClass", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "attributes", ")", ")", "{", "foreach", "(", "$", "this", "->", "attributes", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "obj", "->", "$", "key", "=", "$", "value", ";", "}", "}", "return", "$", "obj", ";", "}" ]
Convert this class to a standard object. @return \stdClass
[ "Convert", "this", "class", "to", "a", "standard", "object", "." ]
train
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Type/Object.php#L20-L31
shinjin/freezer
src/Storage/CouchDB.php
CouchDB.doStore
protected function doStore(array $frozenObject) { $payload = array('docs' => array()); foreach ($frozenObject['objects'] as $id => $object) { if ($object['isDirty'] === true) { $doc = array( '_id' => $id, 'class' => $object['class'], 'state' => $object['state'] ); if (isset($object['state']['__freezer']['_rev'])) { $doc['_rev'] = $object['state']['__freezer']['_rev']; } array_push($payload['docs'], $doc); } } if (!empty($payload['docs'])) { $this->send( 'POST', '/' . $this->database . '/_bulk_docs', json_encode($payload) ); } }
php
protected function doStore(array $frozenObject) { $payload = array('docs' => array()); foreach ($frozenObject['objects'] as $id => $object) { if ($object['isDirty'] === true) { $doc = array( '_id' => $id, 'class' => $object['class'], 'state' => $object['state'] ); if (isset($object['state']['__freezer']['_rev'])) { $doc['_rev'] = $object['state']['__freezer']['_rev']; } array_push($payload['docs'], $doc); } } if (!empty($payload['docs'])) { $this->send( 'POST', '/' . $this->database . '/_bulk_docs', json_encode($payload) ); } }
[ "protected", "function", "doStore", "(", "array", "$", "frozenObject", ")", "{", "$", "payload", "=", "array", "(", "'docs'", "=>", "array", "(", ")", ")", ";", "foreach", "(", "$", "frozenObject", "[", "'objects'", "]", "as", "$", "id", "=>", "$", "object", ")", "{", "if", "(", "$", "object", "[", "'isDirty'", "]", "===", "true", ")", "{", "$", "doc", "=", "array", "(", "'_id'", "=>", "$", "id", ",", "'class'", "=>", "$", "object", "[", "'class'", "]", ",", "'state'", "=>", "$", "object", "[", "'state'", "]", ")", ";", "if", "(", "isset", "(", "$", "object", "[", "'state'", "]", "[", "'__freezer'", "]", "[", "'_rev'", "]", ")", ")", "{", "$", "doc", "[", "'_rev'", "]", "=", "$", "object", "[", "'state'", "]", "[", "'__freezer'", "]", "[", "'_rev'", "]", ";", "}", "array_push", "(", "$", "payload", "[", "'docs'", "]", ",", "$", "doc", ")", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "payload", "[", "'docs'", "]", ")", ")", "{", "$", "this", "->", "send", "(", "'POST'", ",", "'/'", ".", "$", "this", "->", "database", ".", "'/_bulk_docs'", ",", "json_encode", "(", "$", "payload", ")", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/shinjin/freezer/blob/f5955fb5476fa8ac456e27c0edafaae331d02cd3/src/Storage/CouchDB.php#L70-L97
shinjin/freezer
src/Storage/CouchDB.php
CouchDB.doFetch
protected function doFetch($id, array &$objects = array()) { $isRoot = empty($objects); if (!isset($objects[$id])) { $response = $this->send('GET', '/' . $this->database . '/' . $id); if (strpos($response['headers'], 'HTTP/1.1 200 OK') === 0) { $object = json_decode($response['body'], true); } else { return false; } $object['state']['__freezer']['_rev'] = $object['_rev']; $objects[$id] = array( 'class' => $object['class'], 'isDirty' => false, 'state' => $object['state'] ); 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])) { $response = $this->send('GET', '/' . $this->database . '/' . $id); if (strpos($response['headers'], 'HTTP/1.1 200 OK') === 0) { $object = json_decode($response['body'], true); } else { return false; } $object['state']['__freezer']['_rev'] = $object['_rev']; $objects[$id] = array( 'class' => $object['class'], 'isDirty' => false, 'state' => $object['state'] ); 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", "]", ")", ")", "{", "$", "response", "=", "$", "this", "->", "send", "(", "'GET'", ",", "'/'", ".", "$", "this", "->", "database", ".", "'/'", ".", "$", "id", ")", ";", "if", "(", "strpos", "(", "$", "response", "[", "'headers'", "]", ",", "'HTTP/1.1 200 OK'", ")", "===", "0", ")", "{", "$", "object", "=", "json_decode", "(", "$", "response", "[", "'body'", "]", ",", "true", ")", ";", "}", "else", "{", "return", "false", ";", "}", "$", "object", "[", "'state'", "]", "[", "'__freezer'", "]", "[", "'_rev'", "]", "=", "$", "object", "[", "'_rev'", "]", ";", "$", "objects", "[", "$", "id", "]", "=", "array", "(", "'class'", "=>", "$", "object", "[", "'class'", "]", ",", "'isDirty'", "=>", "false", ",", "'state'", "=>", "$", "object", "[", "'state'", "]", ")", ";", "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/CouchDB.php#L102-L131
mle86/php-wq
src/WQ/Job/QueueEntry.php
QueueEntry.fromSerializedJob
public static function fromSerializedJob( string $serializedData, string $originWorkQueue, $handle, string $jobId ): self { /** @var Job $job */ $job = unserialize($serializedData); if ($job === false) { throw new UnserializationException("job {$jobId} (wq {$originWorkQueue}) contained an invalid serialization!"); } if (!is_object($job)) { throw new UnserializationException("job {$jobId} (wq {$originWorkQueue}) contained a non-object serialization!"); } if (!($job instanceof Job)) { throw new UnserializationException("job {$jobId} (wq {$originWorkQueue}) contained a non-Job object serialization!"); } return new self($job, $originWorkQueue, $handle); }
php
public static function fromSerializedJob( string $serializedData, string $originWorkQueue, $handle, string $jobId ): self { /** @var Job $job */ $job = unserialize($serializedData); if ($job === false) { throw new UnserializationException("job {$jobId} (wq {$originWorkQueue}) contained an invalid serialization!"); } if (!is_object($job)) { throw new UnserializationException("job {$jobId} (wq {$originWorkQueue}) contained a non-object serialization!"); } if (!($job instanceof Job)) { throw new UnserializationException("job {$jobId} (wq {$originWorkQueue}) contained a non-Job object serialization!"); } return new self($job, $originWorkQueue, $handle); }
[ "public", "static", "function", "fromSerializedJob", "(", "string", "$", "serializedData", ",", "string", "$", "originWorkQueue", ",", "$", "handle", ",", "string", "$", "jobId", ")", ":", "self", "{", "/** @var Job $job */", "$", "job", "=", "unserialize", "(", "$", "serializedData", ")", ";", "if", "(", "$", "job", "===", "false", ")", "{", "throw", "new", "UnserializationException", "(", "\"job {$jobId} (wq {$originWorkQueue}) contained an invalid serialization!\"", ")", ";", "}", "if", "(", "!", "is_object", "(", "$", "job", ")", ")", "{", "throw", "new", "UnserializationException", "(", "\"job {$jobId} (wq {$originWorkQueue}) contained a non-object serialization!\"", ")", ";", "}", "if", "(", "!", "(", "$", "job", "instanceof", "Job", ")", ")", "{", "throw", "new", "UnserializationException", "(", "\"job {$jobId} (wq {$originWorkQueue}) contained a non-Job object serialization!\"", ")", ";", "}", "return", "new", "self", "(", "$", "job", ",", "$", "originWorkQueue", ",", "$", "handle", ")", ";", "}" ]
Unserializes a stored {@see Job} instance from a Work Queue entry's raw data and wraps it in a {@see QueueEntry} instance. @param string $serializedData The serialized raw data. @param string $originWorkQueue @param mixed $handle The Work Server adapter's representation of this job. @param string $jobId A unique ID for this job. Only used for logging. Not every WorkServerAdapter implementation provides this! @return self @throws UnserializationException if $serializedData corresponded to a non-object or to a non-{@see Job} object
[ "Unserializes", "a", "stored", "{", "@see", "Job", "}", "instance", "from", "a", "Work", "Queue", "entry", "s", "raw", "data", "and", "wraps", "it", "in", "a", "{", "@see", "QueueEntry", "}", "instance", "." ]
train
https://github.com/mle86/php-wq/blob/e1ca1dcfd3d40edb0085f6dfa83d90db74253de4/src/WQ/Job/QueueEntry.php#L72-L92
flipboxstudio/orm-manager
src/Flipbox/OrmManager/BothRelations/MorphManytoMany.php
MorphManytoMany.stylingText
protected function stylingText() { $this->text = array_merge($this->text, [ 'name' => "[".$this->command->paintString($this->defaultOptions['name'], 'green')."]", 'pivot_table' => "[".$this->command->paintString($this->defaultOptions['pivot_table'], 'green')."]", 'foreign_key' => "[".$this->command->paintString($this->defaultOptions['foreign_key'], 'green')."]", 'related_key' => "[".$this->command->paintString($this->defaultOptions['related_key'], 'green')."]", 'pivot_text' => $this->command->paintString('pivot table', 'brown'), 'foreign_text' => $this->command->paintString('foreign key', 'brown'), 'related_text' => $this->command->paintString('related key', 'brown'), ]); }
php
protected function stylingText() { $this->text = array_merge($this->text, [ 'name' => "[".$this->command->paintString($this->defaultOptions['name'], 'green')."]", 'pivot_table' => "[".$this->command->paintString($this->defaultOptions['pivot_table'], 'green')."]", 'foreign_key' => "[".$this->command->paintString($this->defaultOptions['foreign_key'], 'green')."]", 'related_key' => "[".$this->command->paintString($this->defaultOptions['related_key'], 'green')."]", 'pivot_text' => $this->command->paintString('pivot table', 'brown'), 'foreign_text' => $this->command->paintString('foreign key', 'brown'), 'related_text' => $this->command->paintString('related key', 'brown'), ]); }
[ "protected", "function", "stylingText", "(", ")", "{", "$", "this", "->", "text", "=", "array_merge", "(", "$", "this", "->", "text", ",", "[", "'name'", "=>", "\"[\"", ".", "$", "this", "->", "command", "->", "paintString", "(", "$", "this", "->", "defaultOptions", "[", "'name'", "]", ",", "'green'", ")", ".", "\"]\"", ",", "'pivot_table'", "=>", "\"[\"", ".", "$", "this", "->", "command", "->", "paintString", "(", "$", "this", "->", "defaultOptions", "[", "'pivot_table'", "]", ",", "'green'", ")", ".", "\"]\"", ",", "'foreign_key'", "=>", "\"[\"", ".", "$", "this", "->", "command", "->", "paintString", "(", "$", "this", "->", "defaultOptions", "[", "'foreign_key'", "]", ",", "'green'", ")", ".", "\"]\"", ",", "'related_key'", "=>", "\"[\"", ".", "$", "this", "->", "command", "->", "paintString", "(", "$", "this", "->", "defaultOptions", "[", "'related_key'", "]", ",", "'green'", ")", ".", "\"]\"", ",", "'pivot_text'", "=>", "$", "this", "->", "command", "->", "paintString", "(", "'pivot table'", ",", "'brown'", ")", ",", "'foreign_text'", "=>", "$", "this", "->", "command", "->", "paintString", "(", "'foreign key'", ",", "'brown'", ")", ",", "'related_text'", "=>", "$", "this", "->", "command", "->", "paintString", "(", "'related key'", ",", "'brown'", ")", ",", "]", ")", ";", "}" ]
styling text @return void
[ "styling", "text" ]
train
https://github.com/flipboxstudio/orm-manager/blob/4288426517f53d05177b8729c4ba94c5beca9a98/src/Flipbox/OrmManager/BothRelations/MorphManytoMany.php#L86-L97
davidgorges/color-contrast-php
src/ContrastAlgorithm/LuminosityContrast.php
LuminosityContrast.calculate
public function calculate(ColorJizz $foreground, ColorJizz $background) { $fgLuma = $this->relativeLuminosity($foreground->toRGB()); $bgLuma = $this->relativeLuminosity($background->toRGB()); if ($fgLuma > $bgLuma) { return ($fgLuma + 0.05) / ($bgLuma + 0.05); } else { return ($bgLuma + 0.05) / ($fgLuma + 0.05); } }
php
public function calculate(ColorJizz $foreground, ColorJizz $background) { $fgLuma = $this->relativeLuminosity($foreground->toRGB()); $bgLuma = $this->relativeLuminosity($background->toRGB()); if ($fgLuma > $bgLuma) { return ($fgLuma + 0.05) / ($bgLuma + 0.05); } else { return ($bgLuma + 0.05) / ($fgLuma + 0.05); } }
[ "public", "function", "calculate", "(", "ColorJizz", "$", "foreground", ",", "ColorJizz", "$", "background", ")", "{", "$", "fgLuma", "=", "$", "this", "->", "relativeLuminosity", "(", "$", "foreground", "->", "toRGB", "(", ")", ")", ";", "$", "bgLuma", "=", "$", "this", "->", "relativeLuminosity", "(", "$", "background", "->", "toRGB", "(", ")", ")", ";", "if", "(", "$", "fgLuma", ">", "$", "bgLuma", ")", "{", "return", "(", "$", "fgLuma", "+", "0.05", ")", "/", "(", "$", "bgLuma", "+", "0.05", ")", ";", "}", "else", "{", "return", "(", "$", "bgLuma", "+", "0.05", ")", "/", "(", "$", "fgLuma", "+", "0.05", ")", ";", "}", "}" ]
returns the contrast ratio between foreground and background color. @param ColorJizz $foreground @param ColorJizz $background @return float
[ "returns", "the", "contrast", "ratio", "between", "foreground", "and", "background", "color", "." ]
train
https://github.com/davidgorges/color-contrast-php/blob/11edc6e04ce73d8d9b0bffeda1586f2c2fa22e71/src/ContrastAlgorithm/LuminosityContrast.php#L24-L34
davidgorges/color-contrast-php
src/ContrastAlgorithm/LuminosityContrast.php
LuminosityContrast.relativeLuminosity
private function relativeLuminosity(RGB $color) { $luminosity = 0.2126 * pow($color->getRed() / 255, 2.2) + 0.7152 * pow($color->getGreen() / 255, 2.2) + 0.0722 * pow($color->getBlue() / 255, 2.2); return $luminosity; }
php
private function relativeLuminosity(RGB $color) { $luminosity = 0.2126 * pow($color->getRed() / 255, 2.2) + 0.7152 * pow($color->getGreen() / 255, 2.2) + 0.0722 * pow($color->getBlue() / 255, 2.2); return $luminosity; }
[ "private", "function", "relativeLuminosity", "(", "RGB", "$", "color", ")", "{", "$", "luminosity", "=", "0.2126", "*", "pow", "(", "$", "color", "->", "getRed", "(", ")", "/", "255", ",", "2.2", ")", "+", "0.7152", "*", "pow", "(", "$", "color", "->", "getGreen", "(", ")", "/", "255", ",", "2.2", ")", "+", "0.0722", "*", "pow", "(", "$", "color", "->", "getBlue", "(", ")", "/", "255", ",", "2.2", ")", ";", "return", "$", "luminosity", ";", "}" ]
@param RGB $color @return float
[ "@param", "RGB", "$color" ]
train
https://github.com/davidgorges/color-contrast-php/blob/11edc6e04ce73d8d9b0bffeda1586f2c2fa22e71/src/ContrastAlgorithm/LuminosityContrast.php#L41-L48
spiral-modules/auth
source/Auth/Middlewares/AuthMiddleware.php
AuthMiddleware.commitContext
protected function commitContext( Request $request, Response $response, TokenInterface $token ): Response { return $token->getOperator()->commitToken($request, $response, $token); }
php
protected function commitContext( Request $request, Response $response, TokenInterface $token ): Response { return $token->getOperator()->commitToken($request, $response, $token); }
[ "protected", "function", "commitContext", "(", "Request", "$", "request", ",", "Response", "$", "response", ",", "TokenInterface", "$", "token", ")", ":", "Response", "{", "return", "$", "token", "->", "getOperator", "(", ")", "->", "commitToken", "(", "$", "request", ",", "$", "response", ",", "$", "token", ")", ";", "}" ]
@param Request $request @param Response $response @param TokenInterface $token @return Response
[ "@param", "Request", "$request", "@param", "Response", "$response", "@param", "TokenInterface", "$token" ]
train
https://github.com/spiral-modules/auth/blob/24e2070028f7257e8192914556963a4794428a99/source/Auth/Middlewares/AuthMiddleware.php#L96-L102
spiral-modules/auth
source/Auth/Middlewares/AuthMiddleware.php
AuthMiddleware.closeContext
protected function closeContext( Request $request, Response $response, TokenInterface $token ): Response { return $token->getOperator()->removeToken($request, $response, $token); }
php
protected function closeContext( Request $request, Response $response, TokenInterface $token ): Response { return $token->getOperator()->removeToken($request, $response, $token); }
[ "protected", "function", "closeContext", "(", "Request", "$", "request", ",", "Response", "$", "response", ",", "TokenInterface", "$", "token", ")", ":", "Response", "{", "return", "$", "token", "->", "getOperator", "(", ")", "->", "removeToken", "(", "$", "request", ",", "$", "response", ",", "$", "token", ")", ";", "}" ]
@param Request $request @param Response $response @param TokenInterface $token @return Response
[ "@param", "Request", "$request", "@param", "Response", "$response", "@param", "TokenInterface", "$token" ]
train
https://github.com/spiral-modules/auth/blob/24e2070028f7257e8192914556963a4794428a99/source/Auth/Middlewares/AuthMiddleware.php#L111-L117
stanislav-web/phalcon-ulogin
src/ULogin/Parser.php
Parser.map
public static function map($data) { if(is_array($data) === true) { $array = self::arrayResolve($data); } else { $array = self::stringResolve($data); } return $array; }
php
public static function map($data) { if(is_array($data) === true) { $array = self::arrayResolve($data); } else { $array = self::stringResolve($data); } return $array; }
[ "public", "static", "function", "map", "(", "$", "data", ")", "{", "if", "(", "is_array", "(", "$", "data", ")", "===", "true", ")", "{", "$", "array", "=", "self", "::", "arrayResolve", "(", "$", "data", ")", ";", "}", "else", "{", "$", "array", "=", "self", "::", "stringResolve", "(", "$", "data", ")", ";", "}", "return", "$", "array", ";", "}" ]
Resolve mapper @param mixed $data input data @access static @return array
[ "Resolve", "mapper" ]
train
https://github.com/stanislav-web/phalcon-ulogin/blob/0cea8510a244ebb9b1333085b325a283e4fb9f2f/src/ULogin/Parser.php#L23-L35
stanislav-web/phalcon-ulogin
src/ULogin/Parser.php
Parser.arrayResolve
public static function arrayResolve(array $data) { $array = []; foreach ($data as $provider => $bool) { if ($bool === true) { $array['required'][] = $provider; } else { $array['hidden'][] = $provider; } } return $array; }
php
public static function arrayResolve(array $data) { $array = []; foreach ($data as $provider => $bool) { if ($bool === true) { $array['required'][] = $provider; } else { $array['hidden'][] = $provider; } } return $array; }
[ "public", "static", "function", "arrayResolve", "(", "array", "$", "data", ")", "{", "$", "array", "=", "[", "]", ";", "foreach", "(", "$", "data", "as", "$", "provider", "=>", "$", "bool", ")", "{", "if", "(", "$", "bool", "===", "true", ")", "{", "$", "array", "[", "'required'", "]", "[", "]", "=", "$", "provider", ";", "}", "else", "{", "$", "array", "[", "'hidden'", "]", "[", "]", "=", "$", "provider", ";", "}", "}", "return", "$", "array", ";", "}" ]
Resolve array data as providers @param array $data @access static @return array
[ "Resolve", "array", "data", "as", "providers" ]
train
https://github.com/stanislav-web/phalcon-ulogin/blob/0cea8510a244ebb9b1333085b325a283e4fb9f2f/src/ULogin/Parser.php#L44-L64
stanislav-web/phalcon-ulogin
src/ULogin/Parser.php
Parser.separate
private static function separate(array $data) { $array = []; foreach ($data as $provider) { if(($bool = self::isDelim($provider)) === false) { $array['required'][] = $provider; } else { if ($bool[1] === 'true') { $array['required'][] = strval($bool[0]); } else { $array['hidden'][] = strval($bool[0]); } } } return $array; }
php
private static function separate(array $data) { $array = []; foreach ($data as $provider) { if(($bool = self::isDelim($provider)) === false) { $array['required'][] = $provider; } else { if ($bool[1] === 'true') { $array['required'][] = strval($bool[0]); } else { $array['hidden'][] = strval($bool[0]); } } } return $array; }
[ "private", "static", "function", "separate", "(", "array", "$", "data", ")", "{", "$", "array", "=", "[", "]", ";", "foreach", "(", "$", "data", "as", "$", "provider", ")", "{", "if", "(", "(", "$", "bool", "=", "self", "::", "isDelim", "(", "$", "provider", ")", ")", "===", "false", ")", "{", "$", "array", "[", "'required'", "]", "[", "]", "=", "$", "provider", ";", "}", "else", "{", "if", "(", "$", "bool", "[", "1", "]", "===", "'true'", ")", "{", "$", "array", "[", "'required'", "]", "[", "]", "=", "strval", "(", "$", "bool", "[", "0", "]", ")", ";", "}", "else", "{", "$", "array", "[", "'hidden'", "]", "[", "]", "=", "strval", "(", "$", "bool", "[", "0", "]", ")", ";", "}", "}", "}", "return", "$", "array", ";", "}" ]
Separate string @param array $data @access static @return array
[ "Separate", "string" ]
train
https://github.com/stanislav-web/phalcon-ulogin/blob/0cea8510a244ebb9b1333085b325a283e4fb9f2f/src/ULogin/Parser.php#L90-L110
stanislav-web/phalcon-ulogin
src/ULogin/Parser.php
Parser.isDelim
private static function isDelim($provider, $delimiter = '=') { if (mb_strpos($provider, $delimiter) !== false) { $res = explode('=', $provider); return $res; } return false; }
php
private static function isDelim($provider, $delimiter = '=') { if (mb_strpos($provider, $delimiter) !== false) { $res = explode('=', $provider); return $res; } return false; }
[ "private", "static", "function", "isDelim", "(", "$", "provider", ",", "$", "delimiter", "=", "'='", ")", "{", "if", "(", "mb_strpos", "(", "$", "provider", ",", "$", "delimiter", ")", "!==", "false", ")", "{", "$", "res", "=", "explode", "(", "'='", ",", "$", "provider", ")", ";", "return", "$", "res", ";", "}", "return", "false", ";", "}" ]
Check if data has delimiter @param string $provider @param string $delimiter @access static @return array|false
[ "Check", "if", "data", "has", "delimiter" ]
train
https://github.com/stanislav-web/phalcon-ulogin/blob/0cea8510a244ebb9b1333085b325a283e4fb9f2f/src/ULogin/Parser.php#L120-L131
kherge-abandoned/php-wise
src/lib/Herrera/Wise/Processor/ProcessorResolver.php
ProcessorResolver.resolve
public function resolve($resource, $type = null) { foreach ($this->processors as $processor) { if ($processor->supports($resource, $type)) { return $processor; } } return false; }
php
public function resolve($resource, $type = null) { foreach ($this->processors as $processor) { if ($processor->supports($resource, $type)) { return $processor; } } return false; }
[ "public", "function", "resolve", "(", "$", "resource", ",", "$", "type", "=", "null", ")", "{", "foreach", "(", "$", "this", "->", "processors", "as", "$", "processor", ")", "{", "if", "(", "$", "processor", "->", "supports", "(", "$", "resource", ",", "$", "type", ")", ")", "{", "return", "$", "processor", ";", "}", "}", "return", "false", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/kherge-abandoned/php-wise/blob/7621e0be7dbb2a015d68197d290fe8469f539a4d/src/lib/Herrera/Wise/Processor/ProcessorResolver.php#L54-L63
yuncms/framework
src/helpers/Html.php
Html.encodeParams
public static function encodeParams(string $html, array $variables = []): string { // Normalize the param keys $normalizedVariables = []; if (is_array($variables)) { foreach ($variables as $key => $value) { $key = '{' . trim($key, '{}') . '}'; $normalizedVariables[$key] = static::encode($value); } $html = strtr($html, $normalizedVariables); } return $html; }
php
public static function encodeParams(string $html, array $variables = []): string { // Normalize the param keys $normalizedVariables = []; if (is_array($variables)) { foreach ($variables as $key => $value) { $key = '{' . trim($key, '{}') . '}'; $normalizedVariables[$key] = static::encode($value); } $html = strtr($html, $normalizedVariables); } return $html; }
[ "public", "static", "function", "encodeParams", "(", "string", "$", "html", ",", "array", "$", "variables", "=", "[", "]", ")", ":", "string", "{", "// Normalize the param keys", "$", "normalizedVariables", "=", "[", "]", ";", "if", "(", "is_array", "(", "$", "variables", ")", ")", "{", "foreach", "(", "$", "variables", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "key", "=", "'{'", ".", "trim", "(", "$", "key", ",", "'{}'", ")", ".", "'}'", ";", "$", "normalizedVariables", "[", "$", "key", "]", "=", "static", "::", "encode", "(", "$", "value", ")", ";", "}", "$", "html", "=", "strtr", "(", "$", "html", ",", "$", "normalizedVariables", ")", ";", "}", "return", "$", "html", ";", "}" ]
Will take an HTML string and an associative array of key=>value pairs, HTML encode the values and swap them back into the original string using the keys as tokens. @param string $html The HTML string. @param array $variables An associative array of key => value pairs to be applied to the HTML string using `strtr`. @return string The HTML string with the encoded variable values swapped in.
[ "Will", "take", "an", "HTML", "string", "and", "an", "associative", "array", "of", "key", "=", ">", "value", "pairs", "HTML", "encode", "the", "values", "and", "swap", "them", "back", "into", "the", "original", "string", "using", "the", "keys", "as", "tokens", "." ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/helpers/Html.php#L82-L94
factorio-item-browser/export-data
src/Entity/Icon/Color.php
Color.setRed
public function setRed(float $red, float $scale = 1.) { $this->red = $this->setComponent($red, $scale); return $this; }
php
public function setRed(float $red, float $scale = 1.) { $this->red = $this->setComponent($red, $scale); return $this; }
[ "public", "function", "setRed", "(", "float", "$", "red", ",", "float", "$", "scale", "=", "1.", ")", "{", "$", "this", "->", "red", "=", "$", "this", "->", "setComponent", "(", "$", "red", ",", "$", "scale", ")", ";", "return", "$", "this", ";", "}" ]
Sets the red component of the color. @param float $red @param float $scale @return $this
[ "Sets", "the", "red", "component", "of", "the", "color", "." ]
train
https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Icon/Color.php#L50-L54
factorio-item-browser/export-data
src/Entity/Icon/Color.php
Color.setGreen
public function setGreen(float $green, float $scale = 1.) { $this->green = $this->setComponent($green, $scale); return $this; }
php
public function setGreen(float $green, float $scale = 1.) { $this->green = $this->setComponent($green, $scale); return $this; }
[ "public", "function", "setGreen", "(", "float", "$", "green", ",", "float", "$", "scale", "=", "1.", ")", "{", "$", "this", "->", "green", "=", "$", "this", "->", "setComponent", "(", "$", "green", ",", "$", "scale", ")", ";", "return", "$", "this", ";", "}" ]
Sets the green component of the color. @param float $green @param float $scale @return $this
[ "Sets", "the", "green", "component", "of", "the", "color", "." ]
train
https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Icon/Color.php#L72-L76
factorio-item-browser/export-data
src/Entity/Icon/Color.php
Color.setBlue
public function setBlue(float $blue, float $scale = 1.) { $this->blue = $this->setComponent($blue, $scale); return $this; }
php
public function setBlue(float $blue, float $scale = 1.) { $this->blue = $this->setComponent($blue, $scale); return $this; }
[ "public", "function", "setBlue", "(", "float", "$", "blue", ",", "float", "$", "scale", "=", "1.", ")", "{", "$", "this", "->", "blue", "=", "$", "this", "->", "setComponent", "(", "$", "blue", ",", "$", "scale", ")", ";", "return", "$", "this", ";", "}" ]
Sets the blue component of the color. @param float $blue @param float $scale @return $this
[ "Sets", "the", "blue", "component", "of", "the", "color", "." ]
train
https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Icon/Color.php#L94-L98
factorio-item-browser/export-data
src/Entity/Icon/Color.php
Color.setAlpha
public function setAlpha(float $alpha, float $scale = 1.) { $this->alpha = $this->setComponent($alpha, $scale); return $this; }
php
public function setAlpha(float $alpha, float $scale = 1.) { $this->alpha = $this->setComponent($alpha, $scale); return $this; }
[ "public", "function", "setAlpha", "(", "float", "$", "alpha", ",", "float", "$", "scale", "=", "1.", ")", "{", "$", "this", "->", "alpha", "=", "$", "this", "->", "setComponent", "(", "$", "alpha", ",", "$", "scale", ")", ";", "return", "$", "this", ";", "}" ]
Sets the alpha component of the color. @param float $alpha @param float $scale @return $this
[ "Sets", "the", "alpha", "component", "of", "the", "color", "." ]
train
https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Icon/Color.php#L116-L120
factorio-item-browser/export-data
src/Entity/Icon/Color.php
Color.setComponent
protected function setComponent(float $value, float $scale): float { return ($scale < 0) ? (1 - $value / -$scale) : ($value / $scale); }
php
protected function setComponent(float $value, float $scale): float { return ($scale < 0) ? (1 - $value / -$scale) : ($value / $scale); }
[ "protected", "function", "setComponent", "(", "float", "$", "value", ",", "float", "$", "scale", ")", ":", "float", "{", "return", "(", "$", "scale", "<", "0", ")", "?", "(", "1", "-", "$", "value", "/", "-", "$", "scale", ")", ":", "(", "$", "value", "/", "$", "scale", ")", ";", "}" ]
Calculates the value to set a component. @param float $value @param float $scale @return float
[ "Calculates", "the", "value", "to", "set", "a", "component", "." ]
train
https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Icon/Color.php#L138-L141
factorio-item-browser/export-data
src/Entity/Icon/Color.php
Color.getComponent
protected function getComponent(float $value, float $scale): float { return ($scale < 0) ? ((1 - $value) * -$scale) : ($value * $scale); }
php
protected function getComponent(float $value, float $scale): float { return ($scale < 0) ? ((1 - $value) * -$scale) : ($value * $scale); }
[ "protected", "function", "getComponent", "(", "float", "$", "value", ",", "float", "$", "scale", ")", ":", "float", "{", "return", "(", "$", "scale", "<", "0", ")", "?", "(", "(", "1", "-", "$", "value", ")", "*", "-", "$", "scale", ")", ":", "(", "$", "value", "*", "$", "scale", ")", ";", "}" ]
Calculates the value to get a component. @param float $value @param float $scale @return float
[ "Calculates", "the", "value", "to", "get", "a", "component", "." ]
train
https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Icon/Color.php#L149-L152
factorio-item-browser/export-data
src/Entity/Icon/Color.php
Color.writeData
public function writeData(): array { $dataBuilder = new DataBuilder(); $dataBuilder->setFloat('r', $this->getRed(), 1.) ->setFloat('g', $this->getGreen(), 1.) ->setFloat('b', $this->getBlue(), 1.) ->setFloat('a', $this->getAlpha(), 1.); return $dataBuilder->getData(); }
php
public function writeData(): array { $dataBuilder = new DataBuilder(); $dataBuilder->setFloat('r', $this->getRed(), 1.) ->setFloat('g', $this->getGreen(), 1.) ->setFloat('b', $this->getBlue(), 1.) ->setFloat('a', $this->getAlpha(), 1.); return $dataBuilder->getData(); }
[ "public", "function", "writeData", "(", ")", ":", "array", "{", "$", "dataBuilder", "=", "new", "DataBuilder", "(", ")", ";", "$", "dataBuilder", "->", "setFloat", "(", "'r'", ",", "$", "this", "->", "getRed", "(", ")", ",", "1.", ")", "->", "setFloat", "(", "'g'", ",", "$", "this", "->", "getGreen", "(", ")", ",", "1.", ")", "->", "setFloat", "(", "'b'", ",", "$", "this", "->", "getBlue", "(", ")", ",", "1.", ")", "->", "setFloat", "(", "'a'", ",", "$", "this", "->", "getAlpha", "(", ")", ",", "1.", ")", ";", "return", "$", "dataBuilder", "->", "getData", "(", ")", ";", "}" ]
Writes the entity data to an array. @return array
[ "Writes", "the", "entity", "data", "to", "an", "array", "." ]
train
https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Icon/Color.php#L158-L166
factorio-item-browser/export-data
src/Entity/Icon/Color.php
Color.readData
public function readData(DataContainer $data) { $this->red = $data->getFloat('r', 1.); $this->green = $data->getFloat('g', 1.); $this->blue = $data->getFloat('b', 1.); $this->alpha = $data->getFloat('a', 1.); return $this; }
php
public function readData(DataContainer $data) { $this->red = $data->getFloat('r', 1.); $this->green = $data->getFloat('g', 1.); $this->blue = $data->getFloat('b', 1.); $this->alpha = $data->getFloat('a', 1.); return $this; }
[ "public", "function", "readData", "(", "DataContainer", "$", "data", ")", "{", "$", "this", "->", "red", "=", "$", "data", "->", "getFloat", "(", "'r'", ",", "1.", ")", ";", "$", "this", "->", "green", "=", "$", "data", "->", "getFloat", "(", "'g'", ",", "1.", ")", ";", "$", "this", "->", "blue", "=", "$", "data", "->", "getFloat", "(", "'b'", ",", "1.", ")", ";", "$", "this", "->", "alpha", "=", "$", "data", "->", "getFloat", "(", "'a'", ",", "1.", ")", ";", "return", "$", "this", ";", "}" ]
Reads the entity data. @param DataContainer $data @return $this
[ "Reads", "the", "entity", "data", "." ]
train
https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Icon/Color.php#L173-L180
factorio-item-browser/export-data
src/Entity/Icon/Color.php
Color.calculateHash
public function calculateHash(): string { return EntityUtils::calculateHashOfArray([ $this->red, $this->green, $this->blue, $this->alpha, ]); }
php
public function calculateHash(): string { return EntityUtils::calculateHashOfArray([ $this->red, $this->green, $this->blue, $this->alpha, ]); }
[ "public", "function", "calculateHash", "(", ")", ":", "string", "{", "return", "EntityUtils", "::", "calculateHashOfArray", "(", "[", "$", "this", "->", "red", ",", "$", "this", "->", "green", ",", "$", "this", "->", "blue", ",", "$", "this", "->", "alpha", ",", "]", ")", ";", "}" ]
Calculates a hash value representing the entity. @return string
[ "Calculates", "a", "hash", "value", "representing", "the", "entity", "." ]
train
https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Icon/Color.php#L186-L194
forxer/tao
src/Tao/Controller/SearchableControllerTrait.php
SearchableControllerTrait.setSearchCriteriaFromSession
protected function setSearchCriteriaFromSession() { $this->initSearchCriteria(); foreach ($this->aCriteria as $sIndex => $mValue) { $this->aCriteria[$sIndex] = $this->app['session']->get($sIndex, $mValue); } }
php
protected function setSearchCriteriaFromSession() { $this->initSearchCriteria(); foreach ($this->aCriteria as $sIndex => $mValue) { $this->aCriteria[$sIndex] = $this->app['session']->get($sIndex, $mValue); } }
[ "protected", "function", "setSearchCriteriaFromSession", "(", ")", "{", "$", "this", "->", "initSearchCriteria", "(", ")", ";", "foreach", "(", "$", "this", "->", "aCriteria", "as", "$", "sIndex", "=>", "$", "mValue", ")", "{", "$", "this", "->", "aCriteria", "[", "$", "sIndex", "]", "=", "$", "this", "->", "app", "[", "'session'", "]", "->", "get", "(", "$", "sIndex", ",", "$", "mValue", ")", ";", "}", "}" ]
Retrouve les éventuels critères de recherche en _SESSION @return void
[ "Retrouve", "les", "éventuels", "critères", "de", "recherche", "en", "_SESSION" ]
train
https://github.com/forxer/tao/blob/b5e9109c244a29a72403ae6a58633ab96a67c660/src/Tao/Controller/SearchableControllerTrait.php#L40-L47
forxer/tao
src/Tao/Controller/SearchableControllerTrait.php
SearchableControllerTrait.removeSearchCriteriaFromSession
protected function removeSearchCriteriaFromSession() { $this->initSearchCriteria(); foreach (array_keys($this->aCriteria) as $sIndex) { $this->app['session']->remove($sIndex); } }
php
protected function removeSearchCriteriaFromSession() { $this->initSearchCriteria(); foreach (array_keys($this->aCriteria) as $sIndex) { $this->app['session']->remove($sIndex); } }
[ "protected", "function", "removeSearchCriteriaFromSession", "(", ")", "{", "$", "this", "->", "initSearchCriteria", "(", ")", ";", "foreach", "(", "array_keys", "(", "$", "this", "->", "aCriteria", ")", "as", "$", "sIndex", ")", "{", "$", "this", "->", "app", "[", "'session'", "]", "->", "remove", "(", "$", "sIndex", ")", ";", "}", "}" ]
Supprime les critères de recherche de la _SESSION @return void
[ "Supprime", "les", "critères", "de", "recherche", "de", "la", "_SESSION" ]
train
https://github.com/forxer/tao/blob/b5e9109c244a29a72403ae6a58633ab96a67c660/src/Tao/Controller/SearchableControllerTrait.php#L54-L61
forxer/tao
src/Tao/Controller/SearchableControllerTrait.php
SearchableControllerTrait.setSearchCriteriaFromPost
protected function setSearchCriteriaFromPost() { $this->initSearchCriteria(); foreach ($this->aCriteria as $sIndex => $mValue) { $this->aCriteria[$sIndex] = $this->app['request']->request->get($sIndex, $mValue); } }
php
protected function setSearchCriteriaFromPost() { $this->initSearchCriteria(); foreach ($this->aCriteria as $sIndex => $mValue) { $this->aCriteria[$sIndex] = $this->app['request']->request->get($sIndex, $mValue); } }
[ "protected", "function", "setSearchCriteriaFromPost", "(", ")", "{", "$", "this", "->", "initSearchCriteria", "(", ")", ";", "foreach", "(", "$", "this", "->", "aCriteria", "as", "$", "sIndex", "=>", "$", "mValue", ")", "{", "$", "this", "->", "aCriteria", "[", "$", "sIndex", "]", "=", "$", "this", "->", "app", "[", "'request'", "]", "->", "request", "->", "get", "(", "$", "sIndex", ",", "$", "mValue", ")", ";", "}", "}" ]
Retrouve les éventuels critères de recherche en _POST @return void
[ "Retrouve", "les", "éventuels", "critères", "de", "recherche", "en", "_POST" ]
train
https://github.com/forxer/tao/blob/b5e9109c244a29a72403ae6a58633ab96a67c660/src/Tao/Controller/SearchableControllerTrait.php#L68-L75
forxer/tao
src/Tao/Controller/SearchableControllerTrait.php
SearchableControllerTrait.setSearchCriteriaFromQuery
protected function setSearchCriteriaFromQuery() { $this->initSearchCriteria(); foreach ($this->aCriteria as $sIndex => $mValue) { $this->aCriteria[$sIndex] = $this->app['request']->query->get($sIndex, $mValue); } }
php
protected function setSearchCriteriaFromQuery() { $this->initSearchCriteria(); foreach ($this->aCriteria as $sIndex => $mValue) { $this->aCriteria[$sIndex] = $this->app['request']->query->get($sIndex, $mValue); } }
[ "protected", "function", "setSearchCriteriaFromQuery", "(", ")", "{", "$", "this", "->", "initSearchCriteria", "(", ")", ";", "foreach", "(", "$", "this", "->", "aCriteria", "as", "$", "sIndex", "=>", "$", "mValue", ")", "{", "$", "this", "->", "aCriteria", "[", "$", "sIndex", "]", "=", "$", "this", "->", "app", "[", "'request'", "]", "->", "query", "->", "get", "(", "$", "sIndex", ",", "$", "mValue", ")", ";", "}", "}" ]
Retrouve les éventuels critères de recherche en _GET @return void
[ "Retrouve", "les", "éventuels", "critères", "de", "recherche", "en", "_GET" ]
train
https://github.com/forxer/tao/blob/b5e9109c244a29a72403ae6a58633ab96a67c660/src/Tao/Controller/SearchableControllerTrait.php#L82-L89
aedart/laravel-helpers
src/Traits/Notifications/NotificationDispatcherTrait.php
NotificationDispatcherTrait.getNotificationDispatcher
public function getNotificationDispatcher(): ?Dispatcher { if (!$this->hasNotificationDispatcher()) { $this->setNotificationDispatcher($this->getDefaultNotificationDispatcher()); } return $this->notificationDispatcher; }
php
public function getNotificationDispatcher(): ?Dispatcher { if (!$this->hasNotificationDispatcher()) { $this->setNotificationDispatcher($this->getDefaultNotificationDispatcher()); } return $this->notificationDispatcher; }
[ "public", "function", "getNotificationDispatcher", "(", ")", ":", "?", "Dispatcher", "{", "if", "(", "!", "$", "this", "->", "hasNotificationDispatcher", "(", ")", ")", "{", "$", "this", "->", "setNotificationDispatcher", "(", "$", "this", "->", "getDefaultNotificationDispatcher", "(", ")", ")", ";", "}", "return", "$", "this", "->", "notificationDispatcher", ";", "}" ]
Get notification dispatcher If no notification dispatcher has been set, this method will set and return a default notification dispatcher, if any such value is available @see getDefaultNotificationDispatcher() @return Dispatcher|null notification dispatcher or null if none notification dispatcher has been set
[ "Get", "notification", "dispatcher" ]
train
https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Notifications/NotificationDispatcherTrait.php#L53-L59
ClanCats/Core
src/classes/CCUrl.php
CCUrl._init
public static function _init() { static::$path_offset = ClanCats::$config->get( 'url.path', '/' ); if ( empty( static::$path_offset ) ) { static::$path_offset = '/'; } if ( substr( static::$path_offset, -1 ) != '/' ) { static::$path_offset .= '/'; } // register the default parameter providers static::$parameter_provider = array( // Adds a session fingerprint to the parameter list 'fingerprint' => function() { return array( ClanCats::$config->get( 'session.default_fingerprint_parameter' ) => fingerprint() ); }, // Adds the next redirect uri to redirect back on request 'back' => function() { $params = CCIn::$_instance->GET; unset( $params['next'] ); return array( 'next' => CCUrl::current( $params ) ); }, ); }
php
public static function _init() { static::$path_offset = ClanCats::$config->get( 'url.path', '/' ); if ( empty( static::$path_offset ) ) { static::$path_offset = '/'; } if ( substr( static::$path_offset, -1 ) != '/' ) { static::$path_offset .= '/'; } // register the default parameter providers static::$parameter_provider = array( // Adds a session fingerprint to the parameter list 'fingerprint' => function() { return array( ClanCats::$config->get( 'session.default_fingerprint_parameter' ) => fingerprint() ); }, // Adds the next redirect uri to redirect back on request 'back' => function() { $params = CCIn::$_instance->GET; unset( $params['next'] ); return array( 'next' => CCUrl::current( $params ) ); }, ); }
[ "public", "static", "function", "_init", "(", ")", "{", "static", "::", "$", "path_offset", "=", "ClanCats", "::", "$", "config", "->", "get", "(", "'url.path'", ",", "'/'", ")", ";", "if", "(", "empty", "(", "static", "::", "$", "path_offset", ")", ")", "{", "static", "::", "$", "path_offset", "=", "'/'", ";", "}", "if", "(", "substr", "(", "static", "::", "$", "path_offset", ",", "-", "1", ")", "!=", "'/'", ")", "{", "static", "::", "$", "path_offset", ".=", "'/'", ";", "}", "// register the default parameter providers", "static", "::", "$", "parameter_provider", "=", "array", "(", "// Adds a session fingerprint to the parameter list", "'fingerprint'", "=>", "function", "(", ")", "{", "return", "array", "(", "ClanCats", "::", "$", "config", "->", "get", "(", "'session.default_fingerprint_parameter'", ")", "=>", "fingerprint", "(", ")", ")", ";", "}", ",", "// Adds the next redirect uri to redirect back on request", "'back'", "=>", "function", "(", ")", "{", "$", "params", "=", "CCIn", "::", "$", "_instance", "->", "GET", ";", "unset", "(", "$", "params", "[", "'next'", "]", ")", ";", "return", "array", "(", "'next'", "=>", "CCUrl", "::", "current", "(", "$", "params", ")", ")", ";", "}", ",", ")", ";", "}" ]
static CCUrl initialisation
[ "static", "CCUrl", "initialisation" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCUrl.php#L32-L62
ClanCats/Core
src/classes/CCUrl.php
CCUrl.to
public static function to( $uri = '', $params = array(), $retain = false ) { // To avoid // urls we check for a single slash. if ( $uri === '/' ) { $uri = ''; } // When the uri starts with an @ sign we handle the uri as route alias. if ( substr( $uri, 0, 1 ) == '@' ) { return static::alias( substr( $uri, 1 ), $params, $retain ); } // Are there already parameters in the uri? Parse them // and merge them with current argument parameters if ( strpos( $uri, '?' ) !== false ) { $parts = explode( '?', $uri ); $uri = $parts[0]; if ( isset( $parts[1] ) ) { parse_str( $parts[1], $old_params ); $params = array_merge( $old_params, $params ); } } // When the uri contains a protocoll or starts with a slash we assume // a full url is given and we don't have to add a path offest. if ( strpos( $uri, '://' ) === false && substr( $uri, 0, 1 ) !== '/' ) { $uri = static::$path_offset.$uri; } // Try to replace parameters in the uri and remove them from // the array so we can append them as get parameters foreach( $params as $key => $value ) { // replace the parameter provider if ( is_numeric( $key ) && is_string($value) && $value[0] === ':' ) { $param_provider_key = substr( $value, 1 ); // remove the parameter provider from the parameter list unset( $params[$key] ); if ( array_key_exists( $param_provider_key, static::$parameter_provider ) ) { $params = $params + call_user_func( static::$parameter_provider[$param_provider_key] ); } } // replace the parameters if ( !is_array($value)) { $uri = str_replace( ':'.$key, $value, $uri, $count ); if ( $count > 0 ) { unset( $params[$key] ); } } } // Should we keep the get parameters? If retain is enabled // we merge the get parameter array with argument parameters if ( $retain ) { $params = array_merge( CCIn::$_instance->GET, $params ); } // When we still got parameters add them to the url if ( !empty( $params ) ) { $uri .= '?'.http_build_query( $params ); } return $uri; }
php
public static function to( $uri = '', $params = array(), $retain = false ) { // To avoid // urls we check for a single slash. if ( $uri === '/' ) { $uri = ''; } // When the uri starts with an @ sign we handle the uri as route alias. if ( substr( $uri, 0, 1 ) == '@' ) { return static::alias( substr( $uri, 1 ), $params, $retain ); } // Are there already parameters in the uri? Parse them // and merge them with current argument parameters if ( strpos( $uri, '?' ) !== false ) { $parts = explode( '?', $uri ); $uri = $parts[0]; if ( isset( $parts[1] ) ) { parse_str( $parts[1], $old_params ); $params = array_merge( $old_params, $params ); } } // When the uri contains a protocoll or starts with a slash we assume // a full url is given and we don't have to add a path offest. if ( strpos( $uri, '://' ) === false && substr( $uri, 0, 1 ) !== '/' ) { $uri = static::$path_offset.$uri; } // Try to replace parameters in the uri and remove them from // the array so we can append them as get parameters foreach( $params as $key => $value ) { // replace the parameter provider if ( is_numeric( $key ) && is_string($value) && $value[0] === ':' ) { $param_provider_key = substr( $value, 1 ); // remove the parameter provider from the parameter list unset( $params[$key] ); if ( array_key_exists( $param_provider_key, static::$parameter_provider ) ) { $params = $params + call_user_func( static::$parameter_provider[$param_provider_key] ); } } // replace the parameters if ( !is_array($value)) { $uri = str_replace( ':'.$key, $value, $uri, $count ); if ( $count > 0 ) { unset( $params[$key] ); } } } // Should we keep the get parameters? If retain is enabled // we merge the get parameter array with argument parameters if ( $retain ) { $params = array_merge( CCIn::$_instance->GET, $params ); } // When we still got parameters add them to the url if ( !empty( $params ) ) { $uri .= '?'.http_build_query( $params ); } return $uri; }
[ "public", "static", "function", "to", "(", "$", "uri", "=", "''", ",", "$", "params", "=", "array", "(", ")", ",", "$", "retain", "=", "false", ")", "{", "// To avoid // urls we check for a single slash.", "if", "(", "$", "uri", "===", "'/'", ")", "{", "$", "uri", "=", "''", ";", "}", "// When the uri starts with an @ sign we handle the uri as route alias.", "if", "(", "substr", "(", "$", "uri", ",", "0", ",", "1", ")", "==", "'@'", ")", "{", "return", "static", "::", "alias", "(", "substr", "(", "$", "uri", ",", "1", ")", ",", "$", "params", ",", "$", "retain", ")", ";", "}", "// Are there already parameters in the uri? Parse them", "// and merge them with current argument parameters", "if", "(", "strpos", "(", "$", "uri", ",", "'?'", ")", "!==", "false", ")", "{", "$", "parts", "=", "explode", "(", "'?'", ",", "$", "uri", ")", ";", "$", "uri", "=", "$", "parts", "[", "0", "]", ";", "if", "(", "isset", "(", "$", "parts", "[", "1", "]", ")", ")", "{", "parse_str", "(", "$", "parts", "[", "1", "]", ",", "$", "old_params", ")", ";", "$", "params", "=", "array_merge", "(", "$", "old_params", ",", "$", "params", ")", ";", "}", "}", "// When the uri contains a protocoll or starts with a slash we assume", "// a full url is given and we don't have to add a path offest.", "if", "(", "strpos", "(", "$", "uri", ",", "'://'", ")", "===", "false", "&&", "substr", "(", "$", "uri", ",", "0", ",", "1", ")", "!==", "'/'", ")", "{", "$", "uri", "=", "static", "::", "$", "path_offset", ".", "$", "uri", ";", "}", "// Try to replace parameters in the uri and remove them from", "// the array so we can append them as get parameters", "foreach", "(", "$", "params", "as", "$", "key", "=>", "$", "value", ")", "{", "// replace the parameter provider", "if", "(", "is_numeric", "(", "$", "key", ")", "&&", "is_string", "(", "$", "value", ")", "&&", "$", "value", "[", "0", "]", "===", "':'", ")", "{", "$", "param_provider_key", "=", "substr", "(", "$", "value", ",", "1", ")", ";", "// remove the parameter provider from the parameter list", "unset", "(", "$", "params", "[", "$", "key", "]", ")", ";", "if", "(", "array_key_exists", "(", "$", "param_provider_key", ",", "static", "::", "$", "parameter_provider", ")", ")", "{", "$", "params", "=", "$", "params", "+", "call_user_func", "(", "static", "::", "$", "parameter_provider", "[", "$", "param_provider_key", "]", ")", ";", "}", "}", "// replace the parameters", "if", "(", "!", "is_array", "(", "$", "value", ")", ")", "{", "$", "uri", "=", "str_replace", "(", "':'", ".", "$", "key", ",", "$", "value", ",", "$", "uri", ",", "$", "count", ")", ";", "if", "(", "$", "count", ">", "0", ")", "{", "unset", "(", "$", "params", "[", "$", "key", "]", ")", ";", "}", "}", "}", "// Should we keep the get parameters? If retain is enabled", "// we merge the get parameter array with argument parameters", "if", "(", "$", "retain", ")", "{", "$", "params", "=", "array_merge", "(", "CCIn", "::", "$", "_instance", "->", "GET", ",", "$", "params", ")", ";", "}", "// When we still got parameters add them to the url", "if", "(", "!", "empty", "(", "$", "params", ")", ")", "{", "$", "uri", ".=", "'?'", ".", "http_build_query", "(", "$", "params", ")", ";", "}", "return", "$", "uri", ";", "}" ]
Generate an url @param string $uri @param array $params @param bool $retain Should we keep the get parameters? @return string
[ "Generate", "an", "url" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCUrl.php#L84-L167
ClanCats/Core
src/classes/CCUrl.php
CCUrl.alias
public static function alias( $alias, $params = array(), $retain = false ) { $route_params = array(); // to handle the suffix after a slash in an alias define $suffix = ''; if ( strpos( $alias, '/' ) !== false && $alias !== '/' ) { // slashes in aliases get appended as suffix list( $alias, $suffix ) = explode( '/', $alias ); $suffix = '/'.$suffix; } // get the parameters with the numeric keys so we can // pass them as route parameters like [any]-[num]-[num]/[any]/ foreach( $params as $key => $value ) { if ( is_int( $key ) ) { $route_params[] = $value; unset( $params[$key] ); } } return CCUrl::to( CCRouter::alias( $alias, $route_params ).$suffix, $params, $retain ); }
php
public static function alias( $alias, $params = array(), $retain = false ) { $route_params = array(); // to handle the suffix after a slash in an alias define $suffix = ''; if ( strpos( $alias, '/' ) !== false && $alias !== '/' ) { // slashes in aliases get appended as suffix list( $alias, $suffix ) = explode( '/', $alias ); $suffix = '/'.$suffix; } // get the parameters with the numeric keys so we can // pass them as route parameters like [any]-[num]-[num]/[any]/ foreach( $params as $key => $value ) { if ( is_int( $key ) ) { $route_params[] = $value; unset( $params[$key] ); } } return CCUrl::to( CCRouter::alias( $alias, $route_params ).$suffix, $params, $retain ); }
[ "public", "static", "function", "alias", "(", "$", "alias", ",", "$", "params", "=", "array", "(", ")", ",", "$", "retain", "=", "false", ")", "{", "$", "route_params", "=", "array", "(", ")", ";", "// to handle the suffix after a slash in an alias define", "$", "suffix", "=", "''", ";", "if", "(", "strpos", "(", "$", "alias", ",", "'/'", ")", "!==", "false", "&&", "$", "alias", "!==", "'/'", ")", "{", "// slashes in aliases get appended as suffix", "list", "(", "$", "alias", ",", "$", "suffix", ")", "=", "explode", "(", "'/'", ",", "$", "alias", ")", ";", "$", "suffix", "=", "'/'", ".", "$", "suffix", ";", "}", "// get the parameters with the numeric keys so we can ", "// pass them as route parameters like [any]-[num]-[num]/[any]/", "foreach", "(", "$", "params", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_int", "(", "$", "key", ")", ")", "{", "$", "route_params", "[", "]", "=", "$", "value", ";", "unset", "(", "$", "params", "[", "$", "key", "]", ")", ";", "}", "}", "return", "CCUrl", "::", "to", "(", "CCRouter", "::", "alias", "(", "$", "alias", ",", "$", "route_params", ")", ".", "$", "suffix", ",", "$", "params", ",", "$", "retain", ")", ";", "}" ]
Create an URL based on an router alias @param string $alias @param array $params @param bool $retain Should we keep the get parameters? @return string
[ "Create", "an", "URL", "based", "on", "an", "router", "alias" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCUrl.php#L177-L204
ClanCats/Core
src/classes/CCUrl.php
CCUrl.full
public static function full( $uri = '', $params = array(), $retain = false ) { return CCIn::protocol().'://'.CCIn::host().static::to( $uri, $params, $retain ); }
php
public static function full( $uri = '', $params = array(), $retain = false ) { return CCIn::protocol().'://'.CCIn::host().static::to( $uri, $params, $retain ); }
[ "public", "static", "function", "full", "(", "$", "uri", "=", "''", ",", "$", "params", "=", "array", "(", ")", ",", "$", "retain", "=", "false", ")", "{", "return", "CCIn", "::", "protocol", "(", ")", ".", "'://'", ".", "CCIn", "::", "host", "(", ")", ".", "static", "::", "to", "(", "$", "uri", ",", "$", "params", ",", "$", "retain", ")", ";", "}" ]
Create the full url including protocol and hostname @param string $uri @param array $params @param bool $retain Should we keep the get parameters? @return string
[ "Create", "the", "full", "url", "including", "protocol", "and", "hostname" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCUrl.php#L214-L217
ClanCats/Core
src/classes/CCUrl.php
CCUrl.secure
public static function secure( $uri = '', $params = array(), $retain = false ) { return 'https://'.CCIn::host().static::to( $uri, $params, $retain ); }
php
public static function secure( $uri = '', $params = array(), $retain = false ) { return 'https://'.CCIn::host().static::to( $uri, $params, $retain ); }
[ "public", "static", "function", "secure", "(", "$", "uri", "=", "''", ",", "$", "params", "=", "array", "(", ")", ",", "$", "retain", "=", "false", ")", "{", "return", "'https://'", ".", "CCIn", "::", "host", "(", ")", ".", "static", "::", "to", "(", "$", "uri", ",", "$", "params", ",", "$", "retain", ")", ";", "}" ]
Create the url and force the https protocol @param string $uri @param array $params @param bool $retain Should we keep the get parameters? @return string
[ "Create", "the", "url", "and", "force", "the", "https", "protocol" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCUrl.php#L227-L230
ClanCats/Core
src/classes/CCUrl.php
CCUrl.action
public static function action( $action = '', $params = array(), $retain = false ) { if ( $action == 'index' ) { $action = ''; } if ( CCRequest::current() && ( $route = CCRequest::current()->route ) ) { $uri = $route->uri; if ( !is_null( $route->action ) ) { $uri = substr( $uri, 0, strlen( $route->action ) * -1 ); } if ( substr( $uri, -1 ) != '/' ) { $uri .= '/'; } return static::to( $uri.$action, $params, $retain ); } throw new CCException( 'CCUrl::action - There has been no route executed yet.' ); }
php
public static function action( $action = '', $params = array(), $retain = false ) { if ( $action == 'index' ) { $action = ''; } if ( CCRequest::current() && ( $route = CCRequest::current()->route ) ) { $uri = $route->uri; if ( !is_null( $route->action ) ) { $uri = substr( $uri, 0, strlen( $route->action ) * -1 ); } if ( substr( $uri, -1 ) != '/' ) { $uri .= '/'; } return static::to( $uri.$action, $params, $retain ); } throw new CCException( 'CCUrl::action - There has been no route executed yet.' ); }
[ "public", "static", "function", "action", "(", "$", "action", "=", "''", ",", "$", "params", "=", "array", "(", ")", ",", "$", "retain", "=", "false", ")", "{", "if", "(", "$", "action", "==", "'index'", ")", "{", "$", "action", "=", "''", ";", "}", "if", "(", "CCRequest", "::", "current", "(", ")", "&&", "(", "$", "route", "=", "CCRequest", "::", "current", "(", ")", "->", "route", ")", ")", "{", "$", "uri", "=", "$", "route", "->", "uri", ";", "if", "(", "!", "is_null", "(", "$", "route", "->", "action", ")", ")", "{", "$", "uri", "=", "substr", "(", "$", "uri", ",", "0", ",", "strlen", "(", "$", "route", "->", "action", ")", "*", "-", "1", ")", ";", "}", "if", "(", "substr", "(", "$", "uri", ",", "-", "1", ")", "!=", "'/'", ")", "{", "$", "uri", ".=", "'/'", ";", "}", "return", "static", "::", "to", "(", "$", "uri", ".", "$", "action", ",", "$", "params", ",", "$", "retain", ")", ";", "}", "throw", "new", "CCException", "(", "'CCUrl::action - There has been no route executed yet.'", ")", ";", "}" ]
Get the url to a action of the current route !Important it's not possible to link between action on multiple routes This method always assumes that all actions are in the same route. If you want to link to another route using an alias you could do something like: CCUrl::to( '@myalias/myaction' ); @param string $action @param array $params @param bool $retain Should we keep the get parameters? @return string
[ "Get", "the", "url", "to", "a", "action", "of", "the", "current", "route" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCUrl.php#L258-L283
ClanCats/Core
src/classes/CCUrl.php
CCUrl.active
public static function active( $url ) { $url = parse_url( $url, PHP_URL_PATH ); if ( empty( $url ) ) { return false; } if ( $url[0] !== '/' ) { $url = static::to( $url ); } // when we are on "/" only "/" counts as active. if ( $url === '/' ) { return static::current() == $url; } // for everything else we cut the url and compare $cut = substr( static::current(), 0, strlen( $url ) ); return $cut == $url; }
php
public static function active( $url ) { $url = parse_url( $url, PHP_URL_PATH ); if ( empty( $url ) ) { return false; } if ( $url[0] !== '/' ) { $url = static::to( $url ); } // when we are on "/" only "/" counts as active. if ( $url === '/' ) { return static::current() == $url; } // for everything else we cut the url and compare $cut = substr( static::current(), 0, strlen( $url ) ); return $cut == $url; }
[ "public", "static", "function", "active", "(", "$", "url", ")", "{", "$", "url", "=", "parse_url", "(", "$", "url", ",", "PHP_URL_PATH", ")", ";", "if", "(", "empty", "(", "$", "url", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "url", "[", "0", "]", "!==", "'/'", ")", "{", "$", "url", "=", "static", "::", "to", "(", "$", "url", ")", ";", "}", "// when we are on \"/\" only \"/\" counts as active.", "if", "(", "$", "url", "===", "'/'", ")", "{", "return", "static", "::", "current", "(", ")", "==", "$", "url", ";", "}", "// for everything else we cut the url and compare", "$", "cut", "=", "substr", "(", "static", "::", "current", "(", ")", ",", "0", ",", "strlen", "(", "$", "url", ")", ")", ";", "return", "$", "cut", "==", "$", "url", ";", "}" ]
Is the given url active? This function ignores the domain and the parameters if the uri matches the current uri true will be returned. @param string $url @return bool
[ "Is", "the", "given", "url", "active?", "This", "function", "ignores", "the", "domain", "and", "the", "parameters", "if", "the", "uri", "matches", "the", "current", "uri", "true", "will", "be", "returned", "." ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCUrl.php#L293-L317
CakeCMS/Core
src/Plugin.php
Plugin.getData
public static function getData($plugin, $key = null) { $data = self::_checkData($plugin); if (empty($data) && $path = self::getManifestPath($plugin)) { if (FS::isFile($path)) { /** @noinspection PhpIncludeInspection */ $plgData = include $path; $plgData = (array) $plgData; if (!empty($plgData)) { self::$_data[$plugin] = $plgData; $data = $plgData; } } } return self::_getPluginData($data, $key); }
php
public static function getData($plugin, $key = null) { $data = self::_checkData($plugin); if (empty($data) && $path = self::getManifestPath($plugin)) { if (FS::isFile($path)) { /** @noinspection PhpIncludeInspection */ $plgData = include $path; $plgData = (array) $plgData; if (!empty($plgData)) { self::$_data[$plugin] = $plgData; $data = $plgData; } } } return self::_getPluginData($data, $key); }
[ "public", "static", "function", "getData", "(", "$", "plugin", ",", "$", "key", "=", "null", ")", "{", "$", "data", "=", "self", "::", "_checkData", "(", "$", "plugin", ")", ";", "if", "(", "empty", "(", "$", "data", ")", "&&", "$", "path", "=", "self", "::", "getManifestPath", "(", "$", "plugin", ")", ")", "{", "if", "(", "FS", "::", "isFile", "(", "$", "path", ")", ")", "{", "/** @noinspection PhpIncludeInspection */", "$", "plgData", "=", "include", "$", "path", ";", "$", "plgData", "=", "(", "array", ")", "$", "plgData", ";", "if", "(", "!", "empty", "(", "$", "plgData", ")", ")", "{", "self", "::", "$", "_data", "[", "$", "plugin", "]", "=", "$", "plgData", ";", "$", "data", "=", "$", "plgData", ";", "}", "}", "}", "return", "self", "::", "_getPluginData", "(", "$", "data", ",", "$", "key", ")", ";", "}" ]
Get plugin manifest data. @param string $plugin @param null|string $key @return Data
[ "Get", "plugin", "manifest", "data", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Plugin.php#L88-L104
CakeCMS/Core
src/Plugin.php
Plugin.getManifestPath
public static function getManifestPath($plugin) { if (self::loaded($plugin)) { return FS::clean(self::path($plugin) . DS . self::PLUGIN_MANIFEST); } return null; }
php
public static function getManifestPath($plugin) { if (self::loaded($plugin)) { return FS::clean(self::path($plugin) . DS . self::PLUGIN_MANIFEST); } return null; }
[ "public", "static", "function", "getManifestPath", "(", "$", "plugin", ")", "{", "if", "(", "self", "::", "loaded", "(", "$", "plugin", ")", ")", "{", "return", "FS", "::", "clean", "(", "self", "::", "path", "(", "$", "plugin", ")", ".", "DS", ".", "self", "::", "PLUGIN_MANIFEST", ")", ";", "}", "return", "null", ";", "}" ]
Get absolute plugin manifest file path. @param string $plugin @return null|string
[ "Get", "absolute", "plugin", "manifest", "file", "path", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Plugin.php#L123-L130
CakeCMS/Core
src/Plugin.php
Plugin.load
public static function load($plugin, array $config = []) { parent::load($plugin, $config); $plugin = (array) $plugin; foreach ($plugin as $name) { if ((bool) self::loaded($name)) { self::_addManifestCallback($name); Cms::mergeConfig('App.paths.locales', self::getLocalePath($name)); } } }
php
public static function load($plugin, array $config = []) { parent::load($plugin, $config); $plugin = (array) $plugin; foreach ($plugin as $name) { if ((bool) self::loaded($name)) { self::_addManifestCallback($name); Cms::mergeConfig('App.paths.locales', self::getLocalePath($name)); } } }
[ "public", "static", "function", "load", "(", "$", "plugin", ",", "array", "$", "config", "=", "[", "]", ")", "{", "parent", "::", "load", "(", "$", "plugin", ",", "$", "config", ")", ";", "$", "plugin", "=", "(", "array", ")", "$", "plugin", ";", "foreach", "(", "$", "plugin", "as", "$", "name", ")", "{", "if", "(", "(", "bool", ")", "self", "::", "loaded", "(", "$", "name", ")", ")", "{", "self", "::", "_addManifestCallback", "(", "$", "name", ")", ";", "Cms", "::", "mergeConfig", "(", "'App.paths.locales'", ",", "self", "::", "getLocalePath", "(", "$", "name", ")", ")", ";", "}", "}", "}" ]
Load the plugin. @param array|string $plugin @param array $config
[ "Load", "the", "plugin", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Plugin.php#L149-L160
CakeCMS/Core
src/Plugin.php
Plugin.loadList
public static function loadList(array $plugins) { foreach ($plugins as $name) { if (self::loaded($name)) { continue; } if ($path = self::_findPlugin($name)) { self::load($name, self::_getConfigForLoad($path)); } } }
php
public static function loadList(array $plugins) { foreach ($plugins as $name) { if (self::loaded($name)) { continue; } if ($path = self::_findPlugin($name)) { self::load($name, self::_getConfigForLoad($path)); } } }
[ "public", "static", "function", "loadList", "(", "array", "$", "plugins", ")", "{", "foreach", "(", "$", "plugins", "as", "$", "name", ")", "{", "if", "(", "self", "::", "loaded", "(", "$", "name", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "path", "=", "self", "::", "_findPlugin", "(", "$", "name", ")", ")", "{", "self", "::", "load", "(", "$", "name", ",", "self", "::", "_getConfigForLoad", "(", "$", "path", ")", ")", ";", "}", "}", "}" ]
Load list plugin. @param array $plugins @return void
[ "Load", "list", "plugin", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Plugin.php#L168-L179
CakeCMS/Core
src/Plugin.php
Plugin.manifestEvent
public static function manifestEvent() { $args = func_get_args(); $callback = array_shift($args); if (Arr::key($callback, self::$_eventList)) { $callbacks = self::$_eventList[$callback]; foreach ($callbacks as $method) { call_user_func_array($method, $args); } } }
php
public static function manifestEvent() { $args = func_get_args(); $callback = array_shift($args); if (Arr::key($callback, self::$_eventList)) { $callbacks = self::$_eventList[$callback]; foreach ($callbacks as $method) { call_user_func_array($method, $args); } } }
[ "public", "static", "function", "manifestEvent", "(", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "callback", "=", "array_shift", "(", "$", "args", ")", ";", "if", "(", "Arr", "::", "key", "(", "$", "callback", ",", "self", "::", "$", "_eventList", ")", ")", "{", "$", "callbacks", "=", "self", "::", "$", "_eventList", "[", "$", "callback", "]", ";", "foreach", "(", "$", "callbacks", "as", "$", "method", ")", "{", "call_user_func_array", "(", "$", "method", ",", "$", "args", ")", ";", "}", "}", "}" ]
Call plugin manifest callbacks. @return void
[ "Call", "plugin", "manifest", "callbacks", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Plugin.php#L186-L197
CakeCMS/Core
src/Plugin.php
Plugin.unload
public static function unload($plugin = null) { if (self::loaded($plugin)) { $locales = Configure::read('App.paths.locales'); foreach ($locales as $key => $path) { if ($path == self::getLocalePath($plugin)) { unset($locales[$key]); } } Configure::write('App.paths.locales', $locales); } parent::unload($plugin); }
php
public static function unload($plugin = null) { if (self::loaded($plugin)) { $locales = Configure::read('App.paths.locales'); foreach ($locales as $key => $path) { if ($path == self::getLocalePath($plugin)) { unset($locales[$key]); } } Configure::write('App.paths.locales', $locales); } parent::unload($plugin); }
[ "public", "static", "function", "unload", "(", "$", "plugin", "=", "null", ")", "{", "if", "(", "self", "::", "loaded", "(", "$", "plugin", ")", ")", "{", "$", "locales", "=", "Configure", "::", "read", "(", "'App.paths.locales'", ")", ";", "foreach", "(", "$", "locales", "as", "$", "key", "=>", "$", "path", ")", "{", "if", "(", "$", "path", "==", "self", "::", "getLocalePath", "(", "$", "plugin", ")", ")", "{", "unset", "(", "$", "locales", "[", "$", "key", "]", ")", ";", "}", "}", "Configure", "::", "write", "(", "'App.paths.locales'", ",", "$", "locales", ")", ";", "}", "parent", "::", "unload", "(", "$", "plugin", ")", ";", "}" ]
Unload the plugin. @param null|string $plugin @return void
[ "Unload", "the", "plugin", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Plugin.php#L205-L219
CakeCMS/Core
src/Plugin.php
Plugin._addManifestCallback
protected static function _addManifestCallback($plugin) { $data = Plugin::getData($plugin); foreach ($data as $name => $callback) { if (self::_isCallablePluginData($name, $plugin, $callback) && $plugin !== 'Core') { self::$_eventList[$name][$plugin] = $callback; } } }
php
protected static function _addManifestCallback($plugin) { $data = Plugin::getData($plugin); foreach ($data as $name => $callback) { if (self::_isCallablePluginData($name, $plugin, $callback) && $plugin !== 'Core') { self::$_eventList[$name][$plugin] = $callback; } } }
[ "protected", "static", "function", "_addManifestCallback", "(", "$", "plugin", ")", "{", "$", "data", "=", "Plugin", "::", "getData", "(", "$", "plugin", ")", ";", "foreach", "(", "$", "data", "as", "$", "name", "=>", "$", "callback", ")", "{", "if", "(", "self", "::", "_isCallablePluginData", "(", "$", "name", ",", "$", "plugin", ",", "$", "callback", ")", "&&", "$", "plugin", "!==", "'Core'", ")", "{", "self", "::", "$", "_eventList", "[", "$", "name", "]", "[", "$", "plugin", "]", "=", "$", "callback", ";", "}", "}", "}" ]
Registration plugin manifest callbacks. @param string $plugin @return void
[ "Registration", "plugin", "manifest", "callbacks", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Plugin.php#L227-L235