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
|
---|---|---|---|---|---|---|---|---|---|---|
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/xml/reader.php | ezcDbSchemaXmlReader.parseDiffXml | private function parseDiffXml( SimpleXMLElement $xml )
{
$newTables = array();
foreach ( $xml->{'new-tables'}->table as $table )
{
$tableName = (string) $table->name;
$newTables[$tableName] = $this->parseTable( $table );
}
$changedTables = array();
foreach ( $xml->{'changed-tables'}->table as $table )
{
$tableName = (string) $table->name;
$changedTables[$tableName] = $this->parseChangedTable( $table );
}
$removedTables = array();
foreach ( $xml->{'removed-tables'}->table as $table )
{
$tableName = (string) $table->name;
if ( (string) $table->removed == 'true' )
{
$removedTables[$tableName] = true;
}
}
return new ezcDbSchemaDiff( $newTables, $changedTables, $removedTables );
} | php | private function parseDiffXml( SimpleXMLElement $xml )
{
$newTables = array();
foreach ( $xml->{'new-tables'}->table as $table )
{
$tableName = (string) $table->name;
$newTables[$tableName] = $this->parseTable( $table );
}
$changedTables = array();
foreach ( $xml->{'changed-tables'}->table as $table )
{
$tableName = (string) $table->name;
$changedTables[$tableName] = $this->parseChangedTable( $table );
}
$removedTables = array();
foreach ( $xml->{'removed-tables'}->table as $table )
{
$tableName = (string) $table->name;
if ( (string) $table->removed == 'true' )
{
$removedTables[$tableName] = true;
}
}
return new ezcDbSchemaDiff( $newTables, $changedTables, $removedTables );
} | [
"private",
"function",
"parseDiffXml",
"(",
"SimpleXMLElement",
"$",
"xml",
")",
"{",
"$",
"newTables",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"xml",
"->",
"{",
"'new-tables'",
"}",
"->",
"table",
"as",
"$",
"table",
")",
"{",
"$",
"tableName",
"=",
"(",
"string",
")",
"$",
"table",
"->",
"name",
";",
"$",
"newTables",
"[",
"$",
"tableName",
"]",
"=",
"$",
"this",
"->",
"parseTable",
"(",
"$",
"table",
")",
";",
"}",
"$",
"changedTables",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"xml",
"->",
"{",
"'changed-tables'",
"}",
"->",
"table",
"as",
"$",
"table",
")",
"{",
"$",
"tableName",
"=",
"(",
"string",
")",
"$",
"table",
"->",
"name",
";",
"$",
"changedTables",
"[",
"$",
"tableName",
"]",
"=",
"$",
"this",
"->",
"parseChangedTable",
"(",
"$",
"table",
")",
";",
"}",
"$",
"removedTables",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"xml",
"->",
"{",
"'removed-tables'",
"}",
"->",
"table",
"as",
"$",
"table",
")",
"{",
"$",
"tableName",
"=",
"(",
"string",
")",
"$",
"table",
"->",
"name",
";",
"if",
"(",
"(",
"string",
")",
"$",
"table",
"->",
"removed",
"==",
"'true'",
")",
"{",
"$",
"removedTables",
"[",
"$",
"tableName",
"]",
"=",
"true",
";",
"}",
"}",
"return",
"new",
"ezcDbSchemaDiff",
"(",
"$",
"newTables",
",",
"$",
"changedTables",
",",
"$",
"removedTables",
")",
";",
"}"
] | Returns the schema differences definition in $xml as an ezcDbSchemaDiff
@param SimpleXMLElement $xml
@return ezcDbSchemaDiff | [
"Returns",
"the",
"schema",
"differences",
"definition",
"in",
"$xml",
"as",
"an",
"ezcDbSchemaDiff"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/xml/reader.php#L206-L233 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/xml/reader.php | ezcDbSchemaXmlReader.openXmlFile | private function openXmlFile( $file )
{
if ( !file_exists( $file ) )
{
throw new ezcBaseFileNotFoundException( $file, 'schema' );
}
$xml = @simplexml_load_file( $file );
if ( !$xml )
{
throw new ezcDbSchemaInvalidSchemaException( "The schema file '{$file}' is not valid XML." );
}
return $xml;
} | php | private function openXmlFile( $file )
{
if ( !file_exists( $file ) )
{
throw new ezcBaseFileNotFoundException( $file, 'schema' );
}
$xml = @simplexml_load_file( $file );
if ( !$xml )
{
throw new ezcDbSchemaInvalidSchemaException( "The schema file '{$file}' is not valid XML." );
}
return $xml;
} | [
"private",
"function",
"openXmlFile",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"ezcBaseFileNotFoundException",
"(",
"$",
"file",
",",
"'schema'",
")",
";",
"}",
"$",
"xml",
"=",
"@",
"simplexml_load_file",
"(",
"$",
"file",
")",
";",
"if",
"(",
"!",
"$",
"xml",
")",
"{",
"throw",
"new",
"ezcDbSchemaInvalidSchemaException",
"(",
"\"The schema file '{$file}' is not valid XML.\"",
")",
";",
"}",
"return",
"$",
"xml",
";",
"}"
] | Opens the XML file $file for parsing
@param string $file
@throws ezcBaseFileNotFoundException if the file $file could not be
found.
@throws ezcDbSchemaInvalidSchemaException if the XML in the $file is
corrupted or when the file could not be opened.
@return SimpleXML | [
"Opens",
"the",
"XML",
"file",
"$file",
"for",
"parsing"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/xml/reader.php#L245-L259 |
technote-space/wordpress-plugin-base | src/classes/models/lib/custom_post.php | Custom_Post.get_post_type_by_slug | public function get_post_type_by_slug( $slug ) {
if ( ! isset( $this->_custom_posts_mapper[ $slug ] ) ) {
return null;
}
return $this->get_custom_post_type( $this->_custom_posts_mapper[ $slug ] );
} | php | public function get_post_type_by_slug( $slug ) {
if ( ! isset( $this->_custom_posts_mapper[ $slug ] ) ) {
return null;
}
return $this->get_custom_post_type( $this->_custom_posts_mapper[ $slug ] );
} | [
"public",
"function",
"get_post_type_by_slug",
"(",
"$",
"slug",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_custom_posts_mapper",
"[",
"$",
"slug",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"get_custom_post_type",
"(",
"$",
"this",
"->",
"_custom_posts_mapper",
"[",
"$",
"slug",
"]",
")",
";",
"}"
] | @param string $slug
@return \Technote\Interfaces\Helper\Custom_Post|null | [
"@param",
"string",
"$slug"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/custom_post.php#L563-L569 |
technote-space/wordpress-plugin-base | src/classes/models/lib/custom_post.php | Custom_Post.get_custom_post_type | public function get_custom_post_type( $post_type ) {
if ( ! $this->is_valid_custom_post_type( $post_type ) ) {
return null;
}
$custom_posts = $this->get_custom_posts();
return $custom_posts[ $post_type ];
} | php | public function get_custom_post_type( $post_type ) {
if ( ! $this->is_valid_custom_post_type( $post_type ) ) {
return null;
}
$custom_posts = $this->get_custom_posts();
return $custom_posts[ $post_type ];
} | [
"public",
"function",
"get_custom_post_type",
"(",
"$",
"post_type",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"is_valid_custom_post_type",
"(",
"$",
"post_type",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"custom_posts",
"=",
"$",
"this",
"->",
"get_custom_posts",
"(",
")",
";",
"return",
"$",
"custom_posts",
"[",
"$",
"post_type",
"]",
";",
"}"
] | @param string $post_type
@return \Technote\Interfaces\Helper\Custom_Post|null | [
"@param",
"string",
"$post_type"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/custom_post.php#L587-L595 |
technote-space/wordpress-plugin-base | src/classes/models/lib/custom_post.php | Custom_Post.is_valid_update | private function is_valid_update( $post_status, $post_type ) {
return ! $this->app->utility->defined( 'DOING_AUTOSAVE' ) && in_array( $post_status, [
'publish',
'future',
'draft',
'draft',
'pending',
'private',
] ) && $this->is_valid_custom_post_type( $post_type ) && 'untrash' !== $this->app->input->get( 'action' );
} | php | private function is_valid_update( $post_status, $post_type ) {
return ! $this->app->utility->defined( 'DOING_AUTOSAVE' ) && in_array( $post_status, [
'publish',
'future',
'draft',
'draft',
'pending',
'private',
] ) && $this->is_valid_custom_post_type( $post_type ) && 'untrash' !== $this->app->input->get( 'action' );
} | [
"private",
"function",
"is_valid_update",
"(",
"$",
"post_status",
",",
"$",
"post_type",
")",
"{",
"return",
"!",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"defined",
"(",
"'DOING_AUTOSAVE'",
")",
"&&",
"in_array",
"(",
"$",
"post_status",
",",
"[",
"'publish'",
",",
"'future'",
",",
"'draft'",
",",
"'draft'",
",",
"'pending'",
",",
"'private'",
",",
"]",
")",
"&&",
"$",
"this",
"->",
"is_valid_custom_post_type",
"(",
"$",
"post_type",
")",
"&&",
"'untrash'",
"!==",
"$",
"this",
"->",
"app",
"->",
"input",
"->",
"get",
"(",
"'action'",
")",
";",
"}"
] | @since 2.9.4 Fixed: exclude untrash
@param string $post_status
@param string $post_type
@return bool | [
"@since",
"2",
".",
"9",
".",
"4",
"Fixed",
":",
"exclude",
"untrash"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/custom_post.php#L605-L614 |
technote-space/wordpress-plugin-base | src/classes/models/lib/custom_post.php | Custom_Post.uninstall | public function uninstall() {
/** @var \wpdb $wpdb */
global $wpdb;
foreach ( $this->get_custom_post_types() as $post_type ) {
$posts = $this->app->db->select( $wpdb->posts, [
'post_type' => $post_type,
] );
if ( ! empty( $posts ) ) {
foreach ( $posts as $post ) {
wp_delete_post( $post['id'] );
}
}
}
} | php | public function uninstall() {
/** @var \wpdb $wpdb */
global $wpdb;
foreach ( $this->get_custom_post_types() as $post_type ) {
$posts = $this->app->db->select( $wpdb->posts, [
'post_type' => $post_type,
] );
if ( ! empty( $posts ) ) {
foreach ( $posts as $post ) {
wp_delete_post( $post['id'] );
}
}
}
} | [
"public",
"function",
"uninstall",
"(",
")",
"{",
"/** @var \\wpdb $wpdb */",
"global",
"$",
"wpdb",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_custom_post_types",
"(",
")",
"as",
"$",
"post_type",
")",
"{",
"$",
"posts",
"=",
"$",
"this",
"->",
"app",
"->",
"db",
"->",
"select",
"(",
"$",
"wpdb",
"->",
"posts",
",",
"[",
"'post_type'",
"=>",
"$",
"post_type",
",",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"posts",
")",
")",
"{",
"foreach",
"(",
"$",
"posts",
"as",
"$",
"post",
")",
"{",
"wp_delete_post",
"(",
"$",
"post",
"[",
"'id'",
"]",
")",
";",
"}",
"}",
"}",
"}"
] | delete posts | [
"delete",
"posts"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/custom_post.php#L626-L639 |
jasny/codeception-module | src/RequestConvertor.php | RequestConvertor.createStream | protected function createStream(BrowserKitRequest $request)
{
$stream = fopen('php://temp', 'a+');
fwrite($stream, $request->getContent());
return new Stream($stream);
} | php | protected function createStream(BrowserKitRequest $request)
{
$stream = fopen('php://temp', 'a+');
fwrite($stream, $request->getContent());
return new Stream($stream);
} | [
"protected",
"function",
"createStream",
"(",
"BrowserKitRequest",
"$",
"request",
")",
"{",
"$",
"stream",
"=",
"fopen",
"(",
"'php://temp'",
",",
"'a+'",
")",
";",
"fwrite",
"(",
"$",
"stream",
",",
"$",
"request",
"->",
"getContent",
"(",
")",
")",
";",
"return",
"new",
"Stream",
"(",
"$",
"stream",
")",
";",
"}"
] | Create the output stream handle
@param BrowserKitRequest $request
@return Stream | [
"Create",
"the",
"output",
"stream",
"handle"
] | train | https://github.com/jasny/codeception-module/blob/5c2b12e4ab291f26424fda9fbf1618c818bc8d6e/src/RequestConvertor.php#L25-L31 |
jasny/codeception-module | src/RequestConvertor.php | RequestConvertor.buildFullUri | protected function buildFullUri(BrowserKitRequest $request)
{
$uri = new Uri($request->getUri());
$queryParams = [];
parse_str($uri->getQuery(), $queryParams);
if ($request->getMethod() === 'GET') {
$queryParams = array_merge($queryParams, $request->getParameters());
$uri = $uri->withQuery(http_build_query($queryParams));
}
return [$uri, $queryParams];
} | php | protected function buildFullUri(BrowserKitRequest $request)
{
$uri = new Uri($request->getUri());
$queryParams = [];
parse_str($uri->getQuery(), $queryParams);
if ($request->getMethod() === 'GET') {
$queryParams = array_merge($queryParams, $request->getParameters());
$uri = $uri->withQuery(http_build_query($queryParams));
}
return [$uri, $queryParams];
} | [
"protected",
"function",
"buildFullUri",
"(",
"BrowserKitRequest",
"$",
"request",
")",
"{",
"$",
"uri",
"=",
"new",
"Uri",
"(",
"$",
"request",
"->",
"getUri",
"(",
")",
")",
";",
"$",
"queryParams",
"=",
"[",
"]",
";",
"parse_str",
"(",
"$",
"uri",
"->",
"getQuery",
"(",
")",
",",
"$",
"queryParams",
")",
";",
"if",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
"===",
"'GET'",
")",
"{",
"$",
"queryParams",
"=",
"array_merge",
"(",
"$",
"queryParams",
",",
"$",
"request",
"->",
"getParameters",
"(",
")",
")",
";",
"$",
"uri",
"=",
"$",
"uri",
"->",
"withQuery",
"(",
"http_build_query",
"(",
"$",
"queryParams",
")",
")",
";",
"}",
"return",
"[",
"$",
"uri",
",",
"$",
"queryParams",
"]",
";",
"}"
] | Build a full URI from a request
@param BrowserKitRequest $request
@return array [Uri, queryParams] | [
"Build",
"a",
"full",
"URI",
"from",
"a",
"request"
] | train | https://github.com/jasny/codeception-module/blob/5c2b12e4ab291f26424fda9fbf1618c818bc8d6e/src/RequestConvertor.php#L39-L52 |
jasny/codeception-module | src/RequestConvertor.php | RequestConvertor.setRequestHeaders | protected function setRequestHeaders(ServerRequestInterface $baseRequest, array $params)
{
$headers = (new ServerRequest())->withServerParams($params)->getHeaders();
$psrRequest = $baseRequest;
foreach ($headers as $header => $values) {
$psrRequest = $psrRequest->withHeader($header, $values);
}
return $psrRequest;
} | php | protected function setRequestHeaders(ServerRequestInterface $baseRequest, array $params)
{
$headers = (new ServerRequest())->withServerParams($params)->getHeaders();
$psrRequest = $baseRequest;
foreach ($headers as $header => $values) {
$psrRequest = $psrRequest->withHeader($header, $values);
}
return $psrRequest;
} | [
"protected",
"function",
"setRequestHeaders",
"(",
"ServerRequestInterface",
"$",
"baseRequest",
",",
"array",
"$",
"params",
")",
"{",
"$",
"headers",
"=",
"(",
"new",
"ServerRequest",
"(",
")",
")",
"->",
"withServerParams",
"(",
"$",
"params",
")",
"->",
"getHeaders",
"(",
")",
";",
"$",
"psrRequest",
"=",
"$",
"baseRequest",
";",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"header",
"=>",
"$",
"values",
")",
"{",
"$",
"psrRequest",
"=",
"$",
"psrRequest",
"->",
"withHeader",
"(",
"$",
"header",
",",
"$",
"values",
")",
";",
"}",
"return",
"$",
"psrRequest",
";",
"}"
] | Set the request headers
@param ServerRequestInterface $baseRequest
@param array $params
@retrun ServerRequestInterface | [
"Set",
"the",
"request",
"headers"
] | train | https://github.com/jasny/codeception-module/blob/5c2b12e4ab291f26424fda9fbf1618c818bc8d6e/src/RequestConvertor.php#L61-L71 |
jasny/codeception-module | src/RequestConvertor.php | RequestConvertor.determineServerParams | protected function determineServerParams(BrowserKitRequest $request, UriInterface $uri, array $queryParams)
{
return [
'REQUEST_METHOD' => $request->getMethod(),
'QUERY_STRING' => http_build_query($queryParams),
'REQUEST_URI' => (string)($uri->withScheme('')->withHost('')->withPort('')->withUserInfo(''))
];
} | php | protected function determineServerParams(BrowserKitRequest $request, UriInterface $uri, array $queryParams)
{
return [
'REQUEST_METHOD' => $request->getMethod(),
'QUERY_STRING' => http_build_query($queryParams),
'REQUEST_URI' => (string)($uri->withScheme('')->withHost('')->withPort('')->withUserInfo(''))
];
} | [
"protected",
"function",
"determineServerParams",
"(",
"BrowserKitRequest",
"$",
"request",
",",
"UriInterface",
"$",
"uri",
",",
"array",
"$",
"queryParams",
")",
"{",
"return",
"[",
"'REQUEST_METHOD'",
"=>",
"$",
"request",
"->",
"getMethod",
"(",
")",
",",
"'QUERY_STRING'",
"=>",
"http_build_query",
"(",
"$",
"queryParams",
")",
",",
"'REQUEST_URI'",
"=>",
"(",
"string",
")",
"(",
"$",
"uri",
"->",
"withScheme",
"(",
"''",
")",
"->",
"withHost",
"(",
"''",
")",
"->",
"withPort",
"(",
"''",
")",
"->",
"withUserInfo",
"(",
"''",
")",
")",
"]",
";",
"}"
] | Get additional server params from request.
@internal It would be nicer if this was solved by Jasny Http Message
@param BrowserKitRequest $request
@param UriInterface $uri
@param array $queryParams
@return array | [
"Get",
"additional",
"server",
"params",
"from",
"request",
".",
"@internal",
"It",
"would",
"be",
"nicer",
"if",
"this",
"was",
"solved",
"by",
"Jasny",
"Http",
"Message"
] | train | https://github.com/jasny/codeception-module/blob/5c2b12e4ab291f26424fda9fbf1618c818bc8d6e/src/RequestConvertor.php#L82-L89 |
jasny/codeception-module | src/RequestConvertor.php | RequestConvertor.setRequestProperties | protected function setRequestProperties(
ServerRequestInterface $baseRequest,
BrowserKitRequest $request,
Stream $stream,
UriInterface $uri,
array $queryParams
) {
return $baseRequest
->withProtocolVersion('1.1')
->withBody($stream)
->withMethod($request->getMethod())
->withRequestTarget((string)($uri->withScheme('')->withHost('')->withPort('')->withUserInfo('')))
->withCookieParams($request->getCookies())
->withUri($uri)
->withQueryParams($queryParams)
->withParsedBody($request->getMethod() !== 'GET' && !empty($request->getParameters())
? $request->getParameters() : null)
->withUploadedFiles($this->convertUploadedFiles($request->getFiles()));
} | php | protected function setRequestProperties(
ServerRequestInterface $baseRequest,
BrowserKitRequest $request,
Stream $stream,
UriInterface $uri,
array $queryParams
) {
return $baseRequest
->withProtocolVersion('1.1')
->withBody($stream)
->withMethod($request->getMethod())
->withRequestTarget((string)($uri->withScheme('')->withHost('')->withPort('')->withUserInfo('')))
->withCookieParams($request->getCookies())
->withUri($uri)
->withQueryParams($queryParams)
->withParsedBody($request->getMethod() !== 'GET' && !empty($request->getParameters())
? $request->getParameters() : null)
->withUploadedFiles($this->convertUploadedFiles($request->getFiles()));
} | [
"protected",
"function",
"setRequestProperties",
"(",
"ServerRequestInterface",
"$",
"baseRequest",
",",
"BrowserKitRequest",
"$",
"request",
",",
"Stream",
"$",
"stream",
",",
"UriInterface",
"$",
"uri",
",",
"array",
"$",
"queryParams",
")",
"{",
"return",
"$",
"baseRequest",
"->",
"withProtocolVersion",
"(",
"'1.1'",
")",
"->",
"withBody",
"(",
"$",
"stream",
")",
"->",
"withMethod",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
")",
"->",
"withRequestTarget",
"(",
"(",
"string",
")",
"(",
"$",
"uri",
"->",
"withScheme",
"(",
"''",
")",
"->",
"withHost",
"(",
"''",
")",
"->",
"withPort",
"(",
"''",
")",
"->",
"withUserInfo",
"(",
"''",
")",
")",
")",
"->",
"withCookieParams",
"(",
"$",
"request",
"->",
"getCookies",
"(",
")",
")",
"->",
"withUri",
"(",
"$",
"uri",
")",
"->",
"withQueryParams",
"(",
"$",
"queryParams",
")",
"->",
"withParsedBody",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
"!==",
"'GET'",
"&&",
"!",
"empty",
"(",
"$",
"request",
"->",
"getParameters",
"(",
")",
")",
"?",
"$",
"request",
"->",
"getParameters",
"(",
")",
":",
"null",
")",
"->",
"withUploadedFiles",
"(",
"$",
"this",
"->",
"convertUploadedFiles",
"(",
"$",
"request",
"->",
"getFiles",
"(",
")",
")",
")",
";",
"}"
] | Set the server request properties
@param ServerRequestInterface $baseRequest
@param BrowserKitRequest $request
@param Stream $stream
@param UriInterface $uri
@param array $queryParams
@return ServerRequestInterface | [
"Set",
"the",
"server",
"request",
"properties"
] | train | https://github.com/jasny/codeception-module/blob/5c2b12e4ab291f26424fda9fbf1618c818bc8d6e/src/RequestConvertor.php#L101-L119 |
jasny/codeception-module | src/RequestConvertor.php | RequestConvertor.convertUploadedFiles | protected function convertUploadedFiles(array $files)
{
$fileObjects = [];
foreach ($files as $fieldName => $file) {
if ($file instanceof UploadedFileInterface) {
$fileObjects[$fieldName] = $file;
} elseif (!isset($file['tmp_name']) && !isset($file['error'])) {
$fileObjects[$fieldName] = $this->convertUploadedFiles($file);
} else {
$fileObjects[$fieldName] = new UploadedFile($file);
}
}
return $fileObjects;
} | php | protected function convertUploadedFiles(array $files)
{
$fileObjects = [];
foreach ($files as $fieldName => $file) {
if ($file instanceof UploadedFileInterface) {
$fileObjects[$fieldName] = $file;
} elseif (!isset($file['tmp_name']) && !isset($file['error'])) {
$fileObjects[$fieldName] = $this->convertUploadedFiles($file);
} else {
$fileObjects[$fieldName] = new UploadedFile($file);
}
}
return $fileObjects;
} | [
"protected",
"function",
"convertUploadedFiles",
"(",
"array",
"$",
"files",
")",
"{",
"$",
"fileObjects",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"fieldName",
"=>",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"instanceof",
"UploadedFileInterface",
")",
"{",
"$",
"fileObjects",
"[",
"$",
"fieldName",
"]",
"=",
"$",
"file",
";",
"}",
"elseif",
"(",
"!",
"isset",
"(",
"$",
"file",
"[",
"'tmp_name'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"file",
"[",
"'error'",
"]",
")",
")",
"{",
"$",
"fileObjects",
"[",
"$",
"fieldName",
"]",
"=",
"$",
"this",
"->",
"convertUploadedFiles",
"(",
"$",
"file",
")",
";",
"}",
"else",
"{",
"$",
"fileObjects",
"[",
"$",
"fieldName",
"]",
"=",
"new",
"UploadedFile",
"(",
"$",
"file",
")",
";",
"}",
"}",
"return",
"$",
"fileObjects",
";",
"}"
] | Convert a list of uploaded files to a Jasny PSR-7 uploaded files
@param array $files
@return UploadedFile[]|array | [
"Convert",
"a",
"list",
"of",
"uploaded",
"files",
"to",
"a",
"Jasny",
"PSR",
"-",
"7",
"uploaded",
"files"
] | train | https://github.com/jasny/codeception-module/blob/5c2b12e4ab291f26424fda9fbf1618c818bc8d6e/src/RequestConvertor.php#L127-L142 |
jasny/codeception-module | src/RequestConvertor.php | RequestConvertor.convert | public function convert(BrowserKitRequest $request, ServerRequestInterface $baseRequest)
{
$stream = $this->createStream($request);
list($uri, $queryParams) = $this->buildFullUri($request);
if ($baseRequest instanceof ServerRequest) {
$serverParams = $this->determineServerParams($request, $uri, (array)$queryParams);
$psrRequest = $baseRequest->withServerParams($request->getServer() + $serverParams);
} else {
$psrRequest = $this->setRequestHeaders($baseRequest, $request->getServer());
}
return $this->setRequestProperties($psrRequest, $request, $stream, $uri, (array)$queryParams);
} | php | public function convert(BrowserKitRequest $request, ServerRequestInterface $baseRequest)
{
$stream = $this->createStream($request);
list($uri, $queryParams) = $this->buildFullUri($request);
if ($baseRequest instanceof ServerRequest) {
$serverParams = $this->determineServerParams($request, $uri, (array)$queryParams);
$psrRequest = $baseRequest->withServerParams($request->getServer() + $serverParams);
} else {
$psrRequest = $this->setRequestHeaders($baseRequest, $request->getServer());
}
return $this->setRequestProperties($psrRequest, $request, $stream, $uri, (array)$queryParams);
} | [
"public",
"function",
"convert",
"(",
"BrowserKitRequest",
"$",
"request",
",",
"ServerRequestInterface",
"$",
"baseRequest",
")",
"{",
"$",
"stream",
"=",
"$",
"this",
"->",
"createStream",
"(",
"$",
"request",
")",
";",
"list",
"(",
"$",
"uri",
",",
"$",
"queryParams",
")",
"=",
"$",
"this",
"->",
"buildFullUri",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"baseRequest",
"instanceof",
"ServerRequest",
")",
"{",
"$",
"serverParams",
"=",
"$",
"this",
"->",
"determineServerParams",
"(",
"$",
"request",
",",
"$",
"uri",
",",
"(",
"array",
")",
"$",
"queryParams",
")",
";",
"$",
"psrRequest",
"=",
"$",
"baseRequest",
"->",
"withServerParams",
"(",
"$",
"request",
"->",
"getServer",
"(",
")",
"+",
"$",
"serverParams",
")",
";",
"}",
"else",
"{",
"$",
"psrRequest",
"=",
"$",
"this",
"->",
"setRequestHeaders",
"(",
"$",
"baseRequest",
",",
"$",
"request",
"->",
"getServer",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setRequestProperties",
"(",
"$",
"psrRequest",
",",
"$",
"request",
",",
"$",
"stream",
",",
"$",
"uri",
",",
"(",
"array",
")",
"$",
"queryParams",
")",
";",
"}"
] | Convert a codeception request to a PSR-7 server request
@param BrowserKitRequest $request
@param ServerRequestInterface $baseRequest
@return ServerRequest | [
"Convert",
"a",
"codeception",
"request",
"to",
"a",
"PSR",
"-",
"7",
"server",
"request"
] | train | https://github.com/jasny/codeception-module/blob/5c2b12e4ab291f26424fda9fbf1618c818bc8d6e/src/RequestConvertor.php#L152-L165 |
inhere/php-librarys | src/Helpers/PhpException.php | PhpException.toHtml | public static function toHtml($e, $getTrace = true, $catcher = null, $clearHtml = false): string
{
if (!$getTrace) {
$message = "Error: {$e->getMessage()}";
} else {
$message = sprintf(
"<h3>%s(%d): %s</h3>\n<pre><strong>File: %s(Line %d)</strong>%s \n\n%s</pre>",
\get_class($e),
$e->getCode(),
$e->getMessage(),
$e->getFile(),
$e->getLine(),
$catcher ? "\nCatch By: $catcher" : '',
$e->getTraceAsString()
);
}
return $clearHtml ? strip_tags($message) : "<div class=\"exception-box\">{$message}</div>";
} | php | public static function toHtml($e, $getTrace = true, $catcher = null, $clearHtml = false): string
{
if (!$getTrace) {
$message = "Error: {$e->getMessage()}";
} else {
$message = sprintf(
"<h3>%s(%d): %s</h3>\n<pre><strong>File: %s(Line %d)</strong>%s \n\n%s</pre>",
\get_class($e),
$e->getCode(),
$e->getMessage(),
$e->getFile(),
$e->getLine(),
$catcher ? "\nCatch By: $catcher" : '',
$e->getTraceAsString()
);
}
return $clearHtml ? strip_tags($message) : "<div class=\"exception-box\">{$message}</div>";
} | [
"public",
"static",
"function",
"toHtml",
"(",
"$",
"e",
",",
"$",
"getTrace",
"=",
"true",
",",
"$",
"catcher",
"=",
"null",
",",
"$",
"clearHtml",
"=",
"false",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"getTrace",
")",
"{",
"$",
"message",
"=",
"\"Error: {$e->getMessage()}\"",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"\"<h3>%s(%d): %s</h3>\\n<pre><strong>File: %s(Line %d)</strong>%s \\n\\n%s</pre>\"",
",",
"\\",
"get_class",
"(",
"$",
"e",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getFile",
"(",
")",
",",
"$",
"e",
"->",
"getLine",
"(",
")",
",",
"$",
"catcher",
"?",
"\"\\nCatch By: $catcher\"",
":",
"''",
",",
"$",
"e",
"->",
"getTraceAsString",
"(",
")",
")",
";",
"}",
"return",
"$",
"clearHtml",
"?",
"strip_tags",
"(",
"$",
"message",
")",
":",
"\"<div class=\\\"exception-box\\\">{$message}</div>\"",
";",
"}"
] | Converts an exception into a simple string.
@param \Exception|\Throwable $e the exception being converted
@param bool $clearHtml
@param bool $getTrace
@param null|string $catcher
@return string the string representation of the exception. | [
"Converts",
"an",
"exception",
"into",
"a",
"simple",
"string",
"."
] | train | https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Helpers/PhpException.php#L34-L52 |
inhere/php-librarys | src/Helpers/PhpException.php | PhpException.toArray | public static function toArray($e, $getTrace = true, $catcher = null)
{
$data = [
'class' => \get_class($e),
'message' => $e->getMessage(),
'code' => $e->getCode(),
'file' => $e->getFile() . ':' . $e->getLine(),
];
if ($catcher) {
$data['catcher'] = $catcher;
}
if ($getTrace) {
$data['trace'] = $e->getTrace();
}
return $data;
} | php | public static function toArray($e, $getTrace = true, $catcher = null)
{
$data = [
'class' => \get_class($e),
'message' => $e->getMessage(),
'code' => $e->getCode(),
'file' => $e->getFile() . ':' . $e->getLine(),
];
if ($catcher) {
$data['catcher'] = $catcher;
}
if ($getTrace) {
$data['trace'] = $e->getTrace();
}
return $data;
} | [
"public",
"static",
"function",
"toArray",
"(",
"$",
"e",
",",
"$",
"getTrace",
"=",
"true",
",",
"$",
"catcher",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"[",
"'class'",
"=>",
"\\",
"get_class",
"(",
"$",
"e",
")",
",",
"'message'",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"'code'",
"=>",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"'file'",
"=>",
"$",
"e",
"->",
"getFile",
"(",
")",
".",
"':'",
".",
"$",
"e",
"->",
"getLine",
"(",
")",
",",
"]",
";",
"if",
"(",
"$",
"catcher",
")",
"{",
"$",
"data",
"[",
"'catcher'",
"]",
"=",
"$",
"catcher",
";",
"}",
"if",
"(",
"$",
"getTrace",
")",
"{",
"$",
"data",
"[",
"'trace'",
"]",
"=",
"$",
"e",
"->",
"getTrace",
"(",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Converts an exception into a simple array.
@param \Exception|\Throwable $e the exception being converted
@param bool $getTrace
@param null|string $catcher
@return array | [
"Converts",
"an",
"exception",
"into",
"a",
"simple",
"array",
"."
] | train | https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Helpers/PhpException.php#L61-L79 |
php-lug/lug | src/Bundle/GridBundle/Model/Builder/FilterBuilder.php | FilterBuilder.build | public function build(array $config)
{
return new Filter(
$this->buildName($config),
$this->buildLabel($config),
$this->buildType($config),
$this->buildForm($config),
$this->buildFormOptions($config),
$this->buildOptions($config)
);
} | php | public function build(array $config)
{
return new Filter(
$this->buildName($config),
$this->buildLabel($config),
$this->buildType($config),
$this->buildForm($config),
$this->buildFormOptions($config),
$this->buildOptions($config)
);
} | [
"public",
"function",
"build",
"(",
"array",
"$",
"config",
")",
"{",
"return",
"new",
"Filter",
"(",
"$",
"this",
"->",
"buildName",
"(",
"$",
"config",
")",
",",
"$",
"this",
"->",
"buildLabel",
"(",
"$",
"config",
")",
",",
"$",
"this",
"->",
"buildType",
"(",
"$",
"config",
")",
",",
"$",
"this",
"->",
"buildForm",
"(",
"$",
"config",
")",
",",
"$",
"this",
"->",
"buildFormOptions",
"(",
"$",
"config",
")",
",",
"$",
"this",
"->",
"buildOptions",
"(",
"$",
"config",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Model/Builder/FilterBuilder.php#L40-L50 |
php-lug/lug | src/Bundle/GridBundle/Model/Builder/FilterBuilder.php | FilterBuilder.buildForm | protected function buildForm(array $config)
{
return isset($config['form'])
? $config['form']
: ClassUtils::getClass($this->filterFormRegistry[$this->buildType($config)]);
} | php | protected function buildForm(array $config)
{
return isset($config['form'])
? $config['form']
: ClassUtils::getClass($this->filterFormRegistry[$this->buildType($config)]);
} | [
"protected",
"function",
"buildForm",
"(",
"array",
"$",
"config",
")",
"{",
"return",
"isset",
"(",
"$",
"config",
"[",
"'form'",
"]",
")",
"?",
"$",
"config",
"[",
"'form'",
"]",
":",
"ClassUtils",
"::",
"getClass",
"(",
"$",
"this",
"->",
"filterFormRegistry",
"[",
"$",
"this",
"->",
"buildType",
"(",
"$",
"config",
")",
"]",
")",
";",
"}"
] | @param mixed[] $config
@return string | [
"@param",
"mixed",
"[]",
"$config"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Model/Builder/FilterBuilder.php#L57-L62 |
blesta/composer-installer | src/Installer.php | Installer.getInstallPath | public function getInstallPath(PackageInterface $package)
{
$type = $package->getType();
$supportedType = $this->supportedType($type);
if ($supportedType === false) {
throw new InvalidArgumentException(
'Sorry the package type of this package is not supported.'
);
}
$class = 'Blesta\\Composer\\Installer\\' . $this->supportedTypes[$supportedType];
$installer = new $class($package, $this->composer, $this->io);
return $installer->getInstallPath($package, $supportedType);
} | php | public function getInstallPath(PackageInterface $package)
{
$type = $package->getType();
$supportedType = $this->supportedType($type);
if ($supportedType === false) {
throw new InvalidArgumentException(
'Sorry the package type of this package is not supported.'
);
}
$class = 'Blesta\\Composer\\Installer\\' . $this->supportedTypes[$supportedType];
$installer = new $class($package, $this->composer, $this->io);
return $installer->getInstallPath($package, $supportedType);
} | [
"public",
"function",
"getInstallPath",
"(",
"PackageInterface",
"$",
"package",
")",
"{",
"$",
"type",
"=",
"$",
"package",
"->",
"getType",
"(",
")",
";",
"$",
"supportedType",
"=",
"$",
"this",
"->",
"supportedType",
"(",
"$",
"type",
")",
";",
"if",
"(",
"$",
"supportedType",
"===",
"false",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Sorry the package type of this package is not supported.'",
")",
";",
"}",
"$",
"class",
"=",
"'Blesta\\\\Composer\\\\Installer\\\\'",
".",
"$",
"this",
"->",
"supportedTypes",
"[",
"$",
"supportedType",
"]",
";",
"$",
"installer",
"=",
"new",
"$",
"class",
"(",
"$",
"package",
",",
"$",
"this",
"->",
"composer",
",",
"$",
"this",
"->",
"io",
")",
";",
"return",
"$",
"installer",
"->",
"getInstallPath",
"(",
"$",
"package",
",",
"$",
"supportedType",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/blesta/composer-installer/blob/11672a7cbe9c74a6d5bc602ce8148ae92781ba2e/src/Installer.php#L18-L33 |
blesta/composer-installer | src/Installer.php | Installer.uninstall | public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
{
if (!$repo->hasPackage($package)) {
throw new InvalidArgumentException(
sprintf('Package is not installed: %s', $package)
);
}
$repo->removePackage($package);
$installPath = $this->getInstallPath($package);
$this->io->write(
sprintf(
'Deleting %s - %s',
$installPath,
$this->filesystem->removeDirectory($installPath)
? '<comment>deleted</comment>'
: '<error>not deleted</error>'
)
);
} | php | public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
{
if (!$repo->hasPackage($package)) {
throw new InvalidArgumentException(
sprintf('Package is not installed: %s', $package)
);
}
$repo->removePackage($package);
$installPath = $this->getInstallPath($package);
$this->io->write(
sprintf(
'Deleting %s - %s',
$installPath,
$this->filesystem->removeDirectory($installPath)
? '<comment>deleted</comment>'
: '<error>not deleted</error>'
)
);
} | [
"public",
"function",
"uninstall",
"(",
"InstalledRepositoryInterface",
"$",
"repo",
",",
"PackageInterface",
"$",
"package",
")",
"{",
"if",
"(",
"!",
"$",
"repo",
"->",
"hasPackage",
"(",
"$",
"package",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Package is not installed: %s'",
",",
"$",
"package",
")",
")",
";",
"}",
"$",
"repo",
"->",
"removePackage",
"(",
"$",
"package",
")",
";",
"$",
"installPath",
"=",
"$",
"this",
"->",
"getInstallPath",
"(",
"$",
"package",
")",
";",
"$",
"this",
"->",
"io",
"->",
"write",
"(",
"sprintf",
"(",
"'Deleting %s - %s'",
",",
"$",
"installPath",
",",
"$",
"this",
"->",
"filesystem",
"->",
"removeDirectory",
"(",
"$",
"installPath",
")",
"?",
"'<comment>deleted</comment>'",
":",
"'<error>not deleted</error>'",
")",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/blesta/composer-installer/blob/11672a7cbe9c74a6d5bc602ce8148ae92781ba2e/src/Installer.php#L38-L58 |
blesta/composer-installer | src/Installer.php | Installer.supports | public function supports($packageType)
{
$supportedType = $this->supportedType($packageType);
if ($supportedType === false) {
return false;
}
$class = 'Blesta\\Composer\\Installer\\' . $this->supportedTypes[$supportedType];
$installer = new $class(null, $this->composer, $this->io);
$locations = $installer->getLocations();
foreach ($locations as $type => $path) {
if ($supportedType . '-' . $type === $packageType) {
return true;
}
}
return false;
} | php | public function supports($packageType)
{
$supportedType = $this->supportedType($packageType);
if ($supportedType === false) {
return false;
}
$class = 'Blesta\\Composer\\Installer\\' . $this->supportedTypes[$supportedType];
$installer = new $class(null, $this->composer, $this->io);
$locations = $installer->getLocations();
foreach ($locations as $type => $path) {
if ($supportedType . '-' . $type === $packageType) {
return true;
}
}
return false;
} | [
"public",
"function",
"supports",
"(",
"$",
"packageType",
")",
"{",
"$",
"supportedType",
"=",
"$",
"this",
"->",
"supportedType",
"(",
"$",
"packageType",
")",
";",
"if",
"(",
"$",
"supportedType",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"$",
"class",
"=",
"'Blesta\\\\Composer\\\\Installer\\\\'",
".",
"$",
"this",
"->",
"supportedTypes",
"[",
"$",
"supportedType",
"]",
";",
"$",
"installer",
"=",
"new",
"$",
"class",
"(",
"null",
",",
"$",
"this",
"->",
"composer",
",",
"$",
"this",
"->",
"io",
")",
";",
"$",
"locations",
"=",
"$",
"installer",
"->",
"getLocations",
"(",
")",
";",
"foreach",
"(",
"$",
"locations",
"as",
"$",
"type",
"=>",
"$",
"path",
")",
"{",
"if",
"(",
"$",
"supportedType",
".",
"'-'",
".",
"$",
"type",
"===",
"$",
"packageType",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/blesta/composer-installer/blob/11672a7cbe9c74a6d5bc602ce8148ae92781ba2e/src/Installer.php#L63-L81 |
blesta/composer-installer | src/Installer.php | Installer.supportedType | protected function supportedType($type)
{
$supportedType = false;
$baseType = substr($type, 0, strpos($type, '-'));
if (array_key_exists($baseType, $this->supportedTypes)) {
$supportedType = $baseType;
}
return $supportedType;
} | php | protected function supportedType($type)
{
$supportedType = false;
$baseType = substr($type, 0, strpos($type, '-'));
if (array_key_exists($baseType, $this->supportedTypes)) {
$supportedType = $baseType;
}
return $supportedType;
} | [
"protected",
"function",
"supportedType",
"(",
"$",
"type",
")",
"{",
"$",
"supportedType",
"=",
"false",
";",
"$",
"baseType",
"=",
"substr",
"(",
"$",
"type",
",",
"0",
",",
"strpos",
"(",
"$",
"type",
",",
"'-'",
")",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"baseType",
",",
"$",
"this",
"->",
"supportedTypes",
")",
")",
"{",
"$",
"supportedType",
"=",
"$",
"baseType",
";",
"}",
"return",
"$",
"supportedType",
";",
"}"
] | Find the matching installer type
@param string $type
@return boolean|string | [
"Find",
"the",
"matching",
"installer",
"type"
] | train | https://github.com/blesta/composer-installer/blob/11672a7cbe9c74a6d5bc602ce8148ae92781ba2e/src/Installer.php#L89-L100 |
DesignPond/newsletter | src/Http/Controllers/Backend/StatsController.php | StatsController.show | public function show($id)
{
$statistiques = [];
$clickStats = [];
// Stats open, bounce etc.
$campagne = $this->campagne->find($id);
$campagneStats = $this->worker->statsCampagne($campagne->api_campagne_id);
if($campagneStats)
{
$statistiques = $this->charts->compileStats($campagneStats);
// Clicks
$clickStats = $this->worker->clickStatistics($campagneStats['CampaignID'], 0);
}
return view('newsletter::Backend.stats.show')->with(
[
'isChart' => true,
'campagne' => $campagne ,
'statistiques' => $statistiques,
'clickStats' => $clickStats
]
);
} | php | public function show($id)
{
$statistiques = [];
$clickStats = [];
// Stats open, bounce etc.
$campagne = $this->campagne->find($id);
$campagneStats = $this->worker->statsCampagne($campagne->api_campagne_id);
if($campagneStats)
{
$statistiques = $this->charts->compileStats($campagneStats);
// Clicks
$clickStats = $this->worker->clickStatistics($campagneStats['CampaignID'], 0);
}
return view('newsletter::Backend.stats.show')->with(
[
'isChart' => true,
'campagne' => $campagne ,
'statistiques' => $statistiques,
'clickStats' => $clickStats
]
);
} | [
"public",
"function",
"show",
"(",
"$",
"id",
")",
"{",
"$",
"statistiques",
"=",
"[",
"]",
";",
"$",
"clickStats",
"=",
"[",
"]",
";",
"// Stats open, bounce etc.",
"$",
"campagne",
"=",
"$",
"this",
"->",
"campagne",
"->",
"find",
"(",
"$",
"id",
")",
";",
"$",
"campagneStats",
"=",
"$",
"this",
"->",
"worker",
"->",
"statsCampagne",
"(",
"$",
"campagne",
"->",
"api_campagne_id",
")",
";",
"if",
"(",
"$",
"campagneStats",
")",
"{",
"$",
"statistiques",
"=",
"$",
"this",
"->",
"charts",
"->",
"compileStats",
"(",
"$",
"campagneStats",
")",
";",
"// Clicks",
"$",
"clickStats",
"=",
"$",
"this",
"->",
"worker",
"->",
"clickStatistics",
"(",
"$",
"campagneStats",
"[",
"'CampaignID'",
"]",
",",
"0",
")",
";",
"}",
"return",
"view",
"(",
"'newsletter::Backend.stats.show'",
")",
"->",
"with",
"(",
"[",
"'isChart'",
"=>",
"true",
",",
"'campagne'",
"=>",
"$",
"campagne",
",",
"'statistiques'",
"=>",
"$",
"statistiques",
",",
"'clickStats'",
"=>",
"$",
"clickStats",
"]",
")",
";",
"}"
] | Display the specified resource.
GET /stats/{id}
@param int $id
@return Response | [
"Display",
"the",
"specified",
"resource",
".",
"GET",
"/",
"stats",
"/",
"{",
"id",
"}"
] | train | https://github.com/DesignPond/newsletter/blob/0bf0e7a8a42fa4b90a5e937771bb80058e0a91c3/src/Http/Controllers/Backend/StatsController.php#L39-L64 |
blast-project/BaseEntitiesBundle | src/Loggable/Mapping/Driver/Yaml.php | Yaml.readExtendedMetadata | public function readExtendedMetadata($meta, array &$config)
{
$mapping = $this->_getMapping($meta->name);
// Entities that have the Loggable trait don't need the blast:loggable entry in the yaml file
if (ClassAnalyzer::hasTrait($meta->name, 'Blast\BaseEntitiesBundle\Entity\Traits\Loggable')) {
$config['loggable'] = true;
} elseif (isset($mapping['blast'])) {
$classMapping = $mapping['blast'];
if (isset($classMapping['loggable'])) {
$config['loggable'] = true;
if (isset($classMapping['loggable']['logEntryClass'])) {
if (!$cl = $this->getRelatedClassName($meta, $classMapping['loggable']['logEntryClass'])) {
throw new InvalidMappingException("LogEntry class: {$classMapping['loggable']['logEntryClass']} does not exist.");
}
$config['logEntryClass'] = $cl;
}
}
}
if (!isset($config['loggable'])) {
return;
}
if (isset($mapping['fields'])) {
foreach ($mapping['fields'] as $field => $fieldMapping) {
if (!isset($fieldMapping['blast']) || !in_array('unversioned', $fieldMapping['blast'])) {
// fields cannot be overrided and throws mapping exception
if ($meta->isCollectionValuedAssociation($field)) {
throw new InvalidMappingException("Cannot versioned [{$field}] as it is collection in object - {$meta->name}");
}
$config['versioned'][] = $field;
}
}
}
if (isset($mapping['attributeOverride'])) {
foreach ($mapping['attributeOverride'] as $field => $fieldMapping) {
if (!isset($fieldMapping['blast']) || !in_array('unversioned', $fieldMapping['blast'])) {
// fields cannot be overrided and throws mapping exception
if ($meta->isCollectionValuedAssociation($field)) {
throw new InvalidMappingException("Cannot versioned [{$field}] as it is collection in object - {$meta->name}");
}
$config['versioned'][] = $field;
}
}
}
if (isset($mapping['manyToOne'])) {
foreach ($mapping['manyToOne'] as $field => $fieldMapping) {
if (!isset($fieldMapping['blast']) || !in_array('unversioned', $fieldMapping['blast'])) {
// fields cannot be overrided and throws mapping exception
if ($meta->isCollectionValuedAssociation($field)) {
throw new InvalidMappingException("Cannot versioned [{$field}] as it is collection in object - {$meta->name}");
}
$config['versioned'][] = $field;
}
}
}
if (isset($mapping['oneToOne'])) {
foreach ($mapping['oneToOne'] as $field => $fieldMapping) {
if (!isset($fieldMapping['blast']) || !in_array('unversioned', $fieldMapping['blast'])) {
// fields cannot be overrided and throws mapping exception
if ($meta->isCollectionValuedAssociation($field)) {
throw new InvalidMappingException("Cannot versioned [{$field}] as it is collection in object - {$meta->name}");
}
$config['versioned'][] = $field;
}
}
}
if (!$meta->isMappedSuperclass && $config) {
if (is_array($meta->identifier) && count($meta->identifier) > 1) {
throw new InvalidMappingException("Loggable does not support composite identifiers in class - {$meta->name}");
}
if (isset($config['versioned']) && !isset($config['loggable'])) {
throw new InvalidMappingException("Class must be annoted with Loggable annotation in order to track versioned fields in class - {$meta->name}");
}
if (!empty($config['loggable'])) {
$this->addTraitsMetadata($meta, $config);
}
}
} | php | public function readExtendedMetadata($meta, array &$config)
{
$mapping = $this->_getMapping($meta->name);
// Entities that have the Loggable trait don't need the blast:loggable entry in the yaml file
if (ClassAnalyzer::hasTrait($meta->name, 'Blast\BaseEntitiesBundle\Entity\Traits\Loggable')) {
$config['loggable'] = true;
} elseif (isset($mapping['blast'])) {
$classMapping = $mapping['blast'];
if (isset($classMapping['loggable'])) {
$config['loggable'] = true;
if (isset($classMapping['loggable']['logEntryClass'])) {
if (!$cl = $this->getRelatedClassName($meta, $classMapping['loggable']['logEntryClass'])) {
throw new InvalidMappingException("LogEntry class: {$classMapping['loggable']['logEntryClass']} does not exist.");
}
$config['logEntryClass'] = $cl;
}
}
}
if (!isset($config['loggable'])) {
return;
}
if (isset($mapping['fields'])) {
foreach ($mapping['fields'] as $field => $fieldMapping) {
if (!isset($fieldMapping['blast']) || !in_array('unversioned', $fieldMapping['blast'])) {
// fields cannot be overrided and throws mapping exception
if ($meta->isCollectionValuedAssociation($field)) {
throw new InvalidMappingException("Cannot versioned [{$field}] as it is collection in object - {$meta->name}");
}
$config['versioned'][] = $field;
}
}
}
if (isset($mapping['attributeOverride'])) {
foreach ($mapping['attributeOverride'] as $field => $fieldMapping) {
if (!isset($fieldMapping['blast']) || !in_array('unversioned', $fieldMapping['blast'])) {
// fields cannot be overrided and throws mapping exception
if ($meta->isCollectionValuedAssociation($field)) {
throw new InvalidMappingException("Cannot versioned [{$field}] as it is collection in object - {$meta->name}");
}
$config['versioned'][] = $field;
}
}
}
if (isset($mapping['manyToOne'])) {
foreach ($mapping['manyToOne'] as $field => $fieldMapping) {
if (!isset($fieldMapping['blast']) || !in_array('unversioned', $fieldMapping['blast'])) {
// fields cannot be overrided and throws mapping exception
if ($meta->isCollectionValuedAssociation($field)) {
throw new InvalidMappingException("Cannot versioned [{$field}] as it is collection in object - {$meta->name}");
}
$config['versioned'][] = $field;
}
}
}
if (isset($mapping['oneToOne'])) {
foreach ($mapping['oneToOne'] as $field => $fieldMapping) {
if (!isset($fieldMapping['blast']) || !in_array('unversioned', $fieldMapping['blast'])) {
// fields cannot be overrided and throws mapping exception
if ($meta->isCollectionValuedAssociation($field)) {
throw new InvalidMappingException("Cannot versioned [{$field}] as it is collection in object - {$meta->name}");
}
$config['versioned'][] = $field;
}
}
}
if (!$meta->isMappedSuperclass && $config) {
if (is_array($meta->identifier) && count($meta->identifier) > 1) {
throw new InvalidMappingException("Loggable does not support composite identifiers in class - {$meta->name}");
}
if (isset($config['versioned']) && !isset($config['loggable'])) {
throw new InvalidMappingException("Class must be annoted with Loggable annotation in order to track versioned fields in class - {$meta->name}");
}
if (!empty($config['loggable'])) {
$this->addTraitsMetadata($meta, $config);
}
}
} | [
"public",
"function",
"readExtendedMetadata",
"(",
"$",
"meta",
",",
"array",
"&",
"$",
"config",
")",
"{",
"$",
"mapping",
"=",
"$",
"this",
"->",
"_getMapping",
"(",
"$",
"meta",
"->",
"name",
")",
";",
"// Entities that have the Loggable trait don't need the blast:loggable entry in the yaml file",
"if",
"(",
"ClassAnalyzer",
"::",
"hasTrait",
"(",
"$",
"meta",
"->",
"name",
",",
"'Blast\\BaseEntitiesBundle\\Entity\\Traits\\Loggable'",
")",
")",
"{",
"$",
"config",
"[",
"'loggable'",
"]",
"=",
"true",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'blast'",
"]",
")",
")",
"{",
"$",
"classMapping",
"=",
"$",
"mapping",
"[",
"'blast'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"classMapping",
"[",
"'loggable'",
"]",
")",
")",
"{",
"$",
"config",
"[",
"'loggable'",
"]",
"=",
"true",
";",
"if",
"(",
"isset",
"(",
"$",
"classMapping",
"[",
"'loggable'",
"]",
"[",
"'logEntryClass'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"$",
"cl",
"=",
"$",
"this",
"->",
"getRelatedClassName",
"(",
"$",
"meta",
",",
"$",
"classMapping",
"[",
"'loggable'",
"]",
"[",
"'logEntryClass'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidMappingException",
"(",
"\"LogEntry class: {$classMapping['loggable']['logEntryClass']} does not exist.\"",
")",
";",
"}",
"$",
"config",
"[",
"'logEntryClass'",
"]",
"=",
"$",
"cl",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'loggable'",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'fields'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"mapping",
"[",
"'fields'",
"]",
"as",
"$",
"field",
"=>",
"$",
"fieldMapping",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"fieldMapping",
"[",
"'blast'",
"]",
")",
"||",
"!",
"in_array",
"(",
"'unversioned'",
",",
"$",
"fieldMapping",
"[",
"'blast'",
"]",
")",
")",
"{",
"// fields cannot be overrided and throws mapping exception",
"if",
"(",
"$",
"meta",
"->",
"isCollectionValuedAssociation",
"(",
"$",
"field",
")",
")",
"{",
"throw",
"new",
"InvalidMappingException",
"(",
"\"Cannot versioned [{$field}] as it is collection in object - {$meta->name}\"",
")",
";",
"}",
"$",
"config",
"[",
"'versioned'",
"]",
"[",
"]",
"=",
"$",
"field",
";",
"}",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'attributeOverride'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"mapping",
"[",
"'attributeOverride'",
"]",
"as",
"$",
"field",
"=>",
"$",
"fieldMapping",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"fieldMapping",
"[",
"'blast'",
"]",
")",
"||",
"!",
"in_array",
"(",
"'unversioned'",
",",
"$",
"fieldMapping",
"[",
"'blast'",
"]",
")",
")",
"{",
"// fields cannot be overrided and throws mapping exception",
"if",
"(",
"$",
"meta",
"->",
"isCollectionValuedAssociation",
"(",
"$",
"field",
")",
")",
"{",
"throw",
"new",
"InvalidMappingException",
"(",
"\"Cannot versioned [{$field}] as it is collection in object - {$meta->name}\"",
")",
";",
"}",
"$",
"config",
"[",
"'versioned'",
"]",
"[",
"]",
"=",
"$",
"field",
";",
"}",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'manyToOne'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"mapping",
"[",
"'manyToOne'",
"]",
"as",
"$",
"field",
"=>",
"$",
"fieldMapping",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"fieldMapping",
"[",
"'blast'",
"]",
")",
"||",
"!",
"in_array",
"(",
"'unversioned'",
",",
"$",
"fieldMapping",
"[",
"'blast'",
"]",
")",
")",
"{",
"// fields cannot be overrided and throws mapping exception",
"if",
"(",
"$",
"meta",
"->",
"isCollectionValuedAssociation",
"(",
"$",
"field",
")",
")",
"{",
"throw",
"new",
"InvalidMappingException",
"(",
"\"Cannot versioned [{$field}] as it is collection in object - {$meta->name}\"",
")",
";",
"}",
"$",
"config",
"[",
"'versioned'",
"]",
"[",
"]",
"=",
"$",
"field",
";",
"}",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'oneToOne'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"mapping",
"[",
"'oneToOne'",
"]",
"as",
"$",
"field",
"=>",
"$",
"fieldMapping",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"fieldMapping",
"[",
"'blast'",
"]",
")",
"||",
"!",
"in_array",
"(",
"'unversioned'",
",",
"$",
"fieldMapping",
"[",
"'blast'",
"]",
")",
")",
"{",
"// fields cannot be overrided and throws mapping exception",
"if",
"(",
"$",
"meta",
"->",
"isCollectionValuedAssociation",
"(",
"$",
"field",
")",
")",
"{",
"throw",
"new",
"InvalidMappingException",
"(",
"\"Cannot versioned [{$field}] as it is collection in object - {$meta->name}\"",
")",
";",
"}",
"$",
"config",
"[",
"'versioned'",
"]",
"[",
"]",
"=",
"$",
"field",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"$",
"meta",
"->",
"isMappedSuperclass",
"&&",
"$",
"config",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"meta",
"->",
"identifier",
")",
"&&",
"count",
"(",
"$",
"meta",
"->",
"identifier",
")",
">",
"1",
")",
"{",
"throw",
"new",
"InvalidMappingException",
"(",
"\"Loggable does not support composite identifiers in class - {$meta->name}\"",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'versioned'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"config",
"[",
"'loggable'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidMappingException",
"(",
"\"Class must be annoted with Loggable annotation in order to track versioned fields in class - {$meta->name}\"",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"config",
"[",
"'loggable'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addTraitsMetadata",
"(",
"$",
"meta",
",",
"$",
"config",
")",
";",
"}",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/blast-project/BaseEntitiesBundle/blob/abd06891fc38922225ab7e4fcb437a286ba2c0c4/src/Loggable/Mapping/Driver/Yaml.php#L49-L132 |
JBZoo/Assets | src/Asset/Collection.php | Collection.load | public function load(array $filters = [])
{
$factory = $this->_manager->getFactory();
$result = [];
foreach ($this->_source as $key => $source) {
$subAlias = $this->_alias . '-' . $key;
$asset = $factory->create($subAlias, $source, $this->_dependencies, $this->_options);
$result[] = $asset->load($filters);
}
return [Asset::TYPE_COLLECTION, $result];
} | php | public function load(array $filters = [])
{
$factory = $this->_manager->getFactory();
$result = [];
foreach ($this->_source as $key => $source) {
$subAlias = $this->_alias . '-' . $key;
$asset = $factory->create($subAlias, $source, $this->_dependencies, $this->_options);
$result[] = $asset->load($filters);
}
return [Asset::TYPE_COLLECTION, $result];
} | [
"public",
"function",
"load",
"(",
"array",
"$",
"filters",
"=",
"[",
"]",
")",
"{",
"$",
"factory",
"=",
"$",
"this",
"->",
"_manager",
"->",
"getFactory",
"(",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_source",
"as",
"$",
"key",
"=>",
"$",
"source",
")",
"{",
"$",
"subAlias",
"=",
"$",
"this",
"->",
"_alias",
".",
"'-'",
".",
"$",
"key",
";",
"$",
"asset",
"=",
"$",
"factory",
"->",
"create",
"(",
"$",
"subAlias",
",",
"$",
"source",
",",
"$",
"this",
"->",
"_dependencies",
",",
"$",
"this",
"->",
"_options",
")",
";",
"$",
"result",
"[",
"]",
"=",
"$",
"asset",
"->",
"load",
"(",
"$",
"filters",
")",
";",
"}",
"return",
"[",
"Asset",
"::",
"TYPE_COLLECTION",
",",
"$",
"result",
"]",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/JBZoo/Assets/blob/134a109378f5b5e955dfb15e6ed2821581564991/src/Asset/Collection.php#L27-L39 |
canis-io/yii2-broadcaster | lib/models/BroadcastEventDeferred.php | BroadcastEventDeferred.serializeData | public function serializeData()
{
if (isset($this->_dataObject)) {
try {
$this->result = serialize($this->_dataObject);
} catch (\Exception $e) {
\d($this->_dataObject);
exit;
}
}
} | php | public function serializeData()
{
if (isset($this->_dataObject)) {
try {
$this->result = serialize($this->_dataObject);
} catch (\Exception $e) {
\d($this->_dataObject);
exit;
}
}
} | [
"public",
"function",
"serializeData",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_dataObject",
")",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"result",
"=",
"serialize",
"(",
"$",
"this",
"->",
"_dataObject",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"\\",
"d",
"(",
"$",
"this",
"->",
"_dataObject",
")",
";",
"exit",
";",
"}",
"}",
"}"
] | [[@doctodo method_description:serializeAction]]. | [
"[["
] | train | https://github.com/canis-io/yii2-broadcaster/blob/b8d7b5b24f2d8f4fdb29132dd85df34602dcd6b1/lib/models/BroadcastEventDeferred.php#L37-L47 |
canis-io/yii2-broadcaster | lib/models/BroadcastEventDeferred.php | BroadcastEventDeferred.getResultObject | public function getResultObject()
{
if (!isset($this->_dataObject) && !empty($this->result)) {
$this->_dataObject = unserialize($this->result);
} elseif (!isset($this->_dataObject)) {
$this->_dataObject = new Result;
}
$this->_dataObject->model = $this;
return $this->_dataObject;
} | php | public function getResultObject()
{
if (!isset($this->_dataObject) && !empty($this->result)) {
$this->_dataObject = unserialize($this->result);
} elseif (!isset($this->_dataObject)) {
$this->_dataObject = new Result;
}
$this->_dataObject->model = $this;
return $this->_dataObject;
} | [
"public",
"function",
"getResultObject",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_dataObject",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"result",
")",
")",
"{",
"$",
"this",
"->",
"_dataObject",
"=",
"unserialize",
"(",
"$",
"this",
"->",
"result",
")",
";",
"}",
"elseif",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_dataObject",
")",
")",
"{",
"$",
"this",
"->",
"_dataObject",
"=",
"new",
"Result",
";",
"}",
"$",
"this",
"->",
"_dataObject",
"->",
"model",
"=",
"$",
"this",
";",
"return",
"$",
"this",
"->",
"_dataObject",
";",
"}"
] | Get action object.
@return [[@doctodo return_type:getActionObject]] [[@doctodo return_description:getActionObject]] | [
"Get",
"action",
"object",
"."
] | train | https://github.com/canis-io/yii2-broadcaster/blob/b8d7b5b24f2d8f4fdb29132dd85df34602dcd6b1/lib/models/BroadcastEventDeferred.php#L198-L208 |
mothership-ec/composer | src/Composer/Package/Version/VersionParser.php | VersionParser.parseNameVersionPairs | public function parseNameVersionPairs(array $pairs)
{
$pairs = array_values($pairs);
$result = array();
for ($i = 0, $count = count($pairs); $i < $count; $i++) {
$pair = preg_replace('{^([^=: ]+)[=: ](.*)$}', '$1 $2', trim($pairs[$i]));
if (false === strpos($pair, ' ') && isset($pairs[$i+1]) && false === strpos($pairs[$i+1], '/')) {
$pair .= ' '.$pairs[$i+1];
$i++;
}
if (strpos($pair, ' ')) {
list($name, $version) = explode(" ", $pair, 2);
$result[] = array('name' => $name, 'version' => $version);
} else {
$result[] = array('name' => $pair);
}
}
return $result;
} | php | public function parseNameVersionPairs(array $pairs)
{
$pairs = array_values($pairs);
$result = array();
for ($i = 0, $count = count($pairs); $i < $count; $i++) {
$pair = preg_replace('{^([^=: ]+)[=: ](.*)$}', '$1 $2', trim($pairs[$i]));
if (false === strpos($pair, ' ') && isset($pairs[$i+1]) && false === strpos($pairs[$i+1], '/')) {
$pair .= ' '.$pairs[$i+1];
$i++;
}
if (strpos($pair, ' ')) {
list($name, $version) = explode(" ", $pair, 2);
$result[] = array('name' => $name, 'version' => $version);
} else {
$result[] = array('name' => $pair);
}
}
return $result;
} | [
"public",
"function",
"parseNameVersionPairs",
"(",
"array",
"$",
"pairs",
")",
"{",
"$",
"pairs",
"=",
"array_values",
"(",
"$",
"pairs",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"count",
"=",
"count",
"(",
"$",
"pairs",
")",
";",
"$",
"i",
"<",
"$",
"count",
";",
"$",
"i",
"++",
")",
"{",
"$",
"pair",
"=",
"preg_replace",
"(",
"'{^([^=: ]+)[=: ](.*)$}'",
",",
"'$1 $2'",
",",
"trim",
"(",
"$",
"pairs",
"[",
"$",
"i",
"]",
")",
")",
";",
"if",
"(",
"false",
"===",
"strpos",
"(",
"$",
"pair",
",",
"' '",
")",
"&&",
"isset",
"(",
"$",
"pairs",
"[",
"$",
"i",
"+",
"1",
"]",
")",
"&&",
"false",
"===",
"strpos",
"(",
"$",
"pairs",
"[",
"$",
"i",
"+",
"1",
"]",
",",
"'/'",
")",
")",
"{",
"$",
"pair",
".=",
"' '",
".",
"$",
"pairs",
"[",
"$",
"i",
"+",
"1",
"]",
";",
"$",
"i",
"++",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"pair",
",",
"' '",
")",
")",
"{",
"list",
"(",
"$",
"name",
",",
"$",
"version",
")",
"=",
"explode",
"(",
"\" \"",
",",
"$",
"pair",
",",
"2",
")",
";",
"$",
"result",
"[",
"]",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"name",
",",
"'version'",
"=>",
"$",
"version",
")",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"]",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"pair",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Parses a name/version pairs and returns an array of pairs + the
@param array $pairs a set of package/version pairs separated by ":", "=" or " "
@return array[] array of arrays containing a name and (if provided) a version | [
"Parses",
"a",
"name",
"/",
"version",
"pairs",
"and",
"returns",
"an",
"array",
"of",
"pairs",
"+",
"the"
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Package/Version/VersionParser.php#L539-L560 |
Root-XS/SudoBible | src/SudoBible.php | SudoBible.dbConnect | protected function dbConnect(array $aOptions)
{
$aOptions = array_merge(SudoBible::DB_CREDS, $aOptions);
try {
$this->db = new mysqli(
$aOptions['db_host'],
$aOptions['db_user'],
$aOptions['db_pass'],
$aOptions['db_name'],
$aOptions['db_port']
);
} catch (Exception $e) {
// Clean up the error message
throw new Exception(__METHOD__ . ': DB connection failed.');
}
} | php | protected function dbConnect(array $aOptions)
{
$aOptions = array_merge(SudoBible::DB_CREDS, $aOptions);
try {
$this->db = new mysqli(
$aOptions['db_host'],
$aOptions['db_user'],
$aOptions['db_pass'],
$aOptions['db_name'],
$aOptions['db_port']
);
} catch (Exception $e) {
// Clean up the error message
throw new Exception(__METHOD__ . ': DB connection failed.');
}
} | [
"protected",
"function",
"dbConnect",
"(",
"array",
"$",
"aOptions",
")",
"{",
"$",
"aOptions",
"=",
"array_merge",
"(",
"SudoBible",
"::",
"DB_CREDS",
",",
"$",
"aOptions",
")",
";",
"try",
"{",
"$",
"this",
"->",
"db",
"=",
"new",
"mysqli",
"(",
"$",
"aOptions",
"[",
"'db_host'",
"]",
",",
"$",
"aOptions",
"[",
"'db_user'",
"]",
",",
"$",
"aOptions",
"[",
"'db_pass'",
"]",
",",
"$",
"aOptions",
"[",
"'db_name'",
"]",
",",
"$",
"aOptions",
"[",
"'db_port'",
"]",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"// Clean up the error message",
"throw",
"new",
"Exception",
"(",
"__METHOD__",
".",
"': DB connection failed.'",
")",
";",
"}",
"}"
] | Connect to the DB.
@param array $aOptions
@throws Exception | [
"Connect",
"to",
"the",
"DB",
"."
] | train | https://github.com/Root-XS/SudoBible/blob/562462e92e1b2c019bdd48ed83414502ca0bdb0c/src/SudoBible.php#L65-L80 |
Root-XS/SudoBible | src/SudoBible.php | SudoBible.setTranslation | public function setTranslation($mTranslation)
{
$this->iTranslation = is_numeric($mTranslation)
? $mTranslation : $this->getIdFor('translation', $mTranslation);
} | php | public function setTranslation($mTranslation)
{
$this->iTranslation = is_numeric($mTranslation)
? $mTranslation : $this->getIdFor('translation', $mTranslation);
} | [
"public",
"function",
"setTranslation",
"(",
"$",
"mTranslation",
")",
"{",
"$",
"this",
"->",
"iTranslation",
"=",
"is_numeric",
"(",
"$",
"mTranslation",
")",
"?",
"$",
"mTranslation",
":",
"$",
"this",
"->",
"getIdFor",
"(",
"'translation'",
",",
"$",
"mTranslation",
")",
";",
"}"
] | Set the translation preference.
@param int|string $mTranslation | [
"Set",
"the",
"translation",
"preference",
"."
] | train | https://github.com/Root-XS/SudoBible/blob/562462e92e1b2c019bdd48ed83414502ca0bdb0c/src/SudoBible.php#L87-L91 |
Root-XS/SudoBible | src/SudoBible.php | SudoBible.queryFiles | protected function queryFiles($strAction)
{
if (!in_array($strAction, ['create', 'insert', 'drop']))
throw new Exception('Invalid parameter "' . $strAction . '" sent to SudoBible::queryFiles()');
$strPath = 'queries/' . $this->dbType . '/' . $strAction;
foreach (scandir($strPath) as $strFilename) {
// Only run SQL files (eliminates ., .., and subdirs)
// Using in_array() in case DBs other than SQL are supported in the future.
if (in_array(substr($strFilename, -4), ['.sql'])) {
$mResult = $this->db->query(file_get_contents($strPath . '/' . $strFilename));
// Check success if creating or dropping
if ('insert' !== $strAction && true !== $mResult) {
throw new Exception('Unable to ' . $strAction . ' table in ' . $strFilename
. ' - please ensure your DB user has the right permissions.');
}
}
}
} | php | protected function queryFiles($strAction)
{
if (!in_array($strAction, ['create', 'insert', 'drop']))
throw new Exception('Invalid parameter "' . $strAction . '" sent to SudoBible::queryFiles()');
$strPath = 'queries/' . $this->dbType . '/' . $strAction;
foreach (scandir($strPath) as $strFilename) {
// Only run SQL files (eliminates ., .., and subdirs)
// Using in_array() in case DBs other than SQL are supported in the future.
if (in_array(substr($strFilename, -4), ['.sql'])) {
$mResult = $this->db->query(file_get_contents($strPath . '/' . $strFilename));
// Check success if creating or dropping
if ('insert' !== $strAction && true !== $mResult) {
throw new Exception('Unable to ' . $strAction . ' table in ' . $strFilename
. ' - please ensure your DB user has the right permissions.');
}
}
}
} | [
"protected",
"function",
"queryFiles",
"(",
"$",
"strAction",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"strAction",
",",
"[",
"'create'",
",",
"'insert'",
",",
"'drop'",
"]",
")",
")",
"throw",
"new",
"Exception",
"(",
"'Invalid parameter \"'",
".",
"$",
"strAction",
".",
"'\" sent to SudoBible::queryFiles()'",
")",
";",
"$",
"strPath",
"=",
"'queries/'",
".",
"$",
"this",
"->",
"dbType",
".",
"'/'",
".",
"$",
"strAction",
";",
"foreach",
"(",
"scandir",
"(",
"$",
"strPath",
")",
"as",
"$",
"strFilename",
")",
"{",
"// Only run SQL files (eliminates ., .., and subdirs)",
"// Using in_array() in case DBs other than SQL are supported in the future.",
"if",
"(",
"in_array",
"(",
"substr",
"(",
"$",
"strFilename",
",",
"-",
"4",
")",
",",
"[",
"'.sql'",
"]",
")",
")",
"{",
"$",
"mResult",
"=",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"file_get_contents",
"(",
"$",
"strPath",
".",
"'/'",
".",
"$",
"strFilename",
")",
")",
";",
"// Check success if creating or dropping",
"if",
"(",
"'insert'",
"!==",
"$",
"strAction",
"&&",
"true",
"!==",
"$",
"mResult",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Unable to '",
".",
"$",
"strAction",
".",
"' table in '",
".",
"$",
"strFilename",
".",
"' - please ensure your DB user has the right permissions.'",
")",
";",
"}",
"}",
"}",
"}"
] | Run the query files in a given directory.
@param string $strAction create, insert, or drop
@throws Exception | [
"Run",
"the",
"query",
"files",
"in",
"a",
"given",
"directory",
"."
] | train | https://github.com/Root-XS/SudoBible/blob/562462e92e1b2c019bdd48ed83414502ca0bdb0c/src/SudoBible.php#L125-L145 |
Root-XS/SudoBible | src/SudoBible.php | SudoBible.ref | public function ref($mBook, $iChapter, $iVerse = null, $mEnd1 = null, $iEnd2 = null, $iEnd3 = null)
{
// Sanitize input
$strBook = is_numeric($mBook) ? 'Book #' . $mBook : $mBook; // save for later error message
if (!is_numeric($mBook))
$mBook = $this->getIdFor('book', $mBook);
if ($mEnd1 && !is_numeric($mEnd1))
$mEnd1 = $this->getIdFor('book', $mEnd1);
// Validate input
if ($iEnd3) {
// Multiple verses, ending spills into the next book
// @todo Is this necessary? Spanning books might be overkill!
if ($mEnd1 < $mBook)
throw new Exception('2nd book given comes before 1st.');
} elseif ($iEnd2) {
// Multiple verses, ending spills into the next chapter
if ($mEnd1 < $iChapter)
throw new Exception('2nd chapter given comes before 1st.');
} elseif ($mEnd1) {
// Multiple verses
if ($mEnd1 < $iVerse)
throw new Exception('2nd verse given comes before 1st.');
// Must give a starting verse
if (!$iVerse)
throw new Exception('Missing starting verse.');
}
// Begin query
$q = 'SELECT verses.*, books.`name` AS book_name, books.`abbr` AS book_abbr, books.`ot`, books.`nt`'
. ' FROM `sudo_bible_verses` AS verses'
. ' LEFT JOIN `sudo_bible_books` AS books ON books.`id` = verses.`book_id`'
. ' WHERE `translation_id` = ?';
$aParams = [$this->iTranslation];
// Multiple verses, ending spills into the next book
if ($iEnd3) {
$q .= ' AND (';
// End of the starting book
$q .= ' (`book_id` = ? AND ((`chapter` = ? AND `verse` >= ?) OR `chapter` > ?))';
$aParams = array_merge($aParams, [$mBook, $iChapter, $iVerse, $iChapter]);
// Any books in between
$q .= ' OR (`book_id` > ? AND `book_id` < ?)';
$aParams = array_merge($aParams, [$mBook, $mEnd1]);
// Beginning of the finishing book
$q .= ' OR (`book_id` = ? AND (`chapter` < ? OR (`chapter` = ? AND `verse` <= ?)))';
$aParams = array_merge($aParams, [$mEnd1, $iEnd2, $iEnd2, $iEnd3]);
$q .= ' )';
// Verses are contained in a single book
} else {
$q .= ' AND `book_id` = ?';
$aParams[] = $mBook;
}
// Multiple verses, ending spills into the next chapter
if ($iEnd2 && !$iEnd3) {
$q .= ' AND (';
// End of the starting chapter
$q .= ' (`chapter` = ? AND `verse` >= ?)';
$aParams = array_merge($aParams, [$iChapter, $iVerse]);
// Any chapters in between
$q .= ' OR (`chapter` > ? AND `chapter` < ?)';
$aParams = array_merge($aParams, [$iChapter, $mEnd1]);
// Beginning of the finishing chapter
$q .= ' OR (`chapter` = ? AND `verse` <= ?)';
$aParams = array_merge($aParams, [$mEnd1, $iEnd2]);
$q .= ')';
// Verses are contained in a single chapter
} elseif (!$iEnd3) {
$q .= ' AND `chapter` = ?';
$aParams[] = $iChapter;
}
// Multiple verses
if ($mEnd1 && !$iEnd2 && !$iEnd3) {
$q .= ' AND (`verse` >= ? AND `verse` <= ?)';
$aParams = array_merge($aParams, [$iVerse, $mEnd1]);
// A single verse
} elseif (!$mEnd1 && $iVerse) {
$q .= ' AND `verse` = ?';
$aParams[] = $iVerse;
}
$q .= ' ORDER BY `book_id`, `chapter`, `verse`';
return new SudoBiblePassage($this->runPreparedQuery($q, $aParams), $this);
} | php | public function ref($mBook, $iChapter, $iVerse = null, $mEnd1 = null, $iEnd2 = null, $iEnd3 = null)
{
// Sanitize input
$strBook = is_numeric($mBook) ? 'Book #' . $mBook : $mBook; // save for later error message
if (!is_numeric($mBook))
$mBook = $this->getIdFor('book', $mBook);
if ($mEnd1 && !is_numeric($mEnd1))
$mEnd1 = $this->getIdFor('book', $mEnd1);
// Validate input
if ($iEnd3) {
// Multiple verses, ending spills into the next book
// @todo Is this necessary? Spanning books might be overkill!
if ($mEnd1 < $mBook)
throw new Exception('2nd book given comes before 1st.');
} elseif ($iEnd2) {
// Multiple verses, ending spills into the next chapter
if ($mEnd1 < $iChapter)
throw new Exception('2nd chapter given comes before 1st.');
} elseif ($mEnd1) {
// Multiple verses
if ($mEnd1 < $iVerse)
throw new Exception('2nd verse given comes before 1st.');
// Must give a starting verse
if (!$iVerse)
throw new Exception('Missing starting verse.');
}
// Begin query
$q = 'SELECT verses.*, books.`name` AS book_name, books.`abbr` AS book_abbr, books.`ot`, books.`nt`'
. ' FROM `sudo_bible_verses` AS verses'
. ' LEFT JOIN `sudo_bible_books` AS books ON books.`id` = verses.`book_id`'
. ' WHERE `translation_id` = ?';
$aParams = [$this->iTranslation];
// Multiple verses, ending spills into the next book
if ($iEnd3) {
$q .= ' AND (';
// End of the starting book
$q .= ' (`book_id` = ? AND ((`chapter` = ? AND `verse` >= ?) OR `chapter` > ?))';
$aParams = array_merge($aParams, [$mBook, $iChapter, $iVerse, $iChapter]);
// Any books in between
$q .= ' OR (`book_id` > ? AND `book_id` < ?)';
$aParams = array_merge($aParams, [$mBook, $mEnd1]);
// Beginning of the finishing book
$q .= ' OR (`book_id` = ? AND (`chapter` < ? OR (`chapter` = ? AND `verse` <= ?)))';
$aParams = array_merge($aParams, [$mEnd1, $iEnd2, $iEnd2, $iEnd3]);
$q .= ' )';
// Verses are contained in a single book
} else {
$q .= ' AND `book_id` = ?';
$aParams[] = $mBook;
}
// Multiple verses, ending spills into the next chapter
if ($iEnd2 && !$iEnd3) {
$q .= ' AND (';
// End of the starting chapter
$q .= ' (`chapter` = ? AND `verse` >= ?)';
$aParams = array_merge($aParams, [$iChapter, $iVerse]);
// Any chapters in between
$q .= ' OR (`chapter` > ? AND `chapter` < ?)';
$aParams = array_merge($aParams, [$iChapter, $mEnd1]);
// Beginning of the finishing chapter
$q .= ' OR (`chapter` = ? AND `verse` <= ?)';
$aParams = array_merge($aParams, [$mEnd1, $iEnd2]);
$q .= ')';
// Verses are contained in a single chapter
} elseif (!$iEnd3) {
$q .= ' AND `chapter` = ?';
$aParams[] = $iChapter;
}
// Multiple verses
if ($mEnd1 && !$iEnd2 && !$iEnd3) {
$q .= ' AND (`verse` >= ? AND `verse` <= ?)';
$aParams = array_merge($aParams, [$iVerse, $mEnd1]);
// A single verse
} elseif (!$mEnd1 && $iVerse) {
$q .= ' AND `verse` = ?';
$aParams[] = $iVerse;
}
$q .= ' ORDER BY `book_id`, `chapter`, `verse`';
return new SudoBiblePassage($this->runPreparedQuery($q, $aParams), $this);
} | [
"public",
"function",
"ref",
"(",
"$",
"mBook",
",",
"$",
"iChapter",
",",
"$",
"iVerse",
"=",
"null",
",",
"$",
"mEnd1",
"=",
"null",
",",
"$",
"iEnd2",
"=",
"null",
",",
"$",
"iEnd3",
"=",
"null",
")",
"{",
"// Sanitize input",
"$",
"strBook",
"=",
"is_numeric",
"(",
"$",
"mBook",
")",
"?",
"'Book #'",
".",
"$",
"mBook",
":",
"$",
"mBook",
";",
"// save for later error message",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"mBook",
")",
")",
"$",
"mBook",
"=",
"$",
"this",
"->",
"getIdFor",
"(",
"'book'",
",",
"$",
"mBook",
")",
";",
"if",
"(",
"$",
"mEnd1",
"&&",
"!",
"is_numeric",
"(",
"$",
"mEnd1",
")",
")",
"$",
"mEnd1",
"=",
"$",
"this",
"->",
"getIdFor",
"(",
"'book'",
",",
"$",
"mEnd1",
")",
";",
"// Validate input",
"if",
"(",
"$",
"iEnd3",
")",
"{",
"// Multiple verses, ending spills into the next book",
"// @todo Is this necessary? Spanning books might be overkill!",
"if",
"(",
"$",
"mEnd1",
"<",
"$",
"mBook",
")",
"throw",
"new",
"Exception",
"(",
"'2nd book given comes before 1st.'",
")",
";",
"}",
"elseif",
"(",
"$",
"iEnd2",
")",
"{",
"// Multiple verses, ending spills into the next chapter",
"if",
"(",
"$",
"mEnd1",
"<",
"$",
"iChapter",
")",
"throw",
"new",
"Exception",
"(",
"'2nd chapter given comes before 1st.'",
")",
";",
"}",
"elseif",
"(",
"$",
"mEnd1",
")",
"{",
"// Multiple verses",
"if",
"(",
"$",
"mEnd1",
"<",
"$",
"iVerse",
")",
"throw",
"new",
"Exception",
"(",
"'2nd verse given comes before 1st.'",
")",
";",
"// Must give a starting verse",
"if",
"(",
"!",
"$",
"iVerse",
")",
"throw",
"new",
"Exception",
"(",
"'Missing starting verse.'",
")",
";",
"}",
"// Begin query",
"$",
"q",
"=",
"'SELECT verses.*, books.`name` AS book_name, books.`abbr` AS book_abbr, books.`ot`, books.`nt`'",
".",
"' FROM `sudo_bible_verses` AS verses'",
".",
"' LEFT JOIN `sudo_bible_books` AS books ON books.`id` = verses.`book_id`'",
".",
"' WHERE `translation_id` = ?'",
";",
"$",
"aParams",
"=",
"[",
"$",
"this",
"->",
"iTranslation",
"]",
";",
"// Multiple verses, ending spills into the next book",
"if",
"(",
"$",
"iEnd3",
")",
"{",
"$",
"q",
".=",
"' AND ('",
";",
"// End of the starting book",
"$",
"q",
".=",
"' (`book_id` = ? AND ((`chapter` = ? AND `verse` >= ?) OR `chapter` > ?))'",
";",
"$",
"aParams",
"=",
"array_merge",
"(",
"$",
"aParams",
",",
"[",
"$",
"mBook",
",",
"$",
"iChapter",
",",
"$",
"iVerse",
",",
"$",
"iChapter",
"]",
")",
";",
"// Any books in between",
"$",
"q",
".=",
"' OR (`book_id` > ? AND `book_id` < ?)'",
";",
"$",
"aParams",
"=",
"array_merge",
"(",
"$",
"aParams",
",",
"[",
"$",
"mBook",
",",
"$",
"mEnd1",
"]",
")",
";",
"// Beginning of the finishing book",
"$",
"q",
".=",
"' OR (`book_id` = ? AND (`chapter` < ? OR (`chapter` = ? AND `verse` <= ?)))'",
";",
"$",
"aParams",
"=",
"array_merge",
"(",
"$",
"aParams",
",",
"[",
"$",
"mEnd1",
",",
"$",
"iEnd2",
",",
"$",
"iEnd2",
",",
"$",
"iEnd3",
"]",
")",
";",
"$",
"q",
".=",
"' )'",
";",
"// Verses are contained in a single book",
"}",
"else",
"{",
"$",
"q",
".=",
"' AND `book_id` = ?'",
";",
"$",
"aParams",
"[",
"]",
"=",
"$",
"mBook",
";",
"}",
"// Multiple verses, ending spills into the next chapter",
"if",
"(",
"$",
"iEnd2",
"&&",
"!",
"$",
"iEnd3",
")",
"{",
"$",
"q",
".=",
"' AND ('",
";",
"// End of the starting chapter",
"$",
"q",
".=",
"' (`chapter` = ? AND `verse` >= ?)'",
";",
"$",
"aParams",
"=",
"array_merge",
"(",
"$",
"aParams",
",",
"[",
"$",
"iChapter",
",",
"$",
"iVerse",
"]",
")",
";",
"// Any chapters in between",
"$",
"q",
".=",
"' OR (`chapter` > ? AND `chapter` < ?)'",
";",
"$",
"aParams",
"=",
"array_merge",
"(",
"$",
"aParams",
",",
"[",
"$",
"iChapter",
",",
"$",
"mEnd1",
"]",
")",
";",
"// Beginning of the finishing chapter",
"$",
"q",
".=",
"' OR (`chapter` = ? AND `verse` <= ?)'",
";",
"$",
"aParams",
"=",
"array_merge",
"(",
"$",
"aParams",
",",
"[",
"$",
"mEnd1",
",",
"$",
"iEnd2",
"]",
")",
";",
"$",
"q",
".=",
"')'",
";",
"// Verses are contained in a single chapter",
"}",
"elseif",
"(",
"!",
"$",
"iEnd3",
")",
"{",
"$",
"q",
".=",
"' AND `chapter` = ?'",
";",
"$",
"aParams",
"[",
"]",
"=",
"$",
"iChapter",
";",
"}",
"// Multiple verses",
"if",
"(",
"$",
"mEnd1",
"&&",
"!",
"$",
"iEnd2",
"&&",
"!",
"$",
"iEnd3",
")",
"{",
"$",
"q",
".=",
"' AND (`verse` >= ? AND `verse` <= ?)'",
";",
"$",
"aParams",
"=",
"array_merge",
"(",
"$",
"aParams",
",",
"[",
"$",
"iVerse",
",",
"$",
"mEnd1",
"]",
")",
";",
"// A single verse",
"}",
"elseif",
"(",
"!",
"$",
"mEnd1",
"&&",
"$",
"iVerse",
")",
"{",
"$",
"q",
".=",
"' AND `verse` = ?'",
";",
"$",
"aParams",
"[",
"]",
"=",
"$",
"iVerse",
";",
"}",
"$",
"q",
".=",
"' ORDER BY `book_id`, `chapter`, `verse`'",
";",
"return",
"new",
"SudoBiblePassage",
"(",
"$",
"this",
"->",
"runPreparedQuery",
"(",
"$",
"q",
",",
"$",
"aParams",
")",
",",
"$",
"this",
")",
";",
"}"
] | Return a verse, passage, or chapter.
@param int|string $mBook Name or ID of the book.
@param int $iChapter Chapter number.
@param int $iVerse Verse number.
@param int|string $mEnd1 Ending verse, chapter, or book (name or ID).
@param int $iEnd2 Ending verse or chapter.
@param int $iEnd3 Ending verse.
@throws Exception
@return array|false | [
"Return",
"a",
"verse",
"passage",
"or",
"chapter",
"."
] | train | https://github.com/Root-XS/SudoBible/blob/562462e92e1b2c019bdd48ed83414502ca0bdb0c/src/SudoBible.php#L184-L282 |
Root-XS/SudoBible | src/SudoBible.php | SudoBible.topic | public function topic($mTopic, $bRandomOne = false)
{
// Sanitize input
if (is_string($mTopic))
$mTopic = $this->getIdFor('topic', $mTopic);
// Search
$q = 'SELECT tv.*, verses.`text`, books.`name` AS book_name, books.`abbr` AS book_abbr, books.`ot`, books.`nt`'
. ' FROM `sudo_bible_topic_verses` AS tv'
. ' LEFT JOIN `sudo_bible_verses` AS verses ON verses.`book_id` = tv.`book_id`'
. ' AND verses.`chapter` = tv.`chapter` AND verses.`verse` = tv.`verse`'
. ' LEFT JOIN `sudo_bible_books` AS books ON books.`id` = tv.`book_id`'
. ' WHERE verses.`translation_id` = ? AND tv.`topic_id` = ?'
. ' ORDER BY `book_id`, `chapter`, `verse`';
$mResult = $this->runPreparedQuery($q, [$this->iTranslation, $mTopic]);
// If a random passage was requested, pick one
if ($bRandomOne) {
$mResult = new SudoBiblePassage([$mResult[array_rand($mResult)]], $this);
// Otherwise, convert all from stdClass to SudoBiblePassage
} else {
foreach ($mResult as $k => $oResult)
$mResult[$k] = new SudoBiblePassage([$oResult], $this);
}
return $mResult;
} | php | public function topic($mTopic, $bRandomOne = false)
{
// Sanitize input
if (is_string($mTopic))
$mTopic = $this->getIdFor('topic', $mTopic);
// Search
$q = 'SELECT tv.*, verses.`text`, books.`name` AS book_name, books.`abbr` AS book_abbr, books.`ot`, books.`nt`'
. ' FROM `sudo_bible_topic_verses` AS tv'
. ' LEFT JOIN `sudo_bible_verses` AS verses ON verses.`book_id` = tv.`book_id`'
. ' AND verses.`chapter` = tv.`chapter` AND verses.`verse` = tv.`verse`'
. ' LEFT JOIN `sudo_bible_books` AS books ON books.`id` = tv.`book_id`'
. ' WHERE verses.`translation_id` = ? AND tv.`topic_id` = ?'
. ' ORDER BY `book_id`, `chapter`, `verse`';
$mResult = $this->runPreparedQuery($q, [$this->iTranslation, $mTopic]);
// If a random passage was requested, pick one
if ($bRandomOne) {
$mResult = new SudoBiblePassage([$mResult[array_rand($mResult)]], $this);
// Otherwise, convert all from stdClass to SudoBiblePassage
} else {
foreach ($mResult as $k => $oResult)
$mResult[$k] = new SudoBiblePassage([$oResult], $this);
}
return $mResult;
} | [
"public",
"function",
"topic",
"(",
"$",
"mTopic",
",",
"$",
"bRandomOne",
"=",
"false",
")",
"{",
"// Sanitize input",
"if",
"(",
"is_string",
"(",
"$",
"mTopic",
")",
")",
"$",
"mTopic",
"=",
"$",
"this",
"->",
"getIdFor",
"(",
"'topic'",
",",
"$",
"mTopic",
")",
";",
"// Search",
"$",
"q",
"=",
"'SELECT tv.*, verses.`text`, books.`name` AS book_name, books.`abbr` AS book_abbr, books.`ot`, books.`nt`'",
".",
"' FROM `sudo_bible_topic_verses` AS tv'",
".",
"' LEFT JOIN `sudo_bible_verses` AS verses ON verses.`book_id` = tv.`book_id`'",
".",
"' AND verses.`chapter` = tv.`chapter` AND verses.`verse` = tv.`verse`'",
".",
"' LEFT JOIN `sudo_bible_books` AS books ON books.`id` = tv.`book_id`'",
".",
"' WHERE verses.`translation_id` = ? AND tv.`topic_id` = ?'",
".",
"' ORDER BY `book_id`, `chapter`, `verse`'",
";",
"$",
"mResult",
"=",
"$",
"this",
"->",
"runPreparedQuery",
"(",
"$",
"q",
",",
"[",
"$",
"this",
"->",
"iTranslation",
",",
"$",
"mTopic",
"]",
")",
";",
"// If a random passage was requested, pick one",
"if",
"(",
"$",
"bRandomOne",
")",
"{",
"$",
"mResult",
"=",
"new",
"SudoBiblePassage",
"(",
"[",
"$",
"mResult",
"[",
"array_rand",
"(",
"$",
"mResult",
")",
"]",
"]",
",",
"$",
"this",
")",
";",
"// Otherwise, convert all from stdClass to SudoBiblePassage",
"}",
"else",
"{",
"foreach",
"(",
"$",
"mResult",
"as",
"$",
"k",
"=>",
"$",
"oResult",
")",
"$",
"mResult",
"[",
"$",
"k",
"]",
"=",
"new",
"SudoBiblePassage",
"(",
"[",
"$",
"oResult",
"]",
",",
"$",
"this",
")",
";",
"}",
"return",
"$",
"mResult",
";",
"}"
] | Return all verses on a single topic.
@param int|string $mTopic The topic ID or name.
@param bool $bRandomOne Pick a random passage?
@return array|SudoBiblePassage | [
"Return",
"all",
"verses",
"on",
"a",
"single",
"topic",
"."
] | train | https://github.com/Root-XS/SudoBible/blob/562462e92e1b2c019bdd48ed83414502ca0bdb0c/src/SudoBible.php#L291-L317 |
Root-XS/SudoBible | src/SudoBible.php | SudoBible.nextVerse | public function nextVerse($mBook, $iChapter, $iVerse)
{
$oPassage = new SudoBiblePassage([], $this);
$iBookId = is_numeric($mBook) ? $mBook : getIdFor('book', $mBook);
// Steps to try
$aSteps = [
[$iBookId, $iChapter, $iVerse + 1], // next verse in chapter
[$iBookId, $iChapter + 1, 1], // beginning of next chapter in book
[$iBookId + 1, 1, 1], // beginning of next book
];
foreach ($aSteps as $aStep) {
if ($oPassage->isEmpty())
$oPassage = call_user_func_array([$this, 'verse'], $aStep);
else
break;
}
return $oPassage;
} | php | public function nextVerse($mBook, $iChapter, $iVerse)
{
$oPassage = new SudoBiblePassage([], $this);
$iBookId = is_numeric($mBook) ? $mBook : getIdFor('book', $mBook);
// Steps to try
$aSteps = [
[$iBookId, $iChapter, $iVerse + 1], // next verse in chapter
[$iBookId, $iChapter + 1, 1], // beginning of next chapter in book
[$iBookId + 1, 1, 1], // beginning of next book
];
foreach ($aSteps as $aStep) {
if ($oPassage->isEmpty())
$oPassage = call_user_func_array([$this, 'verse'], $aStep);
else
break;
}
return $oPassage;
} | [
"public",
"function",
"nextVerse",
"(",
"$",
"mBook",
",",
"$",
"iChapter",
",",
"$",
"iVerse",
")",
"{",
"$",
"oPassage",
"=",
"new",
"SudoBiblePassage",
"(",
"[",
"]",
",",
"$",
"this",
")",
";",
"$",
"iBookId",
"=",
"is_numeric",
"(",
"$",
"mBook",
")",
"?",
"$",
"mBook",
":",
"getIdFor",
"(",
"'book'",
",",
"$",
"mBook",
")",
";",
"// Steps to try",
"$",
"aSteps",
"=",
"[",
"[",
"$",
"iBookId",
",",
"$",
"iChapter",
",",
"$",
"iVerse",
"+",
"1",
"]",
",",
"// next verse in chapter",
"[",
"$",
"iBookId",
",",
"$",
"iChapter",
"+",
"1",
",",
"1",
"]",
",",
"// beginning of next chapter in book",
"[",
"$",
"iBookId",
"+",
"1",
",",
"1",
",",
"1",
"]",
",",
"// beginning of next book",
"]",
";",
"foreach",
"(",
"$",
"aSteps",
"as",
"$",
"aStep",
")",
"{",
"if",
"(",
"$",
"oPassage",
"->",
"isEmpty",
"(",
")",
")",
"$",
"oPassage",
"=",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"'verse'",
"]",
",",
"$",
"aStep",
")",
";",
"else",
"break",
";",
"}",
"return",
"$",
"oPassage",
";",
"}"
] | Get the verse following the given reference.
@param int|string $mBook
@param int $iChapter
@param int $iVerse
@return SudoBiblePassage | [
"Get",
"the",
"verse",
"following",
"the",
"given",
"reference",
"."
] | train | https://github.com/Root-XS/SudoBible/blob/562462e92e1b2c019bdd48ed83414502ca0bdb0c/src/SudoBible.php#L327-L346 |
Root-XS/SudoBible | src/SudoBible.php | SudoBible.getIdFor | protected function getIdFor($strType, $strNameAbbr)
{
// Validate input
if (!in_array($strType, ['book', 'translation', 'topic']))
throw new Exception('Invalid entity type "' . $strType . '"');
// Query the db to get the ID
$strTableName = 'sudo_bible_' . $strType . 's';
$q = 'SELECT `id` FROM `' . $strTableName . '` WHERE `name` LIKE ?';
$aParams = [$strNameAbbr];
if ('topic' !== $strType) {
$q .= ' OR `abbr` LIKE ?';
$aParams[] = $strNameAbbr;
}
$aResult = $this->runPreparedQuery($q, $aParams);
$iId = $aResult[0]->id;
// Validate result
if (!is_numeric($iId))
throw new Exception('Invalid ' . $strType . ' "' . $strNameAbbr . '" given.');
return $iId;
} | php | protected function getIdFor($strType, $strNameAbbr)
{
// Validate input
if (!in_array($strType, ['book', 'translation', 'topic']))
throw new Exception('Invalid entity type "' . $strType . '"');
// Query the db to get the ID
$strTableName = 'sudo_bible_' . $strType . 's';
$q = 'SELECT `id` FROM `' . $strTableName . '` WHERE `name` LIKE ?';
$aParams = [$strNameAbbr];
if ('topic' !== $strType) {
$q .= ' OR `abbr` LIKE ?';
$aParams[] = $strNameAbbr;
}
$aResult = $this->runPreparedQuery($q, $aParams);
$iId = $aResult[0]->id;
// Validate result
if (!is_numeric($iId))
throw new Exception('Invalid ' . $strType . ' "' . $strNameAbbr . '" given.');
return $iId;
} | [
"protected",
"function",
"getIdFor",
"(",
"$",
"strType",
",",
"$",
"strNameAbbr",
")",
"{",
"// Validate input",
"if",
"(",
"!",
"in_array",
"(",
"$",
"strType",
",",
"[",
"'book'",
",",
"'translation'",
",",
"'topic'",
"]",
")",
")",
"throw",
"new",
"Exception",
"(",
"'Invalid entity type \"'",
".",
"$",
"strType",
".",
"'\"'",
")",
";",
"// Query the db to get the ID",
"$",
"strTableName",
"=",
"'sudo_bible_'",
".",
"$",
"strType",
".",
"'s'",
";",
"$",
"q",
"=",
"'SELECT `id` FROM `'",
".",
"$",
"strTableName",
".",
"'` WHERE `name` LIKE ?'",
";",
"$",
"aParams",
"=",
"[",
"$",
"strNameAbbr",
"]",
";",
"if",
"(",
"'topic'",
"!==",
"$",
"strType",
")",
"{",
"$",
"q",
".=",
"' OR `abbr` LIKE ?'",
";",
"$",
"aParams",
"[",
"]",
"=",
"$",
"strNameAbbr",
";",
"}",
"$",
"aResult",
"=",
"$",
"this",
"->",
"runPreparedQuery",
"(",
"$",
"q",
",",
"$",
"aParams",
")",
";",
"$",
"iId",
"=",
"$",
"aResult",
"[",
"0",
"]",
"->",
"id",
";",
"// Validate result",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"iId",
")",
")",
"throw",
"new",
"Exception",
"(",
"'Invalid '",
".",
"$",
"strType",
".",
"' \"'",
".",
"$",
"strNameAbbr",
".",
"'\" given.'",
")",
";",
"return",
"$",
"iId",
";",
"}"
] | Get an ID, given the name.
For now, we're using this instead of a JOIN in the main query
so we can throw a useful error.
@param string $strType translation, book, or topic
@param string $strNameAbbr Name of the translation or book.
@throws Exception
@return int | [
"Get",
"an",
"ID",
"given",
"the",
"name",
"."
] | train | https://github.com/Root-XS/SudoBible/blob/562462e92e1b2c019bdd48ed83414502ca0bdb0c/src/SudoBible.php#L359-L381 |
Root-XS/SudoBible | src/SudoBible.php | SudoBible.runPreparedQuery | protected function runPreparedQuery($strSql, array $aParams = [])
{
// call_user_func_array needs references, not values
$aRefParams = [];
foreach ($aParams as $k =>$v)
$aRefParams[$k] = &$aParams[$k];
// Build data type string for bind_param
$strDataTypes = '';
foreach ($aRefParams as $mValue)
$strDataTypes .= is_int($mValue) ? 'i' : 's';
array_unshift($aRefParams, $strDataTypes);
// Prepare & execute
$stmt = $this->db->prepare($strSql);
call_user_func_array(array($stmt, 'bind_param'), $aRefParams);
$stmt->execute();
$oResult = $stmt->get_result();
// Build return array
$aReturn = [];
$i = 0;
while ($oRow = $oResult->fetch_object())
$aReturn[] = $oRow;
$stmt->close();
return $aReturn;
} | php | protected function runPreparedQuery($strSql, array $aParams = [])
{
// call_user_func_array needs references, not values
$aRefParams = [];
foreach ($aParams as $k =>$v)
$aRefParams[$k] = &$aParams[$k];
// Build data type string for bind_param
$strDataTypes = '';
foreach ($aRefParams as $mValue)
$strDataTypes .= is_int($mValue) ? 'i' : 's';
array_unshift($aRefParams, $strDataTypes);
// Prepare & execute
$stmt = $this->db->prepare($strSql);
call_user_func_array(array($stmt, 'bind_param'), $aRefParams);
$stmt->execute();
$oResult = $stmt->get_result();
// Build return array
$aReturn = [];
$i = 0;
while ($oRow = $oResult->fetch_object())
$aReturn[] = $oRow;
$stmt->close();
return $aReturn;
} | [
"protected",
"function",
"runPreparedQuery",
"(",
"$",
"strSql",
",",
"array",
"$",
"aParams",
"=",
"[",
"]",
")",
"{",
"// call_user_func_array needs references, not values",
"$",
"aRefParams",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aParams",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"$",
"aRefParams",
"[",
"$",
"k",
"]",
"=",
"&",
"$",
"aParams",
"[",
"$",
"k",
"]",
";",
"// Build data type string for bind_param",
"$",
"strDataTypes",
"=",
"''",
";",
"foreach",
"(",
"$",
"aRefParams",
"as",
"$",
"mValue",
")",
"$",
"strDataTypes",
".=",
"is_int",
"(",
"$",
"mValue",
")",
"?",
"'i'",
":",
"'s'",
";",
"array_unshift",
"(",
"$",
"aRefParams",
",",
"$",
"strDataTypes",
")",
";",
"// Prepare & execute",
"$",
"stmt",
"=",
"$",
"this",
"->",
"db",
"->",
"prepare",
"(",
"$",
"strSql",
")",
";",
"call_user_func_array",
"(",
"array",
"(",
"$",
"stmt",
",",
"'bind_param'",
")",
",",
"$",
"aRefParams",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
")",
";",
"$",
"oResult",
"=",
"$",
"stmt",
"->",
"get_result",
"(",
")",
";",
"// Build return array",
"$",
"aReturn",
"=",
"[",
"]",
";",
"$",
"i",
"=",
"0",
";",
"while",
"(",
"$",
"oRow",
"=",
"$",
"oResult",
"->",
"fetch_object",
"(",
")",
")",
"$",
"aReturn",
"[",
"]",
"=",
"$",
"oRow",
";",
"$",
"stmt",
"->",
"close",
"(",
")",
";",
"return",
"$",
"aReturn",
";",
"}"
] | Run a "mysqli" prepared query, given the query string and params.
@param string $strSql Query string with "?" placeholders.
@param array $aParams Array of values to fill in for the placeholders.
@return array Result set. | [
"Run",
"a",
"mysqli",
"prepared",
"query",
"given",
"the",
"query",
"string",
"and",
"params",
"."
] | train | https://github.com/Root-XS/SudoBible/blob/562462e92e1b2c019bdd48ed83414502ca0bdb0c/src/SudoBible.php#L390-L417 |
NuclearCMS/Hierarchy | src/Support/FileKeeper.php | FileKeeper.tryDelete | protected static function tryDelete($path)
{
$success = true;
try
{
if ( ! @unlink($path))
{
$success = false;
}
} catch (ErrorException $e)
{
$success = false;
}
return $success;
} | php | protected static function tryDelete($path)
{
$success = true;
try
{
if ( ! @unlink($path))
{
$success = false;
}
} catch (ErrorException $e)
{
$success = false;
}
return $success;
} | [
"protected",
"static",
"function",
"tryDelete",
"(",
"$",
"path",
")",
"{",
"$",
"success",
"=",
"true",
";",
"try",
"{",
"if",
"(",
"!",
"@",
"unlink",
"(",
"$",
"path",
")",
")",
"{",
"$",
"success",
"=",
"false",
";",
"}",
"}",
"catch",
"(",
"ErrorException",
"$",
"e",
")",
"{",
"$",
"success",
"=",
"false",
";",
"}",
"return",
"$",
"success",
";",
"}"
] | Try to delete a file
@param $path
@return bool | [
"Try",
"to",
"delete",
"a",
"file"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Support/FileKeeper.php#L89-L105 |
zhengb302/LumengPHP-Db | src/LumengPHP/Db/ConnectionManager.php | ConnectionManager.getConnection | public function getConnection($name = null) {
if (is_null($name)) {
$name = $this->defaultConnectionName;
}
if (isset($this->connectionMap[$name])) {
return $this->connectionMap[$name];
}
if (!isset($this->connectionConfigs[$name])) {
throw new SqlException("未定义的数据库连接,连接名称:{$name}");
}
$connConfig = $this->connectionConfigs[$name];
$conn = $this->buildConnection($connConfig);
$this->connectionMap[$name] = $conn;
return $conn;
} | php | public function getConnection($name = null) {
if (is_null($name)) {
$name = $this->defaultConnectionName;
}
if (isset($this->connectionMap[$name])) {
return $this->connectionMap[$name];
}
if (!isset($this->connectionConfigs[$name])) {
throw new SqlException("未定义的数据库连接,连接名称:{$name}");
}
$connConfig = $this->connectionConfigs[$name];
$conn = $this->buildConnection($connConfig);
$this->connectionMap[$name] = $conn;
return $conn;
} | [
"public",
"function",
"getConnection",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"defaultConnectionName",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"connectionMap",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"connectionMap",
"[",
"$",
"name",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"connectionConfigs",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"SqlException",
"(",
"\"未定义的数据库连接,连接名称:{$name}\");",
"",
"",
"}",
"$",
"connConfig",
"=",
"$",
"this",
"->",
"connectionConfigs",
"[",
"$",
"name",
"]",
";",
"$",
"conn",
"=",
"$",
"this",
"->",
"buildConnection",
"(",
"$",
"connConfig",
")",
";",
"$",
"this",
"->",
"connectionMap",
"[",
"$",
"name",
"]",
"=",
"$",
"conn",
";",
"return",
"$",
"conn",
";",
"}"
] | 根据数据库连接名称返回数据库连接对象
@param string|null $name 连接名称,为null则返回默认连接
@return ConnectionInterface | [
"根据数据库连接名称返回数据库连接对象"
] | train | https://github.com/zhengb302/LumengPHP-Db/blob/47384aa37bc26352efb7ecda3c139cf8cb03db83/src/LumengPHP/Db/ConnectionManager.php#L65-L83 |
zhengb302/LumengPHP-Db | src/LumengPHP/Db/ConnectionManager.php | ConnectionManager.buildConnection | private function buildConnection($connConfig) {
//基于数组的连接配置
if (is_array($connConfig)) {
$pdoProviderClass = $connConfig['pdoProvider'];
unset($connConfig['pdoProvider']);
/* @var $conn PDOProviderInterface */
$pdoProvider = new $pdoProviderClass($connConfig);
$conn = new Connection($pdoProvider, $this->logger);
$conn->setTablePrefix($connConfig['tablePrefix']);
}
//回调函数
//回调函数可以接收当前 ConnectionManager 实例作为参数,当然,这个参数是可选的
elseif ($connConfig instanceof Closure) {
$callback = $connConfig;
$refFunc = new ReflectionFunction($callback);
$conn = $refFunc->getNumberOfParameters() == 1 ? $callback($this) : $callback();
} else {
throw new SqlException('连接配置类型错误');
}
return $conn;
} | php | private function buildConnection($connConfig) {
//基于数组的连接配置
if (is_array($connConfig)) {
$pdoProviderClass = $connConfig['pdoProvider'];
unset($connConfig['pdoProvider']);
/* @var $conn PDOProviderInterface */
$pdoProvider = new $pdoProviderClass($connConfig);
$conn = new Connection($pdoProvider, $this->logger);
$conn->setTablePrefix($connConfig['tablePrefix']);
}
//回调函数
//回调函数可以接收当前 ConnectionManager 实例作为参数,当然,这个参数是可选的
elseif ($connConfig instanceof Closure) {
$callback = $connConfig;
$refFunc = new ReflectionFunction($callback);
$conn = $refFunc->getNumberOfParameters() == 1 ? $callback($this) : $callback();
} else {
throw new SqlException('连接配置类型错误');
}
return $conn;
} | [
"private",
"function",
"buildConnection",
"(",
"$",
"connConfig",
")",
"{",
"//基于数组的连接配置",
"if",
"(",
"is_array",
"(",
"$",
"connConfig",
")",
")",
"{",
"$",
"pdoProviderClass",
"=",
"$",
"connConfig",
"[",
"'pdoProvider'",
"]",
";",
"unset",
"(",
"$",
"connConfig",
"[",
"'pdoProvider'",
"]",
")",
";",
"/* @var $conn PDOProviderInterface */",
"$",
"pdoProvider",
"=",
"new",
"$",
"pdoProviderClass",
"(",
"$",
"connConfig",
")",
";",
"$",
"conn",
"=",
"new",
"Connection",
"(",
"$",
"pdoProvider",
",",
"$",
"this",
"->",
"logger",
")",
";",
"$",
"conn",
"->",
"setTablePrefix",
"(",
"$",
"connConfig",
"[",
"'tablePrefix'",
"]",
")",
";",
"}",
"//回调函数",
"//回调函数可以接收当前 ConnectionManager 实例作为参数,当然,这个参数是可选的",
"elseif",
"(",
"$",
"connConfig",
"instanceof",
"Closure",
")",
"{",
"$",
"callback",
"=",
"$",
"connConfig",
";",
"$",
"refFunc",
"=",
"new",
"ReflectionFunction",
"(",
"$",
"callback",
")",
";",
"$",
"conn",
"=",
"$",
"refFunc",
"->",
"getNumberOfParameters",
"(",
")",
"==",
"1",
"?",
"$",
"callback",
"(",
"$",
"this",
")",
":",
"$",
"callback",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"SqlException",
"(",
"'连接配置类型错误');",
"",
"",
"}",
"return",
"$",
"conn",
";",
"}"
] | 根据连接配置构造连接实例
@param array|Closure $connConfig 连接配置/回调函数
@return ConnectionInterface | [
"根据连接配置构造连接实例"
] | train | https://github.com/zhengb302/LumengPHP-Db/blob/47384aa37bc26352efb7ecda3c139cf8cb03db83/src/LumengPHP/Db/ConnectionManager.php#L91-L114 |
zhengb302/LumengPHP-Db | src/LumengPHP/Db/ConnectionManager.php | ConnectionManager.create | public static function create($connectionConfigs, LoggerInterface $logger = null) {
if (!is_null(self::$instance)) {
throw new SqlException('ConnectionManager实例已创建,不能重复创建~');
}
self::$instance = new ConnectionManager($connectionConfigs, $logger);
return self::$instance;
} | php | public static function create($connectionConfigs, LoggerInterface $logger = null) {
if (!is_null(self::$instance)) {
throw new SqlException('ConnectionManager实例已创建,不能重复创建~');
}
self::$instance = new ConnectionManager($connectionConfigs, $logger);
return self::$instance;
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"connectionConfigs",
",",
"LoggerInterface",
"$",
"logger",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"self",
"::",
"$",
"instance",
")",
")",
"{",
"throw",
"new",
"SqlException",
"(",
"'ConnectionManager实例已创建,不能重复创建~');",
"",
"",
"}",
"self",
"::",
"$",
"instance",
"=",
"new",
"ConnectionManager",
"(",
"$",
"connectionConfigs",
",",
"$",
"logger",
")",
";",
"return",
"self",
"::",
"$",
"instance",
";",
"}"
] | 创建并返回<b>ConnectionManager</b>实例
@param array $connectionConfigs 数据库配置
@param LoggerInterface $logger 日志组件
@return ConnectionManager
@throws SqlException | [
"创建并返回<b",
">",
"ConnectionManager<",
"/",
"b",
">",
"实例"
] | train | https://github.com/zhengb302/LumengPHP-Db/blob/47384aa37bc26352efb7ecda3c139cf8cb03db83/src/LumengPHP/Db/ConnectionManager.php#L138-L145 |
philiplb/Valdi | src/Valdi/Validator/InTheFuture.php | InTheFuture.isValidComparison | protected function isValidComparison(\DateTime $date, array $datetimes, array $parameters) {
$now = new \DateTime();
return $date->getTimestamp() > $now->getTimestamp();
} | php | protected function isValidComparison(\DateTime $date, array $datetimes, array $parameters) {
$now = new \DateTime();
return $date->getTimestamp() > $now->getTimestamp();
} | [
"protected",
"function",
"isValidComparison",
"(",
"\\",
"DateTime",
"$",
"date",
",",
"array",
"$",
"datetimes",
",",
"array",
"$",
"parameters",
")",
"{",
"$",
"now",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"return",
"$",
"date",
"->",
"getTimestamp",
"(",
")",
">",
"$",
"now",
"->",
"getTimestamp",
"(",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/philiplb/Valdi/blob/9927ec34a2cb00cec705e952d3c2374e2dc3c972/src/Valdi/Validator/InTheFuture.php#L40-L43 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/xml/writer.php | ezcDbSchemaXmlWriter.writeField | private function writeField( $fieldName, ezcDbSchemaField $field )
{
$this->writer->startElement( 'name' );
$this->writer->text( $fieldName );
$this->writer->endElement();
$this->writer->startElement( 'type' );
$this->writer->text( $field->type );
$this->writer->endElement();
if ( $field->length )
{
$this->writer->startElement( 'length' );
$this->writer->text( $field->length );
$this->writer->endElement();
}
if ( $field->autoIncrement )
{
$this->writer->startElement( 'autoincrement' );
$this->writer->text( 'true' );
$this->writer->endElement();
}
if ( $field->notNull )
{
$this->writer->startElement( 'notnull' );
$this->writer->text( 'true' );
$this->writer->endElement();
}
if ( !is_null( $field->default ) )
{
$this->writer->startElement( 'default' );
$this->writer->text( $field->default );
$this->writer->endElement();
}
} | php | private function writeField( $fieldName, ezcDbSchemaField $field )
{
$this->writer->startElement( 'name' );
$this->writer->text( $fieldName );
$this->writer->endElement();
$this->writer->startElement( 'type' );
$this->writer->text( $field->type );
$this->writer->endElement();
if ( $field->length )
{
$this->writer->startElement( 'length' );
$this->writer->text( $field->length );
$this->writer->endElement();
}
if ( $field->autoIncrement )
{
$this->writer->startElement( 'autoincrement' );
$this->writer->text( 'true' );
$this->writer->endElement();
}
if ( $field->notNull )
{
$this->writer->startElement( 'notnull' );
$this->writer->text( 'true' );
$this->writer->endElement();
}
if ( !is_null( $field->default ) )
{
$this->writer->startElement( 'default' );
$this->writer->text( $field->default );
$this->writer->endElement();
}
} | [
"private",
"function",
"writeField",
"(",
"$",
"fieldName",
",",
"ezcDbSchemaField",
"$",
"field",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'name'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"text",
"(",
"$",
"fieldName",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'type'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"text",
"(",
"$",
"field",
"->",
"type",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"if",
"(",
"$",
"field",
"->",
"length",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'length'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"text",
"(",
"$",
"field",
"->",
"length",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"}",
"if",
"(",
"$",
"field",
"->",
"autoIncrement",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'autoincrement'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"text",
"(",
"'true'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"}",
"if",
"(",
"$",
"field",
"->",
"notNull",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'notnull'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"text",
"(",
"'true'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"field",
"->",
"default",
")",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'default'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"text",
"(",
"$",
"field",
"->",
"default",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"}",
"}"
] | Uses the $writer object to write the field definition $field for $fieldName
@param string $fieldName
@param ezcDbSchemaField $field | [
"Uses",
"the",
"$writer",
"object",
"to",
"write",
"the",
"field",
"definition",
"$field",
"for",
"$fieldName"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/xml/writer.php#L56-L93 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/xml/writer.php | ezcDbSchemaXmlWriter.writeIndexField | private function writeIndexField( $fieldName, ezcDbSchemaIndexField $field )
{
$this->writer->startElement( 'name' );
$this->writer->text( $fieldName );
$this->writer->endElement();
if ( !is_null( $field->sorting ) )
{
$this->writer->startElement( 'sorting' );
$this->writer->text( $field->sorting ? 'ascending' : 'descending' );
$this->writer->endElement();
}
} | php | private function writeIndexField( $fieldName, ezcDbSchemaIndexField $field )
{
$this->writer->startElement( 'name' );
$this->writer->text( $fieldName );
$this->writer->endElement();
if ( !is_null( $field->sorting ) )
{
$this->writer->startElement( 'sorting' );
$this->writer->text( $field->sorting ? 'ascending' : 'descending' );
$this->writer->endElement();
}
} | [
"private",
"function",
"writeIndexField",
"(",
"$",
"fieldName",
",",
"ezcDbSchemaIndexField",
"$",
"field",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'name'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"text",
"(",
"$",
"fieldName",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"field",
"->",
"sorting",
")",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'sorting'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"text",
"(",
"$",
"field",
"->",
"sorting",
"?",
"'ascending'",
":",
"'descending'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"}",
"}"
] | Uses the $writer object to write the index field definition $field for $fieldName
@param string $fieldName
@param ezcDbSchemaIndexField $field | [
"Uses",
"the",
"$writer",
"object",
"to",
"write",
"the",
"index",
"field",
"definition",
"$field",
"for",
"$fieldName"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/xml/writer.php#L101-L113 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/xml/writer.php | ezcDbSchemaXmlWriter.writeIndex | private function writeIndex( $indexName, ezcDbSchemaIndex $index )
{
$this->writer->startElement( 'name' );
$this->writer->text( $indexName );
$this->writer->endElement();
if ( $index->primary )
{
$this->writer->startElement( 'primary' );
$this->writer->text( 'true' );
$this->writer->endElement();
}
if ( $index->unique )
{
$this->writer->startElement( 'unique' );
$this->writer->text( 'true' );
$this->writer->endElement();
}
$this->writer->flush();
foreach ( $index->indexFields as $fieldName => $field )
{
$this->writer->startElement( 'field' );
$this->writeIndexField( $fieldName, $field );
$this->writer->endElement();
$this->writer->flush();
}
} | php | private function writeIndex( $indexName, ezcDbSchemaIndex $index )
{
$this->writer->startElement( 'name' );
$this->writer->text( $indexName );
$this->writer->endElement();
if ( $index->primary )
{
$this->writer->startElement( 'primary' );
$this->writer->text( 'true' );
$this->writer->endElement();
}
if ( $index->unique )
{
$this->writer->startElement( 'unique' );
$this->writer->text( 'true' );
$this->writer->endElement();
}
$this->writer->flush();
foreach ( $index->indexFields as $fieldName => $field )
{
$this->writer->startElement( 'field' );
$this->writeIndexField( $fieldName, $field );
$this->writer->endElement();
$this->writer->flush();
}
} | [
"private",
"function",
"writeIndex",
"(",
"$",
"indexName",
",",
"ezcDbSchemaIndex",
"$",
"index",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'name'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"text",
"(",
"$",
"indexName",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"if",
"(",
"$",
"index",
"->",
"primary",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'primary'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"text",
"(",
"'true'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"}",
"if",
"(",
"$",
"index",
"->",
"unique",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'unique'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"text",
"(",
"'true'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"}",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"foreach",
"(",
"$",
"index",
"->",
"indexFields",
"as",
"$",
"fieldName",
"=>",
"$",
"field",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'field'",
")",
";",
"$",
"this",
"->",
"writeIndexField",
"(",
"$",
"fieldName",
",",
"$",
"field",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"}",
"}"
] | Uses the $writer object to write the index definition $index for $indexName
@param string $indexName
@param ezcDbSchemaIndex $index | [
"Uses",
"the",
"$writer",
"object",
"to",
"write",
"the",
"index",
"definition",
"$index",
"for",
"$indexName"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/xml/writer.php#L121-L150 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/xml/writer.php | ezcDbSchemaXmlWriter.writeTable | private function writeTable( $tableName, ezcDbSchemaTable $table )
{
$this->writer->startElement( 'table' );
$this->writer->startElement( 'name' );
$this->writer->text( $tableName );
$this->writer->endElement();
$this->writer->flush();
$this->writer->startElement( 'declaration' );
$this->writer->flush();
// fields
foreach ( $table->fields as $fieldName => $field )
{
$this->writer->startElement( 'field' );
$this->writeField( $fieldName, $field );
$this->writer->endElement();
$this->writer->flush();
}
// indices
foreach ( $table->indexes as $indexName => $index )
{
$this->writer->startElement( 'index' );
$this->writeIndex( $indexName, $index );
$this->writer->endElement();
$this->writer->flush();
}
$this->writer->endElement();
$this->writer->flush();
$this->writer->endElement();
} | php | private function writeTable( $tableName, ezcDbSchemaTable $table )
{
$this->writer->startElement( 'table' );
$this->writer->startElement( 'name' );
$this->writer->text( $tableName );
$this->writer->endElement();
$this->writer->flush();
$this->writer->startElement( 'declaration' );
$this->writer->flush();
// fields
foreach ( $table->fields as $fieldName => $field )
{
$this->writer->startElement( 'field' );
$this->writeField( $fieldName, $field );
$this->writer->endElement();
$this->writer->flush();
}
// indices
foreach ( $table->indexes as $indexName => $index )
{
$this->writer->startElement( 'index' );
$this->writeIndex( $indexName, $index );
$this->writer->endElement();
$this->writer->flush();
}
$this->writer->endElement();
$this->writer->flush();
$this->writer->endElement();
} | [
"private",
"function",
"writeTable",
"(",
"$",
"tableName",
",",
"ezcDbSchemaTable",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'table'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'name'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"text",
"(",
"$",
"tableName",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'declaration'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"// fields ",
"foreach",
"(",
"$",
"table",
"->",
"fields",
"as",
"$",
"fieldName",
"=>",
"$",
"field",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'field'",
")",
";",
"$",
"this",
"->",
"writeField",
"(",
"$",
"fieldName",
",",
"$",
"field",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"}",
"// indices",
"foreach",
"(",
"$",
"table",
"->",
"indexes",
"as",
"$",
"indexName",
"=>",
"$",
"index",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'index'",
")",
";",
"$",
"this",
"->",
"writeIndex",
"(",
"$",
"indexName",
",",
"$",
"index",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"}",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"}"
] | Uses the $writer object to write the table definition $table for $tableName
@param string $tableName
@param ezcDbSchemaTable $table | [
"Uses",
"the",
"$writer",
"object",
"to",
"write",
"the",
"table",
"definition",
"$table",
"for",
"$tableName"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/xml/writer.php#L158-L192 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/xml/writer.php | ezcDbSchemaXmlWriter.writeChangedTable | private function writeChangedTable( $tableName, ezcDbSchemaTableDiff $changedTable )
{
$this->writer->startElement( 'table' );
$this->writer->startElement( 'name' );
$this->writer->text( $tableName );
$this->writer->endElement();
$this->writer->flush();
// added fields
$this->writer->startElement( 'added-fields' );
$this->writer->flush();
foreach ( $changedTable->addedFields as $fieldName => $field )
{
$this->writer->startElement( 'field' );
$this->writeField( $fieldName, $field );
$this->writer->endElement();
$this->writer->flush();
}
$this->writer->endElement();
$this->writer->flush();
// changed fields
$this->writer->startElement( 'changed-fields' );
$this->writer->flush();
foreach ( $changedTable->changedFields as $fieldName => $field )
{
$this->writer->startElement( 'field' );
$this->writeField( $fieldName, $field );
$this->writer->endElement();
$this->writer->flush();
}
$this->writer->endElement();
$this->writer->flush();
// Removed fields
$this->writer->startElement( 'removed-fields' );
$this->writer->flush();
foreach ( $changedTable->removedFields as $fieldName => $fieldStatus )
{
$this->writer->startElement( 'field' );
$this->writer->startElement( 'name' );
$this->writer->text( $fieldName );
$this->writer->endElement();
$this->writer->startElement( 'removed' );
$this->writer->text( $fieldStatus ? 'true' : 'false' );
$this->writer->endElement();
$this->writer->endElement();
$this->writer->flush();
}
$this->writer->endElement();
$this->writer->flush();
// added indexes
$this->writer->startElement( 'added-indexes' );
$this->writer->flush();
foreach ( $changedTable->addedIndexes as $indexName => $index )
{
$this->writer->startElement( 'index' );
$this->writeIndex( $indexName, $index );
$this->writer->endElement();
$this->writer->flush();
}
$this->writer->endElement();
$this->writer->flush();
// changed indexes
$this->writer->startElement( 'changed-indexes' );
$this->writer->flush();
foreach ( $changedTable->changedIndexes as $indexName => $index )
{
$this->writer->startElement( 'index' );
$this->writeIndex( $indexName, $index );
$this->writer->endElement();
$this->writer->flush();
}
$this->writer->endElement();
$this->writer->flush();
// Removed indexes
$this->writer->startElement( 'removed-indexes' );
$this->writer->flush();
foreach ( $changedTable->removedIndexes as $indexName => $indexStatus )
{
$this->writer->startElement( 'index' );
$this->writer->startElement( 'name' );
$this->writer->text( $indexName );
$this->writer->endElement();
$this->writer->startElement( 'removed' );
$this->writer->text( $indexStatus ? 'true' : 'false' );
$this->writer->endElement();
$this->writer->endElement();
$this->writer->flush();
}
$this->writer->endElement();
$this->writer->flush();
$this->writer->endElement();
} | php | private function writeChangedTable( $tableName, ezcDbSchemaTableDiff $changedTable )
{
$this->writer->startElement( 'table' );
$this->writer->startElement( 'name' );
$this->writer->text( $tableName );
$this->writer->endElement();
$this->writer->flush();
// added fields
$this->writer->startElement( 'added-fields' );
$this->writer->flush();
foreach ( $changedTable->addedFields as $fieldName => $field )
{
$this->writer->startElement( 'field' );
$this->writeField( $fieldName, $field );
$this->writer->endElement();
$this->writer->flush();
}
$this->writer->endElement();
$this->writer->flush();
// changed fields
$this->writer->startElement( 'changed-fields' );
$this->writer->flush();
foreach ( $changedTable->changedFields as $fieldName => $field )
{
$this->writer->startElement( 'field' );
$this->writeField( $fieldName, $field );
$this->writer->endElement();
$this->writer->flush();
}
$this->writer->endElement();
$this->writer->flush();
// Removed fields
$this->writer->startElement( 'removed-fields' );
$this->writer->flush();
foreach ( $changedTable->removedFields as $fieldName => $fieldStatus )
{
$this->writer->startElement( 'field' );
$this->writer->startElement( 'name' );
$this->writer->text( $fieldName );
$this->writer->endElement();
$this->writer->startElement( 'removed' );
$this->writer->text( $fieldStatus ? 'true' : 'false' );
$this->writer->endElement();
$this->writer->endElement();
$this->writer->flush();
}
$this->writer->endElement();
$this->writer->flush();
// added indexes
$this->writer->startElement( 'added-indexes' );
$this->writer->flush();
foreach ( $changedTable->addedIndexes as $indexName => $index )
{
$this->writer->startElement( 'index' );
$this->writeIndex( $indexName, $index );
$this->writer->endElement();
$this->writer->flush();
}
$this->writer->endElement();
$this->writer->flush();
// changed indexes
$this->writer->startElement( 'changed-indexes' );
$this->writer->flush();
foreach ( $changedTable->changedIndexes as $indexName => $index )
{
$this->writer->startElement( 'index' );
$this->writeIndex( $indexName, $index );
$this->writer->endElement();
$this->writer->flush();
}
$this->writer->endElement();
$this->writer->flush();
// Removed indexes
$this->writer->startElement( 'removed-indexes' );
$this->writer->flush();
foreach ( $changedTable->removedIndexes as $indexName => $indexStatus )
{
$this->writer->startElement( 'index' );
$this->writer->startElement( 'name' );
$this->writer->text( $indexName );
$this->writer->endElement();
$this->writer->startElement( 'removed' );
$this->writer->text( $indexStatus ? 'true' : 'false' );
$this->writer->endElement();
$this->writer->endElement();
$this->writer->flush();
}
$this->writer->endElement();
$this->writer->flush();
$this->writer->endElement();
} | [
"private",
"function",
"writeChangedTable",
"(",
"$",
"tableName",
",",
"ezcDbSchemaTableDiff",
"$",
"changedTable",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'table'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'name'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"text",
"(",
"$",
"tableName",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"// added fields ",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'added-fields'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"foreach",
"(",
"$",
"changedTable",
"->",
"addedFields",
"as",
"$",
"fieldName",
"=>",
"$",
"field",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'field'",
")",
";",
"$",
"this",
"->",
"writeField",
"(",
"$",
"fieldName",
",",
"$",
"field",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"}",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"// changed fields ",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'changed-fields'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"foreach",
"(",
"$",
"changedTable",
"->",
"changedFields",
"as",
"$",
"fieldName",
"=>",
"$",
"field",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'field'",
")",
";",
"$",
"this",
"->",
"writeField",
"(",
"$",
"fieldName",
",",
"$",
"field",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"}",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"// Removed fields",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'removed-fields'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"foreach",
"(",
"$",
"changedTable",
"->",
"removedFields",
"as",
"$",
"fieldName",
"=>",
"$",
"fieldStatus",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'field'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'name'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"text",
"(",
"$",
"fieldName",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'removed'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"text",
"(",
"$",
"fieldStatus",
"?",
"'true'",
":",
"'false'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"}",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"// added indexes ",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'added-indexes'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"foreach",
"(",
"$",
"changedTable",
"->",
"addedIndexes",
"as",
"$",
"indexName",
"=>",
"$",
"index",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'index'",
")",
";",
"$",
"this",
"->",
"writeIndex",
"(",
"$",
"indexName",
",",
"$",
"index",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"}",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"// changed indexes ",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'changed-indexes'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"foreach",
"(",
"$",
"changedTable",
"->",
"changedIndexes",
"as",
"$",
"indexName",
"=>",
"$",
"index",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'index'",
")",
";",
"$",
"this",
"->",
"writeIndex",
"(",
"$",
"indexName",
",",
"$",
"index",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"}",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"// Removed indexes",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'removed-indexes'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"foreach",
"(",
"$",
"changedTable",
"->",
"removedIndexes",
"as",
"$",
"indexName",
"=>",
"$",
"indexStatus",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'index'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'name'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"text",
"(",
"$",
"indexName",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'removed'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"text",
"(",
"$",
"indexStatus",
"?",
"'true'",
":",
"'false'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"}",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"}"
] | Uses the $writer object to write the table changes definition $changedTable for $tableName
@param string $tableName
@param ezcDbSchemaTableDiff $changedTable | [
"Uses",
"the",
"$writer",
"object",
"to",
"write",
"the",
"table",
"changes",
"definition",
"$changedTable",
"for",
"$tableName"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/xml/writer.php#L200-L302 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/xml/writer.php | ezcDbSchemaXmlWriter.saveToFile | public function saveToFile( $file, ezcDbSchema $dbSchema )
{
$schema = $dbSchema->getSchema();
$data = $dbSchema->getData();
$this->writer = new XMLWriter();
if ( ! @$this->writer->openUri( $file ) )
{
throw new ezcBaseFilePermissionException( $file, ezcBaseFileException::WRITE );
}
$this->writer->startDocument( '1.0', 'utf-8' );
$this->writer->setIndent( true );
$this->writer->startElement( 'database' );
foreach ( $schema as $tableName => $table )
{
$this->writer->flush();
$this->writeTable( $tableName, $table );
}
$this->writer->endElement();
$this->writer->endDocument();
} | php | public function saveToFile( $file, ezcDbSchema $dbSchema )
{
$schema = $dbSchema->getSchema();
$data = $dbSchema->getData();
$this->writer = new XMLWriter();
if ( ! @$this->writer->openUri( $file ) )
{
throw new ezcBaseFilePermissionException( $file, ezcBaseFileException::WRITE );
}
$this->writer->startDocument( '1.0', 'utf-8' );
$this->writer->setIndent( true );
$this->writer->startElement( 'database' );
foreach ( $schema as $tableName => $table )
{
$this->writer->flush();
$this->writeTable( $tableName, $table );
}
$this->writer->endElement();
$this->writer->endDocument();
} | [
"public",
"function",
"saveToFile",
"(",
"$",
"file",
",",
"ezcDbSchema",
"$",
"dbSchema",
")",
"{",
"$",
"schema",
"=",
"$",
"dbSchema",
"->",
"getSchema",
"(",
")",
";",
"$",
"data",
"=",
"$",
"dbSchema",
"->",
"getData",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"=",
"new",
"XMLWriter",
"(",
")",
";",
"if",
"(",
"!",
"@",
"$",
"this",
"->",
"writer",
"->",
"openUri",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"ezcBaseFilePermissionException",
"(",
"$",
"file",
",",
"ezcBaseFileException",
"::",
"WRITE",
")",
";",
"}",
"$",
"this",
"->",
"writer",
"->",
"startDocument",
"(",
"'1.0'",
",",
"'utf-8'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"setIndent",
"(",
"true",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'database'",
")",
";",
"foreach",
"(",
"$",
"schema",
"as",
"$",
"tableName",
"=>",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"$",
"this",
"->",
"writeTable",
"(",
"$",
"tableName",
",",
"$",
"table",
")",
";",
"}",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endDocument",
"(",
")",
";",
"}"
] | Writes the schema definition in $dbSchema to the file $file.
@param string $file
@param ezcDbSchema $dbSchema
@todo throw exception when file can not be opened | [
"Writes",
"the",
"schema",
"definition",
"in",
"$dbSchema",
"to",
"the",
"file",
"$file",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/xml/writer.php#L311-L334 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/xml/writer.php | ezcDbSchemaXmlWriter.saveDiffToFile | public function saveDiffToFile( $file, ezcDbSchemaDiff $dbSchema )
{
$this->writer = new XMLWriter();
if ( ! @$this->writer->openUri( $file ) )
{
throw new ezcBaseFilePermissionException( $file, ezcBaseFileException::WRITE );
}
$this->writer->startDocument( '1.0', 'utf-8' );
$this->writer->setIndent( true );
$this->writer->startElement( 'database' );
$this->writer->flush();
// New tables
$this->writer->startElement( 'new-tables' );
$this->writer->flush();
foreach ( $dbSchema->newTables as $tableName => $table )
{
$this->writeTable( $tableName, $table );
$this->writer->flush();
}
$this->writer->endElement();
$this->writer->flush();
// Removed tables
$this->writer->startElement( 'removed-tables' );
$this->writer->flush();
foreach ( $dbSchema->removedTables as $tableName => $tableStatus )
{
$this->writer->startElement( 'table' );
$this->writer->startElement( 'name' );
$this->writer->text( $tableName );
$this->writer->endElement();
$this->writer->startElement( 'removed' );
$this->writer->text( $tableStatus ? 'true' : 'false' );
$this->writer->endElement();
$this->writer->endElement();
$this->writer->flush();
}
$this->writer->endElement();
$this->writer->flush();
// Changed tables
$this->writer->startElement( 'changed-tables' );
$this->writer->flush();
foreach ( $dbSchema->changedTables as $tableName => $table )
{
$this->writeChangedTable( $tableName, $table );
$this->writer->flush();
}
$this->writer->endElement();
$this->writer->flush();
$this->writer->endElement();
$this->writer->endDocument();
} | php | public function saveDiffToFile( $file, ezcDbSchemaDiff $dbSchema )
{
$this->writer = new XMLWriter();
if ( ! @$this->writer->openUri( $file ) )
{
throw new ezcBaseFilePermissionException( $file, ezcBaseFileException::WRITE );
}
$this->writer->startDocument( '1.0', 'utf-8' );
$this->writer->setIndent( true );
$this->writer->startElement( 'database' );
$this->writer->flush();
// New tables
$this->writer->startElement( 'new-tables' );
$this->writer->flush();
foreach ( $dbSchema->newTables as $tableName => $table )
{
$this->writeTable( $tableName, $table );
$this->writer->flush();
}
$this->writer->endElement();
$this->writer->flush();
// Removed tables
$this->writer->startElement( 'removed-tables' );
$this->writer->flush();
foreach ( $dbSchema->removedTables as $tableName => $tableStatus )
{
$this->writer->startElement( 'table' );
$this->writer->startElement( 'name' );
$this->writer->text( $tableName );
$this->writer->endElement();
$this->writer->startElement( 'removed' );
$this->writer->text( $tableStatus ? 'true' : 'false' );
$this->writer->endElement();
$this->writer->endElement();
$this->writer->flush();
}
$this->writer->endElement();
$this->writer->flush();
// Changed tables
$this->writer->startElement( 'changed-tables' );
$this->writer->flush();
foreach ( $dbSchema->changedTables as $tableName => $table )
{
$this->writeChangedTable( $tableName, $table );
$this->writer->flush();
}
$this->writer->endElement();
$this->writer->flush();
$this->writer->endElement();
$this->writer->endDocument();
} | [
"public",
"function",
"saveDiffToFile",
"(",
"$",
"file",
",",
"ezcDbSchemaDiff",
"$",
"dbSchema",
")",
"{",
"$",
"this",
"->",
"writer",
"=",
"new",
"XMLWriter",
"(",
")",
";",
"if",
"(",
"!",
"@",
"$",
"this",
"->",
"writer",
"->",
"openUri",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"ezcBaseFilePermissionException",
"(",
"$",
"file",
",",
"ezcBaseFileException",
"::",
"WRITE",
")",
";",
"}",
"$",
"this",
"->",
"writer",
"->",
"startDocument",
"(",
"'1.0'",
",",
"'utf-8'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"setIndent",
"(",
"true",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'database'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"// New tables",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'new-tables'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"foreach",
"(",
"$",
"dbSchema",
"->",
"newTables",
"as",
"$",
"tableName",
"=>",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"writeTable",
"(",
"$",
"tableName",
",",
"$",
"table",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"}",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"// Removed tables",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'removed-tables'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"foreach",
"(",
"$",
"dbSchema",
"->",
"removedTables",
"as",
"$",
"tableName",
"=>",
"$",
"tableStatus",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'table'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'name'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"text",
"(",
"$",
"tableName",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'removed'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"text",
"(",
"$",
"tableStatus",
"?",
"'true'",
":",
"'false'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"}",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"// Changed tables",
"$",
"this",
"->",
"writer",
"->",
"startElement",
"(",
"'changed-tables'",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"foreach",
"(",
"$",
"dbSchema",
"->",
"changedTables",
"as",
"$",
"tableName",
"=>",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"writeChangedTable",
"(",
"$",
"tableName",
",",
"$",
"table",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"}",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"flush",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"endDocument",
"(",
")",
";",
"}"
] | Writes the schema difference definition in $dbSchema to the file $file.
@param string $file
@param ezcDbSchemaDiff $dbSchema
@todo throw exception when file can not be opened | [
"Writes",
"the",
"schema",
"difference",
"definition",
"in",
"$dbSchema",
"to",
"the",
"file",
"$file",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/xml/writer.php#L343-L398 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/pgsql/reader.php | ezcDbSchemaPgsqlReader.fetchTableIndexes | protected function fetchTableIndexes( $tableName )
{
$indexBuffer = array();
$resultArray = array();
// fetching index info from PostgreSQL
$getIndexSQL = "SELECT relname, pg_index.indisunique, pg_index.indisprimary,
pg_index.indkey, pg_index.indrelid
FROM pg_class, pg_index
WHERE oid IN (
SELECT indexrelid
FROM pg_index, pg_class
WHERE pg_class.relname='$tableName' AND pg_class.oid=pg_index.indrelid
)
AND pg_index.indexrelid = oid";
$indexesArray = $this->db->query( $getIndexSQL )->fetchAll();
// getting columns to which each index related.
foreach ( $indexesArray as $row )
{
$row = $this->lowercase($row);
$myIndex[]=$row['relname'];
$colNumbers = explode( ' ', $row['indkey'] );
$colNumbersSQL = 'IN (' . join( ' ,', $colNumbers ) . ' )';
$indexColumns = $this->db->query( "SELECT attname
FROM pg_attribute
WHERE attrelid={$row['indrelid']}
AND attnum $colNumbersSQL;" );
foreach ( $indexColumns as $colRow )
{
$resultArray[] = array( 'key_name' => $row['relname'],
'column_name' => $colRow['attname'],
'non_unique' => !$row['indisunique'],
'primary' => !$row['indisprimary']
);
$indexColumnNames[] = $colRow['attname'];
}
}
foreach ( $resultArray as $row )
{
$keyName = $row['key_name'];
if ( substr( $keyName, -5) == '_pkey' )
{
$keyName = 'primary';
}
$indexBuffer[$keyName]['primary'] = false;
$indexBuffer[$keyName]['unique'] = true;
if ( $keyName == 'primary' )
{
$indexBuffer[$keyName]['primary'] = true;
$indexBuffer[$keyName]['unique'] = true;
}
else
{
$indexBuffer[$keyName]['unique'] = $row['non_unique'] ? false : true;
}
$indexBuffer[$keyName]['fields'][$row['column_name']] = ezcDbSchema::createNewIndexField();
}
$indexes = array();
foreach ( $indexBuffer as $indexName => $indexInfo )
{
$indexes[$indexName] = ezcDbSchema::createNewIndex( $indexInfo['fields'], $indexInfo['primary'], $indexInfo['unique'] );
}
return $indexes;
} | php | protected function fetchTableIndexes( $tableName )
{
$indexBuffer = array();
$resultArray = array();
// fetching index info from PostgreSQL
$getIndexSQL = "SELECT relname, pg_index.indisunique, pg_index.indisprimary,
pg_index.indkey, pg_index.indrelid
FROM pg_class, pg_index
WHERE oid IN (
SELECT indexrelid
FROM pg_index, pg_class
WHERE pg_class.relname='$tableName' AND pg_class.oid=pg_index.indrelid
)
AND pg_index.indexrelid = oid";
$indexesArray = $this->db->query( $getIndexSQL )->fetchAll();
// getting columns to which each index related.
foreach ( $indexesArray as $row )
{
$row = $this->lowercase($row);
$myIndex[]=$row['relname'];
$colNumbers = explode( ' ', $row['indkey'] );
$colNumbersSQL = 'IN (' . join( ' ,', $colNumbers ) . ' )';
$indexColumns = $this->db->query( "SELECT attname
FROM pg_attribute
WHERE attrelid={$row['indrelid']}
AND attnum $colNumbersSQL;" );
foreach ( $indexColumns as $colRow )
{
$resultArray[] = array( 'key_name' => $row['relname'],
'column_name' => $colRow['attname'],
'non_unique' => !$row['indisunique'],
'primary' => !$row['indisprimary']
);
$indexColumnNames[] = $colRow['attname'];
}
}
foreach ( $resultArray as $row )
{
$keyName = $row['key_name'];
if ( substr( $keyName, -5) == '_pkey' )
{
$keyName = 'primary';
}
$indexBuffer[$keyName]['primary'] = false;
$indexBuffer[$keyName]['unique'] = true;
if ( $keyName == 'primary' )
{
$indexBuffer[$keyName]['primary'] = true;
$indexBuffer[$keyName]['unique'] = true;
}
else
{
$indexBuffer[$keyName]['unique'] = $row['non_unique'] ? false : true;
}
$indexBuffer[$keyName]['fields'][$row['column_name']] = ezcDbSchema::createNewIndexField();
}
$indexes = array();
foreach ( $indexBuffer as $indexName => $indexInfo )
{
$indexes[$indexName] = ezcDbSchema::createNewIndex( $indexInfo['fields'], $indexInfo['primary'], $indexInfo['unique'] );
}
return $indexes;
} | [
"protected",
"function",
"fetchTableIndexes",
"(",
"$",
"tableName",
")",
"{",
"$",
"indexBuffer",
"=",
"array",
"(",
")",
";",
"$",
"resultArray",
"=",
"array",
"(",
")",
";",
"// fetching index info from PostgreSQL",
"$",
"getIndexSQL",
"=",
"\"SELECT relname, pg_index.indisunique, pg_index.indisprimary, \n pg_index.indkey, pg_index.indrelid \n FROM pg_class, pg_index\n WHERE oid IN ( \n SELECT indexrelid \n FROM pg_index, pg_class \n WHERE pg_class.relname='$tableName' AND pg_class.oid=pg_index.indrelid \n ) \n AND pg_index.indexrelid = oid\"",
";",
"$",
"indexesArray",
"=",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"$",
"getIndexSQL",
")",
"->",
"fetchAll",
"(",
")",
";",
"// getting columns to which each index related.",
"foreach",
"(",
"$",
"indexesArray",
"as",
"$",
"row",
")",
"{",
"$",
"row",
"=",
"$",
"this",
"->",
"lowercase",
"(",
"$",
"row",
")",
";",
"$",
"myIndex",
"[",
"]",
"=",
"$",
"row",
"[",
"'relname'",
"]",
";",
"$",
"colNumbers",
"=",
"explode",
"(",
"' '",
",",
"$",
"row",
"[",
"'indkey'",
"]",
")",
";",
"$",
"colNumbersSQL",
"=",
"'IN ('",
".",
"join",
"(",
"' ,'",
",",
"$",
"colNumbers",
")",
".",
"' )'",
";",
"$",
"indexColumns",
"=",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"\"SELECT attname \n FROM pg_attribute \n WHERE attrelid={$row['indrelid']} \n AND attnum $colNumbersSQL;\"",
")",
";",
"foreach",
"(",
"$",
"indexColumns",
"as",
"$",
"colRow",
")",
"{",
"$",
"resultArray",
"[",
"]",
"=",
"array",
"(",
"'key_name'",
"=>",
"$",
"row",
"[",
"'relname'",
"]",
",",
"'column_name'",
"=>",
"$",
"colRow",
"[",
"'attname'",
"]",
",",
"'non_unique'",
"=>",
"!",
"$",
"row",
"[",
"'indisunique'",
"]",
",",
"'primary'",
"=>",
"!",
"$",
"row",
"[",
"'indisprimary'",
"]",
")",
";",
"$",
"indexColumnNames",
"[",
"]",
"=",
"$",
"colRow",
"[",
"'attname'",
"]",
";",
"}",
"}",
"foreach",
"(",
"$",
"resultArray",
"as",
"$",
"row",
")",
"{",
"$",
"keyName",
"=",
"$",
"row",
"[",
"'key_name'",
"]",
";",
"if",
"(",
"substr",
"(",
"$",
"keyName",
",",
"-",
"5",
")",
"==",
"'_pkey'",
")",
"{",
"$",
"keyName",
"=",
"'primary'",
";",
"}",
"$",
"indexBuffer",
"[",
"$",
"keyName",
"]",
"[",
"'primary'",
"]",
"=",
"false",
";",
"$",
"indexBuffer",
"[",
"$",
"keyName",
"]",
"[",
"'unique'",
"]",
"=",
"true",
";",
"if",
"(",
"$",
"keyName",
"==",
"'primary'",
")",
"{",
"$",
"indexBuffer",
"[",
"$",
"keyName",
"]",
"[",
"'primary'",
"]",
"=",
"true",
";",
"$",
"indexBuffer",
"[",
"$",
"keyName",
"]",
"[",
"'unique'",
"]",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"indexBuffer",
"[",
"$",
"keyName",
"]",
"[",
"'unique'",
"]",
"=",
"$",
"row",
"[",
"'non_unique'",
"]",
"?",
"false",
":",
"true",
";",
"}",
"$",
"indexBuffer",
"[",
"$",
"keyName",
"]",
"[",
"'fields'",
"]",
"[",
"$",
"row",
"[",
"'column_name'",
"]",
"]",
"=",
"ezcDbSchema",
"::",
"createNewIndexField",
"(",
")",
";",
"}",
"$",
"indexes",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"indexBuffer",
"as",
"$",
"indexName",
"=>",
"$",
"indexInfo",
")",
"{",
"$",
"indexes",
"[",
"$",
"indexName",
"]",
"=",
"ezcDbSchema",
"::",
"createNewIndex",
"(",
"$",
"indexInfo",
"[",
"'fields'",
"]",
",",
"$",
"indexInfo",
"[",
"'primary'",
"]",
",",
"$",
"indexInfo",
"[",
"'unique'",
"]",
")",
";",
"}",
"return",
"$",
"indexes",
";",
"}"
] | Loops over all the indexes in the table $table and extracts information.
This method extracts information about the table $tableName's indexes
from the database and returns this schema as an array of
ezcDbSchemaIndex objects. The key in the array is the index' name.
@param string $tableName
@return array(string=>ezcDbSchemaIndex) | [
"Loops",
"over",
"all",
"the",
"indexes",
"in",
"the",
"table",
"$table",
"and",
"extracts",
"information",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/pgsql/reader.php#L246-L319 |
bluetree-service/event | src/Event/Base/EventLog.php | EventLog.makeLogEvent | public function makeLogEvent($name, $eventListener, $status)
{
if ($this->options['log_events']
&& ($this->options['log_all_events']
|| in_array($name, $this->logEvents, true)
)
) {
$this->loggerInstance->makeLog(
[
'event_name' => $name,
'listener' => $this->getListenerData($eventListener),
'status' => $status
]
);
}
return $this;
} | php | public function makeLogEvent($name, $eventListener, $status)
{
if ($this->options['log_events']
&& ($this->options['log_all_events']
|| in_array($name, $this->logEvents, true)
)
) {
$this->loggerInstance->makeLog(
[
'event_name' => $name,
'listener' => $this->getListenerData($eventListener),
'status' => $status
]
);
}
return $this;
} | [
"public",
"function",
"makeLogEvent",
"(",
"$",
"name",
",",
"$",
"eventListener",
",",
"$",
"status",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'log_events'",
"]",
"&&",
"(",
"$",
"this",
"->",
"options",
"[",
"'log_all_events'",
"]",
"||",
"in_array",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"logEvents",
",",
"true",
")",
")",
")",
"{",
"$",
"this",
"->",
"loggerInstance",
"->",
"makeLog",
"(",
"[",
"'event_name'",
"=>",
"$",
"name",
",",
"'listener'",
"=>",
"$",
"this",
"->",
"getListenerData",
"(",
"$",
"eventListener",
")",
",",
"'status'",
"=>",
"$",
"status",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | check that event data can be logged and create log message
@param string $name
@param mixed $eventListener
@param bool|string $status
@return $this | [
"check",
"that",
"event",
"data",
"can",
"be",
"logged",
"and",
"create",
"log",
"message"
] | train | https://github.com/bluetree-service/event/blob/64ef4c77af6284fc22748285d5e527edbdbed69b/src/Event/Base/EventLog.php#L56-L73 |
thienhungho/yii2-product-management | src/modules/ProductManage/controllers/ProductTypeMetaController.php | ProductTypeMetaController.actionIndex | public function actionIndex($type)
{
$searchModel = new ProductTypeMetaSearch();
$queryParams = request()->queryParams;
$queryParams['ProductTypeMetaSearch']['product_type'] = $type;
$dataProvider = $searchModel->search($queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
} | php | public function actionIndex($type)
{
$searchModel = new ProductTypeMetaSearch();
$queryParams = request()->queryParams;
$queryParams['ProductTypeMetaSearch']['product_type'] = $type;
$dataProvider = $searchModel->search($queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
} | [
"public",
"function",
"actionIndex",
"(",
"$",
"type",
")",
"{",
"$",
"searchModel",
"=",
"new",
"ProductTypeMetaSearch",
"(",
")",
";",
"$",
"queryParams",
"=",
"request",
"(",
")",
"->",
"queryParams",
";",
"$",
"queryParams",
"[",
"'ProductTypeMetaSearch'",
"]",
"[",
"'product_type'",
"]",
"=",
"$",
"type",
";",
"$",
"dataProvider",
"=",
"$",
"searchModel",
"->",
"search",
"(",
"$",
"queryParams",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'index'",
",",
"[",
"'searchModel'",
"=>",
"$",
"searchModel",
",",
"'dataProvider'",
"=>",
"$",
"dataProvider",
",",
"]",
")",
";",
"}"
] | @param $type
@return string | [
"@param",
"$type"
] | train | https://github.com/thienhungho/yii2-product-management/blob/72e1237bba123faf671e44491bd93077b50adde9/src/modules/ProductManage/controllers/ProductTypeMetaController.php#L34-L45 |
thienhungho/yii2-product-management | src/modules/ProductManage/controllers/ProductTypeMetaController.php | ProductTypeMetaController.actionCreate | public function actionCreate($type)
{
$model = new ProductTypeMeta();
$model->product_type = $type;
if ($model->loadAll(request()->post())) {
$model->product_type = $type;
if ($model->saveAll()) {
return $this->redirect(['update', 'id' => $model->id]);
}
}
return $this->render('create', [
'model' => $model,
]);
} | php | public function actionCreate($type)
{
$model = new ProductTypeMeta();
$model->product_type = $type;
if ($model->loadAll(request()->post())) {
$model->product_type = $type;
if ($model->saveAll()) {
return $this->redirect(['update', 'id' => $model->id]);
}
}
return $this->render('create', [
'model' => $model,
]);
} | [
"public",
"function",
"actionCreate",
"(",
"$",
"type",
")",
"{",
"$",
"model",
"=",
"new",
"ProductTypeMeta",
"(",
")",
";",
"$",
"model",
"->",
"product_type",
"=",
"$",
"type",
";",
"if",
"(",
"$",
"model",
"->",
"loadAll",
"(",
"request",
"(",
")",
"->",
"post",
"(",
")",
")",
")",
"{",
"$",
"model",
"->",
"product_type",
"=",
"$",
"type",
";",
"if",
"(",
"$",
"model",
"->",
"saveAll",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"redirect",
"(",
"[",
"'update'",
",",
"'id'",
"=>",
"$",
"model",
"->",
"id",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'create'",
",",
"[",
"'model'",
"=>",
"$",
"model",
",",
"]",
")",
";",
"}"
] | @param $type
@return string|\yii\web\Response
@throws \yii\db\Exception | [
"@param",
"$type"
] | train | https://github.com/thienhungho/yii2-product-management/blob/72e1237bba123faf671e44491bd93077b50adde9/src/modules/ProductManage/controllers/ProductTypeMetaController.php#L66-L81 |
thienhungho/yii2-product-management | src/modules/ProductManage/controllers/ProductTypeMetaController.php | ProductTypeMetaController.findModel | protected function findModel($id)
{
if (($model = ProductTypeMeta::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException(t('app', 'The requested page does not exist.'));
}
} | php | protected function findModel($id)
{
if (($model = ProductTypeMeta::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException(t('app', 'The requested page does not exist.'));
}
} | [
"protected",
"function",
"findModel",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"(",
"$",
"model",
"=",
"ProductTypeMeta",
"::",
"findOne",
"(",
"$",
"id",
")",
")",
"!==",
"null",
")",
"{",
"return",
"$",
"model",
";",
"}",
"else",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
"t",
"(",
"'app'",
",",
"'The requested page does not exist.'",
")",
")",
";",
"}",
"}"
] | Finds the ProductTypeMeta model based on its primary key value.
If the model is not found, a 404 HTTP exception will be thrown.
@param integer $id
@return ProductTypeMeta the loaded model
@throws NotFoundHttpException if the model cannot be found | [
"Finds",
"the",
"ProductTypeMeta",
"model",
"based",
"on",
"its",
"primary",
"key",
"value",
".",
"If",
"the",
"model",
"is",
"not",
"found",
"a",
"404",
"HTTP",
"exception",
"will",
"be",
"thrown",
"."
] | train | https://github.com/thienhungho/yii2-product-management/blob/72e1237bba123faf671e44491bd93077b50adde9/src/modules/ProductManage/controllers/ProductTypeMetaController.php#L182-L189 |
xiewulong/yii2-fileupload | oss/libs/symfony/class-loader/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php | DebugUniversalClassLoader.enable | public static function enable()
{
if (!is_array($functions = spl_autoload_functions())) {
return;
}
foreach ($functions as $function) {
spl_autoload_unregister($function);
}
foreach ($functions as $function) {
if (is_array($function) && $function[0] instanceof UniversalClassLoader) {
$loader = new static();
$loader->registerNamespaceFallbacks($function[0]->getNamespaceFallbacks());
$loader->registerPrefixFallbacks($function[0]->getPrefixFallbacks());
$loader->registerNamespaces($function[0]->getNamespaces());
$loader->registerPrefixes($function[0]->getPrefixes());
$loader->useIncludePath($function[0]->getUseIncludePath());
$function[0] = $loader;
}
spl_autoload_register($function);
}
} | php | public static function enable()
{
if (!is_array($functions = spl_autoload_functions())) {
return;
}
foreach ($functions as $function) {
spl_autoload_unregister($function);
}
foreach ($functions as $function) {
if (is_array($function) && $function[0] instanceof UniversalClassLoader) {
$loader = new static();
$loader->registerNamespaceFallbacks($function[0]->getNamespaceFallbacks());
$loader->registerPrefixFallbacks($function[0]->getPrefixFallbacks());
$loader->registerNamespaces($function[0]->getNamespaces());
$loader->registerPrefixes($function[0]->getPrefixes());
$loader->useIncludePath($function[0]->getUseIncludePath());
$function[0] = $loader;
}
spl_autoload_register($function);
}
} | [
"public",
"static",
"function",
"enable",
"(",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"functions",
"=",
"spl_autoload_functions",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"functions",
"as",
"$",
"function",
")",
"{",
"spl_autoload_unregister",
"(",
"$",
"function",
")",
";",
"}",
"foreach",
"(",
"$",
"functions",
"as",
"$",
"function",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"function",
")",
"&&",
"$",
"function",
"[",
"0",
"]",
"instanceof",
"UniversalClassLoader",
")",
"{",
"$",
"loader",
"=",
"new",
"static",
"(",
")",
";",
"$",
"loader",
"->",
"registerNamespaceFallbacks",
"(",
"$",
"function",
"[",
"0",
"]",
"->",
"getNamespaceFallbacks",
"(",
")",
")",
";",
"$",
"loader",
"->",
"registerPrefixFallbacks",
"(",
"$",
"function",
"[",
"0",
"]",
"->",
"getPrefixFallbacks",
"(",
")",
")",
";",
"$",
"loader",
"->",
"registerNamespaces",
"(",
"$",
"function",
"[",
"0",
"]",
"->",
"getNamespaces",
"(",
")",
")",
";",
"$",
"loader",
"->",
"registerPrefixes",
"(",
"$",
"function",
"[",
"0",
"]",
"->",
"getPrefixes",
"(",
")",
")",
";",
"$",
"loader",
"->",
"useIncludePath",
"(",
"$",
"function",
"[",
"0",
"]",
"->",
"getUseIncludePath",
"(",
")",
")",
";",
"$",
"function",
"[",
"0",
"]",
"=",
"$",
"loader",
";",
"}",
"spl_autoload_register",
"(",
"$",
"function",
")",
";",
"}",
"}"
] | Replaces all regular UniversalClassLoader instances by a DebugUniversalClassLoader ones. | [
"Replaces",
"all",
"regular",
"UniversalClassLoader",
"instances",
"by",
"a",
"DebugUniversalClassLoader",
"ones",
"."
] | train | https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/symfony/class-loader/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php#L24-L48 |
xiewulong/yii2-fileupload | oss/libs/symfony/class-loader/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php | DebugUniversalClassLoader.loadClass | public function loadClass($class)
{
if ($file = $this->findFile($class)) {
require $file;
if (!class_exists($class, false) && !interface_exists($class, false) && (!function_exists('trait_exists') || !trait_exists($class, false))) {
throw new \RuntimeException(sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file));
}
}
} | php | public function loadClass($class)
{
if ($file = $this->findFile($class)) {
require $file;
if (!class_exists($class, false) && !interface_exists($class, false) && (!function_exists('trait_exists') || !trait_exists($class, false))) {
throw new \RuntimeException(sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file));
}
}
} | [
"public",
"function",
"loadClass",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"$",
"file",
"=",
"$",
"this",
"->",
"findFile",
"(",
"$",
"class",
")",
")",
"{",
"require",
"$",
"file",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
",",
"false",
")",
"&&",
"!",
"interface_exists",
"(",
"$",
"class",
",",
"false",
")",
"&&",
"(",
"!",
"function_exists",
"(",
"'trait_exists'",
")",
"||",
"!",
"trait_exists",
"(",
"$",
"class",
",",
"false",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'The autoloader expected class \"%s\" to be defined in file \"%s\". The file was found but the class was not in it, the class name or namespace probably has a typo.'",
",",
"$",
"class",
",",
"$",
"file",
")",
")",
";",
"}",
"}",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/symfony/class-loader/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php#L53-L62 |
Danack/GithubArtaxService | lib/GithubService/Model/RepoStatsPunchCardInfo.php | RepoStatsPunchCardInfo.createFromData | static function createFromData($data) {
$instance = new static();
$instance->day = $data[0];
$instance->hour = $data[1];
$instance->numberCommits = $data[2];
return $instance;
} | php | static function createFromData($data) {
$instance = new static();
$instance->day = $data[0];
$instance->hour = $data[1];
$instance->numberCommits = $data[2];
return $instance;
} | [
"static",
"function",
"createFromData",
"(",
"$",
"data",
")",
"{",
"$",
"instance",
"=",
"new",
"static",
"(",
")",
";",
"$",
"instance",
"->",
"day",
"=",
"$",
"data",
"[",
"0",
"]",
";",
"$",
"instance",
"->",
"hour",
"=",
"$",
"data",
"[",
"1",
"]",
";",
"$",
"instance",
"->",
"numberCommits",
"=",
"$",
"data",
"[",
"2",
"]",
";",
"return",
"$",
"instance",
";",
"}"
] | Number of commits | [
"Number",
"of",
"commits"
] | train | https://github.com/Danack/GithubArtaxService/blob/9f62b5be4f413207d4012e7fa084d0ae505680eb/lib/GithubService/Model/RepoStatsPunchCardInfo.php#L22-L30 |
raideer/twitch-api | src/Wrapper.php | Wrapper.registerResource | public function registerResource(Resources\Resource $resource)
{
$this->resources[strtolower($resource->getName())] = $resource;
} | php | public function registerResource(Resources\Resource $resource)
{
$this->resources[strtolower($resource->getName())] = $resource;
} | [
"public",
"function",
"registerResource",
"(",
"Resources",
"\\",
"Resource",
"$",
"resource",
")",
"{",
"$",
"this",
"->",
"resources",
"[",
"strtolower",
"(",
"$",
"resource",
"->",
"getName",
"(",
")",
")",
"]",
"=",
"$",
"resource",
";",
"}"
] | Registers a resource.
@param ResourcesResource $resource
@return void | [
"Registers",
"a",
"resource",
"."
] | train | https://github.com/raideer/twitch-api/blob/27ebf1dcb0315206300d507600b6a82ebe33d57e/src/Wrapper.php#L71-L74 |
raideer/twitch-api | src/Wrapper.php | Wrapper.authorize | public function authorize($args)
{
$numArgs = func_num_args();
if ($numArgs === 0) {
throw new \InvalidArgumentException('Wrapper->authorize expects atleast 1 argument!');
return;
}
if ($numArgs === 1) {
$arg1 = func_get_arg(0);
if ($arg1 instanceof OAuthResponse) {
$this->accessToken = $arg1->getAccessToken();
$this->registeredScopes = $arg1->getScope();
} elseif (is_string($arg1)) {
$this->accessToken = $arg1;
} else {
throw new \InvalidArgumentException("Passed argument must be an access token OR an instance of Raideer\TwitchApi\OAuthResponse");
return;
}
} elseif ($numArgs === 2) {
list($arg1, $arg2) = func_get_args();
if (is_string($arg1) && is_array($arg2)) {
$this->accessToken = $arg1;
$this->registeredScopes = $arg2;
} else {
throw new \InvalidArgumentException('First argument must be an accessToken and the second must be an array of registered scopes');
return;
}
} else {
throw new \InvalidArgumentException('Wrapper->authorize expects 1 or 2 arguments');
return;
}
$this->authorized = true;
} | php | public function authorize($args)
{
$numArgs = func_num_args();
if ($numArgs === 0) {
throw new \InvalidArgumentException('Wrapper->authorize expects atleast 1 argument!');
return;
}
if ($numArgs === 1) {
$arg1 = func_get_arg(0);
if ($arg1 instanceof OAuthResponse) {
$this->accessToken = $arg1->getAccessToken();
$this->registeredScopes = $arg1->getScope();
} elseif (is_string($arg1)) {
$this->accessToken = $arg1;
} else {
throw new \InvalidArgumentException("Passed argument must be an access token OR an instance of Raideer\TwitchApi\OAuthResponse");
return;
}
} elseif ($numArgs === 2) {
list($arg1, $arg2) = func_get_args();
if (is_string($arg1) && is_array($arg2)) {
$this->accessToken = $arg1;
$this->registeredScopes = $arg2;
} else {
throw new \InvalidArgumentException('First argument must be an accessToken and the second must be an array of registered scopes');
return;
}
} else {
throw new \InvalidArgumentException('Wrapper->authorize expects 1 or 2 arguments');
return;
}
$this->authorized = true;
} | [
"public",
"function",
"authorize",
"(",
"$",
"args",
")",
"{",
"$",
"numArgs",
"=",
"func_num_args",
"(",
")",
";",
"if",
"(",
"$",
"numArgs",
"===",
"0",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Wrapper->authorize expects atleast 1 argument!'",
")",
";",
"return",
";",
"}",
"if",
"(",
"$",
"numArgs",
"===",
"1",
")",
"{",
"$",
"arg1",
"=",
"func_get_arg",
"(",
"0",
")",
";",
"if",
"(",
"$",
"arg1",
"instanceof",
"OAuthResponse",
")",
"{",
"$",
"this",
"->",
"accessToken",
"=",
"$",
"arg1",
"->",
"getAccessToken",
"(",
")",
";",
"$",
"this",
"->",
"registeredScopes",
"=",
"$",
"arg1",
"->",
"getScope",
"(",
")",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"arg1",
")",
")",
"{",
"$",
"this",
"->",
"accessToken",
"=",
"$",
"arg1",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Passed argument must be an access token OR an instance of Raideer\\TwitchApi\\OAuthResponse\"",
")",
";",
"return",
";",
"}",
"}",
"elseif",
"(",
"$",
"numArgs",
"===",
"2",
")",
"{",
"list",
"(",
"$",
"arg1",
",",
"$",
"arg2",
")",
"=",
"func_get_args",
"(",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"arg1",
")",
"&&",
"is_array",
"(",
"$",
"arg2",
")",
")",
"{",
"$",
"this",
"->",
"accessToken",
"=",
"$",
"arg1",
";",
"$",
"this",
"->",
"registeredScopes",
"=",
"$",
"arg2",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'First argument must be an accessToken and the second must be an array of registered scopes'",
")",
";",
"return",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Wrapper->authorize expects 1 or 2 arguments'",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"authorized",
"=",
"true",
";",
"}"
] | Enables the authorized requests.
@param string $args Access token
OR
@param OAuthResponse $args Object returned by OAuth->getResponse()
OR
@param string $arg1 Access Token
@param array $arg2 Array of registered scopes
@return void | [
"Enables",
"the",
"authorized",
"requests",
"."
] | train | https://github.com/raideer/twitch-api/blob/27ebf1dcb0315206300d507600b6a82ebe33d57e/src/Wrapper.php#L118-L158 |
raideer/twitch-api | src/Wrapper.php | Wrapper.hasScope | public function hasScope($name, $strict = true)
{
if (!$strict) {
if (empty($this->registeredScopes)) {
return true;
}
}
return in_array($name, $this->registeredScopes);
} | php | public function hasScope($name, $strict = true)
{
if (!$strict) {
if (empty($this->registeredScopes)) {
return true;
}
}
return in_array($name, $this->registeredScopes);
} | [
"public",
"function",
"hasScope",
"(",
"$",
"name",
",",
"$",
"strict",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"strict",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"registeredScopes",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"in_array",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"registeredScopes",
")",
";",
"}"
] | Checks if scope is registered.
@param string $name Scope name
@param bool $strict If false and registeredScopes array is empty, function will return true.
Used by Resources. If an array of registered scopes is passed in
Wrapper->authorize() function, authorized requests will check if scope is
registered without making a request to the twitch api.
@return bool | [
"Checks",
"if",
"scope",
"is",
"registered",
"."
] | train | https://github.com/raideer/twitch-api/blob/27ebf1dcb0315206300d507600b6a82ebe33d57e/src/Wrapper.php#L171-L180 |
raideer/twitch-api | src/Wrapper.php | Wrapper.checkScope | public function checkScope($name, $strict = false)
{
if (!$this->hasScope($name, $strict)) {
throw new Exceptions\OutOfScopeException("Scope $name is not registered!");
}
} | php | public function checkScope($name, $strict = false)
{
if (!$this->hasScope($name, $strict)) {
throw new Exceptions\OutOfScopeException("Scope $name is not registered!");
}
} | [
"public",
"function",
"checkScope",
"(",
"$",
"name",
",",
"$",
"strict",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasScope",
"(",
"$",
"name",
",",
"$",
"strict",
")",
")",
"{",
"throw",
"new",
"Exceptions",
"\\",
"OutOfScopeException",
"(",
"\"Scope $name is not registered!\"",
")",
";",
"}",
"}"
] | Checks if scope is registered
Throws an exception if scope doesn't exist.
@param string $name Scope name
@param bool $strict
@return void | [
"Checks",
"if",
"scope",
"is",
"registered",
"Throws",
"an",
"exception",
"if",
"scope",
"doesn",
"t",
"exist",
"."
] | train | https://github.com/raideer/twitch-api/blob/27ebf1dcb0315206300d507600b6a82ebe33d57e/src/Wrapper.php#L191-L196 |
raideer/twitch-api | src/Wrapper.php | Wrapper.resource | public function resource($name)
{
if (!isset($this->resources[$name])) {
throw new Exceptions\ResourceException("Resource $name does not exist!");
return;
}
return $this->resources[$name];
} | php | public function resource($name)
{
if (!isset($this->resources[$name])) {
throw new Exceptions\ResourceException("Resource $name does not exist!");
return;
}
return $this->resources[$name];
} | [
"public",
"function",
"resource",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"resources",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"Exceptions",
"\\",
"ResourceException",
"(",
"\"Resource $name does not exist!\"",
")",
";",
"return",
";",
"}",
"return",
"$",
"this",
"->",
"resources",
"[",
"$",
"name",
"]",
";",
"}"
] | Returns an API resource.
@param string $name Name of the resource
@return Raideer\TwitchApi\Resources\Resource | [
"Returns",
"an",
"API",
"resource",
"."
] | train | https://github.com/raideer/twitch-api/blob/27ebf1dcb0315206300d507600b6a82ebe33d57e/src/Wrapper.php#L223-L232 |
raideer/twitch-api | src/Wrapper.php | Wrapper.request | public function request($type, $target, $options = [], $authorized = false)
{
$headers = [
'Accept' => 'application/vnd.twitchtv.v3+json',
];
if ($authorized) {
$headers['Authorization'] = 'OAuth '.$this->accessToken;
}
$options = array_merge_recursive(['headers' => $headers], $options);
try {
if ($this->throttling) {
$this->throttle->throttle();
}
$response = $this->client->request($type, $this->apiURL.$target, $options);
} catch (RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
} else {
return;
}
}
$body = json_decode($response->getBody()->getContents());
return (json_last_error() == JSON_ERROR_NONE) ? $body : $response->getBody()->getContents();
} | php | public function request($type, $target, $options = [], $authorized = false)
{
$headers = [
'Accept' => 'application/vnd.twitchtv.v3+json',
];
if ($authorized) {
$headers['Authorization'] = 'OAuth '.$this->accessToken;
}
$options = array_merge_recursive(['headers' => $headers], $options);
try {
if ($this->throttling) {
$this->throttle->throttle();
}
$response = $this->client->request($type, $this->apiURL.$target, $options);
} catch (RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
} else {
return;
}
}
$body = json_decode($response->getBody()->getContents());
return (json_last_error() == JSON_ERROR_NONE) ? $body : $response->getBody()->getContents();
} | [
"public",
"function",
"request",
"(",
"$",
"type",
",",
"$",
"target",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"authorized",
"=",
"false",
")",
"{",
"$",
"headers",
"=",
"[",
"'Accept'",
"=>",
"'application/vnd.twitchtv.v3+json'",
",",
"]",
";",
"if",
"(",
"$",
"authorized",
")",
"{",
"$",
"headers",
"[",
"'Authorization'",
"]",
"=",
"'OAuth '",
".",
"$",
"this",
"->",
"accessToken",
";",
"}",
"$",
"options",
"=",
"array_merge_recursive",
"(",
"[",
"'headers'",
"=>",
"$",
"headers",
"]",
",",
"$",
"options",
")",
";",
"try",
"{",
"if",
"(",
"$",
"this",
"->",
"throttling",
")",
"{",
"$",
"this",
"->",
"throttle",
"->",
"throttle",
"(",
")",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"request",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"apiURL",
".",
"$",
"target",
",",
"$",
"options",
")",
";",
"}",
"catch",
"(",
"RequestException",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"e",
"->",
"hasResponse",
"(",
")",
")",
"{",
"$",
"response",
"=",
"$",
"e",
"->",
"getResponse",
"(",
")",
";",
"}",
"else",
"{",
"return",
";",
"}",
"}",
"$",
"body",
"=",
"json_decode",
"(",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"getContents",
"(",
")",
")",
";",
"return",
"(",
"json_last_error",
"(",
")",
"==",
"JSON_ERROR_NONE",
")",
"?",
"$",
"body",
":",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"getContents",
"(",
")",
";",
"}"
] | Makes a GuzzleHttp request.
@param requestType $type GET, POST, PUT, DELETE
@param string $target Target URL
@param array $options Request options
@param bool $authorized Attach Authorization headers
@return array JsonDecoded body contents | [
"Makes",
"a",
"GuzzleHttp",
"request",
"."
] | train | https://github.com/raideer/twitch-api/blob/27ebf1dcb0315206300d507600b6a82ebe33d57e/src/Wrapper.php#L268-L297 |
ComposePress/core | src/Abstracts/Manager.php | Manager.get_module | public function get_module( $name ) {
if ( null === $name ) {
return false;
}
if ( isset( $this->modules[ $name ] ) ) {
return $this->modules[ $name ];
}
$name = "\\{$name}";
if ( isset( $this->modules[ $name ] ) ) {
return $this->modules[ $name ];
}
return false;
} | php | public function get_module( $name ) {
if ( null === $name ) {
return false;
}
if ( isset( $this->modules[ $name ] ) ) {
return $this->modules[ $name ];
}
$name = "\\{$name}";
if ( isset( $this->modules[ $name ] ) ) {
return $this->modules[ $name ];
}
return false;
} | [
"public",
"function",
"get_module",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"name",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"modules",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"modules",
"[",
"$",
"name",
"]",
";",
"}",
"$",
"name",
"=",
"\"\\\\{$name}\"",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"modules",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"modules",
"[",
"$",
"name",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | @param $name
@return bool|mixed | [
"@param",
"$name"
] | train | https://github.com/ComposePress/core/blob/f403f81d06a1e43017cb23c19c980fe3ef3bb6f7/src/Abstracts/Manager.php#L71-L84 |
Isset/pushnotification | src/PushNotification/Type/Apple/AppleNotifier.php | AppleNotifier.sendMessage | protected function sendMessage(Message $message, string $connectionName = null): MessageEnvelope
{
/* @var AppleMessage $message */
try {
$envelope = $this->createMessageEnvelope($message);
$connection = $this->getConnectionHandler()->getConnection($connectionName);
$response = $connection->sendAndReceive($message);
$envelope->setResponse($response);
if ($response->isSuccess()) {
$envelope->setState(MessageEnvelope::SUCCESS);
} else {
$envelope->setState(MessageEnvelope::FAILED);
}
return $envelope;
} catch (Exception $e) {
$this->getLogger()->error('Exception occurred sending an apple message: ' . $e->getMessage());
throw new AppleNotifyFailedException($e->getMessage(), $e->getCode(), $e);
}
} | php | protected function sendMessage(Message $message, string $connectionName = null): MessageEnvelope
{
/* @var AppleMessage $message */
try {
$envelope = $this->createMessageEnvelope($message);
$connection = $this->getConnectionHandler()->getConnection($connectionName);
$response = $connection->sendAndReceive($message);
$envelope->setResponse($response);
if ($response->isSuccess()) {
$envelope->setState(MessageEnvelope::SUCCESS);
} else {
$envelope->setState(MessageEnvelope::FAILED);
}
return $envelope;
} catch (Exception $e) {
$this->getLogger()->error('Exception occurred sending an apple message: ' . $e->getMessage());
throw new AppleNotifyFailedException($e->getMessage(), $e->getCode(), $e);
}
} | [
"protected",
"function",
"sendMessage",
"(",
"Message",
"$",
"message",
",",
"string",
"$",
"connectionName",
"=",
"null",
")",
":",
"MessageEnvelope",
"{",
"/* @var AppleMessage $message */",
"try",
"{",
"$",
"envelope",
"=",
"$",
"this",
"->",
"createMessageEnvelope",
"(",
"$",
"message",
")",
";",
"$",
"connection",
"=",
"$",
"this",
"->",
"getConnectionHandler",
"(",
")",
"->",
"getConnection",
"(",
"$",
"connectionName",
")",
";",
"$",
"response",
"=",
"$",
"connection",
"->",
"sendAndReceive",
"(",
"$",
"message",
")",
";",
"$",
"envelope",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"if",
"(",
"$",
"response",
"->",
"isSuccess",
"(",
")",
")",
"{",
"$",
"envelope",
"->",
"setState",
"(",
"MessageEnvelope",
"::",
"SUCCESS",
")",
";",
"}",
"else",
"{",
"$",
"envelope",
"->",
"setState",
"(",
"MessageEnvelope",
"::",
"FAILED",
")",
";",
"}",
"return",
"$",
"envelope",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"error",
"(",
"'Exception occurred sending an apple message: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"throw",
"new",
"AppleNotifyFailedException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
";",
"}",
"}"
] | @param Message $message
@param string|null $connectionName
@throws ConnectionHandlerException
@throws ConnectionException
@throws AppleNotifyFailedException
@return MessageEnvelope | [
"@param",
"Message",
"$message",
"@param",
"string|null",
"$connectionName"
] | train | https://github.com/Isset/pushnotification/blob/5e7634dc6b1cf4f7c371d1890243a25252db0d85/src/PushNotification/Type/Apple/AppleNotifier.php#L44-L63 |
Isset/pushnotification | src/PushNotification/Type/Apple/AppleNotifier.php | AppleNotifier.flushQueueItem | protected function flushQueueItem(string $connectionName, MessageEnvelopeQueue $queue)
{
if ($queue->isEmpty()) {
return;
}
$connection = $this->getConnectionHandler()->getConnection($connectionName);
/* @var AppleConnection $connection */
foreach ($queue->getQueue() as $item) {
/* @var AppleMessageEnvelope $item */
$connection->send($item->getMessage());
}
$response = $this->getResponseData($connection);
if ($response->isSuccess()) {
$queue->traverseWith(function (MessageEnvelope $messageEnvelope) {
$messageEnvelope->setState(MessageEnvelope::SUCCESS);
});
$queue->clear();
} else {
$this->handleErrorResponse($connectionName, $queue, $response);
}
} | php | protected function flushQueueItem(string $connectionName, MessageEnvelopeQueue $queue)
{
if ($queue->isEmpty()) {
return;
}
$connection = $this->getConnectionHandler()->getConnection($connectionName);
/* @var AppleConnection $connection */
foreach ($queue->getQueue() as $item) {
/* @var AppleMessageEnvelope $item */
$connection->send($item->getMessage());
}
$response = $this->getResponseData($connection);
if ($response->isSuccess()) {
$queue->traverseWith(function (MessageEnvelope $messageEnvelope) {
$messageEnvelope->setState(MessageEnvelope::SUCCESS);
});
$queue->clear();
} else {
$this->handleErrorResponse($connectionName, $queue, $response);
}
} | [
"protected",
"function",
"flushQueueItem",
"(",
"string",
"$",
"connectionName",
",",
"MessageEnvelopeQueue",
"$",
"queue",
")",
"{",
"if",
"(",
"$",
"queue",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"connection",
"=",
"$",
"this",
"->",
"getConnectionHandler",
"(",
")",
"->",
"getConnection",
"(",
"$",
"connectionName",
")",
";",
"/* @var AppleConnection $connection */",
"foreach",
"(",
"$",
"queue",
"->",
"getQueue",
"(",
")",
"as",
"$",
"item",
")",
"{",
"/* @var AppleMessageEnvelope $item */",
"$",
"connection",
"->",
"send",
"(",
"$",
"item",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"getResponseData",
"(",
"$",
"connection",
")",
";",
"if",
"(",
"$",
"response",
"->",
"isSuccess",
"(",
")",
")",
"{",
"$",
"queue",
"->",
"traverseWith",
"(",
"function",
"(",
"MessageEnvelope",
"$",
"messageEnvelope",
")",
"{",
"$",
"messageEnvelope",
"->",
"setState",
"(",
"MessageEnvelope",
"::",
"SUCCESS",
")",
";",
"}",
")",
";",
"$",
"queue",
"->",
"clear",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"handleErrorResponse",
"(",
"$",
"connectionName",
",",
"$",
"queue",
",",
"$",
"response",
")",
";",
"}",
"}"
] | @param string $connectionName
@param MessageEnvelopeQueue $queue
@throws AppleNotifyFailedException
@throws ConnectionHandlerException
@throws ConnectionException | [
"@param",
"string",
"$connectionName",
"@param",
"MessageEnvelopeQueue",
"$queue"
] | train | https://github.com/Isset/pushnotification/blob/5e7634dc6b1cf4f7c371d1890243a25252db0d85/src/PushNotification/Type/Apple/AppleNotifier.php#L73-L95 |
Isset/pushnotification | src/PushNotification/Type/Apple/AppleNotifier.php | AppleNotifier.handleErrorResponse | private function handleErrorResponse(string $connectionName, MessageEnvelopeQueue $queue, Response $response)
{
$error = $response->getResponse();
if (false === is_array($error) or !array_key_exists('identifier', $error)) {
$queue->traverseWith(function (MessageEnvelope $messageEnvelope) {
$messageEnvelope->setState(MessageEnvelope::FAILED);
});
$queue->clear();
throw new AppleNotifyFailedException('Message gave an error but no response all messages marked as failed');
}
// Get all the items that are sent before or are the failed identifier
$preIdentifierQueue = $queue->split($error['identifier']);
// remove the failed identifier from the queue so we can fail it
$failedMessage = $preIdentifierQueue->remove($error['identifier'])->getOrThrow(new AppleNotifyFailedException('Failed identifier not found: ' . $error['identifier']));
$failedMessage->setState(MessageEnvelope::FAILED);
$failedMessage->setResponse($response);
// every message before the failed one are successful
$preIdentifierQueue->traverseWith(function (MessageEnvelope $messageEnvelope) {
$messageEnvelope->setState(MessageEnvelope::SUCCESS);
});
// reflush the remainder of the queue these messages have to be send again
$this->flushQueueItem($connectionName, $queue);
} | php | private function handleErrorResponse(string $connectionName, MessageEnvelopeQueue $queue, Response $response)
{
$error = $response->getResponse();
if (false === is_array($error) or !array_key_exists('identifier', $error)) {
$queue->traverseWith(function (MessageEnvelope $messageEnvelope) {
$messageEnvelope->setState(MessageEnvelope::FAILED);
});
$queue->clear();
throw new AppleNotifyFailedException('Message gave an error but no response all messages marked as failed');
}
// Get all the items that are sent before or are the failed identifier
$preIdentifierQueue = $queue->split($error['identifier']);
// remove the failed identifier from the queue so we can fail it
$failedMessage = $preIdentifierQueue->remove($error['identifier'])->getOrThrow(new AppleNotifyFailedException('Failed identifier not found: ' . $error['identifier']));
$failedMessage->setState(MessageEnvelope::FAILED);
$failedMessage->setResponse($response);
// every message before the failed one are successful
$preIdentifierQueue->traverseWith(function (MessageEnvelope $messageEnvelope) {
$messageEnvelope->setState(MessageEnvelope::SUCCESS);
});
// reflush the remainder of the queue these messages have to be send again
$this->flushQueueItem($connectionName, $queue);
} | [
"private",
"function",
"handleErrorResponse",
"(",
"string",
"$",
"connectionName",
",",
"MessageEnvelopeQueue",
"$",
"queue",
",",
"Response",
"$",
"response",
")",
"{",
"$",
"error",
"=",
"$",
"response",
"->",
"getResponse",
"(",
")",
";",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"error",
")",
"or",
"!",
"array_key_exists",
"(",
"'identifier'",
",",
"$",
"error",
")",
")",
"{",
"$",
"queue",
"->",
"traverseWith",
"(",
"function",
"(",
"MessageEnvelope",
"$",
"messageEnvelope",
")",
"{",
"$",
"messageEnvelope",
"->",
"setState",
"(",
"MessageEnvelope",
"::",
"FAILED",
")",
";",
"}",
")",
";",
"$",
"queue",
"->",
"clear",
"(",
")",
";",
"throw",
"new",
"AppleNotifyFailedException",
"(",
"'Message gave an error but no response all messages marked as failed'",
")",
";",
"}",
"// Get all the items that are sent before or are the failed identifier",
"$",
"preIdentifierQueue",
"=",
"$",
"queue",
"->",
"split",
"(",
"$",
"error",
"[",
"'identifier'",
"]",
")",
";",
"// remove the failed identifier from the queue so we can fail it",
"$",
"failedMessage",
"=",
"$",
"preIdentifierQueue",
"->",
"remove",
"(",
"$",
"error",
"[",
"'identifier'",
"]",
")",
"->",
"getOrThrow",
"(",
"new",
"AppleNotifyFailedException",
"(",
"'Failed identifier not found: '",
".",
"$",
"error",
"[",
"'identifier'",
"]",
")",
")",
";",
"$",
"failedMessage",
"->",
"setState",
"(",
"MessageEnvelope",
"::",
"FAILED",
")",
";",
"$",
"failedMessage",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"// every message before the failed one are successful",
"$",
"preIdentifierQueue",
"->",
"traverseWith",
"(",
"function",
"(",
"MessageEnvelope",
"$",
"messageEnvelope",
")",
"{",
"$",
"messageEnvelope",
"->",
"setState",
"(",
"MessageEnvelope",
"::",
"SUCCESS",
")",
";",
"}",
")",
";",
"// reflush the remainder of the queue these messages have to be send again",
"$",
"this",
"->",
"flushQueueItem",
"(",
"$",
"connectionName",
",",
"$",
"queue",
")",
";",
"}"
] | @param string $connectionName
@param MessageEnvelopeQueue $queue
@param Response $response
@throws AppleNotifyFailedException
@throws ConnectionException
@throws ConnectionHandlerException | [
"@param",
"string",
"$connectionName",
"@param",
"MessageEnvelopeQueue",
"$queue",
"@param",
"Response",
"$response"
] | train | https://github.com/Isset/pushnotification/blob/5e7634dc6b1cf4f7c371d1890243a25252db0d85/src/PushNotification/Type/Apple/AppleNotifier.php#L117-L139 |
yeaha/owl-core | src/Crontab.php | Crontab.start | public function start()
{
$try = $this->tryStart();
$this->log('debug', 'try start', [
'result' => (int) $try,
]);
if (!$try) {
return false;
}
$this->log('info', 'Job start');
// 把进程ID和开始时间记录到上下文中
$this->setContext(self::KEY_PROC_ID, posix_getpid());
$this->setContext(self::KEY_PROC_TIME, time());
$this->saveContext();
// 执行任务逻辑
try {
$this->execute();
} catch (\Exception $ex) {
$this->log('error', 'Job execute error', [
'error' => $ex->getMessage(),
]);
return false;
}
$this->stop();
return true;
} | php | public function start()
{
$try = $this->tryStart();
$this->log('debug', 'try start', [
'result' => (int) $try,
]);
if (!$try) {
return false;
}
$this->log('info', 'Job start');
// 把进程ID和开始时间记录到上下文中
$this->setContext(self::KEY_PROC_ID, posix_getpid());
$this->setContext(self::KEY_PROC_TIME, time());
$this->saveContext();
// 执行任务逻辑
try {
$this->execute();
} catch (\Exception $ex) {
$this->log('error', 'Job execute error', [
'error' => $ex->getMessage(),
]);
return false;
}
$this->stop();
return true;
} | [
"public",
"function",
"start",
"(",
")",
"{",
"$",
"try",
"=",
"$",
"this",
"->",
"tryStart",
"(",
")",
";",
"$",
"this",
"->",
"log",
"(",
"'debug'",
",",
"'try start'",
",",
"[",
"'result'",
"=>",
"(",
"int",
")",
"$",
"try",
",",
"]",
")",
";",
"if",
"(",
"!",
"$",
"try",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"log",
"(",
"'info'",
",",
"'Job start'",
")",
";",
"// 把进程ID和开始时间记录到上下文中",
"$",
"this",
"->",
"setContext",
"(",
"self",
"::",
"KEY_PROC_ID",
",",
"posix_getpid",
"(",
")",
")",
";",
"$",
"this",
"->",
"setContext",
"(",
"self",
"::",
"KEY_PROC_TIME",
",",
"time",
"(",
")",
")",
";",
"$",
"this",
"->",
"saveContext",
"(",
")",
";",
"// 执行任务逻辑",
"try",
"{",
"$",
"this",
"->",
"execute",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"'error'",
",",
"'Job execute error'",
",",
"[",
"'error'",
"=>",
"$",
"ex",
"->",
"getMessage",
"(",
")",
",",
"]",
")",
";",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"stop",
"(",
")",
";",
"return",
"true",
";",
"}"
] | 执行任务
@return bool | [
"执行任务"
] | train | https://github.com/yeaha/owl-core/blob/fd7531c0a5c0142300a96160bd079f2e2d92fe4c/src/Crontab.php#L25-L57 |
yeaha/owl-core | src/Crontab.php | Crontab.stop | public function stop()
{
$this->removeContext(self::KEY_PROC_ID);
$this->removeContext(self::KEY_PROC_TIME);
$this->saveContext();
$this->log('info', 'Job execute completed');
} | php | public function stop()
{
$this->removeContext(self::KEY_PROC_ID);
$this->removeContext(self::KEY_PROC_TIME);
$this->saveContext();
$this->log('info', 'Job execute completed');
} | [
"public",
"function",
"stop",
"(",
")",
"{",
"$",
"this",
"->",
"removeContext",
"(",
"self",
"::",
"KEY_PROC_ID",
")",
";",
"$",
"this",
"->",
"removeContext",
"(",
"self",
"::",
"KEY_PROC_TIME",
")",
";",
"$",
"this",
"->",
"saveContext",
"(",
")",
";",
"$",
"this",
"->",
"log",
"(",
"'info'",
",",
"'Job execute completed'",
")",
";",
"}"
] | 任务执行完毕. | [
"任务执行完毕",
"."
] | train | https://github.com/yeaha/owl-core/blob/fd7531c0a5c0142300a96160bd079f2e2d92fe4c/src/Crontab.php#L62-L69 |
yeaha/owl-core | src/Crontab.php | Crontab.tryStart | protected function tryStart()
{
// 检查是否达到预定时间
try {
if (!$this->testTimer()) {
return false;
}
} catch (\Exception $ex) {
$this->log('error', 'Job testTimer() error', [
'error' => $ex->getMessage(),
]);
return false;
}
// 上下文中是否保存了前一个任务pid
if (!$recent_proc_id = $this->getContext(self::KEY_PROC_ID)) {
return true;
}
// 检查进程ID是否真正存在
if (!posix_kill($recent_proc_id, 0)) {
$errno = posix_get_last_error();
if ($errno === 3) {
return true;
}
$this->log('warning', 'Job kill error', [
'error' => posix_strerror($errno),
]);
return false;
}
// 如果上一个任务还没有超时就放弃当前任务
$recent_proc_time = $this->getContext(self::KEY_PROC_TIME);
if (time() - $recent_proc_time < $this->timeout) {
$this->log('notice', 'Job cancel, previous job still run', [
'previous_proc_id' => $recent_proc_id,
]);
return false;
}
// 中止超时任务
posix_kill($recent_proc_id, SIGKILL);
$this->log('warning', 'Job killed by timeout', [
'previous_proc_id' => $recent_proc_id,
]);
return true;
} | php | protected function tryStart()
{
// 检查是否达到预定时间
try {
if (!$this->testTimer()) {
return false;
}
} catch (\Exception $ex) {
$this->log('error', 'Job testTimer() error', [
'error' => $ex->getMessage(),
]);
return false;
}
// 上下文中是否保存了前一个任务pid
if (!$recent_proc_id = $this->getContext(self::KEY_PROC_ID)) {
return true;
}
// 检查进程ID是否真正存在
if (!posix_kill($recent_proc_id, 0)) {
$errno = posix_get_last_error();
if ($errno === 3) {
return true;
}
$this->log('warning', 'Job kill error', [
'error' => posix_strerror($errno),
]);
return false;
}
// 如果上一个任务还没有超时就放弃当前任务
$recent_proc_time = $this->getContext(self::KEY_PROC_TIME);
if (time() - $recent_proc_time < $this->timeout) {
$this->log('notice', 'Job cancel, previous job still run', [
'previous_proc_id' => $recent_proc_id,
]);
return false;
}
// 中止超时任务
posix_kill($recent_proc_id, SIGKILL);
$this->log('warning', 'Job killed by timeout', [
'previous_proc_id' => $recent_proc_id,
]);
return true;
} | [
"protected",
"function",
"tryStart",
"(",
")",
"{",
"// 检查是否达到预定时间",
"try",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"testTimer",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"'error'",
",",
"'Job testTimer() error'",
",",
"[",
"'error'",
"=>",
"$",
"ex",
"->",
"getMessage",
"(",
")",
",",
"]",
")",
";",
"return",
"false",
";",
"}",
"// 上下文中是否保存了前一个任务pid",
"if",
"(",
"!",
"$",
"recent_proc_id",
"=",
"$",
"this",
"->",
"getContext",
"(",
"self",
"::",
"KEY_PROC_ID",
")",
")",
"{",
"return",
"true",
";",
"}",
"// 检查进程ID是否真正存在",
"if",
"(",
"!",
"posix_kill",
"(",
"$",
"recent_proc_id",
",",
"0",
")",
")",
"{",
"$",
"errno",
"=",
"posix_get_last_error",
"(",
")",
";",
"if",
"(",
"$",
"errno",
"===",
"3",
")",
"{",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"log",
"(",
"'warning'",
",",
"'Job kill error'",
",",
"[",
"'error'",
"=>",
"posix_strerror",
"(",
"$",
"errno",
")",
",",
"]",
")",
";",
"return",
"false",
";",
"}",
"// 如果上一个任务还没有超时就放弃当前任务",
"$",
"recent_proc_time",
"=",
"$",
"this",
"->",
"getContext",
"(",
"self",
"::",
"KEY_PROC_TIME",
")",
";",
"if",
"(",
"time",
"(",
")",
"-",
"$",
"recent_proc_time",
"<",
"$",
"this",
"->",
"timeout",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"'notice'",
",",
"'Job cancel, previous job still run'",
",",
"[",
"'previous_proc_id'",
"=>",
"$",
"recent_proc_id",
",",
"]",
")",
";",
"return",
"false",
";",
"}",
"// 中止超时任务",
"posix_kill",
"(",
"$",
"recent_proc_id",
",",
"SIGKILL",
")",
";",
"$",
"this",
"->",
"log",
"(",
"'warning'",
",",
"'Job killed by timeout'",
",",
"[",
"'previous_proc_id'",
"=>",
"$",
"recent_proc_id",
",",
"]",
")",
";",
"return",
"true",
";",
"}"
] | 尝试开始任务
@return bool | [
"尝试开始任务"
] | train | https://github.com/yeaha/owl-core/blob/fd7531c0a5c0142300a96160bd079f2e2d92fe4c/src/Crontab.php#L76-L128 |
josegonzalez/cakephp-sanction | Lib/Panel/PermitPanel.php | PermitPanel.beforeRender | public function beforeRender(Controller $controller) {
if (empty($controller->Permit->user)) {
$controller->Permit->user = $controller->Toolbar->Session->read($controller->Permit->settings['path']);
}
return array(
'user' => $controller->Permit->user,
'routes' => $controller->Permit->routes,
'executed' => $controller->Permit->executed,
);
} | php | public function beforeRender(Controller $controller) {
if (empty($controller->Permit->user)) {
$controller->Permit->user = $controller->Toolbar->Session->read($controller->Permit->settings['path']);
}
return array(
'user' => $controller->Permit->user,
'routes' => $controller->Permit->routes,
'executed' => $controller->Permit->executed,
);
} | [
"public",
"function",
"beforeRender",
"(",
"Controller",
"$",
"controller",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"controller",
"->",
"Permit",
"->",
"user",
")",
")",
"{",
"$",
"controller",
"->",
"Permit",
"->",
"user",
"=",
"$",
"controller",
"->",
"Toolbar",
"->",
"Session",
"->",
"read",
"(",
"$",
"controller",
"->",
"Permit",
"->",
"settings",
"[",
"'path'",
"]",
")",
";",
"}",
"return",
"array",
"(",
"'user'",
"=>",
"$",
"controller",
"->",
"Permit",
"->",
"user",
",",
"'routes'",
"=>",
"$",
"controller",
"->",
"Permit",
"->",
"routes",
",",
"'executed'",
"=>",
"$",
"controller",
"->",
"Permit",
"->",
"executed",
",",
")",
";",
"}"
] | Prepare output vars before Controller Rendering.
@param \Controller|object $controller Controller reference.
@return array | [
"Prepare",
"output",
"vars",
"before",
"Controller",
"Rendering",
"."
] | train | https://github.com/josegonzalez/cakephp-sanction/blob/df2a8f0c0602c0ace802773db2c2ca6c89555c47/Lib/Panel/PermitPanel.php#L14-L23 |
o2system/email | src/Spool.php | Spool.send | public function send(Message $message)
{
$protocolClass = '\O2System\Email\Protocols\\' . ucfirst($this->config->offsetGet('protocol')) . 'Protocol';
if (class_exists($protocolClass)) {
$protocol = new $protocolClass($this);
if ($protocol instanceof AbstractProtocol) {
return $protocol->send($message);
}
}
return false;
} | php | public function send(Message $message)
{
$protocolClass = '\O2System\Email\Protocols\\' . ucfirst($this->config->offsetGet('protocol')) . 'Protocol';
if (class_exists($protocolClass)) {
$protocol = new $protocolClass($this);
if ($protocol instanceof AbstractProtocol) {
return $protocol->send($message);
}
}
return false;
} | [
"public",
"function",
"send",
"(",
"Message",
"$",
"message",
")",
"{",
"$",
"protocolClass",
"=",
"'\\O2System\\Email\\Protocols\\\\'",
".",
"ucfirst",
"(",
"$",
"this",
"->",
"config",
"->",
"offsetGet",
"(",
"'protocol'",
")",
")",
".",
"'Protocol'",
";",
"if",
"(",
"class_exists",
"(",
"$",
"protocolClass",
")",
")",
"{",
"$",
"protocol",
"=",
"new",
"$",
"protocolClass",
"(",
"$",
"this",
")",
";",
"if",
"(",
"$",
"protocol",
"instanceof",
"AbstractProtocol",
")",
"{",
"return",
"$",
"protocol",
"->",
"send",
"(",
"$",
"message",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Spool::send
@param \O2System\Email\Message $message
@return bool | [
"Spool",
"::",
"send"
] | train | https://github.com/o2system/email/blob/7c64b73f539cac8df4b2aaef474b29b949067898/src/Spool.php#L134-L147 |
krakphp/job | src/Queue/Doctrine/JobRepository.php | JobRepository.addJob | public function addJob(Job\WrappedJob $job, $queue) {
$qb = $this->conn->createQueryBuilder();
$qb->insert($this->table_name);
$qb->values([
'status' => ':status',
'job' => ':job',
'name' => ':name',
'queue' => ':queue',
'created_at' => ':created_at',
'available_at' => ':available_at',
]);
$qb->setParameters([
'status' => self::JOB_STATUS_CREATED,
'queue' => $queue,
'job' => (string) $job,
'name' => $job->getName(),
]);
$qb->setParameter(':created_at', new \DateTime(), Type::DATETIME);
$available_at = $job->getDelay()
? new \DateTime(sprintf('+%d seconds', $job->getDelay()))
: new \DateTime();
$qb->setParameter(':available_at', $available_at, Type::DATETIME);
$qb->execute();
return $job->withAddedPayload([
'_doctrine' => [
'id' => $this->conn->lastInsertId()
]
]);
} | php | public function addJob(Job\WrappedJob $job, $queue) {
$qb = $this->conn->createQueryBuilder();
$qb->insert($this->table_name);
$qb->values([
'status' => ':status',
'job' => ':job',
'name' => ':name',
'queue' => ':queue',
'created_at' => ':created_at',
'available_at' => ':available_at',
]);
$qb->setParameters([
'status' => self::JOB_STATUS_CREATED,
'queue' => $queue,
'job' => (string) $job,
'name' => $job->getName(),
]);
$qb->setParameter(':created_at', new \DateTime(), Type::DATETIME);
$available_at = $job->getDelay()
? new \DateTime(sprintf('+%d seconds', $job->getDelay()))
: new \DateTime();
$qb->setParameter(':available_at', $available_at, Type::DATETIME);
$qb->execute();
return $job->withAddedPayload([
'_doctrine' => [
'id' => $this->conn->lastInsertId()
]
]);
} | [
"public",
"function",
"addJob",
"(",
"Job",
"\\",
"WrappedJob",
"$",
"job",
",",
"$",
"queue",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"conn",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"qb",
"->",
"insert",
"(",
"$",
"this",
"->",
"table_name",
")",
";",
"$",
"qb",
"->",
"values",
"(",
"[",
"'status'",
"=>",
"':status'",
",",
"'job'",
"=>",
"':job'",
",",
"'name'",
"=>",
"':name'",
",",
"'queue'",
"=>",
"':queue'",
",",
"'created_at'",
"=>",
"':created_at'",
",",
"'available_at'",
"=>",
"':available_at'",
",",
"]",
")",
";",
"$",
"qb",
"->",
"setParameters",
"(",
"[",
"'status'",
"=>",
"self",
"::",
"JOB_STATUS_CREATED",
",",
"'queue'",
"=>",
"$",
"queue",
",",
"'job'",
"=>",
"(",
"string",
")",
"$",
"job",
",",
"'name'",
"=>",
"$",
"job",
"->",
"getName",
"(",
")",
",",
"]",
")",
";",
"$",
"qb",
"->",
"setParameter",
"(",
"':created_at'",
",",
"new",
"\\",
"DateTime",
"(",
")",
",",
"Type",
"::",
"DATETIME",
")",
";",
"$",
"available_at",
"=",
"$",
"job",
"->",
"getDelay",
"(",
")",
"?",
"new",
"\\",
"DateTime",
"(",
"sprintf",
"(",
"'+%d seconds'",
",",
"$",
"job",
"->",
"getDelay",
"(",
")",
")",
")",
":",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"qb",
"->",
"setParameter",
"(",
"':available_at'",
",",
"$",
"available_at",
",",
"Type",
"::",
"DATETIME",
")",
";",
"$",
"qb",
"->",
"execute",
"(",
")",
";",
"return",
"$",
"job",
"->",
"withAddedPayload",
"(",
"[",
"'_doctrine'",
"=>",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"conn",
"->",
"lastInsertId",
"(",
")",
"]",
"]",
")",
";",
"}"
] | add a new wrapped job | [
"add",
"a",
"new",
"wrapped",
"job"
] | train | https://github.com/krakphp/job/blob/0c16020c1baa13d91f819ecba8334861ba7c4d6c/src/Queue/Doctrine/JobRepository.php#L32-L61 |
krakphp/job | src/Queue/Doctrine/JobRepository.php | JobRepository.processJob | public function processJob(Job\WrappedJob $job) {
$data = $job->get('_doctrine');
$qb = $this->conn->createQueryBuilder();
$qb->update($this->table_name);
$qb->set('status', ':status');
$qb->set('processed_at', ':processed_at');
$qb->where('id = :id');
$qb->setParameters([
'id' => $data['id'],
'status' => self::JOB_STATUS_PROCESSING,
]);
$qb->setParameter('processed_at', new \DateTime(), Type::DATETIME);
$qb->execute();
} | php | public function processJob(Job\WrappedJob $job) {
$data = $job->get('_doctrine');
$qb = $this->conn->createQueryBuilder();
$qb->update($this->table_name);
$qb->set('status', ':status');
$qb->set('processed_at', ':processed_at');
$qb->where('id = :id');
$qb->setParameters([
'id' => $data['id'],
'status' => self::JOB_STATUS_PROCESSING,
]);
$qb->setParameter('processed_at', new \DateTime(), Type::DATETIME);
$qb->execute();
} | [
"public",
"function",
"processJob",
"(",
"Job",
"\\",
"WrappedJob",
"$",
"job",
")",
"{",
"$",
"data",
"=",
"$",
"job",
"->",
"get",
"(",
"'_doctrine'",
")",
";",
"$",
"qb",
"=",
"$",
"this",
"->",
"conn",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"qb",
"->",
"update",
"(",
"$",
"this",
"->",
"table_name",
")",
";",
"$",
"qb",
"->",
"set",
"(",
"'status'",
",",
"':status'",
")",
";",
"$",
"qb",
"->",
"set",
"(",
"'processed_at'",
",",
"':processed_at'",
")",
";",
"$",
"qb",
"->",
"where",
"(",
"'id = :id'",
")",
";",
"$",
"qb",
"->",
"setParameters",
"(",
"[",
"'id'",
"=>",
"$",
"data",
"[",
"'id'",
"]",
",",
"'status'",
"=>",
"self",
"::",
"JOB_STATUS_PROCESSING",
",",
"]",
")",
";",
"$",
"qb",
"->",
"setParameter",
"(",
"'processed_at'",
",",
"new",
"\\",
"DateTime",
"(",
")",
",",
"Type",
"::",
"DATETIME",
")",
";",
"$",
"qb",
"->",
"execute",
"(",
")",
";",
"}"
] | process job | [
"process",
"job"
] | train | https://github.com/krakphp/job/blob/0c16020c1baa13d91f819ecba8334861ba7c4d6c/src/Queue/Doctrine/JobRepository.php#L80-L93 |
krakphp/job | src/Queue/Doctrine/JobRepository.php | JobRepository.getAvailableJobs | public function getAvailableJobs($queue, $max = 10) {
$qb = $this->conn->createQueryBuilder();
$qb->select('*');
$qb->from($this->table_name);
$qb->where('status = :status AND queue = :queue AND available_at <= :now');
$qb->orderBy('status');
$qb->setParameters([
'status' => self::JOB_STATUS_CREATED,
'queue' => $queue,
]);
$qb->setParameter('now', new \DateTime(), Type::DATETIME);
$qb->setMaxResults($max);
$stmt = $qb->execute();
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
} | php | public function getAvailableJobs($queue, $max = 10) {
$qb = $this->conn->createQueryBuilder();
$qb->select('*');
$qb->from($this->table_name);
$qb->where('status = :status AND queue = :queue AND available_at <= :now');
$qb->orderBy('status');
$qb->setParameters([
'status' => self::JOB_STATUS_CREATED,
'queue' => $queue,
]);
$qb->setParameter('now', new \DateTime(), Type::DATETIME);
$qb->setMaxResults($max);
$stmt = $qb->execute();
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
} | [
"public",
"function",
"getAvailableJobs",
"(",
"$",
"queue",
",",
"$",
"max",
"=",
"10",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"conn",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"qb",
"->",
"select",
"(",
"'*'",
")",
";",
"$",
"qb",
"->",
"from",
"(",
"$",
"this",
"->",
"table_name",
")",
";",
"$",
"qb",
"->",
"where",
"(",
"'status = :status AND queue = :queue AND available_at <= :now'",
")",
";",
"$",
"qb",
"->",
"orderBy",
"(",
"'status'",
")",
";",
"$",
"qb",
"->",
"setParameters",
"(",
"[",
"'status'",
"=>",
"self",
"::",
"JOB_STATUS_CREATED",
",",
"'queue'",
"=>",
"$",
"queue",
",",
"]",
")",
";",
"$",
"qb",
"->",
"setParameter",
"(",
"'now'",
",",
"new",
"\\",
"DateTime",
"(",
")",
",",
"Type",
"::",
"DATETIME",
")",
";",
"$",
"qb",
"->",
"setMaxResults",
"(",
"$",
"max",
")",
";",
"$",
"stmt",
"=",
"$",
"qb",
"->",
"execute",
"(",
")",
";",
"return",
"$",
"stmt",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}"
] | get available jobs | [
"get",
"available",
"jobs"
] | train | https://github.com/krakphp/job/blob/0c16020c1baa13d91f819ecba8334861ba7c4d6c/src/Queue/Doctrine/JobRepository.php#L96-L110 |
lukasz-adamski/teamspeak3-framework | src/TeamSpeak3/Transport/UDP.php | UDP.connect | public function connect()
{
if($this->stream !== null) return;
$host = strval($this->config["host"]);
$port = strval($this->config["port"]);
$address = "udp://" . (strstr($host, ":") !== FALSE ? "[" . $host . "]" : $host) . ":" . $port;
$timeout = (int) $this->config["timeout"];
$this->stream = @stream_socket_client($address, $errno, $errstr, $timeout);
if($this->stream === FALSE)
{
throw new Exception(Str::factory($errstr)->toUtf8()->toString(), $errno);
}
@stream_set_timeout($this->stream, $timeout);
@stream_set_blocking($this->stream, $this->config["blocking"] ? 1 : 0);
} | php | public function connect()
{
if($this->stream !== null) return;
$host = strval($this->config["host"]);
$port = strval($this->config["port"]);
$address = "udp://" . (strstr($host, ":") !== FALSE ? "[" . $host . "]" : $host) . ":" . $port;
$timeout = (int) $this->config["timeout"];
$this->stream = @stream_socket_client($address, $errno, $errstr, $timeout);
if($this->stream === FALSE)
{
throw new Exception(Str::factory($errstr)->toUtf8()->toString(), $errno);
}
@stream_set_timeout($this->stream, $timeout);
@stream_set_blocking($this->stream, $this->config["blocking"] ? 1 : 0);
} | [
"public",
"function",
"connect",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"stream",
"!==",
"null",
")",
"return",
";",
"$",
"host",
"=",
"strval",
"(",
"$",
"this",
"->",
"config",
"[",
"\"host\"",
"]",
")",
";",
"$",
"port",
"=",
"strval",
"(",
"$",
"this",
"->",
"config",
"[",
"\"port\"",
"]",
")",
";",
"$",
"address",
"=",
"\"udp://\"",
".",
"(",
"strstr",
"(",
"$",
"host",
",",
"\":\"",
")",
"!==",
"FALSE",
"?",
"\"[\"",
".",
"$",
"host",
".",
"\"]\"",
":",
"$",
"host",
")",
".",
"\":\"",
".",
"$",
"port",
";",
"$",
"timeout",
"=",
"(",
"int",
")",
"$",
"this",
"->",
"config",
"[",
"\"timeout\"",
"]",
";",
"$",
"this",
"->",
"stream",
"=",
"@",
"stream_socket_client",
"(",
"$",
"address",
",",
"$",
"errno",
",",
"$",
"errstr",
",",
"$",
"timeout",
")",
";",
"if",
"(",
"$",
"this",
"->",
"stream",
"===",
"FALSE",
")",
"{",
"throw",
"new",
"Exception",
"(",
"Str",
"::",
"factory",
"(",
"$",
"errstr",
")",
"->",
"toUtf8",
"(",
")",
"->",
"toString",
"(",
")",
",",
"$",
"errno",
")",
";",
"}",
"@",
"stream_set_timeout",
"(",
"$",
"this",
"->",
"stream",
",",
"$",
"timeout",
")",
";",
"@",
"stream_set_blocking",
"(",
"$",
"this",
"->",
"stream",
",",
"$",
"this",
"->",
"config",
"[",
"\"blocking\"",
"]",
"?",
"1",
":",
"0",
")",
";",
"}"
] | Connects to a remote server.
@throws Exception
@return void | [
"Connects",
"to",
"a",
"remote",
"server",
"."
] | train | https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Transport/UDP.php#L44-L63 |
alevilar/ristorantino-vendor | Risto/Controller/Component/RistoAuthComponent.php | RistoAuthComponent.initialize | public function initialize(Controller $controller) {
parent::initialize($controller);
$loginUrl = array(
'plugin' => 'users',
'controller' => 'users',
'action' => 'login',
'admin' => false,
);
if ( !empty( $controller->request->params['tenant'] ) ) {
$loginUrl['action'] = 'tenant_login';
}
$this->loginAction = $loginUrl;
$this->logoutRedirect = $loginUrl;
} | php | public function initialize(Controller $controller) {
parent::initialize($controller);
$loginUrl = array(
'plugin' => 'users',
'controller' => 'users',
'action' => 'login',
'admin' => false,
);
if ( !empty( $controller->request->params['tenant'] ) ) {
$loginUrl['action'] = 'tenant_login';
}
$this->loginAction = $loginUrl;
$this->logoutRedirect = $loginUrl;
} | [
"public",
"function",
"initialize",
"(",
"Controller",
"$",
"controller",
")",
"{",
"parent",
"::",
"initialize",
"(",
"$",
"controller",
")",
";",
"$",
"loginUrl",
"=",
"array",
"(",
"'plugin'",
"=>",
"'users'",
",",
"'controller'",
"=>",
"'users'",
",",
"'action'",
"=>",
"'login'",
",",
"'admin'",
"=>",
"false",
",",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"controller",
"->",
"request",
"->",
"params",
"[",
"'tenant'",
"]",
")",
")",
"{",
"$",
"loginUrl",
"[",
"'action'",
"]",
"=",
"'tenant_login'",
";",
"}",
"$",
"this",
"->",
"loginAction",
"=",
"$",
"loginUrl",
";",
"$",
"this",
"->",
"logoutRedirect",
"=",
"$",
"loginUrl",
";",
"}"
] | Initializes AuthComponent for use in the controller.
@param Controller $controller A reference to the instantiating controller object
@return void | [
"Initializes",
"AuthComponent",
"for",
"use",
"in",
"the",
"controller",
"."
] | train | https://github.com/alevilar/ristorantino-vendor/blob/6b91a1e20cc0ba09a1968d77e3de6512cfa2d966/Risto/Controller/Component/RistoAuthComponent.php#L57-L72 |
alevilar/ristorantino-vendor | Risto/Controller/Component/RistoAuthComponent.php | RistoAuthComponent.isAuthorized | public function isAuthorized($user = null, CakeRequest $request = null) {
if (empty($user) && !$this->user()) {
return false;
}
if (empty($user)) {
$user = $this->user();
}
if (empty($request)) {
$request = $this->request;
}
if (empty($this->_authorizeObjects)) {
$this->constructAuthorize();
}
foreach ($this->_authorizeObjects as $authorizer) {
if ($authorizer->authorize($user, $request) === false) {
return false;
}
}
return true;
} | php | public function isAuthorized($user = null, CakeRequest $request = null) {
if (empty($user) && !$this->user()) {
return false;
}
if (empty($user)) {
$user = $this->user();
}
if (empty($request)) {
$request = $this->request;
}
if (empty($this->_authorizeObjects)) {
$this->constructAuthorize();
}
foreach ($this->_authorizeObjects as $authorizer) {
if ($authorizer->authorize($user, $request) === false) {
return false;
}
}
return true;
} | [
"public",
"function",
"isAuthorized",
"(",
"$",
"user",
"=",
"null",
",",
"CakeRequest",
"$",
"request",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"user",
")",
"&&",
"!",
"$",
"this",
"->",
"user",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"user",
")",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"user",
"(",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"request",
")",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"request",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_authorizeObjects",
")",
")",
"{",
"$",
"this",
"->",
"constructAuthorize",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"_authorizeObjects",
"as",
"$",
"authorizer",
")",
"{",
"if",
"(",
"$",
"authorizer",
"->",
"authorize",
"(",
"$",
"user",
",",
"$",
"request",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Al contrario que el isAuthorized que viene en CakePhp
este se fija si algun Adapter retorna false, y entonces retorna false.
el orioginal de Cake hace al reves: con que venga un true. ya le da acceso
a todos
@param array|null $user The user to check the authorization of. If empty the user in the session will be used.
@param CakeRequest|null $request The request to authenticate for. If empty, the current request will be used.
@return bool True if $user is authorized, otherwise false | [
"Al",
"contrario",
"que",
"el",
"isAuthorized",
"que",
"viene",
"en",
"CakePhp",
"este",
"se",
"fija",
"si",
"algun",
"Adapter",
"retorna",
"false",
"y",
"entonces",
"retorna",
"false",
"."
] | train | https://github.com/alevilar/ristorantino-vendor/blob/6b91a1e20cc0ba09a1968d77e3de6512cfa2d966/Risto/Controller/Component/RistoAuthComponent.php#L86-L105 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.register_post_type | private function register_post_type() {
$post_type = $this->get_post_type();
$this->_post_type_obj = register_post_type( $post_type, $this->get_post_type_args() );
if ( is_wp_error( $this->_post_type_obj ) ) {
$this->app->log( $this->_post_type_obj );
return;
}
add_filter( "views_edit-{$post_type}", function ( $views ) {
unset( $views['mine'] );
unset( $views['publish'] );
return $views;
} );
add_filter( "bulk_actions-edit-{$post_type}", function ( $actions ) {
unset( $actions['edit'] );
return $actions;
} );
add_filter( "manage_edit-{$post_type}_sortable_columns", function ( $sortable_columns ) {
return $this->manage_posts_columns( $sortable_columns, true );
} );
} | php | private function register_post_type() {
$post_type = $this->get_post_type();
$this->_post_type_obj = register_post_type( $post_type, $this->get_post_type_args() );
if ( is_wp_error( $this->_post_type_obj ) ) {
$this->app->log( $this->_post_type_obj );
return;
}
add_filter( "views_edit-{$post_type}", function ( $views ) {
unset( $views['mine'] );
unset( $views['publish'] );
return $views;
} );
add_filter( "bulk_actions-edit-{$post_type}", function ( $actions ) {
unset( $actions['edit'] );
return $actions;
} );
add_filter( "manage_edit-{$post_type}_sortable_columns", function ( $sortable_columns ) {
return $this->manage_posts_columns( $sortable_columns, true );
} );
} | [
"private",
"function",
"register_post_type",
"(",
")",
"{",
"$",
"post_type",
"=",
"$",
"this",
"->",
"get_post_type",
"(",
")",
";",
"$",
"this",
"->",
"_post_type_obj",
"=",
"register_post_type",
"(",
"$",
"post_type",
",",
"$",
"this",
"->",
"get_post_type_args",
"(",
")",
")",
";",
"if",
"(",
"is_wp_error",
"(",
"$",
"this",
"->",
"_post_type_obj",
")",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"log",
"(",
"$",
"this",
"->",
"_post_type_obj",
")",
";",
"return",
";",
"}",
"add_filter",
"(",
"\"views_edit-{$post_type}\"",
",",
"function",
"(",
"$",
"views",
")",
"{",
"unset",
"(",
"$",
"views",
"[",
"'mine'",
"]",
")",
";",
"unset",
"(",
"$",
"views",
"[",
"'publish'",
"]",
")",
";",
"return",
"$",
"views",
";",
"}",
")",
";",
"add_filter",
"(",
"\"bulk_actions-edit-{$post_type}\"",
",",
"function",
"(",
"$",
"actions",
")",
"{",
"unset",
"(",
"$",
"actions",
"[",
"'edit'",
"]",
")",
";",
"return",
"$",
"actions",
";",
"}",
")",
";",
"add_filter",
"(",
"\"manage_edit-{$post_type}_sortable_columns\"",
",",
"function",
"(",
"$",
"sortable_columns",
")",
"{",
"return",
"$",
"this",
"->",
"manage_posts_columns",
"(",
"$",
"sortable_columns",
",",
"true",
")",
";",
"}",
")",
";",
"}"
] | register post type
@since 2.9.7 Changed: move register post type from model
@since 2.9.10 Changed: visibility (public to private) | [
"register",
"post",
"type"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L77-L99 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.insert | public function insert( $data, $convert_name = true ) {
$_data = [];
$_data['post_type'] = $this->get_post_type();
$_data['post_title'] = $this->app->utility->array_get( $data, 'post_title', '' );
$_data['post_content'] = $this->app->utility->array_get( $data, 'post_content', '' );
$_data['post_status'] = $this->app->utility->array_get( $data, 'post_status', 'publish' );
unset( $data['post_type'] );
unset( $data['post_title'] );
unset( $data['post_content'] );
unset( $data['post_status'] );
foreach ( $this->get_data_field_settings() as $k => $v ) {
$name = $convert_name ? $this->get_post_field_name( $k ) : $k;
unset( $_POST[ $name ] );
}
foreach ( $data as $k => $v ) {
$name = $convert_name ? $this->get_post_field_name( $k ) : $k;
$_data[ $name ] = $v;
$_POST[ $name ] = $v;
}
return wp_insert_post( $_data );
} | php | public function insert( $data, $convert_name = true ) {
$_data = [];
$_data['post_type'] = $this->get_post_type();
$_data['post_title'] = $this->app->utility->array_get( $data, 'post_title', '' );
$_data['post_content'] = $this->app->utility->array_get( $data, 'post_content', '' );
$_data['post_status'] = $this->app->utility->array_get( $data, 'post_status', 'publish' );
unset( $data['post_type'] );
unset( $data['post_title'] );
unset( $data['post_content'] );
unset( $data['post_status'] );
foreach ( $this->get_data_field_settings() as $k => $v ) {
$name = $convert_name ? $this->get_post_field_name( $k ) : $k;
unset( $_POST[ $name ] );
}
foreach ( $data as $k => $v ) {
$name = $convert_name ? $this->get_post_field_name( $k ) : $k;
$_data[ $name ] = $v;
$_POST[ $name ] = $v;
}
return wp_insert_post( $_data );
} | [
"public",
"function",
"insert",
"(",
"$",
"data",
",",
"$",
"convert_name",
"=",
"true",
")",
"{",
"$",
"_data",
"=",
"[",
"]",
";",
"$",
"_data",
"[",
"'post_type'",
"]",
"=",
"$",
"this",
"->",
"get_post_type",
"(",
")",
";",
"$",
"_data",
"[",
"'post_title'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_get",
"(",
"$",
"data",
",",
"'post_title'",
",",
"''",
")",
";",
"$",
"_data",
"[",
"'post_content'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_get",
"(",
"$",
"data",
",",
"'post_content'",
",",
"''",
")",
";",
"$",
"_data",
"[",
"'post_status'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_get",
"(",
"$",
"data",
",",
"'post_status'",
",",
"'publish'",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"'post_type'",
"]",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"'post_title'",
"]",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"'post_content'",
"]",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"'post_status'",
"]",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_data_field_settings",
"(",
")",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"name",
"=",
"$",
"convert_name",
"?",
"$",
"this",
"->",
"get_post_field_name",
"(",
"$",
"k",
")",
":",
"$",
"k",
";",
"unset",
"(",
"$",
"_POST",
"[",
"$",
"name",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"data",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"name",
"=",
"$",
"convert_name",
"?",
"$",
"this",
"->",
"get_post_field_name",
"(",
"$",
"k",
")",
":",
"$",
"k",
";",
"$",
"_data",
"[",
"$",
"name",
"]",
"=",
"$",
"v",
";",
"$",
"_POST",
"[",
"$",
"name",
"]",
"=",
"$",
"v",
";",
"}",
"return",
"wp_insert_post",
"(",
"$",
"_data",
")",
";",
"}"
] | @since 2.9.3
@param array $data
@param bool $convert_name
@return array|bool|int | [
"@since",
"2",
".",
"9",
".",
"3"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L109-L131 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.update | public function update( $data, $where, $convert_name = true ) {
if ( empty( $where['id'] ) && empty( $where['post_id'] ) ) {
return false;
}
if ( ! empty( $where['id'] ) ) {
$d = $this->get_data( $where['id'] );
} else {
$d = $this->get_related_data( $where['post_id'] );
}
if ( empty( $d ) ) {
return false;
}
$_data = [];
$_data['ID'] = $d['post_id'];
$_data['post_type'] = $this->get_post_type();
! empty( $data['post_title'] ) and $_data['post_title'] = $data['post_title'];
! empty( $data['post_content'] ) and $_data['post_content'] = $data['post_content'];
! empty( $data['post_status'] ) and $_data['post_status'] = $data['post_status'];
unset( $data['post_type'] );
unset( $data['post_title'] );
unset( $data['post_content'] );
unset( $data['post_status'] );
foreach ( $this->get_data_field_settings() as $k => $v ) {
$name = $convert_name ? $this->get_post_field_name( $k ) : $k;
unset( $_POST[ $name ] );
}
foreach ( $data as $k => $v ) {
$name = $convert_name ? $this->get_post_field_name( $k ) : $k;
$_data[ $name ] = $v;
$_POST[ $name ] = $v;
}
return wp_update_post( $_data );
} | php | public function update( $data, $where, $convert_name = true ) {
if ( empty( $where['id'] ) && empty( $where['post_id'] ) ) {
return false;
}
if ( ! empty( $where['id'] ) ) {
$d = $this->get_data( $where['id'] );
} else {
$d = $this->get_related_data( $where['post_id'] );
}
if ( empty( $d ) ) {
return false;
}
$_data = [];
$_data['ID'] = $d['post_id'];
$_data['post_type'] = $this->get_post_type();
! empty( $data['post_title'] ) and $_data['post_title'] = $data['post_title'];
! empty( $data['post_content'] ) and $_data['post_content'] = $data['post_content'];
! empty( $data['post_status'] ) and $_data['post_status'] = $data['post_status'];
unset( $data['post_type'] );
unset( $data['post_title'] );
unset( $data['post_content'] );
unset( $data['post_status'] );
foreach ( $this->get_data_field_settings() as $k => $v ) {
$name = $convert_name ? $this->get_post_field_name( $k ) : $k;
unset( $_POST[ $name ] );
}
foreach ( $data as $k => $v ) {
$name = $convert_name ? $this->get_post_field_name( $k ) : $k;
$_data[ $name ] = $v;
$_POST[ $name ] = $v;
}
return wp_update_post( $_data );
} | [
"public",
"function",
"update",
"(",
"$",
"data",
",",
"$",
"where",
",",
"$",
"convert_name",
"=",
"true",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"where",
"[",
"'id'",
"]",
")",
"&&",
"empty",
"(",
"$",
"where",
"[",
"'post_id'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"where",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"d",
"=",
"$",
"this",
"->",
"get_data",
"(",
"$",
"where",
"[",
"'id'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"d",
"=",
"$",
"this",
"->",
"get_related_data",
"(",
"$",
"where",
"[",
"'post_id'",
"]",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"d",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"_data",
"=",
"[",
"]",
";",
"$",
"_data",
"[",
"'ID'",
"]",
"=",
"$",
"d",
"[",
"'post_id'",
"]",
";",
"$",
"_data",
"[",
"'post_type'",
"]",
"=",
"$",
"this",
"->",
"get_post_type",
"(",
")",
";",
"!",
"empty",
"(",
"$",
"data",
"[",
"'post_title'",
"]",
")",
"and",
"$",
"_data",
"[",
"'post_title'",
"]",
"=",
"$",
"data",
"[",
"'post_title'",
"]",
";",
"!",
"empty",
"(",
"$",
"data",
"[",
"'post_content'",
"]",
")",
"and",
"$",
"_data",
"[",
"'post_content'",
"]",
"=",
"$",
"data",
"[",
"'post_content'",
"]",
";",
"!",
"empty",
"(",
"$",
"data",
"[",
"'post_status'",
"]",
")",
"and",
"$",
"_data",
"[",
"'post_status'",
"]",
"=",
"$",
"data",
"[",
"'post_status'",
"]",
";",
"unset",
"(",
"$",
"data",
"[",
"'post_type'",
"]",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"'post_title'",
"]",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"'post_content'",
"]",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"'post_status'",
"]",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_data_field_settings",
"(",
")",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"name",
"=",
"$",
"convert_name",
"?",
"$",
"this",
"->",
"get_post_field_name",
"(",
"$",
"k",
")",
":",
"$",
"k",
";",
"unset",
"(",
"$",
"_POST",
"[",
"$",
"name",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"data",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"name",
"=",
"$",
"convert_name",
"?",
"$",
"this",
"->",
"get_post_field_name",
"(",
"$",
"k",
")",
":",
"$",
"k",
";",
"$",
"_data",
"[",
"$",
"name",
"]",
"=",
"$",
"v",
";",
"$",
"_POST",
"[",
"$",
"name",
"]",
"=",
"$",
"v",
";",
"}",
"return",
"wp_update_post",
"(",
"$",
"_data",
")",
";",
"}"
] | @since 2.9.3
@param array $data
@param array $where
@param bool $convert_name
@return array|bool|int | [
"@since",
"2",
".",
"9",
".",
"3"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L142-L177 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.user_can | public function user_can( $capability ) {
if ( ! ( $this->_post_type_obj instanceof \WP_Post_Type ) ) {
return false;
}
return ! empty( $this->_post_type_obj->cap->$capability );
} | php | public function user_can( $capability ) {
if ( ! ( $this->_post_type_obj instanceof \WP_Post_Type ) ) {
return false;
}
return ! empty( $this->_post_type_obj->cap->$capability );
} | [
"public",
"function",
"user_can",
"(",
"$",
"capability",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"_post_type_obj",
"instanceof",
"\\",
"WP_Post_Type",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"!",
"empty",
"(",
"$",
"this",
"->",
"_post_type_obj",
"->",
"cap",
"->",
"$",
"capability",
")",
";",
"}"
] | @since 2.9.10
@param $capability
@return bool | [
"@since",
"2",
".",
"9",
".",
"10"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L218-L224 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.get_post_type_args | public function get_post_type_args( $capabilities = null ) {
if ( ! isset( $capabilities ) ) {
$capabilities = $this->get_capabilities();
}
return $this->apply_custom_post_filters( 'args', [
'labels' => $this->get_post_type_labels(),
'description' => '',
'public' => false,
'show_ui' => true,
'has_archive' => false,
'show_in_menu' => $this->get_post_type_parent(),
'exclude_from_search' => true,
'capability_type' => $this->get_post_type_capability_type(),
'capabilities' => $capabilities,
'map_meta_cap' => true,
'hierarchical' => false,
'rewrite' => [ 'slug' => $this->get_post_type_slug(), 'with_front' => false ],
'query_var' => true,
'menu_icon' => $this->get_post_type_menu_icon(),
'supports' => $this->get_post_type_supports(),
'menu_position' => $this->get_post_type_position(),
] );
} | php | public function get_post_type_args( $capabilities = null ) {
if ( ! isset( $capabilities ) ) {
$capabilities = $this->get_capabilities();
}
return $this->apply_custom_post_filters( 'args', [
'labels' => $this->get_post_type_labels(),
'description' => '',
'public' => false,
'show_ui' => true,
'has_archive' => false,
'show_in_menu' => $this->get_post_type_parent(),
'exclude_from_search' => true,
'capability_type' => $this->get_post_type_capability_type(),
'capabilities' => $capabilities,
'map_meta_cap' => true,
'hierarchical' => false,
'rewrite' => [ 'slug' => $this->get_post_type_slug(), 'with_front' => false ],
'query_var' => true,
'menu_icon' => $this->get_post_type_menu_icon(),
'supports' => $this->get_post_type_supports(),
'menu_position' => $this->get_post_type_position(),
] );
} | [
"public",
"function",
"get_post_type_args",
"(",
"$",
"capabilities",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"capabilities",
")",
")",
"{",
"$",
"capabilities",
"=",
"$",
"this",
"->",
"get_capabilities",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"apply_custom_post_filters",
"(",
"'args'",
",",
"[",
"'labels'",
"=>",
"$",
"this",
"->",
"get_post_type_labels",
"(",
")",
",",
"'description'",
"=>",
"''",
",",
"'public'",
"=>",
"false",
",",
"'show_ui'",
"=>",
"true",
",",
"'has_archive'",
"=>",
"false",
",",
"'show_in_menu'",
"=>",
"$",
"this",
"->",
"get_post_type_parent",
"(",
")",
",",
"'exclude_from_search'",
"=>",
"true",
",",
"'capability_type'",
"=>",
"$",
"this",
"->",
"get_post_type_capability_type",
"(",
")",
",",
"'capabilities'",
"=>",
"$",
"capabilities",
",",
"'map_meta_cap'",
"=>",
"true",
",",
"'hierarchical'",
"=>",
"false",
",",
"'rewrite'",
"=>",
"[",
"'slug'",
"=>",
"$",
"this",
"->",
"get_post_type_slug",
"(",
")",
",",
"'with_front'",
"=>",
"false",
"]",
",",
"'query_var'",
"=>",
"true",
",",
"'menu_icon'",
"=>",
"$",
"this",
"->",
"get_post_type_menu_icon",
"(",
")",
",",
"'supports'",
"=>",
"$",
"this",
"->",
"get_post_type_supports",
"(",
")",
",",
"'menu_position'",
"=>",
"$",
"this",
"->",
"get_post_type_position",
"(",
")",
",",
"]",
")",
";",
"}"
] | @param null|array $capabilities
@return array | [
"@param",
"null|array",
"$capabilities"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L241-L264 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.posts_search | public function posts_search(
/** @noinspection PhpUnusedParameterInspection */
$search, $wp_query
) {
if ( ! $wp_query->is_search() || ! $wp_query->is_main_query() || ! is_admin() || empty( $wp_query->query_vars['search_terms'] ) ) {
return $search;
}
$fields = $this->get_search_fields();
if ( empty( $fields ) ) {
return $search;
}
global $wpdb;
$exclusion_prefix = apply_filters( 'wp_query_search_exclusion_prefix', '-' );
$search = '';
$q = $wp_query->query_vars;
$n = ! empty( $q['exact'] ) ? '' : '%';
$table = $this->app->db->get_table( $this->get_related_table_name() );
foreach ( $q['search_terms'] as $term ) {
$exclude = $exclusion_prefix && ( $exclusion_prefix === substr( $term, 0, 1 ) );
if ( $exclude ) {
$like_op = 'NOT LIKE';
$andor_op = 'AND';
$term = substr( $term, 1 );
} else {
$like_op = 'LIKE';
$andor_op = 'OR';
}
$conditions = [];
$fields = array_map( function ( $field ) use ( $table ) {
return "{$table}.{$field}";
}, $fields );
$fields[] = "{$wpdb->posts}.post_title";
$fields[] = "{$wpdb->posts}.post_excerpt";
$fields[] = "{$wpdb->posts}.post_content";
$like = $n . $wpdb->esc_like( $term ) . $n;
foreach ( $fields as $field ) {
$conditions[] = $wpdb->prepare( "({$field} $like_op %s)", $like );
}
$conditions = implode( " {$andor_op} ", $conditions );
$search .= " AND ({$conditions})";
}
return $search;
} | php | public function posts_search(
/** @noinspection PhpUnusedParameterInspection */
$search, $wp_query
) {
if ( ! $wp_query->is_search() || ! $wp_query->is_main_query() || ! is_admin() || empty( $wp_query->query_vars['search_terms'] ) ) {
return $search;
}
$fields = $this->get_search_fields();
if ( empty( $fields ) ) {
return $search;
}
global $wpdb;
$exclusion_prefix = apply_filters( 'wp_query_search_exclusion_prefix', '-' );
$search = '';
$q = $wp_query->query_vars;
$n = ! empty( $q['exact'] ) ? '' : '%';
$table = $this->app->db->get_table( $this->get_related_table_name() );
foreach ( $q['search_terms'] as $term ) {
$exclude = $exclusion_prefix && ( $exclusion_prefix === substr( $term, 0, 1 ) );
if ( $exclude ) {
$like_op = 'NOT LIKE';
$andor_op = 'AND';
$term = substr( $term, 1 );
} else {
$like_op = 'LIKE';
$andor_op = 'OR';
}
$conditions = [];
$fields = array_map( function ( $field ) use ( $table ) {
return "{$table}.{$field}";
}, $fields );
$fields[] = "{$wpdb->posts}.post_title";
$fields[] = "{$wpdb->posts}.post_excerpt";
$fields[] = "{$wpdb->posts}.post_content";
$like = $n . $wpdb->esc_like( $term ) . $n;
foreach ( $fields as $field ) {
$conditions[] = $wpdb->prepare( "({$field} $like_op %s)", $like );
}
$conditions = implode( " {$andor_op} ", $conditions );
$search .= " AND ({$conditions})";
}
return $search;
} | [
"public",
"function",
"posts_search",
"(",
"/** @noinspection PhpUnusedParameterInspection */",
"$",
"search",
",",
"$",
"wp_query",
")",
"{",
"if",
"(",
"!",
"$",
"wp_query",
"->",
"is_search",
"(",
")",
"||",
"!",
"$",
"wp_query",
"->",
"is_main_query",
"(",
")",
"||",
"!",
"is_admin",
"(",
")",
"||",
"empty",
"(",
"$",
"wp_query",
"->",
"query_vars",
"[",
"'search_terms'",
"]",
")",
")",
"{",
"return",
"$",
"search",
";",
"}",
"$",
"fields",
"=",
"$",
"this",
"->",
"get_search_fields",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"return",
"$",
"search",
";",
"}",
"global",
"$",
"wpdb",
";",
"$",
"exclusion_prefix",
"=",
"apply_filters",
"(",
"'wp_query_search_exclusion_prefix'",
",",
"'-'",
")",
";",
"$",
"search",
"=",
"''",
";",
"$",
"q",
"=",
"$",
"wp_query",
"->",
"query_vars",
";",
"$",
"n",
"=",
"!",
"empty",
"(",
"$",
"q",
"[",
"'exact'",
"]",
")",
"?",
"''",
":",
"'%'",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"app",
"->",
"db",
"->",
"get_table",
"(",
"$",
"this",
"->",
"get_related_table_name",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"q",
"[",
"'search_terms'",
"]",
"as",
"$",
"term",
")",
"{",
"$",
"exclude",
"=",
"$",
"exclusion_prefix",
"&&",
"(",
"$",
"exclusion_prefix",
"===",
"substr",
"(",
"$",
"term",
",",
"0",
",",
"1",
")",
")",
";",
"if",
"(",
"$",
"exclude",
")",
"{",
"$",
"like_op",
"=",
"'NOT LIKE'",
";",
"$",
"andor_op",
"=",
"'AND'",
";",
"$",
"term",
"=",
"substr",
"(",
"$",
"term",
",",
"1",
")",
";",
"}",
"else",
"{",
"$",
"like_op",
"=",
"'LIKE'",
";",
"$",
"andor_op",
"=",
"'OR'",
";",
"}",
"$",
"conditions",
"=",
"[",
"]",
";",
"$",
"fields",
"=",
"array_map",
"(",
"function",
"(",
"$",
"field",
")",
"use",
"(",
"$",
"table",
")",
"{",
"return",
"\"{$table}.{$field}\"",
";",
"}",
",",
"$",
"fields",
")",
";",
"$",
"fields",
"[",
"]",
"=",
"\"{$wpdb->posts}.post_title\"",
";",
"$",
"fields",
"[",
"]",
"=",
"\"{$wpdb->posts}.post_excerpt\"",
";",
"$",
"fields",
"[",
"]",
"=",
"\"{$wpdb->posts}.post_content\"",
";",
"$",
"like",
"=",
"$",
"n",
".",
"$",
"wpdb",
"->",
"esc_like",
"(",
"$",
"term",
")",
".",
"$",
"n",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"conditions",
"[",
"]",
"=",
"$",
"wpdb",
"->",
"prepare",
"(",
"\"({$field} $like_op %s)\"",
",",
"$",
"like",
")",
";",
"}",
"$",
"conditions",
"=",
"implode",
"(",
"\" {$andor_op} \"",
",",
"$",
"conditions",
")",
";",
"$",
"search",
".=",
"\" AND ({$conditions})\"",
";",
"}",
"return",
"$",
"search",
";",
"}"
] | @param string $search
@param \WP_Query $wp_query
@return string | [
"@param",
"string",
"$search",
"@param",
"\\",
"WP_Query",
"$wp_query"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L338-L386 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.posts_join | public function posts_join(
/** @noinspection PhpUnusedParameterInspection */
$join, $wp_query
) {
/** @var \wpdb $wpdb */
global $wpdb;
$table = $this->app->db->get_table( $this->get_related_table_name() );
$join .= " INNER JOIN {$table} ON {$table}.post_id = {$wpdb->posts}.ID ";
return $join;
} | php | public function posts_join(
/** @noinspection PhpUnusedParameterInspection */
$join, $wp_query
) {
/** @var \wpdb $wpdb */
global $wpdb;
$table = $this->app->db->get_table( $this->get_related_table_name() );
$join .= " INNER JOIN {$table} ON {$table}.post_id = {$wpdb->posts}.ID ";
return $join;
} | [
"public",
"function",
"posts_join",
"(",
"/** @noinspection PhpUnusedParameterInspection */",
"$",
"join",
",",
"$",
"wp_query",
")",
"{",
"/** @var \\wpdb $wpdb */",
"global",
"$",
"wpdb",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"app",
"->",
"db",
"->",
"get_table",
"(",
"$",
"this",
"->",
"get_related_table_name",
"(",
")",
")",
";",
"$",
"join",
".=",
"\" INNER JOIN {$table} ON {$table}.post_id = {$wpdb->posts}.ID \"",
";",
"return",
"$",
"join",
";",
"}"
] | @param string $join
@param \WP_Query $wp_query
@return string | [
"@param",
"string",
"$join",
"@param",
"\\",
"WP_Query",
"$wp_query"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L401-L411 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.manage_posts_columns | public function manage_posts_columns( $columns, $sortable = false ) {
if ( ! $sortable ) {
$title = $this->get_post_column_title();
! isset( $title ) and isset( $columns['title'] ) and $title = $columns['title'];
$date = isset( $columns['date'] ) ? $columns['date'] : null;
unset( $columns['date'] );
}
$columns = $this->pre_filter_posts_columns( $columns, $sortable );
$columns = $this->post_filter_posts_columns( $columns, $sortable );
if ( ! $sortable ) {
isset( $title ) and $columns['title'] = $title;
isset( $date ) and $columns['date'] = $date;
}
return $columns;
} | php | public function manage_posts_columns( $columns, $sortable = false ) {
if ( ! $sortable ) {
$title = $this->get_post_column_title();
! isset( $title ) and isset( $columns['title'] ) and $title = $columns['title'];
$date = isset( $columns['date'] ) ? $columns['date'] : null;
unset( $columns['date'] );
}
$columns = $this->pre_filter_posts_columns( $columns, $sortable );
$columns = $this->post_filter_posts_columns( $columns, $sortable );
if ( ! $sortable ) {
isset( $title ) and $columns['title'] = $title;
isset( $date ) and $columns['date'] = $date;
}
return $columns;
} | [
"public",
"function",
"manage_posts_columns",
"(",
"$",
"columns",
",",
"$",
"sortable",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"sortable",
")",
"{",
"$",
"title",
"=",
"$",
"this",
"->",
"get_post_column_title",
"(",
")",
";",
"!",
"isset",
"(",
"$",
"title",
")",
"and",
"isset",
"(",
"$",
"columns",
"[",
"'title'",
"]",
")",
"and",
"$",
"title",
"=",
"$",
"columns",
"[",
"'title'",
"]",
";",
"$",
"date",
"=",
"isset",
"(",
"$",
"columns",
"[",
"'date'",
"]",
")",
"?",
"$",
"columns",
"[",
"'date'",
"]",
":",
"null",
";",
"unset",
"(",
"$",
"columns",
"[",
"'date'",
"]",
")",
";",
"}",
"$",
"columns",
"=",
"$",
"this",
"->",
"pre_filter_posts_columns",
"(",
"$",
"columns",
",",
"$",
"sortable",
")",
";",
"$",
"columns",
"=",
"$",
"this",
"->",
"post_filter_posts_columns",
"(",
"$",
"columns",
",",
"$",
"sortable",
")",
";",
"if",
"(",
"!",
"$",
"sortable",
")",
"{",
"isset",
"(",
"$",
"title",
")",
"and",
"$",
"columns",
"[",
"'title'",
"]",
"=",
"$",
"title",
";",
"isset",
"(",
"$",
"date",
")",
"and",
"$",
"columns",
"[",
"'date'",
"]",
"=",
"$",
"date",
";",
"}",
"return",
"$",
"columns",
";",
"}"
] | @param array $columns
@param bool $sortable
@return array | [
"@param",
"array",
"$columns",
"@param",
"bool",
"$sortable"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L419-L436 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.pre_filter_posts_columns | protected function pre_filter_posts_columns( $columns, $sortable = false ) {
// for cocoon
unset( $columns['thumbnail'] );
unset( $columns['memo'] );
$_columns = $this->app->db->get_columns( $this->get_related_table_name() );
foreach ( $this->get_manage_posts_columns() as $k => $v ) {
if ( $sortable && ( ! is_array( $v ) || empty( $v['sortable'] ) ) ) {
continue;
}
$key = $this->get_post_type() . '-' . $k;
if ( $sortable ) {
$columns[ $key ] = [ $key, ! empty( $v['desc'] ) ];
continue;
}
$name = isset( $_columns[ $k ] ) ? $this->table_column_to_name( $k, $_columns ) : '';
if ( is_array( $v ) ) {
if ( isset( $v['name'] ) ) {
$name = $v['name'];
}
$columns[ $key ] = $name;
} elseif ( ! $sortable ) {
$columns[ $key ] = empty( $name ) ? $k : $name;
}
}
return $columns;
} | php | protected function pre_filter_posts_columns( $columns, $sortable = false ) {
// for cocoon
unset( $columns['thumbnail'] );
unset( $columns['memo'] );
$_columns = $this->app->db->get_columns( $this->get_related_table_name() );
foreach ( $this->get_manage_posts_columns() as $k => $v ) {
if ( $sortable && ( ! is_array( $v ) || empty( $v['sortable'] ) ) ) {
continue;
}
$key = $this->get_post_type() . '-' . $k;
if ( $sortable ) {
$columns[ $key ] = [ $key, ! empty( $v['desc'] ) ];
continue;
}
$name = isset( $_columns[ $k ] ) ? $this->table_column_to_name( $k, $_columns ) : '';
if ( is_array( $v ) ) {
if ( isset( $v['name'] ) ) {
$name = $v['name'];
}
$columns[ $key ] = $name;
} elseif ( ! $sortable ) {
$columns[ $key ] = empty( $name ) ? $k : $name;
}
}
return $columns;
} | [
"protected",
"function",
"pre_filter_posts_columns",
"(",
"$",
"columns",
",",
"$",
"sortable",
"=",
"false",
")",
"{",
"// for cocoon",
"unset",
"(",
"$",
"columns",
"[",
"'thumbnail'",
"]",
")",
";",
"unset",
"(",
"$",
"columns",
"[",
"'memo'",
"]",
")",
";",
"$",
"_columns",
"=",
"$",
"this",
"->",
"app",
"->",
"db",
"->",
"get_columns",
"(",
"$",
"this",
"->",
"get_related_table_name",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_manage_posts_columns",
"(",
")",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"$",
"sortable",
"&&",
"(",
"!",
"is_array",
"(",
"$",
"v",
")",
"||",
"empty",
"(",
"$",
"v",
"[",
"'sortable'",
"]",
")",
")",
")",
"{",
"continue",
";",
"}",
"$",
"key",
"=",
"$",
"this",
"->",
"get_post_type",
"(",
")",
".",
"'-'",
".",
"$",
"k",
";",
"if",
"(",
"$",
"sortable",
")",
"{",
"$",
"columns",
"[",
"$",
"key",
"]",
"=",
"[",
"$",
"key",
",",
"!",
"empty",
"(",
"$",
"v",
"[",
"'desc'",
"]",
")",
"]",
";",
"continue",
";",
"}",
"$",
"name",
"=",
"isset",
"(",
"$",
"_columns",
"[",
"$",
"k",
"]",
")",
"?",
"$",
"this",
"->",
"table_column_to_name",
"(",
"$",
"k",
",",
"$",
"_columns",
")",
":",
"''",
";",
"if",
"(",
"is_array",
"(",
"$",
"v",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"v",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"name",
"=",
"$",
"v",
"[",
"'name'",
"]",
";",
"}",
"$",
"columns",
"[",
"$",
"key",
"]",
"=",
"$",
"name",
";",
"}",
"elseif",
"(",
"!",
"$",
"sortable",
")",
"{",
"$",
"columns",
"[",
"$",
"key",
"]",
"=",
"empty",
"(",
"$",
"name",
")",
"?",
"$",
"k",
":",
"$",
"name",
";",
"}",
"}",
"return",
"$",
"columns",
";",
"}"
] | @since 2.8.5 Fixed: hide unnecessary columns
@param array $columns
@param bool $sortable
@return array | [
"@since",
"2",
".",
"8",
".",
"5",
"Fixed",
":",
"hide",
"unnecessary",
"columns"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L453-L481 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.set_post_data | protected function set_post_data( $data, $post ) {
$data['post_title'] = $post->post_title;
$data['post'] = $post;
if ( $this->user_can( 'read_post' ) ) {
$data['edit_link'] = get_edit_post_link( $post->ID );
}
foreach ( $this->get_data_field_settings() as $k => $v ) {
$data[ $k ] = $this->sanitize_input( $this->app->utility->array_get( $data, $k ), $v['type'] );
}
return $data;
} | php | protected function set_post_data( $data, $post ) {
$data['post_title'] = $post->post_title;
$data['post'] = $post;
if ( $this->user_can( 'read_post' ) ) {
$data['edit_link'] = get_edit_post_link( $post->ID );
}
foreach ( $this->get_data_field_settings() as $k => $v ) {
$data[ $k ] = $this->sanitize_input( $this->app->utility->array_get( $data, $k ), $v['type'] );
}
return $data;
} | [
"protected",
"function",
"set_post_data",
"(",
"$",
"data",
",",
"$",
"post",
")",
"{",
"$",
"data",
"[",
"'post_title'",
"]",
"=",
"$",
"post",
"->",
"post_title",
";",
"$",
"data",
"[",
"'post'",
"]",
"=",
"$",
"post",
";",
"if",
"(",
"$",
"this",
"->",
"user_can",
"(",
"'read_post'",
")",
")",
"{",
"$",
"data",
"[",
"'edit_link'",
"]",
"=",
"get_edit_post_link",
"(",
"$",
"post",
"->",
"ID",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"get_data_field_settings",
"(",
")",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"data",
"[",
"$",
"k",
"]",
"=",
"$",
"this",
"->",
"sanitize_input",
"(",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_get",
"(",
"$",
"data",
",",
"$",
"k",
")",
",",
"$",
"v",
"[",
"'type'",
"]",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | @param array $data
@param \WP_Post $post
@return array | [
"@param",
"array",
"$data",
"@param",
"\\",
"WP_Post",
"$post"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L560-L572 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.get_related_data | public function get_related_data( $post_id ) {
if ( ! isset( $this->_related_data[ $post_id ] ) ) {
$table = $this->get_related_table_name();
$data = $this->app->db->select_row( $table, [
'post_id' => $post_id,
] );
if ( empty( $data ) ) {
$data = false;
} else {
$post = get_post( $post_id );
if ( empty( $post ) || $post->post_type != $this->get_post_type() ) {
$data = false;
} else {
$data = $this->filter_item( $this->set_post_data( $data, $post ) );
}
}
$this->_related_data[ $post_id ] = $data;
}
return $this->_related_data[ $post_id ];
} | php | public function get_related_data( $post_id ) {
if ( ! isset( $this->_related_data[ $post_id ] ) ) {
$table = $this->get_related_table_name();
$data = $this->app->db->select_row( $table, [
'post_id' => $post_id,
] );
if ( empty( $data ) ) {
$data = false;
} else {
$post = get_post( $post_id );
if ( empty( $post ) || $post->post_type != $this->get_post_type() ) {
$data = false;
} else {
$data = $this->filter_item( $this->set_post_data( $data, $post ) );
}
}
$this->_related_data[ $post_id ] = $data;
}
return $this->_related_data[ $post_id ];
} | [
"public",
"function",
"get_related_data",
"(",
"$",
"post_id",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_related_data",
"[",
"$",
"post_id",
"]",
")",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"get_related_table_name",
"(",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"app",
"->",
"db",
"->",
"select_row",
"(",
"$",
"table",
",",
"[",
"'post_id'",
"=>",
"$",
"post_id",
",",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"post",
"=",
"get_post",
"(",
"$",
"post_id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"post",
")",
"||",
"$",
"post",
"->",
"post_type",
"!=",
"$",
"this",
"->",
"get_post_type",
"(",
")",
")",
"{",
"$",
"data",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"filter_item",
"(",
"$",
"this",
"->",
"set_post_data",
"(",
"$",
"data",
",",
"$",
"post",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_related_data",
"[",
"$",
"post_id",
"]",
"=",
"$",
"data",
";",
"}",
"return",
"$",
"this",
"->",
"_related_data",
"[",
"$",
"post_id",
"]",
";",
"}"
] | @param int $post_id
@return array|false | [
"@param",
"int",
"$post_id"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L579-L600 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.get_data | public function get_data( $id, $is_valid = true ) {
$table = $this->get_related_table_name();
$data = $this->app->db->select_row( $table, [
'id' => $id,
] );
if ( empty( $data ) ) {
return false;
}
$post_id = $data['post_id'];
$post = get_post( $post_id );
if ( empty( $post ) || $post->post_type != $this->get_post_type() || ( $is_valid && $post->post_status !== 'publish' ) ) {
return false;
}
return $this->filter_item( $this->set_post_data( $data, $post ) );
} | php | public function get_data( $id, $is_valid = true ) {
$table = $this->get_related_table_name();
$data = $this->app->db->select_row( $table, [
'id' => $id,
] );
if ( empty( $data ) ) {
return false;
}
$post_id = $data['post_id'];
$post = get_post( $post_id );
if ( empty( $post ) || $post->post_type != $this->get_post_type() || ( $is_valid && $post->post_status !== 'publish' ) ) {
return false;
}
return $this->filter_item( $this->set_post_data( $data, $post ) );
} | [
"public",
"function",
"get_data",
"(",
"$",
"id",
",",
"$",
"is_valid",
"=",
"true",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"get_related_table_name",
"(",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"app",
"->",
"db",
"->",
"select_row",
"(",
"$",
"table",
",",
"[",
"'id'",
"=>",
"$",
"id",
",",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"post_id",
"=",
"$",
"data",
"[",
"'post_id'",
"]",
";",
"$",
"post",
"=",
"get_post",
"(",
"$",
"post_id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"post",
")",
"||",
"$",
"post",
"->",
"post_type",
"!=",
"$",
"this",
"->",
"get_post_type",
"(",
")",
"||",
"(",
"$",
"is_valid",
"&&",
"$",
"post",
"->",
"post_status",
"!==",
"'publish'",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"filter_item",
"(",
"$",
"this",
"->",
"set_post_data",
"(",
"$",
"data",
",",
"$",
"post",
")",
")",
";",
"}"
] | @param int $id
@param bool $is_valid
@return array|false | [
"@param",
"int",
"$id",
"@param",
"bool",
"$is_valid"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L608-L623 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.list_data | public function list_data( $is_valid = true, $per_page = null, $page = 1, $where = [], $orderby = null ) {
/** @var \wpdb $wpdb */
global $wpdb;
$table = $this->get_related_table_name();
$limit = $per_page;
$page = max( 1, $page );
$table = [
[ $table, 't' ],
[
[ $wpdb->posts, 'p' ],
'INNER JOIN',
[
't.post_id',
'=',
'p.ID',
],
],
];
$total = $this->app->db->select_count( $table, null, $where );
$total_page = isset( $per_page ) ? ceil( $total / $per_page ) : 1;
$page = min( $total_page, $page );
$offset = isset( $per_page ) && isset( $page ) ? $per_page * ( $page - 1 ) : null;
if ( $is_valid ) {
$where['p.post_status'] = 'publish';
}
$list = $this->app->db->select( $table, $where, null, $limit, $offset, $orderby );
if ( empty( $list ) ) {
return [
'total' => 0,
'total_page' => 0,
'page' => $page,
'data' => [],
];
}
$post_ids = $this->app->utility->array_pluck( $list, 'post_id' );
$posts = get_posts( [
'include' => $post_ids,
'post_type' => $this->get_post_type(),
] );
$posts = $this->app->utility->array_combine( $posts, 'ID' );
return [
'total' => $total,
'total_page' => $total_page,
'page' => $page,
'data' => array_map( function ( $d ) use ( $posts ) {
return $this->filter_item( $this->set_post_data( $d, $posts[ $d['post_id'] ] ) );
}, $list ),
];
} | php | public function list_data( $is_valid = true, $per_page = null, $page = 1, $where = [], $orderby = null ) {
/** @var \wpdb $wpdb */
global $wpdb;
$table = $this->get_related_table_name();
$limit = $per_page;
$page = max( 1, $page );
$table = [
[ $table, 't' ],
[
[ $wpdb->posts, 'p' ],
'INNER JOIN',
[
't.post_id',
'=',
'p.ID',
],
],
];
$total = $this->app->db->select_count( $table, null, $where );
$total_page = isset( $per_page ) ? ceil( $total / $per_page ) : 1;
$page = min( $total_page, $page );
$offset = isset( $per_page ) && isset( $page ) ? $per_page * ( $page - 1 ) : null;
if ( $is_valid ) {
$where['p.post_status'] = 'publish';
}
$list = $this->app->db->select( $table, $where, null, $limit, $offset, $orderby );
if ( empty( $list ) ) {
return [
'total' => 0,
'total_page' => 0,
'page' => $page,
'data' => [],
];
}
$post_ids = $this->app->utility->array_pluck( $list, 'post_id' );
$posts = get_posts( [
'include' => $post_ids,
'post_type' => $this->get_post_type(),
] );
$posts = $this->app->utility->array_combine( $posts, 'ID' );
return [
'total' => $total,
'total_page' => $total_page,
'page' => $page,
'data' => array_map( function ( $d ) use ( $posts ) {
return $this->filter_item( $this->set_post_data( $d, $posts[ $d['post_id'] ] ) );
}, $list ),
];
} | [
"public",
"function",
"list_data",
"(",
"$",
"is_valid",
"=",
"true",
",",
"$",
"per_page",
"=",
"null",
",",
"$",
"page",
"=",
"1",
",",
"$",
"where",
"=",
"[",
"]",
",",
"$",
"orderby",
"=",
"null",
")",
"{",
"/** @var \\wpdb $wpdb */",
"global",
"$",
"wpdb",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"get_related_table_name",
"(",
")",
";",
"$",
"limit",
"=",
"$",
"per_page",
";",
"$",
"page",
"=",
"max",
"(",
"1",
",",
"$",
"page",
")",
";",
"$",
"table",
"=",
"[",
"[",
"$",
"table",
",",
"'t'",
"]",
",",
"[",
"[",
"$",
"wpdb",
"->",
"posts",
",",
"'p'",
"]",
",",
"'INNER JOIN'",
",",
"[",
"'t.post_id'",
",",
"'='",
",",
"'p.ID'",
",",
"]",
",",
"]",
",",
"]",
";",
"$",
"total",
"=",
"$",
"this",
"->",
"app",
"->",
"db",
"->",
"select_count",
"(",
"$",
"table",
",",
"null",
",",
"$",
"where",
")",
";",
"$",
"total_page",
"=",
"isset",
"(",
"$",
"per_page",
")",
"?",
"ceil",
"(",
"$",
"total",
"/",
"$",
"per_page",
")",
":",
"1",
";",
"$",
"page",
"=",
"min",
"(",
"$",
"total_page",
",",
"$",
"page",
")",
";",
"$",
"offset",
"=",
"isset",
"(",
"$",
"per_page",
")",
"&&",
"isset",
"(",
"$",
"page",
")",
"?",
"$",
"per_page",
"*",
"(",
"$",
"page",
"-",
"1",
")",
":",
"null",
";",
"if",
"(",
"$",
"is_valid",
")",
"{",
"$",
"where",
"[",
"'p.post_status'",
"]",
"=",
"'publish'",
";",
"}",
"$",
"list",
"=",
"$",
"this",
"->",
"app",
"->",
"db",
"->",
"select",
"(",
"$",
"table",
",",
"$",
"where",
",",
"null",
",",
"$",
"limit",
",",
"$",
"offset",
",",
"$",
"orderby",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"list",
")",
")",
"{",
"return",
"[",
"'total'",
"=>",
"0",
",",
"'total_page'",
"=>",
"0",
",",
"'page'",
"=>",
"$",
"page",
",",
"'data'",
"=>",
"[",
"]",
",",
"]",
";",
"}",
"$",
"post_ids",
"=",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_pluck",
"(",
"$",
"list",
",",
"'post_id'",
")",
";",
"$",
"posts",
"=",
"get_posts",
"(",
"[",
"'include'",
"=>",
"$",
"post_ids",
",",
"'post_type'",
"=>",
"$",
"this",
"->",
"get_post_type",
"(",
")",
",",
"]",
")",
";",
"$",
"posts",
"=",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_combine",
"(",
"$",
"posts",
",",
"'ID'",
")",
";",
"return",
"[",
"'total'",
"=>",
"$",
"total",
",",
"'total_page'",
"=>",
"$",
"total_page",
",",
"'page'",
"=>",
"$",
"page",
",",
"'data'",
"=>",
"array_map",
"(",
"function",
"(",
"$",
"d",
")",
"use",
"(",
"$",
"posts",
")",
"{",
"return",
"$",
"this",
"->",
"filter_item",
"(",
"$",
"this",
"->",
"set_post_data",
"(",
"$",
"d",
",",
"$",
"posts",
"[",
"$",
"d",
"[",
"'post_id'",
"]",
"]",
")",
")",
";",
"}",
",",
"$",
"list",
")",
",",
"]",
";",
"}"
] | @param bool $is_valid
@param int|null $per_page
@param int $page
@param array $where
@param null|array $orderby
@return array | [
"@param",
"bool",
"$is_valid",
"@param",
"int|null",
"$per_page",
"@param",
"int",
"$page",
"@param",
"array",
"$where",
"@param",
"null|array",
"$orderby"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L634-L685 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.update_data | public function update_data( $params, $where, $post, $update ) {
$table = $this->get_related_table_name();
$params = array_merge( $params, $this->get_update_data_params( $post, $update ) );
list( $params, $where ) = $this->update_misc( $params, $where, $post, $update );
return $this->app->db->insert_or_update( $table, $params, $where );
} | php | public function update_data( $params, $where, $post, $update ) {
$table = $this->get_related_table_name();
$params = array_merge( $params, $this->get_update_data_params( $post, $update ) );
list( $params, $where ) = $this->update_misc( $params, $where, $post, $update );
return $this->app->db->insert_or_update( $table, $params, $where );
} | [
"public",
"function",
"update_data",
"(",
"$",
"params",
",",
"$",
"where",
",",
"$",
"post",
",",
"$",
"update",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"get_related_table_name",
"(",
")",
";",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"params",
",",
"$",
"this",
"->",
"get_update_data_params",
"(",
"$",
"post",
",",
"$",
"update",
")",
")",
";",
"list",
"(",
"$",
"params",
",",
"$",
"where",
")",
"=",
"$",
"this",
"->",
"update_misc",
"(",
"$",
"params",
",",
"$",
"where",
",",
"$",
"post",
",",
"$",
"update",
")",
";",
"return",
"$",
"this",
"->",
"app",
"->",
"db",
"->",
"insert_or_update",
"(",
"$",
"table",
",",
"$",
"params",
",",
"$",
"where",
")",
";",
"}"
] | @param array $params
@param array $where
@param \WP_Post $post
@param bool $update
@return int|false | [
"@param",
"array",
"$params",
"@param",
"array",
"$where",
"@param",
"\\",
"WP_Post",
"$post",
"@param",
"bool",
"$update"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L704-L710 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.get_update_data_params | public function get_update_data_params(
/** @noinspection PhpUnusedParameterInspection */
$post, $update
) {
$params = [];
foreach ( $this->get_data_field_settings() as $k => $v ) {
$params[ $k ] = $this->get_post_field( $k, $update || ! $v['required'] ? null : $v['default'], null, $v );
$params[ $k ] = $this->sanitize_input( $params[ $k ], $v['type'] );
if ( ! isset( $params[ $k ] ) && ! $update && $v['unset_if_null'] ) {
unset( $params[ $k ] );
continue;
}
}
return $params;
} | php | public function get_update_data_params(
/** @noinspection PhpUnusedParameterInspection */
$post, $update
) {
$params = [];
foreach ( $this->get_data_field_settings() as $k => $v ) {
$params[ $k ] = $this->get_post_field( $k, $update || ! $v['required'] ? null : $v['default'], null, $v );
$params[ $k ] = $this->sanitize_input( $params[ $k ], $v['type'] );
if ( ! isset( $params[ $k ] ) && ! $update && $v['unset_if_null'] ) {
unset( $params[ $k ] );
continue;
}
}
return $params;
} | [
"public",
"function",
"get_update_data_params",
"(",
"/** @noinspection PhpUnusedParameterInspection */",
"$",
"post",
",",
"$",
"update",
")",
"{",
"$",
"params",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_data_field_settings",
"(",
")",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"params",
"[",
"$",
"k",
"]",
"=",
"$",
"this",
"->",
"get_post_field",
"(",
"$",
"k",
",",
"$",
"update",
"||",
"!",
"$",
"v",
"[",
"'required'",
"]",
"?",
"null",
":",
"$",
"v",
"[",
"'default'",
"]",
",",
"null",
",",
"$",
"v",
")",
";",
"$",
"params",
"[",
"$",
"k",
"]",
"=",
"$",
"this",
"->",
"sanitize_input",
"(",
"$",
"params",
"[",
"$",
"k",
"]",
",",
"$",
"v",
"[",
"'type'",
"]",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"$",
"k",
"]",
")",
"&&",
"!",
"$",
"update",
"&&",
"$",
"v",
"[",
"'unset_if_null'",
"]",
")",
"{",
"unset",
"(",
"$",
"params",
"[",
"$",
"k",
"]",
")",
";",
"continue",
";",
"}",
"}",
"return",
"$",
"params",
";",
"}"
] | @since 2.9.6 Improved: behavior of column which has default and nullable
@param \WP_Post $post
@param bool $update
@return array | [
"@since",
"2",
".",
"9",
".",
"6",
"Improved",
":",
"behavior",
"of",
"column",
"which",
"has",
"default",
"and",
"nullable"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L754-L769 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.delete_data | public function delete_data( $post_id ) {
$table = $this->get_related_table_name();
$this->delete_misc( $post_id );
return $this->app->db->delete( $table, [
'post_id' => $post_id,
] );
} | php | public function delete_data( $post_id ) {
$table = $this->get_related_table_name();
$this->delete_misc( $post_id );
return $this->app->db->delete( $table, [
'post_id' => $post_id,
] );
} | [
"public",
"function",
"delete_data",
"(",
"$",
"post_id",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"get_related_table_name",
"(",
")",
";",
"$",
"this",
"->",
"delete_misc",
"(",
"$",
"post_id",
")",
";",
"return",
"$",
"this",
"->",
"app",
"->",
"db",
"->",
"delete",
"(",
"$",
"table",
",",
"[",
"'post_id'",
"=>",
"$",
"post_id",
",",
"]",
")",
";",
"}"
] | @param int $post_id
@return bool|false|int | [
"@param",
"int",
"$post_id"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L785-L792 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.get_validation_var | protected function get_validation_var( $key, $post_array ) {
return $this->app->utility->array_get( $post_array, $this->get_post_field_name( $key ) );
} | php | protected function get_validation_var( $key, $post_array ) {
return $this->app->utility->array_get( $post_array, $this->get_post_field_name( $key ) );
} | [
"protected",
"function",
"get_validation_var",
"(",
"$",
"key",
",",
"$",
"post_array",
")",
"{",
"return",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_get",
"(",
"$",
"post_array",
",",
"$",
"this",
"->",
"get_post_field_name",
"(",
"$",
"key",
")",
")",
";",
"}"
] | @since 2.9.0
@param string $key
@param array $post_array
@return mixed | [
"@since",
"2",
".",
"9",
".",
"0"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L825-L827 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.get_post_field | protected function get_post_field( $key, $default = null, $post_array = null, $setting = [], $filter = true ) {
if ( isset( $post_array ) ) {
$value = $this->app->utility->array_get( $post_array, $this->get_post_field_name( $key ), $default );
} else {
$value = $this->app->input->post( $this->get_post_field_name( $key ), $default );
}
if ( isset( $setting['null'] ) && empty( $setting['null'] ) && (string) $value === '' ) {
$value = null;
}
if ( ! $filter ) {
return $value;
}
return $this->filter_post_field( $key, $value, $default, $post_array );
} | php | protected function get_post_field( $key, $default = null, $post_array = null, $setting = [], $filter = true ) {
if ( isset( $post_array ) ) {
$value = $this->app->utility->array_get( $post_array, $this->get_post_field_name( $key ), $default );
} else {
$value = $this->app->input->post( $this->get_post_field_name( $key ), $default );
}
if ( isset( $setting['null'] ) && empty( $setting['null'] ) && (string) $value === '' ) {
$value = null;
}
if ( ! $filter ) {
return $value;
}
return $this->filter_post_field( $key, $value, $default, $post_array );
} | [
"protected",
"function",
"get_post_field",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
",",
"$",
"post_array",
"=",
"null",
",",
"$",
"setting",
"=",
"[",
"]",
",",
"$",
"filter",
"=",
"true",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"post_array",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_get",
"(",
"$",
"post_array",
",",
"$",
"this",
"->",
"get_post_field_name",
"(",
"$",
"key",
")",
",",
"$",
"default",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"app",
"->",
"input",
"->",
"post",
"(",
"$",
"this",
"->",
"get_post_field_name",
"(",
"$",
"key",
")",
",",
"$",
"default",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"setting",
"[",
"'null'",
"]",
")",
"&&",
"empty",
"(",
"$",
"setting",
"[",
"'null'",
"]",
")",
"&&",
"(",
"string",
")",
"$",
"value",
"===",
"''",
")",
"{",
"$",
"value",
"=",
"null",
";",
"}",
"if",
"(",
"!",
"$",
"filter",
")",
"{",
"return",
"$",
"value",
";",
"}",
"return",
"$",
"this",
"->",
"filter_post_field",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"default",
",",
"$",
"post_array",
")",
";",
"}"
] | @since 2.9.0 Changed: consider null setting
@since 2.9.0 Added: filter value
@param string $key
@param mixed $default
@param array|null $post_array
@param array $setting
@param bool $filter
@return mixed | [
"@since",
"2",
".",
"9",
".",
"0",
"Changed",
":",
"consider",
"null",
"setting",
"@since",
"2",
".",
"9",
".",
"0",
"Added",
":",
"filter",
"value"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L841-L857 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.output_edit_form | public function output_edit_form( $post ) {
$params = $this->get_edit_form_params( $post );
$this->before_output_edit_form( $post, $params );
$this->add_style_view( 'admin/style/custom_post', $params );
$this->add_style_view( 'admin/style/custom_post/' . $this->get_post_type_slug(), $params );
$this->add_script_view( 'admin/script/custom_post', $params );
$this->add_script_view( 'admin/script/custom_post/' . $this->get_post_type_slug(), $params );
if ( ! $this->get_view( 'admin/custom_post/' . $this->get_post_type_slug(), $params, true, false ) ) {
$columns = $this->app->utility->array_pluck( $params['columns'], 'is_user_defined' );
unset( $columns['post_id'] );
if ( ! empty( array_filter( $columns ) ) ) {
$this->get_view( 'admin/custom_post', $params, true, false );
}
}
$this->after_output_edit_form( $post, $params );
} | php | public function output_edit_form( $post ) {
$params = $this->get_edit_form_params( $post );
$this->before_output_edit_form( $post, $params );
$this->add_style_view( 'admin/style/custom_post', $params );
$this->add_style_view( 'admin/style/custom_post/' . $this->get_post_type_slug(), $params );
$this->add_script_view( 'admin/script/custom_post', $params );
$this->add_script_view( 'admin/script/custom_post/' . $this->get_post_type_slug(), $params );
if ( ! $this->get_view( 'admin/custom_post/' . $this->get_post_type_slug(), $params, true, false ) ) {
$columns = $this->app->utility->array_pluck( $params['columns'], 'is_user_defined' );
unset( $columns['post_id'] );
if ( ! empty( array_filter( $columns ) ) ) {
$this->get_view( 'admin/custom_post', $params, true, false );
}
}
$this->after_output_edit_form( $post, $params );
} | [
"public",
"function",
"output_edit_form",
"(",
"$",
"post",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"get_edit_form_params",
"(",
"$",
"post",
")",
";",
"$",
"this",
"->",
"before_output_edit_form",
"(",
"$",
"post",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"add_style_view",
"(",
"'admin/style/custom_post'",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"add_style_view",
"(",
"'admin/style/custom_post/'",
".",
"$",
"this",
"->",
"get_post_type_slug",
"(",
")",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"add_script_view",
"(",
"'admin/script/custom_post'",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"add_script_view",
"(",
"'admin/script/custom_post/'",
".",
"$",
"this",
"->",
"get_post_type_slug",
"(",
")",
",",
"$",
"params",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"get_view",
"(",
"'admin/custom_post/'",
".",
"$",
"this",
"->",
"get_post_type_slug",
"(",
")",
",",
"$",
"params",
",",
"true",
",",
"false",
")",
")",
"{",
"$",
"columns",
"=",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_pluck",
"(",
"$",
"params",
"[",
"'columns'",
"]",
",",
"'is_user_defined'",
")",
";",
"unset",
"(",
"$",
"columns",
"[",
"'post_id'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"array_filter",
"(",
"$",
"columns",
")",
")",
")",
"{",
"$",
"this",
"->",
"get_view",
"(",
"'admin/custom_post'",
",",
"$",
"params",
",",
"true",
",",
"false",
")",
";",
"}",
"}",
"$",
"this",
"->",
"after_output_edit_form",
"(",
"$",
"post",
",",
"$",
"params",
")",
";",
"}"
] | @since 2.8.3 Added: default form view
@since 2.9.0 Improved: not load view if no column
@param \WP_Post $post | [
"@since",
"2",
".",
"8",
".",
"3",
"Added",
":",
"default",
"form",
"view",
"@since",
"2",
".",
"9",
".",
"0",
"Improved",
":",
"not",
"load",
"view",
"if",
"no",
"column"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L922-L937 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.get_edit_form_params | protected function get_edit_form_params( $post ) {
return $this->filter_edit_form_params( [
'post' => $post,
'data' => $this->get_related_data( $post->ID ),
'prefix' => $this->get_post_field_name_prefix(),
'columns' => $this->filter_table_columns( $this->get_table_columns() ),
], $post );
} | php | protected function get_edit_form_params( $post ) {
return $this->filter_edit_form_params( [
'post' => $post,
'data' => $this->get_related_data( $post->ID ),
'prefix' => $this->get_post_field_name_prefix(),
'columns' => $this->filter_table_columns( $this->get_table_columns() ),
], $post );
} | [
"protected",
"function",
"get_edit_form_params",
"(",
"$",
"post",
")",
"{",
"return",
"$",
"this",
"->",
"filter_edit_form_params",
"(",
"[",
"'post'",
"=>",
"$",
"post",
",",
"'data'",
"=>",
"$",
"this",
"->",
"get_related_data",
"(",
"$",
"post",
"->",
"ID",
")",
",",
"'prefix'",
"=>",
"$",
"this",
"->",
"get_post_field_name_prefix",
"(",
")",
",",
"'columns'",
"=>",
"$",
"this",
"->",
"filter_table_columns",
"(",
"$",
"this",
"->",
"get_table_columns",
"(",
")",
")",
",",
"]",
",",
"$",
"post",
")",
";",
"}"
] | @since 2.8.3 Added: columns parameter
@param \WP_Post $post
@return array | [
"@since",
"2",
".",
"8",
".",
"3",
"Added",
":",
"columns",
"parameter"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L969-L976 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.validate_input | public function validate_input( $post_array = null ) {
! isset( $post_array ) and $post_array = $this->app->input->post();
$errors = [];
foreach ( $this->get_data_field_settings() as $k => $v ) {
$param = $this->get_post_field( $k, null, $post_array, $v );
$param = $this->sanitize_input( $param, $v['type'] );
$validate = $this->validate( $param, $v );
if ( $validate instanceof \WP_Error ) {
$errors[ $k ][] = $validate->get_error_message();
}
}
if ( $this->validate_post_title() && in_array( 'title', $this->get_post_type_supports() ) ) {
if ( ! isset( $post_array['post_title'] ) || '' === trim( $post_array['post_title'] ) ) {
$errors['post_title'][] = $this->app->translate( 'Value is required.' );
}
}
return $this->filter_validate_input( $errors, $post_array );
} | php | public function validate_input( $post_array = null ) {
! isset( $post_array ) and $post_array = $this->app->input->post();
$errors = [];
foreach ( $this->get_data_field_settings() as $k => $v ) {
$param = $this->get_post_field( $k, null, $post_array, $v );
$param = $this->sanitize_input( $param, $v['type'] );
$validate = $this->validate( $param, $v );
if ( $validate instanceof \WP_Error ) {
$errors[ $k ][] = $validate->get_error_message();
}
}
if ( $this->validate_post_title() && in_array( 'title', $this->get_post_type_supports() ) ) {
if ( ! isset( $post_array['post_title'] ) || '' === trim( $post_array['post_title'] ) ) {
$errors['post_title'][] = $this->app->translate( 'Value is required.' );
}
}
return $this->filter_validate_input( $errors, $post_array );
} | [
"public",
"function",
"validate_input",
"(",
"$",
"post_array",
"=",
"null",
")",
"{",
"!",
"isset",
"(",
"$",
"post_array",
")",
"and",
"$",
"post_array",
"=",
"$",
"this",
"->",
"app",
"->",
"input",
"->",
"post",
"(",
")",
";",
"$",
"errors",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_data_field_settings",
"(",
")",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"param",
"=",
"$",
"this",
"->",
"get_post_field",
"(",
"$",
"k",
",",
"null",
",",
"$",
"post_array",
",",
"$",
"v",
")",
";",
"$",
"param",
"=",
"$",
"this",
"->",
"sanitize_input",
"(",
"$",
"param",
",",
"$",
"v",
"[",
"'type'",
"]",
")",
";",
"$",
"validate",
"=",
"$",
"this",
"->",
"validate",
"(",
"$",
"param",
",",
"$",
"v",
")",
";",
"if",
"(",
"$",
"validate",
"instanceof",
"\\",
"WP_Error",
")",
"{",
"$",
"errors",
"[",
"$",
"k",
"]",
"[",
"]",
"=",
"$",
"validate",
"->",
"get_error_message",
"(",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"validate_post_title",
"(",
")",
"&&",
"in_array",
"(",
"'title'",
",",
"$",
"this",
"->",
"get_post_type_supports",
"(",
")",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"post_array",
"[",
"'post_title'",
"]",
")",
"||",
"''",
"===",
"trim",
"(",
"$",
"post_array",
"[",
"'post_title'",
"]",
")",
")",
"{",
"$",
"errors",
"[",
"'post_title'",
"]",
"[",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"translate",
"(",
"'Value is required.'",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"filter_validate_input",
"(",
"$",
"errors",
",",
"$",
"post_array",
")",
";",
"}"
] | @since 2.9.0 Improved: validation
@param array|null $post_array
@return array | [
"@since",
"2",
".",
"9",
".",
"0",
"Improved",
":",
"validation"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L1022-L1041 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.get_error_messages | public function get_error_messages(
/** @noinspection PhpUnusedParameterInspection */
$key, $errors
) {
$columns = $this->app->db->get_columns( $this->get_related_table_name() );
unset( $columns['id'] );
$columns = $this->app->utility->array_combine( $columns, 'name' );
return array_map( function ( $d ) use ( $key, $columns ) {
$key = $this->table_column_to_name( $key, $columns );
return "$d: [{$key}]";
}, $errors );
} | php | public function get_error_messages(
/** @noinspection PhpUnusedParameterInspection */
$key, $errors
) {
$columns = $this->app->db->get_columns( $this->get_related_table_name() );
unset( $columns['id'] );
$columns = $this->app->utility->array_combine( $columns, 'name' );
return array_map( function ( $d ) use ( $key, $columns ) {
$key = $this->table_column_to_name( $key, $columns );
return "$d: [{$key}]";
}, $errors );
} | [
"public",
"function",
"get_error_messages",
"(",
"/** @noinspection PhpUnusedParameterInspection */",
"$",
"key",
",",
"$",
"errors",
")",
"{",
"$",
"columns",
"=",
"$",
"this",
"->",
"app",
"->",
"db",
"->",
"get_columns",
"(",
"$",
"this",
"->",
"get_related_table_name",
"(",
")",
")",
";",
"unset",
"(",
"$",
"columns",
"[",
"'id'",
"]",
")",
";",
"$",
"columns",
"=",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_combine",
"(",
"$",
"columns",
",",
"'name'",
")",
";",
"return",
"array_map",
"(",
"function",
"(",
"$",
"d",
")",
"use",
"(",
"$",
"key",
",",
"$",
"columns",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"table_column_to_name",
"(",
"$",
"key",
",",
"$",
"columns",
")",
";",
"return",
"\"$d: [{$key}]\"",
";",
"}",
",",
"$",
"errors",
")",
";",
"}"
] | @param string $key
@param array $errors
@return array | [
"@param",
"string",
"$key",
"@param",
"array",
"$errors"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L1082-L1095 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.table_column_to_name | protected function table_column_to_name( $key, $columns ) {
$name = $this->get_table_column_name( $key );
if ( isset( $name ) ) {
return $name;
}
return isset( $columns[ $key ]['comment'] ) ? $columns[ $key ]['comment'] : $key;
} | php | protected function table_column_to_name( $key, $columns ) {
$name = $this->get_table_column_name( $key );
if ( isset( $name ) ) {
return $name;
}
return isset( $columns[ $key ]['comment'] ) ? $columns[ $key ]['comment'] : $key;
} | [
"protected",
"function",
"table_column_to_name",
"(",
"$",
"key",
",",
"$",
"columns",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"get_table_column_name",
"(",
"$",
"key",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"name",
";",
"}",
"return",
"isset",
"(",
"$",
"columns",
"[",
"$",
"key",
"]",
"[",
"'comment'",
"]",
")",
"?",
"$",
"columns",
"[",
"$",
"key",
"]",
"[",
"'comment'",
"]",
":",
"$",
"key",
";",
"}"
] | @param string $key
@param array $columns
@return string | [
"@param",
"string",
"$key",
"@param",
"array",
"$columns"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L1103-L1110 |
technote-space/wordpress-plugin-base | src/traits/helper/custom_post.php | Custom_Post.get_edit_post_link | public function get_edit_post_link( $post_id ) {
if ( ! $post = get_post( $post_id ) ) {
return admin_url( 'edit.php?post_type=' . $this->get_post_type() );
}
$post_type_object = get_post_type_object( $post->post_type );
if ( ! $post_type_object ) {
return admin_url( 'edit.php?post_type=' . $this->get_post_type() );
}
$action = '&action=edit';
return admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) );
} | php | public function get_edit_post_link( $post_id ) {
if ( ! $post = get_post( $post_id ) ) {
return admin_url( 'edit.php?post_type=' . $this->get_post_type() );
}
$post_type_object = get_post_type_object( $post->post_type );
if ( ! $post_type_object ) {
return admin_url( 'edit.php?post_type=' . $this->get_post_type() );
}
$action = '&action=edit';
return admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) );
} | [
"public",
"function",
"get_edit_post_link",
"(",
"$",
"post_id",
")",
"{",
"if",
"(",
"!",
"$",
"post",
"=",
"get_post",
"(",
"$",
"post_id",
")",
")",
"{",
"return",
"admin_url",
"(",
"'edit.php?post_type='",
".",
"$",
"this",
"->",
"get_post_type",
"(",
")",
")",
";",
"}",
"$",
"post_type_object",
"=",
"get_post_type_object",
"(",
"$",
"post",
"->",
"post_type",
")",
";",
"if",
"(",
"!",
"$",
"post_type_object",
")",
"{",
"return",
"admin_url",
"(",
"'edit.php?post_type='",
".",
"$",
"this",
"->",
"get_post_type",
"(",
")",
")",
";",
"}",
"$",
"action",
"=",
"'&action=edit'",
";",
"return",
"admin_url",
"(",
"sprintf",
"(",
"$",
"post_type_object",
"->",
"_edit_link",
".",
"$",
"action",
",",
"$",
"post",
"->",
"ID",
")",
")",
";",
"}"
] | @param int $post_id
@return string | [
"@param",
"int",
"$post_id"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/custom_post.php#L1138-L1149 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.