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
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
crossjoin/Css
src/Crossjoin/Css/Format/Rule/AtDocument/DocumentRule.php
DocumentRule.parseRuleString
protected function parseRuleString($ruleString) { if (is_string($ruleString)) { // Check for valid rule format // (with vendor prefix check to match e.g. "@-moz-document") if (preg_match( '/^[ \r\n\t\f]*@(' . self::getVendorPrefixRegExp("/") . ')?document[ \r\n\t\f]+(.*)$/i', $ruleString, $matches )) { $vendorPrefix = $matches[1]; $ruleString = trim($matches[2], " \r\n\t\f"); $charset = $this->getCharset(); $inFunction = false; $isEscaped = false; $conditions = []; $currentCondition = ""; $currentValue = ""; for ($i = 0, $j = mb_strlen($ruleString, $charset); $i < $j; $i++) { $char = mb_substr($ruleString, $i, 1, $charset); if ($char === "\\") { if ($isEscaped === false) { $isEscaped = true; } else { $isEscaped = false; } } else { if ($char === "(") { if ($isEscaped === false) { $inFunction = true; continue; } else { $currentValue .= $char; } } else if ($char === ")") { if ($isEscaped === false) { $conditions[$currentCondition] = trim($currentValue, " \r\n\t\f"); $currentCondition = ""; $currentValue = ""; $inFunction = false; continue; } else { $currentValue .= $char; } } else if ($char === "," || $char === " ") { if ($currentCondition === "" && $currentValue === "") { continue; } elseif ($currentValue !== "") { $currentValue .= $char; } else { // something wrong here... } } else { if ($inFunction === false) { $currentCondition .= $char; } else { $currentValue .= $char; } } } // Reset escaped flag if ($isEscaped === true && $char !== "\\") { $isEscaped = false; } } foreach ($conditions as $key => $value) { $conditions[$key] = Placeholder::replaceStringPlaceholders($value, true); } if (isset($conditions["url"])) { $this->setUrl($conditions["url"]); } if (isset($conditions["url-prefix"])) { $this->setUrlPrefix($conditions["url-prefix"]); } if (isset($conditions["domain"])) { $this->setDomain($conditions["domain"]); } if (isset($conditions["regexp"])) { $this->setRegexp($conditions["regexp"]); } if ($vendorPrefix !== "") { $this->setVendorPrefix($vendorPrefix); } } else { throw new \InvalidArgumentException("Invalid format for @document rule."); } } else { throw new \InvalidArgumentException( "Invalid type '" . gettype($ruleString) . "' for argument 'ruleString' given. String expected." ); } }
php
protected function parseRuleString($ruleString) { if (is_string($ruleString)) { // Check for valid rule format // (with vendor prefix check to match e.g. "@-moz-document") if (preg_match( '/^[ \r\n\t\f]*@(' . self::getVendorPrefixRegExp("/") . ')?document[ \r\n\t\f]+(.*)$/i', $ruleString, $matches )) { $vendorPrefix = $matches[1]; $ruleString = trim($matches[2], " \r\n\t\f"); $charset = $this->getCharset(); $inFunction = false; $isEscaped = false; $conditions = []; $currentCondition = ""; $currentValue = ""; for ($i = 0, $j = mb_strlen($ruleString, $charset); $i < $j; $i++) { $char = mb_substr($ruleString, $i, 1, $charset); if ($char === "\\") { if ($isEscaped === false) { $isEscaped = true; } else { $isEscaped = false; } } else { if ($char === "(") { if ($isEscaped === false) { $inFunction = true; continue; } else { $currentValue .= $char; } } else if ($char === ")") { if ($isEscaped === false) { $conditions[$currentCondition] = trim($currentValue, " \r\n\t\f"); $currentCondition = ""; $currentValue = ""; $inFunction = false; continue; } else { $currentValue .= $char; } } else if ($char === "," || $char === " ") { if ($currentCondition === "" && $currentValue === "") { continue; } elseif ($currentValue !== "") { $currentValue .= $char; } else { // something wrong here... } } else { if ($inFunction === false) { $currentCondition .= $char; } else { $currentValue .= $char; } } } // Reset escaped flag if ($isEscaped === true && $char !== "\\") { $isEscaped = false; } } foreach ($conditions as $key => $value) { $conditions[$key] = Placeholder::replaceStringPlaceholders($value, true); } if (isset($conditions["url"])) { $this->setUrl($conditions["url"]); } if (isset($conditions["url-prefix"])) { $this->setUrlPrefix($conditions["url-prefix"]); } if (isset($conditions["domain"])) { $this->setDomain($conditions["domain"]); } if (isset($conditions["regexp"])) { $this->setRegexp($conditions["regexp"]); } if ($vendorPrefix !== "") { $this->setVendorPrefix($vendorPrefix); } } else { throw new \InvalidArgumentException("Invalid format for @document rule."); } } else { throw new \InvalidArgumentException( "Invalid type '" . gettype($ruleString) . "' for argument 'ruleString' given. String expected." ); } }
[ "protected", "function", "parseRuleString", "(", "$", "ruleString", ")", "{", "if", "(", "is_string", "(", "$", "ruleString", ")", ")", "{", "// Check for valid rule format", "// (with vendor prefix check to match e.g. \"@-moz-document\")", "if", "(", "preg_match", "(", "'/^[ \\r\\n\\t\\f]*@('", ".", "self", "::", "getVendorPrefixRegExp", "(", "\"/\"", ")", ".", "')?document[ \\r\\n\\t\\f]+(.*)$/i'", ",", "$", "ruleString", ",", "$", "matches", ")", ")", "{", "$", "vendorPrefix", "=", "$", "matches", "[", "1", "]", ";", "$", "ruleString", "=", "trim", "(", "$", "matches", "[", "2", "]", ",", "\" \\r\\n\\t\\f\"", ")", ";", "$", "charset", "=", "$", "this", "->", "getCharset", "(", ")", ";", "$", "inFunction", "=", "false", ";", "$", "isEscaped", "=", "false", ";", "$", "conditions", "=", "[", "]", ";", "$", "currentCondition", "=", "\"\"", ";", "$", "currentValue", "=", "\"\"", ";", "for", "(", "$", "i", "=", "0", ",", "$", "j", "=", "mb_strlen", "(", "$", "ruleString", ",", "$", "charset", ")", ";", "$", "i", "<", "$", "j", ";", "$", "i", "++", ")", "{", "$", "char", "=", "mb_substr", "(", "$", "ruleString", ",", "$", "i", ",", "1", ",", "$", "charset", ")", ";", "if", "(", "$", "char", "===", "\"\\\\\"", ")", "{", "if", "(", "$", "isEscaped", "===", "false", ")", "{", "$", "isEscaped", "=", "true", ";", "}", "else", "{", "$", "isEscaped", "=", "false", ";", "}", "}", "else", "{", "if", "(", "$", "char", "===", "\"(\"", ")", "{", "if", "(", "$", "isEscaped", "===", "false", ")", "{", "$", "inFunction", "=", "true", ";", "continue", ";", "}", "else", "{", "$", "currentValue", ".=", "$", "char", ";", "}", "}", "else", "if", "(", "$", "char", "===", "\")\"", ")", "{", "if", "(", "$", "isEscaped", "===", "false", ")", "{", "$", "conditions", "[", "$", "currentCondition", "]", "=", "trim", "(", "$", "currentValue", ",", "\" \\r\\n\\t\\f\"", ")", ";", "$", "currentCondition", "=", "\"\"", ";", "$", "currentValue", "=", "\"\"", ";", "$", "inFunction", "=", "false", ";", "continue", ";", "}", "else", "{", "$", "currentValue", ".=", "$", "char", ";", "}", "}", "else", "if", "(", "$", "char", "===", "\",\"", "||", "$", "char", "===", "\" \"", ")", "{", "if", "(", "$", "currentCondition", "===", "\"\"", "&&", "$", "currentValue", "===", "\"\"", ")", "{", "continue", ";", "}", "elseif", "(", "$", "currentValue", "!==", "\"\"", ")", "{", "$", "currentValue", ".=", "$", "char", ";", "}", "else", "{", "// something wrong here...", "}", "}", "else", "{", "if", "(", "$", "inFunction", "===", "false", ")", "{", "$", "currentCondition", ".=", "$", "char", ";", "}", "else", "{", "$", "currentValue", ".=", "$", "char", ";", "}", "}", "}", "// Reset escaped flag", "if", "(", "$", "isEscaped", "===", "true", "&&", "$", "char", "!==", "\"\\\\\"", ")", "{", "$", "isEscaped", "=", "false", ";", "}", "}", "foreach", "(", "$", "conditions", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "conditions", "[", "$", "key", "]", "=", "Placeholder", "::", "replaceStringPlaceholders", "(", "$", "value", ",", "true", ")", ";", "}", "if", "(", "isset", "(", "$", "conditions", "[", "\"url\"", "]", ")", ")", "{", "$", "this", "->", "setUrl", "(", "$", "conditions", "[", "\"url\"", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "conditions", "[", "\"url-prefix\"", "]", ")", ")", "{", "$", "this", "->", "setUrlPrefix", "(", "$", "conditions", "[", "\"url-prefix\"", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "conditions", "[", "\"domain\"", "]", ")", ")", "{", "$", "this", "->", "setDomain", "(", "$", "conditions", "[", "\"domain\"", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "conditions", "[", "\"regexp\"", "]", ")", ")", "{", "$", "this", "->", "setRegexp", "(", "$", "conditions", "[", "\"regexp\"", "]", ")", ";", "}", "if", "(", "$", "vendorPrefix", "!==", "\"\"", ")", "{", "$", "this", "->", "setVendorPrefix", "(", "$", "vendorPrefix", ")", ";", "}", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Invalid format for @document rule.\"", ")", ";", "}", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Invalid type '\"", ".", "gettype", "(", "$", "ruleString", ")", ".", "\"' for argument 'ruleString' given. String expected.\"", ")", ";", "}", "}" ]
Parses the charset rule. @param string $ruleString
[ "Parses", "the", "charset", "rule", "." ]
train
https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Format/Rule/AtDocument/DocumentRule.php#L156-L252
verschoof/bunq-api
src/Resource/UserResource.php
UserResource.getUser
public function getUser($id) { $response = $this->client->get($this->getResourceEndpoint() . '/' . (int)$id); return $response['Response'][0]['UserCompany']; }
php
public function getUser($id) { $response = $this->client->get($this->getResourceEndpoint() . '/' . (int)$id); return $response['Response'][0]['UserCompany']; }
[ "public", "function", "getUser", "(", "$", "id", ")", "{", "$", "response", "=", "$", "this", "->", "client", "->", "get", "(", "$", "this", "->", "getResourceEndpoint", "(", ")", ".", "'/'", ".", "(", "int", ")", "$", "id", ")", ";", "return", "$", "response", "[", "'Response'", "]", "[", "0", "]", "[", "'UserCompany'", "]", ";", "}" ]
Gets a user its information. @param integer $id @return array
[ "Gets", "a", "user", "its", "information", "." ]
train
https://github.com/verschoof/bunq-api/blob/df9aa19f384275f4f0deb26de0cb5e5f8b45ffcd/src/Resource/UserResource.php#L39-L44
stubbles/stubbles-webapp-core
src/main/php/routing/MethodNotAllowed.php
MethodNotAllowed.resolve
public function resolve(Request $request, Response $response) { return $response->methodNotAllowed( $request->method(), $this->allowedMethods ); }
php
public function resolve(Request $request, Response $response) { return $response->methodNotAllowed( $request->method(), $this->allowedMethods ); }
[ "public", "function", "resolve", "(", "Request", "$", "request", ",", "Response", "$", "response", ")", "{", "return", "$", "response", "->", "methodNotAllowed", "(", "$", "request", "->", "method", "(", ")", ",", "$", "this", "->", "allowedMethods", ")", ";", "}" ]
creates processor instance @param \stubbles\webapp\Request $request current request @param \stubbles\webapp\Response $response response to send @return \stubbles\webapp\response\Error
[ "creates", "processor", "instance" ]
train
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/routing/MethodNotAllowed.php#L70-L76
pickles2/px2-sitemapexcel
php/helper/parseSitemapCsv.php
pxplugin_sitemapExcel_helper_parseSitemapCsv.load_sitemap_csv
private function load_sitemap_csv(){ // $path_sitemap_dir = $this->px->get_path_homedir().'sitemaps/'; // $ary_sitemap_files = $this->px->fs()->ls( $path_sitemap_dir ); // sort($ary_sitemap_files); // $path_top の設定値をチューニング $path_top = $this->conf->path_top; if(!strlen( $path_top )){ $path_top = '/'; } $path_top = preg_replace( '/\/$/si' , '/'.$this->px->get_directory_index_primary() , $path_top );//index.htmlを付加する。 // サイトマップをロード $num_auto_pid = 0; $tmp_sitemap = $this->px->fs()->read_csv( $this->path_csv ); foreach ($tmp_sitemap as $row_number=>$row) { set_time_limit(30);//タイマー延命 $num_auto_pid++; $tmp_array = array(); if( preg_match( '/^(?:\*)/is' , $row[0] ) ){ if( $row_number > 0 ){ // アスタリスク始まりの場合はコメント行とみなす。 continue; } // アスタリスク始まりでも、0行目の場合は、定義行とみなす。 // 定義行とみなす条件: 0行目の全セルがアスタリスク始まりであること。 $is_definition_row = true; foreach($row as $cell_value){ if( !preg_match( '/^(?:\*)/is' , $cell_value ) ){ $is_definition_row = false; } } if( !$is_definition_row ){ continue; } $tmp_sitemap_definition = array(); $tmp_col_id = 'A'; foreach($row as $tmp_col_number=>$cell_value){ $cell_value = trim(preg_replace('/^\*/si', '', $cell_value)); $tmp_sitemap_definition[$cell_value] = array( 'num'=>$tmp_col_number, 'col'=>$tmp_col_id++, 'key'=>$cell_value, 'name'=>$cell_value, ); } unset($is_definition_row); unset($cell_value); continue; } foreach ($tmp_sitemap_definition as $defrow) { $tmp_array[$defrow['key']] = $row[$defrow['num']]; } if( !preg_match( '/^(?:\/|alias\:|data\:|javascript\:|\#|[a-zA-Z0-9]+\:\/\/)/is' , $tmp_array['path'] ) ){ // 不正な形式のチェック continue; } switch( $this->get_path_type( $tmp_array['path'] ) ){ case 'full_url': case 'data': case 'javascript': case 'anchor': // 直リンク系のパスをエイリアス扱いにする $tmp_array['path'] = preg_replace('/^(?:alias:)?/s', 'alias:', $tmp_array['path']); break; default: // スラ止のパスに index.html を付加する。 // ただし、JS、アンカー、外部リンクには適用しない。 $tmp_array['path'] = preg_replace( '/\/((?:\?|\#).*)?$/si' , '/'.$this->px->get_directory_index_primary().'$1' , $tmp_array['path'] ); break; } if( !strlen( $tmp_array['id'] ) ){ //ページID文字列を自動生成 $tmp_id = ':auto_page_id.'.($num_auto_pid); $tmp_array['id'] = $tmp_id; unset($tmp_id); } // project.path_top の設定に対する処理 if( $tmp_array['path'] == $path_top ){ $tmp_array['id'] = ''; }elseif( !strlen($tmp_array['id']) ){ $tmp_array['id'] = ':auto_page_id.'.($num_auto_pid); } if($this->get_path_type( $tmp_array['path'] ) == 'dynamic'){ //ダイナミックパスのインデックス作成 $tmp_preg_pattern = $tmp_array['path']; $preg_pattern = ''; while(1){ if( !preg_match('/^(.*?)\{(\$|\*)([a-zA-Z0-9\-\_]*)\}(.*)$/s',$tmp_preg_pattern,$tmp_matched) ){ $preg_pattern .= preg_quote($tmp_preg_pattern,'/'); break; } $preg_pattern .= preg_quote($tmp_matched[1],'/'); switch( $tmp_matched[2] ){ case '$': $preg_pattern .= '([a-zA-Z0-9\-\_]+)';break; case '*': $preg_pattern .= '(.*?)';break; } $tmp_preg_pattern = $tmp_matched[4]; continue; } preg_match_all('/\{(\$|\*)([a-zA-Z0-9\-\_]*)\}/',$tmp_array['path'],$pattern_map); $tmp_path_original = $tmp_array['path']; $tmp_array['path'] = preg_replace('/'.preg_quote('{','/').'(\$|\*)([a-zA-Z0-9\-\_]*)'.preg_quote('}','/').'/s','$2',$tmp_array['path']); array_push( $this->sitemap_dynamic_paths, array( 'path'=>$tmp_array['path'], 'path_original'=>$tmp_path_original, 'id'=>$tmp_array['id'], 'preg'=>'/^'.$preg_pattern.'$/s', 'pattern_map'=>$pattern_map[2], ) ); if( !strlen( $tmp_array['content'] ) ){ $tmp_array['content'] = $tmp_array['path']; } $tmp_array['path'] = $tmp_path_original; unset($preg_pattern); unset($pattern_map); unset($tmp_path_original); } if( !strlen( $tmp_array['content'] ) ){ $tmp_array['content'] = $tmp_array['path']; $tmp_array['content'] = preg_replace('/(?:\?|\#).*$/s','',$tmp_array['content']); $tmp_array['content'] = preg_replace('/\/$/s','/'.$this->px->get_directory_index_primary(), $tmp_array['content']); } $tmp_array['content'] = preg_replace( '/\/$/si' , '/'.$this->px->get_directory_index_primary() , $tmp_array['content'] );//index.htmlを付加する。 if( preg_match( '/^alias\:/s' , $tmp_array['path'] ) ){ //エイリアスの値調整 $tmp_array['content'] = null; $tmp_array['path'] = preg_replace( '/^alias\:/s' , 'alias'.$num_auto_pid.':' , $tmp_array['path'] ); } // パンくず欄の先頭が > から始まっていた場合、削除 $tmp_array['logical_path'] = @preg_replace( '/^\>+/s' , '' , $tmp_array['logical_path'] ); $this->sitemap_array[$tmp_array['path']] = $tmp_array; $this->sitemap_id_map[$tmp_array['id']] = $tmp_array['path']; } unset($tmp_sitemap); // logical_path から、親子関係を整理 foreach ($this->sitemap_array as $row_number=>$row) { if( !strlen($row['id']) ){ continue; } if( array_key_exists('logical_path', $row) ){ $breadcrumb_ary = explode('>', $row['logical_path']); $tmp_tree_key = $this->get_page_info($breadcrumb_ary[count($breadcrumb_ary)-1], 'path'); if( is_null($tmp_tree_key) ){ // 親がいない continue; } if( !array_key_exists($tmp_tree_key, $this->sitemap_page_tree) ){ $this->sitemap_page_tree[$tmp_tree_key] = array(); $this->sitemap_page_tree[$tmp_tree_key]['children'] = array(); $this->sitemap_page_tree[$tmp_tree_key]['children_all'] = array(); } array_push($this->sitemap_page_tree[$tmp_tree_key]['children'], $row['id']); array_push($this->sitemap_page_tree[$tmp_tree_key]['children_all'], $row['id']); // $tmp_array['logical_path'] } } // var_dump($this->sitemap_array); // var_dump($this->sitemap_id_map); return true; }
php
private function load_sitemap_csv(){ // $path_sitemap_dir = $this->px->get_path_homedir().'sitemaps/'; // $ary_sitemap_files = $this->px->fs()->ls( $path_sitemap_dir ); // sort($ary_sitemap_files); // $path_top の設定値をチューニング $path_top = $this->conf->path_top; if(!strlen( $path_top )){ $path_top = '/'; } $path_top = preg_replace( '/\/$/si' , '/'.$this->px->get_directory_index_primary() , $path_top );//index.htmlを付加する。 // サイトマップをロード $num_auto_pid = 0; $tmp_sitemap = $this->px->fs()->read_csv( $this->path_csv ); foreach ($tmp_sitemap as $row_number=>$row) { set_time_limit(30);//タイマー延命 $num_auto_pid++; $tmp_array = array(); if( preg_match( '/^(?:\*)/is' , $row[0] ) ){ if( $row_number > 0 ){ // アスタリスク始まりの場合はコメント行とみなす。 continue; } // アスタリスク始まりでも、0行目の場合は、定義行とみなす。 // 定義行とみなす条件: 0行目の全セルがアスタリスク始まりであること。 $is_definition_row = true; foreach($row as $cell_value){ if( !preg_match( '/^(?:\*)/is' , $cell_value ) ){ $is_definition_row = false; } } if( !$is_definition_row ){ continue; } $tmp_sitemap_definition = array(); $tmp_col_id = 'A'; foreach($row as $tmp_col_number=>$cell_value){ $cell_value = trim(preg_replace('/^\*/si', '', $cell_value)); $tmp_sitemap_definition[$cell_value] = array( 'num'=>$tmp_col_number, 'col'=>$tmp_col_id++, 'key'=>$cell_value, 'name'=>$cell_value, ); } unset($is_definition_row); unset($cell_value); continue; } foreach ($tmp_sitemap_definition as $defrow) { $tmp_array[$defrow['key']] = $row[$defrow['num']]; } if( !preg_match( '/^(?:\/|alias\:|data\:|javascript\:|\#|[a-zA-Z0-9]+\:\/\/)/is' , $tmp_array['path'] ) ){ // 不正な形式のチェック continue; } switch( $this->get_path_type( $tmp_array['path'] ) ){ case 'full_url': case 'data': case 'javascript': case 'anchor': // 直リンク系のパスをエイリアス扱いにする $tmp_array['path'] = preg_replace('/^(?:alias:)?/s', 'alias:', $tmp_array['path']); break; default: // スラ止のパスに index.html を付加する。 // ただし、JS、アンカー、外部リンクには適用しない。 $tmp_array['path'] = preg_replace( '/\/((?:\?|\#).*)?$/si' , '/'.$this->px->get_directory_index_primary().'$1' , $tmp_array['path'] ); break; } if( !strlen( $tmp_array['id'] ) ){ //ページID文字列を自動生成 $tmp_id = ':auto_page_id.'.($num_auto_pid); $tmp_array['id'] = $tmp_id; unset($tmp_id); } // project.path_top の設定に対する処理 if( $tmp_array['path'] == $path_top ){ $tmp_array['id'] = ''; }elseif( !strlen($tmp_array['id']) ){ $tmp_array['id'] = ':auto_page_id.'.($num_auto_pid); } if($this->get_path_type( $tmp_array['path'] ) == 'dynamic'){ //ダイナミックパスのインデックス作成 $tmp_preg_pattern = $tmp_array['path']; $preg_pattern = ''; while(1){ if( !preg_match('/^(.*?)\{(\$|\*)([a-zA-Z0-9\-\_]*)\}(.*)$/s',$tmp_preg_pattern,$tmp_matched) ){ $preg_pattern .= preg_quote($tmp_preg_pattern,'/'); break; } $preg_pattern .= preg_quote($tmp_matched[1],'/'); switch( $tmp_matched[2] ){ case '$': $preg_pattern .= '([a-zA-Z0-9\-\_]+)';break; case '*': $preg_pattern .= '(.*?)';break; } $tmp_preg_pattern = $tmp_matched[4]; continue; } preg_match_all('/\{(\$|\*)([a-zA-Z0-9\-\_]*)\}/',$tmp_array['path'],$pattern_map); $tmp_path_original = $tmp_array['path']; $tmp_array['path'] = preg_replace('/'.preg_quote('{','/').'(\$|\*)([a-zA-Z0-9\-\_]*)'.preg_quote('}','/').'/s','$2',$tmp_array['path']); array_push( $this->sitemap_dynamic_paths, array( 'path'=>$tmp_array['path'], 'path_original'=>$tmp_path_original, 'id'=>$tmp_array['id'], 'preg'=>'/^'.$preg_pattern.'$/s', 'pattern_map'=>$pattern_map[2], ) ); if( !strlen( $tmp_array['content'] ) ){ $tmp_array['content'] = $tmp_array['path']; } $tmp_array['path'] = $tmp_path_original; unset($preg_pattern); unset($pattern_map); unset($tmp_path_original); } if( !strlen( $tmp_array['content'] ) ){ $tmp_array['content'] = $tmp_array['path']; $tmp_array['content'] = preg_replace('/(?:\?|\#).*$/s','',$tmp_array['content']); $tmp_array['content'] = preg_replace('/\/$/s','/'.$this->px->get_directory_index_primary(), $tmp_array['content']); } $tmp_array['content'] = preg_replace( '/\/$/si' , '/'.$this->px->get_directory_index_primary() , $tmp_array['content'] );//index.htmlを付加する。 if( preg_match( '/^alias\:/s' , $tmp_array['path'] ) ){ //エイリアスの値調整 $tmp_array['content'] = null; $tmp_array['path'] = preg_replace( '/^alias\:/s' , 'alias'.$num_auto_pid.':' , $tmp_array['path'] ); } // パンくず欄の先頭が > から始まっていた場合、削除 $tmp_array['logical_path'] = @preg_replace( '/^\>+/s' , '' , $tmp_array['logical_path'] ); $this->sitemap_array[$tmp_array['path']] = $tmp_array; $this->sitemap_id_map[$tmp_array['id']] = $tmp_array['path']; } unset($tmp_sitemap); // logical_path から、親子関係を整理 foreach ($this->sitemap_array as $row_number=>$row) { if( !strlen($row['id']) ){ continue; } if( array_key_exists('logical_path', $row) ){ $breadcrumb_ary = explode('>', $row['logical_path']); $tmp_tree_key = $this->get_page_info($breadcrumb_ary[count($breadcrumb_ary)-1], 'path'); if( is_null($tmp_tree_key) ){ // 親がいない continue; } if( !array_key_exists($tmp_tree_key, $this->sitemap_page_tree) ){ $this->sitemap_page_tree[$tmp_tree_key] = array(); $this->sitemap_page_tree[$tmp_tree_key]['children'] = array(); $this->sitemap_page_tree[$tmp_tree_key]['children_all'] = array(); } array_push($this->sitemap_page_tree[$tmp_tree_key]['children'], $row['id']); array_push($this->sitemap_page_tree[$tmp_tree_key]['children_all'], $row['id']); // $tmp_array['logical_path'] } } // var_dump($this->sitemap_array); // var_dump($this->sitemap_id_map); return true; }
[ "private", "function", "load_sitemap_csv", "(", ")", "{", "// $path_sitemap_dir = $this->px->get_path_homedir().'sitemaps/';\r", "// $ary_sitemap_files = $this->px->fs()->ls( $path_sitemap_dir );\r", "// sort($ary_sitemap_files);\r", "// $path_top の設定値をチューニング\r", "$", "path_top", "=", "$", "this", "->", "conf", "->", "path_top", ";", "if", "(", "!", "strlen", "(", "$", "path_top", ")", ")", "{", "$", "path_top", "=", "'/'", ";", "}", "$", "path_top", "=", "preg_replace", "(", "'/\\/$/si'", ",", "'/'", ".", "$", "this", "->", "px", "->", "get_directory_index_primary", "(", ")", ",", "$", "path_top", ")", ";", "//index.htmlを付加する。\r", "// サイトマップをロード\r", "$", "num_auto_pid", "=", "0", ";", "$", "tmp_sitemap", "=", "$", "this", "->", "px", "->", "fs", "(", ")", "->", "read_csv", "(", "$", "this", "->", "path_csv", ")", ";", "foreach", "(", "$", "tmp_sitemap", "as", "$", "row_number", "=>", "$", "row", ")", "{", "set_time_limit", "(", "30", ")", ";", "//タイマー延命\r", "$", "num_auto_pid", "++", ";", "$", "tmp_array", "=", "array", "(", ")", ";", "if", "(", "preg_match", "(", "'/^(?:\\*)/is'", ",", "$", "row", "[", "0", "]", ")", ")", "{", "if", "(", "$", "row_number", ">", "0", ")", "{", "// アスタリスク始まりの場合はコメント行とみなす。\r", "continue", ";", "}", "// アスタリスク始まりでも、0行目の場合は、定義行とみなす。\r", "// 定義行とみなす条件: 0行目の全セルがアスタリスク始まりであること。\r", "$", "is_definition_row", "=", "true", ";", "foreach", "(", "$", "row", "as", "$", "cell_value", ")", "{", "if", "(", "!", "preg_match", "(", "'/^(?:\\*)/is'", ",", "$", "cell_value", ")", ")", "{", "$", "is_definition_row", "=", "false", ";", "}", "}", "if", "(", "!", "$", "is_definition_row", ")", "{", "continue", ";", "}", "$", "tmp_sitemap_definition", "=", "array", "(", ")", ";", "$", "tmp_col_id", "=", "'A'", ";", "foreach", "(", "$", "row", "as", "$", "tmp_col_number", "=>", "$", "cell_value", ")", "{", "$", "cell_value", "=", "trim", "(", "preg_replace", "(", "'/^\\*/si'", ",", "''", ",", "$", "cell_value", ")", ")", ";", "$", "tmp_sitemap_definition", "[", "$", "cell_value", "]", "=", "array", "(", "'num'", "=>", "$", "tmp_col_number", ",", "'col'", "=>", "$", "tmp_col_id", "++", ",", "'key'", "=>", "$", "cell_value", ",", "'name'", "=>", "$", "cell_value", ",", ")", ";", "}", "unset", "(", "$", "is_definition_row", ")", ";", "unset", "(", "$", "cell_value", ")", ";", "continue", ";", "}", "foreach", "(", "$", "tmp_sitemap_definition", "as", "$", "defrow", ")", "{", "$", "tmp_array", "[", "$", "defrow", "[", "'key'", "]", "]", "=", "$", "row", "[", "$", "defrow", "[", "'num'", "]", "]", ";", "}", "if", "(", "!", "preg_match", "(", "'/^(?:\\/|alias\\:|data\\:|javascript\\:|\\#|[a-zA-Z0-9]+\\:\\/\\/)/is'", ",", "$", "tmp_array", "[", "'path'", "]", ")", ")", "{", "// 不正な形式のチェック\r", "continue", ";", "}", "switch", "(", "$", "this", "->", "get_path_type", "(", "$", "tmp_array", "[", "'path'", "]", ")", ")", "{", "case", "'full_url'", ":", "case", "'data'", ":", "case", "'javascript'", ":", "case", "'anchor'", ":", "// 直リンク系のパスをエイリアス扱いにする\r", "$", "tmp_array", "[", "'path'", "]", "=", "preg_replace", "(", "'/^(?:alias:)?/s'", ",", "'alias:'", ",", "$", "tmp_array", "[", "'path'", "]", ")", ";", "break", ";", "default", ":", "// スラ止のパスに index.html を付加する。\r", "// ただし、JS、アンカー、外部リンクには適用しない。\r", "$", "tmp_array", "[", "'path'", "]", "=", "preg_replace", "(", "'/\\/((?:\\?|\\#).*)?$/si'", ",", "'/'", ".", "$", "this", "->", "px", "->", "get_directory_index_primary", "(", ")", ".", "'$1'", ",", "$", "tmp_array", "[", "'path'", "]", ")", ";", "break", ";", "}", "if", "(", "!", "strlen", "(", "$", "tmp_array", "[", "'id'", "]", ")", ")", "{", "//ページID文字列を自動生成\r", "$", "tmp_id", "=", "':auto_page_id.'", ".", "(", "$", "num_auto_pid", ")", ";", "$", "tmp_array", "[", "'id'", "]", "=", "$", "tmp_id", ";", "unset", "(", "$", "tmp_id", ")", ";", "}", "// project.path_top の設定に対する処理\r", "if", "(", "$", "tmp_array", "[", "'path'", "]", "==", "$", "path_top", ")", "{", "$", "tmp_array", "[", "'id'", "]", "=", "''", ";", "}", "elseif", "(", "!", "strlen", "(", "$", "tmp_array", "[", "'id'", "]", ")", ")", "{", "$", "tmp_array", "[", "'id'", "]", "=", "':auto_page_id.'", ".", "(", "$", "num_auto_pid", ")", ";", "}", "if", "(", "$", "this", "->", "get_path_type", "(", "$", "tmp_array", "[", "'path'", "]", ")", "==", "'dynamic'", ")", "{", "//ダイナミックパスのインデックス作成\r", "$", "tmp_preg_pattern", "=", "$", "tmp_array", "[", "'path'", "]", ";", "$", "preg_pattern", "=", "''", ";", "while", "(", "1", ")", "{", "if", "(", "!", "preg_match", "(", "'/^(.*?)\\{(\\$|\\*)([a-zA-Z0-9\\-\\_]*)\\}(.*)$/s'", ",", "$", "tmp_preg_pattern", ",", "$", "tmp_matched", ")", ")", "{", "$", "preg_pattern", ".=", "preg_quote", "(", "$", "tmp_preg_pattern", ",", "'/'", ")", ";", "break", ";", "}", "$", "preg_pattern", ".=", "preg_quote", "(", "$", "tmp_matched", "[", "1", "]", ",", "'/'", ")", ";", "switch", "(", "$", "tmp_matched", "[", "2", "]", ")", "{", "case", "'$'", ":", "$", "preg_pattern", ".=", "'([a-zA-Z0-9\\-\\_]+)'", ";", "break", ";", "case", "'*'", ":", "$", "preg_pattern", ".=", "'(.*?)'", ";", "break", ";", "}", "$", "tmp_preg_pattern", "=", "$", "tmp_matched", "[", "4", "]", ";", "continue", ";", "}", "preg_match_all", "(", "'/\\{(\\$|\\*)([a-zA-Z0-9\\-\\_]*)\\}/'", ",", "$", "tmp_array", "[", "'path'", "]", ",", "$", "pattern_map", ")", ";", "$", "tmp_path_original", "=", "$", "tmp_array", "[", "'path'", "]", ";", "$", "tmp_array", "[", "'path'", "]", "=", "preg_replace", "(", "'/'", ".", "preg_quote", "(", "'{'", ",", "'/'", ")", ".", "'(\\$|\\*)([a-zA-Z0-9\\-\\_]*)'", ".", "preg_quote", "(", "'}'", ",", "'/'", ")", ".", "'/s'", ",", "'$2'", ",", "$", "tmp_array", "[", "'path'", "]", ")", ";", "array_push", "(", "$", "this", "->", "sitemap_dynamic_paths", ",", "array", "(", "'path'", "=>", "$", "tmp_array", "[", "'path'", "]", ",", "'path_original'", "=>", "$", "tmp_path_original", ",", "'id'", "=>", "$", "tmp_array", "[", "'id'", "]", ",", "'preg'", "=>", "'/^'", ".", "$", "preg_pattern", ".", "'$/s'", ",", "'pattern_map'", "=>", "$", "pattern_map", "[", "2", "]", ",", ")", ")", ";", "if", "(", "!", "strlen", "(", "$", "tmp_array", "[", "'content'", "]", ")", ")", "{", "$", "tmp_array", "[", "'content'", "]", "=", "$", "tmp_array", "[", "'path'", "]", ";", "}", "$", "tmp_array", "[", "'path'", "]", "=", "$", "tmp_path_original", ";", "unset", "(", "$", "preg_pattern", ")", ";", "unset", "(", "$", "pattern_map", ")", ";", "unset", "(", "$", "tmp_path_original", ")", ";", "}", "if", "(", "!", "strlen", "(", "$", "tmp_array", "[", "'content'", "]", ")", ")", "{", "$", "tmp_array", "[", "'content'", "]", "=", "$", "tmp_array", "[", "'path'", "]", ";", "$", "tmp_array", "[", "'content'", "]", "=", "preg_replace", "(", "'/(?:\\?|\\#).*$/s'", ",", "''", ",", "$", "tmp_array", "[", "'content'", "]", ")", ";", "$", "tmp_array", "[", "'content'", "]", "=", "preg_replace", "(", "'/\\/$/s'", ",", "'/'", ".", "$", "this", "->", "px", "->", "get_directory_index_primary", "(", ")", ",", "$", "tmp_array", "[", "'content'", "]", ")", ";", "}", "$", "tmp_array", "[", "'content'", "]", "=", "preg_replace", "(", "'/\\/$/si'", ",", "'/'", ".", "$", "this", "->", "px", "->", "get_directory_index_primary", "(", ")", ",", "$", "tmp_array", "[", "'content'", "]", ")", ";", "//index.htmlを付加する。\r", "if", "(", "preg_match", "(", "'/^alias\\:/s'", ",", "$", "tmp_array", "[", "'path'", "]", ")", ")", "{", "//エイリアスの値調整\r", "$", "tmp_array", "[", "'content'", "]", "=", "null", ";", "$", "tmp_array", "[", "'path'", "]", "=", "preg_replace", "(", "'/^alias\\:/s'", ",", "'alias'", ".", "$", "num_auto_pid", ".", "':'", ",", "$", "tmp_array", "[", "'path'", "]", ")", ";", "}", "// パンくず欄の先頭が > から始まっていた場合、削除\r", "$", "tmp_array", "[", "'logical_path'", "]", "=", "@", "preg_replace", "(", "'/^\\>+/s'", ",", "''", ",", "$", "tmp_array", "[", "'logical_path'", "]", ")", ";", "$", "this", "->", "sitemap_array", "[", "$", "tmp_array", "[", "'path'", "]", "]", "=", "$", "tmp_array", ";", "$", "this", "->", "sitemap_id_map", "[", "$", "tmp_array", "[", "'id'", "]", "]", "=", "$", "tmp_array", "[", "'path'", "]", ";", "}", "unset", "(", "$", "tmp_sitemap", ")", ";", "// logical_path から、親子関係を整理\r", "foreach", "(", "$", "this", "->", "sitemap_array", "as", "$", "row_number", "=>", "$", "row", ")", "{", "if", "(", "!", "strlen", "(", "$", "row", "[", "'id'", "]", ")", ")", "{", "continue", ";", "}", "if", "(", "array_key_exists", "(", "'logical_path'", ",", "$", "row", ")", ")", "{", "$", "breadcrumb_ary", "=", "explode", "(", "'>'", ",", "$", "row", "[", "'logical_path'", "]", ")", ";", "$", "tmp_tree_key", "=", "$", "this", "->", "get_page_info", "(", "$", "breadcrumb_ary", "[", "count", "(", "$", "breadcrumb_ary", ")", "-", "1", "]", ",", "'path'", ")", ";", "if", "(", "is_null", "(", "$", "tmp_tree_key", ")", ")", "{", "// 親がいない\r", "continue", ";", "}", "if", "(", "!", "array_key_exists", "(", "$", "tmp_tree_key", ",", "$", "this", "->", "sitemap_page_tree", ")", ")", "{", "$", "this", "->", "sitemap_page_tree", "[", "$", "tmp_tree_key", "]", "=", "array", "(", ")", ";", "$", "this", "->", "sitemap_page_tree", "[", "$", "tmp_tree_key", "]", "[", "'children'", "]", "=", "array", "(", ")", ";", "$", "this", "->", "sitemap_page_tree", "[", "$", "tmp_tree_key", "]", "[", "'children_all'", "]", "=", "array", "(", ")", ";", "}", "array_push", "(", "$", "this", "->", "sitemap_page_tree", "[", "$", "tmp_tree_key", "]", "[", "'children'", "]", ",", "$", "row", "[", "'id'", "]", ")", ";", "array_push", "(", "$", "this", "->", "sitemap_page_tree", "[", "$", "tmp_tree_key", "]", "[", "'children_all'", "]", ",", "$", "row", "[", "'id'", "]", ")", ";", "// $tmp_array['logical_path']\r", "}", "}", "// var_dump($this->sitemap_array);\r", "// var_dump($this->sitemap_id_map);\r", "return", "true", ";", "}" ]
サイトマップCSV(単体)を読み込む
[ "サイトマップCSV", "(", "単体", ")", "を読み込む" ]
train
https://github.com/pickles2/px2-sitemapexcel/blob/fbfa207ee9b2e4bd977aadf69a935d3fade51fea/php/helper/parseSitemapCsv.php#L51-L219
pickles2/px2-sitemapexcel
php/helper/parseSitemapCsv.php
pxplugin_sitemapExcel_helper_parseSitemapCsv.get_page_info
public function get_page_info( $path, $key = null ){ if( is_null($path) ){ return null; } if( array_key_exists($path, $this->sitemap_id_map) && !is_null($this->sitemap_id_map[$path]) ){ //ページIDで指定された場合、パスに置き換える $path = $this->sitemap_id_map[$path]; } if( !preg_match( '/^(?:\/|[a-zA-Z0-9]+\:)/s', $path ) ){ // $path が相対パスで指定された場合 preg_match( '/(\/)$/s', $path, $tmp_matched ); $path = $this->px->fs()->get_realpath( dirname( $this->px->req()->get_request_file_path() ).'/'.$path ); if( @strlen($tmp_matched[1]) ){ $path .= $tmp_matched[1]; } $path = $this->px->fs()->normalize_path($path); unset( $tmp_matched ); } switch( $this->get_path_type($path) ){ case 'full_url': case 'data': case 'javascript': case 'anchor': break; default: $path = preg_replace('/\/'.$this->px->get_directory_index_preg_pattern().'((?:\?|\#).*)?$/si','/$1',$path);//directory_index を一旦省略 $tmp_path = $path; if( !array_key_exists($path, $this->sitemap_id_map) || is_null( $this->sitemap_array[$path] ) ){ foreach( $this->px->get_directory_index() as $index_file_name ){ $tmp_path = preg_replace('/\/((?:\?|\#).*)?$/si','/'.$index_file_name.'$1',$path);//省略された index.html を付加。 if( !is_null( @$this->sitemap_array[$tmp_path] ) ){ break; } } } $path = $tmp_path; unset($tmp_path); $parsed_url = parse_url($path); break; } if( is_null( @$this->sitemap_array[$path] ) ){ // サイトマップにズバリなければ、 // ダイナミックパスを検索する。 $sitemap_dynamic_path = $this->get_dynamic_path_info( $path ); if( is_array( $sitemap_dynamic_path ) ){ $path = $sitemap_dynamic_path['path_original']; } } $args = func_get_args(); switch( $this->get_path_type($path) ){ case 'full_url': case 'data': case 'javascript': case 'anchor': break; default: $path = preg_replace( '/\/$/si' , '/'.$this->px->get_directory_index_primary() , $path ); break; } if( is_null( @$this->sitemap_array[$path] ) ){ // サイトマップにズバリなければ、 // 引数からパラメータを外したパスだけで再検索 $path = @$parsed_url['path']; } $rtn = @$this->sitemap_array[$path]; if( !is_array($rtn) ){ return null; } // if( !strlen( @$rtn['title_breadcrumb'] ) ){ $rtn['title_breadcrumb'] = $rtn['title']; } // if( !strlen( @$rtn['title_h1'] ) ){ $rtn['title_h1'] = $rtn['title']; } // if( !strlen( @$rtn['title_label'] ) ){ $rtn['title_label'] = $rtn['title']; } // if( !strlen( @$rtn['title_full'] ) ){ $rtn['title_full'] = $rtn['title'].' | '.$this->px->conf()->name; } if( count($args) >= 2 ){ $rtn = $rtn[$args[1]]; } return $rtn; }
php
public function get_page_info( $path, $key = null ){ if( is_null($path) ){ return null; } if( array_key_exists($path, $this->sitemap_id_map) && !is_null($this->sitemap_id_map[$path]) ){ //ページIDで指定された場合、パスに置き換える $path = $this->sitemap_id_map[$path]; } if( !preg_match( '/^(?:\/|[a-zA-Z0-9]+\:)/s', $path ) ){ // $path が相対パスで指定された場合 preg_match( '/(\/)$/s', $path, $tmp_matched ); $path = $this->px->fs()->get_realpath( dirname( $this->px->req()->get_request_file_path() ).'/'.$path ); if( @strlen($tmp_matched[1]) ){ $path .= $tmp_matched[1]; } $path = $this->px->fs()->normalize_path($path); unset( $tmp_matched ); } switch( $this->get_path_type($path) ){ case 'full_url': case 'data': case 'javascript': case 'anchor': break; default: $path = preg_replace('/\/'.$this->px->get_directory_index_preg_pattern().'((?:\?|\#).*)?$/si','/$1',$path);//directory_index を一旦省略 $tmp_path = $path; if( !array_key_exists($path, $this->sitemap_id_map) || is_null( $this->sitemap_array[$path] ) ){ foreach( $this->px->get_directory_index() as $index_file_name ){ $tmp_path = preg_replace('/\/((?:\?|\#).*)?$/si','/'.$index_file_name.'$1',$path);//省略された index.html を付加。 if( !is_null( @$this->sitemap_array[$tmp_path] ) ){ break; } } } $path = $tmp_path; unset($tmp_path); $parsed_url = parse_url($path); break; } if( is_null( @$this->sitemap_array[$path] ) ){ // サイトマップにズバリなければ、 // ダイナミックパスを検索する。 $sitemap_dynamic_path = $this->get_dynamic_path_info( $path ); if( is_array( $sitemap_dynamic_path ) ){ $path = $sitemap_dynamic_path['path_original']; } } $args = func_get_args(); switch( $this->get_path_type($path) ){ case 'full_url': case 'data': case 'javascript': case 'anchor': break; default: $path = preg_replace( '/\/$/si' , '/'.$this->px->get_directory_index_primary() , $path ); break; } if( is_null( @$this->sitemap_array[$path] ) ){ // サイトマップにズバリなければ、 // 引数からパラメータを外したパスだけで再検索 $path = @$parsed_url['path']; } $rtn = @$this->sitemap_array[$path]; if( !is_array($rtn) ){ return null; } // if( !strlen( @$rtn['title_breadcrumb'] ) ){ $rtn['title_breadcrumb'] = $rtn['title']; } // if( !strlen( @$rtn['title_h1'] ) ){ $rtn['title_h1'] = $rtn['title']; } // if( !strlen( @$rtn['title_label'] ) ){ $rtn['title_label'] = $rtn['title']; } // if( !strlen( @$rtn['title_full'] ) ){ $rtn['title_full'] = $rtn['title'].' | '.$this->px->conf()->name; } if( count($args) >= 2 ){ $rtn = $rtn[$args[1]]; } return $rtn; }
[ "public", "function", "get_page_info", "(", "$", "path", ",", "$", "key", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "path", ")", ")", "{", "return", "null", ";", "}", "if", "(", "array_key_exists", "(", "$", "path", ",", "$", "this", "->", "sitemap_id_map", ")", "&&", "!", "is_null", "(", "$", "this", "->", "sitemap_id_map", "[", "$", "path", "]", ")", ")", "{", "//ページIDで指定された場合、パスに置き換える\r", "$", "path", "=", "$", "this", "->", "sitemap_id_map", "[", "$", "path", "]", ";", "}", "if", "(", "!", "preg_match", "(", "'/^(?:\\/|[a-zA-Z0-9]+\\:)/s'", ",", "$", "path", ")", ")", "{", "// $path が相対パスで指定された場合\r", "preg_match", "(", "'/(\\/)$/s'", ",", "$", "path", ",", "$", "tmp_matched", ")", ";", "$", "path", "=", "$", "this", "->", "px", "->", "fs", "(", ")", "->", "get_realpath", "(", "dirname", "(", "$", "this", "->", "px", "->", "req", "(", ")", "->", "get_request_file_path", "(", ")", ")", ".", "'/'", ".", "$", "path", ")", ";", "if", "(", "@", "strlen", "(", "$", "tmp_matched", "[", "1", "]", ")", ")", "{", "$", "path", ".=", "$", "tmp_matched", "[", "1", "]", ";", "}", "$", "path", "=", "$", "this", "->", "px", "->", "fs", "(", ")", "->", "normalize_path", "(", "$", "path", ")", ";", "unset", "(", "$", "tmp_matched", ")", ";", "}", "switch", "(", "$", "this", "->", "get_path_type", "(", "$", "path", ")", ")", "{", "case", "'full_url'", ":", "case", "'data'", ":", "case", "'javascript'", ":", "case", "'anchor'", ":", "break", ";", "default", ":", "$", "path", "=", "preg_replace", "(", "'/\\/'", ".", "$", "this", "->", "px", "->", "get_directory_index_preg_pattern", "(", ")", ".", "'((?:\\?|\\#).*)?$/si'", ",", "'/$1'", ",", "$", "path", ")", ";", "//directory_index を一旦省略\r", "$", "tmp_path", "=", "$", "path", ";", "if", "(", "!", "array_key_exists", "(", "$", "path", ",", "$", "this", "->", "sitemap_id_map", ")", "||", "is_null", "(", "$", "this", "->", "sitemap_array", "[", "$", "path", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "px", "->", "get_directory_index", "(", ")", "as", "$", "index_file_name", ")", "{", "$", "tmp_path", "=", "preg_replace", "(", "'/\\/((?:\\?|\\#).*)?$/si'", ",", "'/'", ".", "$", "index_file_name", ".", "'$1'", ",", "$", "path", ")", ";", "//省略された index.html を付加。\r", "if", "(", "!", "is_null", "(", "@", "$", "this", "->", "sitemap_array", "[", "$", "tmp_path", "]", ")", ")", "{", "break", ";", "}", "}", "}", "$", "path", "=", "$", "tmp_path", ";", "unset", "(", "$", "tmp_path", ")", ";", "$", "parsed_url", "=", "parse_url", "(", "$", "path", ")", ";", "break", ";", "}", "if", "(", "is_null", "(", "@", "$", "this", "->", "sitemap_array", "[", "$", "path", "]", ")", ")", "{", "// サイトマップにズバリなければ、\r", "// ダイナミックパスを検索する。\r", "$", "sitemap_dynamic_path", "=", "$", "this", "->", "get_dynamic_path_info", "(", "$", "path", ")", ";", "if", "(", "is_array", "(", "$", "sitemap_dynamic_path", ")", ")", "{", "$", "path", "=", "$", "sitemap_dynamic_path", "[", "'path_original'", "]", ";", "}", "}", "$", "args", "=", "func_get_args", "(", ")", ";", "switch", "(", "$", "this", "->", "get_path_type", "(", "$", "path", ")", ")", "{", "case", "'full_url'", ":", "case", "'data'", ":", "case", "'javascript'", ":", "case", "'anchor'", ":", "break", ";", "default", ":", "$", "path", "=", "preg_replace", "(", "'/\\/$/si'", ",", "'/'", ".", "$", "this", "->", "px", "->", "get_directory_index_primary", "(", ")", ",", "$", "path", ")", ";", "break", ";", "}", "if", "(", "is_null", "(", "@", "$", "this", "->", "sitemap_array", "[", "$", "path", "]", ")", ")", "{", "// サイトマップにズバリなければ、\r", "// 引数からパラメータを外したパスだけで再検索\r", "$", "path", "=", "@", "$", "parsed_url", "[", "'path'", "]", ";", "}", "$", "rtn", "=", "@", "$", "this", "->", "sitemap_array", "[", "$", "path", "]", ";", "if", "(", "!", "is_array", "(", "$", "rtn", ")", ")", "{", "return", "null", ";", "}", "// if( !strlen( @$rtn['title_breadcrumb'] ) ){ $rtn['title_breadcrumb'] = $rtn['title']; }\r", "// if( !strlen( @$rtn['title_h1'] ) ){ $rtn['title_h1'] = $rtn['title']; }\r", "// if( !strlen( @$rtn['title_label'] ) ){ $rtn['title_label'] = $rtn['title']; }\r", "// if( !strlen( @$rtn['title_full'] ) ){ $rtn['title_full'] = $rtn['title'].' | '.$this->px->conf()->name; }\r", "if", "(", "count", "(", "$", "args", ")", ">=", "2", ")", "{", "$", "rtn", "=", "$", "rtn", "[", "$", "args", "[", "1", "]", "]", ";", "}", "return", "$", "rtn", ";", "}" ]
ページ情報を取得する。 このメソッドは、指定したページの情報を連想配列で返します。対象のページは第1引数にパスまたはページIDで指定します。 カレントページの情報を取得する場合は、代わりに `$px->site()->get_current_page_info()` が使用できます。 パスで指定したページの情報を取得する例 : <pre>&lt;?php // ページ &quot;/aaa/bbb.html&quot; のページ情報を得る $page_info = $px-&gt;site()-&gt;get_page_info('/aaa/bbb.html'); var_dump( $page_info ); ?&gt;</pre> ページIDで指定したページの情報を取得する例 : <pre>&lt;?php // トップページのページ情報を得る // (トップページのページIDは必ず空白の文字列) $page_info = $px-&gt;site()-&gt;get_page_info(''); var_dump( $page_info ); ?&gt;</pre> @param string $path 取得するページのパス または ページID。省略時、カレントページから自動的に取得します。 @param string $key 取り出す単一要素のキー。省略時はすべての要素を含む連想配列が返されます。省略可。 @return mixed 単一ページ情報を格納する連想配列、`$key` が指定された場合は、その値のみ。
[ "ページ情報を取得する。" ]
train
https://github.com/pickles2/px2-sitemapexcel/blob/fbfa207ee9b2e4bd977aadf69a935d3fade51fea/php/helper/parseSitemapCsv.php#L267-L342
pickles2/px2-sitemapexcel
php/helper/parseSitemapCsv.php
pxplugin_sitemapExcel_helper_parseSitemapCsv.get_children
public function get_children( $path = null, $opt = array() ){ if( is_null( $path ) ){ $path = $this->px->req()->get_request_file_path(); } $filter = true; if(!is_null(@$opt['filter'])){ $filter = !empty($opt['filter']); } $page_info = $this->get_page_info( $path ); if( $filter && is_array( @$this->sitemap_page_tree[$page_info['path']]['children'] ) ){ // ページキャッシュツリーがすでに作られている場合 return $this->sitemap_page_tree[$page_info['path']]['children']; } if( !$filter && is_array( @$this->sitemap_page_tree[$page_info['path']]['children_all'] ) ){ // ページキャッシュツリーがすでに作られている場合 return $this->sitemap_page_tree[$page_info['path']]['children_all']; } return array(); }
php
public function get_children( $path = null, $opt = array() ){ if( is_null( $path ) ){ $path = $this->px->req()->get_request_file_path(); } $filter = true; if(!is_null(@$opt['filter'])){ $filter = !empty($opt['filter']); } $page_info = $this->get_page_info( $path ); if( $filter && is_array( @$this->sitemap_page_tree[$page_info['path']]['children'] ) ){ // ページキャッシュツリーがすでに作られている場合 return $this->sitemap_page_tree[$page_info['path']]['children']; } if( !$filter && is_array( @$this->sitemap_page_tree[$page_info['path']]['children_all'] ) ){ // ページキャッシュツリーがすでに作られている場合 return $this->sitemap_page_tree[$page_info['path']]['children_all']; } return array(); }
[ "public", "function", "get_children", "(", "$", "path", "=", "null", ",", "$", "opt", "=", "array", "(", ")", ")", "{", "if", "(", "is_null", "(", "$", "path", ")", ")", "{", "$", "path", "=", "$", "this", "->", "px", "->", "req", "(", ")", "->", "get_request_file_path", "(", ")", ";", "}", "$", "filter", "=", "true", ";", "if", "(", "!", "is_null", "(", "@", "$", "opt", "[", "'filter'", "]", ")", ")", "{", "$", "filter", "=", "!", "empty", "(", "$", "opt", "[", "'filter'", "]", ")", ";", "}", "$", "page_info", "=", "$", "this", "->", "get_page_info", "(", "$", "path", ")", ";", "if", "(", "$", "filter", "&&", "is_array", "(", "@", "$", "this", "->", "sitemap_page_tree", "[", "$", "page_info", "[", "'path'", "]", "]", "[", "'children'", "]", ")", ")", "{", "// ページキャッシュツリーがすでに作られている場合\r", "return", "$", "this", "->", "sitemap_page_tree", "[", "$", "page_info", "[", "'path'", "]", "]", "[", "'children'", "]", ";", "}", "if", "(", "!", "$", "filter", "&&", "is_array", "(", "@", "$", "this", "->", "sitemap_page_tree", "[", "$", "page_info", "[", "'path'", "]", "]", "[", "'children_all'", "]", ")", ")", "{", "// ページキャッシュツリーがすでに作られている場合\r", "return", "$", "this", "->", "sitemap_page_tree", "[", "$", "page_info", "[", "'path'", "]", "]", "[", "'children_all'", "]", ";", "}", "return", "array", "(", ")", ";", "}" ]
子階層のページの一覧を取得する。 このメソッドは、指定したページの子階層のページの一覧を返します。`$path` を省略した場合は、カレントページのパスを起点に一覧を抽出します。 カレントページの子階層のリンクを作成する例 : <pre>&lt;?php // カレントページの子階層のリンクを作成する $children = $px-&gt;site()-&gt;get_children(); print '&lt;ul&gt;'; foreach( $children as $child ){ print '&lt;li&gt;'.$px-&gt;theme()-&gt;mk_link($child).'&lt;/li&gt;'; } print '&lt;/ul&gt;'; ?&gt;</pre> カレントページの子階層のリンクを、list_flg を無視してすべて表示する例 : <pre>&lt;?php // カレントページの子階層のリンクを作成する // (list_flg を無視してすべて表示する) $children = $px-&gt;site()-&gt;get_children(null, array('filter'=&gt;false)); print '&lt;ul&gt;'; foreach( $children as $child ){ print '&lt;li&gt;'.$px-&gt;theme()-&gt;mk_link($child).'&lt;/li&gt;'; } print '&lt;/ul&gt;'; ?&gt;</pre> @param string $path 起点とするページのパス または ページID。省略時、カレントページから自動的に取得します。 @param array $opt オプション(省略可) <dl> <dt>$opt['filter'] (初期値: `true`)</dt> <dd>フィルターの有効/無効を切り替えます。`true` のとき有効、`false`のとき無効となります。フィルターが有効な場合、サイトマップで `list_flg` が `0` のページが一覧から除外されます。</dd> </dl> @return array ページの一覧
[ "子階層のページの一覧を取得する。" ]
train
https://github.com/pickles2/px2-sitemapexcel/blob/fbfa207ee9b2e4bd977aadf69a935d3fade51fea/php/helper/parseSitemapCsv.php#L380-L399
pickles2/px2-sitemapexcel
php/helper/parseSitemapCsv.php
pxplugin_sitemapExcel_helper_parseSitemapCsv.usort_sitemap
private function usort_sitemap( $a , $b ){ $page_info_a = $this->get_page_info( $a ); $page_info_b = $this->get_page_info( $b ); $orderby_a = $page_info_a['orderby']; $orderby_b = $page_info_b['orderby']; if( strlen( $orderby_a ) && !strlen( $orderby_b ) ){ return -1; }elseif( strlen( $orderby_b ) && !strlen( $orderby_a ) ){ return 1; }elseif( $orderby_a < $orderby_b ){ return -1; }elseif( $orderby_a > $orderby_b ){ return 1; } return 0; }
php
private function usort_sitemap( $a , $b ){ $page_info_a = $this->get_page_info( $a ); $page_info_b = $this->get_page_info( $b ); $orderby_a = $page_info_a['orderby']; $orderby_b = $page_info_b['orderby']; if( strlen( $orderby_a ) && !strlen( $orderby_b ) ){ return -1; }elseif( strlen( $orderby_b ) && !strlen( $orderby_a ) ){ return 1; }elseif( $orderby_a < $orderby_b ){ return -1; }elseif( $orderby_a > $orderby_b ){ return 1; } return 0; }
[ "private", "function", "usort_sitemap", "(", "$", "a", ",", "$", "b", ")", "{", "$", "page_info_a", "=", "$", "this", "->", "get_page_info", "(", "$", "a", ")", ";", "$", "page_info_b", "=", "$", "this", "->", "get_page_info", "(", "$", "b", ")", ";", "$", "orderby_a", "=", "$", "page_info_a", "[", "'orderby'", "]", ";", "$", "orderby_b", "=", "$", "page_info_b", "[", "'orderby'", "]", ";", "if", "(", "strlen", "(", "$", "orderby_a", ")", "&&", "!", "strlen", "(", "$", "orderby_b", ")", ")", "{", "return", "-", "1", ";", "}", "elseif", "(", "strlen", "(", "$", "orderby_b", ")", "&&", "!", "strlen", "(", "$", "orderby_a", ")", ")", "{", "return", "1", ";", "}", "elseif", "(", "$", "orderby_a", "<", "$", "orderby_b", ")", "{", "return", "-", "1", ";", "}", "elseif", "(", "$", "orderby_a", ">", "$", "orderby_b", ")", "{", "return", "1", ";", "}", "return", "0", ";", "}" ]
ページ情報の配列を並び替える。 @param string $a 比較対象1のページID @param string $b 比較対象2のページID @return int 並び順の前後関係 (`1`|`0`|`-1`)
[ "ページ情報の配列を並び替える。" ]
train
https://github.com/pickles2/px2-sitemapexcel/blob/fbfa207ee9b2e4bd977aadf69a935d3fade51fea/php/helper/parseSitemapCsv.php#L408-L423
pickles2/px2-sitemapexcel
php/helper/parseSitemapCsv.php
pxplugin_sitemapExcel_helper_parseSitemapCsv.get_dynamic_path_info
public function get_dynamic_path_info( $path ){ foreach( $this->sitemap_dynamic_paths as $sitemap_dynamic_path ){ //ダイナミックパスを検索 if( $sitemap_dynamic_path['path_original'] == $path ){ return $sitemap_dynamic_path; } if( preg_match( $sitemap_dynamic_path['preg'] , $path ) ){ return $sitemap_dynamic_path; } } return false; }
php
public function get_dynamic_path_info( $path ){ foreach( $this->sitemap_dynamic_paths as $sitemap_dynamic_path ){ //ダイナミックパスを検索 if( $sitemap_dynamic_path['path_original'] == $path ){ return $sitemap_dynamic_path; } if( preg_match( $sitemap_dynamic_path['preg'] , $path ) ){ return $sitemap_dynamic_path; } } return false; }
[ "public", "function", "get_dynamic_path_info", "(", "$", "path", ")", "{", "foreach", "(", "$", "this", "->", "sitemap_dynamic_paths", "as", "$", "sitemap_dynamic_path", ")", "{", "//ダイナミックパスを検索\r", "if", "(", "$", "sitemap_dynamic_path", "[", "'path_original'", "]", "==", "$", "path", ")", "{", "return", "$", "sitemap_dynamic_path", ";", "}", "if", "(", "preg_match", "(", "$", "sitemap_dynamic_path", "[", "'preg'", "]", ",", "$", "path", ")", ")", "{", "return", "$", "sitemap_dynamic_path", ";", "}", "}", "return", "false", ";", "}" ]
ダイナミックパス情報を得る。 @param string $path 対象のパス @return string|bool 見つかった場合に、ダイナミックパスを、見つからない場合に `false` を返します。
[ "ダイナミックパス情報を得る。" ]
train
https://github.com/pickles2/px2-sitemapexcel/blob/fbfa207ee9b2e4bd977aadf69a935d3fade51fea/php/helper/parseSitemapCsv.php#L431-L442
pickles2/px2-sitemapexcel
php/helper/parseSitemapCsv.php
pxplugin_sitemapExcel_helper_parseSitemapCsv.get_max_depth
public function get_max_depth(){ if( is_int($this->max_depth) ){ return $this->max_depth; } $this->max_depth = 0; foreach( $this->get_sitemap() as $page_info ){ $tmp_breadcrumb = explode('>',$page_info['logical_path']); if( $this->max_depth < count($tmp_breadcrumb) ){ $this->max_depth = count($tmp_breadcrumb); } } $this->max_depth += 3;//ちょっぴり余裕を return $this->max_depth; }
php
public function get_max_depth(){ if( is_int($this->max_depth) ){ return $this->max_depth; } $this->max_depth = 0; foreach( $this->get_sitemap() as $page_info ){ $tmp_breadcrumb = explode('>',$page_info['logical_path']); if( $this->max_depth < count($tmp_breadcrumb) ){ $this->max_depth = count($tmp_breadcrumb); } } $this->max_depth += 3;//ちょっぴり余裕を return $this->max_depth; }
[ "public", "function", "get_max_depth", "(", ")", "{", "if", "(", "is_int", "(", "$", "this", "->", "max_depth", ")", ")", "{", "return", "$", "this", "->", "max_depth", ";", "}", "$", "this", "->", "max_depth", "=", "0", ";", "foreach", "(", "$", "this", "->", "get_sitemap", "(", ")", "as", "$", "page_info", ")", "{", "$", "tmp_breadcrumb", "=", "explode", "(", "'>'", ",", "$", "page_info", "[", "'logical_path'", "]", ")", ";", "if", "(", "$", "this", "->", "max_depth", "<", "count", "(", "$", "tmp_breadcrumb", ")", ")", "{", "$", "this", "->", "max_depth", "=", "count", "(", "$", "tmp_breadcrumb", ")", ";", "}", "}", "$", "this", "->", "max_depth", "+=", "3", ";", "//ちょっぴり余裕を\r", "return", "$", "this", "->", "max_depth", ";", "}" ]
パンくずの最大の深さを計測
[ "パンくずの最大の深さを計測" ]
train
https://github.com/pickles2/px2-sitemapexcel/blob/fbfa207ee9b2e4bd977aadf69a935d3fade51fea/php/helper/parseSitemapCsv.php#L447-L461
pickles2/px2-sitemapexcel
php/helper/parseSitemapCsv.php
pxplugin_sitemapExcel_helper_parseSitemapCsv.done
public function done($path){ $page_info = $this->get_page_info($path); unset($this->sitemap_array[$page_info['path']]); unset($this->sitemap_id_map[$page_info['id']]); return true; }
php
public function done($path){ $page_info = $this->get_page_info($path); unset($this->sitemap_array[$page_info['path']]); unset($this->sitemap_id_map[$page_info['id']]); return true; }
[ "public", "function", "done", "(", "$", "path", ")", "{", "$", "page_info", "=", "$", "this", "->", "get_page_info", "(", "$", "path", ")", ";", "unset", "(", "$", "this", "->", "sitemap_array", "[", "$", "page_info", "[", "'path'", "]", "]", ")", ";", "unset", "(", "$", "this", "->", "sitemap_id_map", "[", "$", "page_info", "[", "'id'", "]", "]", ")", ";", "return", "true", ";", "}" ]
指定したページの変換が完了したことを記録する
[ "指定したページの変換が完了したことを記録する" ]
train
https://github.com/pickles2/px2-sitemapexcel/blob/fbfa207ee9b2e4bd977aadf69a935d3fade51fea/php/helper/parseSitemapCsv.php#L466-L471
andyvenus/form
src/FormView.php
FormView.getSectionFields
public function getSectionFields($section, $flatten = true) { if ($flatten === false) { $fields = $this->fields; } else { $fields = $this->getFlattenedFields(); } $matchedFields = array(); foreach ($fields as $fieldName => $field) { if (isset($field['options']['section']) && $field['options']['section'] == $section) { $matchedFields[$fieldName] = $field; } } return $matchedFields; }
php
public function getSectionFields($section, $flatten = true) { if ($flatten === false) { $fields = $this->fields; } else { $fields = $this->getFlattenedFields(); } $matchedFields = array(); foreach ($fields as $fieldName => $field) { if (isset($field['options']['section']) && $field['options']['section'] == $section) { $matchedFields[$fieldName] = $field; } } return $matchedFields; }
[ "public", "function", "getSectionFields", "(", "$", "section", ",", "$", "flatten", "=", "true", ")", "{", "if", "(", "$", "flatten", "===", "false", ")", "{", "$", "fields", "=", "$", "this", "->", "fields", ";", "}", "else", "{", "$", "fields", "=", "$", "this", "->", "getFlattenedFields", "(", ")", ";", "}", "$", "matchedFields", "=", "array", "(", ")", ";", "foreach", "(", "$", "fields", "as", "$", "fieldName", "=>", "$", "field", ")", "{", "if", "(", "isset", "(", "$", "field", "[", "'options'", "]", "[", "'section'", "]", ")", "&&", "$", "field", "[", "'options'", "]", "[", "'section'", "]", "==", "$", "section", ")", "{", "$", "matchedFields", "[", "$", "fieldName", "]", "=", "$", "field", ";", "}", "}", "return", "$", "matchedFields", ";", "}" ]
Get fields for a certain section @param $section @param bool $flatten @return array
[ "Get", "fields", "for", "a", "certain", "section" ]
train
https://github.com/andyvenus/form/blob/fde9d7e1741a707028aec4fd55c3568802df3708/src/FormView.php#L188-L204
andyvenus/form
src/FormView.php
FormView.getFlattenedFields
public function getFlattenedFields() { if (!isset($this->flatFields)) { $this->flatFields = []; foreach ($this->fields as $field) { if (isset($field['fields']) && is_array($field['fields'])) { $this->flatFields += $this->flattenCollection($field); } else { $this->flatFields[$field['name']] = $field; } } } return $this->flatFields; }
php
public function getFlattenedFields() { if (!isset($this->flatFields)) { $this->flatFields = []; foreach ($this->fields as $field) { if (isset($field['fields']) && is_array($field['fields'])) { $this->flatFields += $this->flattenCollection($field); } else { $this->flatFields[$field['name']] = $field; } } } return $this->flatFields; }
[ "public", "function", "getFlattenedFields", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "flatFields", ")", ")", "{", "$", "this", "->", "flatFields", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "fields", "as", "$", "field", ")", "{", "if", "(", "isset", "(", "$", "field", "[", "'fields'", "]", ")", "&&", "is_array", "(", "$", "field", "[", "'fields'", "]", ")", ")", "{", "$", "this", "->", "flatFields", "+=", "$", "this", "->", "flattenCollection", "(", "$", "field", ")", ";", "}", "else", "{", "$", "this", "->", "flatFields", "[", "$", "field", "[", "'name'", "]", "]", "=", "$", "field", ";", "}", "}", "}", "return", "$", "this", "->", "flatFields", ";", "}" ]
Flatten all fields by moving collections into the main array @return array
[ "Flatten", "all", "fields", "by", "moving", "collections", "into", "the", "main", "array" ]
train
https://github.com/andyvenus/form/blob/fde9d7e1741a707028aec4fd55c3568802df3708/src/FormView.php#L211-L226
andyvenus/form
src/FormView.php
FormView.flattenCollection
protected function flattenCollection($field) { if (!isset($field['fields']) || !is_array($field['fields'])) { return []; } $fields = []; foreach ($field['fields'] as $field) { if (isset($field['fields']) && is_array($field['fields'])) { $fields += $this->flattenCollection($field); } else { $fields[$field['name']] = $field; } } return $fields; }
php
protected function flattenCollection($field) { if (!isset($field['fields']) || !is_array($field['fields'])) { return []; } $fields = []; foreach ($field['fields'] as $field) { if (isset($field['fields']) && is_array($field['fields'])) { $fields += $this->flattenCollection($field); } else { $fields[$field['name']] = $field; } } return $fields; }
[ "protected", "function", "flattenCollection", "(", "$", "field", ")", "{", "if", "(", "!", "isset", "(", "$", "field", "[", "'fields'", "]", ")", "||", "!", "is_array", "(", "$", "field", "[", "'fields'", "]", ")", ")", "{", "return", "[", "]", ";", "}", "$", "fields", "=", "[", "]", ";", "foreach", "(", "$", "field", "[", "'fields'", "]", "as", "$", "field", ")", "{", "if", "(", "isset", "(", "$", "field", "[", "'fields'", "]", ")", "&&", "is_array", "(", "$", "field", "[", "'fields'", "]", ")", ")", "{", "$", "fields", "+=", "$", "this", "->", "flattenCollection", "(", "$", "field", ")", ";", "}", "else", "{", "$", "fields", "[", "$", "field", "[", "'name'", "]", "]", "=", "$", "field", ";", "}", "}", "return", "$", "fields", ";", "}" ]
Flatten the fields in a collection @param $field @return array
[ "Flatten", "the", "fields", "in", "a", "collection" ]
train
https://github.com/andyvenus/form/blob/fde9d7e1741a707028aec4fd55c3568802df3708/src/FormView.php#L234-L251
andyvenus/form
src/FormView.php
FormView.getFieldsWithoutSection
public function getFieldsWithoutSection() { $matchedFields = array(); foreach ($this->fields as $fieldName => $field) { if (!isset($field['options']['section']) || $field['options']['section'] === null || $field['options']['section'] === '') { $matchedFields[$fieldName] = $field; } } return $matchedFields; }
php
public function getFieldsWithoutSection() { $matchedFields = array(); foreach ($this->fields as $fieldName => $field) { if (!isset($field['options']['section']) || $field['options']['section'] === null || $field['options']['section'] === '') { $matchedFields[$fieldName] = $field; } } return $matchedFields; }
[ "public", "function", "getFieldsWithoutSection", "(", ")", "{", "$", "matchedFields", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "fields", "as", "$", "fieldName", "=>", "$", "field", ")", "{", "if", "(", "!", "isset", "(", "$", "field", "[", "'options'", "]", "[", "'section'", "]", ")", "||", "$", "field", "[", "'options'", "]", "[", "'section'", "]", "===", "null", "||", "$", "field", "[", "'options'", "]", "[", "'section'", "]", "===", "''", ")", "{", "$", "matchedFields", "[", "$", "fieldName", "]", "=", "$", "field", ";", "}", "}", "return", "$", "matchedFields", ";", "}" ]
Get any fields that don't have a section set @return array
[ "Get", "any", "fields", "that", "don", "t", "have", "a", "section", "set" ]
train
https://github.com/andyvenus/form/blob/fde9d7e1741a707028aec4fd55c3568802df3708/src/FormView.php#L258-L268
andyvenus/form
src/FormView.php
FormView.translate
protected function translate($str, $params = array()) { if (isset($this->translator)) { return $this->translator->trans($str, $params); } else { $finalParams = array(); foreach ($params as $placeholder => $value) { $finalParams['{'.$placeholder.'}'] = $value; } return strtr($str, $finalParams); } }
php
protected function translate($str, $params = array()) { if (isset($this->translator)) { return $this->translator->trans($str, $params); } else { $finalParams = array(); foreach ($params as $placeholder => $value) { $finalParams['{'.$placeholder.'}'] = $value; } return strtr($str, $finalParams); } }
[ "protected", "function", "translate", "(", "$", "str", ",", "$", "params", "=", "array", "(", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "translator", ")", ")", "{", "return", "$", "this", "->", "translator", "->", "trans", "(", "$", "str", ",", "$", "params", ")", ";", "}", "else", "{", "$", "finalParams", "=", "array", "(", ")", ";", "foreach", "(", "$", "params", "as", "$", "placeholder", "=>", "$", "value", ")", "{", "$", "finalParams", "[", "'{'", ".", "$", "placeholder", ".", "'}'", "]", "=", "$", "value", ";", "}", "return", "strtr", "(", "$", "str", ",", "$", "finalParams", ")", ";", "}", "}" ]
Translate a string if the translator has been injected @param $str string The string that will be translated @param array $params @return string
[ "Translate", "a", "string", "if", "the", "translator", "has", "been", "injected" ]
train
https://github.com/andyvenus/form/blob/fde9d7e1741a707028aec4fd55c3568802df3708/src/FormView.php#L377-L389
jelix/ldapdao-module
ldapdao/plugins/auth/ldapdao/ldapdao.auth.php
ldapdaoAuthDriver._getLinkId
protected function _getLinkId() { if ($connect = ldap_connect($this->_params['hostname'], $this->_params['port'])) { ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, $this->_params['protocolVersion']); ldap_set_option($connect, LDAP_OPT_REFERRALS, 0); return $connect; } return false; }
php
protected function _getLinkId() { if ($connect = ldap_connect($this->_params['hostname'], $this->_params['port'])) { ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, $this->_params['protocolVersion']); ldap_set_option($connect, LDAP_OPT_REFERRALS, 0); return $connect; } return false; }
[ "protected", "function", "_getLinkId", "(", ")", "{", "if", "(", "$", "connect", "=", "ldap_connect", "(", "$", "this", "->", "_params", "[", "'hostname'", "]", ",", "$", "this", "->", "_params", "[", "'port'", "]", ")", ")", "{", "ldap_set_option", "(", "$", "connect", ",", "LDAP_OPT_PROTOCOL_VERSION", ",", "$", "this", "->", "_params", "[", "'protocolVersion'", "]", ")", ";", "ldap_set_option", "(", "$", "connect", ",", "LDAP_OPT_REFERRALS", ",", "0", ")", ";", "return", "$", "connect", ";", "}", "return", "false", ";", "}" ]
open the connection to the ldap server
[ "open", "the", "connection", "to", "the", "ldap", "server" ]
train
https://github.com/jelix/ldapdao-module/blob/8261aadf643e95c98fcb96f5d65fa007977418cd/ldapdao/plugins/auth/ldapdao/ldapdao.auth.php#L467-L475
jelix/ldapdao-module
ldapdao/plugins/auth/ldapdao/ldapdao.auth.php
ldapdaoAuthDriver._bindLdapAdminUser
protected function _bindLdapAdminUser() { $connect = $this->_getLinkId(); if (!$connect) { jLog::log('ldapdao: impossible to connect to ldap', 'auth'); return false; } if ($this->_params['adminUserDn'] == '') { $bind = ldap_bind($connect); } else { $bind = ldap_bind($connect, $this->_params['adminUserDn'], $this->_params['adminPassword']); } if (!$bind) { if ($this->_params['adminUserDn'] == '') { jLog::log('ldapdao: impossible to authenticate to ldap as anonymous admin user', 'auth'); } else { jLog::log('ldapdao: impossible to authenticate to ldap with admin user '.$this->_params['adminUserDn'], 'auth'); } ldap_close($connect); return false; } return $connect; }
php
protected function _bindLdapAdminUser() { $connect = $this->_getLinkId(); if (!$connect) { jLog::log('ldapdao: impossible to connect to ldap', 'auth'); return false; } if ($this->_params['adminUserDn'] == '') { $bind = ldap_bind($connect); } else { $bind = ldap_bind($connect, $this->_params['adminUserDn'], $this->_params['adminPassword']); } if (!$bind) { if ($this->_params['adminUserDn'] == '') { jLog::log('ldapdao: impossible to authenticate to ldap as anonymous admin user', 'auth'); } else { jLog::log('ldapdao: impossible to authenticate to ldap with admin user '.$this->_params['adminUserDn'], 'auth'); } ldap_close($connect); return false; } return $connect; }
[ "protected", "function", "_bindLdapAdminUser", "(", ")", "{", "$", "connect", "=", "$", "this", "->", "_getLinkId", "(", ")", ";", "if", "(", "!", "$", "connect", ")", "{", "jLog", "::", "log", "(", "'ldapdao: impossible to connect to ldap'", ",", "'auth'", ")", ";", "return", "false", ";", "}", "if", "(", "$", "this", "->", "_params", "[", "'adminUserDn'", "]", "==", "''", ")", "{", "$", "bind", "=", "ldap_bind", "(", "$", "connect", ")", ";", "}", "else", "{", "$", "bind", "=", "ldap_bind", "(", "$", "connect", ",", "$", "this", "->", "_params", "[", "'adminUserDn'", "]", ",", "$", "this", "->", "_params", "[", "'adminPassword'", "]", ")", ";", "}", "if", "(", "!", "$", "bind", ")", "{", "if", "(", "$", "this", "->", "_params", "[", "'adminUserDn'", "]", "==", "''", ")", "{", "jLog", "::", "log", "(", "'ldapdao: impossible to authenticate to ldap as anonymous admin user'", ",", "'auth'", ")", ";", "}", "else", "{", "jLog", "::", "log", "(", "'ldapdao: impossible to authenticate to ldap with admin user '", ".", "$", "this", "->", "_params", "[", "'adminUserDn'", "]", ",", "'auth'", ")", ";", "}", "ldap_close", "(", "$", "connect", ")", ";", "return", "false", ";", "}", "return", "$", "connect", ";", "}" ]
open the connection to the ldap server and bind to the admin user @return resource|false the ldap connection
[ "open", "the", "connection", "to", "the", "ldap", "server", "and", "bind", "to", "the", "admin", "user" ]
train
https://github.com/jelix/ldapdao-module/blob/8261aadf643e95c98fcb96f5d65fa007977418cd/ldapdao/plugins/auth/ldapdao/ldapdao.auth.php#L482-L505
ftrrtf/FtrrtfRollbarBundle
Rollbar/Environment.php
Environment.getRequestData
public function getRequestData() { parent::getRequestData(); if ($this->getRequest() instanceof Request) { if (in_array($this->getRequest()->getMethod(), array('PUT', 'DELETE'))) { $this->requestData[$this->getRequest()->getMethod()] = $this->getRequest()->request->all(); } } return $this->requestData; }
php
public function getRequestData() { parent::getRequestData(); if ($this->getRequest() instanceof Request) { if (in_array($this->getRequest()->getMethod(), array('PUT', 'DELETE'))) { $this->requestData[$this->getRequest()->getMethod()] = $this->getRequest()->request->all(); } } return $this->requestData; }
[ "public", "function", "getRequestData", "(", ")", "{", "parent", "::", "getRequestData", "(", ")", ";", "if", "(", "$", "this", "->", "getRequest", "(", ")", "instanceof", "Request", ")", "{", "if", "(", "in_array", "(", "$", "this", "->", "getRequest", "(", ")", "->", "getMethod", "(", ")", ",", "array", "(", "'PUT'", ",", "'DELETE'", ")", ")", ")", "{", "$", "this", "->", "requestData", "[", "$", "this", "->", "getRequest", "(", ")", "->", "getMethod", "(", ")", "]", "=", "$", "this", "->", "getRequest", "(", ")", "->", "request", "->", "all", "(", ")", ";", "}", "}", "return", "$", "this", "->", "requestData", ";", "}" ]
Cached values for request. @return array|null
[ "Cached", "values", "for", "request", "." ]
train
https://github.com/ftrrtf/FtrrtfRollbarBundle/blob/64c75862b80a4a1ed9e98c0d217003e84df40dd7/Rollbar/Environment.php#L25-L36
puli/discovery
src/Api/Type/BindingType.php
BindingType.getParameter
public function getParameter($name) { if (!isset($this->parameters[$name])) { throw new NoSuchParameterException(sprintf( 'The parameter "%s" does not exist on type "%s".', $name, $this->name )); } return $this->parameters[$name]; }
php
public function getParameter($name) { if (!isset($this->parameters[$name])) { throw new NoSuchParameterException(sprintf( 'The parameter "%s" does not exist on type "%s".', $name, $this->name )); } return $this->parameters[$name]; }
[ "public", "function", "getParameter", "(", "$", "name", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "parameters", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "NoSuchParameterException", "(", "sprintf", "(", "'The parameter \"%s\" does not exist on type \"%s\".'", ",", "$", "name", ",", "$", "this", "->", "name", ")", ")", ";", "}", "return", "$", "this", "->", "parameters", "[", "$", "name", "]", ";", "}" ]
Returns a parameter by name. @param string $name The parameter name. @return BindingParameter The parameter. @throws NoSuchParameterException If the parameter was not found.
[ "Returns", "a", "parameter", "by", "name", "." ]
train
https://github.com/puli/discovery/blob/975f5e099563f1096bfabc17fbe4d1816408ad98/src/Api/Type/BindingType.php#L150-L161
puli/discovery
src/Api/Type/BindingType.php
BindingType.hasParameterValues
public function hasParameterValues() { foreach ($this->parameters as $name => $parameter) { if (!$parameter->isRequired()) { return true; } } return false; }
php
public function hasParameterValues() { foreach ($this->parameters as $name => $parameter) { if (!$parameter->isRequired()) { return true; } } return false; }
[ "public", "function", "hasParameterValues", "(", ")", "{", "foreach", "(", "$", "this", "->", "parameters", "as", "$", "name", "=>", "$", "parameter", ")", "{", "if", "(", "!", "$", "parameter", "->", "isRequired", "(", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Returns whether the type has parameters with default values. @return bool Returns `true` if at least one parameter has a default value and `false` otherwise.
[ "Returns", "whether", "the", "type", "has", "parameters", "with", "default", "values", "." ]
train
https://github.com/puli/discovery/blob/975f5e099563f1096bfabc17fbe4d1816408ad98/src/Api/Type/BindingType.php#L199-L208
puli/discovery
src/Api/Type/BindingType.php
BindingType.acceptsBinding
public function acceptsBinding($binding) { return $binding instanceof $this->acceptedBindingClass || $binding === $this->acceptedBindingClass || is_subclass_of($binding, $this->acceptedBindingClass); }
php
public function acceptsBinding($binding) { return $binding instanceof $this->acceptedBindingClass || $binding === $this->acceptedBindingClass || is_subclass_of($binding, $this->acceptedBindingClass); }
[ "public", "function", "acceptsBinding", "(", "$", "binding", ")", "{", "return", "$", "binding", "instanceof", "$", "this", "->", "acceptedBindingClass", "||", "$", "binding", "===", "$", "this", "->", "acceptedBindingClass", "||", "is_subclass_of", "(", "$", "binding", ",", "$", "this", "->", "acceptedBindingClass", ")", ";", "}" ]
Returns whether the type accepts a binding class. @param Binding|string $binding The binding or the fully-qualified name of the binding class. @return bool Returns `true` if the binding can be bound to this type and `false` otherwise.
[ "Returns", "whether", "the", "type", "accepts", "a", "binding", "class", "." ]
train
https://github.com/puli/discovery/blob/975f5e099563f1096bfabc17fbe4d1816408ad98/src/Api/Type/BindingType.php#L248-L253
sulu/SuluSalesShippingBundle
src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php
OrderManager.updateApiEntity
public function updateApiEntity(Order $apiOrder, $locale) { $items = $apiOrder->getItems(); // perform price calucaltion $prices = $supplierItems = null; $totalPrice = $this->priceCalculator->calculate($items, $prices, $supplierItems); if ($supplierItems) { $supplierItems = array_values($supplierItems); // update media api entities $this->createMediaForSupplierItems($supplierItems, $locale); // set grouped items $apiOrder->setSupplierItems($supplierItems); } $this->createMediaForItems($items, $locale); // check if any price in cart has changed $hasChangedPrices = false; foreach ($items as $item) { if ($item->getPriceChange()) { $hasChangedPrices = true; break; } } $apiOrder->setHasChangedPrices($hasChangedPrices); // set total price $apiOrder->setTotalNetPrice($totalPrice); }
php
public function updateApiEntity(Order $apiOrder, $locale) { $items = $apiOrder->getItems(); // perform price calucaltion $prices = $supplierItems = null; $totalPrice = $this->priceCalculator->calculate($items, $prices, $supplierItems); if ($supplierItems) { $supplierItems = array_values($supplierItems); // update media api entities $this->createMediaForSupplierItems($supplierItems, $locale); // set grouped items $apiOrder->setSupplierItems($supplierItems); } $this->createMediaForItems($items, $locale); // check if any price in cart has changed $hasChangedPrices = false; foreach ($items as $item) { if ($item->getPriceChange()) { $hasChangedPrices = true; break; } } $apiOrder->setHasChangedPrices($hasChangedPrices); // set total price $apiOrder->setTotalNetPrice($totalPrice); }
[ "public", "function", "updateApiEntity", "(", "Order", "$", "apiOrder", ",", "$", "locale", ")", "{", "$", "items", "=", "$", "apiOrder", "->", "getItems", "(", ")", ";", "// perform price calucaltion", "$", "prices", "=", "$", "supplierItems", "=", "null", ";", "$", "totalPrice", "=", "$", "this", "->", "priceCalculator", "->", "calculate", "(", "$", "items", ",", "$", "prices", ",", "$", "supplierItems", ")", ";", "if", "(", "$", "supplierItems", ")", "{", "$", "supplierItems", "=", "array_values", "(", "$", "supplierItems", ")", ";", "// update media api entities", "$", "this", "->", "createMediaForSupplierItems", "(", "$", "supplierItems", ",", "$", "locale", ")", ";", "// set grouped items", "$", "apiOrder", "->", "setSupplierItems", "(", "$", "supplierItems", ")", ";", "}", "$", "this", "->", "createMediaForItems", "(", "$", "items", ",", "$", "locale", ")", ";", "// check if any price in cart has changed", "$", "hasChangedPrices", "=", "false", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "if", "(", "$", "item", "->", "getPriceChange", "(", ")", ")", "{", "$", "hasChangedPrices", "=", "true", ";", "break", ";", "}", "}", "$", "apiOrder", "->", "setHasChangedPrices", "(", "$", "hasChangedPrices", ")", ";", "// set total price", "$", "apiOrder", "->", "setTotalNetPrice", "(", "$", "totalPrice", ")", ";", "}" ]
Function updates the api-entity, like price-calculations @param Order $apiOrder
[ "Function", "updates", "the", "api", "-", "entity", "like", "price", "-", "calculations" ]
train
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L362-L392
sulu/SuluSalesShippingBundle
src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php
OrderManager.getContactData
public function getContactData($addressData, $contact) { $result = array(); // if account is set, take account's name if ($addressData && isset($addressData['firstName']) && isset($addressData['lastName'])) { $result['firstName'] = $addressData['firstName']; $result['lastName'] = $addressData['lastName']; $result['fullName'] = $result['firstName'] . ' ' . $result['lastName']; if (isset($addressData['title'])) { $result['title'] = $addressData['title']; } if (isset($addressData['salutation'])) { $result['salutation'] = $addressData['salutation']; } } else { if ($contact) { $result['firstName'] = $contact->getFirstName(); $result['lastName'] = $contact->getLastName(); $result['fullName'] = $contact->getFullName(); $result['salutation'] = $contact->getFormOfAddress(); if ($contact->getTitle() !== null) { $result['title'] = $contact->getTitle()->getTitle(); } } else { throw new MissingOrderAttributeException('firstName, lastName or contact'); } } return $result; }
php
public function getContactData($addressData, $contact) { $result = array(); // if account is set, take account's name if ($addressData && isset($addressData['firstName']) && isset($addressData['lastName'])) { $result['firstName'] = $addressData['firstName']; $result['lastName'] = $addressData['lastName']; $result['fullName'] = $result['firstName'] . ' ' . $result['lastName']; if (isset($addressData['title'])) { $result['title'] = $addressData['title']; } if (isset($addressData['salutation'])) { $result['salutation'] = $addressData['salutation']; } } else { if ($contact) { $result['firstName'] = $contact->getFirstName(); $result['lastName'] = $contact->getLastName(); $result['fullName'] = $contact->getFullName(); $result['salutation'] = $contact->getFormOfAddress(); if ($contact->getTitle() !== null) { $result['title'] = $contact->getTitle()->getTitle(); } } else { throw new MissingOrderAttributeException('firstName, lastName or contact'); } } return $result; }
[ "public", "function", "getContactData", "(", "$", "addressData", ",", "$", "contact", ")", "{", "$", "result", "=", "array", "(", ")", ";", "// if account is set, take account's name", "if", "(", "$", "addressData", "&&", "isset", "(", "$", "addressData", "[", "'firstName'", "]", ")", "&&", "isset", "(", "$", "addressData", "[", "'lastName'", "]", ")", ")", "{", "$", "result", "[", "'firstName'", "]", "=", "$", "addressData", "[", "'firstName'", "]", ";", "$", "result", "[", "'lastName'", "]", "=", "$", "addressData", "[", "'lastName'", "]", ";", "$", "result", "[", "'fullName'", "]", "=", "$", "result", "[", "'firstName'", "]", ".", "' '", ".", "$", "result", "[", "'lastName'", "]", ";", "if", "(", "isset", "(", "$", "addressData", "[", "'title'", "]", ")", ")", "{", "$", "result", "[", "'title'", "]", "=", "$", "addressData", "[", "'title'", "]", ";", "}", "if", "(", "isset", "(", "$", "addressData", "[", "'salutation'", "]", ")", ")", "{", "$", "result", "[", "'salutation'", "]", "=", "$", "addressData", "[", "'salutation'", "]", ";", "}", "}", "else", "{", "if", "(", "$", "contact", ")", "{", "$", "result", "[", "'firstName'", "]", "=", "$", "contact", "->", "getFirstName", "(", ")", ";", "$", "result", "[", "'lastName'", "]", "=", "$", "contact", "->", "getLastName", "(", ")", ";", "$", "result", "[", "'fullName'", "]", "=", "$", "contact", "->", "getFullName", "(", ")", ";", "$", "result", "[", "'salutation'", "]", "=", "$", "contact", "->", "getFormOfAddress", "(", ")", ";", "if", "(", "$", "contact", "->", "getTitle", "(", ")", "!==", "null", ")", "{", "$", "result", "[", "'title'", "]", "=", "$", "contact", "->", "getTitle", "(", ")", "->", "getTitle", "(", ")", ";", "}", "}", "else", "{", "throw", "new", "MissingOrderAttributeException", "(", "'firstName, lastName or contact'", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
Returns contact data as an array. Either by provided address or contact @param array $addressData @param Contact $contact @throws MissingOrderAttributeException @return array
[ "Returns", "contact", "data", "as", "an", "array", ".", "Either", "by", "provided", "address", "or", "contact" ]
train
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L404-L433
sulu/SuluSalesShippingBundle
src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php
OrderManager.convertStatus
public function convertStatus($order, $statusId, $flush = false, $persist = true) { if ($order instanceof Order) { $order = $order->getEntity(); } // get current status $currentStatus = $order->getStatus(); if ($currentStatus) { if ($currentStatus instanceof \Massive\Bundle\Purchase\OrderBundle\Api\OrderStatus) { $currentStatus = $order->getStatus()->getEntity(); } // if status has not changed, skip if ($currentStatus->getId() === $statusId) { return; } } // get desired status $statusEntity = $this->em ->getRepository(self::$orderStatusEntityName) ->find($statusId); if (!$statusEntity) { throw new EntityNotFoundException(self::$orderStatusEntityName, $statusId); } // ACTIVITY LOG $orderActivity = new OrderActivityLog(); $orderActivity->setOrder($order); if ($currentStatus) { $orderActivity->setStatusFrom($currentStatus); } $orderActivity->setStatusTo($statusEntity); $orderActivity->setCreated(new \DateTime()); if ($persist) { $this->em->persist($orderActivity); } // BITMASK $currentBitmaskStatus = $order->getBitmaskStatus(); // if desired status already is in bitmask, remove current state // since this is a step back if ($currentBitmaskStatus && $currentBitmaskStatus & $statusEntity->getId()) { $order->setBitmaskStatus($currentBitmaskStatus & ~$currentStatus->getId()); } else { // else increment bitmask status $order->setBitmaskStatus($currentBitmaskStatus | $statusEntity->getId()); } // check if status has changed if ($statusId === OrderStatusEntity::STATUS_CREATED) { // TODO: re-edit - do some business logic } $order->setStatus($statusEntity); if ($flush === true) { $this->em->flush(); } }
php
public function convertStatus($order, $statusId, $flush = false, $persist = true) { if ($order instanceof Order) { $order = $order->getEntity(); } // get current status $currentStatus = $order->getStatus(); if ($currentStatus) { if ($currentStatus instanceof \Massive\Bundle\Purchase\OrderBundle\Api\OrderStatus) { $currentStatus = $order->getStatus()->getEntity(); } // if status has not changed, skip if ($currentStatus->getId() === $statusId) { return; } } // get desired status $statusEntity = $this->em ->getRepository(self::$orderStatusEntityName) ->find($statusId); if (!$statusEntity) { throw new EntityNotFoundException(self::$orderStatusEntityName, $statusId); } // ACTIVITY LOG $orderActivity = new OrderActivityLog(); $orderActivity->setOrder($order); if ($currentStatus) { $orderActivity->setStatusFrom($currentStatus); } $orderActivity->setStatusTo($statusEntity); $orderActivity->setCreated(new \DateTime()); if ($persist) { $this->em->persist($orderActivity); } // BITMASK $currentBitmaskStatus = $order->getBitmaskStatus(); // if desired status already is in bitmask, remove current state // since this is a step back if ($currentBitmaskStatus && $currentBitmaskStatus & $statusEntity->getId()) { $order->setBitmaskStatus($currentBitmaskStatus & ~$currentStatus->getId()); } else { // else increment bitmask status $order->setBitmaskStatus($currentBitmaskStatus | $statusEntity->getId()); } // check if status has changed if ($statusId === OrderStatusEntity::STATUS_CREATED) { // TODO: re-edit - do some business logic } $order->setStatus($statusEntity); if ($flush === true) { $this->em->flush(); } }
[ "public", "function", "convertStatus", "(", "$", "order", ",", "$", "statusId", ",", "$", "flush", "=", "false", ",", "$", "persist", "=", "true", ")", "{", "if", "(", "$", "order", "instanceof", "Order", ")", "{", "$", "order", "=", "$", "order", "->", "getEntity", "(", ")", ";", "}", "// get current status", "$", "currentStatus", "=", "$", "order", "->", "getStatus", "(", ")", ";", "if", "(", "$", "currentStatus", ")", "{", "if", "(", "$", "currentStatus", "instanceof", "\\", "Massive", "\\", "Bundle", "\\", "Purchase", "\\", "OrderBundle", "\\", "Api", "\\", "OrderStatus", ")", "{", "$", "currentStatus", "=", "$", "order", "->", "getStatus", "(", ")", "->", "getEntity", "(", ")", ";", "}", "// if status has not changed, skip", "if", "(", "$", "currentStatus", "->", "getId", "(", ")", "===", "$", "statusId", ")", "{", "return", ";", "}", "}", "// get desired status", "$", "statusEntity", "=", "$", "this", "->", "em", "->", "getRepository", "(", "self", "::", "$", "orderStatusEntityName", ")", "->", "find", "(", "$", "statusId", ")", ";", "if", "(", "!", "$", "statusEntity", ")", "{", "throw", "new", "EntityNotFoundException", "(", "self", "::", "$", "orderStatusEntityName", ",", "$", "statusId", ")", ";", "}", "// ACTIVITY LOG", "$", "orderActivity", "=", "new", "OrderActivityLog", "(", ")", ";", "$", "orderActivity", "->", "setOrder", "(", "$", "order", ")", ";", "if", "(", "$", "currentStatus", ")", "{", "$", "orderActivity", "->", "setStatusFrom", "(", "$", "currentStatus", ")", ";", "}", "$", "orderActivity", "->", "setStatusTo", "(", "$", "statusEntity", ")", ";", "$", "orderActivity", "->", "setCreated", "(", "new", "\\", "DateTime", "(", ")", ")", ";", "if", "(", "$", "persist", ")", "{", "$", "this", "->", "em", "->", "persist", "(", "$", "orderActivity", ")", ";", "}", "// BITMASK", "$", "currentBitmaskStatus", "=", "$", "order", "->", "getBitmaskStatus", "(", ")", ";", "// if desired status already is in bitmask, remove current state", "// since this is a step back", "if", "(", "$", "currentBitmaskStatus", "&&", "$", "currentBitmaskStatus", "&", "$", "statusEntity", "->", "getId", "(", ")", ")", "{", "$", "order", "->", "setBitmaskStatus", "(", "$", "currentBitmaskStatus", "&", "~", "$", "currentStatus", "->", "getId", "(", ")", ")", ";", "}", "else", "{", "// else increment bitmask status", "$", "order", "->", "setBitmaskStatus", "(", "$", "currentBitmaskStatus", "|", "$", "statusEntity", "->", "getId", "(", ")", ")", ";", "}", "// check if status has changed", "if", "(", "$", "statusId", "===", "OrderStatusEntity", "::", "STATUS_CREATED", ")", "{", "// TODO: re-edit - do some business logic", "}", "$", "order", "->", "setStatus", "(", "$", "statusEntity", ")", ";", "if", "(", "$", "flush", "===", "true", ")", "{", "$", "this", "->", "em", "->", "flush", "(", ")", ";", "}", "}" ]
Converts the status of an order @param ApiOrderInterface|OrderInterface $order @param int $statusId @param bool $flush @param bool $persist @throws \Sulu\Component\Rest\Exception\EntityNotFoundException
[ "Converts", "the", "status", "of", "an", "order" ]
train
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L485-L544
sulu/SuluSalesShippingBundle
src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php
OrderManager.findOrderEntityById
public function findOrderEntityById($id) { try { return $this->em ->getRepository(static::$orderEntityName) ->find($id); } catch (NoResultException $nre) { throw new EntityNotFoundException(static::$orderEntityName, $id); } }
php
public function findOrderEntityById($id) { try { return $this->em ->getRepository(static::$orderEntityName) ->find($id); } catch (NoResultException $nre) { throw new EntityNotFoundException(static::$orderEntityName, $id); } }
[ "public", "function", "findOrderEntityById", "(", "$", "id", ")", "{", "try", "{", "return", "$", "this", "->", "em", "->", "getRepository", "(", "static", "::", "$", "orderEntityName", ")", "->", "find", "(", "$", "id", ")", ";", "}", "catch", "(", "NoResultException", "$", "nre", ")", "{", "throw", "new", "EntityNotFoundException", "(", "static", "::", "$", "orderEntityName", ",", "$", "id", ")", ";", "}", "}" ]
Find order entity by id @param $id @throws \Sulu\Component\Rest\Exception\EntityNotFoundException @return OrderInterface
[ "Find", "order", "entity", "by", "id" ]
train
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L575-L584
sulu/SuluSalesShippingBundle
src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php
OrderManager.findOrderEntityForItemWithId
public function findOrderEntityForItemWithId($id, $returnMultipleResults = false) { try { return $this->em ->getRepository(static::$orderEntityName) ->findOrderForItemWithId($id, $returnMultipleResults); } catch (NoResultException $nre) { throw new EntityNotFoundException(static::$itemEntity, $id); } }
php
public function findOrderEntityForItemWithId($id, $returnMultipleResults = false) { try { return $this->em ->getRepository(static::$orderEntityName) ->findOrderForItemWithId($id, $returnMultipleResults); } catch (NoResultException $nre) { throw new EntityNotFoundException(static::$itemEntity, $id); } }
[ "public", "function", "findOrderEntityForItemWithId", "(", "$", "id", ",", "$", "returnMultipleResults", "=", "false", ")", "{", "try", "{", "return", "$", "this", "->", "em", "->", "getRepository", "(", "static", "::", "$", "orderEntityName", ")", "->", "findOrderForItemWithId", "(", "$", "id", ",", "$", "returnMultipleResults", ")", ";", "}", "catch", "(", "NoResultException", "$", "nre", ")", "{", "throw", "new", "EntityNotFoundException", "(", "static", "::", "$", "itemEntity", ",", "$", "id", ")", ";", "}", "}" ]
Find order for item with id @param int $id @throws \Sulu\Component\Rest\Exception\EntityNotFoundException @return OrderInterface
[ "Find", "order", "for", "item", "with", "id" ]
train
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L595-L604
sulu/SuluSalesShippingBundle
src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php
OrderManager.addItem
public function addItem($itemData, $locale, $userId, $order) { $item = $this->itemManager->save($itemData, $locale, $userId); $order->addItem($item->getEntity()); return $item; }
php
public function addItem($itemData, $locale, $userId, $order) { $item = $this->itemManager->save($itemData, $locale, $userId); $order->addItem($item->getEntity()); return $item; }
[ "public", "function", "addItem", "(", "$", "itemData", ",", "$", "locale", ",", "$", "userId", ",", "$", "order", ")", "{", "$", "item", "=", "$", "this", "->", "itemManager", "->", "save", "(", "$", "itemData", ",", "$", "locale", ",", "$", "userId", ")", ";", "$", "order", "->", "addItem", "(", "$", "item", "->", "getEntity", "(", ")", ")", ";", "return", "$", "item", ";", "}" ]
@param array $itemData @param string $locale @param int $userId @param Order $order @return ApiItemInterface
[ "@param", "array", "$itemData", "@param", "string", "$locale", "@param", "int", "$userId", "@param", "Order", "$order" ]
train
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L708-L715
sulu/SuluSalesShippingBundle
src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php
OrderManager.updateItem
public function updateItem(ItemInterface $item, $itemData, $locale, $userId) { return $this->itemManager->save($itemData, $locale, $userId, $item); }
php
public function updateItem(ItemInterface $item, $itemData, $locale, $userId) { return $this->itemManager->save($itemData, $locale, $userId, $item); }
[ "public", "function", "updateItem", "(", "ItemInterface", "$", "item", ",", "$", "itemData", ",", "$", "locale", ",", "$", "userId", ")", "{", "return", "$", "this", "->", "itemManager", "->", "save", "(", "$", "itemData", ",", "$", "locale", ",", "$", "userId", ",", "$", "item", ")", ";", "}" ]
@param ItemInterface $item @param array $itemData @param string $locale @param int $userId @return null|\Sulu\Bundle\Sales\CoreBundle\Api\Item
[ "@param", "ItemInterface", "$item", "@param", "array", "$itemData", "@param", "string", "$locale", "@param", "int", "$userId" ]
train
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L725-L728
sulu/SuluSalesShippingBundle
src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php
OrderManager.createMediaForSupplierItems
protected function createMediaForSupplierItems($items, $locale) { foreach ($items as $item) { if (isset($item['items']) && count($item['items'] > 0)) { $this->createMediaForItems($item['items'], $locale); } } }
php
protected function createMediaForSupplierItems($items, $locale) { foreach ($items as $item) { if (isset($item['items']) && count($item['items'] > 0)) { $this->createMediaForItems($item['items'], $locale); } } }
[ "protected", "function", "createMediaForSupplierItems", "(", "$", "items", ",", "$", "locale", ")", "{", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "if", "(", "isset", "(", "$", "item", "[", "'items'", "]", ")", "&&", "count", "(", "$", "item", "[", "'items'", "]", ">", "0", ")", ")", "{", "$", "this", "->", "createMediaForItems", "(", "$", "item", "[", "'items'", "]", ",", "$", "locale", ")", ";", "}", "}", "}" ]
Creates correct media-api for supplier-items array @param array $items @param string $locale
[ "Creates", "correct", "media", "-", "api", "for", "supplier", "-", "items", "array" ]
train
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L790-L797
sulu/SuluSalesShippingBundle
src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php
OrderManager.createMediaForItems
protected function createMediaForItems($items, $locale) { foreach ($items as $item) { $product = $item->getProduct(); if ($product) { $this->productManager->createProductMedia($product, $locale); } // Set api product for returning media-urls $item->setProduct($product); } }
php
protected function createMediaForItems($items, $locale) { foreach ($items as $item) { $product = $item->getProduct(); if ($product) { $this->productManager->createProductMedia($product, $locale); } // Set api product for returning media-urls $item->setProduct($product); } }
[ "protected", "function", "createMediaForItems", "(", "$", "items", ",", "$", "locale", ")", "{", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "$", "product", "=", "$", "item", "->", "getProduct", "(", ")", ";", "if", "(", "$", "product", ")", "{", "$", "this", "->", "productManager", "->", "createProductMedia", "(", "$", "product", ",", "$", "locale", ")", ";", "}", "// Set api product for returning media-urls", "$", "item", "->", "setProduct", "(", "$", "product", ")", ";", "}", "}" ]
Creates correct media-api for items array @param array $items @param string $locale
[ "Creates", "correct", "media", "-", "api", "for", "items", "array" ]
train
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L805-L815
sulu/SuluSalesShippingBundle
src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php
OrderManager.setOrderType
private function setOrderType($data, ApiOrderInterface $order, $patch = false) { // get OrderType $type = $this->getProperty($data, 'type', $order->getType()); // set order type if (isset($data['type'])) { if (is_array($type) && isset($type['id'])) { // if provided as array $typeId = $type['id']; } elseif (is_numeric($type)) { // if is numeric $typeId = $type; } else { throw new OrderException('No typeid given'); } } elseif (!$patch) { // default type is manual $typeId = OrderType::MANUAL; } else { // keep current type return; } // get entity $orderType = $this->getOrderTypeEntityById($typeId); if (!$orderType) { throw new EntityNotFoundException(static::$orderTypeEntityName, $typeId); } // set order type $order->setType($orderType); }
php
private function setOrderType($data, ApiOrderInterface $order, $patch = false) { // get OrderType $type = $this->getProperty($data, 'type', $order->getType()); // set order type if (isset($data['type'])) { if (is_array($type) && isset($type['id'])) { // if provided as array $typeId = $type['id']; } elseif (is_numeric($type)) { // if is numeric $typeId = $type; } else { throw new OrderException('No typeid given'); } } elseif (!$patch) { // default type is manual $typeId = OrderType::MANUAL; } else { // keep current type return; } // get entity $orderType = $this->getOrderTypeEntityById($typeId); if (!$orderType) { throw new EntityNotFoundException(static::$orderTypeEntityName, $typeId); } // set order type $order->setType($orderType); }
[ "private", "function", "setOrderType", "(", "$", "data", ",", "ApiOrderInterface", "$", "order", ",", "$", "patch", "=", "false", ")", "{", "// get OrderType", "$", "type", "=", "$", "this", "->", "getProperty", "(", "$", "data", ",", "'type'", ",", "$", "order", "->", "getType", "(", ")", ")", ";", "// set order type", "if", "(", "isset", "(", "$", "data", "[", "'type'", "]", ")", ")", "{", "if", "(", "is_array", "(", "$", "type", ")", "&&", "isset", "(", "$", "type", "[", "'id'", "]", ")", ")", "{", "// if provided as array", "$", "typeId", "=", "$", "type", "[", "'id'", "]", ";", "}", "elseif", "(", "is_numeric", "(", "$", "type", ")", ")", "{", "// if is numeric", "$", "typeId", "=", "$", "type", ";", "}", "else", "{", "throw", "new", "OrderException", "(", "'No typeid given'", ")", ";", "}", "}", "elseif", "(", "!", "$", "patch", ")", "{", "// default type is manual", "$", "typeId", "=", "OrderType", "::", "MANUAL", ";", "}", "else", "{", "// keep current type", "return", ";", "}", "// get entity", "$", "orderType", "=", "$", "this", "->", "getOrderTypeEntityById", "(", "$", "typeId", ")", ";", "if", "(", "!", "$", "orderType", ")", "{", "throw", "new", "EntityNotFoundException", "(", "static", "::", "$", "orderTypeEntityName", ",", "$", "typeId", ")", ";", "}", "// set order type", "$", "order", "->", "setType", "(", "$", "orderType", ")", ";", "}" ]
Sets OrderType on an order @param array $data @param ApiOrderInterface $order @throws EntityNotFoundException @throws OrderException
[ "Sets", "OrderType", "on", "an", "order" ]
train
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L888-L919
sulu/SuluSalesShippingBundle
src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php
OrderManager.initializeFieldDescriptors
private function initializeFieldDescriptors($locale) { $this->fieldDescriptors['id'] = new DoctrineFieldDescriptor( 'id', 'id', static::$orderEntityName, 'public.id', array(), true, false, 'string' ); $this->fieldDescriptors['number'] = new DoctrineFieldDescriptor( 'number', 'number', static::$orderEntityName, 'salesorder.orders.number', array(), false, true, 'string' ); // TODO: get customer from order-address $contactJoin = array( static::$orderAddressEntityName => new DoctrineJoinDescriptor( static::$orderAddressEntityName, static::$orderEntityName . '.invoiceAddress' ) ); $this->fieldDescriptors['account'] = new DoctrineConcatenationFieldDescriptor( array( new DoctrineFieldDescriptor( 'accountName', 'account', static::$orderAddressEntityName, 'contact.contacts.contact', $contactJoin ) ), 'account', 'salesorder.orders.account', ' ', false, false, 'string', '', '160px' ); $this->fieldDescriptors['contact'] = new DoctrineConcatenationFieldDescriptor( array( new DoctrineFieldDescriptor( 'firstName', 'contact', static::$orderAddressEntityName, 'contact.contacts.contact', $contactJoin ), new DoctrineFieldDescriptor( 'lastName', 'contact', static::$orderAddressEntityName, 'contact.contacts.contact', $contactJoin ) ), 'contact', 'salesorder.orders.contact', ' ', false, false, 'string', '', '160px', false ); $this->fieldDescriptors['status'] = new DoctrineFieldDescriptor( 'name', 'status', static::$orderStatusTranslationEntityName, 'salesorder.orders.status', array( static::$orderStatusEntityName => new DoctrineJoinDescriptor( static::$orderStatusEntityName, static::$orderEntityName . '.status' ), static::$orderStatusTranslationEntityName => new DoctrineJoinDescriptor( static::$orderStatusTranslationEntityName, static::$orderStatusEntityName . '.translations', static::$orderStatusTranslationEntityName . ".locale = '" . $locale . "'" ) ), false, false, 'string' ); $this->fieldDescriptors['type'] = new DoctrineFieldDescriptor( 'name', 'type', static::$orderTypeTranslationEntityName, 'salesorder.orders.type', array( static::$orderTypeEntityName => new DoctrineJoinDescriptor( static::$orderTypeEntityName, static::$orderEntityName . '.type' ), static::$orderTypeTranslationEntityName => new DoctrineJoinDescriptor( static::$orderTypeTranslationEntityName, static::$orderTypeEntityName . '.translations', static::$orderTypeTranslationEntityName . ".locale = '" . $locale . "'" ) ), false, false, 'string' ); $this->fieldDescriptors['created'] = new DoctrineFieldDescriptor( 'created', 'created', static::$orderEntityName, 'public.created', array(), false, false, 'date' ); $contactJoin = array( self::$contactEntityName => new DoctrineJoinDescriptor( self::$contactEntityName, self::$orderEntityName . '.responsibleContact' ) ); $this->fieldDescriptors['responsibleContact'] = new DoctrineConcatenationFieldDescriptor( array( new DoctrineFieldDescriptor( 'firstName', 'contact', self::$contactEntityName, 'contact.contacts.contact', $contactJoin ), new DoctrineFieldDescriptor( 'lastName', 'contact', self::$contactEntityName, 'contact.contacts.contact', $contactJoin ) ), 'responsibleContact', 'salescore.responsible-contact', ' ', false, false, 'string', '', '160px', false ); }
php
private function initializeFieldDescriptors($locale) { $this->fieldDescriptors['id'] = new DoctrineFieldDescriptor( 'id', 'id', static::$orderEntityName, 'public.id', array(), true, false, 'string' ); $this->fieldDescriptors['number'] = new DoctrineFieldDescriptor( 'number', 'number', static::$orderEntityName, 'salesorder.orders.number', array(), false, true, 'string' ); // TODO: get customer from order-address $contactJoin = array( static::$orderAddressEntityName => new DoctrineJoinDescriptor( static::$orderAddressEntityName, static::$orderEntityName . '.invoiceAddress' ) ); $this->fieldDescriptors['account'] = new DoctrineConcatenationFieldDescriptor( array( new DoctrineFieldDescriptor( 'accountName', 'account', static::$orderAddressEntityName, 'contact.contacts.contact', $contactJoin ) ), 'account', 'salesorder.orders.account', ' ', false, false, 'string', '', '160px' ); $this->fieldDescriptors['contact'] = new DoctrineConcatenationFieldDescriptor( array( new DoctrineFieldDescriptor( 'firstName', 'contact', static::$orderAddressEntityName, 'contact.contacts.contact', $contactJoin ), new DoctrineFieldDescriptor( 'lastName', 'contact', static::$orderAddressEntityName, 'contact.contacts.contact', $contactJoin ) ), 'contact', 'salesorder.orders.contact', ' ', false, false, 'string', '', '160px', false ); $this->fieldDescriptors['status'] = new DoctrineFieldDescriptor( 'name', 'status', static::$orderStatusTranslationEntityName, 'salesorder.orders.status', array( static::$orderStatusEntityName => new DoctrineJoinDescriptor( static::$orderStatusEntityName, static::$orderEntityName . '.status' ), static::$orderStatusTranslationEntityName => new DoctrineJoinDescriptor( static::$orderStatusTranslationEntityName, static::$orderStatusEntityName . '.translations', static::$orderStatusTranslationEntityName . ".locale = '" . $locale . "'" ) ), false, false, 'string' ); $this->fieldDescriptors['type'] = new DoctrineFieldDescriptor( 'name', 'type', static::$orderTypeTranslationEntityName, 'salesorder.orders.type', array( static::$orderTypeEntityName => new DoctrineJoinDescriptor( static::$orderTypeEntityName, static::$orderEntityName . '.type' ), static::$orderTypeTranslationEntityName => new DoctrineJoinDescriptor( static::$orderTypeTranslationEntityName, static::$orderTypeEntityName . '.translations', static::$orderTypeTranslationEntityName . ".locale = '" . $locale . "'" ) ), false, false, 'string' ); $this->fieldDescriptors['created'] = new DoctrineFieldDescriptor( 'created', 'created', static::$orderEntityName, 'public.created', array(), false, false, 'date' ); $contactJoin = array( self::$contactEntityName => new DoctrineJoinDescriptor( self::$contactEntityName, self::$orderEntityName . '.responsibleContact' ) ); $this->fieldDescriptors['responsibleContact'] = new DoctrineConcatenationFieldDescriptor( array( new DoctrineFieldDescriptor( 'firstName', 'contact', self::$contactEntityName, 'contact.contacts.contact', $contactJoin ), new DoctrineFieldDescriptor( 'lastName', 'contact', self::$contactEntityName, 'contact.contacts.contact', $contactJoin ) ), 'responsibleContact', 'salescore.responsible-contact', ' ', false, false, 'string', '', '160px', false ); }
[ "private", "function", "initializeFieldDescriptors", "(", "$", "locale", ")", "{", "$", "this", "->", "fieldDescriptors", "[", "'id'", "]", "=", "new", "DoctrineFieldDescriptor", "(", "'id'", ",", "'id'", ",", "static", "::", "$", "orderEntityName", ",", "'public.id'", ",", "array", "(", ")", ",", "true", ",", "false", ",", "'string'", ")", ";", "$", "this", "->", "fieldDescriptors", "[", "'number'", "]", "=", "new", "DoctrineFieldDescriptor", "(", "'number'", ",", "'number'", ",", "static", "::", "$", "orderEntityName", ",", "'salesorder.orders.number'", ",", "array", "(", ")", ",", "false", ",", "true", ",", "'string'", ")", ";", "// TODO: get customer from order-address", "$", "contactJoin", "=", "array", "(", "static", "::", "$", "orderAddressEntityName", "=>", "new", "DoctrineJoinDescriptor", "(", "static", "::", "$", "orderAddressEntityName", ",", "static", "::", "$", "orderEntityName", ".", "'.invoiceAddress'", ")", ")", ";", "$", "this", "->", "fieldDescriptors", "[", "'account'", "]", "=", "new", "DoctrineConcatenationFieldDescriptor", "(", "array", "(", "new", "DoctrineFieldDescriptor", "(", "'accountName'", ",", "'account'", ",", "static", "::", "$", "orderAddressEntityName", ",", "'contact.contacts.contact'", ",", "$", "contactJoin", ")", ")", ",", "'account'", ",", "'salesorder.orders.account'", ",", "' '", ",", "false", ",", "false", ",", "'string'", ",", "''", ",", "'160px'", ")", ";", "$", "this", "->", "fieldDescriptors", "[", "'contact'", "]", "=", "new", "DoctrineConcatenationFieldDescriptor", "(", "array", "(", "new", "DoctrineFieldDescriptor", "(", "'firstName'", ",", "'contact'", ",", "static", "::", "$", "orderAddressEntityName", ",", "'contact.contacts.contact'", ",", "$", "contactJoin", ")", ",", "new", "DoctrineFieldDescriptor", "(", "'lastName'", ",", "'contact'", ",", "static", "::", "$", "orderAddressEntityName", ",", "'contact.contacts.contact'", ",", "$", "contactJoin", ")", ")", ",", "'contact'", ",", "'salesorder.orders.contact'", ",", "' '", ",", "false", ",", "false", ",", "'string'", ",", "''", ",", "'160px'", ",", "false", ")", ";", "$", "this", "->", "fieldDescriptors", "[", "'status'", "]", "=", "new", "DoctrineFieldDescriptor", "(", "'name'", ",", "'status'", ",", "static", "::", "$", "orderStatusTranslationEntityName", ",", "'salesorder.orders.status'", ",", "array", "(", "static", "::", "$", "orderStatusEntityName", "=>", "new", "DoctrineJoinDescriptor", "(", "static", "::", "$", "orderStatusEntityName", ",", "static", "::", "$", "orderEntityName", ".", "'.status'", ")", ",", "static", "::", "$", "orderStatusTranslationEntityName", "=>", "new", "DoctrineJoinDescriptor", "(", "static", "::", "$", "orderStatusTranslationEntityName", ",", "static", "::", "$", "orderStatusEntityName", ".", "'.translations'", ",", "static", "::", "$", "orderStatusTranslationEntityName", ".", "\".locale = '\"", ".", "$", "locale", ".", "\"'\"", ")", ")", ",", "false", ",", "false", ",", "'string'", ")", ";", "$", "this", "->", "fieldDescriptors", "[", "'type'", "]", "=", "new", "DoctrineFieldDescriptor", "(", "'name'", ",", "'type'", ",", "static", "::", "$", "orderTypeTranslationEntityName", ",", "'salesorder.orders.type'", ",", "array", "(", "static", "::", "$", "orderTypeEntityName", "=>", "new", "DoctrineJoinDescriptor", "(", "static", "::", "$", "orderTypeEntityName", ",", "static", "::", "$", "orderEntityName", ".", "'.type'", ")", ",", "static", "::", "$", "orderTypeTranslationEntityName", "=>", "new", "DoctrineJoinDescriptor", "(", "static", "::", "$", "orderTypeTranslationEntityName", ",", "static", "::", "$", "orderTypeEntityName", ".", "'.translations'", ",", "static", "::", "$", "orderTypeTranslationEntityName", ".", "\".locale = '\"", ".", "$", "locale", ".", "\"'\"", ")", ")", ",", "false", ",", "false", ",", "'string'", ")", ";", "$", "this", "->", "fieldDescriptors", "[", "'created'", "]", "=", "new", "DoctrineFieldDescriptor", "(", "'created'", ",", "'created'", ",", "static", "::", "$", "orderEntityName", ",", "'public.created'", ",", "array", "(", ")", ",", "false", ",", "false", ",", "'date'", ")", ";", "$", "contactJoin", "=", "array", "(", "self", "::", "$", "contactEntityName", "=>", "new", "DoctrineJoinDescriptor", "(", "self", "::", "$", "contactEntityName", ",", "self", "::", "$", "orderEntityName", ".", "'.responsibleContact'", ")", ")", ";", "$", "this", "->", "fieldDescriptors", "[", "'responsibleContact'", "]", "=", "new", "DoctrineConcatenationFieldDescriptor", "(", "array", "(", "new", "DoctrineFieldDescriptor", "(", "'firstName'", ",", "'contact'", ",", "self", "::", "$", "contactEntityName", ",", "'contact.contacts.contact'", ",", "$", "contactJoin", ")", ",", "new", "DoctrineFieldDescriptor", "(", "'lastName'", ",", "'contact'", ",", "self", "::", "$", "contactEntityName", ",", "'contact.contacts.contact'", ",", "$", "contactJoin", ")", ")", ",", "'responsibleContact'", ",", "'salescore.responsible-contact'", ",", "' '", ",", "false", ",", "false", ",", "'string'", ",", "''", ",", "'160px'", ",", "false", ")", ";", "}" ]
Initializes field descriptors @param string $locale
[ "Initializes", "field", "descriptors" ]
train
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L926-L1093
sulu/SuluSalesShippingBundle
src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php
OrderManager.addContactRelation
private function addContactRelation(array $data, $key, $addCallback) { $contact = null; if (array_key_exists($key, $data) && is_array($data[$key]) && array_key_exists('id', $data[$key]) ) { /** @var Contact $contact */ $contactId = $data[$key]['id']; $contact = $this->em->getRepository(static::$contactEntityName)->find($contactId); if (!$contact) { throw new OrderDependencyNotFoundException(static::$contactEntityName, $contactId); } $addCallback($contact); } return $contact; }
php
private function addContactRelation(array $data, $key, $addCallback) { $contact = null; if (array_key_exists($key, $data) && is_array($data[$key]) && array_key_exists('id', $data[$key]) ) { /** @var Contact $contact */ $contactId = $data[$key]['id']; $contact = $this->em->getRepository(static::$contactEntityName)->find($contactId); if (!$contact) { throw new OrderDependencyNotFoundException(static::$contactEntityName, $contactId); } $addCallback($contact); } return $contact; }
[ "private", "function", "addContactRelation", "(", "array", "$", "data", ",", "$", "key", ",", "$", "addCallback", ")", "{", "$", "contact", "=", "null", ";", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "data", ")", "&&", "is_array", "(", "$", "data", "[", "$", "key", "]", ")", "&&", "array_key_exists", "(", "'id'", ",", "$", "data", "[", "$", "key", "]", ")", ")", "{", "/** @var Contact $contact */", "$", "contactId", "=", "$", "data", "[", "$", "key", "]", "[", "'id'", "]", ";", "$", "contact", "=", "$", "this", "->", "em", "->", "getRepository", "(", "static", "::", "$", "contactEntityName", ")", "->", "find", "(", "$", "contactId", ")", ";", "if", "(", "!", "$", "contact", ")", "{", "throw", "new", "OrderDependencyNotFoundException", "(", "static", "::", "$", "contactEntityName", ",", "$", "contactId", ")", ";", "}", "$", "addCallback", "(", "$", "contact", ")", ";", "}", "return", "$", "contact", ";", "}" ]
Searches for contact in specified data and calls callback function @param array $data @param string $key @param callable $addCallback @throws Exception\MissingOrderAttributeException @throws Exception\OrderDependencyNotFoundException @return Contact|null
[ "Searches", "for", "contact", "in", "specified", "data", "and", "calls", "callback", "function" ]
train
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L1145-L1162
sulu/SuluSalesShippingBundle
src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php
OrderManager.setTermsOfDelivery
private function setTermsOfDelivery($data, Order $order, $patch = false) { $terms = null; // terms of delivery $termsOfDeliveryData = $this->getProperty($data, 'termsOfDelivery'); $termsOfDeliveryContentData = $this->getProperty($data, 'termsOfDeliveryContent'); if ($termsOfDeliveryData) { if (!array_key_exists('id', $termsOfDeliveryData)) { throw new MissingOrderAttributeException('termsOfDelivery.id'); } // TODO: inject repository class $terms = $this->em->getRepository(static::$termsOfDeliveryEntityName)->find($termsOfDeliveryData['id']); if (!$terms) { throw new OrderDependencyNotFoundException( static::$termsOfDeliveryEntityName, $termsOfDeliveryData['id'] ); } $order->setTermsOfDelivery($terms); $order->setTermsOfDeliveryContent($terms->getTerms()); } elseif (!$patch) { $order->setTermsOfDelivery(null); $order->setTermsOfDeliveryContent(null); } // set content data if ($termsOfDeliveryContentData) { $order->setTermsOfDeliveryContent($termsOfDeliveryContentData); } return $terms; }
php
private function setTermsOfDelivery($data, Order $order, $patch = false) { $terms = null; // terms of delivery $termsOfDeliveryData = $this->getProperty($data, 'termsOfDelivery'); $termsOfDeliveryContentData = $this->getProperty($data, 'termsOfDeliveryContent'); if ($termsOfDeliveryData) { if (!array_key_exists('id', $termsOfDeliveryData)) { throw new MissingOrderAttributeException('termsOfDelivery.id'); } // TODO: inject repository class $terms = $this->em->getRepository(static::$termsOfDeliveryEntityName)->find($termsOfDeliveryData['id']); if (!$terms) { throw new OrderDependencyNotFoundException( static::$termsOfDeliveryEntityName, $termsOfDeliveryData['id'] ); } $order->setTermsOfDelivery($terms); $order->setTermsOfDeliveryContent($terms->getTerms()); } elseif (!$patch) { $order->setTermsOfDelivery(null); $order->setTermsOfDeliveryContent(null); } // set content data if ($termsOfDeliveryContentData) { $order->setTermsOfDeliveryContent($termsOfDeliveryContentData); } return $terms; }
[ "private", "function", "setTermsOfDelivery", "(", "$", "data", ",", "Order", "$", "order", ",", "$", "patch", "=", "false", ")", "{", "$", "terms", "=", "null", ";", "// terms of delivery", "$", "termsOfDeliveryData", "=", "$", "this", "->", "getProperty", "(", "$", "data", ",", "'termsOfDelivery'", ")", ";", "$", "termsOfDeliveryContentData", "=", "$", "this", "->", "getProperty", "(", "$", "data", ",", "'termsOfDeliveryContent'", ")", ";", "if", "(", "$", "termsOfDeliveryData", ")", "{", "if", "(", "!", "array_key_exists", "(", "'id'", ",", "$", "termsOfDeliveryData", ")", ")", "{", "throw", "new", "MissingOrderAttributeException", "(", "'termsOfDelivery.id'", ")", ";", "}", "// TODO: inject repository class", "$", "terms", "=", "$", "this", "->", "em", "->", "getRepository", "(", "static", "::", "$", "termsOfDeliveryEntityName", ")", "->", "find", "(", "$", "termsOfDeliveryData", "[", "'id'", "]", ")", ";", "if", "(", "!", "$", "terms", ")", "{", "throw", "new", "OrderDependencyNotFoundException", "(", "static", "::", "$", "termsOfDeliveryEntityName", ",", "$", "termsOfDeliveryData", "[", "'id'", "]", ")", ";", "}", "$", "order", "->", "setTermsOfDelivery", "(", "$", "terms", ")", ";", "$", "order", "->", "setTermsOfDeliveryContent", "(", "$", "terms", "->", "getTerms", "(", ")", ")", ";", "}", "elseif", "(", "!", "$", "patch", ")", "{", "$", "order", "->", "setTermsOfDelivery", "(", "null", ")", ";", "$", "order", "->", "setTermsOfDeliveryContent", "(", "null", ")", ";", "}", "// set content data", "if", "(", "$", "termsOfDeliveryContentData", ")", "{", "$", "order", "->", "setTermsOfDeliveryContent", "(", "$", "termsOfDeliveryContentData", ")", ";", "}", "return", "$", "terms", ";", "}" ]
@param array $data @param Order $order @param bool $patch @throws MissingOrderAttributeException @throws OrderDependencyNotFoundException @return null|object
[ "@param", "array", "$data", "@param", "Order", "$order", "@param", "bool", "$patch" ]
train
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L1174-L1204
sulu/SuluSalesShippingBundle
src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php
OrderManager.setTermsOfPayment
private function setTermsOfPayment($data, Order $order, $patch = false) { $terms = null; // terms of delivery $termsOfPaymentData = $this->getProperty($data, 'termsOfPayment'); $termsOfPaymentContentData = $this->getProperty($data, 'termsOfPaymentContent'); if ($termsOfPaymentData) { if (!array_key_exists('id', $termsOfPaymentData)) { throw new MissingOrderAttributeException('termsOfPayment.id'); } // TODO: inject repository class $terms = $this->em->getRepository(static::$termsOfPaymentEntityName)->find($termsOfPaymentData['id']); if (!$terms) { throw new OrderDependencyNotFoundException( static::$termsOfPaymentEntityName, $termsOfPaymentData['id'] ); } $order->setTermsOfPayment($terms); $order->setTermsOfPaymentContent($terms->getTerms()); } elseif (!$patch) { $order->setTermsOfPayment(null); $order->setTermsOfPaymentContent(null); } // set content data if ($termsOfPaymentContentData) { $order->setTermsOfPaymentContent($termsOfPaymentContentData); } return $terms; }
php
private function setTermsOfPayment($data, Order $order, $patch = false) { $terms = null; // terms of delivery $termsOfPaymentData = $this->getProperty($data, 'termsOfPayment'); $termsOfPaymentContentData = $this->getProperty($data, 'termsOfPaymentContent'); if ($termsOfPaymentData) { if (!array_key_exists('id', $termsOfPaymentData)) { throw new MissingOrderAttributeException('termsOfPayment.id'); } // TODO: inject repository class $terms = $this->em->getRepository(static::$termsOfPaymentEntityName)->find($termsOfPaymentData['id']); if (!$terms) { throw new OrderDependencyNotFoundException( static::$termsOfPaymentEntityName, $termsOfPaymentData['id'] ); } $order->setTermsOfPayment($terms); $order->setTermsOfPaymentContent($terms->getTerms()); } elseif (!$patch) { $order->setTermsOfPayment(null); $order->setTermsOfPaymentContent(null); } // set content data if ($termsOfPaymentContentData) { $order->setTermsOfPaymentContent($termsOfPaymentContentData); } return $terms; }
[ "private", "function", "setTermsOfPayment", "(", "$", "data", ",", "Order", "$", "order", ",", "$", "patch", "=", "false", ")", "{", "$", "terms", "=", "null", ";", "// terms of delivery", "$", "termsOfPaymentData", "=", "$", "this", "->", "getProperty", "(", "$", "data", ",", "'termsOfPayment'", ")", ";", "$", "termsOfPaymentContentData", "=", "$", "this", "->", "getProperty", "(", "$", "data", ",", "'termsOfPaymentContent'", ")", ";", "if", "(", "$", "termsOfPaymentData", ")", "{", "if", "(", "!", "array_key_exists", "(", "'id'", ",", "$", "termsOfPaymentData", ")", ")", "{", "throw", "new", "MissingOrderAttributeException", "(", "'termsOfPayment.id'", ")", ";", "}", "// TODO: inject repository class", "$", "terms", "=", "$", "this", "->", "em", "->", "getRepository", "(", "static", "::", "$", "termsOfPaymentEntityName", ")", "->", "find", "(", "$", "termsOfPaymentData", "[", "'id'", "]", ")", ";", "if", "(", "!", "$", "terms", ")", "{", "throw", "new", "OrderDependencyNotFoundException", "(", "static", "::", "$", "termsOfPaymentEntityName", ",", "$", "termsOfPaymentData", "[", "'id'", "]", ")", ";", "}", "$", "order", "->", "setTermsOfPayment", "(", "$", "terms", ")", ";", "$", "order", "->", "setTermsOfPaymentContent", "(", "$", "terms", "->", "getTerms", "(", ")", ")", ";", "}", "elseif", "(", "!", "$", "patch", ")", "{", "$", "order", "->", "setTermsOfPayment", "(", "null", ")", ";", "$", "order", "->", "setTermsOfPaymentContent", "(", "null", ")", ";", "}", "// set content data", "if", "(", "$", "termsOfPaymentContentData", ")", "{", "$", "order", "->", "setTermsOfPaymentContent", "(", "$", "termsOfPaymentContentData", ")", ";", "}", "return", "$", "terms", ";", "}" ]
@param array $data @param Order $order @param bool $patch @throws MissingOrderAttributeException @throws OrderDependencyNotFoundException @return null|object
[ "@param", "array", "$data", "@param", "Order", "$order", "@param", "bool", "$patch" ]
train
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L1216-L1246
sulu/SuluSalesShippingBundle
src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php
OrderManager.setCustomerAccount
private function setCustomerAccount($data, Order $order, $patch = false) { $accountData = $this->getProperty($data, 'customerAccount'); if ($accountData) { if (!array_key_exists('id', $accountData)) { throw new MissingOrderAttributeException('account.id'); } $account = $this->accountRepository->find($accountData['id']); if (!$account) { throw new OrderDependencyNotFoundException('Account', $accountData['id']); } $order->setCustomerAccount($account); return $account; } elseif (!$patch) { $order->setCustomerAccount(null); } return null; }
php
private function setCustomerAccount($data, Order $order, $patch = false) { $accountData = $this->getProperty($data, 'customerAccount'); if ($accountData) { if (!array_key_exists('id', $accountData)) { throw new MissingOrderAttributeException('account.id'); } $account = $this->accountRepository->find($accountData['id']); if (!$account) { throw new OrderDependencyNotFoundException('Account', $accountData['id']); } $order->setCustomerAccount($account); return $account; } elseif (!$patch) { $order->setCustomerAccount(null); } return null; }
[ "private", "function", "setCustomerAccount", "(", "$", "data", ",", "Order", "$", "order", ",", "$", "patch", "=", "false", ")", "{", "$", "accountData", "=", "$", "this", "->", "getProperty", "(", "$", "data", ",", "'customerAccount'", ")", ";", "if", "(", "$", "accountData", ")", "{", "if", "(", "!", "array_key_exists", "(", "'id'", ",", "$", "accountData", ")", ")", "{", "throw", "new", "MissingOrderAttributeException", "(", "'account.id'", ")", ";", "}", "$", "account", "=", "$", "this", "->", "accountRepository", "->", "find", "(", "$", "accountData", "[", "'id'", "]", ")", ";", "if", "(", "!", "$", "account", ")", "{", "throw", "new", "OrderDependencyNotFoundException", "(", "'Account'", ",", "$", "accountData", "[", "'id'", "]", ")", ";", "}", "$", "order", "->", "setCustomerAccount", "(", "$", "account", ")", ";", "return", "$", "account", ";", "}", "elseif", "(", "!", "$", "patch", ")", "{", "$", "order", "->", "setCustomerAccount", "(", "null", ")", ";", "}", "return", "null", ";", "}" ]
Sets the customer account of an order @param array $data @param Order $order @param bool $patch @return null|object @throws MissingOrderAttributeException @throws OrderDependencyNotFoundException
[ "Sets", "the", "customer", "account", "of", "an", "order" ]
train
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L1259-L1278
sulu/SuluSalesShippingBundle
src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php
OrderManager.processItems
private function processItems($data, Order $order, $locale, $userId = null) { $result = true; try { if ($this->checkIfSet('items', $data)) { // items has to be an array if (!is_array($data['items'])) { throw new MissingOrderAttributeException('items array'); } $items = $data['items']; $get = function ($item) { return $item->getId(); }; $delete = function ($item) use ($order) { $this->removeItem($item->getEntity(), $order->getEntity()); }; $update = function ($item, $matchedEntry) use ($locale, $userId, $order) { $item = $item->getEntity(); $itemEntity = $this->updateItem($item, $matchedEntry, $locale, $userId); return $itemEntity ? true : false; }; $add = function ($itemData) use ($locale, $userId, $order) { return $this->addItem($itemData, $locale, $userId, $order); }; $result = $this->processSubEntities( $order->getItems(), $items, $get, $add, $update, $delete ); } } catch (\Exception $e) { throw new OrderException('Error while creating items: ' . $e->getMessage()); } return $result; }
php
private function processItems($data, Order $order, $locale, $userId = null) { $result = true; try { if ($this->checkIfSet('items', $data)) { // items has to be an array if (!is_array($data['items'])) { throw new MissingOrderAttributeException('items array'); } $items = $data['items']; $get = function ($item) { return $item->getId(); }; $delete = function ($item) use ($order) { $this->removeItem($item->getEntity(), $order->getEntity()); }; $update = function ($item, $matchedEntry) use ($locale, $userId, $order) { $item = $item->getEntity(); $itemEntity = $this->updateItem($item, $matchedEntry, $locale, $userId); return $itemEntity ? true : false; }; $add = function ($itemData) use ($locale, $userId, $order) { return $this->addItem($itemData, $locale, $userId, $order); }; $result = $this->processSubEntities( $order->getItems(), $items, $get, $add, $update, $delete ); } } catch (\Exception $e) { throw new OrderException('Error while creating items: ' . $e->getMessage()); } return $result; }
[ "private", "function", "processItems", "(", "$", "data", ",", "Order", "$", "order", ",", "$", "locale", ",", "$", "userId", "=", "null", ")", "{", "$", "result", "=", "true", ";", "try", "{", "if", "(", "$", "this", "->", "checkIfSet", "(", "'items'", ",", "$", "data", ")", ")", "{", "// items has to be an array", "if", "(", "!", "is_array", "(", "$", "data", "[", "'items'", "]", ")", ")", "{", "throw", "new", "MissingOrderAttributeException", "(", "'items array'", ")", ";", "}", "$", "items", "=", "$", "data", "[", "'items'", "]", ";", "$", "get", "=", "function", "(", "$", "item", ")", "{", "return", "$", "item", "->", "getId", "(", ")", ";", "}", ";", "$", "delete", "=", "function", "(", "$", "item", ")", "use", "(", "$", "order", ")", "{", "$", "this", "->", "removeItem", "(", "$", "item", "->", "getEntity", "(", ")", ",", "$", "order", "->", "getEntity", "(", ")", ")", ";", "}", ";", "$", "update", "=", "function", "(", "$", "item", ",", "$", "matchedEntry", ")", "use", "(", "$", "locale", ",", "$", "userId", ",", "$", "order", ")", "{", "$", "item", "=", "$", "item", "->", "getEntity", "(", ")", ";", "$", "itemEntity", "=", "$", "this", "->", "updateItem", "(", "$", "item", ",", "$", "matchedEntry", ",", "$", "locale", ",", "$", "userId", ")", ";", "return", "$", "itemEntity", "?", "true", ":", "false", ";", "}", ";", "$", "add", "=", "function", "(", "$", "itemData", ")", "use", "(", "$", "locale", ",", "$", "userId", ",", "$", "order", ")", "{", "return", "$", "this", "->", "addItem", "(", "$", "itemData", ",", "$", "locale", ",", "$", "userId", ",", "$", "order", ")", ";", "}", ";", "$", "result", "=", "$", "this", "->", "processSubEntities", "(", "$", "order", "->", "getItems", "(", ")", ",", "$", "items", ",", "$", "get", ",", "$", "add", ",", "$", "update", ",", "$", "delete", ")", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "OrderException", "(", "'Error while creating items: '", ".", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "return", "$", "result", ";", "}" ]
Processes items defined in an order and creates item entities @param array $data @param Order $order @param string $locale @param int $userId @throws Exception\OrderException @return bool
[ "Processes", "items", "defined", "in", "an", "order", "and", "creates", "item", "entities" ]
train
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php#L1292-L1337
gregorybesson/PlaygroundCore
src/Service/Formgen.php
Formgen.getFormgenMapper
public function getFormgenMapper() { if (null === $this->formgenMapper) { $this->formgenMapper = $this->serviceLocator->get('playgroundcore_formgen_mapper'); } return $this->formgenMapper; }
php
public function getFormgenMapper() { if (null === $this->formgenMapper) { $this->formgenMapper = $this->serviceLocator->get('playgroundcore_formgen_mapper'); } return $this->formgenMapper; }
[ "public", "function", "getFormgenMapper", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "formgenMapper", ")", "{", "$", "this", "->", "formgenMapper", "=", "$", "this", "->", "serviceLocator", "->", "get", "(", "'playgroundcore_formgen_mapper'", ")", ";", "}", "return", "$", "this", "->", "formgenMapper", ";", "}" ]
getFormgenMapper @return FormgenMapper
[ "getFormgenMapper" ]
train
https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/Service/Formgen.php#L374-L381
phpthinktank/blast-facades
src/FacadeFactory.php
FacadeFactory.create
public static function create($accessor, $name, array $arguments = []) { $container = static::getContainer(); $object = $container->get($accessor); return call_user_func_array([$object, $name], $arguments); }
php
public static function create($accessor, $name, array $arguments = []) { $container = static::getContainer(); $object = $container->get($accessor); return call_user_func_array([$object, $name], $arguments); }
[ "public", "static", "function", "create", "(", "$", "accessor", ",", "$", "name", ",", "array", "$", "arguments", "=", "[", "]", ")", "{", "$", "container", "=", "static", "::", "getContainer", "(", ")", ";", "$", "object", "=", "$", "container", "->", "get", "(", "$", "accessor", ")", ";", "return", "call_user_func_array", "(", "[", "$", "object", ",", "$", "name", "]", ",", "$", "arguments", ")", ";", "}" ]
Get provided accessor from container and call method @param $accessor @param $name @param $arguments @return mixed
[ "Get", "provided", "accessor", "from", "container", "and", "call", "method" ]
train
https://github.com/phpthinktank/blast-facades/blob/859fd8352f63febf3e1189ea3142afa5d6d8b9af/src/FacadeFactory.php#L48-L54
gdbots/pbjx-bundle-php
src/Command/CreateEventSearchStorageCommand.php
CreateEventSearchStorageCommand.execute
protected function execute(InputInterface $input, OutputInterface $output) { $context = json_decode($input->getOption('context') ?: '{}', true); $context['tenant_id'] = (string)$input->getOption('tenant-id'); $io = new SymfonyStyle($input, $output); $io->title('EventSearch Storage Creator'); $io->comment(sprintf('context: %s', json_encode($context))); $this->getPbjx()->getEventSearch()->createStorage($context); $io->success(sprintf('EventSearch storage created.')); }
php
protected function execute(InputInterface $input, OutputInterface $output) { $context = json_decode($input->getOption('context') ?: '{}', true); $context['tenant_id'] = (string)$input->getOption('tenant-id'); $io = new SymfonyStyle($input, $output); $io->title('EventSearch Storage Creator'); $io->comment(sprintf('context: %s', json_encode($context))); $this->getPbjx()->getEventSearch()->createStorage($context); $io->success(sprintf('EventSearch storage created.')); }
[ "protected", "function", "execute", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "$", "context", "=", "json_decode", "(", "$", "input", "->", "getOption", "(", "'context'", ")", "?", ":", "'{}'", ",", "true", ")", ";", "$", "context", "[", "'tenant_id'", "]", "=", "(", "string", ")", "$", "input", "->", "getOption", "(", "'tenant-id'", ")", ";", "$", "io", "=", "new", "SymfonyStyle", "(", "$", "input", ",", "$", "output", ")", ";", "$", "io", "->", "title", "(", "'EventSearch Storage Creator'", ")", ";", "$", "io", "->", "comment", "(", "sprintf", "(", "'context: %s'", ",", "json_encode", "(", "$", "context", ")", ")", ")", ";", "$", "this", "->", "getPbjx", "(", ")", "->", "getEventSearch", "(", ")", "->", "createStorage", "(", "$", "context", ")", ";", "$", "io", "->", "success", "(", "sprintf", "(", "'EventSearch storage created.'", ")", ")", ";", "}" ]
@param InputInterface $input @param OutputInterface $output @return null @throws \Exception
[ "@param", "InputInterface", "$input", "@param", "OutputInterface", "$output" ]
train
https://github.com/gdbots/pbjx-bundle-php/blob/f3c0088583879fc92f13247a0752634bd8696eac/src/Command/CreateEventSearchStorageCommand.php#L63-L74
SachaMorard/phalcon-console
Library/Phalcon/Commands/Builtin/Enumerate.php
Enumerate.run
public function run(array $parameters) { print Color::colorize('Available commands:', Color::FG_BROWN) . PHP_EOL; foreach ($this->getScript()->getCommands() as $commands) { $providedCommands = $commands->getCommands(); $commandLen = strlen($providedCommands[0]); print ' ' . Color::colorize($providedCommands[0], Color::FG_GREEN); unset($providedCommands[0]); if (count($providedCommands)) { $spacer = str_repeat(' ', self::COMMAND_COLUMN_LEN - $commandLen); print $spacer.' (alias of: ' . Color::colorize(join(', ', $providedCommands)) . ')'; } print PHP_EOL; } print PHP_EOL; }
php
public function run(array $parameters) { print Color::colorize('Available commands:', Color::FG_BROWN) . PHP_EOL; foreach ($this->getScript()->getCommands() as $commands) { $providedCommands = $commands->getCommands(); $commandLen = strlen($providedCommands[0]); print ' ' . Color::colorize($providedCommands[0], Color::FG_GREEN); unset($providedCommands[0]); if (count($providedCommands)) { $spacer = str_repeat(' ', self::COMMAND_COLUMN_LEN - $commandLen); print $spacer.' (alias of: ' . Color::colorize(join(', ', $providedCommands)) . ')'; } print PHP_EOL; } print PHP_EOL; }
[ "public", "function", "run", "(", "array", "$", "parameters", ")", "{", "print", "Color", "::", "colorize", "(", "'Available commands:'", ",", "Color", "::", "FG_BROWN", ")", ".", "PHP_EOL", ";", "foreach", "(", "$", "this", "->", "getScript", "(", ")", "->", "getCommands", "(", ")", "as", "$", "commands", ")", "{", "$", "providedCommands", "=", "$", "commands", "->", "getCommands", "(", ")", ";", "$", "commandLen", "=", "strlen", "(", "$", "providedCommands", "[", "0", "]", ")", ";", "print", "' '", ".", "Color", "::", "colorize", "(", "$", "providedCommands", "[", "0", "]", ",", "Color", "::", "FG_GREEN", ")", ";", "unset", "(", "$", "providedCommands", "[", "0", "]", ")", ";", "if", "(", "count", "(", "$", "providedCommands", ")", ")", "{", "$", "spacer", "=", "str_repeat", "(", "' '", ",", "self", "::", "COMMAND_COLUMN_LEN", "-", "$", "commandLen", ")", ";", "print", "$", "spacer", ".", "' (alias of: '", ".", "Color", "::", "colorize", "(", "join", "(", "', '", ",", "$", "providedCommands", ")", ")", ".", "')'", ";", "}", "print", "PHP_EOL", ";", "}", "print", "PHP_EOL", ";", "}" ]
{@inheritdoc} @param array $parameters @return mixed
[ "{", "@inheritdoc", "}" ]
train
https://github.com/SachaMorard/phalcon-console/blob/a7922e4c488ea19bc0ecce793e6f01cf9cf3c0c3/Library/Phalcon/Commands/Builtin/Enumerate.php#L53-L69
SachaMorard/phalcon-console
Library/Phalcon/Commands/Builtin/Enumerate.php
Enumerate.getHelp
public function getHelp() { print Color::head('Help:') . PHP_EOL; print Color::colorize(' Lists the commands available in Console') . PHP_EOL . PHP_EOL; $this->run([]); }
php
public function getHelp() { print Color::head('Help:') . PHP_EOL; print Color::colorize(' Lists the commands available in Console') . PHP_EOL . PHP_EOL; $this->run([]); }
[ "public", "function", "getHelp", "(", ")", "{", "print", "Color", "::", "head", "(", "'Help:'", ")", ".", "PHP_EOL", ";", "print", "Color", "::", "colorize", "(", "' Lists the commands available in Console'", ")", ".", "PHP_EOL", ".", "PHP_EOL", ";", "$", "this", "->", "run", "(", "[", "]", ")", ";", "}" ]
{@inheritdoc} @return void
[ "{", "@inheritdoc", "}" ]
train
https://github.com/SachaMorard/phalcon-console/blob/a7922e4c488ea19bc0ecce793e6f01cf9cf3c0c3/Library/Phalcon/Commands/Builtin/Enumerate.php#L96-L102
ripaclub/zf2-sphinxsearch-tool
src/Source/Writer/TSV.php
TSV.openURI
public function openURI($uri) { $this->handle = fopen($uri, 'w'); if (!$this->handle) { return false; } else { return true; } }
php
public function openURI($uri) { $this->handle = fopen($uri, 'w'); if (!$this->handle) { return false; } else { return true; } }
[ "public", "function", "openURI", "(", "$", "uri", ")", "{", "$", "this", "->", "handle", "=", "fopen", "(", "$", "uri", ",", "'w'", ")", ";", "if", "(", "!", "$", "this", "->", "handle", ")", "{", "return", "false", ";", "}", "else", "{", "return", "true", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/ripaclub/zf2-sphinxsearch-tool/blob/4cb51341ccf1db9942e3e578855a579afd608d69/src/Source/Writer/TSV.php#L37-L45
ripaclub/zf2-sphinxsearch-tool
src/Source/Writer/TSV.php
TSV.addDocument
public function addDocument(array $doc) { if (!isset($doc['id'])) { throw new NotValidDocumentException('Document array must have an element with "id" key'); } ob_start(); $len = fputcsv($this->handle, $doc, "\t"); if ($len === false) { throw new \RuntimeException('Error writing document'); } return ob_get_clean(); }
php
public function addDocument(array $doc) { if (!isset($doc['id'])) { throw new NotValidDocumentException('Document array must have an element with "id" key'); } ob_start(); $len = fputcsv($this->handle, $doc, "\t"); if ($len === false) { throw new \RuntimeException('Error writing document'); } return ob_get_clean(); }
[ "public", "function", "addDocument", "(", "array", "$", "doc", ")", "{", "if", "(", "!", "isset", "(", "$", "doc", "[", "'id'", "]", ")", ")", "{", "throw", "new", "NotValidDocumentException", "(", "'Document array must have an element with \"id\" key'", ")", ";", "}", "ob_start", "(", ")", ";", "$", "len", "=", "fputcsv", "(", "$", "this", "->", "handle", ",", "$", "doc", ",", "\"\\t\"", ")", ";", "if", "(", "$", "len", "===", "false", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Error writing document'", ")", ";", "}", "return", "ob_get_clean", "(", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/ripaclub/zf2-sphinxsearch-tool/blob/4cb51341ccf1db9942e3e578855a579afd608d69/src/Source/Writer/TSV.php#L58-L69
PeekAndPoke/psi
src/Operation/Terminal/MinOperation.php
MinOperation.apply
public function apply(\Iterator $set) { $data = iterator_to_array($set); return count($data) > 0 ? min($data) : 0; }
php
public function apply(\Iterator $set) { $data = iterator_to_array($set); return count($data) > 0 ? min($data) : 0; }
[ "public", "function", "apply", "(", "\\", "Iterator", "$", "set", ")", "{", "$", "data", "=", "iterator_to_array", "(", "$", "set", ")", ";", "return", "count", "(", "$", "data", ")", ">", "0", "?", "min", "(", "$", "data", ")", ":", "0", ";", "}" ]
{@inheritdoc} @return float
[ "{", "@inheritdoc", "}" ]
train
https://github.com/PeekAndPoke/psi/blob/cfd45d995d3a2c2ea6ba5b1ce7b5fcc71179456f/src/Operation/Terminal/MinOperation.php#L24-L29
spiral-modules/auth
source/Auth/Operators/PersistentOperator.php
PersistentOperator.createToken
public function createToken(UserInterface $user): TokenInterface { return $this->source->createToken($user, $this->lifetime)->withOperator($this); }
php
public function createToken(UserInterface $user): TokenInterface { return $this->source->createToken($user, $this->lifetime)->withOperator($this); }
[ "public", "function", "createToken", "(", "UserInterface", "$", "user", ")", ":", "TokenInterface", "{", "return", "$", "this", "->", "source", "->", "createToken", "(", "$", "user", ",", "$", "this", "->", "lifetime", ")", "->", "withOperator", "(", "$", "this", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/spiral-modules/auth/blob/24e2070028f7257e8192914556963a4794428a99/source/Auth/Operators/PersistentOperator.php#L68-L71
spiral-modules/auth
source/Auth/Operators/PersistentOperator.php
PersistentOperator.fetchToken
public function fetchToken(Request $request) { if (!$this->hasToken($request)) { return null; } $token = $this->source->findToken($this->bridge->fetchToken($request)); if (empty($token)) { //Token not found or expired return null; } return $token->withOperator($this); }
php
public function fetchToken(Request $request) { if (!$this->hasToken($request)) { return null; } $token = $this->source->findToken($this->bridge->fetchToken($request)); if (empty($token)) { //Token not found or expired return null; } return $token->withOperator($this); }
[ "public", "function", "fetchToken", "(", "Request", "$", "request", ")", "{", "if", "(", "!", "$", "this", "->", "hasToken", "(", "$", "request", ")", ")", "{", "return", "null", ";", "}", "$", "token", "=", "$", "this", "->", "source", "->", "findToken", "(", "$", "this", "->", "bridge", "->", "fetchToken", "(", "$", "request", ")", ")", ";", "if", "(", "empty", "(", "$", "token", ")", ")", "{", "//Token not found or expired", "return", "null", ";", "}", "return", "$", "token", "->", "withOperator", "(", "$", "this", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/spiral-modules/auth/blob/24e2070028f7257e8192914556963a4794428a99/source/Auth/Operators/PersistentOperator.php#L84-L97
spiral-modules/auth
source/Auth/Operators/PersistentOperator.php
PersistentOperator.commitToken
public function commitToken( Request $request, Response $response, TokenInterface $token ): Response { if ($this->updateTokens) { $this->source->touchToken($token, $this->lifetime); } return $this->bridge->writeToken($request, $response, $this->lifetime, $token->getValue()); }
php
public function commitToken( Request $request, Response $response, TokenInterface $token ): Response { if ($this->updateTokens) { $this->source->touchToken($token, $this->lifetime); } return $this->bridge->writeToken($request, $response, $this->lifetime, $token->getValue()); }
[ "public", "function", "commitToken", "(", "Request", "$", "request", ",", "Response", "$", "response", ",", "TokenInterface", "$", "token", ")", ":", "Response", "{", "if", "(", "$", "this", "->", "updateTokens", ")", "{", "$", "this", "->", "source", "->", "touchToken", "(", "$", "token", ",", "$", "this", "->", "lifetime", ")", ";", "}", "return", "$", "this", "->", "bridge", "->", "writeToken", "(", "$", "request", ",", "$", "response", ",", "$", "this", "->", "lifetime", ",", "$", "token", "->", "getValue", "(", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/spiral-modules/auth/blob/24e2070028f7257e8192914556963a4794428a99/source/Auth/Operators/PersistentOperator.php#L102-L112
spiral-modules/auth
source/Auth/Operators/PersistentOperator.php
PersistentOperator.removeToken
public function removeToken( Request $request, Response $response, TokenInterface $token ): Response { $this->source->deleteToken($token); //Reset user token value return $this->bridge->writeToken($request, $response, $this->lifetime, null); }
php
public function removeToken( Request $request, Response $response, TokenInterface $token ): Response { $this->source->deleteToken($token); //Reset user token value return $this->bridge->writeToken($request, $response, $this->lifetime, null); }
[ "public", "function", "removeToken", "(", "Request", "$", "request", ",", "Response", "$", "response", ",", "TokenInterface", "$", "token", ")", ":", "Response", "{", "$", "this", "->", "source", "->", "deleteToken", "(", "$", "token", ")", ";", "//Reset user token value", "return", "$", "this", "->", "bridge", "->", "writeToken", "(", "$", "request", ",", "$", "response", ",", "$", "this", "->", "lifetime", ",", "null", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/spiral-modules/auth/blob/24e2070028f7257e8192914556963a4794428a99/source/Auth/Operators/PersistentOperator.php#L117-L126
alanpich/slender
src/Core/Autoloader/ClassLoader.php
ClassLoader.registerNamespace
public function registerNamespace($namespace, $paths, $type = 'psr-0') { switch ($type) { case 'psr-0': parent::registerNamespace($namespace, $paths); break; case 'psr-4': $this->psr4Loader->addNamespace($namespace,$paths); break; default: throw new AutoloadException("$type is not a known autoloader format"); } }
php
public function registerNamespace($namespace, $paths, $type = 'psr-0') { switch ($type) { case 'psr-0': parent::registerNamespace($namespace, $paths); break; case 'psr-4': $this->psr4Loader->addNamespace($namespace,$paths); break; default: throw new AutoloadException("$type is not a known autoloader format"); } }
[ "public", "function", "registerNamespace", "(", "$", "namespace", ",", "$", "paths", ",", "$", "type", "=", "'psr-0'", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "'psr-0'", ":", "parent", "::", "registerNamespace", "(", "$", "namespace", ",", "$", "paths", ")", ";", "break", ";", "case", "'psr-4'", ":", "$", "this", "->", "psr4Loader", "->", "addNamespace", "(", "$", "namespace", ",", "$", "paths", ")", ";", "break", ";", "default", ":", "throw", "new", "AutoloadException", "(", "\"$type is not a known autoloader format\"", ")", ";", "}", "}" ]
Overridden to allow injecting psr-4 into the mix. Also opens up doors for alternative formats to be used later. Either way, it's a mess here right now @param string $namespace @param array|string $paths @param string $type Either 'psr-0' or 'psr-4'. Defaults to 'psr-0' @throws \Slender\Exception\AutoloadException
[ "Overridden", "to", "allow", "injecting", "psr", "-", "4", "into", "the", "mix", ".", "Also", "opens", "up", "doors", "for", "alternative", "formats", "to", "be", "used", "later", ".", "Either", "way", "it", "s", "a", "mess", "here", "right", "now" ]
train
https://github.com/alanpich/slender/blob/247f5c08af20cda95b116eb5d9f6f623d61e8a8a/src/Core/Autoloader/ClassLoader.php#L56-L68
tigris-php/telegram-bot-api
src/Types/Message.php
Message.detectType
protected static function detectType(array $data) { foreach ([ self::TYPE_TEXT, self::TYPE_AUDIO, self::TYPE_DOCUMENT, self::TYPE_GAME, self::TYPE_PHOTO, self::TYPE_STICKER, self::TYPE_VIDEO, self::TYPE_VOICE, self::TYPE_CONTACT, self::TYPE_LOCATION, self::TYPE_VENUE, self::TYPE_VIDEO_NOTE, self::TYPE_NEW_CHAT_MEMBERS, self::TYPE_LEFT_CHAT_MEMBER, self::TYPE_NEW_CHAT_TITLE, self::TYPE_NEW_CHAT_PHOTO, self::TYPE_DELETE_CHAT_PHOTO, self::TYPE_GROUP_CHAT_CREATED, self::TYPE_SUPERGROUP_CHAT_CREATED, self::TYPE_CHANNEL_CHAT_CREATED, self::TYPE_MESSAGE_PINNED, self::TYPE_INVOICE, self::TYPE_SUCCESSFUL_PAYMENT, ] as $type) { if (isset($data[$type])) { return $type; } } return static::TYPE_UNKNOWN; }
php
protected static function detectType(array $data) { foreach ([ self::TYPE_TEXT, self::TYPE_AUDIO, self::TYPE_DOCUMENT, self::TYPE_GAME, self::TYPE_PHOTO, self::TYPE_STICKER, self::TYPE_VIDEO, self::TYPE_VOICE, self::TYPE_CONTACT, self::TYPE_LOCATION, self::TYPE_VENUE, self::TYPE_VIDEO_NOTE, self::TYPE_NEW_CHAT_MEMBERS, self::TYPE_LEFT_CHAT_MEMBER, self::TYPE_NEW_CHAT_TITLE, self::TYPE_NEW_CHAT_PHOTO, self::TYPE_DELETE_CHAT_PHOTO, self::TYPE_GROUP_CHAT_CREATED, self::TYPE_SUPERGROUP_CHAT_CREATED, self::TYPE_CHANNEL_CHAT_CREATED, self::TYPE_MESSAGE_PINNED, self::TYPE_INVOICE, self::TYPE_SUCCESSFUL_PAYMENT, ] as $type) { if (isset($data[$type])) { return $type; } } return static::TYPE_UNKNOWN; }
[ "protected", "static", "function", "detectType", "(", "array", "$", "data", ")", "{", "foreach", "(", "[", "self", "::", "TYPE_TEXT", ",", "self", "::", "TYPE_AUDIO", ",", "self", "::", "TYPE_DOCUMENT", ",", "self", "::", "TYPE_GAME", ",", "self", "::", "TYPE_PHOTO", ",", "self", "::", "TYPE_STICKER", ",", "self", "::", "TYPE_VIDEO", ",", "self", "::", "TYPE_VOICE", ",", "self", "::", "TYPE_CONTACT", ",", "self", "::", "TYPE_LOCATION", ",", "self", "::", "TYPE_VENUE", ",", "self", "::", "TYPE_VIDEO_NOTE", ",", "self", "::", "TYPE_NEW_CHAT_MEMBERS", ",", "self", "::", "TYPE_LEFT_CHAT_MEMBER", ",", "self", "::", "TYPE_NEW_CHAT_TITLE", ",", "self", "::", "TYPE_NEW_CHAT_PHOTO", ",", "self", "::", "TYPE_DELETE_CHAT_PHOTO", ",", "self", "::", "TYPE_GROUP_CHAT_CREATED", ",", "self", "::", "TYPE_SUPERGROUP_CHAT_CREATED", ",", "self", "::", "TYPE_CHANNEL_CHAT_CREATED", ",", "self", "::", "TYPE_MESSAGE_PINNED", ",", "self", "::", "TYPE_INVOICE", ",", "self", "::", "TYPE_SUCCESSFUL_PAYMENT", ",", "]", "as", "$", "type", ")", "{", "if", "(", "isset", "(", "$", "data", "[", "$", "type", "]", ")", ")", "{", "return", "$", "type", ";", "}", "}", "return", "static", "::", "TYPE_UNKNOWN", ";", "}" ]
Detects message type @param $data @return string
[ "Detects", "message", "type" ]
train
https://github.com/tigris-php/telegram-bot-api/blob/7350c81d571387005d58079d8c654ee44504cdcf/src/Types/Message.php#L114-L146
tbreuss/pvc
src/Middleware/MiddlewarePipe.php
MiddlewarePipe.add
public function add(MiddlewareInterface $middleware): self { $pipe = clone $this; array_push($pipe->middlewares, $middleware); return $pipe; }
php
public function add(MiddlewareInterface $middleware): self { $pipe = clone $this; array_push($pipe->middlewares, $middleware); return $pipe; }
[ "public", "function", "add", "(", "MiddlewareInterface", "$", "middleware", ")", ":", "self", "{", "$", "pipe", "=", "clone", "$", "this", ";", "array_push", "(", "$", "pipe", "->", "middlewares", ",", "$", "middleware", ")", ";", "return", "$", "pipe", ";", "}" ]
Creates a new pipe with the given middleware connected. @param MiddlewareInterface $middleware @return self
[ "Creates", "a", "new", "pipe", "with", "the", "given", "middleware", "connected", "." ]
train
https://github.com/tbreuss/pvc/blob/ae100351010a8c9f645ccb918f70a26e167de7a7/src/Middleware/MiddlewarePipe.php#L56-L61
yuncms/framework
src/helpers/NumberHelper.php
NumberHelper.word
public static function word(int $num): string { $numberWordMap = [ 1 => Yii::t('yuncms', 'One'), 2 => Yii::t('yuncms', 'Two'), 3 => Yii::t('yuncms', 'Three'), 4 => Yii::t('yuncms', 'Four'), 5 => Yii::t('yuncms', 'Five'), 6 => Yii::t('yuncms', 'Six'), 7 => Yii::t('yuncms', 'Seven'), 8 => Yii::t('yuncms', 'Eight'), 9 => Yii::t('yuncms', 'Nine') ]; if (isset($numberWordMap[$num])) { return $numberWordMap[$num]; } return (string)$num; }
php
public static function word(int $num): string { $numberWordMap = [ 1 => Yii::t('yuncms', 'One'), 2 => Yii::t('yuncms', 'Two'), 3 => Yii::t('yuncms', 'Three'), 4 => Yii::t('yuncms', 'Four'), 5 => Yii::t('yuncms', 'Five'), 6 => Yii::t('yuncms', 'Six'), 7 => Yii::t('yuncms', 'Seven'), 8 => Yii::t('yuncms', 'Eight'), 9 => Yii::t('yuncms', 'Nine') ]; if (isset($numberWordMap[$num])) { return $numberWordMap[$num]; } return (string)$num; }
[ "public", "static", "function", "word", "(", "int", "$", "num", ")", ":", "string", "{", "$", "numberWordMap", "=", "[", "1", "=>", "Yii", "::", "t", "(", "'yuncms'", ",", "'One'", ")", ",", "2", "=>", "Yii", "::", "t", "(", "'yuncms'", ",", "'Two'", ")", ",", "3", "=>", "Yii", "::", "t", "(", "'yuncms'", ",", "'Three'", ")", ",", "4", "=>", "Yii", "::", "t", "(", "'yuncms'", ",", "'Four'", ")", ",", "5", "=>", "Yii", "::", "t", "(", "'yuncms'", ",", "'Five'", ")", ",", "6", "=>", "Yii", "::", "t", "(", "'yuncms'", ",", "'Six'", ")", ",", "7", "=>", "Yii", "::", "t", "(", "'yuncms'", ",", "'Seven'", ")", ",", "8", "=>", "Yii", "::", "t", "(", "'yuncms'", ",", "'Eight'", ")", ",", "9", "=>", "Yii", "::", "t", "(", "'yuncms'", ",", "'Nine'", ")", "]", ";", "if", "(", "isset", "(", "$", "numberWordMap", "[", "$", "num", "]", ")", ")", "{", "return", "$", "numberWordMap", "[", "$", "num", "]", ";", "}", "return", "(", "string", ")", "$", "num", ";", "}" ]
Returns the "word" version of a number @param int $num The number @return string The number word, or the original number if it's >= 10
[ "Returns", "the", "word", "version", "of", "a", "number" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/helpers/NumberHelper.php#L22-L41
yuncms/framework
src/helpers/NumberHelper.php
NumberHelper.upperAlpha
public static function upperAlpha(int $num): string { $num--; $alpha = ''; while ($num >= 0) { $ascii = ($num % 26) + 65; $alpha = chr($ascii) . $alpha; $num = (int)($num / 26) - 1; } return $alpha; }
php
public static function upperAlpha(int $num): string { $num--; $alpha = ''; while ($num >= 0) { $ascii = ($num % 26) + 65; $alpha = chr($ascii) . $alpha; $num = (int)($num / 26) - 1; } return $alpha; }
[ "public", "static", "function", "upperAlpha", "(", "int", "$", "num", ")", ":", "string", "{", "$", "num", "--", ";", "$", "alpha", "=", "''", ";", "while", "(", "$", "num", ">=", "0", ")", "{", "$", "ascii", "=", "(", "$", "num", "%", "26", ")", "+", "65", ";", "$", "alpha", "=", "chr", "(", "$", "ascii", ")", ".", "$", "alpha", ";", "$", "num", "=", "(", "int", ")", "(", "$", "num", "/", "26", ")", "-", "1", ";", "}", "return", "$", "alpha", ";", "}" ]
返回数字的大写字母版本 @param int $num The number @return string The alphabetic version of the number
[ "返回数字的大写字母版本" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/helpers/NumberHelper.php#L51-L64
yuncms/framework
src/helpers/NumberHelper.php
NumberHelper.lowerAlpha
public static function lowerAlpha(int $num): string { $alpha = static::upperAlpha($num); return StringHelper::toLowerCase($alpha); }
php
public static function lowerAlpha(int $num): string { $alpha = static::upperAlpha($num); return StringHelper::toLowerCase($alpha); }
[ "public", "static", "function", "lowerAlpha", "(", "int", "$", "num", ")", ":", "string", "{", "$", "alpha", "=", "static", "::", "upperAlpha", "(", "$", "num", ")", ";", "return", "StringHelper", "::", "toLowerCase", "(", "$", "alpha", ")", ";", "}" ]
返回数字的小写字母版本 @param int $num The number @return string The alphabetic version of the number
[ "返回数字的小写字母版本" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/helpers/NumberHelper.php#L73-L78
yuncms/framework
src/helpers/NumberHelper.php
NumberHelper.upperRoman
public static function upperRoman(int $num): string { $roman = ''; $map = [ 'M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400, 'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40, 'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1 ]; foreach ($map as $k => $v) { while ($num >= $v) { $roman .= $k; $num -= $v; } } return $roman; }
php
public static function upperRoman(int $num): string { $roman = ''; $map = [ 'M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400, 'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40, 'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1 ]; foreach ($map as $k => $v) { while ($num >= $v) { $roman .= $k; $num -= $v; } } return $roman; }
[ "public", "static", "function", "upperRoman", "(", "int", "$", "num", ")", ":", "string", "{", "$", "roman", "=", "''", ";", "$", "map", "=", "[", "'M'", "=>", "1000", ",", "'CM'", "=>", "900", ",", "'D'", "=>", "500", ",", "'CD'", "=>", "400", ",", "'C'", "=>", "100", ",", "'XC'", "=>", "90", ",", "'L'", "=>", "50", ",", "'XL'", "=>", "40", ",", "'X'", "=>", "10", ",", "'IX'", "=>", "9", ",", "'V'", "=>", "5", ",", "'IV'", "=>", "4", ",", "'I'", "=>", "1", "]", ";", "foreach", "(", "$", "map", "as", "$", "k", "=>", "$", "v", ")", "{", "while", "(", "$", "num", ">=", "$", "v", ")", "{", "$", "roman", ".=", "$", "k", ";", "$", "num", "-=", "$", "v", ";", "}", "}", "return", "$", "roman", ";", "}" ]
返回数字的大写罗马数字版本 @param int $num The number @return string The roman numeral version of the number
[ "返回数字的大写罗马数字版本" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/helpers/NumberHelper.php#L87-L115
yuncms/framework
src/helpers/NumberHelper.php
NumberHelper.lowerRoman
public static function lowerRoman(int $num): string { $roman = static::upperRoman($num); return StringHelper::toLowerCase($roman); }
php
public static function lowerRoman(int $num): string { $roman = static::upperRoman($num); return StringHelper::toLowerCase($roman); }
[ "public", "static", "function", "lowerRoman", "(", "int", "$", "num", ")", ":", "string", "{", "$", "roman", "=", "static", "::", "upperRoman", "(", "$", "num", ")", ";", "return", "StringHelper", "::", "toLowerCase", "(", "$", "roman", ")", ";", "}" ]
返回数字的小写罗马数字版本 @param int $num The number @return string The roman numeral version of the number
[ "返回数字的小写罗马数字版本" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/helpers/NumberHelper.php#L124-L129
2amigos/yiifoundation
widgets/Tooltip.php
Tooltip.init
public function init() { $this->assets = array( 'js' => YII_DEBUG ? 'foundation/foundation.tooltips.js' : 'foundation.min.js' ); Html::addCssClass($this->htmlOptions, Enum::TOOLTIP); Html::addCssClass($this->htmlOptions, $this->position); ArrayHelper::addValue('title', $this->tip, $this->htmlOptions); ArrayHelper::addValue('data-tooltip', 'data-tooltip', $this->htmlOptions); if ($this->tip === null || $this->text === null) { throw new InvalidConfigException('"tip" and "text" cannot be null.'); } $this->registerClientScript(); parent::init(); }
php
public function init() { $this->assets = array( 'js' => YII_DEBUG ? 'foundation/foundation.tooltips.js' : 'foundation.min.js' ); Html::addCssClass($this->htmlOptions, Enum::TOOLTIP); Html::addCssClass($this->htmlOptions, $this->position); ArrayHelper::addValue('title', $this->tip, $this->htmlOptions); ArrayHelper::addValue('data-tooltip', 'data-tooltip', $this->htmlOptions); if ($this->tip === null || $this->text === null) { throw new InvalidConfigException('"tip" and "text" cannot be null.'); } $this->registerClientScript(); parent::init(); }
[ "public", "function", "init", "(", ")", "{", "$", "this", "->", "assets", "=", "array", "(", "'js'", "=>", "YII_DEBUG", "?", "'foundation/foundation.tooltips.js'", ":", "'foundation.min.js'", ")", ";", "Html", "::", "addCssClass", "(", "$", "this", "->", "htmlOptions", ",", "Enum", "::", "TOOLTIP", ")", ";", "Html", "::", "addCssClass", "(", "$", "this", "->", "htmlOptions", ",", "$", "this", "->", "position", ")", ";", "ArrayHelper", "::", "addValue", "(", "'title'", ",", "$", "this", "->", "tip", ",", "$", "this", "->", "htmlOptions", ")", ";", "ArrayHelper", "::", "addValue", "(", "'data-tooltip'", ",", "'data-tooltip'", ",", "$", "this", "->", "htmlOptions", ")", ";", "if", "(", "$", "this", "->", "tip", "===", "null", "||", "$", "this", "->", "text", "===", "null", ")", "{", "throw", "new", "InvalidConfigException", "(", "'\"tip\" and \"text\" cannot be null.'", ")", ";", "}", "$", "this", "->", "registerClientScript", "(", ")", ";", "parent", "::", "init", "(", ")", ";", "}" ]
Initializes the widget
[ "Initializes", "the", "widget" ]
train
https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/widgets/Tooltip.php#L46-L62
2amigos/yiifoundation
widgets/Tooltip.php
Tooltip.registerClientScript
public function registerClientScript() { if (!empty($this->pluginOptions)) { $options = \CJavaScript::encode($this->pluginOptions); \Yii::app()->clientScript ->registerScript('Tooltip#' . $this->getId(), "$(document).foundation('tooltip', {$options});"); } }
php
public function registerClientScript() { if (!empty($this->pluginOptions)) { $options = \CJavaScript::encode($this->pluginOptions); \Yii::app()->clientScript ->registerScript('Tooltip#' . $this->getId(), "$(document).foundation('tooltip', {$options});"); } }
[ "public", "function", "registerClientScript", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "pluginOptions", ")", ")", "{", "$", "options", "=", "\\", "CJavaScript", "::", "encode", "(", "$", "this", "->", "pluginOptions", ")", ";", "\\", "Yii", "::", "app", "(", ")", "->", "clientScript", "->", "registerScript", "(", "'Tooltip#'", ".", "$", "this", "->", "getId", "(", ")", ",", "\"$(document).foundation('tooltip', {$options});\"", ")", ";", "}", "}" ]
Registers plugin options and events (if any)
[ "Registers", "plugin", "options", "and", "events", "(", "if", "any", ")" ]
train
https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/widgets/Tooltip.php#L84-L91
nodes-php/database
src/Eloquent/Repository.php
Repository.first
public function first($columns = ['*']) { $result = $this->getBuilder()->first($columns); // Reset query builder $this->resetBuilder(); return $result; }
php
public function first($columns = ['*']) { $result = $this->getBuilder()->first($columns); // Reset query builder $this->resetBuilder(); return $result; }
[ "public", "function", "first", "(", "$", "columns", "=", "[", "'*'", "]", ")", "{", "$", "result", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "first", "(", "$", "columns", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "$", "result", ";", "}" ]
Execute the query and get the first result. @author Morten Rugaard <[email protected]> @param array $columns @return \Illuminate\Database\Eloquent\Model
[ "Execute", "the", "query", "and", "get", "the", "first", "result", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L183-L191
nodes-php/database
src/Eloquent/Repository.php
Repository.firstOrFail
public function firstOrFail($columns = ['*']) { $result = $this->first($columns); if (empty($result)) { throw new EntityNotFoundException(sprintf('First record for table [%s] not found', get_class($this->model))); } return $result; }
php
public function firstOrFail($columns = ['*']) { $result = $this->first($columns); if (empty($result)) { throw new EntityNotFoundException(sprintf('First record for table [%s] not found', get_class($this->model))); } return $result; }
[ "public", "function", "firstOrFail", "(", "$", "columns", "=", "[", "'*'", "]", ")", "{", "$", "result", "=", "$", "this", "->", "first", "(", "$", "columns", ")", ";", "if", "(", "empty", "(", "$", "result", ")", ")", "{", "throw", "new", "EntityNotFoundException", "(", "sprintf", "(", "'First record for table [%s] not found'", ",", "get_class", "(", "$", "this", "->", "model", ")", ")", ")", ";", "}", "return", "$", "result", ";", "}" ]
Execute the query and get the first result or throw an exception l. @author Morten Rugaard <[email protected]> @param array $columns @return \Illuminate\Database\Eloquent\Model @throws \Nodes\Database\Exceptions\EntityNotFoundException
[ "Execute", "the", "query", "and", "get", "the", "first", "result", "or", "throw", "an", "exception", "l", ".", "@author", "Morten", "Rugaard", "<moru@nodes", ".", "dk", ">" ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L202-L210
nodes-php/database
src/Eloquent/Repository.php
Repository.get
public function get($columns = ['*']) { $result = $this->getBuilder()->get($columns); // Reset query builder $this->resetBuilder(); return $result; }
php
public function get($columns = ['*']) { $result = $this->getBuilder()->get($columns); // Reset query builder $this->resetBuilder(); return $result; }
[ "public", "function", "get", "(", "$", "columns", "=", "[", "'*'", "]", ")", "{", "$", "result", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "get", "(", "$", "columns", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "$", "result", ";", "}" ]
Execute the query and retrieve result. @author Morten Rugaard <[email protected]> @param array $columns @return \Illuminate\Database\Eloquent\Collection
[ "Execute", "the", "query", "and", "retrieve", "result", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L220-L228
nodes-php/database
src/Eloquent/Repository.php
Repository.paginate
public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null) { $result = $this->getBuilder()->paginate($perPage, $columns, $pageName, $page); // Reset query builder $this->resetBuilder(); return $result; }
php
public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null) { $result = $this->getBuilder()->paginate($perPage, $columns, $pageName, $page); // Reset query builder $this->resetBuilder(); return $result; }
[ "public", "function", "paginate", "(", "$", "perPage", "=", "15", ",", "$", "columns", "=", "[", "'*'", "]", ",", "$", "pageName", "=", "'page'", ",", "$", "page", "=", "null", ")", "{", "$", "result", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "paginate", "(", "$", "perPage", ",", "$", "columns", ",", "$", "pageName", ",", "$", "page", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "$", "result", ";", "}" ]
Paginate the given query into a simple paginator. @author Morten Rugaard <[email protected]> @param int $perPage @param array $columns @param string $pageName @param int $page @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
[ "Paginate", "the", "given", "query", "into", "a", "simple", "paginator", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L241-L249
nodes-php/database
src/Eloquent/Repository.php
Repository.simplePaginate
public function simplePaginate($perPage = 15, $columns = ['*'], $pageName = 'page') { $result = $this->getBuilder()->simplePaginate($perPage, $columns, $pageName); // Reset query builder $this->resetBuilder(); return $result; }
php
public function simplePaginate($perPage = 15, $columns = ['*'], $pageName = 'page') { $result = $this->getBuilder()->simplePaginate($perPage, $columns, $pageName); // Reset query builder $this->resetBuilder(); return $result; }
[ "public", "function", "simplePaginate", "(", "$", "perPage", "=", "15", ",", "$", "columns", "=", "[", "'*'", "]", ",", "$", "pageName", "=", "'page'", ")", "{", "$", "result", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "simplePaginate", "(", "$", "perPage", ",", "$", "columns", ",", "$", "pageName", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "$", "result", ";", "}" ]
Get a paginator only supporting simple next and previous links. This is more efficient on larger data-sets, etc. @author Morten Rugaard <[email protected]> @param int $perPage @param array $columns @param string $pageName @return \Illuminate\Contracts\Pagination\Paginator
[ "Get", "a", "paginator", "only", "supporting", "simple", "next", "and", "previous", "links", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L263-L271
nodes-php/database
src/Eloquent/Repository.php
Repository.getCountForPagination
public function getCountForPagination($columns = ['*']) { $result = $this->getBuilder()->getCountForPagination($columns); // Reset query builder $this->resetBuilder(); return $result; }
php
public function getCountForPagination($columns = ['*']) { $result = $this->getBuilder()->getCountForPagination($columns); // Reset query builder $this->resetBuilder(); return $result; }
[ "public", "function", "getCountForPagination", "(", "$", "columns", "=", "[", "'*'", "]", ")", "{", "$", "result", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "getCountForPagination", "(", "$", "columns", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "$", "result", ";", "}" ]
Get the count of the total records for the paginator. @author Morten Rugaard <[email protected]> @param array $columns @return int
[ "Get", "the", "count", "of", "the", "total", "records", "for", "the", "paginator", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L281-L289
nodes-php/database
src/Eloquent/Repository.php
Repository.value
public function value($column) { $result = $this->getBuilder()->value($column); // Reset query builder $this->resetBuilder(); return $result; }
php
public function value($column) { $result = $this->getBuilder()->value($column); // Reset query builder $this->resetBuilder(); return $result; }
[ "public", "function", "value", "(", "$", "column", ")", "{", "$", "result", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "value", "(", "$", "column", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "$", "result", ";", "}" ]
Get a single column's value from the first result of a query. @author Morten Rugaard <[email protected]> @param string $column @return mixed
[ "Get", "a", "single", "column", "s", "value", "from", "the", "first", "result", "of", "a", "query", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L299-L307
nodes-php/database
src/Eloquent/Repository.php
Repository.chunk
public function chunk($count, callable $callback) { $result = $this->getBuilder()->chunk($count, $callback); // Reset query builder $this->resetBuilder(); return $result; }
php
public function chunk($count, callable $callback) { $result = $this->getBuilder()->chunk($count, $callback); // Reset query builder $this->resetBuilder(); return $result; }
[ "public", "function", "chunk", "(", "$", "count", ",", "callable", "$", "callback", ")", "{", "$", "result", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "chunk", "(", "$", "count", ",", "$", "callback", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "$", "result", ";", "}" ]
Chunk the results of the query. @author Morten Rugaard <[email protected]> @param int $count @param callable $callback @return bool
[ "Chunk", "the", "results", "of", "the", "query", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L318-L326
nodes-php/database
src/Eloquent/Repository.php
Repository.each
public function each(callable $callback, $count = 1000) { $result = $this->getBuilder()->each($callback, $count); // Reset query builder $this->resetBuilder(); return $result; }
php
public function each(callable $callback, $count = 1000) { $result = $this->getBuilder()->each($callback, $count); // Reset query builder $this->resetBuilder(); return $result; }
[ "public", "function", "each", "(", "callable", "$", "callback", ",", "$", "count", "=", "1000", ")", "{", "$", "result", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "each", "(", "$", "callback", ",", "$", "count", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "$", "result", ";", "}" ]
Execute a callback over each item while chunking. @author Morten Rugaard <[email protected]> @param callable $callback @param int $count @return bool @throws \RuntimeException
[ "Execute", "a", "callback", "over", "each", "item", "while", "chunking", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L338-L346
nodes-php/database
src/Eloquent/Repository.php
Repository.pluck
public function pluck($column, $key = null) { $result = $this->getBuilder()->pluck($column, $key); // Reset query builder $this->resetBuilder(); return $result; }
php
public function pluck($column, $key = null) { $result = $this->getBuilder()->pluck($column, $key); // Reset query builder $this->resetBuilder(); return $result; }
[ "public", "function", "pluck", "(", "$", "column", ",", "$", "key", "=", "null", ")", "{", "$", "result", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "pluck", "(", "$", "column", ",", "$", "key", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "$", "result", ";", "}" ]
Get an array with the values of a given column. @author Morten Rugaard <[email protected]> @param string $column @param string $key @return array
[ "Get", "an", "array", "with", "the", "values", "of", "a", "given", "column", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L357-L365
nodes-php/database
src/Eloquent/Repository.php
Repository.implode
public function implode($column, $glue = '') { $result = $this->getBuilder()->implode($column, $glue); // Reset query builder $this->resetBuilder(); return $result; }
php
public function implode($column, $glue = '') { $result = $this->getBuilder()->implode($column, $glue); // Reset query builder $this->resetBuilder(); return $result; }
[ "public", "function", "implode", "(", "$", "column", ",", "$", "glue", "=", "''", ")", "{", "$", "result", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "implode", "(", "$", "column", ",", "$", "glue", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "$", "result", ";", "}" ]
Concatenate values of a given column as a string. @author Morten Rugaard <[email protected]> @param string $column @param string $glue @return string
[ "Concatenate", "values", "of", "a", "given", "column", "as", "a", "string", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L390-L398
nodes-php/database
src/Eloquent/Repository.php
Repository.count
public function count($columns = '*') { $result = $this->getBuilder()->count($columns); // Reset query builder $this->resetBuilder(); return (int) $result; }
php
public function count($columns = '*') { $result = $this->getBuilder()->count($columns); // Reset query builder $this->resetBuilder(); return (int) $result; }
[ "public", "function", "count", "(", "$", "columns", "=", "'*'", ")", "{", "$", "result", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "count", "(", "$", "columns", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "(", "int", ")", "$", "result", ";", "}" ]
Execute query as a count statement. @author Morten Rugaard <[email protected]> @param string $columns @return int
[ "Execute", "query", "as", "a", "count", "statement", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L425-L433
nodes-php/database
src/Eloquent/Repository.php
Repository.min
public function min($column) { $result = $this->getBuilder()->min($column); // Reset query builder $this->resetBuilder(); return $result; }
php
public function min($column) { $result = $this->getBuilder()->min($column); // Reset query builder $this->resetBuilder(); return $result; }
[ "public", "function", "min", "(", "$", "column", ")", "{", "$", "result", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "min", "(", "$", "column", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "$", "result", ";", "}" ]
Retrieve the minimum value of a given column. @author Morten Rugaard <[email protected]> @param string $column @return float|int
[ "Retrieve", "the", "minimum", "value", "of", "a", "given", "column", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L443-L451
nodes-php/database
src/Eloquent/Repository.php
Repository.max
public function max($column) { $result = $this->getBuilder()->max($column); // Reset query builder $this->resetBuilder(); return $result; }
php
public function max($column) { $result = $this->getBuilder()->max($column); // Reset query builder $this->resetBuilder(); return $result; }
[ "public", "function", "max", "(", "$", "column", ")", "{", "$", "result", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "max", "(", "$", "column", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "$", "result", ";", "}" ]
Retrieve the maximum value of a given column. @author Morten Rugaard <[email protected]> @param string $column @return float|int
[ "Retrieve", "the", "maximum", "value", "of", "a", "given", "column", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L461-L469
nodes-php/database
src/Eloquent/Repository.php
Repository.sum
public function sum($column) { $result = $this->getBuilder()->sum($column); // Reset query builder $this->resetBuilder(); return $result ?: 0; }
php
public function sum($column) { $result = $this->getBuilder()->sum($column); // Reset query builder $this->resetBuilder(); return $result ?: 0; }
[ "public", "function", "sum", "(", "$", "column", ")", "{", "$", "result", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "sum", "(", "$", "column", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "$", "result", "?", ":", "0", ";", "}" ]
Retrieve the sum of the values of a given column. @author Morten Rugaard <[email protected]> @param string $column @return float|int
[ "Retrieve", "the", "sum", "of", "the", "values", "of", "a", "given", "column", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L479-L487
nodes-php/database
src/Eloquent/Repository.php
Repository.avg
public function avg($column) { $result = $this->getBuilder()->avg($column); // Reset query builder $this->resetBuilder(); return $result; }
php
public function avg($column) { $result = $this->getBuilder()->avg($column); // Reset query builder $this->resetBuilder(); return $result; }
[ "public", "function", "avg", "(", "$", "column", ")", "{", "$", "result", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "avg", "(", "$", "column", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "$", "result", ";", "}" ]
Retrieve the average of the values of a given column. @author Morten Rugaard <[email protected]> @param string $column @return float|int
[ "Retrieve", "the", "average", "of", "the", "values", "of", "a", "given", "column", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L497-L505
nodes-php/database
src/Eloquent/Repository.php
Repository.aggregate
public function aggregate($function, $columns = ['*']) { $result = $this->getBuilder()->aggregate($function, $columns); // Reset query builder $this->resetBuilder(); return $result; }
php
public function aggregate($function, $columns = ['*']) { $result = $this->getBuilder()->aggregate($function, $columns); // Reset query builder $this->resetBuilder(); return $result; }
[ "public", "function", "aggregate", "(", "$", "function", ",", "$", "columns", "=", "[", "'*'", "]", ")", "{", "$", "result", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "aggregate", "(", "$", "function", ",", "$", "columns", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "$", "result", ";", "}" ]
Execute an aggregate function on the database. @author Morten Rugaard <[email protected]> @param string $function @param array $columns @return float|int
[ "Execute", "an", "aggregate", "function", "on", "the", "database", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L529-L537
nodes-php/database
src/Eloquent/Repository.php
Repository.insert
public function insert(array $values) { $result = $this->getBuilder()->insert($values); // Reset query builder $this->resetBuilder(); return $result; }
php
public function insert(array $values) { $result = $this->getBuilder()->insert($values); // Reset query builder $this->resetBuilder(); return $result; }
[ "public", "function", "insert", "(", "array", "$", "values", ")", "{", "$", "result", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "insert", "(", "$", "values", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "$", "result", ";", "}" ]
Insert a new record into the database. @author Morten Rugaard <[email protected]> @param array $values @return bool
[ "Insert", "a", "new", "record", "into", "the", "database", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L547-L555
nodes-php/database
src/Eloquent/Repository.php
Repository.insertGetId
public function insertGetId(array $values, $sequence = null) { $result = $this->getBuilder()->insertGetId($values, $sequence); // Reset query builder $this->resetBuilder(); return $result; }
php
public function insertGetId(array $values, $sequence = null) { $result = $this->getBuilder()->insertGetId($values, $sequence); // Reset query builder $this->resetBuilder(); return $result; }
[ "public", "function", "insertGetId", "(", "array", "$", "values", ",", "$", "sequence", "=", "null", ")", "{", "$", "result", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "insertGetId", "(", "$", "values", ",", "$", "sequence", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "$", "result", ";", "}" ]
Insert a new record and get the value of the primary key. @author Morten Rugaard <[email protected]> @param array $values @param string $sequence @return int
[ "Insert", "a", "new", "record", "and", "get", "the", "value", "of", "the", "primary", "key", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L566-L574
nodes-php/database
src/Eloquent/Repository.php
Repository.update
public function update(array $values) { $result = $this->getBuilder()->update($values); // Reset query builder $this->resetBuilder(); return (int) $result; }
php
public function update(array $values) { $result = $this->getBuilder()->update($values); // Reset query builder $this->resetBuilder(); return (int) $result; }
[ "public", "function", "update", "(", "array", "$", "values", ")", "{", "$", "result", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "update", "(", "$", "values", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "(", "int", ")", "$", "result", ";", "}" ]
Execute query as an update statement. @author Morten Rugaard <[email protected]> @param array $values @return int
[ "Execute", "query", "as", "an", "update", "statement", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L584-L592
nodes-php/database
src/Eloquent/Repository.php
Repository.increment
public function increment($column, $amount = 1, array $extra = []) { $result = $this->getBuilder()->increment($column, $amount, $extra); // Reset query builder $this->resetBuilder(); return (int) $result; }
php
public function increment($column, $amount = 1, array $extra = []) { $result = $this->getBuilder()->increment($column, $amount, $extra); // Reset query builder $this->resetBuilder(); return (int) $result; }
[ "public", "function", "increment", "(", "$", "column", ",", "$", "amount", "=", "1", ",", "array", "$", "extra", "=", "[", "]", ")", "{", "$", "result", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "increment", "(", "$", "column", ",", "$", "amount", ",", "$", "extra", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "(", "int", ")", "$", "result", ";", "}" ]
Increment a column's value by a given amount. @author Morten Rugaard <[email protected]> @param string $column @param int $amount @param array $extra @return int
[ "Increment", "a", "column", "s", "value", "by", "a", "given", "amount", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L638-L646
nodes-php/database
src/Eloquent/Repository.php
Repository.raw
public function raw($value) { $result = $this->getBuilder()->raw($value); // Reset query builder $this->resetBuilder(); return $result; }
php
public function raw($value) { $result = $this->getBuilder()->raw($value); // Reset query builder $this->resetBuilder(); return $result; }
[ "public", "function", "raw", "(", "$", "value", ")", "{", "$", "result", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "raw", "(", "$", "value", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "$", "result", ";", "}" ]
Create a raw database expression. @author Morten Rugaard <[email protected]> @param mixed $value @return \Illuminate\Database\Query\Expression
[ "Create", "a", "raw", "database", "expression", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L691-L699
nodes-php/database
src/Eloquent/Repository.php
Repository.renderSql
public function renderSql() { $result = vsprintf( $this->getBuilder()->getQuery()->toSql(), $this->getBuilder()->getQuery()->getBindings() ); // Reset query builder $this->resetBuilder(); return $result; }
php
public function renderSql() { $result = vsprintf( $this->getBuilder()->getQuery()->toSql(), $this->getBuilder()->getQuery()->getBindings() ); // Reset query builder $this->resetBuilder(); return $result; }
[ "public", "function", "renderSql", "(", ")", "{", "$", "result", "=", "vsprintf", "(", "$", "this", "->", "getBuilder", "(", ")", "->", "getQuery", "(", ")", "->", "toSql", "(", ")", ",", "$", "this", "->", "getBuilder", "(", ")", "->", "getQuery", "(", ")", "->", "getBindings", "(", ")", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "$", "result", ";", "}" ]
Render repository's query SQL string. @author Morten Rugaard <[email protected]> @return string
[ "Render", "repository", "s", "query", "SQL", "string", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L725-L736
nodes-php/database
src/Eloquent/Repository.php
Repository.withTrashed
public function withTrashed() { // Validate model is soft deletable if (! in_array(IlluminateEloquentSoftDeletes::class, class_uses($this->getModel()))) { throw new ModelNotSoftDeletable('Model [%s] is not using the Soft Delete trait'); } // Set repository builder to include soft deleted entries $this->setBuilder($this->getModel()->withTrashed()); return $this; }
php
public function withTrashed() { // Validate model is soft deletable if (! in_array(IlluminateEloquentSoftDeletes::class, class_uses($this->getModel()))) { throw new ModelNotSoftDeletable('Model [%s] is not using the Soft Delete trait'); } // Set repository builder to include soft deleted entries $this->setBuilder($this->getModel()->withTrashed()); return $this; }
[ "public", "function", "withTrashed", "(", ")", "{", "// Validate model is soft deletable", "if", "(", "!", "in_array", "(", "IlluminateEloquentSoftDeletes", "::", "class", ",", "class_uses", "(", "$", "this", "->", "getModel", "(", ")", ")", ")", ")", "{", "throw", "new", "ModelNotSoftDeletable", "(", "'Model [%s] is not using the Soft Delete trait'", ")", ";", "}", "// Set repository builder to include soft deleted entries", "$", "this", "->", "setBuilder", "(", "$", "this", "->", "getModel", "(", ")", "->", "withTrashed", "(", ")", ")", ";", "return", "$", "this", ";", "}" ]
Include soft deleted entries in query. Note this will reset the build @author Morten Rugaard <[email protected]> @throws \Nodes\Database\Exceptions\ModelNotSoftDeletable
[ "Include", "soft", "deleted", "entries", "in", "query", ".", "Note", "this", "will", "reset", "the", "build" ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L746-L757
nodes-php/database
src/Eloquent/Repository.php
Repository.onlyTrashed
public function onlyTrashed() { // Validate model is soft deletable if (! in_array(IlluminateEloquentSoftDeletes::class, class_uses($this->getModel()))) { throw new ModelNotSoftDeletable('Model [%s] is not using the Soft Delete trait'); } // Set repository builder to include soft deleted entries $this->setBuilder($this->getModel()->onlyTrashed()); return $this; }
php
public function onlyTrashed() { // Validate model is soft deletable if (! in_array(IlluminateEloquentSoftDeletes::class, class_uses($this->getModel()))) { throw new ModelNotSoftDeletable('Model [%s] is not using the Soft Delete trait'); } // Set repository builder to include soft deleted entries $this->setBuilder($this->getModel()->onlyTrashed()); return $this; }
[ "public", "function", "onlyTrashed", "(", ")", "{", "// Validate model is soft deletable", "if", "(", "!", "in_array", "(", "IlluminateEloquentSoftDeletes", "::", "class", ",", "class_uses", "(", "$", "this", "->", "getModel", "(", ")", ")", ")", ")", "{", "throw", "new", "ModelNotSoftDeletable", "(", "'Model [%s] is not using the Soft Delete trait'", ")", ";", "}", "// Set repository builder to include soft deleted entries", "$", "this", "->", "setBuilder", "(", "$", "this", "->", "getModel", "(", ")", "->", "onlyTrashed", "(", ")", ")", ";", "return", "$", "this", ";", "}" ]
Only include soft deleted entries in query. Note this will reset the build @author Morten Rugaard <[email protected]> @return $this @throws \Nodes\Database\Exceptions\ModelNotSoftDeletable
[ "Only", "include", "soft", "deleted", "entries", "in", "query", ".", "Note", "this", "will", "reset", "the", "build" ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L768-L779
nodes-php/database
src/Eloquent/Repository.php
Repository.find
public function find($id, array $columns = ['*']) { if (is_array($id)) { return $this->findMany($id, $columns); } return $this->getBy($this->getModel()->getQualifiedKeyName(), $id, $columns); }
php
public function find($id, array $columns = ['*']) { if (is_array($id)) { return $this->findMany($id, $columns); } return $this->getBy($this->getModel()->getQualifiedKeyName(), $id, $columns); }
[ "public", "function", "find", "(", "$", "id", ",", "array", "$", "columns", "=", "[", "'*'", "]", ")", "{", "if", "(", "is_array", "(", "$", "id", ")", ")", "{", "return", "$", "this", "->", "findMany", "(", "$", "id", ",", "$", "columns", ")", ";", "}", "return", "$", "this", "->", "getBy", "(", "$", "this", "->", "getModel", "(", ")", "->", "getQualifiedKeyName", "(", ")", ",", "$", "id", ",", "$", "columns", ")", ";", "}" ]
Find a model by its primary key. @author Morten Rugaard <[email protected]> @param mixed $id @param array $columns @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|null
[ "Find", "a", "model", "by", "its", "primary", "key", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L790-L797
nodes-php/database
src/Eloquent/Repository.php
Repository.findMany
public function findMany($ids, array $columns = ['*']) { if (empty($ids)) { return $this->model->newCollection(); } $this->getBuilder()->whereIn($this->getModel()->getQualifiedKeyName(), $ids); return $this->get($columns); }
php
public function findMany($ids, array $columns = ['*']) { if (empty($ids)) { return $this->model->newCollection(); } $this->getBuilder()->whereIn($this->getModel()->getQualifiedKeyName(), $ids); return $this->get($columns); }
[ "public", "function", "findMany", "(", "$", "ids", ",", "array", "$", "columns", "=", "[", "'*'", "]", ")", "{", "if", "(", "empty", "(", "$", "ids", ")", ")", "{", "return", "$", "this", "->", "model", "->", "newCollection", "(", ")", ";", "}", "$", "this", "->", "getBuilder", "(", ")", "->", "whereIn", "(", "$", "this", "->", "getModel", "(", ")", "->", "getQualifiedKeyName", "(", ")", ",", "$", "ids", ")", ";", "return", "$", "this", "->", "get", "(", "$", "columns", ")", ";", "}" ]
Find a model by its primary key. @author Morten Rugaard <[email protected]> @param array $ids @param array $columns @return \Illuminate\Database\Eloquent\Collection
[ "Find", "a", "model", "by", "its", "primary", "key", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L808-L817
nodes-php/database
src/Eloquent/Repository.php
Repository.findOrFail
public function findOrFail($id, $columns = ['*']) { $result = $this->find($id, $columns); if (is_array($id)) { if (count($result) == count(array_unique($id))) { return $result; } } elseif (! is_null($result)) { return $result; } throw new EntityNotFoundException('Entity not found'); }
php
public function findOrFail($id, $columns = ['*']) { $result = $this->find($id, $columns); if (is_array($id)) { if (count($result) == count(array_unique($id))) { return $result; } } elseif (! is_null($result)) { return $result; } throw new EntityNotFoundException('Entity not found'); }
[ "public", "function", "findOrFail", "(", "$", "id", ",", "$", "columns", "=", "[", "'*'", "]", ")", "{", "$", "result", "=", "$", "this", "->", "find", "(", "$", "id", ",", "$", "columns", ")", ";", "if", "(", "is_array", "(", "$", "id", ")", ")", "{", "if", "(", "count", "(", "$", "result", ")", "==", "count", "(", "array_unique", "(", "$", "id", ")", ")", ")", "{", "return", "$", "result", ";", "}", "}", "elseif", "(", "!", "is_null", "(", "$", "result", ")", ")", "{", "return", "$", "result", ";", "}", "throw", "new", "EntityNotFoundException", "(", "'Entity not found'", ")", ";", "}" ]
Find a model by its primary key or throw an exception. @author Morten Rugaard <[email protected]> @param mixed $id @param array $columns @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection @throws \Nodes\Database\Exceptions\EntityNotFoundException
[ "Find", "a", "model", "by", "its", "primary", "key", "or", "throw", "an", "exception", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L829-L842
nodes-php/database
src/Eloquent/Repository.php
Repository.getBy
public function getBy($column, $value, array $columns = ['*']) { $result = $this->getBuilder() ->select($columns) ->where($column, '=', $value) ->first(); // Reset query builder $this->resetBuilder(); return $result; }
php
public function getBy($column, $value, array $columns = ['*']) { $result = $this->getBuilder() ->select($columns) ->where($column, '=', $value) ->first(); // Reset query builder $this->resetBuilder(); return $result; }
[ "public", "function", "getBy", "(", "$", "column", ",", "$", "value", ",", "array", "$", "columns", "=", "[", "'*'", "]", ")", "{", "$", "result", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "select", "(", "$", "columns", ")", "->", "where", "(", "$", "column", ",", "'='", ",", "$", "value", ")", "->", "first", "(", ")", ";", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "$", "result", ";", "}" ]
Retrieve entity by a specific column and value. @author Morten Rugaard <[email protected]> @param string $column @param string|int $value @param array $columns @return \Illuminate\Database\Eloquent\Model
[ "Retrieve", "entity", "by", "a", "specific", "column", "and", "value", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L854-L865
nodes-php/database
src/Eloquent/Repository.php
Repository.getByOrFail
public function getByOrFail($column, $value, array $columns = ['*']) { $entity = $this->getBy($column, $value, $columns); if (empty($entity)) { throw new EntityNotFoundException(sprintf('%s not found for column [%s] with value [%s]', get_class($this->getModel()), $column, $value)); } return $entity; }
php
public function getByOrFail($column, $value, array $columns = ['*']) { $entity = $this->getBy($column, $value, $columns); if (empty($entity)) { throw new EntityNotFoundException(sprintf('%s not found for column [%s] with value [%s]', get_class($this->getModel()), $column, $value)); } return $entity; }
[ "public", "function", "getByOrFail", "(", "$", "column", ",", "$", "value", ",", "array", "$", "columns", "=", "[", "'*'", "]", ")", "{", "$", "entity", "=", "$", "this", "->", "getBy", "(", "$", "column", ",", "$", "value", ",", "$", "columns", ")", ";", "if", "(", "empty", "(", "$", "entity", ")", ")", "{", "throw", "new", "EntityNotFoundException", "(", "sprintf", "(", "'%s not found for column [%s] with value [%s]'", ",", "get_class", "(", "$", "this", "->", "getModel", "(", ")", ")", ",", "$", "column", ",", "$", "value", ")", ")", ";", "}", "return", "$", "entity", ";", "}" ]
Retrieve entity by a specific column and value. If entity is not found, we'll throw an exception @author Morten Rugaard <[email protected]> @param string $column @param string|int $value @param array $columns @return \Illuminate\Database\Eloquent\Model @throws \Nodes\Database\Exceptions\EntityNotFoundException
[ "Retrieve", "entity", "by", "a", "specific", "column", "and", "value", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L880-L889
nodes-php/database
src/Eloquent/Repository.php
Repository.getByContinuously
public function getByContinuously($column, $value, array $columns = ['*'], $retries = 10, $delayMs = 100, $maxDelay = 2000, $maxRetries = 100) { // Hard limits $maxDelay = ($maxDelay > 2000) ? 2000 : $maxDelay; $maxRetries = ($maxRetries > 100) ? 100 : $maxRetries; // Validate delay parameter if ($delayMs > $maxDelay) { throw new NodesException('Invalid input parameter. Maximum delay is '.$maxDelay.' milliseconds', 0, null, false); } // Validate retry parameter if ($retries > $maxRetries) { throw new NodesException('Invalid input parameter. Maximum retry amount is '.$maxRetries, 0, null, false); } // Retrieve entity continuously for ($try = 0; $try < $retries; $try++) { $entity = $this->getBy($column, $value, $columns); if (! empty($entity)) { return $entity; } // Delay next retry usleep($delayMs * 1000); } return false; }
php
public function getByContinuously($column, $value, array $columns = ['*'], $retries = 10, $delayMs = 100, $maxDelay = 2000, $maxRetries = 100) { // Hard limits $maxDelay = ($maxDelay > 2000) ? 2000 : $maxDelay; $maxRetries = ($maxRetries > 100) ? 100 : $maxRetries; // Validate delay parameter if ($delayMs > $maxDelay) { throw new NodesException('Invalid input parameter. Maximum delay is '.$maxDelay.' milliseconds', 0, null, false); } // Validate retry parameter if ($retries > $maxRetries) { throw new NodesException('Invalid input parameter. Maximum retry amount is '.$maxRetries, 0, null, false); } // Retrieve entity continuously for ($try = 0; $try < $retries; $try++) { $entity = $this->getBy($column, $value, $columns); if (! empty($entity)) { return $entity; } // Delay next retry usleep($delayMs * 1000); } return false; }
[ "public", "function", "getByContinuously", "(", "$", "column", ",", "$", "value", ",", "array", "$", "columns", "=", "[", "'*'", "]", ",", "$", "retries", "=", "10", ",", "$", "delayMs", "=", "100", ",", "$", "maxDelay", "=", "2000", ",", "$", "maxRetries", "=", "100", ")", "{", "// Hard limits", "$", "maxDelay", "=", "(", "$", "maxDelay", ">", "2000", ")", "?", "2000", ":", "$", "maxDelay", ";", "$", "maxRetries", "=", "(", "$", "maxRetries", ">", "100", ")", "?", "100", ":", "$", "maxRetries", ";", "// Validate delay parameter", "if", "(", "$", "delayMs", ">", "$", "maxDelay", ")", "{", "throw", "new", "NodesException", "(", "'Invalid input parameter. Maximum delay is '", ".", "$", "maxDelay", ".", "' milliseconds'", ",", "0", ",", "null", ",", "false", ")", ";", "}", "// Validate retry parameter", "if", "(", "$", "retries", ">", "$", "maxRetries", ")", "{", "throw", "new", "NodesException", "(", "'Invalid input parameter. Maximum retry amount is '", ".", "$", "maxRetries", ",", "0", ",", "null", ",", "false", ")", ";", "}", "// Retrieve entity continuously", "for", "(", "$", "try", "=", "0", ";", "$", "try", "<", "$", "retries", ";", "$", "try", "++", ")", "{", "$", "entity", "=", "$", "this", "->", "getBy", "(", "$", "column", ",", "$", "value", ",", "$", "columns", ")", ";", "if", "(", "!", "empty", "(", "$", "entity", ")", ")", "{", "return", "$", "entity", ";", "}", "// Delay next retry", "usleep", "(", "$", "delayMs", "*", "1000", ")", ";", "}", "return", "false", ";", "}" ]
Retrieve entity by a specific column and value. Will retry with a delay until found. Should only be used in queues, where databases are in a cluster and there's a chance it's not always in sync @author Casper Rasmussen <[email protected]> @param string $column @param string $value @param array $columns @param int $retries @param int $delayMs @param int $maxDelay @param int $maxRetries @return \Illuminate\Database\Eloquent\Model @throws \Nodes\Exceptions\Exception
[ "Retrieve", "entity", "by", "a", "specific", "column", "and", "value", ".", "Will", "retry", "with", "a", "delay", "until", "found", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L975-L1003
nodes-php/database
src/Eloquent/Repository.php
Repository.getByIdContinuously
public function getByIdContinuously($id, array $columns = ['*'], $retries = 10, $delayMs = 100) { return $this->getByContinuously('id', $id, $columns, $retries, $delayMs); }
php
public function getByIdContinuously($id, array $columns = ['*'], $retries = 10, $delayMs = 100) { return $this->getByContinuously('id', $id, $columns, $retries, $delayMs); }
[ "public", "function", "getByIdContinuously", "(", "$", "id", ",", "array", "$", "columns", "=", "[", "'*'", "]", ",", "$", "retries", "=", "10", ",", "$", "delayMs", "=", "100", ")", "{", "return", "$", "this", "->", "getByContinuously", "(", "'id'", ",", "$", "id", ",", "$", "columns", ",", "$", "retries", ",", "$", "delayMs", ")", ";", "}" ]
Retrieve entity by ID. Will retry with a delay until found. Should only be used in queues, where databases are in a cluster and there's a chance it's not always in sync @author Casper Rasmussen <[email protected]> @param int $id @param array $columns @param int $retries @param int $delayMs @return \Illuminate\Database\Eloquent\Model @throws \Nodes\Exceptions\Exception
[ "Retrieve", "entity", "by", "ID", ".", "Will", "retry", "with", "a", "delay", "until", "found", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L1020-L1023
nodes-php/database
src/Eloquent/Repository.php
Repository.getByIdContinuouslyOrFail
public function getByIdContinuouslyOrFail($id, array $columns = ['*'], $retries = 10, $delayMs = 100) { $result = $this->getByContinuously('id', $id, $columns, $retries, $delayMs); if (empty($result)) { throw new EntityNotFoundException(sprintf('%s not found continuously by Id with value [%s]', get_class($this->getModel()), $id)); } return $result; }
php
public function getByIdContinuouslyOrFail($id, array $columns = ['*'], $retries = 10, $delayMs = 100) { $result = $this->getByContinuously('id', $id, $columns, $retries, $delayMs); if (empty($result)) { throw new EntityNotFoundException(sprintf('%s not found continuously by Id with value [%s]', get_class($this->getModel()), $id)); } return $result; }
[ "public", "function", "getByIdContinuouslyOrFail", "(", "$", "id", ",", "array", "$", "columns", "=", "[", "'*'", "]", ",", "$", "retries", "=", "10", ",", "$", "delayMs", "=", "100", ")", "{", "$", "result", "=", "$", "this", "->", "getByContinuously", "(", "'id'", ",", "$", "id", ",", "$", "columns", ",", "$", "retries", ",", "$", "delayMs", ")", ";", "if", "(", "empty", "(", "$", "result", ")", ")", "{", "throw", "new", "EntityNotFoundException", "(", "sprintf", "(", "'%s not found continuously by Id with value [%s]'", ",", "get_class", "(", "$", "this", "->", "getModel", "(", ")", ")", ",", "$", "id", ")", ")", ";", "}", "return", "$", "result", ";", "}" ]
Retrieve entity by ID. Will retry with a delay until found or throw an exception. Should only be used in queues, where databases are in a cluster and there's a chance it's not always in sync @author Rasmus Ebbesen <[email protected]> @param int $id @param array $columns @param int $retries @param int $delayMs @return \Illuminate\Database\Eloquent\Model @throws \Nodes\Database\Exceptions\EntityNotFoundException
[ "Retrieve", "entity", "by", "ID", ".", "Will", "retry", "with", "a", "delay", "until", "found", "or", "throw", "an", "exception", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L1040-L1049
nodes-php/database
src/Eloquent/Repository.php
Repository.deleteMorphsByEntity
public function deleteMorphsByEntity(IlluminateEloquentModel $entity, $relationName, $forceDelete = false) { // Retrieve all records by entity type and entity ID $entities = $this->getBuilder() ->select(['id']) ->where(function ($query) use ($entity, $relationName) { $query->where($relationName.'_type', '=', get_class($entity)) ->where($relationName.'_id', '=', (int) $entity->id); }) ->get(); // Delete count $deleteCount = 0; // Loop through each entity individually. // This is required to soft delete all found entiries. foreach ($entities as $e) { $status = ($forceDelete) ? $e->forceDelete() : $e->delete(); if ((bool) $status) { $deleteCount += 1; } } // Reset query builder $this->resetBuilder(); return $deleteCount; }
php
public function deleteMorphsByEntity(IlluminateEloquentModel $entity, $relationName, $forceDelete = false) { // Retrieve all records by entity type and entity ID $entities = $this->getBuilder() ->select(['id']) ->where(function ($query) use ($entity, $relationName) { $query->where($relationName.'_type', '=', get_class($entity)) ->where($relationName.'_id', '=', (int) $entity->id); }) ->get(); // Delete count $deleteCount = 0; // Loop through each entity individually. // This is required to soft delete all found entiries. foreach ($entities as $e) { $status = ($forceDelete) ? $e->forceDelete() : $e->delete(); if ((bool) $status) { $deleteCount += 1; } } // Reset query builder $this->resetBuilder(); return $deleteCount; }
[ "public", "function", "deleteMorphsByEntity", "(", "IlluminateEloquentModel", "$", "entity", ",", "$", "relationName", ",", "$", "forceDelete", "=", "false", ")", "{", "// Retrieve all records by entity type and entity ID", "$", "entities", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "select", "(", "[", "'id'", "]", ")", "->", "where", "(", "function", "(", "$", "query", ")", "use", "(", "$", "entity", ",", "$", "relationName", ")", "{", "$", "query", "->", "where", "(", "$", "relationName", ".", "'_type'", ",", "'='", ",", "get_class", "(", "$", "entity", ")", ")", "->", "where", "(", "$", "relationName", ".", "'_id'", ",", "'='", ",", "(", "int", ")", "$", "entity", "->", "id", ")", ";", "}", ")", "->", "get", "(", ")", ";", "// Delete count", "$", "deleteCount", "=", "0", ";", "// Loop through each entity individually.", "// This is required to soft delete all found entiries.", "foreach", "(", "$", "entities", "as", "$", "e", ")", "{", "$", "status", "=", "(", "$", "forceDelete", ")", "?", "$", "e", "->", "forceDelete", "(", ")", ":", "$", "e", "->", "delete", "(", ")", ";", "if", "(", "(", "bool", ")", "$", "status", ")", "{", "$", "deleteCount", "+=", "1", ";", "}", "}", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "$", "deleteCount", ";", "}" ]
Delete morphed relations by entity. Note: This should only be used with morphed relations @author Morten Rugaard <[email protected]> @param \Illuminate\Database\Eloquent\Model $entity @param string $relationName @param bool $forceDelete @return int
[ "Delete", "morphed", "relations", "by", "entity", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L1063-L1090
nodes-php/database
src/Eloquent/Repository.php
Repository.restoreMorphsByEntity
public function restoreMorphsByEntity(IlluminateEloquentModel $entity, $relationName) { // Validate model is soft deletable if (! in_array(IlluminateEloquentSoftDeletes::class, class_uses($this->getModel()))) { throw new ModelNotSoftDeletable('Model [%s] is not using the Soft Delete trait'); } // Retrieve all records by entity type and entity ID $entities = $this->onlyTrashed() ->getBuilder() ->select(['id']) ->where(function ($query) use ($entity, $relationName) { $query->where($relationName.'_type', '=', get_class($entity)) ->where($relationName.'_id', '=', (int) $entity->id); }) ->get(); // Restore count $restoreCount = 0; // Loop through each entity individually. // This is required to soft delete all found entiries. foreach ($entities as $e) { if ((bool) $e->restore()) { $restoreCount += 1; } } // Reset query builder $this->resetBuilder(); return $restoreCount; }
php
public function restoreMorphsByEntity(IlluminateEloquentModel $entity, $relationName) { // Validate model is soft deletable if (! in_array(IlluminateEloquentSoftDeletes::class, class_uses($this->getModel()))) { throw new ModelNotSoftDeletable('Model [%s] is not using the Soft Delete trait'); } // Retrieve all records by entity type and entity ID $entities = $this->onlyTrashed() ->getBuilder() ->select(['id']) ->where(function ($query) use ($entity, $relationName) { $query->where($relationName.'_type', '=', get_class($entity)) ->where($relationName.'_id', '=', (int) $entity->id); }) ->get(); // Restore count $restoreCount = 0; // Loop through each entity individually. // This is required to soft delete all found entiries. foreach ($entities as $e) { if ((bool) $e->restore()) { $restoreCount += 1; } } // Reset query builder $this->resetBuilder(); return $restoreCount; }
[ "public", "function", "restoreMorphsByEntity", "(", "IlluminateEloquentModel", "$", "entity", ",", "$", "relationName", ")", "{", "// Validate model is soft deletable", "if", "(", "!", "in_array", "(", "IlluminateEloquentSoftDeletes", "::", "class", ",", "class_uses", "(", "$", "this", "->", "getModel", "(", ")", ")", ")", ")", "{", "throw", "new", "ModelNotSoftDeletable", "(", "'Model [%s] is not using the Soft Delete trait'", ")", ";", "}", "// Retrieve all records by entity type and entity ID", "$", "entities", "=", "$", "this", "->", "onlyTrashed", "(", ")", "->", "getBuilder", "(", ")", "->", "select", "(", "[", "'id'", "]", ")", "->", "where", "(", "function", "(", "$", "query", ")", "use", "(", "$", "entity", ",", "$", "relationName", ")", "{", "$", "query", "->", "where", "(", "$", "relationName", ".", "'_type'", ",", "'='", ",", "get_class", "(", "$", "entity", ")", ")", "->", "where", "(", "$", "relationName", ".", "'_id'", ",", "'='", ",", "(", "int", ")", "$", "entity", "->", "id", ")", ";", "}", ")", "->", "get", "(", ")", ";", "// Restore count", "$", "restoreCount", "=", "0", ";", "// Loop through each entity individually.", "// This is required to soft delete all found entiries.", "foreach", "(", "$", "entities", "as", "$", "e", ")", "{", "if", "(", "(", "bool", ")", "$", "e", "->", "restore", "(", ")", ")", "{", "$", "restoreCount", "+=", "1", ";", "}", "}", "// Reset query builder", "$", "this", "->", "resetBuilder", "(", ")", ";", "return", "$", "restoreCount", ";", "}" ]
Restore morphed relations by entity. Note: This should only be used with morphed relations @author Morten Rugaard <[email protected]> @param \Illuminate\Database\Eloquent\Model $entity @param string $relationName @return int @throws \Nodes\Database\Exceptions\ModelNotSoftDeletable
[ "Restore", "morphed", "relations", "by", "entity", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L1104-L1136
nodes-php/database
src/Eloquent/Repository.php
Repository.setModel
public function setModel(IlluminateEloquentModel $model) { // Set repository model $this->model = $model; // Set repository builder from model $this->setBuilder($model->newQuery()); return $this; }
php
public function setModel(IlluminateEloquentModel $model) { // Set repository model $this->model = $model; // Set repository builder from model $this->setBuilder($model->newQuery()); return $this; }
[ "public", "function", "setModel", "(", "IlluminateEloquentModel", "$", "model", ")", "{", "// Set repository model", "$", "this", "->", "model", "=", "$", "model", ";", "// Set repository builder from model", "$", "this", "->", "setBuilder", "(", "$", "model", "->", "newQuery", "(", ")", ")", ";", "return", "$", "this", ";", "}" ]
Set repository model. @author Morten Rugaard <[email protected]> @param \Illuminate\Database\Eloquent\Model $model @return $this
[ "Set", "repository", "model", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L1182-L1191
nodes-php/database
src/Eloquent/Repository.php
Repository.setBuilder
public function setBuilder(IlluminateEloquentBuilder $builder = null) { // If no builder was provided, // we'll use the one from this repositorys model if (empty($builder)) { $builder = $this->getModel()->newQuery(); } // Set repository builder $this->builder = $builder; return $this; }
php
public function setBuilder(IlluminateEloquentBuilder $builder = null) { // If no builder was provided, // we'll use the one from this repositorys model if (empty($builder)) { $builder = $this->getModel()->newQuery(); } // Set repository builder $this->builder = $builder; return $this; }
[ "public", "function", "setBuilder", "(", "IlluminateEloquentBuilder", "$", "builder", "=", "null", ")", "{", "// If no builder was provided,", "// we'll use the one from this repositorys model", "if", "(", "empty", "(", "$", "builder", ")", ")", "{", "$", "builder", "=", "$", "this", "->", "getModel", "(", ")", "->", "newQuery", "(", ")", ";", "}", "// Set repository builder", "$", "this", "->", "builder", "=", "$", "builder", ";", "return", "$", "this", ";", "}" ]
Set repository builder. @author Morten Rugaard <[email protected]> @acecss public @param \Illuminate\Database\Eloquent\Builder $builder @return $this
[ "Set", "repository", "builder", "." ]
train
https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Repository.php#L1214-L1226
askupasoftware/amarkal
Assets/Script.php
Script.register
public function register() { wp_register_script( $this->handle, $this->url, $this->dependencies, $this->version, $this->footer ); // Localize the script as needed if( !empty( $this->localize['data'] ) && !empty( $this->localize['data'] ) ) { wp_localize_script( $this->handle, $this->localize['name'], $this->localize['data'] ); } $this->is_registered = true; }
php
public function register() { wp_register_script( $this->handle, $this->url, $this->dependencies, $this->version, $this->footer ); // Localize the script as needed if( !empty( $this->localize['data'] ) && !empty( $this->localize['data'] ) ) { wp_localize_script( $this->handle, $this->localize['name'], $this->localize['data'] ); } $this->is_registered = true; }
[ "public", "function", "register", "(", ")", "{", "wp_register_script", "(", "$", "this", "->", "handle", ",", "$", "this", "->", "url", ",", "$", "this", "->", "dependencies", ",", "$", "this", "->", "version", ",", "$", "this", "->", "footer", ")", ";", "// Localize the script as needed", "if", "(", "!", "empty", "(", "$", "this", "->", "localize", "[", "'data'", "]", ")", "&&", "!", "empty", "(", "$", "this", "->", "localize", "[", "'data'", "]", ")", ")", "{", "wp_localize_script", "(", "$", "this", "->", "handle", ",", "$", "this", "->", "localize", "[", "'name'", "]", ",", "$", "this", "->", "localize", "[", "'data'", "]", ")", ";", "}", "$", "this", "->", "is_registered", "=", "true", ";", "}" ]
Enqueue the script and localize the data as needed
[ "Enqueue", "the", "script", "and", "localize", "the", "data", "as", "needed" ]
train
https://github.com/askupasoftware/amarkal/blob/fe8283e2d6847ef697abec832da7ee741a85058c/Assets/Script.php#L39-L58
mremi/Flowdock
src/Mremi/Flowdock/Api/Push/BaseMessage.php
BaseMessage.setTags
public function setTags(array $tags) { $this->clearTags(); foreach ($tags as $tag) { $this->addTag($tag); } return $this; }
php
public function setTags(array $tags) { $this->clearTags(); foreach ($tags as $tag) { $this->addTag($tag); } return $this; }
[ "public", "function", "setTags", "(", "array", "$", "tags", ")", "{", "$", "this", "->", "clearTags", "(", ")", ";", "foreach", "(", "$", "tags", "as", "$", "tag", ")", "{", "$", "this", "->", "addTag", "(", "$", "tag", ")", ";", "}", "return", "$", "this", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/mremi/Flowdock/blob/287bfdcef17529055f803f2316e3ad31826e79eb/src/Mremi/Flowdock/Api/Push/BaseMessage.php#L77-L86
mremi/Flowdock
src/Mremi/Flowdock/Api/Push/BaseMessage.php
BaseMessage.toArray
public function toArray() { $array = get_object_vars($this); $keys = array_map(array($this, 'underscore'), array_keys($array)); return array_combine($keys, array_values($array)); }
php
public function toArray() { $array = get_object_vars($this); $keys = array_map(array($this, 'underscore'), array_keys($array)); return array_combine($keys, array_values($array)); }
[ "public", "function", "toArray", "(", ")", "{", "$", "array", "=", "get_object_vars", "(", "$", "this", ")", ";", "$", "keys", "=", "array_map", "(", "array", "(", "$", "this", ",", "'underscore'", ")", ",", "array_keys", "(", "$", "array", ")", ")", ";", "return", "array_combine", "(", "$", "keys", ",", "array_values", "(", "$", "array", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/mremi/Flowdock/blob/287bfdcef17529055f803f2316e3ad31826e79eb/src/Mremi/Flowdock/Api/Push/BaseMessage.php#L140-L147
mremi/Flowdock
src/Mremi/Flowdock/Api/Push/BaseMessage.php
BaseMessage.getResponseBody
public function getResponseBody() { if (null === $this->response) { return array(); } $body = json_decode($this->response->getBody(true), true); return is_array($body) ? $body : array(); }
php
public function getResponseBody() { if (null === $this->response) { return array(); } $body = json_decode($this->response->getBody(true), true); return is_array($body) ? $body : array(); }
[ "public", "function", "getResponseBody", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "response", ")", "{", "return", "array", "(", ")", ";", "}", "$", "body", "=", "json_decode", "(", "$", "this", "->", "response", "->", "getBody", "(", "true", ")", ",", "true", ")", ";", "return", "is_array", "(", "$", "body", ")", "?", "$", "body", ":", "array", "(", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/mremi/Flowdock/blob/287bfdcef17529055f803f2316e3ad31826e79eb/src/Mremi/Flowdock/Api/Push/BaseMessage.php#L152-L161