id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
---|---|---|---|---|---|---|---|---|---|---|---|
20,700 |
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/Mail/src/parser/parts/rfc822_digest_parser.php
|
ezcMailRfc822DigestParser.parseBody
|
public function parseBody( $line )
{
$this->mailParser->parseBody( $line );
$this->size += strlen( $line );
}
|
php
|
public function parseBody( $line )
{
$this->mailParser->parseBody( $line );
$this->size += strlen( $line );
}
|
[
"public",
"function",
"parseBody",
"(",
"$",
"line",
")",
"{",
"$",
"this",
"->",
"mailParser",
"->",
"parseBody",
"(",
"$",
"line",
")",
";",
"$",
"this",
"->",
"size",
"+=",
"strlen",
"(",
"$",
"line",
")",
";",
"}"
] |
Parses each line of the digest body.
Every line is part of the digested mail. It is sent directly to the mail parser.
@param string $line
|
[
"Parses",
"each",
"line",
"of",
"the",
"digest",
"body",
"."
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/parser/parts/rfc822_digest_parser.php#L63-L67
|
20,701 |
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/Mail/src/parser/parts/rfc822_digest_parser.php
|
ezcMailRfc822DigestParser.finish
|
public function finish()
{
$digest = new ezcMailRfc822Digest( $this->mailParser->finish() );
ezcMailPartParser::parsePartHeaders( $this->headers, $digest );
$digest->size = $this->size;
return $digest;
}
|
php
|
public function finish()
{
$digest = new ezcMailRfc822Digest( $this->mailParser->finish() );
ezcMailPartParser::parsePartHeaders( $this->headers, $digest );
$digest->size = $this->size;
return $digest;
}
|
[
"public",
"function",
"finish",
"(",
")",
"{",
"$",
"digest",
"=",
"new",
"ezcMailRfc822Digest",
"(",
"$",
"this",
"->",
"mailParser",
"->",
"finish",
"(",
")",
")",
";",
"ezcMailPartParser",
"::",
"parsePartHeaders",
"(",
"$",
"this",
"->",
"headers",
",",
"$",
"digest",
")",
";",
"$",
"digest",
"->",
"size",
"=",
"$",
"this",
"->",
"size",
";",
"return",
"$",
"digest",
";",
"}"
] |
Returns a ezcMailRfc822Digest with the digested mail in it.
@return ezcMailRfc822Digest
|
[
"Returns",
"a",
"ezcMailRfc822Digest",
"with",
"the",
"digested",
"mail",
"in",
"it",
"."
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/parser/parts/rfc822_digest_parser.php#L74-L80
|
20,702 |
zhouyl/mellivora
|
Mellivora/Database/Schema/Grammars/PostgresGrammar.php
|
PostgresGrammar.typeEnum
|
protected function typeEnum(Fluent $column)
{
$allowed = array_map(function ($a) {
return "'{$a}'";
}, $column->allowed);
return "varchar(255) check (\"{$column->name}\" in (" . implode(', ', $allowed) . '))';
}
|
php
|
protected function typeEnum(Fluent $column)
{
$allowed = array_map(function ($a) {
return "'{$a}'";
}, $column->allowed);
return "varchar(255) check (\"{$column->name}\" in (" . implode(', ', $allowed) . '))';
}
|
[
"protected",
"function",
"typeEnum",
"(",
"Fluent",
"$",
"column",
")",
"{",
"$",
"allowed",
"=",
"array_map",
"(",
"function",
"(",
"$",
"a",
")",
"{",
"return",
"\"'{$a}'\"",
";",
"}",
",",
"$",
"column",
"->",
"allowed",
")",
";",
"return",
"\"varchar(255) check (\\\"{$column->name}\\\" in (\"",
".",
"implode",
"(",
"', '",
",",
"$",
"allowed",
")",
".",
"'))'",
";",
"}"
] |
Create the column definition for an enum type.
@param \Mellivora\Support\Fluent $column
@return string
|
[
"Create",
"the",
"column",
"definition",
"for",
"an",
"enum",
"type",
"."
] |
79f844c5c9c25ffbe18d142062e9bc3df00b36a1
|
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Schema/Grammars/PostgresGrammar.php#L449-L456
|
20,703 |
surebert/surebert-framework
|
src/sb/SSH2/Client.php
|
Client.tunnel
|
public function tunnel($host, $port)
{
$stream = @ssh2_tunnel($this->connection, $command);
if(!$stream){
throw new \Exception('Cannot create tunnel to: '.$host.' on port'.$port);
}
return $stream;
}
|
php
|
public function tunnel($host, $port)
{
$stream = @ssh2_tunnel($this->connection, $command);
if(!$stream){
throw new \Exception('Cannot create tunnel to: '.$host.' on port'.$port);
}
return $stream;
}
|
[
"public",
"function",
"tunnel",
"(",
"$",
"host",
",",
"$",
"port",
")",
"{",
"$",
"stream",
"=",
"@",
"ssh2_tunnel",
"(",
"$",
"this",
"->",
"connection",
",",
"$",
"command",
")",
";",
"if",
"(",
"!",
"$",
"stream",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Cannot create tunnel to: '",
".",
"$",
"host",
".",
"' on port'",
".",
"$",
"port",
")",
";",
"}",
"return",
"$",
"stream",
";",
"}"
] |
Tunnels a connection
@param string $host The host to tunnel to via the ssh2 client
@param integer $port The port to tunnel to via the ssh2 client
@return stream The tunnel stream
|
[
"Tunnels",
"a",
"connection"
] |
f2f32eb693bd39385ceb93355efb5b2a429f27ce
|
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/SSH2/Client.php#L109-L117
|
20,704 |
colorium/web
|
src/Colorium/Web/Rest.php
|
Rest.merge
|
public function merge(array $logics)
{
foreach($logics as $name => $specs) {
$this->set($name, $specs);
}
return $this;
}
|
php
|
public function merge(array $logics)
{
foreach($logics as $name => $specs) {
$this->set($name, $specs);
}
return $this;
}
|
[
"public",
"function",
"merge",
"(",
"array",
"$",
"logics",
")",
"{",
"foreach",
"(",
"$",
"logics",
"as",
"$",
"name",
"=>",
"$",
"specs",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"$",
"name",
",",
"$",
"specs",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Merge multiple logics
@param array $logics
@return $this
|
[
"Merge",
"multiple",
"logics"
] |
2a767658b8737022939b0cc4505b5f652c1683d2
|
https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/Rest.php#L67-L74
|
20,705 |
colorium/web
|
src/Colorium/Web/Rest.php
|
Rest.before
|
protected function before(Context $context)
{
// set context forwarder
$context->forwarder = $context->forwarder ?: [$this, 'forward'];
return parent::before($context);
}
|
php
|
protected function before(Context $context)
{
// set context forwarder
$context->forwarder = $context->forwarder ?: [$this, 'forward'];
return parent::before($context);
}
|
[
"protected",
"function",
"before",
"(",
"Context",
"$",
"context",
")",
"{",
"// set context forwarder",
"$",
"context",
"->",
"forwarder",
"=",
"$",
"context",
"->",
"forwarder",
"?",
":",
"[",
"$",
"this",
",",
"'forward'",
"]",
";",
"return",
"parent",
"::",
"before",
"(",
"$",
"context",
")",
";",
"}"
] |
Setup context before process
@param Context $context
@return Context
|
[
"Setup",
"context",
"before",
"process"
] |
2a767658b8737022939b0cc4505b5f652c1683d2
|
https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/Rest.php#L98-L104
|
20,706 |
colorium/web
|
src/Colorium/Web/Rest.php
|
Rest.route
|
protected function route(Context $context)
{
$this->logger->debug('kernel.route: find route from http query');
// logic already specified
if($context->logic) {
$this->logger->debug('kernel.route: forward to #' . $context->logic->name . ', skip routing');
return $context;
}
// find route
$query = $context->request->method . ' ' . $context->request->uri->path;
$route = $this->router->find($query);
// 404
if(!$route) {
throw new NotFoundException('No route found for query ' . $query);
}
// update context
$context->route = $route;
$context->params = $route->params;
$context->logic = $route->resource;
$this->logger->debug('kernel.route: #' . $context->logic->name . ' found for query ' . $query);
return $context;
}
|
php
|
protected function route(Context $context)
{
$this->logger->debug('kernel.route: find route from http query');
// logic already specified
if($context->logic) {
$this->logger->debug('kernel.route: forward to #' . $context->logic->name . ', skip routing');
return $context;
}
// find route
$query = $context->request->method . ' ' . $context->request->uri->path;
$route = $this->router->find($query);
// 404
if(!$route) {
throw new NotFoundException('No route found for query ' . $query);
}
// update context
$context->route = $route;
$context->params = $route->params;
$context->logic = $route->resource;
$this->logger->debug('kernel.route: #' . $context->logic->name . ' found for query ' . $query);
return $context;
}
|
[
"protected",
"function",
"route",
"(",
"Context",
"$",
"context",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'kernel.route: find route from http query'",
")",
";",
"// logic already specified",
"if",
"(",
"$",
"context",
"->",
"logic",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'kernel.route: forward to #'",
".",
"$",
"context",
"->",
"logic",
"->",
"name",
".",
"', skip routing'",
")",
";",
"return",
"$",
"context",
";",
"}",
"// find route",
"$",
"query",
"=",
"$",
"context",
"->",
"request",
"->",
"method",
".",
"' '",
".",
"$",
"context",
"->",
"request",
"->",
"uri",
"->",
"path",
";",
"$",
"route",
"=",
"$",
"this",
"->",
"router",
"->",
"find",
"(",
"$",
"query",
")",
";",
"// 404",
"if",
"(",
"!",
"$",
"route",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"'No route found for query '",
".",
"$",
"query",
")",
";",
"}",
"// update context",
"$",
"context",
"->",
"route",
"=",
"$",
"route",
";",
"$",
"context",
"->",
"params",
"=",
"$",
"route",
"->",
"params",
";",
"$",
"context",
"->",
"logic",
"=",
"$",
"route",
"->",
"resource",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'kernel.route: #'",
".",
"$",
"context",
"->",
"logic",
"->",
"name",
".",
"' found for query '",
".",
"$",
"query",
")",
";",
"return",
"$",
"context",
";",
"}"
] |
Find route from context
@param Context $context
@return Context
@throws NotFoundException
|
[
"Find",
"route",
"from",
"context"
] |
2a767658b8737022939b0cc4505b5f652c1683d2
|
https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/Rest.php#L165-L192
|
20,707 |
dstuecken/notify
|
src/Handler/HeaderHandler.php
|
HeaderHandler.formatAttributes
|
public static function formatAttributes($destroy_callback = null, $create_callback = null, $sticky = null, $life = null, $classname = null, $width = null)
{
$options = [];
if ($destroy_callback !== null)
{
$options['destroyed'] = $destroy_callback;
} // if
if ($create_callback !== null)
{
$options['created'] = $create_callback;
} // if
if ($sticky !== null)
{
$options['sticky'] = !!$sticky;
} // if
if ($life !== null)
{
$options['life'] = $life;
} // if
if ($classname !== null)
{
$options['className'] = $classname;
} // if
if ($width !== null)
{
$options['width'] = $width;
} // if
return $options;
}
|
php
|
public static function formatAttributes($destroy_callback = null, $create_callback = null, $sticky = null, $life = null, $classname = null, $width = null)
{
$options = [];
if ($destroy_callback !== null)
{
$options['destroyed'] = $destroy_callback;
} // if
if ($create_callback !== null)
{
$options['created'] = $create_callback;
} // if
if ($sticky !== null)
{
$options['sticky'] = !!$sticky;
} // if
if ($life !== null)
{
$options['life'] = $life;
} // if
if ($classname !== null)
{
$options['className'] = $classname;
} // if
if ($width !== null)
{
$options['width'] = $width;
} // if
return $options;
}
|
[
"public",
"static",
"function",
"formatAttributes",
"(",
"$",
"destroy_callback",
"=",
"null",
",",
"$",
"create_callback",
"=",
"null",
",",
"$",
"sticky",
"=",
"null",
",",
"$",
"life",
"=",
"null",
",",
"$",
"classname",
"=",
"null",
",",
"$",
"width",
"=",
"null",
")",
"{",
"$",
"options",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"destroy_callback",
"!==",
"null",
")",
"{",
"$",
"options",
"[",
"'destroyed'",
"]",
"=",
"$",
"destroy_callback",
";",
"}",
"// if",
"if",
"(",
"$",
"create_callback",
"!==",
"null",
")",
"{",
"$",
"options",
"[",
"'created'",
"]",
"=",
"$",
"create_callback",
";",
"}",
"// if",
"if",
"(",
"$",
"sticky",
"!==",
"null",
")",
"{",
"$",
"options",
"[",
"'sticky'",
"]",
"=",
"!",
"!",
"$",
"sticky",
";",
"}",
"// if",
"if",
"(",
"$",
"life",
"!==",
"null",
")",
"{",
"$",
"options",
"[",
"'life'",
"]",
"=",
"$",
"life",
";",
"}",
"// if",
"if",
"(",
"$",
"classname",
"!==",
"null",
")",
"{",
"$",
"options",
"[",
"'className'",
"]",
"=",
"$",
"classname",
";",
"}",
"// if",
"if",
"(",
"$",
"width",
"!==",
"null",
")",
"{",
"$",
"options",
"[",
"'width'",
"]",
"=",
"$",
"width",
";",
"}",
"// if",
"return",
"$",
"options",
";",
"}"
] |
Static method for retrieving the options-array.
@param string $destroy_callback
@param string $create_callback
@param boolean $sticky
@param integer $life
@param string $classname
@param integer $width
@return array
|
[
"Static",
"method",
"for",
"retrieving",
"the",
"options",
"-",
"array",
"."
] |
abccf0a6a272caf66baea74323f18e2212c6e11e
|
https://github.com/dstuecken/notify/blob/abccf0a6a272caf66baea74323f18e2212c6e11e/src/Handler/HeaderHandler.php#L149-L184
|
20,708 |
welderlourenco/laravel-facebook
|
src/WelderLourenco/Facebook/Facebook.php
|
Facebook.getFacebookSession
|
private function getFacebookSession($accessToken)
{
$facebookSession = new FacebookSession($accessToken);
try
{
$facebookSession->validate();
return $facebookSession;
}
catch (FacebookRequestException $ex)
{
throw new FacebookException($ex->getMessage());
}
catch (\Exception $ex)
{
throw new FacebookException($ex->getMessage());
}
}
|
php
|
private function getFacebookSession($accessToken)
{
$facebookSession = new FacebookSession($accessToken);
try
{
$facebookSession->validate();
return $facebookSession;
}
catch (FacebookRequestException $ex)
{
throw new FacebookException($ex->getMessage());
}
catch (\Exception $ex)
{
throw new FacebookException($ex->getMessage());
}
}
|
[
"private",
"function",
"getFacebookSession",
"(",
"$",
"accessToken",
")",
"{",
"$",
"facebookSession",
"=",
"new",
"FacebookSession",
"(",
"$",
"accessToken",
")",
";",
"try",
"{",
"$",
"facebookSession",
"->",
"validate",
"(",
")",
";",
"return",
"$",
"facebookSession",
";",
"}",
"catch",
"(",
"FacebookRequestException",
"$",
"ex",
")",
"{",
"throw",
"new",
"FacebookException",
"(",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"throw",
"new",
"FacebookException",
"(",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] |
Get the FacebookSession through an access_token.
@param string $accessToken
@return FacebookSession
|
[
"Get",
"the",
"FacebookSession",
"through",
"an",
"access_token",
"."
] |
e0c80ab5ff1c95b634da8c15a5fd3c00ded232dd
|
https://github.com/welderlourenco/laravel-facebook/blob/e0c80ab5ff1c95b634da8c15a5fd3c00ded232dd/src/WelderLourenco/Facebook/Facebook.php#L74-L92
|
20,709 |
welderlourenco/laravel-facebook
|
src/WelderLourenco/Facebook/Facebook.php
|
Facebook.connect
|
public function connect($accessToken = null)
{
if (is_null($accessToken))
{
return $this->getRedirectLoginHelper();
}
else
{
return $this->getFacebookSession($accessToken);
}
}
|
php
|
public function connect($accessToken = null)
{
if (is_null($accessToken))
{
return $this->getRedirectLoginHelper();
}
else
{
return $this->getFacebookSession($accessToken);
}
}
|
[
"public",
"function",
"connect",
"(",
"$",
"accessToken",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"accessToken",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getRedirectLoginHelper",
"(",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"getFacebookSession",
"(",
"$",
"accessToken",
")",
";",
"}",
"}"
] |
Trigger method that can get either a facebook session with access token or a redirect login helper.
@param string $accessToken The facebook access token.
@return mixed
|
[
"Trigger",
"method",
"that",
"can",
"get",
"either",
"a",
"facebook",
"session",
"with",
"access",
"token",
"or",
"a",
"redirect",
"login",
"helper",
"."
] |
e0c80ab5ff1c95b634da8c15a5fd3c00ded232dd
|
https://github.com/welderlourenco/laravel-facebook/blob/e0c80ab5ff1c95b634da8c15a5fd3c00ded232dd/src/WelderLourenco/Facebook/Facebook.php#L100-L110
|
20,710 |
welderlourenco/laravel-facebook
|
src/WelderLourenco/Facebook/Facebook.php
|
Facebook.process
|
public function process()
{
try
{
$redirectLoginHelper = $this->getRedirectLoginHelper();
return $this->connect($redirectLoginHelper->getSessionFromRedirect()->getToken());
}
catch(FacebookRequestException $ex)
{
throw new FacebookException($ex->getMessage());
}
catch(\Exception $ex)
{
throw new FacebookException($ex->getMessage());
}
}
|
php
|
public function process()
{
try
{
$redirectLoginHelper = $this->getRedirectLoginHelper();
return $this->connect($redirectLoginHelper->getSessionFromRedirect()->getToken());
}
catch(FacebookRequestException $ex)
{
throw new FacebookException($ex->getMessage());
}
catch(\Exception $ex)
{
throw new FacebookException($ex->getMessage());
}
}
|
[
"public",
"function",
"process",
"(",
")",
"{",
"try",
"{",
"$",
"redirectLoginHelper",
"=",
"$",
"this",
"->",
"getRedirectLoginHelper",
"(",
")",
";",
"return",
"$",
"this",
"->",
"connect",
"(",
"$",
"redirectLoginHelper",
"->",
"getSessionFromRedirect",
"(",
")",
"->",
"getToken",
"(",
")",
")",
";",
"}",
"catch",
"(",
"FacebookRequestException",
"$",
"ex",
")",
"{",
"throw",
"new",
"FacebookException",
"(",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"throw",
"new",
"FacebookException",
"(",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] |
Get the redirect postback sent from facebook processed, ready to a facebook session.
@return connect($accessToken)
|
[
"Get",
"the",
"redirect",
"postback",
"sent",
"from",
"facebook",
"processed",
"ready",
"to",
"a",
"facebook",
"session",
"."
] |
e0c80ab5ff1c95b634da8c15a5fd3c00ded232dd
|
https://github.com/welderlourenco/laravel-facebook/blob/e0c80ab5ff1c95b634da8c15a5fd3c00ded232dd/src/WelderLourenco/Facebook/Facebook.php#L117-L133
|
20,711 |
welderlourenco/laravel-facebook
|
src/WelderLourenco/Facebook/Facebook.php
|
Facebook.api
|
public function api(FacebookSession $fbsession, $method, $call)
{
try
{
$facebookResponse = (new FacebookRequest($fbsession, $method, $call))->execute();
return $graphObject = $facebookResponse->getGraphObject();
}
catch (FacebookRequestException $ex)
{
throw new FacebookException($ex->getMessage());
}
catch (\Exception $ex)
{
throw new FacebookException($ex->getMessage());
}
}
|
php
|
public function api(FacebookSession $fbsession, $method, $call)
{
try
{
$facebookResponse = (new FacebookRequest($fbsession, $method, $call))->execute();
return $graphObject = $facebookResponse->getGraphObject();
}
catch (FacebookRequestException $ex)
{
throw new FacebookException($ex->getMessage());
}
catch (\Exception $ex)
{
throw new FacebookException($ex->getMessage());
}
}
|
[
"public",
"function",
"api",
"(",
"FacebookSession",
"$",
"fbsession",
",",
"$",
"method",
",",
"$",
"call",
")",
"{",
"try",
"{",
"$",
"facebookResponse",
"=",
"(",
"new",
"FacebookRequest",
"(",
"$",
"fbsession",
",",
"$",
"method",
",",
"$",
"call",
")",
")",
"->",
"execute",
"(",
")",
";",
"return",
"$",
"graphObject",
"=",
"$",
"facebookResponse",
"->",
"getGraphObject",
"(",
")",
";",
"}",
"catch",
"(",
"FacebookRequestException",
"$",
"ex",
")",
"{",
"throw",
"new",
"FacebookException",
"(",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"throw",
"new",
"FacebookException",
"(",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] |
Make a request into facebook api.
@param FacebookSession $fbsession
@param string $method
@param string $call
@return FacebookRequest
|
[
"Make",
"a",
"request",
"into",
"facebook",
"api",
"."
] |
e0c80ab5ff1c95b634da8c15a5fd3c00ded232dd
|
https://github.com/welderlourenco/laravel-facebook/blob/e0c80ab5ff1c95b634da8c15a5fd3c00ded232dd/src/WelderLourenco/Facebook/Facebook.php#L143-L159
|
20,712 |
welderlourenco/laravel-facebook
|
src/WelderLourenco/Facebook/Facebook.php
|
Facebook.change
|
public function change($appId, $appSecret, $redirectUrl = null)
{
\Config::set('facebook::app.appId', $appId);
\Config::set('facebook::app.appSecret', $appSecret);
if (!is_null($redirectUrl))
\Config::set('facebook::app.redirectUrl', $redirectUrl);
return $this;
}
|
php
|
public function change($appId, $appSecret, $redirectUrl = null)
{
\Config::set('facebook::app.appId', $appId);
\Config::set('facebook::app.appSecret', $appSecret);
if (!is_null($redirectUrl))
\Config::set('facebook::app.redirectUrl', $redirectUrl);
return $this;
}
|
[
"public",
"function",
"change",
"(",
"$",
"appId",
",",
"$",
"appSecret",
",",
"$",
"redirectUrl",
"=",
"null",
")",
"{",
"\\",
"Config",
"::",
"set",
"(",
"'facebook::app.appId'",
",",
"$",
"appId",
")",
";",
"\\",
"Config",
"::",
"set",
"(",
"'facebook::app.appSecret'",
",",
"$",
"appSecret",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"redirectUrl",
")",
")",
"\\",
"Config",
"::",
"set",
"(",
"'facebook::app.redirectUrl'",
",",
"$",
"redirectUrl",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Change the appId, appSecret and redirectUrl before connecting.
@param string $appId
@param string $appSecret
@param string $redireectUrl
@return this
|
[
"Change",
"the",
"appId",
"appSecret",
"and",
"redirectUrl",
"before",
"connecting",
"."
] |
e0c80ab5ff1c95b634da8c15a5fd3c00ded232dd
|
https://github.com/welderlourenco/laravel-facebook/blob/e0c80ab5ff1c95b634da8c15a5fd3c00ded232dd/src/WelderLourenco/Facebook/Facebook.php#L169-L176
|
20,713 |
gyselroth/micro-container
|
src/Container.php
|
Container.has
|
public function has($name): bool
{
try {
$this->container->get($name);
return true;
} catch (\Exception $e) {
return false;
}
}
|
php
|
public function has($name): bool
{
try {
$this->container->get($name);
return true;
} catch (\Exception $e) {
return false;
}
}
|
[
"public",
"function",
"has",
"(",
"$",
"name",
")",
":",
"bool",
"{",
"try",
"{",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"name",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
] |
Check if service is registered.
|
[
"Check",
"if",
"service",
"is",
"registered",
"."
] |
728cf35af9645648392c50752b4b555d491bac4e
|
https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/Container.php#L52-L61
|
20,714 |
GrupaZero/api
|
src/Gzero/Api/Transformer/BlockTranslationTransformer.php
|
BlockTranslationTransformer.transform
|
public function transform($translation)
{
$translation = $this->entityToArray(BlockTranslation::class, $translation);
return [
'id' => (int) $translation['id'],
'langCode' => $translation['lang_code'],
'title' => $translation['title'],
'body' => $translation['body'],
'customFields' => $this->transformCustomFields($translation),
'isActive' => (bool) $translation['is_active'],
'createdAt' => $translation['created_at'],
'updatedAt' => $translation['updated_at'],
];
}
|
php
|
public function transform($translation)
{
$translation = $this->entityToArray(BlockTranslation::class, $translation);
return [
'id' => (int) $translation['id'],
'langCode' => $translation['lang_code'],
'title' => $translation['title'],
'body' => $translation['body'],
'customFields' => $this->transformCustomFields($translation),
'isActive' => (bool) $translation['is_active'],
'createdAt' => $translation['created_at'],
'updatedAt' => $translation['updated_at'],
];
}
|
[
"public",
"function",
"transform",
"(",
"$",
"translation",
")",
"{",
"$",
"translation",
"=",
"$",
"this",
"->",
"entityToArray",
"(",
"BlockTranslation",
"::",
"class",
",",
"$",
"translation",
")",
";",
"return",
"[",
"'id'",
"=>",
"(",
"int",
")",
"$",
"translation",
"[",
"'id'",
"]",
",",
"'langCode'",
"=>",
"$",
"translation",
"[",
"'lang_code'",
"]",
",",
"'title'",
"=>",
"$",
"translation",
"[",
"'title'",
"]",
",",
"'body'",
"=>",
"$",
"translation",
"[",
"'body'",
"]",
",",
"'customFields'",
"=>",
"$",
"this",
"->",
"transformCustomFields",
"(",
"$",
"translation",
")",
",",
"'isActive'",
"=>",
"(",
"bool",
")",
"$",
"translation",
"[",
"'is_active'",
"]",
",",
"'createdAt'",
"=>",
"$",
"translation",
"[",
"'created_at'",
"]",
",",
"'updatedAt'",
"=>",
"$",
"translation",
"[",
"'updated_at'",
"]",
",",
"]",
";",
"}"
] |
Transforms block translation entity
@param BlockTranslation|array $translation BlockTranslation entity
@return array
|
[
"Transforms",
"block",
"translation",
"entity"
] |
fc544bb6057274e9d5e7b617346c3f854ea5effd
|
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Transformer/BlockTranslationTransformer.php#L26-L39
|
20,715 |
SporkCode/Spork
|
src/DateTime/DateInterval.php
|
DateInterval.toSeconds
|
public function toSeconds()
{
$seconds = $this->s;
$seconds += $this->i * 60;
$seconds += $this->h * 3600;
if ($this->days) {
$seconds += $this->days * 86400;
} else {
if ($this->d) {
$seconds += $this->d * 86400;
}
if ($this->m) {
trigger_error('Calculating seconds for interval with months property. Result may not be accurate.', E_USER_WARNING);
$seconds += 2629800;
}
if ($this->y) {
trigger_error('Calculating seconds for interval with years property. Result may not be accurate.', E_USER_WARNING);
$seconds += $this->y * 31557600;
}
}
return $seconds;
}
|
php
|
public function toSeconds()
{
$seconds = $this->s;
$seconds += $this->i * 60;
$seconds += $this->h * 3600;
if ($this->days) {
$seconds += $this->days * 86400;
} else {
if ($this->d) {
$seconds += $this->d * 86400;
}
if ($this->m) {
trigger_error('Calculating seconds for interval with months property. Result may not be accurate.', E_USER_WARNING);
$seconds += 2629800;
}
if ($this->y) {
trigger_error('Calculating seconds for interval with years property. Result may not be accurate.', E_USER_WARNING);
$seconds += $this->y * 31557600;
}
}
return $seconds;
}
|
[
"public",
"function",
"toSeconds",
"(",
")",
"{",
"$",
"seconds",
"=",
"$",
"this",
"->",
"s",
";",
"$",
"seconds",
"+=",
"$",
"this",
"->",
"i",
"*",
"60",
";",
"$",
"seconds",
"+=",
"$",
"this",
"->",
"h",
"*",
"3600",
";",
"if",
"(",
"$",
"this",
"->",
"days",
")",
"{",
"$",
"seconds",
"+=",
"$",
"this",
"->",
"days",
"*",
"86400",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"d",
")",
"{",
"$",
"seconds",
"+=",
"$",
"this",
"->",
"d",
"*",
"86400",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"m",
")",
"{",
"trigger_error",
"(",
"'Calculating seconds for interval with months property. Result may not be accurate.'",
",",
"E_USER_WARNING",
")",
";",
"$",
"seconds",
"+=",
"2629800",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"y",
")",
"{",
"trigger_error",
"(",
"'Calculating seconds for interval with years property. Result may not be accurate.'",
",",
"E_USER_WARNING",
")",
";",
"$",
"seconds",
"+=",
"$",
"this",
"->",
"y",
"*",
"31557600",
";",
"}",
"}",
"return",
"$",
"seconds",
";",
"}"
] |
Convert interval to number of seconds
@return integer
|
[
"Convert",
"interval",
"to",
"number",
"of",
"seconds"
] |
7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a
|
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/DateTime/DateInterval.php#L47-L69
|
20,716 |
SporkCode/Spork
|
src/DateTime/DateInterval.php
|
DateInterval.isQuirkMode
|
protected static function isQuirkMode()
{
if (null === self::$quirkMode) {
self::$quirkMode = version_compare(PHP_VERSION, '5.5.4', '<')
&& version_compare(PHP_VERSION, '5.5.0', '>')
|| version_compare(PHP_VERSION, '5.4.20', '<');
}
return self::$quirkMode;
}
|
php
|
protected static function isQuirkMode()
{
if (null === self::$quirkMode) {
self::$quirkMode = version_compare(PHP_VERSION, '5.5.4', '<')
&& version_compare(PHP_VERSION, '5.5.0', '>')
|| version_compare(PHP_VERSION, '5.4.20', '<');
}
return self::$quirkMode;
}
|
[
"protected",
"static",
"function",
"isQuirkMode",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"self",
"::",
"$",
"quirkMode",
")",
"{",
"self",
"::",
"$",
"quirkMode",
"=",
"version_compare",
"(",
"PHP_VERSION",
",",
"'5.5.4'",
",",
"'<'",
")",
"&&",
"version_compare",
"(",
"PHP_VERSION",
",",
"'5.5.0'",
",",
"'>'",
")",
"||",
"version_compare",
"(",
"PHP_VERSION",
",",
"'5.4.20'",
",",
"'<'",
")",
";",
"}",
"return",
"self",
"::",
"$",
"quirkMode",
";",
"}"
] |
Test if PHP version has quirks
@return boolean
|
[
"Test",
"if",
"PHP",
"version",
"has",
"quirks"
] |
7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a
|
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/DateTime/DateInterval.php#L75-L83
|
20,717 |
zicht/z
|
src/Zicht/Tool/Packager/Node/DynamicStub.php
|
DynamicStub.compileInitialization
|
protected function compileInitialization(Buffer $buffer)
{
$buffer->write('$app = new Zicht\Tool\Application(')
->asPhp($this->appName)
->raw(', Zicht\Version\Version::fromString(')
->asPhp($this->appVersion)
->raw(') ?: new Zicht\Version\Version(), Zicht\Tool\Configuration\ConfigurationLoader::fromEnv(')->asPhp($this->configFilename)->raw(')')
->raw(');')
->eol();
}
|
php
|
protected function compileInitialization(Buffer $buffer)
{
$buffer->write('$app = new Zicht\Tool\Application(')
->asPhp($this->appName)
->raw(', Zicht\Version\Version::fromString(')
->asPhp($this->appVersion)
->raw(') ?: new Zicht\Version\Version(), Zicht\Tool\Configuration\ConfigurationLoader::fromEnv(')->asPhp($this->configFilename)->raw(')')
->raw(');')
->eol();
}
|
[
"protected",
"function",
"compileInitialization",
"(",
"Buffer",
"$",
"buffer",
")",
"{",
"$",
"buffer",
"->",
"write",
"(",
"'$app = new Zicht\\Tool\\Application('",
")",
"->",
"asPhp",
"(",
"$",
"this",
"->",
"appName",
")",
"->",
"raw",
"(",
"', Zicht\\Version\\Version::fromString('",
")",
"->",
"asPhp",
"(",
"$",
"this",
"->",
"appVersion",
")",
"->",
"raw",
"(",
"') ?: new Zicht\\Version\\Version(), Zicht\\Tool\\Configuration\\ConfigurationLoader::fromEnv('",
")",
"->",
"asPhp",
"(",
"$",
"this",
"->",
"configFilename",
")",
"->",
"raw",
"(",
"')'",
")",
"->",
"raw",
"(",
"');'",
")",
"->",
"eol",
"(",
")",
";",
"}"
] |
Writes the initialization code for a dynamic build
@param \Zicht\Tool\Script\Buffer $buffer
@return void
|
[
"Writes",
"the",
"initialization",
"code",
"for",
"a",
"dynamic",
"build"
] |
6a1731dad20b018555a96b726a61d4bf8ec8c886
|
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Packager/Node/DynamicStub.php#L38-L47
|
20,718 |
nabab/bbn
|
src/bbn/html/builder.php
|
builder.reset
|
public function reset()
{
$this->_current_cfg = [];
$this->_cfg = [];
$this->_root_element = false;
$this->_current_element = false;
foreach ( $this->_defaults as $k => $v ){
$this->_current_cfg[$k] = $v;
}
return $this;
}
|
php
|
public function reset()
{
$this->_current_cfg = [];
$this->_cfg = [];
$this->_root_element = false;
$this->_current_element = false;
foreach ( $this->_defaults as $k => $v ){
$this->_current_cfg[$k] = $v;
}
return $this;
}
|
[
"public",
"function",
"reset",
"(",
")",
"{",
"$",
"this",
"->",
"_current_cfg",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"_cfg",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"_root_element",
"=",
"false",
";",
"$",
"this",
"->",
"_current_element",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"_defaults",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"this",
"->",
"_current_cfg",
"[",
"$",
"k",
"]",
"=",
"$",
"v",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Sets the configuration back to its default value
|
[
"Sets",
"the",
"configuration",
"back",
"to",
"its",
"default",
"value"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/html/builder.php#L133-L143
|
20,719 |
nabab/bbn
|
src/bbn/html/builder.php
|
builder.export_config
|
public function export_config()
{
if ( isset($this->_root_element) ){
return bbn\str::make_readable($this->_root_element->get_config());
}
return bbn\str::make_readable($this->_cfg);
}
|
php
|
public function export_config()
{
if ( isset($this->_root_element) ){
return bbn\str::make_readable($this->_root_element->get_config());
}
return bbn\str::make_readable($this->_cfg);
}
|
[
"public",
"function",
"export_config",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_root_element",
")",
")",
"{",
"return",
"bbn",
"\\",
"str",
"::",
"make_readable",
"(",
"$",
"this",
"->",
"_root_element",
"->",
"get_config",
"(",
")",
")",
";",
"}",
"return",
"bbn",
"\\",
"str",
"::",
"make_readable",
"(",
"$",
"this",
"->",
"_cfg",
")",
";",
"}"
] |
Returns the current configuration
@return array
|
[
"Returns",
"the",
"current",
"configuration"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/html/builder.php#L162-L168
|
20,720 |
nabab/bbn
|
src/bbn/html/builder.php
|
builder.option
|
public function option($opt)
{
$args = \func_get_args();
if ( \is_array($opt) && isset($opt[0], $this->_defaults[$opt[0]]) ){
$this->_current_cfg[$opt[0]] = $opt[1];
}
else if ( isset($args[0], $args[1], $this->_defaults[$args[0]]) ){
$this->_current_cfg[$args[0]] = $args[1];
}
else{
throw new InvalidArgumentException('This configuration argument is imaginary... Sorry! :)');
}
return $this;
}
|
php
|
public function option($opt)
{
$args = \func_get_args();
if ( \is_array($opt) && isset($opt[0], $this->_defaults[$opt[0]]) ){
$this->_current_cfg[$opt[0]] = $opt[1];
}
else if ( isset($args[0], $args[1], $this->_defaults[$args[0]]) ){
$this->_current_cfg[$args[0]] = $args[1];
}
else{
throw new InvalidArgumentException('This configuration argument is imaginary... Sorry! :)');
}
return $this;
}
|
[
"public",
"function",
"option",
"(",
"$",
"opt",
")",
"{",
"$",
"args",
"=",
"\\",
"func_get_args",
"(",
")",
";",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"opt",
")",
"&&",
"isset",
"(",
"$",
"opt",
"[",
"0",
"]",
",",
"$",
"this",
"->",
"_defaults",
"[",
"$",
"opt",
"[",
"0",
"]",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_current_cfg",
"[",
"$",
"opt",
"[",
"0",
"]",
"]",
"=",
"$",
"opt",
"[",
"1",
"]",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"this",
"->",
"_defaults",
"[",
"$",
"args",
"[",
"0",
"]",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_current_cfg",
"[",
"$",
"args",
"[",
"0",
"]",
"]",
"=",
"$",
"args",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'This configuration argument is imaginary... Sorry! :)'",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Change an option in the current configuration - Chainable
@param array|string $opt Either an array with the param name and value, or 2 strings in the same order
@return bbn\html\builder
|
[
"Change",
"an",
"option",
"in",
"the",
"current",
"configuration",
"-",
"Chainable"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/html/builder.php#L207-L220
|
20,721 |
mayconpaivac/l5-validation
|
src/Prettus/Validator/AbstractValidator.php
|
AbstractValidator.passesOrFail
|
public function passesOrFail($action = null)
{
if( !$this->passes($action) ){
throw new ValidatorException( $this->errorsBag() );
}
return true;
}
|
php
|
public function passesOrFail($action = null)
{
if( !$this->passes($action) ){
throw new ValidatorException( $this->errorsBag() );
}
return true;
}
|
[
"public",
"function",
"passesOrFail",
"(",
"$",
"action",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"passes",
"(",
"$",
"action",
")",
")",
"{",
"throw",
"new",
"ValidatorException",
"(",
"$",
"this",
"->",
"errorsBag",
"(",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Pass the data and the rules to the validator or throws ValidatorException
@throws ValidatorException
@param string $action
@return boolean
|
[
"Pass",
"the",
"data",
"and",
"the",
"rules",
"to",
"the",
"validator",
"or",
"throws",
"ValidatorException"
] |
0921391d7d9cf2853dd5667fb47c1450a251a0d8
|
https://github.com/mayconpaivac/l5-validation/blob/0921391d7d9cf2853dd5667fb47c1450a251a0d8/src/Prettus/Validator/AbstractValidator.php#L110-L117
|
20,722 |
mayconpaivac/l5-validation
|
src/Prettus/Validator/AbstractValidator.php
|
AbstractValidator.parserValidationRules
|
protected function parserValidationRules($rules, $id = null)
{
if($id === null)
{
return $rules;
}
array_walk($rules, function(&$rules, $field) use ($id)
{
if(!is_array($rules))
{
$rules = explode("|", $rules);
}
foreach($rules as $ruleIdx => $rule)
{
// get name and parameters
@list($name, $params) = array_pad(explode(":", $rule), 2, null);
// only do someting for the unique rule
if(strtolower($name) != "unique") {
continue; // continue in foreach loop, nothing left to do here
}
$p = array_map("trim", explode(",", $params));
// set field name to rules key ($field) (laravel convention)
if(!isset($p[1])) {
$p[1] = $field;
}
// set 3rd parameter to id given to getValidationRules()
$p[2] = $id;
$params = implode(",", $p);
$rules[$ruleIdx] = $name.":".$params;
}
});
return $rules;
}
|
php
|
protected function parserValidationRules($rules, $id = null)
{
if($id === null)
{
return $rules;
}
array_walk($rules, function(&$rules, $field) use ($id)
{
if(!is_array($rules))
{
$rules = explode("|", $rules);
}
foreach($rules as $ruleIdx => $rule)
{
// get name and parameters
@list($name, $params) = array_pad(explode(":", $rule), 2, null);
// only do someting for the unique rule
if(strtolower($name) != "unique") {
continue; // continue in foreach loop, nothing left to do here
}
$p = array_map("trim", explode(",", $params));
// set field name to rules key ($field) (laravel convention)
if(!isset($p[1])) {
$p[1] = $field;
}
// set 3rd parameter to id given to getValidationRules()
$p[2] = $id;
$params = implode(",", $p);
$rules[$ruleIdx] = $name.":".$params;
}
});
return $rules;
}
|
[
"protected",
"function",
"parserValidationRules",
"(",
"$",
"rules",
",",
"$",
"id",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"id",
"===",
"null",
")",
"{",
"return",
"$",
"rules",
";",
"}",
"array_walk",
"(",
"$",
"rules",
",",
"function",
"(",
"&",
"$",
"rules",
",",
"$",
"field",
")",
"use",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"rules",
")",
")",
"{",
"$",
"rules",
"=",
"explode",
"(",
"\"|\"",
",",
"$",
"rules",
")",
";",
"}",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"ruleIdx",
"=>",
"$",
"rule",
")",
"{",
"// get name and parameters",
"@",
"list",
"(",
"$",
"name",
",",
"$",
"params",
")",
"=",
"array_pad",
"(",
"explode",
"(",
"\":\"",
",",
"$",
"rule",
")",
",",
"2",
",",
"null",
")",
";",
"// only do someting for the unique rule",
"if",
"(",
"strtolower",
"(",
"$",
"name",
")",
"!=",
"\"unique\"",
")",
"{",
"continue",
";",
"// continue in foreach loop, nothing left to do here",
"}",
"$",
"p",
"=",
"array_map",
"(",
"\"trim\"",
",",
"explode",
"(",
"\",\"",
",",
"$",
"params",
")",
")",
";",
"// set field name to rules key ($field) (laravel convention)",
"if",
"(",
"!",
"isset",
"(",
"$",
"p",
"[",
"1",
"]",
")",
")",
"{",
"$",
"p",
"[",
"1",
"]",
"=",
"$",
"field",
";",
"}",
"// set 3rd parameter to id given to getValidationRules()",
"$",
"p",
"[",
"2",
"]",
"=",
"$",
"id",
";",
"$",
"params",
"=",
"implode",
"(",
"\",\"",
",",
"$",
"p",
")",
";",
"$",
"rules",
"[",
"$",
"ruleIdx",
"]",
"=",
"$",
"name",
".",
"\":\"",
".",
"$",
"params",
";",
"}",
"}",
")",
";",
"return",
"$",
"rules",
";",
"}"
] |
Parser Validation Rules
@param $rules
@param null $id
@return array
|
[
"Parser",
"Validation",
"Rules"
] |
0921391d7d9cf2853dd5667fb47c1450a251a0d8
|
https://github.com/mayconpaivac/l5-validation/blob/0921391d7d9cf2853dd5667fb47c1450a251a0d8/src/Prettus/Validator/AbstractValidator.php#L174-L215
|
20,723 |
jasny/codeception-module
|
src/ResponseConvertor.php
|
ResponseConvertor.convert
|
public function convert(ResponseInterface $psrResponse)
{
return new BrowserKitResponse(
(string)$psrResponse->getBody(),
$psrResponse->getStatusCode() ?: 200,
$this->flattenHeaders($psrResponse->getHeaders())
);
}
|
php
|
public function convert(ResponseInterface $psrResponse)
{
return new BrowserKitResponse(
(string)$psrResponse->getBody(),
$psrResponse->getStatusCode() ?: 200,
$this->flattenHeaders($psrResponse->getHeaders())
);
}
|
[
"public",
"function",
"convert",
"(",
"ResponseInterface",
"$",
"psrResponse",
")",
"{",
"return",
"new",
"BrowserKitResponse",
"(",
"(",
"string",
")",
"$",
"psrResponse",
"->",
"getBody",
"(",
")",
",",
"$",
"psrResponse",
"->",
"getStatusCode",
"(",
")",
"?",
":",
"200",
",",
"$",
"this",
"->",
"flattenHeaders",
"(",
"$",
"psrResponse",
"->",
"getHeaders",
"(",
")",
")",
")",
";",
"}"
] |
Convert a PSR-7 response to a codeception response
@param ResponseInterface $psrResponse
@return BrowserKitResponse
|
[
"Convert",
"a",
"PSR",
"-",
"7",
"response",
"to",
"a",
"codeception",
"response"
] |
5c2b12e4ab291f26424fda9fbf1618c818bc8d6e
|
https://github.com/jasny/codeception-module/blob/5c2b12e4ab291f26424fda9fbf1618c818bc8d6e/src/ResponseConvertor.php#L19-L26
|
20,724 |
ekuiter/feature-php
|
FeaturePhp/Helper/Partition.php
|
Partition.fromObjects
|
public static function fromObjects($array, $key) {
$elements = array();
foreach ($array as $element) {
$result = call_user_func(array($element, $key));
$elements = array_merge($elements, is_array($result) ? $result : array($result));
}
return new self($elements);
}
|
php
|
public static function fromObjects($array, $key) {
$elements = array();
foreach ($array as $element) {
$result = call_user_func(array($element, $key));
$elements = array_merge($elements, is_array($result) ? $result : array($result));
}
return new self($elements);
}
|
[
"public",
"static",
"function",
"fromObjects",
"(",
"$",
"array",
",",
"$",
"key",
")",
"{",
"$",
"elements",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"element",
")",
"{",
"$",
"result",
"=",
"call_user_func",
"(",
"array",
"(",
"$",
"element",
",",
"$",
"key",
")",
")",
";",
"$",
"elements",
"=",
"array_merge",
"(",
"$",
"elements",
",",
"is_array",
"(",
"$",
"result",
")",
"?",
"$",
"result",
":",
"array",
"(",
"$",
"result",
")",
")",
";",
"}",
"return",
"new",
"self",
"(",
"$",
"elements",
")",
";",
"}"
] |
Creates a partition from a set of objects.
@param array $array
@param callable $key
@return Partition
|
[
"Creates",
"a",
"partition",
"from",
"a",
"set",
"of",
"objects",
"."
] |
daf4a59098802fedcfd1f1a1d07847fcf2fea7bf
|
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Helper/Partition.php#L33-L40
|
20,725 |
ekuiter/feature-php
|
FeaturePhp/Helper/Partition.php
|
Partition.partitionBy
|
public function partitionBy($key) {
$partition = array();
foreach ($this->elements as $element) {
$newEquivalenceClass = true;
for ($i = 0; $i < count($partition); $i++) // partition[$i] is an equivalence class
// an equivalence class is guaranteed to be non-empty
if (call_user_func(array($element, $key), $partition[$i][0])) {
$partition[$i][] = $element;
$newEquivalenceClass = false;
}
if ($newEquivalenceClass)
$partition[] = array($element);
}
return $partition;
}
|
php
|
public function partitionBy($key) {
$partition = array();
foreach ($this->elements as $element) {
$newEquivalenceClass = true;
for ($i = 0; $i < count($partition); $i++) // partition[$i] is an equivalence class
// an equivalence class is guaranteed to be non-empty
if (call_user_func(array($element, $key), $partition[$i][0])) {
$partition[$i][] = $element;
$newEquivalenceClass = false;
}
if ($newEquivalenceClass)
$partition[] = array($element);
}
return $partition;
}
|
[
"public",
"function",
"partitionBy",
"(",
"$",
"key",
")",
"{",
"$",
"partition",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"elements",
"as",
"$",
"element",
")",
"{",
"$",
"newEquivalenceClass",
"=",
"true",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"partition",
")",
";",
"$",
"i",
"++",
")",
"// partition[$i] is an equivalence class",
"// an equivalence class is guaranteed to be non-empty",
"if",
"(",
"call_user_func",
"(",
"array",
"(",
"$",
"element",
",",
"$",
"key",
")",
",",
"$",
"partition",
"[",
"$",
"i",
"]",
"[",
"0",
"]",
")",
")",
"{",
"$",
"partition",
"[",
"$",
"i",
"]",
"[",
"]",
"=",
"$",
"element",
";",
"$",
"newEquivalenceClass",
"=",
"false",
";",
"}",
"if",
"(",
"$",
"newEquivalenceClass",
")",
"$",
"partition",
"[",
"]",
"=",
"array",
"(",
"$",
"element",
")",
";",
"}",
"return",
"$",
"partition",
";",
"}"
] |
Partitions the elements using an equivalence relation.
@param callable $key a binary relation on the elements
@return array[]
|
[
"Partitions",
"the",
"elements",
"using",
"an",
"equivalence",
"relation",
"."
] |
daf4a59098802fedcfd1f1a1d07847fcf2fea7bf
|
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Helper/Partition.php#L47-L61
|
20,726 |
surebert/surebert-framework
|
src/sb/String/HTML.php
|
HTML.escape
|
public static function escape($mixed, $quote_style = ENT_QUOTES, $charset = 'UTF-8')
{
if (is_string($mixed)) {
$mixed = htmlspecialchars($mixed, $quote_style, $charset);
} elseif (is_object($mixed) || is_array($mixed)) {
foreach ($mixed as $k => &$v) {
if ($v) {
if (is_object($mixed)) {
$mixed->$k = self::escape($v, $quote_style, $charset);
} else {
$mixed[$k] = self::escape($v, $quote_style, $charset);
}
}
}
}
return $mixed;
}
|
php
|
public static function escape($mixed, $quote_style = ENT_QUOTES, $charset = 'UTF-8')
{
if (is_string($mixed)) {
$mixed = htmlspecialchars($mixed, $quote_style, $charset);
} elseif (is_object($mixed) || is_array($mixed)) {
foreach ($mixed as $k => &$v) {
if ($v) {
if (is_object($mixed)) {
$mixed->$k = self::escape($v, $quote_style, $charset);
} else {
$mixed[$k] = self::escape($v, $quote_style, $charset);
}
}
}
}
return $mixed;
}
|
[
"public",
"static",
"function",
"escape",
"(",
"$",
"mixed",
",",
"$",
"quote_style",
"=",
"ENT_QUOTES",
",",
"$",
"charset",
"=",
"'UTF-8'",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"mixed",
")",
")",
"{",
"$",
"mixed",
"=",
"htmlspecialchars",
"(",
"$",
"mixed",
",",
"$",
"quote_style",
",",
"$",
"charset",
")",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"mixed",
")",
"||",
"is_array",
"(",
"$",
"mixed",
")",
")",
"{",
"foreach",
"(",
"$",
"mixed",
"as",
"$",
"k",
"=>",
"&",
"$",
"v",
")",
"{",
"if",
"(",
"$",
"v",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"mixed",
")",
")",
"{",
"$",
"mixed",
"->",
"$",
"k",
"=",
"self",
"::",
"escape",
"(",
"$",
"v",
",",
"$",
"quote_style",
",",
"$",
"charset",
")",
";",
"}",
"else",
"{",
"$",
"mixed",
"[",
"$",
"k",
"]",
"=",
"self",
"::",
"escape",
"(",
"$",
"v",
",",
"$",
"quote_style",
",",
"$",
"charset",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"mixed",
";",
"}"
] |
Recursively htmlspecialchars string properties of objects and arrays
@param mixed $mixed The object or array to convert
@param int $quote_style ent quote style from htmlspecialchars
@param string $charset The charset from htmlspecialchars
@return type
|
[
"Recursively",
"htmlspecialchars",
"string",
"properties",
"of",
"objects",
"and",
"arrays"
] |
f2f32eb693bd39385ceb93355efb5b2a429f27ce
|
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/String/HTML.php#L18-L36
|
20,727 |
surebert/surebert-framework
|
src/sb/String/HTML.php
|
HTML.unescape
|
public static function unescape($mixed, $quote_style = ENT_QUOTES, $charset = 'UTF-8')
{
if (is_string($mixed)) {
$mixed = str_replace('&', '&', $mixed);
$mixed = str_replace(''', '\'', $mixed);
$mixed = str_replace('"', '"', $mixed);
$mixed = str_replace('<', '<', $mixed);
$mixed = str_replace('>', '>', $mixed);
} elseif (is_object($mixed) || is_array($mixed)) {
foreach ($mixed as $k => &$v) {
if ($v) {
if (is_object($mixed)) {
$mixed->$k = self::unescape($v);
} else {
$mixed[$k] = self::unescape($v);
}
}
}
}
return $mixed;
}
|
php
|
public static function unescape($mixed, $quote_style = ENT_QUOTES, $charset = 'UTF-8')
{
if (is_string($mixed)) {
$mixed = str_replace('&', '&', $mixed);
$mixed = str_replace(''', '\'', $mixed);
$mixed = str_replace('"', '"', $mixed);
$mixed = str_replace('<', '<', $mixed);
$mixed = str_replace('>', '>', $mixed);
} elseif (is_object($mixed) || is_array($mixed)) {
foreach ($mixed as $k => &$v) {
if ($v) {
if (is_object($mixed)) {
$mixed->$k = self::unescape($v);
} else {
$mixed[$k] = self::unescape($v);
}
}
}
}
return $mixed;
}
|
[
"public",
"static",
"function",
"unescape",
"(",
"$",
"mixed",
",",
"$",
"quote_style",
"=",
"ENT_QUOTES",
",",
"$",
"charset",
"=",
"'UTF-8'",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"mixed",
")",
")",
"{",
"$",
"mixed",
"=",
"str_replace",
"(",
"'&'",
",",
"'&'",
",",
"$",
"mixed",
")",
";",
"$",
"mixed",
"=",
"str_replace",
"(",
"'''",
",",
"'\\''",
",",
"$",
"mixed",
")",
";",
"$",
"mixed",
"=",
"str_replace",
"(",
"'"'",
",",
"'\"'",
",",
"$",
"mixed",
")",
";",
"$",
"mixed",
"=",
"str_replace",
"(",
"'<'",
",",
"'<'",
",",
"$",
"mixed",
")",
";",
"$",
"mixed",
"=",
"str_replace",
"(",
"'>'",
",",
"'>'",
",",
"$",
"mixed",
")",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"mixed",
")",
"||",
"is_array",
"(",
"$",
"mixed",
")",
")",
"{",
"foreach",
"(",
"$",
"mixed",
"as",
"$",
"k",
"=>",
"&",
"$",
"v",
")",
"{",
"if",
"(",
"$",
"v",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"mixed",
")",
")",
"{",
"$",
"mixed",
"->",
"$",
"k",
"=",
"self",
"::",
"unescape",
"(",
"$",
"v",
")",
";",
"}",
"else",
"{",
"$",
"mixed",
"[",
"$",
"k",
"]",
"=",
"self",
"::",
"unescape",
"(",
"$",
"v",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"mixed",
";",
"}"
] |
Recursively unhtmlspecialchars string properties of objects and arrays
@param mixed $mixed The object or array to convert
@param int $quote_style ent quote style from htmlspecialchars
@param string $charset The charset from htmlspecialchars
@return type
|
[
"Recursively",
"unhtmlspecialchars",
"string",
"properties",
"of",
"objects",
"and",
"arrays"
] |
f2f32eb693bd39385ceb93355efb5b2a429f27ce
|
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/String/HTML.php#L45-L67
|
20,728 |
InactiveProjects/limoncello-illuminate
|
app/Http/Controllers/Web/HomeController.php
|
HomeController.authenticate
|
public function authenticate(Request $request)
{
$email = $request->input(self::AUTH_PARAM_EMAIL, null);
$password = $request->input(self::AUTH_PARAM_PASSWORD, null);
if ($email !== null &&
$password !== null &&
($user = User::query()->where(User::FIELD_EMAIL, '=', strtolower($email))->first()) !== null
) {
/** @var HasherInterface $hasher */
$hasher = app(HasherInterface::class);
if ($hasher->check($password, $user->{User::FIELD_PASSWORD_HASH}) === true) {
/** @var TokenCodecInterface $codec */
$codec = app(TokenCodecInterface::class);
$token = $codec->encode($user);
$this->getLogger()->debug(
'Account login success.',
[User::FIELD_EMAIL => $email, User::FIELD_ID => $user->getKey()]
);
return response($token);
}
}
$this->getLogger()->debug('Account login failed.', [User::FIELD_EMAIL => $email]);
return response(null, Response::HTTP_UNAUTHORIZED);
}
|
php
|
public function authenticate(Request $request)
{
$email = $request->input(self::AUTH_PARAM_EMAIL, null);
$password = $request->input(self::AUTH_PARAM_PASSWORD, null);
if ($email !== null &&
$password !== null &&
($user = User::query()->where(User::FIELD_EMAIL, '=', strtolower($email))->first()) !== null
) {
/** @var HasherInterface $hasher */
$hasher = app(HasherInterface::class);
if ($hasher->check($password, $user->{User::FIELD_PASSWORD_HASH}) === true) {
/** @var TokenCodecInterface $codec */
$codec = app(TokenCodecInterface::class);
$token = $codec->encode($user);
$this->getLogger()->debug(
'Account login success.',
[User::FIELD_EMAIL => $email, User::FIELD_ID => $user->getKey()]
);
return response($token);
}
}
$this->getLogger()->debug('Account login failed.', [User::FIELD_EMAIL => $email]);
return response(null, Response::HTTP_UNAUTHORIZED);
}
|
[
"public",
"function",
"authenticate",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"email",
"=",
"$",
"request",
"->",
"input",
"(",
"self",
"::",
"AUTH_PARAM_EMAIL",
",",
"null",
")",
";",
"$",
"password",
"=",
"$",
"request",
"->",
"input",
"(",
"self",
"::",
"AUTH_PARAM_PASSWORD",
",",
"null",
")",
";",
"if",
"(",
"$",
"email",
"!==",
"null",
"&&",
"$",
"password",
"!==",
"null",
"&&",
"(",
"$",
"user",
"=",
"User",
"::",
"query",
"(",
")",
"->",
"where",
"(",
"User",
"::",
"FIELD_EMAIL",
",",
"'='",
",",
"strtolower",
"(",
"$",
"email",
")",
")",
"->",
"first",
"(",
")",
")",
"!==",
"null",
")",
"{",
"/** @var HasherInterface $hasher */",
"$",
"hasher",
"=",
"app",
"(",
"HasherInterface",
"::",
"class",
")",
";",
"if",
"(",
"$",
"hasher",
"->",
"check",
"(",
"$",
"password",
",",
"$",
"user",
"->",
"{",
"User",
"::",
"FIELD_PASSWORD_HASH",
"}",
")",
"===",
"true",
")",
"{",
"/** @var TokenCodecInterface $codec */",
"$",
"codec",
"=",
"app",
"(",
"TokenCodecInterface",
"::",
"class",
")",
";",
"$",
"token",
"=",
"$",
"codec",
"->",
"encode",
"(",
"$",
"user",
")",
";",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"debug",
"(",
"'Account login success.'",
",",
"[",
"User",
"::",
"FIELD_EMAIL",
"=>",
"$",
"email",
",",
"User",
"::",
"FIELD_ID",
"=>",
"$",
"user",
"->",
"getKey",
"(",
")",
"]",
")",
";",
"return",
"response",
"(",
"$",
"token",
")",
";",
"}",
"}",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"debug",
"(",
"'Account login failed.'",
",",
"[",
"User",
"::",
"FIELD_EMAIL",
"=>",
"$",
"email",
"]",
")",
";",
"return",
"response",
"(",
"null",
",",
"Response",
"::",
"HTTP_UNAUTHORIZED",
")",
";",
"}"
] |
Issue auth token.
@param Request $request
@return Response
|
[
"Issue",
"auth",
"token",
"."
] |
cae6fc26190efcf090495a5c3582c10fa2430897
|
https://github.com/InactiveProjects/limoncello-illuminate/blob/cae6fc26190efcf090495a5c3582c10fa2430897/app/Http/Controllers/Web/HomeController.php#L39-L67
|
20,729 |
Danack/GithubArtaxService
|
lib/GithubService/Operation/listForks.php
|
listForks.getFilteredParameter
|
public function getFilteredParameter($name) {
if (array_key_exists($name, $this->parameters) == false) {
throw new \Exception('Parameter '.$name.' does not exist.');
}
$value = $this->parameters[$name];
return $value;
}
|
php
|
public function getFilteredParameter($name) {
if (array_key_exists($name, $this->parameters) == false) {
throw new \Exception('Parameter '.$name.' does not exist.');
}
$value = $this->parameters[$name];
return $value;
}
|
[
"public",
"function",
"getFilteredParameter",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"parameters",
")",
"==",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Parameter '",
".",
"$",
"name",
".",
"' does not exist.'",
")",
";",
"}",
"$",
"value",
"=",
"$",
"this",
"->",
"parameters",
"[",
"$",
"name",
"]",
";",
"return",
"$",
"value",
";",
"}"
] |
Apply any filters necessary to the parameter
@return mixed
@param string $name The name of the parameter to get.
|
[
"Apply",
"any",
"filters",
"necessary",
"to",
"the",
"parameter"
] |
9f62b5be4f413207d4012e7fa084d0ae505680eb
|
https://github.com/Danack/GithubArtaxService/blob/9f62b5be4f413207d4012e7fa084d0ae505680eb/lib/GithubService/Operation/listForks.php#L71-L80
|
20,730 |
nabab/bbn
|
src/bbn/file/image.php
|
image.get_extension
|
public function get_extension(){
parent::get_extension();
if ( !$this->ext2 && $this->file ){
if ( function_exists('exif_imagetype') ){
if ( $r = exif_imagetype($this->file) ){
if ( !array_key_exists($r, bbn\file\image::$allowed_extensions) ){
$this->ext = false;
}
}
else{
$this->ext = false;
}
}
if ( $this->ext ){
$this->ext2 = $this->ext;
if ( $this->ext2 === 'jpg' ){
$this->ext2 = 'jpeg';
}
}
}
return $this->ext;
}
|
php
|
public function get_extension(){
parent::get_extension();
if ( !$this->ext2 && $this->file ){
if ( function_exists('exif_imagetype') ){
if ( $r = exif_imagetype($this->file) ){
if ( !array_key_exists($r, bbn\file\image::$allowed_extensions) ){
$this->ext = false;
}
}
else{
$this->ext = false;
}
}
if ( $this->ext ){
$this->ext2 = $this->ext;
if ( $this->ext2 === 'jpg' ){
$this->ext2 = 'jpeg';
}
}
}
return $this->ext;
}
|
[
"public",
"function",
"get_extension",
"(",
")",
"{",
"parent",
"::",
"get_extension",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"ext2",
"&&",
"$",
"this",
"->",
"file",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'exif_imagetype'",
")",
")",
"{",
"if",
"(",
"$",
"r",
"=",
"exif_imagetype",
"(",
"$",
"this",
"->",
"file",
")",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"r",
",",
"bbn",
"\\",
"file",
"\\",
"image",
"::",
"$",
"allowed_extensions",
")",
")",
"{",
"$",
"this",
"->",
"ext",
"=",
"false",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"ext",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"ext",
")",
"{",
"$",
"this",
"->",
"ext2",
"=",
"$",
"this",
"->",
"ext",
";",
"if",
"(",
"$",
"this",
"->",
"ext2",
"===",
"'jpg'",
")",
"{",
"$",
"this",
"->",
"ext2",
"=",
"'jpeg'",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"ext",
";",
"}"
] |
Returns the extension of the image. If the file has jpg extension will return 'jpeg'.
```php
$img = new bbn\file\image("/home/data/test/image.jpg");
bbn\x::dump($img->get_extension());
// (string) "jpeg"
```
@return string
|
[
"Returns",
"the",
"extension",
"of",
"the",
"image",
".",
"If",
"the",
"file",
"has",
"jpg",
"extension",
"will",
"return",
"jpeg",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L205-L226
|
20,731 |
nabab/bbn
|
src/bbn/file/image.php
|
image.display
|
public function display()
{
if ( $this->test() ){
if ( !headers_sent() ){
header('Content-Type: image/'.$this->ext2);
}
if ( class_exists('\\Imagick') ){
echo $this->img;
$this->img->clear();
$this->img->destroy();
}
else{
\call_user_func('image'.$this->ext2, $this->img);
imagedestroy($this->img);
}
}
return $this;
}
|
php
|
public function display()
{
if ( $this->test() ){
if ( !headers_sent() ){
header('Content-Type: image/'.$this->ext2);
}
if ( class_exists('\\Imagick') ){
echo $this->img;
$this->img->clear();
$this->img->destroy();
}
else{
\call_user_func('image'.$this->ext2, $this->img);
imagedestroy($this->img);
}
}
return $this;
}
|
[
"public",
"function",
"display",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"test",
"(",
")",
")",
"{",
"if",
"(",
"!",
"headers_sent",
"(",
")",
")",
"{",
"header",
"(",
"'Content-Type: image/'",
".",
"$",
"this",
"->",
"ext2",
")",
";",
"}",
"if",
"(",
"class_exists",
"(",
"'\\\\Imagick'",
")",
")",
"{",
"echo",
"$",
"this",
"->",
"img",
";",
"$",
"this",
"->",
"img",
"->",
"clear",
"(",
")",
";",
"$",
"this",
"->",
"img",
"->",
"destroy",
"(",
")",
";",
"}",
"else",
"{",
"\\",
"call_user_func",
"(",
"'image'",
".",
"$",
"this",
"->",
"ext2",
",",
"$",
"this",
"->",
"img",
")",
";",
"imagedestroy",
"(",
"$",
"this",
"->",
"img",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Sends the image with Content-Type.
```php
$img = new bbn\file\image("/home/data/test/image.jpg");
$img->display();
```
@return image
|
[
"Sends",
"the",
"image",
"with",
"Content",
"-",
"Type",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L338-L355
|
20,732 |
nabab/bbn
|
src/bbn/file/image.php
|
image.crop
|
public function crop($w, $h, $x, $y)
{
if ( $this->test() ){
$args = \func_get_args();
foreach ( $args as $arg ){
if ( !is_numeric($arg) ){
$this->error = \defined('BBN_ARGUMENTS_MUST_BE_NUMERIC') ?
BBN_ARGUMENTS_MUST_BE_NUMERIC : 'Arguments must be numeric';
}
}
if ( $w + $x > $this->w ){
return false;
}
if ( $h + $y > $this->h ){
return false;
}
if ( class_exists('\\Imagick') ){
if ( !$this->img->cropImage($w,$h,$x,$y) ){
$this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ?
BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem';
}
}
else
{
$img = imagecreatetruecolor($w,$h);
if ( $this->ext == 'png' || $this->ext == 'gif' || $this->ext == 'svg' ){
imageColorAllocateAlpha($img, 0, 0, 0, 127);
imagealphablending($img, false);
imagesavealpha($img, true);
}
if ( imagecopyresampled($img,$this->img,0,0,$x,$y,$w,$h,$w,$h) ){
$this->img = $img;
}
else{
$this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ?
BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem';
}
}
}
return $this;
}
|
php
|
public function crop($w, $h, $x, $y)
{
if ( $this->test() ){
$args = \func_get_args();
foreach ( $args as $arg ){
if ( !is_numeric($arg) ){
$this->error = \defined('BBN_ARGUMENTS_MUST_BE_NUMERIC') ?
BBN_ARGUMENTS_MUST_BE_NUMERIC : 'Arguments must be numeric';
}
}
if ( $w + $x > $this->w ){
return false;
}
if ( $h + $y > $this->h ){
return false;
}
if ( class_exists('\\Imagick') ){
if ( !$this->img->cropImage($w,$h,$x,$y) ){
$this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ?
BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem';
}
}
else
{
$img = imagecreatetruecolor($w,$h);
if ( $this->ext == 'png' || $this->ext == 'gif' || $this->ext == 'svg' ){
imageColorAllocateAlpha($img, 0, 0, 0, 127);
imagealphablending($img, false);
imagesavealpha($img, true);
}
if ( imagecopyresampled($img,$this->img,0,0,$x,$y,$w,$h,$w,$h) ){
$this->img = $img;
}
else{
$this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ?
BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem';
}
}
}
return $this;
}
|
[
"public",
"function",
"crop",
"(",
"$",
"w",
",",
"$",
"h",
",",
"$",
"x",
",",
"$",
"y",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"test",
"(",
")",
")",
"{",
"$",
"args",
"=",
"\\",
"func_get_args",
"(",
")",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"arg",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"arg",
")",
")",
"{",
"$",
"this",
"->",
"error",
"=",
"\\",
"defined",
"(",
"'BBN_ARGUMENTS_MUST_BE_NUMERIC'",
")",
"?",
"BBN_ARGUMENTS_MUST_BE_NUMERIC",
":",
"'Arguments must be numeric'",
";",
"}",
"}",
"if",
"(",
"$",
"w",
"+",
"$",
"x",
">",
"$",
"this",
"->",
"w",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"h",
"+",
"$",
"y",
">",
"$",
"this",
"->",
"h",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"class_exists",
"(",
"'\\\\Imagick'",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"img",
"->",
"cropImage",
"(",
"$",
"w",
",",
"$",
"h",
",",
"$",
"x",
",",
"$",
"y",
")",
")",
"{",
"$",
"this",
"->",
"error",
"=",
"\\",
"defined",
"(",
"'BBN_THERE_HAS_BEEN_A_PROBLEM'",
")",
"?",
"BBN_THERE_HAS_BEEN_A_PROBLEM",
":",
"'There has been a problem'",
";",
"}",
"}",
"else",
"{",
"$",
"img",
"=",
"imagecreatetruecolor",
"(",
"$",
"w",
",",
"$",
"h",
")",
";",
"if",
"(",
"$",
"this",
"->",
"ext",
"==",
"'png'",
"||",
"$",
"this",
"->",
"ext",
"==",
"'gif'",
"||",
"$",
"this",
"->",
"ext",
"==",
"'svg'",
")",
"{",
"imageColorAllocateAlpha",
"(",
"$",
"img",
",",
"0",
",",
"0",
",",
"0",
",",
"127",
")",
";",
"imagealphablending",
"(",
"$",
"img",
",",
"false",
")",
";",
"imagesavealpha",
"(",
"$",
"img",
",",
"true",
")",
";",
"}",
"if",
"(",
"imagecopyresampled",
"(",
"$",
"img",
",",
"$",
"this",
"->",
"img",
",",
"0",
",",
"0",
",",
"$",
"x",
",",
"$",
"y",
",",
"$",
"w",
",",
"$",
"h",
",",
"$",
"w",
",",
"$",
"h",
")",
")",
"{",
"$",
"this",
"->",
"img",
"=",
"$",
"img",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"error",
"=",
"\\",
"defined",
"(",
"'BBN_THERE_HAS_BEEN_A_PROBLEM'",
")",
"?",
"BBN_THERE_HAS_BEEN_A_PROBLEM",
":",
"'There has been a problem'",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Returns a crop of the image.
```php
$img = new bbn\file\image("/home/data/test/image.jpg");
bbn\x::dump($img->get_width(),$img->get_height());
// (int) 345 146
$img->crop(10, 10, 30, 30)->save("/home/data/test/img2.jpeg");
$img2 = new \bbn\file\image("/home/data/test/img2.jpeg");
bbn\x::hdump($img2->get_width(),$img2->get_height());
// (int) 10 10
```
@param integer $w the new width
@param integer $h the new height
@param integer $x X coordinate
@param integer $y Y coordinate
@return image|false
|
[
"Returns",
"a",
"crop",
"of",
"the",
"image",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L639-L679
|
20,733 |
nabab/bbn
|
src/bbn/file/image.php
|
image.brightness
|
public function brightness($val='+')
{
if ( $this->test() )
{
if ( class_exists('\\Imagick') )
{
$p = ( $val == '-' ) ? 90 : 110;
if ( !$this->img->modulateImage($p,100,100) ){
$this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ?
BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem';
}
}
else if ( function_exists('imagefilter') )
{
$p = ( $val == '-' ) ? -20 : 20;
if ( !imagefilter($this->img,IMG_FILTER_BRIGHTNESS,-20) ){
$this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ?
BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem';
}
}
}
return $this;
}
|
php
|
public function brightness($val='+')
{
if ( $this->test() )
{
if ( class_exists('\\Imagick') )
{
$p = ( $val == '-' ) ? 90 : 110;
if ( !$this->img->modulateImage($p,100,100) ){
$this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ?
BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem';
}
}
else if ( function_exists('imagefilter') )
{
$p = ( $val == '-' ) ? -20 : 20;
if ( !imagefilter($this->img,IMG_FILTER_BRIGHTNESS,-20) ){
$this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ?
BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem';
}
}
}
return $this;
}
|
[
"public",
"function",
"brightness",
"(",
"$",
"val",
"=",
"'+'",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"test",
"(",
")",
")",
"{",
"if",
"(",
"class_exists",
"(",
"'\\\\Imagick'",
")",
")",
"{",
"$",
"p",
"=",
"(",
"$",
"val",
"==",
"'-'",
")",
"?",
"90",
":",
"110",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"img",
"->",
"modulateImage",
"(",
"$",
"p",
",",
"100",
",",
"100",
")",
")",
"{",
"$",
"this",
"->",
"error",
"=",
"\\",
"defined",
"(",
"'BBN_THERE_HAS_BEEN_A_PROBLEM'",
")",
"?",
"BBN_THERE_HAS_BEEN_A_PROBLEM",
":",
"'There has been a problem'",
";",
"}",
"}",
"else",
"if",
"(",
"function_exists",
"(",
"'imagefilter'",
")",
")",
"{",
"$",
"p",
"=",
"(",
"$",
"val",
"==",
"'-'",
")",
"?",
"-",
"20",
":",
"20",
";",
"if",
"(",
"!",
"imagefilter",
"(",
"$",
"this",
"->",
"img",
",",
"IMG_FILTER_BRIGHTNESS",
",",
"-",
"20",
")",
")",
"{",
"$",
"this",
"->",
"error",
"=",
"\\",
"defined",
"(",
"'BBN_THERE_HAS_BEEN_A_PROBLEM'",
")",
"?",
"BBN_THERE_HAS_BEEN_A_PROBLEM",
":",
"'There has been a problem'",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Adjusts the image's brightness.
```php
$img = new bbn\file\image("/home/data/test/image.jpg");
$img->brightness();
$img->brightness("-");
```
@param string $val The value "+" (default) increases the brightness, the value ("-") reduces it.
@return image
|
[
"Adjusts",
"the",
"image",
"s",
"brightness",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L809-L831
|
20,734 |
nabab/bbn
|
src/bbn/file/image.php
|
image.contrast
|
public function contrast($val='+')
{
if ( $this->test() )
{
if ( class_exists('\\Imagick') )
{
$p = ( $val == '-' ) ? 0 : 1;
if ( !$this->img->contrastImage($p) ){
$this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ?
BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem';
}
}
else if ( function_exists('imagefilter') )
{
$p = ( $val == '-' ) ? -20 : 20;
if ( !imagefilter($this->img,IMG_FILTER_CONTRAST,-20) ){
$this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ?
BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem';
}
}
}
return $this;
}
|
php
|
public function contrast($val='+')
{
if ( $this->test() )
{
if ( class_exists('\\Imagick') )
{
$p = ( $val == '-' ) ? 0 : 1;
if ( !$this->img->contrastImage($p) ){
$this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ?
BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem';
}
}
else if ( function_exists('imagefilter') )
{
$p = ( $val == '-' ) ? -20 : 20;
if ( !imagefilter($this->img,IMG_FILTER_CONTRAST,-20) ){
$this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ?
BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem';
}
}
}
return $this;
}
|
[
"public",
"function",
"contrast",
"(",
"$",
"val",
"=",
"'+'",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"test",
"(",
")",
")",
"{",
"if",
"(",
"class_exists",
"(",
"'\\\\Imagick'",
")",
")",
"{",
"$",
"p",
"=",
"(",
"$",
"val",
"==",
"'-'",
")",
"?",
"0",
":",
"1",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"img",
"->",
"contrastImage",
"(",
"$",
"p",
")",
")",
"{",
"$",
"this",
"->",
"error",
"=",
"\\",
"defined",
"(",
"'BBN_THERE_HAS_BEEN_A_PROBLEM'",
")",
"?",
"BBN_THERE_HAS_BEEN_A_PROBLEM",
":",
"'There has been a problem'",
";",
"}",
"}",
"else",
"if",
"(",
"function_exists",
"(",
"'imagefilter'",
")",
")",
"{",
"$",
"p",
"=",
"(",
"$",
"val",
"==",
"'-'",
")",
"?",
"-",
"20",
":",
"20",
";",
"if",
"(",
"!",
"imagefilter",
"(",
"$",
"this",
"->",
"img",
",",
"IMG_FILTER_CONTRAST",
",",
"-",
"20",
")",
")",
"{",
"$",
"this",
"->",
"error",
"=",
"\\",
"defined",
"(",
"'BBN_THERE_HAS_BEEN_A_PROBLEM'",
")",
"?",
"BBN_THERE_HAS_BEEN_A_PROBLEM",
":",
"'There has been a problem'",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Adjusts the image contrast.
```php
$img = new bbn\file\image("/home/data/test/image.jpg");
$img->contrast("-");
$img->contrast();
```
@param string $val The value "+" (default), increases the contrast, the value ("-") reduces it.
@return image
|
[
"Adjusts",
"the",
"image",
"contrast",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L845-L867
|
20,735 |
nabab/bbn
|
src/bbn/file/image.php
|
image.grayscale
|
public function grayscale()
{
if ( $this->test() )
{
if ( class_exists('\\Imagick') )
{
if ( !$this->img->modulateImage(100,0,100) ){
$this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ?
BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem';
}
}
else if ( function_exists('imagefilter') )
{
if ( !imagefilter($this->img,IMG_FILTER_GRAYSCALE) ){
$this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ?
BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem';
}
}
}
return $this;
}
|
php
|
public function grayscale()
{
if ( $this->test() )
{
if ( class_exists('\\Imagick') )
{
if ( !$this->img->modulateImage(100,0,100) ){
$this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ?
BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem';
}
}
else if ( function_exists('imagefilter') )
{
if ( !imagefilter($this->img,IMG_FILTER_GRAYSCALE) ){
$this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ?
BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem';
}
}
}
return $this;
}
|
[
"public",
"function",
"grayscale",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"test",
"(",
")",
")",
"{",
"if",
"(",
"class_exists",
"(",
"'\\\\Imagick'",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"img",
"->",
"modulateImage",
"(",
"100",
",",
"0",
",",
"100",
")",
")",
"{",
"$",
"this",
"->",
"error",
"=",
"\\",
"defined",
"(",
"'BBN_THERE_HAS_BEEN_A_PROBLEM'",
")",
"?",
"BBN_THERE_HAS_BEEN_A_PROBLEM",
":",
"'There has been a problem'",
";",
"}",
"}",
"else",
"if",
"(",
"function_exists",
"(",
"'imagefilter'",
")",
")",
"{",
"if",
"(",
"!",
"imagefilter",
"(",
"$",
"this",
"->",
"img",
",",
"IMG_FILTER_GRAYSCALE",
")",
")",
"{",
"$",
"this",
"->",
"error",
"=",
"\\",
"defined",
"(",
"'BBN_THERE_HAS_BEEN_A_PROBLEM'",
")",
"?",
"BBN_THERE_HAS_BEEN_A_PROBLEM",
":",
"'There has been a problem'",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Converts the image's color to grayscale.
```php
$img = new bbn\file\image("/home/data/test/image.jpg");
$img->grayscale()->save();
```
@return image
|
[
"Converts",
"the",
"image",
"s",
"color",
"to",
"grayscale",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L879-L899
|
20,736 |
nabab/bbn
|
src/bbn/file/image.php
|
image.negate
|
public function negate()
{
if ( $this->test() )
{
if ( class_exists('\\Imagick') )
{
if ( !$this->img->negateImage(false) ){
$this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ?
BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem';
}
}
else if ( function_exists('imagefilter') )
{
if ( !imagefilter($this->img,IMG_FILTER_NEGATE) ){
$this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ?
BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem';
}
}
}
return $this;
}
|
php
|
public function negate()
{
if ( $this->test() )
{
if ( class_exists('\\Imagick') )
{
if ( !$this->img->negateImage(false) ){
$this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ?
BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem';
}
}
else if ( function_exists('imagefilter') )
{
if ( !imagefilter($this->img,IMG_FILTER_NEGATE) ){
$this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ?
BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem';
}
}
}
return $this;
}
|
[
"public",
"function",
"negate",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"test",
"(",
")",
")",
"{",
"if",
"(",
"class_exists",
"(",
"'\\\\Imagick'",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"img",
"->",
"negateImage",
"(",
"false",
")",
")",
"{",
"$",
"this",
"->",
"error",
"=",
"\\",
"defined",
"(",
"'BBN_THERE_HAS_BEEN_A_PROBLEM'",
")",
"?",
"BBN_THERE_HAS_BEEN_A_PROBLEM",
":",
"'There has been a problem'",
";",
"}",
"}",
"else",
"if",
"(",
"function_exists",
"(",
"'imagefilter'",
")",
")",
"{",
"if",
"(",
"!",
"imagefilter",
"(",
"$",
"this",
"->",
"img",
",",
"IMG_FILTER_NEGATE",
")",
")",
"{",
"$",
"this",
"->",
"error",
"=",
"\\",
"defined",
"(",
"'BBN_THERE_HAS_BEEN_A_PROBLEM'",
")",
"?",
"BBN_THERE_HAS_BEEN_A_PROBLEM",
":",
"'There has been a problem'",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Converts the image's color to negative.
```php
$img = new bbn\file\image("/home/data/test/image.jpg");
$img->negate();
```
@return image
|
[
"Converts",
"the",
"image",
"s",
"color",
"to",
"negative",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L911-L931
|
20,737 |
nabab/bbn
|
src/bbn/file/image.php
|
image.polaroid
|
public function polaroid()
{
if ( $this->test() ){
if ( class_exists('\\Imagick') ){
if ( !$this->img->polaroidImage(new \ImagickDraw(), 0) ){
$this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ?
BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem';
}
}
}
return $this;
}
|
php
|
public function polaroid()
{
if ( $this->test() ){
if ( class_exists('\\Imagick') ){
if ( !$this->img->polaroidImage(new \ImagickDraw(), 0) ){
$this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ?
BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem';
}
}
}
return $this;
}
|
[
"public",
"function",
"polaroid",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"test",
"(",
")",
")",
"{",
"if",
"(",
"class_exists",
"(",
"'\\\\Imagick'",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"img",
"->",
"polaroidImage",
"(",
"new",
"\\",
"ImagickDraw",
"(",
")",
",",
"0",
")",
")",
"{",
"$",
"this",
"->",
"error",
"=",
"\\",
"defined",
"(",
"'BBN_THERE_HAS_BEEN_A_PROBLEM'",
")",
"?",
"BBN_THERE_HAS_BEEN_A_PROBLEM",
":",
"'There has been a problem'",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Converts the image's color with polaroid filter.
```php
$img = new bbn\file\image("/home/data/test/image.jpg");
$img->polaroid()->save();
```
@return image
@todo Transparency of png files.
|
[
"Converts",
"the",
"image",
"s",
"color",
"with",
"polaroid",
"filter",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L944-L955
|
20,738 |
nabab/bbn
|
src/bbn/file/image.php
|
image.thumbs
|
public function thumbs($dest = '.', $sizes = [[false, 960], [false, 480], [false, 192], [false, 96], [false, 48]], $mask = '_%s', $crop = false, $bigger = false){
if ( $this->test() && is_dir($dest) ){
$this->get_extension();
$w = $this->get_width();
$h = $this->get_height();
$d = $w >= $h ? 'w' : 'h';
$res = [];
if ( bbn\str::is_integer($sizes) ){
$sizes = [[$sizes, false]];
}
if ( $$d / ($d === 'w' ? $h : $w) < 5 ){
$mask = ($dest === '.' ? '' : $dest.'/').$this->title.$mask.'.'.$this->ext;
//die(var_dump($mask));
foreach ( $sizes as $s ){
if ( bbn\str::is_integer($s) ){
$s = [$s, false];
}
if (
(!empty($s[0]) && ($w > $s[0])) ||
(!empty($s[1]) && ($h > $s[1])) ||
$bigger
){
$smask = (empty($s[0]) ? '' : 'w'.$s[0]).(empty($s[1]) ? '' : 'h'.$s[1]);
$fn = sprintf($mask, $smask);
if ( $s[0] && $s[1] ){
if ( $crop ){
$this->resize($s[0], $s[1], true);
}
else{
$this->resize($d === 'w' ? $s[0] : false, $d === 'h' ? $s[1] : false, false, $s[0], $s[1]);
}
}
else{
$this->resize($s[0], $s[1], $crop);
}
$this->save($fn);
$res[$smask] = $fn;
}
}
return $res;
}
}
return false;
}
|
php
|
public function thumbs($dest = '.', $sizes = [[false, 960], [false, 480], [false, 192], [false, 96], [false, 48]], $mask = '_%s', $crop = false, $bigger = false){
if ( $this->test() && is_dir($dest) ){
$this->get_extension();
$w = $this->get_width();
$h = $this->get_height();
$d = $w >= $h ? 'w' : 'h';
$res = [];
if ( bbn\str::is_integer($sizes) ){
$sizes = [[$sizes, false]];
}
if ( $$d / ($d === 'w' ? $h : $w) < 5 ){
$mask = ($dest === '.' ? '' : $dest.'/').$this->title.$mask.'.'.$this->ext;
//die(var_dump($mask));
foreach ( $sizes as $s ){
if ( bbn\str::is_integer($s) ){
$s = [$s, false];
}
if (
(!empty($s[0]) && ($w > $s[0])) ||
(!empty($s[1]) && ($h > $s[1])) ||
$bigger
){
$smask = (empty($s[0]) ? '' : 'w'.$s[0]).(empty($s[1]) ? '' : 'h'.$s[1]);
$fn = sprintf($mask, $smask);
if ( $s[0] && $s[1] ){
if ( $crop ){
$this->resize($s[0], $s[1], true);
}
else{
$this->resize($d === 'w' ? $s[0] : false, $d === 'h' ? $s[1] : false, false, $s[0], $s[1]);
}
}
else{
$this->resize($s[0], $s[1], $crop);
}
$this->save($fn);
$res[$smask] = $fn;
}
}
return $res;
}
}
return false;
}
|
[
"public",
"function",
"thumbs",
"(",
"$",
"dest",
"=",
"'.'",
",",
"$",
"sizes",
"=",
"[",
"[",
"false",
",",
"960",
"]",
",",
"[",
"false",
",",
"480",
"]",
",",
"[",
"false",
",",
"192",
"]",
",",
"[",
"false",
",",
"96",
"]",
",",
"[",
"false",
",",
"48",
"]",
"]",
",",
"$",
"mask",
"=",
"'_%s'",
",",
"$",
"crop",
"=",
"false",
",",
"$",
"bigger",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"test",
"(",
")",
"&&",
"is_dir",
"(",
"$",
"dest",
")",
")",
"{",
"$",
"this",
"->",
"get_extension",
"(",
")",
";",
"$",
"w",
"=",
"$",
"this",
"->",
"get_width",
"(",
")",
";",
"$",
"h",
"=",
"$",
"this",
"->",
"get_height",
"(",
")",
";",
"$",
"d",
"=",
"$",
"w",
">=",
"$",
"h",
"?",
"'w'",
":",
"'h'",
";",
"$",
"res",
"=",
"[",
"]",
";",
"if",
"(",
"bbn",
"\\",
"str",
"::",
"is_integer",
"(",
"$",
"sizes",
")",
")",
"{",
"$",
"sizes",
"=",
"[",
"[",
"$",
"sizes",
",",
"false",
"]",
"]",
";",
"}",
"if",
"(",
"$",
"$",
"d",
"/",
"(",
"$",
"d",
"===",
"'w'",
"?",
"$",
"h",
":",
"$",
"w",
")",
"<",
"5",
")",
"{",
"$",
"mask",
"=",
"(",
"$",
"dest",
"===",
"'.'",
"?",
"''",
":",
"$",
"dest",
".",
"'/'",
")",
".",
"$",
"this",
"->",
"title",
".",
"$",
"mask",
".",
"'.'",
".",
"$",
"this",
"->",
"ext",
";",
"//die(var_dump($mask));",
"foreach",
"(",
"$",
"sizes",
"as",
"$",
"s",
")",
"{",
"if",
"(",
"bbn",
"\\",
"str",
"::",
"is_integer",
"(",
"$",
"s",
")",
")",
"{",
"$",
"s",
"=",
"[",
"$",
"s",
",",
"false",
"]",
";",
"}",
"if",
"(",
"(",
"!",
"empty",
"(",
"$",
"s",
"[",
"0",
"]",
")",
"&&",
"(",
"$",
"w",
">",
"$",
"s",
"[",
"0",
"]",
")",
")",
"||",
"(",
"!",
"empty",
"(",
"$",
"s",
"[",
"1",
"]",
")",
"&&",
"(",
"$",
"h",
">",
"$",
"s",
"[",
"1",
"]",
")",
")",
"||",
"$",
"bigger",
")",
"{",
"$",
"smask",
"=",
"(",
"empty",
"(",
"$",
"s",
"[",
"0",
"]",
")",
"?",
"''",
":",
"'w'",
".",
"$",
"s",
"[",
"0",
"]",
")",
".",
"(",
"empty",
"(",
"$",
"s",
"[",
"1",
"]",
")",
"?",
"''",
":",
"'h'",
".",
"$",
"s",
"[",
"1",
"]",
")",
";",
"$",
"fn",
"=",
"sprintf",
"(",
"$",
"mask",
",",
"$",
"smask",
")",
";",
"if",
"(",
"$",
"s",
"[",
"0",
"]",
"&&",
"$",
"s",
"[",
"1",
"]",
")",
"{",
"if",
"(",
"$",
"crop",
")",
"{",
"$",
"this",
"->",
"resize",
"(",
"$",
"s",
"[",
"0",
"]",
",",
"$",
"s",
"[",
"1",
"]",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"resize",
"(",
"$",
"d",
"===",
"'w'",
"?",
"$",
"s",
"[",
"0",
"]",
":",
"false",
",",
"$",
"d",
"===",
"'h'",
"?",
"$",
"s",
"[",
"1",
"]",
":",
"false",
",",
"false",
",",
"$",
"s",
"[",
"0",
"]",
",",
"$",
"s",
"[",
"1",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"resize",
"(",
"$",
"s",
"[",
"0",
"]",
",",
"$",
"s",
"[",
"1",
"]",
",",
"$",
"crop",
")",
";",
"}",
"$",
"this",
"->",
"save",
"(",
"$",
"fn",
")",
";",
"$",
"res",
"[",
"$",
"smask",
"]",
"=",
"$",
"fn",
";",
"}",
"}",
"return",
"$",
"res",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Creates miniature of the image
```php
$img = new bbn\file\image("/home/data/test/image.jpg");
$img->thumbs()->save(/home/data/test/image_test.jpg");
```
@return image|false
|
[
"Creates",
"miniature",
"of",
"the",
"image"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L967-L1010
|
20,739 |
nabab/bbn
|
src/bbn/file/image.php
|
image.toString
|
public function toString()
{
if ( $this->test() )
{
if ( class_exists('\\Imagick') )
$m = $this->img;
else
{
ob_start();
\call_user_func('image'.$this->ext2,$this->img);
$m = ob_get_contents();
ob_end_clean();
}
return 'data:image/'.$this->ext.';base64,'.base64_encode($m);
}
}
|
php
|
public function toString()
{
if ( $this->test() )
{
if ( class_exists('\\Imagick') )
$m = $this->img;
else
{
ob_start();
\call_user_func('image'.$this->ext2,$this->img);
$m = ob_get_contents();
ob_end_clean();
}
return 'data:image/'.$this->ext.';base64,'.base64_encode($m);
}
}
|
[
"public",
"function",
"toString",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"test",
"(",
")",
")",
"{",
"if",
"(",
"class_exists",
"(",
"'\\\\Imagick'",
")",
")",
"$",
"m",
"=",
"$",
"this",
"->",
"img",
";",
"else",
"{",
"ob_start",
"(",
")",
";",
"\\",
"call_user_func",
"(",
"'image'",
".",
"$",
"this",
"->",
"ext2",
",",
"$",
"this",
"->",
"img",
")",
";",
"$",
"m",
"=",
"ob_get_contents",
"(",
")",
";",
"ob_end_clean",
"(",
")",
";",
"}",
"return",
"'data:image/'",
".",
"$",
"this",
"->",
"ext",
".",
"';base64,'",
".",
"base64_encode",
"(",
"$",
"m",
")",
";",
"}",
"}"
] |
Return the image as string.
```php
$img = new bbn\file\image("/home/data/test/image.jpg");
bbn\x::hdump($img->toString());
// (string)
```
@return string
|
[
"Return",
"the",
"image",
"as",
"string",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L1023-L1038
|
20,740 |
oroinc/OroLayoutComponent
|
Extension/Theme/PathProvider/ChainPathProvider.php
|
ChainPathProvider.addProvider
|
public function addProvider(PathProviderInterface $provider, $priority = 0)
{
$this->providers[$priority][] = $provider;
$this->sorted = null;
}
|
php
|
public function addProvider(PathProviderInterface $provider, $priority = 0)
{
$this->providers[$priority][] = $provider;
$this->sorted = null;
}
|
[
"public",
"function",
"addProvider",
"(",
"PathProviderInterface",
"$",
"provider",
",",
"$",
"priority",
"=",
"0",
")",
"{",
"$",
"this",
"->",
"providers",
"[",
"$",
"priority",
"]",
"[",
"]",
"=",
"$",
"provider",
";",
"$",
"this",
"->",
"sorted",
"=",
"null",
";",
"}"
] |
For automatically injecting provider should be registered as DI service
with tag layout.resource.path_provider
@param PathProviderInterface $provider
@param int $priority
|
[
"For",
"automatically",
"injecting",
"provider",
"should",
"be",
"registered",
"as",
"DI",
"service",
"with",
"tag",
"layout",
".",
"resource",
".",
"path_provider"
] |
682a96672393d81c63728e47c4a4c3618c515be0
|
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Extension/Theme/PathProvider/ChainPathProvider.php#L23-L27
|
20,741 |
artscorestudio/document-bundle
|
Repository/PageRepository.php
|
PageRepository.getLastVersion
|
public function getLastVersion($page_id)
{
$qb = $this->createQueryBuilder('p');
$qb->where('p.original=:page_id')
->orderBy('p.createdAt', 'DESC')
->setParameter(':page_id', $page_id);
$result = $qb->getQuery()->setMaxResults(1)->getResult();
if ( is_null($result) ) {
$qb2 = $this->createQueryBuilder('p');
$qb2->where('p.id=:page_id')->setParameter(':page_id', $page_id);
$result = $qb->getQuery()->getResult();
}
return $result[0];
}
|
php
|
public function getLastVersion($page_id)
{
$qb = $this->createQueryBuilder('p');
$qb->where('p.original=:page_id')
->orderBy('p.createdAt', 'DESC')
->setParameter(':page_id', $page_id);
$result = $qb->getQuery()->setMaxResults(1)->getResult();
if ( is_null($result) ) {
$qb2 = $this->createQueryBuilder('p');
$qb2->where('p.id=:page_id')->setParameter(':page_id', $page_id);
$result = $qb->getQuery()->getResult();
}
return $result[0];
}
|
[
"public",
"function",
"getLastVersion",
"(",
"$",
"page_id",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'p'",
")",
";",
"$",
"qb",
"->",
"where",
"(",
"'p.original=:page_id'",
")",
"->",
"orderBy",
"(",
"'p.createdAt'",
",",
"'DESC'",
")",
"->",
"setParameter",
"(",
"':page_id'",
",",
"$",
"page_id",
")",
";",
"$",
"result",
"=",
"$",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"setMaxResults",
"(",
"1",
")",
"->",
"getResult",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"result",
")",
")",
"{",
"$",
"qb2",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'p'",
")",
";",
"$",
"qb2",
"->",
"where",
"(",
"'p.id=:page_id'",
")",
"->",
"setParameter",
"(",
"':page_id'",
",",
"$",
"page_id",
")",
";",
"$",
"result",
"=",
"$",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"getResult",
"(",
")",
";",
"}",
"return",
"$",
"result",
"[",
"0",
"]",
";",
"}"
] |
Get last version for a page
@param integer $id ASFDocumentBundle:Page ID
|
[
"Get",
"last",
"version",
"for",
"a",
"page"
] |
3aceab0f75de8f7dd0fad0d0db83d7940bf565c8
|
https://github.com/artscorestudio/document-bundle/blob/3aceab0f75de8f7dd0fad0d0db83d7940bf565c8/Repository/PageRepository.php#L30-L48
|
20,742 |
artscorestudio/document-bundle
|
Repository/PageRepository.php
|
PageRepository.findBySlug
|
public function findBySlug($path)
{
$qb = $this->createQueryBuilder('p');
$qb instanceof QueryBuilder;
$qb->add('where', $qb->expr()->like('p.slug', $qb->expr()->lower(':searched_term')))
->setParameter('searched_term', $path);
return $qb->getQuery()->getResult();
}
|
php
|
public function findBySlug($path)
{
$qb = $this->createQueryBuilder('p');
$qb instanceof QueryBuilder;
$qb->add('where', $qb->expr()->like('p.slug', $qb->expr()->lower(':searched_term')))
->setParameter('searched_term', $path);
return $qb->getQuery()->getResult();
}
|
[
"public",
"function",
"findBySlug",
"(",
"$",
"path",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'p'",
")",
";",
"$",
"qb",
"instanceof",
"QueryBuilder",
";",
"$",
"qb",
"->",
"add",
"(",
"'where'",
",",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"like",
"(",
"'p.slug'",
",",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"lower",
"(",
"':searched_term'",
")",
")",
")",
"->",
"setParameter",
"(",
"'searched_term'",
",",
"$",
"path",
")",
";",
"return",
"$",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"getResult",
"(",
")",
";",
"}"
] |
Find page by slug
@param string $path
|
[
"Find",
"page",
"by",
"slug"
] |
3aceab0f75de8f7dd0fad0d0db83d7940bf565c8
|
https://github.com/artscorestudio/document-bundle/blob/3aceab0f75de8f7dd0fad0d0db83d7940bf565c8/Repository/PageRepository.php#L72-L81
|
20,743 |
oroinc/OroLayoutComponent
|
BlockFactory.php
|
BlockFactory.initializeState
|
protected function initializeState(RawLayout $rawLayout, ContextInterface $context)
{
$this->rawLayout = $rawLayout;
$this->context = $context;
$this->dataAccessor = new DataAccessor($this->registry, $this->context);
$this->optionsResolver = new BlockOptionsResolver($this->registry);
$this->typeHelper = new BlockTypeHelper($this->registry);
$this->blockBuilder = new BlockBuilder(
$this->layoutManipulator,
$this->rawLayout,
$this->typeHelper,
$this->context
);
$this->block = new Block(
$this->rawLayout,
$this->typeHelper,
$this->context,
$this->dataAccessor
);
}
|
php
|
protected function initializeState(RawLayout $rawLayout, ContextInterface $context)
{
$this->rawLayout = $rawLayout;
$this->context = $context;
$this->dataAccessor = new DataAccessor($this->registry, $this->context);
$this->optionsResolver = new BlockOptionsResolver($this->registry);
$this->typeHelper = new BlockTypeHelper($this->registry);
$this->blockBuilder = new BlockBuilder(
$this->layoutManipulator,
$this->rawLayout,
$this->typeHelper,
$this->context
);
$this->block = new Block(
$this->rawLayout,
$this->typeHelper,
$this->context,
$this->dataAccessor
);
}
|
[
"protected",
"function",
"initializeState",
"(",
"RawLayout",
"$",
"rawLayout",
",",
"ContextInterface",
"$",
"context",
")",
"{",
"$",
"this",
"->",
"rawLayout",
"=",
"$",
"rawLayout",
";",
"$",
"this",
"->",
"context",
"=",
"$",
"context",
";",
"$",
"this",
"->",
"dataAccessor",
"=",
"new",
"DataAccessor",
"(",
"$",
"this",
"->",
"registry",
",",
"$",
"this",
"->",
"context",
")",
";",
"$",
"this",
"->",
"optionsResolver",
"=",
"new",
"BlockOptionsResolver",
"(",
"$",
"this",
"->",
"registry",
")",
";",
"$",
"this",
"->",
"typeHelper",
"=",
"new",
"BlockTypeHelper",
"(",
"$",
"this",
"->",
"registry",
")",
";",
"$",
"this",
"->",
"blockBuilder",
"=",
"new",
"BlockBuilder",
"(",
"$",
"this",
"->",
"layoutManipulator",
",",
"$",
"this",
"->",
"rawLayout",
",",
"$",
"this",
"->",
"typeHelper",
",",
"$",
"this",
"->",
"context",
")",
";",
"$",
"this",
"->",
"block",
"=",
"new",
"Block",
"(",
"$",
"this",
"->",
"rawLayout",
",",
"$",
"this",
"->",
"typeHelper",
",",
"$",
"this",
"->",
"context",
",",
"$",
"this",
"->",
"dataAccessor",
")",
";",
"}"
] |
Initializes the state of this factory
@param RawLayout $rawLayout
@param ContextInterface $context
|
[
"Initializes",
"the",
"state",
"of",
"this",
"factory"
] |
682a96672393d81c63728e47c4a4c3618c515be0
|
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/BlockFactory.php#L85-L105
|
20,744 |
oroinc/OroLayoutComponent
|
BlockFactory.php
|
BlockFactory.clearState
|
protected function clearState()
{
$this->rawLayout = null;
$this->context = null;
$this->dataAccessor = null;
$this->optionsResolver = null;
$this->typeHelper = null;
$this->blockBuilder = null;
$this->block = null;
}
|
php
|
protected function clearState()
{
$this->rawLayout = null;
$this->context = null;
$this->dataAccessor = null;
$this->optionsResolver = null;
$this->typeHelper = null;
$this->blockBuilder = null;
$this->block = null;
}
|
[
"protected",
"function",
"clearState",
"(",
")",
"{",
"$",
"this",
"->",
"rawLayout",
"=",
"null",
";",
"$",
"this",
"->",
"context",
"=",
"null",
";",
"$",
"this",
"->",
"dataAccessor",
"=",
"null",
";",
"$",
"this",
"->",
"optionsResolver",
"=",
"null",
";",
"$",
"this",
"->",
"typeHelper",
"=",
"null",
";",
"$",
"this",
"->",
"blockBuilder",
"=",
"null",
";",
"$",
"this",
"->",
"block",
"=",
"null",
";",
"}"
] |
Clears the state of this factory
|
[
"Clears",
"the",
"state",
"of",
"this",
"factory"
] |
682a96672393d81c63728e47c4a4c3618c515be0
|
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/BlockFactory.php#L110-L119
|
20,745 |
oroinc/OroLayoutComponent
|
BlockFactory.php
|
BlockFactory.buildBlocks
|
protected function buildBlocks($rootId)
{
// build the root block
if (!$this->rawLayout->hasProperty($rootId, RawLayout::RESOLVED_OPTIONS, true)) {
$this->buildBlock($rootId);
}
// build child blocks
$iterator = $this->rawLayout->getHierarchyIterator($rootId);
foreach ($iterator as $id) {
if (!$this->rawLayout->has($id) || $this->rawLayout->hasProperty($id, RawLayout::RESOLVED_OPTIONS, true)) {
// the block is already built
continue;
}
if (!$this->isContainerBlock($iterator->getParent())) {
$blockType = $this->rawLayout->getProperty($iterator->getParent(), RawLayout::BLOCK_TYPE, true);
throw new Exception\LogicException(
sprintf(
'The "%s" item cannot be added as a child to "%s" item (block type: %s) '
. 'because only container blocks can have children.',
$id,
$iterator->getParent(),
$blockType instanceof BlockTypeInterface ? $blockType->getName() : $blockType
)
);
}
$this->buildBlock($id);
}
// apply layout changes were made by built blocks and build newly added blocks
$this->layoutManipulator->applyChanges($this->context);
if ($this->layoutManipulator->getNumberOfAddedItems() !== 0) {
$this->buildBlocks($rootId);
}
}
|
php
|
protected function buildBlocks($rootId)
{
// build the root block
if (!$this->rawLayout->hasProperty($rootId, RawLayout::RESOLVED_OPTIONS, true)) {
$this->buildBlock($rootId);
}
// build child blocks
$iterator = $this->rawLayout->getHierarchyIterator($rootId);
foreach ($iterator as $id) {
if (!$this->rawLayout->has($id) || $this->rawLayout->hasProperty($id, RawLayout::RESOLVED_OPTIONS, true)) {
// the block is already built
continue;
}
if (!$this->isContainerBlock($iterator->getParent())) {
$blockType = $this->rawLayout->getProperty($iterator->getParent(), RawLayout::BLOCK_TYPE, true);
throw new Exception\LogicException(
sprintf(
'The "%s" item cannot be added as a child to "%s" item (block type: %s) '
. 'because only container blocks can have children.',
$id,
$iterator->getParent(),
$blockType instanceof BlockTypeInterface ? $blockType->getName() : $blockType
)
);
}
$this->buildBlock($id);
}
// apply layout changes were made by built blocks and build newly added blocks
$this->layoutManipulator->applyChanges($this->context);
if ($this->layoutManipulator->getNumberOfAddedItems() !== 0) {
$this->buildBlocks($rootId);
}
}
|
[
"protected",
"function",
"buildBlocks",
"(",
"$",
"rootId",
")",
"{",
"// build the root block",
"if",
"(",
"!",
"$",
"this",
"->",
"rawLayout",
"->",
"hasProperty",
"(",
"$",
"rootId",
",",
"RawLayout",
"::",
"RESOLVED_OPTIONS",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"buildBlock",
"(",
"$",
"rootId",
")",
";",
"}",
"// build child blocks",
"$",
"iterator",
"=",
"$",
"this",
"->",
"rawLayout",
"->",
"getHierarchyIterator",
"(",
"$",
"rootId",
")",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"rawLayout",
"->",
"has",
"(",
"$",
"id",
")",
"||",
"$",
"this",
"->",
"rawLayout",
"->",
"hasProperty",
"(",
"$",
"id",
",",
"RawLayout",
"::",
"RESOLVED_OPTIONS",
",",
"true",
")",
")",
"{",
"// the block is already built",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isContainerBlock",
"(",
"$",
"iterator",
"->",
"getParent",
"(",
")",
")",
")",
"{",
"$",
"blockType",
"=",
"$",
"this",
"->",
"rawLayout",
"->",
"getProperty",
"(",
"$",
"iterator",
"->",
"getParent",
"(",
")",
",",
"RawLayout",
"::",
"BLOCK_TYPE",
",",
"true",
")",
";",
"throw",
"new",
"Exception",
"\\",
"LogicException",
"(",
"sprintf",
"(",
"'The \"%s\" item cannot be added as a child to \"%s\" item (block type: %s) '",
".",
"'because only container blocks can have children.'",
",",
"$",
"id",
",",
"$",
"iterator",
"->",
"getParent",
"(",
")",
",",
"$",
"blockType",
"instanceof",
"BlockTypeInterface",
"?",
"$",
"blockType",
"->",
"getName",
"(",
")",
":",
"$",
"blockType",
")",
")",
";",
"}",
"$",
"this",
"->",
"buildBlock",
"(",
"$",
"id",
")",
";",
"}",
"// apply layout changes were made by built blocks and build newly added blocks",
"$",
"this",
"->",
"layoutManipulator",
"->",
"applyChanges",
"(",
"$",
"this",
"->",
"context",
")",
";",
"if",
"(",
"$",
"this",
"->",
"layoutManipulator",
"->",
"getNumberOfAddedItems",
"(",
")",
"!==",
"0",
")",
"{",
"$",
"this",
"->",
"buildBlocks",
"(",
"$",
"rootId",
")",
";",
"}",
"}"
] |
Builds all blocks starting with and including the given root block
@param string $rootId
@throws Exception\LogicException if a child block is added to not container
|
[
"Builds",
"all",
"blocks",
"starting",
"with",
"and",
"including",
"the",
"given",
"root",
"block"
] |
682a96672393d81c63728e47c4a4c3618c515be0
|
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/BlockFactory.php#L128-L163
|
20,746 |
oroinc/OroLayoutComponent
|
BlockFactory.php
|
BlockFactory.buildBlockViews
|
protected function buildBlockViews($rootId)
{
/** @var BlockView[] $views */
$views = [];
// build the root view
$rootView = $this->buildBlockView($rootId);
$views[$rootId] = $rootView;
// build child views
$iterator = $this->rawLayout->getHierarchyIterator($rootId);
foreach ($iterator as $id) {
$parentView = $views[$iterator->getParent()];
// build child view
$view = $this->buildBlockView($id, $parentView);
$parentView->children[$id] = $view;
$views[$id] = $view;
}
$viewsCollection = new BlockViewCollection($views);
foreach ($views as $view) {
$view->blocks = $viewsCollection;
}
// finish the root view
$this->finishBlockView($rootView, $rootId);
// finish child views
foreach ($iterator as $id) {
$this->finishBlockView($views[$id], $id);
}
return $rootView;
}
|
php
|
protected function buildBlockViews($rootId)
{
/** @var BlockView[] $views */
$views = [];
// build the root view
$rootView = $this->buildBlockView($rootId);
$views[$rootId] = $rootView;
// build child views
$iterator = $this->rawLayout->getHierarchyIterator($rootId);
foreach ($iterator as $id) {
$parentView = $views[$iterator->getParent()];
// build child view
$view = $this->buildBlockView($id, $parentView);
$parentView->children[$id] = $view;
$views[$id] = $view;
}
$viewsCollection = new BlockViewCollection($views);
foreach ($views as $view) {
$view->blocks = $viewsCollection;
}
// finish the root view
$this->finishBlockView($rootView, $rootId);
// finish child views
foreach ($iterator as $id) {
$this->finishBlockView($views[$id], $id);
}
return $rootView;
}
|
[
"protected",
"function",
"buildBlockViews",
"(",
"$",
"rootId",
")",
"{",
"/** @var BlockView[] $views */",
"$",
"views",
"=",
"[",
"]",
";",
"// build the root view",
"$",
"rootView",
"=",
"$",
"this",
"->",
"buildBlockView",
"(",
"$",
"rootId",
")",
";",
"$",
"views",
"[",
"$",
"rootId",
"]",
"=",
"$",
"rootView",
";",
"// build child views",
"$",
"iterator",
"=",
"$",
"this",
"->",
"rawLayout",
"->",
"getHierarchyIterator",
"(",
"$",
"rootId",
")",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"id",
")",
"{",
"$",
"parentView",
"=",
"$",
"views",
"[",
"$",
"iterator",
"->",
"getParent",
"(",
")",
"]",
";",
"// build child view",
"$",
"view",
"=",
"$",
"this",
"->",
"buildBlockView",
"(",
"$",
"id",
",",
"$",
"parentView",
")",
";",
"$",
"parentView",
"->",
"children",
"[",
"$",
"id",
"]",
"=",
"$",
"view",
";",
"$",
"views",
"[",
"$",
"id",
"]",
"=",
"$",
"view",
";",
"}",
"$",
"viewsCollection",
"=",
"new",
"BlockViewCollection",
"(",
"$",
"views",
")",
";",
"foreach",
"(",
"$",
"views",
"as",
"$",
"view",
")",
"{",
"$",
"view",
"->",
"blocks",
"=",
"$",
"viewsCollection",
";",
"}",
"// finish the root view",
"$",
"this",
"->",
"finishBlockView",
"(",
"$",
"rootView",
",",
"$",
"rootId",
")",
";",
"// finish child views",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"id",
")",
"{",
"$",
"this",
"->",
"finishBlockView",
"(",
"$",
"views",
"[",
"$",
"id",
"]",
",",
"$",
"id",
")",
";",
"}",
"return",
"$",
"rootView",
";",
"}"
] |
Builds views for all blocks starting with and including the given root block
@param string $rootId
@return BlockView The root block view
|
[
"Builds",
"views",
"for",
"all",
"blocks",
"starting",
"with",
"and",
"including",
"the",
"given",
"root",
"block"
] |
682a96672393d81c63728e47c4a4c3618c515be0
|
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/BlockFactory.php#L172-L204
|
20,747 |
oroinc/OroLayoutComponent
|
BlockFactory.php
|
BlockFactory.buildBlock
|
protected function buildBlock($id)
{
$blockType = $this->rawLayout->getProperty($id, RawLayout::BLOCK_TYPE, true);
$options = $this->rawLayout->getProperty($id, RawLayout::OPTIONS, true);
$types = $this->typeHelper->getTypes($blockType);
$this->setBlockResolvedOptions($id, $blockType, $options, $types);
}
|
php
|
protected function buildBlock($id)
{
$blockType = $this->rawLayout->getProperty($id, RawLayout::BLOCK_TYPE, true);
$options = $this->rawLayout->getProperty($id, RawLayout::OPTIONS, true);
$types = $this->typeHelper->getTypes($blockType);
$this->setBlockResolvedOptions($id, $blockType, $options, $types);
}
|
[
"protected",
"function",
"buildBlock",
"(",
"$",
"id",
")",
"{",
"$",
"blockType",
"=",
"$",
"this",
"->",
"rawLayout",
"->",
"getProperty",
"(",
"$",
"id",
",",
"RawLayout",
"::",
"BLOCK_TYPE",
",",
"true",
")",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"rawLayout",
"->",
"getProperty",
"(",
"$",
"id",
",",
"RawLayout",
"::",
"OPTIONS",
",",
"true",
")",
";",
"$",
"types",
"=",
"$",
"this",
"->",
"typeHelper",
"->",
"getTypes",
"(",
"$",
"blockType",
")",
";",
"$",
"this",
"->",
"setBlockResolvedOptions",
"(",
"$",
"id",
",",
"$",
"blockType",
",",
"$",
"options",
",",
"$",
"types",
")",
";",
"}"
] |
Builds the block
@param string $id
|
[
"Builds",
"the",
"block"
] |
682a96672393d81c63728e47c4a4c3618c515be0
|
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/BlockFactory.php#L211-L218
|
20,748 |
oroinc/OroLayoutComponent
|
BlockFactory.php
|
BlockFactory.buildBlockView
|
protected function buildBlockView($id, BlockView $parentView = null)
{
$blockType = $this->rawLayout->getProperty($id, RawLayout::BLOCK_TYPE, true);
$resolvedOptions = $this->rawLayout->getProperty($id, RawLayout::RESOLVED_OPTIONS, true);
$types = $this->typeHelper->getTypes($blockType);
$view = new BlockView($parentView);
if (is_null($resolvedOptions)) { // Try to resolve options again to render block
$options = $this->rawLayout->getProperty($id, RawLayout::OPTIONS, true);
$resolvedOptions = $this->setBlockResolvedOptions($id, $blockType, $options, $types);
}
// point the block view state to the current block
$this->block->initialize($id);
// build the view
foreach ($types as $type) {
$type->buildView($view, $this->block, $resolvedOptions);
$this->registry->buildView($type->getName(), $view, $this->block, $resolvedOptions);
}
array_walk_recursive(
$view->vars,
function (&$var) {
if ($var instanceof Options) {
$var = $var->toArray();
}
}
);
return $view;
}
|
php
|
protected function buildBlockView($id, BlockView $parentView = null)
{
$blockType = $this->rawLayout->getProperty($id, RawLayout::BLOCK_TYPE, true);
$resolvedOptions = $this->rawLayout->getProperty($id, RawLayout::RESOLVED_OPTIONS, true);
$types = $this->typeHelper->getTypes($blockType);
$view = new BlockView($parentView);
if (is_null($resolvedOptions)) { // Try to resolve options again to render block
$options = $this->rawLayout->getProperty($id, RawLayout::OPTIONS, true);
$resolvedOptions = $this->setBlockResolvedOptions($id, $blockType, $options, $types);
}
// point the block view state to the current block
$this->block->initialize($id);
// build the view
foreach ($types as $type) {
$type->buildView($view, $this->block, $resolvedOptions);
$this->registry->buildView($type->getName(), $view, $this->block, $resolvedOptions);
}
array_walk_recursive(
$view->vars,
function (&$var) {
if ($var instanceof Options) {
$var = $var->toArray();
}
}
);
return $view;
}
|
[
"protected",
"function",
"buildBlockView",
"(",
"$",
"id",
",",
"BlockView",
"$",
"parentView",
"=",
"null",
")",
"{",
"$",
"blockType",
"=",
"$",
"this",
"->",
"rawLayout",
"->",
"getProperty",
"(",
"$",
"id",
",",
"RawLayout",
"::",
"BLOCK_TYPE",
",",
"true",
")",
";",
"$",
"resolvedOptions",
"=",
"$",
"this",
"->",
"rawLayout",
"->",
"getProperty",
"(",
"$",
"id",
",",
"RawLayout",
"::",
"RESOLVED_OPTIONS",
",",
"true",
")",
";",
"$",
"types",
"=",
"$",
"this",
"->",
"typeHelper",
"->",
"getTypes",
"(",
"$",
"blockType",
")",
";",
"$",
"view",
"=",
"new",
"BlockView",
"(",
"$",
"parentView",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"resolvedOptions",
")",
")",
"{",
"// Try to resolve options again to render block",
"$",
"options",
"=",
"$",
"this",
"->",
"rawLayout",
"->",
"getProperty",
"(",
"$",
"id",
",",
"RawLayout",
"::",
"OPTIONS",
",",
"true",
")",
";",
"$",
"resolvedOptions",
"=",
"$",
"this",
"->",
"setBlockResolvedOptions",
"(",
"$",
"id",
",",
"$",
"blockType",
",",
"$",
"options",
",",
"$",
"types",
")",
";",
"}",
"// point the block view state to the current block",
"$",
"this",
"->",
"block",
"->",
"initialize",
"(",
"$",
"id",
")",
";",
"// build the view",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"$",
"type",
"->",
"buildView",
"(",
"$",
"view",
",",
"$",
"this",
"->",
"block",
",",
"$",
"resolvedOptions",
")",
";",
"$",
"this",
"->",
"registry",
"->",
"buildView",
"(",
"$",
"type",
"->",
"getName",
"(",
")",
",",
"$",
"view",
",",
"$",
"this",
"->",
"block",
",",
"$",
"resolvedOptions",
")",
";",
"}",
"array_walk_recursive",
"(",
"$",
"view",
"->",
"vars",
",",
"function",
"(",
"&",
"$",
"var",
")",
"{",
"if",
"(",
"$",
"var",
"instanceof",
"Options",
")",
"{",
"$",
"var",
"=",
"$",
"var",
"->",
"toArray",
"(",
")",
";",
"}",
"}",
")",
";",
"return",
"$",
"view",
";",
"}"
] |
Created and builds the block view
@param string $id
@param BlockView|null $parentView
@return BlockView
|
[
"Created",
"and",
"builds",
"the",
"block",
"view"
] |
682a96672393d81c63728e47c4a4c3618c515be0
|
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/BlockFactory.php#L228-L258
|
20,749 |
oroinc/OroLayoutComponent
|
BlockFactory.php
|
BlockFactory.finishBlockView
|
protected function finishBlockView(BlockView $view, $id)
{
$blockType = $this->rawLayout->getProperty($id, RawLayout::BLOCK_TYPE, true);
$types = $this->typeHelper->getTypes($blockType);
// point the block view state to the current block
$this->block->initialize($id);
// finish the view
foreach ($types as $type) {
$type->finishView($view, $this->block);
$this->registry->finishView($type->getName(), $view, $this->block);
}
}
|
php
|
protected function finishBlockView(BlockView $view, $id)
{
$blockType = $this->rawLayout->getProperty($id, RawLayout::BLOCK_TYPE, true);
$types = $this->typeHelper->getTypes($blockType);
// point the block view state to the current block
$this->block->initialize($id);
// finish the view
foreach ($types as $type) {
$type->finishView($view, $this->block);
$this->registry->finishView($type->getName(), $view, $this->block);
}
}
|
[
"protected",
"function",
"finishBlockView",
"(",
"BlockView",
"$",
"view",
",",
"$",
"id",
")",
"{",
"$",
"blockType",
"=",
"$",
"this",
"->",
"rawLayout",
"->",
"getProperty",
"(",
"$",
"id",
",",
"RawLayout",
"::",
"BLOCK_TYPE",
",",
"true",
")",
";",
"$",
"types",
"=",
"$",
"this",
"->",
"typeHelper",
"->",
"getTypes",
"(",
"$",
"blockType",
")",
";",
"// point the block view state to the current block",
"$",
"this",
"->",
"block",
"->",
"initialize",
"(",
"$",
"id",
")",
";",
"// finish the view",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"$",
"type",
"->",
"finishView",
"(",
"$",
"view",
",",
"$",
"this",
"->",
"block",
")",
";",
"$",
"this",
"->",
"registry",
"->",
"finishView",
"(",
"$",
"type",
"->",
"getName",
"(",
")",
",",
"$",
"view",
",",
"$",
"this",
"->",
"block",
")",
";",
"}",
"}"
] |
Finishes the building of the block view
@param BlockView $view
@param string $id
|
[
"Finishes",
"the",
"building",
"of",
"the",
"block",
"view"
] |
682a96672393d81c63728e47c4a4c3618c515be0
|
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/BlockFactory.php#L266-L278
|
20,750 |
oroinc/OroLayoutComponent
|
BlockFactory.php
|
BlockFactory.isContainerBlock
|
protected function isContainerBlock($id)
{
return $this->typeHelper->isInstanceOf(
$this->rawLayout->getProperty($id, RawLayout::BLOCK_TYPE, true),
ContainerType::NAME
);
}
|
php
|
protected function isContainerBlock($id)
{
return $this->typeHelper->isInstanceOf(
$this->rawLayout->getProperty($id, RawLayout::BLOCK_TYPE, true),
ContainerType::NAME
);
}
|
[
"protected",
"function",
"isContainerBlock",
"(",
"$",
"id",
")",
"{",
"return",
"$",
"this",
"->",
"typeHelper",
"->",
"isInstanceOf",
"(",
"$",
"this",
"->",
"rawLayout",
"->",
"getProperty",
"(",
"$",
"id",
",",
"RawLayout",
"::",
"BLOCK_TYPE",
",",
"true",
")",
",",
"ContainerType",
"::",
"NAME",
")",
";",
"}"
] |
Checks whether the given block is a container for other blocks
@param string $id
@return bool
|
[
"Checks",
"whether",
"the",
"given",
"block",
"is",
"a",
"container",
"for",
"other",
"blocks"
] |
682a96672393d81c63728e47c4a4c3618c515be0
|
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/BlockFactory.php#L287-L293
|
20,751 |
oroinc/OroLayoutComponent
|
BlockFactory.php
|
BlockFactory.processExpressions
|
protected function processExpressions(Options $options)
{
if (!$this->context->getOr('expressions_evaluate')) {
return;
}
$values = $options->toArray();
if ($this->context->getOr('expressions_evaluate_deferred')) {
$this->expressionProcessor->processExpressions($values, $this->context, null, true, null);
} else {
$this->expressionProcessor->processExpressions(
$values,
$this->context,
$this->dataAccessor,
true,
$this->context->getOr('expressions_encoding')
);
}
$options->setMultiple($values);
}
|
php
|
protected function processExpressions(Options $options)
{
if (!$this->context->getOr('expressions_evaluate')) {
return;
}
$values = $options->toArray();
if ($this->context->getOr('expressions_evaluate_deferred')) {
$this->expressionProcessor->processExpressions($values, $this->context, null, true, null);
} else {
$this->expressionProcessor->processExpressions(
$values,
$this->context,
$this->dataAccessor,
true,
$this->context->getOr('expressions_encoding')
);
}
$options->setMultiple($values);
}
|
[
"protected",
"function",
"processExpressions",
"(",
"Options",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"context",
"->",
"getOr",
"(",
"'expressions_evaluate'",
")",
")",
"{",
"return",
";",
"}",
"$",
"values",
"=",
"$",
"options",
"->",
"toArray",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"context",
"->",
"getOr",
"(",
"'expressions_evaluate_deferred'",
")",
")",
"{",
"$",
"this",
"->",
"expressionProcessor",
"->",
"processExpressions",
"(",
"$",
"values",
",",
"$",
"this",
"->",
"context",
",",
"null",
",",
"true",
",",
"null",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"expressionProcessor",
"->",
"processExpressions",
"(",
"$",
"values",
",",
"$",
"this",
"->",
"context",
",",
"$",
"this",
"->",
"dataAccessor",
",",
"true",
",",
"$",
"this",
"->",
"context",
"->",
"getOr",
"(",
"'expressions_encoding'",
")",
")",
";",
"}",
"$",
"options",
"->",
"setMultiple",
"(",
"$",
"values",
")",
";",
"}"
] |
Processes expressions that don't work with data
@param Options $options
|
[
"Processes",
"expressions",
"that",
"don",
"t",
"work",
"with",
"data"
] |
682a96672393d81c63728e47c4a4c3618c515be0
|
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/BlockFactory.php#L300-L321
|
20,752 |
oroinc/OroLayoutComponent
|
BlockFactory.php
|
BlockFactory.setBlockResolvedOptions
|
protected function setBlockResolvedOptions($id, $blockType, $options, $types)
{
// resolve options
$resolvedOptions = new Options($this->optionsResolver->resolveOptions($blockType, $options));
$this->processExpressions($resolvedOptions);
$resolvedOptions = $this->resolveValueBags($resolvedOptions);
if ($resolvedOptions->get('visible', false) !== false) {
// point the block builder state to the current block
$this->blockBuilder->initialize($id);
// iterate from parent to current
foreach ($types as $type) {
$type->buildBlock($this->blockBuilder, $resolvedOptions);
$this->registry->buildBlock($type->getName(), $this->blockBuilder, $resolvedOptions);
}
$this->rawLayout->setProperty($id, RawLayout::RESOLVED_OPTIONS, $resolvedOptions);
} else {
$this->rawLayout->remove($id);
}
return $resolvedOptions;
}
|
php
|
protected function setBlockResolvedOptions($id, $blockType, $options, $types)
{
// resolve options
$resolvedOptions = new Options($this->optionsResolver->resolveOptions($blockType, $options));
$this->processExpressions($resolvedOptions);
$resolvedOptions = $this->resolveValueBags($resolvedOptions);
if ($resolvedOptions->get('visible', false) !== false) {
// point the block builder state to the current block
$this->blockBuilder->initialize($id);
// iterate from parent to current
foreach ($types as $type) {
$type->buildBlock($this->blockBuilder, $resolvedOptions);
$this->registry->buildBlock($type->getName(), $this->blockBuilder, $resolvedOptions);
}
$this->rawLayout->setProperty($id, RawLayout::RESOLVED_OPTIONS, $resolvedOptions);
} else {
$this->rawLayout->remove($id);
}
return $resolvedOptions;
}
|
[
"protected",
"function",
"setBlockResolvedOptions",
"(",
"$",
"id",
",",
"$",
"blockType",
",",
"$",
"options",
",",
"$",
"types",
")",
"{",
"// resolve options",
"$",
"resolvedOptions",
"=",
"new",
"Options",
"(",
"$",
"this",
"->",
"optionsResolver",
"->",
"resolveOptions",
"(",
"$",
"blockType",
",",
"$",
"options",
")",
")",
";",
"$",
"this",
"->",
"processExpressions",
"(",
"$",
"resolvedOptions",
")",
";",
"$",
"resolvedOptions",
"=",
"$",
"this",
"->",
"resolveValueBags",
"(",
"$",
"resolvedOptions",
")",
";",
"if",
"(",
"$",
"resolvedOptions",
"->",
"get",
"(",
"'visible'",
",",
"false",
")",
"!==",
"false",
")",
"{",
"// point the block builder state to the current block",
"$",
"this",
"->",
"blockBuilder",
"->",
"initialize",
"(",
"$",
"id",
")",
";",
"// iterate from parent to current",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"$",
"type",
"->",
"buildBlock",
"(",
"$",
"this",
"->",
"blockBuilder",
",",
"$",
"resolvedOptions",
")",
";",
"$",
"this",
"->",
"registry",
"->",
"buildBlock",
"(",
"$",
"type",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"blockBuilder",
",",
"$",
"resolvedOptions",
")",
";",
"}",
"$",
"this",
"->",
"rawLayout",
"->",
"setProperty",
"(",
"$",
"id",
",",
"RawLayout",
"::",
"RESOLVED_OPTIONS",
",",
"$",
"resolvedOptions",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"rawLayout",
"->",
"remove",
"(",
"$",
"id",
")",
";",
"}",
"return",
"$",
"resolvedOptions",
";",
"}"
] |
Setting resolved options for block
@param string $id
@param string $blockType
@param array $options
@param array $types
@return Options
|
[
"Setting",
"resolved",
"options",
"for",
"block"
] |
682a96672393d81c63728e47c4a4c3618c515be0
|
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/BlockFactory.php#L354-L376
|
20,753 |
flipboxfactory/craft-psr3
|
src/Logger.php
|
Logger.log
|
public function log($level, $message, array $context = [])
{
// Resolve category from 'context'
$category = ArrayHelper::remove($context, 'category', $this->category);
// Resolve level
$level = ArrayHelper::getValue($this->map, $level, $this->level);
$this->logger->log(
$this->interpolate($message, $context),
$level,
$category
);
}
|
php
|
public function log($level, $message, array $context = [])
{
// Resolve category from 'context'
$category = ArrayHelper::remove($context, 'category', $this->category);
// Resolve level
$level = ArrayHelper::getValue($this->map, $level, $this->level);
$this->logger->log(
$this->interpolate($message, $context),
$level,
$category
);
}
|
[
"public",
"function",
"log",
"(",
"$",
"level",
",",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"// Resolve category from 'context'",
"$",
"category",
"=",
"ArrayHelper",
"::",
"remove",
"(",
"$",
"context",
",",
"'category'",
",",
"$",
"this",
"->",
"category",
")",
";",
"// Resolve level",
"$",
"level",
"=",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"this",
"->",
"map",
",",
"$",
"level",
",",
"$",
"this",
"->",
"level",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"log",
"(",
"$",
"this",
"->",
"interpolate",
"(",
"$",
"message",
",",
"$",
"context",
")",
",",
"$",
"level",
",",
"$",
"category",
")",
";",
"}"
] |
Log a message, transforming from PSR3 to the closest Yii2.
@inheritdoc
|
[
"Log",
"a",
"message",
"transforming",
"from",
"PSR3",
"to",
"the",
"closest",
"Yii2",
"."
] |
cac258edc823fddd42f18904a94d603d51d80177
|
https://github.com/flipboxfactory/craft-psr3/blob/cac258edc823fddd42f18904a94d603d51d80177/src/Logger.php#L76-L89
|
20,754 |
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/common_sql_writer.php
|
ezcDbSchemaCommonSqlWriter.generateSchemaAsSql
|
protected function generateSchemaAsSql()
{
$prefix = ezcDbSchema::$options->tableNamePrefix;
foreach ( $this->schema as $tableName => $tableDefinition )
{
$this->generateDropTableSql( $prefix . $tableName );
$this->generateCreateTableSql( $prefix . $tableName, $tableDefinition );
}
}
|
php
|
protected function generateSchemaAsSql()
{
$prefix = ezcDbSchema::$options->tableNamePrefix;
foreach ( $this->schema as $tableName => $tableDefinition )
{
$this->generateDropTableSql( $prefix . $tableName );
$this->generateCreateTableSql( $prefix . $tableName, $tableDefinition );
}
}
|
[
"protected",
"function",
"generateSchemaAsSql",
"(",
")",
"{",
"$",
"prefix",
"=",
"ezcDbSchema",
"::",
"$",
"options",
"->",
"tableNamePrefix",
";",
"foreach",
"(",
"$",
"this",
"->",
"schema",
"as",
"$",
"tableName",
"=>",
"$",
"tableDefinition",
")",
"{",
"$",
"this",
"->",
"generateDropTableSql",
"(",
"$",
"prefix",
".",
"$",
"tableName",
")",
";",
"$",
"this",
"->",
"generateCreateTableSql",
"(",
"$",
"prefix",
".",
"$",
"tableName",
",",
"$",
"tableDefinition",
")",
";",
"}",
"}"
] |
Creates SQL DDL statements from a schema definitin.
Loops over the tables in the schema definition in $this->schema and
creates SQL SSL statements for this which it stores internally into the
$this->queries array.
|
[
"Creates",
"SQL",
"DDL",
"statements",
"from",
"a",
"schema",
"definitin",
"."
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/common_sql_writer.php#L116-L124
|
20,755 |
jim-moser/zf2-validators-empty-or
|
src/OrChain.php
|
OrChain.getValidators
|
public function getValidators()
{
$allValidatorData = $this->validators->
toArray(PriorityQueue::EXTR_DATA);
foreach ($allValidatorData as $key => $validatorData) {
$allValidatorData[$key] = $validatorData['instance'];
}
return $allValidatorData;
}
|
php
|
public function getValidators()
{
$allValidatorData = $this->validators->
toArray(PriorityQueue::EXTR_DATA);
foreach ($allValidatorData as $key => $validatorData) {
$allValidatorData[$key] = $validatorData['instance'];
}
return $allValidatorData;
}
|
[
"public",
"function",
"getValidators",
"(",
")",
"{",
"$",
"allValidatorData",
"=",
"$",
"this",
"->",
"validators",
"->",
"toArray",
"(",
"PriorityQueue",
"::",
"EXTR_DATA",
")",
";",
"foreach",
"(",
"$",
"allValidatorData",
"as",
"$",
"key",
"=>",
"$",
"validatorData",
")",
"{",
"$",
"allValidatorData",
"[",
"$",
"key",
"]",
"=",
"$",
"validatorData",
"[",
"'instance'",
"]",
";",
"}",
"return",
"$",
"allValidatorData",
";",
"}"
] |
Returns array of all validators.
@return PriorityQueue
|
[
"Returns",
"array",
"of",
"all",
"validators",
"."
] |
12f799e18ff59986c23ff3f934702834046438f2
|
https://github.com/jim-moser/zf2-validators-empty-or/blob/12f799e18ff59986c23ff3f934702834046438f2/src/OrChain.php#L376-L384
|
20,756 |
activecollab/controller
|
src/ResultEncoder/ResultEncoder.php
|
ResultEncoder.encodeArray
|
protected function encodeArray(array $action_result, ResponseInterface $response, $status = 200)
{
return $response->write(json_encode($action_result))->withStatus($status);
}
|
php
|
protected function encodeArray(array $action_result, ResponseInterface $response, $status = 200)
{
return $response->write(json_encode($action_result))->withStatus($status);
}
|
[
"protected",
"function",
"encodeArray",
"(",
"array",
"$",
"action_result",
",",
"ResponseInterface",
"$",
"response",
",",
"$",
"status",
"=",
"200",
")",
"{",
"return",
"$",
"response",
"->",
"write",
"(",
"json_encode",
"(",
"$",
"action_result",
")",
")",
"->",
"withStatus",
"(",
"$",
"status",
")",
";",
"}"
] |
Encode regular array response, with status 200.
@param array $action_result
@param ResponseInterface $response
@param int $status
@return ResponseInterface
|
[
"Encode",
"regular",
"array",
"response",
"with",
"status",
"200",
"."
] |
51d24f3f203f7f5ae56edde2e35b5ef2d9293caa
|
https://github.com/activecollab/controller/blob/51d24f3f203f7f5ae56edde2e35b5ef2d9293caa/src/ResultEncoder/ResultEncoder.php#L107-L110
|
20,757 |
activecollab/controller
|
src/ResultEncoder/ResultEncoder.php
|
ResultEncoder.encodeScalar
|
protected function encodeScalar($action_result, ResponseInterface $response, $status = 200)
{
return $response->write(json_encode($action_result))->withStatus($status);
}
|
php
|
protected function encodeScalar($action_result, ResponseInterface $response, $status = 200)
{
return $response->write(json_encode($action_result))->withStatus($status);
}
|
[
"protected",
"function",
"encodeScalar",
"(",
"$",
"action_result",
",",
"ResponseInterface",
"$",
"response",
",",
"$",
"status",
"=",
"200",
")",
"{",
"return",
"$",
"response",
"->",
"write",
"(",
"json_encode",
"(",
"$",
"action_result",
")",
")",
"->",
"withStatus",
"(",
"$",
"status",
")",
";",
"}"
] |
Encode scalar value, with status 200.
@param mixed $action_result
@param ResponseInterface $response
@param int $status
@return ResponseInterface
|
[
"Encode",
"scalar",
"value",
"with",
"status",
"200",
"."
] |
51d24f3f203f7f5ae56edde2e35b5ef2d9293caa
|
https://github.com/activecollab/controller/blob/51d24f3f203f7f5ae56edde2e35b5ef2d9293caa/src/ResultEncoder/ResultEncoder.php#L120-L123
|
20,758 |
activecollab/controller
|
src/ResultEncoder/ResultEncoder.php
|
ResultEncoder.encodeStatus
|
protected function encodeStatus(StatusResponse $action_result, ResponseInterface $response)
{
$response = $response->withStatus($action_result->getHttpCode(), $action_result->getMessage());
if ($action_result->getHttpCode() >= 400) {
$response = $response->write(json_encode(['message' => $action_result->getMessage()]));
}
return $response;
}
|
php
|
protected function encodeStatus(StatusResponse $action_result, ResponseInterface $response)
{
$response = $response->withStatus($action_result->getHttpCode(), $action_result->getMessage());
if ($action_result->getHttpCode() >= 400) {
$response = $response->write(json_encode(['message' => $action_result->getMessage()]));
}
return $response;
}
|
[
"protected",
"function",
"encodeStatus",
"(",
"StatusResponse",
"$",
"action_result",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"response",
"=",
"$",
"response",
"->",
"withStatus",
"(",
"$",
"action_result",
"->",
"getHttpCode",
"(",
")",
",",
"$",
"action_result",
"->",
"getMessage",
"(",
")",
")",
";",
"if",
"(",
"$",
"action_result",
"->",
"getHttpCode",
"(",
")",
">=",
"400",
")",
"{",
"$",
"response",
"=",
"$",
"response",
"->",
"write",
"(",
"json_encode",
"(",
"[",
"'message'",
"=>",
"$",
"action_result",
"->",
"getMessage",
"(",
")",
"]",
")",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] |
Encode and return status response.
@param StatusResponse $action_result
@param ResponseInterface $response
@return ResponseInterface
|
[
"Encode",
"and",
"return",
"status",
"response",
"."
] |
51d24f3f203f7f5ae56edde2e35b5ef2d9293caa
|
https://github.com/activecollab/controller/blob/51d24f3f203f7f5ae56edde2e35b5ef2d9293caa/src/ResultEncoder/ResultEncoder.php#L132-L141
|
20,759 |
activecollab/controller
|
src/ResultEncoder/ResultEncoder.php
|
ResultEncoder.encodeException
|
protected function encodeException($exception, ResponseInterface $response, $status = 500)
{
$error = ['message' => $exception->getMessage(), 'type' => get_class($exception)];
if ($this->getDisplayErrorDetails()) {
$error['exception'] = [];
do {
$error['exception'][] = [
'type' => get_class($exception),
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'trace' => explode("\n", $exception->getTraceAsString()),
];
} while ($exception = $exception->getPrevious());
}
return $response->write(json_encode($error))->withStatus($status);
}
|
php
|
protected function encodeException($exception, ResponseInterface $response, $status = 500)
{
$error = ['message' => $exception->getMessage(), 'type' => get_class($exception)];
if ($this->getDisplayErrorDetails()) {
$error['exception'] = [];
do {
$error['exception'][] = [
'type' => get_class($exception),
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'trace' => explode("\n", $exception->getTraceAsString()),
];
} while ($exception = $exception->getPrevious());
}
return $response->write(json_encode($error))->withStatus($status);
}
|
[
"protected",
"function",
"encodeException",
"(",
"$",
"exception",
",",
"ResponseInterface",
"$",
"response",
",",
"$",
"status",
"=",
"500",
")",
"{",
"$",
"error",
"=",
"[",
"'message'",
"=>",
"$",
"exception",
"->",
"getMessage",
"(",
")",
",",
"'type'",
"=>",
"get_class",
"(",
"$",
"exception",
")",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"getDisplayErrorDetails",
"(",
")",
")",
"{",
"$",
"error",
"[",
"'exception'",
"]",
"=",
"[",
"]",
";",
"do",
"{",
"$",
"error",
"[",
"'exception'",
"]",
"[",
"]",
"=",
"[",
"'type'",
"=>",
"get_class",
"(",
"$",
"exception",
")",
",",
"'code'",
"=>",
"$",
"exception",
"->",
"getCode",
"(",
")",
",",
"'message'",
"=>",
"$",
"exception",
"->",
"getMessage",
"(",
")",
",",
"'file'",
"=>",
"$",
"exception",
"->",
"getFile",
"(",
")",
",",
"'line'",
"=>",
"$",
"exception",
"->",
"getLine",
"(",
")",
",",
"'trace'",
"=>",
"explode",
"(",
"\"\\n\"",
",",
"$",
"exception",
"->",
"getTraceAsString",
"(",
")",
")",
",",
"]",
";",
"}",
"while",
"(",
"$",
"exception",
"=",
"$",
"exception",
"->",
"getPrevious",
"(",
")",
")",
";",
"}",
"return",
"$",
"response",
"->",
"write",
"(",
"json_encode",
"(",
"$",
"error",
")",
")",
"->",
"withStatus",
"(",
"$",
"status",
")",
";",
"}"
] |
Encode and return exception.
@param Throwable|Exception $exception
@param ResponseInterface $response
@param int $status
@return ResponseInterface
|
[
"Encode",
"and",
"return",
"exception",
"."
] |
51d24f3f203f7f5ae56edde2e35b5ef2d9293caa
|
https://github.com/activecollab/controller/blob/51d24f3f203f7f5ae56edde2e35b5ef2d9293caa/src/ResultEncoder/ResultEncoder.php#L151-L171
|
20,760 |
zicht/z
|
src/Zicht/Tool/Application.php
|
Application.renderException
|
public function renderException($e, $output)
{
if ($output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) {
parent::renderException($e, $output);
} else {
/** @var $ancestry \Exception[] */
$ancestry = array();
$maxLength = 0;
do {
$ancestry[] = $e;
$maxLength = max($maxLength, strlen(get_class($e)));
$last = $e;
} while ($e = $e->getPrevious());
if ($last instanceof VerboseException) {
$last->output($output);
} else {
$depth = 0;
foreach ($ancestry as $e) {
$output->writeln(
sprintf(
'%s%-40s %s',
($depth > 0 ? str_repeat(' ', $depth - 1) . '-> ' : ''),
'<fg=red;options=bold>' . $e->getMessage() . '</fg=red;options=bold>',
$depth == count($ancestry) - 1 ? str_pad('[' . get_class($e) . ']', $maxLength + 15, ' ') : ''
)
);
$depth++;
}
}
}
$output->writeln('[' . join('::', Debug::$scope) . ']');
}
|
php
|
public function renderException($e, $output)
{
if ($output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) {
parent::renderException($e, $output);
} else {
/** @var $ancestry \Exception[] */
$ancestry = array();
$maxLength = 0;
do {
$ancestry[] = $e;
$maxLength = max($maxLength, strlen(get_class($e)));
$last = $e;
} while ($e = $e->getPrevious());
if ($last instanceof VerboseException) {
$last->output($output);
} else {
$depth = 0;
foreach ($ancestry as $e) {
$output->writeln(
sprintf(
'%s%-40s %s',
($depth > 0 ? str_repeat(' ', $depth - 1) . '-> ' : ''),
'<fg=red;options=bold>' . $e->getMessage() . '</fg=red;options=bold>',
$depth == count($ancestry) - 1 ? str_pad('[' . get_class($e) . ']', $maxLength + 15, ' ') : ''
)
);
$depth++;
}
}
}
$output->writeln('[' . join('::', Debug::$scope) . ']');
}
|
[
"public",
"function",
"renderException",
"(",
"$",
"e",
",",
"$",
"output",
")",
"{",
"if",
"(",
"$",
"output",
"->",
"getVerbosity",
"(",
")",
">",
"OutputInterface",
"::",
"VERBOSITY_VERBOSE",
")",
"{",
"parent",
"::",
"renderException",
"(",
"$",
"e",
",",
"$",
"output",
")",
";",
"}",
"else",
"{",
"/** @var $ancestry \\Exception[] */",
"$",
"ancestry",
"=",
"array",
"(",
")",
";",
"$",
"maxLength",
"=",
"0",
";",
"do",
"{",
"$",
"ancestry",
"[",
"]",
"=",
"$",
"e",
";",
"$",
"maxLength",
"=",
"max",
"(",
"$",
"maxLength",
",",
"strlen",
"(",
"get_class",
"(",
"$",
"e",
")",
")",
")",
";",
"$",
"last",
"=",
"$",
"e",
";",
"}",
"while",
"(",
"$",
"e",
"=",
"$",
"e",
"->",
"getPrevious",
"(",
")",
")",
";",
"if",
"(",
"$",
"last",
"instanceof",
"VerboseException",
")",
"{",
"$",
"last",
"->",
"output",
"(",
"$",
"output",
")",
";",
"}",
"else",
"{",
"$",
"depth",
"=",
"0",
";",
"foreach",
"(",
"$",
"ancestry",
"as",
"$",
"e",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'%s%-40s %s'",
",",
"(",
"$",
"depth",
">",
"0",
"?",
"str_repeat",
"(",
"' '",
",",
"$",
"depth",
"-",
"1",
")",
".",
"'-> '",
":",
"''",
")",
",",
"'<fg=red;options=bold>'",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"'</fg=red;options=bold>'",
",",
"$",
"depth",
"==",
"count",
"(",
"$",
"ancestry",
")",
"-",
"1",
"?",
"str_pad",
"(",
"'['",
".",
"get_class",
"(",
"$",
"e",
")",
".",
"']'",
",",
"$",
"maxLength",
"+",
"15",
",",
"' '",
")",
":",
"''",
")",
")",
";",
"$",
"depth",
"++",
";",
"}",
"}",
"}",
"$",
"output",
"->",
"writeln",
"(",
"'['",
".",
"join",
"(",
"'::'",
",",
"Debug",
"::",
"$",
"scope",
")",
".",
"']'",
")",
";",
"}"
] |
Custom exception rendering, renders only the exception types and messages, hierarchically, but with regular
formatting if verbosity is higher.
@param \Exception $e
@param \Symfony\Component\Console\Output\OutputInterface $output
@return void
|
[
"Custom",
"exception",
"rendering",
"renders",
"only",
"the",
"exception",
"types",
"and",
"messages",
"hierarchically",
"but",
"with",
"regular",
"formatting",
"if",
"verbosity",
"is",
"higher",
"."
] |
6a1731dad20b018555a96b726a61d4bf8ec8c886
|
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Application.php#L66-L98
|
20,761 |
zicht/z
|
src/Zicht/Tool/Application.php
|
Application.getContainer
|
public function getContainer($forceRecompile = false)
{
if (null === $this->container) {
$config = $this->loader->processConfiguration();
$config['z']['sources'] = $this->loader->getSourceFiles();
$config['z']['cache_file'] = sys_get_temp_dir() . '/z_' . $this->getCacheKey($config) . '.php';
if ($forceRecompile && is_file($config['z']['cache_file'])) {
unlink($config['z']['cache_file']);
clearstatcache();
}
$compiler = new ContainerCompiler(
$config,
$this->loader->getPlugins(),
$config['z']['cache_file']
);
$this->container = $compiler->getContainer();
}
return $this->container;
}
|
php
|
public function getContainer($forceRecompile = false)
{
if (null === $this->container) {
$config = $this->loader->processConfiguration();
$config['z']['sources'] = $this->loader->getSourceFiles();
$config['z']['cache_file'] = sys_get_temp_dir() . '/z_' . $this->getCacheKey($config) . '.php';
if ($forceRecompile && is_file($config['z']['cache_file'])) {
unlink($config['z']['cache_file']);
clearstatcache();
}
$compiler = new ContainerCompiler(
$config,
$this->loader->getPlugins(),
$config['z']['cache_file']
);
$this->container = $compiler->getContainer();
}
return $this->container;
}
|
[
"public",
"function",
"getContainer",
"(",
"$",
"forceRecompile",
"=",
"false",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"container",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"loader",
"->",
"processConfiguration",
"(",
")",
";",
"$",
"config",
"[",
"'z'",
"]",
"[",
"'sources'",
"]",
"=",
"$",
"this",
"->",
"loader",
"->",
"getSourceFiles",
"(",
")",
";",
"$",
"config",
"[",
"'z'",
"]",
"[",
"'cache_file'",
"]",
"=",
"sys_get_temp_dir",
"(",
")",
".",
"'/z_'",
".",
"$",
"this",
"->",
"getCacheKey",
"(",
"$",
"config",
")",
".",
"'.php'",
";",
"if",
"(",
"$",
"forceRecompile",
"&&",
"is_file",
"(",
"$",
"config",
"[",
"'z'",
"]",
"[",
"'cache_file'",
"]",
")",
")",
"{",
"unlink",
"(",
"$",
"config",
"[",
"'z'",
"]",
"[",
"'cache_file'",
"]",
")",
";",
"clearstatcache",
"(",
")",
";",
"}",
"$",
"compiler",
"=",
"new",
"ContainerCompiler",
"(",
"$",
"config",
",",
"$",
"this",
"->",
"loader",
"->",
"getPlugins",
"(",
")",
",",
"$",
"config",
"[",
"'z'",
"]",
"[",
"'cache_file'",
"]",
")",
";",
"$",
"this",
"->",
"container",
"=",
"$",
"compiler",
"->",
"getContainer",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"container",
";",
"}"
] |
Returns the container instance, and initializes it if not yet available.
@param bool $forceRecompile
@return Container
|
[
"Returns",
"the",
"container",
"instance",
"and",
"initializes",
"it",
"if",
"not",
"yet",
"available",
"."
] |
6a1731dad20b018555a96b726a61d4bf8ec8c886
|
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Application.php#L134-L152
|
20,762 |
OKTOTV/OktolabMediaBundle
|
Controller/SeriesController.php
|
SeriesController.newAction
|
public function newAction(Request $request)
{
$series = $this->get('oktolab_media')->createSeries();
$form = $this->createForm(SeriesType::class, $series);
$form->add('submit', SubmitType::class, ['label' => 'oktolab_media.new_series_button', 'attr' => ['class' => 'btn btn-primary']]);
if ($request->getMethod() == "POST") { //sends form
$form->handleRequest($request);
$em = $this->getDoctrine()->getManager();
if ($form->isValid()) { //form is valid, save or preview
if ($form->get('submit')->isClicked()) { //save me
$em->persist($series);
$em->flush();
$this->get('session')->getFlashBag()->add('success', 'oktolab_media.success_create_series');
return $this->redirect($this->generateUrl('oktolab_series_show', ['series' => $series->getUniqId()]));
} else { //???
$this->get('session')->getFlashBag()->add('success', 'oktolab_media.unknown_action_series');
return $this->redirect($this->generateUrl('oktolab_series'));
}
}
$this->get('session')->getFlashBag()->add('error', 'oktolab_media.error_create_series');
}
return ['form' => $form->createView()];
}
|
php
|
public function newAction(Request $request)
{
$series = $this->get('oktolab_media')->createSeries();
$form = $this->createForm(SeriesType::class, $series);
$form->add('submit', SubmitType::class, ['label' => 'oktolab_media.new_series_button', 'attr' => ['class' => 'btn btn-primary']]);
if ($request->getMethod() == "POST") { //sends form
$form->handleRequest($request);
$em = $this->getDoctrine()->getManager();
if ($form->isValid()) { //form is valid, save or preview
if ($form->get('submit')->isClicked()) { //save me
$em->persist($series);
$em->flush();
$this->get('session')->getFlashBag()->add('success', 'oktolab_media.success_create_series');
return $this->redirect($this->generateUrl('oktolab_series_show', ['series' => $series->getUniqId()]));
} else { //???
$this->get('session')->getFlashBag()->add('success', 'oktolab_media.unknown_action_series');
return $this->redirect($this->generateUrl('oktolab_series'));
}
}
$this->get('session')->getFlashBag()->add('error', 'oktolab_media.error_create_series');
}
return ['form' => $form->createView()];
}
|
[
"public",
"function",
"newAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"series",
"=",
"$",
"this",
"->",
"get",
"(",
"'oktolab_media'",
")",
"->",
"createSeries",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"SeriesType",
"::",
"class",
",",
"$",
"series",
")",
";",
"$",
"form",
"->",
"add",
"(",
"'submit'",
",",
"SubmitType",
"::",
"class",
",",
"[",
"'label'",
"=>",
"'oktolab_media.new_series_button'",
",",
"'attr'",
"=>",
"[",
"'class'",
"=>",
"'btn btn-primary'",
"]",
"]",
")",
";",
"if",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
"==",
"\"POST\"",
")",
"{",
"//sends form",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"//form is valid, save or preview",
"if",
"(",
"$",
"form",
"->",
"get",
"(",
"'submit'",
")",
"->",
"isClicked",
"(",
")",
")",
"{",
"//save me",
"$",
"em",
"->",
"persist",
"(",
"$",
"series",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'success'",
",",
"'oktolab_media.success_create_series'",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'oktolab_series_show'",
",",
"[",
"'series'",
"=>",
"$",
"series",
"->",
"getUniqId",
"(",
")",
"]",
")",
")",
";",
"}",
"else",
"{",
"//???",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'success'",
",",
"'oktolab_media.unknown_action_series'",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'oktolab_series'",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'error'",
",",
"'oktolab_media.error_create_series'",
")",
";",
"}",
"return",
"[",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
"]",
";",
"}"
] |
Displays a form to create a new Series entity.
@Route("/new", name="oktolab_series_new")
@Method({"GET", "POST"})
@Template()
|
[
"Displays",
"a",
"form",
"to",
"create",
"a",
"new",
"Series",
"entity",
"."
] |
f9c1eac4f6b19d2ab25288b301dd0d9350478bb3
|
https://github.com/OKTOTV/OktolabMediaBundle/blob/f9c1eac4f6b19d2ab25288b301dd0d9350478bb3/Controller/SeriesController.php#L60-L84
|
20,763 |
OKTOTV/OktolabMediaBundle
|
Controller/SeriesController.php
|
SeriesController.editAction
|
public function editAction(Request $request, $series)
{
$series = $this->get('oktolab_media')->getSeries($series);
$form = $this->createForm(SeriesType::class, $series);
$form->add('submit', SubmitType::class, ['label' => 'oktolab_media.edit_series_button', 'attr' => ['class' => 'btn btn-primary']]);
$form->add('delete', SubmitType::class, ['label' => 'oktolab_media.delete_series_button', 'attr' => ['class' => 'btn btn-danger']]);
if ($request->getMethod() == "POST") { //sends form
$form->handleRequest($request);
$em = $this->getDoctrine()->getManager();
if ($form->isValid() || $form->get('delete')->isClicked()) { //form is valid, save or preview
if ($form->get('submit')->isClicked()) { //save me
$em->persist($series);
$em->flush();
$this->get('session')->getFlashBag()->add('success', 'oktolab_media.success_edit_series');
return $this->redirect($this->generateUrl('oktolab_series_show', ['series' => $series->getUniqID()]));
} elseif ($form->get('delete')->isClicked()) {
$this->get('oktolab_media_helper')->deleteSeries($series);
$this->get('session')->getFlashBag()->add('success', 'oktolab_media.success_delete_series');
return $this->redirect($this->generateUrl('oktolab_series'));
} else { //???
$this->get('session')->getFlashBag()->add('success', 'oktolab_media.unknown_action_series');
return $this->redirect($this->generateUrl('oktolab_series_show', ['series' => $series->getUniqID()]));
}
}
$this->get('session')->getFlashBag()->add('error', 'oktolab_media.error_edit_series');
}
return ['form' => $form->createView()];
}
|
php
|
public function editAction(Request $request, $series)
{
$series = $this->get('oktolab_media')->getSeries($series);
$form = $this->createForm(SeriesType::class, $series);
$form->add('submit', SubmitType::class, ['label' => 'oktolab_media.edit_series_button', 'attr' => ['class' => 'btn btn-primary']]);
$form->add('delete', SubmitType::class, ['label' => 'oktolab_media.delete_series_button', 'attr' => ['class' => 'btn btn-danger']]);
if ($request->getMethod() == "POST") { //sends form
$form->handleRequest($request);
$em = $this->getDoctrine()->getManager();
if ($form->isValid() || $form->get('delete')->isClicked()) { //form is valid, save or preview
if ($form->get('submit')->isClicked()) { //save me
$em->persist($series);
$em->flush();
$this->get('session')->getFlashBag()->add('success', 'oktolab_media.success_edit_series');
return $this->redirect($this->generateUrl('oktolab_series_show', ['series' => $series->getUniqID()]));
} elseif ($form->get('delete')->isClicked()) {
$this->get('oktolab_media_helper')->deleteSeries($series);
$this->get('session')->getFlashBag()->add('success', 'oktolab_media.success_delete_series');
return $this->redirect($this->generateUrl('oktolab_series'));
} else { //???
$this->get('session')->getFlashBag()->add('success', 'oktolab_media.unknown_action_series');
return $this->redirect($this->generateUrl('oktolab_series_show', ['series' => $series->getUniqID()]));
}
}
$this->get('session')->getFlashBag()->add('error', 'oktolab_media.error_edit_series');
}
return ['form' => $form->createView()];
}
|
[
"public",
"function",
"editAction",
"(",
"Request",
"$",
"request",
",",
"$",
"series",
")",
"{",
"$",
"series",
"=",
"$",
"this",
"->",
"get",
"(",
"'oktolab_media'",
")",
"->",
"getSeries",
"(",
"$",
"series",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"SeriesType",
"::",
"class",
",",
"$",
"series",
")",
";",
"$",
"form",
"->",
"add",
"(",
"'submit'",
",",
"SubmitType",
"::",
"class",
",",
"[",
"'label'",
"=>",
"'oktolab_media.edit_series_button'",
",",
"'attr'",
"=>",
"[",
"'class'",
"=>",
"'btn btn-primary'",
"]",
"]",
")",
";",
"$",
"form",
"->",
"add",
"(",
"'delete'",
",",
"SubmitType",
"::",
"class",
",",
"[",
"'label'",
"=>",
"'oktolab_media.delete_series_button'",
",",
"'attr'",
"=>",
"[",
"'class'",
"=>",
"'btn btn-danger'",
"]",
"]",
")",
";",
"if",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
"==",
"\"POST\"",
")",
"{",
"//sends form",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isValid",
"(",
")",
"||",
"$",
"form",
"->",
"get",
"(",
"'delete'",
")",
"->",
"isClicked",
"(",
")",
")",
"{",
"//form is valid, save or preview",
"if",
"(",
"$",
"form",
"->",
"get",
"(",
"'submit'",
")",
"->",
"isClicked",
"(",
")",
")",
"{",
"//save me",
"$",
"em",
"->",
"persist",
"(",
"$",
"series",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'success'",
",",
"'oktolab_media.success_edit_series'",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'oktolab_series_show'",
",",
"[",
"'series'",
"=>",
"$",
"series",
"->",
"getUniqID",
"(",
")",
"]",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"form",
"->",
"get",
"(",
"'delete'",
")",
"->",
"isClicked",
"(",
")",
")",
"{",
"$",
"this",
"->",
"get",
"(",
"'oktolab_media_helper'",
")",
"->",
"deleteSeries",
"(",
"$",
"series",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'success'",
",",
"'oktolab_media.success_delete_series'",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'oktolab_series'",
")",
")",
";",
"}",
"else",
"{",
"//???",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'success'",
",",
"'oktolab_media.unknown_action_series'",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'oktolab_series_show'",
",",
"[",
"'series'",
"=>",
"$",
"series",
"->",
"getUniqID",
"(",
")",
"]",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'error'",
",",
"'oktolab_media.error_edit_series'",
")",
";",
"}",
"return",
"[",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
"]",
";",
"}"
] |
Displays a form to edit an existing Series entity.
@ ParamConverter("series", class="OktolabMediaBundle:Series")
@Method({"GET", "POST"})
@Template()
|
[
"Displays",
"a",
"form",
"to",
"edit",
"an",
"existing",
"Series",
"entity",
"."
] |
f9c1eac4f6b19d2ab25288b301dd0d9350478bb3
|
https://github.com/OKTOTV/OktolabMediaBundle/blob/f9c1eac4f6b19d2ab25288b301dd0d9350478bb3/Controller/SeriesController.php#L114-L143
|
20,764 |
richardhj/contao-widget-upload-preview
|
src/FormUploadPreview.php
|
FormUploadPreview.validate
|
public function validate()
{
// Delete the file when requested
if (true === $this->enableReset && $this->getPost($this->strName.'_reset')) {
if (null !== ($fileModel = FilesModel::findByPk($this->varValue))) {
$file = new File($fileModel->path);
$file->delete();
}
unset($_FILES[$this->strName]);
return;
}
// Handle file upload
parent::validate();
// Set the image as varValue
$file = $_SESSION['FILES'][$this->strName];
if (true === $file['uploaded']) {
$this->varValue = StringUtil::uuidToBin($file['uuid']);
} else {
$this->blnSubmitInput = false;
}
}
|
php
|
public function validate()
{
// Delete the file when requested
if (true === $this->enableReset && $this->getPost($this->strName.'_reset')) {
if (null !== ($fileModel = FilesModel::findByPk($this->varValue))) {
$file = new File($fileModel->path);
$file->delete();
}
unset($_FILES[$this->strName]);
return;
}
// Handle file upload
parent::validate();
// Set the image as varValue
$file = $_SESSION['FILES'][$this->strName];
if (true === $file['uploaded']) {
$this->varValue = StringUtil::uuidToBin($file['uuid']);
} else {
$this->blnSubmitInput = false;
}
}
|
[
"public",
"function",
"validate",
"(",
")",
"{",
"// Delete the file when requested",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"enableReset",
"&&",
"$",
"this",
"->",
"getPost",
"(",
"$",
"this",
"->",
"strName",
".",
"'_reset'",
")",
")",
"{",
"if",
"(",
"null",
"!==",
"(",
"$",
"fileModel",
"=",
"FilesModel",
"::",
"findByPk",
"(",
"$",
"this",
"->",
"varValue",
")",
")",
")",
"{",
"$",
"file",
"=",
"new",
"File",
"(",
"$",
"fileModel",
"->",
"path",
")",
";",
"$",
"file",
"->",
"delete",
"(",
")",
";",
"}",
"unset",
"(",
"$",
"_FILES",
"[",
"$",
"this",
"->",
"strName",
"]",
")",
";",
"return",
";",
"}",
"// Handle file upload",
"parent",
"::",
"validate",
"(",
")",
";",
"// Set the image as varValue",
"$",
"file",
"=",
"$",
"_SESSION",
"[",
"'FILES'",
"]",
"[",
"$",
"this",
"->",
"strName",
"]",
";",
"if",
"(",
"true",
"===",
"$",
"file",
"[",
"'uploaded'",
"]",
")",
"{",
"$",
"this",
"->",
"varValue",
"=",
"StringUtil",
"::",
"uuidToBin",
"(",
"$",
"file",
"[",
"'uuid'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"blnSubmitInput",
"=",
"false",
";",
"}",
"}"
] |
Validate the user input and set the value.
@throws \Exception
|
[
"Validate",
"the",
"user",
"input",
"and",
"set",
"the",
"value",
"."
] |
5de3488ad55c69cd311ff26e749a74097b7a9db1
|
https://github.com/richardhj/contao-widget-upload-preview/blob/5de3488ad55c69cd311ff26e749a74097b7a9db1/src/FormUploadPreview.php#L133-L157
|
20,765 |
david-mk/mail-map
|
src/MailMap/MailFactory.php
|
MailFactory.create
|
public function create($uid, $stream)
{
return new $this->mailClass(
$uid,
$stream,
$this->parseMailHeader($stream, $uid),
$this->parseHeaders($stream, $uid),
$this->parseBody($stream, $uid)
);
}
|
php
|
public function create($uid, $stream)
{
return new $this->mailClass(
$uid,
$stream,
$this->parseMailHeader($stream, $uid),
$this->parseHeaders($stream, $uid),
$this->parseBody($stream, $uid)
);
}
|
[
"public",
"function",
"create",
"(",
"$",
"uid",
",",
"$",
"stream",
")",
"{",
"return",
"new",
"$",
"this",
"->",
"mailClass",
"(",
"$",
"uid",
",",
"$",
"stream",
",",
"$",
"this",
"->",
"parseMailHeader",
"(",
"$",
"stream",
",",
"$",
"uid",
")",
",",
"$",
"this",
"->",
"parseHeaders",
"(",
"$",
"stream",
",",
"$",
"uid",
")",
",",
"$",
"this",
"->",
"parseBody",
"(",
"$",
"stream",
",",
"$",
"uid",
")",
")",
";",
"}"
] |
Create new mail from uid
@param int $uid
@param resource $stream
@return \MailMap\Contracts\Mail
|
[
"Create",
"new",
"mail",
"from",
"uid"
] |
4eea346ece9fa35c0d309b5a909f657ad83e1e6a
|
https://github.com/david-mk/mail-map/blob/4eea346ece9fa35c0d309b5a909f657ad83e1e6a/src/MailMap/MailFactory.php#L65-L74
|
20,766 |
david-mk/mail-map
|
src/MailMap/MailFactory.php
|
MailFactory.parseMailHeader
|
protected function parseMailHeader($stream, $uid)
{
$header = imap_headerinfo($stream, imap_msgno($stream, $uid));
return [
'msgNo' => (int) $header->Msgno,
'subject' => $this->parseSubject($header->subject),
'date' => $header->udate,
'to' => isset($header->to)
? $this->parseAddress($header->to) : null,
'cc' => isset($header->cc)
? $this->parseAddress($header->cc) : null,
'bcc' => isset($header->bcc)
? $this->parseAddress($header->bcc) : null,
'sender' => isset($header->sender)
? $this->parseAddress($header->sender) : null,
'from' => isset($header->from)
? $this->parseAddress($header->from) : null,
'replyTo' => isset($header->reply_to)
? $this->parseAddress($header->reply_to) : null,
'recent' => $this->parseFlag('R', $header->Recent),
'unseen' => $this->parseFlag('U', $header->Unseen),
'flagged' => $this->parseFlag('F', $header->Flagged),
'answered' => $this->parseFlag('A', $header->Answered),
'deleted' => $this->parseFlag('D', $header->Deleted),
'draft' => $this->parseFlag('X', $header->Draft)
];
}
|
php
|
protected function parseMailHeader($stream, $uid)
{
$header = imap_headerinfo($stream, imap_msgno($stream, $uid));
return [
'msgNo' => (int) $header->Msgno,
'subject' => $this->parseSubject($header->subject),
'date' => $header->udate,
'to' => isset($header->to)
? $this->parseAddress($header->to) : null,
'cc' => isset($header->cc)
? $this->parseAddress($header->cc) : null,
'bcc' => isset($header->bcc)
? $this->parseAddress($header->bcc) : null,
'sender' => isset($header->sender)
? $this->parseAddress($header->sender) : null,
'from' => isset($header->from)
? $this->parseAddress($header->from) : null,
'replyTo' => isset($header->reply_to)
? $this->parseAddress($header->reply_to) : null,
'recent' => $this->parseFlag('R', $header->Recent),
'unseen' => $this->parseFlag('U', $header->Unseen),
'flagged' => $this->parseFlag('F', $header->Flagged),
'answered' => $this->parseFlag('A', $header->Answered),
'deleted' => $this->parseFlag('D', $header->Deleted),
'draft' => $this->parseFlag('X', $header->Draft)
];
}
|
[
"protected",
"function",
"parseMailHeader",
"(",
"$",
"stream",
",",
"$",
"uid",
")",
"{",
"$",
"header",
"=",
"imap_headerinfo",
"(",
"$",
"stream",
",",
"imap_msgno",
"(",
"$",
"stream",
",",
"$",
"uid",
")",
")",
";",
"return",
"[",
"'msgNo'",
"=>",
"(",
"int",
")",
"$",
"header",
"->",
"Msgno",
",",
"'subject'",
"=>",
"$",
"this",
"->",
"parseSubject",
"(",
"$",
"header",
"->",
"subject",
")",
",",
"'date'",
"=>",
"$",
"header",
"->",
"udate",
",",
"'to'",
"=>",
"isset",
"(",
"$",
"header",
"->",
"to",
")",
"?",
"$",
"this",
"->",
"parseAddress",
"(",
"$",
"header",
"->",
"to",
")",
":",
"null",
",",
"'cc'",
"=>",
"isset",
"(",
"$",
"header",
"->",
"cc",
")",
"?",
"$",
"this",
"->",
"parseAddress",
"(",
"$",
"header",
"->",
"cc",
")",
":",
"null",
",",
"'bcc'",
"=>",
"isset",
"(",
"$",
"header",
"->",
"bcc",
")",
"?",
"$",
"this",
"->",
"parseAddress",
"(",
"$",
"header",
"->",
"bcc",
")",
":",
"null",
",",
"'sender'",
"=>",
"isset",
"(",
"$",
"header",
"->",
"sender",
")",
"?",
"$",
"this",
"->",
"parseAddress",
"(",
"$",
"header",
"->",
"sender",
")",
":",
"null",
",",
"'from'",
"=>",
"isset",
"(",
"$",
"header",
"->",
"from",
")",
"?",
"$",
"this",
"->",
"parseAddress",
"(",
"$",
"header",
"->",
"from",
")",
":",
"null",
",",
"'replyTo'",
"=>",
"isset",
"(",
"$",
"header",
"->",
"reply_to",
")",
"?",
"$",
"this",
"->",
"parseAddress",
"(",
"$",
"header",
"->",
"reply_to",
")",
":",
"null",
",",
"'recent'",
"=>",
"$",
"this",
"->",
"parseFlag",
"(",
"'R'",
",",
"$",
"header",
"->",
"Recent",
")",
",",
"'unseen'",
"=>",
"$",
"this",
"->",
"parseFlag",
"(",
"'U'",
",",
"$",
"header",
"->",
"Unseen",
")",
",",
"'flagged'",
"=>",
"$",
"this",
"->",
"parseFlag",
"(",
"'F'",
",",
"$",
"header",
"->",
"Flagged",
")",
",",
"'answered'",
"=>",
"$",
"this",
"->",
"parseFlag",
"(",
"'A'",
",",
"$",
"header",
"->",
"Answered",
")",
",",
"'deleted'",
"=>",
"$",
"this",
"->",
"parseFlag",
"(",
"'D'",
",",
"$",
"header",
"->",
"Deleted",
")",
",",
"'draft'",
"=>",
"$",
"this",
"->",
"parseFlag",
"(",
"'X'",
",",
"$",
"header",
"->",
"Draft",
")",
"]",
";",
"}"
] |
Parse the mail header
@param resource $stream
@param int $uid
@return array
|
[
"Parse",
"the",
"mail",
"header"
] |
4eea346ece9fa35c0d309b5a909f657ad83e1e6a
|
https://github.com/david-mk/mail-map/blob/4eea346ece9fa35c0d309b5a909f657ad83e1e6a/src/MailMap/MailFactory.php#L83-L110
|
20,767 |
david-mk/mail-map
|
src/MailMap/MailFactory.php
|
MailFactory.parseAddress
|
protected function parseAddress(array $addresses)
{
return array_map(function ($address) {
return (object) [
'address' => $address->mailbox.'@'.$address->host,
'domain' => $address->host,
'name' => isset($address->personal)
? static::convertBodyEncoding($address->personal)
: null
];
}, array_filter($addresses, function ($address) {
return property_exists($address, 'mailbox') && strtolower($address->mailbox) !== 'undisclosed-recipients';
}));
}
|
php
|
protected function parseAddress(array $addresses)
{
return array_map(function ($address) {
return (object) [
'address' => $address->mailbox.'@'.$address->host,
'domain' => $address->host,
'name' => isset($address->personal)
? static::convertBodyEncoding($address->personal)
: null
];
}, array_filter($addresses, function ($address) {
return property_exists($address, 'mailbox') && strtolower($address->mailbox) !== 'undisclosed-recipients';
}));
}
|
[
"protected",
"function",
"parseAddress",
"(",
"array",
"$",
"addresses",
")",
"{",
"return",
"array_map",
"(",
"function",
"(",
"$",
"address",
")",
"{",
"return",
"(",
"object",
")",
"[",
"'address'",
"=>",
"$",
"address",
"->",
"mailbox",
".",
"'@'",
".",
"$",
"address",
"->",
"host",
",",
"'domain'",
"=>",
"$",
"address",
"->",
"host",
",",
"'name'",
"=>",
"isset",
"(",
"$",
"address",
"->",
"personal",
")",
"?",
"static",
"::",
"convertBodyEncoding",
"(",
"$",
"address",
"->",
"personal",
")",
":",
"null",
"]",
";",
"}",
",",
"array_filter",
"(",
"$",
"addresses",
",",
"function",
"(",
"$",
"address",
")",
"{",
"return",
"property_exists",
"(",
"$",
"address",
",",
"'mailbox'",
")",
"&&",
"strtolower",
"(",
"$",
"address",
"->",
"mailbox",
")",
"!==",
"'undisclosed-recipients'",
";",
"}",
")",
")",
";",
"}"
] |
Parse email addresses from header
@param array $addresses
@return array
|
[
"Parse",
"email",
"addresses",
"from",
"header"
] |
4eea346ece9fa35c0d309b5a909f657ad83e1e6a
|
https://github.com/david-mk/mail-map/blob/4eea346ece9fa35c0d309b5a909f657ad83e1e6a/src/MailMap/MailFactory.php#L118-L131
|
20,768 |
david-mk/mail-map
|
src/MailMap/MailFactory.php
|
MailFactory.parseSubject
|
protected function parseSubject($subject)
{
$subject = imap_mime_header_decode($subject);
$subjectParts = array_map(function ($subj) {
if (strtolower($subj->charset) === 'default') {
return $subj->text;
}
return iconv($subj->charset, static::$charset, $subj->text);
}, $subject);
return implode('', $subjectParts);
}
|
php
|
protected function parseSubject($subject)
{
$subject = imap_mime_header_decode($subject);
$subjectParts = array_map(function ($subj) {
if (strtolower($subj->charset) === 'default') {
return $subj->text;
}
return iconv($subj->charset, static::$charset, $subj->text);
}, $subject);
return implode('', $subjectParts);
}
|
[
"protected",
"function",
"parseSubject",
"(",
"$",
"subject",
")",
"{",
"$",
"subject",
"=",
"imap_mime_header_decode",
"(",
"$",
"subject",
")",
";",
"$",
"subjectParts",
"=",
"array_map",
"(",
"function",
"(",
"$",
"subj",
")",
"{",
"if",
"(",
"strtolower",
"(",
"$",
"subj",
"->",
"charset",
")",
"===",
"'default'",
")",
"{",
"return",
"$",
"subj",
"->",
"text",
";",
"}",
"return",
"iconv",
"(",
"$",
"subj",
"->",
"charset",
",",
"static",
"::",
"$",
"charset",
",",
"$",
"subj",
"->",
"text",
")",
";",
"}",
",",
"$",
"subject",
")",
";",
"return",
"implode",
"(",
"''",
",",
"$",
"subjectParts",
")",
";",
"}"
] |
Parse the subject of the email
@param string $subject
@return string
|
[
"Parse",
"the",
"subject",
"of",
"the",
"email"
] |
4eea346ece9fa35c0d309b5a909f657ad83e1e6a
|
https://github.com/david-mk/mail-map/blob/4eea346ece9fa35c0d309b5a909f657ad83e1e6a/src/MailMap/MailFactory.php#L151-L163
|
20,769 |
david-mk/mail-map
|
src/MailMap/MailFactory.php
|
MailFactory.parseHeaders
|
protected function parseHeaders($stream, $uid)
{
$rawHeaders = imap_fetchheader($stream, $uid, static::$fetchFlags);
$headers = [];
$key = null;
foreach (explode("\n", $rawHeaders) as $line) {
// Test if continutation
if ($line !== '' && !preg_match('/^\s/', $line)) {
list($key, $val) = explode(':', $line, 2);
$headers[$key] = trim($val);
} elseif (!is_null($key) && ($trimmed = trim($line)) !== '') {
$headers[$key] = $headers[$key].$trimmed;
}
}
foreach($headers as $headerKey => $headerValue) {
if (preg_match('/(\w+)=(\S+);(?:\s|$)/', $headerValue)) {
$headers[$headerKey] = $this->parseNestedKeyPairHeader($headerValue);
}
}
return $headers;
}
|
php
|
protected function parseHeaders($stream, $uid)
{
$rawHeaders = imap_fetchheader($stream, $uid, static::$fetchFlags);
$headers = [];
$key = null;
foreach (explode("\n", $rawHeaders) as $line) {
// Test if continutation
if ($line !== '' && !preg_match('/^\s/', $line)) {
list($key, $val) = explode(':', $line, 2);
$headers[$key] = trim($val);
} elseif (!is_null($key) && ($trimmed = trim($line)) !== '') {
$headers[$key] = $headers[$key].$trimmed;
}
}
foreach($headers as $headerKey => $headerValue) {
if (preg_match('/(\w+)=(\S+);(?:\s|$)/', $headerValue)) {
$headers[$headerKey] = $this->parseNestedKeyPairHeader($headerValue);
}
}
return $headers;
}
|
[
"protected",
"function",
"parseHeaders",
"(",
"$",
"stream",
",",
"$",
"uid",
")",
"{",
"$",
"rawHeaders",
"=",
"imap_fetchheader",
"(",
"$",
"stream",
",",
"$",
"uid",
",",
"static",
"::",
"$",
"fetchFlags",
")",
";",
"$",
"headers",
"=",
"[",
"]",
";",
"$",
"key",
"=",
"null",
";",
"foreach",
"(",
"explode",
"(",
"\"\\n\"",
",",
"$",
"rawHeaders",
")",
"as",
"$",
"line",
")",
"{",
"// Test if continutation",
"if",
"(",
"$",
"line",
"!==",
"''",
"&&",
"!",
"preg_match",
"(",
"'/^\\s/'",
",",
"$",
"line",
")",
")",
"{",
"list",
"(",
"$",
"key",
",",
"$",
"val",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"line",
",",
"2",
")",
";",
"$",
"headers",
"[",
"$",
"key",
"]",
"=",
"trim",
"(",
"$",
"val",
")",
";",
"}",
"elseif",
"(",
"!",
"is_null",
"(",
"$",
"key",
")",
"&&",
"(",
"$",
"trimmed",
"=",
"trim",
"(",
"$",
"line",
")",
")",
"!==",
"''",
")",
"{",
"$",
"headers",
"[",
"$",
"key",
"]",
"=",
"$",
"headers",
"[",
"$",
"key",
"]",
".",
"$",
"trimmed",
";",
"}",
"}",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"headerKey",
"=>",
"$",
"headerValue",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/(\\w+)=(\\S+);(?:\\s|$)/'",
",",
"$",
"headerValue",
")",
")",
"{",
"$",
"headers",
"[",
"$",
"headerKey",
"]",
"=",
"$",
"this",
"->",
"parseNestedKeyPairHeader",
"(",
"$",
"headerValue",
")",
";",
"}",
"}",
"return",
"$",
"headers",
";",
"}"
] |
Parse the email headers into array structure
@param resource $stream
@param int $uid
@return array
|
[
"Parse",
"the",
"email",
"headers",
"into",
"array",
"structure"
] |
4eea346ece9fa35c0d309b5a909f657ad83e1e6a
|
https://github.com/david-mk/mail-map/blob/4eea346ece9fa35c0d309b5a909f657ad83e1e6a/src/MailMap/MailFactory.php#L172-L196
|
20,770 |
david-mk/mail-map
|
src/MailMap/MailFactory.php
|
MailFactory.parseNestedKeyPairHeader
|
protected function parseNestedKeyPairHeader($nestedPairs)
{
return array_reduce(explode(';', $nestedPairs), function($result, $pair) {
$keyVal = explode('=', $pair, 2);
$key = trim(array_shift($keyVal));
$val = trim(implode('=', $keyVal));
if ($key !== '' && $val !== '') {
$result[$key] = $val;
}
return $result;
}, []);
}
|
php
|
protected function parseNestedKeyPairHeader($nestedPairs)
{
return array_reduce(explode(';', $nestedPairs), function($result, $pair) {
$keyVal = explode('=', $pair, 2);
$key = trim(array_shift($keyVal));
$val = trim(implode('=', $keyVal));
if ($key !== '' && $val !== '') {
$result[$key] = $val;
}
return $result;
}, []);
}
|
[
"protected",
"function",
"parseNestedKeyPairHeader",
"(",
"$",
"nestedPairs",
")",
"{",
"return",
"array_reduce",
"(",
"explode",
"(",
"';'",
",",
"$",
"nestedPairs",
")",
",",
"function",
"(",
"$",
"result",
",",
"$",
"pair",
")",
"{",
"$",
"keyVal",
"=",
"explode",
"(",
"'='",
",",
"$",
"pair",
",",
"2",
")",
";",
"$",
"key",
"=",
"trim",
"(",
"array_shift",
"(",
"$",
"keyVal",
")",
")",
";",
"$",
"val",
"=",
"trim",
"(",
"implode",
"(",
"'='",
",",
"$",
"keyVal",
")",
")",
";",
"if",
"(",
"$",
"key",
"!==",
"''",
"&&",
"$",
"val",
"!==",
"''",
")",
"{",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"return",
"$",
"result",
";",
"}",
",",
"[",
"]",
")",
";",
"}"
] |
Parse the any nested key-pair values in the header value
@param string $nestedPairs
@return array
|
[
"Parse",
"the",
"any",
"nested",
"key",
"-",
"pair",
"values",
"in",
"the",
"header",
"value"
] |
4eea346ece9fa35c0d309b5a909f657ad83e1e6a
|
https://github.com/david-mk/mail-map/blob/4eea346ece9fa35c0d309b5a909f657ad83e1e6a/src/MailMap/MailFactory.php#L204-L215
|
20,771 |
david-mk/mail-map
|
src/MailMap/MailFactory.php
|
MailFactory.parseBody
|
protected function parseBody($stream, $uid)
{
$struct = imap_fetchstructure($stream, $uid, static::$fetchFlags);
if (!isset($struct->parts)) {
return array_filter([$this->parsePart($stream, $uid, $struct)]);
}
$parsedParts = [];
foreach ($this->flattenParts($struct->parts) as $partNo => $part) {
$parsedParts[] = $this->parsePart($stream, $uid, $part, $partNo);
}
return array_filter($parsedParts);
}
|
php
|
protected function parseBody($stream, $uid)
{
$struct = imap_fetchstructure($stream, $uid, static::$fetchFlags);
if (!isset($struct->parts)) {
return array_filter([$this->parsePart($stream, $uid, $struct)]);
}
$parsedParts = [];
foreach ($this->flattenParts($struct->parts) as $partNo => $part) {
$parsedParts[] = $this->parsePart($stream, $uid, $part, $partNo);
}
return array_filter($parsedParts);
}
|
[
"protected",
"function",
"parseBody",
"(",
"$",
"stream",
",",
"$",
"uid",
")",
"{",
"$",
"struct",
"=",
"imap_fetchstructure",
"(",
"$",
"stream",
",",
"$",
"uid",
",",
"static",
"::",
"$",
"fetchFlags",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"struct",
"->",
"parts",
")",
")",
"{",
"return",
"array_filter",
"(",
"[",
"$",
"this",
"->",
"parsePart",
"(",
"$",
"stream",
",",
"$",
"uid",
",",
"$",
"struct",
")",
"]",
")",
";",
"}",
"$",
"parsedParts",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"flattenParts",
"(",
"$",
"struct",
"->",
"parts",
")",
"as",
"$",
"partNo",
"=>",
"$",
"part",
")",
"{",
"$",
"parsedParts",
"[",
"]",
"=",
"$",
"this",
"->",
"parsePart",
"(",
"$",
"stream",
",",
"$",
"uid",
",",
"$",
"part",
",",
"$",
"partNo",
")",
";",
"}",
"return",
"array_filter",
"(",
"$",
"parsedParts",
")",
";",
"}"
] |
Parse the email body and its parts
@param resource $stream
@param int $uid
@return array
|
[
"Parse",
"the",
"email",
"body",
"and",
"its",
"parts"
] |
4eea346ece9fa35c0d309b5a909f657ad83e1e6a
|
https://github.com/david-mk/mail-map/blob/4eea346ece9fa35c0d309b5a909f657ad83e1e6a/src/MailMap/MailFactory.php#L224-L237
|
20,772 |
david-mk/mail-map
|
src/MailMap/MailFactory.php
|
MailFactory.flattenParts
|
protected function flattenParts(array $parts, array $flattened = [], $pre = '', $idx = 1, $full = true)
{
foreach ($parts as $part) {
$key = $pre.$idx;
$flattened[$key] = $part;
if (isset($part->parts)) {
if ($part->type == TYPEMULTIPART) {
$flattened = $this->flattenParts($part->parts, $flattened, $key.'.', 1, false);
} elseif ($full) {
$flattened = $this->flattenParts($part->parts, $flattened, $key.'.');
} else {
$flattened = $this->flattenParts($part->parts, $flattened, $pre);
}
unset($flattened[$key]->parts);
}
$idx++;
}
return $flattened;
}
|
php
|
protected function flattenParts(array $parts, array $flattened = [], $pre = '', $idx = 1, $full = true)
{
foreach ($parts as $part) {
$key = $pre.$idx;
$flattened[$key] = $part;
if (isset($part->parts)) {
if ($part->type == TYPEMULTIPART) {
$flattened = $this->flattenParts($part->parts, $flattened, $key.'.', 1, false);
} elseif ($full) {
$flattened = $this->flattenParts($part->parts, $flattened, $key.'.');
} else {
$flattened = $this->flattenParts($part->parts, $flattened, $pre);
}
unset($flattened[$key]->parts);
}
$idx++;
}
return $flattened;
}
|
[
"protected",
"function",
"flattenParts",
"(",
"array",
"$",
"parts",
",",
"array",
"$",
"flattened",
"=",
"[",
"]",
",",
"$",
"pre",
"=",
"''",
",",
"$",
"idx",
"=",
"1",
",",
"$",
"full",
"=",
"true",
")",
"{",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"part",
")",
"{",
"$",
"key",
"=",
"$",
"pre",
".",
"$",
"idx",
";",
"$",
"flattened",
"[",
"$",
"key",
"]",
"=",
"$",
"part",
";",
"if",
"(",
"isset",
"(",
"$",
"part",
"->",
"parts",
")",
")",
"{",
"if",
"(",
"$",
"part",
"->",
"type",
"==",
"TYPEMULTIPART",
")",
"{",
"$",
"flattened",
"=",
"$",
"this",
"->",
"flattenParts",
"(",
"$",
"part",
"->",
"parts",
",",
"$",
"flattened",
",",
"$",
"key",
".",
"'.'",
",",
"1",
",",
"false",
")",
";",
"}",
"elseif",
"(",
"$",
"full",
")",
"{",
"$",
"flattened",
"=",
"$",
"this",
"->",
"flattenParts",
"(",
"$",
"part",
"->",
"parts",
",",
"$",
"flattened",
",",
"$",
"key",
".",
"'.'",
")",
";",
"}",
"else",
"{",
"$",
"flattened",
"=",
"$",
"this",
"->",
"flattenParts",
"(",
"$",
"part",
"->",
"parts",
",",
"$",
"flattened",
",",
"$",
"pre",
")",
";",
"}",
"unset",
"(",
"$",
"flattened",
"[",
"$",
"key",
"]",
"->",
"parts",
")",
";",
"}",
"$",
"idx",
"++",
";",
"}",
"return",
"$",
"flattened",
";",
"}"
] |
Flatten email structure recursively.
Parts re-keyed as 1, 1.1, 2, 2.1, 2.1.1 etc
@param array $parts
@param array $flattened
@param string $pre
@param int $idx
@param bool $full
@return array
|
[
"Flatten",
"email",
"structure",
"recursively",
"."
] |
4eea346ece9fa35c0d309b5a909f657ad83e1e6a
|
https://github.com/david-mk/mail-map/blob/4eea346ece9fa35c0d309b5a909f657ad83e1e6a/src/MailMap/MailFactory.php#L251-L270
|
20,773 |
david-mk/mail-map
|
src/MailMap/MailFactory.php
|
MailFactory.parsePart
|
protected function parsePart($stream, $uid, $part, $partNo = 1)
{
if (!in_array($part->type, [TYPETEXT, TYPEMULTIPART])) {
return null;
}
$body = imap_fetchbody($stream, $uid, $partNo, static::$bodyFlags);
$body = static::decode($body, $part->encoding);
if ('' !== ($charset = $this->findCharset($part))) {
$body = static::convertBodyEncoding($body, $charset, $part->encoding);
}
return (object) [
'body' => $body,
'mime_type' => strtolower($part->subtype)
];
}
|
php
|
protected function parsePart($stream, $uid, $part, $partNo = 1)
{
if (!in_array($part->type, [TYPETEXT, TYPEMULTIPART])) {
return null;
}
$body = imap_fetchbody($stream, $uid, $partNo, static::$bodyFlags);
$body = static::decode($body, $part->encoding);
if ('' !== ($charset = $this->findCharset($part))) {
$body = static::convertBodyEncoding($body, $charset, $part->encoding);
}
return (object) [
'body' => $body,
'mime_type' => strtolower($part->subtype)
];
}
|
[
"protected",
"function",
"parsePart",
"(",
"$",
"stream",
",",
"$",
"uid",
",",
"$",
"part",
",",
"$",
"partNo",
"=",
"1",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"part",
"->",
"type",
",",
"[",
"TYPETEXT",
",",
"TYPEMULTIPART",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"body",
"=",
"imap_fetchbody",
"(",
"$",
"stream",
",",
"$",
"uid",
",",
"$",
"partNo",
",",
"static",
"::",
"$",
"bodyFlags",
")",
";",
"$",
"body",
"=",
"static",
"::",
"decode",
"(",
"$",
"body",
",",
"$",
"part",
"->",
"encoding",
")",
";",
"if",
"(",
"''",
"!==",
"(",
"$",
"charset",
"=",
"$",
"this",
"->",
"findCharset",
"(",
"$",
"part",
")",
")",
")",
"{",
"$",
"body",
"=",
"static",
"::",
"convertBodyEncoding",
"(",
"$",
"body",
",",
"$",
"charset",
",",
"$",
"part",
"->",
"encoding",
")",
";",
"}",
"return",
"(",
"object",
")",
"[",
"'body'",
"=>",
"$",
"body",
",",
"'mime_type'",
"=>",
"strtolower",
"(",
"$",
"part",
"->",
"subtype",
")",
"]",
";",
"}"
] |
Parse individual part of the structure
@param resource $stream
@param int $uid
@param stdClass $part
@param int $partNo
@return stdClass | null
|
[
"Parse",
"individual",
"part",
"of",
"the",
"structure"
] |
4eea346ece9fa35c0d309b5a909f657ad83e1e6a
|
https://github.com/david-mk/mail-map/blob/4eea346ece9fa35c0d309b5a909f657ad83e1e6a/src/MailMap/MailFactory.php#L281-L298
|
20,774 |
david-mk/mail-map
|
src/MailMap/MailFactory.php
|
MailFactory.decode
|
protected static function decode($body, $encoding)
{
if (ENCQUOTEDPRINTABLE === $encoding) {
return quoted_printable_decode($body);
}
if (ENCBASE64 === $encoding) {
return base64_decode($body);
}
return $body;
}
|
php
|
protected static function decode($body, $encoding)
{
if (ENCQUOTEDPRINTABLE === $encoding) {
return quoted_printable_decode($body);
}
if (ENCBASE64 === $encoding) {
return base64_decode($body);
}
return $body;
}
|
[
"protected",
"static",
"function",
"decode",
"(",
"$",
"body",
",",
"$",
"encoding",
")",
"{",
"if",
"(",
"ENCQUOTEDPRINTABLE",
"===",
"$",
"encoding",
")",
"{",
"return",
"quoted_printable_decode",
"(",
"$",
"body",
")",
";",
"}",
"if",
"(",
"ENCBASE64",
"===",
"$",
"encoding",
")",
"{",
"return",
"base64_decode",
"(",
"$",
"body",
")",
";",
"}",
"return",
"$",
"body",
";",
"}"
] |
Decode the body text
@param string $body
@param int $encoding
@return string
|
[
"Decode",
"the",
"body",
"text"
] |
4eea346ece9fa35c0d309b5a909f657ad83e1e6a
|
https://github.com/david-mk/mail-map/blob/4eea346ece9fa35c0d309b5a909f657ad83e1e6a/src/MailMap/MailFactory.php#L307-L318
|
20,775 |
david-mk/mail-map
|
src/MailMap/MailFactory.php
|
MailFactory.convertBodyEncoding
|
protected static function convertBodyEncoding($body, $charset = '', $encoding = -1)
{
if ('' === $charset) {
$charset = static::$charset;
}
if (!mb_check_encoding($body, $charset)) {
$charset = mb_detect_encoding($body);
}
if ($charset === static::$charset) {
return $body;
}
if (!in_array($charset, mb_list_encodings())) {
$charset = $encoding === ENC7BIT ? 'US-ASCII' : static::$charset;
}
return mb_convert_encoding($body, static::$charset, $charset);
}
|
php
|
protected static function convertBodyEncoding($body, $charset = '', $encoding = -1)
{
if ('' === $charset) {
$charset = static::$charset;
}
if (!mb_check_encoding($body, $charset)) {
$charset = mb_detect_encoding($body);
}
if ($charset === static::$charset) {
return $body;
}
if (!in_array($charset, mb_list_encodings())) {
$charset = $encoding === ENC7BIT ? 'US-ASCII' : static::$charset;
}
return mb_convert_encoding($body, static::$charset, $charset);
}
|
[
"protected",
"static",
"function",
"convertBodyEncoding",
"(",
"$",
"body",
",",
"$",
"charset",
"=",
"''",
",",
"$",
"encoding",
"=",
"-",
"1",
")",
"{",
"if",
"(",
"''",
"===",
"$",
"charset",
")",
"{",
"$",
"charset",
"=",
"static",
"::",
"$",
"charset",
";",
"}",
"if",
"(",
"!",
"mb_check_encoding",
"(",
"$",
"body",
",",
"$",
"charset",
")",
")",
"{",
"$",
"charset",
"=",
"mb_detect_encoding",
"(",
"$",
"body",
")",
";",
"}",
"if",
"(",
"$",
"charset",
"===",
"static",
"::",
"$",
"charset",
")",
"{",
"return",
"$",
"body",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"charset",
",",
"mb_list_encodings",
"(",
")",
")",
")",
"{",
"$",
"charset",
"=",
"$",
"encoding",
"===",
"ENC7BIT",
"?",
"'US-ASCII'",
":",
"static",
"::",
"$",
"charset",
";",
"}",
"return",
"mb_convert_encoding",
"(",
"$",
"body",
",",
"static",
"::",
"$",
"charset",
",",
"$",
"charset",
")",
";",
"}"
] |
Convert body encoding from given coding to default
@param string $body
@param string $charset
@param int $encoding
@return string
|
[
"Convert",
"body",
"encoding",
"from",
"given",
"coding",
"to",
"default"
] |
4eea346ece9fa35c0d309b5a909f657ad83e1e6a
|
https://github.com/david-mk/mail-map/blob/4eea346ece9fa35c0d309b5a909f657ad83e1e6a/src/MailMap/MailFactory.php#L328-L347
|
20,776 |
david-mk/mail-map
|
src/MailMap/MailFactory.php
|
MailFactory.findCharset
|
protected function findCharset($struct)
{
if (isset($struct->parameters)) {
foreach ($struct->parameters as $param) {
if (strtolower($param->attribute) === 'charset') {
return strtoupper($param->value);
}
}
}
if (isset($struct->dparameters)) {
foreach ($struct->dparameters as $param) {
if (strtolower($param->attribute) === 'charset') {
return strtoupper($param->value);
}
}
}
return '';
}
|
php
|
protected function findCharset($struct)
{
if (isset($struct->parameters)) {
foreach ($struct->parameters as $param) {
if (strtolower($param->attribute) === 'charset') {
return strtoupper($param->value);
}
}
}
if (isset($struct->dparameters)) {
foreach ($struct->dparameters as $param) {
if (strtolower($param->attribute) === 'charset') {
return strtoupper($param->value);
}
}
}
return '';
}
|
[
"protected",
"function",
"findCharset",
"(",
"$",
"struct",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"struct",
"->",
"parameters",
")",
")",
"{",
"foreach",
"(",
"$",
"struct",
"->",
"parameters",
"as",
"$",
"param",
")",
"{",
"if",
"(",
"strtolower",
"(",
"$",
"param",
"->",
"attribute",
")",
"===",
"'charset'",
")",
"{",
"return",
"strtoupper",
"(",
"$",
"param",
"->",
"value",
")",
";",
"}",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"struct",
"->",
"dparameters",
")",
")",
"{",
"foreach",
"(",
"$",
"struct",
"->",
"dparameters",
"as",
"$",
"param",
")",
"{",
"if",
"(",
"strtolower",
"(",
"$",
"param",
"->",
"attribute",
")",
"===",
"'charset'",
")",
"{",
"return",
"strtoupper",
"(",
"$",
"param",
"->",
"value",
")",
";",
"}",
"}",
"}",
"return",
"''",
";",
"}"
] |
Locate the charset within the struct
@param stdClass $struct
@return string
|
[
"Locate",
"the",
"charset",
"within",
"the",
"struct"
] |
4eea346ece9fa35c0d309b5a909f657ad83e1e6a
|
https://github.com/david-mk/mail-map/blob/4eea346ece9fa35c0d309b5a909f657ad83e1e6a/src/MailMap/MailFactory.php#L355-L373
|
20,777 |
inhere/php-librarys
|
src/Collections/FixedArray.php
|
FixedArray.offsetUnset
|
public function offsetUnset($offset)
{
$index = $this->getKeyIndex($offset);
if ($index >= 0) {
// change size.
$this->values->setSize($index - 1);
unset($this->keys[$offset], $this->values[$index]);
}
}
|
php
|
public function offsetUnset($offset)
{
$index = $this->getKeyIndex($offset);
if ($index >= 0) {
// change size.
$this->values->setSize($index - 1);
unset($this->keys[$offset], $this->values[$index]);
}
}
|
[
"public",
"function",
"offsetUnset",
"(",
"$",
"offset",
")",
"{",
"$",
"index",
"=",
"$",
"this",
"->",
"getKeyIndex",
"(",
"$",
"offset",
")",
";",
"if",
"(",
"$",
"index",
">=",
"0",
")",
"{",
"// change size.",
"$",
"this",
"->",
"values",
"->",
"setSize",
"(",
"$",
"index",
"-",
"1",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"keys",
"[",
"$",
"offset",
"]",
",",
"$",
"this",
"->",
"values",
"[",
"$",
"index",
"]",
")",
";",
"}",
"}"
] |
Unset an offset in the iterator.
@param mixed $offset The array offset.
@return void
|
[
"Unset",
"an",
"offset",
"in",
"the",
"iterator",
"."
] |
e6ca598685469794f310e3ab0e2bc19519cd0ae6
|
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Collections/FixedArray.php#L186-L196
|
20,778 |
mainio/c5pkg_symfony_forms
|
src/Mainio/C5/Symfony/Form/Extension/Concrete5/DataTransformer/FileToIntegerTransformer.php
|
FileToIntegerTransformer.transform
|
public function transform($value)
{
if ($value === null || $value == '') {
return null;
}
if (!($value instanceof File)) {
throw new TransformationFailedException('Expected an instance of a concrete5 file object.');
}
return intval($value->getFileID());
}
|
php
|
public function transform($value)
{
if ($value === null || $value == '') {
return null;
}
if (!($value instanceof File)) {
throw new TransformationFailedException('Expected an instance of a concrete5 file object.');
}
return intval($value->getFileID());
}
|
[
"public",
"function",
"transform",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
"||",
"$",
"value",
"==",
"''",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"value",
"instanceof",
"File",
")",
")",
"{",
"throw",
"new",
"TransformationFailedException",
"(",
"'Expected an instance of a concrete5 file object.'",
")",
";",
"}",
"return",
"intval",
"(",
"$",
"value",
"->",
"getFileID",
"(",
")",
")",
";",
"}"
] |
Converts a concrete5 file object to an integer.
@param \Concrete\Core\File\File $value The file object value
@return int The integer value
@throws TransformationFailedException If the given value is not an
instance of Concrete\Core\File\File.
|
[
"Converts",
"a",
"concrete5",
"file",
"object",
"to",
"an",
"integer",
"."
] |
41a93c293d986574ec5cade8a7c8700e083dbaaa
|
https://github.com/mainio/c5pkg_symfony_forms/blob/41a93c293d986574ec5cade8a7c8700e083dbaaa/src/Mainio/C5/Symfony/Form/Extension/Concrete5/DataTransformer/FileToIntegerTransformer.php#L34-L43
|
20,779 |
mainio/c5pkg_symfony_forms
|
src/Mainio/C5/Symfony/Form/Extension/Concrete5/DataTransformer/FileToIntegerTransformer.php
|
FileToIntegerTransformer.reverseTransform
|
public function reverseTransform($fID)
{
if (!is_numeric($fID) || $fID == 0) {
return null;
}
$rep = $this->entityManager->getRepository('Concrete\Core\File\File');
$f = $rep->find($fID);
if (!is_object($f) || $f->isError()) {
throw new TransformationFailedException('Invalid file ID.');
}
return $f;
}
|
php
|
public function reverseTransform($fID)
{
if (!is_numeric($fID) || $fID == 0) {
return null;
}
$rep = $this->entityManager->getRepository('Concrete\Core\File\File');
$f = $rep->find($fID);
if (!is_object($f) || $f->isError()) {
throw new TransformationFailedException('Invalid file ID.');
}
return $f;
}
|
[
"public",
"function",
"reverseTransform",
"(",
"$",
"fID",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"fID",
")",
"||",
"$",
"fID",
"==",
"0",
")",
"{",
"return",
"null",
";",
"}",
"$",
"rep",
"=",
"$",
"this",
"->",
"entityManager",
"->",
"getRepository",
"(",
"'Concrete\\Core\\File\\File'",
")",
";",
"$",
"f",
"=",
"$",
"rep",
"->",
"find",
"(",
"$",
"fID",
")",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"f",
")",
"||",
"$",
"f",
"->",
"isError",
"(",
")",
")",
"{",
"throw",
"new",
"TransformationFailedException",
"(",
"'Invalid file ID.'",
")",
";",
"}",
"return",
"$",
"f",
";",
"}"
] |
Converts an integer to a concrete5 file object.
@param int $fID
@return mixed The value
@throws TransformationFailedException If the given value is not a proper
concrete5 file ID.
|
[
"Converts",
"an",
"integer",
"to",
"a",
"concrete5",
"file",
"object",
"."
] |
41a93c293d986574ec5cade8a7c8700e083dbaaa
|
https://github.com/mainio/c5pkg_symfony_forms/blob/41a93c293d986574ec5cade8a7c8700e083dbaaa/src/Mainio/C5/Symfony/Form/Extension/Concrete5/DataTransformer/FileToIntegerTransformer.php#L53-L67
|
20,780 |
webdevvie/pheanstalk-task-queue-bundle
|
Command/RegenerateFailedTaskCommand.php
|
RegenerateFailedTaskCommand.regenerateTaskById
|
private function regenerateTaskById($id)
{
try {
$response = $this->taskQueueService->regenerateTask($id);
if ($response) {
$this->output->writeln("<info>Regeneration succes</info>");
} else {
$this->output->writeln("<error>Regeneration succes</error>");
}
} catch (TaskQueueServiceException $e) {
$this->output->writeln("<error>Error!:</error>" . $e->getMessage());
}
}
|
php
|
private function regenerateTaskById($id)
{
try {
$response = $this->taskQueueService->regenerateTask($id);
if ($response) {
$this->output->writeln("<info>Regeneration succes</info>");
} else {
$this->output->writeln("<error>Regeneration succes</error>");
}
} catch (TaskQueueServiceException $e) {
$this->output->writeln("<error>Error!:</error>" . $e->getMessage());
}
}
|
[
"private",
"function",
"regenerateTaskById",
"(",
"$",
"id",
")",
"{",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"taskQueueService",
"->",
"regenerateTask",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"response",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"<info>Regeneration succes</info>\"",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"<error>Regeneration succes</error>\"",
")",
";",
"}",
"}",
"catch",
"(",
"TaskQueueServiceException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"<error>Error!:</error>\"",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] |
Regenerates a task that has failed
@param integer $id
@return void
|
[
"Regenerates",
"a",
"task",
"that",
"has",
"failed"
] |
db5e63a8f844e345dc2e69ce8e94b32d851020eb
|
https://github.com/webdevvie/pheanstalk-task-queue-bundle/blob/db5e63a8f844e345dc2e69ce8e94b32d851020eb/Command/RegenerateFailedTaskCommand.php#L72-L84
|
20,781 |
eghojansu/moe
|
src/Instance.php
|
Instance.__callstatic
|
static function __callstatic($func,array $args) {
if (!self::$fw)
self::$fw=Base::instance();
return call_user_func_array(array(self::$fw,$func),$args);
}
|
php
|
static function __callstatic($func,array $args) {
if (!self::$fw)
self::$fw=Base::instance();
return call_user_func_array(array(self::$fw,$func),$args);
}
|
[
"static",
"function",
"__callstatic",
"(",
"$",
"func",
",",
"array",
"$",
"args",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"fw",
")",
"self",
"::",
"$",
"fw",
"=",
"Base",
"::",
"instance",
"(",
")",
";",
"return",
"call_user_func_array",
"(",
"array",
"(",
"self",
"::",
"$",
"fw",
",",
"$",
"func",
")",
",",
"$",
"args",
")",
";",
"}"
] |
Forward function calls to framework
@return mixed
@param $func callback
@param $args array
|
[
"Forward",
"function",
"calls",
"to",
"framework"
] |
f58ec75a3116d1a572782256e2b38bb9aab95e3c
|
https://github.com/eghojansu/moe/blob/f58ec75a3116d1a572782256e2b38bb9aab95e3c/src/Instance.php#L19-L23
|
20,782 |
odiaseo/pagebuilder
|
src/PageBuilder/Service/LayoutService.php
|
LayoutService.getPageThemeLayout
|
public function getPageThemeLayout($pageThemeId)
{
/** @var $themeModel \PageBuilder\Model\PageTemplateModel */
$themeModel = $this->getServiceLocator()->get('pagebuilder\model\pageTheme');
$pageTheme = $themeModel->findObject($pageThemeId);
return $this->getPageLayout($pageTheme->getPageId()->getId(), $pageTheme->getThemeId()->getId());
}
|
php
|
public function getPageThemeLayout($pageThemeId)
{
/** @var $themeModel \PageBuilder\Model\PageTemplateModel */
$themeModel = $this->getServiceLocator()->get('pagebuilder\model\pageTheme');
$pageTheme = $themeModel->findObject($pageThemeId);
return $this->getPageLayout($pageTheme->getPageId()->getId(), $pageTheme->getThemeId()->getId());
}
|
[
"public",
"function",
"getPageThemeLayout",
"(",
"$",
"pageThemeId",
")",
"{",
"/** @var $themeModel \\PageBuilder\\Model\\PageTemplateModel */",
"$",
"themeModel",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'pagebuilder\\model\\pageTheme'",
")",
";",
"$",
"pageTheme",
"=",
"$",
"themeModel",
"->",
"findObject",
"(",
"$",
"pageThemeId",
")",
";",
"return",
"$",
"this",
"->",
"getPageLayout",
"(",
"$",
"pageTheme",
"->",
"getPageId",
"(",
")",
"->",
"getId",
"(",
")",
",",
"$",
"pageTheme",
"->",
"getThemeId",
"(",
")",
"->",
"getId",
"(",
")",
")",
";",
"}"
] |
Get Page theme layout
@param $pageThemeId
@return array
|
[
"Get",
"Page",
"theme",
"layout"
] |
88ef7cccf305368561307efe4ca07fac8e5774f3
|
https://github.com/odiaseo/pagebuilder/blob/88ef7cccf305368561307efe4ca07fac8e5774f3/src/PageBuilder/Service/LayoutService.php#L101-L109
|
20,783 |
sciactive/nymph-server
|
src/Drivers/MySQLDriver.php
|
MySQLDriver.connect
|
public function connect() {
// Check that the MySQLi extension is installed.
if (!is_callable('mysqli_connect')) {
throw new Exceptions\UnableToConnectException(
'MySQLi PHP extension is not available. It probably has not been '.
'installed. Please install and configure it in order to use MySQL.'
);
}
$host = $this->config['MySQL']['host'];
$user = $this->config['MySQL']['user'];
$password = $this->config['MySQL']['password'];
$database = $this->config['MySQL']['database'];
$port = $this->config['MySQL']['port'];
// If we think we're connected, try pinging the server.
if ($this->connected && !mysqli_ping($this->link)) {
$this->connected = false;
}
// Connecting, selecting database
if (!$this->connected) {
$link = is_callable($this->config['MySQL']['link'])
? $this->config['MySQL']['link']()
: null;
if ($this->link = $link ??
mysqli_connect(
$host,
$user,
$password,
$database,
$port
)) {
$this->connected = true;
} else {
$this->connected = false;
if ($host === 'localhost'
&& $user === 'nymph'
&& $password === 'password'
&& $database === 'nymph'
&& $link === null) {
throw new Exceptions\NotConfiguredException();
} else {
throw new Exceptions\UnableToConnectException(
'Could not connect: '.
mysqli_error($this->link)
);
}
}
}
return $this->connected;
}
|
php
|
public function connect() {
// Check that the MySQLi extension is installed.
if (!is_callable('mysqli_connect')) {
throw new Exceptions\UnableToConnectException(
'MySQLi PHP extension is not available. It probably has not been '.
'installed. Please install and configure it in order to use MySQL.'
);
}
$host = $this->config['MySQL']['host'];
$user = $this->config['MySQL']['user'];
$password = $this->config['MySQL']['password'];
$database = $this->config['MySQL']['database'];
$port = $this->config['MySQL']['port'];
// If we think we're connected, try pinging the server.
if ($this->connected && !mysqli_ping($this->link)) {
$this->connected = false;
}
// Connecting, selecting database
if (!$this->connected) {
$link = is_callable($this->config['MySQL']['link'])
? $this->config['MySQL']['link']()
: null;
if ($this->link = $link ??
mysqli_connect(
$host,
$user,
$password,
$database,
$port
)) {
$this->connected = true;
} else {
$this->connected = false;
if ($host === 'localhost'
&& $user === 'nymph'
&& $password === 'password'
&& $database === 'nymph'
&& $link === null) {
throw new Exceptions\NotConfiguredException();
} else {
throw new Exceptions\UnableToConnectException(
'Could not connect: '.
mysqli_error($this->link)
);
}
}
}
return $this->connected;
}
|
[
"public",
"function",
"connect",
"(",
")",
"{",
"// Check that the MySQLi extension is installed.",
"if",
"(",
"!",
"is_callable",
"(",
"'mysqli_connect'",
")",
")",
"{",
"throw",
"new",
"Exceptions",
"\\",
"UnableToConnectException",
"(",
"'MySQLi PHP extension is not available. It probably has not been '",
".",
"'installed. Please install and configure it in order to use MySQL.'",
")",
";",
"}",
"$",
"host",
"=",
"$",
"this",
"->",
"config",
"[",
"'MySQL'",
"]",
"[",
"'host'",
"]",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"config",
"[",
"'MySQL'",
"]",
"[",
"'user'",
"]",
";",
"$",
"password",
"=",
"$",
"this",
"->",
"config",
"[",
"'MySQL'",
"]",
"[",
"'password'",
"]",
";",
"$",
"database",
"=",
"$",
"this",
"->",
"config",
"[",
"'MySQL'",
"]",
"[",
"'database'",
"]",
";",
"$",
"port",
"=",
"$",
"this",
"->",
"config",
"[",
"'MySQL'",
"]",
"[",
"'port'",
"]",
";",
"// If we think we're connected, try pinging the server.",
"if",
"(",
"$",
"this",
"->",
"connected",
"&&",
"!",
"mysqli_ping",
"(",
"$",
"this",
"->",
"link",
")",
")",
"{",
"$",
"this",
"->",
"connected",
"=",
"false",
";",
"}",
"// Connecting, selecting database",
"if",
"(",
"!",
"$",
"this",
"->",
"connected",
")",
"{",
"$",
"link",
"=",
"is_callable",
"(",
"$",
"this",
"->",
"config",
"[",
"'MySQL'",
"]",
"[",
"'link'",
"]",
")",
"?",
"$",
"this",
"->",
"config",
"[",
"'MySQL'",
"]",
"[",
"'link'",
"]",
"(",
")",
":",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"link",
"=",
"$",
"link",
"??",
"mysqli_connect",
"(",
"$",
"host",
",",
"$",
"user",
",",
"$",
"password",
",",
"$",
"database",
",",
"$",
"port",
")",
")",
"{",
"$",
"this",
"->",
"connected",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"connected",
"=",
"false",
";",
"if",
"(",
"$",
"host",
"===",
"'localhost'",
"&&",
"$",
"user",
"===",
"'nymph'",
"&&",
"$",
"password",
"===",
"'password'",
"&&",
"$",
"database",
"===",
"'nymph'",
"&&",
"$",
"link",
"===",
"null",
")",
"{",
"throw",
"new",
"Exceptions",
"\\",
"NotConfiguredException",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exceptions",
"\\",
"UnableToConnectException",
"(",
"'Could not connect: '",
".",
"mysqli_error",
"(",
"$",
"this",
"->",
"link",
")",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"connected",
";",
"}"
] |
Connect to the MySQL database.
@return bool Whether this instance is connected to a MySQL database after
the method has run.
|
[
"Connect",
"to",
"the",
"MySQL",
"database",
"."
] |
3c18dbf45c2750d07c798e14534dba87387beeba
|
https://github.com/sciactive/nymph-server/blob/3c18dbf45c2750d07c798e14534dba87387beeba/src/Drivers/MySQLDriver.php#L46-L97
|
20,784 |
sciactive/nymph-server
|
src/Drivers/MySQLDriver.php
|
MySQLDriver.disconnect
|
public function disconnect() {
if ($this->connected) {
if (is_a($this->link, 'mysqli')) {
unset($this->link);
}
$this->link = null;
$this->connected = false;
}
return $this->connected;
}
|
php
|
public function disconnect() {
if ($this->connected) {
if (is_a($this->link, 'mysqli')) {
unset($this->link);
}
$this->link = null;
$this->connected = false;
}
return $this->connected;
}
|
[
"public",
"function",
"disconnect",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"connected",
")",
"{",
"if",
"(",
"is_a",
"(",
"$",
"this",
"->",
"link",
",",
"'mysqli'",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"link",
")",
";",
"}",
"$",
"this",
"->",
"link",
"=",
"null",
";",
"$",
"this",
"->",
"connected",
"=",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"connected",
";",
"}"
] |
Disconnect from the MySQL database.
@return bool Whether this instance is connected to a MySQL database after
the method has run.
|
[
"Disconnect",
"from",
"the",
"MySQL",
"database",
"."
] |
3c18dbf45c2750d07c798e14534dba87387beeba
|
https://github.com/sciactive/nymph-server/blob/3c18dbf45c2750d07c798e14534dba87387beeba/src/Drivers/MySQLDriver.php#L105-L114
|
20,785 |
hametuha/wpametu
|
src/WPametu/API/Rewrite.php
|
Rewrite.rewrite_rules_array
|
public function rewrite_rules_array( array $rules ){
if( !empty($this->classes) ){
// Normal rewrite rules
$new_rewrite = [];
$error_message = [];
foreach( $this->classes as $class_name ){
$prefix = $this->get_prefix($class_name);
/** @var RestBase $class_name */
if( empty($prefix) ){
$error_message[] = sprintf($this->__('<code>%s</code> should have prefix property.'), $class_name);
continue;
}
// API Rewrite rules
$new_rewrite[trim($prefix, '/').'(/.*)?$'] = "index.php?{$this->api_class}={$class_name}&{$this->api_vars}=\$matches[1]";
}
if( !empty($new_rewrite) ){
$rules = array_merge($new_rewrite, $rules);
}
if( !empty($error_message) ){
add_action('admin_notices', function() use ($error_message) {
printf('<div class="error"><p>%s</p></div>', implode('<br />', $error_message));
});
}
}
return $rules;
}
|
php
|
public function rewrite_rules_array( array $rules ){
if( !empty($this->classes) ){
// Normal rewrite rules
$new_rewrite = [];
$error_message = [];
foreach( $this->classes as $class_name ){
$prefix = $this->get_prefix($class_name);
/** @var RestBase $class_name */
if( empty($prefix) ){
$error_message[] = sprintf($this->__('<code>%s</code> should have prefix property.'), $class_name);
continue;
}
// API Rewrite rules
$new_rewrite[trim($prefix, '/').'(/.*)?$'] = "index.php?{$this->api_class}={$class_name}&{$this->api_vars}=\$matches[1]";
}
if( !empty($new_rewrite) ){
$rules = array_merge($new_rewrite, $rules);
}
if( !empty($error_message) ){
add_action('admin_notices', function() use ($error_message) {
printf('<div class="error"><p>%s</p></div>', implode('<br />', $error_message));
});
}
}
return $rules;
}
|
[
"public",
"function",
"rewrite_rules_array",
"(",
"array",
"$",
"rules",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"classes",
")",
")",
"{",
"// Normal rewrite rules",
"$",
"new_rewrite",
"=",
"[",
"]",
";",
"$",
"error_message",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"classes",
"as",
"$",
"class_name",
")",
"{",
"$",
"prefix",
"=",
"$",
"this",
"->",
"get_prefix",
"(",
"$",
"class_name",
")",
";",
"/** @var RestBase $class_name */",
"if",
"(",
"empty",
"(",
"$",
"prefix",
")",
")",
"{",
"$",
"error_message",
"[",
"]",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"__",
"(",
"'<code>%s</code> should have prefix property.'",
")",
",",
"$",
"class_name",
")",
";",
"continue",
";",
"}",
"// API Rewrite rules",
"$",
"new_rewrite",
"[",
"trim",
"(",
"$",
"prefix",
",",
"'/'",
")",
".",
"'(/.*)?$'",
"]",
"=",
"\"index.php?{$this->api_class}={$class_name}&{$this->api_vars}=\\$matches[1]\"",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"new_rewrite",
")",
")",
"{",
"$",
"rules",
"=",
"array_merge",
"(",
"$",
"new_rewrite",
",",
"$",
"rules",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"error_message",
")",
")",
"{",
"add_action",
"(",
"'admin_notices'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"error_message",
")",
"{",
"printf",
"(",
"'<div class=\"error\"><p>%s</p></div>'",
",",
"implode",
"(",
"'<br />'",
",",
"$",
"error_message",
")",
")",
";",
"}",
")",
";",
"}",
"}",
"return",
"$",
"rules",
";",
"}"
] |
Add rewrite rules.
@param array $rules
@return array
|
[
"Add",
"rewrite",
"rules",
"."
] |
0939373800815a8396291143d2a57967340da5aa
|
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/API/Rewrite.php#L95-L120
|
20,786 |
hametuha/wpametu
|
src/WPametu/API/Rewrite.php
|
Rewrite.pre_get_posts
|
public function pre_get_posts( \WP_Query &$wp_query ){
if( !is_admin() && $wp_query->is_main_query() && ($api_class = $wp_query->get($this->api_class)) ){
// Detect class is valid
try{
// Fix escaped namespace delimiter
$api_class = str_replace('\\\\', '\\', $api_class);
// Check class existence
if( !$this->is_valid_class($api_class) ){
throw new \Exception($this->__('Specified URL is invalid.'), 404);
}
/** @var RestBase $instance */
$instance = $api_class::get_instance();
$instance->parse_request($wp_query->get($this->api_vars), $wp_query);
}catch ( \Exception $e ){
switch( $e->getCode() ){
case 404:
$wp_query->set_404();
break;
case 200:
case 201:
// If status is O.K.
// Do nothing.
break;
default:
wp_die($e->getMessage(), get_status_header_desc($e->getCode()), [
'response' => $e->getCode(),
'back_link' => true,
]);
break;
}
}
}
}
|
php
|
public function pre_get_posts( \WP_Query &$wp_query ){
if( !is_admin() && $wp_query->is_main_query() && ($api_class = $wp_query->get($this->api_class)) ){
// Detect class is valid
try{
// Fix escaped namespace delimiter
$api_class = str_replace('\\\\', '\\', $api_class);
// Check class existence
if( !$this->is_valid_class($api_class) ){
throw new \Exception($this->__('Specified URL is invalid.'), 404);
}
/** @var RestBase $instance */
$instance = $api_class::get_instance();
$instance->parse_request($wp_query->get($this->api_vars), $wp_query);
}catch ( \Exception $e ){
switch( $e->getCode() ){
case 404:
$wp_query->set_404();
break;
case 200:
case 201:
// If status is O.K.
// Do nothing.
break;
default:
wp_die($e->getMessage(), get_status_header_desc($e->getCode()), [
'response' => $e->getCode(),
'back_link' => true,
]);
break;
}
}
}
}
|
[
"public",
"function",
"pre_get_posts",
"(",
"\\",
"WP_Query",
"&",
"$",
"wp_query",
")",
"{",
"if",
"(",
"!",
"is_admin",
"(",
")",
"&&",
"$",
"wp_query",
"->",
"is_main_query",
"(",
")",
"&&",
"(",
"$",
"api_class",
"=",
"$",
"wp_query",
"->",
"get",
"(",
"$",
"this",
"->",
"api_class",
")",
")",
")",
"{",
"// Detect class is valid",
"try",
"{",
"// Fix escaped namespace delimiter",
"$",
"api_class",
"=",
"str_replace",
"(",
"'\\\\\\\\'",
",",
"'\\\\'",
",",
"$",
"api_class",
")",
";",
"// Check class existence",
"if",
"(",
"!",
"$",
"this",
"->",
"is_valid_class",
"(",
"$",
"api_class",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"this",
"->",
"__",
"(",
"'Specified URL is invalid.'",
")",
",",
"404",
")",
";",
"}",
"/** @var RestBase $instance */",
"$",
"instance",
"=",
"$",
"api_class",
"::",
"get_instance",
"(",
")",
";",
"$",
"instance",
"->",
"parse_request",
"(",
"$",
"wp_query",
"->",
"get",
"(",
"$",
"this",
"->",
"api_vars",
")",
",",
"$",
"wp_query",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"switch",
"(",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
"{",
"case",
"404",
":",
"$",
"wp_query",
"->",
"set_404",
"(",
")",
";",
"break",
";",
"case",
"200",
":",
"case",
"201",
":",
"// If status is O.K.",
"// Do nothing.",
"break",
";",
"default",
":",
"wp_die",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"get_status_header_desc",
"(",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
",",
"[",
"'response'",
"=>",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"'back_link'",
"=>",
"true",
",",
"]",
")",
";",
"break",
";",
"}",
"}",
"}",
"}"
] |
Parse request and invoke REST class if possible
@param \WP_Query $wp_query
|
[
"Parse",
"request",
"and",
"invoke",
"REST",
"class",
"if",
"possible"
] |
0939373800815a8396291143d2a57967340da5aa
|
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/API/Rewrite.php#L127-L159
|
20,787 |
hametuha/wpametu
|
src/WPametu/API/Rewrite.php
|
Rewrite.admin_init
|
public function admin_init(){
if( !AjaxBase::is_ajax() && current_user_can('manage_options') ){
if( !empty($this->classes) ){
$rewrites = '';
foreach( $this->classes as $class_name ){
$rewrites .= $this->get_prefix($class_name);
}
$rewrites = md5($rewrites);
if( get_option('rewrite_rules') && $this->rewrite_md5 != $rewrites ){
flush_rewrite_rules();
$last_updated = current_time('timestamp');
update_option($this->option_name, $last_updated);
update_option($this->rewrite_md5_name, $rewrites);
$message = sprintf($this->__('Rewrite rules updated. Last modified date is %s'), date_i18n(get_option('date_format').' '.get_option('time_format'), $last_updated));
add_action('admin_notices', function() use ($message){
printf('<div class="updated"><p>%s</p></div>', $message);
});
}
}
}
}
|
php
|
public function admin_init(){
if( !AjaxBase::is_ajax() && current_user_can('manage_options') ){
if( !empty($this->classes) ){
$rewrites = '';
foreach( $this->classes as $class_name ){
$rewrites .= $this->get_prefix($class_name);
}
$rewrites = md5($rewrites);
if( get_option('rewrite_rules') && $this->rewrite_md5 != $rewrites ){
flush_rewrite_rules();
$last_updated = current_time('timestamp');
update_option($this->option_name, $last_updated);
update_option($this->rewrite_md5_name, $rewrites);
$message = sprintf($this->__('Rewrite rules updated. Last modified date is %s'), date_i18n(get_option('date_format').' '.get_option('time_format'), $last_updated));
add_action('admin_notices', function() use ($message){
printf('<div class="updated"><p>%s</p></div>', $message);
});
}
}
}
}
|
[
"public",
"function",
"admin_init",
"(",
")",
"{",
"if",
"(",
"!",
"AjaxBase",
"::",
"is_ajax",
"(",
")",
"&&",
"current_user_can",
"(",
"'manage_options'",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"classes",
")",
")",
"{",
"$",
"rewrites",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"classes",
"as",
"$",
"class_name",
")",
"{",
"$",
"rewrites",
".=",
"$",
"this",
"->",
"get_prefix",
"(",
"$",
"class_name",
")",
";",
"}",
"$",
"rewrites",
"=",
"md5",
"(",
"$",
"rewrites",
")",
";",
"if",
"(",
"get_option",
"(",
"'rewrite_rules'",
")",
"&&",
"$",
"this",
"->",
"rewrite_md5",
"!=",
"$",
"rewrites",
")",
"{",
"flush_rewrite_rules",
"(",
")",
";",
"$",
"last_updated",
"=",
"current_time",
"(",
"'timestamp'",
")",
";",
"update_option",
"(",
"$",
"this",
"->",
"option_name",
",",
"$",
"last_updated",
")",
";",
"update_option",
"(",
"$",
"this",
"->",
"rewrite_md5_name",
",",
"$",
"rewrites",
")",
";",
"$",
"message",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"__",
"(",
"'Rewrite rules updated. Last modified date is %s'",
")",
",",
"date_i18n",
"(",
"get_option",
"(",
"'date_format'",
")",
".",
"' '",
".",
"get_option",
"(",
"'time_format'",
")",
",",
"$",
"last_updated",
")",
")",
";",
"add_action",
"(",
"'admin_notices'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"message",
")",
"{",
"printf",
"(",
"'<div class=\"updated\"><p>%s</p></div>'",
",",
"$",
"message",
")",
";",
"}",
")",
";",
"}",
"}",
"}",
"}"
] |
Update rewrite rules if possible
|
[
"Update",
"rewrite",
"rules",
"if",
"possible"
] |
0939373800815a8396291143d2a57967340da5aa
|
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/API/Rewrite.php#L187-L207
|
20,788 |
hametuha/wpametu
|
src/WPametu/API/Rewrite.php
|
Rewrite.get_prefix
|
public function get_prefix($class_name){
/** @var RestBase $class_name */
if( !empty($class_name::$prefix) ){
return $class_name::$prefix;
}else{
$seg = explode('\\', $class_name);
$base = $seg[count($seg) - 1];
return $this->str->camel_to_hyphen($base);
}
}
|
php
|
public function get_prefix($class_name){
/** @var RestBase $class_name */
if( !empty($class_name::$prefix) ){
return $class_name::$prefix;
}else{
$seg = explode('\\', $class_name);
$base = $seg[count($seg) - 1];
return $this->str->camel_to_hyphen($base);
}
}
|
[
"public",
"function",
"get_prefix",
"(",
"$",
"class_name",
")",
"{",
"/** @var RestBase $class_name */",
"if",
"(",
"!",
"empty",
"(",
"$",
"class_name",
"::",
"$",
"prefix",
")",
")",
"{",
"return",
"$",
"class_name",
"::",
"$",
"prefix",
";",
"}",
"else",
"{",
"$",
"seg",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"class_name",
")",
";",
"$",
"base",
"=",
"$",
"seg",
"[",
"count",
"(",
"$",
"seg",
")",
"-",
"1",
"]",
";",
"return",
"$",
"this",
"->",
"str",
"->",
"camel_to_hyphen",
"(",
"$",
"base",
")",
";",
"}",
"}"
] |
Get class prefix
@param string $class_name
@return string
|
[
"Get",
"class",
"prefix"
] |
0939373800815a8396291143d2a57967340da5aa
|
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/API/Rewrite.php#L215-L224
|
20,789 |
DotZecker/Larafeed
|
src/Entry.php
|
Entry.prepare
|
public function prepare()
{
// The date format method to use with Carbon to convert the dates
$dateFormatMethod = 'to' . strtolower($this->format) . 'String';
if (null !== $this->pubDate) {
$this->pubDate = Carbon::parse($this->pubDate)->{$dateFormatMethod}();
}
if (null !== $this->updated) {
$this->updated = Carbon::parse($this->updated)->{$dateFormatMethod}();
}
$this->title = strip_tags($this->title);
$this->autoFill();
}
|
php
|
public function prepare()
{
// The date format method to use with Carbon to convert the dates
$dateFormatMethod = 'to' . strtolower($this->format) . 'String';
if (null !== $this->pubDate) {
$this->pubDate = Carbon::parse($this->pubDate)->{$dateFormatMethod}();
}
if (null !== $this->updated) {
$this->updated = Carbon::parse($this->updated)->{$dateFormatMethod}();
}
$this->title = strip_tags($this->title);
$this->autoFill();
}
|
[
"public",
"function",
"prepare",
"(",
")",
"{",
"// The date format method to use with Carbon to convert the dates",
"$",
"dateFormatMethod",
"=",
"'to'",
".",
"strtolower",
"(",
"$",
"this",
"->",
"format",
")",
".",
"'String'",
";",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"pubDate",
")",
"{",
"$",
"this",
"->",
"pubDate",
"=",
"Carbon",
"::",
"parse",
"(",
"$",
"this",
"->",
"pubDate",
")",
"->",
"{",
"$",
"dateFormatMethod",
"}",
"(",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"updated",
")",
"{",
"$",
"this",
"->",
"updated",
"=",
"Carbon",
"::",
"parse",
"(",
"$",
"this",
"->",
"updated",
")",
"->",
"{",
"$",
"dateFormatMethod",
"}",
"(",
")",
";",
"}",
"$",
"this",
"->",
"title",
"=",
"strip_tags",
"(",
"$",
"this",
"->",
"title",
")",
";",
"$",
"this",
"->",
"autoFill",
"(",
")",
";",
"}"
] |
Validate, auto-fill and sanitize the entry
@return void
|
[
"Validate",
"auto",
"-",
"fill",
"and",
"sanitize",
"the",
"entry"
] |
d696e2f97b584ed690fe7ba4ac5d739e266c75dd
|
https://github.com/DotZecker/Larafeed/blob/d696e2f97b584ed690fe7ba4ac5d739e266c75dd/src/Entry.php#L33-L49
|
20,790 |
DotZecker/Larafeed
|
src/Entry.php
|
Entry.autoFill
|
public function autoFill()
{
// The date format method to use with Carbon to convert the dates
$dateFormatMethod = 'to' . strtolower($this->format) . 'String';
if (null === $this->pubDate) {
$this->pubDate = Carbon::parse('now')->{$dateFormatMethod}();
}
if (null === $this->summary) {
$summary = strip_tags($this->content);
$this->summary = substr($summary, 0, 144) . '...';
}
}
|
php
|
public function autoFill()
{
// The date format method to use with Carbon to convert the dates
$dateFormatMethod = 'to' . strtolower($this->format) . 'String';
if (null === $this->pubDate) {
$this->pubDate = Carbon::parse('now')->{$dateFormatMethod}();
}
if (null === $this->summary) {
$summary = strip_tags($this->content);
$this->summary = substr($summary, 0, 144) . '...';
}
}
|
[
"public",
"function",
"autoFill",
"(",
")",
"{",
"// The date format method to use with Carbon to convert the dates",
"$",
"dateFormatMethod",
"=",
"'to'",
".",
"strtolower",
"(",
"$",
"this",
"->",
"format",
")",
".",
"'String'",
";",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"pubDate",
")",
"{",
"$",
"this",
"->",
"pubDate",
"=",
"Carbon",
"::",
"parse",
"(",
"'now'",
")",
"->",
"{",
"$",
"dateFormatMethod",
"}",
"(",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"summary",
")",
"{",
"$",
"summary",
"=",
"strip_tags",
"(",
"$",
"this",
"->",
"content",
")",
";",
"$",
"this",
"->",
"summary",
"=",
"substr",
"(",
"$",
"summary",
",",
"0",
",",
"144",
")",
".",
"'...'",
";",
"}",
"}"
] |
Fill the attributes that can be auto-generated
@return void
|
[
"Fill",
"the",
"attributes",
"that",
"can",
"be",
"auto",
"-",
"generated"
] |
d696e2f97b584ed690fe7ba4ac5d739e266c75dd
|
https://github.com/DotZecker/Larafeed/blob/d696e2f97b584ed690fe7ba4ac5d739e266c75dd/src/Entry.php#L56-L70
|
20,791 |
DevGroup-ru/yii2-users-module
|
src/UsersModule.php
|
UsersModule.buildAliases
|
protected function buildAliases()
{
$this->routes = ArrayHelper::merge($this->defaultRoutes, $this->routes);
foreach ($this->routes as $alias => $route) {
Yii::setAlias($alias, $route);
}
}
|
php
|
protected function buildAliases()
{
$this->routes = ArrayHelper::merge($this->defaultRoutes, $this->routes);
foreach ($this->routes as $alias => $route) {
Yii::setAlias($alias, $route);
}
}
|
[
"protected",
"function",
"buildAliases",
"(",
")",
"{",
"$",
"this",
"->",
"routes",
"=",
"ArrayHelper",
"::",
"merge",
"(",
"$",
"this",
"->",
"defaultRoutes",
",",
"$",
"this",
"->",
"routes",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"routes",
"as",
"$",
"alias",
"=>",
"$",
"route",
")",
"{",
"Yii",
"::",
"setAlias",
"(",
"$",
"alias",
",",
"$",
"route",
")",
";",
"}",
"}"
] |
Sets needed routes aliases
|
[
"Sets",
"needed",
"routes",
"aliases"
] |
ff0103dc55c3462627ccc704c33e70c96053f750
|
https://github.com/DevGroup-ru/yii2-users-module/blob/ff0103dc55c3462627ccc704c33e70c96053f750/src/UsersModule.php#L165-L171
|
20,792 |
phpnfe/tools
|
src/Validar.php
|
Validar.validar
|
public static function validar($xml, $schemaFile)
{
//Para poder pegar os erros caso houver
libxml_use_internal_errors(true);
libxml_clear_errors();
if (is_file($xml)) {
$xml = file_get_contents($xml);
}
$dom = new DOMDocument('1.0', 'utf-8');
$dom->loadXML($xml, LIBXML_NOBLANKS | LIBXML_NOEMPTYTAG);
if (! $dom->schemaValidate($schemaFile)) {
$errors = libxml_get_errors();
$returnErrors = [];
foreach ($errors as $error) {
$returnErrors[] = $error->message . 'at line ' . $error->line;
}
$msg = "Erro ao validar XML:\r\n" . implode("\r\n", $returnErrors);
throw new \Exception($msg);
}
return true;
}
|
php
|
public static function validar($xml, $schemaFile)
{
//Para poder pegar os erros caso houver
libxml_use_internal_errors(true);
libxml_clear_errors();
if (is_file($xml)) {
$xml = file_get_contents($xml);
}
$dom = new DOMDocument('1.0', 'utf-8');
$dom->loadXML($xml, LIBXML_NOBLANKS | LIBXML_NOEMPTYTAG);
if (! $dom->schemaValidate($schemaFile)) {
$errors = libxml_get_errors();
$returnErrors = [];
foreach ($errors as $error) {
$returnErrors[] = $error->message . 'at line ' . $error->line;
}
$msg = "Erro ao validar XML:\r\n" . implode("\r\n", $returnErrors);
throw new \Exception($msg);
}
return true;
}
|
[
"public",
"static",
"function",
"validar",
"(",
"$",
"xml",
",",
"$",
"schemaFile",
")",
"{",
"//Para poder pegar os erros caso houver",
"libxml_use_internal_errors",
"(",
"true",
")",
";",
"libxml_clear_errors",
"(",
")",
";",
"if",
"(",
"is_file",
"(",
"$",
"xml",
")",
")",
"{",
"$",
"xml",
"=",
"file_get_contents",
"(",
"$",
"xml",
")",
";",
"}",
"$",
"dom",
"=",
"new",
"DOMDocument",
"(",
"'1.0'",
",",
"'utf-8'",
")",
";",
"$",
"dom",
"->",
"loadXML",
"(",
"$",
"xml",
",",
"LIBXML_NOBLANKS",
"|",
"LIBXML_NOEMPTYTAG",
")",
";",
"if",
"(",
"!",
"$",
"dom",
"->",
"schemaValidate",
"(",
"$",
"schemaFile",
")",
")",
"{",
"$",
"errors",
"=",
"libxml_get_errors",
"(",
")",
";",
"$",
"returnErrors",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"errors",
"as",
"$",
"error",
")",
"{",
"$",
"returnErrors",
"[",
"]",
"=",
"$",
"error",
"->",
"message",
".",
"'at line '",
".",
"$",
"error",
"->",
"line",
";",
"}",
"$",
"msg",
"=",
"\"Erro ao validar XML:\\r\\n\"",
".",
"implode",
"(",
"\"\\r\\n\"",
",",
"$",
"returnErrors",
")",
";",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"msg",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Valida um xml assinado.
@param $xml
@param $schemaFile
@return bool
@throws \Exception
|
[
"Valida",
"um",
"xml",
"assinado",
"."
] |
303ca311989e0b345071f61b71d2b3bf7ee80454
|
https://github.com/phpnfe/tools/blob/303ca311989e0b345071f61b71d2b3bf7ee80454/src/Validar.php#L15-L42
|
20,793 |
hametuha/wpametu
|
src/WPametu/UI/MetaBox.php
|
MetaBox.override
|
public function override($post_type, $post){
if( $this->is_valid_post_type($post_type) ){
foreach( $this->fields as $name => $vars ){
switch( $name ){
case 'excerpt':
remove_meta_box('postexcerpt', $post_type, 'normal');
break;
case 'post_format':
remove_meta_box('formatdiv', $post_type, 'side');
break;
default:
if( false !== array_search(Taxonomy::class, class_uses($vars['class'])) ){
if( taxonomy_exists($name) ){
if( is_taxonomy_hierarchical($name) ){
$box_id = $name.'div';
}else{
$box_id = 'tagsdiv-'.$name;
}
remove_meta_box($box_id, $post_type, 'side');
}
}else{
// Do nothing
}
break;
}
}
}
}
|
php
|
public function override($post_type, $post){
if( $this->is_valid_post_type($post_type) ){
foreach( $this->fields as $name => $vars ){
switch( $name ){
case 'excerpt':
remove_meta_box('postexcerpt', $post_type, 'normal');
break;
case 'post_format':
remove_meta_box('formatdiv', $post_type, 'side');
break;
default:
if( false !== array_search(Taxonomy::class, class_uses($vars['class'])) ){
if( taxonomy_exists($name) ){
if( is_taxonomy_hierarchical($name) ){
$box_id = $name.'div';
}else{
$box_id = 'tagsdiv-'.$name;
}
remove_meta_box($box_id, $post_type, 'side');
}
}else{
// Do nothing
}
break;
}
}
}
}
|
[
"public",
"function",
"override",
"(",
"$",
"post_type",
",",
"$",
"post",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_valid_post_type",
"(",
"$",
"post_type",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"fields",
"as",
"$",
"name",
"=>",
"$",
"vars",
")",
"{",
"switch",
"(",
"$",
"name",
")",
"{",
"case",
"'excerpt'",
":",
"remove_meta_box",
"(",
"'postexcerpt'",
",",
"$",
"post_type",
",",
"'normal'",
")",
";",
"break",
";",
"case",
"'post_format'",
":",
"remove_meta_box",
"(",
"'formatdiv'",
",",
"$",
"post_type",
",",
"'side'",
")",
";",
"break",
";",
"default",
":",
"if",
"(",
"false",
"!==",
"array_search",
"(",
"Taxonomy",
"::",
"class",
",",
"class_uses",
"(",
"$",
"vars",
"[",
"'class'",
"]",
")",
")",
")",
"{",
"if",
"(",
"taxonomy_exists",
"(",
"$",
"name",
")",
")",
"{",
"if",
"(",
"is_taxonomy_hierarchical",
"(",
"$",
"name",
")",
")",
"{",
"$",
"box_id",
"=",
"$",
"name",
".",
"'div'",
";",
"}",
"else",
"{",
"$",
"box_id",
"=",
"'tagsdiv-'",
".",
"$",
"name",
";",
"}",
"remove_meta_box",
"(",
"$",
"box_id",
",",
"$",
"post_type",
",",
"'side'",
")",
";",
"}",
"}",
"else",
"{",
"// Do nothing",
"}",
"break",
";",
"}",
"}",
"}",
"}"
] |
Override default meta box
@param string $post_type
@param \WP_Post $post
|
[
"Override",
"default",
"meta",
"box"
] |
0939373800815a8396291143d2a57967340da5aa
|
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/UI/MetaBox.php#L117-L144
|
20,794 |
hametuha/wpametu
|
src/WPametu/UI/MetaBox.php
|
MetaBox.render
|
public function render( \WP_Post $post ){
$this->nonce_field();
$this->desc();
echo '<table class="table form-table wpametu-meta-table">';
foreach( $this->loop_fields() as $field ){
if( !is_wp_error($field) ){
/** @var \WPametu\UI\Field\Base $field */
$field->render($post);
}else{
/** @var \WP_Error $field */
printf('<div class="error"><p>%s</p></div>', $field->get_error_message());
}
}
echo '</table>';
}
|
php
|
public function render( \WP_Post $post ){
$this->nonce_field();
$this->desc();
echo '<table class="table form-table wpametu-meta-table">';
foreach( $this->loop_fields() as $field ){
if( !is_wp_error($field) ){
/** @var \WPametu\UI\Field\Base $field */
$field->render($post);
}else{
/** @var \WP_Error $field */
printf('<div class="error"><p>%s</p></div>', $field->get_error_message());
}
}
echo '</table>';
}
|
[
"public",
"function",
"render",
"(",
"\\",
"WP_Post",
"$",
"post",
")",
"{",
"$",
"this",
"->",
"nonce_field",
"(",
")",
";",
"$",
"this",
"->",
"desc",
"(",
")",
";",
"echo",
"'<table class=\"table form-table wpametu-meta-table\">'",
";",
"foreach",
"(",
"$",
"this",
"->",
"loop_fields",
"(",
")",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"is_wp_error",
"(",
"$",
"field",
")",
")",
"{",
"/** @var \\WPametu\\UI\\Field\\Base $field */",
"$",
"field",
"->",
"render",
"(",
"$",
"post",
")",
";",
"}",
"else",
"{",
"/** @var \\WP_Error $field */",
"printf",
"(",
"'<div class=\"error\"><p>%s</p></div>'",
",",
"$",
"field",
"->",
"get_error_message",
"(",
")",
")",
";",
"}",
"}",
"echo",
"'</table>'",
";",
"}"
] |
Render meta box content
@param \WP_Post $post
|
[
"Render",
"meta",
"box",
"content"
] |
0939373800815a8396291143d2a57967340da5aa
|
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/UI/MetaBox.php#L198-L212
|
20,795 |
willhoffmann/domuserp-php
|
src/Resources/Brands/Secondary/Models.php
|
Models.getList
|
public function getList(array $query = [])
{
$list = $this->pagination(
self::DOMUSERP_API_OPERACIONAL . '/marcas/' . $this->brandId . '/modelos',
$query
);
return $list;
}
|
php
|
public function getList(array $query = [])
{
$list = $this->pagination(
self::DOMUSERP_API_OPERACIONAL . '/marcas/' . $this->brandId . '/modelos',
$query
);
return $list;
}
|
[
"public",
"function",
"getList",
"(",
"array",
"$",
"query",
"=",
"[",
"]",
")",
"{",
"$",
"list",
"=",
"$",
"this",
"->",
"pagination",
"(",
"self",
"::",
"DOMUSERP_API_OPERACIONAL",
".",
"'/marcas/'",
".",
"$",
"this",
"->",
"brandId",
".",
"'/modelos'",
",",
"$",
"query",
")",
";",
"return",
"$",
"list",
";",
"}"
] |
List of product models
@param array $query
@return array|string
@throws \GuzzleHttp\Exception\GuzzleException
|
[
"List",
"of",
"product",
"models"
] |
44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6
|
https://github.com/willhoffmann/domuserp-php/blob/44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6/src/Resources/Brands/Secondary/Models.php#L35-L43
|
20,796 |
willhoffmann/domuserp-php
|
src/Resources/Brands/Secondary/Models.php
|
Models.get
|
public function get($id)
{
$data = $this->execute(
self::HTTP_GET,
self::DOMUSERP_API_OPERACIONAL . '/marcas/' . $this->brandId . '/modelos/' . $id
);
return $data;
}
|
php
|
public function get($id)
{
$data = $this->execute(
self::HTTP_GET,
self::DOMUSERP_API_OPERACIONAL . '/marcas/' . $this->brandId . '/modelos/' . $id
);
return $data;
}
|
[
"public",
"function",
"get",
"(",
"$",
"id",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"execute",
"(",
"self",
"::",
"HTTP_GET",
",",
"self",
"::",
"DOMUSERP_API_OPERACIONAL",
".",
"'/marcas/'",
".",
"$",
"this",
"->",
"brandId",
".",
"'/modelos/'",
".",
"$",
"id",
")",
";",
"return",
"$",
"data",
";",
"}"
] |
Gets the product models data according to the id parameter
@param int $id
@return array|string
@throws \GuzzleHttp\Exception\GuzzleException
|
[
"Gets",
"the",
"product",
"models",
"data",
"according",
"to",
"the",
"id",
"parameter"
] |
44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6
|
https://github.com/willhoffmann/domuserp-php/blob/44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6/src/Resources/Brands/Secondary/Models.php#L52-L60
|
20,797 |
WellCommerce/AppBundle
|
Form/DataTransformer/UserGroupPermissionToArrayTransformer.php
|
UserGroupPermissionToArrayTransformer.clearPreviousCollection
|
protected function clearPreviousCollection(Collection $collection)
{
if ($collection->count()) {
foreach ($collection as $item) {
$collection->removeElement($item);
}
}
}
|
php
|
protected function clearPreviousCollection(Collection $collection)
{
if ($collection->count()) {
foreach ($collection as $item) {
$collection->removeElement($item);
}
}
}
|
[
"protected",
"function",
"clearPreviousCollection",
"(",
"Collection",
"$",
"collection",
")",
"{",
"if",
"(",
"$",
"collection",
"->",
"count",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"item",
")",
"{",
"$",
"collection",
"->",
"removeElement",
"(",
"$",
"item",
")",
";",
"}",
"}",
"}"
] |
Resets previous photo collection
@param Collection $collection
|
[
"Resets",
"previous",
"photo",
"collection"
] |
2add687d1c898dd0b24afd611d896e3811a0eac3
|
https://github.com/WellCommerce/AppBundle/blob/2add687d1c898dd0b24afd611d896e3811a0eac3/Form/DataTransformer/UserGroupPermissionToArrayTransformer.php#L78-L85
|
20,798 |
heidelpay/PhpDoc
|
src/phpDocumentor/Transformer/Command/Template/ListCommand.php
|
ListCommand.execute
|
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Available templates:');
foreach ($this->factory->getAllNames() as $template_name) {
$output->writeln('* '.$template_name);
}
$output->writeln('');
}
|
php
|
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Available templates:');
foreach ($this->factory->getAllNames() as $template_name) {
$output->writeln('* '.$template_name);
}
$output->writeln('');
}
|
[
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"'Available templates:'",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"factory",
"->",
"getAllNames",
"(",
")",
"as",
"$",
"template_name",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"'* '",
".",
"$",
"template_name",
")",
";",
"}",
"$",
"output",
"->",
"writeln",
"(",
"''",
")",
";",
"}"
] |
Retrieves all template names from the Template Factory and sends those to stdout.
@param InputInterface $input
@param OutputInterface $output
@return void
|
[
"Retrieves",
"all",
"template",
"names",
"from",
"the",
"Template",
"Factory",
"and",
"sends",
"those",
"to",
"stdout",
"."
] |
5ac9e842cbd4cbb70900533b240c131f3515ee02
|
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Transformer/Command/Template/ListCommand.php#L67-L74
|
20,799 |
surebert/surebert-framework
|
src/sb/Request.php
|
Request.setInput
|
public function setInput(&$post, &$cookie, &$files, &$put, &$delete, &$data)
{
$this->post = $post;
$this->cookie = $cookie;
$this->files = $files;
$this->put = $put;
$this->delete = $delete;
$this->data = $data;
}
|
php
|
public function setInput(&$post, &$cookie, &$files, &$put, &$delete, &$data)
{
$this->post = $post;
$this->cookie = $cookie;
$this->files = $files;
$this->put = $put;
$this->delete = $delete;
$this->data = $data;
}
|
[
"public",
"function",
"setInput",
"(",
"&",
"$",
"post",
",",
"&",
"$",
"cookie",
",",
"&",
"$",
"files",
",",
"&",
"$",
"put",
",",
"&",
"$",
"delete",
",",
"&",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"post",
"=",
"$",
"post",
";",
"$",
"this",
"->",
"cookie",
"=",
"$",
"cookie",
";",
"$",
"this",
"->",
"files",
"=",
"$",
"files",
";",
"$",
"this",
"->",
"put",
"=",
"$",
"put",
";",
"$",
"this",
"->",
"delete",
"=",
"$",
"delete",
";",
"$",
"this",
"->",
"data",
"=",
"$",
"data",
";",
"}"
] |
Sets the input for the request
@param $post
@param $cookie
@param $files
|
[
"Sets",
"the",
"input",
"for",
"the",
"request"
] |
f2f32eb693bd39385ceb93355efb5b2a429f27ce
|
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Request.php#L123-L132
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.