repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
kecik-framework/kecik | Kecik/Kecik.php | Kecik.run | public function run( $yield = NULL ) {
if ( php_sapi_name() == 'cli-server' ) {
if ( is_file( route::$BasePath . str_replace( '/', DIRECTORY_SEPARATOR, $_SERVER['REQUEST_URI'] ) ) &&
file_exists( route::$BasePath . str_replace( '/', DIRECTORY_SEPARATOR, $_SERVER['REQUEST_URI'] ) ) &&
substr( strtolower( $_SERVER['REQUEST_URI'] ), - 4 ) != '.php'
) {
readfile( route::$BasePath . str_replace( '/', DIRECTORY_SEPARATOR, $_SERVER['REQUEST_URI'] ) );
return TRUE;
}
}
if ( is_callable( $yield ) ) {
$this->callable = Closure::bind( $yield, $this, get_class() );
}
if ( self::$FullRender != '' ) {
if ( is_callable( $this->callable ) ) {
if ( is_callable( $this->before ) ) {
$before = $this->before;
$before( $this->request );
}
// Run Middleware Before
foreach ( $this->middleware['before'] as $middleware ) {
$middleware( $this, $this->request );
}
ob_start();
$response = call_user_func_array( $this->callable, $this->route->getParams() );
if ( ! is_string( $response ) && ! is_numeric( $response ) ) {
$response = json_encode( $response );
}
$result = ob_get_clean();
if ( is_callable( $this->after ) ) {
$after = $this->after;
$response = $after( $this->request, $response );
}
$response = ( empty( $response ) || is_bool( $response ) ) ? $result : $response . $result;
if ( count( self::$header ) > 0 && php_sapi_name() != 'cli' ) {
foreach ( self::$header as $headerValue ) {
header( $headerValue );
}
}
// Run Middleware After
foreach ( $this->middleware['after'] as $middleware ) {
$middleware( $this, $this->request );
}
// Replace Tag
echo self::$FullRender = $this->render(
$this->config->get( 'path.basepath' ) . $this->config->get( 'path.template' ) . '/' .
self::$FullRender . '.php',
$response
);
} else {
if ( php_sapi_name() != 'cli' ) {
header( $_SERVER["SERVER_PROTOCOL"] . ' ' . Route::$HttpResponse[404] );
}
if ( $this->config->get( 'error.404' ) != '' ) {
include $this->config->get( 'path.template' ) . '/' . $this->config->get( 'error.404' ) . '.php';
} else {
die( Route::$HttpResponse[404] );
}
}
self::$FullRender = '';
} else {
if ( is_callable( $this->callable ) ) {
if ( is_callable( $this->before ) ) {
$before = $this->before;
$before( $this->request );
}
// Run Middleware Before
foreach ( $this->middleware['before'] as $middleware ) {
$middleware( $this, $this->request );
}
ob_start();
$response = call_user_func_array( $this->callable, $this->route->getParams() );
if ( ! is_string( $response ) && ! is_numeric( $response ) ) {
$response = json_encode( $response );
}
$result = ob_get_clean();
if ( is_callable( $this->after ) ) {
$after = $this->after;
$response = $after( $this->request, $response );
}
$response = ( empty( $response ) || is_bool( $response ) ) ? $result : $response . $result;
if ( count( self::$header ) > 0 && php_sapi_name() != 'cli' ) {
foreach ( self::$header as $headerValue ) {
header( $headerValue );
}
}
// Run Middleware After
foreach ( $this->middleware['after'] as $middleware ) {
$middleware( $this, $this->request );
}
echo $response;
//echo $result;
} else {
if ( php_sapi_name() != 'cli' ) {
header( $_SERVER["SERVER_PROTOCOL"] . ' ' . Route::$HttpResponse[404] );
}
if ( $this->config->get( 'error.404' ) != '' ) {
echo $this->render( $this->config->get( 'path.template' ) . '/' . $this->config->get( 'error.404' ) . '.php' );
} else {
die( Route::$HttpResponse[404] );
}
}
}
} | php | public function run( $yield = NULL ) {
if ( php_sapi_name() == 'cli-server' ) {
if ( is_file( route::$BasePath . str_replace( '/', DIRECTORY_SEPARATOR, $_SERVER['REQUEST_URI'] ) ) &&
file_exists( route::$BasePath . str_replace( '/', DIRECTORY_SEPARATOR, $_SERVER['REQUEST_URI'] ) ) &&
substr( strtolower( $_SERVER['REQUEST_URI'] ), - 4 ) != '.php'
) {
readfile( route::$BasePath . str_replace( '/', DIRECTORY_SEPARATOR, $_SERVER['REQUEST_URI'] ) );
return TRUE;
}
}
if ( is_callable( $yield ) ) {
$this->callable = Closure::bind( $yield, $this, get_class() );
}
if ( self::$FullRender != '' ) {
if ( is_callable( $this->callable ) ) {
if ( is_callable( $this->before ) ) {
$before = $this->before;
$before( $this->request );
}
// Run Middleware Before
foreach ( $this->middleware['before'] as $middleware ) {
$middleware( $this, $this->request );
}
ob_start();
$response = call_user_func_array( $this->callable, $this->route->getParams() );
if ( ! is_string( $response ) && ! is_numeric( $response ) ) {
$response = json_encode( $response );
}
$result = ob_get_clean();
if ( is_callable( $this->after ) ) {
$after = $this->after;
$response = $after( $this->request, $response );
}
$response = ( empty( $response ) || is_bool( $response ) ) ? $result : $response . $result;
if ( count( self::$header ) > 0 && php_sapi_name() != 'cli' ) {
foreach ( self::$header as $headerValue ) {
header( $headerValue );
}
}
// Run Middleware After
foreach ( $this->middleware['after'] as $middleware ) {
$middleware( $this, $this->request );
}
// Replace Tag
echo self::$FullRender = $this->render(
$this->config->get( 'path.basepath' ) . $this->config->get( 'path.template' ) . '/' .
self::$FullRender . '.php',
$response
);
} else {
if ( php_sapi_name() != 'cli' ) {
header( $_SERVER["SERVER_PROTOCOL"] . ' ' . Route::$HttpResponse[404] );
}
if ( $this->config->get( 'error.404' ) != '' ) {
include $this->config->get( 'path.template' ) . '/' . $this->config->get( 'error.404' ) . '.php';
} else {
die( Route::$HttpResponse[404] );
}
}
self::$FullRender = '';
} else {
if ( is_callable( $this->callable ) ) {
if ( is_callable( $this->before ) ) {
$before = $this->before;
$before( $this->request );
}
// Run Middleware Before
foreach ( $this->middleware['before'] as $middleware ) {
$middleware( $this, $this->request );
}
ob_start();
$response = call_user_func_array( $this->callable, $this->route->getParams() );
if ( ! is_string( $response ) && ! is_numeric( $response ) ) {
$response = json_encode( $response );
}
$result = ob_get_clean();
if ( is_callable( $this->after ) ) {
$after = $this->after;
$response = $after( $this->request, $response );
}
$response = ( empty( $response ) || is_bool( $response ) ) ? $result : $response . $result;
if ( count( self::$header ) > 0 && php_sapi_name() != 'cli' ) {
foreach ( self::$header as $headerValue ) {
header( $headerValue );
}
}
// Run Middleware After
foreach ( $this->middleware['after'] as $middleware ) {
$middleware( $this, $this->request );
}
echo $response;
//echo $result;
} else {
if ( php_sapi_name() != 'cli' ) {
header( $_SERVER["SERVER_PROTOCOL"] . ' ' . Route::$HttpResponse[404] );
}
if ( $this->config->get( 'error.404' ) != '' ) {
echo $this->render( $this->config->get( 'path.template' ) . '/' . $this->config->get( 'error.404' ) . '.php' );
} else {
die( Route::$HttpResponse[404] );
}
}
}
} | [
"public",
"function",
"run",
"(",
"$",
"yield",
"=",
"NULL",
")",
"{",
"if",
"(",
"php_sapi_name",
"(",
")",
"==",
"'cli-server'",
")",
"{",
"if",
"(",
"is_file",
"(",
"route",
"::",
"$",
"BasePath",
".",
"str_replace",
"(",
"'/'",
",",
"DIRECTORY_SEPARATOR",
",",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
")",
"&&",
"file_exists",
"(",
"route",
"::",
"$",
"BasePath",
".",
"str_replace",
"(",
"'/'",
",",
"DIRECTORY_SEPARATOR",
",",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
")",
"&&",
"substr",
"(",
"strtolower",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
",",
"-",
"4",
")",
"!=",
"'.php'",
")",
"{",
"readfile",
"(",
"route",
"::",
"$",
"BasePath",
".",
"str_replace",
"(",
"'/'",
",",
"DIRECTORY_SEPARATOR",
",",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
")",
";",
"return",
"TRUE",
";",
"}",
"}",
"if",
"(",
"is_callable",
"(",
"$",
"yield",
")",
")",
"{",
"$",
"this",
"->",
"callable",
"=",
"Closure",
"::",
"bind",
"(",
"$",
"yield",
",",
"$",
"this",
",",
"get_class",
"(",
")",
")",
";",
"}",
"if",
"(",
"self",
"::",
"$",
"FullRender",
"!=",
"''",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"callable",
")",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"before",
")",
")",
"{",
"$",
"before",
"=",
"$",
"this",
"->",
"before",
";",
"$",
"before",
"(",
"$",
"this",
"->",
"request",
")",
";",
"}",
"// Run Middleware Before\r",
"foreach",
"(",
"$",
"this",
"->",
"middleware",
"[",
"'before'",
"]",
"as",
"$",
"middleware",
")",
"{",
"$",
"middleware",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"request",
")",
";",
"}",
"ob_start",
"(",
")",
";",
"$",
"response",
"=",
"call_user_func_array",
"(",
"$",
"this",
"->",
"callable",
",",
"$",
"this",
"->",
"route",
"->",
"getParams",
"(",
")",
")",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"response",
")",
"&&",
"!",
"is_numeric",
"(",
"$",
"response",
")",
")",
"{",
"$",
"response",
"=",
"json_encode",
"(",
"$",
"response",
")",
";",
"}",
"$",
"result",
"=",
"ob_get_clean",
"(",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"after",
")",
")",
"{",
"$",
"after",
"=",
"$",
"this",
"->",
"after",
";",
"$",
"response",
"=",
"$",
"after",
"(",
"$",
"this",
"->",
"request",
",",
"$",
"response",
")",
";",
"}",
"$",
"response",
"=",
"(",
"empty",
"(",
"$",
"response",
")",
"||",
"is_bool",
"(",
"$",
"response",
")",
")",
"?",
"$",
"result",
":",
"$",
"response",
".",
"$",
"result",
";",
"if",
"(",
"count",
"(",
"self",
"::",
"$",
"header",
")",
">",
"0",
"&&",
"php_sapi_name",
"(",
")",
"!=",
"'cli'",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"header",
"as",
"$",
"headerValue",
")",
"{",
"header",
"(",
"$",
"headerValue",
")",
";",
"}",
"}",
"// Run Middleware After\r",
"foreach",
"(",
"$",
"this",
"->",
"middleware",
"[",
"'after'",
"]",
"as",
"$",
"middleware",
")",
"{",
"$",
"middleware",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"request",
")",
";",
"}",
"// Replace Tag\r",
"echo",
"self",
"::",
"$",
"FullRender",
"=",
"$",
"this",
"->",
"render",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'path.basepath'",
")",
".",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'path.template'",
")",
".",
"'/'",
".",
"self",
"::",
"$",
"FullRender",
".",
"'.php'",
",",
"$",
"response",
")",
";",
"}",
"else",
"{",
"if",
"(",
"php_sapi_name",
"(",
")",
"!=",
"'cli'",
")",
"{",
"header",
"(",
"$",
"_SERVER",
"[",
"\"SERVER_PROTOCOL\"",
"]",
".",
"' '",
".",
"Route",
"::",
"$",
"HttpResponse",
"[",
"404",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'error.404'",
")",
"!=",
"''",
")",
"{",
"include",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'path.template'",
")",
".",
"'/'",
".",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'error.404'",
")",
".",
"'.php'",
";",
"}",
"else",
"{",
"die",
"(",
"Route",
"::",
"$",
"HttpResponse",
"[",
"404",
"]",
")",
";",
"}",
"}",
"self",
"::",
"$",
"FullRender",
"=",
"''",
";",
"}",
"else",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"callable",
")",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"before",
")",
")",
"{",
"$",
"before",
"=",
"$",
"this",
"->",
"before",
";",
"$",
"before",
"(",
"$",
"this",
"->",
"request",
")",
";",
"}",
"// Run Middleware Before\r",
"foreach",
"(",
"$",
"this",
"->",
"middleware",
"[",
"'before'",
"]",
"as",
"$",
"middleware",
")",
"{",
"$",
"middleware",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"request",
")",
";",
"}",
"ob_start",
"(",
")",
";",
"$",
"response",
"=",
"call_user_func_array",
"(",
"$",
"this",
"->",
"callable",
",",
"$",
"this",
"->",
"route",
"->",
"getParams",
"(",
")",
")",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"response",
")",
"&&",
"!",
"is_numeric",
"(",
"$",
"response",
")",
")",
"{",
"$",
"response",
"=",
"json_encode",
"(",
"$",
"response",
")",
";",
"}",
"$",
"result",
"=",
"ob_get_clean",
"(",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"after",
")",
")",
"{",
"$",
"after",
"=",
"$",
"this",
"->",
"after",
";",
"$",
"response",
"=",
"$",
"after",
"(",
"$",
"this",
"->",
"request",
",",
"$",
"response",
")",
";",
"}",
"$",
"response",
"=",
"(",
"empty",
"(",
"$",
"response",
")",
"||",
"is_bool",
"(",
"$",
"response",
")",
")",
"?",
"$",
"result",
":",
"$",
"response",
".",
"$",
"result",
";",
"if",
"(",
"count",
"(",
"self",
"::",
"$",
"header",
")",
">",
"0",
"&&",
"php_sapi_name",
"(",
")",
"!=",
"'cli'",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"header",
"as",
"$",
"headerValue",
")",
"{",
"header",
"(",
"$",
"headerValue",
")",
";",
"}",
"}",
"// Run Middleware After\r",
"foreach",
"(",
"$",
"this",
"->",
"middleware",
"[",
"'after'",
"]",
"as",
"$",
"middleware",
")",
"{",
"$",
"middleware",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"request",
")",
";",
"}",
"echo",
"$",
"response",
";",
"//echo $result;\r",
"}",
"else",
"{",
"if",
"(",
"php_sapi_name",
"(",
")",
"!=",
"'cli'",
")",
"{",
"header",
"(",
"$",
"_SERVER",
"[",
"\"SERVER_PROTOCOL\"",
"]",
".",
"' '",
".",
"Route",
"::",
"$",
"HttpResponse",
"[",
"404",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'error.404'",
")",
"!=",
"''",
")",
"{",
"echo",
"$",
"this",
"->",
"render",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'path.template'",
")",
".",
"'/'",
".",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'error.404'",
")",
".",
"'.php'",
")",
";",
"}",
"else",
"{",
"die",
"(",
"Route",
"::",
"$",
"HttpResponse",
"[",
"404",
"]",
")",
";",
"}",
"}",
"}",
"}"
] | Run Kecik Framework
@param null $yield
@return bool | [
"Run",
"Kecik",
"Framework"
] | train | https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Kecik.php#L708-L853 |
kecik-framework/kecik | Kecik/Kecik.php | Kecik.render | public function render( $file, $response = "" ) {
ob_start();
include $file;
self::$FullRender = ob_get_clean();
$config = $this->config;
self::$FullRender = preg_replace_callback(
array(
'/(\\\)?' . addslashes( $this->config->get( 'template.open_tag' ) ) . '=?' . '/',
'/(\\\)?' . addslashes( $this->config->get( 'template.close_tag' ) ) . '/'
),
function ( $s ) use ( $config ) {
if ( isset( $s[0] ) ) {
if ( isset( $s[1] ) && $s[1] == '\\' ) {
return substr( $s[0], 1 );
} elseif ( $s[0] == $this->config->get( 'template.open_tag' ) ) {
return '<?php ';
} elseif ( $s[0] == $this->config->get( 'template.open_tag' ) . '=' ) {
return '<?php echo ';
} elseif ( $s[0] == $this->config->get( 'template.close_tag' ) ) {
return '?>';
}
}
},
self::$FullRender
);
self::$FullRender = str_replace(
array( '@js', '@css' ),
array( $this->assets->js->render(), $this->assets->css->render() ),
self::$FullRender
);
if ( ! empty( $response ) ) {
self::$FullRender = str_replace(
array( '@yield', '@response' ),
array( $response, $response ),
self::$FullRender
);
}
//--- END Replace Tag
ob_start();
eval( '?>' . self::$FullRender );
self::$FullRender = ob_get_clean();
return self::$FullRender;
} | php | public function render( $file, $response = "" ) {
ob_start();
include $file;
self::$FullRender = ob_get_clean();
$config = $this->config;
self::$FullRender = preg_replace_callback(
array(
'/(\\\)?' . addslashes( $this->config->get( 'template.open_tag' ) ) . '=?' . '/',
'/(\\\)?' . addslashes( $this->config->get( 'template.close_tag' ) ) . '/'
),
function ( $s ) use ( $config ) {
if ( isset( $s[0] ) ) {
if ( isset( $s[1] ) && $s[1] == '\\' ) {
return substr( $s[0], 1 );
} elseif ( $s[0] == $this->config->get( 'template.open_tag' ) ) {
return '<?php ';
} elseif ( $s[0] == $this->config->get( 'template.open_tag' ) . '=' ) {
return '<?php echo ';
} elseif ( $s[0] == $this->config->get( 'template.close_tag' ) ) {
return '?>';
}
}
},
self::$FullRender
);
self::$FullRender = str_replace(
array( '@js', '@css' ),
array( $this->assets->js->render(), $this->assets->css->render() ),
self::$FullRender
);
if ( ! empty( $response ) ) {
self::$FullRender = str_replace(
array( '@yield', '@response' ),
array( $response, $response ),
self::$FullRender
);
}
//--- END Replace Tag
ob_start();
eval( '?>' . self::$FullRender );
self::$FullRender = ob_get_clean();
return self::$FullRender;
} | [
"public",
"function",
"render",
"(",
"$",
"file",
",",
"$",
"response",
"=",
"\"\"",
")",
"{",
"ob_start",
"(",
")",
";",
"include",
"$",
"file",
";",
"self",
"::",
"$",
"FullRender",
"=",
"ob_get_clean",
"(",
")",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"config",
";",
"self",
"::",
"$",
"FullRender",
"=",
"preg_replace_callback",
"(",
"array",
"(",
"'/(\\\\\\)?'",
".",
"addslashes",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'template.open_tag'",
")",
")",
".",
"'=?'",
".",
"'/'",
",",
"'/(\\\\\\)?'",
".",
"addslashes",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'template.close_tag'",
")",
")",
".",
"'/'",
")",
",",
"function",
"(",
"$",
"s",
")",
"use",
"(",
"$",
"config",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"s",
"[",
"0",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"s",
"[",
"1",
"]",
")",
"&&",
"$",
"s",
"[",
"1",
"]",
"==",
"'\\\\'",
")",
"{",
"return",
"substr",
"(",
"$",
"s",
"[",
"0",
"]",
",",
"1",
")",
";",
"}",
"elseif",
"(",
"$",
"s",
"[",
"0",
"]",
"==",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'template.open_tag'",
")",
")",
"{",
"return",
"'<?php '",
";",
"}",
"elseif",
"(",
"$",
"s",
"[",
"0",
"]",
"==",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'template.open_tag'",
")",
".",
"'='",
")",
"{",
"return",
"'<?php echo '",
";",
"}",
"elseif",
"(",
"$",
"s",
"[",
"0",
"]",
"==",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'template.close_tag'",
")",
")",
"{",
"return",
"'?>'",
";",
"}",
"}",
"}",
",",
"self",
"::",
"$",
"FullRender",
")",
";",
"self",
"::",
"$",
"FullRender",
"=",
"str_replace",
"(",
"array",
"(",
"'@js'",
",",
"'@css'",
")",
",",
"array",
"(",
"$",
"this",
"->",
"assets",
"->",
"js",
"->",
"render",
"(",
")",
",",
"$",
"this",
"->",
"assets",
"->",
"css",
"->",
"render",
"(",
")",
")",
",",
"self",
"::",
"$",
"FullRender",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"response",
")",
")",
"{",
"self",
"::",
"$",
"FullRender",
"=",
"str_replace",
"(",
"array",
"(",
"'@yield'",
",",
"'@response'",
")",
",",
"array",
"(",
"$",
"response",
",",
"$",
"response",
")",
",",
"self",
"::",
"$",
"FullRender",
")",
";",
"}",
"//--- END Replace Tag\r",
"ob_start",
"(",
")",
";",
"eval",
"(",
"'?>'",
".",
"self",
"::",
"$",
"FullRender",
")",
";",
"self",
"::",
"$",
"FullRender",
"=",
"ob_get_clean",
"(",
")",
";",
"return",
"self",
"::",
"$",
"FullRender",
";",
"}"
] | Render the template
@param $file
@param string $response
@return string | [
"Render",
"the",
"template"
] | train | https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Kecik.php#L863-L916 |
kecik-framework/kecik | Kecik/Kecik.php | Kecik.error | public function error( $code ) {
header( $_SERVER["SERVER_PROTOCOL"] . Route::$HttpResponse[ $code ] );
if ( $this->config->get( "error.$code" ) != '' ) {
echo $this->render( $this->config->get( 'path.template' ) . '/' . $this->config->get( "error.$code" ) . '.php' );
} else {
die( Route::$HttpResponse[ $code ] );
}
} | php | public function error( $code ) {
header( $_SERVER["SERVER_PROTOCOL"] . Route::$HttpResponse[ $code ] );
if ( $this->config->get( "error.$code" ) != '' ) {
echo $this->render( $this->config->get( 'path.template' ) . '/' . $this->config->get( "error.$code" ) . '.php' );
} else {
die( Route::$HttpResponse[ $code ] );
}
} | [
"public",
"function",
"error",
"(",
"$",
"code",
")",
"{",
"header",
"(",
"$",
"_SERVER",
"[",
"\"SERVER_PROTOCOL\"",
"]",
".",
"Route",
"::",
"$",
"HttpResponse",
"[",
"$",
"code",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"\"error.$code\"",
")",
"!=",
"''",
")",
"{",
"echo",
"$",
"this",
"->",
"render",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'path.template'",
")",
".",
"'/'",
".",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"\"error.$code\"",
")",
".",
"'.php'",
")",
";",
"}",
"else",
"{",
"die",
"(",
"Route",
"::",
"$",
"HttpResponse",
"[",
"$",
"code",
"]",
")",
";",
"}",
"}"
] | Set error
@param $code | [
"Set",
"error"
] | train | https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Kecik.php#L923-L932 |
kecik-framework/kecik | Kecik/Kecik.php | Kecik.header | public function header( $code = 200 ) {
if ( ! is_array( $code ) ) {
$code = array( $code );
}
self::$header = array();
foreach ( $code as $value ) {
if ( is_int( $value ) ) {
self::$header[] = $_SERVER["SERVER_PROTOCOL"] . ' ' . Route::$HttpResponse[ $value ];
} else {
self::$header[] = $value;
}
}
} | php | public function header( $code = 200 ) {
if ( ! is_array( $code ) ) {
$code = array( $code );
}
self::$header = array();
foreach ( $code as $value ) {
if ( is_int( $value ) ) {
self::$header[] = $_SERVER["SERVER_PROTOCOL"] . ' ' . Route::$HttpResponse[ $value ];
} else {
self::$header[] = $value;
}
}
} | [
"public",
"function",
"header",
"(",
"$",
"code",
"=",
"200",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"code",
")",
")",
"{",
"$",
"code",
"=",
"array",
"(",
"$",
"code",
")",
";",
"}",
"self",
"::",
"$",
"header",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"code",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"value",
")",
")",
"{",
"self",
"::",
"$",
"header",
"[",
"]",
"=",
"$",
"_SERVER",
"[",
"\"SERVER_PROTOCOL\"",
"]",
".",
"' '",
".",
"Route",
"::",
"$",
"HttpResponse",
"[",
"$",
"value",
"]",
";",
"}",
"else",
"{",
"self",
"::",
"$",
"header",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}"
] | Set Header Response
@param int $code | [
"Set",
"Header",
"Response"
] | train | https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Kecik.php#L946-L964 |
php-lug/lug | src/Bundle/ResourceBundle/Form/Extension/AbstractLabelExtension.php | AbstractLabelExtension.finishView | public function finishView(FormView $view, FormInterface $form, array $options)
{
if ($view->vars['label'] !== null) {
return;
}
$view->vars['label'] = $label = $this->createLabelPrefix($view, $form);
if (array_key_exists('label_add', $view->vars) && $view->vars['label_add'] === null) {
$view->vars['label_add'] = $label.'.add';
$view->vars['label'] = $label.'.label';
}
if (array_key_exists('label_delete', $view->vars) && $view->vars['label_delete'] === null) {
$view->vars['label_delete'] = $label.'.delete';
$view->vars['label'] = $label.'.label';
}
} | php | public function finishView(FormView $view, FormInterface $form, array $options)
{
if ($view->vars['label'] !== null) {
return;
}
$view->vars['label'] = $label = $this->createLabelPrefix($view, $form);
if (array_key_exists('label_add', $view->vars) && $view->vars['label_add'] === null) {
$view->vars['label_add'] = $label.'.add';
$view->vars['label'] = $label.'.label';
}
if (array_key_exists('label_delete', $view->vars) && $view->vars['label_delete'] === null) {
$view->vars['label_delete'] = $label.'.delete';
$view->vars['label'] = $label.'.label';
}
} | [
"public",
"function",
"finishView",
"(",
"FormView",
"$",
"view",
",",
"FormInterface",
"$",
"form",
",",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"$",
"view",
"->",
"vars",
"[",
"'label'",
"]",
"!==",
"null",
")",
"{",
"return",
";",
"}",
"$",
"view",
"->",
"vars",
"[",
"'label'",
"]",
"=",
"$",
"label",
"=",
"$",
"this",
"->",
"createLabelPrefix",
"(",
"$",
"view",
",",
"$",
"form",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'label_add'",
",",
"$",
"view",
"->",
"vars",
")",
"&&",
"$",
"view",
"->",
"vars",
"[",
"'label_add'",
"]",
"===",
"null",
")",
"{",
"$",
"view",
"->",
"vars",
"[",
"'label_add'",
"]",
"=",
"$",
"label",
".",
"'.add'",
";",
"$",
"view",
"->",
"vars",
"[",
"'label'",
"]",
"=",
"$",
"label",
".",
"'.label'",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'label_delete'",
",",
"$",
"view",
"->",
"vars",
")",
"&&",
"$",
"view",
"->",
"vars",
"[",
"'label_delete'",
"]",
"===",
"null",
")",
"{",
"$",
"view",
"->",
"vars",
"[",
"'label_delete'",
"]",
"=",
"$",
"label",
".",
"'.delete'",
";",
"$",
"view",
"->",
"vars",
"[",
"'label'",
"]",
"=",
"$",
"label",
".",
"'.label'",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/ResourceBundle/Form/Extension/AbstractLabelExtension.php#L35-L52 |
php-lug/lug | src/Bundle/ResourceBundle/Form/Extension/AbstractLabelExtension.php | AbstractLabelExtension.createLabelPrefix | private function createLabelPrefix(FormView $view, FormInterface $form, $depth = 1)
{
if (($labelPrefix = $form->getConfig()->getOption('label_prefix')) === null) {
return $this->createParentLabelPrefix($view, $form, $depth);
}
if ($depth === 1 && ($rootLabelPrefix = $this->createParentLabelPrefix($view, $form, $depth)) !== null) {
return $rootLabelPrefix;
}
return $labelPrefix;
} | php | private function createLabelPrefix(FormView $view, FormInterface $form, $depth = 1)
{
if (($labelPrefix = $form->getConfig()->getOption('label_prefix')) === null) {
return $this->createParentLabelPrefix($view, $form, $depth);
}
if ($depth === 1 && ($rootLabelPrefix = $this->createParentLabelPrefix($view, $form, $depth)) !== null) {
return $rootLabelPrefix;
}
return $labelPrefix;
} | [
"private",
"function",
"createLabelPrefix",
"(",
"FormView",
"$",
"view",
",",
"FormInterface",
"$",
"form",
",",
"$",
"depth",
"=",
"1",
")",
"{",
"if",
"(",
"(",
"$",
"labelPrefix",
"=",
"$",
"form",
"->",
"getConfig",
"(",
")",
"->",
"getOption",
"(",
"'label_prefix'",
")",
")",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"createParentLabelPrefix",
"(",
"$",
"view",
",",
"$",
"form",
",",
"$",
"depth",
")",
";",
"}",
"if",
"(",
"$",
"depth",
"===",
"1",
"&&",
"(",
"$",
"rootLabelPrefix",
"=",
"$",
"this",
"->",
"createParentLabelPrefix",
"(",
"$",
"view",
",",
"$",
"form",
",",
"$",
"depth",
")",
")",
"!==",
"null",
")",
"{",
"return",
"$",
"rootLabelPrefix",
";",
"}",
"return",
"$",
"labelPrefix",
";",
"}"
] | @param FormView $view
@param FormInterface $form
@param int $depth
@return string|null | [
"@param",
"FormView",
"$view",
"@param",
"FormInterface",
"$form",
"@param",
"int",
"$depth"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/ResourceBundle/Form/Extension/AbstractLabelExtension.php#L75-L86 |
php-lug/lug | src/Bundle/ResourceBundle/Form/Extension/AbstractLabelExtension.php | AbstractLabelExtension.createParentLabelPrefix | private function createParentLabelPrefix(FormView $view, FormInterface $form, $depth)
{
if ($view->parent !== null
&& $form->getParent() !== null
&& ($label = $this->createLabelPrefix($view->parent, $form->getParent(), ++$depth)) !== null) {
return $label.'.'.$view->vars['name'];
}
} | php | private function createParentLabelPrefix(FormView $view, FormInterface $form, $depth)
{
if ($view->parent !== null
&& $form->getParent() !== null
&& ($label = $this->createLabelPrefix($view->parent, $form->getParent(), ++$depth)) !== null) {
return $label.'.'.$view->vars['name'];
}
} | [
"private",
"function",
"createParentLabelPrefix",
"(",
"FormView",
"$",
"view",
",",
"FormInterface",
"$",
"form",
",",
"$",
"depth",
")",
"{",
"if",
"(",
"$",
"view",
"->",
"parent",
"!==",
"null",
"&&",
"$",
"form",
"->",
"getParent",
"(",
")",
"!==",
"null",
"&&",
"(",
"$",
"label",
"=",
"$",
"this",
"->",
"createLabelPrefix",
"(",
"$",
"view",
"->",
"parent",
",",
"$",
"form",
"->",
"getParent",
"(",
")",
",",
"++",
"$",
"depth",
")",
")",
"!==",
"null",
")",
"{",
"return",
"$",
"label",
".",
"'.'",
".",
"$",
"view",
"->",
"vars",
"[",
"'name'",
"]",
";",
"}",
"}"
] | @param FormView $view
@param FormInterface $form
@param int $depth
@return string|null | [
"@param",
"FormView",
"$view",
"@param",
"FormInterface",
"$form",
"@param",
"int",
"$depth"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/ResourceBundle/Form/Extension/AbstractLabelExtension.php#L95-L102 |
jaeger-app/db-mysql | src/Traits/MySQL/Mycnf.php | Mycnf.createMyCnf | private function createMyCnf(array $db_info, $path)
{
$this->db_info = $db_info;
$data = array(
'head' => '[client]',
'user' => 'user = ' . $this->db_info['user'],
'password' => 'password = ' . $this->db_info['password'],
'host' => 'host = ' . $this->db_info['host']
);
$content = implode(PHP_EOL, $data);
$path = $path . DIRECTORY_SEPARATOR . 'my.cnf';
$fp = fopen($path, "wb");
fwrite($fp, $content);
fclose($fp);
return $path;
} | php | private function createMyCnf(array $db_info, $path)
{
$this->db_info = $db_info;
$data = array(
'head' => '[client]',
'user' => 'user = ' . $this->db_info['user'],
'password' => 'password = ' . $this->db_info['password'],
'host' => 'host = ' . $this->db_info['host']
);
$content = implode(PHP_EOL, $data);
$path = $path . DIRECTORY_SEPARATOR . 'my.cnf';
$fp = fopen($path, "wb");
fwrite($fp, $content);
fclose($fp);
return $path;
} | [
"private",
"function",
"createMyCnf",
"(",
"array",
"$",
"db_info",
",",
"$",
"path",
")",
"{",
"$",
"this",
"->",
"db_info",
"=",
"$",
"db_info",
";",
"$",
"data",
"=",
"array",
"(",
"'head'",
"=>",
"'[client]'",
",",
"'user'",
"=>",
"'user = '",
".",
"$",
"this",
"->",
"db_info",
"[",
"'user'",
"]",
",",
"'password'",
"=>",
"'password = '",
".",
"$",
"this",
"->",
"db_info",
"[",
"'password'",
"]",
",",
"'host'",
"=>",
"'host = '",
".",
"$",
"this",
"->",
"db_info",
"[",
"'host'",
"]",
")",
";",
"$",
"content",
"=",
"implode",
"(",
"PHP_EOL",
",",
"$",
"data",
")",
";",
"$",
"path",
"=",
"$",
"path",
".",
"DIRECTORY_SEPARATOR",
".",
"'my.cnf'",
";",
"$",
"fp",
"=",
"fopen",
"(",
"$",
"path",
",",
"\"wb\"",
")",
";",
"fwrite",
"(",
"$",
"fp",
",",
"$",
"content",
")",
";",
"fclose",
"(",
"$",
"fp",
")",
";",
"return",
"$",
"path",
";",
"}"
] | Creates the my.cnf file for
@param array $db_info
@param unknown $path
@return string | [
"Creates",
"the",
"my",
".",
"cnf",
"file",
"for"
] | train | https://github.com/jaeger-app/db-mysql/blob/8211957b97dbcebeb7e65e0e5ab686c12992da72/src/Traits/MySQL/Mycnf.php#L30-L47 |
petrica/php-statsd-system | Model/TopCommand.php | TopCommand.run | public function run()
{
$result = $this->getCommand()->run();
if ($result->getExitCode() != 0) {
throw new \RuntimeException(sprintf(
'Command failed. Exit code %d, output %s',
$result->getExitCode(),
$result->getStdErr()));
}
return $this->parse($result->getStdOut());
} | php | public function run()
{
$result = $this->getCommand()->run();
if ($result->getExitCode() != 0) {
throw new \RuntimeException(sprintf(
'Command failed. Exit code %d, output %s',
$result->getExitCode(),
$result->getStdErr()));
}
return $this->parse($result->getStdOut());
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getCommand",
"(",
")",
"->",
"run",
"(",
")",
";",
"if",
"(",
"$",
"result",
"->",
"getExitCode",
"(",
")",
"!=",
"0",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Command failed. Exit code %d, output %s'",
",",
"$",
"result",
"->",
"getExitCode",
"(",
")",
",",
"$",
"result",
"->",
"getStdErr",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"parse",
"(",
"$",
"result",
"->",
"getStdOut",
"(",
")",
")",
";",
"}"
] | Run configured command
@return string | [
"Run",
"configured",
"command"
] | train | https://github.com/petrica/php-statsd-system/blob/c476be3514a631a605737888bb8f6eb096789c9d/Model/TopCommand.php#L39-L51 |
petrica/php-statsd-system | Model/TopCommand.php | TopCommand.parse | protected function parse($output)
{
$lines = explode(PHP_EOL, $output);
$stats = array();
foreach ($lines as $line) {
$data = explode(' ', $line);
array_walk($data, 'trim');
$stats[] = array_values(array_filter($data, function ($value) {
return strlen($value) > 0;
}));
}
return $stats;
} | php | protected function parse($output)
{
$lines = explode(PHP_EOL, $output);
$stats = array();
foreach ($lines as $line) {
$data = explode(' ', $line);
array_walk($data, 'trim');
$stats[] = array_values(array_filter($data, function ($value) {
return strlen($value) > 0;
}));
}
return $stats;
} | [
"protected",
"function",
"parse",
"(",
"$",
"output",
")",
"{",
"$",
"lines",
"=",
"explode",
"(",
"PHP_EOL",
",",
"$",
"output",
")",
";",
"$",
"stats",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"$",
"data",
"=",
"explode",
"(",
"' '",
",",
"$",
"line",
")",
";",
"array_walk",
"(",
"$",
"data",
",",
"'trim'",
")",
";",
"$",
"stats",
"[",
"]",
"=",
"array_values",
"(",
"array_filter",
"(",
"$",
"data",
",",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"strlen",
"(",
"$",
"value",
")",
">",
"0",
";",
"}",
")",
")",
";",
"}",
"return",
"$",
"stats",
";",
"}"
] | Parse top utility command output
Returns an array of lines with the same top columns
@param $output
@return array | [
"Parse",
"top",
"utility",
"command",
"output"
] | train | https://github.com/petrica/php-statsd-system/blob/c476be3514a631a605737888bb8f6eb096789c9d/Model/TopCommand.php#L61-L74 |
petrica/php-statsd-system | Model/TopCommand.php | TopCommand.buildCommand | protected function buildCommand()
{
$command = new Command(\Tivie\Command\ESCAPE);
$command
->setCommand('top')
->addArgument(new Argument('-b'))
->addArgument(new Argument('-n', 1));
return $command;
} | php | protected function buildCommand()
{
$command = new Command(\Tivie\Command\ESCAPE);
$command
->setCommand('top')
->addArgument(new Argument('-b'))
->addArgument(new Argument('-n', 1));
return $command;
} | [
"protected",
"function",
"buildCommand",
"(",
")",
"{",
"$",
"command",
"=",
"new",
"Command",
"(",
"\\",
"Tivie",
"\\",
"Command",
"\\",
"ESCAPE",
")",
";",
"$",
"command",
"->",
"setCommand",
"(",
"'top'",
")",
"->",
"addArgument",
"(",
"new",
"Argument",
"(",
"'-b'",
")",
")",
"->",
"addArgument",
"(",
"new",
"Argument",
"(",
"'-n'",
",",
"1",
")",
")",
";",
"return",
"$",
"command",
";",
"}"
] | Build commit command
@return Command
@throws \Tivie\Command\Exception\Exception
@throws \Tivie\Command\Exception\InvalidArgumentException | [
"Build",
"commit",
"command"
] | train | https://github.com/petrica/php-statsd-system/blob/c476be3514a631a605737888bb8f6eb096789c9d/Model/TopCommand.php#L83-L92 |
wenbinye/PhalconX | src/Helper/ClassResolver.php | ClassResolver.resolve | public function resolve($name, $declaringClass)
{
if (strpos($name, '\\') !== false) {
return $name;
}
$imports = $this->cache->get('_PHX.imports.'.$declaringClass);
if (!isset($imports)) {
$imports = ClassHelper::getImports($declaringClass);
$this->cache->save('_PHX.imports.'.$declaringClass, $imports);
}
if (isset($imports[$name])) {
return $imports[$name];
}
$class = ClassHelper::getNamespaceName($declaringClass) . $name;
if (class_exists($class)) {
return $class;
}
} | php | public function resolve($name, $declaringClass)
{
if (strpos($name, '\\') !== false) {
return $name;
}
$imports = $this->cache->get('_PHX.imports.'.$declaringClass);
if (!isset($imports)) {
$imports = ClassHelper::getImports($declaringClass);
$this->cache->save('_PHX.imports.'.$declaringClass, $imports);
}
if (isset($imports[$name])) {
return $imports[$name];
}
$class = ClassHelper::getNamespaceName($declaringClass) . $name;
if (class_exists($class)) {
return $class;
}
} | [
"public",
"function",
"resolve",
"(",
"$",
"name",
",",
"$",
"declaringClass",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"'\\\\'",
")",
"!==",
"false",
")",
"{",
"return",
"$",
"name",
";",
"}",
"$",
"imports",
"=",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
"'_PHX.imports.'",
".",
"$",
"declaringClass",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"imports",
")",
")",
"{",
"$",
"imports",
"=",
"ClassHelper",
"::",
"getImports",
"(",
"$",
"declaringClass",
")",
";",
"$",
"this",
"->",
"cache",
"->",
"save",
"(",
"'_PHX.imports.'",
".",
"$",
"declaringClass",
",",
"$",
"imports",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"imports",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"imports",
"[",
"$",
"name",
"]",
";",
"}",
"$",
"class",
"=",
"ClassHelper",
"::",
"getNamespaceName",
"(",
"$",
"declaringClass",
")",
".",
"$",
"name",
";",
"if",
"(",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"return",
"$",
"class",
";",
"}",
"}"
] | Gets full class name
@param string $name
@param string $declaringClass
@return string|null | [
"Gets",
"full",
"class",
"name"
] | train | https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Helper/ClassResolver.php#L28-L45 |
hnhdigital-os/laravel-html-builder | src/Tag.php | Tag.add | public function add($tag, ...$arguments)
{
$tag = strtolower($tag);
$text = '';
$attributes = [];
for ($i = 0; $i <= 1; $i++) {
if (array_has($arguments, $i)) {
if (is_array(array_get($arguments, $i))) {
$attributes = array_get($arguments, $i);
} elseif (is_string(array_get($arguments, $i)) || is_object(array_get($arguments, $i))) {
$text = array_get($arguments, $i);
}
}
}
if ($this->tag === 'tag'
|| empty($this->allowed_tags)
|| in_array($tag, $this->allowed_tags)
|| in_array($tag, self::$special_tags)) {
// Tag belongs to the special tags list.
if (in_array($tag, self::$special_tags)) {
$tag_object = Html::createElement($tag, $text, $attributes);
$tag_object->text($text)->addAttributes($attributes);
self::$tag_registry[] = &$tag_object;
$this->child_nodes[] = &$tag_object;
return $tag_object;
}
// Create the class name for this tag
$class_name = 'Bluora\\LaravelHtmlBuilder\\Tag\\'.ucfirst($tag);
// If the tag exists, otherwise we throw an exception.
if (class_exists($class_name)) {
$tag_object = (new $class_name())
->setAttributes($attributes)
->setText($text);
self::$tag_registry[] = &$tag_object;
$this->child_nodes[] = &$tag_object;
$tag_object->setParent($tag_object);
return $tag_object;
}
throw new \Exception($tag.' does not exist.');
}
throw new \Exception($this->tag.' does permit '.$tag);
} | php | public function add($tag, ...$arguments)
{
$tag = strtolower($tag);
$text = '';
$attributes = [];
for ($i = 0; $i <= 1; $i++) {
if (array_has($arguments, $i)) {
if (is_array(array_get($arguments, $i))) {
$attributes = array_get($arguments, $i);
} elseif (is_string(array_get($arguments, $i)) || is_object(array_get($arguments, $i))) {
$text = array_get($arguments, $i);
}
}
}
if ($this->tag === 'tag'
|| empty($this->allowed_tags)
|| in_array($tag, $this->allowed_tags)
|| in_array($tag, self::$special_tags)) {
// Tag belongs to the special tags list.
if (in_array($tag, self::$special_tags)) {
$tag_object = Html::createElement($tag, $text, $attributes);
$tag_object->text($text)->addAttributes($attributes);
self::$tag_registry[] = &$tag_object;
$this->child_nodes[] = &$tag_object;
return $tag_object;
}
// Create the class name for this tag
$class_name = 'Bluora\\LaravelHtmlBuilder\\Tag\\'.ucfirst($tag);
// If the tag exists, otherwise we throw an exception.
if (class_exists($class_name)) {
$tag_object = (new $class_name())
->setAttributes($attributes)
->setText($text);
self::$tag_registry[] = &$tag_object;
$this->child_nodes[] = &$tag_object;
$tag_object->setParent($tag_object);
return $tag_object;
}
throw new \Exception($tag.' does not exist.');
}
throw new \Exception($this->tag.' does permit '.$tag);
} | [
"public",
"function",
"add",
"(",
"$",
"tag",
",",
"...",
"$",
"arguments",
")",
"{",
"$",
"tag",
"=",
"strtolower",
"(",
"$",
"tag",
")",
";",
"$",
"text",
"=",
"''",
";",
"$",
"attributes",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<=",
"1",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"array_has",
"(",
"$",
"arguments",
",",
"$",
"i",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"array_get",
"(",
"$",
"arguments",
",",
"$",
"i",
")",
")",
")",
"{",
"$",
"attributes",
"=",
"array_get",
"(",
"$",
"arguments",
",",
"$",
"i",
")",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"array_get",
"(",
"$",
"arguments",
",",
"$",
"i",
")",
")",
"||",
"is_object",
"(",
"array_get",
"(",
"$",
"arguments",
",",
"$",
"i",
")",
")",
")",
"{",
"$",
"text",
"=",
"array_get",
"(",
"$",
"arguments",
",",
"$",
"i",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"tag",
"===",
"'tag'",
"||",
"empty",
"(",
"$",
"this",
"->",
"allowed_tags",
")",
"||",
"in_array",
"(",
"$",
"tag",
",",
"$",
"this",
"->",
"allowed_tags",
")",
"||",
"in_array",
"(",
"$",
"tag",
",",
"self",
"::",
"$",
"special_tags",
")",
")",
"{",
"// Tag belongs to the special tags list.",
"if",
"(",
"in_array",
"(",
"$",
"tag",
",",
"self",
"::",
"$",
"special_tags",
")",
")",
"{",
"$",
"tag_object",
"=",
"Html",
"::",
"createElement",
"(",
"$",
"tag",
",",
"$",
"text",
",",
"$",
"attributes",
")",
";",
"$",
"tag_object",
"->",
"text",
"(",
"$",
"text",
")",
"->",
"addAttributes",
"(",
"$",
"attributes",
")",
";",
"self",
"::",
"$",
"tag_registry",
"[",
"]",
"=",
"&",
"$",
"tag_object",
";",
"$",
"this",
"->",
"child_nodes",
"[",
"]",
"=",
"&",
"$",
"tag_object",
";",
"return",
"$",
"tag_object",
";",
"}",
"// Create the class name for this tag",
"$",
"class_name",
"=",
"'Bluora\\\\LaravelHtmlBuilder\\\\Tag\\\\'",
".",
"ucfirst",
"(",
"$",
"tag",
")",
";",
"// If the tag exists, otherwise we throw an exception.",
"if",
"(",
"class_exists",
"(",
"$",
"class_name",
")",
")",
"{",
"$",
"tag_object",
"=",
"(",
"new",
"$",
"class_name",
"(",
")",
")",
"->",
"setAttributes",
"(",
"$",
"attributes",
")",
"->",
"setText",
"(",
"$",
"text",
")",
";",
"self",
"::",
"$",
"tag_registry",
"[",
"]",
"=",
"&",
"$",
"tag_object",
";",
"$",
"this",
"->",
"child_nodes",
"[",
"]",
"=",
"&",
"$",
"tag_object",
";",
"$",
"tag_object",
"->",
"setParent",
"(",
"$",
"tag_object",
")",
";",
"return",
"$",
"tag_object",
";",
"}",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"tag",
".",
"' does not exist.'",
")",
";",
"}",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"this",
"->",
"tag",
".",
"' does permit '",
".",
"$",
"tag",
")",
";",
"}"
] | Add a child node to this tag.
@param string $tag
@param array $arguments
@return Bluora\LaravelHtmlBuilder\Tag | [
"Add",
"a",
"child",
"node",
"to",
"this",
"tag",
"."
] | train | https://github.com/hnhdigital-os/laravel-html-builder/blob/3c3c1f370e6ff77769b37130d12cbd041db3a841/src/Tag.php#L45-L95 |
hnhdigital-os/laravel-html-builder | src/Tag.php | Tag.setTag | public function setTag($tag)
{
if (in_array($tag, $this->getParent()->allowed_tags)) {
throw new \Exception($tag.' can not be changed as it is not allowed under '.$this->getParent()->getTag().'.');
}
$this->tag = $tag;
return $this;
} | php | public function setTag($tag)
{
if (in_array($tag, $this->getParent()->allowed_tags)) {
throw new \Exception($tag.' can not be changed as it is not allowed under '.$this->getParent()->getTag().'.');
}
$this->tag = $tag;
return $this;
} | [
"public",
"function",
"setTag",
"(",
"$",
"tag",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"tag",
",",
"$",
"this",
"->",
"getParent",
"(",
")",
"->",
"allowed_tags",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"tag",
".",
"' can not be changed as it is not allowed under '",
".",
"$",
"this",
"->",
"getParent",
"(",
")",
"->",
"getTag",
"(",
")",
".",
"'.'",
")",
";",
"}",
"$",
"this",
"->",
"tag",
"=",
"$",
"tag",
";",
"return",
"$",
"this",
";",
"}"
] | Set the tag name.
@return Bluora\LaravelHtmlBuilder\Tag | [
"Set",
"the",
"tag",
"name",
"."
] | train | https://github.com/hnhdigital-os/laravel-html-builder/blob/3c3c1f370e6ff77769b37130d12cbd041db3a841/src/Tag.php#L126-L135 |
hnhdigital-os/laravel-html-builder | src/Tag.php | Tag.setText | public function setText($value)
{
$this->text = $value;
// Auto-convert into html.
if (is_object($value) && stripos(get_class($value), 'HtmlGenerator\\Html')) {
$this->text = (string) $value;
}
return $this;
} | php | public function setText($value)
{
$this->text = $value;
// Auto-convert into html.
if (is_object($value) && stripos(get_class($value), 'HtmlGenerator\\Html')) {
$this->text = (string) $value;
}
return $this;
} | [
"public",
"function",
"setText",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"text",
"=",
"$",
"value",
";",
"// Auto-convert into html.",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"stripos",
"(",
"get_class",
"(",
"$",
"value",
")",
",",
"'HtmlGenerator\\\\Html'",
")",
")",
"{",
"$",
"this",
"->",
"text",
"=",
"(",
"string",
")",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the text for this tag.
@param string $value
@return Bluora\LaravelHtmlBuilder\Tag | [
"Set",
"the",
"text",
"for",
"this",
"tag",
"."
] | train | https://github.com/hnhdigital-os/laravel-html-builder/blob/3c3c1f370e6ff77769b37130d12cbd041db3a841/src/Tag.php#L154-L164 |
hnhdigital-os/laravel-html-builder | src/Tag.php | Tag.setAttributes | public function setAttributes()
{
$attributes = func_get_args();
if (count($attributes)) {
if (count($attributes) == 1 && is_array($attributes[0])) {
$attributes = $attributes[0];
}
$this->attributes = $attributes;
}
return $this;
} | php | public function setAttributes()
{
$attributes = func_get_args();
if (count($attributes)) {
if (count($attributes) == 1 && is_array($attributes[0])) {
$attributes = $attributes[0];
}
$this->attributes = $attributes;
}
return $this;
} | [
"public",
"function",
"setAttributes",
"(",
")",
"{",
"$",
"attributes",
"=",
"func_get_args",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"attributes",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"attributes",
")",
"==",
"1",
"&&",
"is_array",
"(",
"$",
"attributes",
"[",
"0",
"]",
")",
")",
"{",
"$",
"attributes",
"=",
"$",
"attributes",
"[",
"0",
"]",
";",
"}",
"$",
"this",
"->",
"attributes",
"=",
"$",
"attributes",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set one or many attributes.
@param array ...$attributes
@return Bluora\LaravelHtmlBuilder\Tag | [
"Set",
"one",
"or",
"many",
"attributes",
"."
] | train | https://github.com/hnhdigital-os/laravel-html-builder/blob/3c3c1f370e6ff77769b37130d12cbd041db3a841/src/Tag.php#L183-L194 |
hnhdigital-os/laravel-html-builder | src/Tag.php | Tag.buildHtml | private static function buildHtml(&$html, $tag_object, $options, $tab = 0)
{
self::checkBuildOptions($options);
$tag_is_special = in_array($tag_object->getTag(), self::$special_tags);
$tag_is_ignored = in_array($tag_object->getTag(), array_get($options, 'ignore_tags', []));
$ignore_tag = true;
if (!isset($options['ignore_tags']) || !$tag_is_ignored) {
$ignore_tag = false;
} elseif (isset($options['ignore_tags']) && $tag_is_ignored) {
$tab--;
}
$pad = '';
if ($tab > 0) {
$pad = str_pad($pad, $tab * 2, ' ', STR_PAD_LEFT);
}
if (!$ignore_tag) {
if ($tag_is_special) {
$html .= $pad.trim((string) $tag_object)."\n";
} elseif (!$tag_is_special) {
$html .= $pad;
$html .= '<'.$tag_object->tag.''.self::buildHtmlAttribute($tag_object->getAttributes()).'>';
$html .= ($tag_object->use_whitespace) ? "\n" : '';
if (strlen($tag_object->getText())) {
$html .= ($tag_object->use_whitespace) ? $pad.' ' : '';
$html .= $tag_object->getText();
}
$html .= ($tag_object->use_whitespace && strlen($tag_object->getText())) ? "\n" : '';
}
}
if (!$tag_is_special && $tag_object->hasChildNodes()) {
foreach ($tag_object->getChildNodes() as $child_tag_object) {
self::buildHtml($html, $child_tag_object, $options, $tab + 1);
}
}
$pad = '';
if ($tab > 0) {
$pad = str_pad($pad, $tab * 2, ' ', STR_PAD_LEFT);
}
if (!$ignore_tag && !$tag_is_special) {
$html .= ($tag_object->use_whitespace) ? $pad : '';
$html .= '</'.$tag_object->tag.'>'."\n";
}
} | php | private static function buildHtml(&$html, $tag_object, $options, $tab = 0)
{
self::checkBuildOptions($options);
$tag_is_special = in_array($tag_object->getTag(), self::$special_tags);
$tag_is_ignored = in_array($tag_object->getTag(), array_get($options, 'ignore_tags', []));
$ignore_tag = true;
if (!isset($options['ignore_tags']) || !$tag_is_ignored) {
$ignore_tag = false;
} elseif (isset($options['ignore_tags']) && $tag_is_ignored) {
$tab--;
}
$pad = '';
if ($tab > 0) {
$pad = str_pad($pad, $tab * 2, ' ', STR_PAD_LEFT);
}
if (!$ignore_tag) {
if ($tag_is_special) {
$html .= $pad.trim((string) $tag_object)."\n";
} elseif (!$tag_is_special) {
$html .= $pad;
$html .= '<'.$tag_object->tag.''.self::buildHtmlAttribute($tag_object->getAttributes()).'>';
$html .= ($tag_object->use_whitespace) ? "\n" : '';
if (strlen($tag_object->getText())) {
$html .= ($tag_object->use_whitespace) ? $pad.' ' : '';
$html .= $tag_object->getText();
}
$html .= ($tag_object->use_whitespace && strlen($tag_object->getText())) ? "\n" : '';
}
}
if (!$tag_is_special && $tag_object->hasChildNodes()) {
foreach ($tag_object->getChildNodes() as $child_tag_object) {
self::buildHtml($html, $child_tag_object, $options, $tab + 1);
}
}
$pad = '';
if ($tab > 0) {
$pad = str_pad($pad, $tab * 2, ' ', STR_PAD_LEFT);
}
if (!$ignore_tag && !$tag_is_special) {
$html .= ($tag_object->use_whitespace) ? $pad : '';
$html .= '</'.$tag_object->tag.'>'."\n";
}
} | [
"private",
"static",
"function",
"buildHtml",
"(",
"&",
"$",
"html",
",",
"$",
"tag_object",
",",
"$",
"options",
",",
"$",
"tab",
"=",
"0",
")",
"{",
"self",
"::",
"checkBuildOptions",
"(",
"$",
"options",
")",
";",
"$",
"tag_is_special",
"=",
"in_array",
"(",
"$",
"tag_object",
"->",
"getTag",
"(",
")",
",",
"self",
"::",
"$",
"special_tags",
")",
";",
"$",
"tag_is_ignored",
"=",
"in_array",
"(",
"$",
"tag_object",
"->",
"getTag",
"(",
")",
",",
"array_get",
"(",
"$",
"options",
",",
"'ignore_tags'",
",",
"[",
"]",
")",
")",
";",
"$",
"ignore_tag",
"=",
"true",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'ignore_tags'",
"]",
")",
"||",
"!",
"$",
"tag_is_ignored",
")",
"{",
"$",
"ignore_tag",
"=",
"false",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"options",
"[",
"'ignore_tags'",
"]",
")",
"&&",
"$",
"tag_is_ignored",
")",
"{",
"$",
"tab",
"--",
";",
"}",
"$",
"pad",
"=",
"''",
";",
"if",
"(",
"$",
"tab",
">",
"0",
")",
"{",
"$",
"pad",
"=",
"str_pad",
"(",
"$",
"pad",
",",
"$",
"tab",
"*",
"2",
",",
"' '",
",",
"STR_PAD_LEFT",
")",
";",
"}",
"if",
"(",
"!",
"$",
"ignore_tag",
")",
"{",
"if",
"(",
"$",
"tag_is_special",
")",
"{",
"$",
"html",
".=",
"$",
"pad",
".",
"trim",
"(",
"(",
"string",
")",
"$",
"tag_object",
")",
".",
"\"\\n\"",
";",
"}",
"elseif",
"(",
"!",
"$",
"tag_is_special",
")",
"{",
"$",
"html",
".=",
"$",
"pad",
";",
"$",
"html",
".=",
"'<'",
".",
"$",
"tag_object",
"->",
"tag",
".",
"''",
".",
"self",
"::",
"buildHtmlAttribute",
"(",
"$",
"tag_object",
"->",
"getAttributes",
"(",
")",
")",
".",
"'>'",
";",
"$",
"html",
".=",
"(",
"$",
"tag_object",
"->",
"use_whitespace",
")",
"?",
"\"\\n\"",
":",
"''",
";",
"if",
"(",
"strlen",
"(",
"$",
"tag_object",
"->",
"getText",
"(",
")",
")",
")",
"{",
"$",
"html",
".=",
"(",
"$",
"tag_object",
"->",
"use_whitespace",
")",
"?",
"$",
"pad",
".",
"' '",
":",
"''",
";",
"$",
"html",
".=",
"$",
"tag_object",
"->",
"getText",
"(",
")",
";",
"}",
"$",
"html",
".=",
"(",
"$",
"tag_object",
"->",
"use_whitespace",
"&&",
"strlen",
"(",
"$",
"tag_object",
"->",
"getText",
"(",
")",
")",
")",
"?",
"\"\\n\"",
":",
"''",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"tag_is_special",
"&&",
"$",
"tag_object",
"->",
"hasChildNodes",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"tag_object",
"->",
"getChildNodes",
"(",
")",
"as",
"$",
"child_tag_object",
")",
"{",
"self",
"::",
"buildHtml",
"(",
"$",
"html",
",",
"$",
"child_tag_object",
",",
"$",
"options",
",",
"$",
"tab",
"+",
"1",
")",
";",
"}",
"}",
"$",
"pad",
"=",
"''",
";",
"if",
"(",
"$",
"tab",
">",
"0",
")",
"{",
"$",
"pad",
"=",
"str_pad",
"(",
"$",
"pad",
",",
"$",
"tab",
"*",
"2",
",",
"' '",
",",
"STR_PAD_LEFT",
")",
";",
"}",
"if",
"(",
"!",
"$",
"ignore_tag",
"&&",
"!",
"$",
"tag_is_special",
")",
"{",
"$",
"html",
".=",
"(",
"$",
"tag_object",
"->",
"use_whitespace",
")",
"?",
"$",
"pad",
":",
"''",
";",
"$",
"html",
".=",
"'</'",
".",
"$",
"tag_object",
"->",
"tag",
".",
"'>'",
".",
"\"\\n\"",
";",
"}",
"}"
] | Build html from this object.
@param string &$html
@param LaravelHtmlBuilder\Tag $tag_object
@param array $options
@param int $tab
@return void | [
"Build",
"html",
"from",
"this",
"object",
"."
] | train | https://github.com/hnhdigital-os/laravel-html-builder/blob/3c3c1f370e6ff77769b37130d12cbd041db3a841/src/Tag.php#L277-L326 |
hnhdigital-os/laravel-html-builder | src/Tag.php | Tag.buildHtmlAttribute | private static function buildHtmlAttribute($attributes)
{
$html = '';
foreach ($attributes as $name => $value) {
$html .= ' '.$name.'="'.$value.'"';
$class_list = explode(' ', $value);
foreach ($class_list as $class_name) {
switch ($class_name) {
case 'class':
if (function_exists('hookAddClassHtmlTag')) {
hookAddClassHtmlTag($class_name);
}
}
}
}
return $html;
} | php | private static function buildHtmlAttribute($attributes)
{
$html = '';
foreach ($attributes as $name => $value) {
$html .= ' '.$name.'="'.$value.'"';
$class_list = explode(' ', $value);
foreach ($class_list as $class_name) {
switch ($class_name) {
case 'class':
if (function_exists('hookAddClassHtmlTag')) {
hookAddClassHtmlTag($class_name);
}
}
}
}
return $html;
} | [
"private",
"static",
"function",
"buildHtmlAttribute",
"(",
"$",
"attributes",
")",
"{",
"$",
"html",
"=",
"''",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"html",
".=",
"' '",
".",
"$",
"name",
".",
"'=\"'",
".",
"$",
"value",
".",
"'\"'",
";",
"$",
"class_list",
"=",
"explode",
"(",
"' '",
",",
"$",
"value",
")",
";",
"foreach",
"(",
"$",
"class_list",
"as",
"$",
"class_name",
")",
"{",
"switch",
"(",
"$",
"class_name",
")",
"{",
"case",
"'class'",
":",
"if",
"(",
"function_exists",
"(",
"'hookAddClassHtmlTag'",
")",
")",
"{",
"hookAddClassHtmlTag",
"(",
"$",
"class_name",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"html",
";",
"}"
] | Build html attributes from array.
@param array $attributes
@return string | [
"Build",
"html",
"attributes",
"from",
"array",
"."
] | train | https://github.com/hnhdigital-os/laravel-html-builder/blob/3c3c1f370e6ff77769b37130d12cbd041db3a841/src/Tag.php#L335-L352 |
hnhdigital-os/laravel-html-builder | src/Tag.php | Tag.buildArray | private static function buildArray(&$array, $tag_object, $options = [])
{
self::checkBuildOptions($options);
if (in_array($tag_object->getTag(), self::$special_tags)) {
$array[] = [trim((string) $tag_object)];
} elseif (!isset($options['ignore_tags']) || !in_array($tag_object->getTag(), $options['ignore_tags'])) {
$array[] = [
$tag_object->getTag(),
self::buildHtmlAttribute($tag_object->getAttributes()),
$tag_object->getText(),
[],
];
}
if ($tag_object->hasChildNodes()) {
if (isset($options['ignore_tags']) && in_array($tag_object->getTag(), $options['ignore_tags'])) {
foreach ($tag_object->getChildNodes() as $child_tag_object) {
self::buildArray($array, $child_tag_object);
}
return;
}
foreach ($tag_object->getChildNodes() as $child_tag_object) {
$current_position = count($array) - 1;
if (isset($array[$current_position][3]) && !is_null($array[$current_position][3])) {
self::buildArray($array[count($array) - 1][3], $child_tag_object);
}
}
}
} | php | private static function buildArray(&$array, $tag_object, $options = [])
{
self::checkBuildOptions($options);
if (in_array($tag_object->getTag(), self::$special_tags)) {
$array[] = [trim((string) $tag_object)];
} elseif (!isset($options['ignore_tags']) || !in_array($tag_object->getTag(), $options['ignore_tags'])) {
$array[] = [
$tag_object->getTag(),
self::buildHtmlAttribute($tag_object->getAttributes()),
$tag_object->getText(),
[],
];
}
if ($tag_object->hasChildNodes()) {
if (isset($options['ignore_tags']) && in_array($tag_object->getTag(), $options['ignore_tags'])) {
foreach ($tag_object->getChildNodes() as $child_tag_object) {
self::buildArray($array, $child_tag_object);
}
return;
}
foreach ($tag_object->getChildNodes() as $child_tag_object) {
$current_position = count($array) - 1;
if (isset($array[$current_position][3]) && !is_null($array[$current_position][3])) {
self::buildArray($array[count($array) - 1][3], $child_tag_object);
}
}
}
} | [
"private",
"static",
"function",
"buildArray",
"(",
"&",
"$",
"array",
",",
"$",
"tag_object",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"self",
"::",
"checkBuildOptions",
"(",
"$",
"options",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"tag_object",
"->",
"getTag",
"(",
")",
",",
"self",
"::",
"$",
"special_tags",
")",
")",
"{",
"$",
"array",
"[",
"]",
"=",
"[",
"trim",
"(",
"(",
"string",
")",
"$",
"tag_object",
")",
"]",
";",
"}",
"elseif",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'ignore_tags'",
"]",
")",
"||",
"!",
"in_array",
"(",
"$",
"tag_object",
"->",
"getTag",
"(",
")",
",",
"$",
"options",
"[",
"'ignore_tags'",
"]",
")",
")",
"{",
"$",
"array",
"[",
"]",
"=",
"[",
"$",
"tag_object",
"->",
"getTag",
"(",
")",
",",
"self",
"::",
"buildHtmlAttribute",
"(",
"$",
"tag_object",
"->",
"getAttributes",
"(",
")",
")",
",",
"$",
"tag_object",
"->",
"getText",
"(",
")",
",",
"[",
"]",
",",
"]",
";",
"}",
"if",
"(",
"$",
"tag_object",
"->",
"hasChildNodes",
"(",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'ignore_tags'",
"]",
")",
"&&",
"in_array",
"(",
"$",
"tag_object",
"->",
"getTag",
"(",
")",
",",
"$",
"options",
"[",
"'ignore_tags'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"tag_object",
"->",
"getChildNodes",
"(",
")",
"as",
"$",
"child_tag_object",
")",
"{",
"self",
"::",
"buildArray",
"(",
"$",
"array",
",",
"$",
"child_tag_object",
")",
";",
"}",
"return",
";",
"}",
"foreach",
"(",
"$",
"tag_object",
"->",
"getChildNodes",
"(",
")",
"as",
"$",
"child_tag_object",
")",
"{",
"$",
"current_position",
"=",
"count",
"(",
"$",
"array",
")",
"-",
"1",
";",
"if",
"(",
"isset",
"(",
"$",
"array",
"[",
"$",
"current_position",
"]",
"[",
"3",
"]",
")",
"&&",
"!",
"is_null",
"(",
"$",
"array",
"[",
"$",
"current_position",
"]",
"[",
"3",
"]",
")",
")",
"{",
"self",
"::",
"buildArray",
"(",
"$",
"array",
"[",
"count",
"(",
"$",
"array",
")",
"-",
"1",
"]",
"[",
"3",
"]",
",",
"$",
"child_tag_object",
")",
";",
"}",
"}",
"}",
"}"
] | Build an array from this object.
@param array &$array
@param LaravelHtmlBuilder\Tag $tag_object
@param array $options
@return void | [
"Build",
"an",
"array",
"from",
"this",
"object",
"."
] | train | https://github.com/hnhdigital-os/laravel-html-builder/blob/3c3c1f370e6ff77769b37130d12cbd041db3a841/src/Tag.php#L363-L394 |
hnhdigital-os/laravel-html-builder | src/Tag.php | Tag.buildFromArray | public static function buildFromArray(&$html, $array, $tab = 0)
{
$pad = '';
if ($tab > 0) {
$pad = str_pad($pad, $tab * 2, ' ', STR_PAD_LEFT);
}
if (!isset($array[1])) {
$html .= $array[0]."\n";
return;
}
if (!empty($array[0])) {
$html .= $pad;
$html .= '<'.$array[0].$array[1].'>';
$html .= "\n";
}
if (!empty($array[2])) {
$html .= $pad.' ';
$html .= $array[2];
$html .= "\n";
}
if (isset($array[3]) && is_array($array[3])) {
foreach ($array[3] as $child_array) {
self::buildFromArray($html, $child_array, $tab + 1);
}
}
if (!empty($array[0])) {
$html .= $pad;
$html .= '</'.$array[0].'>';
$html .= "\n";
}
} | php | public static function buildFromArray(&$html, $array, $tab = 0)
{
$pad = '';
if ($tab > 0) {
$pad = str_pad($pad, $tab * 2, ' ', STR_PAD_LEFT);
}
if (!isset($array[1])) {
$html .= $array[0]."\n";
return;
}
if (!empty($array[0])) {
$html .= $pad;
$html .= '<'.$array[0].$array[1].'>';
$html .= "\n";
}
if (!empty($array[2])) {
$html .= $pad.' ';
$html .= $array[2];
$html .= "\n";
}
if (isset($array[3]) && is_array($array[3])) {
foreach ($array[3] as $child_array) {
self::buildFromArray($html, $child_array, $tab + 1);
}
}
if (!empty($array[0])) {
$html .= $pad;
$html .= '</'.$array[0].'>';
$html .= "\n";
}
} | [
"public",
"static",
"function",
"buildFromArray",
"(",
"&",
"$",
"html",
",",
"$",
"array",
",",
"$",
"tab",
"=",
"0",
")",
"{",
"$",
"pad",
"=",
"''",
";",
"if",
"(",
"$",
"tab",
">",
"0",
")",
"{",
"$",
"pad",
"=",
"str_pad",
"(",
"$",
"pad",
",",
"$",
"tab",
"*",
"2",
",",
"' '",
",",
"STR_PAD_LEFT",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"array",
"[",
"1",
"]",
")",
")",
"{",
"$",
"html",
".=",
"$",
"array",
"[",
"0",
"]",
".",
"\"\\n\"",
";",
"return",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"array",
"[",
"0",
"]",
")",
")",
"{",
"$",
"html",
".=",
"$",
"pad",
";",
"$",
"html",
".=",
"'<'",
".",
"$",
"array",
"[",
"0",
"]",
".",
"$",
"array",
"[",
"1",
"]",
".",
"'>'",
";",
"$",
"html",
".=",
"\"\\n\"",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"array",
"[",
"2",
"]",
")",
")",
"{",
"$",
"html",
".=",
"$",
"pad",
".",
"' '",
";",
"$",
"html",
".=",
"$",
"array",
"[",
"2",
"]",
";",
"$",
"html",
".=",
"\"\\n\"",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"array",
"[",
"3",
"]",
")",
"&&",
"is_array",
"(",
"$",
"array",
"[",
"3",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"array",
"[",
"3",
"]",
"as",
"$",
"child_array",
")",
"{",
"self",
"::",
"buildFromArray",
"(",
"$",
"html",
",",
"$",
"child_array",
",",
"$",
"tab",
"+",
"1",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"array",
"[",
"0",
"]",
")",
")",
"{",
"$",
"html",
".=",
"$",
"pad",
";",
"$",
"html",
".=",
"'</'",
".",
"$",
"array",
"[",
"0",
"]",
".",
"'>'",
";",
"$",
"html",
".=",
"\"\\n\"",
";",
"}",
"}"
] | Build html from an array.
@param string &$html
@param array $array
@param int $tab
@return void | [
"Build",
"html",
"from",
"an",
"array",
"."
] | train | https://github.com/hnhdigital-os/laravel-html-builder/blob/3c3c1f370e6ff77769b37130d12cbd041db3a841/src/Tag.php#L405-L441 |
hnhdigital-os/laravel-html-builder | src/Tag.php | Tag.prepare | public function prepare($options = [])
{
if (request()->ajax()) {
return $this->getArray($options);
}
return $this->getHtml($options);
} | php | public function prepare($options = [])
{
if (request()->ajax()) {
return $this->getArray($options);
}
return $this->getHtml($options);
} | [
"public",
"function",
"prepare",
"(",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"request",
"(",
")",
"->",
"ajax",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getArray",
"(",
"$",
"options",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getHtml",
"(",
"$",
"options",
")",
";",
"}"
] | Automatically returns the object based on the http request.
@return html|array | [
"Automatically",
"returns",
"the",
"object",
"based",
"on",
"the",
"http",
"request",
"."
] | train | https://github.com/hnhdigital-os/laravel-html-builder/blob/3c3c1f370e6ff77769b37130d12cbd041db3a841/src/Tag.php#L448-L455 |
xiewulong/yii2-fileupload | oss/libs/symfony/class-loader/Symfony/Component/ClassLoader/ClassCollectionLoader.php | ClassCollectionLoader.load | public static function load($classes, $cacheDir, $name, $autoReload, $adaptive = false, $extension = '.php')
{
// each $name can only be loaded once per PHP process
if (isset(self::$loaded[$name])) {
return;
}
self::$loaded[$name] = true;
$declared = array_merge(get_declared_classes(), get_declared_interfaces());
if (function_exists('get_declared_traits')) {
$declared = array_merge($declared, get_declared_traits());
}
if ($adaptive) {
// don't include already declared classes
$classes = array_diff($classes, $declared);
// the cache is different depending on which classes are already declared
$name = $name.'-'.substr(md5(implode('|', $classes)), 0, 5);
}
$classes = array_unique($classes);
$cache = $cacheDir.'/'.$name.$extension;
// auto-reload
$reload = false;
if ($autoReload) {
$metadata = $cache.'.meta';
if (!is_file($metadata) || !is_file($cache)) {
$reload = true;
} else {
$time = filemtime($cache);
$meta = unserialize(file_get_contents($metadata));
sort($meta[1]);
sort($classes);
if ($meta[1] != $classes) {
$reload = true;
} else {
foreach ($meta[0] as $resource) {
if (!is_file($resource) || filemtime($resource) > $time) {
$reload = true;
break;
}
}
}
}
}
if (!$reload && is_file($cache)) {
require_once $cache;
return;
}
$files = array();
$content = '';
foreach (self::getOrderedClasses($classes) as $class) {
if (in_array($class->getName(), $declared)) {
continue;
}
$files[] = $class->getFileName();
$c = preg_replace(array('/^\s*<\?php/', '/\?>\s*$/'), '', file_get_contents($class->getFileName()));
// fakes namespace declaration for global code
if (!$class->inNamespace()) {
$c = "\nnamespace\n{\n".$c."\n}\n";
}
$c = self::fixNamespaceDeclarations('<?php '.$c);
$c = preg_replace('/^\s*<\?php/', '', $c);
$content .= $c;
}
// cache the core classes
if (!is_dir(dirname($cache))) {
mkdir(dirname($cache), 0777, true);
}
self::writeCacheFile($cache, '<?php '.$content);
if ($autoReload) {
// save the resources
self::writeCacheFile($metadata, serialize(array($files, $classes)));
}
} | php | public static function load($classes, $cacheDir, $name, $autoReload, $adaptive = false, $extension = '.php')
{
// each $name can only be loaded once per PHP process
if (isset(self::$loaded[$name])) {
return;
}
self::$loaded[$name] = true;
$declared = array_merge(get_declared_classes(), get_declared_interfaces());
if (function_exists('get_declared_traits')) {
$declared = array_merge($declared, get_declared_traits());
}
if ($adaptive) {
// don't include already declared classes
$classes = array_diff($classes, $declared);
// the cache is different depending on which classes are already declared
$name = $name.'-'.substr(md5(implode('|', $classes)), 0, 5);
}
$classes = array_unique($classes);
$cache = $cacheDir.'/'.$name.$extension;
// auto-reload
$reload = false;
if ($autoReload) {
$metadata = $cache.'.meta';
if (!is_file($metadata) || !is_file($cache)) {
$reload = true;
} else {
$time = filemtime($cache);
$meta = unserialize(file_get_contents($metadata));
sort($meta[1]);
sort($classes);
if ($meta[1] != $classes) {
$reload = true;
} else {
foreach ($meta[0] as $resource) {
if (!is_file($resource) || filemtime($resource) > $time) {
$reload = true;
break;
}
}
}
}
}
if (!$reload && is_file($cache)) {
require_once $cache;
return;
}
$files = array();
$content = '';
foreach (self::getOrderedClasses($classes) as $class) {
if (in_array($class->getName(), $declared)) {
continue;
}
$files[] = $class->getFileName();
$c = preg_replace(array('/^\s*<\?php/', '/\?>\s*$/'), '', file_get_contents($class->getFileName()));
// fakes namespace declaration for global code
if (!$class->inNamespace()) {
$c = "\nnamespace\n{\n".$c."\n}\n";
}
$c = self::fixNamespaceDeclarations('<?php '.$c);
$c = preg_replace('/^\s*<\?php/', '', $c);
$content .= $c;
}
// cache the core classes
if (!is_dir(dirname($cache))) {
mkdir(dirname($cache), 0777, true);
}
self::writeCacheFile($cache, '<?php '.$content);
if ($autoReload) {
// save the resources
self::writeCacheFile($metadata, serialize(array($files, $classes)));
}
} | [
"public",
"static",
"function",
"load",
"(",
"$",
"classes",
",",
"$",
"cacheDir",
",",
"$",
"name",
",",
"$",
"autoReload",
",",
"$",
"adaptive",
"=",
"false",
",",
"$",
"extension",
"=",
"'.php'",
")",
"{",
"// each $name can only be loaded once per PHP process",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"loaded",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
";",
"}",
"self",
"::",
"$",
"loaded",
"[",
"$",
"name",
"]",
"=",
"true",
";",
"$",
"declared",
"=",
"array_merge",
"(",
"get_declared_classes",
"(",
")",
",",
"get_declared_interfaces",
"(",
")",
")",
";",
"if",
"(",
"function_exists",
"(",
"'get_declared_traits'",
")",
")",
"{",
"$",
"declared",
"=",
"array_merge",
"(",
"$",
"declared",
",",
"get_declared_traits",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"adaptive",
")",
"{",
"// don't include already declared classes",
"$",
"classes",
"=",
"array_diff",
"(",
"$",
"classes",
",",
"$",
"declared",
")",
";",
"// the cache is different depending on which classes are already declared",
"$",
"name",
"=",
"$",
"name",
".",
"'-'",
".",
"substr",
"(",
"md5",
"(",
"implode",
"(",
"'|'",
",",
"$",
"classes",
")",
")",
",",
"0",
",",
"5",
")",
";",
"}",
"$",
"classes",
"=",
"array_unique",
"(",
"$",
"classes",
")",
";",
"$",
"cache",
"=",
"$",
"cacheDir",
".",
"'/'",
".",
"$",
"name",
".",
"$",
"extension",
";",
"// auto-reload",
"$",
"reload",
"=",
"false",
";",
"if",
"(",
"$",
"autoReload",
")",
"{",
"$",
"metadata",
"=",
"$",
"cache",
".",
"'.meta'",
";",
"if",
"(",
"!",
"is_file",
"(",
"$",
"metadata",
")",
"||",
"!",
"is_file",
"(",
"$",
"cache",
")",
")",
"{",
"$",
"reload",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"time",
"=",
"filemtime",
"(",
"$",
"cache",
")",
";",
"$",
"meta",
"=",
"unserialize",
"(",
"file_get_contents",
"(",
"$",
"metadata",
")",
")",
";",
"sort",
"(",
"$",
"meta",
"[",
"1",
"]",
")",
";",
"sort",
"(",
"$",
"classes",
")",
";",
"if",
"(",
"$",
"meta",
"[",
"1",
"]",
"!=",
"$",
"classes",
")",
"{",
"$",
"reload",
"=",
"true",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"meta",
"[",
"0",
"]",
"as",
"$",
"resource",
")",
"{",
"if",
"(",
"!",
"is_file",
"(",
"$",
"resource",
")",
"||",
"filemtime",
"(",
"$",
"resource",
")",
">",
"$",
"time",
")",
"{",
"$",
"reload",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"}",
"}",
"if",
"(",
"!",
"$",
"reload",
"&&",
"is_file",
"(",
"$",
"cache",
")",
")",
"{",
"require_once",
"$",
"cache",
";",
"return",
";",
"}",
"$",
"files",
"=",
"array",
"(",
")",
";",
"$",
"content",
"=",
"''",
";",
"foreach",
"(",
"self",
"::",
"getOrderedClasses",
"(",
"$",
"classes",
")",
"as",
"$",
"class",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"class",
"->",
"getName",
"(",
")",
",",
"$",
"declared",
")",
")",
"{",
"continue",
";",
"}",
"$",
"files",
"[",
"]",
"=",
"$",
"class",
"->",
"getFileName",
"(",
")",
";",
"$",
"c",
"=",
"preg_replace",
"(",
"array",
"(",
"'/^\\s*<\\?php/'",
",",
"'/\\?>\\s*$/'",
")",
",",
"''",
",",
"file_get_contents",
"(",
"$",
"class",
"->",
"getFileName",
"(",
")",
")",
")",
";",
"// fakes namespace declaration for global code",
"if",
"(",
"!",
"$",
"class",
"->",
"inNamespace",
"(",
")",
")",
"{",
"$",
"c",
"=",
"\"\\nnamespace\\n{\\n\"",
".",
"$",
"c",
".",
"\"\\n}\\n\"",
";",
"}",
"$",
"c",
"=",
"self",
"::",
"fixNamespaceDeclarations",
"(",
"'<?php '",
".",
"$",
"c",
")",
";",
"$",
"c",
"=",
"preg_replace",
"(",
"'/^\\s*<\\?php/'",
",",
"''",
",",
"$",
"c",
")",
";",
"$",
"content",
".=",
"$",
"c",
";",
"}",
"// cache the core classes",
"if",
"(",
"!",
"is_dir",
"(",
"dirname",
"(",
"$",
"cache",
")",
")",
")",
"{",
"mkdir",
"(",
"dirname",
"(",
"$",
"cache",
")",
",",
"0777",
",",
"true",
")",
";",
"}",
"self",
"::",
"writeCacheFile",
"(",
"$",
"cache",
",",
"'<?php '",
".",
"$",
"content",
")",
";",
"if",
"(",
"$",
"autoReload",
")",
"{",
"// save the resources",
"self",
"::",
"writeCacheFile",
"(",
"$",
"metadata",
",",
"serialize",
"(",
"array",
"(",
"$",
"files",
",",
"$",
"classes",
")",
")",
")",
";",
"}",
"}"
] | Loads a list of classes and caches them in one big file.
@param array $classes An array of classes to load
@param string $cacheDir A cache directory
@param string $name The cache name prefix
@param Boolean $autoReload Whether to flush the cache when the cache is stale or not
@param Boolean $adaptive Whether to remove already declared classes or not
@param string $extension File extension of the resulting file
@throws \InvalidArgumentException When class can't be loaded | [
"Loads",
"a",
"list",
"of",
"classes",
"and",
"caches",
"them",
"in",
"one",
"big",
"file",
"."
] | train | https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/symfony/class-loader/Symfony/Component/ClassLoader/ClassCollectionLoader.php#L37-L128 |
xiewulong/yii2-fileupload | oss/libs/symfony/class-loader/Symfony/Component/ClassLoader/ClassCollectionLoader.php | ClassCollectionLoader.fixNamespaceDeclarations | public static function fixNamespaceDeclarations($source)
{
if (!function_exists('token_get_all') || !self::$useTokenizer) {
if (preg_match('/namespace(.*?)\s*;/', $source)) {
$source = preg_replace('/namespace(.*?)\s*;/', "namespace$1\n{", $source)."}\n";
}
return $source;
}
$rawChunk = '';
$output = '';
$inNamespace = false;
$tokens = token_get_all($source);
for (reset($tokens); false !== $token = current($tokens); next($tokens)) {
if (is_string($token)) {
$rawChunk .= $token;
} elseif (in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
// strip comments
continue;
} elseif (T_NAMESPACE === $token[0]) {
if ($inNamespace) {
$rawChunk .= "}\n";
}
$rawChunk .= $token[1];
// namespace name and whitespaces
while (($t = next($tokens)) && is_array($t) && in_array($t[0], array(T_WHITESPACE, T_NS_SEPARATOR, T_STRING))) {
$rawChunk .= $t[1];
}
if ('{' === $t) {
$inNamespace = false;
prev($tokens);
} else {
$rawChunk = rtrim($rawChunk)."\n{";
$inNamespace = true;
}
} elseif (T_START_HEREDOC === $token[0]) {
$output .= self::compressCode($rawChunk).$token[1];
do {
$token = next($tokens);
$output .= is_string($token) ? $token : $token[1];
} while ($token[0] !== T_END_HEREDOC);
$output .= "\n";
$rawChunk = '';
} elseif (T_CONSTANT_ENCAPSED_STRING === $token[0]) {
$output .= self::compressCode($rawChunk).$token[1];
$rawChunk = '';
} else {
$rawChunk .= $token[1];
}
}
if ($inNamespace) {
$rawChunk .= "}\n";
}
return $output.self::compressCode($rawChunk);
} | php | public static function fixNamespaceDeclarations($source)
{
if (!function_exists('token_get_all') || !self::$useTokenizer) {
if (preg_match('/namespace(.*?)\s*;/', $source)) {
$source = preg_replace('/namespace(.*?)\s*;/', "namespace$1\n{", $source)."}\n";
}
return $source;
}
$rawChunk = '';
$output = '';
$inNamespace = false;
$tokens = token_get_all($source);
for (reset($tokens); false !== $token = current($tokens); next($tokens)) {
if (is_string($token)) {
$rawChunk .= $token;
} elseif (in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
// strip comments
continue;
} elseif (T_NAMESPACE === $token[0]) {
if ($inNamespace) {
$rawChunk .= "}\n";
}
$rawChunk .= $token[1];
// namespace name and whitespaces
while (($t = next($tokens)) && is_array($t) && in_array($t[0], array(T_WHITESPACE, T_NS_SEPARATOR, T_STRING))) {
$rawChunk .= $t[1];
}
if ('{' === $t) {
$inNamespace = false;
prev($tokens);
} else {
$rawChunk = rtrim($rawChunk)."\n{";
$inNamespace = true;
}
} elseif (T_START_HEREDOC === $token[0]) {
$output .= self::compressCode($rawChunk).$token[1];
do {
$token = next($tokens);
$output .= is_string($token) ? $token : $token[1];
} while ($token[0] !== T_END_HEREDOC);
$output .= "\n";
$rawChunk = '';
} elseif (T_CONSTANT_ENCAPSED_STRING === $token[0]) {
$output .= self::compressCode($rawChunk).$token[1];
$rawChunk = '';
} else {
$rawChunk .= $token[1];
}
}
if ($inNamespace) {
$rawChunk .= "}\n";
}
return $output.self::compressCode($rawChunk);
} | [
"public",
"static",
"function",
"fixNamespaceDeclarations",
"(",
"$",
"source",
")",
"{",
"if",
"(",
"!",
"function_exists",
"(",
"'token_get_all'",
")",
"||",
"!",
"self",
"::",
"$",
"useTokenizer",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/namespace(.*?)\\s*;/'",
",",
"$",
"source",
")",
")",
"{",
"$",
"source",
"=",
"preg_replace",
"(",
"'/namespace(.*?)\\s*;/'",
",",
"\"namespace$1\\n{\"",
",",
"$",
"source",
")",
".",
"\"}\\n\"",
";",
"}",
"return",
"$",
"source",
";",
"}",
"$",
"rawChunk",
"=",
"''",
";",
"$",
"output",
"=",
"''",
";",
"$",
"inNamespace",
"=",
"false",
";",
"$",
"tokens",
"=",
"token_get_all",
"(",
"$",
"source",
")",
";",
"for",
"(",
"reset",
"(",
"$",
"tokens",
")",
";",
"false",
"!==",
"$",
"token",
"=",
"current",
"(",
"$",
"tokens",
")",
";",
"next",
"(",
"$",
"tokens",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"token",
")",
")",
"{",
"$",
"rawChunk",
".=",
"$",
"token",
";",
"}",
"elseif",
"(",
"in_array",
"(",
"$",
"token",
"[",
"0",
"]",
",",
"array",
"(",
"T_COMMENT",
",",
"T_DOC_COMMENT",
")",
")",
")",
"{",
"// strip comments",
"continue",
";",
"}",
"elseif",
"(",
"T_NAMESPACE",
"===",
"$",
"token",
"[",
"0",
"]",
")",
"{",
"if",
"(",
"$",
"inNamespace",
")",
"{",
"$",
"rawChunk",
".=",
"\"}\\n\"",
";",
"}",
"$",
"rawChunk",
".=",
"$",
"token",
"[",
"1",
"]",
";",
"// namespace name and whitespaces",
"while",
"(",
"(",
"$",
"t",
"=",
"next",
"(",
"$",
"tokens",
")",
")",
"&&",
"is_array",
"(",
"$",
"t",
")",
"&&",
"in_array",
"(",
"$",
"t",
"[",
"0",
"]",
",",
"array",
"(",
"T_WHITESPACE",
",",
"T_NS_SEPARATOR",
",",
"T_STRING",
")",
")",
")",
"{",
"$",
"rawChunk",
".=",
"$",
"t",
"[",
"1",
"]",
";",
"}",
"if",
"(",
"'{'",
"===",
"$",
"t",
")",
"{",
"$",
"inNamespace",
"=",
"false",
";",
"prev",
"(",
"$",
"tokens",
")",
";",
"}",
"else",
"{",
"$",
"rawChunk",
"=",
"rtrim",
"(",
"$",
"rawChunk",
")",
".",
"\"\\n{\"",
";",
"$",
"inNamespace",
"=",
"true",
";",
"}",
"}",
"elseif",
"(",
"T_START_HEREDOC",
"===",
"$",
"token",
"[",
"0",
"]",
")",
"{",
"$",
"output",
".=",
"self",
"::",
"compressCode",
"(",
"$",
"rawChunk",
")",
".",
"$",
"token",
"[",
"1",
"]",
";",
"do",
"{",
"$",
"token",
"=",
"next",
"(",
"$",
"tokens",
")",
";",
"$",
"output",
".=",
"is_string",
"(",
"$",
"token",
")",
"?",
"$",
"token",
":",
"$",
"token",
"[",
"1",
"]",
";",
"}",
"while",
"(",
"$",
"token",
"[",
"0",
"]",
"!==",
"T_END_HEREDOC",
")",
";",
"$",
"output",
".=",
"\"\\n\"",
";",
"$",
"rawChunk",
"=",
"''",
";",
"}",
"elseif",
"(",
"T_CONSTANT_ENCAPSED_STRING",
"===",
"$",
"token",
"[",
"0",
"]",
")",
"{",
"$",
"output",
".=",
"self",
"::",
"compressCode",
"(",
"$",
"rawChunk",
")",
".",
"$",
"token",
"[",
"1",
"]",
";",
"$",
"rawChunk",
"=",
"''",
";",
"}",
"else",
"{",
"$",
"rawChunk",
".=",
"$",
"token",
"[",
"1",
"]",
";",
"}",
"}",
"if",
"(",
"$",
"inNamespace",
")",
"{",
"$",
"rawChunk",
".=",
"\"}\\n\"",
";",
"}",
"return",
"$",
"output",
".",
"self",
"::",
"compressCode",
"(",
"$",
"rawChunk",
")",
";",
"}"
] | Adds brackets around each namespace if it's not already the case.
@param string $source Namespace string
@return string Namespaces with brackets | [
"Adds",
"brackets",
"around",
"each",
"namespace",
"if",
"it",
"s",
"not",
"already",
"the",
"case",
"."
] | train | https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/symfony/class-loader/Symfony/Component/ClassLoader/ClassCollectionLoader.php#L137-L196 |
xiewulong/yii2-fileupload | oss/libs/symfony/class-loader/Symfony/Component/ClassLoader/ClassCollectionLoader.php | ClassCollectionLoader.resolveDependencies | private static function resolveDependencies(array $tree, $node, \ArrayObject $resolved = null, \ArrayObject $unresolved = null)
{
if (null === $resolved) {
$resolved = new \ArrayObject();
}
if (null === $unresolved) {
$unresolved = new \ArrayObject();
}
$nodeName = $node->getName();
$unresolved[$nodeName] = $node;
foreach ($tree[$nodeName] as $dependency) {
if (!$resolved->offsetExists($dependency->getName())) {
self::resolveDependencies($tree, $dependency, $resolved, $unresolved);
}
}
$resolved[$nodeName] = $node;
unset($unresolved[$nodeName]);
return $resolved;
} | php | private static function resolveDependencies(array $tree, $node, \ArrayObject $resolved = null, \ArrayObject $unresolved = null)
{
if (null === $resolved) {
$resolved = new \ArrayObject();
}
if (null === $unresolved) {
$unresolved = new \ArrayObject();
}
$nodeName = $node->getName();
$unresolved[$nodeName] = $node;
foreach ($tree[$nodeName] as $dependency) {
if (!$resolved->offsetExists($dependency->getName())) {
self::resolveDependencies($tree, $dependency, $resolved, $unresolved);
}
}
$resolved[$nodeName] = $node;
unset($unresolved[$nodeName]);
return $resolved;
} | [
"private",
"static",
"function",
"resolveDependencies",
"(",
"array",
"$",
"tree",
",",
"$",
"node",
",",
"\\",
"ArrayObject",
"$",
"resolved",
"=",
"null",
",",
"\\",
"ArrayObject",
"$",
"unresolved",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"resolved",
")",
"{",
"$",
"resolved",
"=",
"new",
"\\",
"ArrayObject",
"(",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"unresolved",
")",
"{",
"$",
"unresolved",
"=",
"new",
"\\",
"ArrayObject",
"(",
")",
";",
"}",
"$",
"nodeName",
"=",
"$",
"node",
"->",
"getName",
"(",
")",
";",
"$",
"unresolved",
"[",
"$",
"nodeName",
"]",
"=",
"$",
"node",
";",
"foreach",
"(",
"$",
"tree",
"[",
"$",
"nodeName",
"]",
"as",
"$",
"dependency",
")",
"{",
"if",
"(",
"!",
"$",
"resolved",
"->",
"offsetExists",
"(",
"$",
"dependency",
"->",
"getName",
"(",
")",
")",
")",
"{",
"self",
"::",
"resolveDependencies",
"(",
"$",
"tree",
",",
"$",
"dependency",
",",
"$",
"resolved",
",",
"$",
"unresolved",
")",
";",
"}",
"}",
"$",
"resolved",
"[",
"$",
"nodeName",
"]",
"=",
"$",
"node",
";",
"unset",
"(",
"$",
"unresolved",
"[",
"$",
"nodeName",
"]",
")",
";",
"return",
"$",
"resolved",
";",
"}"
] | Dependencies resolution.
This function does not check for circular dependencies as it should never
occur with PHP traits.
@param array $tree The dependency tree
@param \ReflectionClass $node The node
@param \ArrayObject $resolved An array of already resolved dependencies
@param \ArrayObject $unresolved An array of dependencies to be resolved
@return \ArrayObject The dependencies for the given node
@throws \RuntimeException if a circular dependency is detected | [
"Dependencies",
"resolution",
"."
] | train | https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/symfony/class-loader/Symfony/Component/ClassLoader/ClassCollectionLoader.php#L347-L366 |
surebert/surebert-framework | src/sb/SFTP/Client.php | Client.login | public function login($uname, $pass)
{
if(parent::login($uname, $pass)){
$this->connect();
}
return true;
} | php | public function login($uname, $pass)
{
if(parent::login($uname, $pass)){
$this->connect();
}
return true;
} | [
"public",
"function",
"login",
"(",
"$",
"uname",
",",
"$",
"pass",
")",
"{",
"if",
"(",
"parent",
"::",
"login",
"(",
"$",
"uname",
",",
"$",
"pass",
")",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Login to a remote server with uname and pass based credentials
@param string $uname The user name to log in with
@param <type> $pass The password to login in with | [
"Login",
"to",
"a",
"remote",
"server",
"with",
"uname",
"and",
"pass",
"based",
"credentials"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/SFTP/Client.php#L55-L63 |
surebert/surebert-framework | src/sb/SFTP/Client.php | Client.loginWithKey | public function loginWithKey($uname, $public_key_file, $private_key_file, $pass='')
{
if(parent::loginWithKey($uname, $public_key_file, $private_key_file, $pass)) {
$this->connect();
}
return true;
} | php | public function loginWithKey($uname, $public_key_file, $private_key_file, $pass='')
{
if(parent::loginWithKey($uname, $public_key_file, $private_key_file, $pass)) {
$this->connect();
}
return true;
} | [
"public",
"function",
"loginWithKey",
"(",
"$",
"uname",
",",
"$",
"public_key_file",
",",
"$",
"private_key_file",
",",
"$",
"pass",
"=",
"''",
")",
"{",
"if",
"(",
"parent",
"::",
"loginWithKey",
"(",
"$",
"uname",
",",
"$",
"public_key_file",
",",
"$",
"private_key_file",
",",
"$",
"pass",
")",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Login with public key
@param string $uname The username to login in as
@param string $public_key_file The path to the public key file to use (id_rsa.pub), make sure it is readible by your script
@param string $private_key_file The private key file to use id (id_rsa), make sure it is readible by your script
@param string $pass The passphrase of the keyfile to use if one is required | [
"Login",
"with",
"public",
"key"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/SFTP/Client.php#L72-L80 |
surebert/surebert-framework | src/sb/SFTP/Client.php | Client.put | public function put($local_file, $remote_file, $mode=null)
{
if(!is_null($mode)){
return $this->scpSend($local_path, $remote_path, $mode);
return true;
}
$stream = @fopen("ssh2.sftp://".$this->sftp.$remote_file, 'w');
if (! $stream){
throw new \Exception("Could not open file: $remote_file");
}
$data_to_send = @file_get_contents($local_file);
if ($data_to_send === false){
throw new \Exception("Could not open local file: $local_file.");
}
if (@fwrite($stream, $data_to_send) === false){
throw new \Exception("Could not send data from file: $local_file.");
}
@fclose($stream);
return true;
} | php | public function put($local_file, $remote_file, $mode=null)
{
if(!is_null($mode)){
return $this->scpSend($local_path, $remote_path, $mode);
return true;
}
$stream = @fopen("ssh2.sftp://".$this->sftp.$remote_file, 'w');
if (! $stream){
throw new \Exception("Could not open file: $remote_file");
}
$data_to_send = @file_get_contents($local_file);
if ($data_to_send === false){
throw new \Exception("Could not open local file: $local_file.");
}
if (@fwrite($stream, $data_to_send) === false){
throw new \Exception("Could not send data from file: $local_file.");
}
@fclose($stream);
return true;
} | [
"public",
"function",
"put",
"(",
"$",
"local_file",
",",
"$",
"remote_file",
",",
"$",
"mode",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"mode",
")",
")",
"{",
"return",
"$",
"this",
"->",
"scpSend",
"(",
"$",
"local_path",
",",
"$",
"remote_path",
",",
"$",
"mode",
")",
";",
"return",
"true",
";",
"}",
"$",
"stream",
"=",
"@",
"fopen",
"(",
"\"ssh2.sftp://\"",
".",
"$",
"this",
"->",
"sftp",
".",
"$",
"remote_file",
",",
"'w'",
")",
";",
"if",
"(",
"!",
"$",
"stream",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Could not open file: $remote_file\"",
")",
";",
"}",
"$",
"data_to_send",
"=",
"@",
"file_get_contents",
"(",
"$",
"local_file",
")",
";",
"if",
"(",
"$",
"data_to_send",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Could not open local file: $local_file.\"",
")",
";",
"}",
"if",
"(",
"@",
"fwrite",
"(",
"$",
"stream",
",",
"$",
"data_to_send",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Could not send data from file: $local_file.\"",
")",
";",
"}",
"@",
"fclose",
"(",
"$",
"stream",
")",
";",
"return",
"true",
";",
"}"
] | Put a file on the remote machine
@param string $local_file The path to the local file to read
@param string $remote_file The path to the remote file to write
@param integer $mode File permission mode, if is set, uses scp which is slower | [
"Put",
"a",
"file",
"on",
"the",
"remote",
"machine"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/SFTP/Client.php#L88-L113 |
surebert/surebert-framework | src/sb/SFTP/Client.php | Client.get | public function get($remote_file, $local_file)
{
$stream = @fopen("ssh2.sftp://".$this->sftp.$remote_file, 'r');
if (! $stream){
throw new \Exception("Could not get remote file:". $remote_file);
}
$size = $this->size($remote_file);
$contents = '';
$read = 0;
$len = $size;
while ($read < $len && ($buf = fread($stream, $len - $read))) {
$read += strlen($buf);
$contents .= $buf;
}
file_put_contents ($local_file, $contents);
@fclose($stream);
return true;
} | php | public function get($remote_file, $local_file)
{
$stream = @fopen("ssh2.sftp://".$this->sftp.$remote_file, 'r');
if (! $stream){
throw new \Exception("Could not get remote file:". $remote_file);
}
$size = $this->size($remote_file);
$contents = '';
$read = 0;
$len = $size;
while ($read < $len && ($buf = fread($stream, $len - $read))) {
$read += strlen($buf);
$contents .= $buf;
}
file_put_contents ($local_file, $contents);
@fclose($stream);
return true;
} | [
"public",
"function",
"get",
"(",
"$",
"remote_file",
",",
"$",
"local_file",
")",
"{",
"$",
"stream",
"=",
"@",
"fopen",
"(",
"\"ssh2.sftp://\"",
".",
"$",
"this",
"->",
"sftp",
".",
"$",
"remote_file",
",",
"'r'",
")",
";",
"if",
"(",
"!",
"$",
"stream",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Could not get remote file:\"",
".",
"$",
"remote_file",
")",
";",
"}",
"$",
"size",
"=",
"$",
"this",
"->",
"size",
"(",
"$",
"remote_file",
")",
";",
"$",
"contents",
"=",
"''",
";",
"$",
"read",
"=",
"0",
";",
"$",
"len",
"=",
"$",
"size",
";",
"while",
"(",
"$",
"read",
"<",
"$",
"len",
"&&",
"(",
"$",
"buf",
"=",
"fread",
"(",
"$",
"stream",
",",
"$",
"len",
"-",
"$",
"read",
")",
")",
")",
"{",
"$",
"read",
"+=",
"strlen",
"(",
"$",
"buf",
")",
";",
"$",
"contents",
".=",
"$",
"buf",
";",
"}",
"file_put_contents",
"(",
"$",
"local_file",
",",
"$",
"contents",
")",
";",
"@",
"fclose",
"(",
"$",
"stream",
")",
";",
"return",
"true",
";",
"}"
] | Get a file from the remote machine
@param string $remote_file The path to the remote file to read
@param string $local_file The path to the local file to write | [
"Get",
"a",
"file",
"from",
"the",
"remote",
"machine"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/SFTP/Client.php#L121-L142 |
surebert/surebert-framework | src/sb/SFTP/Client.php | Client.ls | public function ls($remote_dir)
{
$dir = "ssh2.sftp://".$this->sftp.$remote_dir;
$handle = opendir($dir);
$files = Array();
while (false !== ($file = readdir($handle))) {
if (substr($file, 0, 1) != '.'){
$files[] = $file;
}
}
closedir($handle);
return $files;
} | php | public function ls($remote_dir)
{
$dir = "ssh2.sftp://".$this->sftp.$remote_dir;
$handle = opendir($dir);
$files = Array();
while (false !== ($file = readdir($handle))) {
if (substr($file, 0, 1) != '.'){
$files[] = $file;
}
}
closedir($handle);
return $files;
} | [
"public",
"function",
"ls",
"(",
"$",
"remote_dir",
")",
"{",
"$",
"dir",
"=",
"\"ssh2.sftp://\"",
".",
"$",
"this",
"->",
"sftp",
".",
"$",
"remote_dir",
";",
"$",
"handle",
"=",
"opendir",
"(",
"$",
"dir",
")",
";",
"$",
"files",
"=",
"Array",
"(",
")",
";",
"while",
"(",
"false",
"!==",
"(",
"$",
"file",
"=",
"readdir",
"(",
"$",
"handle",
")",
")",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"file",
",",
"0",
",",
"1",
")",
"!=",
"'.'",
")",
"{",
"$",
"files",
"[",
"]",
"=",
"$",
"file",
";",
"}",
"}",
"closedir",
"(",
"$",
"handle",
")",
";",
"return",
"$",
"files",
";",
"}"
] | Lists the contents of a remote directory
@param string $remote_dir
@return Array The array of files | [
"Lists",
"the",
"contents",
"of",
"a",
"remote",
"directory"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/SFTP/Client.php#L149-L164 |
surebert/surebert-framework | src/sb/SFTP/Client.php | Client.renameRemoteFile | public function renameRemoteFile($from, $to)
{
if(@ssh2_sftp_rename($this->sftp, $from, $to)){
throw new \Exception("Could not rename file from $from to $to");
}
return true;
} | php | public function renameRemoteFile($from, $to)
{
if(@ssh2_sftp_rename($this->sftp, $from, $to)){
throw new \Exception("Could not rename file from $from to $to");
}
return true;
} | [
"public",
"function",
"renameRemoteFile",
"(",
"$",
"from",
",",
"$",
"to",
")",
"{",
"if",
"(",
"@",
"ssh2_sftp_rename",
"(",
"$",
"this",
"->",
"sftp",
",",
"$",
"from",
",",
"$",
"to",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Could not rename file from $from to $to\"",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Renames remote files
@param string $from The old path/file name
@param string $to The new path/file name | [
"Renames",
"remote",
"files"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/SFTP/Client.php#L181-L188 |
surebert/surebert-framework | src/sb/SFTP/Client.php | Client.getFileStats | public function getFileStats($path)
{
$stats = @ssh2_sftp_stat($this->sftp, $path);
if(!$stats['size']){
throw new \Exception("Could get file stat: ".$path);
}
return $stats;
} | php | public function getFileStats($path)
{
$stats = @ssh2_sftp_stat($this->sftp, $path);
if(!$stats['size']){
throw new \Exception("Could get file stat: ".$path);
}
return $stats;
} | [
"public",
"function",
"getFileStats",
"(",
"$",
"path",
")",
"{",
"$",
"stats",
"=",
"@",
"ssh2_sftp_stat",
"(",
"$",
"this",
"->",
"sftp",
",",
"$",
"path",
")",
";",
"if",
"(",
"!",
"$",
"stats",
"[",
"'size'",
"]",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Could get file stat: \"",
".",
"$",
"path",
")",
";",
"}",
"return",
"$",
"stats",
";",
"}"
] | Gets remote file stats
@param string $path The path to the file to get stats for
@return Array with size, gid, uid, atime, mtime, mode keys | [
"Gets",
"remote",
"file",
"stats"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/SFTP/Client.php#L230-L237 |
surebert/surebert-framework | src/sb/SFTP/Client.php | Client.readlink | public function readlink($path)
{
$result = @ssh2_sftp_readlink($this->sftp, $path);
if(!$result){
throw new \Exception("Could get readlink: ".$path);
}
return $result;
} | php | public function readlink($path)
{
$result = @ssh2_sftp_readlink($this->sftp, $path);
if(!$result){
throw new \Exception("Could get readlink: ".$path);
}
return $result;
} | [
"public",
"function",
"readlink",
"(",
"$",
"path",
")",
"{",
"$",
"result",
"=",
"@",
"ssh2_sftp_readlink",
"(",
"$",
"this",
"->",
"sftp",
",",
"$",
"path",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Could get readlink: \"",
".",
"$",
"path",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Return the target of a symbolic link
@param string $path
@return string the real path to the file | [
"Return",
"the",
"target",
"of",
"a",
"symbolic",
"link"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/SFTP/Client.php#L244-L251 |
surebert/surebert-framework | src/sb/SFTP/Client.php | Client.ssh2SftpSymlink | public function ssh2SftpSymlink($orig_path, $symlink_path)
{
$result = @ssh2_sftp_symlink($this->sftp, $orig_path, $symlink_path);
if(!$result){
throw new \Exception("Could create symlink: ".$path);
}
return $result;
} | php | public function ssh2SftpSymlink($orig_path, $symlink_path)
{
$result = @ssh2_sftp_symlink($this->sftp, $orig_path, $symlink_path);
if(!$result){
throw new \Exception("Could create symlink: ".$path);
}
return $result;
} | [
"public",
"function",
"ssh2SftpSymlink",
"(",
"$",
"orig_path",
",",
"$",
"symlink_path",
")",
"{",
"$",
"result",
"=",
"@",
"ssh2_sftp_symlink",
"(",
"$",
"this",
"->",
"sftp",
",",
"$",
"orig_path",
",",
"$",
"symlink_path",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Could create symlink: \"",
".",
"$",
"path",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Create a symlink on the remote system
@param string $orig_path The path to the original remote file
@param string $symlink_path The path to the symlink you want to create
@return boolean success or failure | [
"Create",
"a",
"symlink",
"on",
"the",
"remote",
"system"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/SFTP/Client.php#L259-L266 |
surebert/surebert-framework | src/sb/SFTP/Client.php | Client.scpSend | protected function scpSend($local_path, $remote_path, $mode=0644)
{
if(@ssh2_scpSend($connection, $remote_path, $remote_path, $mode)){
throw new \Exception("Could send file with scp: ".$local_path.' to '.$remote_path);
}
} | php | protected function scpSend($local_path, $remote_path, $mode=0644)
{
if(@ssh2_scpSend($connection, $remote_path, $remote_path, $mode)){
throw new \Exception("Could send file with scp: ".$local_path.' to '.$remote_path);
}
} | [
"protected",
"function",
"scpSend",
"(",
"$",
"local_path",
",",
"$",
"remote_path",
",",
"$",
"mode",
"=",
"0644",
")",
"{",
"if",
"(",
"@",
"ssh2_scpSend",
"(",
"$",
"connection",
",",
"$",
"remote_path",
",",
"$",
"remote_path",
",",
"$",
"mode",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Could send file with scp: \"",
".",
"$",
"local_path",
".",
"' to '",
".",
"$",
"remote_path",
")",
";",
"}",
"}"
] | Use scp to send, slower than $this->get which uses sftp but allows mode change
@param string $local_path The local file path
@param string $remote_path The remote file path
@param int $mode The file mode to set for the remote file
@return boolean | [
"Use",
"scp",
"to",
"send",
"slower",
"than",
"$this",
"-",
">",
"get",
"which",
"uses",
"sftp",
"but",
"allows",
"mode",
"change"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/SFTP/Client.php#L287-L292 |
php-lug/lug | src/Bundle/LocaleBundle/Validator/LocaleIntegrityValidator.php | LocaleIntegrityValidator.validate | public function validate($locale, Constraint $constraint)
{
if ($locale->isEnabled() && $locale->isRequired()) {
return;
}
$this->validateDefaultLocale($locale, $constraint);
$this->validateLastLocale($locale, $constraint);
} | php | public function validate($locale, Constraint $constraint)
{
if ($locale->isEnabled() && $locale->isRequired()) {
return;
}
$this->validateDefaultLocale($locale, $constraint);
$this->validateLastLocale($locale, $constraint);
} | [
"public",
"function",
"validate",
"(",
"$",
"locale",
",",
"Constraint",
"$",
"constraint",
")",
"{",
"if",
"(",
"$",
"locale",
"->",
"isEnabled",
"(",
")",
"&&",
"$",
"locale",
"->",
"isRequired",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"validateDefaultLocale",
"(",
"$",
"locale",
",",
"$",
"constraint",
")",
";",
"$",
"this",
"->",
"validateLastLocale",
"(",
"$",
"locale",
",",
"$",
"constraint",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/LocaleBundle/Validator/LocaleIntegrityValidator.php#L40-L48 |
zhouyl/mellivora | Mellivora/Database/Query/Grammars/Grammar.php | Grammar.compileJoins | protected function compileJoins(Builder $query, $joins)
{
return collect($joins)->map(function ($join) use ($query) {
$table = $this->wrapTable($join->table);
return trim("{$join->type} join {$table} {$this->compileWheres($join)}");
})->implode(' ');
} | php | protected function compileJoins(Builder $query, $joins)
{
return collect($joins)->map(function ($join) use ($query) {
$table = $this->wrapTable($join->table);
return trim("{$join->type} join {$table} {$this->compileWheres($join)}");
})->implode(' ');
} | [
"protected",
"function",
"compileJoins",
"(",
"Builder",
"$",
"query",
",",
"$",
"joins",
")",
"{",
"return",
"collect",
"(",
"$",
"joins",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"join",
")",
"use",
"(",
"$",
"query",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"wrapTable",
"(",
"$",
"join",
"->",
"table",
")",
";",
"return",
"trim",
"(",
"\"{$join->type} join {$table} {$this->compileWheres($join)}\"",
")",
";",
"}",
")",
"->",
"implode",
"(",
"' '",
")",
";",
"}"
] | Compile the "join" portions of the query.
@param \Mellivora\Database\Query\Builder $query
@param array $joins
@return string | [
"Compile",
"the",
"join",
"portions",
"of",
"the",
"query",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Query/Grammars/Grammar.php#L161-L168 |
zhouyl/mellivora | Mellivora/Database/Query/Grammars/Grammar.php | Grammar.prepareBindingsForUpdate | public function prepareBindingsForUpdate(array $bindings, array $values)
{
$bindingsWithoutJoin = Arr::except($bindings, 'join');
return array_values(
array_merge($bindings['join'], $values, Arr::flatten($bindingsWithoutJoin))
);
} | php | public function prepareBindingsForUpdate(array $bindings, array $values)
{
$bindingsWithoutJoin = Arr::except($bindings, 'join');
return array_values(
array_merge($bindings['join'], $values, Arr::flatten($bindingsWithoutJoin))
);
} | [
"public",
"function",
"prepareBindingsForUpdate",
"(",
"array",
"$",
"bindings",
",",
"array",
"$",
"values",
")",
"{",
"$",
"bindingsWithoutJoin",
"=",
"Arr",
"::",
"except",
"(",
"$",
"bindings",
",",
"'join'",
")",
";",
"return",
"array_values",
"(",
"array_merge",
"(",
"$",
"bindings",
"[",
"'join'",
"]",
",",
"$",
"values",
",",
"Arr",
"::",
"flatten",
"(",
"$",
"bindingsWithoutJoin",
")",
")",
")",
";",
"}"
] | Prepare the bindings for an update statement.
@param array $bindings
@param array $values
@return array | [
"Prepare",
"the",
"bindings",
"for",
"an",
"update",
"statement",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Query/Grammars/Grammar.php#L789-L796 |
ronaldborla/chikka | src/Borla/Chikka/Support/Loader.php | Loader.config | static function config($config) {
// Cache
static $cache;
// If found
if ($cache && array_key_exists($config, $cache)) {
// Return
return $cache[$config];
}
// If there's config
if (function_exists('config')) {
// Use this
return $cache[$config] = config('chikka.' . $config);
}
// Or else
else {
// Load config from defaults
$defaults = static::defaults();
// Split by .
$tree = explode('.', $config);
// Loop through tree
foreach ($tree as $branch) {
// If not set
if ( ! isset($defaults[$branch])) {
// Return null
return $cache[$config] = null;
}
// Set defaults
$defaults = $defaults[$branch];
}
// Return
return $cache[$config] = $defaults;
}
} | php | static function config($config) {
// Cache
static $cache;
// If found
if ($cache && array_key_exists($config, $cache)) {
// Return
return $cache[$config];
}
// If there's config
if (function_exists('config')) {
// Use this
return $cache[$config] = config('chikka.' . $config);
}
// Or else
else {
// Load config from defaults
$defaults = static::defaults();
// Split by .
$tree = explode('.', $config);
// Loop through tree
foreach ($tree as $branch) {
// If not set
if ( ! isset($defaults[$branch])) {
// Return null
return $cache[$config] = null;
}
// Set defaults
$defaults = $defaults[$branch];
}
// Return
return $cache[$config] = $defaults;
}
} | [
"static",
"function",
"config",
"(",
"$",
"config",
")",
"{",
"// Cache",
"static",
"$",
"cache",
";",
"// If found",
"if",
"(",
"$",
"cache",
"&&",
"array_key_exists",
"(",
"$",
"config",
",",
"$",
"cache",
")",
")",
"{",
"// Return",
"return",
"$",
"cache",
"[",
"$",
"config",
"]",
";",
"}",
"// If there's config",
"if",
"(",
"function_exists",
"(",
"'config'",
")",
")",
"{",
"// Use this",
"return",
"$",
"cache",
"[",
"$",
"config",
"]",
"=",
"config",
"(",
"'chikka.'",
".",
"$",
"config",
")",
";",
"}",
"// Or else",
"else",
"{",
"// Load config from defaults",
"$",
"defaults",
"=",
"static",
"::",
"defaults",
"(",
")",
";",
"// Split by .",
"$",
"tree",
"=",
"explode",
"(",
"'.'",
",",
"$",
"config",
")",
";",
"// Loop through tree",
"foreach",
"(",
"$",
"tree",
"as",
"$",
"branch",
")",
"{",
"// If not set",
"if",
"(",
"!",
"isset",
"(",
"$",
"defaults",
"[",
"$",
"branch",
"]",
")",
")",
"{",
"// Return null",
"return",
"$",
"cache",
"[",
"$",
"config",
"]",
"=",
"null",
";",
"}",
"// Set defaults",
"$",
"defaults",
"=",
"$",
"defaults",
"[",
"$",
"branch",
"]",
";",
"}",
"// Return",
"return",
"$",
"cache",
"[",
"$",
"config",
"]",
"=",
"$",
"defaults",
";",
"}",
"}"
] | Get config | [
"Get",
"config"
] | train | https://github.com/ronaldborla/chikka/blob/446987706f81d5a0efbc8bd6b7d3b259d0527719/src/Borla/Chikka/Support/Loader.php#L38-L70 |
ronaldborla/chikka | src/Borla/Chikka/Support/Loader.php | Loader.getClass | static function getClass($class) {
// Cache
static $cache;
// If found
if ($cache && array_key_exists($class, $cache)) {
// Return
return $cache[$class];
}
// Get class name
$className = static::config($class);
// If not found
if ( ! $className) {
// Attempt models
$className = static::config('models.' . $class);
}
// If not found
if ( ! $className) {
// Throw error
throw new InvalidClass('Class not set: ' . $class);
}
// Prepend \
$className = '\\' . str_replace('/', '\\', trim($className, '/\\'));
// If class doesn't exist
if ( ! class_exists($className)) {
// Invalid class
throw new Exception('Class undefined: ' . $className);
}
// Return class name
return $cache[$class] = $className;
} | php | static function getClass($class) {
// Cache
static $cache;
// If found
if ($cache && array_key_exists($class, $cache)) {
// Return
return $cache[$class];
}
// Get class name
$className = static::config($class);
// If not found
if ( ! $className) {
// Attempt models
$className = static::config('models.' . $class);
}
// If not found
if ( ! $className) {
// Throw error
throw new InvalidClass('Class not set: ' . $class);
}
// Prepend \
$className = '\\' . str_replace('/', '\\', trim($className, '/\\'));
// If class doesn't exist
if ( ! class_exists($className)) {
// Invalid class
throw new Exception('Class undefined: ' . $className);
}
// Return class name
return $cache[$class] = $className;
} | [
"static",
"function",
"getClass",
"(",
"$",
"class",
")",
"{",
"// Cache",
"static",
"$",
"cache",
";",
"// If found",
"if",
"(",
"$",
"cache",
"&&",
"array_key_exists",
"(",
"$",
"class",
",",
"$",
"cache",
")",
")",
"{",
"// Return",
"return",
"$",
"cache",
"[",
"$",
"class",
"]",
";",
"}",
"// Get class name",
"$",
"className",
"=",
"static",
"::",
"config",
"(",
"$",
"class",
")",
";",
"// If not found",
"if",
"(",
"!",
"$",
"className",
")",
"{",
"// Attempt models",
"$",
"className",
"=",
"static",
"::",
"config",
"(",
"'models.'",
".",
"$",
"class",
")",
";",
"}",
"// If not found",
"if",
"(",
"!",
"$",
"className",
")",
"{",
"// Throw error",
"throw",
"new",
"InvalidClass",
"(",
"'Class not set: '",
".",
"$",
"class",
")",
";",
"}",
"// Prepend \\",
"$",
"className",
"=",
"'\\\\'",
".",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"trim",
"(",
"$",
"className",
",",
"'/\\\\'",
")",
")",
";",
"// If class doesn't exist",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"// Invalid class",
"throw",
"new",
"Exception",
"(",
"'Class undefined: '",
".",
"$",
"className",
")",
";",
"}",
"// Return class name",
"return",
"$",
"cache",
"[",
"$",
"class",
"]",
"=",
"$",
"className",
";",
"}"
] | Get class | [
"Get",
"class"
] | train | https://github.com/ronaldborla/chikka/blob/446987706f81d5a0efbc8bd6b7d3b259d0527719/src/Borla/Chikka/Support/Loader.php#L75-L104 |
ronaldborla/chikka | src/Borla/Chikka/Support/Loader.php | Loader.instance | static function instance($class, array $args = []) {
// Get class name
$class = static::getClass($class);
// Count args
switch (count($args)) {
case 1: return new $class($args[0]);
case 2: return new $class($args[0], $args[1]);
case 3: return new $class($args[0], $args[1], $args[2]);
case 4: return new $class($args[0], $args[1], $args[2], $args[3]);
case 5: return new $class($args[0], $args[1], $args[2], $args[3], $args[4]);
case 6: return new $class($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]);
case 7: return new $class($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6]);
case 8: return new $class($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]);
case 9: return new $class($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8]);
case 10: return new $class($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8], $args[9]);
}
// Return without args
return new $class();
} | php | static function instance($class, array $args = []) {
// Get class name
$class = static::getClass($class);
// Count args
switch (count($args)) {
case 1: return new $class($args[0]);
case 2: return new $class($args[0], $args[1]);
case 3: return new $class($args[0], $args[1], $args[2]);
case 4: return new $class($args[0], $args[1], $args[2], $args[3]);
case 5: return new $class($args[0], $args[1], $args[2], $args[3], $args[4]);
case 6: return new $class($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]);
case 7: return new $class($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6]);
case 8: return new $class($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]);
case 9: return new $class($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8]);
case 10: return new $class($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8], $args[9]);
}
// Return without args
return new $class();
} | [
"static",
"function",
"instance",
"(",
"$",
"class",
",",
"array",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"// Get class name",
"$",
"class",
"=",
"static",
"::",
"getClass",
"(",
"$",
"class",
")",
";",
"// Count args",
"switch",
"(",
"count",
"(",
"$",
"args",
")",
")",
"{",
"case",
"1",
":",
"return",
"new",
"$",
"class",
"(",
"$",
"args",
"[",
"0",
"]",
")",
";",
"case",
"2",
":",
"return",
"new",
"$",
"class",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
")",
";",
"case",
"3",
":",
"return",
"new",
"$",
"class",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"args",
"[",
"2",
"]",
")",
";",
"case",
"4",
":",
"return",
"new",
"$",
"class",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"args",
"[",
"2",
"]",
",",
"$",
"args",
"[",
"3",
"]",
")",
";",
"case",
"5",
":",
"return",
"new",
"$",
"class",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"args",
"[",
"2",
"]",
",",
"$",
"args",
"[",
"3",
"]",
",",
"$",
"args",
"[",
"4",
"]",
")",
";",
"case",
"6",
":",
"return",
"new",
"$",
"class",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"args",
"[",
"2",
"]",
",",
"$",
"args",
"[",
"3",
"]",
",",
"$",
"args",
"[",
"4",
"]",
",",
"$",
"args",
"[",
"5",
"]",
")",
";",
"case",
"7",
":",
"return",
"new",
"$",
"class",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"args",
"[",
"2",
"]",
",",
"$",
"args",
"[",
"3",
"]",
",",
"$",
"args",
"[",
"4",
"]",
",",
"$",
"args",
"[",
"5",
"]",
",",
"$",
"args",
"[",
"6",
"]",
")",
";",
"case",
"8",
":",
"return",
"new",
"$",
"class",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"args",
"[",
"2",
"]",
",",
"$",
"args",
"[",
"3",
"]",
",",
"$",
"args",
"[",
"4",
"]",
",",
"$",
"args",
"[",
"5",
"]",
",",
"$",
"args",
"[",
"6",
"]",
",",
"$",
"args",
"[",
"7",
"]",
")",
";",
"case",
"9",
":",
"return",
"new",
"$",
"class",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"args",
"[",
"2",
"]",
",",
"$",
"args",
"[",
"3",
"]",
",",
"$",
"args",
"[",
"4",
"]",
",",
"$",
"args",
"[",
"5",
"]",
",",
"$",
"args",
"[",
"6",
"]",
",",
"$",
"args",
"[",
"7",
"]",
",",
"$",
"args",
"[",
"8",
"]",
")",
";",
"case",
"10",
":",
"return",
"new",
"$",
"class",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"args",
"[",
"2",
"]",
",",
"$",
"args",
"[",
"3",
"]",
",",
"$",
"args",
"[",
"4",
"]",
",",
"$",
"args",
"[",
"5",
"]",
",",
"$",
"args",
"[",
"6",
"]",
",",
"$",
"args",
"[",
"7",
"]",
",",
"$",
"args",
"[",
"8",
"]",
",",
"$",
"args",
"[",
"9",
"]",
")",
";",
"}",
"// Return without args",
"return",
"new",
"$",
"class",
"(",
")",
";",
"}"
] | Instantiate class | [
"Instantiate",
"class"
] | train | https://github.com/ronaldborla/chikka/blob/446987706f81d5a0efbc8bd6b7d3b259d0527719/src/Borla/Chikka/Support/Loader.php#L109-L127 |
Eresus/EresusCMS | src/core/client.php | TClientUI.replaceMacros | public function replaceMacros($text)
{
$section = $this->section;
if (siteTitleReverse)
{
$section = array_reverse($section);
}
$section = strip_tags(implode($section, option('siteTitleDivider')));
$result = str_replace(
array(
'$(httpHost)',
'$(httpPath)',
'$(httpRoot)',
'$(styleRoot)',
'$(dataRoot)',
'$(siteName)',
'$(siteTitle)',
'$(siteKeywords)',
'$(siteDescription)',
'$(pageId)',
'$(pageName)',
'$(pageTitle)',
'$(pageCaption)',
'$(pageHint)',
'$(pageDescription)',
'$(pageKeywords)',
'$(pageAccessLevel)',
'$(pageAccessName)',
'$(sectionTitle)',
),
array(
httpHost,
httpPath,
httpRoot,
styleRoot,
dataRoot,
siteName,
siteTitle,
siteKeywords,
siteDescription,
$this->id,
$this->name,
$this->title,
$this->caption,
$this->hint,
$this->description,
$this->keywords,
$this->access,
constant('ACCESSLEVEL'.$this->access),
$section,
),
$text
);
$result = preg_replace_callback('/\$\(const:(.*?)\)/i', '__macroConst', $result);
$result = preg_replace_callback('/\$\(var:(([\w]*)(\[.*?\]){0,1})\)/i', '__macroVar', $result);
$result = preg_replace('/\$\(\w+(:.*?)*?\)/', '', $result);
return $result;
} | php | public function replaceMacros($text)
{
$section = $this->section;
if (siteTitleReverse)
{
$section = array_reverse($section);
}
$section = strip_tags(implode($section, option('siteTitleDivider')));
$result = str_replace(
array(
'$(httpHost)',
'$(httpPath)',
'$(httpRoot)',
'$(styleRoot)',
'$(dataRoot)',
'$(siteName)',
'$(siteTitle)',
'$(siteKeywords)',
'$(siteDescription)',
'$(pageId)',
'$(pageName)',
'$(pageTitle)',
'$(pageCaption)',
'$(pageHint)',
'$(pageDescription)',
'$(pageKeywords)',
'$(pageAccessLevel)',
'$(pageAccessName)',
'$(sectionTitle)',
),
array(
httpHost,
httpPath,
httpRoot,
styleRoot,
dataRoot,
siteName,
siteTitle,
siteKeywords,
siteDescription,
$this->id,
$this->name,
$this->title,
$this->caption,
$this->hint,
$this->description,
$this->keywords,
$this->access,
constant('ACCESSLEVEL'.$this->access),
$section,
),
$text
);
$result = preg_replace_callback('/\$\(const:(.*?)\)/i', '__macroConst', $result);
$result = preg_replace_callback('/\$\(var:(([\w]*)(\[.*?\]){0,1})\)/i', '__macroVar', $result);
$result = preg_replace('/\$\(\w+(:.*?)*?\)/', '', $result);
return $result;
} | [
"public",
"function",
"replaceMacros",
"(",
"$",
"text",
")",
"{",
"$",
"section",
"=",
"$",
"this",
"->",
"section",
";",
"if",
"(",
"siteTitleReverse",
")",
"{",
"$",
"section",
"=",
"array_reverse",
"(",
"$",
"section",
")",
";",
"}",
"$",
"section",
"=",
"strip_tags",
"(",
"implode",
"(",
"$",
"section",
",",
"option",
"(",
"'siteTitleDivider'",
")",
")",
")",
";",
"$",
"result",
"=",
"str_replace",
"(",
"array",
"(",
"'$(httpHost)'",
",",
"'$(httpPath)'",
",",
"'$(httpRoot)'",
",",
"'$(styleRoot)'",
",",
"'$(dataRoot)'",
",",
"'$(siteName)'",
",",
"'$(siteTitle)'",
",",
"'$(siteKeywords)'",
",",
"'$(siteDescription)'",
",",
"'$(pageId)'",
",",
"'$(pageName)'",
",",
"'$(pageTitle)'",
",",
"'$(pageCaption)'",
",",
"'$(pageHint)'",
",",
"'$(pageDescription)'",
",",
"'$(pageKeywords)'",
",",
"'$(pageAccessLevel)'",
",",
"'$(pageAccessName)'",
",",
"'$(sectionTitle)'",
",",
")",
",",
"array",
"(",
"httpHost",
",",
"httpPath",
",",
"httpRoot",
",",
"styleRoot",
",",
"dataRoot",
",",
"siteName",
",",
"siteTitle",
",",
"siteKeywords",
",",
"siteDescription",
",",
"$",
"this",
"->",
"id",
",",
"$",
"this",
"->",
"name",
",",
"$",
"this",
"->",
"title",
",",
"$",
"this",
"->",
"caption",
",",
"$",
"this",
"->",
"hint",
",",
"$",
"this",
"->",
"description",
",",
"$",
"this",
"->",
"keywords",
",",
"$",
"this",
"->",
"access",
",",
"constant",
"(",
"'ACCESSLEVEL'",
".",
"$",
"this",
"->",
"access",
")",
",",
"$",
"section",
",",
")",
",",
"$",
"text",
")",
";",
"$",
"result",
"=",
"preg_replace_callback",
"(",
"'/\\$\\(const:(.*?)\\)/i'",
",",
"'__macroConst'",
",",
"$",
"result",
")",
";",
"$",
"result",
"=",
"preg_replace_callback",
"(",
"'/\\$\\(var:(([\\w]*)(\\[.*?\\]){0,1})\\)/i'",
",",
"'__macroVar'",
",",
"$",
"result",
")",
";",
"$",
"result",
"=",
"preg_replace",
"(",
"'/\\$\\(\\w+(:.*?)*?\\)/'",
",",
"''",
",",
"$",
"result",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Подставляет значения макросов
@param string $text
@return mixed | [
"Подставляет",
"значения",
"макросов"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/client.php#L129-L192 |
Eresus/EresusCMS | src/core/client.php | TClientUI.pageSelector | public function pageSelector($total, $current, $url = null, $templates = null)
{
if (is_null($url))
{
$url = $this->url().'p%d/';
}
$Templates = Templates::getInstance();
$defaults = explode('---', $Templates->get('PageSelector', 'std'));
if (!is_array($templates))
{
$templates = array();
}
for ($i=0; $i < 5; $i++)
{
if (!isset($templates[$i]))
{
$templates[$i] = $defaults[$i];
}
}
$result = parent::pageSelector($total, $current, $url, $templates);
return $result;
} | php | public function pageSelector($total, $current, $url = null, $templates = null)
{
if (is_null($url))
{
$url = $this->url().'p%d/';
}
$Templates = Templates::getInstance();
$defaults = explode('---', $Templates->get('PageSelector', 'std'));
if (!is_array($templates))
{
$templates = array();
}
for ($i=0; $i < 5; $i++)
{
if (!isset($templates[$i]))
{
$templates[$i] = $defaults[$i];
}
}
$result = parent::pageSelector($total, $current, $url, $templates);
return $result;
} | [
"public",
"function",
"pageSelector",
"(",
"$",
"total",
",",
"$",
"current",
",",
"$",
"url",
"=",
"null",
",",
"$",
"templates",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"url",
")",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"url",
"(",
")",
".",
"'p%d/'",
";",
"}",
"$",
"Templates",
"=",
"Templates",
"::",
"getInstance",
"(",
")",
";",
"$",
"defaults",
"=",
"explode",
"(",
"'---'",
",",
"$",
"Templates",
"->",
"get",
"(",
"'PageSelector'",
",",
"'std'",
")",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"templates",
")",
")",
"{",
"$",
"templates",
"=",
"array",
"(",
")",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"5",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"templates",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"templates",
"[",
"$",
"i",
"]",
"=",
"$",
"defaults",
"[",
"$",
"i",
"]",
";",
"}",
"}",
"$",
"result",
"=",
"parent",
"::",
"pageSelector",
"(",
"$",
"total",
",",
"$",
"current",
",",
"$",
"url",
",",
"$",
"templates",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Отрисовка переключателя страниц
@param int $total Общее количество страниц
@param int $current Номер текущей страницы
@param string $url Шаблон адреса для перехода к подстранице.
@param array $templates Шаблоны оформления
@return string | [
"Отрисовка",
"переключателя",
"страниц"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/client.php#L203-L224 |
Eresus/EresusCMS | src/core/client.php | TClientUI.loadPage | private function loadPage()
{
$result = false;
$main_fake = false;
if (!count(Eresus_CMS::getLegacyKernel()->request['params']) ||
Eresus_CMS::getLegacyKernel()->request['params'][0] != 'main')
{
array_unshift(Eresus_CMS::getLegacyKernel()->request['params'], 'main');
$main_fake = true;
}
reset(Eresus_CMS::getLegacyKernel()->request['params']);
$item['id'] = 0;
$url = '';
do
{
$items = Eresus_CMS::getLegacyKernel()->sections->children($item['id'],
Eresus_CMS::getLegacyKernel()->user['auth'] ?
Eresus_CMS::getLegacyKernel()->user['access'] : GUEST, SECTIONS_ACTIVE);
$item = false;
for ($i=0; $i<count($items); $i++)
{
if ($items[$i]['name'] == current(Eresus_CMS::getLegacyKernel()->request['params']))
{
$result = $item = $items[$i];
if ($item['id'] != 1 || !$main_fake)
{
$url .= $item['name'].'/';
}
$event = new Eresus_Event_UrlSectionFound($item, $url);
Eresus_Kernel::app()->getEventDispatcher()
->dispatch('cms.client.url_section_found', $event);
$this->section[] = $item['title'];
next(Eresus_CMS::getLegacyKernel()->request['params']);
array_shift(Eresus_CMS::getLegacyKernel()->request['params']);
break;
}
}
if ($item && $item['id'] == 1 && $main_fake)
{
$item['id'] = 0;
}
}
while ($item && current(Eresus_CMS::getLegacyKernel()->request['params']));
Eresus_CMS::getLegacyKernel()->request['path'] =
Eresus_CMS::getLegacyKernel()->request['path'] = Eresus_CMS::getLegacyKernel()->root . $url;
if ($result)
{
$result = Eresus_CMS::getLegacyKernel()->sections->get($result['id']);
}
return $result;
} | php | private function loadPage()
{
$result = false;
$main_fake = false;
if (!count(Eresus_CMS::getLegacyKernel()->request['params']) ||
Eresus_CMS::getLegacyKernel()->request['params'][0] != 'main')
{
array_unshift(Eresus_CMS::getLegacyKernel()->request['params'], 'main');
$main_fake = true;
}
reset(Eresus_CMS::getLegacyKernel()->request['params']);
$item['id'] = 0;
$url = '';
do
{
$items = Eresus_CMS::getLegacyKernel()->sections->children($item['id'],
Eresus_CMS::getLegacyKernel()->user['auth'] ?
Eresus_CMS::getLegacyKernel()->user['access'] : GUEST, SECTIONS_ACTIVE);
$item = false;
for ($i=0; $i<count($items); $i++)
{
if ($items[$i]['name'] == current(Eresus_CMS::getLegacyKernel()->request['params']))
{
$result = $item = $items[$i];
if ($item['id'] != 1 || !$main_fake)
{
$url .= $item['name'].'/';
}
$event = new Eresus_Event_UrlSectionFound($item, $url);
Eresus_Kernel::app()->getEventDispatcher()
->dispatch('cms.client.url_section_found', $event);
$this->section[] = $item['title'];
next(Eresus_CMS::getLegacyKernel()->request['params']);
array_shift(Eresus_CMS::getLegacyKernel()->request['params']);
break;
}
}
if ($item && $item['id'] == 1 && $main_fake)
{
$item['id'] = 0;
}
}
while ($item && current(Eresus_CMS::getLegacyKernel()->request['params']));
Eresus_CMS::getLegacyKernel()->request['path'] =
Eresus_CMS::getLegacyKernel()->request['path'] = Eresus_CMS::getLegacyKernel()->root . $url;
if ($result)
{
$result = Eresus_CMS::getLegacyKernel()->sections->get($result['id']);
}
return $result;
} | [
"private",
"function",
"loadPage",
"(",
")",
"{",
"$",
"result",
"=",
"false",
";",
"$",
"main_fake",
"=",
"false",
";",
"if",
"(",
"!",
"count",
"(",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
"->",
"request",
"[",
"'params'",
"]",
")",
"||",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
"->",
"request",
"[",
"'params'",
"]",
"[",
"0",
"]",
"!=",
"'main'",
")",
"{",
"array_unshift",
"(",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
"->",
"request",
"[",
"'params'",
"]",
",",
"'main'",
")",
";",
"$",
"main_fake",
"=",
"true",
";",
"}",
"reset",
"(",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
"->",
"request",
"[",
"'params'",
"]",
")",
";",
"$",
"item",
"[",
"'id'",
"]",
"=",
"0",
";",
"$",
"url",
"=",
"''",
";",
"do",
"{",
"$",
"items",
"=",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
"->",
"sections",
"->",
"children",
"(",
"$",
"item",
"[",
"'id'",
"]",
",",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
"->",
"user",
"[",
"'auth'",
"]",
"?",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
"->",
"user",
"[",
"'access'",
"]",
":",
"GUEST",
",",
"SECTIONS_ACTIVE",
")",
";",
"$",
"item",
"=",
"false",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"items",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"items",
"[",
"$",
"i",
"]",
"[",
"'name'",
"]",
"==",
"current",
"(",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
"->",
"request",
"[",
"'params'",
"]",
")",
")",
"{",
"$",
"result",
"=",
"$",
"item",
"=",
"$",
"items",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"$",
"item",
"[",
"'id'",
"]",
"!=",
"1",
"||",
"!",
"$",
"main_fake",
")",
"{",
"$",
"url",
".=",
"$",
"item",
"[",
"'name'",
"]",
".",
"'/'",
";",
"}",
"$",
"event",
"=",
"new",
"Eresus_Event_UrlSectionFound",
"(",
"$",
"item",
",",
"$",
"url",
")",
";",
"Eresus_Kernel",
"::",
"app",
"(",
")",
"->",
"getEventDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"'cms.client.url_section_found'",
",",
"$",
"event",
")",
";",
"$",
"this",
"->",
"section",
"[",
"]",
"=",
"$",
"item",
"[",
"'title'",
"]",
";",
"next",
"(",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
"->",
"request",
"[",
"'params'",
"]",
")",
";",
"array_shift",
"(",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
"->",
"request",
"[",
"'params'",
"]",
")",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"item",
"&&",
"$",
"item",
"[",
"'id'",
"]",
"==",
"1",
"&&",
"$",
"main_fake",
")",
"{",
"$",
"item",
"[",
"'id'",
"]",
"=",
"0",
";",
"}",
"}",
"while",
"(",
"$",
"item",
"&&",
"current",
"(",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
"->",
"request",
"[",
"'params'",
"]",
")",
")",
";",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
"->",
"request",
"[",
"'path'",
"]",
"=",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
"->",
"request",
"[",
"'path'",
"]",
"=",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
"->",
"root",
".",
"$",
"url",
";",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"result",
"=",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
"->",
"sections",
"->",
"get",
"(",
"$",
"result",
"[",
"'id'",
"]",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Производит разбор URL и загрузку соответствующего раздела
@return array|bool Описание загруженного раздела или false если он не найден | [
"Производит",
"разбор",
"URL",
"и",
"загрузку",
"соответствующего",
"раздела"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/client.php#L231-L281 |
Eresus/EresusCMS | src/core/client.php | TClientUI.init | private function init()
{
Eresus_Kernel::app()->getEventDispatcher()->dispatch('cms.client.start');
$item = $this->loadPage();
if ($item)
{
if (count(Eresus_CMS::getLegacyKernel()->request['params']))
{
if (preg_match('/p[\d]+/i', Eresus_CMS::getLegacyKernel()->request['params'][0]))
{
$this->subpage = substr(array_shift(Eresus_CMS::getLegacyKernel()->request['params']), 1);
}
if (count(Eresus_CMS::getLegacyKernel()->request['params']))
{
$this->topic = array_shift(Eresus_CMS::getLegacyKernel()->request['params']);
}
}
$this->dbItem = $item;
$this->id = $item['id'];
$this->name = $item['name'];
$this->owner = $item['owner'];
$this->title = $item['title'];
$this->description = $item['description'];
$this->keywords = $item['keywords'];
$this->caption = $item['caption'];
$this->hint = $item['hint'];
$this->access = $item['access'];
$this->visible = $item['visible'];
$this->type = $item['type'];
$this->setTemplate($item['template']);
$this->content = $item['content'];
$this->scripts = '';
$this->styles = '';
$this->options = $item['options'];
}
else
{
throw new Eresus_CMS_Exception_NotFound;
}
} | php | private function init()
{
Eresus_Kernel::app()->getEventDispatcher()->dispatch('cms.client.start');
$item = $this->loadPage();
if ($item)
{
if (count(Eresus_CMS::getLegacyKernel()->request['params']))
{
if (preg_match('/p[\d]+/i', Eresus_CMS::getLegacyKernel()->request['params'][0]))
{
$this->subpage = substr(array_shift(Eresus_CMS::getLegacyKernel()->request['params']), 1);
}
if (count(Eresus_CMS::getLegacyKernel()->request['params']))
{
$this->topic = array_shift(Eresus_CMS::getLegacyKernel()->request['params']);
}
}
$this->dbItem = $item;
$this->id = $item['id'];
$this->name = $item['name'];
$this->owner = $item['owner'];
$this->title = $item['title'];
$this->description = $item['description'];
$this->keywords = $item['keywords'];
$this->caption = $item['caption'];
$this->hint = $item['hint'];
$this->access = $item['access'];
$this->visible = $item['visible'];
$this->type = $item['type'];
$this->setTemplate($item['template']);
$this->content = $item['content'];
$this->scripts = '';
$this->styles = '';
$this->options = $item['options'];
}
else
{
throw new Eresus_CMS_Exception_NotFound;
}
} | [
"private",
"function",
"init",
"(",
")",
"{",
"Eresus_Kernel",
"::",
"app",
"(",
")",
"->",
"getEventDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"'cms.client.start'",
")",
";",
"$",
"item",
"=",
"$",
"this",
"->",
"loadPage",
"(",
")",
";",
"if",
"(",
"$",
"item",
")",
"{",
"if",
"(",
"count",
"(",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
"->",
"request",
"[",
"'params'",
"]",
")",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/p[\\d]+/i'",
",",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
"->",
"request",
"[",
"'params'",
"]",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"subpage",
"=",
"substr",
"(",
"array_shift",
"(",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
"->",
"request",
"[",
"'params'",
"]",
")",
",",
"1",
")",
";",
"}",
"if",
"(",
"count",
"(",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
"->",
"request",
"[",
"'params'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"topic",
"=",
"array_shift",
"(",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
"->",
"request",
"[",
"'params'",
"]",
")",
";",
"}",
"}",
"$",
"this",
"->",
"dbItem",
"=",
"$",
"item",
";",
"$",
"this",
"->",
"id",
"=",
"$",
"item",
"[",
"'id'",
"]",
";",
"$",
"this",
"->",
"name",
"=",
"$",
"item",
"[",
"'name'",
"]",
";",
"$",
"this",
"->",
"owner",
"=",
"$",
"item",
"[",
"'owner'",
"]",
";",
"$",
"this",
"->",
"title",
"=",
"$",
"item",
"[",
"'title'",
"]",
";",
"$",
"this",
"->",
"description",
"=",
"$",
"item",
"[",
"'description'",
"]",
";",
"$",
"this",
"->",
"keywords",
"=",
"$",
"item",
"[",
"'keywords'",
"]",
";",
"$",
"this",
"->",
"caption",
"=",
"$",
"item",
"[",
"'caption'",
"]",
";",
"$",
"this",
"->",
"hint",
"=",
"$",
"item",
"[",
"'hint'",
"]",
";",
"$",
"this",
"->",
"access",
"=",
"$",
"item",
"[",
"'access'",
"]",
";",
"$",
"this",
"->",
"visible",
"=",
"$",
"item",
"[",
"'visible'",
"]",
";",
"$",
"this",
"->",
"type",
"=",
"$",
"item",
"[",
"'type'",
"]",
";",
"$",
"this",
"->",
"setTemplate",
"(",
"$",
"item",
"[",
"'template'",
"]",
")",
";",
"$",
"this",
"->",
"content",
"=",
"$",
"item",
"[",
"'content'",
"]",
";",
"$",
"this",
"->",
"scripts",
"=",
"''",
";",
"$",
"this",
"->",
"styles",
"=",
"''",
";",
"$",
"this",
"->",
"options",
"=",
"$",
"item",
"[",
"'options'",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"Eresus_CMS_Exception_NotFound",
";",
"}",
"}"
] | Проводит инициализацию страницы
@throws Eresus_CMS_Exception_NotFound | [
"Проводит",
"инициализацию",
"страницы"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/client.php#L288-L329 |
Eresus/EresusCMS | src/core/client.php | TClientUI.httpError | public function httpError($code)
{
switch ($code)
{
case 400:
throw new Eresus_HTTP_Exception_BadRequest;
case 401:
throw new Eresus_HTTP_Exception_Unauthorized;
case 402:
throw new Eresus_HTTP_Exception_PaymentRequired;
case 403:
throw new Eresus_HTTP_Exception_Forbidden;
case 404:
throw new Eresus_HTTP_Exception_NotFound;
default:
throw new Eresus_HTTP_Exception('', $code);
}
} | php | public function httpError($code)
{
switch ($code)
{
case 400:
throw new Eresus_HTTP_Exception_BadRequest;
case 401:
throw new Eresus_HTTP_Exception_Unauthorized;
case 402:
throw new Eresus_HTTP_Exception_PaymentRequired;
case 403:
throw new Eresus_HTTP_Exception_Forbidden;
case 404:
throw new Eresus_HTTP_Exception_NotFound;
default:
throw new Eresus_HTTP_Exception('', $code);
}
} | [
"public",
"function",
"httpError",
"(",
"$",
"code",
")",
"{",
"switch",
"(",
"$",
"code",
")",
"{",
"case",
"400",
":",
"throw",
"new",
"Eresus_HTTP_Exception_BadRequest",
";",
"case",
"401",
":",
"throw",
"new",
"Eresus_HTTP_Exception_Unauthorized",
";",
"case",
"402",
":",
"throw",
"new",
"Eresus_HTTP_Exception_PaymentRequired",
";",
"case",
"403",
":",
"throw",
"new",
"Eresus_HTTP_Exception_Forbidden",
";",
"case",
"404",
":",
"throw",
"new",
"Eresus_HTTP_Exception_NotFound",
";",
"default",
":",
"throw",
"new",
"Eresus_HTTP_Exception",
"(",
"''",
",",
"$",
"code",
")",
";",
"}",
"}"
] | Выводит сообщение об ошибке и прекращает выполнение программы
@param int $code код ошибки HTTP
@throws Eresus_HTTP_Exception
@deprecated с 3.01 используйте исключения Eresus_HTTP_Exception_* | [
"Выводит",
"сообщение",
"об",
"ошибке",
"и",
"прекращает",
"выполнение",
"программы"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/client.php#L352-L369 |
Eresus/EresusCMS | src/core/client.php | TClientUI.render | public function render(Eresus_CMS_Request $request)
{
Eresus_Kernel::log(__METHOD__, LOG_DEBUG, 'starting...');
try
{
$this->init();
$plugins = Eresus_Plugin_Registry::getInstance();
$response = $plugins->clientRenderContent($request);
if (!($response instanceof Eresus_HTTP_Response))
{
Eresus_Kernel::log(__METHOD__, LOG_DEBUG, 'got string content');
$content = new Eresus_CMS_Page_Content($this, $response);
$response = $this->createPageForContent($content);
}
}
catch (Eresus_CMS_Exception $e)
{
Eresus_Kernel::log(__METHOD__, LOG_NOTICE, '%s: "%s"', get_class($e), $e->getMessage());
$httpStatusCode = $e->getHttpException()->getCode();
$content = new Eresus_CMS_Page_Content($this,
$e->getMessage() ?: Eresus_HTTP_Response::getStatusText($httpStatusCode));
$response = $this->createPageForContent($content, $httpStatusCode);
}
// TODO: Обратная совместимость (убрать)
$response->setContent($this->replaceMacros($response->getContent()));
$event = new Eresus_Event_Response($response);
Eresus_Kernel::app()->getEventDispatcher()->dispatch('cms.client.response', $event);
return $response;
} | php | public function render(Eresus_CMS_Request $request)
{
Eresus_Kernel::log(__METHOD__, LOG_DEBUG, 'starting...');
try
{
$this->init();
$plugins = Eresus_Plugin_Registry::getInstance();
$response = $plugins->clientRenderContent($request);
if (!($response instanceof Eresus_HTTP_Response))
{
Eresus_Kernel::log(__METHOD__, LOG_DEBUG, 'got string content');
$content = new Eresus_CMS_Page_Content($this, $response);
$response = $this->createPageForContent($content);
}
}
catch (Eresus_CMS_Exception $e)
{
Eresus_Kernel::log(__METHOD__, LOG_NOTICE, '%s: "%s"', get_class($e), $e->getMessage());
$httpStatusCode = $e->getHttpException()->getCode();
$content = new Eresus_CMS_Page_Content($this,
$e->getMessage() ?: Eresus_HTTP_Response::getStatusText($httpStatusCode));
$response = $this->createPageForContent($content, $httpStatusCode);
}
// TODO: Обратная совместимость (убрать)
$response->setContent($this->replaceMacros($response->getContent()));
$event = new Eresus_Event_Response($response);
Eresus_Kernel::app()->getEventDispatcher()->dispatch('cms.client.response', $event);
return $response;
} | [
"public",
"function",
"render",
"(",
"Eresus_CMS_Request",
"$",
"request",
")",
"{",
"Eresus_Kernel",
"::",
"log",
"(",
"__METHOD__",
",",
"LOG_DEBUG",
",",
"'starting...'",
")",
";",
"try",
"{",
"$",
"this",
"->",
"init",
"(",
")",
";",
"$",
"plugins",
"=",
"Eresus_Plugin_Registry",
"::",
"getInstance",
"(",
")",
";",
"$",
"response",
"=",
"$",
"plugins",
"->",
"clientRenderContent",
"(",
"$",
"request",
")",
";",
"if",
"(",
"!",
"(",
"$",
"response",
"instanceof",
"Eresus_HTTP_Response",
")",
")",
"{",
"Eresus_Kernel",
"::",
"log",
"(",
"__METHOD__",
",",
"LOG_DEBUG",
",",
"'got string content'",
")",
";",
"$",
"content",
"=",
"new",
"Eresus_CMS_Page_Content",
"(",
"$",
"this",
",",
"$",
"response",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"createPageForContent",
"(",
"$",
"content",
")",
";",
"}",
"}",
"catch",
"(",
"Eresus_CMS_Exception",
"$",
"e",
")",
"{",
"Eresus_Kernel",
"::",
"log",
"(",
"__METHOD__",
",",
"LOG_NOTICE",
",",
"'%s: \"%s\"'",
",",
"get_class",
"(",
"$",
"e",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"httpStatusCode",
"=",
"$",
"e",
"->",
"getHttpException",
"(",
")",
"->",
"getCode",
"(",
")",
";",
"$",
"content",
"=",
"new",
"Eresus_CMS_Page_Content",
"(",
"$",
"this",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
"?",
":",
"Eresus_HTTP_Response",
"::",
"getStatusText",
"(",
"$",
"httpStatusCode",
")",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"createPageForContent",
"(",
"$",
"content",
",",
"$",
"httpStatusCode",
")",
";",
"}",
"// TODO: Обратная совместимость (убрать)",
"$",
"response",
"->",
"setContent",
"(",
"$",
"this",
"->",
"replaceMacros",
"(",
"$",
"response",
"->",
"getContent",
"(",
")",
")",
")",
";",
"$",
"event",
"=",
"new",
"Eresus_Event_Response",
"(",
"$",
"response",
")",
";",
"Eresus_Kernel",
"::",
"app",
"(",
")",
"->",
"getEventDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"'cms.client.response'",
",",
"$",
"event",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Отправляет созданную страницу пользователю.
@param Eresus_CMS_Request $request
@return Eresus_HTTP_Response | [
"Отправляет",
"созданную",
"страницу",
"пользователю",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/client.php#L378-L412 |
Eresus/EresusCMS | src/core/client.php | TClientUI.pages | public function pages($pagesCount, $itemsPerPage, $reverse = false)
{
$eresus = Eresus_CMS::getLegacyKernel();
if ($pagesCount>1)
{
$at_once = option('clientPagesAtOnce');
if (!$at_once)
{
$at_once = 10;
}
$side_left = '';
$side_right = '';
$for_from = $reverse ? $pagesCount : 1;
$default = $for_from;
$for_to = $reverse ? 0 : $pagesCount+1;
$for_delta = $reverse ? -1 : 1;
# Если количество страниц превышает AT_ONCE
if ($pagesCount > $at_once)
{
# Если установлен обратный порядок страниц
if ($reverse)
{
if ($this->subpage < ($pagesCount - (integer) ($at_once / 2)))
{
$for_from = ($this->subpage + (integer) ($at_once / 2));
}
if ($this->subpage < (integer) ($at_once / 2))
{
$for_from = $at_once;
}
$for_to = $for_from - $at_once;
if ($for_to < 0)
{
$for_from += abs($for_to);
$for_to = 0;
}
if ($for_from != $pagesCount)
{
$side_left = "<a href=\"".$eresus->request['path']."\" title=\"".strLastPage.
"\"> « </a>";
}
if ($for_to != 0)
{
$side_right = "<a href=\"".$eresus->request['path']."p1/\" title=\"".strFirstPage.
"\"> » </a>";
}
}
# Если установлен прямой порядок страниц
else
{
if ($this->subpage > (integer) ($at_once / 2))
{
$for_from = $this->subpage - (integer) ($at_once / 2);
}
if ($pagesCount - $this->subpage < (integer) ($at_once / 2) + (($at_once % 2)>0))
{
$for_from = $pagesCount - $at_once+1;
}
$for_to = $for_from + $at_once;
if ($for_from != 1)
{
$side_left = "<a href=\"".$eresus->request['path']."\" title=\"".strFirstPage.
"\"> « </a>";
}
if ($for_to < $pagesCount)
{
$side_right = "<a href=\"".$eresus->request['path']."p".$pagesCount."/\" title=\"".
strLastPage."\"> » </a>";
}
}
}
$result = '<div class="pages">'.strPages;
$result .= $side_left;
for ($i = $for_from; $i != $for_to; $i += $for_delta)
{
if ($i == $this->subpage)
{
$result .= '<span class="selected"> '.$i.' </span>';
}
else
{
$result .= '<a href="'.$eresus->request['path'].($i==$default?'':'p'.$i.'/').
'"> '.$i.' </a>';
}
}
$result .= $side_right;
$result .= "</div>\n";
return $result;
}
else
{
return '';
}
} | php | public function pages($pagesCount, $itemsPerPage, $reverse = false)
{
$eresus = Eresus_CMS::getLegacyKernel();
if ($pagesCount>1)
{
$at_once = option('clientPagesAtOnce');
if (!$at_once)
{
$at_once = 10;
}
$side_left = '';
$side_right = '';
$for_from = $reverse ? $pagesCount : 1;
$default = $for_from;
$for_to = $reverse ? 0 : $pagesCount+1;
$for_delta = $reverse ? -1 : 1;
# Если количество страниц превышает AT_ONCE
if ($pagesCount > $at_once)
{
# Если установлен обратный порядок страниц
if ($reverse)
{
if ($this->subpage < ($pagesCount - (integer) ($at_once / 2)))
{
$for_from = ($this->subpage + (integer) ($at_once / 2));
}
if ($this->subpage < (integer) ($at_once / 2))
{
$for_from = $at_once;
}
$for_to = $for_from - $at_once;
if ($for_to < 0)
{
$for_from += abs($for_to);
$for_to = 0;
}
if ($for_from != $pagesCount)
{
$side_left = "<a href=\"".$eresus->request['path']."\" title=\"".strLastPage.
"\"> « </a>";
}
if ($for_to != 0)
{
$side_right = "<a href=\"".$eresus->request['path']."p1/\" title=\"".strFirstPage.
"\"> » </a>";
}
}
# Если установлен прямой порядок страниц
else
{
if ($this->subpage > (integer) ($at_once / 2))
{
$for_from = $this->subpage - (integer) ($at_once / 2);
}
if ($pagesCount - $this->subpage < (integer) ($at_once / 2) + (($at_once % 2)>0))
{
$for_from = $pagesCount - $at_once+1;
}
$for_to = $for_from + $at_once;
if ($for_from != 1)
{
$side_left = "<a href=\"".$eresus->request['path']."\" title=\"".strFirstPage.
"\"> « </a>";
}
if ($for_to < $pagesCount)
{
$side_right = "<a href=\"".$eresus->request['path']."p".$pagesCount."/\" title=\"".
strLastPage."\"> » </a>";
}
}
}
$result = '<div class="pages">'.strPages;
$result .= $side_left;
for ($i = $for_from; $i != $for_to; $i += $for_delta)
{
if ($i == $this->subpage)
{
$result .= '<span class="selected"> '.$i.' </span>';
}
else
{
$result .= '<a href="'.$eresus->request['path'].($i==$default?'':'p'.$i.'/').
'"> '.$i.' </a>';
}
}
$result .= $side_right;
$result .= "</div>\n";
return $result;
}
else
{
return '';
}
} | [
"public",
"function",
"pages",
"(",
"$",
"pagesCount",
",",
"$",
"itemsPerPage",
",",
"$",
"reverse",
"=",
"false",
")",
"{",
"$",
"eresus",
"=",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
";",
"if",
"(",
"$",
"pagesCount",
">",
"1",
")",
"{",
"$",
"at_once",
"=",
"option",
"(",
"'clientPagesAtOnce'",
")",
";",
"if",
"(",
"!",
"$",
"at_once",
")",
"{",
"$",
"at_once",
"=",
"10",
";",
"}",
"$",
"side_left",
"=",
"''",
";",
"$",
"side_right",
"=",
"''",
";",
"$",
"for_from",
"=",
"$",
"reverse",
"?",
"$",
"pagesCount",
":",
"1",
";",
"$",
"default",
"=",
"$",
"for_from",
";",
"$",
"for_to",
"=",
"$",
"reverse",
"?",
"0",
":",
"$",
"pagesCount",
"+",
"1",
";",
"$",
"for_delta",
"=",
"$",
"reverse",
"?",
"-",
"1",
":",
"1",
";",
"# Если количество страниц превышает AT_ONCE",
"if",
"(",
"$",
"pagesCount",
">",
"$",
"at_once",
")",
"{",
"# Если установлен обратный порядок страниц",
"if",
"(",
"$",
"reverse",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"subpage",
"<",
"(",
"$",
"pagesCount",
"-",
"(",
"integer",
")",
"(",
"$",
"at_once",
"/",
"2",
")",
")",
")",
"{",
"$",
"for_from",
"=",
"(",
"$",
"this",
"->",
"subpage",
"+",
"(",
"integer",
")",
"(",
"$",
"at_once",
"/",
"2",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"subpage",
"<",
"(",
"integer",
")",
"(",
"$",
"at_once",
"/",
"2",
")",
")",
"{",
"$",
"for_from",
"=",
"$",
"at_once",
";",
"}",
"$",
"for_to",
"=",
"$",
"for_from",
"-",
"$",
"at_once",
";",
"if",
"(",
"$",
"for_to",
"<",
"0",
")",
"{",
"$",
"for_from",
"+=",
"abs",
"(",
"$",
"for_to",
")",
";",
"$",
"for_to",
"=",
"0",
";",
"}",
"if",
"(",
"$",
"for_from",
"!=",
"$",
"pagesCount",
")",
"{",
"$",
"side_left",
"=",
"\"<a href=\\\"\"",
".",
"$",
"eresus",
"->",
"request",
"[",
"'path'",
"]",
".",
"\"\\\" title=\\\"\"",
".",
"strLastPage",
".",
"\"\\\"> « </a>\"",
";",
"}",
"if",
"(",
"$",
"for_to",
"!=",
"0",
")",
"{",
"$",
"side_right",
"=",
"\"<a href=\\\"\"",
".",
"$",
"eresus",
"->",
"request",
"[",
"'path'",
"]",
".",
"\"p1/\\\" title=\\\"\"",
".",
"strFirstPage",
".",
"\"\\\"> » </a>\"",
";",
"}",
"}",
"# Если установлен прямой порядок страниц",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"subpage",
">",
"(",
"integer",
")",
"(",
"$",
"at_once",
"/",
"2",
")",
")",
"{",
"$",
"for_from",
"=",
"$",
"this",
"->",
"subpage",
"-",
"(",
"integer",
")",
"(",
"$",
"at_once",
"/",
"2",
")",
";",
"}",
"if",
"(",
"$",
"pagesCount",
"-",
"$",
"this",
"->",
"subpage",
"<",
"(",
"integer",
")",
"(",
"$",
"at_once",
"/",
"2",
")",
"+",
"(",
"(",
"$",
"at_once",
"%",
"2",
")",
">",
"0",
")",
")",
"{",
"$",
"for_from",
"=",
"$",
"pagesCount",
"-",
"$",
"at_once",
"+",
"1",
";",
"}",
"$",
"for_to",
"=",
"$",
"for_from",
"+",
"$",
"at_once",
";",
"if",
"(",
"$",
"for_from",
"!=",
"1",
")",
"{",
"$",
"side_left",
"=",
"\"<a href=\\\"\"",
".",
"$",
"eresus",
"->",
"request",
"[",
"'path'",
"]",
".",
"\"\\\" title=\\\"\"",
".",
"strFirstPage",
".",
"\"\\\"> « </a>\"",
";",
"}",
"if",
"(",
"$",
"for_to",
"<",
"$",
"pagesCount",
")",
"{",
"$",
"side_right",
"=",
"\"<a href=\\\"\"",
".",
"$",
"eresus",
"->",
"request",
"[",
"'path'",
"]",
".",
"\"p\"",
".",
"$",
"pagesCount",
".",
"\"/\\\" title=\\\"\"",
".",
"strLastPage",
".",
"\"\\\"> » </a>\"",
";",
"}",
"}",
"}",
"$",
"result",
"=",
"'<div class=\"pages\">'",
".",
"strPages",
";",
"$",
"result",
".=",
"$",
"side_left",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"for_from",
";",
"$",
"i",
"!=",
"$",
"for_to",
";",
"$",
"i",
"+=",
"$",
"for_delta",
")",
"{",
"if",
"(",
"$",
"i",
"==",
"$",
"this",
"->",
"subpage",
")",
"{",
"$",
"result",
".=",
"'<span class=\"selected\"> '",
".",
"$",
"i",
".",
"' </span>'",
";",
"}",
"else",
"{",
"$",
"result",
".=",
"'<a href=\"'",
".",
"$",
"eresus",
"->",
"request",
"[",
"'path'",
"]",
".",
"(",
"$",
"i",
"==",
"$",
"default",
"?",
"''",
":",
"'p'",
".",
"$",
"i",
".",
"'/'",
")",
".",
"'\"> '",
".",
"$",
"i",
".",
"' </a>'",
";",
"}",
"}",
"$",
"result",
".=",
"$",
"side_right",
";",
"$",
"result",
".=",
"\"</div>\\n\"",
";",
"return",
"$",
"result",
";",
"}",
"else",
"{",
"return",
"''",
";",
"}",
"}"
] | Выводит список подстраниц для навигации по ним
@param int $pagesCount
@param int $itemsPerPage
@param bool $reverse
@return string | [
"Выводит",
"список",
"подстраниц",
"для",
"навигации",
"по",
"ним"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/client.php#L423-L520 |
Eresus/EresusCMS | src/core/client.php | TClientUI.setTemplate | public function setTemplate($template, $type = '')
{
if (!is_string($template)
&& (!is_object($template) || !($template instanceof Eresus_Template)))
{
throw Eresus_Exception_InvalidArgumentType::factory(__METHOD__, 1,
'string or an instance of Eresus_Template', $template);
}
if (is_string($template))
{
$template = Templates::getInstance()->load($template, $type);
}
$this->template = $template;
} | php | public function setTemplate($template, $type = '')
{
if (!is_string($template)
&& (!is_object($template) || !($template instanceof Eresus_Template)))
{
throw Eresus_Exception_InvalidArgumentType::factory(__METHOD__, 1,
'string or an instance of Eresus_Template', $template);
}
if (is_string($template))
{
$template = Templates::getInstance()->load($template, $type);
}
$this->template = $template;
} | [
"public",
"function",
"setTemplate",
"(",
"$",
"template",
",",
"$",
"type",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"template",
")",
"&&",
"(",
"!",
"is_object",
"(",
"$",
"template",
")",
"||",
"!",
"(",
"$",
"template",
"instanceof",
"Eresus_Template",
")",
")",
")",
"{",
"throw",
"Eresus_Exception_InvalidArgumentType",
"::",
"factory",
"(",
"__METHOD__",
",",
"1",
",",
"'string or an instance of Eresus_Template'",
",",
"$",
"template",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"template",
")",
")",
"{",
"$",
"template",
"=",
"Templates",
"::",
"getInstance",
"(",
")",
"->",
"load",
"(",
"$",
"template",
",",
"$",
"type",
")",
";",
"}",
"$",
"this",
"->",
"template",
"=",
"$",
"template",
";",
"}"
] | Задаёт шаблон страницы
<b>Обратите внимание!</b> Этот метод не влияет на результат, возвращаемый
{@link getTemplateName()}.
@param string|Eresus_Template $template имя файла шаблона или уже созданный объект шаблона
@param string $type тип шаблона, только если $template — строка
@throws Eresus_Exception_InvalidArgumentType
@since 3.01 | [
"Задаёт",
"шаблон",
"страницы"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/client.php#L550-L563 |
Eresus/EresusCMS | src/core/client.php | TClientUI.createPageForContent | private function createPageForContent(Eresus_CMS_Page_Content $content, $statusCode = 200)
{
Eresus_Kernel::log(__METHOD__, LOG_DEBUG, '(%s, %d)', $content, $statusCode);
$legacyKernel = Eresus_Kernel::app()->getLegacyKernel();
$html = $content->render();
if (
isset($legacyKernel->session['msg']['information']) &&
count($legacyKernel->session['msg']['information'])
)
{
$messages = '';
foreach ($legacyKernel->session['msg']['information'] as $message)
{
$messages .= InfoBox($message);
}
$html = $messages . $html;
$legacyKernel->session['msg']['information'] = array();
}
if (
isset($legacyKernel->session['msg']['errors']) &&
count($legacyKernel->session['msg']['errors'])
)
{
$messages = '';
foreach ($legacyKernel->session['msg']['errors'] as $message)
{
$messages .= ErrorBox($message);
}
$html = $messages . $html;
$legacyKernel->session['msg']['errors'] = array();
}
$this->content = $html;
$html = $this->template->compile();
// TODO: Обратная совместимость (удалить)
if (!empty($this->styles))
{
$this->addStyles($this->styles);
}
$event = new Eresus_Event_Render($html);
Eresus_Kernel::app()->getEventDispatcher()
->dispatch('cms.client.render_page', $event);
$html = $event->getText();
// TODO: Обратная совместимость (удалить)
if (!empty($this->scripts))
{
$this->addScripts($this->scripts);
}
$html = preg_replace('|(.*)</head>|i', '$1' . $this->renderHeadSection() . "\n</head>",
$html);
$response = new Eresus_HTTP_Response($html, $statusCode, $this->headers);
return $response;
} | php | private function createPageForContent(Eresus_CMS_Page_Content $content, $statusCode = 200)
{
Eresus_Kernel::log(__METHOD__, LOG_DEBUG, '(%s, %d)', $content, $statusCode);
$legacyKernel = Eresus_Kernel::app()->getLegacyKernel();
$html = $content->render();
if (
isset($legacyKernel->session['msg']['information']) &&
count($legacyKernel->session['msg']['information'])
)
{
$messages = '';
foreach ($legacyKernel->session['msg']['information'] as $message)
{
$messages .= InfoBox($message);
}
$html = $messages . $html;
$legacyKernel->session['msg']['information'] = array();
}
if (
isset($legacyKernel->session['msg']['errors']) &&
count($legacyKernel->session['msg']['errors'])
)
{
$messages = '';
foreach ($legacyKernel->session['msg']['errors'] as $message)
{
$messages .= ErrorBox($message);
}
$html = $messages . $html;
$legacyKernel->session['msg']['errors'] = array();
}
$this->content = $html;
$html = $this->template->compile();
// TODO: Обратная совместимость (удалить)
if (!empty($this->styles))
{
$this->addStyles($this->styles);
}
$event = new Eresus_Event_Render($html);
Eresus_Kernel::app()->getEventDispatcher()
->dispatch('cms.client.render_page', $event);
$html = $event->getText();
// TODO: Обратная совместимость (удалить)
if (!empty($this->scripts))
{
$this->addScripts($this->scripts);
}
$html = preg_replace('|(.*)</head>|i', '$1' . $this->renderHeadSection() . "\n</head>",
$html);
$response = new Eresus_HTTP_Response($html, $statusCode, $this->headers);
return $response;
} | [
"private",
"function",
"createPageForContent",
"(",
"Eresus_CMS_Page_Content",
"$",
"content",
",",
"$",
"statusCode",
"=",
"200",
")",
"{",
"Eresus_Kernel",
"::",
"log",
"(",
"__METHOD__",
",",
"LOG_DEBUG",
",",
"'(%s, %d)'",
",",
"$",
"content",
",",
"$",
"statusCode",
")",
";",
"$",
"legacyKernel",
"=",
"Eresus_Kernel",
"::",
"app",
"(",
")",
"->",
"getLegacyKernel",
"(",
")",
";",
"$",
"html",
"=",
"$",
"content",
"->",
"render",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"legacyKernel",
"->",
"session",
"[",
"'msg'",
"]",
"[",
"'information'",
"]",
")",
"&&",
"count",
"(",
"$",
"legacyKernel",
"->",
"session",
"[",
"'msg'",
"]",
"[",
"'information'",
"]",
")",
")",
"{",
"$",
"messages",
"=",
"''",
";",
"foreach",
"(",
"$",
"legacyKernel",
"->",
"session",
"[",
"'msg'",
"]",
"[",
"'information'",
"]",
"as",
"$",
"message",
")",
"{",
"$",
"messages",
".=",
"InfoBox",
"(",
"$",
"message",
")",
";",
"}",
"$",
"html",
"=",
"$",
"messages",
".",
"$",
"html",
";",
"$",
"legacyKernel",
"->",
"session",
"[",
"'msg'",
"]",
"[",
"'information'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"legacyKernel",
"->",
"session",
"[",
"'msg'",
"]",
"[",
"'errors'",
"]",
")",
"&&",
"count",
"(",
"$",
"legacyKernel",
"->",
"session",
"[",
"'msg'",
"]",
"[",
"'errors'",
"]",
")",
")",
"{",
"$",
"messages",
"=",
"''",
";",
"foreach",
"(",
"$",
"legacyKernel",
"->",
"session",
"[",
"'msg'",
"]",
"[",
"'errors'",
"]",
"as",
"$",
"message",
")",
"{",
"$",
"messages",
".=",
"ErrorBox",
"(",
"$",
"message",
")",
";",
"}",
"$",
"html",
"=",
"$",
"messages",
".",
"$",
"html",
";",
"$",
"legacyKernel",
"->",
"session",
"[",
"'msg'",
"]",
"[",
"'errors'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"content",
"=",
"$",
"html",
";",
"$",
"html",
"=",
"$",
"this",
"->",
"template",
"->",
"compile",
"(",
")",
";",
"// TODO: Обратная совместимость (удалить)",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"styles",
")",
")",
"{",
"$",
"this",
"->",
"addStyles",
"(",
"$",
"this",
"->",
"styles",
")",
";",
"}",
"$",
"event",
"=",
"new",
"Eresus_Event_Render",
"(",
"$",
"html",
")",
";",
"Eresus_Kernel",
"::",
"app",
"(",
")",
"->",
"getEventDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"'cms.client.render_page'",
",",
"$",
"event",
")",
";",
"$",
"html",
"=",
"$",
"event",
"->",
"getText",
"(",
")",
";",
"// TODO: Обратная совместимость (удалить)",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"scripts",
")",
")",
"{",
"$",
"this",
"->",
"addScripts",
"(",
"$",
"this",
"->",
"scripts",
")",
";",
"}",
"$",
"html",
"=",
"preg_replace",
"(",
"'|(.*)</head>|i'",
",",
"'$1'",
".",
"$",
"this",
"->",
"renderHeadSection",
"(",
")",
".",
"\"\\n</head>\"",
",",
"$",
"html",
")",
";",
"$",
"response",
"=",
"new",
"Eresus_HTTP_Response",
"(",
"$",
"html",
",",
"$",
"statusCode",
",",
"$",
"this",
"->",
"headers",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Создаёт страницу для переданного контента
@param Eresus_CMS_Page_Content $content
@param int $statusCode
@return Eresus_HTTP_Response
@since 3.01 | [
"Создаёт",
"страницу",
"для",
"переданного",
"контента"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/client.php#L575-L633 |
trunda/SmfMenu | src/Smf/Menu/Matcher/Voter/PresenterVoter.php | PresenterVoter.matchItem | public function matchItem(ItemInterface $item)
{
if ($item->getExtra('link', false) && $this->parentControl) {
$presenter = $this->parentControl->getPresenter(true);
$item->setCurrent(call_user_func_array(array($presenter, 'isLinkCurrent'), $item->getExtra('link')));
return $item->isCurrent();
}
return null;
} | php | public function matchItem(ItemInterface $item)
{
if ($item->getExtra('link', false) && $this->parentControl) {
$presenter = $this->parentControl->getPresenter(true);
$item->setCurrent(call_user_func_array(array($presenter, 'isLinkCurrent'), $item->getExtra('link')));
return $item->isCurrent();
}
return null;
} | [
"public",
"function",
"matchItem",
"(",
"ItemInterface",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"->",
"getExtra",
"(",
"'link'",
",",
"false",
")",
"&&",
"$",
"this",
"->",
"parentControl",
")",
"{",
"$",
"presenter",
"=",
"$",
"this",
"->",
"parentControl",
"->",
"getPresenter",
"(",
"true",
")",
";",
"$",
"item",
"->",
"setCurrent",
"(",
"call_user_func_array",
"(",
"array",
"(",
"$",
"presenter",
",",
"'isLinkCurrent'",
")",
",",
"$",
"item",
"->",
"getExtra",
"(",
"'link'",
")",
")",
")",
";",
"return",
"$",
"item",
"->",
"isCurrent",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Checks whether an item is current.
If the voter is not able to determine a result,
it should return null to let other voters do the job.
@param ItemInterface $item
@return boolean|null | [
"Checks",
"whether",
"an",
"item",
"is",
"current",
"."
] | train | https://github.com/trunda/SmfMenu/blob/739e74fb664c1f018b4a74142bd28d20c004bac6/src/Smf/Menu/Matcher/Voter/PresenterVoter.php#L41-L49 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Cache/src/manager.php | ezcCacheManager.createCache | public static function createCache( $id, $location = null, $storageClass, $options = array() )
{
// BC for missing location. The location should not be missing.
if ( $location !== null )
{
// Unifiy file system locations
if ( substr( $location, 0, 1 ) === '/' )
{
// If non-existent
if ( ( $realLocation = realpath( $location ) ) === false )
{
throw new ezcBaseFileNotFoundException(
$location,
'cache location',
'Does not exist or is no directory.'
);
}
$location = $realLocation;
}
// Sanity check double taken locations.
foreach ( self::$configurations as $confId => $config )
{
if ( $config['location'] === $location )
{
throw new ezcCacheUsedLocationException( $location, $confId );
}
}
}
// Sanity check storage class.
if ( !ezcBaseFeatures::classExists( $storageClass ) || !is_subclass_of( $storageClass, 'ezcCacheStorage' ) )
{
throw new ezcCacheInvalidStorageClassException( $storageClass );
}
self::$configurations[$id] = array(
'location' => $location,
'class' => $storageClass,
'options' => $options,
);
} | php | public static function createCache( $id, $location = null, $storageClass, $options = array() )
{
// BC for missing location. The location should not be missing.
if ( $location !== null )
{
// Unifiy file system locations
if ( substr( $location, 0, 1 ) === '/' )
{
// If non-existent
if ( ( $realLocation = realpath( $location ) ) === false )
{
throw new ezcBaseFileNotFoundException(
$location,
'cache location',
'Does not exist or is no directory.'
);
}
$location = $realLocation;
}
// Sanity check double taken locations.
foreach ( self::$configurations as $confId => $config )
{
if ( $config['location'] === $location )
{
throw new ezcCacheUsedLocationException( $location, $confId );
}
}
}
// Sanity check storage class.
if ( !ezcBaseFeatures::classExists( $storageClass ) || !is_subclass_of( $storageClass, 'ezcCacheStorage' ) )
{
throw new ezcCacheInvalidStorageClassException( $storageClass );
}
self::$configurations[$id] = array(
'location' => $location,
'class' => $storageClass,
'options' => $options,
);
} | [
"public",
"static",
"function",
"createCache",
"(",
"$",
"id",
",",
"$",
"location",
"=",
"null",
",",
"$",
"storageClass",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"// BC for missing location. The location should not be missing.",
"if",
"(",
"$",
"location",
"!==",
"null",
")",
"{",
"// Unifiy file system locations",
"if",
"(",
"substr",
"(",
"$",
"location",
",",
"0",
",",
"1",
")",
"===",
"'/'",
")",
"{",
"// If non-existent",
"if",
"(",
"(",
"$",
"realLocation",
"=",
"realpath",
"(",
"$",
"location",
")",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"ezcBaseFileNotFoundException",
"(",
"$",
"location",
",",
"'cache location'",
",",
"'Does not exist or is no directory.'",
")",
";",
"}",
"$",
"location",
"=",
"$",
"realLocation",
";",
"}",
"// Sanity check double taken locations.",
"foreach",
"(",
"self",
"::",
"$",
"configurations",
"as",
"$",
"confId",
"=>",
"$",
"config",
")",
"{",
"if",
"(",
"$",
"config",
"[",
"'location'",
"]",
"===",
"$",
"location",
")",
"{",
"throw",
"new",
"ezcCacheUsedLocationException",
"(",
"$",
"location",
",",
"$",
"confId",
")",
";",
"}",
"}",
"}",
"// Sanity check storage class.",
"if",
"(",
"!",
"ezcBaseFeatures",
"::",
"classExists",
"(",
"$",
"storageClass",
")",
"||",
"!",
"is_subclass_of",
"(",
"$",
"storageClass",
",",
"'ezcCacheStorage'",
")",
")",
"{",
"throw",
"new",
"ezcCacheInvalidStorageClassException",
"(",
"$",
"storageClass",
")",
";",
"}",
"self",
"::",
"$",
"configurations",
"[",
"$",
"id",
"]",
"=",
"array",
"(",
"'location'",
"=>",
"$",
"location",
",",
"'class'",
"=>",
"$",
"storageClass",
",",
"'options'",
"=>",
"$",
"options",
",",
")",
";",
"}"
] | Creates a new cache in the manager.
This method is used to create a new cache inside the manager.
Each cache has a unique ID to access it during the application
runtime. Each location may only be used by 1 cache.
The $storageClass parameter must be a subclass of
{@link ezcCacheStorage} and tells the manager which object
will be used for the cache.
The $location parameter depends on the kind of {@link ezcCacheStorage}
used for the cache you create. Usually this is a directory on your
file system, but may also be e.g. a data source name, if you cache in
a database or similar. For memory-based storage ({@link ezcCacheStorageApcPlain}
or {@link ezcCacheStorageMemcachePlain}) it is null, but for
memory/file hybrid storage ({@link ezcCacheStorageFileApcArray}) it should
be an existing writeable path.
The $options array consists of several standard attributes and can
additionally contain options defined by the {@link ezcCacheStorage}
class. Standard options are:
<code>
array(
'ttl' => 60*60*24, // Time-to-life, default: 1 day
);
</code>
@param string $id ID of the cache to create.
@param string $location Location to create the cache in. Null for
memory-based storage and an existing
writeable path for file or memory/file
storage.
@param string $storageClass Subclass of {@link ezcCacheStorage}.
@param array(string=>string) $options Options for the cache.
@return void
@throws ezcBaseFileNotFoundException
If the given location does not exist or is not a
directory (thrown by sanity checks performed when storing the
configuration of a cache to ensure the latter calls to
{@link ezcCacheManager::getCache()} do not fail).
@throws ezcBaseFilePermissionException
If the given location is not read/writeable (thrown by sanity
checks performed when storing the configuration of a cache to
ensure the latter calls to {@link ezcCacheManager::getCache()}
do not fail).
@throws ezcCacheUsedLocationException
If the given location is already in use by another cache.
@throws ezcCacheInvalidStorageClassException
If the given storage class does not exist or is no subclass of
ezcCacheStorage. | [
"Creates",
"a",
"new",
"cache",
"in",
"the",
"manager",
".",
"This",
"method",
"is",
"used",
"to",
"create",
"a",
"new",
"cache",
"inside",
"the",
"manager",
".",
"Each",
"cache",
"has",
"a",
"unique",
"ID",
"to",
"access",
"it",
"during",
"the",
"application",
"runtime",
".",
"Each",
"location",
"may",
"only",
"be",
"used",
"by",
"1",
"cache",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Cache/src/manager.php#L196-L236 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Cache/src/manager.php | ezcCacheManager.getCache | public static function getCache( $id )
{
// Look for already existing cache object
if ( !isset( self::$caches[$id] ) )
{
// Failed, look for configuration, and if it does not exist, use
// delayed initialization.
if ( !isset( self::$configurations[$id] ) )
{
ezcBaseInit::fetchConfig( 'ezcInitCacheManager', $id );
}
// Check whether delayed initialization actually worked, if not,
// throw an exception
if ( !isset( self::$configurations[$id] ) )
{
throw new ezcCacheInvalidIdException( $id );
}
$class = self::$configurations[$id]['class'];
self::$caches[$id] = new $class( self::$configurations[$id]['location'], self::$configurations[$id]['options'] );
}
return self::$caches[$id];
} | php | public static function getCache( $id )
{
// Look for already existing cache object
if ( !isset( self::$caches[$id] ) )
{
// Failed, look for configuration, and if it does not exist, use
// delayed initialization.
if ( !isset( self::$configurations[$id] ) )
{
ezcBaseInit::fetchConfig( 'ezcInitCacheManager', $id );
}
// Check whether delayed initialization actually worked, if not,
// throw an exception
if ( !isset( self::$configurations[$id] ) )
{
throw new ezcCacheInvalidIdException( $id );
}
$class = self::$configurations[$id]['class'];
self::$caches[$id] = new $class( self::$configurations[$id]['location'], self::$configurations[$id]['options'] );
}
return self::$caches[$id];
} | [
"public",
"static",
"function",
"getCache",
"(",
"$",
"id",
")",
"{",
"// Look for already existing cache object",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"caches",
"[",
"$",
"id",
"]",
")",
")",
"{",
"// Failed, look for configuration, and if it does not exist, use",
"// delayed initialization.",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"configurations",
"[",
"$",
"id",
"]",
")",
")",
"{",
"ezcBaseInit",
"::",
"fetchConfig",
"(",
"'ezcInitCacheManager'",
",",
"$",
"id",
")",
";",
"}",
"// Check whether delayed initialization actually worked, if not,",
"// throw an exception",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"configurations",
"[",
"$",
"id",
"]",
")",
")",
"{",
"throw",
"new",
"ezcCacheInvalidIdException",
"(",
"$",
"id",
")",
";",
"}",
"$",
"class",
"=",
"self",
"::",
"$",
"configurations",
"[",
"$",
"id",
"]",
"[",
"'class'",
"]",
";",
"self",
"::",
"$",
"caches",
"[",
"$",
"id",
"]",
"=",
"new",
"$",
"class",
"(",
"self",
"::",
"$",
"configurations",
"[",
"$",
"id",
"]",
"[",
"'location'",
"]",
",",
"self",
"::",
"$",
"configurations",
"[",
"$",
"id",
"]",
"[",
"'options'",
"]",
")",
";",
"}",
"return",
"self",
"::",
"$",
"caches",
"[",
"$",
"id",
"]",
";",
"}"
] | Returns the ezcCacheStorage object with the given ID.
The cache ID has to be defined before using the
{@link ezcCacheManager::createCache()} method. If no instance of this
cache does exist yet, it's created on the fly. If one exists, it will
be reused.
@param string $id The ID of the cache to return.
@return ezcCacheStorage The cache with the given ID.
@throws ezcCacheInvalidIdException
If the ID of a cache you try to access does not exist. To access
a cache using this method, it first hast to be created using
{@link ezcCacheManager::createCache()}.
@throws ezcBaseFileNotFoundException
If the storage location does not exist. This should usually not
happen, since {@link ezcCacheManager::createCache()} already
performs sanity checks for the cache location. In case this
exception is thrown, your cache location has been corrupted
after the cache was configured.
@throws ezcBaseFileNotFoundException
If the storage location is not a directory. This should usually
not happen, since {@link ezcCacheManager::createCache()} already
performs sanity checks for the cache location. In case this
exception is thrown, your cache location has been corrupted
after the cache was configured.
@throws ezcBaseFilePermissionException
If the storage location is not writeable. This should usually not
happen, since {@link ezcCacheManager::createCache()} already
performs sanity checks for the cache location. In case this
exception is thrown, your cache location has been corrupted
after the cache was configured.
@throws ezcBasePropertyNotFoundException
If you tried to set a non-existent option value. The accepted
options depend on the ezcCacheStorage implementation and may
vary. | [
"Returns",
"the",
"ezcCacheStorage",
"object",
"with",
"the",
"given",
"ID",
".",
"The",
"cache",
"ID",
"has",
"to",
"be",
"defined",
"before",
"using",
"the",
"{",
"@link",
"ezcCacheManager",
"::",
"createCache",
"()",
"}",
"method",
".",
"If",
"no",
"instance",
"of",
"this",
"cache",
"does",
"exist",
"yet",
"it",
"s",
"created",
"on",
"the",
"fly",
".",
"If",
"one",
"exists",
"it",
"will",
"be",
"reused",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Cache/src/manager.php#L275-L296 |
WellCommerce/AppBundle | Form/Admin/UserGroupFormBuilder.php | UserGroupFormBuilder.getPermissionActions | private function getPermissionActions()
{
$actions = [];
/**
* @var $route \Symfony\Component\Routing\Route
*/
foreach ($this->get('router')->getRouteCollection()->all() as $name => $route) {
if ($route->hasOption('require_admin_permission')) {
list(, $action) = explode('.', $route->getOption('require_admin_permission'));
$actions[$action] = [
'id' => $action,
'name' => $action
];
}
}
ksort($actions);
return array_values($actions);
} | php | private function getPermissionActions()
{
$actions = [];
/**
* @var $route \Symfony\Component\Routing\Route
*/
foreach ($this->get('router')->getRouteCollection()->all() as $name => $route) {
if ($route->hasOption('require_admin_permission')) {
list(, $action) = explode('.', $route->getOption('require_admin_permission'));
$actions[$action] = [
'id' => $action,
'name' => $action
];
}
}
ksort($actions);
return array_values($actions);
} | [
"private",
"function",
"getPermissionActions",
"(",
")",
"{",
"$",
"actions",
"=",
"[",
"]",
";",
"/**\n * @var $route \\Symfony\\Component\\Routing\\Route\n */",
"foreach",
"(",
"$",
"this",
"->",
"get",
"(",
"'router'",
")",
"->",
"getRouteCollection",
"(",
")",
"->",
"all",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"route",
")",
"{",
"if",
"(",
"$",
"route",
"->",
"hasOption",
"(",
"'require_admin_permission'",
")",
")",
"{",
"list",
"(",
",",
"$",
"action",
")",
"=",
"explode",
"(",
"'.'",
",",
"$",
"route",
"->",
"getOption",
"(",
"'require_admin_permission'",
")",
")",
";",
"$",
"actions",
"[",
"$",
"action",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"action",
",",
"'name'",
"=>",
"$",
"action",
"]",
";",
"}",
"}",
"ksort",
"(",
"$",
"actions",
")",
";",
"return",
"array_values",
"(",
"$",
"actions",
")",
";",
"}"
] | Returns all routes which have require_permission option enabled
@return array | [
"Returns",
"all",
"routes",
"which",
"have",
"require_permission",
"option",
"enabled"
] | train | https://github.com/WellCommerce/AppBundle/blob/2add687d1c898dd0b24afd611d896e3811a0eac3/Form/Admin/UserGroupFormBuilder.php#L62-L82 |
WellCommerce/AppBundle | Form/Admin/UserGroupFormBuilder.php | UserGroupFormBuilder.getPermissionTypes | private function getPermissionTypes()
{
$types = [];
/**
* @var $route \Symfony\Component\Routing\Route
*/
foreach ($this->get('router')->getRouteCollection()->all() as $name => $route) {
if ($route->hasOption('require_admin_permission')) {
list($permissionType,) = explode('.', $route->getOption('require_admin_permission'));
$types[$permissionType] = [
'id' => $permissionType,
'name' => $permissionType
];
}
}
ksort($types);
return array_values($types);
} | php | private function getPermissionTypes()
{
$types = [];
/**
* @var $route \Symfony\Component\Routing\Route
*/
foreach ($this->get('router')->getRouteCollection()->all() as $name => $route) {
if ($route->hasOption('require_admin_permission')) {
list($permissionType,) = explode('.', $route->getOption('require_admin_permission'));
$types[$permissionType] = [
'id' => $permissionType,
'name' => $permissionType
];
}
}
ksort($types);
return array_values($types);
} | [
"private",
"function",
"getPermissionTypes",
"(",
")",
"{",
"$",
"types",
"=",
"[",
"]",
";",
"/**\n * @var $route \\Symfony\\Component\\Routing\\Route\n */",
"foreach",
"(",
"$",
"this",
"->",
"get",
"(",
"'router'",
")",
"->",
"getRouteCollection",
"(",
")",
"->",
"all",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"route",
")",
"{",
"if",
"(",
"$",
"route",
"->",
"hasOption",
"(",
"'require_admin_permission'",
")",
")",
"{",
"list",
"(",
"$",
"permissionType",
",",
")",
"=",
"explode",
"(",
"'.'",
",",
"$",
"route",
"->",
"getOption",
"(",
"'require_admin_permission'",
")",
")",
";",
"$",
"types",
"[",
"$",
"permissionType",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"permissionType",
",",
"'name'",
"=>",
"$",
"permissionType",
"]",
";",
"}",
"}",
"ksort",
"(",
"$",
"types",
")",
";",
"return",
"array_values",
"(",
"$",
"types",
")",
";",
"}"
] | Returns all routes which have require_permission option enabled
@return array | [
"Returns",
"all",
"routes",
"which",
"have",
"require_permission",
"option",
"enabled"
] | train | https://github.com/WellCommerce/AppBundle/blob/2add687d1c898dd0b24afd611d896e3811a0eac3/Form/Admin/UserGroupFormBuilder.php#L89-L109 |
ShaoZeMing/laravel-merchant | src/Form/Builder.php | Builder.option | public function option($option, $value = null)
{
if (func_num_args() == 1) {
return array_get($this->options, $option);
}
$this->options[$option] = $value;
return $this;
} | php | public function option($option, $value = null)
{
if (func_num_args() == 1) {
return array_get($this->options, $option);
}
$this->options[$option] = $value;
return $this;
} | [
"public",
"function",
"option",
"(",
"$",
"option",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"func_num_args",
"(",
")",
"==",
"1",
")",
"{",
"return",
"array_get",
"(",
"$",
"this",
"->",
"options",
",",
"$",
"option",
")",
";",
"}",
"$",
"this",
"->",
"options",
"[",
"$",
"option",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Get or set option.
@param string $option
@param mixed $value
@return $this | [
"Get",
"or",
"set",
"option",
"."
] | train | https://github.com/ShaoZeMing/laravel-merchant/blob/20801b1735e7832a6e58b37c2c391328f8d626fa/src/Form/Builder.php#L319-L328 |
ShaoZeMing/laravel-merchant | src/Form/Builder.php | Builder.addRedirectUrlField | protected function addRedirectUrlField()
{
$previous = URL::previous();
if (!$previous || $previous == URL::current()) {
return;
}
if (Str::contains($previous, url($this->getResource()))) {
$this->addHiddenField((new Form\Field\Hidden(static::PREVIOUS_URL_KEY))->value($previous));
}
} | php | protected function addRedirectUrlField()
{
$previous = URL::previous();
if (!$previous || $previous == URL::current()) {
return;
}
if (Str::contains($previous, url($this->getResource()))) {
$this->addHiddenField((new Form\Field\Hidden(static::PREVIOUS_URL_KEY))->value($previous));
}
} | [
"protected",
"function",
"addRedirectUrlField",
"(",
")",
"{",
"$",
"previous",
"=",
"URL",
"::",
"previous",
"(",
")",
";",
"if",
"(",
"!",
"$",
"previous",
"||",
"$",
"previous",
"==",
"URL",
"::",
"current",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"Str",
"::",
"contains",
"(",
"$",
"previous",
",",
"url",
"(",
"$",
"this",
"->",
"getResource",
"(",
")",
")",
")",
")",
"{",
"$",
"this",
"->",
"addHiddenField",
"(",
"(",
"new",
"Form",
"\\",
"Field",
"\\",
"Hidden",
"(",
"static",
"::",
"PREVIOUS_URL_KEY",
")",
")",
"->",
"value",
"(",
"$",
"previous",
")",
")",
";",
"}",
"}"
] | Add field for store redirect url after update or store.
@return void | [
"Add",
"field",
"for",
"store",
"redirect",
"url",
"after",
"update",
"or",
"store",
"."
] | train | https://github.com/ShaoZeMing/laravel-merchant/blob/20801b1735e7832a6e58b37c2c391328f8d626fa/src/Form/Builder.php#L371-L382 |
zicht/z | src/Zicht/Tool/Configuration/FileLoader.php | FileLoader.parseAnnotations | public function parseAnnotations($fileContents)
{
$ret = array();
if (preg_match('/^#\s*@(\w+)[:=]?\s+([\'"])?(.*)\2\s*$/m', $fileContents, $m)) {
$ret[$m[1]] = $m[3];
}
return $ret;
} | php | public function parseAnnotations($fileContents)
{
$ret = array();
if (preg_match('/^#\s*@(\w+)[:=]?\s+([\'"])?(.*)\2\s*$/m', $fileContents, $m)) {
$ret[$m[1]] = $m[3];
}
return $ret;
} | [
"public",
"function",
"parseAnnotations",
"(",
"$",
"fileContents",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/^#\\s*@(\\w+)[:=]?\\s+([\\'\"])?(.*)\\2\\s*$/m'",
",",
"$",
"fileContents",
",",
"$",
"m",
")",
")",
"{",
"$",
"ret",
"[",
"$",
"m",
"[",
"1",
"]",
"]",
"=",
"$",
"m",
"[",
"3",
"]",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Parse the annotations contained in commented lines, starting with #
Annotation format is '@' followed by a word, followed by an optional ':' or '=', followed by a quoted value,
e.g.
<code>@foo="bar"</code>
@param string $fileContents
@return array | [
"Parse",
"the",
"annotations",
"contained",
"in",
"commented",
"lines",
"starting",
"with",
"#"
] | train | https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Configuration/FileLoader.php#L165-L172 |
zicht/z | src/Zicht/Tool/Configuration/FileLoader.php | FileLoader.processPlugins | protected function processPlugins($plugins, $dir)
{
foreach ($plugins as $plugin) {
$this->addPlugin($plugin, $dir);
}
} | php | protected function processPlugins($plugins, $dir)
{
foreach ($plugins as $plugin) {
$this->addPlugin($plugin, $dir);
}
} | [
"protected",
"function",
"processPlugins",
"(",
"$",
"plugins",
",",
"$",
"dir",
")",
"{",
"foreach",
"(",
"$",
"plugins",
"as",
"$",
"plugin",
")",
"{",
"$",
"this",
"->",
"addPlugin",
"(",
"$",
"plugin",
",",
"$",
"dir",
")",
";",
"}",
"}"
] | Processes plugin definitions
@param array $plugins
@param string $dir
@return void | [
"Processes",
"plugin",
"definitions"
] | train | https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Configuration/FileLoader.php#L191-L196 |
zicht/z | src/Zicht/Tool/Configuration/FileLoader.php | FileLoader.addPlugin | public function addPlugin($name, $dir)
{
Debug::enterScope($name);
$hasPlugin = $hasZfile = false;
try {
$this->plugins[$name] = $this->getLocator()->locate($name . '/Plugin.php', $dir, true);
$this->pluginPaths[$name] = dirname($this->plugins[$name]);
$hasPlugin = true;
$this->sourceFiles[] = $this->plugins[$name];
} catch (\InvalidArgumentException $e) {
}
try {
$zFileLocation = $this->getLocator()->locate($name . '/z.yml', $dir);
$this->import($zFileLocation, self::PLUGIN);
if (!isset($this->pluginPaths[$name])) {
$this->pluginPaths[$name] = dirname($zFileLocation);
} else if ($this->pluginPaths[$name] != dirname($zFileLocation)) {
throw new \UnexpectedValueException(
"Ambiguous plugin configuration:\n"
. "There was a Plugin.php found in {$this->pluginPaths[$name]}, but also a z.yml at $zFileLocation"
);
}
$hasZfile = true;
$this->sourceFiles[] = $zFileLocation;
} catch (\InvalidArgumentException $e) {
}
if (!$hasPlugin && !$hasZfile) {
throw new \InvalidArgumentException("You need at least either a z.yml or a Plugin.php in the plugin path for '{$name}'");
}
Debug::exitScope($name);
} | php | public function addPlugin($name, $dir)
{
Debug::enterScope($name);
$hasPlugin = $hasZfile = false;
try {
$this->plugins[$name] = $this->getLocator()->locate($name . '/Plugin.php', $dir, true);
$this->pluginPaths[$name] = dirname($this->plugins[$name]);
$hasPlugin = true;
$this->sourceFiles[] = $this->plugins[$name];
} catch (\InvalidArgumentException $e) {
}
try {
$zFileLocation = $this->getLocator()->locate($name . '/z.yml', $dir);
$this->import($zFileLocation, self::PLUGIN);
if (!isset($this->pluginPaths[$name])) {
$this->pluginPaths[$name] = dirname($zFileLocation);
} else if ($this->pluginPaths[$name] != dirname($zFileLocation)) {
throw new \UnexpectedValueException(
"Ambiguous plugin configuration:\n"
. "There was a Plugin.php found in {$this->pluginPaths[$name]}, but also a z.yml at $zFileLocation"
);
}
$hasZfile = true;
$this->sourceFiles[] = $zFileLocation;
} catch (\InvalidArgumentException $e) {
}
if (!$hasPlugin && !$hasZfile) {
throw new \InvalidArgumentException("You need at least either a z.yml or a Plugin.php in the plugin path for '{$name}'");
}
Debug::exitScope($name);
} | [
"public",
"function",
"addPlugin",
"(",
"$",
"name",
",",
"$",
"dir",
")",
"{",
"Debug",
"::",
"enterScope",
"(",
"$",
"name",
")",
";",
"$",
"hasPlugin",
"=",
"$",
"hasZfile",
"=",
"false",
";",
"try",
"{",
"$",
"this",
"->",
"plugins",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"getLocator",
"(",
")",
"->",
"locate",
"(",
"$",
"name",
".",
"'/Plugin.php'",
",",
"$",
"dir",
",",
"true",
")",
";",
"$",
"this",
"->",
"pluginPaths",
"[",
"$",
"name",
"]",
"=",
"dirname",
"(",
"$",
"this",
"->",
"plugins",
"[",
"$",
"name",
"]",
")",
";",
"$",
"hasPlugin",
"=",
"true",
";",
"$",
"this",
"->",
"sourceFiles",
"[",
"]",
"=",
"$",
"this",
"->",
"plugins",
"[",
"$",
"name",
"]",
";",
"}",
"catch",
"(",
"\\",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"}",
"try",
"{",
"$",
"zFileLocation",
"=",
"$",
"this",
"->",
"getLocator",
"(",
")",
"->",
"locate",
"(",
"$",
"name",
".",
"'/z.yml'",
",",
"$",
"dir",
")",
";",
"$",
"this",
"->",
"import",
"(",
"$",
"zFileLocation",
",",
"self",
"::",
"PLUGIN",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"pluginPaths",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"pluginPaths",
"[",
"$",
"name",
"]",
"=",
"dirname",
"(",
"$",
"zFileLocation",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"pluginPaths",
"[",
"$",
"name",
"]",
"!=",
"dirname",
"(",
"$",
"zFileLocation",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"\"Ambiguous plugin configuration:\\n\"",
".",
"\"There was a Plugin.php found in {$this->pluginPaths[$name]}, but also a z.yml at $zFileLocation\"",
")",
";",
"}",
"$",
"hasZfile",
"=",
"true",
";",
"$",
"this",
"->",
"sourceFiles",
"[",
"]",
"=",
"$",
"zFileLocation",
";",
"}",
"catch",
"(",
"\\",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"}",
"if",
"(",
"!",
"$",
"hasPlugin",
"&&",
"!",
"$",
"hasZfile",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"You need at least either a z.yml or a Plugin.php in the plugin path for '{$name}'\"",
")",
";",
"}",
"Debug",
"::",
"exitScope",
"(",
"$",
"name",
")",
";",
"}"
] | Add a plugin at the passed location
@param string $name
@param string $dir
@return void
@throws \InvalidArgumentException
@throws \UnexpectedValueException | [
"Add",
"a",
"plugin",
"at",
"the",
"passed",
"location"
] | train | https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Configuration/FileLoader.php#L208-L243 |
zicht/z | src/Zicht/Tool/Configuration/FileLoader.php | FileLoader.processImports | protected function processImports($imports, $dir)
{
foreach ($imports as $import) {
$this->setCurrentDir($dir);
$this->import($import);
}
} | php | protected function processImports($imports, $dir)
{
foreach ($imports as $import) {
$this->setCurrentDir($dir);
$this->import($import);
}
} | [
"protected",
"function",
"processImports",
"(",
"$",
"imports",
",",
"$",
"dir",
")",
"{",
"foreach",
"(",
"$",
"imports",
"as",
"$",
"import",
")",
"{",
"$",
"this",
"->",
"setCurrentDir",
"(",
"$",
"dir",
")",
";",
"$",
"this",
"->",
"import",
"(",
"$",
"import",
")",
";",
"}",
"}"
] | Processes imports
@param array $imports
@param string $dir
@return void | [
"Processes",
"imports"
] | train | https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Configuration/FileLoader.php#L253-L259 |
zhouyl/mellivora | Mellivora/Database/Eloquent/FactoryBuilder.php | FactoryBuilder.create | public function create(array $attributes = [])
{
$results = $this->make($attributes);
if ($results instanceof Model) {
$results->save();
} else {
$results->each->save();
}
return $results;
} | php | public function create(array $attributes = [])
{
$results = $this->make($attributes);
if ($results instanceof Model) {
$results->save();
} else {
$results->each->save();
}
return $results;
} | [
"public",
"function",
"create",
"(",
"array",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"$",
"results",
"=",
"$",
"this",
"->",
"make",
"(",
"$",
"attributes",
")",
";",
"if",
"(",
"$",
"results",
"instanceof",
"Model",
")",
"{",
"$",
"results",
"->",
"save",
"(",
")",
";",
"}",
"else",
"{",
"$",
"results",
"->",
"each",
"->",
"save",
"(",
")",
";",
"}",
"return",
"$",
"results",
";",
"}"
] | Create a collection of models and persist them to the database.
@param array $attributes
@return mixed | [
"Create",
"a",
"collection",
"of",
"models",
"and",
"persist",
"them",
"to",
"the",
"database",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Eloquent/FactoryBuilder.php#L115-L126 |
zhouyl/mellivora | Mellivora/Database/Eloquent/FactoryBuilder.php | FactoryBuilder.make | public function make(array $attributes = [])
{
if ($this->amount === null) {
return $this->makeInstance($attributes);
}
if ($this->amount < 1) {
return (new $this->class)->newCollection();
}
return (new $this->class)->newCollection(array_map(function () use ($attributes) {
return $this->makeInstance($attributes);
}, range(1, $this->amount)));
} | php | public function make(array $attributes = [])
{
if ($this->amount === null) {
return $this->makeInstance($attributes);
}
if ($this->amount < 1) {
return (new $this->class)->newCollection();
}
return (new $this->class)->newCollection(array_map(function () use ($attributes) {
return $this->makeInstance($attributes);
}, range(1, $this->amount)));
} | [
"public",
"function",
"make",
"(",
"array",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"amount",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"makeInstance",
"(",
"$",
"attributes",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"amount",
"<",
"1",
")",
"{",
"return",
"(",
"new",
"$",
"this",
"->",
"class",
")",
"->",
"newCollection",
"(",
")",
";",
"}",
"return",
"(",
"new",
"$",
"this",
"->",
"class",
")",
"->",
"newCollection",
"(",
"array_map",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"attributes",
")",
"{",
"return",
"$",
"this",
"->",
"makeInstance",
"(",
"$",
"attributes",
")",
";",
"}",
",",
"range",
"(",
"1",
",",
"$",
"this",
"->",
"amount",
")",
")",
")",
";",
"}"
] | Create a collection of models.
@param array $attributes
@return mixed | [
"Create",
"a",
"collection",
"of",
"models",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Eloquent/FactoryBuilder.php#L135-L148 |
zhouyl/mellivora | Mellivora/Database/Eloquent/FactoryBuilder.php | FactoryBuilder.makeInstance | protected function makeInstance(array $attributes = [])
{
return Model::unguarded(function () use ($attributes) {
if (!isset($this->definitions[$this->class][$this->name])) {
throw new InvalidArgumentException("Unable to locate factory with name [{$this->name}] [{$this->class}].");
}
$definition = call_user_func(
$this->definitions[$this->class][$this->name],
$this->faker,
$attributes
);
return new $this->class($this->callClosureAttributes(
array_merge($this->applyStates($definition, $attributes), $attributes)
));
});
} | php | protected function makeInstance(array $attributes = [])
{
return Model::unguarded(function () use ($attributes) {
if (!isset($this->definitions[$this->class][$this->name])) {
throw new InvalidArgumentException("Unable to locate factory with name [{$this->name}] [{$this->class}].");
}
$definition = call_user_func(
$this->definitions[$this->class][$this->name],
$this->faker,
$attributes
);
return new $this->class($this->callClosureAttributes(
array_merge($this->applyStates($definition, $attributes), $attributes)
));
});
} | [
"protected",
"function",
"makeInstance",
"(",
"array",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"return",
"Model",
"::",
"unguarded",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"attributes",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"definitions",
"[",
"$",
"this",
"->",
"class",
"]",
"[",
"$",
"this",
"->",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Unable to locate factory with name [{$this->name}] [{$this->class}].\"",
")",
";",
"}",
"$",
"definition",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"definitions",
"[",
"$",
"this",
"->",
"class",
"]",
"[",
"$",
"this",
"->",
"name",
"]",
",",
"$",
"this",
"->",
"faker",
",",
"$",
"attributes",
")",
";",
"return",
"new",
"$",
"this",
"->",
"class",
"(",
"$",
"this",
"->",
"callClosureAttributes",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"applyStates",
"(",
"$",
"definition",
",",
"$",
"attributes",
")",
",",
"$",
"attributes",
")",
")",
")",
";",
"}",
")",
";",
"}"
] | Make an instance of the model with the given attributes.
@param array $attributes
@throws \InvalidArgumentException
@return \Mellivora\Database\Eloquent\Model | [
"Make",
"an",
"instance",
"of",
"the",
"model",
"with",
"the",
"given",
"attributes",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Eloquent/FactoryBuilder.php#L159-L176 |
zhouyl/mellivora | Mellivora/Database/Eloquent/FactoryBuilder.php | FactoryBuilder.applyStates | protected function applyStates(array $definition, array $attributes = [])
{
foreach ($this->activeStates as $state) {
if (!isset($this->states[$this->class][$state])) {
throw new InvalidArgumentException("Unable to locate [{$state}] state for [{$this->class}].");
}
$definition = array_merge($definition, call_user_func(
$this->states[$this->class][$state],
$this->faker,
$attributes
));
}
return $definition;
} | php | protected function applyStates(array $definition, array $attributes = [])
{
foreach ($this->activeStates as $state) {
if (!isset($this->states[$this->class][$state])) {
throw new InvalidArgumentException("Unable to locate [{$state}] state for [{$this->class}].");
}
$definition = array_merge($definition, call_user_func(
$this->states[$this->class][$state],
$this->faker,
$attributes
));
}
return $definition;
} | [
"protected",
"function",
"applyStates",
"(",
"array",
"$",
"definition",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"activeStates",
"as",
"$",
"state",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"states",
"[",
"$",
"this",
"->",
"class",
"]",
"[",
"$",
"state",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Unable to locate [{$state}] state for [{$this->class}].\"",
")",
";",
"}",
"$",
"definition",
"=",
"array_merge",
"(",
"$",
"definition",
",",
"call_user_func",
"(",
"$",
"this",
"->",
"states",
"[",
"$",
"this",
"->",
"class",
"]",
"[",
"$",
"state",
"]",
",",
"$",
"this",
"->",
"faker",
",",
"$",
"attributes",
")",
")",
";",
"}",
"return",
"$",
"definition",
";",
"}"
] | Apply the active states to the model definition array.
@param array $definition
@param array $attributes
@return array | [
"Apply",
"the",
"active",
"states",
"to",
"the",
"model",
"definition",
"array",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Eloquent/FactoryBuilder.php#L186-L201 |
zhouyl/mellivora | Mellivora/Database/Eloquent/FactoryBuilder.php | FactoryBuilder.callClosureAttributes | protected function callClosureAttributes(array $attributes)
{
foreach ($attributes as &$attribute) {
$attribute = $attribute instanceof Closure
? $attribute($attributes) : $attribute;
}
return $attributes;
} | php | protected function callClosureAttributes(array $attributes)
{
foreach ($attributes as &$attribute) {
$attribute = $attribute instanceof Closure
? $attribute($attributes) : $attribute;
}
return $attributes;
} | [
"protected",
"function",
"callClosureAttributes",
"(",
"array",
"$",
"attributes",
")",
"{",
"foreach",
"(",
"$",
"attributes",
"as",
"&",
"$",
"attribute",
")",
"{",
"$",
"attribute",
"=",
"$",
"attribute",
"instanceof",
"Closure",
"?",
"$",
"attribute",
"(",
"$",
"attributes",
")",
":",
"$",
"attribute",
";",
"}",
"return",
"$",
"attributes",
";",
"}"
] | Evaluate any Closure attributes on the attribute array.
@param array $attributes
@return array | [
"Evaluate",
"any",
"Closure",
"attributes",
"on",
"the",
"attribute",
"array",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Eloquent/FactoryBuilder.php#L210-L218 |
Salamek/nette-tempnam | src/Salamek/Tempnam/Tempnam.php | Tempnam.remove | public function remove($key)
{
$keyGen = $this->generateKey($key);
$this->cache->remove($keyGen);
@unlink($this->getFilePath($keyGen));
} | php | public function remove($key)
{
$keyGen = $this->generateKey($key);
$this->cache->remove($keyGen);
@unlink($this->getFilePath($keyGen));
} | [
"public",
"function",
"remove",
"(",
"$",
"key",
")",
"{",
"$",
"keyGen",
"=",
"$",
"this",
"->",
"generateKey",
"(",
"$",
"key",
")",
";",
"$",
"this",
"->",
"cache",
"->",
"remove",
"(",
"$",
"keyGen",
")",
";",
"@",
"unlink",
"(",
"$",
"this",
"->",
"getFilePath",
"(",
"$",
"keyGen",
")",
")",
";",
"}"
] | Removes tempnam file by its key
@param $key string tempnam key | [
"Removes",
"tempnam",
"file",
"by",
"its",
"key"
] | train | https://github.com/Salamek/nette-tempnam/blob/47af43ec9a3f9f812177c83f021ffafeeff0305e/src/Salamek/Tempnam/Tempnam.php#L116-L121 |
Salamek/nette-tempnam | src/Salamek/Tempnam/Tempnam.php | Tempnam.load | public function load($key, \DateTimeInterface $updatedAt = null)
{
$keyGen = $this->generateKey($key);
$updateDate = $this->cache->load($keyGen);
if ($updateDate === null || $updateDate != $updatedAt) {
if ($updateDate) {
$this->remove($key);
}
return null;
}
return $this->getFilePath($keyGen);
} | php | public function load($key, \DateTimeInterface $updatedAt = null)
{
$keyGen = $this->generateKey($key);
$updateDate = $this->cache->load($keyGen);
if ($updateDate === null || $updateDate != $updatedAt) {
if ($updateDate) {
$this->remove($key);
}
return null;
}
return $this->getFilePath($keyGen);
} | [
"public",
"function",
"load",
"(",
"$",
"key",
",",
"\\",
"DateTimeInterface",
"$",
"updatedAt",
"=",
"null",
")",
"{",
"$",
"keyGen",
"=",
"$",
"this",
"->",
"generateKey",
"(",
"$",
"key",
")",
";",
"$",
"updateDate",
"=",
"$",
"this",
"->",
"cache",
"->",
"load",
"(",
"$",
"keyGen",
")",
";",
"if",
"(",
"$",
"updateDate",
"===",
"null",
"||",
"$",
"updateDate",
"!=",
"$",
"updatedAt",
")",
"{",
"if",
"(",
"$",
"updateDate",
")",
"{",
"$",
"this",
"->",
"remove",
"(",
"$",
"key",
")",
";",
"}",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"getFilePath",
"(",
"$",
"keyGen",
")",
";",
"}"
] | Loads tempnam file path
@param $key string tempnam key
@param \DateTimeInterface|null $updatedAt When data was last updated
@return null|string path to tempnam | [
"Loads",
"tempnam",
"file",
"path"
] | train | https://github.com/Salamek/nette-tempnam/blob/47af43ec9a3f9f812177c83f021ffafeeff0305e/src/Salamek/Tempnam/Tempnam.php#L129-L142 |
Salamek/nette-tempnam | src/Salamek/Tempnam/Tempnam.php | Tempnam.save | public function save($key, $data, \DateTimeInterface $updatedAt = null)
{
$keyGen = $this->generateKey($key);
$path = $this->putFile($keyGen, $data);
$this->cache->save($keyGen, $updatedAt);
return $path;
} | php | public function save($key, $data, \DateTimeInterface $updatedAt = null)
{
$keyGen = $this->generateKey($key);
$path = $this->putFile($keyGen, $data);
$this->cache->save($keyGen, $updatedAt);
return $path;
} | [
"public",
"function",
"save",
"(",
"$",
"key",
",",
"$",
"data",
",",
"\\",
"DateTimeInterface",
"$",
"updatedAt",
"=",
"null",
")",
"{",
"$",
"keyGen",
"=",
"$",
"this",
"->",
"generateKey",
"(",
"$",
"key",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"putFile",
"(",
"$",
"keyGen",
",",
"$",
"data",
")",
";",
"$",
"this",
"->",
"cache",
"->",
"save",
"(",
"$",
"keyGen",
",",
"$",
"updatedAt",
")",
";",
"return",
"$",
"path",
";",
"}"
] | Saves tempnam file and returns its path
@param $key string tempnam key
@param $data string content of file
@param \DateTimeInterface|null $updatedAt When data was last updated
@return string path to tempnam | [
"Saves",
"tempnam",
"file",
"and",
"returns",
"its",
"path"
] | train | https://github.com/Salamek/nette-tempnam/blob/47af43ec9a3f9f812177c83f021ffafeeff0305e/src/Salamek/Tempnam/Tempnam.php#L151-L157 |
Salamek/nette-tempnam | src/Salamek/Tempnam/Tempnam.php | Tempnam.clean | private function clean()
{
foreach (Finder::find($this->namespace . '*')->from($this->tempDir)->childFirst() as $entry) {
$path = (string)$entry;
if ($entry->isDir()) {
//We dont use dirs, ignore
continue;
}
$updateDate = $this->cache->load($entry->getFilename());
if ($updateDate === null) {
@unlink($path);
}
}
return;
} | php | private function clean()
{
foreach (Finder::find($this->namespace . '*')->from($this->tempDir)->childFirst() as $entry) {
$path = (string)$entry;
if ($entry->isDir()) {
//We dont use dirs, ignore
continue;
}
$updateDate = $this->cache->load($entry->getFilename());
if ($updateDate === null) {
@unlink($path);
}
}
return;
} | [
"private",
"function",
"clean",
"(",
")",
"{",
"foreach",
"(",
"Finder",
"::",
"find",
"(",
"$",
"this",
"->",
"namespace",
".",
"'*'",
")",
"->",
"from",
"(",
"$",
"this",
"->",
"tempDir",
")",
"->",
"childFirst",
"(",
")",
"as",
"$",
"entry",
")",
"{",
"$",
"path",
"=",
"(",
"string",
")",
"$",
"entry",
";",
"if",
"(",
"$",
"entry",
"->",
"isDir",
"(",
")",
")",
"{",
"//We dont use dirs, ignore",
"continue",
";",
"}",
"$",
"updateDate",
"=",
"$",
"this",
"->",
"cache",
"->",
"load",
"(",
"$",
"entry",
"->",
"getFilename",
"(",
")",
")",
";",
"if",
"(",
"$",
"updateDate",
"===",
"null",
")",
"{",
"@",
"unlink",
"(",
"$",
"path",
")",
";",
"}",
"}",
"return",
";",
"}"
] | Cleans unused tempnam files
@return void | [
"Cleans",
"unused",
"tempnam",
"files"
] | train | https://github.com/Salamek/nette-tempnam/blob/47af43ec9a3f9f812177c83f021ffafeeff0305e/src/Salamek/Tempnam/Tempnam.php#L163-L179 |
php-lug/lug | src/Bundle/ResourceBundle/Form/Extension/Base64FileExtension.php | Base64FileExtension.configureOptions | public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);
$resolver->setDefaults([
'base64' => $this->parameterResolver->resolveApi(),
]);
} | php | public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);
$resolver->setDefaults([
'base64' => $this->parameterResolver->resolveApi(),
]);
} | [
"public",
"function",
"configureOptions",
"(",
"OptionsResolver",
"$",
"resolver",
")",
"{",
"parent",
"::",
"configureOptions",
"(",
"$",
"resolver",
")",
";",
"$",
"resolver",
"->",
"setDefaults",
"(",
"[",
"'base64'",
"=>",
"$",
"this",
"->",
"parameterResolver",
"->",
"resolveApi",
"(",
")",
",",
"]",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/ResourceBundle/Form/Extension/Base64FileExtension.php#L41-L48 |
heidelpay/PhpDoc | src/phpDocumentor/Descriptor/Builder/Reflector/Tags/AuthorAssembler.php | AuthorAssembler.create | public function create($data)
{
$descriptor = new AuthorDescriptor($data->getName());
$descriptor->setDescription($data->getDescription());
return $descriptor;
} | php | public function create($data)
{
$descriptor = new AuthorDescriptor($data->getName());
$descriptor->setDescription($data->getDescription());
return $descriptor;
} | [
"public",
"function",
"create",
"(",
"$",
"data",
")",
"{",
"$",
"descriptor",
"=",
"new",
"AuthorDescriptor",
"(",
"$",
"data",
"->",
"getName",
"(",
")",
")",
";",
"$",
"descriptor",
"->",
"setDescription",
"(",
"$",
"data",
"->",
"getDescription",
"(",
")",
")",
";",
"return",
"$",
"descriptor",
";",
"}"
] | Creates a new Descriptor from the given Reflector.
@param AuthorTag $data
@return AuthorDescriptor | [
"Creates",
"a",
"new",
"Descriptor",
"from",
"the",
"given",
"Reflector",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Descriptor/Builder/Reflector/Tags/AuthorAssembler.php#L33-L39 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/schema_diff.php | ezcDbSchemaDiff.checkSchemaDiffReader | static private function checkSchemaDiffReader( $obj, $type )
{
if ( !( ( $obj->getDiffReaderType() & $type ) == $type ) )
{
throw new ezcDbSchemaInvalidReaderClassException( get_class( $obj ), $type );
}
} | php | static private function checkSchemaDiffReader( $obj, $type )
{
if ( !( ( $obj->getDiffReaderType() & $type ) == $type ) )
{
throw new ezcDbSchemaInvalidReaderClassException( get_class( $obj ), $type );
}
} | [
"static",
"private",
"function",
"checkSchemaDiffReader",
"(",
"$",
"obj",
",",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"(",
"(",
"$",
"obj",
"->",
"getDiffReaderType",
"(",
")",
"&",
"$",
"type",
")",
"==",
"$",
"type",
")",
")",
"{",
"throw",
"new",
"ezcDbSchemaInvalidReaderClassException",
"(",
"get_class",
"(",
"$",
"obj",
")",
",",
"$",
"type",
")",
";",
"}",
"}"
] | Checks whether the object in $obj implements the correct $type of reader handler.
@throws ezcDbSchemaInvalidReaderClassException if the object in $obj is
not a schema reader of the correct type.
@param ezcDbSchemaReader $obj
@param int $type | [
"Checks",
"whether",
"the",
"object",
"in",
"$obj",
"implements",
"the",
"correct",
"$type",
"of",
"reader",
"handler",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/schema_diff.php#L69-L75 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/schema_diff.php | ezcDbSchemaDiff.createFromFile | static public function createFromFile( $format, $file )
{
$className = ezcDbSchemaHandlerManager::getDiffReaderByFormat( $format );
$reader = new $className();
self::checkSchemaDiffReader( $reader, ezcDbSchema::FILE );
return $reader->loadDiffFromFile( $file );
} | php | static public function createFromFile( $format, $file )
{
$className = ezcDbSchemaHandlerManager::getDiffReaderByFormat( $format );
$reader = new $className();
self::checkSchemaDiffReader( $reader, ezcDbSchema::FILE );
return $reader->loadDiffFromFile( $file );
} | [
"static",
"public",
"function",
"createFromFile",
"(",
"$",
"format",
",",
"$",
"file",
")",
"{",
"$",
"className",
"=",
"ezcDbSchemaHandlerManager",
"::",
"getDiffReaderByFormat",
"(",
"$",
"format",
")",
";",
"$",
"reader",
"=",
"new",
"$",
"className",
"(",
")",
";",
"self",
"::",
"checkSchemaDiffReader",
"(",
"$",
"reader",
",",
"ezcDbSchema",
"::",
"FILE",
")",
";",
"return",
"$",
"reader",
"->",
"loadDiffFromFile",
"(",
"$",
"file",
")",
";",
"}"
] | Factory method to create a ezcDbSchemaDiff object from the file $file with the format $format.
@throws ezcDbSchemaInvalidReaderClassException if the handler associated
with the $format is not a file schema reader.
@param string $format
@param string $file
@return ezcDbSchemaDiff | [
"Factory",
"method",
"to",
"create",
"a",
"ezcDbSchemaDiff",
"object",
"from",
"the",
"file",
"$file",
"with",
"the",
"format",
"$format",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/schema_diff.php#L87-L93 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/schema_diff.php | ezcDbSchemaDiff.checkSchemaDiffWriter | static private function checkSchemaDiffWriter( $obj, $type )
{
if ( !( ( $obj->getDiffWriterType() & $type ) == $type ) )
{
throw new ezcDbSchemaInvalidWriterClassException( get_class( $obj ), $type );
}
} | php | static private function checkSchemaDiffWriter( $obj, $type )
{
if ( !( ( $obj->getDiffWriterType() & $type ) == $type ) )
{
throw new ezcDbSchemaInvalidWriterClassException( get_class( $obj ), $type );
}
} | [
"static",
"private",
"function",
"checkSchemaDiffWriter",
"(",
"$",
"obj",
",",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"(",
"(",
"$",
"obj",
"->",
"getDiffWriterType",
"(",
")",
"&",
"$",
"type",
")",
"==",
"$",
"type",
")",
")",
"{",
"throw",
"new",
"ezcDbSchemaInvalidWriterClassException",
"(",
"get_class",
"(",
"$",
"obj",
")",
",",
"$",
"type",
")",
";",
"}",
"}"
] | Checks whether the object in $obj implements the correct $type of writer handler.
@throws ezcDbSchemaInvalidWriterClassException if the object in $obj is
not a schema writer of the correct type.
@param ezcDbSchemaWriter $obj
@param int $type | [
"Checks",
"whether",
"the",
"object",
"in",
"$obj",
"implements",
"the",
"correct",
"$type",
"of",
"writer",
"handler",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/schema_diff.php#L104-L110 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/schema_diff.php | ezcDbSchemaDiff.writeToFile | public function writeToFile( $format, $file )
{
$className = ezcDbSchemaHandlerManager::getDiffWriterByFormat( $format );
$reader = new $className();
self::checkSchemaDiffWriter( $reader, ezcDbSchema::FILE );
$reader->saveDiffToFile( $file, $this );
} | php | public function writeToFile( $format, $file )
{
$className = ezcDbSchemaHandlerManager::getDiffWriterByFormat( $format );
$reader = new $className();
self::checkSchemaDiffWriter( $reader, ezcDbSchema::FILE );
$reader->saveDiffToFile( $file, $this );
} | [
"public",
"function",
"writeToFile",
"(",
"$",
"format",
",",
"$",
"file",
")",
"{",
"$",
"className",
"=",
"ezcDbSchemaHandlerManager",
"::",
"getDiffWriterByFormat",
"(",
"$",
"format",
")",
";",
"$",
"reader",
"=",
"new",
"$",
"className",
"(",
")",
";",
"self",
"::",
"checkSchemaDiffWriter",
"(",
"$",
"reader",
",",
"ezcDbSchema",
"::",
"FILE",
")",
";",
"$",
"reader",
"->",
"saveDiffToFile",
"(",
"$",
"file",
",",
"$",
"this",
")",
";",
"}"
] | Writes the schema differences to the file $file in format $format.
@throws ezcDbSchemaInvalidWriterClassException if the handler associated
with the $format is not a file schema writer.
@param string $format
@param string $file | [
"Writes",
"the",
"schema",
"differences",
"to",
"the",
"file",
"$file",
"in",
"format",
"$format",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/schema_diff.php#L121-L127 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/schema_diff.php | ezcDbSchemaDiff.applyToDb | public function applyToDb( ezcDbHandler $db )
{
$className = ezcDbSchemaHandlerManager::getDiffWriterByFormat( $db->getName() );
$writer = new $className();
self::checkSchemaDiffWriter( $writer, ezcDbSchema::DATABASE );
$writer->applyDiffToDb( $db, $this );
} | php | public function applyToDb( ezcDbHandler $db )
{
$className = ezcDbSchemaHandlerManager::getDiffWriterByFormat( $db->getName() );
$writer = new $className();
self::checkSchemaDiffWriter( $writer, ezcDbSchema::DATABASE );
$writer->applyDiffToDb( $db, $this );
} | [
"public",
"function",
"applyToDb",
"(",
"ezcDbHandler",
"$",
"db",
")",
"{",
"$",
"className",
"=",
"ezcDbSchemaHandlerManager",
"::",
"getDiffWriterByFormat",
"(",
"$",
"db",
"->",
"getName",
"(",
")",
")",
";",
"$",
"writer",
"=",
"new",
"$",
"className",
"(",
")",
";",
"self",
"::",
"checkSchemaDiffWriter",
"(",
"$",
"writer",
",",
"ezcDbSchema",
"::",
"DATABASE",
")",
";",
"$",
"writer",
"->",
"applyDiffToDb",
"(",
"$",
"db",
",",
"$",
"this",
")",
";",
"}"
] | Upgrades the database $db with the differences.
@throws ezcDbSchemaInvalidWriterClassException if the handler associated
with the $format is not a database schema writer.
@param ezcDbHandler $db | [
"Upgrades",
"the",
"database",
"$db",
"with",
"the",
"differences",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/schema_diff.php#L137-L143 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/schema_diff.php | ezcDbSchemaDiff.convertToDDL | public function convertToDDL( $db )
{
if ( $db instanceof ezcDbHandler )
{
$db = $db->getName();
}
$className = ezcDbSchemaHandlerManager::getDiffWriterByFormat( $db );
$writer = new $className();
self::checkSchemaDiffWriter( $writer, ezcDbSchema::DATABASE );
return $writer->convertDiffToDDL( $this );
} | php | public function convertToDDL( $db )
{
if ( $db instanceof ezcDbHandler )
{
$db = $db->getName();
}
$className = ezcDbSchemaHandlerManager::getDiffWriterByFormat( $db );
$writer = new $className();
self::checkSchemaDiffWriter( $writer, ezcDbSchema::DATABASE );
return $writer->convertDiffToDDL( $this );
} | [
"public",
"function",
"convertToDDL",
"(",
"$",
"db",
")",
"{",
"if",
"(",
"$",
"db",
"instanceof",
"ezcDbHandler",
")",
"{",
"$",
"db",
"=",
"$",
"db",
"->",
"getName",
"(",
")",
";",
"}",
"$",
"className",
"=",
"ezcDbSchemaHandlerManager",
"::",
"getDiffWriterByFormat",
"(",
"$",
"db",
")",
";",
"$",
"writer",
"=",
"new",
"$",
"className",
"(",
")",
";",
"self",
"::",
"checkSchemaDiffWriter",
"(",
"$",
"writer",
",",
"ezcDbSchema",
"::",
"DATABASE",
")",
";",
"return",
"$",
"writer",
"->",
"convertDiffToDDL",
"(",
"$",
"this",
")",
";",
"}"
] | Returns the $db specific SQL queries that would update the database $db
The database type can be given as both a database handler (instanceof
ezcDbHandler) or the name of the database as string as retrieved through
calling getName() on the database handler object.
@see ezcDbHandler::getName()
@throws ezcDbSchemaInvalidWriterClassException if the handler associated
with the $format is not a database schema writer.
@param string|ezcDbHandler $db
@return array(string) | [
"Returns",
"the",
"$db",
"specific",
"SQL",
"queries",
"that",
"would",
"update",
"the",
"database",
"$db"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/schema_diff.php#L160-L170 |
willhoffmann/domuserp-php | src/Resources/People/People.php | People.deliveryAddresses | public function deliveryAddresses($personId)
{
$deliveryAddresses = $this->execute(
self::HTTP_GET,
self::DOMUSERP_API_PEDIDOVENDA . '/pessoas/' . $personId . '/enderecosentrega'
);
return $deliveryAddresses;
} | php | public function deliveryAddresses($personId)
{
$deliveryAddresses = $this->execute(
self::HTTP_GET,
self::DOMUSERP_API_PEDIDOVENDA . '/pessoas/' . $personId . '/enderecosentrega'
);
return $deliveryAddresses;
} | [
"public",
"function",
"deliveryAddresses",
"(",
"$",
"personId",
")",
"{",
"$",
"deliveryAddresses",
"=",
"$",
"this",
"->",
"execute",
"(",
"self",
"::",
"HTTP_GET",
",",
"self",
"::",
"DOMUSERP_API_PEDIDOVENDA",
".",
"'/pessoas/'",
".",
"$",
"personId",
".",
"'/enderecosentrega'",
")",
";",
"return",
"$",
"deliveryAddresses",
";",
"}"
] | Gets the delivery address of the person according to the id passed as parameter
@param $personId
@return string
@throws \GuzzleHttp\Exception\GuzzleException | [
"Gets",
"the",
"delivery",
"address",
"of",
"the",
"person",
"according",
"to",
"the",
"id",
"passed",
"as",
"parameter"
] | train | https://github.com/willhoffmann/domuserp-php/blob/44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6/src/Resources/People/People.php#L47-L55 |
willhoffmann/domuserp-php | src/Resources/People/People.php | People.orderDefaultValues | public function orderDefaultValues($personId)
{
$orderDefaultValues = $this->execute(
self::HTTP_GET,
self::DOMUSERP_API_PEDIDOVENDA . '/pessoas/' . $personId . '/valoresPadraoPedido'
);
return $orderDefaultValues;
} | php | public function orderDefaultValues($personId)
{
$orderDefaultValues = $this->execute(
self::HTTP_GET,
self::DOMUSERP_API_PEDIDOVENDA . '/pessoas/' . $personId . '/valoresPadraoPedido'
);
return $orderDefaultValues;
} | [
"public",
"function",
"orderDefaultValues",
"(",
"$",
"personId",
")",
"{",
"$",
"orderDefaultValues",
"=",
"$",
"this",
"->",
"execute",
"(",
"self",
"::",
"HTTP_GET",
",",
"self",
"::",
"DOMUSERP_API_PEDIDOVENDA",
".",
"'/pessoas/'",
".",
"$",
"personId",
".",
"'/valoresPadraoPedido'",
")",
";",
"return",
"$",
"orderDefaultValues",
";",
"}"
] | Gets the order default values of a person according to the person id passed as parameter
@param $personId
@return string
@throws \GuzzleHttp\Exception\GuzzleException | [
"Gets",
"the",
"order",
"default",
"values",
"of",
"a",
"person",
"according",
"to",
"the",
"person",
"id",
"passed",
"as",
"parameter"
] | train | https://github.com/willhoffmann/domuserp-php/blob/44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6/src/Resources/People/People.php#L64-L72 |
willhoffmann/domuserp-php | src/Resources/People/People.php | People.document | public function document($documentNumber)
{
$data = $this->execute(
self::HTTP_GET,
self::DOMUSERP_API_PEDIDOVENDA . '/pessoas/documento',
['query' => ['num' => $documentNumber]]
);
return $data;
} | php | public function document($documentNumber)
{
$data = $this->execute(
self::HTTP_GET,
self::DOMUSERP_API_PEDIDOVENDA . '/pessoas/documento',
['query' => ['num' => $documentNumber]]
);
return $data;
} | [
"public",
"function",
"document",
"(",
"$",
"documentNumber",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"execute",
"(",
"self",
"::",
"HTTP_GET",
",",
"self",
"::",
"DOMUSERP_API_PEDIDOVENDA",
".",
"'/pessoas/documento'",
",",
"[",
"'query'",
"=>",
"[",
"'num'",
"=>",
"$",
"documentNumber",
"]",
"]",
")",
";",
"return",
"$",
"data",
";",
"}"
] | Make sure the person - document (CNPJ/CPF) already exists
@param $documentNumber
@return string
@throws \GuzzleHttp\Exception\GuzzleException | [
"Make",
"sure",
"the",
"person",
"-",
"document",
"(",
"CNPJ",
"/",
"CPF",
")",
"already",
"exists"
] | train | https://github.com/willhoffmann/domuserp-php/blob/44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6/src/Resources/People/People.php#L81-L90 |
willhoffmann/domuserp-php | src/Resources/People/People.php | People.validateDocument | public function validateDocument($documentNumber)
{
$data = $this->execute(
self::HTTP_GET,
self::DOMUSERP_API_PEDIDOVENDA . '/pessoas/validarDocumento',
['query' => ['num' => $documentNumber]]
);
return $data;
} | php | public function validateDocument($documentNumber)
{
$data = $this->execute(
self::HTTP_GET,
self::DOMUSERP_API_PEDIDOVENDA . '/pessoas/validarDocumento',
['query' => ['num' => $documentNumber]]
);
return $data;
} | [
"public",
"function",
"validateDocument",
"(",
"$",
"documentNumber",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"execute",
"(",
"self",
"::",
"HTTP_GET",
",",
"self",
"::",
"DOMUSERP_API_PEDIDOVENDA",
".",
"'/pessoas/validarDocumento'",
",",
"[",
"'query'",
"=>",
"[",
"'num'",
"=>",
"$",
"documentNumber",
"]",
"]",
")",
";",
"return",
"$",
"data",
";",
"}"
] | Document Validation (CNPJ/CPF)
@param $documentNumber
@return string
@throws \GuzzleHttp\Exception\GuzzleException | [
"Document",
"Validation",
"(",
"CNPJ",
"/",
"CPF",
")"
] | train | https://github.com/willhoffmann/domuserp-php/blob/44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6/src/Resources/People/People.php#L99-L108 |
willhoffmann/domuserp-php | src/Resources/People/People.php | People.save | public function save(PersonData $personData)
{
$id = (int) ($personData->getId() > 0 ? '/' . $personData->getId() : '');
return $this->execute(
is_null($id) ? self::HTTP_POST : self::HTTP_PUT,
self::DOMUSERP_API_PEDIDOVENDA . '/pessoas' . $id,
['json' => $personData->toArray()]
);
} | php | public function save(PersonData $personData)
{
$id = (int) ($personData->getId() > 0 ? '/' . $personData->getId() : '');
return $this->execute(
is_null($id) ? self::HTTP_POST : self::HTTP_PUT,
self::DOMUSERP_API_PEDIDOVENDA . '/pessoas' . $id,
['json' => $personData->toArray()]
);
} | [
"public",
"function",
"save",
"(",
"PersonData",
"$",
"personData",
")",
"{",
"$",
"id",
"=",
"(",
"int",
")",
"(",
"$",
"personData",
"->",
"getId",
"(",
")",
">",
"0",
"?",
"'/'",
".",
"$",
"personData",
"->",
"getId",
"(",
")",
":",
"''",
")",
";",
"return",
"$",
"this",
"->",
"execute",
"(",
"is_null",
"(",
"$",
"id",
")",
"?",
"self",
"::",
"HTTP_POST",
":",
"self",
"::",
"HTTP_PUT",
",",
"self",
"::",
"DOMUSERP_API_PEDIDOVENDA",
".",
"'/pessoas'",
".",
"$",
"id",
",",
"[",
"'json'",
"=>",
"$",
"personData",
"->",
"toArray",
"(",
")",
"]",
")",
";",
"}"
] | Send the save request
@param PersonData $personData
@return string
@throws \GuzzleHttp\Exception\GuzzleException | [
"Send",
"the",
"save",
"request"
] | train | https://github.com/willhoffmann/domuserp-php/blob/44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6/src/Resources/People/People.php#L138-L147 |
inhere/php-librarys | src/Traits/LiteEventStaticTrait.php | LiteEventStaticTrait.on | public static function on($name, callable $cb, $replace = false)
{
if ($replace || !isset(self::$_events[$name])) {
self::$_events[$name] = $cb;
}
} | php | public static function on($name, callable $cb, $replace = false)
{
if ($replace || !isset(self::$_events[$name])) {
self::$_events[$name] = $cb;
}
} | [
"public",
"static",
"function",
"on",
"(",
"$",
"name",
",",
"callable",
"$",
"cb",
",",
"$",
"replace",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"replace",
"||",
"!",
"isset",
"(",
"self",
"::",
"$",
"_events",
"[",
"$",
"name",
"]",
")",
")",
"{",
"self",
"::",
"$",
"_events",
"[",
"$",
"name",
"]",
"=",
"$",
"cb",
";",
"}",
"}"
] | register a event callback
@param string $name event name
@param callable $cb event callback
@param bool $replace replace exists's event cb | [
"register",
"a",
"event",
"callback"
] | train | https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Traits/LiteEventStaticTrait.php#L34-L39 |
blast-project/BaseEntitiesBundle | src/Entity/Traits/Tree/Node.php | Node.setChildNodeOf | public function setChildNodeOf(NodeInterface $node)
{
$id = $this->getNodeId();
if (empty($id)) {
throw new \LogicException('You must provide an id for this node if you want it to be part of a tree.');
}
$path = rtrim($node->getRealMaterializedPath(), static::getMaterializedPathSeparator());
$this->setMaterializedPath($path);
if (null !== $this->parentNode) {
$this->parentNode->getChildNodes()->removeElement($this);
}
$this->parentNode = $node;
$this->parentNode->addChildNode($this);
foreach ($this->getChildNodes() as $child) {
$child->setChildNodeOf($this);
}
return $this;
} | php | public function setChildNodeOf(NodeInterface $node)
{
$id = $this->getNodeId();
if (empty($id)) {
throw new \LogicException('You must provide an id for this node if you want it to be part of a tree.');
}
$path = rtrim($node->getRealMaterializedPath(), static::getMaterializedPathSeparator());
$this->setMaterializedPath($path);
if (null !== $this->parentNode) {
$this->parentNode->getChildNodes()->removeElement($this);
}
$this->parentNode = $node;
$this->parentNode->addChildNode($this);
foreach ($this->getChildNodes() as $child) {
$child->setChildNodeOf($this);
}
return $this;
} | [
"public",
"function",
"setChildNodeOf",
"(",
"NodeInterface",
"$",
"node",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getNodeId",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'You must provide an id for this node if you want it to be part of a tree.'",
")",
";",
"}",
"$",
"path",
"=",
"rtrim",
"(",
"$",
"node",
"->",
"getRealMaterializedPath",
"(",
")",
",",
"static",
"::",
"getMaterializedPathSeparator",
"(",
")",
")",
";",
"$",
"this",
"->",
"setMaterializedPath",
"(",
"$",
"path",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"parentNode",
")",
"{",
"$",
"this",
"->",
"parentNode",
"->",
"getChildNodes",
"(",
")",
"->",
"removeElement",
"(",
"$",
"this",
")",
";",
"}",
"$",
"this",
"->",
"parentNode",
"=",
"$",
"node",
";",
"$",
"this",
"->",
"parentNode",
"->",
"addChildNode",
"(",
"$",
"this",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getChildNodes",
"(",
")",
"as",
"$",
"child",
")",
"{",
"$",
"child",
"->",
"setChildNodeOf",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/blast-project/BaseEntitiesBundle/blob/abd06891fc38922225ab7e4fcb437a286ba2c0c4/src/Entity/Traits/Tree/Node.php#L158-L180 |
surebert/surebert-framework | src/sb/Excel/Workbook.php | Workbook.addStyle | public function addStyle($name, $properties)
{
$style = $this->createElement('ss:Style');
$style->setAttribute('ss:ID', $name);
$this->styles->appendChild($style);
$font = $this->createElement('ss:Font');
$style->appendChild($font);
foreach($properties as $prop=>$val){
$font->setAttribute('ss:'.$prop, $val);
}
return $style;
} | php | public function addStyle($name, $properties)
{
$style = $this->createElement('ss:Style');
$style->setAttribute('ss:ID', $name);
$this->styles->appendChild($style);
$font = $this->createElement('ss:Font');
$style->appendChild($font);
foreach($properties as $prop=>$val){
$font->setAttribute('ss:'.$prop, $val);
}
return $style;
} | [
"public",
"function",
"addStyle",
"(",
"$",
"name",
",",
"$",
"properties",
")",
"{",
"$",
"style",
"=",
"$",
"this",
"->",
"createElement",
"(",
"'ss:Style'",
")",
";",
"$",
"style",
"->",
"setAttribute",
"(",
"'ss:ID'",
",",
"$",
"name",
")",
";",
"$",
"this",
"->",
"styles",
"->",
"appendChild",
"(",
"$",
"style",
")",
";",
"$",
"font",
"=",
"$",
"this",
"->",
"createElement",
"(",
"'ss:Font'",
")",
";",
"$",
"style",
"->",
"appendChild",
"(",
"$",
"font",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"prop",
"=>",
"$",
"val",
")",
"{",
"$",
"font",
"->",
"setAttribute",
"(",
"'ss:'",
".",
"$",
"prop",
",",
"$",
"val",
")",
";",
"}",
"return",
"$",
"style",
";",
"}"
] | Creates a new style node and adds it to the styles section
@param string $name The name of the style, used when assigning it
@param array $properties http://msdn.microsoft.com/en-us/library/aa140066%28office.10%29.aspx#odc_xmlss_ss:font e.g. Array('Color' => '#FF0000', 'Bold' => 1);
@return DOMElement The Style tag itself | [
"Creates",
"a",
"new",
"style",
"node",
"and",
"adds",
"it",
"to",
"the",
"styles",
"section"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Excel/Workbook.php#L82-L93 |
surebert/surebert-framework | src/sb/Excel/Workbook.php | Workbook.assignStyle | public function assignStyle(DOMElement $item, $style)
{
if($style instanceOf \DOMElement){
$style_id = $style->getAttribute('ss:ID');
} else {
$style_id = $style;
}
$item->setAttribute('ss:StyleID', $style_id);
} | php | public function assignStyle(DOMElement $item, $style)
{
if($style instanceOf \DOMElement){
$style_id = $style->getAttribute('ss:ID');
} else {
$style_id = $style;
}
$item->setAttribute('ss:StyleID', $style_id);
} | [
"public",
"function",
"assignStyle",
"(",
"DOMElement",
"$",
"item",
",",
"$",
"style",
")",
"{",
"if",
"(",
"$",
"style",
"instanceOf",
"\\",
"DOMElement",
")",
"{",
"$",
"style_id",
"=",
"$",
"style",
"->",
"getAttribute",
"(",
"'ss:ID'",
")",
";",
"}",
"else",
"{",
"$",
"style_id",
"=",
"$",
"style",
";",
"}",
"$",
"item",
"->",
"setAttribute",
"(",
"'ss:StyleID'",
",",
"$",
"style_id",
")",
";",
"}"
] | Assigns the style for an element Row, Cell
@param DOMElement $item The item to assign the style for
@param mixed $style DOMElement style or the string based style id The style to assign to the item | [
"Assigns",
"the",
"style",
"for",
"an",
"element",
"Row",
"Cell"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Excel/Workbook.php#L100-L108 |
surebert/surebert-framework | src/sb/Excel/Workbook.php | Workbook.addWorksheet | public function addWorksheet($title)
{
$worksheet = $this->workbook->appendChild($this->createElement('Worksheet'));
$title = preg_replace("/[\\\|:|\/|\?|\*|\[|\]]/", "", $title);
$title = substr($title, 0, 31);
$worksheet->setAttribute('ss:Name', $title);
$worksheet->table = $worksheet->appendChild($this->createElement('Table'));
$this->worksheets[md5($title)] = $worksheet;
return $worksheet;
} | php | public function addWorksheet($title)
{
$worksheet = $this->workbook->appendChild($this->createElement('Worksheet'));
$title = preg_replace("/[\\\|:|\/|\?|\*|\[|\]]/", "", $title);
$title = substr($title, 0, 31);
$worksheet->setAttribute('ss:Name', $title);
$worksheet->table = $worksheet->appendChild($this->createElement('Table'));
$this->worksheets[md5($title)] = $worksheet;
return $worksheet;
} | [
"public",
"function",
"addWorksheet",
"(",
"$",
"title",
")",
"{",
"$",
"worksheet",
"=",
"$",
"this",
"->",
"workbook",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"createElement",
"(",
"'Worksheet'",
")",
")",
";",
"$",
"title",
"=",
"preg_replace",
"(",
"\"/[\\\\\\|:|\\/|\\?|\\*|\\[|\\]]/\"",
",",
"\"\"",
",",
"$",
"title",
")",
";",
"$",
"title",
"=",
"substr",
"(",
"$",
"title",
",",
"0",
",",
"31",
")",
";",
"$",
"worksheet",
"->",
"setAttribute",
"(",
"'ss:Name'",
",",
"$",
"title",
")",
";",
"$",
"worksheet",
"->",
"table",
"=",
"$",
"worksheet",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"createElement",
"(",
"'Table'",
")",
")",
";",
"$",
"this",
"->",
"worksheets",
"[",
"md5",
"(",
"$",
"title",
")",
"]",
"=",
"$",
"worksheet",
";",
"return",
"$",
"worksheet",
";",
"}"
] | Adds a new worksheet to the workbook
@param string $title
@return DOMElement The worksheet itself | [
"Adds",
"a",
"new",
"worksheet",
"to",
"the",
"workbook"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Excel/Workbook.php#L115-L124 |
surebert/surebert-framework | src/sb/Excel/Workbook.php | Workbook.setActiveWorksheet | public function setActiveWorksheet($worksheet)
{
if(is_string($worksheet)){
$worksheet = $this->worksheets[md5($worksheet)];
}
$this->active_worksheet = $worksheet;
return $worksheet;
} | php | public function setActiveWorksheet($worksheet)
{
if(is_string($worksheet)){
$worksheet = $this->worksheets[md5($worksheet)];
}
$this->active_worksheet = $worksheet;
return $worksheet;
} | [
"public",
"function",
"setActiveWorksheet",
"(",
"$",
"worksheet",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"worksheet",
")",
")",
"{",
"$",
"worksheet",
"=",
"$",
"this",
"->",
"worksheets",
"[",
"md5",
"(",
"$",
"worksheet",
")",
"]",
";",
"}",
"$",
"this",
"->",
"active_worksheet",
"=",
"$",
"worksheet",
";",
"return",
"$",
"worksheet",
";",
"}"
] | Sets the active worksheet
@param string $worksheet The name of the worksheet or a reference to the DOMElement itself
@return DOMElement The active worksheet | [
"Sets",
"the",
"active",
"worksheet"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Excel/Workbook.php#L131-L139 |
surebert/surebert-framework | src/sb/Excel/Workbook.php | Workbook.setRow | public function setRow($row_index, $values_arr, $type=null)
{
$cell = null;
foreach($values_arr as $col_index=>$val){
$cell = $this->setCell($col_index+1, $row_index, $val, $type);
}
if($cell){
return $cell->parentNode;
}
return false;
} | php | public function setRow($row_index, $values_arr, $type=null)
{
$cell = null;
foreach($values_arr as $col_index=>$val){
$cell = $this->setCell($col_index+1, $row_index, $val, $type);
}
if($cell){
return $cell->parentNode;
}
return false;
} | [
"public",
"function",
"setRow",
"(",
"$",
"row_index",
",",
"$",
"values_arr",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"cell",
"=",
"null",
";",
"foreach",
"(",
"$",
"values_arr",
"as",
"$",
"col_index",
"=>",
"$",
"val",
")",
"{",
"$",
"cell",
"=",
"$",
"this",
"->",
"setCell",
"(",
"$",
"col_index",
"+",
"1",
",",
"$",
"row_index",
",",
"$",
"val",
",",
"$",
"type",
")",
";",
"}",
"if",
"(",
"$",
"cell",
")",
"{",
"return",
"$",
"cell",
"->",
"parentNode",
";",
"}",
"return",
"false",
";",
"}"
] | Sets an entire row of data
@param integer $row_index The 1 based row index to use
@param array $values_arr An array of values
@param string $type ss:Type attribute
@return DOMElement The row | [
"Sets",
"an",
"entire",
"row",
"of",
"data"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Excel/Workbook.php#L148-L159 |
surebert/surebert-framework | src/sb/Excel/Workbook.php | Workbook.setCell | public function setCell($col_index, $row_index, $val, $type=null)
{
$result = $this->xpath->query("//Row[@Index='".$row_index."']/Cell[@Index='".$col_index."']/Data", $this->active_worksheet);
$data = $result->item(0);
$type = $type ? $type : $this->getValueType($val);
if($data){
$data->setAttribute('ss:Type', $type);
$data->firstChild->nodeValue = $val;
} else {
$result = $this->xpath->query("//Row[@Index='".$row_index."']");
$row = $result->item(0);
if(!$row){
$row = $this->createElement('Row');
$this->active_worksheet->table->appendChild($row);
$row->setAttribute('Index', $row_index);
}
$result = $this->xpath->query("//Row[@Index='".$row_index."']/Cell[@Index='".$col_index."']", $row);
$cell = $result->item(0);
if(!$cell){
$cell = $this->createElement('Cell');
$row->appendChild($cell);
$cell->setAttribute('Index', $col_index);
$data = $this->createElement('Data');
$cell->appendChild($data);
$data->setAttribute('ss:Type', $type);
$data->appendChild($this->createTextNode($val));
} else {
$data = $cell->getElementsByTagName('Data')->item(0);
$data->setAttribute('ss:Type', $type);
$data->firstChild->nodeValue = $val;
}
}
return $data->parentNode;
} | php | public function setCell($col_index, $row_index, $val, $type=null)
{
$result = $this->xpath->query("//Row[@Index='".$row_index."']/Cell[@Index='".$col_index."']/Data", $this->active_worksheet);
$data = $result->item(0);
$type = $type ? $type : $this->getValueType($val);
if($data){
$data->setAttribute('ss:Type', $type);
$data->firstChild->nodeValue = $val;
} else {
$result = $this->xpath->query("//Row[@Index='".$row_index."']");
$row = $result->item(0);
if(!$row){
$row = $this->createElement('Row');
$this->active_worksheet->table->appendChild($row);
$row->setAttribute('Index', $row_index);
}
$result = $this->xpath->query("//Row[@Index='".$row_index."']/Cell[@Index='".$col_index."']", $row);
$cell = $result->item(0);
if(!$cell){
$cell = $this->createElement('Cell');
$row->appendChild($cell);
$cell->setAttribute('Index', $col_index);
$data = $this->createElement('Data');
$cell->appendChild($data);
$data->setAttribute('ss:Type', $type);
$data->appendChild($this->createTextNode($val));
} else {
$data = $cell->getElementsByTagName('Data')->item(0);
$data->setAttribute('ss:Type', $type);
$data->firstChild->nodeValue = $val;
}
}
return $data->parentNode;
} | [
"public",
"function",
"setCell",
"(",
"$",
"col_index",
",",
"$",
"row_index",
",",
"$",
"val",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"xpath",
"->",
"query",
"(",
"\"//Row[@Index='\"",
".",
"$",
"row_index",
".",
"\"']/Cell[@Index='\"",
".",
"$",
"col_index",
".",
"\"']/Data\"",
",",
"$",
"this",
"->",
"active_worksheet",
")",
";",
"$",
"data",
"=",
"$",
"result",
"->",
"item",
"(",
"0",
")",
";",
"$",
"type",
"=",
"$",
"type",
"?",
"$",
"type",
":",
"$",
"this",
"->",
"getValueType",
"(",
"$",
"val",
")",
";",
"if",
"(",
"$",
"data",
")",
"{",
"$",
"data",
"->",
"setAttribute",
"(",
"'ss:Type'",
",",
"$",
"type",
")",
";",
"$",
"data",
"->",
"firstChild",
"->",
"nodeValue",
"=",
"$",
"val",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"xpath",
"->",
"query",
"(",
"\"//Row[@Index='\"",
".",
"$",
"row_index",
".",
"\"']\"",
")",
";",
"$",
"row",
"=",
"$",
"result",
"->",
"item",
"(",
"0",
")",
";",
"if",
"(",
"!",
"$",
"row",
")",
"{",
"$",
"row",
"=",
"$",
"this",
"->",
"createElement",
"(",
"'Row'",
")",
";",
"$",
"this",
"->",
"active_worksheet",
"->",
"table",
"->",
"appendChild",
"(",
"$",
"row",
")",
";",
"$",
"row",
"->",
"setAttribute",
"(",
"'Index'",
",",
"$",
"row_index",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"xpath",
"->",
"query",
"(",
"\"//Row[@Index='\"",
".",
"$",
"row_index",
".",
"\"']/Cell[@Index='\"",
".",
"$",
"col_index",
".",
"\"']\"",
",",
"$",
"row",
")",
";",
"$",
"cell",
"=",
"$",
"result",
"->",
"item",
"(",
"0",
")",
";",
"if",
"(",
"!",
"$",
"cell",
")",
"{",
"$",
"cell",
"=",
"$",
"this",
"->",
"createElement",
"(",
"'Cell'",
")",
";",
"$",
"row",
"->",
"appendChild",
"(",
"$",
"cell",
")",
";",
"$",
"cell",
"->",
"setAttribute",
"(",
"'Index'",
",",
"$",
"col_index",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"createElement",
"(",
"'Data'",
")",
";",
"$",
"cell",
"->",
"appendChild",
"(",
"$",
"data",
")",
";",
"$",
"data",
"->",
"setAttribute",
"(",
"'ss:Type'",
",",
"$",
"type",
")",
";",
"$",
"data",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"createTextNode",
"(",
"$",
"val",
")",
")",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"$",
"cell",
"->",
"getElementsByTagName",
"(",
"'Data'",
")",
"->",
"item",
"(",
"0",
")",
";",
"$",
"data",
"->",
"setAttribute",
"(",
"'ss:Type'",
",",
"$",
"type",
")",
";",
"$",
"data",
"->",
"firstChild",
"->",
"nodeValue",
"=",
"$",
"val",
";",
"}",
"}",
"return",
"$",
"data",
"->",
"parentNode",
";",
"}"
] | Sets a cell by 1 based column and row index
@param integer $col_index 1based column index
@param integer $row_index 1 based row index
@param mixed $val The value to insert
@param string $type The ss:Type attribute
@return DOMElement the cell itself | [
"Sets",
"a",
"cell",
"by",
"1",
"based",
"column",
"and",
"row",
"index"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Excel/Workbook.php#L169-L210 |
surebert/surebert-framework | src/sb/Excel/Workbook.php | Workbook.setcellByAlphaIndex | public function setcellByAlphaIndex($alpha_index, $val, $type=null)
{
$pos = $this->alphaIndexToNumeric($alpha_index);
return $this->setCell($pos[0], $pos[1], $val, $type);
} | php | public function setcellByAlphaIndex($alpha_index, $val, $type=null)
{
$pos = $this->alphaIndexToNumeric($alpha_index);
return $this->setCell($pos[0], $pos[1], $val, $type);
} | [
"public",
"function",
"setcellByAlphaIndex",
"(",
"$",
"alpha_index",
",",
"$",
"val",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"pos",
"=",
"$",
"this",
"->",
"alphaIndexToNumeric",
"(",
"$",
"alpha_index",
")",
";",
"return",
"$",
"this",
"->",
"setCell",
"(",
"$",
"pos",
"[",
"0",
"]",
",",
"$",
"pos",
"[",
"1",
"]",
",",
"$",
"val",
",",
"$",
"type",
")",
";",
"}"
] | Sets a cells value by alpha index e.g. A4
@param string $alpha_index A4
@param mixed $val the value to set the cell to
@param string $type The ss:Type attribute
@return DomElement The cell itself | [
"Sets",
"a",
"cells",
"value",
"by",
"alpha",
"index",
"e",
".",
"g",
".",
"A4"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Excel/Workbook.php#L231-L236 |
surebert/surebert-framework | src/sb/Excel/Workbook.php | Workbook.outputWithHeaders | public function outputWithHeaders($filename='worksheet')
{
$filename = preg_replace('/[^aA-zZ0-9\_\-]/', '', $filename);
header("Content-Type: application/msexcel; charset=" . $this->encoding);
header("Content-Disposition: inline; filename=\"" . $filename . ".xlsx\"");
echo $this->__toString();
} | php | public function outputWithHeaders($filename='worksheet')
{
$filename = preg_replace('/[^aA-zZ0-9\_\-]/', '', $filename);
header("Content-Type: application/msexcel; charset=" . $this->encoding);
header("Content-Disposition: inline; filename=\"" . $filename . ".xlsx\"");
echo $this->__toString();
} | [
"public",
"function",
"outputWithHeaders",
"(",
"$",
"filename",
"=",
"'worksheet'",
")",
"{",
"$",
"filename",
"=",
"preg_replace",
"(",
"'/[^aA-zZ0-9\\_\\-]/'",
",",
"''",
",",
"$",
"filename",
")",
";",
"header",
"(",
"\"Content-Type: application/msexcel; charset=\"",
".",
"$",
"this",
"->",
"encoding",
")",
";",
"header",
"(",
"\"Content-Disposition: inline; filename=\\\"\"",
".",
"$",
"filename",
".",
"\".xlsx\\\"\"",
")",
";",
"echo",
"$",
"this",
"->",
"__toString",
"(",
")",
";",
"}"
] | Used to generate the xml with output headers
@param string $filename Name of excel file to generate (...xls) default worksheet.xls | [
"Used",
"to",
"generate",
"the",
"xml",
"with",
"output",
"headers"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Excel/Workbook.php#L242-L249 |
surebert/surebert-framework | src/sb/Excel/Workbook.php | Workbook.getValueType | protected function getValueType($val)
{
$type = 'String';
if ($this->auto_convert_types === true && is_numeric($val)) {
$type = 'Number';
}
return $type;
} | php | protected function getValueType($val)
{
$type = 'String';
if ($this->auto_convert_types === true && is_numeric($val)) {
$type = 'Number';
}
return $type;
} | [
"protected",
"function",
"getValueType",
"(",
"$",
"val",
")",
"{",
"$",
"type",
"=",
"'String'",
";",
"if",
"(",
"$",
"this",
"->",
"auto_convert_types",
"===",
"true",
"&&",
"is_numeric",
"(",
"$",
"val",
")",
")",
"{",
"$",
"type",
"=",
"'Number'",
";",
"}",
"return",
"$",
"type",
";",
"}"
] | Determines value type
@param string $val
@return string | [
"Determines",
"value",
"type"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Excel/Workbook.php#L274-L282 |
surebert/surebert-framework | src/sb/Excel/Workbook.php | Workbook.alphaIndexToNumeric | protected function alphaIndexToNumeric($alpha_index)
{
preg_match("~([A-Z]+)(\d)+~", $alpha_index, $match);
$letters = range('A', 'Z');
$letters = array_flip($letters);
$col_index = 0;
$strlen = strlen($match[1]);
if($strlen== 1){
$col_index += ($letters[$match[1]]+1);
} elseif($strlen > 1){
$arr = str_split($match[1]);
$last = array_pop($arr);
foreach($arr as $letter){
$col_index += ($letters[$letter]+1)*26;
}
$col_index += ($letters[$last]+1);
}
return Array($col_index, $match[2]);
} | php | protected function alphaIndexToNumeric($alpha_index)
{
preg_match("~([A-Z]+)(\d)+~", $alpha_index, $match);
$letters = range('A', 'Z');
$letters = array_flip($letters);
$col_index = 0;
$strlen = strlen($match[1]);
if($strlen== 1){
$col_index += ($letters[$match[1]]+1);
} elseif($strlen > 1){
$arr = str_split($match[1]);
$last = array_pop($arr);
foreach($arr as $letter){
$col_index += ($letters[$letter]+1)*26;
}
$col_index += ($letters[$last]+1);
}
return Array($col_index, $match[2]);
} | [
"protected",
"function",
"alphaIndexToNumeric",
"(",
"$",
"alpha_index",
")",
"{",
"preg_match",
"(",
"\"~([A-Z]+)(\\d)+~\"",
",",
"$",
"alpha_index",
",",
"$",
"match",
")",
";",
"$",
"letters",
"=",
"range",
"(",
"'A'",
",",
"'Z'",
")",
";",
"$",
"letters",
"=",
"array_flip",
"(",
"$",
"letters",
")",
";",
"$",
"col_index",
"=",
"0",
";",
"$",
"strlen",
"=",
"strlen",
"(",
"$",
"match",
"[",
"1",
"]",
")",
";",
"if",
"(",
"$",
"strlen",
"==",
"1",
")",
"{",
"$",
"col_index",
"+=",
"(",
"$",
"letters",
"[",
"$",
"match",
"[",
"1",
"]",
"]",
"+",
"1",
")",
";",
"}",
"elseif",
"(",
"$",
"strlen",
">",
"1",
")",
"{",
"$",
"arr",
"=",
"str_split",
"(",
"$",
"match",
"[",
"1",
"]",
")",
";",
"$",
"last",
"=",
"array_pop",
"(",
"$",
"arr",
")",
";",
"foreach",
"(",
"$",
"arr",
"as",
"$",
"letter",
")",
"{",
"$",
"col_index",
"+=",
"(",
"$",
"letters",
"[",
"$",
"letter",
"]",
"+",
"1",
")",
"*",
"26",
";",
"}",
"$",
"col_index",
"+=",
"(",
"$",
"letters",
"[",
"$",
"last",
"]",
"+",
"1",
")",
";",
"}",
"return",
"Array",
"(",
"$",
"col_index",
",",
"$",
"match",
"[",
"2",
"]",
")",
";",
"}"
] | Converts Alpha column data to numeric indexes
@param string $alpha_index e.g. A1 or AA4
@return array (col, row) | [
"Converts",
"Alpha",
"column",
"data",
"to",
"numeric",
"indexes"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Excel/Workbook.php#L289-L310 |
ronaldborla/chikka | src/Borla/Chikka/Models/Message.php | Message.toSend | public function toSend() {
// Set type
$this->type = static::SEND;
// Refresh
$this->refresh();
// Return array
return [
'message_type' => $this->message_type,
'mobile_number' => $this->mobile_number,
'message_id' => $this->id,
'message' => $this->getMessage(),
];
} | php | public function toSend() {
// Set type
$this->type = static::SEND;
// Refresh
$this->refresh();
// Return array
return [
'message_type' => $this->message_type,
'mobile_number' => $this->mobile_number,
'message_id' => $this->id,
'message' => $this->getMessage(),
];
} | [
"public",
"function",
"toSend",
"(",
")",
"{",
"// Set type",
"$",
"this",
"->",
"type",
"=",
"static",
"::",
"SEND",
";",
"// Refresh",
"$",
"this",
"->",
"refresh",
"(",
")",
";",
"// Return array",
"return",
"[",
"'message_type'",
"=>",
"$",
"this",
"->",
"message_type",
",",
"'mobile_number'",
"=>",
"$",
"this",
"->",
"mobile_number",
",",
"'message_id'",
"=>",
"$",
"this",
"->",
"id",
",",
"'message'",
"=>",
"$",
"this",
"->",
"getMessage",
"(",
")",
",",
"]",
";",
"}"
] | To send | [
"To",
"send"
] | train | https://github.com/ronaldborla/chikka/blob/446987706f81d5a0efbc8bd6b7d3b259d0527719/src/Borla/Chikka/Models/Message.php#L94-L106 |
ronaldborla/chikka | src/Borla/Chikka/Models/Message.php | Message.toReply | public function toReply($adjustCost = true) {
// Set type
$this->type = static::REPLY;
// If to adjust
if ($adjustCost) {
// Do adjust
$this->cost->adjust($this->mobile->carrier);
}
// Refresh
$this->refresh();
// Return array
return [
'message_type' => $this->message_type,
'mobile_number' => $this->mobile_number,
'request_id' => $this->request_id,
'message_id' => $this->id,
'message' => $this->getMessage(),
'request_cost' => $this->request_cost,
];
} | php | public function toReply($adjustCost = true) {
// Set type
$this->type = static::REPLY;
// If to adjust
if ($adjustCost) {
// Do adjust
$this->cost->adjust($this->mobile->carrier);
}
// Refresh
$this->refresh();
// Return array
return [
'message_type' => $this->message_type,
'mobile_number' => $this->mobile_number,
'request_id' => $this->request_id,
'message_id' => $this->id,
'message' => $this->getMessage(),
'request_cost' => $this->request_cost,
];
} | [
"public",
"function",
"toReply",
"(",
"$",
"adjustCost",
"=",
"true",
")",
"{",
"// Set type",
"$",
"this",
"->",
"type",
"=",
"static",
"::",
"REPLY",
";",
"// If to adjust",
"if",
"(",
"$",
"adjustCost",
")",
"{",
"// Do adjust",
"$",
"this",
"->",
"cost",
"->",
"adjust",
"(",
"$",
"this",
"->",
"mobile",
"->",
"carrier",
")",
";",
"}",
"// Refresh",
"$",
"this",
"->",
"refresh",
"(",
")",
";",
"// Return array",
"return",
"[",
"'message_type'",
"=>",
"$",
"this",
"->",
"message_type",
",",
"'mobile_number'",
"=>",
"$",
"this",
"->",
"mobile_number",
",",
"'request_id'",
"=>",
"$",
"this",
"->",
"request_id",
",",
"'message_id'",
"=>",
"$",
"this",
"->",
"id",
",",
"'message'",
"=>",
"$",
"this",
"->",
"getMessage",
"(",
")",
",",
"'request_cost'",
"=>",
"$",
"this",
"->",
"request_cost",
",",
"]",
";",
"}"
] | To reply | [
"To",
"reply"
] | train | https://github.com/ronaldborla/chikka/blob/446987706f81d5a0efbc8bd6b7d3b259d0527719/src/Borla/Chikka/Models/Message.php#L111-L130 |
ronaldborla/chikka | src/Borla/Chikka/Models/Message.php | Message.refresh | protected function refresh() {
// Refresh other attributes
$this->message_id = $this->id;
$this->message_type = $this->getMessageType();
$this->mobile_number = $this->mobile->intl();
$this->request_cost = (string) $this->cost;
} | php | protected function refresh() {
// Refresh other attributes
$this->message_id = $this->id;
$this->message_type = $this->getMessageType();
$this->mobile_number = $this->mobile->intl();
$this->request_cost = (string) $this->cost;
} | [
"protected",
"function",
"refresh",
"(",
")",
"{",
"// Refresh other attributes",
"$",
"this",
"->",
"message_id",
"=",
"$",
"this",
"->",
"id",
";",
"$",
"this",
"->",
"message_type",
"=",
"$",
"this",
"->",
"getMessageType",
"(",
")",
";",
"$",
"this",
"->",
"mobile_number",
"=",
"$",
"this",
"->",
"mobile",
"->",
"intl",
"(",
")",
";",
"$",
"this",
"->",
"request_cost",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"cost",
";",
"}"
] | Refresh | [
"Refresh"
] | train | https://github.com/ronaldborla/chikka/blob/446987706f81d5a0efbc8bd6b7d3b259d0527719/src/Borla/Chikka/Models/Message.php#L135-L141 |
ronaldborla/chikka | src/Borla/Chikka/Models/Message.php | Message.setTypeAttribute | protected function setTypeAttribute($value) {
// If null
if ($value === null) {
// Return null
return null;
}
// If numeric
if (is_int($value) || is_numeric($value)) {
// If not valid
if (isset(static::types()[$value])) {
// Return int value
return (int) $value;
}
}
// Else
else {
// Find
if (($type = array_search(strtolower($value), static::types())) !== false) {
// Return type
return $type;
}
}
// Throw error
throw new InvalidAttribute('Invalid type value: ' . $value);
} | php | protected function setTypeAttribute($value) {
// If null
if ($value === null) {
// Return null
return null;
}
// If numeric
if (is_int($value) || is_numeric($value)) {
// If not valid
if (isset(static::types()[$value])) {
// Return int value
return (int) $value;
}
}
// Else
else {
// Find
if (($type = array_search(strtolower($value), static::types())) !== false) {
// Return type
return $type;
}
}
// Throw error
throw new InvalidAttribute('Invalid type value: ' . $value);
} | [
"protected",
"function",
"setTypeAttribute",
"(",
"$",
"value",
")",
"{",
"// If null",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"// Return null",
"return",
"null",
";",
"}",
"// If numeric",
"if",
"(",
"is_int",
"(",
"$",
"value",
")",
"||",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"// If not valid",
"if",
"(",
"isset",
"(",
"static",
"::",
"types",
"(",
")",
"[",
"$",
"value",
"]",
")",
")",
"{",
"// Return int value",
"return",
"(",
"int",
")",
"$",
"value",
";",
"}",
"}",
"// Else",
"else",
"{",
"// Find ",
"if",
"(",
"(",
"$",
"type",
"=",
"array_search",
"(",
"strtolower",
"(",
"$",
"value",
")",
",",
"static",
"::",
"types",
"(",
")",
")",
")",
"!==",
"false",
")",
"{",
"// Return type",
"return",
"$",
"type",
";",
"}",
"}",
"// Throw error",
"throw",
"new",
"InvalidAttribute",
"(",
"'Invalid type value: '",
".",
"$",
"value",
")",
";",
"}"
] | Set type | [
"Set",
"type"
] | train | https://github.com/ronaldborla/chikka/blob/446987706f81d5a0efbc8bd6b7d3b259d0527719/src/Borla/Chikka/Models/Message.php#L162-L186 |
ronaldborla/chikka | src/Borla/Chikka/Models/Message.php | Message.setMobileAttribute | protected function setMobileAttribute($value) {
// If null
if ($value === null) {
// Return null
return null;
}
// Return mobile
return ($value instanceof Mobile) ? $value : Loader::mobile($value);
} | php | protected function setMobileAttribute($value) {
// If null
if ($value === null) {
// Return null
return null;
}
// Return mobile
return ($value instanceof Mobile) ? $value : Loader::mobile($value);
} | [
"protected",
"function",
"setMobileAttribute",
"(",
"$",
"value",
")",
"{",
"// If null",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"// Return null",
"return",
"null",
";",
"}",
"// Return mobile",
"return",
"(",
"$",
"value",
"instanceof",
"Mobile",
")",
"?",
"$",
"value",
":",
"Loader",
"::",
"mobile",
"(",
"$",
"value",
")",
";",
"}"
] | Set mobile | [
"Set",
"mobile"
] | train | https://github.com/ronaldborla/chikka/blob/446987706f81d5a0efbc8bd6b7d3b259d0527719/src/Borla/Chikka/Models/Message.php#L191-L199 |
ronaldborla/chikka | src/Borla/Chikka/Models/Message.php | Message.getMessageType | public function getMessageType() {
// Get message type
$messageType = static::types()[$this->type];
// If not incoming
if ($this->type != static::INCOMING) {
// Change to uppercase
$messageType = strtoupper($messageType);
}
// Return
return $messageType;
} | php | public function getMessageType() {
// Get message type
$messageType = static::types()[$this->type];
// If not incoming
if ($this->type != static::INCOMING) {
// Change to uppercase
$messageType = strtoupper($messageType);
}
// Return
return $messageType;
} | [
"public",
"function",
"getMessageType",
"(",
")",
"{",
"// Get message type",
"$",
"messageType",
"=",
"static",
"::",
"types",
"(",
")",
"[",
"$",
"this",
"->",
"type",
"]",
";",
"// If not incoming",
"if",
"(",
"$",
"this",
"->",
"type",
"!=",
"static",
"::",
"INCOMING",
")",
"{",
"// Change to uppercase",
"$",
"messageType",
"=",
"strtoupper",
"(",
"$",
"messageType",
")",
";",
"}",
"// Return",
"return",
"$",
"messageType",
";",
"}"
] | Get message type | [
"Get",
"message",
"type"
] | train | https://github.com/ronaldborla/chikka/blob/446987706f81d5a0efbc8bd6b7d3b259d0527719/src/Borla/Chikka/Models/Message.php#L249-L259 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.