repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
listlengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
listlengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
withfatpanda/illuminate-wordpress
|
src/WordPress/Plugin.php
|
Plugin.registerArtisanCommand
|
protected function registerArtisanCommand()
{
if (!class_exists('WP_CLI')) {
return false;
}
/**
* Run Laravel Artisan for this plugin
*/
\WP_CLI::add_command($this->getCLICommandName(), function() {
$args = [];
// rebuild args, because WP_CLI does stuff to it...
if (!empty($_SERVER['argv'])) {
$args = array_slice($_SERVER['argv'], 2);
array_unshift($args, $_SERVER['argv'][0]);
}
$this->artisan->handle(
new \Symfony\Component\Console\Input\ArgvInput($args),
new \Symfony\Component\Console\Output\ConsoleOutput
);
});
}
|
php
|
protected function registerArtisanCommand()
{
if (!class_exists('WP_CLI')) {
return false;
}
/**
* Run Laravel Artisan for this plugin
*/
\WP_CLI::add_command($this->getCLICommandName(), function() {
$args = [];
// rebuild args, because WP_CLI does stuff to it...
if (!empty($_SERVER['argv'])) {
$args = array_slice($_SERVER['argv'], 2);
array_unshift($args, $_SERVER['argv'][0]);
}
$this->artisan->handle(
new \Symfony\Component\Console\Input\ArgvInput($args),
new \Symfony\Component\Console\Output\ConsoleOutput
);
});
}
|
[
"protected",
"function",
"registerArtisanCommand",
"(",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"'WP_CLI'",
")",
")",
"{",
"return",
"false",
";",
"}",
"/**\n * Run Laravel Artisan for this plugin\n */",
"\\",
"WP_CLI",
"::",
"add_command",
"(",
"$",
"this",
"->",
"getCLICommandName",
"(",
")",
",",
"function",
"(",
")",
"{",
"$",
"args",
"=",
"[",
"]",
";",
"// rebuild args, because WP_CLI does stuff to it...",
"if",
"(",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'argv'",
"]",
")",
")",
"{",
"$",
"args",
"=",
"array_slice",
"(",
"$",
"_SERVER",
"[",
"'argv'",
"]",
",",
"2",
")",
";",
"array_unshift",
"(",
"$",
"args",
",",
"$",
"_SERVER",
"[",
"'argv'",
"]",
"[",
"0",
"]",
")",
";",
"}",
"$",
"this",
"->",
"artisan",
"->",
"handle",
"(",
"new",
"\\",
"Symfony",
"\\",
"Component",
"\\",
"Console",
"\\",
"Input",
"\\",
"ArgvInput",
"(",
"$",
"args",
")",
",",
"new",
"\\",
"Symfony",
"\\",
"Component",
"\\",
"Console",
"\\",
"Output",
"\\",
"ConsoleOutput",
")",
";",
"}",
")",
";",
"}"
] |
Create a WP-CLI command for running Artisan.
|
[
"Create",
"a",
"WP",
"-",
"CLI",
"command",
"for",
"running",
"Artisan",
"."
] |
train
|
https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/WordPress/Plugin.php#L1083-L1106
|
withfatpanda/illuminate-wordpress
|
src/WordPress/Plugin.php
|
Plugin.registerRestRouter
|
protected function registerRestRouter()
{
$this->singleton('FatPanda\Illuminate\WordPress\Http\Router', function() {
// create the router
$router = new Router($this);
$router->setNamespace($this->getRestNamespace());
$router->setVersion($this->getRestVersion());
$router->setControllerClasspath($this->getNamespaceName() . '\\Http\\Controllers');
// load the routes
$plugin = $this;
require $this->basePath('src/routes.php');
return $router;
});
}
|
php
|
protected function registerRestRouter()
{
$this->singleton('FatPanda\Illuminate\WordPress\Http\Router', function() {
// create the router
$router = new Router($this);
$router->setNamespace($this->getRestNamespace());
$router->setVersion($this->getRestVersion());
$router->setControllerClasspath($this->getNamespaceName() . '\\Http\\Controllers');
// load the routes
$plugin = $this;
require $this->basePath('src/routes.php');
return $router;
});
}
|
[
"protected",
"function",
"registerRestRouter",
"(",
")",
"{",
"$",
"this",
"->",
"singleton",
"(",
"'FatPanda\\Illuminate\\WordPress\\Http\\Router'",
",",
"function",
"(",
")",
"{",
"// create the router",
"$",
"router",
"=",
"new",
"Router",
"(",
"$",
"this",
")",
";",
"$",
"router",
"->",
"setNamespace",
"(",
"$",
"this",
"->",
"getRestNamespace",
"(",
")",
")",
";",
"$",
"router",
"->",
"setVersion",
"(",
"$",
"this",
"->",
"getRestVersion",
"(",
")",
")",
";",
"$",
"router",
"->",
"setControllerClasspath",
"(",
"$",
"this",
"->",
"getNamespaceName",
"(",
")",
".",
"'\\\\Http\\\\Controllers'",
")",
";",
"// load the routes",
"$",
"plugin",
"=",
"$",
"this",
";",
"require",
"$",
"this",
"->",
"basePath",
"(",
"'src/routes.php'",
")",
";",
"return",
"$",
"router",
";",
"}",
")",
";",
"}"
] |
Create router instance and load routes
|
[
"Create",
"router",
"instance",
"and",
"load",
"routes"
] |
train
|
https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/WordPress/Plugin.php#L1156-L1170
|
tequila/mongodb-php-lib
|
src/Write/Model/Update.php
|
Update.writeToBulk
|
public function writeToBulk(BulkWrite $bulk)
{
$bulk->update($this->filter, $this->update, $this->options);
}
|
php
|
public function writeToBulk(BulkWrite $bulk)
{
$bulk->update($this->filter, $this->update, $this->options);
}
|
[
"public",
"function",
"writeToBulk",
"(",
"BulkWrite",
"$",
"bulk",
")",
"{",
"$",
"bulk",
"->",
"update",
"(",
"$",
"this",
"->",
"filter",
",",
"$",
"this",
"->",
"update",
",",
"$",
"this",
"->",
"options",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Write/Model/Update.php#L41-L44
|
FrenchFrogs/framework
|
src/Table/Table/Export.php
|
Export.toCsv
|
public function toCsv($filename = null)
{
// on set le nom du fichier
if (!is_null($filename)) {
$this->setFilename($filename);
}
// si pas de nom de fichier setté, on met celui par default
if (!$this->hasFilename()) {
$this->setFilename($this->filenameDefault);
}
// backup du renderer
$renderer = $this->getRenderer();
// render export
$this->setRenderer(new Csv());
// appel du collback
if ($this->hasExport()){
call_user_func($this->export, $this);
}
// rendu
$this->render();
// restore renderer
$this->setRenderer($renderer);
return $this;
}
|
php
|
public function toCsv($filename = null)
{
// on set le nom du fichier
if (!is_null($filename)) {
$this->setFilename($filename);
}
// si pas de nom de fichier setté, on met celui par default
if (!$this->hasFilename()) {
$this->setFilename($this->filenameDefault);
}
// backup du renderer
$renderer = $this->getRenderer();
// render export
$this->setRenderer(new Csv());
// appel du collback
if ($this->hasExport()){
call_user_func($this->export, $this);
}
// rendu
$this->render();
// restore renderer
$this->setRenderer($renderer);
return $this;
}
|
[
"public",
"function",
"toCsv",
"(",
"$",
"filename",
"=",
"null",
")",
"{",
"// on set le nom du fichier",
"if",
"(",
"!",
"is_null",
"(",
"$",
"filename",
")",
")",
"{",
"$",
"this",
"->",
"setFilename",
"(",
"$",
"filename",
")",
";",
"}",
"// si pas de nom de fichier setté, on met celui par default",
"if",
"(",
"!",
"$",
"this",
"->",
"hasFilename",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setFilename",
"(",
"$",
"this",
"->",
"filenameDefault",
")",
";",
"}",
"// backup du renderer",
"$",
"renderer",
"=",
"$",
"this",
"->",
"getRenderer",
"(",
")",
";",
"// render export",
"$",
"this",
"->",
"setRenderer",
"(",
"new",
"Csv",
"(",
")",
")",
";",
"// appel du collback",
"if",
"(",
"$",
"this",
"->",
"hasExport",
"(",
")",
")",
"{",
"call_user_func",
"(",
"$",
"this",
"->",
"export",
",",
"$",
"this",
")",
";",
"}",
"// rendu",
"$",
"this",
"->",
"render",
"(",
")",
";",
"// restore renderer",
"$",
"this",
"->",
"setRenderer",
"(",
"$",
"renderer",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Export dans un fichier CSV
@param $filename
@param bool $download
@return $this
|
[
"Export",
"dans",
"un",
"fichier",
"CSV"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Export.php#L119-L150
|
remialvado/RiakBundle
|
DependencyInjection/Configuration.php
|
Configuration.getConfigTreeBuilder
|
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('riak');
$rootNode
->children()
->arrayNode("clusters")
->useAttributeAsKey('name')
->prototype("array")
->children()
->scalarNode("protocol")->defaultValue(Cluster::DEFAULT_PROTOCOL)->end()
->scalarNode("domain")->defaultValue(Cluster::DEFAULT_DOMAIN)->end()
->scalarNode("port")->defaultValue(Cluster::DEFAULT_PORT)->end()
->scalarNode("client_id")->isRequired()->end()
->scalarNode("max_parallel_calls")->defaultValue(Cluster::DEFAULT_MAX_PARALLEL_CALLS)->end()
->scalarNode("guzzle_client_provider_service")->defaultValue(Cluster::DEFAULT_GUZZLE_CLIENT_PROVIDER_SERVICE)->end()
->arrayNode("buckets")
->useAttributeAsKey('name')
->prototype("array")
->children()
->scalarNode("fqcn")->defaultNull()->end()
->scalarNode("format")->defaultNull()->end()
->scalarNode("class")->defaultValue("\Kbrw\RiakBundle\Model\Bucket\Bucket")->end()
->scalarNode("r")->defaultNull()->end()
->scalarNode("w")->defaultNull()->end()
->scalarNode("rw")->defaultNull()->end()
->scalarNode("dw")->defaultNull()->end()
->end()
->end()
->end()
->end()
->end()
->end()
->end()
;
return $treeBuilder;
}
|
php
|
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('riak');
$rootNode
->children()
->arrayNode("clusters")
->useAttributeAsKey('name')
->prototype("array")
->children()
->scalarNode("protocol")->defaultValue(Cluster::DEFAULT_PROTOCOL)->end()
->scalarNode("domain")->defaultValue(Cluster::DEFAULT_DOMAIN)->end()
->scalarNode("port")->defaultValue(Cluster::DEFAULT_PORT)->end()
->scalarNode("client_id")->isRequired()->end()
->scalarNode("max_parallel_calls")->defaultValue(Cluster::DEFAULT_MAX_PARALLEL_CALLS)->end()
->scalarNode("guzzle_client_provider_service")->defaultValue(Cluster::DEFAULT_GUZZLE_CLIENT_PROVIDER_SERVICE)->end()
->arrayNode("buckets")
->useAttributeAsKey('name')
->prototype("array")
->children()
->scalarNode("fqcn")->defaultNull()->end()
->scalarNode("format")->defaultNull()->end()
->scalarNode("class")->defaultValue("\Kbrw\RiakBundle\Model\Bucket\Bucket")->end()
->scalarNode("r")->defaultNull()->end()
->scalarNode("w")->defaultNull()->end()
->scalarNode("rw")->defaultNull()->end()
->scalarNode("dw")->defaultNull()->end()
->end()
->end()
->end()
->end()
->end()
->end()
->end()
;
return $treeBuilder;
}
|
[
"public",
"function",
"getConfigTreeBuilder",
"(",
")",
"{",
"$",
"treeBuilder",
"=",
"new",
"TreeBuilder",
"(",
")",
";",
"$",
"rootNode",
"=",
"$",
"treeBuilder",
"->",
"root",
"(",
"'riak'",
")",
";",
"$",
"rootNode",
"->",
"children",
"(",
")",
"->",
"arrayNode",
"(",
"\"clusters\"",
")",
"->",
"useAttributeAsKey",
"(",
"'name'",
")",
"->",
"prototype",
"(",
"\"array\"",
")",
"->",
"children",
"(",
")",
"->",
"scalarNode",
"(",
"\"protocol\"",
")",
"->",
"defaultValue",
"(",
"Cluster",
"::",
"DEFAULT_PROTOCOL",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"\"domain\"",
")",
"->",
"defaultValue",
"(",
"Cluster",
"::",
"DEFAULT_DOMAIN",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"\"port\"",
")",
"->",
"defaultValue",
"(",
"Cluster",
"::",
"DEFAULT_PORT",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"\"client_id\"",
")",
"->",
"isRequired",
"(",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"\"max_parallel_calls\"",
")",
"->",
"defaultValue",
"(",
"Cluster",
"::",
"DEFAULT_MAX_PARALLEL_CALLS",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"\"guzzle_client_provider_service\"",
")",
"->",
"defaultValue",
"(",
"Cluster",
"::",
"DEFAULT_GUZZLE_CLIENT_PROVIDER_SERVICE",
")",
"->",
"end",
"(",
")",
"->",
"arrayNode",
"(",
"\"buckets\"",
")",
"->",
"useAttributeAsKey",
"(",
"'name'",
")",
"->",
"prototype",
"(",
"\"array\"",
")",
"->",
"children",
"(",
")",
"->",
"scalarNode",
"(",
"\"fqcn\"",
")",
"->",
"defaultNull",
"(",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"\"format\"",
")",
"->",
"defaultNull",
"(",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"\"class\"",
")",
"->",
"defaultValue",
"(",
"\"\\Kbrw\\RiakBundle\\Model\\Bucket\\Bucket\"",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"\"r\"",
")",
"->",
"defaultNull",
"(",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"\"w\"",
")",
"->",
"defaultNull",
"(",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"\"rw\"",
")",
"->",
"defaultNull",
"(",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"\"dw\"",
")",
"->",
"defaultNull",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
";",
"return",
"$",
"treeBuilder",
";",
"}"
] |
{@inheritDoc}
|
[
"{"
] |
train
|
https://github.com/remialvado/RiakBundle/blob/089ae818738e512a90b2fa93de6c4991242f5b7b/DependencyInjection/Configuration.php#L20-L58
|
Graphiques-Digitale/silverstripe-seo-metadata
|
code/SEO_Metadata_SiteTree_DataExtension.php
|
SEO_Metadata_SiteTree_DataExtension.getSEOFields
|
public function getSEOFields()
{
// Variables
$config = SiteConfig::current_site_config();
$SEO = [];
// Canonical
if ($config->CanonicalEnabled()) {
$SEO[] = ReadonlyField::create('ReadonlyMetaCanonical', 'link rel="canonical"', $this->owner->AbsoluteLink());
}
// Title
if ($config->TitleEnabled()) {
$SEO[] = TextField::create('MetaTitle', 'meta title')
->setAttribute('placeholder', $this->owner->GenerateTitle());
}
// Description
$SEO[] = TextareaField::create('MetaDescription', 'meta description')
->setAttribute('placeholder', $this->owner->GenerateDescriptionFromContent());
// ExtraMeta
if ($config->ExtraMetaEnabled()) {
$SEO[] = TextareaField::create('ExtraMeta', 'Custom Metadata');
}
return $SEO;
}
|
php
|
public function getSEOFields()
{
// Variables
$config = SiteConfig::current_site_config();
$SEO = [];
// Canonical
if ($config->CanonicalEnabled()) {
$SEO[] = ReadonlyField::create('ReadonlyMetaCanonical', 'link rel="canonical"', $this->owner->AbsoluteLink());
}
// Title
if ($config->TitleEnabled()) {
$SEO[] = TextField::create('MetaTitle', 'meta title')
->setAttribute('placeholder', $this->owner->GenerateTitle());
}
// Description
$SEO[] = TextareaField::create('MetaDescription', 'meta description')
->setAttribute('placeholder', $this->owner->GenerateDescriptionFromContent());
// ExtraMeta
if ($config->ExtraMetaEnabled()) {
$SEO[] = TextareaField::create('ExtraMeta', 'Custom Metadata');
}
return $SEO;
}
|
[
"public",
"function",
"getSEOFields",
"(",
")",
"{",
"// Variables",
"$",
"config",
"=",
"SiteConfig",
"::",
"current_site_config",
"(",
")",
";",
"$",
"SEO",
"=",
"[",
"]",
";",
"// Canonical",
"if",
"(",
"$",
"config",
"->",
"CanonicalEnabled",
"(",
")",
")",
"{",
"$",
"SEO",
"[",
"]",
"=",
"ReadonlyField",
"::",
"create",
"(",
"'ReadonlyMetaCanonical'",
",",
"'link rel=\"canonical\"'",
",",
"$",
"this",
"->",
"owner",
"->",
"AbsoluteLink",
"(",
")",
")",
";",
"}",
"// Title",
"if",
"(",
"$",
"config",
"->",
"TitleEnabled",
"(",
")",
")",
"{",
"$",
"SEO",
"[",
"]",
"=",
"TextField",
"::",
"create",
"(",
"'MetaTitle'",
",",
"'meta title'",
")",
"->",
"setAttribute",
"(",
"'placeholder'",
",",
"$",
"this",
"->",
"owner",
"->",
"GenerateTitle",
"(",
")",
")",
";",
"}",
"// Description",
"$",
"SEO",
"[",
"]",
"=",
"TextareaField",
"::",
"create",
"(",
"'MetaDescription'",
",",
"'meta description'",
")",
"->",
"setAttribute",
"(",
"'placeholder'",
",",
"$",
"this",
"->",
"owner",
"->",
"GenerateDescriptionFromContent",
"(",
")",
")",
";",
"// ExtraMeta",
"if",
"(",
"$",
"config",
"->",
"ExtraMetaEnabled",
"(",
")",
")",
"{",
"$",
"SEO",
"[",
"]",
"=",
"TextareaField",
"::",
"create",
"(",
"'ExtraMeta'",
",",
"'Custom Metadata'",
")",
";",
"}",
"return",
"$",
"SEO",
";",
"}"
] |
Gets SEO fields.
@return array
|
[
"Gets",
"SEO",
"fields",
"."
] |
train
|
https://github.com/Graphiques-Digitale/silverstripe-seo-metadata/blob/f92128688a60b6c6b514b6efb1486ac60f4a8e03/code/SEO_Metadata_SiteTree_DataExtension.php#L51-L73
|
Graphiques-Digitale/silverstripe-seo-metadata
|
code/SEO_Metadata_SiteTree_DataExtension.php
|
SEO_Metadata_SiteTree_DataExtension.getFullOutput
|
public function getFullOutput()
{
return array(
LiteralField::create('HeaderMetadata', '<pre class="bold">$Metadata()</pre>'),
LiteralField::create('LiteralMetadata', '<pre>' . nl2br(htmlentities(trim($this->owner->Metadata()), ENT_QUOTES)) . '</pre>')
);
}
|
php
|
public function getFullOutput()
{
return array(
LiteralField::create('HeaderMetadata', '<pre class="bold">$Metadata()</pre>'),
LiteralField::create('LiteralMetadata', '<pre>' . nl2br(htmlentities(trim($this->owner->Metadata()), ENT_QUOTES)) . '</pre>')
);
}
|
[
"public",
"function",
"getFullOutput",
"(",
")",
"{",
"return",
"array",
"(",
"LiteralField",
"::",
"create",
"(",
"'HeaderMetadata'",
",",
"'<pre class=\"bold\">$Metadata()</pre>'",
")",
",",
"LiteralField",
"::",
"create",
"(",
"'LiteralMetadata'",
",",
"'<pre>'",
".",
"nl2br",
"(",
"htmlentities",
"(",
"trim",
"(",
"$",
"this",
"->",
"owner",
"->",
"Metadata",
"(",
")",
")",
",",
"ENT_QUOTES",
")",
")",
".",
"'</pre>'",
")",
")",
";",
"}"
] |
Gets the full output.
@return array
|
[
"Gets",
"the",
"full",
"output",
"."
] |
train
|
https://github.com/Graphiques-Digitale/silverstripe-seo-metadata/blob/f92128688a60b6c6b514b6efb1486ac60f4a8e03/code/SEO_Metadata_SiteTree_DataExtension.php#L80-L86
|
Graphiques-Digitale/silverstripe-seo-metadata
|
code/SEO_Metadata_SiteTree_DataExtension.php
|
SEO_Metadata_SiteTree_DataExtension.Metadata
|
public function Metadata()
{
// variables
$config = SiteConfig::current_site_config();
// begin SEO
$metadata = PHP_EOL . $this->owner->MarkupComment('SEO');
// register extension update hook
$this->owner->extend('updateMetadata', $config, $this->owner, $metadata);
// end
$metadata .= $this->owner->MarkupComment('END SEO');
// return
return $metadata;
}
|
php
|
public function Metadata()
{
// variables
$config = SiteConfig::current_site_config();
// begin SEO
$metadata = PHP_EOL . $this->owner->MarkupComment('SEO');
// register extension update hook
$this->owner->extend('updateMetadata', $config, $this->owner, $metadata);
// end
$metadata .= $this->owner->MarkupComment('END SEO');
// return
return $metadata;
}
|
[
"public",
"function",
"Metadata",
"(",
")",
"{",
"// variables",
"$",
"config",
"=",
"SiteConfig",
"::",
"current_site_config",
"(",
")",
";",
"// begin SEO",
"$",
"metadata",
"=",
"PHP_EOL",
".",
"$",
"this",
"->",
"owner",
"->",
"MarkupComment",
"(",
"'SEO'",
")",
";",
"// register extension update hook",
"$",
"this",
"->",
"owner",
"->",
"extend",
"(",
"'updateMetadata'",
",",
"$",
"config",
",",
"$",
"this",
"->",
"owner",
",",
"$",
"metadata",
")",
";",
"// end",
"$",
"metadata",
".=",
"$",
"this",
"->",
"owner",
"->",
"MarkupComment",
"(",
"'END SEO'",
")",
";",
"// return",
"return",
"$",
"metadata",
";",
"}"
] |
Main function to format & output metadata as an HTML string.
Use the `updateMetadata($config, $owner, $metadata)` update hook when extending `DataExtension`s.
@return string
|
[
"Main",
"function",
"to",
"format",
"&",
"output",
"metadata",
"as",
"an",
"HTML",
"string",
"."
] |
train
|
https://github.com/Graphiques-Digitale/silverstripe-seo-metadata/blob/f92128688a60b6c6b514b6efb1486ac60f4a8e03/code/SEO_Metadata_SiteTree_DataExtension.php#L95-L107
|
Graphiques-Digitale/silverstripe-seo-metadata
|
code/SEO_Metadata_SiteTree_DataExtension.php
|
SEO_Metadata_SiteTree_DataExtension.updateMetadata
|
public function updateMetadata(SiteConfig $config, SiteTree $owner, &$metadata)
{
// metadata
$metadata .= $owner->MarkupComment('Metadata');
// charset
if ($config->CharsetEnabled()) {
$metadata .= '<meta charset="' . $config->Charset() . '" />' . PHP_EOL;
}
// canonical
if ($config->CanonicalEnabled()) {
$metadata .= $owner->MarkupLink('canonical', $owner->AbsoluteLink());
}
// title
if ($config->TitleEnabled()) {
$metadata .= '<title>' . $owner->encodeContent($owner->GenerateTitle(), $config->Charset()) . '</title>' . PHP_EOL;
}
// description
if ($description = $owner->GenerateDescription()) {
$metadata .= $owner->MarkupMeta('description', $description, $config->Charset());
}
// extra metadata
if ($config->ExtraMetaEnabled()) {
$metadata .= $owner->MarkupComment('Extra Metadata');
$metadata .= $owner->GenerateExtraMeta();
}
}
|
php
|
public function updateMetadata(SiteConfig $config, SiteTree $owner, &$metadata)
{
// metadata
$metadata .= $owner->MarkupComment('Metadata');
// charset
if ($config->CharsetEnabled()) {
$metadata .= '<meta charset="' . $config->Charset() . '" />' . PHP_EOL;
}
// canonical
if ($config->CanonicalEnabled()) {
$metadata .= $owner->MarkupLink('canonical', $owner->AbsoluteLink());
}
// title
if ($config->TitleEnabled()) {
$metadata .= '<title>' . $owner->encodeContent($owner->GenerateTitle(), $config->Charset()) . '</title>' . PHP_EOL;
}
// description
if ($description = $owner->GenerateDescription()) {
$metadata .= $owner->MarkupMeta('description', $description, $config->Charset());
}
// extra metadata
if ($config->ExtraMetaEnabled()) {
$metadata .= $owner->MarkupComment('Extra Metadata');
$metadata .= $owner->GenerateExtraMeta();
}
}
|
[
"public",
"function",
"updateMetadata",
"(",
"SiteConfig",
"$",
"config",
",",
"SiteTree",
"$",
"owner",
",",
"&",
"$",
"metadata",
")",
"{",
"// metadata",
"$",
"metadata",
".=",
"$",
"owner",
"->",
"MarkupComment",
"(",
"'Metadata'",
")",
";",
"// charset",
"if",
"(",
"$",
"config",
"->",
"CharsetEnabled",
"(",
")",
")",
"{",
"$",
"metadata",
".=",
"'<meta charset=\"'",
".",
"$",
"config",
"->",
"Charset",
"(",
")",
".",
"'\" />'",
".",
"PHP_EOL",
";",
"}",
"// canonical",
"if",
"(",
"$",
"config",
"->",
"CanonicalEnabled",
"(",
")",
")",
"{",
"$",
"metadata",
".=",
"$",
"owner",
"->",
"MarkupLink",
"(",
"'canonical'",
",",
"$",
"owner",
"->",
"AbsoluteLink",
"(",
")",
")",
";",
"}",
"// title",
"if",
"(",
"$",
"config",
"->",
"TitleEnabled",
"(",
")",
")",
"{",
"$",
"metadata",
".=",
"'<title>'",
".",
"$",
"owner",
"->",
"encodeContent",
"(",
"$",
"owner",
"->",
"GenerateTitle",
"(",
")",
",",
"$",
"config",
"->",
"Charset",
"(",
")",
")",
".",
"'</title>'",
".",
"PHP_EOL",
";",
"}",
"// description",
"if",
"(",
"$",
"description",
"=",
"$",
"owner",
"->",
"GenerateDescription",
"(",
")",
")",
"{",
"$",
"metadata",
".=",
"$",
"owner",
"->",
"MarkupMeta",
"(",
"'description'",
",",
"$",
"description",
",",
"$",
"config",
"->",
"Charset",
"(",
")",
")",
";",
"}",
"// extra metadata",
"if",
"(",
"$",
"config",
"->",
"ExtraMetaEnabled",
"(",
")",
")",
"{",
"$",
"metadata",
".=",
"$",
"owner",
"->",
"MarkupComment",
"(",
"'Extra Metadata'",
")",
";",
"$",
"metadata",
".=",
"$",
"owner",
"->",
"GenerateExtraMeta",
"(",
")",
";",
"}",
"}"
] |
Updates metadata fields.
@param SiteConfig $config
@param SiteTree $owner
@param string $metadata
@return void
|
[
"Updates",
"metadata",
"fields",
"."
] |
train
|
https://github.com/Graphiques-Digitale/silverstripe-seo-metadata/blob/f92128688a60b6c6b514b6efb1486ac60f4a8e03/code/SEO_Metadata_SiteTree_DataExtension.php#L122-L147
|
Graphiques-Digitale/silverstripe-seo-metadata
|
code/SEO_Metadata_SiteTree_DataExtension.php
|
SEO_Metadata_SiteTree_DataExtension.MarkupMeta
|
public function MarkupMeta($name, $content, $encode = null)
{
if ($encode !== null) {
return '<meta name="' . $name . '" content="' . $this->encodeContent($content, $encode) . '" />' . PHP_EOL;
} else {
return '<meta name="' . $name . '" content="' . $content . '" />' . PHP_EOL;
}
}
|
php
|
public function MarkupMeta($name, $content, $encode = null)
{
if ($encode !== null) {
return '<meta name="' . $name . '" content="' . $this->encodeContent($content, $encode) . '" />' . PHP_EOL;
} else {
return '<meta name="' . $name . '" content="' . $content . '" />' . PHP_EOL;
}
}
|
[
"public",
"function",
"MarkupMeta",
"(",
"$",
"name",
",",
"$",
"content",
",",
"$",
"encode",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"encode",
"!==",
"null",
")",
"{",
"return",
"'<meta name=\"'",
".",
"$",
"name",
".",
"'\" content=\"'",
".",
"$",
"this",
"->",
"encodeContent",
"(",
"$",
"content",
",",
"$",
"encode",
")",
".",
"'\" />'",
".",
"PHP_EOL",
";",
"}",
"else",
"{",
"return",
"'<meta name=\"'",
".",
"$",
"name",
".",
"'\" content=\"'",
".",
"$",
"content",
".",
"'\" />'",
".",
"PHP_EOL",
";",
"}",
"}"
] |
Returns markup for a HTML meta element. Can be flagged for encoding.
@param string $name
@param string $content
@param string|null $encode
@return string
|
[
"Returns",
"markup",
"for",
"a",
"HTML",
"meta",
"element",
".",
"Can",
"be",
"flagged",
"for",
"encoding",
"."
] |
train
|
https://github.com/Graphiques-Digitale/silverstripe-seo-metadata/blob/f92128688a60b6c6b514b6efb1486ac60f4a8e03/code/SEO_Metadata_SiteTree_DataExtension.php#L174-L181
|
Graphiques-Digitale/silverstripe-seo-metadata
|
code/SEO_Metadata_SiteTree_DataExtension.php
|
SEO_Metadata_SiteTree_DataExtension.MarkupLink
|
public function MarkupLink($rel, $href, $type = null, $sizes = null)
{
// start fragment
$return = '<link rel="' . $rel . '" href="' . $href . '"';
// if type
if ($type !== null) {
$return .= ' type="' . $type . '"';
}
// if sizes
if ($sizes !== null) {
$return .= ' sizes="' . $sizes . '"';
}
// end fragment
$return .= ' />' . PHP_EOL;
// return
return $return;
}
|
php
|
public function MarkupLink($rel, $href, $type = null, $sizes = null)
{
// start fragment
$return = '<link rel="' . $rel . '" href="' . $href . '"';
// if type
if ($type !== null) {
$return .= ' type="' . $type . '"';
}
// if sizes
if ($sizes !== null) {
$return .= ' sizes="' . $sizes . '"';
}
// end fragment
$return .= ' />' . PHP_EOL;
// return
return $return;
}
|
[
"public",
"function",
"MarkupLink",
"(",
"$",
"rel",
",",
"$",
"href",
",",
"$",
"type",
"=",
"null",
",",
"$",
"sizes",
"=",
"null",
")",
"{",
"// start fragment",
"$",
"return",
"=",
"'<link rel=\"'",
".",
"$",
"rel",
".",
"'\" href=\"'",
".",
"$",
"href",
".",
"'\"'",
";",
"// if type",
"if",
"(",
"$",
"type",
"!==",
"null",
")",
"{",
"$",
"return",
".=",
"' type=\"'",
".",
"$",
"type",
".",
"'\"'",
";",
"}",
"// if sizes",
"if",
"(",
"$",
"sizes",
"!==",
"null",
")",
"{",
"$",
"return",
".=",
"' sizes=\"'",
".",
"$",
"sizes",
".",
"'\"'",
";",
"}",
"// end fragment",
"$",
"return",
".=",
"' />'",
".",
"PHP_EOL",
";",
"// return",
"return",
"$",
"return",
";",
"}"
] |
Returns markup for a HTML link element.
@param string $rel
@param string $href
@param string|null $type
@param string|null $sizes
@return string
|
[
"Returns",
"markup",
"for",
"a",
"HTML",
"link",
"element",
"."
] |
train
|
https://github.com/Graphiques-Digitale/silverstripe-seo-metadata/blob/f92128688a60b6c6b514b6efb1486ac60f4a8e03/code/SEO_Metadata_SiteTree_DataExtension.php#L193-L209
|
Graphiques-Digitale/silverstripe-seo-metadata
|
code/SEO_Metadata_SiteTree_DataExtension.php
|
SEO_Metadata_SiteTree_DataExtension.GenerateTitle
|
public function GenerateTitle()
{
if ($this->owner->MetaTitle) {
return $this->owner->MetaTitle;
} else {
return SiteConfig::current_site_config()->GenerateTitle($this->owner->Title);
}
}
|
php
|
public function GenerateTitle()
{
if ($this->owner->MetaTitle) {
return $this->owner->MetaTitle;
} else {
return SiteConfig::current_site_config()->GenerateTitle($this->owner->Title);
}
}
|
[
"public",
"function",
"GenerateTitle",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"owner",
"->",
"MetaTitle",
")",
"{",
"return",
"$",
"this",
"->",
"owner",
"->",
"MetaTitle",
";",
"}",
"else",
"{",
"return",
"SiteConfig",
"::",
"current_site_config",
"(",
")",
"->",
"GenerateTitle",
"(",
"$",
"this",
"->",
"owner",
"->",
"Title",
")",
";",
"}",
"}"
] |
Generates HTML title based on configuration settings.
@return string|null
|
[
"Generates",
"HTML",
"title",
"based",
"on",
"configuration",
"settings",
"."
] |
train
|
https://github.com/Graphiques-Digitale/silverstripe-seo-metadata/blob/f92128688a60b6c6b514b6efb1486ac60f4a8e03/code/SEO_Metadata_SiteTree_DataExtension.php#L220-L227
|
Graphiques-Digitale/silverstripe-seo-metadata
|
code/SEO_Metadata_SiteTree_DataExtension.php
|
SEO_Metadata_SiteTree_DataExtension.GenerateDescription
|
public function GenerateDescription()
{
if ($this->owner->MetaDescription) {
return $this->owner->MetaDescription;
} else {
return $this->owner->GenerateDescriptionFromContent();
}
}
|
php
|
public function GenerateDescription()
{
if ($this->owner->MetaDescription) {
return $this->owner->MetaDescription;
} else {
return $this->owner->GenerateDescriptionFromContent();
}
}
|
[
"public",
"function",
"GenerateDescription",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"owner",
"->",
"MetaDescription",
")",
"{",
"return",
"$",
"this",
"->",
"owner",
"->",
"MetaDescription",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"owner",
"->",
"GenerateDescriptionFromContent",
"(",
")",
";",
"}",
"}"
] |
Generates description from the page `MetaDescription`, or the first paragraph of the `Content` attribute.
@return string|null
|
[
"Generates",
"description",
"from",
"the",
"page",
"MetaDescription",
"or",
"the",
"first",
"paragraph",
"of",
"the",
"Content",
"attribute",
"."
] |
train
|
https://github.com/Graphiques-Digitale/silverstripe-seo-metadata/blob/f92128688a60b6c6b514b6efb1486ac60f4a8e03/code/SEO_Metadata_SiteTree_DataExtension.php#L234-L241
|
Graphiques-Digitale/silverstripe-seo-metadata
|
code/SEO_Metadata_SiteTree_DataExtension.php
|
SEO_Metadata_SiteTree_DataExtension.GenerateDescriptionFromContent
|
public function GenerateDescriptionFromContent()
{
// check for content
if ($content = trim($this->owner->Content)) {
// pillage first paragraph from page content
if (preg_match('/<p>(.*?)<\/p>/i', $content, $match)) {
// is HTML
$content = $match[0];
} else {
// is plain text
$content = explode(PHP_EOL, $content);
$content = $content[0];
}
// decode (no harm done) & return
return trim(html_entity_decode(strip_tags($content)));
} else {
return null;
}
}
|
php
|
public function GenerateDescriptionFromContent()
{
// check for content
if ($content = trim($this->owner->Content)) {
// pillage first paragraph from page content
if (preg_match('/<p>(.*?)<\/p>/i', $content, $match)) {
// is HTML
$content = $match[0];
} else {
// is plain text
$content = explode(PHP_EOL, $content);
$content = $content[0];
}
// decode (no harm done) & return
return trim(html_entity_decode(strip_tags($content)));
} else {
return null;
}
}
|
[
"public",
"function",
"GenerateDescriptionFromContent",
"(",
")",
"{",
"// check for content",
"if",
"(",
"$",
"content",
"=",
"trim",
"(",
"$",
"this",
"->",
"owner",
"->",
"Content",
")",
")",
"{",
"// pillage first paragraph from page content",
"if",
"(",
"preg_match",
"(",
"'/<p>(.*?)<\\/p>/i'",
",",
"$",
"content",
",",
"$",
"match",
")",
")",
"{",
"// is HTML",
"$",
"content",
"=",
"$",
"match",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"// is plain text",
"$",
"content",
"=",
"explode",
"(",
"PHP_EOL",
",",
"$",
"content",
")",
";",
"$",
"content",
"=",
"$",
"content",
"[",
"0",
"]",
";",
"}",
"// decode (no harm done) & return",
"return",
"trim",
"(",
"html_entity_decode",
"(",
"strip_tags",
"(",
"$",
"content",
")",
")",
")",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] |
Generates description from the first paragraph of the `Content` attribute.
@return string|null
|
[
"Generates",
"description",
"from",
"the",
"first",
"paragraph",
"of",
"the",
"Content",
"attribute",
"."
] |
train
|
https://github.com/Graphiques-Digitale/silverstripe-seo-metadata/blob/f92128688a60b6c6b514b6efb1486ac60f4a8e03/code/SEO_Metadata_SiteTree_DataExtension.php#L248-L266
|
Graphiques-Digitale/silverstripe-seo-metadata
|
code/SEO_Metadata_SiteTree_DataExtension.php
|
SEO_Metadata_SiteTree_DataExtension.GenerateExtraMeta
|
public function GenerateExtraMeta()
{
if ($this->owner->ExtraMeta) {
return $this->owner->ExtraMeta . PHP_EOL;
} else {
return $this->owner->MarkupComment('none');
}
}
|
php
|
public function GenerateExtraMeta()
{
if ($this->owner->ExtraMeta) {
return $this->owner->ExtraMeta . PHP_EOL;
} else {
return $this->owner->MarkupComment('none');
}
}
|
[
"public",
"function",
"GenerateExtraMeta",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"owner",
"->",
"ExtraMeta",
")",
"{",
"return",
"$",
"this",
"->",
"owner",
"->",
"ExtraMeta",
".",
"PHP_EOL",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"owner",
"->",
"MarkupComment",
"(",
"'none'",
")",
";",
"}",
"}"
] |
Generates extra metadata.
@return string
|
[
"Generates",
"extra",
"metadata",
"."
] |
train
|
https://github.com/Graphiques-Digitale/silverstripe-seo-metadata/blob/f92128688a60b6c6b514b6efb1486ac60f4a8e03/code/SEO_Metadata_SiteTree_DataExtension.php#L273-L280
|
phossa2/middleware
|
src/Middleware/Middleware/Phossa2RouteMiddleware.php
|
Phossa2RouteMiddleware.before
|
protected function before(
RequestInterface $request,
ResponseInterface $response
)/* : ResponseInterface */ {
$this->dispatcher->dispatch(
$request->getMethod(),
$request->getUri()->getPath(),
['request' => $request, 'response' => $response]
);
// response in the result
return $this->dispatcher->getResult()->getParameters()['response'];
}
|
php
|
protected function before(
RequestInterface $request,
ResponseInterface $response
)/* : ResponseInterface */ {
$this->dispatcher->dispatch(
$request->getMethod(),
$request->getUri()->getPath(),
['request' => $request, 'response' => $response]
);
// response in the result
return $this->dispatcher->getResult()->getParameters()['response'];
}
|
[
"protected",
"function",
"before",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"/* : ResponseInterface */",
"{",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
",",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"getPath",
"(",
")",
",",
"[",
"'request'",
"=>",
"$",
"request",
",",
"'response'",
"=>",
"$",
"response",
"]",
")",
";",
"// response in the result",
"return",
"$",
"this",
"->",
"dispatcher",
"->",
"getResult",
"(",
")",
"->",
"getParameters",
"(",
")",
"[",
"'response'",
"]",
";",
"}"
] |
{@inheritDoc}
|
[
"{"
] |
train
|
https://github.com/phossa2/middleware/blob/518e97ae48077f2c11adcd3c2393830ed7ab7ce7/src/Middleware/Middleware/Phossa2RouteMiddleware.php#L52-L64
|
o2system/filesystem
|
src/System.php
|
System.getMacAddress
|
public function getMacAddress()
{
switch (PHP_OS) {
default:
case 'Darwin':
case 'FreeBSD':
$cmd = '/sbin/ifconfig';
break;
case 'Windows':
$cmd = "ipconfig /all ";
break;
}
$string = trim(shell_exec($cmd));
if (preg_match_all('/([0-9a-f]{2}:){5}\w\w/i', $string, $matches)) {
if (isset($matches[ 0 ])) {
return reset($matches[ 0 ]); // get first mac address
}
} else {
return implode(':', str_split(substr(md5('none'), 0, 12), 2));
}
}
|
php
|
public function getMacAddress()
{
switch (PHP_OS) {
default:
case 'Darwin':
case 'FreeBSD':
$cmd = '/sbin/ifconfig';
break;
case 'Windows':
$cmd = "ipconfig /all ";
break;
}
$string = trim(shell_exec($cmd));
if (preg_match_all('/([0-9a-f]{2}:){5}\w\w/i', $string, $matches)) {
if (isset($matches[ 0 ])) {
return reset($matches[ 0 ]); // get first mac address
}
} else {
return implode(':', str_split(substr(md5('none'), 0, 12), 2));
}
}
|
[
"public",
"function",
"getMacAddress",
"(",
")",
"{",
"switch",
"(",
"PHP_OS",
")",
"{",
"default",
":",
"case",
"'Darwin'",
":",
"case",
"'FreeBSD'",
":",
"$",
"cmd",
"=",
"'/sbin/ifconfig'",
";",
"break",
";",
"case",
"'Windows'",
":",
"$",
"cmd",
"=",
"\"ipconfig /all \"",
";",
"break",
";",
"}",
"$",
"string",
"=",
"trim",
"(",
"shell_exec",
"(",
"$",
"cmd",
")",
")",
";",
"if",
"(",
"preg_match_all",
"(",
"'/([0-9a-f]{2}:){5}\\w\\w/i'",
",",
"$",
"string",
",",
"$",
"matches",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"matches",
"[",
"0",
"]",
")",
")",
"{",
"return",
"reset",
"(",
"$",
"matches",
"[",
"0",
"]",
")",
";",
"// get first mac address",
"}",
"}",
"else",
"{",
"return",
"implode",
"(",
"':'",
",",
"str_split",
"(",
"substr",
"(",
"md5",
"(",
"'none'",
")",
",",
"0",
",",
"12",
")",
",",
"2",
")",
")",
";",
"}",
"}"
] |
System::getMacAddress
Gets system mac address.
@return string
|
[
"System",
"::",
"getMacAddress"
] |
train
|
https://github.com/o2system/filesystem/blob/58f6515f56bcc92408dc155add570c99a0abb6e8/src/System.php#L242-L264
|
o2system/filesystem
|
src/System.php
|
System.getLoadAvg
|
public function getLoadAvg($interval = 1)
{
$rs = sys_getloadavg();
$interval = $interval >= 1 && 3 <= $interval ? $interval : 1;
$load = $rs[ $interval ];
return round(($load * 100) / $this->getCpuCores(), 2);
}
|
php
|
public function getLoadAvg($interval = 1)
{
$rs = sys_getloadavg();
$interval = $interval >= 1 && 3 <= $interval ? $interval : 1;
$load = $rs[ $interval ];
return round(($load * 100) / $this->getCpuCores(), 2);
}
|
[
"public",
"function",
"getLoadAvg",
"(",
"$",
"interval",
"=",
"1",
")",
"{",
"$",
"rs",
"=",
"sys_getloadavg",
"(",
")",
";",
"$",
"interval",
"=",
"$",
"interval",
">=",
"1",
"&&",
"3",
"<=",
"$",
"interval",
"?",
"$",
"interval",
":",
"1",
";",
"$",
"load",
"=",
"$",
"rs",
"[",
"$",
"interval",
"]",
";",
"return",
"round",
"(",
"(",
"$",
"load",
"*",
"100",
")",
"/",
"$",
"this",
"->",
"getCpuCores",
"(",
")",
",",
"2",
")",
";",
"}"
] |
System::getLoadAvg
Gets system load averages.
@param int $interval
@return float
|
[
"System",
"::",
"getLoadAvg"
] |
train
|
https://github.com/o2system/filesystem/blob/58f6515f56bcc92408dc155add570c99a0abb6e8/src/System.php#L277-L284
|
yoanm/php-jsonrpc-http-server-openapi-doc-sdk
|
features/bootstrap/DocNormalizerContext.php
|
DocNormalizerContext.extractPath
|
private function extractPath($httpMethod, $pathName)
{
return $this->lastNormalizedOutput[self::PATHS_KEY][$pathName][strtolower($httpMethod)];
}
|
php
|
private function extractPath($httpMethod, $pathName)
{
return $this->lastNormalizedOutput[self::PATHS_KEY][$pathName][strtolower($httpMethod)];
}
|
[
"private",
"function",
"extractPath",
"(",
"$",
"httpMethod",
",",
"$",
"pathName",
")",
"{",
"return",
"$",
"this",
"->",
"lastNormalizedOutput",
"[",
"self",
"::",
"PATHS_KEY",
"]",
"[",
"$",
"pathName",
"]",
"[",
"strtolower",
"(",
"$",
"httpMethod",
")",
"]",
";",
"}"
] |
@param $httpMethod
@param $pathName
@return mixed
|
[
"@param",
"$httpMethod",
"@param",
"$pathName"
] |
train
|
https://github.com/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/blob/52d6bb5d0671e0363bbf482c3c75fef97d7d1d5e/features/bootstrap/DocNormalizerContext.php#L461-L464
|
bdunogier/xmlrpcbundle
|
XmlRpc/Handler/Custom/ResponseGenerator.php
|
ResponseGenerator.fromXmlRpcResponse
|
public function fromXmlRpcResponse( Response $xmlRpcResponse )
{
$response = new HttpResponse();
$response->setStatusCode( 200 );
$response->headers->set( 'Content-Type', 'text/xml' );
$response->setContent( $this->generateXml( $xmlRpcResponse->return ) );
return $response;
}
|
php
|
public function fromXmlRpcResponse( Response $xmlRpcResponse )
{
$response = new HttpResponse();
$response->setStatusCode( 200 );
$response->headers->set( 'Content-Type', 'text/xml' );
$response->setContent( $this->generateXml( $xmlRpcResponse->return ) );
return $response;
}
|
[
"public",
"function",
"fromXmlRpcResponse",
"(",
"Response",
"$",
"xmlRpcResponse",
")",
"{",
"$",
"response",
"=",
"new",
"HttpResponse",
"(",
")",
";",
"$",
"response",
"->",
"setStatusCode",
"(",
"200",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'Content-Type'",
",",
"'text/xml'",
")",
";",
"$",
"response",
"->",
"setContent",
"(",
"$",
"this",
"->",
"generateXml",
"(",
"$",
"xmlRpcResponse",
"->",
"return",
")",
")",
";",
"return",
"$",
"response",
";",
"}"
] |
Generates an XML-RPC HTTP response for $xmlRpcResponse
@param \BD\Bundle\XmlRpcBundle\XmlRpc\Response
@return \Symfony\Component\HttpFoundation\Response
|
[
"Generates",
"an",
"XML",
"-",
"RPC",
"HTTP",
"response",
"for",
"$xmlRpcResponse"
] |
train
|
https://github.com/bdunogier/xmlrpcbundle/blob/9a3d59609131d438d259b3ae2c113bb4b813a16b/XmlRpc/Handler/Custom/ResponseGenerator.php#L24-L31
|
bdunogier/xmlrpcbundle
|
XmlRpc/Handler/Custom/ResponseGenerator.php
|
ResponseGenerator.fromException
|
public function fromException( Exception $exception )
{
$response = new HttpResponse();
$response->setStatusCode( 200 );
$response->headers->set( 'Content-Type', 'text/xml' );
$response->setContent( $this->generateXmlFromException( $exception ) );
return $response;
}
|
php
|
public function fromException( Exception $exception )
{
$response = new HttpResponse();
$response->setStatusCode( 200 );
$response->headers->set( 'Content-Type', 'text/xml' );
$response->setContent( $this->generateXmlFromException( $exception ) );
return $response;
}
|
[
"public",
"function",
"fromException",
"(",
"Exception",
"$",
"exception",
")",
"{",
"$",
"response",
"=",
"new",
"HttpResponse",
"(",
")",
";",
"$",
"response",
"->",
"setStatusCode",
"(",
"200",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'Content-Type'",
",",
"'text/xml'",
")",
";",
"$",
"response",
"->",
"setContent",
"(",
"$",
"this",
"->",
"generateXmlFromException",
"(",
"$",
"exception",
")",
")",
";",
"return",
"$",
"response",
";",
"}"
] |
Generates an XMLRPC HTTP response for the Exception $e
@param \Exception $e
@return \Symfony\Component\HttpFoundation\Response
|
[
"Generates",
"an",
"XMLRPC",
"HTTP",
"response",
"for",
"the",
"Exception",
"$e"
] |
train
|
https://github.com/bdunogier/xmlrpcbundle/blob/9a3d59609131d438d259b3ae2c113bb4b813a16b/XmlRpc/Handler/Custom/ResponseGenerator.php#L38-L45
|
bdunogier/xmlrpcbundle
|
XmlRpc/Handler/Custom/ResponseGenerator.php
|
ResponseGenerator.handleValue
|
private function handleValue( $value, DOMDocument $domDocument )
{
switch ( gettype( $value ) )
{
case 'integer':
$node = $domDocument->createElement( 'int', $value );
break;
case 'boolean':
$node = $domDocument->createElement( 'boolean', $value );
break;
case 'string':
$node = $domDocument->createElement( 'string', $value );
break;
case 'double':
$node = $domDocument->createElement( 'double', $value );
break;
case 'array':
// array
if ( empty( $value ) || key( $value ) === 0 )
{
$node = $domDocument->createElement( 'array' );
$dataNode = $domDocument->createElement( 'data' );
$node->appendChild( $dataNode );
foreach ( $value as $cell )
{
$valueNode = $domDocument->createElement( 'value' );
$valueNode->appendChild( $this->handleValue( $cell, $domDocument ) );
$dataNode->appendChild( $valueNode );
}
}
// hash
else
{
$node = $domDocument->createElement( 'struct' );
foreach ( $value as $name => $cell )
{
// //member
$memberNode = $domDocument->createElement( 'member' );
// //member/name
$memberNode->appendChild( $domDocument->createElement( 'name', $name ) );
// //member/value
$valueNode = $domDocument->createElement( 'value' );
$memberNode->appendChild( $valueNode );
// //member/value/*
$valueNode->appendChild( $this->handleValue( $cell, $domDocument ) );
$node->appendChild( $memberNode );
}
}
break;
case 'object':
{
// DateTime is okay
if ( !$value instanceof DateTime )
continue;
$node = $domDocument->createElement( 'dateTime.iso8601', $value->format( DateTime::ISO8601 ) );
}
break;
default:
{
throw new \UnexpectedValueException( "Unknown return value type" );
}
}
return $node;
}
|
php
|
private function handleValue( $value, DOMDocument $domDocument )
{
switch ( gettype( $value ) )
{
case 'integer':
$node = $domDocument->createElement( 'int', $value );
break;
case 'boolean':
$node = $domDocument->createElement( 'boolean', $value );
break;
case 'string':
$node = $domDocument->createElement( 'string', $value );
break;
case 'double':
$node = $domDocument->createElement( 'double', $value );
break;
case 'array':
// array
if ( empty( $value ) || key( $value ) === 0 )
{
$node = $domDocument->createElement( 'array' );
$dataNode = $domDocument->createElement( 'data' );
$node->appendChild( $dataNode );
foreach ( $value as $cell )
{
$valueNode = $domDocument->createElement( 'value' );
$valueNode->appendChild( $this->handleValue( $cell, $domDocument ) );
$dataNode->appendChild( $valueNode );
}
}
// hash
else
{
$node = $domDocument->createElement( 'struct' );
foreach ( $value as $name => $cell )
{
// //member
$memberNode = $domDocument->createElement( 'member' );
// //member/name
$memberNode->appendChild( $domDocument->createElement( 'name', $name ) );
// //member/value
$valueNode = $domDocument->createElement( 'value' );
$memberNode->appendChild( $valueNode );
// //member/value/*
$valueNode->appendChild( $this->handleValue( $cell, $domDocument ) );
$node->appendChild( $memberNode );
}
}
break;
case 'object':
{
// DateTime is okay
if ( !$value instanceof DateTime )
continue;
$node = $domDocument->createElement( 'dateTime.iso8601', $value->format( DateTime::ISO8601 ) );
}
break;
default:
{
throw new \UnexpectedValueException( "Unknown return value type" );
}
}
return $node;
}
|
[
"private",
"function",
"handleValue",
"(",
"$",
"value",
",",
"DOMDocument",
"$",
"domDocument",
")",
"{",
"switch",
"(",
"gettype",
"(",
"$",
"value",
")",
")",
"{",
"case",
"'integer'",
":",
"$",
"node",
"=",
"$",
"domDocument",
"->",
"createElement",
"(",
"'int'",
",",
"$",
"value",
")",
";",
"break",
";",
"case",
"'boolean'",
":",
"$",
"node",
"=",
"$",
"domDocument",
"->",
"createElement",
"(",
"'boolean'",
",",
"$",
"value",
")",
";",
"break",
";",
"case",
"'string'",
":",
"$",
"node",
"=",
"$",
"domDocument",
"->",
"createElement",
"(",
"'string'",
",",
"$",
"value",
")",
";",
"break",
";",
"case",
"'double'",
":",
"$",
"node",
"=",
"$",
"domDocument",
"->",
"createElement",
"(",
"'double'",
",",
"$",
"value",
")",
";",
"break",
";",
"case",
"'array'",
":",
"// array",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
"||",
"key",
"(",
"$",
"value",
")",
"===",
"0",
")",
"{",
"$",
"node",
"=",
"$",
"domDocument",
"->",
"createElement",
"(",
"'array'",
")",
";",
"$",
"dataNode",
"=",
"$",
"domDocument",
"->",
"createElement",
"(",
"'data'",
")",
";",
"$",
"node",
"->",
"appendChild",
"(",
"$",
"dataNode",
")",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"cell",
")",
"{",
"$",
"valueNode",
"=",
"$",
"domDocument",
"->",
"createElement",
"(",
"'value'",
")",
";",
"$",
"valueNode",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"handleValue",
"(",
"$",
"cell",
",",
"$",
"domDocument",
")",
")",
";",
"$",
"dataNode",
"->",
"appendChild",
"(",
"$",
"valueNode",
")",
";",
"}",
"}",
"// hash",
"else",
"{",
"$",
"node",
"=",
"$",
"domDocument",
"->",
"createElement",
"(",
"'struct'",
")",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"name",
"=>",
"$",
"cell",
")",
"{",
"// //member",
"$",
"memberNode",
"=",
"$",
"domDocument",
"->",
"createElement",
"(",
"'member'",
")",
";",
"// //member/name",
"$",
"memberNode",
"->",
"appendChild",
"(",
"$",
"domDocument",
"->",
"createElement",
"(",
"'name'",
",",
"$",
"name",
")",
")",
";",
"// //member/value",
"$",
"valueNode",
"=",
"$",
"domDocument",
"->",
"createElement",
"(",
"'value'",
")",
";",
"$",
"memberNode",
"->",
"appendChild",
"(",
"$",
"valueNode",
")",
";",
"// //member/value/*",
"$",
"valueNode",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"handleValue",
"(",
"$",
"cell",
",",
"$",
"domDocument",
")",
")",
";",
"$",
"node",
"->",
"appendChild",
"(",
"$",
"memberNode",
")",
";",
"}",
"}",
"break",
";",
"case",
"'object'",
":",
"{",
"// DateTime is okay",
"if",
"(",
"!",
"$",
"value",
"instanceof",
"DateTime",
")",
"continue",
";",
"$",
"node",
"=",
"$",
"domDocument",
"->",
"createElement",
"(",
"'dateTime.iso8601'",
",",
"$",
"value",
"->",
"format",
"(",
"DateTime",
"::",
"ISO8601",
")",
")",
";",
"}",
"break",
";",
"default",
":",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"\"Unknown return value type\"",
")",
";",
"}",
"}",
"return",
"$",
"node",
";",
"}"
] |
@param mixed $value
@param \DomDocument $domDocument
@throws \UnexpectedValueException
@return \DOMElement
|
[
"@param",
"mixed",
"$value",
"@param",
"\\",
"DomDocument",
"$domDocument"
] |
train
|
https://github.com/bdunogier/xmlrpcbundle/blob/9a3d59609131d438d259b3ae2c113bb4b813a16b/XmlRpc/Handler/Custom/ResponseGenerator.php#L117-L192
|
FrenchFrogs/framework
|
src/Ruler/Page/Page.php
|
Page.hasChild
|
public function hasChild($index, $is_recursive = true)
{
$recursive = function(Page $page) use ($index, &$recursive) {
foreach ($page->getChildren() as $k => $p ) {
/**@var Page $p*/
if ($index == $k) {
return true;
}
if ($p->hasChildren()) {
if ($recursive($p)) {
return true;
}
}
}
};
return $recursive($this);
}
|
php
|
public function hasChild($index, $is_recursive = true)
{
$recursive = function(Page $page) use ($index, &$recursive) {
foreach ($page->getChildren() as $k => $p ) {
/**@var Page $p*/
if ($index == $k) {
return true;
}
if ($p->hasChildren()) {
if ($recursive($p)) {
return true;
}
}
}
};
return $recursive($this);
}
|
[
"public",
"function",
"hasChild",
"(",
"$",
"index",
",",
"$",
"is_recursive",
"=",
"true",
")",
"{",
"$",
"recursive",
"=",
"function",
"(",
"Page",
"$",
"page",
")",
"use",
"(",
"$",
"index",
",",
"&",
"$",
"recursive",
")",
"{",
"foreach",
"(",
"$",
"page",
"->",
"getChildren",
"(",
")",
"as",
"$",
"k",
"=>",
"$",
"p",
")",
"{",
"/**@var Page $p*/",
"if",
"(",
"$",
"index",
"==",
"$",
"k",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"p",
"->",
"hasChildren",
"(",
")",
")",
"{",
"if",
"(",
"$",
"recursive",
"(",
"$",
"p",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"}",
";",
"return",
"$",
"recursive",
"(",
"$",
"this",
")",
";",
"}"
] |
Return TRUE id $index page exist in $children container
@param $index
@return bool
|
[
"Return",
"TRUE",
"id",
"$index",
"page",
"exist",
"in",
"$children",
"container"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Ruler/Page/Page.php#L260-L280
|
FrenchFrogs/framework
|
src/Ruler/Page/Page.php
|
Page.getChild
|
public function getChild($index, $is_recursive = true)
{
if (!$this->hasChild($index, $is_recursive)) {
throw new InvalidArgumentException('Child doesn\'t exist : ' . $index);
}
$recursive = function(Page $page) use ($index, &$recursive) {
foreach ($page->getChildren() as $k => $p ) {
/**@var Page $p*/
if ($index == $k) {
return $p;
}
if ($p->hasChildren()) {
if ($pp = $recursive($p)) {
return $pp;
}
}
}
};
return $recursive($this);
}
|
php
|
public function getChild($index, $is_recursive = true)
{
if (!$this->hasChild($index, $is_recursive)) {
throw new InvalidArgumentException('Child doesn\'t exist : ' . $index);
}
$recursive = function(Page $page) use ($index, &$recursive) {
foreach ($page->getChildren() as $k => $p ) {
/**@var Page $p*/
if ($index == $k) {
return $p;
}
if ($p->hasChildren()) {
if ($pp = $recursive($p)) {
return $pp;
}
}
}
};
return $recursive($this);
}
|
[
"public",
"function",
"getChild",
"(",
"$",
"index",
",",
"$",
"is_recursive",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasChild",
"(",
"$",
"index",
",",
"$",
"is_recursive",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Child doesn\\'t exist : '",
".",
"$",
"index",
")",
";",
"}",
"$",
"recursive",
"=",
"function",
"(",
"Page",
"$",
"page",
")",
"use",
"(",
"$",
"index",
",",
"&",
"$",
"recursive",
")",
"{",
"foreach",
"(",
"$",
"page",
"->",
"getChildren",
"(",
")",
"as",
"$",
"k",
"=>",
"$",
"p",
")",
"{",
"/**@var Page $p*/",
"if",
"(",
"$",
"index",
"==",
"$",
"k",
")",
"{",
"return",
"$",
"p",
";",
"}",
"if",
"(",
"$",
"p",
"->",
"hasChildren",
"(",
")",
")",
"{",
"if",
"(",
"$",
"pp",
"=",
"$",
"recursive",
"(",
"$",
"p",
")",
")",
"{",
"return",
"$",
"pp",
";",
"}",
"}",
"}",
"}",
";",
"return",
"$",
"recursive",
"(",
"$",
"this",
")",
";",
"}"
] |
Return $index page from $children container
@param $index
@return mixed
|
[
"Return",
"$index",
"page",
"from",
"$children",
"container"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Ruler/Page/Page.php#L288-L313
|
FrenchFrogs/framework
|
src/Ruler/Page/Page.php
|
Page.removeChild
|
public function removeChild($index)
{
if (!$this->hasChild($index)) {
throw new InvalidArgumentException('Child doesn\'t exist : ' . $index);
}
unset($this->children[$index]);
return $this;
}
|
php
|
public function removeChild($index)
{
if (!$this->hasChild($index)) {
throw new InvalidArgumentException('Child doesn\'t exist : ' . $index);
}
unset($this->children[$index]);
return $this;
}
|
[
"public",
"function",
"removeChild",
"(",
"$",
"index",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasChild",
"(",
"$",
"index",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Child doesn\\'t exist : '",
".",
"$",
"index",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"children",
"[",
"$",
"index",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Remove $index child from $children container
@param $index
@return $this
|
[
"Remove",
"$index",
"child",
"from",
"$children",
"container"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Ruler/Page/Page.php#L322-L331
|
FrenchFrogs/framework
|
src/Ruler/Page/Page.php
|
Page.isCurrent
|
public function isCurrent()
{
$link = $this->getLink();
if ($link{0} == '/') {
$link = substr($link, 1);
}
return request()->is($link);
}
|
php
|
public function isCurrent()
{
$link = $this->getLink();
if ($link{0} == '/') {
$link = substr($link, 1);
}
return request()->is($link);
}
|
[
"public",
"function",
"isCurrent",
"(",
")",
"{",
"$",
"link",
"=",
"$",
"this",
"->",
"getLink",
"(",
")",
";",
"if",
"(",
"$",
"link",
"{",
"0",
"}",
"==",
"'/'",
")",
"{",
"$",
"link",
"=",
"substr",
"(",
"$",
"link",
",",
"1",
")",
";",
"}",
"return",
"request",
"(",
")",
"->",
"is",
"(",
"$",
"link",
")",
";",
"}"
] |
Return TRUE if the current page is this page
@return bool
|
[
"Return",
"TRUE",
"if",
"the",
"current",
"page",
"is",
"this",
"page"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Ruler/Page/Page.php#L338-L346
|
readdle/fqdb
|
src/Readdle/Database/FQDBQueryAPI.php
|
FQDBQueryAPI._runQuery
|
private function _runQuery($query, $options)
{
$this->_testQueryStarts($query, '[select|show]');
$statement = $this->_executeQuery($query, $options);
if (is_object($statement) && $statement instanceof \PDOStatement) {
return $statement;
}
else {
$this->_error(FQDBException::INTERNAL_ASSERTION_FAIL, FQDBException::FQDB_CODE);
}
}
|
php
|
private function _runQuery($query, $options)
{
$this->_testQueryStarts($query, '[select|show]');
$statement = $this->_executeQuery($query, $options);
if (is_object($statement) && $statement instanceof \PDOStatement) {
return $statement;
}
else {
$this->_error(FQDBException::INTERNAL_ASSERTION_FAIL, FQDBException::FQDB_CODE);
}
}
|
[
"private",
"function",
"_runQuery",
"(",
"$",
"query",
",",
"$",
"options",
")",
"{",
"$",
"this",
"->",
"_testQueryStarts",
"(",
"$",
"query",
",",
"'[select|show]'",
")",
";",
"$",
"statement",
"=",
"$",
"this",
"->",
"_executeQuery",
"(",
"$",
"query",
",",
"$",
"options",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"statement",
")",
"&&",
"$",
"statement",
"instanceof",
"\\",
"PDOStatement",
")",
"{",
"return",
"$",
"statement",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_error",
"(",
"FQDBException",
"::",
"INTERNAL_ASSERTION_FAIL",
",",
"FQDBException",
"::",
"FQDB_CODE",
")",
";",
"}",
"}"
] |
executes prepared \PDO query
@param string $query
@param array $options
@return \PDOStatement PDO statement from query
|
[
"executes",
"prepared",
"\\",
"PDO",
"query"
] |
train
|
https://github.com/readdle/fqdb/blob/4ef2e8f3343a7c8fbb309c243be502a160c42083/src/Readdle/Database/FQDBQueryAPI.php#L14-L24
|
readdle/fqdb
|
src/Readdle/Database/FQDBQueryAPI.php
|
FQDBQueryAPI.queryArray
|
private function queryArray($query, $options, $fetcher)
{
$statement = $this->_runQuery($query, $options);
$result = call_user_func($fetcher, $statement);
return is_array($result) ? $result : [];
}
|
php
|
private function queryArray($query, $options, $fetcher)
{
$statement = $this->_runQuery($query, $options);
$result = call_user_func($fetcher, $statement);
return is_array($result) ? $result : [];
}
|
[
"private",
"function",
"queryArray",
"(",
"$",
"query",
",",
"$",
"options",
",",
"$",
"fetcher",
")",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"_runQuery",
"(",
"$",
"query",
",",
"$",
"options",
")",
";",
"$",
"result",
"=",
"call_user_func",
"(",
"$",
"fetcher",
",",
"$",
"statement",
")",
";",
"return",
"is_array",
"(",
"$",
"result",
")",
"?",
"$",
"result",
":",
"[",
"]",
";",
"}"
] |
executes SELECT or SHOW query and returns result array
@param string $query
@param array $options
@param callable $fetcher
@return array
|
[
"executes",
"SELECT",
"or",
"SHOW",
"query",
"and",
"returns",
"result",
"array"
] |
train
|
https://github.com/readdle/fqdb/blob/4ef2e8f3343a7c8fbb309c243be502a160c42083/src/Readdle/Database/FQDBQueryAPI.php#L34-L39
|
readdle/fqdb
|
src/Readdle/Database/FQDBQueryAPI.php
|
FQDBQueryAPI.queryValue
|
public function queryValue($query, $options = array())
{
$statement = $this->_runQuery($query, $options);
return $statement->fetch(\PDO::FETCH_COLUMN);
}
|
php
|
public function queryValue($query, $options = array())
{
$statement = $this->_runQuery($query, $options);
return $statement->fetch(\PDO::FETCH_COLUMN);
}
|
[
"public",
"function",
"queryValue",
"(",
"$",
"query",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"_runQuery",
"(",
"$",
"query",
",",
"$",
"options",
")",
";",
"return",
"$",
"statement",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_COLUMN",
")",
";",
"}"
] |
executes SELECT or SHOW query and returns 1st returned element
@param string $query
@param array $options
@return string|false
|
[
"executes",
"SELECT",
"or",
"SHOW",
"query",
"and",
"returns",
"1st",
"returned",
"element"
] |
train
|
https://github.com/readdle/fqdb/blob/4ef2e8f3343a7c8fbb309c243be502a160c42083/src/Readdle/Database/FQDBQueryAPI.php#L47-L51
|
readdle/fqdb
|
src/Readdle/Database/FQDBQueryAPI.php
|
FQDBQueryAPI.queryAssoc
|
public function queryAssoc($query, $options = array())
{
$statement = $this->_runQuery($query, $options);
return $statement->fetch(\PDO::FETCH_ASSOC);
}
|
php
|
public function queryAssoc($query, $options = array())
{
$statement = $this->_runQuery($query, $options);
return $statement->fetch(\PDO::FETCH_ASSOC);
}
|
[
"public",
"function",
"queryAssoc",
"(",
"$",
"query",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"_runQuery",
"(",
"$",
"query",
",",
"$",
"options",
")",
";",
"return",
"$",
"statement",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}"
] |
executes SELECT or SHOW query and returns 1st row as assoc array
@param string $query
@param array $options
@return array|false
|
[
"executes",
"SELECT",
"or",
"SHOW",
"query",
"and",
"returns",
"1st",
"row",
"as",
"assoc",
"array"
] |
train
|
https://github.com/readdle/fqdb/blob/4ef2e8f3343a7c8fbb309c243be502a160c42083/src/Readdle/Database/FQDBQueryAPI.php#L59-L63
|
readdle/fqdb
|
src/Readdle/Database/FQDBQueryAPI.php
|
FQDBQueryAPI.queryList
|
public function queryList($query, $options = array())
{
$statement = $this->_runQuery($query, $options);
return $statement->fetch(\PDO::FETCH_NUM);
}
|
php
|
public function queryList($query, $options = array())
{
$statement = $this->_runQuery($query, $options);
return $statement->fetch(\PDO::FETCH_NUM);
}
|
[
"public",
"function",
"queryList",
"(",
"$",
"query",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"_runQuery",
"(",
"$",
"query",
",",
"$",
"options",
")",
";",
"return",
"$",
"statement",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_NUM",
")",
";",
"}"
] |
executes SELECT or SHOW query and returns as array
@param string $query
@param array $options
@return array|false
|
[
"executes",
"SELECT",
"or",
"SHOW",
"query",
"and",
"returns",
"as",
"array"
] |
train
|
https://github.com/readdle/fqdb/blob/4ef2e8f3343a7c8fbb309c243be502a160c42083/src/Readdle/Database/FQDBQueryAPI.php#L71-L75
|
readdle/fqdb
|
src/Readdle/Database/FQDBQueryAPI.php
|
FQDBQueryAPI.queryVector
|
public function queryVector($query, $options = array())
{
return $this->queryArray($query, $options,
function(\PDOStatement $statement) { return $statement->fetchAll(\PDO::FETCH_COLUMN, 0); });
}
|
php
|
public function queryVector($query, $options = array())
{
return $this->queryArray($query, $options,
function(\PDOStatement $statement) { return $statement->fetchAll(\PDO::FETCH_COLUMN, 0); });
}
|
[
"public",
"function",
"queryVector",
"(",
"$",
"query",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"queryArray",
"(",
"$",
"query",
",",
"$",
"options",
",",
"function",
"(",
"\\",
"PDOStatement",
"$",
"statement",
")",
"{",
"return",
"$",
"statement",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_COLUMN",
",",
"0",
")",
";",
"}",
")",
";",
"}"
] |
executes SELECT or SHOW query and returns result as array
@param string $query
@param array $options
@return array
|
[
"executes",
"SELECT",
"or",
"SHOW",
"query",
"and",
"returns",
"result",
"as",
"array"
] |
train
|
https://github.com/readdle/fqdb/blob/4ef2e8f3343a7c8fbb309c243be502a160c42083/src/Readdle/Database/FQDBQueryAPI.php#L85-L90
|
readdle/fqdb
|
src/Readdle/Database/FQDBQueryAPI.php
|
FQDBQueryAPI.queryTable
|
public function queryTable($query, $options = array())
{
return $this->queryArray($query, $options,
function(\PDOStatement $statement) { return $statement->fetchAll(\PDO::FETCH_ASSOC); }
);
}
|
php
|
public function queryTable($query, $options = array())
{
return $this->queryArray($query, $options,
function(\PDOStatement $statement) { return $statement->fetchAll(\PDO::FETCH_ASSOC); }
);
}
|
[
"public",
"function",
"queryTable",
"(",
"$",
"query",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"queryArray",
"(",
"$",
"query",
",",
"$",
"options",
",",
"function",
"(",
"\\",
"PDOStatement",
"$",
"statement",
")",
"{",
"return",
"$",
"statement",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}",
")",
";",
"}"
] |
executes SELECT or SHOW query and returns result as assoc array
@param string $query
@param array $options
@return array
|
[
"executes",
"SELECT",
"or",
"SHOW",
"query",
"and",
"returns",
"result",
"as",
"assoc",
"array"
] |
train
|
https://github.com/readdle/fqdb/blob/4ef2e8f3343a7c8fbb309c243be502a160c42083/src/Readdle/Database/FQDBQueryAPI.php#L98-L103
|
readdle/fqdb
|
src/Readdle/Database/FQDBQueryAPI.php
|
FQDBQueryAPI.queryObjArray
|
public function queryObjArray($query, $className, $options = array(), $classConstructorArguments = NULL)
{
if (!class_exists($className)) {
$this->_error(FQDBException::CLASS_NOT_EXIST, FQDBException::FQDB_CODE);
}
return $this->queryArray($query, $options,
function(\PDOStatement $statement) use ($className, $classConstructorArguments) {
return $statement->fetchAll(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE,
$className, $classConstructorArguments);
}
);
}
|
php
|
public function queryObjArray($query, $className, $options = array(), $classConstructorArguments = NULL)
{
if (!class_exists($className)) {
$this->_error(FQDBException::CLASS_NOT_EXIST, FQDBException::FQDB_CODE);
}
return $this->queryArray($query, $options,
function(\PDOStatement $statement) use ($className, $classConstructorArguments) {
return $statement->fetchAll(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE,
$className, $classConstructorArguments);
}
);
}
|
[
"public",
"function",
"queryObjArray",
"(",
"$",
"query",
",",
"$",
"className",
",",
"$",
"options",
"=",
"array",
"(",
")",
",",
"$",
"classConstructorArguments",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"$",
"this",
"->",
"_error",
"(",
"FQDBException",
"::",
"CLASS_NOT_EXIST",
",",
"FQDBException",
"::",
"FQDB_CODE",
")",
";",
"}",
"return",
"$",
"this",
"->",
"queryArray",
"(",
"$",
"query",
",",
"$",
"options",
",",
"function",
"(",
"\\",
"PDOStatement",
"$",
"statement",
")",
"use",
"(",
"$",
"className",
",",
"$",
"classConstructorArguments",
")",
"{",
"return",
"$",
"statement",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_CLASS",
"|",
"\\",
"PDO",
"::",
"FETCH_PROPS_LATE",
",",
"$",
"className",
",",
"$",
"classConstructorArguments",
")",
";",
"}",
")",
";",
"}"
] |
executes SELECT or SHOW query and returns result as array of objects of given class
@param string $query
@param string $className
@param array $options
@param array $classConstructorArguments
@return array
|
[
"executes",
"SELECT",
"or",
"SHOW",
"query",
"and",
"returns",
"result",
"as",
"array",
"of",
"objects",
"of",
"given",
"class"
] |
train
|
https://github.com/readdle/fqdb/blob/4ef2e8f3343a7c8fbb309c243be502a160c42083/src/Readdle/Database/FQDBQueryAPI.php#L113-L125
|
readdle/fqdb
|
src/Readdle/Database/FQDBQueryAPI.php
|
FQDBQueryAPI.queryObj
|
public function queryObj($query, $className, $options = array(), $classConstructorArguments = NULL)
{
if (!class_exists($className)) {
$this->_error(FQDBException::CLASS_NOT_EXIST, FQDBException::FQDB_CODE);
}
$statement = $this->_runQuery($query, $options);
$statement->setFetchMode(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, $className, $classConstructorArguments);
return $statement->fetch();
}
|
php
|
public function queryObj($query, $className, $options = array(), $classConstructorArguments = NULL)
{
if (!class_exists($className)) {
$this->_error(FQDBException::CLASS_NOT_EXIST, FQDBException::FQDB_CODE);
}
$statement = $this->_runQuery($query, $options);
$statement->setFetchMode(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, $className, $classConstructorArguments);
return $statement->fetch();
}
|
[
"public",
"function",
"queryObj",
"(",
"$",
"query",
",",
"$",
"className",
",",
"$",
"options",
"=",
"array",
"(",
")",
",",
"$",
"classConstructorArguments",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"$",
"this",
"->",
"_error",
"(",
"FQDBException",
"::",
"CLASS_NOT_EXIST",
",",
"FQDBException",
"::",
"FQDB_CODE",
")",
";",
"}",
"$",
"statement",
"=",
"$",
"this",
"->",
"_runQuery",
"(",
"$",
"query",
",",
"$",
"options",
")",
";",
"$",
"statement",
"->",
"setFetchMode",
"(",
"\\",
"PDO",
"::",
"FETCH_CLASS",
"|",
"\\",
"PDO",
"::",
"FETCH_PROPS_LATE",
",",
"$",
"className",
",",
"$",
"classConstructorArguments",
")",
";",
"return",
"$",
"statement",
"->",
"fetch",
"(",
")",
";",
"}"
] |
executes SELECT or SHOW query and returns object of given class
@param string $query
@param string $className
@param array $options
@param array $classConstructorArguments
@return object|false
|
[
"executes",
"SELECT",
"or",
"SHOW",
"query",
"and",
"returns",
"object",
"of",
"given",
"class"
] |
train
|
https://github.com/readdle/fqdb/blob/4ef2e8f3343a7c8fbb309c243be502a160c42083/src/Readdle/Database/FQDBQueryAPI.php#L136-L146
|
readdle/fqdb
|
src/Readdle/Database/FQDBQueryAPI.php
|
FQDBQueryAPI.queryTableCallback
|
public function queryTableCallback($query, $options = [], $callback)
{
if(!is_callable($callback)) {
$this->_error(FQDBException::NOT_CALLABLE_ERROR, FQDBException::FQDB_CODE);
}
$statement = $this->_runQuery($query, $options);
while ($row = $statement->fetch(\PDO::FETCH_ASSOC)) {
call_user_func($callback, $row);
}
return true; //executed successfully
}
|
php
|
public function queryTableCallback($query, $options = [], $callback)
{
if(!is_callable($callback)) {
$this->_error(FQDBException::NOT_CALLABLE_ERROR, FQDBException::FQDB_CODE);
}
$statement = $this->_runQuery($query, $options);
while ($row = $statement->fetch(\PDO::FETCH_ASSOC)) {
call_user_func($callback, $row);
}
return true; //executed successfully
}
|
[
"public",
"function",
"queryTableCallback",
"(",
"$",
"query",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"callback",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"callback",
")",
")",
"{",
"$",
"this",
"->",
"_error",
"(",
"FQDBException",
"::",
"NOT_CALLABLE_ERROR",
",",
"FQDBException",
"::",
"FQDB_CODE",
")",
";",
"}",
"$",
"statement",
"=",
"$",
"this",
"->",
"_runQuery",
"(",
"$",
"query",
",",
"$",
"options",
")",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"statement",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
")",
"{",
"call_user_func",
"(",
"$",
"callback",
",",
"$",
"row",
")",
";",
"}",
"return",
"true",
";",
"//executed successfully",
"}"
] |
Execute query and apply a callback function to each row
@param string $query
@param array $options
@param callable $callback
@return boolean
|
[
"Execute",
"query",
"and",
"apply",
"a",
"callback",
"function",
"to",
"each",
"row"
] |
train
|
https://github.com/readdle/fqdb/blob/4ef2e8f3343a7c8fbb309c243be502a160c42083/src/Readdle/Database/FQDBQueryAPI.php#L156-L166
|
readdle/fqdb
|
src/Readdle/Database/FQDBQueryAPI.php
|
FQDBQueryAPI.queryTableGenerator
|
public function queryTableGenerator($query, $options = [])
{
$statement = $this->_runQuery($query, $options);
while ($row = $statement->fetch(\PDO::FETCH_ASSOC)) {
yield $row;
}
}
|
php
|
public function queryTableGenerator($query, $options = [])
{
$statement = $this->_runQuery($query, $options);
while ($row = $statement->fetch(\PDO::FETCH_ASSOC)) {
yield $row;
}
}
|
[
"public",
"function",
"queryTableGenerator",
"(",
"$",
"query",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"_runQuery",
"(",
"$",
"query",
",",
"$",
"options",
")",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"statement",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
")",
"{",
"yield",
"$",
"row",
";",
"}",
"}"
] |
Execute a query and makes generator from the result
@param $query
@param array $options
@return \Generator
|
[
"Execute",
"a",
"query",
"and",
"makes",
"generator",
"from",
"the",
"result"
] |
train
|
https://github.com/readdle/fqdb/blob/4ef2e8f3343a7c8fbb309c243be502a160c42083/src/Readdle/Database/FQDBQueryAPI.php#L175-L181
|
readdle/fqdb
|
src/Readdle/Database/FQDBQueryAPI.php
|
FQDBQueryAPI.queryHash
|
public function queryHash($query, $options = array())
{
return $this->queryArray(
$query,
$options,
function(\PDOStatement $statement) {
return $statement->fetchAll(\PDO::FETCH_KEY_PAIR);
}
);
}
|
php
|
public function queryHash($query, $options = array())
{
return $this->queryArray(
$query,
$options,
function(\PDOStatement $statement) {
return $statement->fetchAll(\PDO::FETCH_KEY_PAIR);
}
);
}
|
[
"public",
"function",
"queryHash",
"(",
"$",
"query",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"queryArray",
"(",
"$",
"query",
",",
"$",
"options",
",",
"function",
"(",
"\\",
"PDOStatement",
"$",
"statement",
")",
"{",
"return",
"$",
"statement",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_KEY_PAIR",
")",
";",
"}",
")",
";",
"}"
] |
executes SELECT or SHOW query and returns an assoc array made of two-columns
where the first column is a key and the second column is the value
@param $query
@param array $options
@return array
|
[
"executes",
"SELECT",
"or",
"SHOW",
"query",
"and",
"returns",
"an",
"assoc",
"array",
"made",
"of",
"two",
"-",
"columns",
"where",
"the",
"first",
"column",
"is",
"a",
"key",
"and",
"the",
"second",
"column",
"is",
"the",
"value"
] |
train
|
https://github.com/readdle/fqdb/blob/4ef2e8f3343a7c8fbb309c243be502a160c42083/src/Readdle/Database/FQDBQueryAPI.php#L190-L199
|
comodojo/dispatcher.framework
|
src/Comodojo/Dispatcher/Router/Parser.php
|
Parser.read
|
public function read($folders = array(), Route $value = null, $regex = '') {
if (is_null($value)) {
$value = new Route();
}
// if the first 'folder' is empty is removed
while (!empty($folders) && empty($folders[0])) {
array_shift($folders);
}
// if the 'folder' array is empty, the route has been fully analyzed
// this is the exit condition from the recursive loop.
if (empty($folders)) {
return '^'.$regex.'[\/]?$';
} else {
// The first element of the array 'folders' is taken in order to be analyzed
$folder = array_shift($folders);
// All the parameters of the route must be json strings
$decoded = json_decode($folder, true);
if (!is_null($decoded) && is_array($decoded)) {
$param_regex = '';
$param_required = false;
/* All the folders can include more than one parameter
* Eg: /service_name/{'param1': 'regex1', 'param2': 'regex2'}/
* /calendar/{'ux_timestamp*': '\d{10}', 'microseconds': '\d{4}'}/
*
* The '*' at the end of the paramerter name implies that the parameter is required
* This example can be read as a calendar service that accepts both
* timestamps in unix or javascript format.
*
* This is the reason of the following 'foreach'
*/
foreach ($decoded as $key => $string) {
$this->logger->debug("Route parser - parameter key: $key");
$this->logger->debug("Route parser - parameter string: $string");
/* The key and the regex of every paramater is passed to the 'param'
* method which will build an appropriate regular expression and will understand
* if the parameter is required and will build the Route query object
*/
$param_regex .= $this->param($key, $string, $value);
if ($value->isQueryRequired($key)) {
$param_required = true;
}
$this->logger->debug("Route parser - parameter regex: $param_regex");
}
// Once the parameter is analyzed, the result is passed to the next iteration
return $this->read(
$folders,
$value,
$regex.'(?:\/'.$param_regex.')'.(($param_required) ? '{1}' : '?')
);
} else {
// if the element is not a json string, I assume it's the service name
$value->addService($folder);
return $this->read(
$folders,
$value,
$regex.'\/'.$folder
);
}
}
}
|
php
|
public function read($folders = array(), Route $value = null, $regex = '') {
if (is_null($value)) {
$value = new Route();
}
// if the first 'folder' is empty is removed
while (!empty($folders) && empty($folders[0])) {
array_shift($folders);
}
// if the 'folder' array is empty, the route has been fully analyzed
// this is the exit condition from the recursive loop.
if (empty($folders)) {
return '^'.$regex.'[\/]?$';
} else {
// The first element of the array 'folders' is taken in order to be analyzed
$folder = array_shift($folders);
// All the parameters of the route must be json strings
$decoded = json_decode($folder, true);
if (!is_null($decoded) && is_array($decoded)) {
$param_regex = '';
$param_required = false;
/* All the folders can include more than one parameter
* Eg: /service_name/{'param1': 'regex1', 'param2': 'regex2'}/
* /calendar/{'ux_timestamp*': '\d{10}', 'microseconds': '\d{4}'}/
*
* The '*' at the end of the paramerter name implies that the parameter is required
* This example can be read as a calendar service that accepts both
* timestamps in unix or javascript format.
*
* This is the reason of the following 'foreach'
*/
foreach ($decoded as $key => $string) {
$this->logger->debug("Route parser - parameter key: $key");
$this->logger->debug("Route parser - parameter string: $string");
/* The key and the regex of every paramater is passed to the 'param'
* method which will build an appropriate regular expression and will understand
* if the parameter is required and will build the Route query object
*/
$param_regex .= $this->param($key, $string, $value);
if ($value->isQueryRequired($key)) {
$param_required = true;
}
$this->logger->debug("Route parser - parameter regex: $param_regex");
}
// Once the parameter is analyzed, the result is passed to the next iteration
return $this->read(
$folders,
$value,
$regex.'(?:\/'.$param_regex.')'.(($param_required) ? '{1}' : '?')
);
} else {
// if the element is not a json string, I assume it's the service name
$value->addService($folder);
return $this->read(
$folders,
$value,
$regex.'\/'.$folder
);
}
}
}
|
[
"public",
"function",
"read",
"(",
"$",
"folders",
"=",
"array",
"(",
")",
",",
"Route",
"$",
"value",
"=",
"null",
",",
"$",
"regex",
"=",
"''",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"new",
"Route",
"(",
")",
";",
"}",
"// if the first 'folder' is empty is removed",
"while",
"(",
"!",
"empty",
"(",
"$",
"folders",
")",
"&&",
"empty",
"(",
"$",
"folders",
"[",
"0",
"]",
")",
")",
"{",
"array_shift",
"(",
"$",
"folders",
")",
";",
"}",
"// if the 'folder' array is empty, the route has been fully analyzed",
"// this is the exit condition from the recursive loop.",
"if",
"(",
"empty",
"(",
"$",
"folders",
")",
")",
"{",
"return",
"'^'",
".",
"$",
"regex",
".",
"'[\\/]?$'",
";",
"}",
"else",
"{",
"// The first element of the array 'folders' is taken in order to be analyzed",
"$",
"folder",
"=",
"array_shift",
"(",
"$",
"folders",
")",
";",
"// All the parameters of the route must be json strings",
"$",
"decoded",
"=",
"json_decode",
"(",
"$",
"folder",
",",
"true",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"decoded",
")",
"&&",
"is_array",
"(",
"$",
"decoded",
")",
")",
"{",
"$",
"param_regex",
"=",
"''",
";",
"$",
"param_required",
"=",
"false",
";",
"/* All the folders can include more than one parameter\n * Eg: /service_name/{'param1': 'regex1', 'param2': 'regex2'}/\n * /calendar/{'ux_timestamp*': '\\d{10}', 'microseconds': '\\d{4}'}/\n *\n * The '*' at the end of the paramerter name implies that the parameter is required\n * This example can be read as a calendar service that accepts both\n * timestamps in unix or javascript format.\n *\n * This is the reason of the following 'foreach'\n */",
"foreach",
"(",
"$",
"decoded",
"as",
"$",
"key",
"=>",
"$",
"string",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\"Route parser - parameter key: $key\"",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\"Route parser - parameter string: $string\"",
")",
";",
"/* The key and the regex of every paramater is passed to the 'param'\n * method which will build an appropriate regular expression and will understand\n * if the parameter is required and will build the Route query object\n */",
"$",
"param_regex",
".=",
"$",
"this",
"->",
"param",
"(",
"$",
"key",
",",
"$",
"string",
",",
"$",
"value",
")",
";",
"if",
"(",
"$",
"value",
"->",
"isQueryRequired",
"(",
"$",
"key",
")",
")",
"{",
"$",
"param_required",
"=",
"true",
";",
"}",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\"Route parser - parameter regex: $param_regex\"",
")",
";",
"}",
"// Once the parameter is analyzed, the result is passed to the next iteration",
"return",
"$",
"this",
"->",
"read",
"(",
"$",
"folders",
",",
"$",
"value",
",",
"$",
"regex",
".",
"'(?:\\/'",
".",
"$",
"param_regex",
".",
"')'",
".",
"(",
"(",
"$",
"param_required",
")",
"?",
"'{1}'",
":",
"'?'",
")",
")",
";",
"}",
"else",
"{",
"// if the element is not a json string, I assume it's the service name",
"$",
"value",
"->",
"addService",
"(",
"$",
"folder",
")",
";",
"return",
"$",
"this",
"->",
"read",
"(",
"$",
"folders",
",",
"$",
"value",
",",
"$",
"regex",
".",
"'\\/'",
".",
"$",
"folder",
")",
";",
"}",
"}",
"}"
] |
the global regular expression against which all the request URI will be compared
|
[
"the",
"global",
"regular",
"expression",
"against",
"which",
"all",
"the",
"request",
"URI",
"will",
"be",
"compared"
] |
train
|
https://github.com/comodojo/dispatcher.framework/blob/5093297dcb7441a8d8f79cbb2429c93232e16d1c/src/Comodojo/Dispatcher/Router/Parser.php#L37-L122
|
comodojo/dispatcher.framework
|
src/Comodojo/Dispatcher/Router/Parser.php
|
Parser.param
|
private function param($key, $string, $value) {
$field_required = false;
// If the field name ends with a '*', the parameter is considered as required
if (preg_match('/^(.+)\*$/', $key, $bits)) {
$key = $bits[1];
$field_required = true;
}
// The $value query object contains all regex which will be used by the collector to parse the route fields
$value->setQuery($key, $string, $field_required);
/* Every parameter can include it's own logic into the regular expression,
* it can use backreferences and it's expected to be used against a single parameter.
* This means that it can't be used as is to build the route regular expression,
* Backreferences are not useful at this point and can make the regular expression more time consuming
* and resource hungry. This is why they are replaced with the grouping parenthesis.
* Eg: (value) changes in (?:value)
*
* Delimiting characters like '^' and '$' are also meaningless in the complete regular expression and
* need to be removed. Contrariwise, wildcards must be delimited in order to keep the whole regular
* expression consistent, hence a '?' is added to all the '.*' or '.+' that don't already have one.
*/
$string = preg_replace("/(?<!\\\\)\\((?!\\?)/", '(?:', $string);
$string = preg_replace("/\\.([\\*\\+])(?!\\?)/", '.${1}?', $string);
$string = preg_replace("/^[\\^]/", '', $string);
$string = preg_replace("/[\\$]$/", '', $string);
/* The produced regular expression is grouped and associated with its key (this means that the 'preg_match'
* function will generate an associative array where the key/value association is preserved).
* If the field is required, the regular expression is completed with a '{1}' (which make it compulsory),
* otherwise a '?' is added.
*/
return '(?P<'.$key.'>'.$string.')'.(($field_required) ? '{1}' : '?');
}
|
php
|
private function param($key, $string, $value) {
$field_required = false;
// If the field name ends with a '*', the parameter is considered as required
if (preg_match('/^(.+)\*$/', $key, $bits)) {
$key = $bits[1];
$field_required = true;
}
// The $value query object contains all regex which will be used by the collector to parse the route fields
$value->setQuery($key, $string, $field_required);
/* Every parameter can include it's own logic into the regular expression,
* it can use backreferences and it's expected to be used against a single parameter.
* This means that it can't be used as is to build the route regular expression,
* Backreferences are not useful at this point and can make the regular expression more time consuming
* and resource hungry. This is why they are replaced with the grouping parenthesis.
* Eg: (value) changes in (?:value)
*
* Delimiting characters like '^' and '$' are also meaningless in the complete regular expression and
* need to be removed. Contrariwise, wildcards must be delimited in order to keep the whole regular
* expression consistent, hence a '?' is added to all the '.*' or '.+' that don't already have one.
*/
$string = preg_replace("/(?<!\\\\)\\((?!\\?)/", '(?:', $string);
$string = preg_replace("/\\.([\\*\\+])(?!\\?)/", '.${1}?', $string);
$string = preg_replace("/^[\\^]/", '', $string);
$string = preg_replace("/[\\$]$/", '', $string);
/* The produced regular expression is grouped and associated with its key (this means that the 'preg_match'
* function will generate an associative array where the key/value association is preserved).
* If the field is required, the regular expression is completed with a '{1}' (which make it compulsory),
* otherwise a '?' is added.
*/
return '(?P<'.$key.'>'.$string.')'.(($field_required) ? '{1}' : '?');
}
|
[
"private",
"function",
"param",
"(",
"$",
"key",
",",
"$",
"string",
",",
"$",
"value",
")",
"{",
"$",
"field_required",
"=",
"false",
";",
"// If the field name ends with a '*', the parameter is considered as required",
"if",
"(",
"preg_match",
"(",
"'/^(.+)\\*$/'",
",",
"$",
"key",
",",
"$",
"bits",
")",
")",
"{",
"$",
"key",
"=",
"$",
"bits",
"[",
"1",
"]",
";",
"$",
"field_required",
"=",
"true",
";",
"}",
"// The $value query object contains all regex which will be used by the collector to parse the route fields",
"$",
"value",
"->",
"setQuery",
"(",
"$",
"key",
",",
"$",
"string",
",",
"$",
"field_required",
")",
";",
"/* Every parameter can include it's own logic into the regular expression,\n * it can use backreferences and it's expected to be used against a single parameter.\n * This means that it can't be used as is to build the route regular expression,\n * Backreferences are not useful at this point and can make the regular expression more time consuming\n * and resource hungry. This is why they are replaced with the grouping parenthesis.\n * Eg: (value) changes in (?:value)\n *\n * Delimiting characters like '^' and '$' are also meaningless in the complete regular expression and\n * need to be removed. Contrariwise, wildcards must be delimited in order to keep the whole regular\n * expression consistent, hence a '?' is added to all the '.*' or '.+' that don't already have one.\n */",
"$",
"string",
"=",
"preg_replace",
"(",
"\"/(?<!\\\\\\\\)\\\\((?!\\\\?)/\"",
",",
"'(?:'",
",",
"$",
"string",
")",
";",
"$",
"string",
"=",
"preg_replace",
"(",
"\"/\\\\.([\\\\*\\\\+])(?!\\\\?)/\"",
",",
"'.${1}?'",
",",
"$",
"string",
")",
";",
"$",
"string",
"=",
"preg_replace",
"(",
"\"/^[\\\\^]/\"",
",",
"''",
",",
"$",
"string",
")",
";",
"$",
"string",
"=",
"preg_replace",
"(",
"\"/[\\\\$]$/\"",
",",
"''",
",",
"$",
"string",
")",
";",
"/* The produced regular expression is grouped and associated with its key (this means that the 'preg_match'\n * function will generate an associative array where the key/value association is preserved).\n * If the field is required, the regular expression is completed with a '{1}' (which make it compulsory),\n * otherwise a '?' is added.\n */",
"return",
"'(?P<'",
".",
"$",
"key",
".",
"'>'",
".",
"$",
"string",
".",
"')'",
".",
"(",
"(",
"$",
"field_required",
")",
"?",
"'{1}'",
":",
"'?'",
")",
";",
"}"
] |
This method read a single parameter and build the regular expression
|
[
"This",
"method",
"read",
"a",
"single",
"parameter",
"and",
"build",
"the",
"regular",
"expression"
] |
train
|
https://github.com/comodojo/dispatcher.framework/blob/5093297dcb7441a8d8f79cbb2429c93232e16d1c/src/Comodojo/Dispatcher/Router/Parser.php#L125-L163
|
Elendev/ElendevRoxyFilemanBundle
|
DependencyInjection/ElendevRoxyFilemanExtension.php
|
ElendevRoxyFilemanExtension.load
|
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
foreach ($config['conf'] as $key => $value) {
$container->setParameter('elendev_roxyfileman.conf.' . $key, $value);
}
//set path to roxyfileman library, default one if no library is set
if (empty($config['roxyfileman_lib_path'])) {
$libPath = __DIR__ . '/../Resources/lib/roxyfileman';
} else {
$libPath = $config['roxyfileman_lib_path'];
}
$container->setParameter('elendev_roxyfileman.roxyfileman_library_path', $libPath);
// New syntax: multiple profiles
if (!empty($config['profiles'])) {
foreach ($config['profiles'] as $profileName => $profileConfig) {
foreach ($profileConfig['conf'] as $key => $value) {
$container->setParameter('elendev_roxyfileman.' . $profileName . '.conf.' . $key, $value);
}
if (!empty($profileConfig['file_system_service_id'])) {
$container->setAlias('elendev_roxy_fileman.' . $profileName . '.file_system', $profileConfig['file_system_service_id'])->setPublic(true);
} else {
// Create file system service for profile
if (empty($profileConfig['local_file_system']) || empty($profileConfig['local_file_system']['base_path']) || empty($profileConfig['local_file_system']['base_url'])) {
throw new InvalidConfigurationException('local_file_system.base_path and local_file_system.base_url have to be defined if file_system_service_id is empty in elendev_roxyfileman configuration');
}
$fileSystemDefinition = new Definition(
'Elendev\\RoxyFilemanBundle\\FileSystem\\LocalFileSystem',
array(
$profileConfig['local_file_system']['base_path'],
$profileConfig['local_file_system']['base_url'],
)
);
$container->setDefinition('elendev_roxy_fileman.' . $profileName . '.file_system', $fileSystemDefinition)->setPublic(true);
}
}
} else {
// Assumes legacy syntax if no profile is defined.
// Alias correct file system service if one is specified
if (!empty($config['file_system_service_id'])) {
$container->setAlias('elendev_roxy_fileman.file_system', $config['file_system_service_id'])->setPublic(true);
$container->removeDefinition('elendev_roxy_fileman.local_file_system');
} else {
if (empty($config['local_file_system']) || empty($config['local_file_system']['base_path']) || empty($config['local_file_system']['base_url'])) {
throw new InvalidConfigurationException('local_file_system.base_path and local_file_system.base_url have to be defined if file_system_service_id is empty in elendev_roxyfileman configuration');
}
$container->setParameter('elendev_roxyfileman.local_file_system.base_path', $config['local_file_system']['base_path']);
$container->setParameter('elendev_roxyfileman.local_file_system.base_url', $config['local_file_system']['base_url']);
}
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
}
}
|
php
|
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
foreach ($config['conf'] as $key => $value) {
$container->setParameter('elendev_roxyfileman.conf.' . $key, $value);
}
//set path to roxyfileman library, default one if no library is set
if (empty($config['roxyfileman_lib_path'])) {
$libPath = __DIR__ . '/../Resources/lib/roxyfileman';
} else {
$libPath = $config['roxyfileman_lib_path'];
}
$container->setParameter('elendev_roxyfileman.roxyfileman_library_path', $libPath);
// New syntax: multiple profiles
if (!empty($config['profiles'])) {
foreach ($config['profiles'] as $profileName => $profileConfig) {
foreach ($profileConfig['conf'] as $key => $value) {
$container->setParameter('elendev_roxyfileman.' . $profileName . '.conf.' . $key, $value);
}
if (!empty($profileConfig['file_system_service_id'])) {
$container->setAlias('elendev_roxy_fileman.' . $profileName . '.file_system', $profileConfig['file_system_service_id'])->setPublic(true);
} else {
// Create file system service for profile
if (empty($profileConfig['local_file_system']) || empty($profileConfig['local_file_system']['base_path']) || empty($profileConfig['local_file_system']['base_url'])) {
throw new InvalidConfigurationException('local_file_system.base_path and local_file_system.base_url have to be defined if file_system_service_id is empty in elendev_roxyfileman configuration');
}
$fileSystemDefinition = new Definition(
'Elendev\\RoxyFilemanBundle\\FileSystem\\LocalFileSystem',
array(
$profileConfig['local_file_system']['base_path'],
$profileConfig['local_file_system']['base_url'],
)
);
$container->setDefinition('elendev_roxy_fileman.' . $profileName . '.file_system', $fileSystemDefinition)->setPublic(true);
}
}
} else {
// Assumes legacy syntax if no profile is defined.
// Alias correct file system service if one is specified
if (!empty($config['file_system_service_id'])) {
$container->setAlias('elendev_roxy_fileman.file_system', $config['file_system_service_id'])->setPublic(true);
$container->removeDefinition('elendev_roxy_fileman.local_file_system');
} else {
if (empty($config['local_file_system']) || empty($config['local_file_system']['base_path']) || empty($config['local_file_system']['base_url'])) {
throw new InvalidConfigurationException('local_file_system.base_path and local_file_system.base_url have to be defined if file_system_service_id is empty in elendev_roxyfileman configuration');
}
$container->setParameter('elendev_roxyfileman.local_file_system.base_path', $config['local_file_system']['base_path']);
$container->setParameter('elendev_roxyfileman.local_file_system.base_url', $config['local_file_system']['base_url']);
}
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
}
}
|
[
"public",
"function",
"load",
"(",
"array",
"$",
"configs",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"configuration",
"=",
"new",
"Configuration",
"(",
")",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"processConfiguration",
"(",
"$",
"configuration",
",",
"$",
"configs",
")",
";",
"foreach",
"(",
"$",
"config",
"[",
"'conf'",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"container",
"->",
"setParameter",
"(",
"'elendev_roxyfileman.conf.'",
".",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"//set path to roxyfileman library, default one if no library is set",
"if",
"(",
"empty",
"(",
"$",
"config",
"[",
"'roxyfileman_lib_path'",
"]",
")",
")",
"{",
"$",
"libPath",
"=",
"__DIR__",
".",
"'/../Resources/lib/roxyfileman'",
";",
"}",
"else",
"{",
"$",
"libPath",
"=",
"$",
"config",
"[",
"'roxyfileman_lib_path'",
"]",
";",
"}",
"$",
"container",
"->",
"setParameter",
"(",
"'elendev_roxyfileman.roxyfileman_library_path'",
",",
"$",
"libPath",
")",
";",
"// New syntax: multiple profiles",
"if",
"(",
"!",
"empty",
"(",
"$",
"config",
"[",
"'profiles'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"config",
"[",
"'profiles'",
"]",
"as",
"$",
"profileName",
"=>",
"$",
"profileConfig",
")",
"{",
"foreach",
"(",
"$",
"profileConfig",
"[",
"'conf'",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"container",
"->",
"setParameter",
"(",
"'elendev_roxyfileman.'",
".",
"$",
"profileName",
".",
"'.conf.'",
".",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"profileConfig",
"[",
"'file_system_service_id'",
"]",
")",
")",
"{",
"$",
"container",
"->",
"setAlias",
"(",
"'elendev_roxy_fileman.'",
".",
"$",
"profileName",
".",
"'.file_system'",
",",
"$",
"profileConfig",
"[",
"'file_system_service_id'",
"]",
")",
"->",
"setPublic",
"(",
"true",
")",
";",
"}",
"else",
"{",
"// Create file system service for profile",
"if",
"(",
"empty",
"(",
"$",
"profileConfig",
"[",
"'local_file_system'",
"]",
")",
"||",
"empty",
"(",
"$",
"profileConfig",
"[",
"'local_file_system'",
"]",
"[",
"'base_path'",
"]",
")",
"||",
"empty",
"(",
"$",
"profileConfig",
"[",
"'local_file_system'",
"]",
"[",
"'base_url'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidConfigurationException",
"(",
"'local_file_system.base_path and local_file_system.base_url have to be defined if file_system_service_id is empty in elendev_roxyfileman configuration'",
")",
";",
"}",
"$",
"fileSystemDefinition",
"=",
"new",
"Definition",
"(",
"'Elendev\\\\RoxyFilemanBundle\\\\FileSystem\\\\LocalFileSystem'",
",",
"array",
"(",
"$",
"profileConfig",
"[",
"'local_file_system'",
"]",
"[",
"'base_path'",
"]",
",",
"$",
"profileConfig",
"[",
"'local_file_system'",
"]",
"[",
"'base_url'",
"]",
",",
")",
")",
";",
"$",
"container",
"->",
"setDefinition",
"(",
"'elendev_roxy_fileman.'",
".",
"$",
"profileName",
".",
"'.file_system'",
",",
"$",
"fileSystemDefinition",
")",
"->",
"setPublic",
"(",
"true",
")",
";",
"}",
"}",
"}",
"else",
"{",
"// Assumes legacy syntax if no profile is defined.",
"// Alias correct file system service if one is specified",
"if",
"(",
"!",
"empty",
"(",
"$",
"config",
"[",
"'file_system_service_id'",
"]",
")",
")",
"{",
"$",
"container",
"->",
"setAlias",
"(",
"'elendev_roxy_fileman.file_system'",
",",
"$",
"config",
"[",
"'file_system_service_id'",
"]",
")",
"->",
"setPublic",
"(",
"true",
")",
";",
"$",
"container",
"->",
"removeDefinition",
"(",
"'elendev_roxy_fileman.local_file_system'",
")",
";",
"}",
"else",
"{",
"if",
"(",
"empty",
"(",
"$",
"config",
"[",
"'local_file_system'",
"]",
")",
"||",
"empty",
"(",
"$",
"config",
"[",
"'local_file_system'",
"]",
"[",
"'base_path'",
"]",
")",
"||",
"empty",
"(",
"$",
"config",
"[",
"'local_file_system'",
"]",
"[",
"'base_url'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidConfigurationException",
"(",
"'local_file_system.base_path and local_file_system.base_url have to be defined if file_system_service_id is empty in elendev_roxyfileman configuration'",
")",
";",
"}",
"$",
"container",
"->",
"setParameter",
"(",
"'elendev_roxyfileman.local_file_system.base_path'",
",",
"$",
"config",
"[",
"'local_file_system'",
"]",
"[",
"'base_path'",
"]",
")",
";",
"$",
"container",
"->",
"setParameter",
"(",
"'elendev_roxyfileman.local_file_system.base_url'",
",",
"$",
"config",
"[",
"'local_file_system'",
"]",
"[",
"'base_url'",
"]",
")",
";",
"}",
"$",
"loader",
"=",
"new",
"Loader",
"\\",
"YamlFileLoader",
"(",
"$",
"container",
",",
"new",
"FileLocator",
"(",
"__DIR__",
".",
"'/../Resources/config'",
")",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services.yml'",
")",
";",
"}",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/Elendev/ElendevRoxyFilemanBundle/blob/2173ce00e4f1d22960eec70b437a5908f4681dc1/DependencyInjection/ElendevRoxyFilemanExtension.php#L30-L96
|
baleen/cli
|
src/CommandBus/Timeline/MigrateHandler.php
|
MigrateHandler.handle
|
public function handle(MigrateMessage $command)
{
$input = $command->getInput();
$output = $command->getOutput();
$this->command = $command;
$targetArg = (string) $input->getArgument(MigrateMessage::ARG_TARGET);
$strategy = (string) $this->getStrategyOption($input);
$options = new Options(Options::DIRECTION_UP); // this value will get replaced by timeline later
$options->setDryRun($input->getOption(MigrateMessage::OPT_DRY_RUN));
$options->setExceptionOnSkip(false);
$this->saveChanges = !$input->getOption(MigrateMessage::OPT_NO_STORAGE) && !$options->isDryRun();
$this->trackProgress = ($output->getVerbosity() !== OutputInterface::VERBOSITY_QUIET)
&& !$input->getOption(MigrateMessage::OPT_NOPROGRESS);
$this->attachEvents($output, $command->getTimeline()->getEventDispatcher());
/* @var \Baleen\Migrations\Version\Collection\LinkedVersions $results */
$command->getTimeline()->$strategy($targetArg, $options);
}
|
php
|
public function handle(MigrateMessage $command)
{
$input = $command->getInput();
$output = $command->getOutput();
$this->command = $command;
$targetArg = (string) $input->getArgument(MigrateMessage::ARG_TARGET);
$strategy = (string) $this->getStrategyOption($input);
$options = new Options(Options::DIRECTION_UP); // this value will get replaced by timeline later
$options->setDryRun($input->getOption(MigrateMessage::OPT_DRY_RUN));
$options->setExceptionOnSkip(false);
$this->saveChanges = !$input->getOption(MigrateMessage::OPT_NO_STORAGE) && !$options->isDryRun();
$this->trackProgress = ($output->getVerbosity() !== OutputInterface::VERBOSITY_QUIET)
&& !$input->getOption(MigrateMessage::OPT_NOPROGRESS);
$this->attachEvents($output, $command->getTimeline()->getEventDispatcher());
/* @var \Baleen\Migrations\Version\Collection\LinkedVersions $results */
$command->getTimeline()->$strategy($targetArg, $options);
}
|
[
"public",
"function",
"handle",
"(",
"MigrateMessage",
"$",
"command",
")",
"{",
"$",
"input",
"=",
"$",
"command",
"->",
"getInput",
"(",
")",
";",
"$",
"output",
"=",
"$",
"command",
"->",
"getOutput",
"(",
")",
";",
"$",
"this",
"->",
"command",
"=",
"$",
"command",
";",
"$",
"targetArg",
"=",
"(",
"string",
")",
"$",
"input",
"->",
"getArgument",
"(",
"MigrateMessage",
"::",
"ARG_TARGET",
")",
";",
"$",
"strategy",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"getStrategyOption",
"(",
"$",
"input",
")",
";",
"$",
"options",
"=",
"new",
"Options",
"(",
"Options",
"::",
"DIRECTION_UP",
")",
";",
"// this value will get replaced by timeline later",
"$",
"options",
"->",
"setDryRun",
"(",
"$",
"input",
"->",
"getOption",
"(",
"MigrateMessage",
"::",
"OPT_DRY_RUN",
")",
")",
";",
"$",
"options",
"->",
"setExceptionOnSkip",
"(",
"false",
")",
";",
"$",
"this",
"->",
"saveChanges",
"=",
"!",
"$",
"input",
"->",
"getOption",
"(",
"MigrateMessage",
"::",
"OPT_NO_STORAGE",
")",
"&&",
"!",
"$",
"options",
"->",
"isDryRun",
"(",
")",
";",
"$",
"this",
"->",
"trackProgress",
"=",
"(",
"$",
"output",
"->",
"getVerbosity",
"(",
")",
"!==",
"OutputInterface",
"::",
"VERBOSITY_QUIET",
")",
"&&",
"!",
"$",
"input",
"->",
"getOption",
"(",
"MigrateMessage",
"::",
"OPT_NOPROGRESS",
")",
";",
"$",
"this",
"->",
"attachEvents",
"(",
"$",
"output",
",",
"$",
"command",
"->",
"getTimeline",
"(",
")",
"->",
"getEventDispatcher",
"(",
")",
")",
";",
"/* @var \\Baleen\\Migrations\\Version\\Collection\\LinkedVersions $results */",
"$",
"command",
"->",
"getTimeline",
"(",
")",
"->",
"$",
"strategy",
"(",
"$",
"targetArg",
",",
"$",
"options",
")",
";",
"}"
] |
handle.
@param MigrateMessage $command
@throws CliException
|
[
"handle",
"."
] |
train
|
https://github.com/baleen/cli/blob/2ecbc7179c5800c9075fd93204ef25da375536ed/src/CommandBus/Timeline/MigrateHandler.php#L69-L91
|
baleen/cli
|
src/CommandBus/Timeline/MigrateHandler.php
|
MigrateHandler.saveVersionListener
|
public function saveVersionListener(MigrationEvent $event)
{
$version = $event->getVersion();
$this->command->getStorage()->update($version);
}
|
php
|
public function saveVersionListener(MigrationEvent $event)
{
$version = $event->getVersion();
$this->command->getStorage()->update($version);
}
|
[
"public",
"function",
"saveVersionListener",
"(",
"MigrationEvent",
"$",
"event",
")",
"{",
"$",
"version",
"=",
"$",
"event",
"->",
"getVersion",
"(",
")",
";",
"$",
"this",
"->",
"command",
"->",
"getStorage",
"(",
")",
"->",
"update",
"(",
"$",
"version",
")",
";",
"}"
] |
saveVersionListener.
@param MigrationEvent $event
|
[
"saveVersionListener",
"."
] |
train
|
https://github.com/baleen/cli/blob/2ecbc7179c5800c9075fd93204ef25da375536ed/src/CommandBus/Timeline/MigrateHandler.php#L117-L121
|
baleen/cli
|
src/CommandBus/Timeline/MigrateHandler.php
|
MigrateHandler.onMigrationAfter
|
public function onMigrationAfter(MigrationEvent $event)
{
if ($this->progress) {
$runProgress = $event->getProgress();
$this->progress->setProgress($runProgress->getCurrent());
}
}
|
php
|
public function onMigrationAfter(MigrationEvent $event)
{
if ($this->progress) {
$runProgress = $event->getProgress();
$this->progress->setProgress($runProgress->getCurrent());
}
}
|
[
"public",
"function",
"onMigrationAfter",
"(",
"MigrationEvent",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"progress",
")",
"{",
"$",
"runProgress",
"=",
"$",
"event",
"->",
"getProgress",
"(",
")",
";",
"$",
"this",
"->",
"progress",
"->",
"setProgress",
"(",
"$",
"runProgress",
"->",
"getCurrent",
"(",
")",
")",
";",
"}",
"}"
] |
onMigrationAfter.
@param MigrationEvent $event
|
[
"onMigrationAfter",
"."
] |
train
|
https://github.com/baleen/cli/blob/2ecbc7179c5800c9075fd93204ef25da375536ed/src/CommandBus/Timeline/MigrateHandler.php#L143-L149
|
baleen/cli
|
src/CommandBus/Timeline/MigrateHandler.php
|
MigrateHandler.onCollectionBefore
|
public function onCollectionBefore(CollectionEvent $event)
{
$target = $event->getTarget();
$this->output->writeln(sprintf(
'<info>[START]</info> Migrating %s to <comment>%s</comment>:',
$event->getOptions()->isDirectionUp() ? 'up' : 'down',
$target->getId()
));
if ($this->trackProgress) {
$this->progress = new ProgressBar($this->output, $event->getProgress()->getTotal());
$this->progress->setFormat('verbose');
$this->progress->setProgress(0);
}
}
|
php
|
public function onCollectionBefore(CollectionEvent $event)
{
$target = $event->getTarget();
$this->output->writeln(sprintf(
'<info>[START]</info> Migrating %s to <comment>%s</comment>:',
$event->getOptions()->isDirectionUp() ? 'up' : 'down',
$target->getId()
));
if ($this->trackProgress) {
$this->progress = new ProgressBar($this->output, $event->getProgress()->getTotal());
$this->progress->setFormat('verbose');
$this->progress->setProgress(0);
}
}
|
[
"public",
"function",
"onCollectionBefore",
"(",
"CollectionEvent",
"$",
"event",
")",
"{",
"$",
"target",
"=",
"$",
"event",
"->",
"getTarget",
"(",
")",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'<info>[START]</info> Migrating %s to <comment>%s</comment>:'",
",",
"$",
"event",
"->",
"getOptions",
"(",
")",
"->",
"isDirectionUp",
"(",
")",
"?",
"'up'",
":",
"'down'",
",",
"$",
"target",
"->",
"getId",
"(",
")",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"trackProgress",
")",
"{",
"$",
"this",
"->",
"progress",
"=",
"new",
"ProgressBar",
"(",
"$",
"this",
"->",
"output",
",",
"$",
"event",
"->",
"getProgress",
"(",
")",
"->",
"getTotal",
"(",
")",
")",
";",
"$",
"this",
"->",
"progress",
"->",
"setFormat",
"(",
"'verbose'",
")",
";",
"$",
"this",
"->",
"progress",
"->",
"setProgress",
"(",
"0",
")",
";",
"}",
"}"
] |
onCollectionBefore.
@param CollectionEvent $event
|
[
"onCollectionBefore",
"."
] |
train
|
https://github.com/baleen/cli/blob/2ecbc7179c5800c9075fd93204ef25da375536ed/src/CommandBus/Timeline/MigrateHandler.php#L156-L170
|
baleen/cli
|
src/CommandBus/Timeline/MigrateHandler.php
|
MigrateHandler.onCollectionAfter
|
public function onCollectionAfter()
{
if ($this->progress) {
$this->progress->finish();
$this->output->writeln(''); // new line after progress bar
}
$this->output->writeln('<info>[END]</info>');
}
|
php
|
public function onCollectionAfter()
{
if ($this->progress) {
$this->progress->finish();
$this->output->writeln(''); // new line after progress bar
}
$this->output->writeln('<info>[END]</info>');
}
|
[
"public",
"function",
"onCollectionAfter",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"progress",
")",
"{",
"$",
"this",
"->",
"progress",
"->",
"finish",
"(",
")",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"''",
")",
";",
"// new line after progress bar",
"}",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"'<info>[END]</info>'",
")",
";",
"}"
] |
onCollectionAfter.
|
[
"onCollectionAfter",
"."
] |
train
|
https://github.com/baleen/cli/blob/2ecbc7179c5800c9075fd93204ef25da375536ed/src/CommandBus/Timeline/MigrateHandler.php#L175-L182
|
baleen/cli
|
src/CommandBus/Timeline/MigrateHandler.php
|
MigrateHandler.getStrategyOption
|
protected function getStrategyOption(InputInterface $input)
{
$strategy = strtolower($input->getOption(MigrateMessage::OPT_STRATEGY));
if (!isset($this->strategies[$strategy])) {
throw new CliException(sprintf(
'Unknown strategy "%s". Must be one of: %s',
$strategy,
implode(', ', array_keys($this->strategies))
));
}
return $this->strategies[$strategy];
}
|
php
|
protected function getStrategyOption(InputInterface $input)
{
$strategy = strtolower($input->getOption(MigrateMessage::OPT_STRATEGY));
if (!isset($this->strategies[$strategy])) {
throw new CliException(sprintf(
'Unknown strategy "%s". Must be one of: %s',
$strategy,
implode(', ', array_keys($this->strategies))
));
}
return $this->strategies[$strategy];
}
|
[
"protected",
"function",
"getStrategyOption",
"(",
"InputInterface",
"$",
"input",
")",
"{",
"$",
"strategy",
"=",
"strtolower",
"(",
"$",
"input",
"->",
"getOption",
"(",
"MigrateMessage",
"::",
"OPT_STRATEGY",
")",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"strategies",
"[",
"$",
"strategy",
"]",
")",
")",
"{",
"throw",
"new",
"CliException",
"(",
"sprintf",
"(",
"'Unknown strategy \"%s\". Must be one of: %s'",
",",
"$",
"strategy",
",",
"implode",
"(",
"', '",
",",
"array_keys",
"(",
"$",
"this",
"->",
"strategies",
")",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"strategies",
"[",
"$",
"strategy",
"]",
";",
"}"
] |
@param InputInterface $input
@return string
@throws CliException
|
[
"@param",
"InputInterface",
"$input"
] |
train
|
https://github.com/baleen/cli/blob/2ecbc7179c5800c9075fd93204ef25da375536ed/src/CommandBus/Timeline/MigrateHandler.php#L191-L203
|
fsi-open/datasource-bundle
|
Twig/TokenParser/DataSourceRouteTokenParser.php
|
DataSourceRouteTokenParser.parse
|
public function parse(\Twig_Token $token)
{
$stream = $this->parser->getStream();
$dataSource = $this->parser->getExpressionParser()->parseExpression();
$route = $this->parser->getExpressionParser()->parseExpression();
$additional_parameters = new \Twig_Node_Expression_Array([], $stream->getCurrent()->getLine());
if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'with')) {
$this->parser->getStream()->next();
if ($this->parser->getStream()->test(\Twig_Token::PUNCTUATION_TYPE) || $this->parser->getStream()->test(\Twig_Token::NAME_TYPE)) {
$additional_parameters = $this->parser->getExpressionParser()->parseExpression();
}
}
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
return new DataSourceRouteNode($dataSource, $route, $additional_parameters, $token->getLine(), $this->getTag());
}
|
php
|
public function parse(\Twig_Token $token)
{
$stream = $this->parser->getStream();
$dataSource = $this->parser->getExpressionParser()->parseExpression();
$route = $this->parser->getExpressionParser()->parseExpression();
$additional_parameters = new \Twig_Node_Expression_Array([], $stream->getCurrent()->getLine());
if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'with')) {
$this->parser->getStream()->next();
if ($this->parser->getStream()->test(\Twig_Token::PUNCTUATION_TYPE) || $this->parser->getStream()->test(\Twig_Token::NAME_TYPE)) {
$additional_parameters = $this->parser->getExpressionParser()->parseExpression();
}
}
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
return new DataSourceRouteNode($dataSource, $route, $additional_parameters, $token->getLine(), $this->getTag());
}
|
[
"public",
"function",
"parse",
"(",
"\\",
"Twig_Token",
"$",
"token",
")",
"{",
"$",
"stream",
"=",
"$",
"this",
"->",
"parser",
"->",
"getStream",
"(",
")",
";",
"$",
"dataSource",
"=",
"$",
"this",
"->",
"parser",
"->",
"getExpressionParser",
"(",
")",
"->",
"parseExpression",
"(",
")",
";",
"$",
"route",
"=",
"$",
"this",
"->",
"parser",
"->",
"getExpressionParser",
"(",
")",
"->",
"parseExpression",
"(",
")",
";",
"$",
"additional_parameters",
"=",
"new",
"\\",
"Twig_Node_Expression_Array",
"(",
"[",
"]",
",",
"$",
"stream",
"->",
"getCurrent",
"(",
")",
"->",
"getLine",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"parser",
"->",
"getStream",
"(",
")",
"->",
"test",
"(",
"\\",
"Twig_Token",
"::",
"NAME_TYPE",
",",
"'with'",
")",
")",
"{",
"$",
"this",
"->",
"parser",
"->",
"getStream",
"(",
")",
"->",
"next",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"parser",
"->",
"getStream",
"(",
")",
"->",
"test",
"(",
"\\",
"Twig_Token",
"::",
"PUNCTUATION_TYPE",
")",
"||",
"$",
"this",
"->",
"parser",
"->",
"getStream",
"(",
")",
"->",
"test",
"(",
"\\",
"Twig_Token",
"::",
"NAME_TYPE",
")",
")",
"{",
"$",
"additional_parameters",
"=",
"$",
"this",
"->",
"parser",
"->",
"getExpressionParser",
"(",
")",
"->",
"parseExpression",
"(",
")",
";",
"}",
"}",
"$",
"stream",
"->",
"expect",
"(",
"\\",
"Twig_Token",
"::",
"BLOCK_END_TYPE",
")",
";",
"return",
"new",
"DataSourceRouteNode",
"(",
"$",
"dataSource",
",",
"$",
"route",
",",
"$",
"additional_parameters",
",",
"$",
"token",
"->",
"getLine",
"(",
")",
",",
"$",
"this",
"->",
"getTag",
"(",
")",
")",
";",
"}"
] |
{@inheritDoc}
|
[
"{"
] |
train
|
https://github.com/fsi-open/datasource-bundle/blob/06964672c838af9f4125065e3a90b2df4e8aa077/Twig/TokenParser/DataSourceRouteTokenParser.php#L19-L37
|
bfitech/zapcore
|
dev/RouterDev.php
|
RouterDev.reset
|
public static function reset() {
$_SERVER['REQUEST_URI'] = '/';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_GET = $_POST = $_FILES = $_REQUEST = [];
self::$code = 200;
self::$head = [];
self::$body_raw = null;
self::$body = null;
self::$errno = 0;
self::$data = [];
}
|
php
|
public static function reset() {
$_SERVER['REQUEST_URI'] = '/';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_GET = $_POST = $_FILES = $_REQUEST = [];
self::$code = 200;
self::$head = [];
self::$body_raw = null;
self::$body = null;
self::$errno = 0;
self::$data = [];
}
|
[
"public",
"static",
"function",
"reset",
"(",
")",
"{",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
"=",
"'/'",
";",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"=",
"'GET'",
";",
"$",
"_GET",
"=",
"$",
"_POST",
"=",
"$",
"_FILES",
"=",
"$",
"_REQUEST",
"=",
"[",
"]",
";",
"self",
"::",
"$",
"code",
"=",
"200",
";",
"self",
"::",
"$",
"head",
"=",
"[",
"]",
";",
"self",
"::",
"$",
"body_raw",
"=",
"null",
";",
"self",
"::",
"$",
"body",
"=",
"null",
";",
"self",
"::",
"$",
"errno",
"=",
"0",
";",
"self",
"::",
"$",
"data",
"=",
"[",
"]",
";",
"}"
] |
Reset fake HTTP variables and properties.
|
[
"Reset",
"fake",
"HTTP",
"variables",
"and",
"properties",
"."
] |
train
|
https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/dev/RouterDev.php#L35-L45
|
bfitech/zapcore
|
dev/RouterDev.php
|
RouterDev.header
|
public static function header(
string $header_string, bool $replace=false
) {
if (strpos($header_string, 'HTTP/1') !== false) {
self::$code = explode(' ', $header_string)[1];
} else {
self::$head[] = $header_string;
}
}
|
php
|
public static function header(
string $header_string, bool $replace=false
) {
if (strpos($header_string, 'HTTP/1') !== false) {
self::$code = explode(' ', $header_string)[1];
} else {
self::$head[] = $header_string;
}
}
|
[
"public",
"static",
"function",
"header",
"(",
"string",
"$",
"header_string",
",",
"bool",
"$",
"replace",
"=",
"false",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"header_string",
",",
"'HTTP/1'",
")",
"!==",
"false",
")",
"{",
"self",
"::",
"$",
"code",
"=",
"explode",
"(",
"' '",
",",
"$",
"header_string",
")",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"self",
"::",
"$",
"head",
"[",
"]",
"=",
"$",
"header_string",
";",
"}",
"}"
] |
Patched Header::header().
@param string $header_string Header string.
@param bool $replace The 'replace' option for standard
header() function.
@cond
@SuppressWarnings(PHPMD.UnusedFormalParameter)
@endcond
|
[
"Patched",
"Header",
"::",
"header",
"()",
"."
] |
train
|
https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/dev/RouterDev.php#L58-L66
|
bfitech/zapcore
|
dev/RouterDev.php
|
RouterDev.send_cookie
|
public static function send_cookie(
$name, $value='', $expire=0, $path='', $domain='',
$secure=false, $httponly=false
) {
if (!isset($_COOKIE))
$_COOKIE = [];
if ($expire > 0) {
$_COOKIE[$name] = $value;
return;
}
if (isset($_COOKIE[$name]))
unset($_COOKIE[$name]);
}
|
php
|
public static function send_cookie(
$name, $value='', $expire=0, $path='', $domain='',
$secure=false, $httponly=false
) {
if (!isset($_COOKIE))
$_COOKIE = [];
if ($expire > 0) {
$_COOKIE[$name] = $value;
return;
}
if (isset($_COOKIE[$name]))
unset($_COOKIE[$name]);
}
|
[
"public",
"static",
"function",
"send_cookie",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"''",
",",
"$",
"expire",
"=",
"0",
",",
"$",
"path",
"=",
"''",
",",
"$",
"domain",
"=",
"''",
",",
"$",
"secure",
"=",
"false",
",",
"$",
"httponly",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_COOKIE",
")",
")",
"$",
"_COOKIE",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"expire",
">",
"0",
")",
"{",
"$",
"_COOKIE",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"return",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_COOKIE",
"[",
"$",
"name",
"]",
")",
")",
"unset",
"(",
"$",
"_COOKIE",
"[",
"$",
"name",
"]",
")",
";",
"}"
] |
Patched Header::send_cookie().
@cond
@SuppressWarnings(PHPMD.UnusedFormalParameter)
@endcond
|
[
"Patched",
"Header",
"::",
"send_cookie",
"()",
"."
] |
train
|
https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/dev/RouterDev.php#L75-L87
|
bfitech/zapcore
|
dev/RouterDev.php
|
RouterDev.wrap_callback
|
public function wrap_callback(callable $callback, array $args=[]) {
ob_start();
foreach (self::$override_args as $key => $val)
$args[$key] = $val;
$callback($args);
self::$body_raw = ob_get_clean();
self::$body = json_decode(self::$body_raw, true);
if (self::$body) {
self::$errno = self::$body['errno'];
self::$data = self::$body['data'];
} else {
self::$errno = 0;
self::$data = [];
}
}
|
php
|
public function wrap_callback(callable $callback, array $args=[]) {
ob_start();
foreach (self::$override_args as $key => $val)
$args[$key] = $val;
$callback($args);
self::$body_raw = ob_get_clean();
self::$body = json_decode(self::$body_raw, true);
if (self::$body) {
self::$errno = self::$body['errno'];
self::$data = self::$body['data'];
} else {
self::$errno = 0;
self::$data = [];
}
}
|
[
"public",
"function",
"wrap_callback",
"(",
"callable",
"$",
"callback",
",",
"array",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"ob_start",
"(",
")",
";",
"foreach",
"(",
"self",
"::",
"$",
"override_args",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"$",
"args",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"$",
"callback",
"(",
"$",
"args",
")",
";",
"self",
"::",
"$",
"body_raw",
"=",
"ob_get_clean",
"(",
")",
";",
"self",
"::",
"$",
"body",
"=",
"json_decode",
"(",
"self",
"::",
"$",
"body_raw",
",",
"true",
")",
";",
"if",
"(",
"self",
"::",
"$",
"body",
")",
"{",
"self",
"::",
"$",
"errno",
"=",
"self",
"::",
"$",
"body",
"[",
"'errno'",
"]",
";",
"self",
"::",
"$",
"data",
"=",
"self",
"::",
"$",
"body",
"[",
"'data'",
"]",
";",
"}",
"else",
"{",
"self",
"::",
"$",
"errno",
"=",
"0",
";",
"self",
"::",
"$",
"data",
"=",
"[",
"]",
";",
"}",
"}"
] |
Patched Router::wrap_callback().
@param callable $callback Callback method.
@param array $args HTTP variables collected by router.
|
[
"Patched",
"Router",
"::",
"wrap_callback",
"()",
"."
] |
train
|
https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/dev/RouterDev.php#L106-L120
|
bfitech/zapcore
|
dev/RouterDev.php
|
RouterDev.override_callback_args
|
public function override_callback_args(array $args=[]) {
foreach ($args as $key => $val) {
if (!in_array($key, [
'get', 'post', 'files', 'put', 'patch', 'delete',
]))
continue;
self::$override_args[$key] = $val;
}
}
|
php
|
public function override_callback_args(array $args=[]) {
foreach ($args as $key => $val) {
if (!in_array($key, [
'get', 'post', 'files', 'put', 'patch', 'delete',
]))
continue;
self::$override_args[$key] = $val;
}
}
|
[
"public",
"function",
"override_callback_args",
"(",
"array",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"args",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"key",
",",
"[",
"'get'",
",",
"'post'",
",",
"'files'",
",",
"'put'",
",",
"'patch'",
",",
"'delete'",
",",
"]",
")",
")",
"continue",
";",
"self",
"::",
"$",
"override_args",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"}"
] |
Overrides callback args.
Use this in case you want to manipulate collected HTTP
variables without actually changing the entire route.
@param array $args Dict of HTTP variables for overriding
existing args. Key must be one or more of: 'get',
'post', 'files', 'put', 'patch', 'delete'. Invalid
keys are ignored.
|
[
"Overrides",
"callback",
"args",
"."
] |
train
|
https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/dev/RouterDev.php#L133-L141
|
bfitech/zapcore
|
dev/RouterDev.php
|
RouterDev.abort_custom
|
public function abort_custom(int $code) {
self::$code = $code;
static::$body_raw = "ERROR: $code";
self::$body = "ERROR: $code";
self::$errno = $code;
self::$data = [];
}
|
php
|
public function abort_custom(int $code) {
self::$code = $code;
static::$body_raw = "ERROR: $code";
self::$body = "ERROR: $code";
self::$errno = $code;
self::$data = [];
}
|
[
"public",
"function",
"abort_custom",
"(",
"int",
"$",
"code",
")",
"{",
"self",
"::",
"$",
"code",
"=",
"$",
"code",
";",
"static",
"::",
"$",
"body_raw",
"=",
"\"ERROR: $code\"",
";",
"self",
"::",
"$",
"body",
"=",
"\"ERROR: $code\"",
";",
"self",
"::",
"$",
"errno",
"=",
"$",
"code",
";",
"self",
"::",
"$",
"data",
"=",
"[",
"]",
";",
"}"
] |
Custom abort for testing.
@param int $code HTTP error code.
|
[
"Custom",
"abort",
"for",
"testing",
"."
] |
train
|
https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/dev/RouterDev.php#L148-L154
|
bfitech/zapcore
|
dev/RouterDev.php
|
RouterDev.redirect_custom
|
public function redirect_custom(string $url) {
self::$code = 301;
self::$head = ["Location: $url"];
self::$body_raw = self::$body = "Location: $url";
self::$errno = 0;
self::$data = [$url];
}
|
php
|
public function redirect_custom(string $url) {
self::$code = 301;
self::$head = ["Location: $url"];
self::$body_raw = self::$body = "Location: $url";
self::$errno = 0;
self::$data = [$url];
}
|
[
"public",
"function",
"redirect_custom",
"(",
"string",
"$",
"url",
")",
"{",
"self",
"::",
"$",
"code",
"=",
"301",
";",
"self",
"::",
"$",
"head",
"=",
"[",
"\"Location: $url\"",
"]",
";",
"self",
"::",
"$",
"body_raw",
"=",
"self",
"::",
"$",
"body",
"=",
"\"Location: $url\"",
";",
"self",
"::",
"$",
"errno",
"=",
"0",
";",
"self",
"::",
"$",
"data",
"=",
"[",
"$",
"url",
"]",
";",
"}"
] |
Custom redirect for testing.
@param string $url Destination URL.
|
[
"Custom",
"redirect",
"for",
"testing",
"."
] |
train
|
https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/dev/RouterDev.php#L161-L167
|
bfitech/zapcore
|
dev/RouterDev.php
|
RouterDev.static_file_custom
|
public function static_file_custom(
string $path, int $cache=0, $disposition=null
) {
self::reset();
if (file_exists($path)) {
self::$code = 200;
self::$body_raw = file_get_contents($path);
self::$body = "Path: $path";
self::$errno = 0;
self::$data = [$path];
} else {
self::$code = 404;
}
}
|
php
|
public function static_file_custom(
string $path, int $cache=0, $disposition=null
) {
self::reset();
if (file_exists($path)) {
self::$code = 200;
self::$body_raw = file_get_contents($path);
self::$body = "Path: $path";
self::$errno = 0;
self::$data = [$path];
} else {
self::$code = 404;
}
}
|
[
"public",
"function",
"static_file_custom",
"(",
"string",
"$",
"path",
",",
"int",
"$",
"cache",
"=",
"0",
",",
"$",
"disposition",
"=",
"null",
")",
"{",
"self",
"::",
"reset",
"(",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"self",
"::",
"$",
"code",
"=",
"200",
";",
"self",
"::",
"$",
"body_raw",
"=",
"file_get_contents",
"(",
"$",
"path",
")",
";",
"self",
"::",
"$",
"body",
"=",
"\"Path: $path\"",
";",
"self",
"::",
"$",
"errno",
"=",
"0",
";",
"self",
"::",
"$",
"data",
"=",
"[",
"$",
"path",
"]",
";",
"}",
"else",
"{",
"self",
"::",
"$",
"code",
"=",
"404",
";",
"}",
"}"
] |
Custom static file serving for testing.
@param string $path Absolute path to file.
@param int $cache Cache age in seconds.
@param mixed $disposition If string, use it as
content-disposition in header. If true, infer from basename.
If null, no content-disposition header is sent.
@cond
@SuppressWarnings(PHPMD.UnusedFormalParameter)
@endcond
|
[
"Custom",
"static",
"file",
"serving",
"for",
"testing",
"."
] |
train
|
https://github.com/bfitech/zapcore/blob/0ae4cb9370876ab3583556bf272063685ec57948/dev/RouterDev.php#L182-L195
|
drupol/valuewrapper
|
src/ValueWrapper.php
|
ValueWrapper.make
|
public function make($value): ValueInterface
{
$type = $this->getType($value);
switch ($type) {
case 'object':
if ($value instanceof ValueInterface) {
return $value;
}
$mappings = self::$objectMappingRegistry;
$type = \get_class($value);
if (0 === \strpos($type, 'class@anonymous')) {
$type = 'Anonymous';
}
break;
case 'resource':
$mappings = self::$resourceMappingRegistry;
$type = \get_resource_type($value);
break;
default:
$mappings = self::$typeMappingRegistry;
break;
}
if (isset($mappings[$type])) {
return new $mappings[$type]($value);
}
throw new \OutOfBoundsException(
\sprintf('Unable to find a wrapping class for value type "%s".', $type)
);
}
|
php
|
public function make($value): ValueInterface
{
$type = $this->getType($value);
switch ($type) {
case 'object':
if ($value instanceof ValueInterface) {
return $value;
}
$mappings = self::$objectMappingRegistry;
$type = \get_class($value);
if (0 === \strpos($type, 'class@anonymous')) {
$type = 'Anonymous';
}
break;
case 'resource':
$mappings = self::$resourceMappingRegistry;
$type = \get_resource_type($value);
break;
default:
$mappings = self::$typeMappingRegistry;
break;
}
if (isset($mappings[$type])) {
return new $mappings[$type]($value);
}
throw new \OutOfBoundsException(
\sprintf('Unable to find a wrapping class for value type "%s".', $type)
);
}
|
[
"public",
"function",
"make",
"(",
"$",
"value",
")",
":",
"ValueInterface",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"getType",
"(",
"$",
"value",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'object'",
":",
"if",
"(",
"$",
"value",
"instanceof",
"ValueInterface",
")",
"{",
"return",
"$",
"value",
";",
"}",
"$",
"mappings",
"=",
"self",
"::",
"$",
"objectMappingRegistry",
";",
"$",
"type",
"=",
"\\",
"get_class",
"(",
"$",
"value",
")",
";",
"if",
"(",
"0",
"===",
"\\",
"strpos",
"(",
"$",
"type",
",",
"'class@anonymous'",
")",
")",
"{",
"$",
"type",
"=",
"'Anonymous'",
";",
"}",
"break",
";",
"case",
"'resource'",
":",
"$",
"mappings",
"=",
"self",
"::",
"$",
"resourceMappingRegistry",
";",
"$",
"type",
"=",
"\\",
"get_resource_type",
"(",
"$",
"value",
")",
";",
"break",
";",
"default",
":",
"$",
"mappings",
"=",
"self",
"::",
"$",
"typeMappingRegistry",
";",
"break",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mappings",
"[",
"$",
"type",
"]",
")",
")",
"{",
"return",
"new",
"$",
"mappings",
"[",
"$",
"type",
"]",
"(",
"$",
"value",
")",
";",
"}",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"\\",
"sprintf",
"(",
"'Unable to find a wrapping class for value type \"%s\".'",
",",
"$",
"type",
")",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/drupol/valuewrapper/blob/49cc07e4d0284718c24ba6e9cf524c1f4226694e/src/ValueWrapper.php#L83-L121
|
Stampie/stampie-bundle
|
Command/SendEmailCommand.php
|
SendEmailCommand.execute
|
protected function execute(InputInterface $input, OutputInterface $output)
{
$to = $input->getArgument('to');
$from = $input->getArgument('from');
$mailerClass = new \ReflectionClass($this->mailer);
$output->writeln(sprintf('Sending message from <info>%s</info> to <info>%s</info> using <info>%s</info> mailer',
$from, $to, $mailerClass->getShortName()));
$identity = new Identity($to);
$message = new TestMessage($identity, $from);
$message->setText('This is a test message');
$this->mailer->send($message);
$output->writeln(sprintf('Message successfully sent to <info>%s</info>', $to));
}
|
php
|
protected function execute(InputInterface $input, OutputInterface $output)
{
$to = $input->getArgument('to');
$from = $input->getArgument('from');
$mailerClass = new \ReflectionClass($this->mailer);
$output->writeln(sprintf('Sending message from <info>%s</info> to <info>%s</info> using <info>%s</info> mailer',
$from, $to, $mailerClass->getShortName()));
$identity = new Identity($to);
$message = new TestMessage($identity, $from);
$message->setText('This is a test message');
$this->mailer->send($message);
$output->writeln(sprintf('Message successfully sent to <info>%s</info>', $to));
}
|
[
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"to",
"=",
"$",
"input",
"->",
"getArgument",
"(",
"'to'",
")",
";",
"$",
"from",
"=",
"$",
"input",
"->",
"getArgument",
"(",
"'from'",
")",
";",
"$",
"mailerClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"this",
"->",
"mailer",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'Sending message from <info>%s</info> to <info>%s</info> using <info>%s</info> mailer'",
",",
"$",
"from",
",",
"$",
"to",
",",
"$",
"mailerClass",
"->",
"getShortName",
"(",
")",
")",
")",
";",
"$",
"identity",
"=",
"new",
"Identity",
"(",
"$",
"to",
")",
";",
"$",
"message",
"=",
"new",
"TestMessage",
"(",
"$",
"identity",
",",
"$",
"from",
")",
";",
"$",
"message",
"->",
"setText",
"(",
"'This is a test message'",
")",
";",
"$",
"this",
"->",
"mailer",
"->",
"send",
"(",
"$",
"message",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'Message successfully sent to <info>%s</info>'",
",",
"$",
"to",
")",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/Stampie/stampie-bundle/blob/a996d355a9d24ff667096315cc70b92f426b45f1/Command/SendEmailCommand.php#L50-L65
|
ftrrtf/FtrrtfRollbarBundle
|
Twig/RollbarExtension.php
|
RollbarExtension.getInitRollbarCode
|
public function getInitRollbarCode(array $context)
{
$accessToken = $this->notifierOptions['access_token'];
$config = array(
'accessToken' => $accessToken,
'captureUncaught' => true,
'payload' => array(
'environment' => $this->environmentOptions['environment'],
),
);
$user = $context['app']->getUser();
if (isset($user)) {
$config['payload']['person'] = $this->userHelper->buildUserData($user);
}
if ($this->notifierOptions['source_map_enabled']) {
$config['payload']['client'] = array(
'javascript' => array(
'source_map_enabled' => $this->notifierOptions['source_map_enabled'],
'code_version' => $this->notifierOptions['code_version'],
'guess_uncaught_frames' => $this->notifierOptions['guess_uncaught_frames'],
),
);
}
$rollbarJsVersion = $this->notifierOptions['rollbarjs_version'];
$config = json_encode($config);
$checkIgnoreConfig = $this->getCheckIgnoreConfig();
$transform = $this->transformPayloadFunctionProvider->getTransformFunctionCode();
return <<<END_HTML
<script>
var _rollbarConfig = {$config};
_rollbarConfig.transform = {$transform};
// Rollbar Snippet
!function(r){function o(e){if(t[e])return t[e].exports;var n=t[e]={exports:{},id:e,loaded:!1};return r[e].call(n.exports,n,n.exports,o),n.loaded=!0,n.exports}var t={};return o.m=r,o.c=t,o.p="",o(0)}([function(r,o,t){"use strict";var e=t(1).Rollbar,n=t(2);_rollbarConfig.rollbarJsUrl=_rollbarConfig.rollbarJsUrl||"https://d37gvrvc0wt4s1.cloudfront.net/js/{$rollbarJsVersion}/rollbar.min.js";var a=e.init(window,_rollbarConfig),i=n(a,_rollbarConfig);a.loadFull(window,document,!_rollbarConfig.async,_rollbarConfig,i)},function(r,o){"use strict";function t(r){return function(){try{return r.apply(this,arguments)}catch(o){try{console.error("[Rollbar]: Internal error",o)}catch(t){}}}}function e(r,o,t){window._rollbarWrappedError&&(t[4]||(t[4]=window._rollbarWrappedError),t[5]||(t[5]=window._rollbarWrappedError._rollbarContext),window._rollbarWrappedError=null),r.uncaughtError.apply(r,t),o&&o.apply(window,t)}function n(r){var o=function(){var o=Array.prototype.slice.call(arguments,0);e(r,r._rollbarOldOnError,o)};return o.belongsToShim=!0,o}function a(r){this.shimId=++s,this.notifier=null,this.parentShim=r,this._rollbarOldOnError=null}function i(r){var o=a;return t(function(){if(this.notifier)return this.notifier[r].apply(this.notifier,arguments);var t=this,e="scope"===r;e&&(t=new o(this));var n=Array.prototype.slice.call(arguments,0),a={shim:t,method:r,args:n,ts:new Date};return window._rollbarShimQueue.push(a),e?t:void 0})}function l(r,o){if(o.hasOwnProperty&&o.hasOwnProperty("addEventListener")){var t=o.addEventListener;o.addEventListener=function(o,e,n){t.call(this,o,r.wrap(e),n)};var e=o.removeEventListener;o.removeEventListener=function(r,o,t){e.call(this,r,o&&o._wrapped?o._wrapped:o,t)}}}var s=0;a.init=function(r,o){var e=o.globalAlias||"Rollbar";if("object"==typeof r[e])return r[e];r._rollbarShimQueue=[],r._rollbarWrappedError=null,o=o||{};var i=new a;return t(function(){if(i.configure(o),o.captureUncaught){i._rollbarOldOnError=r.onerror,r.onerror=n(i);var t,a,s="EventTarget,Window,Node,ApplicationCache,AudioTrackList,ChannelMergerNode,CryptoOperation,EventSource,FileReader,HTMLUnknownElement,IDBDatabase,IDBRequest,IDBTransaction,KeyOperation,MediaController,MessagePort,ModalWindow,Notification,SVGElementInstance,Screen,TextTrack,TextTrackCue,TextTrackList,WebSocket,WebSocketWorker,Worker,XMLHttpRequest,XMLHttpRequestEventTarget,XMLHttpRequestUpload".split(",");for(t=0;t<s.length;++t)a=s[t],r[a]&&r[a].prototype&&l(i,r[a].prototype)}return r[e]=i,i})()},a.prototype.loadFull=function(r,o,e,n,a){var i=function(){var o;if(void 0===r._rollbarPayloadQueue){var t,e,n,i;for(o=new Error("rollbar.js did not load");t=r._rollbarShimQueue.shift();)for(n=t.args,i=0;i<n.length;++i)if(e=n[i],"function"==typeof e){e(o);break}}"function"==typeof a&&a(o)},l=!1,s=o.createElement("script"),u=o.getElementsByTagName("script")[0],p=u.parentNode;s.crossOrigin="",s.src=n.rollbarJsUrl,s.async=!e,s.onload=s.onreadystatechange=t(function(){if(!(l||this.readyState&&"loaded"!==this.readyState&&"complete"!==this.readyState)){s.onload=s.onreadystatechange=null;try{p.removeChild(s)}catch(r){}l=!0,i()}}),p.insertBefore(s,u)},a.prototype.wrap=function(r,o){try{var t;if(t="function"==typeof o?o:function(){return o||{}},"function"!=typeof r)return r;if(r._isWrap)return r;if(!r._wrapped){r._wrapped=function(){try{return r.apply(this,arguments)}catch(o){throw o._rollbarContext=t()||{},o._rollbarContext._wrappedSource=r.toString(),window._rollbarWrappedError=o,o}},r._wrapped._isWrap=!0;for(var e in r)r.hasOwnProperty(e)&&(r._wrapped[e]=r[e])}return r._wrapped}catch(n){return r}};for(var u="log,debug,info,warn,warning,error,critical,global,configure,scope,uncaughtError".split(","),p=0;p<u.length;++p)a.prototype[u[p]]=i(u[p]);r.exports={Rollbar:a,_rollbarWindowOnError:e}},function(r,o){"use strict";r.exports=function(r,o){return function(t){if(!t&&!window._rollbarInitialized){var e=window.RollbarNotifier,n=o||{},a=n.globalAlias||"Rollbar",i=window.Rollbar.init(n,r);i._processShimQueue(window._rollbarShimQueue||[]),window[a]=i,window._rollbarInitialized=!0,e.processPayloads()}}}}]);
// End Rollbar Snippet
{$checkIgnoreConfig}
</script>
END_HTML;
}
|
php
|
public function getInitRollbarCode(array $context)
{
$accessToken = $this->notifierOptions['access_token'];
$config = array(
'accessToken' => $accessToken,
'captureUncaught' => true,
'payload' => array(
'environment' => $this->environmentOptions['environment'],
),
);
$user = $context['app']->getUser();
if (isset($user)) {
$config['payload']['person'] = $this->userHelper->buildUserData($user);
}
if ($this->notifierOptions['source_map_enabled']) {
$config['payload']['client'] = array(
'javascript' => array(
'source_map_enabled' => $this->notifierOptions['source_map_enabled'],
'code_version' => $this->notifierOptions['code_version'],
'guess_uncaught_frames' => $this->notifierOptions['guess_uncaught_frames'],
),
);
}
$rollbarJsVersion = $this->notifierOptions['rollbarjs_version'];
$config = json_encode($config);
$checkIgnoreConfig = $this->getCheckIgnoreConfig();
$transform = $this->transformPayloadFunctionProvider->getTransformFunctionCode();
return <<<END_HTML
<script>
var _rollbarConfig = {$config};
_rollbarConfig.transform = {$transform};
// Rollbar Snippet
!function(r){function o(e){if(t[e])return t[e].exports;var n=t[e]={exports:{},id:e,loaded:!1};return r[e].call(n.exports,n,n.exports,o),n.loaded=!0,n.exports}var t={};return o.m=r,o.c=t,o.p="",o(0)}([function(r,o,t){"use strict";var e=t(1).Rollbar,n=t(2);_rollbarConfig.rollbarJsUrl=_rollbarConfig.rollbarJsUrl||"https://d37gvrvc0wt4s1.cloudfront.net/js/{$rollbarJsVersion}/rollbar.min.js";var a=e.init(window,_rollbarConfig),i=n(a,_rollbarConfig);a.loadFull(window,document,!_rollbarConfig.async,_rollbarConfig,i)},function(r,o){"use strict";function t(r){return function(){try{return r.apply(this,arguments)}catch(o){try{console.error("[Rollbar]: Internal error",o)}catch(t){}}}}function e(r,o,t){window._rollbarWrappedError&&(t[4]||(t[4]=window._rollbarWrappedError),t[5]||(t[5]=window._rollbarWrappedError._rollbarContext),window._rollbarWrappedError=null),r.uncaughtError.apply(r,t),o&&o.apply(window,t)}function n(r){var o=function(){var o=Array.prototype.slice.call(arguments,0);e(r,r._rollbarOldOnError,o)};return o.belongsToShim=!0,o}function a(r){this.shimId=++s,this.notifier=null,this.parentShim=r,this._rollbarOldOnError=null}function i(r){var o=a;return t(function(){if(this.notifier)return this.notifier[r].apply(this.notifier,arguments);var t=this,e="scope"===r;e&&(t=new o(this));var n=Array.prototype.slice.call(arguments,0),a={shim:t,method:r,args:n,ts:new Date};return window._rollbarShimQueue.push(a),e?t:void 0})}function l(r,o){if(o.hasOwnProperty&&o.hasOwnProperty("addEventListener")){var t=o.addEventListener;o.addEventListener=function(o,e,n){t.call(this,o,r.wrap(e),n)};var e=o.removeEventListener;o.removeEventListener=function(r,o,t){e.call(this,r,o&&o._wrapped?o._wrapped:o,t)}}}var s=0;a.init=function(r,o){var e=o.globalAlias||"Rollbar";if("object"==typeof r[e])return r[e];r._rollbarShimQueue=[],r._rollbarWrappedError=null,o=o||{};var i=new a;return t(function(){if(i.configure(o),o.captureUncaught){i._rollbarOldOnError=r.onerror,r.onerror=n(i);var t,a,s="EventTarget,Window,Node,ApplicationCache,AudioTrackList,ChannelMergerNode,CryptoOperation,EventSource,FileReader,HTMLUnknownElement,IDBDatabase,IDBRequest,IDBTransaction,KeyOperation,MediaController,MessagePort,ModalWindow,Notification,SVGElementInstance,Screen,TextTrack,TextTrackCue,TextTrackList,WebSocket,WebSocketWorker,Worker,XMLHttpRequest,XMLHttpRequestEventTarget,XMLHttpRequestUpload".split(",");for(t=0;t<s.length;++t)a=s[t],r[a]&&r[a].prototype&&l(i,r[a].prototype)}return r[e]=i,i})()},a.prototype.loadFull=function(r,o,e,n,a){var i=function(){var o;if(void 0===r._rollbarPayloadQueue){var t,e,n,i;for(o=new Error("rollbar.js did not load");t=r._rollbarShimQueue.shift();)for(n=t.args,i=0;i<n.length;++i)if(e=n[i],"function"==typeof e){e(o);break}}"function"==typeof a&&a(o)},l=!1,s=o.createElement("script"),u=o.getElementsByTagName("script")[0],p=u.parentNode;s.crossOrigin="",s.src=n.rollbarJsUrl,s.async=!e,s.onload=s.onreadystatechange=t(function(){if(!(l||this.readyState&&"loaded"!==this.readyState&&"complete"!==this.readyState)){s.onload=s.onreadystatechange=null;try{p.removeChild(s)}catch(r){}l=!0,i()}}),p.insertBefore(s,u)},a.prototype.wrap=function(r,o){try{var t;if(t="function"==typeof o?o:function(){return o||{}},"function"!=typeof r)return r;if(r._isWrap)return r;if(!r._wrapped){r._wrapped=function(){try{return r.apply(this,arguments)}catch(o){throw o._rollbarContext=t()||{},o._rollbarContext._wrappedSource=r.toString(),window._rollbarWrappedError=o,o}},r._wrapped._isWrap=!0;for(var e in r)r.hasOwnProperty(e)&&(r._wrapped[e]=r[e])}return r._wrapped}catch(n){return r}};for(var u="log,debug,info,warn,warning,error,critical,global,configure,scope,uncaughtError".split(","),p=0;p<u.length;++p)a.prototype[u[p]]=i(u[p]);r.exports={Rollbar:a,_rollbarWindowOnError:e}},function(r,o){"use strict";r.exports=function(r,o){return function(t){if(!t&&!window._rollbarInitialized){var e=window.RollbarNotifier,n=o||{},a=n.globalAlias||"Rollbar",i=window.Rollbar.init(n,r);i._processShimQueue(window._rollbarShimQueue||[]),window[a]=i,window._rollbarInitialized=!0,e.processPayloads()}}}}]);
// End Rollbar Snippet
{$checkIgnoreConfig}
</script>
END_HTML;
}
|
[
"public",
"function",
"getInitRollbarCode",
"(",
"array",
"$",
"context",
")",
"{",
"$",
"accessToken",
"=",
"$",
"this",
"->",
"notifierOptions",
"[",
"'access_token'",
"]",
";",
"$",
"config",
"=",
"array",
"(",
"'accessToken'",
"=>",
"$",
"accessToken",
",",
"'captureUncaught'",
"=>",
"true",
",",
"'payload'",
"=>",
"array",
"(",
"'environment'",
"=>",
"$",
"this",
"->",
"environmentOptions",
"[",
"'environment'",
"]",
",",
")",
",",
")",
";",
"$",
"user",
"=",
"$",
"context",
"[",
"'app'",
"]",
"->",
"getUser",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"user",
")",
")",
"{",
"$",
"config",
"[",
"'payload'",
"]",
"[",
"'person'",
"]",
"=",
"$",
"this",
"->",
"userHelper",
"->",
"buildUserData",
"(",
"$",
"user",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"notifierOptions",
"[",
"'source_map_enabled'",
"]",
")",
"{",
"$",
"config",
"[",
"'payload'",
"]",
"[",
"'client'",
"]",
"=",
"array",
"(",
"'javascript'",
"=>",
"array",
"(",
"'source_map_enabled'",
"=>",
"$",
"this",
"->",
"notifierOptions",
"[",
"'source_map_enabled'",
"]",
",",
"'code_version'",
"=>",
"$",
"this",
"->",
"notifierOptions",
"[",
"'code_version'",
"]",
",",
"'guess_uncaught_frames'",
"=>",
"$",
"this",
"->",
"notifierOptions",
"[",
"'guess_uncaught_frames'",
"]",
",",
")",
",",
")",
";",
"}",
"$",
"rollbarJsVersion",
"=",
"$",
"this",
"->",
"notifierOptions",
"[",
"'rollbarjs_version'",
"]",
";",
"$",
"config",
"=",
"json_encode",
"(",
"$",
"config",
")",
";",
"$",
"checkIgnoreConfig",
"=",
"$",
"this",
"->",
"getCheckIgnoreConfig",
"(",
")",
";",
"$",
"transform",
"=",
"$",
"this",
"->",
"transformPayloadFunctionProvider",
"->",
"getTransformFunctionCode",
"(",
")",
";",
"return",
" <<<END_HTML\n<script>\nvar _rollbarConfig = {$config};\n_rollbarConfig.transform = {$transform};\n// Rollbar Snippet\n!function(r){function o(e){if(t[e])return t[e].exports;var n=t[e]={exports:{},id:e,loaded:!1};return r[e].call(n.exports,n,n.exports,o),n.loaded=!0,n.exports}var t={};return o.m=r,o.c=t,o.p=\"\",o(0)}([function(r,o,t){\"use strict\";var e=t(1).Rollbar,n=t(2);_rollbarConfig.rollbarJsUrl=_rollbarConfig.rollbarJsUrl||\"https://d37gvrvc0wt4s1.cloudfront.net/js/{$rollbarJsVersion}/rollbar.min.js\";var a=e.init(window,_rollbarConfig),i=n(a,_rollbarConfig);a.loadFull(window,document,!_rollbarConfig.async,_rollbarConfig,i)},function(r,o){\"use strict\";function t(r){return function(){try{return r.apply(this,arguments)}catch(o){try{console.error(\"[Rollbar]: Internal error\",o)}catch(t){}}}}function e(r,o,t){window._rollbarWrappedError&&(t[4]||(t[4]=window._rollbarWrappedError),t[5]||(t[5]=window._rollbarWrappedError._rollbarContext),window._rollbarWrappedError=null),r.uncaughtError.apply(r,t),o&&o.apply(window,t)}function n(r){var o=function(){var o=Array.prototype.slice.call(arguments,0);e(r,r._rollbarOldOnError,o)};return o.belongsToShim=!0,o}function a(r){this.shimId=++s,this.notifier=null,this.parentShim=r,this._rollbarOldOnError=null}function i(r){var o=a;return t(function(){if(this.notifier)return this.notifier[r].apply(this.notifier,arguments);var t=this,e=\"scope\"===r;e&&(t=new o(this));var n=Array.prototype.slice.call(arguments,0),a={shim:t,method:r,args:n,ts:new Date};return window._rollbarShimQueue.push(a),e?t:void 0})}function l(r,o){if(o.hasOwnProperty&&o.hasOwnProperty(\"addEventListener\")){var t=o.addEventListener;o.addEventListener=function(o,e,n){t.call(this,o,r.wrap(e),n)};var e=o.removeEventListener;o.removeEventListener=function(r,o,t){e.call(this,r,o&&o._wrapped?o._wrapped:o,t)}}}var s=0;a.init=function(r,o){var e=o.globalAlias||\"Rollbar\";if(\"object\"==typeof r[e])return r[e];r._rollbarShimQueue=[],r._rollbarWrappedError=null,o=o||{};var i=new a;return t(function(){if(i.configure(o),o.captureUncaught){i._rollbarOldOnError=r.onerror,r.onerror=n(i);var t,a,s=\"EventTarget,Window,Node,ApplicationCache,AudioTrackList,ChannelMergerNode,CryptoOperation,EventSource,FileReader,HTMLUnknownElement,IDBDatabase,IDBRequest,IDBTransaction,KeyOperation,MediaController,MessagePort,ModalWindow,Notification,SVGElementInstance,Screen,TextTrack,TextTrackCue,TextTrackList,WebSocket,WebSocketWorker,Worker,XMLHttpRequest,XMLHttpRequestEventTarget,XMLHttpRequestUpload\".split(\",\");for(t=0;t<s.length;++t)a=s[t],r[a]&&r[a].prototype&&l(i,r[a].prototype)}return r[e]=i,i})()},a.prototype.loadFull=function(r,o,e,n,a){var i=function(){var o;if(void 0===r._rollbarPayloadQueue){var t,e,n,i;for(o=new Error(\"rollbar.js did not load\");t=r._rollbarShimQueue.shift();)for(n=t.args,i=0;i<n.length;++i)if(e=n[i],\"function\"==typeof e){e(o);break}}\"function\"==typeof a&&a(o)},l=!1,s=o.createElement(\"script\"),u=o.getElementsByTagName(\"script\")[0],p=u.parentNode;s.crossOrigin=\"\",s.src=n.rollbarJsUrl,s.async=!e,s.onload=s.onreadystatechange=t(function(){if(!(l||this.readyState&&\"loaded\"!==this.readyState&&\"complete\"!==this.readyState)){s.onload=s.onreadystatechange=null;try{p.removeChild(s)}catch(r){}l=!0,i()}}),p.insertBefore(s,u)},a.prototype.wrap=function(r,o){try{var t;if(t=\"function\"==typeof o?o:function(){return o||{}},\"function\"!=typeof r)return r;if(r._isWrap)return r;if(!r._wrapped){r._wrapped=function(){try{return r.apply(this,arguments)}catch(o){throw o._rollbarContext=t()||{},o._rollbarContext._wrappedSource=r.toString(),window._rollbarWrappedError=o,o}},r._wrapped._isWrap=!0;for(var e in r)r.hasOwnProperty(e)&&(r._wrapped[e]=r[e])}return r._wrapped}catch(n){return r}};for(var u=\"log,debug,info,warn,warning,error,critical,global,configure,scope,uncaughtError\".split(\",\"),p=0;p<u.length;++p)a.prototype[u[p]]=i(u[p]);r.exports={Rollbar:a,_rollbarWindowOnError:e}},function(r,o){\"use strict\";r.exports=function(r,o){return function(t){if(!t&&!window._rollbarInitialized){var e=window.RollbarNotifier,n=o||{},a=n.globalAlias||\"Rollbar\",i=window.Rollbar.init(n,r);i._processShimQueue(window._rollbarShimQueue||[]),window[a]=i,window._rollbarInitialized=!0,e.processPayloads()}}}}]);\n// End Rollbar Snippet\n{$checkIgnoreConfig}\n</script>\nEND_HTML",
";",
"}"
] |
@param array $context
@return string
|
[
"@param",
"array",
"$context"
] |
train
|
https://github.com/ftrrtf/FtrrtfRollbarBundle/blob/64c75862b80a4a1ed9e98c0d217003e84df40dd7/Twig/RollbarExtension.php#L84-L129
|
comodojo/dispatcher.framework
|
src/Comodojo/Dispatcher/Router/Table.php
|
Table.registerRoute
|
private function registerRoute($folders, $type, $class = null, array $parameters = []) {
// The values associated with a route are as follows:
// $route = new Route($this->router);
$route = new Route();
$this->updateRoute($route, $type, $class, $parameters);
// $route->setType($type) // Type of route
// ->setClassName($class) // Class to be invoked
// ->setParameters($parameters); // Parameters passed via the composer.json configuration (cache, ttl, etc...)
$this->logger->debug("Route table - route: ".implode("/", $folders));
// This method generate a global regular expression which will be able to match all the URI supported by the route
$regex = $this->parser->read($folders, $route);
$this->logger->debug("Route table - route regex: $regex");
$this->routes = array_merge($this->routes, [$regex => $route]);
}
|
php
|
private function registerRoute($folders, $type, $class = null, array $parameters = []) {
// The values associated with a route are as follows:
// $route = new Route($this->router);
$route = new Route();
$this->updateRoute($route, $type, $class, $parameters);
// $route->setType($type) // Type of route
// ->setClassName($class) // Class to be invoked
// ->setParameters($parameters); // Parameters passed via the composer.json configuration (cache, ttl, etc...)
$this->logger->debug("Route table - route: ".implode("/", $folders));
// This method generate a global regular expression which will be able to match all the URI supported by the route
$regex = $this->parser->read($folders, $route);
$this->logger->debug("Route table - route regex: $regex");
$this->routes = array_merge($this->routes, [$regex => $route]);
}
|
[
"private",
"function",
"registerRoute",
"(",
"$",
"folders",
",",
"$",
"type",
",",
"$",
"class",
"=",
"null",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"// The values associated with a route are as follows:",
"// $route = new Route($this->router);",
"$",
"route",
"=",
"new",
"Route",
"(",
")",
";",
"$",
"this",
"->",
"updateRoute",
"(",
"$",
"route",
",",
"$",
"type",
",",
"$",
"class",
",",
"$",
"parameters",
")",
";",
"// $route->setType($type) // Type of route",
"// ->setClassName($class) // Class to be invoked",
"// ->setParameters($parameters); // Parameters passed via the composer.json configuration (cache, ttl, etc...)",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\"Route table - route: \"",
".",
"implode",
"(",
"\"/\"",
",",
"$",
"folders",
")",
")",
";",
"// This method generate a global regular expression which will be able to match all the URI supported by the route",
"$",
"regex",
"=",
"$",
"this",
"->",
"parser",
"->",
"read",
"(",
"$",
"folders",
",",
"$",
"route",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\"Route table - route regex: $regex\"",
")",
";",
"$",
"this",
"->",
"routes",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"routes",
",",
"[",
"$",
"regex",
"=>",
"$",
"route",
"]",
")",
";",
"}"
] |
This method add a route to the supported list
|
[
"This",
"method",
"add",
"a",
"route",
"to",
"the",
"supported",
"list"
] |
train
|
https://github.com/comodojo/dispatcher.framework/blob/5093297dcb7441a8d8f79cbb2429c93232e16d1c/src/Comodojo/Dispatcher/Router/Table.php#L206-L227
|
bolt/configuration-notices
|
src/EventListener/ConfigurationNoticesListener.php
|
ConfigurationNoticesListener.onKernelRequest
|
public function onKernelRequest(GetResponseEvent $event)
{
// Nothing to do here, if it's not the Master request.
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
$route = $request->get('_route');
// Only do these 'expensive' checks on a select few backend pages.
if (!in_array($route, ['dashboard', 'login', 'userfirst'])) {
return;
}
$this->logThreshold = $this->app['config']->get('general/configuration_notices/log_threshold', 10000);
$this->app['stopwatch']->start('bolt.configuration_notices');
$this->singleHostnameCheck($request);
$this->ipAddressCheck($request);
$this->topLevelCheck($request);
$this->writableFolderCheck();
// Do these only when logged in, on the dashboard
if ($route === 'dashboard') {
$this->mailConfigCheck();
$this->developmentCheck();
$this->liveCheck($request);
$this->gdCheck();
$this->thumbsFolderCheck();
$this->canonicalCheck($request);
$this->imageFunctionsCheck();
$this->maintenanceCheck();
$this->thumbnailConfigCheck();
$this->changelogCheck();
$this->systemlogCheck();
}
$this->app['stopwatch']->stop('bolt.configuration_notices');
}
|
php
|
public function onKernelRequest(GetResponseEvent $event)
{
// Nothing to do here, if it's not the Master request.
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
$route = $request->get('_route');
// Only do these 'expensive' checks on a select few backend pages.
if (!in_array($route, ['dashboard', 'login', 'userfirst'])) {
return;
}
$this->logThreshold = $this->app['config']->get('general/configuration_notices/log_threshold', 10000);
$this->app['stopwatch']->start('bolt.configuration_notices');
$this->singleHostnameCheck($request);
$this->ipAddressCheck($request);
$this->topLevelCheck($request);
$this->writableFolderCheck();
// Do these only when logged in, on the dashboard
if ($route === 'dashboard') {
$this->mailConfigCheck();
$this->developmentCheck();
$this->liveCheck($request);
$this->gdCheck();
$this->thumbsFolderCheck();
$this->canonicalCheck($request);
$this->imageFunctionsCheck();
$this->maintenanceCheck();
$this->thumbnailConfigCheck();
$this->changelogCheck();
$this->systemlogCheck();
}
$this->app['stopwatch']->stop('bolt.configuration_notices');
}
|
[
"public",
"function",
"onKernelRequest",
"(",
"GetResponseEvent",
"$",
"event",
")",
"{",
"// Nothing to do here, if it's not the Master request.",
"if",
"(",
"!",
"$",
"event",
"->",
"isMasterRequest",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"request",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
";",
"$",
"route",
"=",
"$",
"request",
"->",
"get",
"(",
"'_route'",
")",
";",
"// Only do these 'expensive' checks on a select few backend pages.",
"if",
"(",
"!",
"in_array",
"(",
"$",
"route",
",",
"[",
"'dashboard'",
",",
"'login'",
",",
"'userfirst'",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"logThreshold",
"=",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'general/configuration_notices/log_threshold'",
",",
"10000",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'stopwatch'",
"]",
"->",
"start",
"(",
"'bolt.configuration_notices'",
")",
";",
"$",
"this",
"->",
"singleHostnameCheck",
"(",
"$",
"request",
")",
";",
"$",
"this",
"->",
"ipAddressCheck",
"(",
"$",
"request",
")",
";",
"$",
"this",
"->",
"topLevelCheck",
"(",
"$",
"request",
")",
";",
"$",
"this",
"->",
"writableFolderCheck",
"(",
")",
";",
"// Do these only when logged in, on the dashboard",
"if",
"(",
"$",
"route",
"===",
"'dashboard'",
")",
"{",
"$",
"this",
"->",
"mailConfigCheck",
"(",
")",
";",
"$",
"this",
"->",
"developmentCheck",
"(",
")",
";",
"$",
"this",
"->",
"liveCheck",
"(",
"$",
"request",
")",
";",
"$",
"this",
"->",
"gdCheck",
"(",
")",
";",
"$",
"this",
"->",
"thumbsFolderCheck",
"(",
")",
";",
"$",
"this",
"->",
"canonicalCheck",
"(",
"$",
"request",
")",
";",
"$",
"this",
"->",
"imageFunctionsCheck",
"(",
")",
";",
"$",
"this",
"->",
"maintenanceCheck",
"(",
")",
";",
"$",
"this",
"->",
"thumbnailConfigCheck",
"(",
")",
";",
"$",
"this",
"->",
"changelogCheck",
"(",
")",
";",
"$",
"this",
"->",
"systemlogCheck",
"(",
")",
";",
"}",
"$",
"this",
"->",
"app",
"[",
"'stopwatch'",
"]",
"->",
"stop",
"(",
"'bolt.configuration_notices'",
")",
";",
"}"
] |
Kernel request listener callback.
@param GetResponseEvent $event
|
[
"Kernel",
"request",
"listener",
"callback",
"."
] |
train
|
https://github.com/bolt/configuration-notices/blob/0e6439f69bf3099bd6ea30288207a3fd2351e404/src/EventListener/ConfigurationNoticesListener.php#L45-L85
|
bolt/configuration-notices
|
src/EventListener/ConfigurationNoticesListener.php
|
ConfigurationNoticesListener.mailConfigCheck
|
protected function mailConfigCheck()
{
if (!$this->app['config']->get('general/mailoptions') && $this->app['users']->getCurrentuser() && $this->app['users']->isAllowed('files:config')) {
$notice = json_encode([
'severity' => 1,
'notice' => 'The <strong>mail configuration parameters</strong> have not been set up. This may interfere with password resets, and extension functionality. Please set up the <code>mailoptions</code> in <code>config.yml</code>.',
]);
$this->app['logger.flash']->configuration($notice);
}
}
|
php
|
protected function mailConfigCheck()
{
if (!$this->app['config']->get('general/mailoptions') && $this->app['users']->getCurrentuser() && $this->app['users']->isAllowed('files:config')) {
$notice = json_encode([
'severity' => 1,
'notice' => 'The <strong>mail configuration parameters</strong> have not been set up. This may interfere with password resets, and extension functionality. Please set up the <code>mailoptions</code> in <code>config.yml</code>.',
]);
$this->app['logger.flash']->configuration($notice);
}
}
|
[
"protected",
"function",
"mailConfigCheck",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'general/mailoptions'",
")",
"&&",
"$",
"this",
"->",
"app",
"[",
"'users'",
"]",
"->",
"getCurrentuser",
"(",
")",
"&&",
"$",
"this",
"->",
"app",
"[",
"'users'",
"]",
"->",
"isAllowed",
"(",
"'files:config'",
")",
")",
"{",
"$",
"notice",
"=",
"json_encode",
"(",
"[",
"'severity'",
"=>",
"1",
",",
"'notice'",
"=>",
"'The <strong>mail configuration parameters</strong> have not been set up. This may interfere with password resets, and extension functionality. Please set up the <code>mailoptions</code> in <code>config.yml</code>.'",
",",
"]",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'logger.flash'",
"]",
"->",
"configuration",
"(",
"$",
"notice",
")",
";",
"}",
"}"
] |
No mail transport has been set. We should gently nudge the user to set
the mail configuration.
@see https://github.com/bolt/bolt/issues/2908
|
[
"No",
"mail",
"transport",
"has",
"been",
"set",
".",
"We",
"should",
"gently",
"nudge",
"the",
"user",
"to",
"set",
"the",
"mail",
"configuration",
"."
] |
train
|
https://github.com/bolt/configuration-notices/blob/0e6439f69bf3099bd6ea30288207a3fd2351e404/src/EventListener/ConfigurationNoticesListener.php#L93-L102
|
bolt/configuration-notices
|
src/EventListener/ConfigurationNoticesListener.php
|
ConfigurationNoticesListener.liveCheck
|
protected function liveCheck(Request $request)
{
if (!$this->app['debug']) {
return;
}
$host = parse_url($request->getSchemeAndHttpHost());
// If we have an IP-address, we assume it's "dev"
if (filter_var($host['host'], FILTER_VALIDATE_IP) !== false) {
return;
}
$domainPartials = (array) $this->app['config']->get('general/debug_local_domains', []);
$domainPartials = array_unique(array_merge(
(array) $domainPartials,
$this->defaultDomainPartials
));
foreach ($domainPartials as $partial) {
if (strpos($host['host'], $partial) !== false) {
return;
}
}
$notice = json_encode([
'severity' => 2,
'notice' => "It seems like this website is running on a <strong>non-development environment</strong>, while 'debug' is enabled. Make sure debug is disabled in production environments. If you don't do this, it will result in an extremely large <code>app/cache</code> folder and a measurable reduced performance across all pages.",
'info' => "If you wish to hide this message, add a key to your <code>config.yml</code> with a (partial) domain name in it, that should be seen as a development environment: <code>debug_local_domains: [ '.foo' ]</code>.",
]);
$this->app['logger.flash']->configuration($notice);
}
|
php
|
protected function liveCheck(Request $request)
{
if (!$this->app['debug']) {
return;
}
$host = parse_url($request->getSchemeAndHttpHost());
// If we have an IP-address, we assume it's "dev"
if (filter_var($host['host'], FILTER_VALIDATE_IP) !== false) {
return;
}
$domainPartials = (array) $this->app['config']->get('general/debug_local_domains', []);
$domainPartials = array_unique(array_merge(
(array) $domainPartials,
$this->defaultDomainPartials
));
foreach ($domainPartials as $partial) {
if (strpos($host['host'], $partial) !== false) {
return;
}
}
$notice = json_encode([
'severity' => 2,
'notice' => "It seems like this website is running on a <strong>non-development environment</strong>, while 'debug' is enabled. Make sure debug is disabled in production environments. If you don't do this, it will result in an extremely large <code>app/cache</code> folder and a measurable reduced performance across all pages.",
'info' => "If you wish to hide this message, add a key to your <code>config.yml</code> with a (partial) domain name in it, that should be seen as a development environment: <code>debug_local_domains: [ '.foo' ]</code>.",
]);
$this->app['logger.flash']->configuration($notice);
}
|
[
"protected",
"function",
"liveCheck",
"(",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"app",
"[",
"'debug'",
"]",
")",
"{",
"return",
";",
"}",
"$",
"host",
"=",
"parse_url",
"(",
"$",
"request",
"->",
"getSchemeAndHttpHost",
"(",
")",
")",
";",
"// If we have an IP-address, we assume it's \"dev\"",
"if",
"(",
"filter_var",
"(",
"$",
"host",
"[",
"'host'",
"]",
",",
"FILTER_VALIDATE_IP",
")",
"!==",
"false",
")",
"{",
"return",
";",
"}",
"$",
"domainPartials",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'general/debug_local_domains'",
",",
"[",
"]",
")",
";",
"$",
"domainPartials",
"=",
"array_unique",
"(",
"array_merge",
"(",
"(",
"array",
")",
"$",
"domainPartials",
",",
"$",
"this",
"->",
"defaultDomainPartials",
")",
")",
";",
"foreach",
"(",
"$",
"domainPartials",
"as",
"$",
"partial",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"host",
"[",
"'host'",
"]",
",",
"$",
"partial",
")",
"!==",
"false",
")",
"{",
"return",
";",
"}",
"}",
"$",
"notice",
"=",
"json_encode",
"(",
"[",
"'severity'",
"=>",
"2",
",",
"'notice'",
"=>",
"\"It seems like this website is running on a <strong>non-development environment</strong>, while 'debug' is enabled. Make sure debug is disabled in production environments. If you don't do this, it will result in an extremely large <code>app/cache</code> folder and a measurable reduced performance across all pages.\"",
",",
"'info'",
"=>",
"\"If you wish to hide this message, add a key to your <code>config.yml</code> with a (partial) domain name in it, that should be seen as a development environment: <code>debug_local_domains: [ '.foo' ]</code>.\"",
",",
"]",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'logger.flash'",
"]",
"->",
"configuration",
"(",
"$",
"notice",
")",
";",
"}"
] |
Check whether the site is live or not.
|
[
"Check",
"whether",
"the",
"site",
"is",
"live",
"or",
"not",
"."
] |
train
|
https://github.com/bolt/configuration-notices/blob/0e6439f69bf3099bd6ea30288207a3fd2351e404/src/EventListener/ConfigurationNoticesListener.php#L121-L154
|
bolt/configuration-notices
|
src/EventListener/ConfigurationNoticesListener.php
|
ConfigurationNoticesListener.singleHostnameCheck
|
protected function singleHostnameCheck(Request $request)
{
$hostname = $request->getHttpHost();
if (strpos($hostname, '.') === false) {
$message = "You are using <code>$hostname</code> as host name. Some browsers have problems with sessions on hostnames that do not have a <code>.tld</code> in them.";
$info = 'If you experience difficulties logging on, either configure your webserver to use a hostname with a dot in it, or use another browser.';
$notice = json_encode([
'severity' => 1,
'notice' => $message,
'info' => $info,
]);
$this->app['logger.flash']->configuration($notice);
if (in_array($this->app['request']->get('_route'), ['login', 'userfirst'])) {
$this->app['logger.flash']->error($message . ' ' . $info);
}
}
}
|
php
|
protected function singleHostnameCheck(Request $request)
{
$hostname = $request->getHttpHost();
if (strpos($hostname, '.') === false) {
$message = "You are using <code>$hostname</code> as host name. Some browsers have problems with sessions on hostnames that do not have a <code>.tld</code> in them.";
$info = 'If you experience difficulties logging on, either configure your webserver to use a hostname with a dot in it, or use another browser.';
$notice = json_encode([
'severity' => 1,
'notice' => $message,
'info' => $info,
]);
$this->app['logger.flash']->configuration($notice);
if (in_array($this->app['request']->get('_route'), ['login', 'userfirst'])) {
$this->app['logger.flash']->error($message . ' ' . $info);
}
}
}
|
[
"protected",
"function",
"singleHostnameCheck",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"hostname",
"=",
"$",
"request",
"->",
"getHttpHost",
"(",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"hostname",
",",
"'.'",
")",
"===",
"false",
")",
"{",
"$",
"message",
"=",
"\"You are using <code>$hostname</code> as host name. Some browsers have problems with sessions on hostnames that do not have a <code>.tld</code> in them.\"",
";",
"$",
"info",
"=",
"'If you experience difficulties logging on, either configure your webserver to use a hostname with a dot in it, or use another browser.'",
";",
"$",
"notice",
"=",
"json_encode",
"(",
"[",
"'severity'",
"=>",
"1",
",",
"'notice'",
"=>",
"$",
"message",
",",
"'info'",
"=>",
"$",
"info",
",",
"]",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'logger.flash'",
"]",
"->",
"configuration",
"(",
"$",
"notice",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"app",
"[",
"'request'",
"]",
"->",
"get",
"(",
"'_route'",
")",
",",
"[",
"'login'",
",",
"'userfirst'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"app",
"[",
"'logger.flash'",
"]",
"->",
"error",
"(",
"$",
"message",
".",
"' '",
".",
"$",
"info",
")",
";",
"}",
"}",
"}"
] |
Check whether or not we're running on a hostname without TLD, like 'http://localhost'.
|
[
"Check",
"whether",
"or",
"not",
"we",
"re",
"running",
"on",
"a",
"hostname",
"without",
"TLD",
"like",
"http",
":",
"//",
"localhost",
"."
] |
train
|
https://github.com/bolt/configuration-notices/blob/0e6439f69bf3099bd6ea30288207a3fd2351e404/src/EventListener/ConfigurationNoticesListener.php#L174-L193
|
bolt/configuration-notices
|
src/EventListener/ConfigurationNoticesListener.php
|
ConfigurationNoticesListener.ipAddressCheck
|
protected function ipAddressCheck(Request $request)
{
$hostname = $request->getHttpHost();
if (filter_var($hostname, FILTER_VALIDATE_IP)) {
$message = "You are using the <strong>IP address</strong> <code>$hostname</code> as host name. This is known to cause problems with sessions.";
$info = 'If you experience difficulties logging on, either configure your webserver to use a proper hostname, or use another browser.';
$notice = json_encode([
'severity' => 1,
'notice' => $message,
'info' => $info,
]);
$this->app['logger.flash']->configuration($notice);
if (in_array($this->app['request']->get('_route'), ['login', 'userfirst'])) {
$this->app['logger.flash']->error($message . ' ' . $info);
}
}
}
|
php
|
protected function ipAddressCheck(Request $request)
{
$hostname = $request->getHttpHost();
if (filter_var($hostname, FILTER_VALIDATE_IP)) {
$message = "You are using the <strong>IP address</strong> <code>$hostname</code> as host name. This is known to cause problems with sessions.";
$info = 'If you experience difficulties logging on, either configure your webserver to use a proper hostname, or use another browser.';
$notice = json_encode([
'severity' => 1,
'notice' => $message,
'info' => $info,
]);
$this->app['logger.flash']->configuration($notice);
if (in_array($this->app['request']->get('_route'), ['login', 'userfirst'])) {
$this->app['logger.flash']->error($message . ' ' . $info);
}
}
}
|
[
"protected",
"function",
"ipAddressCheck",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"hostname",
"=",
"$",
"request",
"->",
"getHttpHost",
"(",
")",
";",
"if",
"(",
"filter_var",
"(",
"$",
"hostname",
",",
"FILTER_VALIDATE_IP",
")",
")",
"{",
"$",
"message",
"=",
"\"You are using the <strong>IP address</strong> <code>$hostname</code> as host name. This is known to cause problems with sessions.\"",
";",
"$",
"info",
"=",
"'If you experience difficulties logging on, either configure your webserver to use a proper hostname, or use another browser.'",
";",
"$",
"notice",
"=",
"json_encode",
"(",
"[",
"'severity'",
"=>",
"1",
",",
"'notice'",
"=>",
"$",
"message",
",",
"'info'",
"=>",
"$",
"info",
",",
"]",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'logger.flash'",
"]",
"->",
"configuration",
"(",
"$",
"notice",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"app",
"[",
"'request'",
"]",
"->",
"get",
"(",
"'_route'",
")",
",",
"[",
"'login'",
",",
"'userfirst'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"app",
"[",
"'logger.flash'",
"]",
"->",
"error",
"(",
"$",
"message",
".",
"' '",
".",
"$",
"info",
")",
";",
"}",
"}",
"}"
] |
Check whether or not we're running on a hostname without TLD, like 'http://localhost'.
|
[
"Check",
"whether",
"or",
"not",
"we",
"re",
"running",
"on",
"a",
"hostname",
"without",
"TLD",
"like",
"http",
":",
"//",
"localhost",
"."
] |
train
|
https://github.com/bolt/configuration-notices/blob/0e6439f69bf3099bd6ea30288207a3fd2351e404/src/EventListener/ConfigurationNoticesListener.php#L198-L217
|
bolt/configuration-notices
|
src/EventListener/ConfigurationNoticesListener.php
|
ConfigurationNoticesListener.topLevelCheck
|
protected function topLevelCheck(Request $request)
{
$base = $request->getBaseUrl();
if (!empty($base)) {
$notice = json_encode([
'severity' => 1,
'notice' => 'You are using Bolt in a subfolder, <strong>instead of the webroot</strong>.',
'info' => "It is recommended to use Bolt from the 'web root', so that it is in the top level. If you wish to use Bolt for only part of a website, we recommend setting up a subdomain like <code>news.example.org</code>. If you are having trouble setting up Bolt in the top level, look into the <a href='https://docs.bolt.cm/howto/troubleshooting-outside-webroot#option-2-use-the-flat-structure-distribution'>Flat Structure</a> distribution, or one of the other options listed on that page.",
]);
$this->app['logger.flash']->configuration($notice);
}
}
|
php
|
protected function topLevelCheck(Request $request)
{
$base = $request->getBaseUrl();
if (!empty($base)) {
$notice = json_encode([
'severity' => 1,
'notice' => 'You are using Bolt in a subfolder, <strong>instead of the webroot</strong>.',
'info' => "It is recommended to use Bolt from the 'web root', so that it is in the top level. If you wish to use Bolt for only part of a website, we recommend setting up a subdomain like <code>news.example.org</code>. If you are having trouble setting up Bolt in the top level, look into the <a href='https://docs.bolt.cm/howto/troubleshooting-outside-webroot#option-2-use-the-flat-structure-distribution'>Flat Structure</a> distribution, or one of the other options listed on that page.",
]);
$this->app['logger.flash']->configuration($notice);
}
}
|
[
"protected",
"function",
"topLevelCheck",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"base",
"=",
"$",
"request",
"->",
"getBaseUrl",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"base",
")",
")",
"{",
"$",
"notice",
"=",
"json_encode",
"(",
"[",
"'severity'",
"=>",
"1",
",",
"'notice'",
"=>",
"'You are using Bolt in a subfolder, <strong>instead of the webroot</strong>.'",
",",
"'info'",
"=>",
"\"It is recommended to use Bolt from the 'web root', so that it is in the top level. If you wish to use Bolt for only part of a website, we recommend setting up a subdomain like <code>news.example.org</code>. If you are having trouble setting up Bolt in the top level, look into the <a href='https://docs.bolt.cm/howto/troubleshooting-outside-webroot#option-2-use-the-flat-structure-distribution'>Flat Structure</a> distribution, or one of the other options listed on that page.\"",
",",
"]",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'logger.flash'",
"]",
"->",
"configuration",
"(",
"$",
"notice",
")",
";",
"}",
"}"
] |
Check whether or not we're running on a hostname without TLD, like 'http://localhost'.
@param Request $request
|
[
"Check",
"whether",
"or",
"not",
"we",
"re",
"running",
"on",
"a",
"hostname",
"without",
"TLD",
"like",
"http",
":",
"//",
"localhost",
"."
] |
train
|
https://github.com/bolt/configuration-notices/blob/0e6439f69bf3099bd6ea30288207a3fd2351e404/src/EventListener/ConfigurationNoticesListener.php#L224-L237
|
bolt/configuration-notices
|
src/EventListener/ConfigurationNoticesListener.php
|
ConfigurationNoticesListener.writableFolderCheck
|
protected function writableFolderCheck()
{
$fileName = '/configtester_' . date('Y-m-d-h-i-s') . '.txt';
$fileSystems = [
['name' => 'files', 'folder' => '', 'label' => '<code>files/</code> in the webroot'],
['name' => 'extensions', 'folder' => '', 'label' => '<code>extensions/</code> in the webroot'],
['name' => 'config', 'folder' => ''],
['name' => 'cache', 'folder' => ''],
];
if ($this->app['config']->get('general/database/driver') === 'pdo_sqlite') {
$fileSystems[] = ['name' => 'app', 'folder' => 'database'];
}
$fileSystems = Bag::fromRecursive($fileSystems);
foreach ($fileSystems as $fileSystem) {
$contents = $this->isWritable($fileSystem, $fileName);
if ($contents != 'ok') {
$folderName = $this->getFoldername($fileSystem);
$notice = json_encode([
'severity' => 1,
'notice' => 'Bolt needs to be able to <strong>write files to</strong> the folder <code>' . $folderName . "</code>, but it doesn't seem to be writable.",
'info' => 'Make sure the folder exists, and is writable to the webserver.',
]);
$this->app['logger.flash']->configuration($notice);
}
}
}
|
php
|
protected function writableFolderCheck()
{
$fileName = '/configtester_' . date('Y-m-d-h-i-s') . '.txt';
$fileSystems = [
['name' => 'files', 'folder' => '', 'label' => '<code>files/</code> in the webroot'],
['name' => 'extensions', 'folder' => '', 'label' => '<code>extensions/</code> in the webroot'],
['name' => 'config', 'folder' => ''],
['name' => 'cache', 'folder' => ''],
];
if ($this->app['config']->get('general/database/driver') === 'pdo_sqlite') {
$fileSystems[] = ['name' => 'app', 'folder' => 'database'];
}
$fileSystems = Bag::fromRecursive($fileSystems);
foreach ($fileSystems as $fileSystem) {
$contents = $this->isWritable($fileSystem, $fileName);
if ($contents != 'ok') {
$folderName = $this->getFoldername($fileSystem);
$notice = json_encode([
'severity' => 1,
'notice' => 'Bolt needs to be able to <strong>write files to</strong> the folder <code>' . $folderName . "</code>, but it doesn't seem to be writable.",
'info' => 'Make sure the folder exists, and is writable to the webserver.',
]);
$this->app['logger.flash']->configuration($notice);
}
}
}
|
[
"protected",
"function",
"writableFolderCheck",
"(",
")",
"{",
"$",
"fileName",
"=",
"'/configtester_'",
".",
"date",
"(",
"'Y-m-d-h-i-s'",
")",
".",
"'.txt'",
";",
"$",
"fileSystems",
"=",
"[",
"[",
"'name'",
"=>",
"'files'",
",",
"'folder'",
"=>",
"''",
",",
"'label'",
"=>",
"'<code>files/</code> in the webroot'",
"]",
",",
"[",
"'name'",
"=>",
"'extensions'",
",",
"'folder'",
"=>",
"''",
",",
"'label'",
"=>",
"'<code>extensions/</code> in the webroot'",
"]",
",",
"[",
"'name'",
"=>",
"'config'",
",",
"'folder'",
"=>",
"''",
"]",
",",
"[",
"'name'",
"=>",
"'cache'",
",",
"'folder'",
"=>",
"''",
"]",
",",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'general/database/driver'",
")",
"===",
"'pdo_sqlite'",
")",
"{",
"$",
"fileSystems",
"[",
"]",
"=",
"[",
"'name'",
"=>",
"'app'",
",",
"'folder'",
"=>",
"'database'",
"]",
";",
"}",
"$",
"fileSystems",
"=",
"Bag",
"::",
"fromRecursive",
"(",
"$",
"fileSystems",
")",
";",
"foreach",
"(",
"$",
"fileSystems",
"as",
"$",
"fileSystem",
")",
"{",
"$",
"contents",
"=",
"$",
"this",
"->",
"isWritable",
"(",
"$",
"fileSystem",
",",
"$",
"fileName",
")",
";",
"if",
"(",
"$",
"contents",
"!=",
"'ok'",
")",
"{",
"$",
"folderName",
"=",
"$",
"this",
"->",
"getFoldername",
"(",
"$",
"fileSystem",
")",
";",
"$",
"notice",
"=",
"json_encode",
"(",
"[",
"'severity'",
"=>",
"1",
",",
"'notice'",
"=>",
"'Bolt needs to be able to <strong>write files to</strong> the folder <code>'",
".",
"$",
"folderName",
".",
"\"</code>, but it doesn't seem to be writable.\"",
",",
"'info'",
"=>",
"'Make sure the folder exists, and is writable to the webserver.'",
",",
"]",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'logger.flash'",
"]",
"->",
"configuration",
"(",
"$",
"notice",
")",
";",
"}",
"}",
"}"
] |
Check if some common file locations are writable.
|
[
"Check",
"if",
"some",
"common",
"file",
"locations",
"are",
"writable",
"."
] |
train
|
https://github.com/bolt/configuration-notices/blob/0e6439f69bf3099bd6ea30288207a3fd2351e404/src/EventListener/ConfigurationNoticesListener.php#L242-L269
|
bolt/configuration-notices
|
src/EventListener/ConfigurationNoticesListener.php
|
ConfigurationNoticesListener.thumbsFolderCheck
|
protected function thumbsFolderCheck()
{
if (!$this->app['config']->get('general/thumbnails/save_files')) {
return;
}
$filePath = 'configtester_' . date('Y-m-d-h-i-s') . '.txt';
$contents = $this->isWritable(Bag::from(['name' => 'web', 'folder' => 'thumbs']), $filePath);
if ($contents != 'ok') {
$notice = json_encode([
'severity' => 1,
'notice' => "Bolt is configured to save thumbnails to disk for performance, but the <code>thumbs/</code> folder doesn't seem to be writable.",
'info' => 'Make sure the folder exists, and is writable to the webserver.',
]);
$this->app['logger.flash']->configuration($notice);
}
}
|
php
|
protected function thumbsFolderCheck()
{
if (!$this->app['config']->get('general/thumbnails/save_files')) {
return;
}
$filePath = 'configtester_' . date('Y-m-d-h-i-s') . '.txt';
$contents = $this->isWritable(Bag::from(['name' => 'web', 'folder' => 'thumbs']), $filePath);
if ($contents != 'ok') {
$notice = json_encode([
'severity' => 1,
'notice' => "Bolt is configured to save thumbnails to disk for performance, but the <code>thumbs/</code> folder doesn't seem to be writable.",
'info' => 'Make sure the folder exists, and is writable to the webserver.',
]);
$this->app['logger.flash']->configuration($notice);
}
}
|
[
"protected",
"function",
"thumbsFolderCheck",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'general/thumbnails/save_files'",
")",
")",
"{",
"return",
";",
"}",
"$",
"filePath",
"=",
"'configtester_'",
".",
"date",
"(",
"'Y-m-d-h-i-s'",
")",
".",
"'.txt'",
";",
"$",
"contents",
"=",
"$",
"this",
"->",
"isWritable",
"(",
"Bag",
"::",
"from",
"(",
"[",
"'name'",
"=>",
"'web'",
",",
"'folder'",
"=>",
"'thumbs'",
"]",
")",
",",
"$",
"filePath",
")",
";",
"if",
"(",
"$",
"contents",
"!=",
"'ok'",
")",
"{",
"$",
"notice",
"=",
"json_encode",
"(",
"[",
"'severity'",
"=>",
"1",
",",
"'notice'",
"=>",
"\"Bolt is configured to save thumbnails to disk for performance, but the <code>thumbs/</code> folder doesn't seem to be writable.\"",
",",
"'info'",
"=>",
"'Make sure the folder exists, and is writable to the webserver.'",
",",
"]",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'logger.flash'",
"]",
"->",
"configuration",
"(",
"$",
"notice",
")",
";",
"}",
"}"
] |
Check if the thumbs/ folder is writable, if `save_files: true`
|
[
"Check",
"if",
"the",
"thumbs",
"/",
"folder",
"is",
"writable",
"if",
"save_files",
":",
"true"
] |
train
|
https://github.com/bolt/configuration-notices/blob/0e6439f69bf3099bd6ea30288207a3fd2351e404/src/EventListener/ConfigurationNoticesListener.php#L274-L290
|
bolt/configuration-notices
|
src/EventListener/ConfigurationNoticesListener.php
|
ConfigurationNoticesListener.canonicalCheck
|
protected function canonicalCheck(Request $request)
{
$hostname = strtok($request->getUri(), '?');
$canonical = strtok($this->app['canonical']->getUrl());
if (!empty($canonical) && ($hostname != $canonical)) {
$notice = json_encode([
'severity' => 1,
'notice' => "The <code>canonical hostname</code> is set to <code>$canonical</code> in <code>config.yml</code>, but you are currently logged in using another hostname. This might cause issues with uploaded files, or links inserted in the content.",
'info' => sprintf(
"Log in on Bolt using the proper URL: <code><a href='%s'>%s</a></code>.",
$this->app['canonical']->getUrl(),
$this->app['canonical']->getUrl()
),
]);
$this->app['logger.flash']->configuration($notice);
}
}
|
php
|
protected function canonicalCheck(Request $request)
{
$hostname = strtok($request->getUri(), '?');
$canonical = strtok($this->app['canonical']->getUrl());
if (!empty($canonical) && ($hostname != $canonical)) {
$notice = json_encode([
'severity' => 1,
'notice' => "The <code>canonical hostname</code> is set to <code>$canonical</code> in <code>config.yml</code>, but you are currently logged in using another hostname. This might cause issues with uploaded files, or links inserted in the content.",
'info' => sprintf(
"Log in on Bolt using the proper URL: <code><a href='%s'>%s</a></code>.",
$this->app['canonical']->getUrl(),
$this->app['canonical']->getUrl()
),
]);
$this->app['logger.flash']->configuration($notice);
}
}
|
[
"protected",
"function",
"canonicalCheck",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"hostname",
"=",
"strtok",
"(",
"$",
"request",
"->",
"getUri",
"(",
")",
",",
"'?'",
")",
";",
"$",
"canonical",
"=",
"strtok",
"(",
"$",
"this",
"->",
"app",
"[",
"'canonical'",
"]",
"->",
"getUrl",
"(",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"canonical",
")",
"&&",
"(",
"$",
"hostname",
"!=",
"$",
"canonical",
")",
")",
"{",
"$",
"notice",
"=",
"json_encode",
"(",
"[",
"'severity'",
"=>",
"1",
",",
"'notice'",
"=>",
"\"The <code>canonical hostname</code> is set to <code>$canonical</code> in <code>config.yml</code>, but you are currently logged in using another hostname. This might cause issues with uploaded files, or links inserted in the content.\"",
",",
"'info'",
"=>",
"sprintf",
"(",
"\"Log in on Bolt using the proper URL: <code><a href='%s'>%s</a></code>.\"",
",",
"$",
"this",
"->",
"app",
"[",
"'canonical'",
"]",
"->",
"getUrl",
"(",
")",
",",
"$",
"this",
"->",
"app",
"[",
"'canonical'",
"]",
"->",
"getUrl",
"(",
")",
")",
",",
"]",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'logger.flash'",
"]",
"->",
"configuration",
"(",
"$",
"notice",
")",
";",
"}",
"}"
] |
Check if the current url matches the canonical.
@param Request $request
|
[
"Check",
"if",
"the",
"current",
"url",
"matches",
"the",
"canonical",
"."
] |
train
|
https://github.com/bolt/configuration-notices/blob/0e6439f69bf3099bd6ea30288207a3fd2351e404/src/EventListener/ConfigurationNoticesListener.php#L297-L314
|
bolt/configuration-notices
|
src/EventListener/ConfigurationNoticesListener.php
|
ConfigurationNoticesListener.imageFunctionsCheck
|
protected function imageFunctionsCheck()
{
if (!extension_loaded('exif') || !function_exists('exif_read_data')) {
$notice = json_encode([
'severity' => 1,
'notice' => 'The function <code>exif_read_data</code> does not exist, which means that Bolt can not create thumbnail images.',
'info' => "Make sure the <code>php-exif</code> extension is enabled and/or compiled into your PHP setup. See <a href='http://php.net/manual/en/exif.installation.php'>here</a>.",
]);
$this->app['logger.flash']->configuration($notice);
}
if (!extension_loaded('fileinfo') || !class_exists('finfo')) {
$notice = json_encode([
'severity' => 1,
'notice' => 'The class <code>finfo</code> does not exist, which means that Bolt can not create thumbnail images.',
'info' => "Make sure the <code>fileinfo</code> extension is enabled and/or compiled into your PHP setup. See <a href='http://php.net/manual/en/fileinfo.installation.php'>here</a>.",
]);
$this->app['logger.flash']->configuration($notice);
}
if (!extension_loaded('gd') || !function_exists('gd_info')) {
$notice = json_encode([
'severity' => 1,
'notice' => 'The function <code>gd_info</code> does not exist, which means that Bolt can not create thumbnail images.',
'info' => "Make sure the <code>gd</code> extension is enabled and/or compiled into your PHP setup. See <a href='http://php.net/manual/en/image.installation.php'>here</a>.",
]);
$this->app['logger.flash']->configuration($notice);
}
}
|
php
|
protected function imageFunctionsCheck()
{
if (!extension_loaded('exif') || !function_exists('exif_read_data')) {
$notice = json_encode([
'severity' => 1,
'notice' => 'The function <code>exif_read_data</code> does not exist, which means that Bolt can not create thumbnail images.',
'info' => "Make sure the <code>php-exif</code> extension is enabled and/or compiled into your PHP setup. See <a href='http://php.net/manual/en/exif.installation.php'>here</a>.",
]);
$this->app['logger.flash']->configuration($notice);
}
if (!extension_loaded('fileinfo') || !class_exists('finfo')) {
$notice = json_encode([
'severity' => 1,
'notice' => 'The class <code>finfo</code> does not exist, which means that Bolt can not create thumbnail images.',
'info' => "Make sure the <code>fileinfo</code> extension is enabled and/or compiled into your PHP setup. See <a href='http://php.net/manual/en/fileinfo.installation.php'>here</a>.",
]);
$this->app['logger.flash']->configuration($notice);
}
if (!extension_loaded('gd') || !function_exists('gd_info')) {
$notice = json_encode([
'severity' => 1,
'notice' => 'The function <code>gd_info</code> does not exist, which means that Bolt can not create thumbnail images.',
'info' => "Make sure the <code>gd</code> extension is enabled and/or compiled into your PHP setup. See <a href='http://php.net/manual/en/image.installation.php'>here</a>.",
]);
$this->app['logger.flash']->configuration($notice);
}
}
|
[
"protected",
"function",
"imageFunctionsCheck",
"(",
")",
"{",
"if",
"(",
"!",
"extension_loaded",
"(",
"'exif'",
")",
"||",
"!",
"function_exists",
"(",
"'exif_read_data'",
")",
")",
"{",
"$",
"notice",
"=",
"json_encode",
"(",
"[",
"'severity'",
"=>",
"1",
",",
"'notice'",
"=>",
"'The function <code>exif_read_data</code> does not exist, which means that Bolt can not create thumbnail images.'",
",",
"'info'",
"=>",
"\"Make sure the <code>php-exif</code> extension is enabled and/or compiled into your PHP setup. See <a href='http://php.net/manual/en/exif.installation.php'>here</a>.\"",
",",
"]",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'logger.flash'",
"]",
"->",
"configuration",
"(",
"$",
"notice",
")",
";",
"}",
"if",
"(",
"!",
"extension_loaded",
"(",
"'fileinfo'",
")",
"||",
"!",
"class_exists",
"(",
"'finfo'",
")",
")",
"{",
"$",
"notice",
"=",
"json_encode",
"(",
"[",
"'severity'",
"=>",
"1",
",",
"'notice'",
"=>",
"'The class <code>finfo</code> does not exist, which means that Bolt can not create thumbnail images.'",
",",
"'info'",
"=>",
"\"Make sure the <code>fileinfo</code> extension is enabled and/or compiled into your PHP setup. See <a href='http://php.net/manual/en/fileinfo.installation.php'>here</a>.\"",
",",
"]",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'logger.flash'",
"]",
"->",
"configuration",
"(",
"$",
"notice",
")",
";",
"}",
"if",
"(",
"!",
"extension_loaded",
"(",
"'gd'",
")",
"||",
"!",
"function_exists",
"(",
"'gd_info'",
")",
")",
"{",
"$",
"notice",
"=",
"json_encode",
"(",
"[",
"'severity'",
"=>",
"1",
",",
"'notice'",
"=>",
"'The function <code>gd_info</code> does not exist, which means that Bolt can not create thumbnail images.'",
",",
"'info'",
"=>",
"\"Make sure the <code>gd</code> extension is enabled and/or compiled into your PHP setup. See <a href='http://php.net/manual/en/image.installation.php'>here</a>.\"",
",",
"]",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'logger.flash'",
"]",
"->",
"configuration",
"(",
"$",
"notice",
")",
";",
"}",
"}"
] |
Check if the exif, fileinfo and gd extensions are enabled / compiled into PHP.
|
[
"Check",
"if",
"the",
"exif",
"fileinfo",
"and",
"gd",
"extensions",
"are",
"enabled",
"/",
"compiled",
"into",
"PHP",
"."
] |
train
|
https://github.com/bolt/configuration-notices/blob/0e6439f69bf3099bd6ea30288207a3fd2351e404/src/EventListener/ConfigurationNoticesListener.php#L319-L347
|
bolt/configuration-notices
|
src/EventListener/ConfigurationNoticesListener.php
|
ConfigurationNoticesListener.maintenanceCheck
|
protected function maintenanceCheck()
{
if ($this->app['config']->get('general/maintenance_mode', false)) {
$notice = json_encode([
'severity' => 1,
'notice' => "Bolt's <strong>maintenance mode</strong> is enabled. This means that non-authenticated users will not be able to see the website.",
'info' => 'To make the site available to the general public again, set <code>maintenance_mode: false</code> in your <code>config.yml</code> file.',
]);
$this->app['logger.flash']->configuration($notice);
}
}
|
php
|
protected function maintenanceCheck()
{
if ($this->app['config']->get('general/maintenance_mode', false)) {
$notice = json_encode([
'severity' => 1,
'notice' => "Bolt's <strong>maintenance mode</strong> is enabled. This means that non-authenticated users will not be able to see the website.",
'info' => 'To make the site available to the general public again, set <code>maintenance_mode: false</code> in your <code>config.yml</code> file.',
]);
$this->app['logger.flash']->configuration($notice);
}
}
|
[
"protected",
"function",
"maintenanceCheck",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'general/maintenance_mode'",
",",
"false",
")",
")",
"{",
"$",
"notice",
"=",
"json_encode",
"(",
"[",
"'severity'",
"=>",
"1",
",",
"'notice'",
"=>",
"\"Bolt's <strong>maintenance mode</strong> is enabled. This means that non-authenticated users will not be able to see the website.\"",
",",
"'info'",
"=>",
"'To make the site available to the general public again, set <code>maintenance_mode: false</code> in your <code>config.yml</code> file.'",
",",
"]",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'logger.flash'",
"]",
"->",
"configuration",
"(",
"$",
"notice",
")",
";",
"}",
"}"
] |
If the site is in maintenance mode, show this on the dashboard.
|
[
"If",
"the",
"site",
"is",
"in",
"maintenance",
"mode",
"show",
"this",
"on",
"the",
"dashboard",
"."
] |
train
|
https://github.com/bolt/configuration-notices/blob/0e6439f69bf3099bd6ea30288207a3fd2351e404/src/EventListener/ConfigurationNoticesListener.php#L352-L362
|
bolt/configuration-notices
|
src/EventListener/ConfigurationNoticesListener.php
|
ConfigurationNoticesListener.changelogCheck
|
protected function changelogCheck()
{
if (!$this->app['config']->get('general/changelog/enabled', false)) {
return;
}
// Get the number of items in the changelog
$count = $this->app['storage']->getRepository(LogChange::class)->count();
if ($count > $this->logThreshold) {
$message = sprintf(
"Bolt's <strong>changelog</strong> is enabled, and there are more than %s rows in the table.",
$this->logThreshold
);
$info = sprintf(
"Be sure to clean it up periodically, using a Cron job or on the <a href='%s'>Changelog page</a>.",
$this->app['url_generator']->generate('changelog')
);
$notice = json_encode([
'severity' => 1,
'notice' => $message,
'info' => $info,
]);
$this->app['logger.flash']->configuration($notice);
}
}
|
php
|
protected function changelogCheck()
{
if (!$this->app['config']->get('general/changelog/enabled', false)) {
return;
}
// Get the number of items in the changelog
$count = $this->app['storage']->getRepository(LogChange::class)->count();
if ($count > $this->logThreshold) {
$message = sprintf(
"Bolt's <strong>changelog</strong> is enabled, and there are more than %s rows in the table.",
$this->logThreshold
);
$info = sprintf(
"Be sure to clean it up periodically, using a Cron job or on the <a href='%s'>Changelog page</a>.",
$this->app['url_generator']->generate('changelog')
);
$notice = json_encode([
'severity' => 1,
'notice' => $message,
'info' => $info,
]);
$this->app['logger.flash']->configuration($notice);
}
}
|
[
"protected",
"function",
"changelogCheck",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'general/changelog/enabled'",
",",
"false",
")",
")",
"{",
"return",
";",
"}",
"// Get the number of items in the changelog",
"$",
"count",
"=",
"$",
"this",
"->",
"app",
"[",
"'storage'",
"]",
"->",
"getRepository",
"(",
"LogChange",
"::",
"class",
")",
"->",
"count",
"(",
")",
";",
"if",
"(",
"$",
"count",
">",
"$",
"this",
"->",
"logThreshold",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"\"Bolt's <strong>changelog</strong> is enabled, and there are more than %s rows in the table.\"",
",",
"$",
"this",
"->",
"logThreshold",
")",
";",
"$",
"info",
"=",
"sprintf",
"(",
"\"Be sure to clean it up periodically, using a Cron job or on the <a href='%s'>Changelog page</a>.\"",
",",
"$",
"this",
"->",
"app",
"[",
"'url_generator'",
"]",
"->",
"generate",
"(",
"'changelog'",
")",
")",
";",
"$",
"notice",
"=",
"json_encode",
"(",
"[",
"'severity'",
"=>",
"1",
",",
"'notice'",
"=>",
"$",
"message",
",",
"'info'",
"=>",
"$",
"info",
",",
"]",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'logger.flash'",
"]",
"->",
"configuration",
"(",
"$",
"notice",
")",
";",
"}",
"}"
] |
Check if Changelog is enabled, and if doesn't contain too many rows.
|
[
"Check",
"if",
"Changelog",
"is",
"enabled",
"and",
"if",
"doesn",
"t",
"contain",
"too",
"many",
"rows",
"."
] |
train
|
https://github.com/bolt/configuration-notices/blob/0e6439f69bf3099bd6ea30288207a3fd2351e404/src/EventListener/ConfigurationNoticesListener.php#L367-L392
|
bolt/configuration-notices
|
src/EventListener/ConfigurationNoticesListener.php
|
ConfigurationNoticesListener.systemlogCheck
|
protected function systemlogCheck()
{
// Get the number of items in the changelog
$count = $this->app['storage']->getRepository(LogSystem::class)->count();
if ($count > $this->logThreshold) {
$message = sprintf(
"Bolt's <strong>systemlog</strong> is enabled, and there are more than %s rows in the table.",
$this->logThreshold
);
$info = sprintf(
"Be sure to clean it up periodically, using a Cron job or on the <a href='%s'>Systemlog page</a>.",
$this->app['url_generator']->generate('systemlog')
);
$notice = json_encode([
'severity' => 1,
'notice' => $message,
'info' => $info,
]);
$this->app['logger.flash']->configuration($notice);
}
}
|
php
|
protected function systemlogCheck()
{
// Get the number of items in the changelog
$count = $this->app['storage']->getRepository(LogSystem::class)->count();
if ($count > $this->logThreshold) {
$message = sprintf(
"Bolt's <strong>systemlog</strong> is enabled, and there are more than %s rows in the table.",
$this->logThreshold
);
$info = sprintf(
"Be sure to clean it up periodically, using a Cron job or on the <a href='%s'>Systemlog page</a>.",
$this->app['url_generator']->generate('systemlog')
);
$notice = json_encode([
'severity' => 1,
'notice' => $message,
'info' => $info,
]);
$this->app['logger.flash']->configuration($notice);
}
}
|
[
"protected",
"function",
"systemlogCheck",
"(",
")",
"{",
"// Get the number of items in the changelog",
"$",
"count",
"=",
"$",
"this",
"->",
"app",
"[",
"'storage'",
"]",
"->",
"getRepository",
"(",
"LogSystem",
"::",
"class",
")",
"->",
"count",
"(",
")",
";",
"if",
"(",
"$",
"count",
">",
"$",
"this",
"->",
"logThreshold",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"\"Bolt's <strong>systemlog</strong> is enabled, and there are more than %s rows in the table.\"",
",",
"$",
"this",
"->",
"logThreshold",
")",
";",
"$",
"info",
"=",
"sprintf",
"(",
"\"Be sure to clean it up periodically, using a Cron job or on the <a href='%s'>Systemlog page</a>.\"",
",",
"$",
"this",
"->",
"app",
"[",
"'url_generator'",
"]",
"->",
"generate",
"(",
"'systemlog'",
")",
")",
";",
"$",
"notice",
"=",
"json_encode",
"(",
"[",
"'severity'",
"=>",
"1",
",",
"'notice'",
"=>",
"$",
"message",
",",
"'info'",
"=>",
"$",
"info",
",",
"]",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'logger.flash'",
"]",
"->",
"configuration",
"(",
"$",
"notice",
")",
";",
"}",
"}"
] |
Check if systemlog doesn't contain too many rows.
|
[
"Check",
"if",
"systemlog",
"doesn",
"t",
"contain",
"too",
"many",
"rows",
"."
] |
train
|
https://github.com/bolt/configuration-notices/blob/0e6439f69bf3099bd6ea30288207a3fd2351e404/src/EventListener/ConfigurationNoticesListener.php#L397-L418
|
bolt/configuration-notices
|
src/EventListener/ConfigurationNoticesListener.php
|
ConfigurationNoticesListener.thumbnailConfigCheck
|
protected function thumbnailConfigCheck()
{
$thumbConfig = $this->app['config']->get('general/thumbnails');
if ((strpos($thumbConfig['notfound_image'] . $thumbConfig['error_image'], '://') === false)) {
$notice = json_encode([
'severity' => 1,
'notice' => 'Your configuration settings for <code>thumbnails/notfound_image</code> or <code>thumbnails/error_image</code> contain a value that needs to be updated.',
'info' => 'Update the value with a namespace, for example: <code>bolt_assets://img/default_notfound.png</code>.',
]);
$this->app['logger.flash']->configuration($notice);
}
}
|
php
|
protected function thumbnailConfigCheck()
{
$thumbConfig = $this->app['config']->get('general/thumbnails');
if ((strpos($thumbConfig['notfound_image'] . $thumbConfig['error_image'], '://') === false)) {
$notice = json_encode([
'severity' => 1,
'notice' => 'Your configuration settings for <code>thumbnails/notfound_image</code> or <code>thumbnails/error_image</code> contain a value that needs to be updated.',
'info' => 'Update the value with a namespace, for example: <code>bolt_assets://img/default_notfound.png</code>.',
]);
$this->app['logger.flash']->configuration($notice);
}
}
|
[
"protected",
"function",
"thumbnailConfigCheck",
"(",
")",
"{",
"$",
"thumbConfig",
"=",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'general/thumbnails'",
")",
";",
"if",
"(",
"(",
"strpos",
"(",
"$",
"thumbConfig",
"[",
"'notfound_image'",
"]",
".",
"$",
"thumbConfig",
"[",
"'error_image'",
"]",
",",
"'://'",
")",
"===",
"false",
")",
")",
"{",
"$",
"notice",
"=",
"json_encode",
"(",
"[",
"'severity'",
"=>",
"1",
",",
"'notice'",
"=>",
"'Your configuration settings for <code>thumbnails/notfound_image</code> or <code>thumbnails/error_image</code> contain a value that needs to be updated.'",
",",
"'info'",
"=>",
"'Update the value with a namespace, for example: <code>bolt_assets://img/default_notfound.png</code>.'",
",",
"]",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'logger.flash'",
"]",
"->",
"configuration",
"(",
"$",
"notice",
")",
";",
"}",
"}"
] |
Check if the thumbnail config has been updated for 3.3+ .
|
[
"Check",
"if",
"the",
"thumbnail",
"config",
"has",
"been",
"updated",
"for",
"3",
".",
"3",
"+",
"."
] |
train
|
https://github.com/bolt/configuration-notices/blob/0e6439f69bf3099bd6ea30288207a3fd2351e404/src/EventListener/ConfigurationNoticesListener.php#L423-L435
|
bolt/configuration-notices
|
src/EventListener/ConfigurationNoticesListener.php
|
ConfigurationNoticesListener.isWritable
|
private function isWritable(Bag $fileSystem, $filePath)
{
/** @var \Bolt\Filesystem\FilesystemInterface $fs */
$fs = $this->app['filesystem']->getFilesystem($fileSystem->get('name'));
$filePath = $fileSystem->get('folder') . '/' . $filePath;
try {
$fs->put($filePath, 'ok');
$contents = $fs->read($filePath);
$fs->delete($filePath);
} catch (\Exception $e) {
return false;
}
return $contents;
}
|
php
|
private function isWritable(Bag $fileSystem, $filePath)
{
/** @var \Bolt\Filesystem\FilesystemInterface $fs */
$fs = $this->app['filesystem']->getFilesystem($fileSystem->get('name'));
$filePath = $fileSystem->get('folder') . '/' . $filePath;
try {
$fs->put($filePath, 'ok');
$contents = $fs->read($filePath);
$fs->delete($filePath);
} catch (\Exception $e) {
return false;
}
return $contents;
}
|
[
"private",
"function",
"isWritable",
"(",
"Bag",
"$",
"fileSystem",
",",
"$",
"filePath",
")",
"{",
"/** @var \\Bolt\\Filesystem\\FilesystemInterface $fs */",
"$",
"fs",
"=",
"$",
"this",
"->",
"app",
"[",
"'filesystem'",
"]",
"->",
"getFilesystem",
"(",
"$",
"fileSystem",
"->",
"get",
"(",
"'name'",
")",
")",
";",
"$",
"filePath",
"=",
"$",
"fileSystem",
"->",
"get",
"(",
"'folder'",
")",
".",
"'/'",
".",
"$",
"filePath",
";",
"try",
"{",
"$",
"fs",
"->",
"put",
"(",
"$",
"filePath",
",",
"'ok'",
")",
";",
"$",
"contents",
"=",
"$",
"fs",
"->",
"read",
"(",
"$",
"filePath",
")",
";",
"$",
"fs",
"->",
"delete",
"(",
"$",
"filePath",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"contents",
";",
"}"
] |
@param Bag $fileSystem
@param string $filePath
@return bool|string
|
[
"@param",
"Bag",
"$fileSystem",
"@param",
"string",
"$filePath"
] |
train
|
https://github.com/bolt/configuration-notices/blob/0e6439f69bf3099bd6ea30288207a3fd2351e404/src/EventListener/ConfigurationNoticesListener.php#L443-L459
|
bolt/configuration-notices
|
src/EventListener/ConfigurationNoticesListener.php
|
ConfigurationNoticesListener.getFolderName
|
private function getFolderName(Bag $fileSystem)
{
if ($fileSystem->has('label')) {
return $fileSystem->get('label');
}
return sprintf('%s://%s', $fileSystem->get('name'), $fileSystem->get('folder'));
}
|
php
|
private function getFolderName(Bag $fileSystem)
{
if ($fileSystem->has('label')) {
return $fileSystem->get('label');
}
return sprintf('%s://%s', $fileSystem->get('name'), $fileSystem->get('folder'));
}
|
[
"private",
"function",
"getFolderName",
"(",
"Bag",
"$",
"fileSystem",
")",
"{",
"if",
"(",
"$",
"fileSystem",
"->",
"has",
"(",
"'label'",
")",
")",
"{",
"return",
"$",
"fileSystem",
"->",
"get",
"(",
"'label'",
")",
";",
"}",
"return",
"sprintf",
"(",
"'%s://%s'",
",",
"$",
"fileSystem",
"->",
"get",
"(",
"'name'",
")",
",",
"$",
"fileSystem",
"->",
"get",
"(",
"'folder'",
")",
")",
";",
"}"
] |
@param Bag $fileSystem
@return string
|
[
"@param",
"Bag",
"$fileSystem"
] |
train
|
https://github.com/bolt/configuration-notices/blob/0e6439f69bf3099bd6ea30288207a3fd2351e404/src/EventListener/ConfigurationNoticesListener.php#L466-L473
|
FrenchFrogs/framework
|
src/Table/Column/Strainer/Strainer.php
|
Strainer.call
|
public function call(\FrenchFrogs\Table\Table\Table $table, ...$params)
{
if ($this->hasCallable()) {
array_unshift($params, $this);
array_unshift($params, $table);
call_user_func_array($this->callable, $params);
} else {
// verify that source is a query
if (!$table->isSourceQueryBuilder()) {
throw new \Exception('Table source is not an instance of query builder');
}
$this->setValue($params[0]);
$table->getSource()->where($this->getField(), '=', $params[0]);
}
return $this;
}
|
php
|
public function call(\FrenchFrogs\Table\Table\Table $table, ...$params)
{
if ($this->hasCallable()) {
array_unshift($params, $this);
array_unshift($params, $table);
call_user_func_array($this->callable, $params);
} else {
// verify that source is a query
if (!$table->isSourceQueryBuilder()) {
throw new \Exception('Table source is not an instance of query builder');
}
$this->setValue($params[0]);
$table->getSource()->where($this->getField(), '=', $params[0]);
}
return $this;
}
|
[
"public",
"function",
"call",
"(",
"\\",
"FrenchFrogs",
"\\",
"Table",
"\\",
"Table",
"\\",
"Table",
"$",
"table",
",",
"...",
"$",
"params",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasCallable",
"(",
")",
")",
"{",
"array_unshift",
"(",
"$",
"params",
",",
"$",
"this",
")",
";",
"array_unshift",
"(",
"$",
"params",
",",
"$",
"table",
")",
";",
"call_user_func_array",
"(",
"$",
"this",
"->",
"callable",
",",
"$",
"params",
")",
";",
"}",
"else",
"{",
"// verify that source is a query",
"if",
"(",
"!",
"$",
"table",
"->",
"isSourceQueryBuilder",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Table source is not an instance of query builder'",
")",
";",
"}",
"$",
"this",
"->",
"setValue",
"(",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"table",
"->",
"getSource",
"(",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"getField",
"(",
")",
",",
"'='",
",",
"$",
"params",
"[",
"0",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Execute strainer
@param \FrenchFrogs\Table\Table\Table $table
@param array ...$params
@return $this
@throws \Exception
|
[
"Execute",
"strainer"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Column/Strainer/Strainer.php#L120-L139
|
FrenchFrogs/framework
|
src/Table/Column/Strainer/Strainer.php
|
Strainer.setValue
|
public function setValue($value)
{
if (isset($this->element)) {
$this->element->setValue($value);
}
return $this;
}
|
php
|
public function setValue($value)
{
if (isset($this->element)) {
$this->element->setValue($value);
}
return $this;
}
|
[
"public",
"function",
"setValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"element",
")",
")",
"{",
"$",
"this",
"->",
"element",
"->",
"setValue",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set value to strainer element
@param $value
@return $this
|
[
"Set",
"value",
"to",
"strainer",
"element"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Column/Strainer/Strainer.php#L148-L156
|
acasademont/wurfl
|
WURFL/Storage/Factory.php
|
WURFL_Storage_Factory.create
|
public static function create($configuration)
{
$currentConfiguration = is_array($configuration) ?
array_merge(self::$defaultConfiguration, $configuration)
: self::$defaultConfiguration;
$class = self::className($currentConfiguration);
return new $class($currentConfiguration["params"]);
}
|
php
|
public static function create($configuration)
{
$currentConfiguration = is_array($configuration) ?
array_merge(self::$defaultConfiguration, $configuration)
: self::$defaultConfiguration;
$class = self::className($currentConfiguration);
return new $class($currentConfiguration["params"]);
}
|
[
"public",
"static",
"function",
"create",
"(",
"$",
"configuration",
")",
"{",
"$",
"currentConfiguration",
"=",
"is_array",
"(",
"$",
"configuration",
")",
"?",
"array_merge",
"(",
"self",
"::",
"$",
"defaultConfiguration",
",",
"$",
"configuration",
")",
":",
"self",
"::",
"$",
"defaultConfiguration",
";",
"$",
"class",
"=",
"self",
"::",
"className",
"(",
"$",
"currentConfiguration",
")",
";",
"return",
"new",
"$",
"class",
"(",
"$",
"currentConfiguration",
"[",
"\"params\"",
"]",
")",
";",
"}"
] |
Create a configuration based on the default configuration with the differences from $configuration
@param array $configuration
@return WURFL_Storage_Base Storage object, initialized with the given $configuration
|
[
"Create",
"a",
"configuration",
"based",
"on",
"the",
"default",
"configuration",
"with",
"the",
"differences",
"from",
"$configuration"
] |
train
|
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/Storage/Factory.php#L38-L45
|
PandawanTechnology/neo4j-data-fixtures
|
src/Loader.php
|
Loader.loadFromDirectory
|
public function loadFromDirectory($dir)
{
if (!is_dir($dir)) {
throw new \InvalidArgumentException(sprintf('"%s" does not exist', $dir));
}
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::LEAVES_ONLY
);
return $this->loadFromIterator($iterator);
}
|
php
|
public function loadFromDirectory($dir)
{
if (!is_dir($dir)) {
throw new \InvalidArgumentException(sprintf('"%s" does not exist', $dir));
}
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::LEAVES_ONLY
);
return $this->loadFromIterator($iterator);
}
|
[
"public",
"function",
"loadFromDirectory",
"(",
"$",
"dir",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'\"%s\" does not exist'",
",",
"$",
"dir",
")",
")",
";",
"}",
"$",
"iterator",
"=",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"new",
"\\",
"RecursiveDirectoryIterator",
"(",
"$",
"dir",
",",
"\\",
"RecursiveDirectoryIterator",
"::",
"SKIP_DOTS",
")",
",",
"\\",
"RecursiveIteratorIterator",
"::",
"LEAVES_ONLY",
")",
";",
"return",
"$",
"this",
"->",
"loadFromIterator",
"(",
"$",
"iterator",
")",
";",
"}"
] |
Find fixtures classes in a given directory and load them.
@param string $dir Directory to find fixture classes in.
@return array $fixtures Array of loaded fixture object instances.
|
[
"Find",
"fixtures",
"classes",
"in",
"a",
"given",
"directory",
"and",
"load",
"them",
"."
] |
train
|
https://github.com/PandawanTechnology/neo4j-data-fixtures/blob/58701f30f3de9c848308623c5e773aada106a2aa/src/Loader.php#L36-L48
|
PandawanTechnology/neo4j-data-fixtures
|
src/Loader.php
|
Loader.addFixture
|
public function addFixture(Neo4jFixtureInterface $fixture)
{
$fixtureClass = get_class($fixture);
if (isset($this->fixtures[$fixtureClass])) {
return;
}
$this->fixtures[$fixtureClass] = $fixture;
if ($fixture instanceof Neo4jDependentFixtureInterface) {
$this->orderFixturesByDependencies = true;
foreach ($fixture->getDependencies() as $class) {
if (class_exists($class)) {
$this->addFixture(new $class());
}
}
}
}
|
php
|
public function addFixture(Neo4jFixtureInterface $fixture)
{
$fixtureClass = get_class($fixture);
if (isset($this->fixtures[$fixtureClass])) {
return;
}
$this->fixtures[$fixtureClass] = $fixture;
if ($fixture instanceof Neo4jDependentFixtureInterface) {
$this->orderFixturesByDependencies = true;
foreach ($fixture->getDependencies() as $class) {
if (class_exists($class)) {
$this->addFixture(new $class());
}
}
}
}
|
[
"public",
"function",
"addFixture",
"(",
"Neo4jFixtureInterface",
"$",
"fixture",
")",
"{",
"$",
"fixtureClass",
"=",
"get_class",
"(",
"$",
"fixture",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"fixtures",
"[",
"$",
"fixtureClass",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"fixtures",
"[",
"$",
"fixtureClass",
"]",
"=",
"$",
"fixture",
";",
"if",
"(",
"$",
"fixture",
"instanceof",
"Neo4jDependentFixtureInterface",
")",
"{",
"$",
"this",
"->",
"orderFixturesByDependencies",
"=",
"true",
";",
"foreach",
"(",
"$",
"fixture",
"->",
"getDependencies",
"(",
")",
"as",
"$",
"class",
")",
"{",
"if",
"(",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"this",
"->",
"addFixture",
"(",
"new",
"$",
"class",
"(",
")",
")",
";",
"}",
"}",
"}",
"}"
] |
Add a fixture object instance to the loader.
@param Neo4jFixtureInterface $fixture
|
[
"Add",
"a",
"fixture",
"object",
"instance",
"to",
"the",
"loader",
"."
] |
train
|
https://github.com/PandawanTechnology/neo4j-data-fixtures/blob/58701f30f3de9c848308623c5e773aada106a2aa/src/Loader.php#L85-L104
|
PandawanTechnology/neo4j-data-fixtures
|
src/Loader.php
|
Loader.isTransient
|
public function isTransient($className)
{
$rc = new \ReflectionClass($className);
if ($rc->isAbstract()) {
return true;
}
$interfaces = class_implements($className);
return !in_array('PandawanTechnology\Neo4jDataFixtures\Neo4jFixtureInterface', $interfaces);
}
|
php
|
public function isTransient($className)
{
$rc = new \ReflectionClass($className);
if ($rc->isAbstract()) {
return true;
}
$interfaces = class_implements($className);
return !in_array('PandawanTechnology\Neo4jDataFixtures\Neo4jFixtureInterface', $interfaces);
}
|
[
"public",
"function",
"isTransient",
"(",
"$",
"className",
")",
"{",
"$",
"rc",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"if",
"(",
"$",
"rc",
"->",
"isAbstract",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"interfaces",
"=",
"class_implements",
"(",
"$",
"className",
")",
";",
"return",
"!",
"in_array",
"(",
"'PandawanTechnology\\Neo4jDataFixtures\\Neo4jFixtureInterface'",
",",
"$",
"interfaces",
")",
";",
"}"
] |
Check if a given fixture is transient and should not be considered a data fixtures
class.
@param string $className
@return bool
|
[
"Check",
"if",
"a",
"given",
"fixture",
"is",
"transient",
"and",
"should",
"not",
"be",
"considered",
"a",
"data",
"fixtures",
"class",
"."
] |
train
|
https://github.com/PandawanTechnology/neo4j-data-fixtures/blob/58701f30f3de9c848308623c5e773aada106a2aa/src/Loader.php#L134-L145
|
PandawanTechnology/neo4j-data-fixtures
|
src/Loader.php
|
Loader.loadFromIterator
|
private function loadFromIterator(\Iterator $iterator)
{
$includedFiles = [];
foreach ($iterator as $file) {
if (($fileName = $file->getBasename($this->fileExtension)) == $file->getBasename()) {
continue;
}
$sourceFile = realpath($file->getPathName());
require_once $sourceFile;
$includedFiles[] = $sourceFile;
}
$fixtures = [];
$declared = get_declared_classes();
foreach ($declared as $className) {
$reflClass = new \ReflectionClass($className);
$sourceFile = $reflClass->getFileName();
if (in_array($sourceFile, $includedFiles) && !$this->isTransient($className)) {
$fixture = new $className();
$fixtures[] = $fixture;
$this->addFixture($fixture);
}
}
return $fixtures;
}
|
php
|
private function loadFromIterator(\Iterator $iterator)
{
$includedFiles = [];
foreach ($iterator as $file) {
if (($fileName = $file->getBasename($this->fileExtension)) == $file->getBasename()) {
continue;
}
$sourceFile = realpath($file->getPathName());
require_once $sourceFile;
$includedFiles[] = $sourceFile;
}
$fixtures = [];
$declared = get_declared_classes();
foreach ($declared as $className) {
$reflClass = new \ReflectionClass($className);
$sourceFile = $reflClass->getFileName();
if (in_array($sourceFile, $includedFiles) && !$this->isTransient($className)) {
$fixture = new $className();
$fixtures[] = $fixture;
$this->addFixture($fixture);
}
}
return $fixtures;
}
|
[
"private",
"function",
"loadFromIterator",
"(",
"\\",
"Iterator",
"$",
"iterator",
")",
"{",
"$",
"includedFiles",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"(",
"$",
"fileName",
"=",
"$",
"file",
"->",
"getBasename",
"(",
"$",
"this",
"->",
"fileExtension",
")",
")",
"==",
"$",
"file",
"->",
"getBasename",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"sourceFile",
"=",
"realpath",
"(",
"$",
"file",
"->",
"getPathName",
"(",
")",
")",
";",
"require_once",
"$",
"sourceFile",
";",
"$",
"includedFiles",
"[",
"]",
"=",
"$",
"sourceFile",
";",
"}",
"$",
"fixtures",
"=",
"[",
"]",
";",
"$",
"declared",
"=",
"get_declared_classes",
"(",
")",
";",
"foreach",
"(",
"$",
"declared",
"as",
"$",
"className",
")",
"{",
"$",
"reflClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"$",
"sourceFile",
"=",
"$",
"reflClass",
"->",
"getFileName",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"sourceFile",
",",
"$",
"includedFiles",
")",
"&&",
"!",
"$",
"this",
"->",
"isTransient",
"(",
"$",
"className",
")",
")",
"{",
"$",
"fixture",
"=",
"new",
"$",
"className",
"(",
")",
";",
"$",
"fixtures",
"[",
"]",
"=",
"$",
"fixture",
";",
"$",
"this",
"->",
"addFixture",
"(",
"$",
"fixture",
")",
";",
"}",
"}",
"return",
"$",
"fixtures",
";",
"}"
] |
Load fixtures from files contained in iterator.
@param \Iterator $iterator Iterator over files from which fixtures should be loaded.
@return Neo4jFixtureInterface[] $fixtures Array of loaded fixture object instances.
|
[
"Load",
"fixtures",
"from",
"files",
"contained",
"in",
"iterator",
"."
] |
train
|
https://github.com/PandawanTechnology/neo4j-data-fixtures/blob/58701f30f3de9c848308623c5e773aada106a2aa/src/Loader.php#L274-L303
|
jan-dolata/crude-crud
|
src/Http/Requests/ExportRequest.php
|
ExportRequest.authorize
|
public function authorize()
{
$crude = CrudeInstance::get($this->crudeName);
if ($crude == null)
return false;
if ($crude->cannotExport())
return false;
$this->crude = $crude;
return true;
}
|
php
|
public function authorize()
{
$crude = CrudeInstance::get($this->crudeName);
if ($crude == null)
return false;
if ($crude->cannotExport())
return false;
$this->crude = $crude;
return true;
}
|
[
"public",
"function",
"authorize",
"(",
")",
"{",
"$",
"crude",
"=",
"CrudeInstance",
"::",
"get",
"(",
"$",
"this",
"->",
"crudeName",
")",
";",
"if",
"(",
"$",
"crude",
"==",
"null",
")",
"return",
"false",
";",
"if",
"(",
"$",
"crude",
"->",
"cannotExport",
"(",
")",
")",
"return",
"false",
";",
"$",
"this",
"->",
"crude",
"=",
"$",
"crude",
";",
"return",
"true",
";",
"}"
] |
Determine if the user is authorized to make this request.
@return bool
|
[
"Determine",
"if",
"the",
"user",
"is",
"authorized",
"to",
"make",
"this",
"request",
"."
] |
train
|
https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Http/Requests/ExportRequest.php#L16-L29
|
jkribeiro/composer-hydration
|
src/Composer/ComposerHydrationHandler.php
|
ComposerHydrationHandler.toUpperCamelCase
|
public function toUpperCamelCase($string)
{
$string = str_replace(array('-', '_'), ' ', $string);
$string = ucwords(strtolower($string));
$string = str_replace(' ', '', $string);
return $string;
}
|
php
|
public function toUpperCamelCase($string)
{
$string = str_replace(array('-', '_'), ' ', $string);
$string = ucwords(strtolower($string));
$string = str_replace(' ', '', $string);
return $string;
}
|
[
"public",
"function",
"toUpperCamelCase",
"(",
"$",
"string",
")",
"{",
"$",
"string",
"=",
"str_replace",
"(",
"array",
"(",
"'-'",
",",
"'_'",
")",
",",
"' '",
",",
"$",
"string",
")",
";",
"$",
"string",
"=",
"ucwords",
"(",
"strtolower",
"(",
"$",
"string",
")",
")",
";",
"$",
"string",
"=",
"str_replace",
"(",
"' '",
",",
"''",
",",
"$",
"string",
")",
";",
"return",
"$",
"string",
";",
"}"
] |
Converts a string to upper camel case.
@param string $string
The string to be converted.
@return string
An upper camel case string.
|
[
"Converts",
"a",
"string",
"to",
"upper",
"camel",
"case",
"."
] |
train
|
https://github.com/jkribeiro/composer-hydration/blob/b0dd7e9c4a966f664c2df08b3067c1b6f263e226/src/Composer/ComposerHydrationHandler.php#L99-L106
|
jkribeiro/composer-hydration
|
src/Composer/ComposerHydrationHandler.php
|
ComposerHydrationHandler.getMagicVariableValue
|
public function getMagicVariableValue($variable)
{
$base_path_name = basename(realpath("."));
switch ($variable) {
case self::MAGIC_VAR_BASENAME:
return $base_path_name;
break;
case self::MAGIC_VAR_UCFIRST_BASENAME:
return ucfirst($base_path_name);
break;
case self::MAGIC_VAR_UPPER_CAMEL_CASE_BASENAME:
return $this->toUpperCamelCase($base_path_name);
break;
case self::MAGIC_VAR_LOWER_CAMEL_CASE_BASENAME:
return $this->toLowerCamelCase($base_path_name);
break;
}
return null;
}
|
php
|
public function getMagicVariableValue($variable)
{
$base_path_name = basename(realpath("."));
switch ($variable) {
case self::MAGIC_VAR_BASENAME:
return $base_path_name;
break;
case self::MAGIC_VAR_UCFIRST_BASENAME:
return ucfirst($base_path_name);
break;
case self::MAGIC_VAR_UPPER_CAMEL_CASE_BASENAME:
return $this->toUpperCamelCase($base_path_name);
break;
case self::MAGIC_VAR_LOWER_CAMEL_CASE_BASENAME:
return $this->toLowerCamelCase($base_path_name);
break;
}
return null;
}
|
[
"public",
"function",
"getMagicVariableValue",
"(",
"$",
"variable",
")",
"{",
"$",
"base_path_name",
"=",
"basename",
"(",
"realpath",
"(",
"\".\"",
")",
")",
";",
"switch",
"(",
"$",
"variable",
")",
"{",
"case",
"self",
"::",
"MAGIC_VAR_BASENAME",
":",
"return",
"$",
"base_path_name",
";",
"break",
";",
"case",
"self",
"::",
"MAGIC_VAR_UCFIRST_BASENAME",
":",
"return",
"ucfirst",
"(",
"$",
"base_path_name",
")",
";",
"break",
";",
"case",
"self",
"::",
"MAGIC_VAR_UPPER_CAMEL_CASE_BASENAME",
":",
"return",
"$",
"this",
"->",
"toUpperCamelCase",
"(",
"$",
"base_path_name",
")",
";",
"break",
";",
"case",
"self",
"::",
"MAGIC_VAR_LOWER_CAMEL_CASE_BASENAME",
":",
"return",
"$",
"this",
"->",
"toLowerCamelCase",
"(",
"$",
"base_path_name",
")",
";",
"break",
";",
"}",
"return",
"null",
";",
"}"
] |
Returns the magic value of a magic variable.
@return string
The magic value.
|
[
"Returns",
"the",
"magic",
"value",
"of",
"a",
"magic",
"variable",
"."
] |
train
|
https://github.com/jkribeiro/composer-hydration/blob/b0dd7e9c4a966f664c2df08b3067c1b6f263e226/src/Composer/ComposerHydrationHandler.php#L130-L153
|
jkribeiro/composer-hydration
|
src/Composer/ComposerHydrationHandler.php
|
ComposerHydrationHandler.getReplaceValuesFromArgument
|
public function getReplaceValuesFromArgument($argValues)
{
$replaceValues = array();
$argValues = explode(',', $argValues);
foreach ($argValues as $argValue) {
$argValue = explode(':', $argValue);
if (count($argValue) != 2) {
$msg = 'Command argument "--replace" must follow the format: --replace="{SEARCH}:{REPLACE},..."';
throw new \ErrorException($msg);
}
$search = trim($argValue[0]);
$replace = trim($argValue[1]);
if ($this->isMagicVariable($replace)) {
// Is magic variable, so, replace by the magic value.
$replace = $this->getMagicVariableValue($replace);
}
$replaceValues[$search] = $replace;
}
return $replaceValues;
}
|
php
|
public function getReplaceValuesFromArgument($argValues)
{
$replaceValues = array();
$argValues = explode(',', $argValues);
foreach ($argValues as $argValue) {
$argValue = explode(':', $argValue);
if (count($argValue) != 2) {
$msg = 'Command argument "--replace" must follow the format: --replace="{SEARCH}:{REPLACE},..."';
throw new \ErrorException($msg);
}
$search = trim($argValue[0]);
$replace = trim($argValue[1]);
if ($this->isMagicVariable($replace)) {
// Is magic variable, so, replace by the magic value.
$replace = $this->getMagicVariableValue($replace);
}
$replaceValues[$search] = $replace;
}
return $replaceValues;
}
|
[
"public",
"function",
"getReplaceValuesFromArgument",
"(",
"$",
"argValues",
")",
"{",
"$",
"replaceValues",
"=",
"array",
"(",
")",
";",
"$",
"argValues",
"=",
"explode",
"(",
"','",
",",
"$",
"argValues",
")",
";",
"foreach",
"(",
"$",
"argValues",
"as",
"$",
"argValue",
")",
"{",
"$",
"argValue",
"=",
"explode",
"(",
"':'",
",",
"$",
"argValue",
")",
";",
"if",
"(",
"count",
"(",
"$",
"argValue",
")",
"!=",
"2",
")",
"{",
"$",
"msg",
"=",
"'Command argument \"--replace\" must follow the format: --replace=\"{SEARCH}:{REPLACE},...\"'",
";",
"throw",
"new",
"\\",
"ErrorException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"search",
"=",
"trim",
"(",
"$",
"argValue",
"[",
"0",
"]",
")",
";",
"$",
"replace",
"=",
"trim",
"(",
"$",
"argValue",
"[",
"1",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isMagicVariable",
"(",
"$",
"replace",
")",
")",
"{",
"// Is magic variable, so, replace by the magic value.",
"$",
"replace",
"=",
"$",
"this",
"->",
"getMagicVariableValue",
"(",
"$",
"replace",
")",
";",
"}",
"$",
"replaceValues",
"[",
"$",
"search",
"]",
"=",
"$",
"replace",
";",
"}",
"return",
"$",
"replaceValues",
";",
"}"
] |
Returns an array containing the replace values from command argument.
@param string $argValues
Command argument replace value.
@return array
An array, following the format: SEARCH => REPLACE.
|
[
"Returns",
"an",
"array",
"containing",
"the",
"replace",
"values",
"from",
"command",
"argument",
"."
] |
train
|
https://github.com/jkribeiro/composer-hydration/blob/b0dd7e9c4a966f664c2df08b3067c1b6f263e226/src/Composer/ComposerHydrationHandler.php#L164-L187
|
jkribeiro/composer-hydration
|
src/Composer/ComposerHydrationHandler.php
|
ComposerHydrationHandler.getArguments
|
public function getArguments()
{
// Checks if script received command arguments.
$cmdArguments = $this->event->getArguments();
if (!$cmdArguments) {
throw new \ErrorException('Hydrate command expects arguments.');
}
// Treats arguments.
$returnArguments = array();
foreach ($cmdArguments as $cmdArgument) {
$cmdArgument = explode('=', $cmdArgument);
$argument = $cmdArgument[0];
// Checks if the argument exists.
if (!$this->cmdArgumentExist($argument)) {
throw new \ErrorException("Command argument '$argument' do not exist.");
}
// Treats REPLACE_ARG argument.
if ($argument == self::REPLACE_ARG) {
$replaceValues = !empty($cmdArgument[1]) ? $cmdArgument[1] : null;
if (!$replaceValues) {
$msg = 'Command argument "--replace" must contain values, like: --replace="{SEARCH}:{REPLACE},.."';
throw new \ErrorException($msg);
}
$returnArguments[self::REPLACE_ARG] = $this->getReplaceValuesFromArgument($replaceValues);
}
}
return $returnArguments;
}
|
php
|
public function getArguments()
{
// Checks if script received command arguments.
$cmdArguments = $this->event->getArguments();
if (!$cmdArguments) {
throw new \ErrorException('Hydrate command expects arguments.');
}
// Treats arguments.
$returnArguments = array();
foreach ($cmdArguments as $cmdArgument) {
$cmdArgument = explode('=', $cmdArgument);
$argument = $cmdArgument[0];
// Checks if the argument exists.
if (!$this->cmdArgumentExist($argument)) {
throw new \ErrorException("Command argument '$argument' do not exist.");
}
// Treats REPLACE_ARG argument.
if ($argument == self::REPLACE_ARG) {
$replaceValues = !empty($cmdArgument[1]) ? $cmdArgument[1] : null;
if (!$replaceValues) {
$msg = 'Command argument "--replace" must contain values, like: --replace="{SEARCH}:{REPLACE},.."';
throw new \ErrorException($msg);
}
$returnArguments[self::REPLACE_ARG] = $this->getReplaceValuesFromArgument($replaceValues);
}
}
return $returnArguments;
}
|
[
"public",
"function",
"getArguments",
"(",
")",
"{",
"// Checks if script received command arguments.",
"$",
"cmdArguments",
"=",
"$",
"this",
"->",
"event",
"->",
"getArguments",
"(",
")",
";",
"if",
"(",
"!",
"$",
"cmdArguments",
")",
"{",
"throw",
"new",
"\\",
"ErrorException",
"(",
"'Hydrate command expects arguments.'",
")",
";",
"}",
"// Treats arguments.",
"$",
"returnArguments",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"cmdArguments",
"as",
"$",
"cmdArgument",
")",
"{",
"$",
"cmdArgument",
"=",
"explode",
"(",
"'='",
",",
"$",
"cmdArgument",
")",
";",
"$",
"argument",
"=",
"$",
"cmdArgument",
"[",
"0",
"]",
";",
"// Checks if the argument exists.",
"if",
"(",
"!",
"$",
"this",
"->",
"cmdArgumentExist",
"(",
"$",
"argument",
")",
")",
"{",
"throw",
"new",
"\\",
"ErrorException",
"(",
"\"Command argument '$argument' do not exist.\"",
")",
";",
"}",
"// Treats REPLACE_ARG argument.",
"if",
"(",
"$",
"argument",
"==",
"self",
"::",
"REPLACE_ARG",
")",
"{",
"$",
"replaceValues",
"=",
"!",
"empty",
"(",
"$",
"cmdArgument",
"[",
"1",
"]",
")",
"?",
"$",
"cmdArgument",
"[",
"1",
"]",
":",
"null",
";",
"if",
"(",
"!",
"$",
"replaceValues",
")",
"{",
"$",
"msg",
"=",
"'Command argument \"--replace\" must contain values, like: --replace=\"{SEARCH}:{REPLACE},..\"'",
";",
"throw",
"new",
"\\",
"ErrorException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"returnArguments",
"[",
"self",
"::",
"REPLACE_ARG",
"]",
"=",
"$",
"this",
"->",
"getReplaceValuesFromArgument",
"(",
"$",
"replaceValues",
")",
";",
"}",
"}",
"return",
"$",
"returnArguments",
";",
"}"
] |
Returns an array containing the command arguments values.
@return array
An array containing the script command arguments.
|
[
"Returns",
"an",
"array",
"containing",
"the",
"command",
"arguments",
"values",
"."
] |
train
|
https://github.com/jkribeiro/composer-hydration/blob/b0dd7e9c4a966f664c2df08b3067c1b6f263e226/src/Composer/ComposerHydrationHandler.php#L195-L227
|
jkribeiro/composer-hydration
|
src/Composer/ComposerHydrationHandler.php
|
ComposerHydrationHandler.hydrateFileContents
|
public function hydrateFileContents($replaceMap)
{
$io = $this->event->getIO();
$finder = new Finder();
$finder->in($this->basePath);
$finder->ignoreDotFiles(false);
$finder->notPath('vendor');
$finder->notName('composer.json');
// Find files.
foreach ($replaceMap as $search => $replace) {
// Restrict files by search.
$finder->contains($search);
}
$count = iterator_count($finder);
if (!$count) {
$io->write("[Hydration][OK] Skipping, no file contents to be replaced.");
return;
}
$io->write("[Hydration][INFO] Hydrating $count file(s).");
foreach ($finder as $file) {
$filePath = $file->getRelativePathname();
// Replace values.
$fileContent = str_replace(array_keys($replaceMap), array_values($replaceMap), $file->getContents());
// Save file with new replaced content.
if (!file_put_contents($filePath, $fileContent)) {
// Failed.
$msg = "Unable to Hydrate the file, check the file permissions and try again: $filePath";
throw new \ErrorException($msg);
}
// Success.
$io->write("[Hydration][OK] File Hydrated: $filePath");
}
}
|
php
|
public function hydrateFileContents($replaceMap)
{
$io = $this->event->getIO();
$finder = new Finder();
$finder->in($this->basePath);
$finder->ignoreDotFiles(false);
$finder->notPath('vendor');
$finder->notName('composer.json');
// Find files.
foreach ($replaceMap as $search => $replace) {
// Restrict files by search.
$finder->contains($search);
}
$count = iterator_count($finder);
if (!$count) {
$io->write("[Hydration][OK] Skipping, no file contents to be replaced.");
return;
}
$io->write("[Hydration][INFO] Hydrating $count file(s).");
foreach ($finder as $file) {
$filePath = $file->getRelativePathname();
// Replace values.
$fileContent = str_replace(array_keys($replaceMap), array_values($replaceMap), $file->getContents());
// Save file with new replaced content.
if (!file_put_contents($filePath, $fileContent)) {
// Failed.
$msg = "Unable to Hydrate the file, check the file permissions and try again: $filePath";
throw new \ErrorException($msg);
}
// Success.
$io->write("[Hydration][OK] File Hydrated: $filePath");
}
}
|
[
"public",
"function",
"hydrateFileContents",
"(",
"$",
"replaceMap",
")",
"{",
"$",
"io",
"=",
"$",
"this",
"->",
"event",
"->",
"getIO",
"(",
")",
";",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"finder",
"->",
"in",
"(",
"$",
"this",
"->",
"basePath",
")",
";",
"$",
"finder",
"->",
"ignoreDotFiles",
"(",
"false",
")",
";",
"$",
"finder",
"->",
"notPath",
"(",
"'vendor'",
")",
";",
"$",
"finder",
"->",
"notName",
"(",
"'composer.json'",
")",
";",
"// Find files.",
"foreach",
"(",
"$",
"replaceMap",
"as",
"$",
"search",
"=>",
"$",
"replace",
")",
"{",
"// Restrict files by search.",
"$",
"finder",
"->",
"contains",
"(",
"$",
"search",
")",
";",
"}",
"$",
"count",
"=",
"iterator_count",
"(",
"$",
"finder",
")",
";",
"if",
"(",
"!",
"$",
"count",
")",
"{",
"$",
"io",
"->",
"write",
"(",
"\"[Hydration][OK] Skipping, no file contents to be replaced.\"",
")",
";",
"return",
";",
"}",
"$",
"io",
"->",
"write",
"(",
"\"[Hydration][INFO] Hydrating $count file(s).\"",
")",
";",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"file",
")",
"{",
"$",
"filePath",
"=",
"$",
"file",
"->",
"getRelativePathname",
"(",
")",
";",
"// Replace values.",
"$",
"fileContent",
"=",
"str_replace",
"(",
"array_keys",
"(",
"$",
"replaceMap",
")",
",",
"array_values",
"(",
"$",
"replaceMap",
")",
",",
"$",
"file",
"->",
"getContents",
"(",
")",
")",
";",
"// Save file with new replaced content.",
"if",
"(",
"!",
"file_put_contents",
"(",
"$",
"filePath",
",",
"$",
"fileContent",
")",
")",
"{",
"// Failed.",
"$",
"msg",
"=",
"\"Unable to Hydrate the file, check the file permissions and try again: $filePath\"",
";",
"throw",
"new",
"\\",
"ErrorException",
"(",
"$",
"msg",
")",
";",
"}",
"// Success.",
"$",
"io",
"->",
"write",
"(",
"\"[Hydration][OK] File Hydrated: $filePath\"",
")",
";",
"}",
"}"
] |
Process hydration to File contents.
@param string $replaceMap
An array containing the replacement map following the format:
[{SEARCH} => {REPLACE},
{SEARCH} => {REPLACE},
...]
|
[
"Process",
"hydration",
"to",
"File",
"contents",
"."
] |
train
|
https://github.com/jkribeiro/composer-hydration/blob/b0dd7e9c4a966f664c2df08b3067c1b6f263e226/src/Composer/ComposerHydrationHandler.php#L238-L279
|
jkribeiro/composer-hydration
|
src/Composer/ComposerHydrationHandler.php
|
ComposerHydrationHandler.hydrateRenameFilesAndFolders
|
public function hydrateRenameFilesAndFolders($replaceMap)
{
$io = $this->event->getIO();
$finder = new Finder();
$finder->in($this->basePath);
$finder->ignoreDotFiles(false);
$finder->exclude('vendor');
foreach ($replaceMap as $search => $replace) {
// Restrict files by search.
$finder->name(".*$search*");
$finder->name("*$search*");
}
$count = iterator_count($finder);
if (!$count) {
$io->write("[Hydration][OK] Skipping, no folders and files to be renamed.");
return;
}
$io->write("[Hydration][INFO] Renaming $count file(s)/folder(s).");
$finder = array_keys(iterator_to_array($finder, true));
foreach ($finder as $currentName) {
$newName = str_replace(array_keys($replaceMap), array_values($replaceMap), $currentName);
// Replace values.
$renamed = rename($currentName, $newName);
if (!$renamed) {
// Failed.
throw new \ErrorException("Unable to rename file/folder: $currentName");
}
// Success.
$io->write("[Hydration][OK] Renamed $currentName ---> $newName");
}
}
|
php
|
public function hydrateRenameFilesAndFolders($replaceMap)
{
$io = $this->event->getIO();
$finder = new Finder();
$finder->in($this->basePath);
$finder->ignoreDotFiles(false);
$finder->exclude('vendor');
foreach ($replaceMap as $search => $replace) {
// Restrict files by search.
$finder->name(".*$search*");
$finder->name("*$search*");
}
$count = iterator_count($finder);
if (!$count) {
$io->write("[Hydration][OK] Skipping, no folders and files to be renamed.");
return;
}
$io->write("[Hydration][INFO] Renaming $count file(s)/folder(s).");
$finder = array_keys(iterator_to_array($finder, true));
foreach ($finder as $currentName) {
$newName = str_replace(array_keys($replaceMap), array_values($replaceMap), $currentName);
// Replace values.
$renamed = rename($currentName, $newName);
if (!$renamed) {
// Failed.
throw new \ErrorException("Unable to rename file/folder: $currentName");
}
// Success.
$io->write("[Hydration][OK] Renamed $currentName ---> $newName");
}
}
|
[
"public",
"function",
"hydrateRenameFilesAndFolders",
"(",
"$",
"replaceMap",
")",
"{",
"$",
"io",
"=",
"$",
"this",
"->",
"event",
"->",
"getIO",
"(",
")",
";",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"finder",
"->",
"in",
"(",
"$",
"this",
"->",
"basePath",
")",
";",
"$",
"finder",
"->",
"ignoreDotFiles",
"(",
"false",
")",
";",
"$",
"finder",
"->",
"exclude",
"(",
"'vendor'",
")",
";",
"foreach",
"(",
"$",
"replaceMap",
"as",
"$",
"search",
"=>",
"$",
"replace",
")",
"{",
"// Restrict files by search.",
"$",
"finder",
"->",
"name",
"(",
"\".*$search*\"",
")",
";",
"$",
"finder",
"->",
"name",
"(",
"\"*$search*\"",
")",
";",
"}",
"$",
"count",
"=",
"iterator_count",
"(",
"$",
"finder",
")",
";",
"if",
"(",
"!",
"$",
"count",
")",
"{",
"$",
"io",
"->",
"write",
"(",
"\"[Hydration][OK] Skipping, no folders and files to be renamed.\"",
")",
";",
"return",
";",
"}",
"$",
"io",
"->",
"write",
"(",
"\"[Hydration][INFO] Renaming $count file(s)/folder(s).\"",
")",
";",
"$",
"finder",
"=",
"array_keys",
"(",
"iterator_to_array",
"(",
"$",
"finder",
",",
"true",
")",
")",
";",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"currentName",
")",
"{",
"$",
"newName",
"=",
"str_replace",
"(",
"array_keys",
"(",
"$",
"replaceMap",
")",
",",
"array_values",
"(",
"$",
"replaceMap",
")",
",",
"$",
"currentName",
")",
";",
"// Replace values.",
"$",
"renamed",
"=",
"rename",
"(",
"$",
"currentName",
",",
"$",
"newName",
")",
";",
"if",
"(",
"!",
"$",
"renamed",
")",
"{",
"// Failed.",
"throw",
"new",
"\\",
"ErrorException",
"(",
"\"Unable to rename file/folder: $currentName\"",
")",
";",
"}",
"// Success.",
"$",
"io",
"->",
"write",
"(",
"\"[Hydration][OK] Renamed $currentName ---> $newName\"",
")",
";",
"}",
"}"
] |
Process hydration renaming files and folders.
@param string $replaceMap
An array containing the replacement map following the format:
[{SEARCH} => {REPLACE},
{SEARCH} => {REPLACE},
...]
|
[
"Process",
"hydration",
"renaming",
"files",
"and",
"folders",
"."
] |
train
|
https://github.com/jkribeiro/composer-hydration/blob/b0dd7e9c4a966f664c2df08b3067c1b6f263e226/src/Composer/ComposerHydrationHandler.php#L290-L328
|
jkribeiro/composer-hydration
|
src/Composer/ComposerHydrationHandler.php
|
ComposerHydrationHandler.hydrate
|
public function hydrate()
{
$arguments = $this->getArguments();
$replaceMap = $arguments[self::REPLACE_ARG];
// Rename Files and Folders.
$this->hydrateRenameFilesAndFolders($replaceMap);
// Hydrate file contents.
$this->hydrateFileContents($replaceMap);
}
|
php
|
public function hydrate()
{
$arguments = $this->getArguments();
$replaceMap = $arguments[self::REPLACE_ARG];
// Rename Files and Folders.
$this->hydrateRenameFilesAndFolders($replaceMap);
// Hydrate file contents.
$this->hydrateFileContents($replaceMap);
}
|
[
"public",
"function",
"hydrate",
"(",
")",
"{",
"$",
"arguments",
"=",
"$",
"this",
"->",
"getArguments",
"(",
")",
";",
"$",
"replaceMap",
"=",
"$",
"arguments",
"[",
"self",
"::",
"REPLACE_ARG",
"]",
";",
"// Rename Files and Folders.",
"$",
"this",
"->",
"hydrateRenameFilesAndFolders",
"(",
"$",
"replaceMap",
")",
";",
"// Hydrate file contents.",
"$",
"this",
"->",
"hydrateFileContents",
"(",
"$",
"replaceMap",
")",
";",
"}"
] |
Performs Hydration process.
|
[
"Performs",
"Hydration",
"process",
"."
] |
train
|
https://github.com/jkribeiro/composer-hydration/blob/b0dd7e9c4a966f664c2df08b3067c1b6f263e226/src/Composer/ComposerHydrationHandler.php#L333-L343
|
acasademont/wurfl
|
WURFL/DeviceRepositoryBuilder.php
|
WURFL_DeviceRepositoryBuilder.build
|
public function build($wurflFile, $wurflPatches = array(), $capabilityFilter = array())
{
if (!$this->isRepositoryBuilt()) {
// If acquireLock() is false, the WURFL is being reloaded in another thread
if ($this->acquireLock()) {
set_time_limit(600);
$infoIterator = new WURFL_Xml_VersionIterator($wurflFile);
$deviceIterator = new WURFL_Xml_DeviceIterator($wurflFile, $capabilityFilter);
$patchIterators = $this->toPatchIterators($wurflPatches, $capabilityFilter);
$this->buildRepository($infoIterator, $deviceIterator, $patchIterators);
$this->verifyRepository();
$this->setRepositoryBuilt();
$this->releaseLock();
}
}
$deviceClassificationNames = $this->deviceClassificationNames();
return new WURFL_CustomDeviceRepository($this->persistenceProvider, $deviceClassificationNames);
}
|
php
|
public function build($wurflFile, $wurflPatches = array(), $capabilityFilter = array())
{
if (!$this->isRepositoryBuilt()) {
// If acquireLock() is false, the WURFL is being reloaded in another thread
if ($this->acquireLock()) {
set_time_limit(600);
$infoIterator = new WURFL_Xml_VersionIterator($wurflFile);
$deviceIterator = new WURFL_Xml_DeviceIterator($wurflFile, $capabilityFilter);
$patchIterators = $this->toPatchIterators($wurflPatches, $capabilityFilter);
$this->buildRepository($infoIterator, $deviceIterator, $patchIterators);
$this->verifyRepository();
$this->setRepositoryBuilt();
$this->releaseLock();
}
}
$deviceClassificationNames = $this->deviceClassificationNames();
return new WURFL_CustomDeviceRepository($this->persistenceProvider, $deviceClassificationNames);
}
|
[
"public",
"function",
"build",
"(",
"$",
"wurflFile",
",",
"$",
"wurflPatches",
"=",
"array",
"(",
")",
",",
"$",
"capabilityFilter",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isRepositoryBuilt",
"(",
")",
")",
"{",
"// If acquireLock() is false, the WURFL is being reloaded in another thread",
"if",
"(",
"$",
"this",
"->",
"acquireLock",
"(",
")",
")",
"{",
"set_time_limit",
"(",
"600",
")",
";",
"$",
"infoIterator",
"=",
"new",
"WURFL_Xml_VersionIterator",
"(",
"$",
"wurflFile",
")",
";",
"$",
"deviceIterator",
"=",
"new",
"WURFL_Xml_DeviceIterator",
"(",
"$",
"wurflFile",
",",
"$",
"capabilityFilter",
")",
";",
"$",
"patchIterators",
"=",
"$",
"this",
"->",
"toPatchIterators",
"(",
"$",
"wurflPatches",
",",
"$",
"capabilityFilter",
")",
";",
"$",
"this",
"->",
"buildRepository",
"(",
"$",
"infoIterator",
",",
"$",
"deviceIterator",
",",
"$",
"patchIterators",
")",
";",
"$",
"this",
"->",
"verifyRepository",
"(",
")",
";",
"$",
"this",
"->",
"setRepositoryBuilt",
"(",
")",
";",
"$",
"this",
"->",
"releaseLock",
"(",
")",
";",
"}",
"}",
"$",
"deviceClassificationNames",
"=",
"$",
"this",
"->",
"deviceClassificationNames",
"(",
")",
";",
"return",
"new",
"WURFL_CustomDeviceRepository",
"(",
"$",
"this",
"->",
"persistenceProvider",
",",
"$",
"deviceClassificationNames",
")",
";",
"}"
] |
Builds DeviceRepository in PersistenceProvider from $wurflFile and $wurflPatches using $capabilityFilter
@param string $wurflFile Filename of wurfl.xml or other complete WURFL file
@param array $wurflPatches Array of WURFL patch files
@param array $capabilityFilter Array of capabilities to be included in the DeviceRepository
@return WURFL_CustomDeviceRepository
|
[
"Builds",
"DeviceRepository",
"in",
"PersistenceProvider",
"from",
"$wurflFile",
"and",
"$wurflPatches",
"using",
"$capabilityFilter"
] |
train
|
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/DeviceRepositoryBuilder.php#L76-L94
|
acasademont/wurfl
|
WURFL/DeviceRepositoryBuilder.php
|
WURFL_DeviceRepositoryBuilder.acquireLock
|
private function acquireLock()
{
if (file_exists($this->lockFile)) {
$stale_after = filemtime($this->lockFile) + $this->maxLockAge;
if (time() > $stale_after) {
// The lockfile is stale, delete it and reacquire a lock
@rmdir($this->lockFile);
} else {
// The lockfile is valid, WURFL is probably being reloaded in another thread
return false;
}
}
// Using mkdir instead of touch since mkdir is atomic
$this->isLocked = @mkdir($this->lockFile, 0775);
return $this->isLocked;
}
|
php
|
private function acquireLock()
{
if (file_exists($this->lockFile)) {
$stale_after = filemtime($this->lockFile) + $this->maxLockAge;
if (time() > $stale_after) {
// The lockfile is stale, delete it and reacquire a lock
@rmdir($this->lockFile);
} else {
// The lockfile is valid, WURFL is probably being reloaded in another thread
return false;
}
}
// Using mkdir instead of touch since mkdir is atomic
$this->isLocked = @mkdir($this->lockFile, 0775);
return $this->isLocked;
}
|
[
"private",
"function",
"acquireLock",
"(",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"lockFile",
")",
")",
"{",
"$",
"stale_after",
"=",
"filemtime",
"(",
"$",
"this",
"->",
"lockFile",
")",
"+",
"$",
"this",
"->",
"maxLockAge",
";",
"if",
"(",
"time",
"(",
")",
">",
"$",
"stale_after",
")",
"{",
"// The lockfile is stale, delete it and reacquire a lock",
"@",
"rmdir",
"(",
"$",
"this",
"->",
"lockFile",
")",
";",
"}",
"else",
"{",
"// The lockfile is valid, WURFL is probably being reloaded in another thread",
"return",
"false",
";",
"}",
"}",
"// Using mkdir instead of touch since mkdir is atomic",
"$",
"this",
"->",
"isLocked",
"=",
"@",
"mkdir",
"(",
"$",
"this",
"->",
"lockFile",
",",
"0775",
")",
";",
"return",
"$",
"this",
"->",
"isLocked",
";",
"}"
] |
Acquires a lock so only this thread reloads the WURFL data, returns false if it cannot be acquired
@return boolean
|
[
"Acquires",
"a",
"lock",
"so",
"only",
"this",
"thread",
"reloads",
"the",
"WURFL",
"data",
"returns",
"false",
"if",
"it",
"cannot",
"be",
"acquired"
] |
train
|
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/DeviceRepositoryBuilder.php#L147-L163
|
acasademont/wurfl
|
WURFL/DeviceRepositoryBuilder.php
|
WURFL_DeviceRepositoryBuilder.buildRepository
|
private function buildRepository($wurflInfoIterator, $deviceIterator, $patchDeviceIterators = null)
{
$this->persistWurflInfo($wurflInfoIterator);
$patchingDevices = $this->toListOfPatchingDevices($patchDeviceIterators);
try {
$this->process($deviceIterator, $patchingDevices);
} catch (Exception $exception) {
$this->clean();
throw new Exception("Problem Building WURFL Repository: " . $exception->getMessage(), 0, $exception);
}
}
|
php
|
private function buildRepository($wurflInfoIterator, $deviceIterator, $patchDeviceIterators = null)
{
$this->persistWurflInfo($wurflInfoIterator);
$patchingDevices = $this->toListOfPatchingDevices($patchDeviceIterators);
try {
$this->process($deviceIterator, $patchingDevices);
} catch (Exception $exception) {
$this->clean();
throw new Exception("Problem Building WURFL Repository: " . $exception->getMessage(), 0, $exception);
}
}
|
[
"private",
"function",
"buildRepository",
"(",
"$",
"wurflInfoIterator",
",",
"$",
"deviceIterator",
",",
"$",
"patchDeviceIterators",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"persistWurflInfo",
"(",
"$",
"wurflInfoIterator",
")",
";",
"$",
"patchingDevices",
"=",
"$",
"this",
"->",
"toListOfPatchingDevices",
"(",
"$",
"patchDeviceIterators",
")",
";",
"try",
"{",
"$",
"this",
"->",
"process",
"(",
"$",
"deviceIterator",
",",
"$",
"patchingDevices",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"clean",
"(",
")",
";",
"throw",
"new",
"Exception",
"(",
"\"Problem Building WURFL Repository: \"",
".",
"$",
"exception",
"->",
"getMessage",
"(",
")",
",",
"0",
",",
"$",
"exception",
")",
";",
"}",
"}"
] |
Iterates over XML files and pulls relevent data
@param WURFL_Xml_VersionIterator $wurflInfoIterator
@param WURFL_Xml_DeviceIterator $deviceIterator
@param array $patchDeviceIterators arrray of WURFL_Xml_DeviceIterator objects for patch files
@throws Exception
|
[
"Iterates",
"over",
"XML",
"files",
"and",
"pulls",
"relevent",
"data"
] |
train
|
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/DeviceRepositoryBuilder.php#L185-L195
|
acasademont/wurfl
|
WURFL/DeviceRepositoryBuilder.php
|
WURFL_DeviceRepositoryBuilder.toPatchIterators
|
private function toPatchIterators($wurflPatches, $capabilityFilter)
{
$patchIterators = array();
if (is_array($wurflPatches)) {
foreach ($wurflPatches as $wurflPatch) {
$patchIterators[] = new WURFL_Xml_DeviceIterator($wurflPatch, $capabilityFilter);
}
}
return $patchIterators;
}
|
php
|
private function toPatchIterators($wurflPatches, $capabilityFilter)
{
$patchIterators = array();
if (is_array($wurflPatches)) {
foreach ($wurflPatches as $wurflPatch) {
$patchIterators[] = new WURFL_Xml_DeviceIterator($wurflPatch, $capabilityFilter);
}
}
return $patchIterators;
}
|
[
"private",
"function",
"toPatchIterators",
"(",
"$",
"wurflPatches",
",",
"$",
"capabilityFilter",
")",
"{",
"$",
"patchIterators",
"=",
"array",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"wurflPatches",
")",
")",
"{",
"foreach",
"(",
"$",
"wurflPatches",
"as",
"$",
"wurflPatch",
")",
"{",
"$",
"patchIterators",
"[",
"]",
"=",
"new",
"WURFL_Xml_DeviceIterator",
"(",
"$",
"wurflPatch",
",",
"$",
"capabilityFilter",
")",
";",
"}",
"}",
"return",
"$",
"patchIterators",
";",
"}"
] |
Returns an array of WURFL_Xml_DeviceIterator for the given $wurflPatches and $capabilityFilter
@param array $wurflPatches Array of (string)filenames
@param array $capabilityFilter Array of (string) WURFL capabilities
@return array Array of WURFL_Xml_DeviceIterator objects
|
[
"Returns",
"an",
"array",
"of",
"WURFL_Xml_DeviceIterator",
"for",
"the",
"given",
"$wurflPatches",
"and",
"$capabilityFilter"
] |
train
|
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/DeviceRepositoryBuilder.php#L203-L212
|
acasademont/wurfl
|
WURFL/DeviceRepositoryBuilder.php
|
WURFL_DeviceRepositoryBuilder.persistWurflInfo
|
private function persistWurflInfo($wurflInfoIterator)
{
foreach ($wurflInfoIterator as $info) {
$this->persistenceProvider->save(WURFL_Xml_Info::PERSISTENCE_KEY, $info);
return;
}
}
|
php
|
private function persistWurflInfo($wurflInfoIterator)
{
foreach ($wurflInfoIterator as $info) {
$this->persistenceProvider->save(WURFL_Xml_Info::PERSISTENCE_KEY, $info);
return;
}
}
|
[
"private",
"function",
"persistWurflInfo",
"(",
"$",
"wurflInfoIterator",
")",
"{",
"foreach",
"(",
"$",
"wurflInfoIterator",
"as",
"$",
"info",
")",
"{",
"$",
"this",
"->",
"persistenceProvider",
"->",
"save",
"(",
"WURFL_Xml_Info",
"::",
"PERSISTENCE_KEY",
",",
"$",
"info",
")",
";",
"return",
";",
"}",
"}"
] |
Save Loaded WURFL info in the persistence provider
@param WURFL_Xml_VersionIterator $wurflInfoIterator
|
[
"Save",
"Loaded",
"WURFL",
"info",
"in",
"the",
"persistence",
"provider"
] |
train
|
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/DeviceRepositoryBuilder.php#L257-L263
|
acasademont/wurfl
|
WURFL/DeviceRepositoryBuilder.php
|
WURFL_DeviceRepositoryBuilder.classifyAndPersistDevice
|
private function classifyAndPersistDevice($device)
{
if ($this->validateDevice($device) === false) {
return;
}
array_push($this->devices, $device->id);
if ($device->fallBack != 'root') {
$this->fallbacks[$device->fallBack]= $device->id;
}
$this->userAgentHandlerChain->filter($device->userAgent, $device->id);
$this->persistenceProvider->save($device->id, $device);
}
|
php
|
private function classifyAndPersistDevice($device)
{
if ($this->validateDevice($device) === false) {
return;
}
array_push($this->devices, $device->id);
if ($device->fallBack != 'root') {
$this->fallbacks[$device->fallBack]= $device->id;
}
$this->userAgentHandlerChain->filter($device->userAgent, $device->id);
$this->persistenceProvider->save($device->id, $device);
}
|
[
"private",
"function",
"classifyAndPersistDevice",
"(",
"$",
"device",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"validateDevice",
"(",
"$",
"device",
")",
"===",
"false",
")",
"{",
"return",
";",
"}",
"array_push",
"(",
"$",
"this",
"->",
"devices",
",",
"$",
"device",
"->",
"id",
")",
";",
"if",
"(",
"$",
"device",
"->",
"fallBack",
"!=",
"'root'",
")",
"{",
"$",
"this",
"->",
"fallbacks",
"[",
"$",
"device",
"->",
"fallBack",
"]",
"=",
"$",
"device",
"->",
"id",
";",
"}",
"$",
"this",
"->",
"userAgentHandlerChain",
"->",
"filter",
"(",
"$",
"device",
"->",
"userAgent",
",",
"$",
"device",
"->",
"id",
")",
";",
"$",
"this",
"->",
"persistenceProvider",
"->",
"save",
"(",
"$",
"device",
"->",
"id",
",",
"$",
"device",
")",
";",
"}"
] |
Save given $device in the persistence provider. This is called when loading the WURFL XML
data, directly after reading the complete device node.
@param WURFL_Xml_ModelDevice $device
@see WURFL_UserAgentHandlerChain::filter(), WURFL_Storage_Base::save()
|
[
"Save",
"given",
"$device",
"in",
"the",
"persistence",
"provider",
".",
"This",
"is",
"called",
"when",
"loading",
"the",
"WURFL",
"XML",
"data",
"directly",
"after",
"reading",
"the",
"complete",
"device",
"node",
"."
] |
train
|
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/DeviceRepositoryBuilder.php#L320-L333
|
marmelab/phpcr-api
|
src/PHPCRAPI/PHPCR/Node.php
|
Node.getReducedTree
|
public function getReducedTree()
{
$parseTree = function (Node $node, Node $target) use ( &$parseTree ) {
if (substr($target->getPath(),0, strlen($node->getPath())) != $node->getPath()) {
return array();
}
$tree = array();
foreach ($node->getNodes() as $child) {
$tree[] = array(
'name' => $child->getName(),
'path' => $child->getPath(),
'hasChildren' => $child->hasNodes(),
'children' => $parseTree($child, $target)
);
}
return $tree;
};
$treeFactory = function($parent, $node) use ($parseTree) {
return [ '/' => [
'name' => '/',
'path' => '/',
'hasChildren' => $parent->hasNodes(),
'children' => $parseTree($parent, $node)
]];
};
if ($this->getPath() == '/') {
return $treeFactory($this, $this);
}
$parent = $this;
do {
$parent = $parent->getParent();
} while ($parent->getPath() != '/');
return $treeFactory($parent, $this);
}
|
php
|
public function getReducedTree()
{
$parseTree = function (Node $node, Node $target) use ( &$parseTree ) {
if (substr($target->getPath(),0, strlen($node->getPath())) != $node->getPath()) {
return array();
}
$tree = array();
foreach ($node->getNodes() as $child) {
$tree[] = array(
'name' => $child->getName(),
'path' => $child->getPath(),
'hasChildren' => $child->hasNodes(),
'children' => $parseTree($child, $target)
);
}
return $tree;
};
$treeFactory = function($parent, $node) use ($parseTree) {
return [ '/' => [
'name' => '/',
'path' => '/',
'hasChildren' => $parent->hasNodes(),
'children' => $parseTree($parent, $node)
]];
};
if ($this->getPath() == '/') {
return $treeFactory($this, $this);
}
$parent = $this;
do {
$parent = $parent->getParent();
} while ($parent->getPath() != '/');
return $treeFactory($parent, $this);
}
|
[
"public",
"function",
"getReducedTree",
"(",
")",
"{",
"$",
"parseTree",
"=",
"function",
"(",
"Node",
"$",
"node",
",",
"Node",
"$",
"target",
")",
"use",
"(",
"&",
"$",
"parseTree",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"target",
"->",
"getPath",
"(",
")",
",",
"0",
",",
"strlen",
"(",
"$",
"node",
"->",
"getPath",
"(",
")",
")",
")",
"!=",
"$",
"node",
"->",
"getPath",
"(",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"tree",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"node",
"->",
"getNodes",
"(",
")",
"as",
"$",
"child",
")",
"{",
"$",
"tree",
"[",
"]",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"child",
"->",
"getName",
"(",
")",
",",
"'path'",
"=>",
"$",
"child",
"->",
"getPath",
"(",
")",
",",
"'hasChildren'",
"=>",
"$",
"child",
"->",
"hasNodes",
"(",
")",
",",
"'children'",
"=>",
"$",
"parseTree",
"(",
"$",
"child",
",",
"$",
"target",
")",
")",
";",
"}",
"return",
"$",
"tree",
";",
"}",
";",
"$",
"treeFactory",
"=",
"function",
"(",
"$",
"parent",
",",
"$",
"node",
")",
"use",
"(",
"$",
"parseTree",
")",
"{",
"return",
"[",
"'/'",
"=>",
"[",
"'name'",
"=>",
"'/'",
",",
"'path'",
"=>",
"'/'",
",",
"'hasChildren'",
"=>",
"$",
"parent",
"->",
"hasNodes",
"(",
")",
",",
"'children'",
"=>",
"$",
"parseTree",
"(",
"$",
"parent",
",",
"$",
"node",
")",
"]",
"]",
";",
"}",
";",
"if",
"(",
"$",
"this",
"->",
"getPath",
"(",
")",
"==",
"'/'",
")",
"{",
"return",
"$",
"treeFactory",
"(",
"$",
"this",
",",
"$",
"this",
")",
";",
"}",
"$",
"parent",
"=",
"$",
"this",
";",
"do",
"{",
"$",
"parent",
"=",
"$",
"parent",
"->",
"getParent",
"(",
")",
";",
"}",
"while",
"(",
"$",
"parent",
"->",
"getPath",
"(",
")",
"!=",
"'/'",
")",
";",
"return",
"$",
"treeFactory",
"(",
"$",
"parent",
",",
"$",
"this",
")",
";",
"}"
] |
Return a the minimum tree to display for a node
@return array The tree
@api
|
[
"Return",
"a",
"the",
"minimum",
"tree",
"to",
"display",
"for",
"a",
"node"
] |
train
|
https://github.com/marmelab/phpcr-api/blob/372149e27d45babe142d0546894362fce987729b/src/PHPCRAPI/PHPCR/Node.php#L88-L127
|
marmelab/phpcr-api
|
src/PHPCRAPI/PHPCR/Node.php
|
Node.getPropertiesAsArray
|
public function getPropertiesAsArray()
{
$array = array();
foreach ($this->getProperties() as $property) {
$array[$property->getName()] = [ 'value' => $property->getValue(), 'type' => $property->getType() ];
}
return $array;
}
|
php
|
public function getPropertiesAsArray()
{
$array = array();
foreach ($this->getProperties() as $property) {
$array[$property->getName()] = [ 'value' => $property->getValue(), 'type' => $property->getType() ];
}
return $array;
}
|
[
"public",
"function",
"getPropertiesAsArray",
"(",
")",
"{",
"$",
"array",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getProperties",
"(",
")",
"as",
"$",
"property",
")",
"{",
"$",
"array",
"[",
"$",
"property",
"->",
"getName",
"(",
")",
"]",
"=",
"[",
"'value'",
"=>",
"$",
"property",
"->",
"getValue",
"(",
")",
",",
"'type'",
"=>",
"$",
"property",
"->",
"getType",
"(",
")",
"]",
";",
"}",
"return",
"$",
"array",
";",
"}"
] |
Convert node's properties to array
@return array Properties
@api
|
[
"Convert",
"node",
"s",
"properties",
"to",
"array"
] |
train
|
https://github.com/marmelab/phpcr-api/blob/372149e27d45babe142d0546894362fce987729b/src/PHPCRAPI/PHPCR/Node.php#L136-L145
|
jan-dolata/crude-crud
|
src/Engine/CrudeSetupTrait/Filters.php
|
Filters.setFilters
|
public function setFilters($filters)
{
if (! is_array($filters))
$filters = [$filters];
$this->filters = array_unique(array_merge($this->filters, $filters));
return $this;
}
|
php
|
public function setFilters($filters)
{
if (! is_array($filters))
$filters = [$filters];
$this->filters = array_unique(array_merge($this->filters, $filters));
return $this;
}
|
[
"public",
"function",
"setFilters",
"(",
"$",
"filters",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"filters",
")",
")",
"$",
"filters",
"=",
"[",
"$",
"filters",
"]",
";",
"$",
"this",
"->",
"filters",
"=",
"array_unique",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"filters",
",",
"$",
"filters",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets the Filters.
@param array|sting $filters the filters
@return self
|
[
"Sets",
"the",
"Filters",
"."
] |
train
|
https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/CrudeSetupTrait/Filters.php#L33-L41
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.