id int32 0 241k | repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 |
|---|---|---|---|---|---|---|---|---|---|---|---|
36,300 | CeusMedia/Common | src/UI/HTML/Exception/Trace.php | UI_HTML_Exception_Trace.renderFromTrace | public static function renderFromTrace( $trace )
{
if( !is_array( $trace ) )
throw new InvalidArgumentException( "Trace must be an array" );
if( !count( $trace ) )
return '';
$i = 0;
$j = 0;
$list = array();
foreach( $trace as $key => $trace )
{
$step = self::renderTraceStep( $trace, $i++, $j );
if( !$step )
continue;
$list[] = UI_HTML_Tag::create( 'li', $step );
$j++;
}
return UI_HTML_Tag::create( 'ol', implode( $list ), array( 'class' => 'trace' ) );
} | php | public static function renderFromTrace( $trace )
{
if( !is_array( $trace ) )
throw new InvalidArgumentException( "Trace must be an array" );
if( !count( $trace ) )
return '';
$i = 0;
$j = 0;
$list = array();
foreach( $trace as $key => $trace )
{
$step = self::renderTraceStep( $trace, $i++, $j );
if( !$step )
continue;
$list[] = UI_HTML_Tag::create( 'li', $step );
$j++;
}
return UI_HTML_Tag::create( 'ol', implode( $list ), array( 'class' => 'trace' ) );
} | [
"public",
"static",
"function",
"renderFromTrace",
"(",
"$",
"trace",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"trace",
")",
")",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Trace must be an array\"",
")",
";",
"if",
"(",
"!",
"count",
"(",
"$",
"trace",
")",
")",
"return",
"''",
";",
"$",
"i",
"=",
"0",
";",
"$",
"j",
"=",
"0",
";",
"$",
"list",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"trace",
"as",
"$",
"key",
"=>",
"$",
"trace",
")",
"{",
"$",
"step",
"=",
"self",
"::",
"renderTraceStep",
"(",
"$",
"trace",
",",
"$",
"i",
"++",
",",
"$",
"j",
")",
";",
"if",
"(",
"!",
"$",
"step",
")",
"continue",
";",
"$",
"list",
"[",
"]",
"=",
"UI_HTML_Tag",
"::",
"create",
"(",
"'li'",
",",
"$",
"step",
")",
";",
"$",
"j",
"++",
";",
"}",
"return",
"UI_HTML_Tag",
"::",
"create",
"(",
"'ol'",
",",
"implode",
"(",
"$",
"list",
")",
",",
"array",
"(",
"'class'",
"=>",
"'trace'",
")",
")",
";",
"}"
] | Renders exception trace HTML code from exception trace array.
@access public
@param array $trace Trace of exception
@return string | [
"Renders",
"exception",
"trace",
"HTML",
"code",
"from",
"exception",
"trace",
"array",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/Exception/Trace.php#L60-L78 |
36,301 | CeusMedia/Common | src/UI/HTML/Exception/Trace.php | UI_HTML_Exception_Trace.renderArgumentArray | protected static function renderArgumentArray( $array )
{
$list = array();
foreach( $array as $key => $value )
{
$type = self::renderArgumentType( $value );
$string = self::renderArgument( $value );
$list[] = UI_HTML_Tag::create( 'dt', $type." ".$key );
$list[] = UI_HTML_Tag::create( 'dd', $string );
}
$list = UI_HTML_Tag::create( 'dl', implode( $list ) );
$block = UI_HTML_Tag::create( 'blockquote', $list );
return '{'.$block.'}';
} | php | protected static function renderArgumentArray( $array )
{
$list = array();
foreach( $array as $key => $value )
{
$type = self::renderArgumentType( $value );
$string = self::renderArgument( $value );
$list[] = UI_HTML_Tag::create( 'dt', $type." ".$key );
$list[] = UI_HTML_Tag::create( 'dd', $string );
}
$list = UI_HTML_Tag::create( 'dl', implode( $list ) );
$block = UI_HTML_Tag::create( 'blockquote', $list );
return '{'.$block.'}';
} | [
"protected",
"static",
"function",
"renderArgumentArray",
"(",
"$",
"array",
")",
"{",
"$",
"list",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"type",
"=",
"self",
"::",
"renderArgumentType",
"(",
"$",
"value",
")",
";",
"$",
"string",
"=",
"self",
"::",
"renderArgument",
"(",
"$",
"value",
")",
";",
"$",
"list",
"[",
"]",
"=",
"UI_HTML_Tag",
"::",
"create",
"(",
"'dt'",
",",
"$",
"type",
".",
"\" \"",
".",
"$",
"key",
")",
";",
"$",
"list",
"[",
"]",
"=",
"UI_HTML_Tag",
"::",
"create",
"(",
"'dd'",
",",
"$",
"string",
")",
";",
"}",
"$",
"list",
"=",
"UI_HTML_Tag",
"::",
"create",
"(",
"'dl'",
",",
"implode",
"(",
"$",
"list",
")",
")",
";",
"$",
"block",
"=",
"UI_HTML_Tag",
"::",
"create",
"(",
"'blockquote'",
",",
"$",
"list",
")",
";",
"return",
"'{'",
".",
"$",
"block",
".",
"'}'",
";",
"}"
] | Renders an argument array.
@access protected
@static
@param array $array Array to render
@return string | [
"Renders",
"an",
"argument",
"array",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/Exception/Trace.php#L123-L136 |
36,302 | CeusMedia/Common | src/UI/HTML/Exception/Trace.php | UI_HTML_Exception_Trace.renderArgumentType | protected static function renderArgumentType( $argument )
{
$type = gettype( $argument );
$length = '';
if( $type == 'string' )
$length = '('.strlen( $argument ).')';
else if( $type == 'array' || $argument instanceof Countable )
$length = '('.count( $argument ).')';
$type = ucFirst( strtolower( gettype( $argument ) ) );
return UI_HTML_Tag::create( 'span', $type.$length, array( 'class' => 'type' ) );
} | php | protected static function renderArgumentType( $argument )
{
$type = gettype( $argument );
$length = '';
if( $type == 'string' )
$length = '('.strlen( $argument ).')';
else if( $type == 'array' || $argument instanceof Countable )
$length = '('.count( $argument ).')';
$type = ucFirst( strtolower( gettype( $argument ) ) );
return UI_HTML_Tag::create( 'span', $type.$length, array( 'class' => 'type' ) );
} | [
"protected",
"static",
"function",
"renderArgumentType",
"(",
"$",
"argument",
")",
"{",
"$",
"type",
"=",
"gettype",
"(",
"$",
"argument",
")",
";",
"$",
"length",
"=",
"''",
";",
"if",
"(",
"$",
"type",
"==",
"'string'",
")",
"$",
"length",
"=",
"'('",
".",
"strlen",
"(",
"$",
"argument",
")",
".",
"')'",
";",
"else",
"if",
"(",
"$",
"type",
"==",
"'array'",
"||",
"$",
"argument",
"instanceof",
"Countable",
")",
"$",
"length",
"=",
"'('",
".",
"count",
"(",
"$",
"argument",
")",
".",
"')'",
";",
"$",
"type",
"=",
"ucFirst",
"(",
"strtolower",
"(",
"gettype",
"(",
"$",
"argument",
")",
")",
")",
";",
"return",
"UI_HTML_Tag",
"::",
"create",
"(",
"'span'",
",",
"$",
"type",
".",
"$",
"length",
",",
"array",
"(",
"'class'",
"=>",
"'type'",
")",
")",
";",
"}"
] | Renders formatted argument type.
@access protected
@static
@param string $argument Argument to render type for
@return string | [
"Renders",
"formatted",
"argument",
"type",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/Exception/Trace.php#L145-L155 |
36,303 | CeusMedia/Common | src/UI/HTML/Exception/Trace.php | UI_HTML_Exception_Trace.secureString | protected static function secureString( $string, $maxLength = 0, $mask = '…' )
{
if( $maxLength && strlen( $string ) > $maxLength )
$value = Alg_Text_Trimmer::trimCentric( $string, $maxLength, $mask );
// $string = addslashes( $string );
$string = htmlentities( $string, ENT_QUOTES, 'UTF-8' );
$string = nl2br( $string );
return $string;
} | php | protected static function secureString( $string, $maxLength = 0, $mask = '…' )
{
if( $maxLength && strlen( $string ) > $maxLength )
$value = Alg_Text_Trimmer::trimCentric( $string, $maxLength, $mask );
// $string = addslashes( $string );
$string = htmlentities( $string, ENT_QUOTES, 'UTF-8' );
$string = nl2br( $string );
return $string;
} | [
"protected",
"static",
"function",
"secureString",
"(",
"$",
"string",
",",
"$",
"maxLength",
"=",
"0",
",",
"$",
"mask",
"=",
"'…'",
")",
"{",
"if",
"(",
"$",
"maxLength",
"&&",
"strlen",
"(",
"$",
"string",
")",
">",
"$",
"maxLength",
")",
"$",
"value",
"=",
"Alg_Text_Trimmer",
"::",
"trimCentric",
"(",
"$",
"string",
",",
"$",
"maxLength",
",",
"$",
"mask",
")",
";",
"//\t\t$string\t= addslashes( $string );",
"$",
"string",
"=",
"htmlentities",
"(",
"$",
"string",
",",
"ENT_QUOTES",
",",
"'UTF-8'",
")",
";",
"$",
"string",
"=",
"nl2br",
"(",
"$",
"string",
")",
";",
"return",
"$",
"string",
";",
"}"
] | Applies filters on content string to avoid injections.
@access public
@static
@param string $string String to secure
@param integer $maxLength Number of characters to show at most
@param string $mask Mask to show for cutted content
@return string | [
"Applies",
"filters",
"on",
"content",
"string",
"to",
"avoid",
"injections",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/Exception/Trace.php#L223-L231 |
36,304 | CeusMedia/Common | src/UI/HTML/Image.php | UI_HTML_Image.render | public function render()
{
$attributes = $this->getAttributes();
if( empty( $this->url ) )
throw new InvalidArgumentException( 'Image URL is empty' );
$attributes['title'] = (string) $this->title;
$attributes['alt'] = (string) $this->title;
$attributes['src'] = $this->url;
return UI_HTML_Tag::create( 'img', NULL, $attributes );
} | php | public function render()
{
$attributes = $this->getAttributes();
if( empty( $this->url ) )
throw new InvalidArgumentException( 'Image URL is empty' );
$attributes['title'] = (string) $this->title;
$attributes['alt'] = (string) $this->title;
$attributes['src'] = $this->url;
return UI_HTML_Tag::create( 'img', NULL, $attributes );
} | [
"public",
"function",
"render",
"(",
")",
"{",
"$",
"attributes",
"=",
"$",
"this",
"->",
"getAttributes",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"url",
")",
")",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Image URL is empty'",
")",
";",
"$",
"attributes",
"[",
"'title'",
"]",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"title",
";",
"$",
"attributes",
"[",
"'alt'",
"]",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"title",
";",
"$",
"attributes",
"[",
"'src'",
"]",
"=",
"$",
"this",
"->",
"url",
";",
"return",
"UI_HTML_Tag",
"::",
"create",
"(",
"'img'",
",",
"NULL",
",",
"$",
"attributes",
")",
";",
"}"
] | Returns rendered HTML Element.
@access public
@return string | [
"Returns",
"rendered",
"HTML",
"Element",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/Image.php#L68-L77 |
36,305 | CeusMedia/Common | src/Alg/Search/Strange.php | Alg_Search_Strange.search | public function search( $array, $key, $left = FALSE, $right = FALSE )
{
if( !$right )
{
$left = 0;
$right = sizeof( $array ) - 1;
$this->counter = 0;
}
$this->counter++;
$index1 = round( $left + ( $right - $left ) / 3, 0 );
$index2 = round( $left + ( ( $right-$left ) / 3 ) * 2, 0 );
//echo "searching from $left to $right [$index1 - $index2]<br>";
if( $key == $array[$index1] )
return ":".$index1;
if( $key == $array[$index2] )
return ":".$index2;
if( $left == $right )
return false;
if( $key < $array[$index1] )
return $this->search( $array, $key, $left, $index1 );
else if( $key >= $array[$index2] )
return $this->search( $array, $key, $index2, $right );
else
return $this->search( $array, $key, $index1 + 1, $index2 - 1 );
} | php | public function search( $array, $key, $left = FALSE, $right = FALSE )
{
if( !$right )
{
$left = 0;
$right = sizeof( $array ) - 1;
$this->counter = 0;
}
$this->counter++;
$index1 = round( $left + ( $right - $left ) / 3, 0 );
$index2 = round( $left + ( ( $right-$left ) / 3 ) * 2, 0 );
//echo "searching from $left to $right [$index1 - $index2]<br>";
if( $key == $array[$index1] )
return ":".$index1;
if( $key == $array[$index2] )
return ":".$index2;
if( $left == $right )
return false;
if( $key < $array[$index1] )
return $this->search( $array, $key, $left, $index1 );
else if( $key >= $array[$index2] )
return $this->search( $array, $key, $index2, $right );
else
return $this->search( $array, $key, $index1 + 1, $index2 - 1 );
} | [
"public",
"function",
"search",
"(",
"$",
"array",
",",
"$",
"key",
",",
"$",
"left",
"=",
"FALSE",
",",
"$",
"right",
"=",
"FALSE",
")",
"{",
"if",
"(",
"!",
"$",
"right",
")",
"{",
"$",
"left",
"=",
"0",
";",
"$",
"right",
"=",
"sizeof",
"(",
"$",
"array",
")",
"-",
"1",
";",
"$",
"this",
"->",
"counter",
"=",
"0",
";",
"}",
"$",
"this",
"->",
"counter",
"++",
";",
"$",
"index1",
"=",
"round",
"(",
"$",
"left",
"+",
"(",
"$",
"right",
"-",
"$",
"left",
")",
"/",
"3",
",",
"0",
")",
";",
"$",
"index2",
"=",
"round",
"(",
"$",
"left",
"+",
"(",
"(",
"$",
"right",
"-",
"$",
"left",
")",
"/",
"3",
")",
"*",
"2",
",",
"0",
")",
";",
"//echo \"searching from $left to $right [$index1 - $index2]<br>\";\r",
"if",
"(",
"$",
"key",
"==",
"$",
"array",
"[",
"$",
"index1",
"]",
")",
"return",
"\":\"",
".",
"$",
"index1",
";",
"if",
"(",
"$",
"key",
"==",
"$",
"array",
"[",
"$",
"index2",
"]",
")",
"return",
"\":\"",
".",
"$",
"index2",
";",
"if",
"(",
"$",
"left",
"==",
"$",
"right",
")",
"return",
"false",
";",
"if",
"(",
"$",
"key",
"<",
"$",
"array",
"[",
"$",
"index1",
"]",
")",
"return",
"$",
"this",
"->",
"search",
"(",
"$",
"array",
",",
"$",
"key",
",",
"$",
"left",
",",
"$",
"index1",
")",
";",
"else",
"if",
"(",
"$",
"key",
">=",
"$",
"array",
"[",
"$",
"index2",
"]",
")",
"return",
"$",
"this",
"->",
"search",
"(",
"$",
"array",
",",
"$",
"key",
",",
"$",
"index2",
",",
"$",
"right",
")",
";",
"else",
"return",
"$",
"this",
"->",
"search",
"(",
"$",
"array",
",",
"$",
"key",
",",
"$",
"index1",
"+",
"1",
",",
"$",
"index2",
"-",
"1",
")",
";",
"}"
] | Searches in List and returns position if found.
@access public
@param array $ist List to search in
@param mixed $search Element to search
@param int $left Left bound
@param int $right Right bound
@return int | [
"Searches",
"in",
"List",
"and",
"returns",
"position",
"if",
"found",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Search/Strange.php#L52-L76 |
36,306 | ncou/Chiron | src/Chiron/Handler/Formatter/ViewFormatter.php | ViewFormatter.format | public function format(ServerRequestInterface $request, Throwable $e): string
{
// This class doesn't show debug information, so by default we hide the php exception behind a neutral http 500 error.
if (! $e instanceof HttpException) {
$e = new \Chiron\Http\Exception\Server\InternalServerErrorHttpException();
}
$info = $e->toArray();
// TODO : ajouter plus d'information dans ce tableau qui va être passé à la vue pour pouvoir utiliser ces informations => https://github.com/cakephp/cakephp/blob/dc63c2f0d8a1e9d5f336ab81b587a54929d9e1cf/src/Error/ExceptionRenderer.php#L218
/*
Arguments à passer à la vue :
$templateData = [
'response' => $response,
'request' => $request,
'uri' => (string) $request->getUri(),
'status' => $response->getStatusCode(),
'reason' => $response->getReasonPhrase(),
'debug' => $this->debug,
];
if ($this->debug) {
$templateData['error'] = $e;
}
]*/
$info = array_merge($info, ['exception' => $e]); // TODO : vérifier qu'on accéde bien aux informations ajoutées en attribut !!!!!!!!!!!!!
$statusCode = $info['status'];
// TODO : gérer le cas des PDOException pour la BDD, avec un template spécial => https://github.com/cakephp/cakephp/blob/dc63c2f0d8a1e9d5f336ab81b587a54929d9e1cf/src/Error/ExceptionRenderer.php#L335
//https://github.com/cakephp/cakephp/blob/2341c3cd7c32e315c2d54b625313ef55a86ca9cc/src/Template/Error/pdo_error.ctp
return $this->renderer->render("errors/{$statusCode}", $info);
} | php | public function format(ServerRequestInterface $request, Throwable $e): string
{
// This class doesn't show debug information, so by default we hide the php exception behind a neutral http 500 error.
if (! $e instanceof HttpException) {
$e = new \Chiron\Http\Exception\Server\InternalServerErrorHttpException();
}
$info = $e->toArray();
// TODO : ajouter plus d'information dans ce tableau qui va être passé à la vue pour pouvoir utiliser ces informations => https://github.com/cakephp/cakephp/blob/dc63c2f0d8a1e9d5f336ab81b587a54929d9e1cf/src/Error/ExceptionRenderer.php#L218
/*
Arguments à passer à la vue :
$templateData = [
'response' => $response,
'request' => $request,
'uri' => (string) $request->getUri(),
'status' => $response->getStatusCode(),
'reason' => $response->getReasonPhrase(),
'debug' => $this->debug,
];
if ($this->debug) {
$templateData['error'] = $e;
}
]*/
$info = array_merge($info, ['exception' => $e]); // TODO : vérifier qu'on accéde bien aux informations ajoutées en attribut !!!!!!!!!!!!!
$statusCode = $info['status'];
// TODO : gérer le cas des PDOException pour la BDD, avec un template spécial => https://github.com/cakephp/cakephp/blob/dc63c2f0d8a1e9d5f336ab81b587a54929d9e1cf/src/Error/ExceptionRenderer.php#L335
//https://github.com/cakephp/cakephp/blob/2341c3cd7c32e315c2d54b625313ef55a86ca9cc/src/Template/Error/pdo_error.ctp
return $this->renderer->render("errors/{$statusCode}", $info);
} | [
"public",
"function",
"format",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"Throwable",
"$",
"e",
")",
":",
"string",
"{",
"// This class doesn't show debug information, so by default we hide the php exception behind a neutral http 500 error.",
"if",
"(",
"!",
"$",
"e",
"instanceof",
"HttpException",
")",
"{",
"$",
"e",
"=",
"new",
"\\",
"Chiron",
"\\",
"Http",
"\\",
"Exception",
"\\",
"Server",
"\\",
"InternalServerErrorHttpException",
"(",
")",
";",
"}",
"$",
"info",
"=",
"$",
"e",
"->",
"toArray",
"(",
")",
";",
"// TODO : ajouter plus d'information dans ce tableau qui va être passé à la vue pour pouvoir utiliser ces informations => https://github.com/cakephp/cakephp/blob/dc63c2f0d8a1e9d5f336ab81b587a54929d9e1cf/src/Error/ExceptionRenderer.php#L218",
"/*\n Arguments à passer à la vue :\n $templateData = [\n 'response' => $response,\n 'request' => $request,\n 'uri' => (string) $request->getUri(),\n 'status' => $response->getStatusCode(),\n 'reason' => $response->getReasonPhrase(),\n 'debug' => $this->debug,\n ];\n if ($this->debug) {\n $templateData['error'] = $e;\n }\n ]*/",
"$",
"info",
"=",
"array_merge",
"(",
"$",
"info",
",",
"[",
"'exception'",
"=>",
"$",
"e",
"]",
")",
";",
"// TODO : vérifier qu'on accéde bien aux informations ajoutées en attribut !!!!!!!!!!!!!",
"$",
"statusCode",
"=",
"$",
"info",
"[",
"'status'",
"]",
";",
"// TODO : gérer le cas des PDOException pour la BDD, avec un template spécial => https://github.com/cakephp/cakephp/blob/dc63c2f0d8a1e9d5f336ab81b587a54929d9e1cf/src/Error/ExceptionRenderer.php#L335",
"//https://github.com/cakephp/cakephp/blob/2341c3cd7c32e315c2d54b625313ef55a86ca9cc/src/Template/Error/pdo_error.ctp",
"return",
"$",
"this",
"->",
"renderer",
"->",
"render",
"(",
"\"errors/{$statusCode}\"",
",",
"$",
"info",
")",
";",
"}"
] | Render JSON error.
@param \Throwable $e
@return string | [
"Render",
"JSON",
"error",
"."
] | bfb6f85faba0e54005896b09a7c34e456d1a1bed | https://github.com/ncou/Chiron/blob/bfb6f85faba0e54005896b09a7c34e456d1a1bed/src/Chiron/Handler/Formatter/ViewFormatter.php#L38-L69 |
36,307 | ncou/Chiron | src/Chiron/Handler/Formatter/ViewFormatter.php | ViewFormatter.canFormat | public function canFormat(Throwable $e): bool
{
$statusCode = $e instanceof HttpException ? $e->getStatusCode() : 500;
return $this->renderer->exists("errors/{$statusCode}");
} | php | public function canFormat(Throwable $e): bool
{
$statusCode = $e instanceof HttpException ? $e->getStatusCode() : 500;
return $this->renderer->exists("errors/{$statusCode}");
} | [
"public",
"function",
"canFormat",
"(",
"Throwable",
"$",
"e",
")",
":",
"bool",
"{",
"$",
"statusCode",
"=",
"$",
"e",
"instanceof",
"HttpException",
"?",
"$",
"e",
"->",
"getStatusCode",
"(",
")",
":",
"500",
";",
"return",
"$",
"this",
"->",
"renderer",
"->",
"exists",
"(",
"\"errors/{$statusCode}\"",
")",
";",
"}"
] | Can we format the exception?
@param \Throwable $e
@return bool | [
"Can",
"we",
"format",
"the",
"exception?"
] | bfb6f85faba0e54005896b09a7c34e456d1a1bed | https://github.com/ncou/Chiron/blob/bfb6f85faba0e54005896b09a7c34e456d1a1bed/src/Chiron/Handler/Formatter/ViewFormatter.php#L98-L103 |
36,308 | Assasz/yggdrasil | src/Yggdrasil/Utils/Service/ServiceDTOGenerator.php | ServiceDTOGenerator.generateClass | private function generateClass(): ServiceDTOGenerator
{
$this->DTOFile = (new PhpFile())
->addComment('This file is auto-generated.');
$namespace = $this->inputData['namespace'] . '\\' . $this->inputData['module'] . 'Module\\' . $this->inputData['type'];
$this->DTOClass = $this->DTOFile
->addNamespace($namespace)
->addClass($this->inputData['class'] . $this->inputData['type'])
->addComment($this->inputData['class'] . ' service ' . strtolower($this->inputData['type']) . PHP_EOL)
->addComment('@package ' . $namespace);
return $this;
} | php | private function generateClass(): ServiceDTOGenerator
{
$this->DTOFile = (new PhpFile())
->addComment('This file is auto-generated.');
$namespace = $this->inputData['namespace'] . '\\' . $this->inputData['module'] . 'Module\\' . $this->inputData['type'];
$this->DTOClass = $this->DTOFile
->addNamespace($namespace)
->addClass($this->inputData['class'] . $this->inputData['type'])
->addComment($this->inputData['class'] . ' service ' . strtolower($this->inputData['type']) . PHP_EOL)
->addComment('@package ' . $namespace);
return $this;
} | [
"private",
"function",
"generateClass",
"(",
")",
":",
"ServiceDTOGenerator",
"{",
"$",
"this",
"->",
"DTOFile",
"=",
"(",
"new",
"PhpFile",
"(",
")",
")",
"->",
"addComment",
"(",
"'This file is auto-generated.'",
")",
";",
"$",
"namespace",
"=",
"$",
"this",
"->",
"inputData",
"[",
"'namespace'",
"]",
".",
"'\\\\'",
".",
"$",
"this",
"->",
"inputData",
"[",
"'module'",
"]",
".",
"'Module\\\\'",
".",
"$",
"this",
"->",
"inputData",
"[",
"'type'",
"]",
";",
"$",
"this",
"->",
"DTOClass",
"=",
"$",
"this",
"->",
"DTOFile",
"->",
"addNamespace",
"(",
"$",
"namespace",
")",
"->",
"addClass",
"(",
"$",
"this",
"->",
"inputData",
"[",
"'class'",
"]",
".",
"$",
"this",
"->",
"inputData",
"[",
"'type'",
"]",
")",
"->",
"addComment",
"(",
"$",
"this",
"->",
"inputData",
"[",
"'class'",
"]",
".",
"' service '",
".",
"strtolower",
"(",
"$",
"this",
"->",
"inputData",
"[",
"'type'",
"]",
")",
".",
"PHP_EOL",
")",
"->",
"addComment",
"(",
"'@package '",
".",
"$",
"namespace",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Generates service DTO class
@return ServiceDTOGenerator | [
"Generates",
"service",
"DTO",
"class"
] | bee9bef7713b85799cdd3e9b23dccae33154f3b3 | https://github.com/Assasz/yggdrasil/blob/bee9bef7713b85799cdd3e9b23dccae33154f3b3/src/Yggdrasil/Utils/Service/ServiceDTOGenerator.php#L67-L81 |
36,309 | Assasz/yggdrasil | src/Yggdrasil/Utils/Service/ServiceDTOGenerator.php | ServiceDTOGenerator.generateProperties | private function generateProperties(): ServiceDTOGenerator
{
foreach ($this->inputData['properties'] as $name => $type) {
if ('datetime' === $type) {
$type = '\DateTime';
}
$this->DTOClass
->addProperty($name)
->setVisibility('private')
->addComment($this->inputData['class'] . ' ' . $name . PHP_EOL)
->addComment('@var ' . $type . ' $' . $name);
}
return $this;
} | php | private function generateProperties(): ServiceDTOGenerator
{
foreach ($this->inputData['properties'] as $name => $type) {
if ('datetime' === $type) {
$type = '\DateTime';
}
$this->DTOClass
->addProperty($name)
->setVisibility('private')
->addComment($this->inputData['class'] . ' ' . $name . PHP_EOL)
->addComment('@var ' . $type . ' $' . $name);
}
return $this;
} | [
"private",
"function",
"generateProperties",
"(",
")",
":",
"ServiceDTOGenerator",
"{",
"foreach",
"(",
"$",
"this",
"->",
"inputData",
"[",
"'properties'",
"]",
"as",
"$",
"name",
"=>",
"$",
"type",
")",
"{",
"if",
"(",
"'datetime'",
"===",
"$",
"type",
")",
"{",
"$",
"type",
"=",
"'\\DateTime'",
";",
"}",
"$",
"this",
"->",
"DTOClass",
"->",
"addProperty",
"(",
"$",
"name",
")",
"->",
"setVisibility",
"(",
"'private'",
")",
"->",
"addComment",
"(",
"$",
"this",
"->",
"inputData",
"[",
"'class'",
"]",
".",
"' '",
".",
"$",
"name",
".",
"PHP_EOL",
")",
"->",
"addComment",
"(",
"'@var '",
".",
"$",
"type",
".",
"' $'",
".",
"$",
"name",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Generates service DTO properties
@return ServiceDTOGenerator | [
"Generates",
"service",
"DTO",
"properties"
] | bee9bef7713b85799cdd3e9b23dccae33154f3b3 | https://github.com/Assasz/yggdrasil/blob/bee9bef7713b85799cdd3e9b23dccae33154f3b3/src/Yggdrasil/Utils/Service/ServiceDTOGenerator.php#L88-L103 |
36,310 | Assasz/yggdrasil | src/Yggdrasil/Utils/Service/ServiceDTOGenerator.php | ServiceDTOGenerator.generateMethods | private function generateMethods(): ServiceDTOGenerator
{
foreach ($this->inputData['properties'] as $name => $type) {
$this
->generateGetter($name, $type)
->generateSetter($name, $type);
}
return $this;
} | php | private function generateMethods(): ServiceDTOGenerator
{
foreach ($this->inputData['properties'] as $name => $type) {
$this
->generateGetter($name, $type)
->generateSetter($name, $type);
}
return $this;
} | [
"private",
"function",
"generateMethods",
"(",
")",
":",
"ServiceDTOGenerator",
"{",
"foreach",
"(",
"$",
"this",
"->",
"inputData",
"[",
"'properties'",
"]",
"as",
"$",
"name",
"=>",
"$",
"type",
")",
"{",
"$",
"this",
"->",
"generateGetter",
"(",
"$",
"name",
",",
"$",
"type",
")",
"->",
"generateSetter",
"(",
"$",
"name",
",",
"$",
"type",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Generates service DTO methods
@return ServiceDTOGenerator | [
"Generates",
"service",
"DTO",
"methods"
] | bee9bef7713b85799cdd3e9b23dccae33154f3b3 | https://github.com/Assasz/yggdrasil/blob/bee9bef7713b85799cdd3e9b23dccae33154f3b3/src/Yggdrasil/Utils/Service/ServiceDTOGenerator.php#L110-L119 |
36,311 | Assasz/yggdrasil | src/Yggdrasil/Utils/Service/ServiceDTOGenerator.php | ServiceDTOGenerator.saveFile | private function saveFile(): void
{
$sourceCode = Helpers::tabsToSpaces((string) $this->DTOFile);
$fullPath = implode('/', [
dirname(__DIR__, 7) . '/src',
$this->inputData['namespace'],
$this->inputData['module'] . 'Module',
$this->inputData['type'],
$this->inputData['class'] . $this->inputData['type'] . '.php'
]);
$dirname = dirname($fullPath);
if (!is_dir($dirname)) {
mkdir($dirname, 0755, true);
}
$handle = fopen($fullPath, 'w');
fwrite($handle, $sourceCode);
fclose($handle);
} | php | private function saveFile(): void
{
$sourceCode = Helpers::tabsToSpaces((string) $this->DTOFile);
$fullPath = implode('/', [
dirname(__DIR__, 7) . '/src',
$this->inputData['namespace'],
$this->inputData['module'] . 'Module',
$this->inputData['type'],
$this->inputData['class'] . $this->inputData['type'] . '.php'
]);
$dirname = dirname($fullPath);
if (!is_dir($dirname)) {
mkdir($dirname, 0755, true);
}
$handle = fopen($fullPath, 'w');
fwrite($handle, $sourceCode);
fclose($handle);
} | [
"private",
"function",
"saveFile",
"(",
")",
":",
"void",
"{",
"$",
"sourceCode",
"=",
"Helpers",
"::",
"tabsToSpaces",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"DTOFile",
")",
";",
"$",
"fullPath",
"=",
"implode",
"(",
"'/'",
",",
"[",
"dirname",
"(",
"__DIR__",
",",
"7",
")",
".",
"'/src'",
",",
"$",
"this",
"->",
"inputData",
"[",
"'namespace'",
"]",
",",
"$",
"this",
"->",
"inputData",
"[",
"'module'",
"]",
".",
"'Module'",
",",
"$",
"this",
"->",
"inputData",
"[",
"'type'",
"]",
",",
"$",
"this",
"->",
"inputData",
"[",
"'class'",
"]",
".",
"$",
"this",
"->",
"inputData",
"[",
"'type'",
"]",
".",
"'.php'",
"]",
")",
";",
"$",
"dirname",
"=",
"dirname",
"(",
"$",
"fullPath",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dirname",
")",
")",
"{",
"mkdir",
"(",
"$",
"dirname",
",",
"0755",
",",
"true",
")",
";",
"}",
"$",
"handle",
"=",
"fopen",
"(",
"$",
"fullPath",
",",
"'w'",
")",
";",
"fwrite",
"(",
"$",
"handle",
",",
"$",
"sourceCode",
")",
";",
"fclose",
"(",
"$",
"handle",
")",
";",
"}"
] | Saves service DTO file in given path | [
"Saves",
"service",
"DTO",
"file",
"in",
"given",
"path"
] | bee9bef7713b85799cdd3e9b23dccae33154f3b3 | https://github.com/Assasz/yggdrasil/blob/bee9bef7713b85799cdd3e9b23dccae33154f3b3/src/Yggdrasil/Utils/Service/ServiceDTOGenerator.php#L186-L207 |
36,312 | CeusMedia/Common | src/Net/API/DDNSS.php | Net_API_DDNSS.update | static public function update( $key, $hosts ){
if( is_array( $hosts ) )
$hosts = implode( ",", $hosts );
$url = sprintf( self::$urlUpdate, $key, $hosts );
try{
$reader = new Net_Reader( $url );
$reader->setUserAgent( "cURL" );
$response = strip_tags( $reader->read() );
if( !preg_match( "/Updated [0-9]+ /", $response ) )
return 0;
$number = preg_replace( "/^.+Updated ([0-9]+) host.+$/s", "\\1", $response );
return (int) $number;
}
catch( Exception $e ){
die( $e->getMessage() );
}
} | php | static public function update( $key, $hosts ){
if( is_array( $hosts ) )
$hosts = implode( ",", $hosts );
$url = sprintf( self::$urlUpdate, $key, $hosts );
try{
$reader = new Net_Reader( $url );
$reader->setUserAgent( "cURL" );
$response = strip_tags( $reader->read() );
if( !preg_match( "/Updated [0-9]+ /", $response ) )
return 0;
$number = preg_replace( "/^.+Updated ([0-9]+) host.+$/s", "\\1", $response );
return (int) $number;
}
catch( Exception $e ){
die( $e->getMessage() );
}
} | [
"static",
"public",
"function",
"update",
"(",
"$",
"key",
",",
"$",
"hosts",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"hosts",
")",
")",
"$",
"hosts",
"=",
"implode",
"(",
"\",\"",
",",
"$",
"hosts",
")",
";",
"$",
"url",
"=",
"sprintf",
"(",
"self",
"::",
"$",
"urlUpdate",
",",
"$",
"key",
",",
"$",
"hosts",
")",
";",
"try",
"{",
"$",
"reader",
"=",
"new",
"Net_Reader",
"(",
"$",
"url",
")",
";",
"$",
"reader",
"->",
"setUserAgent",
"(",
"\"cURL\"",
")",
";",
"$",
"response",
"=",
"strip_tags",
"(",
"$",
"reader",
"->",
"read",
"(",
")",
")",
";",
"if",
"(",
"!",
"preg_match",
"(",
"\"/Updated [0-9]+ /\"",
",",
"$",
"response",
")",
")",
"return",
"0",
";",
"$",
"number",
"=",
"preg_replace",
"(",
"\"/^.+Updated ([0-9]+) host.+$/s\"",
",",
"\"\\\\1\"",
",",
"$",
"response",
")",
";",
"return",
"(",
"int",
")",
"$",
"number",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"die",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Updated host or hosts.
@static
@param string $key Auth key from DDNSS
@param string|array $hosts Host or list of hosts
@return integer Number of updated hosts
@todo parse response header DDNSS-Response
@todo and handle update errors | [
"Updated",
"host",
"or",
"hosts",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/API/DDNSS.php#L55-L71 |
36,313 | CeusMedia/Common | src/XML/DOM/Formater.php | XML_DOM_Formater.format | public static function format( $xml, $leadingTabs = FALSE )
{
$validator = new XML_DOM_SyntaxValidator();
if( !$validator->validate( $xml ) )
throw new InvalidArgumentException( 'String is no valid XML' );
$document = new DOMDocument();
$document->preserveWhiteSpace = FALSE;
$document->loadXml( $xml );
$document->formatOutput = TRUE;
$xml = $document->saveXml();
if( $leadingTabs ){
$lines = explode( "\n", $xml );
foreach( $lines as $nr => $line )
while( preg_match( "/^\t* /", $lines[$nr] ) )
$lines[$nr] = preg_replace( "/^(\t*) /", "\\1\t", $lines[$nr] );
$xml = implode( "\n", $lines );
}
return $xml;
} | php | public static function format( $xml, $leadingTabs = FALSE )
{
$validator = new XML_DOM_SyntaxValidator();
if( !$validator->validate( $xml ) )
throw new InvalidArgumentException( 'String is no valid XML' );
$document = new DOMDocument();
$document->preserveWhiteSpace = FALSE;
$document->loadXml( $xml );
$document->formatOutput = TRUE;
$xml = $document->saveXml();
if( $leadingTabs ){
$lines = explode( "\n", $xml );
foreach( $lines as $nr => $line )
while( preg_match( "/^\t* /", $lines[$nr] ) )
$lines[$nr] = preg_replace( "/^(\t*) /", "\\1\t", $lines[$nr] );
$xml = implode( "\n", $lines );
}
return $xml;
} | [
"public",
"static",
"function",
"format",
"(",
"$",
"xml",
",",
"$",
"leadingTabs",
"=",
"FALSE",
")",
"{",
"$",
"validator",
"=",
"new",
"XML_DOM_SyntaxValidator",
"(",
")",
";",
"if",
"(",
"!",
"$",
"validator",
"->",
"validate",
"(",
"$",
"xml",
")",
")",
"throw",
"new",
"InvalidArgumentException",
"(",
"'String is no valid XML'",
")",
";",
"$",
"document",
"=",
"new",
"DOMDocument",
"(",
")",
";",
"$",
"document",
"->",
"preserveWhiteSpace",
"=",
"FALSE",
";",
"$",
"document",
"->",
"loadXml",
"(",
"$",
"xml",
")",
";",
"$",
"document",
"->",
"formatOutput",
"=",
"TRUE",
";",
"$",
"xml",
"=",
"$",
"document",
"->",
"saveXml",
"(",
")",
";",
"if",
"(",
"$",
"leadingTabs",
")",
"{",
"$",
"lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"xml",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"nr",
"=>",
"$",
"line",
")",
"while",
"(",
"preg_match",
"(",
"\"/^\\t* /\"",
",",
"$",
"lines",
"[",
"$",
"nr",
"]",
")",
")",
"$",
"lines",
"[",
"$",
"nr",
"]",
"=",
"preg_replace",
"(",
"\"/^(\\t*) /\"",
",",
"\"\\\\1\\t\"",
",",
"$",
"lines",
"[",
"$",
"nr",
"]",
")",
";",
"$",
"xml",
"=",
"implode",
"(",
"\"\\n\"",
",",
"$",
"lines",
")",
";",
"}",
"return",
"$",
"xml",
";",
"}"
] | Formats a XML String with Line Breaks and Indention and returns it.
@access public
@static
@param string $xml XML String to format
@param boolean $leadingTabs Flag: replace leading spaces by tabs
@return string | [
"Formats",
"a",
"XML",
"String",
"with",
"Line",
"Breaks",
"and",
"Indention",
"and",
"returns",
"it",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/DOM/Formater.php#L52-L72 |
36,314 | CeusMedia/Common | src/XML/DOM/Formater.php | XML_DOM_Formater.recode | public static function recode( $xml, $encodeTo = "UTF-8" )
{
$validator = new XML_DOM_SyntaxValidator();
if( !$validator->validate( $xml ) )
throw new InvalidArgumentException( 'String is no valid XML' );
$encodeTo = strtoupper( $encodeTo );
$document = new DOMDocument();
$document->loadXml( $xml );
$encoding = strtoupper( $document->actualEncoding );
# remark( "Encoding: ".$encoding );
if( $encoding == $encodeTo )
return $xml;
$pattern = '@<\?(.*) encoding=(\'|")'.$encoding.'(\'|")(.*)\?>@i';
$replacement = '<?\\1 encoding="'.$encodeTo.'"\\4?>';
$xml = iconv( $encoding, $encodeTo, $xml );
$xml = preg_replace( $pattern, $replacement, $xml );
return $xml;
} | php | public static function recode( $xml, $encodeTo = "UTF-8" )
{
$validator = new XML_DOM_SyntaxValidator();
if( !$validator->validate( $xml ) )
throw new InvalidArgumentException( 'String is no valid XML' );
$encodeTo = strtoupper( $encodeTo );
$document = new DOMDocument();
$document->loadXml( $xml );
$encoding = strtoupper( $document->actualEncoding );
# remark( "Encoding: ".$encoding );
if( $encoding == $encodeTo )
return $xml;
$pattern = '@<\?(.*) encoding=(\'|")'.$encoding.'(\'|")(.*)\?>@i';
$replacement = '<?\\1 encoding="'.$encodeTo.'"\\4?>';
$xml = iconv( $encoding, $encodeTo, $xml );
$xml = preg_replace( $pattern, $replacement, $xml );
return $xml;
} | [
"public",
"static",
"function",
"recode",
"(",
"$",
"xml",
",",
"$",
"encodeTo",
"=",
"\"UTF-8\"",
")",
"{",
"$",
"validator",
"=",
"new",
"XML_DOM_SyntaxValidator",
"(",
")",
";",
"if",
"(",
"!",
"$",
"validator",
"->",
"validate",
"(",
"$",
"xml",
")",
")",
"throw",
"new",
"InvalidArgumentException",
"(",
"'String is no valid XML'",
")",
";",
"$",
"encodeTo",
"=",
"strtoupper",
"(",
"$",
"encodeTo",
")",
";",
"$",
"document",
"=",
"new",
"DOMDocument",
"(",
")",
";",
"$",
"document",
"->",
"loadXml",
"(",
"$",
"xml",
")",
";",
"$",
"encoding",
"=",
"strtoupper",
"(",
"$",
"document",
"->",
"actualEncoding",
")",
";",
"#\t\tremark( \"Encoding: \".$encoding );",
"if",
"(",
"$",
"encoding",
"==",
"$",
"encodeTo",
")",
"return",
"$",
"xml",
";",
"$",
"pattern",
"=",
"'@<\\?(.*) encoding=(\\'|\")'",
".",
"$",
"encoding",
".",
"'(\\'|\")(.*)\\?>@i'",
";",
"$",
"replacement",
"=",
"'<?\\\\1 encoding=\"'",
".",
"$",
"encodeTo",
".",
"'\"\\\\4?>'",
";",
"$",
"xml",
"=",
"iconv",
"(",
"$",
"encoding",
",",
"$",
"encodeTo",
",",
"$",
"xml",
")",
";",
"$",
"xml",
"=",
"preg_replace",
"(",
"$",
"pattern",
",",
"$",
"replacement",
",",
"$",
"xml",
")",
";",
"return",
"$",
"xml",
";",
"}"
] | Recodes a XML String to another Character Set.
@access public
@static
@param string $xml XML String to format
@param string $encodeTo Character Set to encode to
@see http://www.iana.org/assignments/character-sets
@return string | [
"Recodes",
"a",
"XML",
"String",
"to",
"another",
"Character",
"Set",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/DOM/Formater.php#L83-L103 |
36,315 | CeusMedia/Common | src/UI/HTML/CountryFlagIcon.php | UI_HTML_CountryFlagIcon.build | public static function build( $languageCode, $title = NULL, $class = NULL )
{
if( !$languageCode )
throw new InvalidArgumentException( 'No country language code given' );
$languageCode = self::transformCode( $languageCode );
$url = self::$imageBaseUri.$languageCode.".".self::$imageExtension;
$code = UI_HTML_Elements::Image( $url, $title, $class );
return $code;
} | php | public static function build( $languageCode, $title = NULL, $class = NULL )
{
if( !$languageCode )
throw new InvalidArgumentException( 'No country language code given' );
$languageCode = self::transformCode( $languageCode );
$url = self::$imageBaseUri.$languageCode.".".self::$imageExtension;
$code = UI_HTML_Elements::Image( $url, $title, $class );
return $code;
} | [
"public",
"static",
"function",
"build",
"(",
"$",
"languageCode",
",",
"$",
"title",
"=",
"NULL",
",",
"$",
"class",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"$",
"languageCode",
")",
"throw",
"new",
"InvalidArgumentException",
"(",
"'No country language code given'",
")",
";",
"$",
"languageCode",
"=",
"self",
"::",
"transformCode",
"(",
"$",
"languageCode",
")",
";",
"$",
"url",
"=",
"self",
"::",
"$",
"imageBaseUri",
".",
"$",
"languageCode",
".",
"\".\"",
".",
"self",
"::",
"$",
"imageExtension",
";",
"$",
"code",
"=",
"UI_HTML_Elements",
"::",
"Image",
"(",
"$",
"url",
",",
"$",
"title",
",",
"$",
"class",
")",
";",
"return",
"$",
"code",
";",
"}"
] | Builds HTML Code of Country Flag Icon statically.
@access public
@param string $languageCode Language Code or ISO Code of Country
@param string $title Title and alternative Text of Image (needed for valid XHTML)
@param string $class CSS Class
@return string HTML Code of Country Flag Icon | [
"Builds",
"HTML",
"Code",
"of",
"Country",
"Flag",
"Icon",
"statically",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/CountryFlagIcon.php#L62-L70 |
36,316 | CeusMedia/Common | src/UI/HTML/CountryFlagIcon.php | UI_HTML_CountryFlagIcon.transformCode | protected static function transformCode( $languageCode )
{
$isoCode = $languageCode;
if( $languageCode == "en" || $languageCode == "uk" )
$isoCode = "gb";
if( $languageCode == "cs" )
$isoCode = "cz";
return $isoCode;
} | php | protected static function transformCode( $languageCode )
{
$isoCode = $languageCode;
if( $languageCode == "en" || $languageCode == "uk" )
$isoCode = "gb";
if( $languageCode == "cs" )
$isoCode = "cz";
return $isoCode;
} | [
"protected",
"static",
"function",
"transformCode",
"(",
"$",
"languageCode",
")",
"{",
"$",
"isoCode",
"=",
"$",
"languageCode",
";",
"if",
"(",
"$",
"languageCode",
"==",
"\"en\"",
"||",
"$",
"languageCode",
"==",
"\"uk\"",
")",
"$",
"isoCode",
"=",
"\"gb\"",
";",
"if",
"(",
"$",
"languageCode",
"==",
"\"cs\"",
")",
"$",
"isoCode",
"=",
"\"cz\"",
";",
"return",
"$",
"isoCode",
";",
"}"
] | Transforms special Language Codes to ISO Codes. To be overwritten.
@access protected
@param string $languageCode Language Code
@return string | [
"Transforms",
"special",
"Language",
"Codes",
"to",
"ISO",
"Codes",
".",
"To",
"be",
"overwritten",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/CountryFlagIcon.php#L78-L86 |
36,317 | meritoo/common-library | src/Utilities/Xml.php | Xml.mergeNodes | public static function mergeNodes(SimpleXMLElement $element1, SimpleXMLElement $element2)
{
$document1 = new DOMDocument();
$document2 = new DOMDocument();
$document1->loadXML($element1->asXML());
$document2->loadXML($element2->asXML());
$path = new DOMXPath($document2);
$query = $path->query('/*/*');
$nodesCount = $query->length;
if (0 === $nodesCount) {
return $element1;
}
for ($i = 0; $i < $nodesCount; ++$i) {
$node = $document1->importNode($query->item($i), true);
$document1->documentElement->appendChild($node);
}
return simplexml_import_dom($document1);
} | php | public static function mergeNodes(SimpleXMLElement $element1, SimpleXMLElement $element2)
{
$document1 = new DOMDocument();
$document2 = new DOMDocument();
$document1->loadXML($element1->asXML());
$document2->loadXML($element2->asXML());
$path = new DOMXPath($document2);
$query = $path->query('/*/*');
$nodesCount = $query->length;
if (0 === $nodesCount) {
return $element1;
}
for ($i = 0; $i < $nodesCount; ++$i) {
$node = $document1->importNode($query->item($i), true);
$document1->documentElement->appendChild($node);
}
return simplexml_import_dom($document1);
} | [
"public",
"static",
"function",
"mergeNodes",
"(",
"SimpleXMLElement",
"$",
"element1",
",",
"SimpleXMLElement",
"$",
"element2",
")",
"{",
"$",
"document1",
"=",
"new",
"DOMDocument",
"(",
")",
";",
"$",
"document2",
"=",
"new",
"DOMDocument",
"(",
")",
";",
"$",
"document1",
"->",
"loadXML",
"(",
"$",
"element1",
"->",
"asXML",
"(",
")",
")",
";",
"$",
"document2",
"->",
"loadXML",
"(",
"$",
"element2",
"->",
"asXML",
"(",
")",
")",
";",
"$",
"path",
"=",
"new",
"DOMXPath",
"(",
"$",
"document2",
")",
";",
"$",
"query",
"=",
"$",
"path",
"->",
"query",
"(",
"'/*/*'",
")",
";",
"$",
"nodesCount",
"=",
"$",
"query",
"->",
"length",
";",
"if",
"(",
"0",
"===",
"$",
"nodesCount",
")",
"{",
"return",
"$",
"element1",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"nodesCount",
";",
"++",
"$",
"i",
")",
"{",
"$",
"node",
"=",
"$",
"document1",
"->",
"importNode",
"(",
"$",
"query",
"->",
"item",
"(",
"$",
"i",
")",
",",
"true",
")",
";",
"$",
"document1",
"->",
"documentElement",
"->",
"appendChild",
"(",
"$",
"node",
")",
";",
"}",
"return",
"simplexml_import_dom",
"(",
"$",
"document1",
")",
";",
"}"
] | Merges nodes of given elements.
Returns merged instance of SimpleXMLElement.
@param SimpleXMLElement $element1 First element to merge
@param SimpleXMLElement $element2 Second element to merge
@return SimpleXMLElement | [
"Merges",
"nodes",
"of",
"given",
"elements",
".",
"Returns",
"merged",
"instance",
"of",
"SimpleXMLElement",
"."
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Xml.php#L31-L53 |
36,318 | CeusMedia/Common | src/Alg/SgmlTagReader.php | Alg_SgmlTagReader.getNodeName | public static function getNodeName( $string, $transform = 0 )
{
$data = self::getTagData( $string );
switch( $transform )
{
case self::TRANSFORM_LOWERCASE: return strtolower( $data['nodename'] );
case self::TRANSFORM_UPPERCASE: return strtoupper( $data['nodename'] );
default: return $data['nodename'];
}
} | php | public static function getNodeName( $string, $transform = 0 )
{
$data = self::getTagData( $string );
switch( $transform )
{
case self::TRANSFORM_LOWERCASE: return strtolower( $data['nodename'] );
case self::TRANSFORM_UPPERCASE: return strtoupper( $data['nodename'] );
default: return $data['nodename'];
}
} | [
"public",
"static",
"function",
"getNodeName",
"(",
"$",
"string",
",",
"$",
"transform",
"=",
"0",
")",
"{",
"$",
"data",
"=",
"self",
"::",
"getTagData",
"(",
"$",
"string",
")",
";",
"switch",
"(",
"$",
"transform",
")",
"{",
"case",
"self",
"::",
"TRANSFORM_LOWERCASE",
":",
"return",
"strtolower",
"(",
"$",
"data",
"[",
"'nodename'",
"]",
")",
";",
"case",
"self",
"::",
"TRANSFORM_UPPERCASE",
":",
"return",
"strtoupper",
"(",
"$",
"data",
"[",
"'nodename'",
"]",
")",
";",
"default",
":",
"return",
"$",
"data",
"[",
"'nodename'",
"]",
";",
"}",
"}"
] | Returns Node Name from Tag.
@access public
@static
@param string $string String containing exactly 1 SGML based Tag
@return string | [
"Returns",
"Node",
"Name",
"from",
"Tag",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/SgmlTagReader.php#L78-L87 |
36,319 | CeusMedia/Common | src/Alg/SgmlTagReader.php | Alg_SgmlTagReader.getTagData | public static function getTagData( $string, $transformKeys = 0 )
{
$string = trim( $string );
$attributes = array();
$content = "";
$nodename = "";
if( preg_match( "@^<([a-z]+)@", $string, $results ) )
$nodename = $results[1];
if( preg_match( "@>([^<]*)<@", $string, $results ) )
$content = $results[1];
if( preg_match_all( '@ (\S+)="([^"]+)"@', $string, $results ) )
{
$array = array_combine( $results[1], $results[2] );
foreach( $array as $key => $value )
{
if( $transformKeys == self::TRANSFORM_LOWERCASE )
$key = strtolower( $key );
else if( $transformKeys == self::TRANSFORM_UPPERCASE )
$key = strtoupper( $key );
$attributes[$key] = $value;
}
}
if( preg_match_all( "@ (\S+)='([^']+)'@", $string, $results ) )
{
$array = array_combine( $results[1], $results[2] );
foreach( $array as $key => $value )
{
if( $transformKeys == self::TRANSFORM_LOWERCASE )
$key = strtolower( $key );
else if( $transformKeys == self::TRANSFORM_UPPERCASE )
$key = strtoupper( $key );
$attributes[$key] = $value;
}
}
return array(
'nodename' => $nodename,
'content' => $content,
'attributes' => $attributes
);
} | php | public static function getTagData( $string, $transformKeys = 0 )
{
$string = trim( $string );
$attributes = array();
$content = "";
$nodename = "";
if( preg_match( "@^<([a-z]+)@", $string, $results ) )
$nodename = $results[1];
if( preg_match( "@>([^<]*)<@", $string, $results ) )
$content = $results[1];
if( preg_match_all( '@ (\S+)="([^"]+)"@', $string, $results ) )
{
$array = array_combine( $results[1], $results[2] );
foreach( $array as $key => $value )
{
if( $transformKeys == self::TRANSFORM_LOWERCASE )
$key = strtolower( $key );
else if( $transformKeys == self::TRANSFORM_UPPERCASE )
$key = strtoupper( $key );
$attributes[$key] = $value;
}
}
if( preg_match_all( "@ (\S+)='([^']+)'@", $string, $results ) )
{
$array = array_combine( $results[1], $results[2] );
foreach( $array as $key => $value )
{
if( $transformKeys == self::TRANSFORM_LOWERCASE )
$key = strtolower( $key );
else if( $transformKeys == self::TRANSFORM_UPPERCASE )
$key = strtoupper( $key );
$attributes[$key] = $value;
}
}
return array(
'nodename' => $nodename,
'content' => $content,
'attributes' => $attributes
);
} | [
"public",
"static",
"function",
"getTagData",
"(",
"$",
"string",
",",
"$",
"transformKeys",
"=",
"0",
")",
"{",
"$",
"string",
"=",
"trim",
"(",
"$",
"string",
")",
";",
"$",
"attributes",
"=",
"array",
"(",
")",
";",
"$",
"content",
"=",
"\"\"",
";",
"$",
"nodename",
"=",
"\"\"",
";",
"if",
"(",
"preg_match",
"(",
"\"@^<([a-z]+)@\"",
",",
"$",
"string",
",",
"$",
"results",
")",
")",
"$",
"nodename",
"=",
"$",
"results",
"[",
"1",
"]",
";",
"if",
"(",
"preg_match",
"(",
"\"@>([^<]*)<@\"",
",",
"$",
"string",
",",
"$",
"results",
")",
")",
"$",
"content",
"=",
"$",
"results",
"[",
"1",
"]",
";",
"if",
"(",
"preg_match_all",
"(",
"'@ (\\S+)=\"([^\"]+)\"@'",
",",
"$",
"string",
",",
"$",
"results",
")",
")",
"{",
"$",
"array",
"=",
"array_combine",
"(",
"$",
"results",
"[",
"1",
"]",
",",
"$",
"results",
"[",
"2",
"]",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"transformKeys",
"==",
"self",
"::",
"TRANSFORM_LOWERCASE",
")",
"$",
"key",
"=",
"strtolower",
"(",
"$",
"key",
")",
";",
"else",
"if",
"(",
"$",
"transformKeys",
"==",
"self",
"::",
"TRANSFORM_UPPERCASE",
")",
"$",
"key",
"=",
"strtoupper",
"(",
"$",
"key",
")",
";",
"$",
"attributes",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"if",
"(",
"preg_match_all",
"(",
"\"@ (\\S+)='([^']+)'@\"",
",",
"$",
"string",
",",
"$",
"results",
")",
")",
"{",
"$",
"array",
"=",
"array_combine",
"(",
"$",
"results",
"[",
"1",
"]",
",",
"$",
"results",
"[",
"2",
"]",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"transformKeys",
"==",
"self",
"::",
"TRANSFORM_LOWERCASE",
")",
"$",
"key",
"=",
"strtolower",
"(",
"$",
"key",
")",
";",
"else",
"if",
"(",
"$",
"transformKeys",
"==",
"self",
"::",
"TRANSFORM_UPPERCASE",
")",
"$",
"key",
"=",
"strtoupper",
"(",
"$",
"key",
")",
";",
"$",
"attributes",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"array",
"(",
"'nodename'",
"=>",
"$",
"nodename",
",",
"'content'",
"=>",
"$",
"content",
",",
"'attributes'",
"=>",
"$",
"attributes",
")",
";",
"}"
] | Returns all Information from a Tag.
@access public
@static
@param string $string String containing exactly 1 SGML based Tag
@return array | [
"Returns",
"all",
"Information",
"from",
"a",
"Tag",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/SgmlTagReader.php#L96-L136 |
36,320 | CeusMedia/Common | src/UI/HTML/EventMonthCalendar.php | UI_HTML_EventMonthCalendar.modifyDay | protected function modifyDay( $day )
{
$classes = array();
if( (int)$this->getOption( 'show_day' ) == $day )
$classes[] = 'shown';
if( in_array( $day, $this->events ) )
{
$url = $this->getOption( 'url' );
$url .= "&".$this->getOption( 'carrier_year' )."=".$this->getOption( 'show_year' );
$url .= "&".$this->getOption( 'carrier_month' )."=".$this->getOption( 'show_month' );
$url .= "&".$this->getOption( 'carrier_day' )."=".$day;
$day = $this->html->Link( $url, $day );
$classes[] = 'event';
}
$class = implode( ' ', $classes );
return $data = array( 'day' => $day, 'class' => $class );
} | php | protected function modifyDay( $day )
{
$classes = array();
if( (int)$this->getOption( 'show_day' ) == $day )
$classes[] = 'shown';
if( in_array( $day, $this->events ) )
{
$url = $this->getOption( 'url' );
$url .= "&".$this->getOption( 'carrier_year' )."=".$this->getOption( 'show_year' );
$url .= "&".$this->getOption( 'carrier_month' )."=".$this->getOption( 'show_month' );
$url .= "&".$this->getOption( 'carrier_day' )."=".$day;
$day = $this->html->Link( $url, $day );
$classes[] = 'event';
}
$class = implode( ' ', $classes );
return $data = array( 'day' => $day, 'class' => $class );
} | [
"protected",
"function",
"modifyDay",
"(",
"$",
"day",
")",
"{",
"$",
"classes",
"=",
"array",
"(",
")",
";",
"if",
"(",
"(",
"int",
")",
"$",
"this",
"->",
"getOption",
"(",
"'show_day'",
")",
"==",
"$",
"day",
")",
"$",
"classes",
"[",
"]",
"=",
"'shown'",
";",
"if",
"(",
"in_array",
"(",
"$",
"day",
",",
"$",
"this",
"->",
"events",
")",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"getOption",
"(",
"'url'",
")",
";",
"$",
"url",
".=",
"\"&\"",
".",
"$",
"this",
"->",
"getOption",
"(",
"'carrier_year'",
")",
".",
"\"=\"",
".",
"$",
"this",
"->",
"getOption",
"(",
"'show_year'",
")",
";",
"$",
"url",
".=",
"\"&\"",
".",
"$",
"this",
"->",
"getOption",
"(",
"'carrier_month'",
")",
".",
"\"=\"",
".",
"$",
"this",
"->",
"getOption",
"(",
"'show_month'",
")",
";",
"$",
"url",
".=",
"\"&\"",
".",
"$",
"this",
"->",
"getOption",
"(",
"'carrier_day'",
")",
".",
"\"=\"",
".",
"$",
"day",
";",
"$",
"day",
"=",
"$",
"this",
"->",
"html",
"->",
"Link",
"(",
"$",
"url",
",",
"$",
"day",
")",
";",
"$",
"classes",
"[",
"]",
"=",
"'event'",
";",
"}",
"$",
"class",
"=",
"implode",
"(",
"' '",
",",
"$",
"classes",
")",
";",
"return",
"$",
"data",
"=",
"array",
"(",
"'day'",
"=>",
"$",
"day",
",",
"'class'",
"=>",
"$",
"class",
")",
";",
"}"
] | Modification of Cell Content of Days - to be overwritten.
@access protected
@param string $day Number of Day to modify
@return string | [
"Modification",
"of",
"Cell",
"Content",
"of",
"Days",
"-",
"to",
"be",
"overwritten",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/EventMonthCalendar.php#L65-L81 |
36,321 | CeusMedia/Common | src/FS/File/Configuration/Converter.php | FS_File_Configuration_Converter.convertIniToJson | public static function convertIniToJson( $sourceFile, $targetFile )
{
$data = self::loadIni( $sourceFile );
return self::saveJson( $targetFile, $data );
} | php | public static function convertIniToJson( $sourceFile, $targetFile )
{
$data = self::loadIni( $sourceFile );
return self::saveJson( $targetFile, $data );
} | [
"public",
"static",
"function",
"convertIniToJson",
"(",
"$",
"sourceFile",
",",
"$",
"targetFile",
")",
"{",
"$",
"data",
"=",
"self",
"::",
"loadIni",
"(",
"$",
"sourceFile",
")",
";",
"return",
"self",
"::",
"saveJson",
"(",
"$",
"targetFile",
",",
"$",
"data",
")",
";",
"}"
] | Converts Configuration File from INI to JSON and returns Length of Target File.
@access public
@static
@param string $sourceFile File Name of Source File
@param string $targetFile File Name of Target File
@return int | [
"Converts",
"Configuration",
"File",
"from",
"INI",
"to",
"JSON",
"and",
"returns",
"Length",
"of",
"Target",
"File",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Configuration/Converter.php#L63-L67 |
36,322 | CeusMedia/Common | src/FS/File/Configuration/Converter.php | FS_File_Configuration_Converter.convertIniToXml | public static function convertIniToXml( $sourceFile, $targetFile )
{
$data = self::loadIni( $sourceFile );
return self::saveXml( $targetFile, $data );
} | php | public static function convertIniToXml( $sourceFile, $targetFile )
{
$data = self::loadIni( $sourceFile );
return self::saveXml( $targetFile, $data );
} | [
"public",
"static",
"function",
"convertIniToXml",
"(",
"$",
"sourceFile",
",",
"$",
"targetFile",
")",
"{",
"$",
"data",
"=",
"self",
"::",
"loadIni",
"(",
"$",
"sourceFile",
")",
";",
"return",
"self",
"::",
"saveXml",
"(",
"$",
"targetFile",
",",
"$",
"data",
")",
";",
"}"
] | Converts Configuration File from INI to XML and returns Length of Target File.
@access public
@static
@param string $sourceFile File Name of Source File
@param string $targetFile File Name of Target File
@return int | [
"Converts",
"Configuration",
"File",
"from",
"INI",
"to",
"XML",
"and",
"returns",
"Length",
"of",
"Target",
"File",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Configuration/Converter.php#L77-L81 |
36,323 | CeusMedia/Common | src/FS/File/Configuration/Converter.php | FS_File_Configuration_Converter.convertJsonToIni | public static function convertJsonToIni( $sourceFile, $targetFile )
{
$data = self::loadJson( $sourceFile );
return self::saveIni( $targetFile, $data );
} | php | public static function convertJsonToIni( $sourceFile, $targetFile )
{
$data = self::loadJson( $sourceFile );
return self::saveIni( $targetFile, $data );
} | [
"public",
"static",
"function",
"convertJsonToIni",
"(",
"$",
"sourceFile",
",",
"$",
"targetFile",
")",
"{",
"$",
"data",
"=",
"self",
"::",
"loadJson",
"(",
"$",
"sourceFile",
")",
";",
"return",
"self",
"::",
"saveIni",
"(",
"$",
"targetFile",
",",
"$",
"data",
")",
";",
"}"
] | Converts Configuration File from JSON to INI and returns Length of Target File.
@access public
@static
@param string $sourceFile File Name of Source File
@param string $targetFile File Name of Target File
@return int | [
"Converts",
"Configuration",
"File",
"from",
"JSON",
"to",
"INI",
"and",
"returns",
"Length",
"of",
"Target",
"File",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Configuration/Converter.php#L91-L95 |
36,324 | CeusMedia/Common | src/FS/File/Configuration/Converter.php | FS_File_Configuration_Converter.convertJsonToXml | public static function convertJsonToXml( $sourceFile, $targetFile )
{
$data = self::loadJson( $sourceFile );
return self::saveXml( $targetFile, $data );
} | php | public static function convertJsonToXml( $sourceFile, $targetFile )
{
$data = self::loadJson( $sourceFile );
return self::saveXml( $targetFile, $data );
} | [
"public",
"static",
"function",
"convertJsonToXml",
"(",
"$",
"sourceFile",
",",
"$",
"targetFile",
")",
"{",
"$",
"data",
"=",
"self",
"::",
"loadJson",
"(",
"$",
"sourceFile",
")",
";",
"return",
"self",
"::",
"saveXml",
"(",
"$",
"targetFile",
",",
"$",
"data",
")",
";",
"}"
] | Converts Configuration File from JSON to XML and returns Length of Target File.
@access public
@static
@param string $sourceFile File Name of Source File
@param string $targetFile File Name of Target File
@return int | [
"Converts",
"Configuration",
"File",
"from",
"JSON",
"to",
"XML",
"and",
"returns",
"Length",
"of",
"Target",
"File",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Configuration/Converter.php#L105-L109 |
36,325 | CeusMedia/Common | src/FS/File/Configuration/Converter.php | FS_File_Configuration_Converter.convertXmlToIni | public static function convertXmlToIni( $sourceFile, $targetFile )
{
$data = self::loadXml( $sourceFile );
return self::saveIni( $targetFile, $data );
} | php | public static function convertXmlToIni( $sourceFile, $targetFile )
{
$data = self::loadXml( $sourceFile );
return self::saveIni( $targetFile, $data );
} | [
"public",
"static",
"function",
"convertXmlToIni",
"(",
"$",
"sourceFile",
",",
"$",
"targetFile",
")",
"{",
"$",
"data",
"=",
"self",
"::",
"loadXml",
"(",
"$",
"sourceFile",
")",
";",
"return",
"self",
"::",
"saveIni",
"(",
"$",
"targetFile",
",",
"$",
"data",
")",
";",
"}"
] | Converts Configuration File from XML to INI and returns Length of Target File.
@access public
@static
@param string $sourceFile File Name of Source File
@param string $targetFile File Name of Target File
@return int | [
"Converts",
"Configuration",
"File",
"from",
"XML",
"to",
"INI",
"and",
"returns",
"Length",
"of",
"Target",
"File",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Configuration/Converter.php#L119-L123 |
36,326 | CeusMedia/Common | src/FS/File/Configuration/Converter.php | FS_File_Configuration_Converter.convertXmlToJson | public static function convertXmlToJson( $sourceFile, $targetFile )
{
$data = self::loadXml( $sourceFile );
return self::saveJson( $targetFile, $data );
} | php | public static function convertXmlToJson( $sourceFile, $targetFile )
{
$data = self::loadXml( $sourceFile );
return self::saveJson( $targetFile, $data );
} | [
"public",
"static",
"function",
"convertXmlToJson",
"(",
"$",
"sourceFile",
",",
"$",
"targetFile",
")",
"{",
"$",
"data",
"=",
"self",
"::",
"loadXml",
"(",
"$",
"sourceFile",
")",
";",
"return",
"self",
"::",
"saveJson",
"(",
"$",
"targetFile",
",",
"$",
"data",
")",
";",
"}"
] | Converts Configuration File from XML to JSON and returns Length of Target File.
@access public
@static
@param string $sourceFile File Name of Source File
@param string $targetFile File Name of Target File
@return int | [
"Converts",
"Configuration",
"File",
"from",
"XML",
"to",
"JSON",
"and",
"returns",
"Length",
"of",
"Target",
"File",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Configuration/Converter.php#L133-L137 |
36,327 | CeusMedia/Common | src/FS/File/Configuration/Converter.php | FS_File_Configuration_Converter.loadIni | protected static function loadIni( $fileName )
{
$reader = new FS_File_INI_Reader( $fileName, TRUE );
$ini = $reader->getCommentedProperties();
foreach( $ini as $sectionName => $sectionData )
{
foreach( $sectionData as $pair )
{
$item = array(
'key' => $pair['key'],
'value' => $pair['value'],
'type' => "string",
);
if( isset( $pair['comment'] ) )
{
$matches = array();
if( preg_match_all( self::$iniTypePattern, $pair['comment'], $matches ) )
{
$item['type'] = $matches[1][0];
if( $matches[2][0] )
$item['comment'] = $matches[2][0];
settype( $item['value'], $item['type'] );
}
else
$item['comment'] = $pair['comment'];
}
$data[$sectionName][] = $item;
}
}
return $data;
} | php | protected static function loadIni( $fileName )
{
$reader = new FS_File_INI_Reader( $fileName, TRUE );
$ini = $reader->getCommentedProperties();
foreach( $ini as $sectionName => $sectionData )
{
foreach( $sectionData as $pair )
{
$item = array(
'key' => $pair['key'],
'value' => $pair['value'],
'type' => "string",
);
if( isset( $pair['comment'] ) )
{
$matches = array();
if( preg_match_all( self::$iniTypePattern, $pair['comment'], $matches ) )
{
$item['type'] = $matches[1][0];
if( $matches[2][0] )
$item['comment'] = $matches[2][0];
settype( $item['value'], $item['type'] );
}
else
$item['comment'] = $pair['comment'];
}
$data[$sectionName][] = $item;
}
}
return $data;
} | [
"protected",
"static",
"function",
"loadIni",
"(",
"$",
"fileName",
")",
"{",
"$",
"reader",
"=",
"new",
"FS_File_INI_Reader",
"(",
"$",
"fileName",
",",
"TRUE",
")",
";",
"$",
"ini",
"=",
"$",
"reader",
"->",
"getCommentedProperties",
"(",
")",
";",
"foreach",
"(",
"$",
"ini",
"as",
"$",
"sectionName",
"=>",
"$",
"sectionData",
")",
"{",
"foreach",
"(",
"$",
"sectionData",
"as",
"$",
"pair",
")",
"{",
"$",
"item",
"=",
"array",
"(",
"'key'",
"=>",
"$",
"pair",
"[",
"'key'",
"]",
",",
"'value'",
"=>",
"$",
"pair",
"[",
"'value'",
"]",
",",
"'type'",
"=>",
"\"string\"",
",",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"pair",
"[",
"'comment'",
"]",
")",
")",
"{",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"if",
"(",
"preg_match_all",
"(",
"self",
"::",
"$",
"iniTypePattern",
",",
"$",
"pair",
"[",
"'comment'",
"]",
",",
"$",
"matches",
")",
")",
"{",
"$",
"item",
"[",
"'type'",
"]",
"=",
"$",
"matches",
"[",
"1",
"]",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"matches",
"[",
"2",
"]",
"[",
"0",
"]",
")",
"$",
"item",
"[",
"'comment'",
"]",
"=",
"$",
"matches",
"[",
"2",
"]",
"[",
"0",
"]",
";",
"settype",
"(",
"$",
"item",
"[",
"'value'",
"]",
",",
"$",
"item",
"[",
"'type'",
"]",
")",
";",
"}",
"else",
"$",
"item",
"[",
"'comment'",
"]",
"=",
"$",
"pair",
"[",
"'comment'",
"]",
";",
"}",
"$",
"data",
"[",
"$",
"sectionName",
"]",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Loads Configuration Data from INI File.
@access protected
@static
@param string $fileName File Name of INI File.
@return array | [
"Loads",
"Configuration",
"Data",
"from",
"INI",
"File",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Configuration/Converter.php#L146-L176 |
36,328 | CeusMedia/Common | src/FS/File/Configuration/Converter.php | FS_File_Configuration_Converter.loadJson | protected static function loadJson( $fileName )
{
$json = FS_File_Reader::load( $fileName );
$json = ADT_JSON_Converter::convertToArray( $json );
foreach( $json as $sectionName => $sectionData )
{
foreach( $sectionData as $pairKey => $pairData )
{
$pairData = array_merge( array( 'key' => $pairKey ), $pairData );
$data[$sectionName][] = $pairData;
}
}
return $data;
} | php | protected static function loadJson( $fileName )
{
$json = FS_File_Reader::load( $fileName );
$json = ADT_JSON_Converter::convertToArray( $json );
foreach( $json as $sectionName => $sectionData )
{
foreach( $sectionData as $pairKey => $pairData )
{
$pairData = array_merge( array( 'key' => $pairKey ), $pairData );
$data[$sectionName][] = $pairData;
}
}
return $data;
} | [
"protected",
"static",
"function",
"loadJson",
"(",
"$",
"fileName",
")",
"{",
"$",
"json",
"=",
"FS_File_Reader",
"::",
"load",
"(",
"$",
"fileName",
")",
";",
"$",
"json",
"=",
"ADT_JSON_Converter",
"::",
"convertToArray",
"(",
"$",
"json",
")",
";",
"foreach",
"(",
"$",
"json",
"as",
"$",
"sectionName",
"=>",
"$",
"sectionData",
")",
"{",
"foreach",
"(",
"$",
"sectionData",
"as",
"$",
"pairKey",
"=>",
"$",
"pairData",
")",
"{",
"$",
"pairData",
"=",
"array_merge",
"(",
"array",
"(",
"'key'",
"=>",
"$",
"pairKey",
")",
",",
"$",
"pairData",
")",
";",
"$",
"data",
"[",
"$",
"sectionName",
"]",
"[",
"]",
"=",
"$",
"pairData",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Loads Configuration Data from JSON File.
@access protected
@static
@param string $fileName File Name of JSON File.
@return array | [
"Loads",
"Configuration",
"Data",
"from",
"JSON",
"File",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Configuration/Converter.php#L185-L198 |
36,329 | CeusMedia/Common | src/FS/File/Configuration/Converter.php | FS_File_Configuration_Converter.loadXml | protected static function loadXml( $fileName )
{
$xml = XML_ElementReader::readFile( $fileName );
foreach( $xml as $sectionNode )
{
$sectionName = $sectionNode->getAttribute( 'name' );
foreach( $sectionNode as $valueNode )
{
$item = array(
'key' => $valueNode->getAttribute( 'name' ),
'value' => (string) $valueNode,
'type' => $valueNode->getAttribute( 'type' ),
);
if( $valueNode->hasAttribute( 'comment' ) )
$item['comment'] = $valueNode->getAttribute( 'comment' );
settype( $item['value'], $item['type'] );
$data[$sectionName][] = $item;
}
}
return $data;
} | php | protected static function loadXml( $fileName )
{
$xml = XML_ElementReader::readFile( $fileName );
foreach( $xml as $sectionNode )
{
$sectionName = $sectionNode->getAttribute( 'name' );
foreach( $sectionNode as $valueNode )
{
$item = array(
'key' => $valueNode->getAttribute( 'name' ),
'value' => (string) $valueNode,
'type' => $valueNode->getAttribute( 'type' ),
);
if( $valueNode->hasAttribute( 'comment' ) )
$item['comment'] = $valueNode->getAttribute( 'comment' );
settype( $item['value'], $item['type'] );
$data[$sectionName][] = $item;
}
}
return $data;
} | [
"protected",
"static",
"function",
"loadXml",
"(",
"$",
"fileName",
")",
"{",
"$",
"xml",
"=",
"XML_ElementReader",
"::",
"readFile",
"(",
"$",
"fileName",
")",
";",
"foreach",
"(",
"$",
"xml",
"as",
"$",
"sectionNode",
")",
"{",
"$",
"sectionName",
"=",
"$",
"sectionNode",
"->",
"getAttribute",
"(",
"'name'",
")",
";",
"foreach",
"(",
"$",
"sectionNode",
"as",
"$",
"valueNode",
")",
"{",
"$",
"item",
"=",
"array",
"(",
"'key'",
"=>",
"$",
"valueNode",
"->",
"getAttribute",
"(",
"'name'",
")",
",",
"'value'",
"=>",
"(",
"string",
")",
"$",
"valueNode",
",",
"'type'",
"=>",
"$",
"valueNode",
"->",
"getAttribute",
"(",
"'type'",
")",
",",
")",
";",
"if",
"(",
"$",
"valueNode",
"->",
"hasAttribute",
"(",
"'comment'",
")",
")",
"$",
"item",
"[",
"'comment'",
"]",
"=",
"$",
"valueNode",
"->",
"getAttribute",
"(",
"'comment'",
")",
";",
"settype",
"(",
"$",
"item",
"[",
"'value'",
"]",
",",
"$",
"item",
"[",
"'type'",
"]",
")",
";",
"$",
"data",
"[",
"$",
"sectionName",
"]",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Loads Configuration Data from XML File.
@access protected
@static
@param string $fileName File Name of XML File.
@return array | [
"Loads",
"Configuration",
"Data",
"from",
"XML",
"File",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Configuration/Converter.php#L207-L228 |
36,330 | CeusMedia/Common | src/FS/File/Configuration/Converter.php | FS_File_Configuration_Converter.saveIni | protected static function saveIni( $fileName, $data )
{
$creator = new FS_File_INI_Creator( TRUE );
foreach( $data as $sectionName => $sectionData )
{
$creator->addSection( $sectionName );
foreach( $sectionData as $pair )
{
switch( $pair['type'] )
{
case 'string':
$pair['value'] = '"'.addslashes( $pair['value'] ).'"';
break;
case 'bool':
case 'boolean':
$pair['value'] = $pair['value'] ? "yes" : "no";
break;
}
$pair['comment'] = isset( $pair['comment'] ) ? $pair['type'].": ".$pair['comment'] : $pair['type'];
$creator->addProperty( $pair['key'], $pair['value'], $pair['comment'] );
}
}
return $creator->write( $fileName );
} | php | protected static function saveIni( $fileName, $data )
{
$creator = new FS_File_INI_Creator( TRUE );
foreach( $data as $sectionName => $sectionData )
{
$creator->addSection( $sectionName );
foreach( $sectionData as $pair )
{
switch( $pair['type'] )
{
case 'string':
$pair['value'] = '"'.addslashes( $pair['value'] ).'"';
break;
case 'bool':
case 'boolean':
$pair['value'] = $pair['value'] ? "yes" : "no";
break;
}
$pair['comment'] = isset( $pair['comment'] ) ? $pair['type'].": ".$pair['comment'] : $pair['type'];
$creator->addProperty( $pair['key'], $pair['value'], $pair['comment'] );
}
}
return $creator->write( $fileName );
} | [
"protected",
"static",
"function",
"saveIni",
"(",
"$",
"fileName",
",",
"$",
"data",
")",
"{",
"$",
"creator",
"=",
"new",
"FS_File_INI_Creator",
"(",
"TRUE",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"sectionName",
"=>",
"$",
"sectionData",
")",
"{",
"$",
"creator",
"->",
"addSection",
"(",
"$",
"sectionName",
")",
";",
"foreach",
"(",
"$",
"sectionData",
"as",
"$",
"pair",
")",
"{",
"switch",
"(",
"$",
"pair",
"[",
"'type'",
"]",
")",
"{",
"case",
"'string'",
":",
"$",
"pair",
"[",
"'value'",
"]",
"=",
"'\"'",
".",
"addslashes",
"(",
"$",
"pair",
"[",
"'value'",
"]",
")",
".",
"'\"'",
";",
"break",
";",
"case",
"'bool'",
":",
"case",
"'boolean'",
":",
"$",
"pair",
"[",
"'value'",
"]",
"=",
"$",
"pair",
"[",
"'value'",
"]",
"?",
"\"yes\"",
":",
"\"no\"",
";",
"break",
";",
"}",
"$",
"pair",
"[",
"'comment'",
"]",
"=",
"isset",
"(",
"$",
"pair",
"[",
"'comment'",
"]",
")",
"?",
"$",
"pair",
"[",
"'type'",
"]",
".",
"\": \"",
".",
"$",
"pair",
"[",
"'comment'",
"]",
":",
"$",
"pair",
"[",
"'type'",
"]",
";",
"$",
"creator",
"->",
"addProperty",
"(",
"$",
"pair",
"[",
"'key'",
"]",
",",
"$",
"pair",
"[",
"'value'",
"]",
",",
"$",
"pair",
"[",
"'comment'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"creator",
"->",
"write",
"(",
"$",
"fileName",
")",
";",
"}"
] | Saves Configuration Data as INI File and returns Number of written Bytes.
@access protected
@static
@param string $fileName File Name of INI File
@param array $data Configuration Data as Array
@return int | [
"Saves",
"Configuration",
"Data",
"as",
"INI",
"File",
"and",
"returns",
"Number",
"of",
"written",
"Bytes",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Configuration/Converter.php#L238-L261 |
36,331 | CeusMedia/Common | src/FS/File/Configuration/Converter.php | FS_File_Configuration_Converter.saveJson | protected static function saveJson( $fileName, $data )
{
$json = array();
foreach( $data as $sectionName => $sectionData )
{
foreach( $sectionData as $pair )
{
$key = $pair['key'];
unset( $pair['key'] );
$json[$sectionName][$key] = $pair;
}
}
$json = ADT_JSON_Formater::format( $json, TRUE );
return FS_File_Writer::save( $fileName, $json );
} | php | protected static function saveJson( $fileName, $data )
{
$json = array();
foreach( $data as $sectionName => $sectionData )
{
foreach( $sectionData as $pair )
{
$key = $pair['key'];
unset( $pair['key'] );
$json[$sectionName][$key] = $pair;
}
}
$json = ADT_JSON_Formater::format( $json, TRUE );
return FS_File_Writer::save( $fileName, $json );
} | [
"protected",
"static",
"function",
"saveJson",
"(",
"$",
"fileName",
",",
"$",
"data",
")",
"{",
"$",
"json",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"sectionName",
"=>",
"$",
"sectionData",
")",
"{",
"foreach",
"(",
"$",
"sectionData",
"as",
"$",
"pair",
")",
"{",
"$",
"key",
"=",
"$",
"pair",
"[",
"'key'",
"]",
";",
"unset",
"(",
"$",
"pair",
"[",
"'key'",
"]",
")",
";",
"$",
"json",
"[",
"$",
"sectionName",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"pair",
";",
"}",
"}",
"$",
"json",
"=",
"ADT_JSON_Formater",
"::",
"format",
"(",
"$",
"json",
",",
"TRUE",
")",
";",
"return",
"FS_File_Writer",
"::",
"save",
"(",
"$",
"fileName",
",",
"$",
"json",
")",
";",
"}"
] | Saves Configuration Data as JSON File and returns Number of written Bytes.
@access protected
@static
@param string $fileName File Name of JSON File
@param array $data Configuration Data as Array
@return int | [
"Saves",
"Configuration",
"Data",
"as",
"JSON",
"File",
"and",
"returns",
"Number",
"of",
"written",
"Bytes",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Configuration/Converter.php#L271-L285 |
36,332 | CeusMedia/Common | src/FS/File/Configuration/Converter.php | FS_File_Configuration_Converter.saveXml | protected static function saveXml( $fileName, $data )
{
$root = new XML_DOM_Node( "configuration" );
foreach( $data as $sectionName => $sectionData )
{
$sectionNode = new XML_DOM_Node( "section" );
$sectionNode->setAttribute( 'name', $sectionName );
foreach( $sectionData as $pair )
{
$comment = isset( $pair['comment'] ) ? $pair['comment'] : NULL;
$valueNode = new XML_DOM_Node( "value", $pair['value'] );
$valueNode->setAttribute( 'type', $pair['type'] );
$valueNode->setAttribute( 'name', $pair['key'] );
if( isset( $pair['comment'] ) )
$valueNode->setAttribute( 'comment', $comment );
$sectionNode->addChild( $valueNode );
}
$root->addChild( $sectionNode );
}
return XML_DOM_FileWriter::save( $fileName, $root );
} | php | protected static function saveXml( $fileName, $data )
{
$root = new XML_DOM_Node( "configuration" );
foreach( $data as $sectionName => $sectionData )
{
$sectionNode = new XML_DOM_Node( "section" );
$sectionNode->setAttribute( 'name', $sectionName );
foreach( $sectionData as $pair )
{
$comment = isset( $pair['comment'] ) ? $pair['comment'] : NULL;
$valueNode = new XML_DOM_Node( "value", $pair['value'] );
$valueNode->setAttribute( 'type', $pair['type'] );
$valueNode->setAttribute( 'name', $pair['key'] );
if( isset( $pair['comment'] ) )
$valueNode->setAttribute( 'comment', $comment );
$sectionNode->addChild( $valueNode );
}
$root->addChild( $sectionNode );
}
return XML_DOM_FileWriter::save( $fileName, $root );
} | [
"protected",
"static",
"function",
"saveXml",
"(",
"$",
"fileName",
",",
"$",
"data",
")",
"{",
"$",
"root",
"=",
"new",
"XML_DOM_Node",
"(",
"\"configuration\"",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"sectionName",
"=>",
"$",
"sectionData",
")",
"{",
"$",
"sectionNode",
"=",
"new",
"XML_DOM_Node",
"(",
"\"section\"",
")",
";",
"$",
"sectionNode",
"->",
"setAttribute",
"(",
"'name'",
",",
"$",
"sectionName",
")",
";",
"foreach",
"(",
"$",
"sectionData",
"as",
"$",
"pair",
")",
"{",
"$",
"comment",
"=",
"isset",
"(",
"$",
"pair",
"[",
"'comment'",
"]",
")",
"?",
"$",
"pair",
"[",
"'comment'",
"]",
":",
"NULL",
";",
"$",
"valueNode",
"=",
"new",
"XML_DOM_Node",
"(",
"\"value\"",
",",
"$",
"pair",
"[",
"'value'",
"]",
")",
";",
"$",
"valueNode",
"->",
"setAttribute",
"(",
"'type'",
",",
"$",
"pair",
"[",
"'type'",
"]",
")",
";",
"$",
"valueNode",
"->",
"setAttribute",
"(",
"'name'",
",",
"$",
"pair",
"[",
"'key'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"pair",
"[",
"'comment'",
"]",
")",
")",
"$",
"valueNode",
"->",
"setAttribute",
"(",
"'comment'",
",",
"$",
"comment",
")",
";",
"$",
"sectionNode",
"->",
"addChild",
"(",
"$",
"valueNode",
")",
";",
"}",
"$",
"root",
"->",
"addChild",
"(",
"$",
"sectionNode",
")",
";",
"}",
"return",
"XML_DOM_FileWriter",
"::",
"save",
"(",
"$",
"fileName",
",",
"$",
"root",
")",
";",
"}"
] | Saves Configuration Data as XML File and returns Number of written Bytes.
@access protected
@static
@param string $fileName File Name of XML File
@param array $data Configuration Data as Array
@return int | [
"Saves",
"Configuration",
"Data",
"as",
"XML",
"File",
"and",
"returns",
"Number",
"of",
"written",
"Bytes",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Configuration/Converter.php#L295-L315 |
36,333 | CeusMedia/Common | src/FS/File/JSON/Reader.php | FS_File_JSON_Reader.load | public static function load( $filePath, $asArray = NULL )
{
$reader = new FS_File_JSON_Reader( $filePath );
return $reader->read( $asArray );
} | php | public static function load( $filePath, $asArray = NULL )
{
$reader = new FS_File_JSON_Reader( $filePath );
return $reader->read( $asArray );
} | [
"public",
"static",
"function",
"load",
"(",
"$",
"filePath",
",",
"$",
"asArray",
"=",
"NULL",
")",
"{",
"$",
"reader",
"=",
"new",
"FS_File_JSON_Reader",
"(",
"$",
"filePath",
")",
";",
"return",
"$",
"reader",
"->",
"read",
"(",
"$",
"asArray",
")",
";",
"}"
] | Reads a JSON file to an object or array statically.
@access public
@param string $filePath Path to JSON file
@param bool $asArray Flag: read into an array
@return object|array | [
"Reads",
"a",
"JSON",
"file",
"to",
"an",
"object",
"or",
"array",
"statically",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/JSON/Reader.php#L75-L79 |
36,334 | CeusMedia/Common | src/FS/File/JSON/Reader.php | FS_File_JSON_Reader.read | public function read( $asArray = NULL )
{
$json = FS_File_Reader::load( $this->filePath );
$data = json_decode( $json, $asArray );
if( json_last_error() !== JSON_ERROR_NONE ){
$message = 'Decoding JSON failed (%s): %s';
$message = vsprintf( $message, array(
ADT_Constant::getKeyByValue( 'JSON_ERROR_', json_last_error() ),
json_last_error_msg()
) );
throw new RuntimeException( $message, json_last_error() );
}
return $data;
} | php | public function read( $asArray = NULL )
{
$json = FS_File_Reader::load( $this->filePath );
$data = json_decode( $json, $asArray );
if( json_last_error() !== JSON_ERROR_NONE ){
$message = 'Decoding JSON failed (%s): %s';
$message = vsprintf( $message, array(
ADT_Constant::getKeyByValue( 'JSON_ERROR_', json_last_error() ),
json_last_error_msg()
) );
throw new RuntimeException( $message, json_last_error() );
}
return $data;
} | [
"public",
"function",
"read",
"(",
"$",
"asArray",
"=",
"NULL",
")",
"{",
"$",
"json",
"=",
"FS_File_Reader",
"::",
"load",
"(",
"$",
"this",
"->",
"filePath",
")",
";",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"json",
",",
"$",
"asArray",
")",
";",
"if",
"(",
"json_last_error",
"(",
")",
"!==",
"JSON_ERROR_NONE",
")",
"{",
"$",
"message",
"=",
"'Decoding JSON failed (%s): %s'",
";",
"$",
"message",
"=",
"vsprintf",
"(",
"$",
"message",
",",
"array",
"(",
"ADT_Constant",
"::",
"getKeyByValue",
"(",
"'JSON_ERROR_'",
",",
"json_last_error",
"(",
")",
")",
",",
"json_last_error_msg",
"(",
")",
")",
")",
";",
"throw",
"new",
"RuntimeException",
"(",
"$",
"message",
",",
"json_last_error",
"(",
")",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Reads the JSON file to an object or array.
@access public
@param bool $asArray Flag: read into an array
@return object|array
@throws RuntimeException if parsing failed | [
"Reads",
"the",
"JSON",
"file",
"to",
"an",
"object",
"or",
"array",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/JSON/Reader.php#L96-L109 |
36,335 | ncou/Chiron | src/Chiron/Http/Middleware/SecurityHeadersMiddleware.php | SecurityHeadersMiddleware.compileHeaders | private function compileHeaders(): array
{
return array_merge(
$this->security['settings']['enable-hsts'] ? $this->hsts() : [],
$this->security['settings']['enable-hpkp'] ? $this->hpkp() : [],
$this->security['settings']['enable-ect'] ? $this->ect() : [],
$this->security['settings']['enable-extras'] ? $this->extras() : []
);
} | php | private function compileHeaders(): array
{
return array_merge(
$this->security['settings']['enable-hsts'] ? $this->hsts() : [],
$this->security['settings']['enable-hpkp'] ? $this->hpkp() : [],
$this->security['settings']['enable-ect'] ? $this->ect() : [],
$this->security['settings']['enable-extras'] ? $this->extras() : []
);
} | [
"private",
"function",
"compileHeaders",
"(",
")",
":",
"array",
"{",
"return",
"array_merge",
"(",
"$",
"this",
"->",
"security",
"[",
"'settings'",
"]",
"[",
"'enable-hsts'",
"]",
"?",
"$",
"this",
"->",
"hsts",
"(",
")",
":",
"[",
"]",
",",
"$",
"this",
"->",
"security",
"[",
"'settings'",
"]",
"[",
"'enable-hpkp'",
"]",
"?",
"$",
"this",
"->",
"hpkp",
"(",
")",
":",
"[",
"]",
",",
"$",
"this",
"->",
"security",
"[",
"'settings'",
"]",
"[",
"'enable-ect'",
"]",
"?",
"$",
"this",
"->",
"ect",
"(",
")",
":",
"[",
"]",
",",
"$",
"this",
"->",
"security",
"[",
"'settings'",
"]",
"[",
"'enable-extras'",
"]",
"?",
"$",
"this",
"->",
"extras",
"(",
")",
":",
"[",
"]",
")",
";",
"}"
] | Compile the security HTTP headers.
@return array | [
"Compile",
"the",
"security",
"HTTP",
"headers",
"."
] | bfb6f85faba0e54005896b09a7c34e456d1a1bed | https://github.com/ncou/Chiron/blob/bfb6f85faba0e54005896b09a7c34e456d1a1bed/src/Chiron/Http/Middleware/SecurityHeadersMiddleware.php#L91-L99 |
36,336 | ncou/Chiron | src/Chiron/Http/Middleware/SecurityHeadersMiddleware.php | SecurityHeadersMiddleware.hpkp | private function hpkp(): array
{
// TODO : lever une exception si les champs hashes et max-age sont vide, car ils doivent tous les deux avoir une valeur chacun (cad un hash au minimum + un maxage)
$values = [];
foreach ($this->security['hpkp']['hashes'] as $hash) {
$values[] = sprintf('pin-sha256="%s"', $hash);
}
$values[] = sprintf('max-age=%d', $this->security['hpkp']['max-age']);
if ($this->security['hpkp']['include-sub-domains']) {
$values[] = 'includeSubDomains';
}
if (! empty($this->security['hpkp']['report-uri'])) {
$values[] = sprintf('report-uri="%s"', $this->security['hpkp']['report-uri']);
}
$header = $this->security['hpkp']['report-only']
? 'Public-Key-Pins-Report-Only'
: 'Public-Key-Pins';
return [$header => implode('; ', $values)];
} | php | private function hpkp(): array
{
// TODO : lever une exception si les champs hashes et max-age sont vide, car ils doivent tous les deux avoir une valeur chacun (cad un hash au minimum + un maxage)
$values = [];
foreach ($this->security['hpkp']['hashes'] as $hash) {
$values[] = sprintf('pin-sha256="%s"', $hash);
}
$values[] = sprintf('max-age=%d', $this->security['hpkp']['max-age']);
if ($this->security['hpkp']['include-sub-domains']) {
$values[] = 'includeSubDomains';
}
if (! empty($this->security['hpkp']['report-uri'])) {
$values[] = sprintf('report-uri="%s"', $this->security['hpkp']['report-uri']);
}
$header = $this->security['hpkp']['report-only']
? 'Public-Key-Pins-Report-Only'
: 'Public-Key-Pins';
return [$header => implode('; ', $values)];
} | [
"private",
"function",
"hpkp",
"(",
")",
":",
"array",
"{",
"// TODO : lever une exception si les champs hashes et max-age sont vide, car ils doivent tous les deux avoir une valeur chacun (cad un hash au minimum + un maxage)",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"security",
"[",
"'hpkp'",
"]",
"[",
"'hashes'",
"]",
"as",
"$",
"hash",
")",
"{",
"$",
"values",
"[",
"]",
"=",
"sprintf",
"(",
"'pin-sha256=\"%s\"'",
",",
"$",
"hash",
")",
";",
"}",
"$",
"values",
"[",
"]",
"=",
"sprintf",
"(",
"'max-age=%d'",
",",
"$",
"this",
"->",
"security",
"[",
"'hpkp'",
"]",
"[",
"'max-age'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"security",
"[",
"'hpkp'",
"]",
"[",
"'include-sub-domains'",
"]",
")",
"{",
"$",
"values",
"[",
"]",
"=",
"'includeSubDomains'",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"security",
"[",
"'hpkp'",
"]",
"[",
"'report-uri'",
"]",
")",
")",
"{",
"$",
"values",
"[",
"]",
"=",
"sprintf",
"(",
"'report-uri=\"%s\"'",
",",
"$",
"this",
"->",
"security",
"[",
"'hpkp'",
"]",
"[",
"'report-uri'",
"]",
")",
";",
"}",
"$",
"header",
"=",
"$",
"this",
"->",
"security",
"[",
"'hpkp'",
"]",
"[",
"'report-only'",
"]",
"?",
"'Public-Key-Pins-Report-Only'",
":",
"'Public-Key-Pins'",
";",
"return",
"[",
"$",
"header",
"=>",
"implode",
"(",
"'; '",
",",
"$",
"values",
")",
"]",
";",
"}"
] | Get HPKP header.
@see https://tools.ietf.org/html/rfc7469
@return array | [
"Get",
"HPKP",
"header",
"."
] | bfb6f85faba0e54005896b09a7c34e456d1a1bed | https://github.com/ncou/Chiron/blob/bfb6f85faba0e54005896b09a7c34e456d1a1bed/src/Chiron/Http/Middleware/SecurityHeadersMiddleware.php#L129-L148 |
36,337 | ncou/Chiron | src/Chiron/Http/Middleware/SecurityHeadersMiddleware.php | SecurityHeadersMiddleware.ect | private function ect(): array
{
$ect = "max-age={$this->security['ect']['max-age']}";
if ($this->security['ect']['enforce']) {
$ect .= ', enforce';
}
if (! empty($this->security['ect']['report-uri'])) {
$ect .= sprintf(', report-uri="%s"', $this->security['ect']['report-uri']);
}
return ['Expect-CT' => $ect];
} | php | private function ect(): array
{
$ect = "max-age={$this->security['ect']['max-age']}";
if ($this->security['ect']['enforce']) {
$ect .= ', enforce';
}
if (! empty($this->security['ect']['report-uri'])) {
$ect .= sprintf(', report-uri="%s"', $this->security['ect']['report-uri']);
}
return ['Expect-CT' => $ect];
} | [
"private",
"function",
"ect",
"(",
")",
":",
"array",
"{",
"$",
"ect",
"=",
"\"max-age={$this->security['ect']['max-age']}\"",
";",
"if",
"(",
"$",
"this",
"->",
"security",
"[",
"'ect'",
"]",
"[",
"'enforce'",
"]",
")",
"{",
"$",
"ect",
".=",
"', enforce'",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"security",
"[",
"'ect'",
"]",
"[",
"'report-uri'",
"]",
")",
")",
"{",
"$",
"ect",
".=",
"sprintf",
"(",
"', report-uri=\"%s\"'",
",",
"$",
"this",
"->",
"security",
"[",
"'ect'",
"]",
"[",
"'report-uri'",
"]",
")",
";",
"}",
"return",
"[",
"'Expect-CT'",
"=>",
"$",
"ect",
"]",
";",
"}"
] | Get Expect-CT header.
@see https://tools.ietf.org/html/draft-ietf-httpbis-expect-ct-03
@return array | [
"Get",
"Expect",
"-",
"CT",
"header",
"."
] | bfb6f85faba0e54005896b09a7c34e456d1a1bed | https://github.com/ncou/Chiron/blob/bfb6f85faba0e54005896b09a7c34e456d1a1bed/src/Chiron/Http/Middleware/SecurityHeadersMiddleware.php#L157-L169 |
36,338 | CeusMedia/Common | src/UI/HTML/Tree/LayerMenu.php | UI_HTML_Tree_LayerMenu.buildMenuFromOpml | public function buildMenuFromOpml( $opml )
{
$list = Alg_Tree_Menu_Converter::convertFromOpml( $opml, $this->rootLabel );
return $this->buildMenuFromMenuList( $list );
} | php | public function buildMenuFromOpml( $opml )
{
$list = Alg_Tree_Menu_Converter::convertFromOpml( $opml, $this->rootLabel );
return $this->buildMenuFromMenuList( $list );
} | [
"public",
"function",
"buildMenuFromOpml",
"(",
"$",
"opml",
")",
"{",
"$",
"list",
"=",
"Alg_Tree_Menu_Converter",
"::",
"convertFromOpml",
"(",
"$",
"opml",
",",
"$",
"this",
"->",
"rootLabel",
")",
";",
"return",
"$",
"this",
"->",
"buildMenuFromMenuList",
"(",
"$",
"list",
")",
";",
"}"
] | Builds Layer Menu from OPML String.
@access public
@param string $opml OPML String
@return | [
"Builds",
"Layer",
"Menu",
"from",
"OPML",
"String",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/Tree/LayerMenu.php#L155-L159 |
36,339 | Assasz/yggdrasil | src/Yggdrasil/Core/Controller/AbstractController.php | AbstractController.render | protected function render(string $view, array $params = []): Response
{
$this->getTemplateEngine()->addGlobal('_request', $this->getRequest());
$template = $this->getTemplateEngine()->render($view, $params);
return $this->getResponse()->setContent($template);
} | php | protected function render(string $view, array $params = []): Response
{
$this->getTemplateEngine()->addGlobal('_request', $this->getRequest());
$template = $this->getTemplateEngine()->render($view, $params);
return $this->getResponse()->setContent($template);
} | [
"protected",
"function",
"render",
"(",
"string",
"$",
"view",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
":",
"Response",
"{",
"$",
"this",
"->",
"getTemplateEngine",
"(",
")",
"->",
"addGlobal",
"(",
"'_request'",
",",
"$",
"this",
"->",
"getRequest",
"(",
")",
")",
";",
"$",
"template",
"=",
"$",
"this",
"->",
"getTemplateEngine",
"(",
")",
"->",
"render",
"(",
"$",
"view",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"getResponse",
"(",
")",
"->",
"setContent",
"(",
"$",
"template",
")",
";",
"}"
] | Renders given view as response
@param string $view Name of view file
@param array $params Parameters supposed to be passed to the view
@return Response | [
"Renders",
"given",
"view",
"as",
"response"
] | bee9bef7713b85799cdd3e9b23dccae33154f3b3 | https://github.com/Assasz/yggdrasil/blob/bee9bef7713b85799cdd3e9b23dccae33154f3b3/src/Yggdrasil/Core/Controller/AbstractController.php#L63-L69 |
36,340 | Assasz/yggdrasil | src/Yggdrasil/Core/Controller/AbstractController.php | AbstractController.redirectToAction | protected function redirectToAction(string $alias = null, array $params = []): RedirectResponse
{
if (empty($alias)) {
$routerConfig = $this->getRouter()->getConfiguration();
$alias = "{$routerConfig->getDefaultController()}:{$routerConfig->getDefaultAction()}";
}
$query = $this->getRouter()->getQuery($alias, $params);
$headers = $this->getResponse()->headers->all();
return new RedirectResponse($query, Response::HTTP_FOUND, $headers);
} | php | protected function redirectToAction(string $alias = null, array $params = []): RedirectResponse
{
if (empty($alias)) {
$routerConfig = $this->getRouter()->getConfiguration();
$alias = "{$routerConfig->getDefaultController()}:{$routerConfig->getDefaultAction()}";
}
$query = $this->getRouter()->getQuery($alias, $params);
$headers = $this->getResponse()->headers->all();
return new RedirectResponse($query, Response::HTTP_FOUND, $headers);
} | [
"protected",
"function",
"redirectToAction",
"(",
"string",
"$",
"alias",
"=",
"null",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
":",
"RedirectResponse",
"{",
"if",
"(",
"empty",
"(",
"$",
"alias",
")",
")",
"{",
"$",
"routerConfig",
"=",
"$",
"this",
"->",
"getRouter",
"(",
")",
"->",
"getConfiguration",
"(",
")",
";",
"$",
"alias",
"=",
"\"{$routerConfig->getDefaultController()}:{$routerConfig->getDefaultAction()}\"",
";",
"}",
"$",
"query",
"=",
"$",
"this",
"->",
"getRouter",
"(",
")",
"->",
"getQuery",
"(",
"$",
"alias",
",",
"$",
"params",
")",
";",
"$",
"headers",
"=",
"$",
"this",
"->",
"getResponse",
"(",
")",
"->",
"headers",
"->",
"all",
"(",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"query",
",",
"Response",
"::",
"HTTP_FOUND",
",",
"$",
"headers",
")",
";",
"}"
] | Redirects to given action
@param string? $alias Alias of action like Controller:action, if left empty default action will be chosen
@param array $params Parameters supposed to be passed to the action
@return RedirectResponse | [
"Redirects",
"to",
"given",
"action"
] | bee9bef7713b85799cdd3e9b23dccae33154f3b3 | https://github.com/Assasz/yggdrasil/blob/bee9bef7713b85799cdd3e9b23dccae33154f3b3/src/Yggdrasil/Core/Controller/AbstractController.php#L92-L103 |
36,341 | CeusMedia/Common | src/FS/File/CSS/Reader.php | FS_File_CSS_Reader.setFileName | public function setFileName( $fileName ){
$this->fileName = $fileName;
$this->sheet = self::load( $fileName );
} | php | public function setFileName( $fileName ){
$this->fileName = $fileName;
$this->sheet = self::load( $fileName );
} | [
"public",
"function",
"setFileName",
"(",
"$",
"fileName",
")",
"{",
"$",
"this",
"->",
"fileName",
"=",
"$",
"fileName",
";",
"$",
"this",
"->",
"sheet",
"=",
"self",
"::",
"load",
"(",
"$",
"fileName",
")",
";",
"}"
] | Points reader to a CSS file which will be parsed and stored internally.
@access public
@param string $fileName Relative or absolute file URI
@return void | [
"Points",
"reader",
"to",
"a",
"CSS",
"file",
"which",
"will",
"be",
"parsed",
"and",
"stored",
"internally",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/CSS/Reader.php#L99-L102 |
36,342 | CeusMedia/Common | src/ADT/Tree/BinaryNode.php | ADT_Tree_BinaryNode.add | public function add( $value )
{
if( !isset( $this->value ) )
return $this->value = $value;
if( $value == $this->value)
return -1;
if( $value < $this->value )
{
if( $this->left )
$this->left->add( $value );
else
$this->left = new ADT_Tree_BinaryNode( $value );
}
else if( $value > $this->value )
{
if( $this->right )
$this->right->add( $value );
else
$this->right = new ADT_Tree_BinaryNode( $value );
}
} | php | public function add( $value )
{
if( !isset( $this->value ) )
return $this->value = $value;
if( $value == $this->value)
return -1;
if( $value < $this->value )
{
if( $this->left )
$this->left->add( $value );
else
$this->left = new ADT_Tree_BinaryNode( $value );
}
else if( $value > $this->value )
{
if( $this->right )
$this->right->add( $value );
else
$this->right = new ADT_Tree_BinaryNode( $value );
}
} | [
"public",
"function",
"add",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"value",
")",
")",
"return",
"$",
"this",
"->",
"value",
"=",
"$",
"value",
";",
"if",
"(",
"$",
"value",
"==",
"$",
"this",
"->",
"value",
")",
"return",
"-",
"1",
";",
"if",
"(",
"$",
"value",
"<",
"$",
"this",
"->",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"left",
")",
"$",
"this",
"->",
"left",
"->",
"add",
"(",
"$",
"value",
")",
";",
"else",
"$",
"this",
"->",
"left",
"=",
"new",
"ADT_Tree_BinaryNode",
"(",
"$",
"value",
")",
";",
"}",
"else",
"if",
"(",
"$",
"value",
">",
"$",
"this",
"->",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"right",
")",
"$",
"this",
"->",
"right",
"->",
"add",
"(",
"$",
"value",
")",
";",
"else",
"$",
"this",
"->",
"right",
"=",
"new",
"ADT_Tree_BinaryNode",
"(",
"$",
"value",
")",
";",
"}",
"}"
] | Adds a Node to the Tree.
@access public
@param mixed $value Value to be added to the Tree
@return void | [
"Adds",
"a",
"Node",
"to",
"the",
"Tree",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/Tree/BinaryNode.php#L65-L85 |
36,343 | CeusMedia/Common | src/ADT/Tree/BinaryNode.php | ADT_Tree_BinaryNode.countNodes | public function countNodes()
{
$nodes = 1;
if( $this->left || $this->right )
{
if( $this->left )
$nodes += $this->left->countNodes();
if( $this->right )
$nodes += $this->right->countNodes();
}
return $nodes;
} | php | public function countNodes()
{
$nodes = 1;
if( $this->left || $this->right )
{
if( $this->left )
$nodes += $this->left->countNodes();
if( $this->right )
$nodes += $this->right->countNodes();
}
return $nodes;
} | [
"public",
"function",
"countNodes",
"(",
")",
"{",
"$",
"nodes",
"=",
"1",
";",
"if",
"(",
"$",
"this",
"->",
"left",
"||",
"$",
"this",
"->",
"right",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"left",
")",
"$",
"nodes",
"+=",
"$",
"this",
"->",
"left",
"->",
"countNodes",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"right",
")",
"$",
"nodes",
"+=",
"$",
"this",
"->",
"right",
"->",
"countNodes",
"(",
")",
";",
"}",
"return",
"$",
"nodes",
";",
"}"
] | Returns the amount of Nodes in the Tree.
@access public
@return int | [
"Returns",
"the",
"amount",
"of",
"Nodes",
"in",
"the",
"Tree",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/Tree/BinaryNode.php#L92-L103 |
36,344 | CeusMedia/Common | src/ADT/Tree/BinaryNode.php | ADT_Tree_BinaryNode.getHeight | public function getHeight()
{
$left_height = $this->left ? $this->left->getHeight() : 0; // Rekursiver Aufruf des linken Teilbaumes
$right_height = $this->right ? $this->right->getHeight() : 0; // Rekursiver Aufruf des rechten Teilbaumes
$height = max( $left_height, $right_height ); // Vergleichen welcher der beiden Teilbäume höher ist
$height++; // Höhe hochzählen
return $height;
} | php | public function getHeight()
{
$left_height = $this->left ? $this->left->getHeight() : 0; // Rekursiver Aufruf des linken Teilbaumes
$right_height = $this->right ? $this->right->getHeight() : 0; // Rekursiver Aufruf des rechten Teilbaumes
$height = max( $left_height, $right_height ); // Vergleichen welcher der beiden Teilbäume höher ist
$height++; // Höhe hochzählen
return $height;
} | [
"public",
"function",
"getHeight",
"(",
")",
"{",
"$",
"left_height",
"=",
"$",
"this",
"->",
"left",
"?",
"$",
"this",
"->",
"left",
"->",
"getHeight",
"(",
")",
":",
"0",
";",
"// Rekursiver Aufruf des linken Teilbaumes\r",
"$",
"right_height",
"=",
"$",
"this",
"->",
"right",
"?",
"$",
"this",
"->",
"right",
"->",
"getHeight",
"(",
")",
":",
"0",
";",
"// Rekursiver Aufruf des rechten Teilbaumes\r",
"$",
"height",
"=",
"max",
"(",
"$",
"left_height",
",",
"$",
"right_height",
")",
";",
"// Vergleichen welcher der beiden Teilbäume höher ist\r",
"$",
"height",
"++",
";",
"// Höhe hochzählen\r",
"return",
"$",
"height",
";",
"}"
] | Returns the height of the Tree.
@access public
@return int | [
"Returns",
"the",
"height",
"of",
"the",
"Tree",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/Tree/BinaryNode.php#L110-L117 |
36,345 | CeusMedia/Common | src/ADT/Tree/BinaryNode.php | ADT_Tree_BinaryNode.search | public function search( $value )
{
if( $value == $this->value )
return $this;
else if( $value < $this->value )
{
if( $this->left )
return $this->left->search( $value );
}
else if( $value > $this->value )
{
if( $this->right )
return $this->right->search( $value );
}
return NULL;
} | php | public function search( $value )
{
if( $value == $this->value )
return $this;
else if( $value < $this->value )
{
if( $this->left )
return $this->left->search( $value );
}
else if( $value > $this->value )
{
if( $this->right )
return $this->right->search( $value );
}
return NULL;
} | [
"public",
"function",
"search",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"==",
"$",
"this",
"->",
"value",
")",
"return",
"$",
"this",
";",
"else",
"if",
"(",
"$",
"value",
"<",
"$",
"this",
"->",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"left",
")",
"return",
"$",
"this",
"->",
"left",
"->",
"search",
"(",
"$",
"value",
")",
";",
"}",
"else",
"if",
"(",
"$",
"value",
">",
"$",
"this",
"->",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"right",
")",
"return",
"$",
"this",
"->",
"right",
"->",
"search",
"(",
"$",
"value",
")",
";",
"}",
"return",
"NULL",
";",
"}"
] | Indicates wheter a Value can be found in the Tree.
@access public
@param mixed $value Value to be found in the Tree
@return void | [
"Indicates",
"wheter",
"a",
"Value",
"can",
"be",
"found",
"in",
"the",
"Tree",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/Tree/BinaryNode.php#L159-L174 |
36,346 | CeusMedia/Common | src/ADT/Tree/BinaryNode.php | ADT_Tree_BinaryNode.toList | public function toList( $dir = NULL )
{
$array = array();
if( !$dir || $dir == "lwr" )
{
if( $this->left )
$array = array_merge( $array, $this->left->toList( $dir ) );
$array = array_merge( $array, array( $this->value ) );
if( $this->right )
$array = array_merge( $array, $this->right->toList( $dir ) );
}
else if( $dir == "rwl" )
{
if( $this->right )
$array = array_merge( $array, $this->right->toList( $dir ) );
$array = array_merge( $array, array ($this->value));
if( $this->left)
$array = array_merge( $array, $this->left->toList( $dir ) );
}
else if( $dir == "wlr" )
{
$array = array_merge( $array, array ($this->value));
if( $this->left )
$array = array_merge( $array, $this->left->toList( $dir ) );
if( $this->right )
$array = array_merge( $array, $this->right->toList( $dir ) );
}
else if( $dir == "wrl" )
{
$array = array_merge( $array, array ($this->value));
if( $this->right )
$array = array_merge( $array, $this->right->toList( $dir ) );
if( $this->left )
$array = array_merge( $array, $this->left->toList( $dir ) );
}
return $array;
} | php | public function toList( $dir = NULL )
{
$array = array();
if( !$dir || $dir == "lwr" )
{
if( $this->left )
$array = array_merge( $array, $this->left->toList( $dir ) );
$array = array_merge( $array, array( $this->value ) );
if( $this->right )
$array = array_merge( $array, $this->right->toList( $dir ) );
}
else if( $dir == "rwl" )
{
if( $this->right )
$array = array_merge( $array, $this->right->toList( $dir ) );
$array = array_merge( $array, array ($this->value));
if( $this->left)
$array = array_merge( $array, $this->left->toList( $dir ) );
}
else if( $dir == "wlr" )
{
$array = array_merge( $array, array ($this->value));
if( $this->left )
$array = array_merge( $array, $this->left->toList( $dir ) );
if( $this->right )
$array = array_merge( $array, $this->right->toList( $dir ) );
}
else if( $dir == "wrl" )
{
$array = array_merge( $array, array ($this->value));
if( $this->right )
$array = array_merge( $array, $this->right->toList( $dir ) );
if( $this->left )
$array = array_merge( $array, $this->left->toList( $dir ) );
}
return $array;
} | [
"public",
"function",
"toList",
"(",
"$",
"dir",
"=",
"NULL",
")",
"{",
"$",
"array",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"$",
"dir",
"||",
"$",
"dir",
"==",
"\"lwr\"",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"left",
")",
"$",
"array",
"=",
"array_merge",
"(",
"$",
"array",
",",
"$",
"this",
"->",
"left",
"->",
"toList",
"(",
"$",
"dir",
")",
")",
";",
"$",
"array",
"=",
"array_merge",
"(",
"$",
"array",
",",
"array",
"(",
"$",
"this",
"->",
"value",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"right",
")",
"$",
"array",
"=",
"array_merge",
"(",
"$",
"array",
",",
"$",
"this",
"->",
"right",
"->",
"toList",
"(",
"$",
"dir",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"dir",
"==",
"\"rwl\"",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"right",
")",
"$",
"array",
"=",
"array_merge",
"(",
"$",
"array",
",",
"$",
"this",
"->",
"right",
"->",
"toList",
"(",
"$",
"dir",
")",
")",
";",
"$",
"array",
"=",
"array_merge",
"(",
"$",
"array",
",",
"array",
"(",
"$",
"this",
"->",
"value",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"left",
")",
"$",
"array",
"=",
"array_merge",
"(",
"$",
"array",
",",
"$",
"this",
"->",
"left",
"->",
"toList",
"(",
"$",
"dir",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"dir",
"==",
"\"wlr\"",
")",
"{",
"$",
"array",
"=",
"array_merge",
"(",
"$",
"array",
",",
"array",
"(",
"$",
"this",
"->",
"value",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"left",
")",
"$",
"array",
"=",
"array_merge",
"(",
"$",
"array",
",",
"$",
"this",
"->",
"left",
"->",
"toList",
"(",
"$",
"dir",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"right",
")",
"$",
"array",
"=",
"array_merge",
"(",
"$",
"array",
",",
"$",
"this",
"->",
"right",
"->",
"toList",
"(",
"$",
"dir",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"dir",
"==",
"\"wrl\"",
")",
"{",
"$",
"array",
"=",
"array_merge",
"(",
"$",
"array",
",",
"array",
"(",
"$",
"this",
"->",
"value",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"right",
")",
"$",
"array",
"=",
"array_merge",
"(",
"$",
"array",
",",
"$",
"this",
"->",
"right",
"->",
"toList",
"(",
"$",
"dir",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"left",
")",
"$",
"array",
"=",
"array_merge",
"(",
"$",
"array",
",",
"$",
"this",
"->",
"left",
"->",
"toList",
"(",
"$",
"dir",
")",
")",
";",
"}",
"return",
"$",
"array",
";",
"}"
] | Runs through the Tree in any Directions and returns the Tree as List.
@access public
@param string $dir Direction to run through the Tree (lwr|rwl|wlr|wrl)
@return array | [
"Runs",
"through",
"the",
"Tree",
"in",
"any",
"Directions",
"and",
"returns",
"the",
"Tree",
"as",
"List",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/Tree/BinaryNode.php#L182-L218 |
36,347 | CeusMedia/Common | src/ADT/Tree/BinaryNode.php | ADT_Tree_BinaryNode.toTable | public function toTable()
{
$code = "<table cellspacing=1 cellpadding=0>\n<tr><td colspan=2 align=center><hr>".$this->value."</td></tr>";
if( $this->left || $this->right )
{
$code .= "<tr><td align=center valign=top>";
if( $this->left )
$code .= $this->left->toTable();
else
$code .= " ";
$code .= "</td><td align=center valign=top>";
if( $this->right )
$code .= $this->right->toTable();
else
$code .= " ";
$code .= "</td></tr>\n";
}
$code .= "</table>\n";
return $code;
} | php | public function toTable()
{
$code = "<table cellspacing=1 cellpadding=0>\n<tr><td colspan=2 align=center><hr>".$this->value."</td></tr>";
if( $this->left || $this->right )
{
$code .= "<tr><td align=center valign=top>";
if( $this->left )
$code .= $this->left->toTable();
else
$code .= " ";
$code .= "</td><td align=center valign=top>";
if( $this->right )
$code .= $this->right->toTable();
else
$code .= " ";
$code .= "</td></tr>\n";
}
$code .= "</table>\n";
return $code;
} | [
"public",
"function",
"toTable",
"(",
")",
"{",
"$",
"code",
"=",
"\"<table cellspacing=1 cellpadding=0>\\n<tr><td colspan=2 align=center><hr>\"",
".",
"$",
"this",
"->",
"value",
".",
"\"</td></tr>\"",
";",
"if",
"(",
"$",
"this",
"->",
"left",
"||",
"$",
"this",
"->",
"right",
")",
"{",
"$",
"code",
".=",
"\"<tr><td align=center valign=top>\"",
";",
"if",
"(",
"$",
"this",
"->",
"left",
")",
"$",
"code",
".=",
"$",
"this",
"->",
"left",
"->",
"toTable",
"(",
")",
";",
"else",
"$",
"code",
".=",
"\" \"",
";",
"$",
"code",
".=",
"\"</td><td align=center valign=top>\"",
";",
"if",
"(",
"$",
"this",
"->",
"right",
")",
"$",
"code",
".=",
"$",
"this",
"->",
"right",
"->",
"toTable",
"(",
")",
";",
"else",
"$",
"code",
".=",
"\" \"",
";",
"$",
"code",
".=",
"\"</td></tr>\\n\"",
";",
"}",
"$",
"code",
".=",
"\"</table>\\n\"",
";",
"return",
"$",
"code",
";",
"}"
] | Returns the Tree as HTML-Table.
@access public
@return string | [
"Returns",
"the",
"Tree",
"as",
"HTML",
"-",
"Table",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/Tree/BinaryNode.php#L225-L244 |
36,348 | CeusMedia/Common | src/XML/RSS/SimpleParser.php | XML_RSS_SimpleParser.parse | public static function parse( $xml )
{
$channelData = array();
$itemList = array();
$xml = new SimpleXMLElement( $xml );
foreach( $xml->channel->children() as $nodeName => $nodeValue )
{
if( $nodeName == "image" && $nodeValue->children() )
{
$channelData[$nodeName] = self::readSubSet( $nodeValue );
continue;
}
if( $nodeName == "textInput" && $nodeValue->children() )
{
$channelData[$nodeName] = self::readSubSet( $nodeValue );
continue;
}
if( $nodeName != "item" )
{
$channelData[$nodeName] = (string) $nodeValue;
continue;
}
$item = array();
$itemNode = $nodeValue;
foreach( $itemNode->children() as $nodeName => $nodeValue )
$item[$nodeName] = (string) $nodeValue;
$itemList[] = $item;
}
$attributes = $xml->attributes();
$data = array(
'encoding' => $attributes['encoding'],
'channelData' => $channelData,
'itemList' => $itemList,
);
return $data;
} | php | public static function parse( $xml )
{
$channelData = array();
$itemList = array();
$xml = new SimpleXMLElement( $xml );
foreach( $xml->channel->children() as $nodeName => $nodeValue )
{
if( $nodeName == "image" && $nodeValue->children() )
{
$channelData[$nodeName] = self::readSubSet( $nodeValue );
continue;
}
if( $nodeName == "textInput" && $nodeValue->children() )
{
$channelData[$nodeName] = self::readSubSet( $nodeValue );
continue;
}
if( $nodeName != "item" )
{
$channelData[$nodeName] = (string) $nodeValue;
continue;
}
$item = array();
$itemNode = $nodeValue;
foreach( $itemNode->children() as $nodeName => $nodeValue )
$item[$nodeName] = (string) $nodeValue;
$itemList[] = $item;
}
$attributes = $xml->attributes();
$data = array(
'encoding' => $attributes['encoding'],
'channelData' => $channelData,
'itemList' => $itemList,
);
return $data;
} | [
"public",
"static",
"function",
"parse",
"(",
"$",
"xml",
")",
"{",
"$",
"channelData",
"=",
"array",
"(",
")",
";",
"$",
"itemList",
"=",
"array",
"(",
")",
";",
"$",
"xml",
"=",
"new",
"SimpleXMLElement",
"(",
"$",
"xml",
")",
";",
"foreach",
"(",
"$",
"xml",
"->",
"channel",
"->",
"children",
"(",
")",
"as",
"$",
"nodeName",
"=>",
"$",
"nodeValue",
")",
"{",
"if",
"(",
"$",
"nodeName",
"==",
"\"image\"",
"&&",
"$",
"nodeValue",
"->",
"children",
"(",
")",
")",
"{",
"$",
"channelData",
"[",
"$",
"nodeName",
"]",
"=",
"self",
"::",
"readSubSet",
"(",
"$",
"nodeValue",
")",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"nodeName",
"==",
"\"textInput\"",
"&&",
"$",
"nodeValue",
"->",
"children",
"(",
")",
")",
"{",
"$",
"channelData",
"[",
"$",
"nodeName",
"]",
"=",
"self",
"::",
"readSubSet",
"(",
"$",
"nodeValue",
")",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"nodeName",
"!=",
"\"item\"",
")",
"{",
"$",
"channelData",
"[",
"$",
"nodeName",
"]",
"=",
"(",
"string",
")",
"$",
"nodeValue",
";",
"continue",
";",
"}",
"$",
"item",
"=",
"array",
"(",
")",
";",
"$",
"itemNode",
"=",
"$",
"nodeValue",
";",
"foreach",
"(",
"$",
"itemNode",
"->",
"children",
"(",
")",
"as",
"$",
"nodeName",
"=>",
"$",
"nodeValue",
")",
"$",
"item",
"[",
"$",
"nodeName",
"]",
"=",
"(",
"string",
")",
"$",
"nodeValue",
";",
"$",
"itemList",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"$",
"attributes",
"=",
"$",
"xml",
"->",
"attributes",
"(",
")",
";",
"$",
"data",
"=",
"array",
"(",
"'encoding'",
"=>",
"$",
"attributes",
"[",
"'encoding'",
"]",
",",
"'channelData'",
"=>",
"$",
"channelData",
",",
"'itemList'",
"=>",
"$",
"itemList",
",",
")",
";",
"return",
"$",
"data",
";",
"}"
] | Reads RSS from XML statically and returns Array containing Channel Data and Items.
@access public
@static
@param string $xml XML String to read
@return array | [
"Reads",
"RSS",
"from",
"XML",
"statically",
"and",
"returns",
"Array",
"containing",
"Channel",
"Data",
"and",
"Items",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/RSS/SimpleParser.php#L49-L84 |
36,349 | CeusMedia/Common | src/XML/RSS/SimpleParser.php | XML_RSS_SimpleParser.readSubSet | protected static function readSubSet( $node )
{
$item = array();
foreach( $node->children() as $nodeName => $nodeValue )
$item[$nodeName] = (string) $nodeValue;
return $item;
} | php | protected static function readSubSet( $node )
{
$item = array();
foreach( $node->children() as $nodeName => $nodeValue )
$item[$nodeName] = (string) $nodeValue;
return $item;
} | [
"protected",
"static",
"function",
"readSubSet",
"(",
"$",
"node",
")",
"{",
"$",
"item",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"node",
"->",
"children",
"(",
")",
"as",
"$",
"nodeName",
"=>",
"$",
"nodeValue",
")",
"$",
"item",
"[",
"$",
"nodeName",
"]",
"=",
"(",
"string",
")",
"$",
"nodeValue",
";",
"return",
"$",
"item",
";",
"}"
] | Reads Subset of Node.
@access protected
@static
@param SimpleXMLElement $node Subset Node
@return array | [
"Reads",
"Subset",
"of",
"Node",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/RSS/SimpleParser.php#L93-L99 |
36,350 | CeusMedia/Common | src/UI/HTML/Options.php | UI_HTML_Options.buildCode | public function buildCode()
{
$select = UI_HTML_Elements::Select( $this->name, $this->options, $this->class );
return $select;
} | php | public function buildCode()
{
$select = UI_HTML_Elements::Select( $this->name, $this->options, $this->class );
return $select;
} | [
"public",
"function",
"buildCode",
"(",
")",
"{",
"$",
"select",
"=",
"UI_HTML_Elements",
"::",
"Select",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"this",
"->",
"options",
",",
"$",
"this",
"->",
"class",
")",
";",
"return",
"$",
"select",
";",
"}"
] | Builds HTML Code of Select Box.
@access public
@return string | [
"Builds",
"HTML",
"Code",
"of",
"Select",
"Box",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/Options.php#L69-L73 |
36,351 | CeusMedia/Common | src/UI/HTML/Options.php | UI_HTML_Options.buildScript | public function buildScript()
{
$options = array(
'url' => $this->url,
'async' => $this->async,
'cache' => $this->cache,
'data' => $this->data,
'selected' => $this->selected
);
return UI_HTML_JQuery::buildPluginCall( 'ajaxOptions', "select[name='".$this->name."']", $options );
} | php | public function buildScript()
{
$options = array(
'url' => $this->url,
'async' => $this->async,
'cache' => $this->cache,
'data' => $this->data,
'selected' => $this->selected
);
return UI_HTML_JQuery::buildPluginCall( 'ajaxOptions', "select[name='".$this->name."']", $options );
} | [
"public",
"function",
"buildScript",
"(",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"'url'",
"=>",
"$",
"this",
"->",
"url",
",",
"'async'",
"=>",
"$",
"this",
"->",
"async",
",",
"'cache'",
"=>",
"$",
"this",
"->",
"cache",
",",
"'data'",
"=>",
"$",
"this",
"->",
"data",
",",
"'selected'",
"=>",
"$",
"this",
"->",
"selected",
")",
";",
"return",
"UI_HTML_JQuery",
"::",
"buildPluginCall",
"(",
"'ajaxOptions'",
",",
"\"select[name='\"",
".",
"$",
"this",
"->",
"name",
".",
"\"']\"",
",",
"$",
"options",
")",
";",
"}"
] | Builds JavaScript Code for AJAX Options.
@access public
@return string | [
"Builds",
"JavaScript",
"Code",
"for",
"AJAX",
"Options",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/Options.php#L80-L90 |
36,352 | CeusMedia/Common | src/Alg/UnitFormater.php | Alg_UnitFormater.formatNumber | public static function formatNumber( $float, $unit = 1, $precision = 0 )
{
Deprecation::getInstance()->setExceptionVersion( '0.8' )
->message( 'Use one of the other methods instead' );
if( (int) $unit )
{
$float = $float / $unit;
if( is_int( $precision ) )
$float = round( $float, $precision );
}
return $float;
} | php | public static function formatNumber( $float, $unit = 1, $precision = 0 )
{
Deprecation::getInstance()->setExceptionVersion( '0.8' )
->message( 'Use one of the other methods instead' );
if( (int) $unit )
{
$float = $float / $unit;
if( is_int( $precision ) )
$float = round( $float, $precision );
}
return $float;
} | [
"public",
"static",
"function",
"formatNumber",
"(",
"$",
"float",
",",
"$",
"unit",
"=",
"1",
",",
"$",
"precision",
"=",
"0",
")",
"{",
"Deprecation",
"::",
"getInstance",
"(",
")",
"->",
"setExceptionVersion",
"(",
"'0.8'",
")",
"->",
"message",
"(",
"'Use one of the other methods instead'",
")",
";",
"if",
"(",
"(",
"int",
")",
"$",
"unit",
")",
"{",
"$",
"float",
"=",
"$",
"float",
"/",
"$",
"unit",
";",
"if",
"(",
"is_int",
"(",
"$",
"precision",
")",
")",
"$",
"float",
"=",
"round",
"(",
"$",
"float",
",",
"$",
"precision",
")",
";",
"}",
"return",
"$",
"float",
";",
"}"
] | Formats Number.
@access public
@static
@param float $float Number to format
@param int $unit Number of Digits for dot to move to left
@param int $precision Number of Digits after dot
@return void
@deprecated uncomplete method, please remove | [
"Formats",
"Number",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/UnitFormater.php#L239-L250 |
36,353 | CeusMedia/Common | src/Alg/Sort/Bubble.php | Alg_Sort_Bubble.sort | public static function sort($list)
{
for( $i=sizeof( $list ) - 1; $i>=1; $i-- )
for( $j=0; $j<$i; $j++ )
if( $list[$j] > $list[$j+1] )
self::swap( $list, $j, $j + 1 );
return $list;
} | php | public static function sort($list)
{
for( $i=sizeof( $list ) - 1; $i>=1; $i-- )
for( $j=0; $j<$i; $j++ )
if( $list[$j] > $list[$j+1] )
self::swap( $list, $j, $j + 1 );
return $list;
} | [
"public",
"static",
"function",
"sort",
"(",
"$",
"list",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"sizeof",
"(",
"$",
"list",
")",
"-",
"1",
";",
"$",
"i",
">=",
"1",
";",
"$",
"i",
"--",
")",
"for",
"(",
"$",
"j",
"=",
"0",
";",
"$",
"j",
"<",
"$",
"i",
";",
"$",
"j",
"++",
")",
"if",
"(",
"$",
"list",
"[",
"$",
"j",
"]",
">",
"$",
"list",
"[",
"$",
"j",
"+",
"1",
"]",
")",
"self",
"::",
"swap",
"(",
"$",
"list",
",",
"$",
"j",
",",
"$",
"j",
"+",
"1",
")",
";",
"return",
"$",
"list",
";",
"}"
] | Sorts List with Bubble Sort.
@access public
@static
@param array $list List to sort
@return array | [
"Sorts",
"List",
"with",
"Bubble",
"Sort",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Sort/Bubble.php#L48-L55 |
36,354 | CeusMedia/Common | src/FS/File/JSON/Config.php | FS_File_JSON_Config.save | public function save(){
$json = $this->data->toJson();
if( $this->format )
$json = ADT_JSON_Formater::format( $json );
return FS_File_Writer::save( $this->fileName, $json );
} | php | public function save(){
$json = $this->data->toJson();
if( $this->format )
$json = ADT_JSON_Formater::format( $json );
return FS_File_Writer::save( $this->fileName, $json );
} | [
"public",
"function",
"save",
"(",
")",
"{",
"$",
"json",
"=",
"$",
"this",
"->",
"data",
"->",
"toJson",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"format",
")",
"$",
"json",
"=",
"ADT_JSON_Formater",
"::",
"format",
"(",
"$",
"json",
")",
";",
"return",
"FS_File_Writer",
"::",
"save",
"(",
"$",
"this",
"->",
"fileName",
",",
"$",
"json",
")",
";",
"}"
] | Save node structure to JSON file.
@access public
@return integer Number of saved bytes | [
"Save",
"node",
"structure",
"to",
"JSON",
"file",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/JSON/Config.php#L90-L95 |
36,355 | CeusMedia/Common | src/Alg/Parcel/Packer.php | Alg_Parcel_Packer.calculatePackage | public function calculatePackage( $articleList )
{
$this->packetList = array(); // reset Packet List
foreach( $articleList as $name => $quantity ) // iterate Article List
if( !$quantity ) // and remove all Articles
unset( $articleList[$name] ); // without Quantity
while( $articleList ) // iterate Article List
{
// -- ADD FIRST PACKET -- //
$largestArticle = $this->getLargestArticle( $articleList ); // get Largest Article in List
if( !count( $this->packetList ) ) // no Packets yet in Packet List
{
$packetName = $this->getNameOfSmallestPacketForArticle( $largestArticle ); // get smallest Packet Type for Article
$packet = $this->factory->produce( $packetName, array( $largestArticle => 1 ) ); // put Article in new Packet
$this->packetList[] = $packet; // add Packet to Packet List
$this->removeArticleFromList( $articleList, $largestArticle ); // remove Article from Article List
continue; // step to next Article
}
// -- FILL PACKET -- //
$found = false; //
for( $i=0; $i<count( $this->packetList ); $i++ ) // iterate Packets in Packet List
{
$packet = $this->getPacket( $i ); // get current Packet
$articleVolume = $this->volumes[$packet->getName()][$largestArticle]; // get Article Volume in this Packet
if( $packet->hasVolumeLeft( $articleVolume ) ) // check if Article will fit in Packet
{
$packet->addArticle( $largestArticle, $articleVolume ); // put Article in Packet
$found = $this->removeArticleFromList( $articleList, $largestArticle ); // remove Article From Article List
break; // break Packet Loop
}
}
if( $found ) // Article has been put into a Packet
continue; // step to next Article
// -- RESIZE PACKET -- //
for( $i=0; $i<count( $this->packetList ); $i++ ) // iterate Packets in Packet List
{
$packet = $this->getPacket( $i ); // get current Packet
while( $this->hasLargerPacket( $packet->getName() ) ) // there is a larger Packet Type
{
$largerPacketName = $this->getNameOfLargerPacket( $packet->getName() );
$articles = $packet->getArticles(); // get larger Packet
$largerPacket = $this->factory->produce( $largerPacketName, $articles ); // produce new Packet and add Articles from old Packet
$articleVolume = $this->volumes[$largerPacketName][$largestArticle]; // get Volume of current Article in this Packet
if( $largerPacket->hasVolumeLeft( $articleVolume ) )
{
$largerPacket->addArticle( $largestArticle, $articleVolume ); // add Article to Packet
$this->replacePacket( $i, $largerPacket ); // replace old Packet with new Packet
$found = $this->removeArticleFromList( $articleList, $largestArticle ); // remove Article from Article List
break; // break Packet Loop
}
}
if( $found ) // Article has been put into a Packet
continue; // break Packet Loop
}
if( $found ) // Article has been put into a Packet
continue; // step to next Article
// -- ADD NEW PACKET -- //
$packetName = $this->getNameOfSmallestPacketForArticle( $largestArticle ); // get smallest Packet Type for Article
$packet = $this->factory->produce( $packetName, array( $largestArticle => 1 ) ); // produce new Packet and put Article in
$this->packetList[] = $packet; // add Packet to Packet List
$this->removeArticleFromList( $articleList, $largestArticle ); // remove Article from Article List
}
return $this->packetList; // return final Packet List with Articles
} | php | public function calculatePackage( $articleList )
{
$this->packetList = array(); // reset Packet List
foreach( $articleList as $name => $quantity ) // iterate Article List
if( !$quantity ) // and remove all Articles
unset( $articleList[$name] ); // without Quantity
while( $articleList ) // iterate Article List
{
// -- ADD FIRST PACKET -- //
$largestArticle = $this->getLargestArticle( $articleList ); // get Largest Article in List
if( !count( $this->packetList ) ) // no Packets yet in Packet List
{
$packetName = $this->getNameOfSmallestPacketForArticle( $largestArticle ); // get smallest Packet Type for Article
$packet = $this->factory->produce( $packetName, array( $largestArticle => 1 ) ); // put Article in new Packet
$this->packetList[] = $packet; // add Packet to Packet List
$this->removeArticleFromList( $articleList, $largestArticle ); // remove Article from Article List
continue; // step to next Article
}
// -- FILL PACKET -- //
$found = false; //
for( $i=0; $i<count( $this->packetList ); $i++ ) // iterate Packets in Packet List
{
$packet = $this->getPacket( $i ); // get current Packet
$articleVolume = $this->volumes[$packet->getName()][$largestArticle]; // get Article Volume in this Packet
if( $packet->hasVolumeLeft( $articleVolume ) ) // check if Article will fit in Packet
{
$packet->addArticle( $largestArticle, $articleVolume ); // put Article in Packet
$found = $this->removeArticleFromList( $articleList, $largestArticle ); // remove Article From Article List
break; // break Packet Loop
}
}
if( $found ) // Article has been put into a Packet
continue; // step to next Article
// -- RESIZE PACKET -- //
for( $i=0; $i<count( $this->packetList ); $i++ ) // iterate Packets in Packet List
{
$packet = $this->getPacket( $i ); // get current Packet
while( $this->hasLargerPacket( $packet->getName() ) ) // there is a larger Packet Type
{
$largerPacketName = $this->getNameOfLargerPacket( $packet->getName() );
$articles = $packet->getArticles(); // get larger Packet
$largerPacket = $this->factory->produce( $largerPacketName, $articles ); // produce new Packet and add Articles from old Packet
$articleVolume = $this->volumes[$largerPacketName][$largestArticle]; // get Volume of current Article in this Packet
if( $largerPacket->hasVolumeLeft( $articleVolume ) )
{
$largerPacket->addArticle( $largestArticle, $articleVolume ); // add Article to Packet
$this->replacePacket( $i, $largerPacket ); // replace old Packet with new Packet
$found = $this->removeArticleFromList( $articleList, $largestArticle ); // remove Article from Article List
break; // break Packet Loop
}
}
if( $found ) // Article has been put into a Packet
continue; // break Packet Loop
}
if( $found ) // Article has been put into a Packet
continue; // step to next Article
// -- ADD NEW PACKET -- //
$packetName = $this->getNameOfSmallestPacketForArticle( $largestArticle ); // get smallest Packet Type for Article
$packet = $this->factory->produce( $packetName, array( $largestArticle => 1 ) ); // produce new Packet and put Article in
$this->packetList[] = $packet; // add Packet to Packet List
$this->removeArticleFromList( $articleList, $largestArticle ); // remove Article from Article List
}
return $this->packetList; // return final Packet List with Articles
} | [
"public",
"function",
"calculatePackage",
"(",
"$",
"articleList",
")",
"{",
"$",
"this",
"->",
"packetList",
"=",
"array",
"(",
")",
";",
"// reset Packet List",
"foreach",
"(",
"$",
"articleList",
"as",
"$",
"name",
"=>",
"$",
"quantity",
")",
"// iterate Article List",
"if",
"(",
"!",
"$",
"quantity",
")",
"// and remove all Articles",
"unset",
"(",
"$",
"articleList",
"[",
"$",
"name",
"]",
")",
";",
"// without Quantity",
"while",
"(",
"$",
"articleList",
")",
"// iterate Article List",
"{",
"// -- ADD FIRST PACKET -- //",
"$",
"largestArticle",
"=",
"$",
"this",
"->",
"getLargestArticle",
"(",
"$",
"articleList",
")",
";",
"// get Largest Article in List",
"if",
"(",
"!",
"count",
"(",
"$",
"this",
"->",
"packetList",
")",
")",
"// no Packets yet in Packet List",
"{",
"$",
"packetName",
"=",
"$",
"this",
"->",
"getNameOfSmallestPacketForArticle",
"(",
"$",
"largestArticle",
")",
";",
"// get smallest Packet Type for Article",
"$",
"packet",
"=",
"$",
"this",
"->",
"factory",
"->",
"produce",
"(",
"$",
"packetName",
",",
"array",
"(",
"$",
"largestArticle",
"=>",
"1",
")",
")",
";",
"// put Article in new Packet",
"$",
"this",
"->",
"packetList",
"[",
"]",
"=",
"$",
"packet",
";",
"// add Packet to Packet List",
"$",
"this",
"->",
"removeArticleFromList",
"(",
"$",
"articleList",
",",
"$",
"largestArticle",
")",
";",
"// remove Article from Article List",
"continue",
";",
"// step to next Article",
"}",
"// -- FILL PACKET -- //",
"$",
"found",
"=",
"false",
";",
"// ",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"this",
"->",
"packetList",
")",
";",
"$",
"i",
"++",
")",
"// iterate Packets in Packet List",
"{",
"$",
"packet",
"=",
"$",
"this",
"->",
"getPacket",
"(",
"$",
"i",
")",
";",
"// get current Packet",
"$",
"articleVolume",
"=",
"$",
"this",
"->",
"volumes",
"[",
"$",
"packet",
"->",
"getName",
"(",
")",
"]",
"[",
"$",
"largestArticle",
"]",
";",
"// get Article Volume in this Packet",
"if",
"(",
"$",
"packet",
"->",
"hasVolumeLeft",
"(",
"$",
"articleVolume",
")",
")",
"// check if Article will fit in Packet",
"{",
"$",
"packet",
"->",
"addArticle",
"(",
"$",
"largestArticle",
",",
"$",
"articleVolume",
")",
";",
"// put Article in Packet",
"$",
"found",
"=",
"$",
"this",
"->",
"removeArticleFromList",
"(",
"$",
"articleList",
",",
"$",
"largestArticle",
")",
";",
"// remove Article From Article List",
"break",
";",
"// break Packet Loop",
"}",
"}",
"if",
"(",
"$",
"found",
")",
"// Article has been put into a Packet",
"continue",
";",
"// step to next Article",
"// -- RESIZE PACKET -- //",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"this",
"->",
"packetList",
")",
";",
"$",
"i",
"++",
")",
"// iterate Packets in Packet List",
"{",
"$",
"packet",
"=",
"$",
"this",
"->",
"getPacket",
"(",
"$",
"i",
")",
";",
"// get current Packet",
"while",
"(",
"$",
"this",
"->",
"hasLargerPacket",
"(",
"$",
"packet",
"->",
"getName",
"(",
")",
")",
")",
"// there is a larger Packet Type",
"{",
"$",
"largerPacketName",
"=",
"$",
"this",
"->",
"getNameOfLargerPacket",
"(",
"$",
"packet",
"->",
"getName",
"(",
")",
")",
";",
"$",
"articles",
"=",
"$",
"packet",
"->",
"getArticles",
"(",
")",
";",
"// get larger Packet",
"$",
"largerPacket",
"=",
"$",
"this",
"->",
"factory",
"->",
"produce",
"(",
"$",
"largerPacketName",
",",
"$",
"articles",
")",
";",
"// produce new Packet and add Articles from old Packet",
"$",
"articleVolume",
"=",
"$",
"this",
"->",
"volumes",
"[",
"$",
"largerPacketName",
"]",
"[",
"$",
"largestArticle",
"]",
";",
"// get Volume of current Article in this Packet",
"if",
"(",
"$",
"largerPacket",
"->",
"hasVolumeLeft",
"(",
"$",
"articleVolume",
")",
")",
"{",
"$",
"largerPacket",
"->",
"addArticle",
"(",
"$",
"largestArticle",
",",
"$",
"articleVolume",
")",
";",
"// add Article to Packet",
"$",
"this",
"->",
"replacePacket",
"(",
"$",
"i",
",",
"$",
"largerPacket",
")",
";",
"// replace old Packet with new Packet",
"$",
"found",
"=",
"$",
"this",
"->",
"removeArticleFromList",
"(",
"$",
"articleList",
",",
"$",
"largestArticle",
")",
";",
"// remove Article from Article List",
"break",
";",
"// break Packet Loop",
"}",
"}",
"if",
"(",
"$",
"found",
")",
"// Article has been put into a Packet",
"continue",
";",
"// break Packet Loop",
"}",
"if",
"(",
"$",
"found",
")",
"// Article has been put into a Packet",
"continue",
";",
"// step to next Article",
"// -- ADD NEW PACKET -- //",
"$",
"packetName",
"=",
"$",
"this",
"->",
"getNameOfSmallestPacketForArticle",
"(",
"$",
"largestArticle",
")",
";",
"// get smallest Packet Type for Article",
"$",
"packet",
"=",
"$",
"this",
"->",
"factory",
"->",
"produce",
"(",
"$",
"packetName",
",",
"array",
"(",
"$",
"largestArticle",
"=>",
"1",
")",
")",
";",
"// produce new Packet and put Article in",
"$",
"this",
"->",
"packetList",
"[",
"]",
"=",
"$",
"packet",
";",
"// add Packet to Packet List",
"$",
"this",
"->",
"removeArticleFromList",
"(",
"$",
"articleList",
",",
"$",
"largestArticle",
")",
";",
"// remove Article from Article List",
"}",
"return",
"$",
"this",
"->",
"packetList",
";",
"// return final Packet List with Articles",
"}"
] | Calculates Packages for Articles and returns Packet List.
@access public
@param array $articleList Array of Articles and their Quantities.
@return array | [
"Calculates",
"Packages",
"for",
"Articles",
"and",
"returns",
"Packet",
"List",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Parcel/Packer.php#L75-L142 |
36,356 | CeusMedia/Common | src/Alg/Parcel/Packer.php | Alg_Parcel_Packer.getLargestArticle | protected function getLargestArticle( $articleList )
{
$largestPacketName = $this->getNameOfLargestPacket();
$articleVolumes = $this->volumes[$largestPacketName];
asort( $articleVolumes );
$articleKeys = array_keys( $articleVolumes );
do
{
$articleName = array_pop( $articleKeys );
if( array_key_exists( $articleName, $articleList ) )
return $articleName;
}
while( $articleKeys );
} | php | protected function getLargestArticle( $articleList )
{
$largestPacketName = $this->getNameOfLargestPacket();
$articleVolumes = $this->volumes[$largestPacketName];
asort( $articleVolumes );
$articleKeys = array_keys( $articleVolumes );
do
{
$articleName = array_pop( $articleKeys );
if( array_key_exists( $articleName, $articleList ) )
return $articleName;
}
while( $articleKeys );
} | [
"protected",
"function",
"getLargestArticle",
"(",
"$",
"articleList",
")",
"{",
"$",
"largestPacketName",
"=",
"$",
"this",
"->",
"getNameOfLargestPacket",
"(",
")",
";",
"$",
"articleVolumes",
"=",
"$",
"this",
"->",
"volumes",
"[",
"$",
"largestPacketName",
"]",
";",
"asort",
"(",
"$",
"articleVolumes",
")",
";",
"$",
"articleKeys",
"=",
"array_keys",
"(",
"$",
"articleVolumes",
")",
";",
"do",
"{",
"$",
"articleName",
"=",
"array_pop",
"(",
"$",
"articleKeys",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"articleName",
",",
"$",
"articleList",
")",
")",
"return",
"$",
"articleName",
";",
"}",
"while",
"(",
"$",
"articleKeys",
")",
";",
"}"
] | Returns the largest Article from an Article List by Article Volume.
@access protected
@param array $articleList Array of Articles and their Quantities.
@return string | [
"Returns",
"the",
"largest",
"Article",
"from",
"an",
"Article",
"List",
"by",
"Article",
"Volume",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Parcel/Packer.php#L177-L190 |
36,357 | CeusMedia/Common | src/Alg/Parcel/Packer.php | Alg_Parcel_Packer.getNameOfLargerPacket | protected function getNameOfLargerPacket( $packetName )
{
$keys = array_keys( $this->packets );
$index = array_search( $packetName, $keys );
$next = array_pop( array_slice( $keys, $index + 1, 1 ) );
return $next;
} | php | protected function getNameOfLargerPacket( $packetName )
{
$keys = array_keys( $this->packets );
$index = array_search( $packetName, $keys );
$next = array_pop( array_slice( $keys, $index + 1, 1 ) );
return $next;
} | [
"protected",
"function",
"getNameOfLargerPacket",
"(",
"$",
"packetName",
")",
"{",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"packets",
")",
";",
"$",
"index",
"=",
"array_search",
"(",
"$",
"packetName",
",",
"$",
"keys",
")",
";",
"$",
"next",
"=",
"array_pop",
"(",
"array_slice",
"(",
"$",
"keys",
",",
"$",
"index",
"+",
"1",
",",
"1",
")",
")",
";",
"return",
"$",
"next",
";",
"}"
] | Returns Name of next larger Packet.
@access protected
@param string $packetName Packet Name to get next larger Packet for
@return string | [
"Returns",
"Name",
"of",
"next",
"larger",
"Packet",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Parcel/Packer.php#L198-L204 |
36,358 | CeusMedia/Common | src/Alg/Parcel/Packer.php | Alg_Parcel_Packer.getNameOfLargestPacket | protected function getNameOfLargestPacket()
{
$packets = $this->packets;
asort( $packets );
$packetName = key( array_slice( $packets, -1 ) );
return $packetName;
} | php | protected function getNameOfLargestPacket()
{
$packets = $this->packets;
asort( $packets );
$packetName = key( array_slice( $packets, -1 ) );
return $packetName;
} | [
"protected",
"function",
"getNameOfLargestPacket",
"(",
")",
"{",
"$",
"packets",
"=",
"$",
"this",
"->",
"packets",
";",
"asort",
"(",
"$",
"packets",
")",
";",
"$",
"packetName",
"=",
"key",
"(",
"array_slice",
"(",
"$",
"packets",
",",
"-",
"1",
")",
")",
";",
"return",
"$",
"packetName",
";",
"}"
] | Returns Name of largest Packet from Packet Definition.
@access protected
@return string | [
"Returns",
"Name",
"of",
"largest",
"Packet",
"from",
"Packet",
"Definition",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Parcel/Packer.php#L211-L217 |
36,359 | CeusMedia/Common | src/Alg/Parcel/Packer.php | Alg_Parcel_Packer.getNameOfSmallestPacketForArticle | protected function getNameOfSmallestPacketForArticle( $articleName )
{
foreach( array_keys( $this->packets ) as $packetName )
if( $this->volumes[$packetName][$articleName] <= 1 )
return $packetName;
} | php | protected function getNameOfSmallestPacketForArticle( $articleName )
{
foreach( array_keys( $this->packets ) as $packetName )
if( $this->volumes[$packetName][$articleName] <= 1 )
return $packetName;
} | [
"protected",
"function",
"getNameOfSmallestPacketForArticle",
"(",
"$",
"articleName",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"packets",
")",
"as",
"$",
"packetName",
")",
"if",
"(",
"$",
"this",
"->",
"volumes",
"[",
"$",
"packetName",
"]",
"[",
"$",
"articleName",
"]",
"<=",
"1",
")",
"return",
"$",
"packetName",
";",
"}"
] | Returns Name of smallest Packet for an Article.
@access protected
@param string $articleName Name of Article to get smallest Article for
@return string | [
"Returns",
"Name",
"of",
"smallest",
"Packet",
"for",
"an",
"Article",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Parcel/Packer.php#L225-L230 |
36,360 | CeusMedia/Common | src/Alg/Parcel/Packer.php | Alg_Parcel_Packer.replacePacket | public function replacePacket( $index, $packet )
{
if( !isset( $this->packetList[$index] ) )
throw new OutOfRangeException( 'Invalid Packet Index.' );
$this->packetList[$index] = $packet;
} | php | public function replacePacket( $index, $packet )
{
if( !isset( $this->packetList[$index] ) )
throw new OutOfRangeException( 'Invalid Packet Index.' );
$this->packetList[$index] = $packet;
} | [
"public",
"function",
"replacePacket",
"(",
"$",
"index",
",",
"$",
"packet",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"packetList",
"[",
"$",
"index",
"]",
")",
")",
"throw",
"new",
"OutOfRangeException",
"(",
"'Invalid Packet Index.'",
")",
";",
"$",
"this",
"->",
"packetList",
"[",
"$",
"index",
"]",
"=",
"$",
"packet",
";",
"}"
] | Replaces a Packet from current Packet List with another Packet.
@access public
@param int $index Index of Packet to replace
@param Alg_Parcel_packet $packet Packet to set for another Packet
@return void | [
"Replaces",
"a",
"Packet",
"from",
"current",
"Packet",
"List",
"with",
"another",
"Packet",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Parcel/Packer.php#L278-L283 |
36,361 | CeusMedia/Common | src/XML/OPML/FileReader.php | XML_OPML_FileReader.load | public static function load( $fileName )
{
$file = new FS_File_Reader( $fileName );
if( !$file->exists() )
throw new Exception( "File '".$fileName."' is not existing." );
$xml = $file->readString();
$parser = new XML_OPML_Parser();
return $parser->parse( $xml );
} | php | public static function load( $fileName )
{
$file = new FS_File_Reader( $fileName );
if( !$file->exists() )
throw new Exception( "File '".$fileName."' is not existing." );
$xml = $file->readString();
$parser = new XML_OPML_Parser();
return $parser->parse( $xml );
} | [
"public",
"static",
"function",
"load",
"(",
"$",
"fileName",
")",
"{",
"$",
"file",
"=",
"new",
"FS_File_Reader",
"(",
"$",
"fileName",
")",
";",
"if",
"(",
"!",
"$",
"file",
"->",
"exists",
"(",
")",
")",
"throw",
"new",
"Exception",
"(",
"\"File '\"",
".",
"$",
"fileName",
".",
"\"' is not existing.\"",
")",
";",
"$",
"xml",
"=",
"$",
"file",
"->",
"readString",
"(",
")",
";",
"$",
"parser",
"=",
"new",
"XML_OPML_Parser",
"(",
")",
";",
"return",
"$",
"parser",
"->",
"parse",
"(",
"$",
"xml",
")",
";",
"}"
] | Loads a OPML File statically.
@access public
@static
@param string $fileName URI of OPML File
@return bool | [
"Loads",
"a",
"OPML",
"File",
"statically",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/OPML/FileReader.php#L62-L70 |
36,362 | smasty/Neevo | src/Neevo/Parser.php | Parser.parse | public function parse(){
$where = $order = $group = $limit = $q = '';
$source = $this->parseSource();
if($this->stmt->getConditions())
$where = $this->parseWhere();
if($this->stmt instanceof Result && $this->stmt->getGrouping())
$group = $this->parseGrouping();
if($this->stmt->getSorting())
$order = $this->parseSorting();
$this->clauses = array($source, $where, $group, $order);
if($this->stmt->getType() === Manager::STMT_SELECT)
$q = $this->parseSelectStmt();
elseif($this->stmt->getType() === Manager::STMT_INSERT)
$q = $this->parseInsertStmt();
elseif($this->stmt->getType() === Manager::STMT_UPDATE)
$q = $this->parseUpdateStmt();
elseif($this->stmt->getType() === Manager::STMT_DELETE)
$q = $this->parseDeleteStmt();
return trim($q);
} | php | public function parse(){
$where = $order = $group = $limit = $q = '';
$source = $this->parseSource();
if($this->stmt->getConditions())
$where = $this->parseWhere();
if($this->stmt instanceof Result && $this->stmt->getGrouping())
$group = $this->parseGrouping();
if($this->stmt->getSorting())
$order = $this->parseSorting();
$this->clauses = array($source, $where, $group, $order);
if($this->stmt->getType() === Manager::STMT_SELECT)
$q = $this->parseSelectStmt();
elseif($this->stmt->getType() === Manager::STMT_INSERT)
$q = $this->parseInsertStmt();
elseif($this->stmt->getType() === Manager::STMT_UPDATE)
$q = $this->parseUpdateStmt();
elseif($this->stmt->getType() === Manager::STMT_DELETE)
$q = $this->parseDeleteStmt();
return trim($q);
} | [
"public",
"function",
"parse",
"(",
")",
"{",
"$",
"where",
"=",
"$",
"order",
"=",
"$",
"group",
"=",
"$",
"limit",
"=",
"$",
"q",
"=",
"''",
";",
"$",
"source",
"=",
"$",
"this",
"->",
"parseSource",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"stmt",
"->",
"getConditions",
"(",
")",
")",
"$",
"where",
"=",
"$",
"this",
"->",
"parseWhere",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"stmt",
"instanceof",
"Result",
"&&",
"$",
"this",
"->",
"stmt",
"->",
"getGrouping",
"(",
")",
")",
"$",
"group",
"=",
"$",
"this",
"->",
"parseGrouping",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"stmt",
"->",
"getSorting",
"(",
")",
")",
"$",
"order",
"=",
"$",
"this",
"->",
"parseSorting",
"(",
")",
";",
"$",
"this",
"->",
"clauses",
"=",
"array",
"(",
"$",
"source",
",",
"$",
"where",
",",
"$",
"group",
",",
"$",
"order",
")",
";",
"if",
"(",
"$",
"this",
"->",
"stmt",
"->",
"getType",
"(",
")",
"===",
"Manager",
"::",
"STMT_SELECT",
")",
"$",
"q",
"=",
"$",
"this",
"->",
"parseSelectStmt",
"(",
")",
";",
"elseif",
"(",
"$",
"this",
"->",
"stmt",
"->",
"getType",
"(",
")",
"===",
"Manager",
"::",
"STMT_INSERT",
")",
"$",
"q",
"=",
"$",
"this",
"->",
"parseInsertStmt",
"(",
")",
";",
"elseif",
"(",
"$",
"this",
"->",
"stmt",
"->",
"getType",
"(",
")",
"===",
"Manager",
"::",
"STMT_UPDATE",
")",
"$",
"q",
"=",
"$",
"this",
"->",
"parseUpdateStmt",
"(",
")",
";",
"elseif",
"(",
"$",
"this",
"->",
"stmt",
"->",
"getType",
"(",
")",
"===",
"Manager",
"::",
"STMT_DELETE",
")",
"$",
"q",
"=",
"$",
"this",
"->",
"parseDeleteStmt",
"(",
")",
";",
"return",
"trim",
"(",
"$",
"q",
")",
";",
"}"
] | Parses the given statement.
@return string The SQL statement | [
"Parses",
"the",
"given",
"statement",
"."
] | 3a1bf7e8ce24d453bb27dca3a9aca86852789f11 | https://github.com/smasty/Neevo/blob/3a1bf7e8ce24d453bb27dca3a9aca86852789f11/src/Neevo/Parser.php#L45-L68 |
36,363 | smasty/Neevo | src/Neevo/Parser.php | Parser.parseSelectStmt | protected function parseSelectStmt(){
$cols = $this->stmt->getColumns();
list($source, $where, $group, $order) = $this->clauses;
foreach($cols as $key => $col){
$col = preg_match('~^[\w.]+$~', $col) ? ":$col" : $col;
$cols[$key] = $this->tryDelimite($col);
}
$cols = implode(', ', $cols);
return $this->applyLimit("SELECT $cols\nFROM " . $source . $where . $group . $order);
} | php | protected function parseSelectStmt(){
$cols = $this->stmt->getColumns();
list($source, $where, $group, $order) = $this->clauses;
foreach($cols as $key => $col){
$col = preg_match('~^[\w.]+$~', $col) ? ":$col" : $col;
$cols[$key] = $this->tryDelimite($col);
}
$cols = implode(', ', $cols);
return $this->applyLimit("SELECT $cols\nFROM " . $source . $where . $group . $order);
} | [
"protected",
"function",
"parseSelectStmt",
"(",
")",
"{",
"$",
"cols",
"=",
"$",
"this",
"->",
"stmt",
"->",
"getColumns",
"(",
")",
";",
"list",
"(",
"$",
"source",
",",
"$",
"where",
",",
"$",
"group",
",",
"$",
"order",
")",
"=",
"$",
"this",
"->",
"clauses",
";",
"foreach",
"(",
"$",
"cols",
"as",
"$",
"key",
"=>",
"$",
"col",
")",
"{",
"$",
"col",
"=",
"preg_match",
"(",
"'~^[\\w.]+$~'",
",",
"$",
"col",
")",
"?",
"\":$col\"",
":",
"$",
"col",
";",
"$",
"cols",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"tryDelimite",
"(",
"$",
"col",
")",
";",
"}",
"$",
"cols",
"=",
"implode",
"(",
"', '",
",",
"$",
"cols",
")",
";",
"return",
"$",
"this",
"->",
"applyLimit",
"(",
"\"SELECT $cols\\nFROM \"",
".",
"$",
"source",
".",
"$",
"where",
".",
"$",
"group",
".",
"$",
"order",
")",
";",
"}"
] | Parses SELECT statement.
@return string | [
"Parses",
"SELECT",
"statement",
"."
] | 3a1bf7e8ce24d453bb27dca3a9aca86852789f11 | https://github.com/smasty/Neevo/blob/3a1bf7e8ce24d453bb27dca3a9aca86852789f11/src/Neevo/Parser.php#L75-L85 |
36,364 | smasty/Neevo | src/Neevo/Parser.php | Parser.parseInsertStmt | protected function parseInsertStmt(){
$cols = array();
foreach($this->escapeValue($this->stmt->getValues()) as $col => $value){
$cols[] = $this->parseFieldName($col);
$values[] = $value;
}
$data = ' (' . implode(', ', $cols) . ")\nVALUES (" . implode(', ', $values). ')';
return 'INSERT INTO ' . $this->clauses[0] . $data;
} | php | protected function parseInsertStmt(){
$cols = array();
foreach($this->escapeValue($this->stmt->getValues()) as $col => $value){
$cols[] = $this->parseFieldName($col);
$values[] = $value;
}
$data = ' (' . implode(', ', $cols) . ")\nVALUES (" . implode(', ', $values). ')';
return 'INSERT INTO ' . $this->clauses[0] . $data;
} | [
"protected",
"function",
"parseInsertStmt",
"(",
")",
"{",
"$",
"cols",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"escapeValue",
"(",
"$",
"this",
"->",
"stmt",
"->",
"getValues",
"(",
")",
")",
"as",
"$",
"col",
"=>",
"$",
"value",
")",
"{",
"$",
"cols",
"[",
"]",
"=",
"$",
"this",
"->",
"parseFieldName",
"(",
"$",
"col",
")",
";",
"$",
"values",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"$",
"data",
"=",
"' ('",
".",
"implode",
"(",
"', '",
",",
"$",
"cols",
")",
".",
"\")\\nVALUES (\"",
".",
"implode",
"(",
"', '",
",",
"$",
"values",
")",
".",
"')'",
";",
"return",
"'INSERT INTO '",
".",
"$",
"this",
"->",
"clauses",
"[",
"0",
"]",
".",
"$",
"data",
";",
"}"
] | Parses INSERT statement.
@return string | [
"Parses",
"INSERT",
"statement",
"."
] | 3a1bf7e8ce24d453bb27dca3a9aca86852789f11 | https://github.com/smasty/Neevo/blob/3a1bf7e8ce24d453bb27dca3a9aca86852789f11/src/Neevo/Parser.php#L92-L101 |
36,365 | smasty/Neevo | src/Neevo/Parser.php | Parser.parseSource | protected function parseSource(){
if(!$this->stmt instanceof Result)
return $this->escapeValue($this->stmt->getTable(), Manager::IDENTIFIER);
// Simple table
if($this->stmt->getTable() !== null){
$source = $this->escapeValue($this->stmt->getTable(), Manager::IDENTIFIER);
}
// Sub-select
else{
$subq = $this->stmt->getSource();
$alias = $this->escapeValue($subq->getAlias()
? $subq->getAlias() : '_table_', Manager::IDENTIFIER);
$source = "(\n\t" . implode("\n\t", explode("\n", $subq)) . "\n) $alias";
}
$source = $this->tryDelimite($source);
// JOINs
foreach($this->stmt->getJoins() as $key => $join){
list($join_source, $cond, $type) = $join;
// JOIN sub-select
if($join_source instanceof Result){
$join_alias = $this->escapeValue($join_source->getAlias()
? $join_source->getAlias() : '_join_' . ($key+1), Manager::IDENTIFIER);
$join_source = "(\n\t" . implode("\n\t", explode("\n", $join_source)) . "\n) $join_alias";
}
// JOIN Literal
elseif($join_source instanceof Literal){
$join_source = $join_source->value;
}
// JOIN table
elseif(is_scalar($join_source)){
$join_source = $this->parseFieldName($join_source, true);
}
$type = strtoupper(substr($type, 5));
$type .= ($type === '') ? '' : ' ';
$source .= $cond instanceof Literal
? "\n{$type}JOIN $join_source ON $cond->value"
: $this->tryDelimite("\n{$type}JOIN $join_source ON $cond");
}
return $source;
} | php | protected function parseSource(){
if(!$this->stmt instanceof Result)
return $this->escapeValue($this->stmt->getTable(), Manager::IDENTIFIER);
// Simple table
if($this->stmt->getTable() !== null){
$source = $this->escapeValue($this->stmt->getTable(), Manager::IDENTIFIER);
}
// Sub-select
else{
$subq = $this->stmt->getSource();
$alias = $this->escapeValue($subq->getAlias()
? $subq->getAlias() : '_table_', Manager::IDENTIFIER);
$source = "(\n\t" . implode("\n\t", explode("\n", $subq)) . "\n) $alias";
}
$source = $this->tryDelimite($source);
// JOINs
foreach($this->stmt->getJoins() as $key => $join){
list($join_source, $cond, $type) = $join;
// JOIN sub-select
if($join_source instanceof Result){
$join_alias = $this->escapeValue($join_source->getAlias()
? $join_source->getAlias() : '_join_' . ($key+1), Manager::IDENTIFIER);
$join_source = "(\n\t" . implode("\n\t", explode("\n", $join_source)) . "\n) $join_alias";
}
// JOIN Literal
elseif($join_source instanceof Literal){
$join_source = $join_source->value;
}
// JOIN table
elseif(is_scalar($join_source)){
$join_source = $this->parseFieldName($join_source, true);
}
$type = strtoupper(substr($type, 5));
$type .= ($type === '') ? '' : ' ';
$source .= $cond instanceof Literal
? "\n{$type}JOIN $join_source ON $cond->value"
: $this->tryDelimite("\n{$type}JOIN $join_source ON $cond");
}
return $source;
} | [
"protected",
"function",
"parseSource",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"stmt",
"instanceof",
"Result",
")",
"return",
"$",
"this",
"->",
"escapeValue",
"(",
"$",
"this",
"->",
"stmt",
"->",
"getTable",
"(",
")",
",",
"Manager",
"::",
"IDENTIFIER",
")",
";",
"// Simple table",
"if",
"(",
"$",
"this",
"->",
"stmt",
"->",
"getTable",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"source",
"=",
"$",
"this",
"->",
"escapeValue",
"(",
"$",
"this",
"->",
"stmt",
"->",
"getTable",
"(",
")",
",",
"Manager",
"::",
"IDENTIFIER",
")",
";",
"}",
"// Sub-select",
"else",
"{",
"$",
"subq",
"=",
"$",
"this",
"->",
"stmt",
"->",
"getSource",
"(",
")",
";",
"$",
"alias",
"=",
"$",
"this",
"->",
"escapeValue",
"(",
"$",
"subq",
"->",
"getAlias",
"(",
")",
"?",
"$",
"subq",
"->",
"getAlias",
"(",
")",
":",
"'_table_'",
",",
"Manager",
"::",
"IDENTIFIER",
")",
";",
"$",
"source",
"=",
"\"(\\n\\t\"",
".",
"implode",
"(",
"\"\\n\\t\"",
",",
"explode",
"(",
"\"\\n\"",
",",
"$",
"subq",
")",
")",
".",
"\"\\n) $alias\"",
";",
"}",
"$",
"source",
"=",
"$",
"this",
"->",
"tryDelimite",
"(",
"$",
"source",
")",
";",
"// JOINs",
"foreach",
"(",
"$",
"this",
"->",
"stmt",
"->",
"getJoins",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"join",
")",
"{",
"list",
"(",
"$",
"join_source",
",",
"$",
"cond",
",",
"$",
"type",
")",
"=",
"$",
"join",
";",
"// JOIN sub-select",
"if",
"(",
"$",
"join_source",
"instanceof",
"Result",
")",
"{",
"$",
"join_alias",
"=",
"$",
"this",
"->",
"escapeValue",
"(",
"$",
"join_source",
"->",
"getAlias",
"(",
")",
"?",
"$",
"join_source",
"->",
"getAlias",
"(",
")",
":",
"'_join_'",
".",
"(",
"$",
"key",
"+",
"1",
")",
",",
"Manager",
"::",
"IDENTIFIER",
")",
";",
"$",
"join_source",
"=",
"\"(\\n\\t\"",
".",
"implode",
"(",
"\"\\n\\t\"",
",",
"explode",
"(",
"\"\\n\"",
",",
"$",
"join_source",
")",
")",
".",
"\"\\n) $join_alias\"",
";",
"}",
"// JOIN Literal",
"elseif",
"(",
"$",
"join_source",
"instanceof",
"Literal",
")",
"{",
"$",
"join_source",
"=",
"$",
"join_source",
"->",
"value",
";",
"}",
"// JOIN table",
"elseif",
"(",
"is_scalar",
"(",
"$",
"join_source",
")",
")",
"{",
"$",
"join_source",
"=",
"$",
"this",
"->",
"parseFieldName",
"(",
"$",
"join_source",
",",
"true",
")",
";",
"}",
"$",
"type",
"=",
"strtoupper",
"(",
"substr",
"(",
"$",
"type",
",",
"5",
")",
")",
";",
"$",
"type",
".=",
"(",
"$",
"type",
"===",
"''",
")",
"?",
"''",
":",
"' '",
";",
"$",
"source",
".=",
"$",
"cond",
"instanceof",
"Literal",
"?",
"\"\\n{$type}JOIN $join_source ON $cond->value\"",
":",
"$",
"this",
"->",
"tryDelimite",
"(",
"\"\\n{$type}JOIN $join_source ON $cond\"",
")",
";",
"}",
"return",
"$",
"source",
";",
"}"
] | Parses statement source.
@return string | [
"Parses",
"statement",
"source",
"."
] | 3a1bf7e8ce24d453bb27dca3a9aca86852789f11 | https://github.com/smasty/Neevo/blob/3a1bf7e8ce24d453bb27dca3a9aca86852789f11/src/Neevo/Parser.php#L133-L176 |
36,366 | smasty/Neevo | src/Neevo/Parser.php | Parser.parseWhere | protected function parseWhere(){
$conds = $this->stmt->getConditions();
// Unset glue on last condition
unset($conds[count($conds)-1]['glue']);
$conditions = array();
foreach($conds as $cond){
// Conditions with modifiers
if($cond['simple'] === false){
$values = $this->escapeValue($cond['values'], $cond['types']);
$s = '(' . $this->applyModifiers($cond['expr'], $cond['modifiers'], $values) . ')';
if(isset($cond['glue']))
$s .= ' ' . $cond['glue'];
$conditions[] = $s;
continue;
}
// Simple conditions
$field = $this->parseFieldName($cond['field']);
$operator = '';
$value = $cond['value'];
if($value === null){ // field IS NULL
$value = ' IS NULL';
} elseif($value === true){ // field
$value = '';
} elseif($value === false){ // NOT field
$value = $field;
$field = 'NOT ';
} elseif($value instanceof Result){
$operator = ' IN ';
$value = $this->escapeValue($value, Manager::SUBQUERY);
} elseif(is_array($value) || $value instanceof Traversable){ // field IN (array)
$value = ' IN ' . $this->escapeValue($value, Manager::ARR);
} elseif($value instanceof Literal){ // field = SQL literal
$operator = ' = ';
$value = $this->escapeValue($value, Manager::LITERAL);
} elseif($value instanceof DateTime){ // field = DateTime
$operator = ' = ';
$value = $this->escapeValue($value, Manager::DATETIME);
} else{ // field = value
$operator = ' = ';
$value = $this->escapeValue($value);
}
$s = '(' . $field . $operator . $value . ')';
if(isset($cond['glue']))
$s .= ' '.$cond['glue'];
$conditions[] = $s;
}
return "\nWHERE " . implode(' ', $conditions);
} | php | protected function parseWhere(){
$conds = $this->stmt->getConditions();
// Unset glue on last condition
unset($conds[count($conds)-1]['glue']);
$conditions = array();
foreach($conds as $cond){
// Conditions with modifiers
if($cond['simple'] === false){
$values = $this->escapeValue($cond['values'], $cond['types']);
$s = '(' . $this->applyModifiers($cond['expr'], $cond['modifiers'], $values) . ')';
if(isset($cond['glue']))
$s .= ' ' . $cond['glue'];
$conditions[] = $s;
continue;
}
// Simple conditions
$field = $this->parseFieldName($cond['field']);
$operator = '';
$value = $cond['value'];
if($value === null){ // field IS NULL
$value = ' IS NULL';
} elseif($value === true){ // field
$value = '';
} elseif($value === false){ // NOT field
$value = $field;
$field = 'NOT ';
} elseif($value instanceof Result){
$operator = ' IN ';
$value = $this->escapeValue($value, Manager::SUBQUERY);
} elseif(is_array($value) || $value instanceof Traversable){ // field IN (array)
$value = ' IN ' . $this->escapeValue($value, Manager::ARR);
} elseif($value instanceof Literal){ // field = SQL literal
$operator = ' = ';
$value = $this->escapeValue($value, Manager::LITERAL);
} elseif($value instanceof DateTime){ // field = DateTime
$operator = ' = ';
$value = $this->escapeValue($value, Manager::DATETIME);
} else{ // field = value
$operator = ' = ';
$value = $this->escapeValue($value);
}
$s = '(' . $field . $operator . $value . ')';
if(isset($cond['glue']))
$s .= ' '.$cond['glue'];
$conditions[] = $s;
}
return "\nWHERE " . implode(' ', $conditions);
} | [
"protected",
"function",
"parseWhere",
"(",
")",
"{",
"$",
"conds",
"=",
"$",
"this",
"->",
"stmt",
"->",
"getConditions",
"(",
")",
";",
"// Unset glue on last condition",
"unset",
"(",
"$",
"conds",
"[",
"count",
"(",
"$",
"conds",
")",
"-",
"1",
"]",
"[",
"'glue'",
"]",
")",
";",
"$",
"conditions",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"conds",
"as",
"$",
"cond",
")",
"{",
"// Conditions with modifiers",
"if",
"(",
"$",
"cond",
"[",
"'simple'",
"]",
"===",
"false",
")",
"{",
"$",
"values",
"=",
"$",
"this",
"->",
"escapeValue",
"(",
"$",
"cond",
"[",
"'values'",
"]",
",",
"$",
"cond",
"[",
"'types'",
"]",
")",
";",
"$",
"s",
"=",
"'('",
".",
"$",
"this",
"->",
"applyModifiers",
"(",
"$",
"cond",
"[",
"'expr'",
"]",
",",
"$",
"cond",
"[",
"'modifiers'",
"]",
",",
"$",
"values",
")",
".",
"')'",
";",
"if",
"(",
"isset",
"(",
"$",
"cond",
"[",
"'glue'",
"]",
")",
")",
"$",
"s",
".=",
"' '",
".",
"$",
"cond",
"[",
"'glue'",
"]",
";",
"$",
"conditions",
"[",
"]",
"=",
"$",
"s",
";",
"continue",
";",
"}",
"// Simple conditions",
"$",
"field",
"=",
"$",
"this",
"->",
"parseFieldName",
"(",
"$",
"cond",
"[",
"'field'",
"]",
")",
";",
"$",
"operator",
"=",
"''",
";",
"$",
"value",
"=",
"$",
"cond",
"[",
"'value'",
"]",
";",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"// field IS NULL",
"$",
"value",
"=",
"' IS NULL'",
";",
"}",
"elseif",
"(",
"$",
"value",
"===",
"true",
")",
"{",
"// field",
"$",
"value",
"=",
"''",
";",
"}",
"elseif",
"(",
"$",
"value",
"===",
"false",
")",
"{",
"// NOT field",
"$",
"value",
"=",
"$",
"field",
";",
"$",
"field",
"=",
"'NOT '",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"Result",
")",
"{",
"$",
"operator",
"=",
"' IN '",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"escapeValue",
"(",
"$",
"value",
",",
"Manager",
"::",
"SUBQUERY",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"value",
")",
"||",
"$",
"value",
"instanceof",
"Traversable",
")",
"{",
"// field IN (array)",
"$",
"value",
"=",
"' IN '",
".",
"$",
"this",
"->",
"escapeValue",
"(",
"$",
"value",
",",
"Manager",
"::",
"ARR",
")",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"Literal",
")",
"{",
"// field = SQL literal",
"$",
"operator",
"=",
"' = '",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"escapeValue",
"(",
"$",
"value",
",",
"Manager",
"::",
"LITERAL",
")",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"DateTime",
")",
"{",
"// field = DateTime",
"$",
"operator",
"=",
"' = '",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"escapeValue",
"(",
"$",
"value",
",",
"Manager",
"::",
"DATETIME",
")",
";",
"}",
"else",
"{",
"// field = value",
"$",
"operator",
"=",
"' = '",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"escapeValue",
"(",
"$",
"value",
")",
";",
"}",
"$",
"s",
"=",
"'('",
".",
"$",
"field",
".",
"$",
"operator",
".",
"$",
"value",
".",
"')'",
";",
"if",
"(",
"isset",
"(",
"$",
"cond",
"[",
"'glue'",
"]",
")",
")",
"$",
"s",
".=",
"' '",
".",
"$",
"cond",
"[",
"'glue'",
"]",
";",
"$",
"conditions",
"[",
"]",
"=",
"$",
"s",
";",
"}",
"return",
"\"\\nWHERE \"",
".",
"implode",
"(",
"' '",
",",
"$",
"conditions",
")",
";",
"}"
] | Parses WHERE clause.
@return string | [
"Parses",
"WHERE",
"clause",
"."
] | 3a1bf7e8ce24d453bb27dca3a9aca86852789f11 | https://github.com/smasty/Neevo/blob/3a1bf7e8ce24d453bb27dca3a9aca86852789f11/src/Neevo/Parser.php#L183-L238 |
36,367 | smasty/Neevo | src/Neevo/Parser.php | Parser.parseSorting | protected function parseSorting(){
$order = array();
foreach($this->stmt->getSorting() as $rule){
list($field, $type) = $rule;
$order[] = $this->tryDelimite($field) . ($type !== null ? ' ' . $type : '');
}
return "\nORDER BY " . implode(', ', $order);
} | php | protected function parseSorting(){
$order = array();
foreach($this->stmt->getSorting() as $rule){
list($field, $type) = $rule;
$order[] = $this->tryDelimite($field) . ($type !== null ? ' ' . $type : '');
}
return "\nORDER BY " . implode(', ', $order);
} | [
"protected",
"function",
"parseSorting",
"(",
")",
"{",
"$",
"order",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"stmt",
"->",
"getSorting",
"(",
")",
"as",
"$",
"rule",
")",
"{",
"list",
"(",
"$",
"field",
",",
"$",
"type",
")",
"=",
"$",
"rule",
";",
"$",
"order",
"[",
"]",
"=",
"$",
"this",
"->",
"tryDelimite",
"(",
"$",
"field",
")",
".",
"(",
"$",
"type",
"!==",
"null",
"?",
"' '",
".",
"$",
"type",
":",
"''",
")",
";",
"}",
"return",
"\"\\nORDER BY \"",
".",
"implode",
"(",
"', '",
",",
"$",
"order",
")",
";",
"}"
] | Parses ORDER BY clause.
@return string | [
"Parses",
"ORDER",
"BY",
"clause",
"."
] | 3a1bf7e8ce24d453bb27dca3a9aca86852789f11 | https://github.com/smasty/Neevo/blob/3a1bf7e8ce24d453bb27dca3a9aca86852789f11/src/Neevo/Parser.php#L245-L252 |
36,368 | smasty/Neevo | src/Neevo/Parser.php | Parser.parseGrouping | protected function parseGrouping(){
list($group, $having) = $this->stmt->getGrouping();
return $this->tryDelimite("\nGROUP BY $group" . ($having !== null ? " HAVING $having" : ''));
} | php | protected function parseGrouping(){
list($group, $having) = $this->stmt->getGrouping();
return $this->tryDelimite("\nGROUP BY $group" . ($having !== null ? " HAVING $having" : ''));
} | [
"protected",
"function",
"parseGrouping",
"(",
")",
"{",
"list",
"(",
"$",
"group",
",",
"$",
"having",
")",
"=",
"$",
"this",
"->",
"stmt",
"->",
"getGrouping",
"(",
")",
";",
"return",
"$",
"this",
"->",
"tryDelimite",
"(",
"\"\\nGROUP BY $group\"",
".",
"(",
"$",
"having",
"!==",
"null",
"?",
"\" HAVING $having\"",
":",
"''",
")",
")",
";",
"}"
] | Parses GROUP BY clause.
@return string | [
"Parses",
"GROUP",
"BY",
"clause",
"."
] | 3a1bf7e8ce24d453bb27dca3a9aca86852789f11 | https://github.com/smasty/Neevo/blob/3a1bf7e8ce24d453bb27dca3a9aca86852789f11/src/Neevo/Parser.php#L259-L262 |
36,369 | smasty/Neevo | src/Neevo/Parser.php | Parser.parseFieldName | protected function parseFieldName($field, $table = false){
// preg_replace callback behaviour
if(is_array($field))
$field = $field[0];
if($field instanceof Literal)
return $field->value;
$field = trim($field);
if($field === '*')
return $field;
if(strpos($field, ' '))
return $field;
$field = str_replace(':', '', $field);
if(strpos($field, '.') !== false || $table === true){
$prefix = $this->stmt->getConnection()->getPrefix();
$field = $prefix . $field;
}
return $this->stmt->getConnection()->getDriver()->escape($field, Manager::IDENTIFIER);
} | php | protected function parseFieldName($field, $table = false){
// preg_replace callback behaviour
if(is_array($field))
$field = $field[0];
if($field instanceof Literal)
return $field->value;
$field = trim($field);
if($field === '*')
return $field;
if(strpos($field, ' '))
return $field;
$field = str_replace(':', '', $field);
if(strpos($field, '.') !== false || $table === true){
$prefix = $this->stmt->getConnection()->getPrefix();
$field = $prefix . $field;
}
return $this->stmt->getConnection()->getDriver()->escape($field, Manager::IDENTIFIER);
} | [
"protected",
"function",
"parseFieldName",
"(",
"$",
"field",
",",
"$",
"table",
"=",
"false",
")",
"{",
"// preg_replace callback behaviour",
"if",
"(",
"is_array",
"(",
"$",
"field",
")",
")",
"$",
"field",
"=",
"$",
"field",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"field",
"instanceof",
"Literal",
")",
"return",
"$",
"field",
"->",
"value",
";",
"$",
"field",
"=",
"trim",
"(",
"$",
"field",
")",
";",
"if",
"(",
"$",
"field",
"===",
"'*'",
")",
"return",
"$",
"field",
";",
"if",
"(",
"strpos",
"(",
"$",
"field",
",",
"' '",
")",
")",
"return",
"$",
"field",
";",
"$",
"field",
"=",
"str_replace",
"(",
"':'",
",",
"''",
",",
"$",
"field",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"field",
",",
"'.'",
")",
"!==",
"false",
"||",
"$",
"table",
"===",
"true",
")",
"{",
"$",
"prefix",
"=",
"$",
"this",
"->",
"stmt",
"->",
"getConnection",
"(",
")",
"->",
"getPrefix",
"(",
")",
";",
"$",
"field",
"=",
"$",
"prefix",
".",
"$",
"field",
";",
"}",
"return",
"$",
"this",
"->",
"stmt",
"->",
"getConnection",
"(",
")",
"->",
"getDriver",
"(",
")",
"->",
"escape",
"(",
"$",
"field",
",",
"Manager",
"::",
"IDENTIFIER",
")",
";",
"}"
] | Parses column name.
@param string|array|Literal $field
@param bool $table Parse table name.
@return string | [
"Parses",
"column",
"name",
"."
] | 3a1bf7e8ce24d453bb27dca3a9aca86852789f11 | https://github.com/smasty/Neevo/blob/3a1bf7e8ce24d453bb27dca3a9aca86852789f11/src/Neevo/Parser.php#L271-L294 |
36,370 | smasty/Neevo | src/Neevo/Parser.php | Parser.applyModifiers | protected function applyModifiers($expr, array $modifiers, array $values){
foreach($modifiers as &$mod){
$mod = preg_quote("/$mod/");
}
$expr = $this->tryDelimite($expr);
return preg_replace($modifiers, $values, $expr, 1);
} | php | protected function applyModifiers($expr, array $modifiers, array $values){
foreach($modifiers as &$mod){
$mod = preg_quote("/$mod/");
}
$expr = $this->tryDelimite($expr);
return preg_replace($modifiers, $values, $expr, 1);
} | [
"protected",
"function",
"applyModifiers",
"(",
"$",
"expr",
",",
"array",
"$",
"modifiers",
",",
"array",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"modifiers",
"as",
"&",
"$",
"mod",
")",
"{",
"$",
"mod",
"=",
"preg_quote",
"(",
"\"/$mod/\"",
")",
";",
"}",
"$",
"expr",
"=",
"$",
"this",
"->",
"tryDelimite",
"(",
"$",
"expr",
")",
";",
"return",
"preg_replace",
"(",
"$",
"modifiers",
",",
"$",
"values",
",",
"$",
"expr",
",",
"1",
")",
";",
"}"
] | Applies modifiers to expression.
@param string $expr
@param array $modifiers
@param array $values
@return string | [
"Applies",
"modifiers",
"to",
"expression",
"."
] | 3a1bf7e8ce24d453bb27dca3a9aca86852789f11 | https://github.com/smasty/Neevo/blob/3a1bf7e8ce24d453bb27dca3a9aca86852789f11/src/Neevo/Parser.php#L383-L389 |
36,371 | CeusMedia/Common | src/UI/HTML/Tree/FolderView.php | UI_HTML_Tree_FolderView.getHtml | public function getHtml( $currentId, $attributes = array(), $linkNodes = FALSE, $classNode = "folder", $classLeaf = "file" )
{
$nodes = new ArrayObject();
$this->readRecursive( $this->path, $currentId, $nodes, $linkNodes, $classNode, $classLeaf );
return $this->view->constructTree( $nodes, $currentId, $attributes );
} | php | public function getHtml( $currentId, $attributes = array(), $linkNodes = FALSE, $classNode = "folder", $classLeaf = "file" )
{
$nodes = new ArrayObject();
$this->readRecursive( $this->path, $currentId, $nodes, $linkNodes, $classNode, $classLeaf );
return $this->view->constructTree( $nodes, $currentId, $attributes );
} | [
"public",
"function",
"getHtml",
"(",
"$",
"currentId",
",",
"$",
"attributes",
"=",
"array",
"(",
")",
",",
"$",
"linkNodes",
"=",
"FALSE",
",",
"$",
"classNode",
"=",
"\"folder\"",
",",
"$",
"classLeaf",
"=",
"\"file\"",
")",
"{",
"$",
"nodes",
"=",
"new",
"ArrayObject",
"(",
")",
";",
"$",
"this",
"->",
"readRecursive",
"(",
"$",
"this",
"->",
"path",
",",
"$",
"currentId",
",",
"$",
"nodes",
",",
"$",
"linkNodes",
",",
"$",
"classNode",
",",
"$",
"classLeaf",
")",
";",
"return",
"$",
"this",
"->",
"view",
"->",
"constructTree",
"(",
"$",
"nodes",
",",
"$",
"currentId",
",",
"$",
"attributes",
")",
";",
"}"
] | Returns HTML Code of Tree.
@access public
@param string $currentId ID current selected in Tree
@param array $attributes Attributes for List Tag
@param string $linkNodes Link Nodes (no Icons possible)
@param string $classNode CSS Class of Nodes / Folders
@param string $classLeaf CSS Class of Leafes / Files
@return string | [
"Returns",
"HTML",
"Code",
"of",
"Tree",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/Tree/FolderView.php#L72-L77 |
36,372 | CeusMedia/Common | src/UI/HTML/Tree/FolderView.php | UI_HTML_Tree_FolderView.getScript | public function getScript( $selector, $cookieId = NULL, $animated = "fast", $unique = FALSE, $collapsed = FALSE )
{
return $this->view->buildJavaScript( $selector, $cookieId, $animated, $unique, $collapsed );
} | php | public function getScript( $selector, $cookieId = NULL, $animated = "fast", $unique = FALSE, $collapsed = FALSE )
{
return $this->view->buildJavaScript( $selector, $cookieId, $animated, $unique, $collapsed );
} | [
"public",
"function",
"getScript",
"(",
"$",
"selector",
",",
"$",
"cookieId",
"=",
"NULL",
",",
"$",
"animated",
"=",
"\"fast\"",
",",
"$",
"unique",
"=",
"FALSE",
",",
"$",
"collapsed",
"=",
"FALSE",
")",
"{",
"return",
"$",
"this",
"->",
"view",
"->",
"buildJavaScript",
"(",
"$",
"selector",
",",
"$",
"cookieId",
",",
"$",
"animated",
",",
"$",
"unique",
",",
"$",
"collapsed",
")",
";",
"}"
] | Returns JavaScript Code to call Plugin.
@access public
@param string $selector JQuery Selector of Tree
@param string $cookieId Store Tree in Cookie
@param string $animated Speed of Animation (fast|slow)
@param bool $unique Flag: open only 1 Node in every Level
@param bool $collapsed Flag: start with collapsed Nodes
@return string | [
"Returns",
"JavaScript",
"Code",
"to",
"call",
"Plugin",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/Tree/FolderView.php#L89-L92 |
36,373 | CeusMedia/Common | src/UI/HTML/Tree/FolderView.php | UI_HTML_Tree_FolderView.readRecursive | protected function readRecursive( $path, $currentId, &$nodes, $linkNodes, $classNode = "folder", $classLeaf = "file" )
{
$files = array();
$index = new DirectoryIterator( $path );
foreach( $index as $file )
{
if( $file->isDot() )
continue;
if( preg_match( "@^\.\w@", $file->getFilename() ) )
continue;
if( $file->isDir() )
{
$children = array();
$this->readRecursive( $file->getPathname(), $currentId, $children, $linkNodes, $classNode, $classLeaf );
$dir = array(
'label' => basename( $file->getPathname() ),
'type' => "node",
'class' => $classNode,
'linked' => $linkNodes,
'children' => $children,
);
$nodes[] = $dir;
}
else
{
$classes = array();
$info = pathinfo( $file->getFilename() );
if( $classLeaf )
$classes[] = $classLeaf;
if( isset( $info['extension'] ) )
$classes[] = "file-".strtolower( $info['extension'] );
$classes = implode( " ", $classes );
$files[] = array(
'label' => $file->getFilename(),
'type' => "leaf",
'class' => $classes,
'linked' => TRUE,
);
}
}
foreach( $files as $file )
$nodes[] = $file;
} | php | protected function readRecursive( $path, $currentId, &$nodes, $linkNodes, $classNode = "folder", $classLeaf = "file" )
{
$files = array();
$index = new DirectoryIterator( $path );
foreach( $index as $file )
{
if( $file->isDot() )
continue;
if( preg_match( "@^\.\w@", $file->getFilename() ) )
continue;
if( $file->isDir() )
{
$children = array();
$this->readRecursive( $file->getPathname(), $currentId, $children, $linkNodes, $classNode, $classLeaf );
$dir = array(
'label' => basename( $file->getPathname() ),
'type' => "node",
'class' => $classNode,
'linked' => $linkNodes,
'children' => $children,
);
$nodes[] = $dir;
}
else
{
$classes = array();
$info = pathinfo( $file->getFilename() );
if( $classLeaf )
$classes[] = $classLeaf;
if( isset( $info['extension'] ) )
$classes[] = "file-".strtolower( $info['extension'] );
$classes = implode( " ", $classes );
$files[] = array(
'label' => $file->getFilename(),
'type' => "leaf",
'class' => $classes,
'linked' => TRUE,
);
}
}
foreach( $files as $file )
$nodes[] = $file;
} | [
"protected",
"function",
"readRecursive",
"(",
"$",
"path",
",",
"$",
"currentId",
",",
"&",
"$",
"nodes",
",",
"$",
"linkNodes",
",",
"$",
"classNode",
"=",
"\"folder\"",
",",
"$",
"classLeaf",
"=",
"\"file\"",
")",
"{",
"$",
"files",
"=",
"array",
"(",
")",
";",
"$",
"index",
"=",
"new",
"DirectoryIterator",
"(",
"$",
"path",
")",
";",
"foreach",
"(",
"$",
"index",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"->",
"isDot",
"(",
")",
")",
"continue",
";",
"if",
"(",
"preg_match",
"(",
"\"@^\\.\\w@\"",
",",
"$",
"file",
"->",
"getFilename",
"(",
")",
")",
")",
"continue",
";",
"if",
"(",
"$",
"file",
"->",
"isDir",
"(",
")",
")",
"{",
"$",
"children",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"readRecursive",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
",",
"$",
"currentId",
",",
"$",
"children",
",",
"$",
"linkNodes",
",",
"$",
"classNode",
",",
"$",
"classLeaf",
")",
";",
"$",
"dir",
"=",
"array",
"(",
"'label'",
"=>",
"basename",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
",",
"'type'",
"=>",
"\"node\"",
",",
"'class'",
"=>",
"$",
"classNode",
",",
"'linked'",
"=>",
"$",
"linkNodes",
",",
"'children'",
"=>",
"$",
"children",
",",
")",
";",
"$",
"nodes",
"[",
"]",
"=",
"$",
"dir",
";",
"}",
"else",
"{",
"$",
"classes",
"=",
"array",
"(",
")",
";",
"$",
"info",
"=",
"pathinfo",
"(",
"$",
"file",
"->",
"getFilename",
"(",
")",
")",
";",
"if",
"(",
"$",
"classLeaf",
")",
"$",
"classes",
"[",
"]",
"=",
"$",
"classLeaf",
";",
"if",
"(",
"isset",
"(",
"$",
"info",
"[",
"'extension'",
"]",
")",
")",
"$",
"classes",
"[",
"]",
"=",
"\"file-\"",
".",
"strtolower",
"(",
"$",
"info",
"[",
"'extension'",
"]",
")",
";",
"$",
"classes",
"=",
"implode",
"(",
"\" \"",
",",
"$",
"classes",
")",
";",
"$",
"files",
"[",
"]",
"=",
"array",
"(",
"'label'",
"=>",
"$",
"file",
"->",
"getFilename",
"(",
")",
",",
"'type'",
"=>",
"\"leaf\"",
",",
"'class'",
"=>",
"$",
"classes",
",",
"'linked'",
"=>",
"TRUE",
",",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"$",
"nodes",
"[",
"]",
"=",
"$",
"file",
";",
"}"
] | Reads Folder recursive.
@access protected
@param string $path Path to Folder to index
@param string $currentId ID current selected in Tree
@param ArrayObject $nodes Array Object of Folders and Files
@param string $linkNodes Link Nodes (no Icons possible)
@param string $classNode CSS Class of Nodes / Folders
@param string $classLeaf CSS Class of Leafes / Files
@return void | [
"Reads",
"Folder",
"recursive",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/Tree/FolderView.php#L105-L147 |
36,374 | CeusMedia/Common | src/FS/File/CSS/Combiner.php | FS_File_CSS_Combiner.combineFile | public function combineFile( $fileUri )
{
$pathName = dirname( realpath( $fileUri ) )."/";
$fileBase = preg_replace( "@\.css@", "", basename( $fileUri ));
if( !file_exists( $fileUri ) )
throw new Exception( "Style File '".$fileUri."' is not existing." );
$this->statistics = array();
$content = file_get_contents( $fileUri );
$content = $this->combineString( $pathName, $content );
$fileName = $this->prefix.$fileBase.$this->suffix.".css";
$fileUri = $pathName.$fileName;
$fileUri = str_replace( "\\", "/", $fileUri );
file_put_contents( $fileUri, $content );
return $fileUri;
} | php | public function combineFile( $fileUri )
{
$pathName = dirname( realpath( $fileUri ) )."/";
$fileBase = preg_replace( "@\.css@", "", basename( $fileUri ));
if( !file_exists( $fileUri ) )
throw new Exception( "Style File '".$fileUri."' is not existing." );
$this->statistics = array();
$content = file_get_contents( $fileUri );
$content = $this->combineString( $pathName, $content );
$fileName = $this->prefix.$fileBase.$this->suffix.".css";
$fileUri = $pathName.$fileName;
$fileUri = str_replace( "\\", "/", $fileUri );
file_put_contents( $fileUri, $content );
return $fileUri;
} | [
"public",
"function",
"combineFile",
"(",
"$",
"fileUri",
")",
"{",
"$",
"pathName",
"=",
"dirname",
"(",
"realpath",
"(",
"$",
"fileUri",
")",
")",
".",
"\"/\"",
";",
"$",
"fileBase",
"=",
"preg_replace",
"(",
"\"@\\.css@\"",
",",
"\"\"",
",",
"basename",
"(",
"$",
"fileUri",
")",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"fileUri",
")",
")",
"throw",
"new",
"Exception",
"(",
"\"Style File '\"",
".",
"$",
"fileUri",
".",
"\"' is not existing.\"",
")",
";",
"$",
"this",
"->",
"statistics",
"=",
"array",
"(",
")",
";",
"$",
"content",
"=",
"file_get_contents",
"(",
"$",
"fileUri",
")",
";",
"$",
"content",
"=",
"$",
"this",
"->",
"combineString",
"(",
"$",
"pathName",
",",
"$",
"content",
")",
";",
"$",
"fileName",
"=",
"$",
"this",
"->",
"prefix",
".",
"$",
"fileBase",
".",
"$",
"this",
"->",
"suffix",
".",
"\".css\"",
";",
"$",
"fileUri",
"=",
"$",
"pathName",
".",
"$",
"fileName",
";",
"$",
"fileUri",
"=",
"str_replace",
"(",
"\"\\\\\"",
",",
"\"/\"",
",",
"$",
"fileUri",
")",
";",
"file_put_contents",
"(",
"$",
"fileUri",
",",
"$",
"content",
")",
";",
"return",
"$",
"fileUri",
";",
"}"
] | Combines all CSS Files imported in Style File, saves Combination File and returns File URI of Combination File.
@access public
@param string $styleFile File Name of Style without Extension (iE. style.css,import.css,default.css)
@param bool $verbose Flag: list loaded CSS Files
@return string | [
"Combines",
"all",
"CSS",
"Files",
"imported",
"in",
"Style",
"File",
"saves",
"Combination",
"File",
"and",
"returns",
"File",
"URI",
"of",
"Combination",
"File",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/CSS/Combiner.php#L58-L76 |
36,375 | CeusMedia/Common | src/FS/File/CSS/Combiner.php | FS_File_CSS_Combiner.combineString | public function combineString( $path, $content, $throwException = FALSE )
{
$listLines = array();
$listImport = array();
$this->statistics['sizeOriginal'] = 0;
$this->statistics['sizeCombined'] = 0;
$this->statistics['sizeCompressed'] = 0;
$this->statistics['numberFiles'] = 0;
$this->statistics['filesFound'] = array();
$this->statistics['filesSkipped'] = array();
$content = preg_replace( '/\/\*.+\*\//sU', '', $content );
$lines = explode( "\n", $content );
foreach( $lines as $line )
{
$line = trim( $line );
if( !$line )
continue;
if( preg_match( $this->importPattern, $line ) )
{
preg_match_all( $this->importPattern, $line, $matches );
$fileName = $matches[2][0];
$this->statistics['filesFound'][] = $fileName;
if( !file_exists( $path.$fileName ) )
{
if( $throwException )
throw new RuntimeException( 'CSS File "'.$fileName.'" is not existing.' );
$this->statistics['filesSkipped'][] = $fileName;
continue;
}
$content = file_get_contents( $path.$fileName );
$content = $this->reviseStyle( $content );
$this->statistics['numberFiles'] ++;
$this->statistics['sizeOriginal'] += strlen( $content );
// $depth = substr
if( substr_count( $fileName, "/" ) )
$content = preg_replace( "@(\.\./){1}([^\.])@i", "\\2", $content );
$listImport[] = "/* -- ".$fileName." -- */";
$listImport[] = $content."\n";
}
else
$listLines[] = $line;
}
$content = implode( "\n", $listImport ).implode( "\n", $listLines );
$this->statistics['sizeCombined'] = strlen( $content );
return $content;
} | php | public function combineString( $path, $content, $throwException = FALSE )
{
$listLines = array();
$listImport = array();
$this->statistics['sizeOriginal'] = 0;
$this->statistics['sizeCombined'] = 0;
$this->statistics['sizeCompressed'] = 0;
$this->statistics['numberFiles'] = 0;
$this->statistics['filesFound'] = array();
$this->statistics['filesSkipped'] = array();
$content = preg_replace( '/\/\*.+\*\//sU', '', $content );
$lines = explode( "\n", $content );
foreach( $lines as $line )
{
$line = trim( $line );
if( !$line )
continue;
if( preg_match( $this->importPattern, $line ) )
{
preg_match_all( $this->importPattern, $line, $matches );
$fileName = $matches[2][0];
$this->statistics['filesFound'][] = $fileName;
if( !file_exists( $path.$fileName ) )
{
if( $throwException )
throw new RuntimeException( 'CSS File "'.$fileName.'" is not existing.' );
$this->statistics['filesSkipped'][] = $fileName;
continue;
}
$content = file_get_contents( $path.$fileName );
$content = $this->reviseStyle( $content );
$this->statistics['numberFiles'] ++;
$this->statistics['sizeOriginal'] += strlen( $content );
// $depth = substr
if( substr_count( $fileName, "/" ) )
$content = preg_replace( "@(\.\./){1}([^\.])@i", "\\2", $content );
$listImport[] = "/* -- ".$fileName." -- */";
$listImport[] = $content."\n";
}
else
$listLines[] = $line;
}
$content = implode( "\n", $listImport ).implode( "\n", $listLines );
$this->statistics['sizeCombined'] = strlen( $content );
return $content;
} | [
"public",
"function",
"combineString",
"(",
"$",
"path",
",",
"$",
"content",
",",
"$",
"throwException",
"=",
"FALSE",
")",
"{",
"$",
"listLines",
"=",
"array",
"(",
")",
";",
"$",
"listImport",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"statistics",
"[",
"'sizeOriginal'",
"]",
"=",
"0",
";",
"$",
"this",
"->",
"statistics",
"[",
"'sizeCombined'",
"]",
"=",
"0",
";",
"$",
"this",
"->",
"statistics",
"[",
"'sizeCompressed'",
"]",
"=",
"0",
";",
"$",
"this",
"->",
"statistics",
"[",
"'numberFiles'",
"]",
"=",
"0",
";",
"$",
"this",
"->",
"statistics",
"[",
"'filesFound'",
"]",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"statistics",
"[",
"'filesSkipped'",
"]",
"=",
"array",
"(",
")",
";",
"$",
"content",
"=",
"preg_replace",
"(",
"'/\\/\\*.+\\*\\//sU'",
",",
"''",
",",
"$",
"content",
")",
";",
"$",
"lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"content",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"$",
"line",
"=",
"trim",
"(",
"$",
"line",
")",
";",
"if",
"(",
"!",
"$",
"line",
")",
"continue",
";",
"if",
"(",
"preg_match",
"(",
"$",
"this",
"->",
"importPattern",
",",
"$",
"line",
")",
")",
"{",
"preg_match_all",
"(",
"$",
"this",
"->",
"importPattern",
",",
"$",
"line",
",",
"$",
"matches",
")",
";",
"$",
"fileName",
"=",
"$",
"matches",
"[",
"2",
"]",
"[",
"0",
"]",
";",
"$",
"this",
"->",
"statistics",
"[",
"'filesFound'",
"]",
"[",
"]",
"=",
"$",
"fileName",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
".",
"$",
"fileName",
")",
")",
"{",
"if",
"(",
"$",
"throwException",
")",
"throw",
"new",
"RuntimeException",
"(",
"'CSS File \"'",
".",
"$",
"fileName",
".",
"'\" is not existing.'",
")",
";",
"$",
"this",
"->",
"statistics",
"[",
"'filesSkipped'",
"]",
"[",
"]",
"=",
"$",
"fileName",
";",
"continue",
";",
"}",
"$",
"content",
"=",
"file_get_contents",
"(",
"$",
"path",
".",
"$",
"fileName",
")",
";",
"$",
"content",
"=",
"$",
"this",
"->",
"reviseStyle",
"(",
"$",
"content",
")",
";",
"$",
"this",
"->",
"statistics",
"[",
"'numberFiles'",
"]",
"++",
";",
"$",
"this",
"->",
"statistics",
"[",
"'sizeOriginal'",
"]",
"+=",
"strlen",
"(",
"$",
"content",
")",
";",
"//\t\t\t$depth\t= substr",
"if",
"(",
"substr_count",
"(",
"$",
"fileName",
",",
"\"/\"",
")",
")",
"$",
"content",
"=",
"preg_replace",
"(",
"\"@(\\.\\./){1}([^\\.])@i\"",
",",
"\"\\\\2\"",
",",
"$",
"content",
")",
";",
"$",
"listImport",
"[",
"]",
"=",
"\"/* -- \"",
".",
"$",
"fileName",
".",
"\" -- */\"",
";",
"$",
"listImport",
"[",
"]",
"=",
"$",
"content",
".",
"\"\\n\"",
";",
"}",
"else",
"$",
"listLines",
"[",
"]",
"=",
"$",
"line",
";",
"}",
"$",
"content",
"=",
"implode",
"(",
"\"\\n\"",
",",
"$",
"listImport",
")",
".",
"implode",
"(",
"\"\\n\"",
",",
"$",
"listLines",
")",
";",
"$",
"this",
"->",
"statistics",
"[",
"'sizeCombined'",
"]",
"=",
"strlen",
"(",
"$",
"content",
")",
";",
"return",
"$",
"content",
";",
"}"
] | Combines all CSS Files imported in CSS String and returns Combination String;
@access public
@param string $path Style Path
@param string $styleFile File Name of Style without Extension (iE. style.css,import.css,default.css)
@return string | [
"Combines",
"all",
"CSS",
"Files",
"imported",
"in",
"CSS",
"String",
"and",
"returns",
"Combination",
"String",
";"
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/CSS/Combiner.php#L85-L132 |
36,376 | CeusMedia/Common | src/UI/HTML/Tree/FolderCheckView.php | UI_HTML_Tree_FolderCheckView.buildRecursive | protected function buildRecursive( $path, $level = 0, $pathRoot = NULL )
{
if( !$pathRoot )
$pathRoot = $path;
$list = array(); // empty Array for current Level Items
$lister = new FS_Folder_Lister( $path ); // create Lister for Folder Contents
$lister->showFolders( $this->showFolders ); // switch Folders Visibility
$lister->showFiles( $this->showFiles ); // switch Files Visibility
$index = $lister->getList(); // get Iterator
foreach( $index as $item ) // iterate current Path
{
$ignore = FALSE;
$path = str_replace( "\\", "/", $item->getPathname() ); // correct Slashes on Windows
$path = substr( $path, strlen( $this->path ) ); // remove Tree Root Path
foreach( $this->ignorePatterns as $pattern )
if( preg_match( '@^'.$pattern.'$@', $path ) )
$ignore = TRUE;
if( $ignore )
continue;
$label = $item->getFilename();
$sublist = ""; // empty Sublist
if( $item->isDir() ) // current Path has Folders
$sublist = $this->buildRecursive( $item->getPathname(), $level + 1, $pathRoot ); // call Method for nested Folder
$state = $this->selected ? in_array( $path, $this->selected ) : TRUE; // current Item is set to be selected or no presets at all
$check = UI_HTML_FormElements::CheckBox( $this->inputName.'[]', $path, $state ); // build Checkbox
$span = UI_HTML_Tag::create( 'span', $check.$label ); // build Label
$item = UI_HTML_Elements::ListItem( $span.$sublist, $level ); // build List Item
$list[$label] = $item; // append to List
}
ksort( $list );
$list = $list ? UI_HTML_Elements::unorderedList( $list, $level ) : ""; // build List
return $list; // return List of this Level
} | php | protected function buildRecursive( $path, $level = 0, $pathRoot = NULL )
{
if( !$pathRoot )
$pathRoot = $path;
$list = array(); // empty Array for current Level Items
$lister = new FS_Folder_Lister( $path ); // create Lister for Folder Contents
$lister->showFolders( $this->showFolders ); // switch Folders Visibility
$lister->showFiles( $this->showFiles ); // switch Files Visibility
$index = $lister->getList(); // get Iterator
foreach( $index as $item ) // iterate current Path
{
$ignore = FALSE;
$path = str_replace( "\\", "/", $item->getPathname() ); // correct Slashes on Windows
$path = substr( $path, strlen( $this->path ) ); // remove Tree Root Path
foreach( $this->ignorePatterns as $pattern )
if( preg_match( '@^'.$pattern.'$@', $path ) )
$ignore = TRUE;
if( $ignore )
continue;
$label = $item->getFilename();
$sublist = ""; // empty Sublist
if( $item->isDir() ) // current Path has Folders
$sublist = $this->buildRecursive( $item->getPathname(), $level + 1, $pathRoot ); // call Method for nested Folder
$state = $this->selected ? in_array( $path, $this->selected ) : TRUE; // current Item is set to be selected or no presets at all
$check = UI_HTML_FormElements::CheckBox( $this->inputName.'[]', $path, $state ); // build Checkbox
$span = UI_HTML_Tag::create( 'span', $check.$label ); // build Label
$item = UI_HTML_Elements::ListItem( $span.$sublist, $level ); // build List Item
$list[$label] = $item; // append to List
}
ksort( $list );
$list = $list ? UI_HTML_Elements::unorderedList( $list, $level ) : ""; // build List
return $list; // return List of this Level
} | [
"protected",
"function",
"buildRecursive",
"(",
"$",
"path",
",",
"$",
"level",
"=",
"0",
",",
"$",
"pathRoot",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"$",
"pathRoot",
")",
"$",
"pathRoot",
"=",
"$",
"path",
";",
"$",
"list",
"=",
"array",
"(",
")",
";",
"// empty Array for current Level Items",
"$",
"lister",
"=",
"new",
"FS_Folder_Lister",
"(",
"$",
"path",
")",
";",
"// create Lister for Folder Contents",
"$",
"lister",
"->",
"showFolders",
"(",
"$",
"this",
"->",
"showFolders",
")",
";",
"// switch Folders Visibility",
"$",
"lister",
"->",
"showFiles",
"(",
"$",
"this",
"->",
"showFiles",
")",
";",
"// switch Files Visibility",
"$",
"index",
"=",
"$",
"lister",
"->",
"getList",
"(",
")",
";",
"// get Iterator",
"foreach",
"(",
"$",
"index",
"as",
"$",
"item",
")",
"// iterate current Path",
"{",
"$",
"ignore",
"=",
"FALSE",
";",
"$",
"path",
"=",
"str_replace",
"(",
"\"\\\\\"",
",",
"\"/\"",
",",
"$",
"item",
"->",
"getPathname",
"(",
")",
")",
";",
"// correct Slashes on Windows",
"$",
"path",
"=",
"substr",
"(",
"$",
"path",
",",
"strlen",
"(",
"$",
"this",
"->",
"path",
")",
")",
";",
"// remove Tree Root Path",
"foreach",
"(",
"$",
"this",
"->",
"ignorePatterns",
"as",
"$",
"pattern",
")",
"if",
"(",
"preg_match",
"(",
"'@^'",
".",
"$",
"pattern",
".",
"'$@'",
",",
"$",
"path",
")",
")",
"$",
"ignore",
"=",
"TRUE",
";",
"if",
"(",
"$",
"ignore",
")",
"continue",
";",
"$",
"label",
"=",
"$",
"item",
"->",
"getFilename",
"(",
")",
";",
"$",
"sublist",
"=",
"\"\"",
";",
"// empty Sublist",
"if",
"(",
"$",
"item",
"->",
"isDir",
"(",
")",
")",
"// current Path has Folders",
"$",
"sublist",
"=",
"$",
"this",
"->",
"buildRecursive",
"(",
"$",
"item",
"->",
"getPathname",
"(",
")",
",",
"$",
"level",
"+",
"1",
",",
"$",
"pathRoot",
")",
";",
"// call Method for nested Folder",
"$",
"state",
"=",
"$",
"this",
"->",
"selected",
"?",
"in_array",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"selected",
")",
":",
"TRUE",
";",
"// current Item is set to be selected or no presets at all ",
"$",
"check",
"=",
"UI_HTML_FormElements",
"::",
"CheckBox",
"(",
"$",
"this",
"->",
"inputName",
".",
"'[]'",
",",
"$",
"path",
",",
"$",
"state",
")",
";",
"// build Checkbox",
"$",
"span",
"=",
"UI_HTML_Tag",
"::",
"create",
"(",
"'span'",
",",
"$",
"check",
".",
"$",
"label",
")",
";",
"// build Label",
"$",
"item",
"=",
"UI_HTML_Elements",
"::",
"ListItem",
"(",
"$",
"span",
".",
"$",
"sublist",
",",
"$",
"level",
")",
";",
"// build List Item",
"$",
"list",
"[",
"$",
"label",
"]",
"=",
"$",
"item",
";",
"// append to List",
"}",
"ksort",
"(",
"$",
"list",
")",
";",
"$",
"list",
"=",
"$",
"list",
"?",
"UI_HTML_Elements",
"::",
"unorderedList",
"(",
"$",
"list",
",",
"$",
"level",
")",
":",
"\"\"",
";",
"// build List",
"return",
"$",
"list",
";",
"// return List of this Level",
"}"
] | Builds recursively nested HTML Lists and Items from Folder Structure.
@access public
@param string $path URI (local only) of Folder to list
@param int $level Current nesting depth
@return string | [
"Builds",
"recursively",
"nested",
"HTML",
"Lists",
"and",
"Items",
"from",
"Folder",
"Structure",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/Tree/FolderCheckView.php#L88-L120 |
36,377 | CeusMedia/Common | src/FS/File/Arc/TarBzip.php | FS_File_Arc_TarBzip.open | public function open( $fileName )
{
if( !file_exists( $fileName ) ) // If the tar file doesn't exist...
throw new RuntimeException( 'TBZ file "'.$fileName.'" is not existing.' );
$this->fileName = $fileName;
$this->readBzipTar( $fileName );
} | php | public function open( $fileName )
{
if( !file_exists( $fileName ) ) // If the tar file doesn't exist...
throw new RuntimeException( 'TBZ file "'.$fileName.'" is not existing.' );
$this->fileName = $fileName;
$this->readBzipTar( $fileName );
} | [
"public",
"function",
"open",
"(",
"$",
"fileName",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"fileName",
")",
")",
"// If the tar file doesn't exist...\r",
"throw",
"new",
"RuntimeException",
"(",
"'TBZ file \"'",
".",
"$",
"fileName",
".",
"'\" is not existing.'",
")",
";",
"$",
"this",
"->",
"fileName",
"=",
"$",
"fileName",
";",
"$",
"this",
"->",
"readBzipTar",
"(",
"$",
"fileName",
")",
";",
"}"
] | Opens an existing Tar Bzip File and loads contents.
@access public
@param string $fileName Name of Tar Bzip Archive to open
@return bool | [
"Opens",
"an",
"existing",
"Tar",
"Bzip",
"File",
"and",
"loads",
"contents",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Arc/TarBzip.php#L60-L66 |
36,378 | CeusMedia/Common | src/FS/File/Arc/TarBzip.php | FS_File_Arc_TarBzip.readBzipTar | private function readBzipTar( $fileName )
{
$f = new FS_File_Arc_Bzip( $fileName );
$this->content = $f->readString();
$this->parseTar(); // Parse the TAR file
return true;
} | php | private function readBzipTar( $fileName )
{
$f = new FS_File_Arc_Bzip( $fileName );
$this->content = $f->readString();
$this->parseTar(); // Parse the TAR file
return true;
} | [
"private",
"function",
"readBzipTar",
"(",
"$",
"fileName",
")",
"{",
"$",
"f",
"=",
"new",
"FS_File_Arc_Bzip",
"(",
"$",
"fileName",
")",
";",
"$",
"this",
"->",
"content",
"=",
"$",
"f",
"->",
"readString",
"(",
")",
";",
"$",
"this",
"->",
"parseTar",
"(",
")",
";",
"// Parse the TAR file\r",
"return",
"true",
";",
"}"
] | Reads an existing Tar Bzip File.
@access private
@param string $fileName Name of Tar Bzip Archive to read
@return bool | [
"Reads",
"an",
"existing",
"Tar",
"Bzip",
"File",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Arc/TarBzip.php#L74-L80 |
36,379 | CeusMedia/Common | src/FS/File/Arc/TarBzip.php | FS_File_Arc_TarBzip.save | public function save( $fileName = false )
{
if( !$fileName )
{
if( !$this->fileName )
throw new RuntimeException( 'No TBZ file name for saving given.' );
$fileName = $this->fileName;
}
$this->generateTar(); // Encode processed files into TAR file format
$f = new FS_File_Arc_Bzip( $fileName );
$f->writeString( $this->content );
return true;
} | php | public function save( $fileName = false )
{
if( !$fileName )
{
if( !$this->fileName )
throw new RuntimeException( 'No TBZ file name for saving given.' );
$fileName = $this->fileName;
}
$this->generateTar(); // Encode processed files into TAR file format
$f = new FS_File_Arc_Bzip( $fileName );
$f->writeString( $this->content );
return true;
} | [
"public",
"function",
"save",
"(",
"$",
"fileName",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"fileName",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"fileName",
")",
"throw",
"new",
"RuntimeException",
"(",
"'No TBZ file name for saving given.'",
")",
";",
"$",
"fileName",
"=",
"$",
"this",
"->",
"fileName",
";",
"}",
"$",
"this",
"->",
"generateTar",
"(",
")",
";",
"// Encode processed files into TAR file format\r",
"$",
"f",
"=",
"new",
"FS_File_Arc_Bzip",
"(",
"$",
"fileName",
")",
";",
"$",
"f",
"->",
"writeString",
"(",
"$",
"this",
"->",
"content",
")",
";",
"return",
"true",
";",
"}"
] | Write down the currently loaded Tar Bzip Archive.
@access public
@param string $fileName Name of Tar Bzip Archive to save
@return bool | [
"Write",
"down",
"the",
"currently",
"loaded",
"Tar",
"Bzip",
"Archive",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Arc/TarBzip.php#L88-L100 |
36,380 | CeusMedia/Common | src/Net/HTTP/Request/Receiver.php | Net_HTTP_Request_Receiver.getAllFromSource | public function getAllFromSource( $source, $strict = FALSE )
{
$source = strtolower( $source );
if( isset( $this->sources[$source] ) )
return new ADT_List_Dictionary( $this->sources[$source] );
if( !$strict )
return array();
throw new InvalidArgumentException( 'Invalid source "'.$source.'"' );
} | php | public function getAllFromSource( $source, $strict = FALSE )
{
$source = strtolower( $source );
if( isset( $this->sources[$source] ) )
return new ADT_List_Dictionary( $this->sources[$source] );
if( !$strict )
return array();
throw new InvalidArgumentException( 'Invalid source "'.$source.'"' );
} | [
"public",
"function",
"getAllFromSource",
"(",
"$",
"source",
",",
"$",
"strict",
"=",
"FALSE",
")",
"{",
"$",
"source",
"=",
"strtolower",
"(",
"$",
"source",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"sources",
"[",
"$",
"source",
"]",
")",
")",
"return",
"new",
"ADT_List_Dictionary",
"(",
"$",
"this",
"->",
"sources",
"[",
"$",
"source",
"]",
")",
";",
"if",
"(",
"!",
"$",
"strict",
")",
"return",
"array",
"(",
")",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid source \"'",
".",
"$",
"source",
".",
"'\"'",
")",
";",
"}"
] | Reads and returns Data from Sources.
@access public
@param string $source Source key (not case sensitive) (get,post,files[,session,cookie])
@param bool $strict Flag: throw exception if not set, otherwise return NULL
@throws InvalidArgumentException if key is not set in source and strict is on
@return array Pairs in source (or empty array if not set on strict is off) | [
"Reads",
"and",
"returns",
"Data",
"from",
"Sources",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/HTTP/Request/Receiver.php#L105-L113 |
36,381 | CeusMedia/Common | src/Net/HTTP/Request/Receiver.php | Net_HTTP_Request_Receiver.getFromSource | public function getFromSource( $key, $source, $strict = FALSE )
{
$data = $this->getAllFromSource( $source );
if( isset( $data[$key] ) )
return $data[$key];
if( !$strict )
return NULL;
throw new InvalidArgumentException( 'Invalid key "'.$key.'" in source "'.$source.'"' );
} | php | public function getFromSource( $key, $source, $strict = FALSE )
{
$data = $this->getAllFromSource( $source );
if( isset( $data[$key] ) )
return $data[$key];
if( !$strict )
return NULL;
throw new InvalidArgumentException( 'Invalid key "'.$key.'" in source "'.$source.'"' );
} | [
"public",
"function",
"getFromSource",
"(",
"$",
"key",
",",
"$",
"source",
",",
"$",
"strict",
"=",
"FALSE",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getAllFromSource",
"(",
"$",
"source",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
")",
"return",
"$",
"data",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"!",
"$",
"strict",
")",
"return",
"NULL",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid key \"'",
".",
"$",
"key",
".",
"'\" in source \"'",
".",
"$",
"source",
".",
"'\"'",
")",
";",
"}"
] | Returns value or null by its key in a specified source.
@access public
@param string $key ...
@param string $source Source key (not case sensitive) (get,post,files[,session,cookie])
@param bool $strict Flag: throw exception if not set, otherwise return NULL
@throws InvalidArgumentException if key is not set in source and strict is on
@return mixed Value of key in source or NULL if not set | [
"Returns",
"value",
"or",
"null",
"by",
"its",
"key",
"in",
"a",
"specified",
"source",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/HTTP/Request/Receiver.php#L124-L132 |
36,382 | meritoo/common-library | src/Utilities/Miscellaneous.php | Miscellaneous.checkboxValue2Boolean | public static function checkboxValue2Boolean($checkboxValue)
{
$mapping = [
'on' => true,
'off' => false,
];
$clearValue = strtolower(trim($checkboxValue));
if (isset($mapping[$clearValue])) {
return $mapping[$clearValue];
}
return false;
} | php | public static function checkboxValue2Boolean($checkboxValue)
{
$mapping = [
'on' => true,
'off' => false,
];
$clearValue = strtolower(trim($checkboxValue));
if (isset($mapping[$clearValue])) {
return $mapping[$clearValue];
}
return false;
} | [
"public",
"static",
"function",
"checkboxValue2Boolean",
"(",
"$",
"checkboxValue",
")",
"{",
"$",
"mapping",
"=",
"[",
"'on'",
"=>",
"true",
",",
"'off'",
"=>",
"false",
",",
"]",
";",
"$",
"clearValue",
"=",
"strtolower",
"(",
"trim",
"(",
"$",
"checkboxValue",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"$",
"clearValue",
"]",
")",
")",
"{",
"return",
"$",
"mapping",
"[",
"$",
"clearValue",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | Converts checkbox value to boolean
@param string $checkboxValue Checkbox value
@return bool | [
"Converts",
"checkbox",
"value",
"to",
"boolean"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L125-L139 |
36,383 | meritoo/common-library | src/Utilities/Miscellaneous.php | Miscellaneous.includeFileExtension | public static function includeFileExtension($fileName, $extension)
{
$fileExtension = self::getFileExtension($fileName, true);
/*
* File has given extension?
* Nothing to do
*/
if ($fileExtension === strtolower($extension)) {
return $fileName;
}
return sprintf('%s.%s', $fileName, $extension);
} | php | public static function includeFileExtension($fileName, $extension)
{
$fileExtension = self::getFileExtension($fileName, true);
/*
* File has given extension?
* Nothing to do
*/
if ($fileExtension === strtolower($extension)) {
return $fileName;
}
return sprintf('%s.%s', $fileName, $extension);
} | [
"public",
"static",
"function",
"includeFileExtension",
"(",
"$",
"fileName",
",",
"$",
"extension",
")",
"{",
"$",
"fileExtension",
"=",
"self",
"::",
"getFileExtension",
"(",
"$",
"fileName",
",",
"true",
")",
";",
"/*\n * File has given extension?\n * Nothing to do\n */",
"if",
"(",
"$",
"fileExtension",
"===",
"strtolower",
"(",
"$",
"extension",
")",
")",
"{",
"return",
"$",
"fileName",
";",
"}",
"return",
"sprintf",
"(",
"'%s.%s'",
",",
"$",
"fileName",
",",
"$",
"extension",
")",
";",
"}"
] | Returns name of file with given extension after verification if it contains the extension
@param string $fileName The file name to verify
@param string $extension The extension to verify and include
@return string | [
"Returns",
"name",
"of",
"file",
"with",
"given",
"extension",
"after",
"verification",
"if",
"it",
"contains",
"the",
"extension"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L159-L172 |
36,384 | meritoo/common-library | src/Utilities/Miscellaneous.php | Miscellaneous.getFileExtension | public static function getFileExtension($fileName, $asLowerCase = false)
{
$extension = '';
$matches = [];
if (preg_match('|(.+)\.(.+)|', $fileName, $matches)) {
$extension = end($matches);
}
if ($asLowerCase) {
return strtolower($extension);
}
return $extension;
} | php | public static function getFileExtension($fileName, $asLowerCase = false)
{
$extension = '';
$matches = [];
if (preg_match('|(.+)\.(.+)|', $fileName, $matches)) {
$extension = end($matches);
}
if ($asLowerCase) {
return strtolower($extension);
}
return $extension;
} | [
"public",
"static",
"function",
"getFileExtension",
"(",
"$",
"fileName",
",",
"$",
"asLowerCase",
"=",
"false",
")",
"{",
"$",
"extension",
"=",
"''",
";",
"$",
"matches",
"=",
"[",
"]",
";",
"if",
"(",
"preg_match",
"(",
"'|(.+)\\.(.+)|'",
",",
"$",
"fileName",
",",
"$",
"matches",
")",
")",
"{",
"$",
"extension",
"=",
"end",
"(",
"$",
"matches",
")",
";",
"}",
"if",
"(",
"$",
"asLowerCase",
")",
"{",
"return",
"strtolower",
"(",
"$",
"extension",
")",
";",
"}",
"return",
"$",
"extension",
";",
"}"
] | Returns file extension
@param string $fileName File name
@param bool $asLowerCase (optional) if true extension is returned as lowercase string
@return string | [
"Returns",
"file",
"extension"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L181-L195 |
36,385 | meritoo/common-library | src/Utilities/Miscellaneous.php | Miscellaneous.getFileNameFromPath | public static function getFileNameFromPath($path)
{
$matches = [];
$pattern = sprintf('|([^\%s.]+\.[A-Za-z0-9.]+)$|', DIRECTORY_SEPARATOR);
if ((bool)preg_match($pattern, $path, $matches)) {
return $matches[1];
}
return '';
} | php | public static function getFileNameFromPath($path)
{
$matches = [];
$pattern = sprintf('|([^\%s.]+\.[A-Za-z0-9.]+)$|', DIRECTORY_SEPARATOR);
if ((bool)preg_match($pattern, $path, $matches)) {
return $matches[1];
}
return '';
} | [
"public",
"static",
"function",
"getFileNameFromPath",
"(",
"$",
"path",
")",
"{",
"$",
"matches",
"=",
"[",
"]",
";",
"$",
"pattern",
"=",
"sprintf",
"(",
"'|([^\\%s.]+\\.[A-Za-z0-9.]+)$|'",
",",
"DIRECTORY_SEPARATOR",
")",
";",
"if",
"(",
"(",
"bool",
")",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"path",
",",
"$",
"matches",
")",
")",
"{",
"return",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"return",
"''",
";",
"}"
] | Returns file name from given path
@param string $path A path that contains file name
@return string | [
"Returns",
"file",
"name",
"from",
"given",
"path"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L203-L213 |
36,386 | meritoo/common-library | src/Utilities/Miscellaneous.php | Miscellaneous.getUniqueFileName | public static function getUniqueFileName($originalFileName, $objectId = 0)
{
$withoutExtension = self::getFileNameWithoutExtension($originalFileName);
$extension = self::getFileExtension($originalFileName, true);
/*
* Let's clear name of file
*
* Attention.
* The name without extension may be cleared / urlized only to avoid incorrect name by replacing "." with "-".
*/
$withoutExtension = Urlizer::urlize($withoutExtension);
// Now I have to complete the template used to build / generate unique name
$template = '%s-%s.%s'; // [file's name]-[unique key].[file's extension]
// Add some uniqueness
$unique = self::getUniqueString(mt_rand());
// Finally build and return the unique name
if ($objectId > 0) {
$template = '%s-%s-%s.%s'; // [file's name]-[unique key]-[object ID].[file's extension]
return sprintf($template, $withoutExtension, $unique, $objectId, $extension);
}
return sprintf($template, $withoutExtension, $unique, $extension);
} | php | public static function getUniqueFileName($originalFileName, $objectId = 0)
{
$withoutExtension = self::getFileNameWithoutExtension($originalFileName);
$extension = self::getFileExtension($originalFileName, true);
/*
* Let's clear name of file
*
* Attention.
* The name without extension may be cleared / urlized only to avoid incorrect name by replacing "." with "-".
*/
$withoutExtension = Urlizer::urlize($withoutExtension);
// Now I have to complete the template used to build / generate unique name
$template = '%s-%s.%s'; // [file's name]-[unique key].[file's extension]
// Add some uniqueness
$unique = self::getUniqueString(mt_rand());
// Finally build and return the unique name
if ($objectId > 0) {
$template = '%s-%s-%s.%s'; // [file's name]-[unique key]-[object ID].[file's extension]
return sprintf($template, $withoutExtension, $unique, $objectId, $extension);
}
return sprintf($template, $withoutExtension, $unique, $extension);
} | [
"public",
"static",
"function",
"getUniqueFileName",
"(",
"$",
"originalFileName",
",",
"$",
"objectId",
"=",
"0",
")",
"{",
"$",
"withoutExtension",
"=",
"self",
"::",
"getFileNameWithoutExtension",
"(",
"$",
"originalFileName",
")",
";",
"$",
"extension",
"=",
"self",
"::",
"getFileExtension",
"(",
"$",
"originalFileName",
",",
"true",
")",
";",
"/*\n * Let's clear name of file\n *\n * Attention.\n * The name without extension may be cleared / urlized only to avoid incorrect name by replacing \".\" with \"-\".\n */",
"$",
"withoutExtension",
"=",
"Urlizer",
"::",
"urlize",
"(",
"$",
"withoutExtension",
")",
";",
"// Now I have to complete the template used to build / generate unique name",
"$",
"template",
"=",
"'%s-%s.%s'",
";",
"// [file's name]-[unique key].[file's extension]",
"// Add some uniqueness",
"$",
"unique",
"=",
"self",
"::",
"getUniqueString",
"(",
"mt_rand",
"(",
")",
")",
";",
"// Finally build and return the unique name",
"if",
"(",
"$",
"objectId",
">",
"0",
")",
"{",
"$",
"template",
"=",
"'%s-%s-%s.%s'",
";",
"// [file's name]-[unique key]-[object ID].[file's extension]",
"return",
"sprintf",
"(",
"$",
"template",
",",
"$",
"withoutExtension",
",",
"$",
"unique",
",",
"$",
"objectId",
",",
"$",
"extension",
")",
";",
"}",
"return",
"sprintf",
"(",
"$",
"template",
",",
"$",
"withoutExtension",
",",
"$",
"unique",
",",
"$",
"extension",
")",
";",
"}"
] | Returns unique name for file based on given original name
@param string $originalFileName Original name of the file
@param int $objectId (optional) Object ID, the ID of database's row. May be included into the
generated / unique name.
@return string | [
"Returns",
"unique",
"name",
"for",
"file",
"based",
"on",
"given",
"original",
"name"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L223-L250 |
36,387 | meritoo/common-library | src/Utilities/Miscellaneous.php | Miscellaneous.getFileNameWithoutExtension | public static function getFileNameWithoutExtension($fileName)
{
$matches = [];
if (is_string($fileName) && (bool)preg_match('|(.+)\.(.+)|', $fileName, $matches)) {
return $matches[1];
}
return '';
} | php | public static function getFileNameWithoutExtension($fileName)
{
$matches = [];
if (is_string($fileName) && (bool)preg_match('|(.+)\.(.+)|', $fileName, $matches)) {
return $matches[1];
}
return '';
} | [
"public",
"static",
"function",
"getFileNameWithoutExtension",
"(",
"$",
"fileName",
")",
"{",
"$",
"matches",
"=",
"[",
"]",
";",
"if",
"(",
"is_string",
"(",
"$",
"fileName",
")",
"&&",
"(",
"bool",
")",
"preg_match",
"(",
"'|(.+)\\.(.+)|'",
",",
"$",
"fileName",
",",
"$",
"matches",
")",
")",
"{",
"return",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"return",
"''",
";",
"}"
] | Returns file name without extension
@param string $fileName The file name
@return string | [
"Returns",
"file",
"name",
"without",
"extension"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L258-L267 |
36,388 | meritoo/common-library | src/Utilities/Miscellaneous.php | Miscellaneous.toLatin | public static function toLatin($string, $lowerCaseHuman = true, $replacementChar = '-')
{
if (is_string($string)) {
$string = trim($string);
}
/*
* Empty value?
* Nothing to do
*/
if (empty($string)) {
return '';
}
$converter = Transliterator::create('Latin-ASCII;');
/*
* Oops, cannot instantiate converter
* Nothing to do
*/
if (null === $converter) {
return '';
}
$converted = $converter->transliterate($string);
// Make the string lowercase and human-readable
if ($lowerCaseHuman) {
$matches = [];
$matchCount = preg_match_all('|[A-Z]{1}[^A-Z]*|', $converted, $matches);
if ($matchCount > 0) {
$parts = $matches[0];
$converted = mb_strtolower(implode($replacementChar, $parts));
}
}
/*
* Let's replace special characters to spaces
* ...and finally spaces to $replacementChar
*/
$replaced = preg_replace('|[^a-zA-Z0-9]|', ' ', $converted);
return preg_replace('| +|', $replacementChar, trim($replaced));
} | php | public static function toLatin($string, $lowerCaseHuman = true, $replacementChar = '-')
{
if (is_string($string)) {
$string = trim($string);
}
/*
* Empty value?
* Nothing to do
*/
if (empty($string)) {
return '';
}
$converter = Transliterator::create('Latin-ASCII;');
/*
* Oops, cannot instantiate converter
* Nothing to do
*/
if (null === $converter) {
return '';
}
$converted = $converter->transliterate($string);
// Make the string lowercase and human-readable
if ($lowerCaseHuman) {
$matches = [];
$matchCount = preg_match_all('|[A-Z]{1}[^A-Z]*|', $converted, $matches);
if ($matchCount > 0) {
$parts = $matches[0];
$converted = mb_strtolower(implode($replacementChar, $parts));
}
}
/*
* Let's replace special characters to spaces
* ...and finally spaces to $replacementChar
*/
$replaced = preg_replace('|[^a-zA-Z0-9]|', ' ', $converted);
return preg_replace('| +|', $replacementChar, trim($replaced));
} | [
"public",
"static",
"function",
"toLatin",
"(",
"$",
"string",
",",
"$",
"lowerCaseHuman",
"=",
"true",
",",
"$",
"replacementChar",
"=",
"'-'",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"string",
")",
")",
"{",
"$",
"string",
"=",
"trim",
"(",
"$",
"string",
")",
";",
"}",
"/*\n * Empty value?\n * Nothing to do\n */",
"if",
"(",
"empty",
"(",
"$",
"string",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"converter",
"=",
"Transliterator",
"::",
"create",
"(",
"'Latin-ASCII;'",
")",
";",
"/*\n * Oops, cannot instantiate converter\n * Nothing to do\n */",
"if",
"(",
"null",
"===",
"$",
"converter",
")",
"{",
"return",
"''",
";",
"}",
"$",
"converted",
"=",
"$",
"converter",
"->",
"transliterate",
"(",
"$",
"string",
")",
";",
"// Make the string lowercase and human-readable",
"if",
"(",
"$",
"lowerCaseHuman",
")",
"{",
"$",
"matches",
"=",
"[",
"]",
";",
"$",
"matchCount",
"=",
"preg_match_all",
"(",
"'|[A-Z]{1}[^A-Z]*|'",
",",
"$",
"converted",
",",
"$",
"matches",
")",
";",
"if",
"(",
"$",
"matchCount",
">",
"0",
")",
"{",
"$",
"parts",
"=",
"$",
"matches",
"[",
"0",
"]",
";",
"$",
"converted",
"=",
"mb_strtolower",
"(",
"implode",
"(",
"$",
"replacementChar",
",",
"$",
"parts",
")",
")",
";",
"}",
"}",
"/*\n * Let's replace special characters to spaces\n * ...and finally spaces to $replacementChar\n */",
"$",
"replaced",
"=",
"preg_replace",
"(",
"'|[^a-zA-Z0-9]|'",
",",
"' '",
",",
"$",
"converted",
")",
";",
"return",
"preg_replace",
"(",
"'| +|'",
",",
"$",
"replacementChar",
",",
"trim",
"(",
"$",
"replaced",
")",
")",
";",
"}"
] | Converts given string characters to latin characters
@param string $string String to convert
@param bool $lowerCaseHuman (optional) If is set to true, converted string is returned as lowercase and
human-readable. Otherwise - as original.
@param string $replacementChar (optional) Replacement character for all non-latin characters and uppercase
letters, if 2nd argument is set to true
@return string | [
"Converts",
"given",
"string",
"characters",
"to",
"latin",
"characters"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L310-L354 |
36,389 | meritoo/common-library | src/Utilities/Miscellaneous.php | Miscellaneous.getUniqueString | public static function getUniqueString($prefix = '', $hashed = false)
{
$unique = uniqid($prefix, true);
if ($hashed) {
return sha1($unique);
}
return $unique;
} | php | public static function getUniqueString($prefix = '', $hashed = false)
{
$unique = uniqid($prefix, true);
if ($hashed) {
return sha1($unique);
}
return $unique;
} | [
"public",
"static",
"function",
"getUniqueString",
"(",
"$",
"prefix",
"=",
"''",
",",
"$",
"hashed",
"=",
"false",
")",
"{",
"$",
"unique",
"=",
"uniqid",
"(",
"$",
"prefix",
",",
"true",
")",
";",
"if",
"(",
"$",
"hashed",
")",
"{",
"return",
"sha1",
"(",
"$",
"unique",
")",
";",
"}",
"return",
"$",
"unique",
";",
"}"
] | Returns unique string
@param string $prefix (optional) Prefix of the unique string. May be used while generating the unique
string simultaneously on several hosts at the same microsecond.
@param bool $hashed (optional) If is set to true, the unique string is hashed additionally. Otherwise - not.
@return string | [
"Returns",
"unique",
"string"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L364-L373 |
36,390 | meritoo/common-library | src/Utilities/Miscellaneous.php | Miscellaneous.replace | public static function replace($subject, $search, $replacement, $quoteStrings = false)
{
/*
* Unknown source or item to find or replacement is an empty array?
* Nothing to do
*/
if (empty($subject) || empty($search) || [] === $replacement) {
return $subject;
}
$effect = $subject;
$searchIsString = is_string($search);
$searchIsArray = is_array($search);
/*
* Value to find is neither a string nor an array OR it's an empty string?
* Nothing to do
*/
if ((!$searchIsString && !$searchIsArray) || ($searchIsString && '' === $search)) {
return $effect;
}
$replacementIsString = is_string($replacement);
$replacementIsArray = is_array($replacement);
$bothAreStrings = $searchIsString && $replacementIsString;
$bothAreArrays = $searchIsArray && $replacementIsArray;
if ($quoteStrings) {
if ($replacementIsString) {
$replacement = '\'' . $replacement . '\'';
} elseif ($replacementIsArray) {
foreach ($replacement as &$item) {
if (is_string($item)) {
$item = '\'' . $item . '\'';
}
}
unset($item);
}
}
// 1st step: replace strings, simple operation with strings
if ($bothAreStrings) {
$effect = str_replace($search, $replacement, $subject);
}
/*
* 2nd step: replace with regular expressions.
* Attention. Searched and replacement value should be the same type: strings or arrays.
*/
if ($effect === $subject && ($bothAreStrings || $bothAreArrays)) {
/*
* I have to avoid string that contains spaces only, e.g. " ".
* It's required to avoid bug: preg_replace(): Empty regular expression.
*/
if ($searchIsArray || ($searchIsString && !empty(trim($search)))) {
$replaced = @preg_replace($search, $replacement, $subject);
if (null !== $replaced && [] !== $replaced) {
$effect = $replaced;
}
}
}
/*
* 3rd step: complex replace of the replacement defined as an array.
* It may be useful when you want to search for a one string and replace the string with multiple values.
*/
if ($effect === $subject && $searchIsString && $replacementIsArray) {
$subjectIsArray = is_array($subject);
$effect = '';
if ($subjectIsArray) {
$effect = [];
}
$subject = Arrays::makeArray($subject);
// I have to iterate through the subjects, because explode() function expects strings as both arguments
// (1st and 2nd)
foreach ($subject as $subSubject) {
$subEffect = '';
$exploded = explode($search, $subSubject);
$explodedCount = count($exploded);
foreach ($exploded as $key => $item) {
$subEffect .= $item;
// The replacement shouldn't be included when the searched string was not found
if ($explodedCount > 1 && $key < $explodedCount - 1 && isset($replacement[$key])) {
$subEffect .= $replacement[$key];
}
}
if ($subjectIsArray) {
$effect[] = $subEffect;
continue;
}
$effect .= $subEffect;
}
}
return $effect;
} | php | public static function replace($subject, $search, $replacement, $quoteStrings = false)
{
/*
* Unknown source or item to find or replacement is an empty array?
* Nothing to do
*/
if (empty($subject) || empty($search) || [] === $replacement) {
return $subject;
}
$effect = $subject;
$searchIsString = is_string($search);
$searchIsArray = is_array($search);
/*
* Value to find is neither a string nor an array OR it's an empty string?
* Nothing to do
*/
if ((!$searchIsString && !$searchIsArray) || ($searchIsString && '' === $search)) {
return $effect;
}
$replacementIsString = is_string($replacement);
$replacementIsArray = is_array($replacement);
$bothAreStrings = $searchIsString && $replacementIsString;
$bothAreArrays = $searchIsArray && $replacementIsArray;
if ($quoteStrings) {
if ($replacementIsString) {
$replacement = '\'' . $replacement . '\'';
} elseif ($replacementIsArray) {
foreach ($replacement as &$item) {
if (is_string($item)) {
$item = '\'' . $item . '\'';
}
}
unset($item);
}
}
// 1st step: replace strings, simple operation with strings
if ($bothAreStrings) {
$effect = str_replace($search, $replacement, $subject);
}
/*
* 2nd step: replace with regular expressions.
* Attention. Searched and replacement value should be the same type: strings or arrays.
*/
if ($effect === $subject && ($bothAreStrings || $bothAreArrays)) {
/*
* I have to avoid string that contains spaces only, e.g. " ".
* It's required to avoid bug: preg_replace(): Empty regular expression.
*/
if ($searchIsArray || ($searchIsString && !empty(trim($search)))) {
$replaced = @preg_replace($search, $replacement, $subject);
if (null !== $replaced && [] !== $replaced) {
$effect = $replaced;
}
}
}
/*
* 3rd step: complex replace of the replacement defined as an array.
* It may be useful when you want to search for a one string and replace the string with multiple values.
*/
if ($effect === $subject && $searchIsString && $replacementIsArray) {
$subjectIsArray = is_array($subject);
$effect = '';
if ($subjectIsArray) {
$effect = [];
}
$subject = Arrays::makeArray($subject);
// I have to iterate through the subjects, because explode() function expects strings as both arguments
// (1st and 2nd)
foreach ($subject as $subSubject) {
$subEffect = '';
$exploded = explode($search, $subSubject);
$explodedCount = count($exploded);
foreach ($exploded as $key => $item) {
$subEffect .= $item;
// The replacement shouldn't be included when the searched string was not found
if ($explodedCount > 1 && $key < $explodedCount - 1 && isset($replacement[$key])) {
$subEffect .= $replacement[$key];
}
}
if ($subjectIsArray) {
$effect[] = $subEffect;
continue;
}
$effect .= $subEffect;
}
}
return $effect;
} | [
"public",
"static",
"function",
"replace",
"(",
"$",
"subject",
",",
"$",
"search",
",",
"$",
"replacement",
",",
"$",
"quoteStrings",
"=",
"false",
")",
"{",
"/*\n * Unknown source or item to find or replacement is an empty array?\n * Nothing to do\n */",
"if",
"(",
"empty",
"(",
"$",
"subject",
")",
"||",
"empty",
"(",
"$",
"search",
")",
"||",
"[",
"]",
"===",
"$",
"replacement",
")",
"{",
"return",
"$",
"subject",
";",
"}",
"$",
"effect",
"=",
"$",
"subject",
";",
"$",
"searchIsString",
"=",
"is_string",
"(",
"$",
"search",
")",
";",
"$",
"searchIsArray",
"=",
"is_array",
"(",
"$",
"search",
")",
";",
"/*\n * Value to find is neither a string nor an array OR it's an empty string?\n * Nothing to do\n */",
"if",
"(",
"(",
"!",
"$",
"searchIsString",
"&&",
"!",
"$",
"searchIsArray",
")",
"||",
"(",
"$",
"searchIsString",
"&&",
"''",
"===",
"$",
"search",
")",
")",
"{",
"return",
"$",
"effect",
";",
"}",
"$",
"replacementIsString",
"=",
"is_string",
"(",
"$",
"replacement",
")",
";",
"$",
"replacementIsArray",
"=",
"is_array",
"(",
"$",
"replacement",
")",
";",
"$",
"bothAreStrings",
"=",
"$",
"searchIsString",
"&&",
"$",
"replacementIsString",
";",
"$",
"bothAreArrays",
"=",
"$",
"searchIsArray",
"&&",
"$",
"replacementIsArray",
";",
"if",
"(",
"$",
"quoteStrings",
")",
"{",
"if",
"(",
"$",
"replacementIsString",
")",
"{",
"$",
"replacement",
"=",
"'\\''",
".",
"$",
"replacement",
".",
"'\\''",
";",
"}",
"elseif",
"(",
"$",
"replacementIsArray",
")",
"{",
"foreach",
"(",
"$",
"replacement",
"as",
"&",
"$",
"item",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"item",
")",
")",
"{",
"$",
"item",
"=",
"'\\''",
".",
"$",
"item",
".",
"'\\''",
";",
"}",
"}",
"unset",
"(",
"$",
"item",
")",
";",
"}",
"}",
"// 1st step: replace strings, simple operation with strings",
"if",
"(",
"$",
"bothAreStrings",
")",
"{",
"$",
"effect",
"=",
"str_replace",
"(",
"$",
"search",
",",
"$",
"replacement",
",",
"$",
"subject",
")",
";",
"}",
"/*\n * 2nd step: replace with regular expressions.\n * Attention. Searched and replacement value should be the same type: strings or arrays.\n */",
"if",
"(",
"$",
"effect",
"===",
"$",
"subject",
"&&",
"(",
"$",
"bothAreStrings",
"||",
"$",
"bothAreArrays",
")",
")",
"{",
"/*\n * I have to avoid string that contains spaces only, e.g. \" \".\n * It's required to avoid bug: preg_replace(): Empty regular expression.\n */",
"if",
"(",
"$",
"searchIsArray",
"||",
"(",
"$",
"searchIsString",
"&&",
"!",
"empty",
"(",
"trim",
"(",
"$",
"search",
")",
")",
")",
")",
"{",
"$",
"replaced",
"=",
"@",
"preg_replace",
"(",
"$",
"search",
",",
"$",
"replacement",
",",
"$",
"subject",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"replaced",
"&&",
"[",
"]",
"!==",
"$",
"replaced",
")",
"{",
"$",
"effect",
"=",
"$",
"replaced",
";",
"}",
"}",
"}",
"/*\n * 3rd step: complex replace of the replacement defined as an array.\n * It may be useful when you want to search for a one string and replace the string with multiple values.\n */",
"if",
"(",
"$",
"effect",
"===",
"$",
"subject",
"&&",
"$",
"searchIsString",
"&&",
"$",
"replacementIsArray",
")",
"{",
"$",
"subjectIsArray",
"=",
"is_array",
"(",
"$",
"subject",
")",
";",
"$",
"effect",
"=",
"''",
";",
"if",
"(",
"$",
"subjectIsArray",
")",
"{",
"$",
"effect",
"=",
"[",
"]",
";",
"}",
"$",
"subject",
"=",
"Arrays",
"::",
"makeArray",
"(",
"$",
"subject",
")",
";",
"// I have to iterate through the subjects, because explode() function expects strings as both arguments",
"// (1st and 2nd)",
"foreach",
"(",
"$",
"subject",
"as",
"$",
"subSubject",
")",
"{",
"$",
"subEffect",
"=",
"''",
";",
"$",
"exploded",
"=",
"explode",
"(",
"$",
"search",
",",
"$",
"subSubject",
")",
";",
"$",
"explodedCount",
"=",
"count",
"(",
"$",
"exploded",
")",
";",
"foreach",
"(",
"$",
"exploded",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"subEffect",
".=",
"$",
"item",
";",
"// The replacement shouldn't be included when the searched string was not found",
"if",
"(",
"$",
"explodedCount",
">",
"1",
"&&",
"$",
"key",
"<",
"$",
"explodedCount",
"-",
"1",
"&&",
"isset",
"(",
"$",
"replacement",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"subEffect",
".=",
"$",
"replacement",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"if",
"(",
"$",
"subjectIsArray",
")",
"{",
"$",
"effect",
"[",
"]",
"=",
"$",
"subEffect",
";",
"continue",
";",
"}",
"$",
"effect",
".=",
"$",
"subEffect",
";",
"}",
"}",
"return",
"$",
"effect",
";",
"}"
] | Replaces part of string with other string or strings.
There is a few combination of what should be searched and with what it should be replaced.
@param array|string $subject The string or an array of strings to search and replace
@param array|string $search String or pattern or array of patterns to find. It may be: string, an array
of strings or an array of patterns.
@param array|string $replacement The string or an array of strings to replace. It may be: string or an array
of strings.
@param bool $quoteStrings (optional) If is set to true, strings are surrounded with single quote sign
@return string
Example:
a) an array of strings to search
$subject = [
'Lorem ipsum dolor sit amet.',
'Etiam ullamcorper. Suspendisse a pellentesque dui, non felis.',
];
b) an array of patterns
$search = [
'|ipsum|',
'|pellentesque|',
];
c) an array of strings to replace
$replacement = [
'commodo',
'interdum',
];
The result:
[
'Lorem commodo dolor sit amet.',
'Etiam ullamcorper. Suspendisse a interdum dui, non felis.',
]; | [
"Replaces",
"part",
"of",
"string",
"with",
"other",
"string",
"or",
"strings",
".",
"There",
"is",
"a",
"few",
"combination",
"of",
"what",
"should",
"be",
"searched",
"and",
"with",
"what",
"it",
"should",
"be",
"replaced",
"."
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L412-L520 |
36,391 | meritoo/common-library | src/Utilities/Miscellaneous.php | Miscellaneous.substringToWord | public static function substringToWord($text, $maxLength, $suffix = '...')
{
$effect = $text;
$textLength = mb_strlen($text, 'utf-8');
$suffixLength = mb_strlen($suffix, 'utf-8');
$maxLength -= $suffixLength;
if ($textLength > $maxLength) {
$effect = mb_substr($text, 0, $maxLength, 'utf-8');
$lastSpacePosition = mb_strrpos($effect, ' ', 'utf-8');
if (false !== $lastSpacePosition) {
$effect = mb_substr($effect, 0, $lastSpacePosition, 'utf-8');
}
$effect .= $suffix;
}
return $effect;
} | php | public static function substringToWord($text, $maxLength, $suffix = '...')
{
$effect = $text;
$textLength = mb_strlen($text, 'utf-8');
$suffixLength = mb_strlen($suffix, 'utf-8');
$maxLength -= $suffixLength;
if ($textLength > $maxLength) {
$effect = mb_substr($text, 0, $maxLength, 'utf-8');
$lastSpacePosition = mb_strrpos($effect, ' ', 'utf-8');
if (false !== $lastSpacePosition) {
$effect = mb_substr($effect, 0, $lastSpacePosition, 'utf-8');
}
$effect .= $suffix;
}
return $effect;
} | [
"public",
"static",
"function",
"substringToWord",
"(",
"$",
"text",
",",
"$",
"maxLength",
",",
"$",
"suffix",
"=",
"'...'",
")",
"{",
"$",
"effect",
"=",
"$",
"text",
";",
"$",
"textLength",
"=",
"mb_strlen",
"(",
"$",
"text",
",",
"'utf-8'",
")",
";",
"$",
"suffixLength",
"=",
"mb_strlen",
"(",
"$",
"suffix",
",",
"'utf-8'",
")",
";",
"$",
"maxLength",
"-=",
"$",
"suffixLength",
";",
"if",
"(",
"$",
"textLength",
">",
"$",
"maxLength",
")",
"{",
"$",
"effect",
"=",
"mb_substr",
"(",
"$",
"text",
",",
"0",
",",
"$",
"maxLength",
",",
"'utf-8'",
")",
";",
"$",
"lastSpacePosition",
"=",
"mb_strrpos",
"(",
"$",
"effect",
",",
"' '",
",",
"'utf-8'",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"lastSpacePosition",
")",
"{",
"$",
"effect",
"=",
"mb_substr",
"(",
"$",
"effect",
",",
"0",
",",
"$",
"lastSpacePosition",
",",
"'utf-8'",
")",
";",
"}",
"$",
"effect",
".=",
"$",
"suffix",
";",
"}",
"return",
"$",
"effect",
";",
"}"
] | Returns part of string preserving words
@param string $text The string / text
@param int $maxLength Maximum length of given string
@param string $suffix (optional) The suffix to add at the end of string
@return string | [
"Returns",
"part",
"of",
"string",
"preserving",
"words"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L566-L587 |
36,392 | meritoo/common-library | src/Utilities/Miscellaneous.php | Miscellaneous.breakLongText | public static function breakLongText(
$text,
$perLine = 100,
$separator = '<br>',
$encoding = 'utf-8',
$proportionalAberration = 20
) {
$effect = $text;
$textLength = mb_strlen($text);
if (!empty($text) && $textLength > $perLine) {
/*
* The html_entity_decode() function is used here, because while operating
* on string that contains only special characters the string is divided
* incorrectly, e.g. "<<<<<" -> "<<<<&<br />lt;".
*/
//$text = htmlspecialchars_decode($text);
$text = html_entity_decode($text, ENT_QUOTES);
$effect = '';
$currentPosition = 0;
$charsAberration = ceil($perLine * ($proportionalAberration / 100));
$charsPerLineDefault = $perLine;
while ($currentPosition <= $textLength) {
$insertSeparator = false;
/*
* Looking for spaces before and after current position. It was done, because text wasn't
* broken properly and some words were breaked and placed into two lines.
*/
if ($charsAberration > 0) {
$length = $perLine + $charsAberration;
$lineWithAberration = mb_substr($text, $currentPosition, $length, $encoding);
if (!Regex::contains($lineWithAberration, ' ')) {
$length = $perLine - $charsAberration;
$lineWithAberration = mb_substr($text, $currentPosition, $length, $encoding);
}
if (Regex::startsWith($lineWithAberration, ' ')) {
++$currentPosition;
$lineWithAberration = ltrim($lineWithAberration);
}
$spacePosition = mb_strrpos($lineWithAberration, ' ', 0, $encoding);
if (false !== $spacePosition && 0 < $spacePosition) {
/** @var int $spacePosition */
$perLine = $spacePosition;
$insertSeparator = true;
}
}
$charsOneLine = mb_substr($text, $currentPosition, $perLine, $encoding);
/*
* The htmlspecialchars() function is used here, because...
* Reason and comment the same as above for html_entity_decode() function.
*/
$effect .= htmlspecialchars($charsOneLine);
//$effect .= $charsOneLine;
$currentPosition += $perLine;
$oneLineContainsSpace = Regex::contains($charsOneLine, ' ');
if (($insertSeparator || !$oneLineContainsSpace) && $currentPosition <= $textLength) {
$effect .= $separator;
}
$perLine = $charsPerLineDefault;
}
}
return $effect;
} | php | public static function breakLongText(
$text,
$perLine = 100,
$separator = '<br>',
$encoding = 'utf-8',
$proportionalAberration = 20
) {
$effect = $text;
$textLength = mb_strlen($text);
if (!empty($text) && $textLength > $perLine) {
/*
* The html_entity_decode() function is used here, because while operating
* on string that contains only special characters the string is divided
* incorrectly, e.g. "<<<<<" -> "<<<<&<br />lt;".
*/
//$text = htmlspecialchars_decode($text);
$text = html_entity_decode($text, ENT_QUOTES);
$effect = '';
$currentPosition = 0;
$charsAberration = ceil($perLine * ($proportionalAberration / 100));
$charsPerLineDefault = $perLine;
while ($currentPosition <= $textLength) {
$insertSeparator = false;
/*
* Looking for spaces before and after current position. It was done, because text wasn't
* broken properly and some words were breaked and placed into two lines.
*/
if ($charsAberration > 0) {
$length = $perLine + $charsAberration;
$lineWithAberration = mb_substr($text, $currentPosition, $length, $encoding);
if (!Regex::contains($lineWithAberration, ' ')) {
$length = $perLine - $charsAberration;
$lineWithAberration = mb_substr($text, $currentPosition, $length, $encoding);
}
if (Regex::startsWith($lineWithAberration, ' ')) {
++$currentPosition;
$lineWithAberration = ltrim($lineWithAberration);
}
$spacePosition = mb_strrpos($lineWithAberration, ' ', 0, $encoding);
if (false !== $spacePosition && 0 < $spacePosition) {
/** @var int $spacePosition */
$perLine = $spacePosition;
$insertSeparator = true;
}
}
$charsOneLine = mb_substr($text, $currentPosition, $perLine, $encoding);
/*
* The htmlspecialchars() function is used here, because...
* Reason and comment the same as above for html_entity_decode() function.
*/
$effect .= htmlspecialchars($charsOneLine);
//$effect .= $charsOneLine;
$currentPosition += $perLine;
$oneLineContainsSpace = Regex::contains($charsOneLine, ' ');
if (($insertSeparator || !$oneLineContainsSpace) && $currentPosition <= $textLength) {
$effect .= $separator;
}
$perLine = $charsPerLineDefault;
}
}
return $effect;
} | [
"public",
"static",
"function",
"breakLongText",
"(",
"$",
"text",
",",
"$",
"perLine",
"=",
"100",
",",
"$",
"separator",
"=",
"'<br>'",
",",
"$",
"encoding",
"=",
"'utf-8'",
",",
"$",
"proportionalAberration",
"=",
"20",
")",
"{",
"$",
"effect",
"=",
"$",
"text",
";",
"$",
"textLength",
"=",
"mb_strlen",
"(",
"$",
"text",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"text",
")",
"&&",
"$",
"textLength",
">",
"$",
"perLine",
")",
"{",
"/*\n * The html_entity_decode() function is used here, because while operating\n * on string that contains only special characters the string is divided\n * incorrectly, e.g. \"<<<<<\" -> \"<<<<&<br />lt;\".\n */",
"//$text = htmlspecialchars_decode($text);",
"$",
"text",
"=",
"html_entity_decode",
"(",
"$",
"text",
",",
"ENT_QUOTES",
")",
";",
"$",
"effect",
"=",
"''",
";",
"$",
"currentPosition",
"=",
"0",
";",
"$",
"charsAberration",
"=",
"ceil",
"(",
"$",
"perLine",
"*",
"(",
"$",
"proportionalAberration",
"/",
"100",
")",
")",
";",
"$",
"charsPerLineDefault",
"=",
"$",
"perLine",
";",
"while",
"(",
"$",
"currentPosition",
"<=",
"$",
"textLength",
")",
"{",
"$",
"insertSeparator",
"=",
"false",
";",
"/*\n * Looking for spaces before and after current position. It was done, because text wasn't\n * broken properly and some words were breaked and placed into two lines.\n */",
"if",
"(",
"$",
"charsAberration",
">",
"0",
")",
"{",
"$",
"length",
"=",
"$",
"perLine",
"+",
"$",
"charsAberration",
";",
"$",
"lineWithAberration",
"=",
"mb_substr",
"(",
"$",
"text",
",",
"$",
"currentPosition",
",",
"$",
"length",
",",
"$",
"encoding",
")",
";",
"if",
"(",
"!",
"Regex",
"::",
"contains",
"(",
"$",
"lineWithAberration",
",",
"' '",
")",
")",
"{",
"$",
"length",
"=",
"$",
"perLine",
"-",
"$",
"charsAberration",
";",
"$",
"lineWithAberration",
"=",
"mb_substr",
"(",
"$",
"text",
",",
"$",
"currentPosition",
",",
"$",
"length",
",",
"$",
"encoding",
")",
";",
"}",
"if",
"(",
"Regex",
"::",
"startsWith",
"(",
"$",
"lineWithAberration",
",",
"' '",
")",
")",
"{",
"++",
"$",
"currentPosition",
";",
"$",
"lineWithAberration",
"=",
"ltrim",
"(",
"$",
"lineWithAberration",
")",
";",
"}",
"$",
"spacePosition",
"=",
"mb_strrpos",
"(",
"$",
"lineWithAberration",
",",
"' '",
",",
"0",
",",
"$",
"encoding",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"spacePosition",
"&&",
"0",
"<",
"$",
"spacePosition",
")",
"{",
"/** @var int $spacePosition */",
"$",
"perLine",
"=",
"$",
"spacePosition",
";",
"$",
"insertSeparator",
"=",
"true",
";",
"}",
"}",
"$",
"charsOneLine",
"=",
"mb_substr",
"(",
"$",
"text",
",",
"$",
"currentPosition",
",",
"$",
"perLine",
",",
"$",
"encoding",
")",
";",
"/*\n * The htmlspecialchars() function is used here, because...\n * Reason and comment the same as above for html_entity_decode() function.\n */",
"$",
"effect",
".=",
"htmlspecialchars",
"(",
"$",
"charsOneLine",
")",
";",
"//$effect .= $charsOneLine;",
"$",
"currentPosition",
"+=",
"$",
"perLine",
";",
"$",
"oneLineContainsSpace",
"=",
"Regex",
"::",
"contains",
"(",
"$",
"charsOneLine",
",",
"' '",
")",
";",
"if",
"(",
"(",
"$",
"insertSeparator",
"||",
"!",
"$",
"oneLineContainsSpace",
")",
"&&",
"$",
"currentPosition",
"<=",
"$",
"textLength",
")",
"{",
"$",
"effect",
".=",
"$",
"separator",
";",
"}",
"$",
"perLine",
"=",
"$",
"charsPerLineDefault",
";",
"}",
"}",
"return",
"$",
"effect",
";",
"}"
] | Breaks long text
@param string $text The text to check and break
@param int $perLine (optional) Characters count per line. Default: 100.
@param string $separator (optional) Separator that is placed between lines. Default: "<br>".
@param string $encoding (optional) Character encoding. Used by mb_substr(). Default: "UTF-8".
@param int $proportionalAberration (optional) Proportional aberration for chars (percent value). Default: 20.
@return string | [
"Breaks",
"long",
"text"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L599-L676 |
36,393 | meritoo/common-library | src/Utilities/Miscellaneous.php | Miscellaneous.removeDirectory | public static function removeDirectory($directoryPath, $contentOnly = false)
{
/*
* Directory does not exist?
* Nothing to do
*/
if (!file_exists($directoryPath)) {
return null;
}
/*
* It's not a directory?
* Let's treat it like file
*/
if (!is_dir($directoryPath)) {
return unlink($directoryPath);
}
foreach (scandir($directoryPath, SCANDIR_SORT_ASCENDING) as $item) {
if ('.' === $item || '..' === $item) {
continue;
}
if (!self::removeDirectory($directoryPath . DIRECTORY_SEPARATOR . $item)) {
return false;
}
}
// Directory should be removed too?
if (!$contentOnly) {
return rmdir($directoryPath);
}
return true;
} | php | public static function removeDirectory($directoryPath, $contentOnly = false)
{
/*
* Directory does not exist?
* Nothing to do
*/
if (!file_exists($directoryPath)) {
return null;
}
/*
* It's not a directory?
* Let's treat it like file
*/
if (!is_dir($directoryPath)) {
return unlink($directoryPath);
}
foreach (scandir($directoryPath, SCANDIR_SORT_ASCENDING) as $item) {
if ('.' === $item || '..' === $item) {
continue;
}
if (!self::removeDirectory($directoryPath . DIRECTORY_SEPARATOR . $item)) {
return false;
}
}
// Directory should be removed too?
if (!$contentOnly) {
return rmdir($directoryPath);
}
return true;
} | [
"public",
"static",
"function",
"removeDirectory",
"(",
"$",
"directoryPath",
",",
"$",
"contentOnly",
"=",
"false",
")",
"{",
"/*\n * Directory does not exist?\n * Nothing to do\n */",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"directoryPath",
")",
")",
"{",
"return",
"null",
";",
"}",
"/*\n * It's not a directory?\n * Let's treat it like file\n */",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"directoryPath",
")",
")",
"{",
"return",
"unlink",
"(",
"$",
"directoryPath",
")",
";",
"}",
"foreach",
"(",
"scandir",
"(",
"$",
"directoryPath",
",",
"SCANDIR_SORT_ASCENDING",
")",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"'.'",
"===",
"$",
"item",
"||",
"'..'",
"===",
"$",
"item",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"self",
"::",
"removeDirectory",
"(",
"$",
"directoryPath",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"item",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"// Directory should be removed too?",
"if",
"(",
"!",
"$",
"contentOnly",
")",
"{",
"return",
"rmdir",
"(",
"$",
"directoryPath",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Removes the directory.
If not empty, removes also contents.
@param string $directoryPath Directory path
@param bool $contentOnly (optional) If is set to true, only content of the directory is removed, not
directory itself. Otherwise - directory is removed too (default behaviour).
@return null|bool | [
"Removes",
"the",
"directory",
".",
"If",
"not",
"empty",
"removes",
"also",
"contents",
"."
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L687-L721 |
36,394 | meritoo/common-library | src/Utilities/Miscellaneous.php | Miscellaneous.getCamelCase | public static function getCamelCase($string, $separator = ' ')
{
if (empty($string)) {
return '';
}
$effect = '';
$members = explode($separator, $string);
foreach ($members as $key => $value) {
$value = mb_strtolower($value);
if (0 === $key) {
$effect .= self::lowercaseFirst($value);
} else {
$effect .= self::uppercaseFirst($value);
}
}
return $effect;
} | php | public static function getCamelCase($string, $separator = ' ')
{
if (empty($string)) {
return '';
}
$effect = '';
$members = explode($separator, $string);
foreach ($members as $key => $value) {
$value = mb_strtolower($value);
if (0 === $key) {
$effect .= self::lowercaseFirst($value);
} else {
$effect .= self::uppercaseFirst($value);
}
}
return $effect;
} | [
"public",
"static",
"function",
"getCamelCase",
"(",
"$",
"string",
",",
"$",
"separator",
"=",
"' '",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"string",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"effect",
"=",
"''",
";",
"$",
"members",
"=",
"explode",
"(",
"$",
"separator",
",",
"$",
"string",
")",
";",
"foreach",
"(",
"$",
"members",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"mb_strtolower",
"(",
"$",
"value",
")",
";",
"if",
"(",
"0",
"===",
"$",
"key",
")",
"{",
"$",
"effect",
".=",
"self",
"::",
"lowercaseFirst",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"effect",
".=",
"self",
"::",
"uppercaseFirst",
"(",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"effect",
";",
"}"
] | Returns the string in camel case
@param string $string The string to convert e.g. this-is-eXamplE (return: thisIsExample)
@param string $separator (optional) Separator used to find parts of the string, e.g. '-' or ','
@return string | [
"Returns",
"the",
"string",
"in",
"camel",
"case"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L741-L761 |
36,395 | meritoo/common-library | src/Utilities/Miscellaneous.php | Miscellaneous.lowercaseFirst | public static function lowercaseFirst($text, $restLowercase = null)
{
if (empty($text)) {
return '';
}
$effect = $text;
if ($restLowercase) {
$effect = mb_strtolower($effect);
} elseif (false === $restLowercase) {
$effect = mb_strtoupper($effect);
}
return lcfirst($effect);
} | php | public static function lowercaseFirst($text, $restLowercase = null)
{
if (empty($text)) {
return '';
}
$effect = $text;
if ($restLowercase) {
$effect = mb_strtolower($effect);
} elseif (false === $restLowercase) {
$effect = mb_strtoupper($effect);
}
return lcfirst($effect);
} | [
"public",
"static",
"function",
"lowercaseFirst",
"(",
"$",
"text",
",",
"$",
"restLowercase",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"text",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"effect",
"=",
"$",
"text",
";",
"if",
"(",
"$",
"restLowercase",
")",
"{",
"$",
"effect",
"=",
"mb_strtolower",
"(",
"$",
"effect",
")",
";",
"}",
"elseif",
"(",
"false",
"===",
"$",
"restLowercase",
")",
"{",
"$",
"effect",
"=",
"mb_strtoupper",
"(",
"$",
"effect",
")",
";",
"}",
"return",
"lcfirst",
"(",
"$",
"effect",
")",
";",
"}"
] | Make a string's first character lowercase
@param string $text The text to get first character lowercase
@param null|bool $restLowercase (optional) Information that to do with rest of given string
@return string
Values of the $restLowercase argument:
- null (default): nothing is done with the string
- true: the rest of string is lowercased
- false: the rest of string is uppercased | [
"Make",
"a",
"string",
"s",
"first",
"character",
"lowercase"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L775-L790 |
36,396 | meritoo/common-library | src/Utilities/Miscellaneous.php | Miscellaneous.quoteValue | public static function quoteValue($value, $useApostrophe = true)
{
if (is_string($value)) {
$quotes = '"';
if ($useApostrophe) {
$quotes = '\'';
}
$value = sprintf('%s%s%s', $quotes, $value, $quotes);
}
return $value;
} | php | public static function quoteValue($value, $useApostrophe = true)
{
if (is_string($value)) {
$quotes = '"';
if ($useApostrophe) {
$quotes = '\'';
}
$value = sprintf('%s%s%s', $quotes, $value, $quotes);
}
return $value;
} | [
"public",
"static",
"function",
"quoteValue",
"(",
"$",
"value",
",",
"$",
"useApostrophe",
"=",
"true",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"quotes",
"=",
"'\"'",
";",
"if",
"(",
"$",
"useApostrophe",
")",
"{",
"$",
"quotes",
"=",
"'\\''",
";",
"}",
"$",
"value",
"=",
"sprintf",
"(",
"'%s%s%s'",
",",
"$",
"quotes",
",",
"$",
"value",
",",
"$",
"quotes",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Quotes given value with apostrophes or quotation marks
@param mixed $value The value to quote
@param bool $useApostrophe (optional) If is set to true, apostrophes are used. Otherwise - quotation marks.
@return string | [
"Quotes",
"given",
"value",
"with",
"apostrophes",
"or",
"quotation",
"marks"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L828-L841 |
36,397 | meritoo/common-library | src/Utilities/Miscellaneous.php | Miscellaneous.getStringWithoutLastElement | public static function getStringWithoutLastElement($string, $separator)
{
$elements = self::getStringElements($string, $separator);
$lastKey = Arrays::getLastKey($elements);
unset($elements[$lastKey]);
return implode($separator, $elements);
} | php | public static function getStringWithoutLastElement($string, $separator)
{
$elements = self::getStringElements($string, $separator);
$lastKey = Arrays::getLastKey($elements);
unset($elements[$lastKey]);
return implode($separator, $elements);
} | [
"public",
"static",
"function",
"getStringWithoutLastElement",
"(",
"$",
"string",
",",
"$",
"separator",
")",
"{",
"$",
"elements",
"=",
"self",
"::",
"getStringElements",
"(",
"$",
"string",
",",
"$",
"separator",
")",
";",
"$",
"lastKey",
"=",
"Arrays",
"::",
"getLastKey",
"(",
"$",
"elements",
")",
";",
"unset",
"(",
"$",
"elements",
"[",
"$",
"lastKey",
"]",
")",
";",
"return",
"implode",
"(",
"$",
"separator",
",",
"$",
"elements",
")",
";",
"}"
] | Returns string without the last element.
The string should contain given separator.
@param string $string The string to check
@param string $separator The separator which divides elements of string
@return string | [
"Returns",
"string",
"without",
"the",
"last",
"element",
".",
"The",
"string",
"should",
"contain",
"given",
"separator",
"."
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L875-L883 |
36,398 | meritoo/common-library | src/Utilities/Miscellaneous.php | Miscellaneous.getStringElements | public static function getStringElements($string, $separator)
{
$matches = [];
$pattern = sprintf('|[^\%s]+|', $separator);
$matchCount = preg_match_all($pattern, $string, $matches);
if ($matchCount > 1) {
return $matches[0];
}
return [];
} | php | public static function getStringElements($string, $separator)
{
$matches = [];
$pattern = sprintf('|[^\%s]+|', $separator);
$matchCount = preg_match_all($pattern, $string, $matches);
if ($matchCount > 1) {
return $matches[0];
}
return [];
} | [
"public",
"static",
"function",
"getStringElements",
"(",
"$",
"string",
",",
"$",
"separator",
")",
"{",
"$",
"matches",
"=",
"[",
"]",
";",
"$",
"pattern",
"=",
"sprintf",
"(",
"'|[^\\%s]+|'",
",",
"$",
"separator",
")",
";",
"$",
"matchCount",
"=",
"preg_match_all",
"(",
"$",
"pattern",
",",
"$",
"string",
",",
"$",
"matches",
")",
";",
"if",
"(",
"$",
"matchCount",
">",
"1",
")",
"{",
"return",
"$",
"matches",
"[",
"0",
"]",
";",
"}",
"return",
"[",
"]",
";",
"}"
] | Returns elements of given string divided by given separator
@param string $string The string to check
@param string $separator The separator which divides elements of string
@return array | [
"Returns",
"elements",
"of",
"given",
"string",
"divided",
"by",
"given",
"separator"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L892-L903 |
36,399 | meritoo/common-library | src/Utilities/Miscellaneous.php | Miscellaneous.getLastElementOfString | public static function getLastElementOfString($string, $separator)
{
$elements = self::getStringElements($string, $separator);
/*
* No elements?
* Nothing to do
*/
if (empty($elements)) {
return null;
}
$element = Arrays::getLastElement($elements);
return trim($element);
} | php | public static function getLastElementOfString($string, $separator)
{
$elements = self::getStringElements($string, $separator);
/*
* No elements?
* Nothing to do
*/
if (empty($elements)) {
return null;
}
$element = Arrays::getLastElement($elements);
return trim($element);
} | [
"public",
"static",
"function",
"getLastElementOfString",
"(",
"$",
"string",
",",
"$",
"separator",
")",
"{",
"$",
"elements",
"=",
"self",
"::",
"getStringElements",
"(",
"$",
"string",
",",
"$",
"separator",
")",
";",
"/*\n * No elements?\n * Nothing to do\n */",
"if",
"(",
"empty",
"(",
"$",
"elements",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"element",
"=",
"Arrays",
"::",
"getLastElement",
"(",
"$",
"elements",
")",
";",
"return",
"trim",
"(",
"$",
"element",
")",
";",
"}"
] | Returns the last element of given string divided by given separator
@param string $string The string to check
@param string $separator The separator which divides elements of string
@return null|string | [
"Returns",
"the",
"last",
"element",
"of",
"given",
"string",
"divided",
"by",
"given",
"separator"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L912-L927 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.