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
|
---|---|---|---|---|---|---|---|---|---|---|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Base/Role.php
|
Role.removePermission
|
public function removePermission(ChildPermission $permission)
{
if ($this->getPermissions()->contains($permission)) { $rolePermission = new ChildRolePermission();
$rolePermission->setPermission($permission);
if ($permission->isRolesLoaded()) {
//remove the back reference if available
$permission->getRoles()->removeObject($this);
}
$rolePermission->setRole($this);
$this->removeRolePermission(clone $rolePermission);
$rolePermission->clear();
$this->collPermissions->remove($this->collPermissions->search($permission));
if (null === $this->permissionsScheduledForDeletion) {
$this->permissionsScheduledForDeletion = clone $this->collPermissions;
$this->permissionsScheduledForDeletion->clear();
}
$this->permissionsScheduledForDeletion->push($permission);
}
return $this;
}
|
php
|
public function removePermission(ChildPermission $permission)
{
if ($this->getPermissions()->contains($permission)) { $rolePermission = new ChildRolePermission();
$rolePermission->setPermission($permission);
if ($permission->isRolesLoaded()) {
//remove the back reference if available
$permission->getRoles()->removeObject($this);
}
$rolePermission->setRole($this);
$this->removeRolePermission(clone $rolePermission);
$rolePermission->clear();
$this->collPermissions->remove($this->collPermissions->search($permission));
if (null === $this->permissionsScheduledForDeletion) {
$this->permissionsScheduledForDeletion = clone $this->collPermissions;
$this->permissionsScheduledForDeletion->clear();
}
$this->permissionsScheduledForDeletion->push($permission);
}
return $this;
}
|
[
"public",
"function",
"removePermission",
"(",
"ChildPermission",
"$",
"permission",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getPermissions",
"(",
")",
"->",
"contains",
"(",
"$",
"permission",
")",
")",
"{",
"$",
"rolePermission",
"=",
"new",
"ChildRolePermission",
"(",
")",
";",
"$",
"rolePermission",
"->",
"setPermission",
"(",
"$",
"permission",
")",
";",
"if",
"(",
"$",
"permission",
"->",
"isRolesLoaded",
"(",
")",
")",
"{",
"//remove the back reference if available",
"$",
"permission",
"->",
"getRoles",
"(",
")",
"->",
"removeObject",
"(",
"$",
"this",
")",
";",
"}",
"$",
"rolePermission",
"->",
"setRole",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"removeRolePermission",
"(",
"clone",
"$",
"rolePermission",
")",
";",
"$",
"rolePermission",
"->",
"clear",
"(",
")",
";",
"$",
"this",
"->",
"collPermissions",
"->",
"remove",
"(",
"$",
"this",
"->",
"collPermissions",
"->",
"search",
"(",
"$",
"permission",
")",
")",
";",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"permissionsScheduledForDeletion",
")",
"{",
"$",
"this",
"->",
"permissionsScheduledForDeletion",
"=",
"clone",
"$",
"this",
"->",
"collPermissions",
";",
"$",
"this",
"->",
"permissionsScheduledForDeletion",
"->",
"clear",
"(",
")",
";",
"}",
"$",
"this",
"->",
"permissionsScheduledForDeletion",
"->",
"push",
"(",
"$",
"permission",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Remove permission of this object
through the role_permission cross reference table.
@param ChildPermission $permission
@return ChildRole The current object (for fluent API support)
|
[
"Remove",
"permission",
"of",
"this",
"object",
"through",
"the",
"role_permission",
"cross",
"reference",
"table",
"."
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Role.php#L2394-L2420
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Base/Role.php
|
Role.clearAllReferences
|
public function clearAllReferences($deep = false)
{
if ($deep) {
if ($this->collUserRoles) {
foreach ($this->collUserRoles as $o) {
$o->clearAllReferences($deep);
}
}
if ($this->collRolePermissions) {
foreach ($this->collRolePermissions as $o) {
$o->clearAllReferences($deep);
}
}
if ($this->collUsers) {
foreach ($this->collUsers as $o) {
$o->clearAllReferences($deep);
}
}
if ($this->collPermissions) {
foreach ($this->collPermissions as $o) {
$o->clearAllReferences($deep);
}
}
} // if ($deep)
$this->collUserRoles = null;
$this->collRolePermissions = null;
$this->collUsers = null;
$this->collPermissions = null;
}
|
php
|
public function clearAllReferences($deep = false)
{
if ($deep) {
if ($this->collUserRoles) {
foreach ($this->collUserRoles as $o) {
$o->clearAllReferences($deep);
}
}
if ($this->collRolePermissions) {
foreach ($this->collRolePermissions as $o) {
$o->clearAllReferences($deep);
}
}
if ($this->collUsers) {
foreach ($this->collUsers as $o) {
$o->clearAllReferences($deep);
}
}
if ($this->collPermissions) {
foreach ($this->collPermissions as $o) {
$o->clearAllReferences($deep);
}
}
} // if ($deep)
$this->collUserRoles = null;
$this->collRolePermissions = null;
$this->collUsers = null;
$this->collPermissions = null;
}
|
[
"public",
"function",
"clearAllReferences",
"(",
"$",
"deep",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"deep",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"collUserRoles",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"collUserRoles",
"as",
"$",
"o",
")",
"{",
"$",
"o",
"->",
"clearAllReferences",
"(",
"$",
"deep",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"collRolePermissions",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"collRolePermissions",
"as",
"$",
"o",
")",
"{",
"$",
"o",
"->",
"clearAllReferences",
"(",
"$",
"deep",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"collUsers",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"collUsers",
"as",
"$",
"o",
")",
"{",
"$",
"o",
"->",
"clearAllReferences",
"(",
"$",
"deep",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"collPermissions",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"collPermissions",
"as",
"$",
"o",
")",
"{",
"$",
"o",
"->",
"clearAllReferences",
"(",
"$",
"deep",
")",
";",
"}",
"}",
"}",
"// if ($deep)",
"$",
"this",
"->",
"collUserRoles",
"=",
"null",
";",
"$",
"this",
"->",
"collRolePermissions",
"=",
"null",
";",
"$",
"this",
"->",
"collUsers",
"=",
"null",
";",
"$",
"this",
"->",
"collPermissions",
"=",
"null",
";",
"}"
] |
Resets all references and back-references to other model objects or collections of model objects.
This method is used to reset all php object references (not the actual reference in the database).
Necessary for object serialisation.
@param boolean $deep Whether to also clear the references on all referrer objects.
|
[
"Resets",
"all",
"references",
"and",
"back",
"-",
"references",
"to",
"other",
"model",
"objects",
"or",
"collections",
"of",
"model",
"objects",
"."
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Role.php#L2451-L2480
|
fuelphp/display
|
src/Parser/MustacheLoader.php
|
MustacheLoader.findView
|
public function findView($name)
{
if (substr($name, -9) !== '.mustache')
{
$name .= '.mustache';
}
if ( ! $file = parent::findView($name))
{
throw new Mustache_Exception_UnknownTemplateException('Could not locate: '.$name);
}
return $file;
}
|
php
|
public function findView($name)
{
if (substr($name, -9) !== '.mustache')
{
$name .= '.mustache';
}
if ( ! $file = parent::findView($name))
{
throw new Mustache_Exception_UnknownTemplateException('Could not locate: '.$name);
}
return $file;
}
|
[
"public",
"function",
"findView",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"name",
",",
"-",
"9",
")",
"!==",
"'.mustache'",
")",
"{",
"$",
"name",
".=",
"'.mustache'",
";",
"}",
"if",
"(",
"!",
"$",
"file",
"=",
"parent",
"::",
"findView",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"Mustache_Exception_UnknownTemplateException",
"(",
"'Could not locate: '",
".",
"$",
"name",
")",
";",
"}",
"return",
"$",
"file",
";",
"}"
] |
{@inheritdoc}
@throws Mustache_Exception_UnknownTemplateException If the template is not found
|
[
"{",
"@inheritdoc",
"}"
] |
train
|
https://github.com/fuelphp/display/blob/d9a3eddbf80f0fd81beb40d9f4507600ac6611a4/src/Parser/MustacheLoader.php#L27-L40
|
nealerickson/laravel-azure-blob-storage
|
src/Heedworks/LaravelAzureBlobStorage/LaravelAzureBlobStorageServiceProvider.php
|
LaravelAzureBlobStorageServiceProvider.register
|
public function register()
{
$this->app['blob-storage'] = $this->app->share(function($app)
{
return new BlobClient(
Config::get('laravel-azure-blob-storage::accountUrl'),
Config::get('laravel-azure-blob-storage::accountName'),
Config::get('laravel-azure-blob-storage::accountKey')
);
});
}
|
php
|
public function register()
{
$this->app['blob-storage'] = $this->app->share(function($app)
{
return new BlobClient(
Config::get('laravel-azure-blob-storage::accountUrl'),
Config::get('laravel-azure-blob-storage::accountName'),
Config::get('laravel-azure-blob-storage::accountKey')
);
});
}
|
[
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"[",
"'blob-storage'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"share",
"(",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"BlobClient",
"(",
"Config",
"::",
"get",
"(",
"'laravel-azure-blob-storage::accountUrl'",
")",
",",
"Config",
"::",
"get",
"(",
"'laravel-azure-blob-storage::accountName'",
")",
",",
"Config",
"::",
"get",
"(",
"'laravel-azure-blob-storage::accountKey'",
")",
")",
";",
"}",
")",
";",
"}"
] |
Register the service provider.
@return void
|
[
"Register",
"the",
"service",
"provider",
"."
] |
train
|
https://github.com/nealerickson/laravel-azure-blob-storage/blob/e1d9e1acf0bd26fb6d273eb6b364df162c5fbd53/src/Heedworks/LaravelAzureBlobStorage/LaravelAzureBlobStorageServiceProvider.php#L31-L41
|
Coercive/Xss
|
XssUrl.php
|
XssUrl.detect
|
private function detect()
{
# Init
$this->xss = false;
# No data
if(!$this->string) { return; }
# Detect
foreach ($this->list as $item) {
if(preg_match("`$item`i", $this->string)) {
$this->xss = true;
}
}
}
|
php
|
private function detect()
{
# Init
$this->xss = false;
# No data
if(!$this->string) { return; }
# Detect
foreach ($this->list as $item) {
if(preg_match("`$item`i", $this->string)) {
$this->xss = true;
}
}
}
|
[
"private",
"function",
"detect",
"(",
")",
"{",
"# Init",
"$",
"this",
"->",
"xss",
"=",
"false",
";",
"# No data",
"if",
"(",
"!",
"$",
"this",
"->",
"string",
")",
"{",
"return",
";",
"}",
"# Detect",
"foreach",
"(",
"$",
"this",
"->",
"list",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"preg_match",
"(",
"\"`$item`i\"",
",",
"$",
"this",
"->",
"string",
")",
")",
"{",
"$",
"this",
"->",
"xss",
"=",
"true",
";",
"}",
"}",
"}"
] |
DETECT XSS URL ATTACK
@return void
|
[
"DETECT",
"XSS",
"URL",
"ATTACK"
] |
train
|
https://github.com/Coercive/Xss/blob/d47a05347550f7e2c846d7015483a7e91e5a5138/XssUrl.php#L94-L108
|
avoo/SerializerTranslation
|
Expression/ExpressionEvaluator.php
|
ExpressionEvaluator.registerFunction
|
public function registerFunction(ExpressionFunctionInterface $function)
{
$this->expressionLanguage->register(
$function->getName(),
$function->getCompiler(),
$function->getEvaluator()
);
foreach ($function->getContextVariables() as $name => $value) {
$this->setContextVariable($name, $value);
}
return $this;
}
|
php
|
public function registerFunction(ExpressionFunctionInterface $function)
{
$this->expressionLanguage->register(
$function->getName(),
$function->getCompiler(),
$function->getEvaluator()
);
foreach ($function->getContextVariables() as $name => $value) {
$this->setContextVariable($name, $value);
}
return $this;
}
|
[
"public",
"function",
"registerFunction",
"(",
"ExpressionFunctionInterface",
"$",
"function",
")",
"{",
"$",
"this",
"->",
"expressionLanguage",
"->",
"register",
"(",
"$",
"function",
"->",
"getName",
"(",
")",
",",
"$",
"function",
"->",
"getCompiler",
"(",
")",
",",
"$",
"function",
"->",
"getEvaluator",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"function",
"->",
"getContextVariables",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setContextVariable",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Register a new new ExpressionLanguage function.
@param ExpressionFunctionInterface $function
@return ExpressionEvaluator
|
[
"Register",
"a",
"new",
"new",
"ExpressionLanguage",
"function",
"."
] |
train
|
https://github.com/avoo/SerializerTranslation/blob/e66de5482adb944197a36874465ef144b293a157/Expression/ExpressionEvaluator.php#L84-L97
|
letyii/yii2-jstree
|
JsTree.php
|
JsTree.run
|
public function run()
{
$clientOptions = $this->getClientOptions();
$clientOptions = empty($clientOptions) ? '' : Json::encode($clientOptions);
$view = $this->getView();
$view->registerJs("
jQuery('#" . $this->options['id'] . "')
.on('loaded.jstree', function() { jQuery(this).jstree('select_node', jQuery('#" . $this->options['id'] . "').val().split(','), true); })
.on('changed.jstree', function(e, data) { jQuery('#" . $this->options['id'] . "').val(data.selected.join()); })
.jstree($clientOptions);
");
echo Html::tag('div', '', $this->options);
}
|
php
|
public function run()
{
$clientOptions = $this->getClientOptions();
$clientOptions = empty($clientOptions) ? '' : Json::encode($clientOptions);
$view = $this->getView();
$view->registerJs("
jQuery('#" . $this->options['id'] . "')
.on('loaded.jstree', function() { jQuery(this).jstree('select_node', jQuery('#" . $this->options['id'] . "').val().split(','), true); })
.on('changed.jstree', function(e, data) { jQuery('#" . $this->options['id'] . "').val(data.selected.join()); })
.jstree($clientOptions);
");
echo Html::tag('div', '', $this->options);
}
|
[
"public",
"function",
"run",
"(",
")",
"{",
"$",
"clientOptions",
"=",
"$",
"this",
"->",
"getClientOptions",
"(",
")",
";",
"$",
"clientOptions",
"=",
"empty",
"(",
"$",
"clientOptions",
")",
"?",
"''",
":",
"Json",
"::",
"encode",
"(",
"$",
"clientOptions",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"getView",
"(",
")",
";",
"$",
"view",
"->",
"registerJs",
"(",
"\"\n jQuery('#\"",
".",
"$",
"this",
"->",
"options",
"[",
"'id'",
"]",
".",
"\"')\n .on('loaded.jstree', function() { jQuery(this).jstree('select_node', jQuery('#\"",
".",
"$",
"this",
"->",
"options",
"[",
"'id'",
"]",
".",
"\"').val().split(','), true); })\n .on('changed.jstree', function(e, data) { jQuery('#\"",
".",
"$",
"this",
"->",
"options",
"[",
"'id'",
"]",
".",
"\"').val(data.selected.join()); })\n .jstree($clientOptions);\n \"",
")",
";",
"echo",
"Html",
"::",
"tag",
"(",
"'div'",
",",
"''",
",",
"$",
"this",
"->",
"options",
")",
";",
"}"
] |
Renders the widget.
|
[
"Renders",
"the",
"widget",
"."
] |
train
|
https://github.com/letyii/yii2-jstree/blob/33bcce6e0109994a86c8ae236cbb9084ee360c45/JsTree.php#L48-L60
|
letyii/yii2-jstree
|
JsTree.php
|
JsTree.getClientOptions
|
protected function getClientOptions()
{
$options = $this->clientOptions;
if ($this->items !== null)
$options['core']['data'] = $this->items;
$options['core']['check_callback'] = isset($options['core']['check_callback']) ? $options['core']['check_callback'] : true;
return $options;
}
|
php
|
protected function getClientOptions()
{
$options = $this->clientOptions;
if ($this->items !== null)
$options['core']['data'] = $this->items;
$options['core']['check_callback'] = isset($options['core']['check_callback']) ? $options['core']['check_callback'] : true;
return $options;
}
|
[
"protected",
"function",
"getClientOptions",
"(",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"clientOptions",
";",
"if",
"(",
"$",
"this",
"->",
"items",
"!==",
"null",
")",
"$",
"options",
"[",
"'core'",
"]",
"[",
"'data'",
"]",
"=",
"$",
"this",
"->",
"items",
";",
"$",
"options",
"[",
"'core'",
"]",
"[",
"'check_callback'",
"]",
"=",
"isset",
"(",
"$",
"options",
"[",
"'core'",
"]",
"[",
"'check_callback'",
"]",
")",
"?",
"$",
"options",
"[",
"'core'",
"]",
"[",
"'check_callback'",
"]",
":",
"true",
";",
"return",
"$",
"options",
";",
"}"
] |
Returns the options for jstree
@return array
|
[
"Returns",
"the",
"options",
"for",
"jstree"
] |
train
|
https://github.com/letyii/yii2-jstree/blob/33bcce6e0109994a86c8ae236cbb9084ee360c45/JsTree.php#L66-L76
|
datasift/datasift-php
|
examples/football.php
|
EventHandler.onInteraction
|
public function onInteraction($consumer, $interaction, $hash)
{
echo 'Type: '.$interaction['interaction']['type']."\n";
echo 'Content: '.$interaction['interaction']['content']."\n--\n";
// Stop after 10
if ($this->_num-- == 1) {
echo "Stopping consumer...\n";
$consumer->stop();
}
}
|
php
|
public function onInteraction($consumer, $interaction, $hash)
{
echo 'Type: '.$interaction['interaction']['type']."\n";
echo 'Content: '.$interaction['interaction']['content']."\n--\n";
// Stop after 10
if ($this->_num-- == 1) {
echo "Stopping consumer...\n";
$consumer->stop();
}
}
|
[
"public",
"function",
"onInteraction",
"(",
"$",
"consumer",
",",
"$",
"interaction",
",",
"$",
"hash",
")",
"{",
"echo",
"'Type: '",
".",
"$",
"interaction",
"[",
"'interaction'",
"]",
"[",
"'type'",
"]",
".",
"\"\\n\"",
";",
"echo",
"'Content: '",
".",
"$",
"interaction",
"[",
"'interaction'",
"]",
"[",
"'content'",
"]",
".",
"\"\\n--\\n\"",
";",
"// Stop after 10",
"if",
"(",
"$",
"this",
"->",
"_num",
"--",
"==",
"1",
")",
"{",
"echo",
"\"Stopping consumer...\\n\"",
";",
"$",
"consumer",
"->",
"stop",
"(",
")",
";",
"}",
"}"
] |
Called for each interaction consumed.
@param DataSift_StreamConsumer $consumer The consumer sending the
event.
@param array $interaction The interaction data.
@param string $hash The hash of the stream that
matched this interaction.
@return void
|
[
"Called",
"for",
"each",
"interaction",
"consumed",
"."
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/examples/football.php#L70-L80
|
sulu/SuluSalesShippingBundle
|
src/Sulu/Bundle/Sales/OrderBundle/Controller/PdfController.php
|
PdfController.orderConfirmationAction
|
public function orderConfirmationAction(Request $request, $id)
{
$locale = $this->getLocale($request);
$this->get('translator')->setLocale($locale);
try {
$orderApiEntity = $this->getOrderManager()->findByIdAndLocale($id, $locale);
$order = $orderApiEntity->getEntity();
} catch (OrderNotFoundException $exc) {
throw new OrderNotFoundException($id);
}
$pdf = $this->getPdfManager()->createOrderConfirmation($orderApiEntity);
$pdfName = $this->getPdfManager()->getPdfName($order);
return new Response(
$pdf,
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="' . $pdfName . '"'
)
);
}
|
php
|
public function orderConfirmationAction(Request $request, $id)
{
$locale = $this->getLocale($request);
$this->get('translator')->setLocale($locale);
try {
$orderApiEntity = $this->getOrderManager()->findByIdAndLocale($id, $locale);
$order = $orderApiEntity->getEntity();
} catch (OrderNotFoundException $exc) {
throw new OrderNotFoundException($id);
}
$pdf = $this->getPdfManager()->createOrderConfirmation($orderApiEntity);
$pdfName = $this->getPdfManager()->getPdfName($order);
return new Response(
$pdf,
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="' . $pdfName . '"'
)
);
}
|
[
"public",
"function",
"orderConfirmationAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"getLocale",
"(",
"$",
"request",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"setLocale",
"(",
"$",
"locale",
")",
";",
"try",
"{",
"$",
"orderApiEntity",
"=",
"$",
"this",
"->",
"getOrderManager",
"(",
")",
"->",
"findByIdAndLocale",
"(",
"$",
"id",
",",
"$",
"locale",
")",
";",
"$",
"order",
"=",
"$",
"orderApiEntity",
"->",
"getEntity",
"(",
")",
";",
"}",
"catch",
"(",
"OrderNotFoundException",
"$",
"exc",
")",
"{",
"throw",
"new",
"OrderNotFoundException",
"(",
"$",
"id",
")",
";",
"}",
"$",
"pdf",
"=",
"$",
"this",
"->",
"getPdfManager",
"(",
")",
"->",
"createOrderConfirmation",
"(",
"$",
"orderApiEntity",
")",
";",
"$",
"pdfName",
"=",
"$",
"this",
"->",
"getPdfManager",
"(",
")",
"->",
"getPdfName",
"(",
"$",
"order",
")",
";",
"return",
"new",
"Response",
"(",
"$",
"pdf",
",",
"200",
",",
"array",
"(",
"'Content-Type'",
"=>",
"'application/pdf'",
",",
"'Content-Disposition'",
"=>",
"'attachment; filename=\"'",
".",
"$",
"pdfName",
".",
"'\"'",
")",
")",
";",
"}"
] |
Finds a order object by a given id from the url
and returns a rendered pdf in a download window
@param Request $request
@param $id
@throws OrderNotFoundException
@return Response
|
[
"Finds",
"a",
"order",
"object",
"by",
"a",
"given",
"id",
"from",
"the",
"url",
"and",
"returns",
"a",
"rendered",
"pdf",
"in",
"a",
"download",
"window"
] |
train
|
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/OrderBundle/Controller/PdfController.php#L49-L74
|
o2system/html
|
src/Dom/Style.php
|
Style.import
|
public function import(Style $style)
{
foreach ($style->getArrayCopy() as $styleTextContent) {
$this->append($styleTextContent);
}
}
|
php
|
public function import(Style $style)
{
foreach ($style->getArrayCopy() as $styleTextContent) {
$this->append($styleTextContent);
}
}
|
[
"public",
"function",
"import",
"(",
"Style",
"$",
"style",
")",
"{",
"foreach",
"(",
"$",
"style",
"->",
"getArrayCopy",
"(",
")",
"as",
"$",
"styleTextContent",
")",
"{",
"$",
"this",
"->",
"append",
"(",
"$",
"styleTextContent",
")",
";",
"}",
"}"
] |
Style::import
@param \O2System\Html\Dom\Style $style
|
[
"Style",
"::",
"import"
] |
train
|
https://github.com/o2system/html/blob/b7336fb45d42603ce1064b25572a05d495887670/src/Dom/Style.php#L30-L35
|
kderyabin/logger
|
src/Handlers/StreamHandler.php
|
StreamHandler.open
|
public function open(): bool
{
$path = $this->getOptionOrDefault('path');
if (is_resource($path)) {
$this->resource = $path;
return true;
}
$context = $this->getOptionOrDefault('context');
if (is_resource($context)) {
$this->resource = @fopen($path, 'ab', false, $context);
} else {
$this->resource = @fopen($path, 'ab');
}
return is_resource($this->resource);
}
|
php
|
public function open(): bool
{
$path = $this->getOptionOrDefault('path');
if (is_resource($path)) {
$this->resource = $path;
return true;
}
$context = $this->getOptionOrDefault('context');
if (is_resource($context)) {
$this->resource = @fopen($path, 'ab', false, $context);
} else {
$this->resource = @fopen($path, 'ab');
}
return is_resource($this->resource);
}
|
[
"public",
"function",
"open",
"(",
")",
":",
"bool",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getOptionOrDefault",
"(",
"'path'",
")",
";",
"if",
"(",
"is_resource",
"(",
"$",
"path",
")",
")",
"{",
"$",
"this",
"->",
"resource",
"=",
"$",
"path",
";",
"return",
"true",
";",
"}",
"$",
"context",
"=",
"$",
"this",
"->",
"getOptionOrDefault",
"(",
"'context'",
")",
";",
"if",
"(",
"is_resource",
"(",
"$",
"context",
")",
")",
"{",
"$",
"this",
"->",
"resource",
"=",
"@",
"fopen",
"(",
"$",
"path",
",",
"'ab'",
",",
"false",
",",
"$",
"context",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"resource",
"=",
"@",
"fopen",
"(",
"$",
"path",
",",
"'ab'",
")",
";",
"}",
"return",
"is_resource",
"(",
"$",
"this",
"->",
"resource",
")",
";",
"}"
] |
Open a log destination.
@return bool
|
[
"Open",
"a",
"log",
"destination",
"."
] |
train
|
https://github.com/kderyabin/logger/blob/683890192b37fe9d36611972e12c2994669f5b85/src/Handlers/StreamHandler.php#L41-L57
|
kderyabin/logger
|
src/Handlers/StreamHandler.php
|
StreamHandler.handle
|
public function handle(string $level, string $log): bool
{
if (!is_resource($this->resource)) {
$status = $this->open();
if (!$status) {
throw new \Exception(
sprintf('Failed to open a resource "%s"', $this->getOptionOrDefault('path'))
);
}
}
return fwrite($this->resource, $log) !== false;
}
|
php
|
public function handle(string $level, string $log): bool
{
if (!is_resource($this->resource)) {
$status = $this->open();
if (!$status) {
throw new \Exception(
sprintf('Failed to open a resource "%s"', $this->getOptionOrDefault('path'))
);
}
}
return fwrite($this->resource, $log) !== false;
}
|
[
"public",
"function",
"handle",
"(",
"string",
"$",
"level",
",",
"string",
"$",
"log",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"this",
"->",
"resource",
")",
")",
"{",
"$",
"status",
"=",
"$",
"this",
"->",
"open",
"(",
")",
";",
"if",
"(",
"!",
"$",
"status",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Failed to open a resource \"%s\"'",
",",
"$",
"this",
"->",
"getOptionOrDefault",
"(",
"'path'",
")",
")",
")",
";",
"}",
"}",
"return",
"fwrite",
"(",
"$",
"this",
"->",
"resource",
",",
"$",
"log",
")",
"!==",
"false",
";",
"}"
] |
Write a log message.
@param string $level
@param string $log
@return bool
@throws \Exception
|
[
"Write",
"a",
"log",
"message",
"."
] |
train
|
https://github.com/kderyabin/logger/blob/683890192b37fe9d36611972e12c2994669f5b85/src/Handlers/StreamHandler.php#L77-L88
|
siriusphp/middleware
|
src/FrameRunner.php
|
FrameRunner.factory
|
public static function factory(array $middlewares = array())
{
$runner = null;
foreach ($middlewares as $middleware) {
$runner = $runner ? $runner->add($middleware) : new static($middleware);
}
return $runner;
}
|
php
|
public static function factory(array $middlewares = array())
{
$runner = null;
foreach ($middlewares as $middleware) {
$runner = $runner ? $runner->add($middleware) : new static($middleware);
}
return $runner;
}
|
[
"public",
"static",
"function",
"factory",
"(",
"array",
"$",
"middlewares",
"=",
"array",
"(",
")",
")",
"{",
"$",
"runner",
"=",
"null",
";",
"foreach",
"(",
"$",
"middlewares",
"as",
"$",
"middleware",
")",
"{",
"$",
"runner",
"=",
"$",
"runner",
"?",
"$",
"runner",
"->",
"add",
"(",
"$",
"middleware",
")",
":",
"new",
"static",
"(",
"$",
"middleware",
")",
";",
"}",
"return",
"$",
"runner",
";",
"}"
] |
Creates a runner based on an array of middleware
@param array $middlewares
@return FrameRunner
|
[
"Creates",
"a",
"runner",
"based",
"on",
"an",
"array",
"of",
"middleware"
] |
train
|
https://github.com/siriusphp/middleware/blob/e6805639982d2c0ae01dc9e9a1583915b7873782/src/FrameRunner.php#L26-L33
|
fuzz-productions/laravel-api-data
|
src/Support/CollectionUtility.php
|
CollectionUtility.collapseSerialized
|
public static function collapseSerialized(EloquentCollection $collection)
{
return $collection->map(
function (SerializedModel $menu_item) {
return $menu_item->serialized();
}
)->collapse();
}
|
php
|
public static function collapseSerialized(EloquentCollection $collection)
{
return $collection->map(
function (SerializedModel $menu_item) {
return $menu_item->serialized();
}
)->collapse();
}
|
[
"public",
"static",
"function",
"collapseSerialized",
"(",
"EloquentCollection",
"$",
"collection",
")",
"{",
"return",
"$",
"collection",
"->",
"map",
"(",
"function",
"(",
"SerializedModel",
"$",
"menu_item",
")",
"{",
"return",
"$",
"menu_item",
"->",
"serialized",
"(",
")",
";",
"}",
")",
"->",
"collapse",
"(",
")",
";",
"}"
] |
Collapse a keyed Eloquent Collection.
@param \Illuminate\Database\Eloquent\Collection $collection
@return \Illuminate\Support\Collection
|
[
"Collapse",
"a",
"keyed",
"Eloquent",
"Collection",
"."
] |
train
|
https://github.com/fuzz-productions/laravel-api-data/blob/25e181860d2f269b3b212195944c2bca95b411bb/src/Support/CollectionUtility.php#L21-L28
|
withfatpanda/illuminate-wordpress
|
src/WordPress/Providers/Pagination/PaginationServiceProvider.php
|
PaginationServiceProvider.boot
|
public function boot()
{
$this->loadViewsFrom(__DIR__.'/resources/views', 'pagination');
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/resources/views' => $this->app->basePath('resources/views/vendor/pagination'),
], 'laravel-pagination');
}
}
|
php
|
public function boot()
{
$this->loadViewsFrom(__DIR__.'/resources/views', 'pagination');
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/resources/views' => $this->app->basePath('resources/views/vendor/pagination'),
], 'laravel-pagination');
}
}
|
[
"public",
"function",
"boot",
"(",
")",
"{",
"$",
"this",
"->",
"loadViewsFrom",
"(",
"__DIR__",
".",
"'/resources/views'",
",",
"'pagination'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"app",
"->",
"runningInConsole",
"(",
")",
")",
"{",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/resources/views'",
"=>",
"$",
"this",
"->",
"app",
"->",
"basePath",
"(",
"'resources/views/vendor/pagination'",
")",
",",
"]",
",",
"'laravel-pagination'",
")",
";",
"}",
"}"
] |
Bootstrap any application services.
@return void
|
[
"Bootstrap",
"any",
"application",
"services",
"."
] |
train
|
https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/WordPress/Providers/Pagination/PaginationServiceProvider.php#L11-L20
|
Laralum/Roles
|
src/Models/Role.php
|
Role.addUser
|
public function addUser($user)
{
if (!$this->hasUser($user)) {
return RoleUser::create(['role_id' => $this->id, 'user_id' => $user->id]);
}
return false;
}
|
php
|
public function addUser($user)
{
if (!$this->hasUser($user)) {
return RoleUser::create(['role_id' => $this->id, 'user_id' => $user->id]);
}
return false;
}
|
[
"public",
"function",
"addUser",
"(",
"$",
"user",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasUser",
"(",
"$",
"user",
")",
")",
"{",
"return",
"RoleUser",
"::",
"create",
"(",
"[",
"'role_id'",
"=>",
"$",
"this",
"->",
"id",
",",
"'user_id'",
"=>",
"$",
"user",
"->",
"id",
"]",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Adds a user into the role.
@param mixed $user
|
[
"Adds",
"a",
"user",
"into",
"the",
"role",
"."
] |
train
|
https://github.com/Laralum/Roles/blob/f934967a5dcebebf81915dd50fccdbcb7e23c113/src/Models/Role.php#L62-L69
|
Laralum/Roles
|
src/Models/Role.php
|
Role.addPermission
|
public function addPermission($permission)
{
if (!$this->hasPermission($permission)) {
return PermissionRole::create(['role_id' => $this->id, 'permission_id' => $permission->id]);
}
return false;
}
|
php
|
public function addPermission($permission)
{
if (!$this->hasPermission($permission)) {
return PermissionRole::create(['role_id' => $this->id, 'permission_id' => $permission->id]);
}
return false;
}
|
[
"public",
"function",
"addPermission",
"(",
"$",
"permission",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasPermission",
"(",
"$",
"permission",
")",
")",
"{",
"return",
"PermissionRole",
"::",
"create",
"(",
"[",
"'role_id'",
"=>",
"$",
"this",
"->",
"id",
",",
"'permission_id'",
"=>",
"$",
"permission",
"->",
"id",
"]",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Adds a permission into the role.
@param mixed $permission
|
[
"Adds",
"a",
"permission",
"into",
"the",
"role",
"."
] |
train
|
https://github.com/Laralum/Roles/blob/f934967a5dcebebf81915dd50fccdbcb7e23c113/src/Models/Role.php#L76-L83
|
Laralum/Roles
|
src/Models/Role.php
|
Role.deleteUser
|
public function deleteUser($user)
{
if ($this->hasUser($user)) {
return RoleUser::where(
['role_id' => $this->id, 'user_id' => $user->id]
)->first()->delete();
}
return false;
}
|
php
|
public function deleteUser($user)
{
if ($this->hasUser($user)) {
return RoleUser::where(
['role_id' => $this->id, 'user_id' => $user->id]
)->first()->delete();
}
return false;
}
|
[
"public",
"function",
"deleteUser",
"(",
"$",
"user",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasUser",
"(",
"$",
"user",
")",
")",
"{",
"return",
"RoleUser",
"::",
"where",
"(",
"[",
"'role_id'",
"=>",
"$",
"this",
"->",
"id",
",",
"'user_id'",
"=>",
"$",
"user",
"->",
"id",
"]",
")",
"->",
"first",
"(",
")",
"->",
"delete",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Deletes the specified role user.
@param mixed $user
|
[
"Deletes",
"the",
"specified",
"role",
"user",
"."
] |
train
|
https://github.com/Laralum/Roles/blob/f934967a5dcebebf81915dd50fccdbcb7e23c113/src/Models/Role.php#L118-L127
|
Laralum/Roles
|
src/Models/Role.php
|
Role.deletePermission
|
public function deletePermission($permission)
{
if ($this->hasPermission($permission)) {
return PermissionRole::where(
['role_id' => $this->id, 'permission_id' => $permission->id]
)->first()->delete();
}
return false;
}
|
php
|
public function deletePermission($permission)
{
if ($this->hasPermission($permission)) {
return PermissionRole::where(
['role_id' => $this->id, 'permission_id' => $permission->id]
)->first()->delete();
}
return false;
}
|
[
"public",
"function",
"deletePermission",
"(",
"$",
"permission",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasPermission",
"(",
"$",
"permission",
")",
")",
"{",
"return",
"PermissionRole",
"::",
"where",
"(",
"[",
"'role_id'",
"=>",
"$",
"this",
"->",
"id",
",",
"'permission_id'",
"=>",
"$",
"permission",
"->",
"id",
"]",
")",
"->",
"first",
"(",
")",
"->",
"delete",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Deletes the specified role permission.
@param mixed $permission
|
[
"Deletes",
"the",
"specified",
"role",
"permission",
"."
] |
train
|
https://github.com/Laralum/Roles/blob/f934967a5dcebebf81915dd50fccdbcb7e23c113/src/Models/Role.php#L134-L143
|
heyday/heystack
|
src/Storage/Storage.php
|
Storage.process
|
public function process(StorableInterface $object)
{
if (is_array($this->backends) && count($this->backends) > 0) {
$results = [];
$identifiers = $object->getStorableBackendIdentifiers();
foreach ($this->backends as $identifier => $backend) {
if (in_array($identifier, $identifiers)) {
$results[$identifier] = $backend->write($object);
}
}
return $results;
} else {
throw new StorageProcessingException(
sprintf(
"Tried to process an storable object '%s' with no backends",
$object->getStorableIdentifier()
)
);
}
}
|
php
|
public function process(StorableInterface $object)
{
if (is_array($this->backends) && count($this->backends) > 0) {
$results = [];
$identifiers = $object->getStorableBackendIdentifiers();
foreach ($this->backends as $identifier => $backend) {
if (in_array($identifier, $identifiers)) {
$results[$identifier] = $backend->write($object);
}
}
return $results;
} else {
throw new StorageProcessingException(
sprintf(
"Tried to process an storable object '%s' with no backends",
$object->getStorableIdentifier()
)
);
}
}
|
[
"public",
"function",
"process",
"(",
"StorableInterface",
"$",
"object",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"backends",
")",
"&&",
"count",
"(",
"$",
"this",
"->",
"backends",
")",
">",
"0",
")",
"{",
"$",
"results",
"=",
"[",
"]",
";",
"$",
"identifiers",
"=",
"$",
"object",
"->",
"getStorableBackendIdentifiers",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"backends",
"as",
"$",
"identifier",
"=>",
"$",
"backend",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"identifier",
",",
"$",
"identifiers",
")",
")",
"{",
"$",
"results",
"[",
"$",
"identifier",
"]",
"=",
"$",
"backend",
"->",
"write",
"(",
"$",
"object",
")",
";",
"}",
"}",
"return",
"$",
"results",
";",
"}",
"else",
"{",
"throw",
"new",
"StorageProcessingException",
"(",
"sprintf",
"(",
"\"Tried to process an storable object '%s' with no backends\"",
",",
"$",
"object",
"->",
"getStorableIdentifier",
"(",
")",
")",
")",
";",
"}",
"}"
] |
Runs through each storage backend and processes the Storable object
@param StorableInterface $object
@return array
@throws \Exception
|
[
"Runs",
"through",
"each",
"storage",
"backend",
"and",
"processes",
"the",
"Storable",
"object"
] |
train
|
https://github.com/heyday/heystack/blob/2c051933f8c532d0a9a23be6ee1ff5c619e47dfe/src/Storage/Storage.php#L69-L91
|
czim/laravel-pxlcms
|
src/Generator/Writer/Model/CmsModelWriter.php
|
CmsModelWriter.processSteps
|
protected function processSteps()
{
return [
Steps\CheckConditionsAndSetup::class,
Steps\StubReplaceSimple::class,
Steps\StubReplaceAttributeData::class,
Steps\StubReplaceRelationData::class,
Steps\StubReplaceAccessorsAndMutators::class,
Steps\StubReplaceSluggableData::class,
Steps\StubReplaceScopes::class,
Steps\StubReplaceDocBlock::class,
Steps\StubReplaceImportsAndTraits::class,
Steps\WriteFile::class,
];
}
|
php
|
protected function processSteps()
{
return [
Steps\CheckConditionsAndSetup::class,
Steps\StubReplaceSimple::class,
Steps\StubReplaceAttributeData::class,
Steps\StubReplaceRelationData::class,
Steps\StubReplaceAccessorsAndMutators::class,
Steps\StubReplaceSluggableData::class,
Steps\StubReplaceScopes::class,
Steps\StubReplaceDocBlock::class,
Steps\StubReplaceImportsAndTraits::class,
Steps\WriteFile::class,
];
}
|
[
"protected",
"function",
"processSteps",
"(",
")",
"{",
"return",
"[",
"Steps",
"\\",
"CheckConditionsAndSetup",
"::",
"class",
",",
"Steps",
"\\",
"StubReplaceSimple",
"::",
"class",
",",
"Steps",
"\\",
"StubReplaceAttributeData",
"::",
"class",
",",
"Steps",
"\\",
"StubReplaceRelationData",
"::",
"class",
",",
"Steps",
"\\",
"StubReplaceAccessorsAndMutators",
"::",
"class",
",",
"Steps",
"\\",
"StubReplaceSluggableData",
"::",
"class",
",",
"Steps",
"\\",
"StubReplaceScopes",
"::",
"class",
",",
"Steps",
"\\",
"StubReplaceDocBlock",
"::",
"class",
",",
"Steps",
"\\",
"StubReplaceImportsAndTraits",
"::",
"class",
",",
"Steps",
"\\",
"WriteFile",
"::",
"class",
",",
"]",
";",
"}"
] |
Gathers the steps to pass the dataobject through as a collection
These are the steps for AFTER the initial checks and retrieval
has been handled.
@return array
|
[
"Gathers",
"the",
"steps",
"to",
"pass",
"the",
"dataobject",
"through",
"as",
"a",
"collection",
"These",
"are",
"the",
"steps",
"for",
"AFTER",
"the",
"initial",
"checks",
"and",
"retrieval",
"has",
"been",
"handled",
"."
] |
train
|
https://github.com/czim/laravel-pxlcms/blob/910297d2a3f2db86dde51b0e10fe5aad45f1aa1a/src/Generator/Writer/Model/CmsModelWriter.php#L39-L55
|
phower/escaper
|
src/Phower/Escaper/Escaper.php
|
Escaper.toUtf8
|
protected function toUtf8($string)
{
if ($this->getEncoding() === 'utf-8') {
$result = $string;
} else {
$result = $this->convertEncoding($string, 'UTF-8', $this->getEncoding());
}
return $result;
}
|
php
|
protected function toUtf8($string)
{
if ($this->getEncoding() === 'utf-8') {
$result = $string;
} else {
$result = $this->convertEncoding($string, 'UTF-8', $this->getEncoding());
}
return $result;
}
|
[
"protected",
"function",
"toUtf8",
"(",
"$",
"string",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getEncoding",
"(",
")",
"===",
"'utf-8'",
")",
"{",
"$",
"result",
"=",
"$",
"string",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"convertEncoding",
"(",
"$",
"string",
",",
"'UTF-8'",
",",
"$",
"this",
"->",
"getEncoding",
"(",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Convert string to UTF-8
@param string $string
@return string
@throws RuntimeException
|
[
"Convert",
"string",
"to",
"UTF",
"-",
"8"
] |
train
|
https://github.com/phower/escaper/blob/2c74ab507ac8cb272da27d6225c596abd972a0c3/src/Phower/Escaper/Escaper.php#L187-L196
|
phower/escaper
|
src/Phower/Escaper/Escaper.php
|
Escaper.escapeAttribute
|
public function escapeAttribute($attribute)
{
$attribute = $this->toUtf8($attribute);
if ($attribute === '' || ctype_digit($attribute)) {
return $attribute;
}
$result = preg_replace_callback('/[^a-z0-9,\.\-_]/iSu', $this->attributeMatcher, $attribute);
return $this->fromUtf8($result);
}
|
php
|
public function escapeAttribute($attribute)
{
$attribute = $this->toUtf8($attribute);
if ($attribute === '' || ctype_digit($attribute)) {
return $attribute;
}
$result = preg_replace_callback('/[^a-z0-9,\.\-_]/iSu', $this->attributeMatcher, $attribute);
return $this->fromUtf8($result);
}
|
[
"public",
"function",
"escapeAttribute",
"(",
"$",
"attribute",
")",
"{",
"$",
"attribute",
"=",
"$",
"this",
"->",
"toUtf8",
"(",
"$",
"attribute",
")",
";",
"if",
"(",
"$",
"attribute",
"===",
"''",
"||",
"ctype_digit",
"(",
"$",
"attribute",
")",
")",
"{",
"return",
"$",
"attribute",
";",
"}",
"$",
"result",
"=",
"preg_replace_callback",
"(",
"'/[^a-z0-9,\\.\\-_]/iSu'",
",",
"$",
"this",
"->",
"attributeMatcher",
",",
"$",
"attribute",
")",
";",
"return",
"$",
"this",
"->",
"fromUtf8",
"(",
"$",
"result",
")",
";",
"}"
] |
Escape attribute
@param string $attribute
@return string
|
[
"Escape",
"attribute"
] |
train
|
https://github.com/phower/escaper/blob/2c74ab507ac8cb272da27d6225c596abd972a0c3/src/Phower/Escaper/Escaper.php#L258-L268
|
phower/escaper
|
src/Phower/Escaper/Escaper.php
|
Escaper.escapeJs
|
public function escapeJs($js)
{
$js = $this->toUtf8($js);
if ($js === '' || ctype_digit($js)) {
return $js;
}
$result = preg_replace_callback('/[^a-z0-9,\._]/iSu', $this->jsMatcher, $js);
return $this->fromUtf8($result);
}
|
php
|
public function escapeJs($js)
{
$js = $this->toUtf8($js);
if ($js === '' || ctype_digit($js)) {
return $js;
}
$result = preg_replace_callback('/[^a-z0-9,\._]/iSu', $this->jsMatcher, $js);
return $this->fromUtf8($result);
}
|
[
"public",
"function",
"escapeJs",
"(",
"$",
"js",
")",
"{",
"$",
"js",
"=",
"$",
"this",
"->",
"toUtf8",
"(",
"$",
"js",
")",
";",
"if",
"(",
"$",
"js",
"===",
"''",
"||",
"ctype_digit",
"(",
"$",
"js",
")",
")",
"{",
"return",
"$",
"js",
";",
"}",
"$",
"result",
"=",
"preg_replace_callback",
"(",
"'/[^a-z0-9,\\._]/iSu'",
",",
"$",
"this",
"->",
"jsMatcher",
",",
"$",
"js",
")",
";",
"return",
"$",
"this",
"->",
"fromUtf8",
"(",
"$",
"result",
")",
";",
"}"
] |
Escape JS
@param string $js
@return string
|
[
"Escape",
"JS"
] |
train
|
https://github.com/phower/escaper/blob/2c74ab507ac8cb272da27d6225c596abd972a0c3/src/Phower/Escaper/Escaper.php#L276-L287
|
phower/escaper
|
src/Phower/Escaper/Escaper.php
|
Escaper.escapeCss
|
public function escapeCss($css)
{
$css = $this->toUtf8($css);
if ($css === '' || ctype_digit($css)) {
return $css;
}
$result = preg_replace_callback('/[^a-z0-9]/iSu', $this->cssMatcher, $css);
return $this->fromUtf8($result);
}
|
php
|
public function escapeCss($css)
{
$css = $this->toUtf8($css);
if ($css === '' || ctype_digit($css)) {
return $css;
}
$result = preg_replace_callback('/[^a-z0-9]/iSu', $this->cssMatcher, $css);
return $this->fromUtf8($result);
}
|
[
"public",
"function",
"escapeCss",
"(",
"$",
"css",
")",
"{",
"$",
"css",
"=",
"$",
"this",
"->",
"toUtf8",
"(",
"$",
"css",
")",
";",
"if",
"(",
"$",
"css",
"===",
"''",
"||",
"ctype_digit",
"(",
"$",
"css",
")",
")",
"{",
"return",
"$",
"css",
";",
"}",
"$",
"result",
"=",
"preg_replace_callback",
"(",
"'/[^a-z0-9]/iSu'",
",",
"$",
"this",
"->",
"cssMatcher",
",",
"$",
"css",
")",
";",
"return",
"$",
"this",
"->",
"fromUtf8",
"(",
"$",
"result",
")",
";",
"}"
] |
Escape CSS
@param string $css
@return string
|
[
"Escape",
"CSS"
] |
train
|
https://github.com/phower/escaper/blob/2c74ab507ac8cb272da27d6225c596abd972a0c3/src/Phower/Escaper/Escaper.php#L295-L306
|
pageon/SlackWebhookMonolog
|
src/Monolog/Error.php
|
Error.addParameterFallback
|
private function addParameterFallback($name, $fallbackData = null)
{
if (!isset($this->parameters[$name]) && !empty($fallbackData)) {
$this->parameters[$name] = $fallbackData;
}
}
|
php
|
private function addParameterFallback($name, $fallbackData = null)
{
if (!isset($this->parameters[$name]) && !empty($fallbackData)) {
$this->parameters[$name] = $fallbackData;
}
}
|
[
"private",
"function",
"addParameterFallback",
"(",
"$",
"name",
",",
"$",
"fallbackData",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"parameters",
"[",
"$",
"name",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"fallbackData",
")",
")",
"{",
"$",
"this",
"->",
"parameters",
"[",
"$",
"name",
"]",
"=",
"$",
"fallbackData",
";",
"}",
"}"
] |
This will add fallback data to the parameters if the key is not set.
@param string $name
@param mixed $fallbackData
|
[
"This",
"will",
"add",
"fallback",
"data",
"to",
"the",
"parameters",
"if",
"the",
"key",
"is",
"not",
"set",
"."
] |
train
|
https://github.com/pageon/SlackWebhookMonolog/blob/6755060ddd6429620fd4c7decbb95f05463fc36b/src/Monolog/Error.php#L127-L132
|
Wonail/wocenter
|
libs/PinYin.php
|
PinYin.Pinyin
|
public static function Pinyin($_String, $_Code = 'UTF8')
{
// GBK页面可改为gb2312,其他随意填写为UTF8
$_DataKey = "a|ai|an|ang|ao|ba|bai|ban|bang|bao|bei|ben|beng|bi|bian|biao|bie|bin|bing|bo|bu|ca|cai|can|cang|cao|ce|ceng|cha" .
"|chai|chan|chang|chao|che|chen|cheng|chi|chong|chou|chu|chuai|chuan|chuang|chui|chun|chuo|ci|cong|cou|cu|" .
"cuan|cui|cun|cuo|da|dai|dan|dang|dao|de|deng|di|dian|diao|die|ding|diu|dong|dou|du|duan|dui|dun|duo|e|en|er" .
"|fa|fan|fang|fei|fen|feng|fo|fou|fu|ga|gai|gan|gang|gao|ge|gei|gen|geng|gong|gou|gu|gua|guai|guan|guang|gui" .
"|gun|guo|ha|hai|han|hang|hao|he|hei|hen|heng|hong|hou|hu|hua|huai|huan|huang|hui|hun|huo|ji|jia|jian|jiang" .
"|jiao|jie|jin|jing|jiong|jiu|ju|juan|jue|jun|ka|kai|kan|kang|kao|ke|ken|keng|kong|kou|ku|kua|kuai|kuan|kuang" .
"|kui|kun|kuo|la|lai|lan|lang|lao|le|lei|leng|li|lia|lian|liang|liao|lie|lin|ling|liu|long|lou|lu|lv|luan|lue" .
"|lun|luo|ma|mai|man|mang|mao|me|mei|men|meng|mi|mian|miao|mie|min|ming|miu|mo|mou|mu|na|nai|nan|nang|nao|ne" .
"|nei|nen|neng|ni|nian|niang|niao|nie|nin|ning|niu|nong|nu|nv|nuan|nue|nuo|o|ou|pa|pai|pan|pang|pao|pei|pen" .
"|peng|pi|pian|piao|pie|pin|ping|po|pu|qi|qia|qian|qiang|qiao|qie|qin|qing|qiong|qiu|qu|quan|que|qun|ran|rang" .
"|rao|re|ren|reng|ri|rong|rou|ru|ruan|rui|run|ruo|sa|sai|san|sang|sao|se|sen|seng|sha|shai|shan|shang|shao|" .
"she|shen|sheng|shi|shou|shu|shua|shuai|shuan|shuang|shui|shun|shuo|si|song|sou|su|suan|sui|sun|suo|ta|tai|" .
"tan|tang|tao|te|teng|ti|tian|tiao|tie|ting|tong|tou|tu|tuan|tui|tun|tuo|wa|wai|wan|wang|wei|wen|weng|wo|wu" .
"|xi|xia|xian|xiang|xiao|xie|xin|xing|xiong|xiu|xu|xuan|xue|xun|ya|yan|yang|yao|ye|yi|yin|ying|yo|yong|you" .
"|yu|yuan|yue|yun|za|zai|zan|zang|zao|ze|zei|zen|zeng|zha|zhai|zhan|zhang|zhao|zhe|zhen|zheng|zhi|zhong|" .
"zhou|zhu|zhua|zhuai|zhuan|zhuang|zhui|zhun|zhuo|zi|zong|zou|zu|zuan|zui|zun|zuo";
$_DataValue = "-20319|-20317|-20304|-20295|-20292|-20283|-20265|-20257|-20242|-20230|-20051|-20036|-20032|-20026|-20002|-19990" .
"|-19986|-19982|-19976|-19805|-19784|-19775|-19774|-19763|-19756|-19751|-19746|-19741|-19739|-19728|-19725" .
"|-19715|-19540|-19531|-19525|-19515|-19500|-19484|-19479|-19467|-19289|-19288|-19281|-19275|-19270|-19263" .
"|-19261|-19249|-19243|-19242|-19238|-19235|-19227|-19224|-19218|-19212|-19038|-19023|-19018|-19006|-19003" .
"|-18996|-18977|-18961|-18952|-18783|-18774|-18773|-18763|-18756|-18741|-18735|-18731|-18722|-18710|-18697" .
"|-18696|-18526|-18518|-18501|-18490|-18478|-18463|-18448|-18447|-18446|-18239|-18237|-18231|-18220|-18211" .
"|-18201|-18184|-18183|-18181|-18012|-17997|-17988|-17970|-17964|-17961|-17950|-17947|-17931|-17928|-17922" .
"|-17759|-17752|-17733|-17730|-17721|-17703|-17701|-17697|-17692|-17683|-17676|-17496|-17487|-17482|-17468" .
"|-17454|-17433|-17427|-17417|-17202|-17185|-16983|-16970|-16942|-16915|-16733|-16708|-16706|-16689|-16664" .
"|-16657|-16647|-16474|-16470|-16465|-16459|-16452|-16448|-16433|-16429|-16427|-16423|-16419|-16412|-16407" .
"|-16403|-16401|-16393|-16220|-16216|-16212|-16205|-16202|-16187|-16180|-16171|-16169|-16158|-16155|-15959" .
"|-15958|-15944|-15933|-15920|-15915|-15903|-15889|-15878|-15707|-15701|-15681|-15667|-15661|-15659|-15652" .
"|-15640|-15631|-15625|-15454|-15448|-15436|-15435|-15419|-15416|-15408|-15394|-15385|-15377|-15375|-15369" .
"|-15363|-15362|-15183|-15180|-15165|-15158|-15153|-15150|-15149|-15144|-15143|-15141|-15140|-15139|-15128" .
"|-15121|-15119|-15117|-15110|-15109|-14941|-14937|-14933|-14930|-14929|-14928|-14926|-14922|-14921|-14914" .
"|-14908|-14902|-14894|-14889|-14882|-14873|-14871|-14857|-14678|-14674|-14670|-14668|-14663|-14654|-14645" .
"|-14630|-14594|-14429|-14407|-14399|-14384|-14379|-14368|-14355|-14353|-14345|-14170|-14159|-14151|-14149" .
"|-14145|-14140|-14137|-14135|-14125|-14123|-14122|-14112|-14109|-14099|-14097|-14094|-14092|-14090|-14087" .
"|-14083|-13917|-13914|-13910|-13907|-13906|-13905|-13896|-13894|-13878|-13870|-13859|-13847|-13831|-13658" .
"|-13611|-13601|-13406|-13404|-13400|-13398|-13395|-13391|-13387|-13383|-13367|-13359|-13356|-13343|-13340" .
"|-13329|-13326|-13318|-13147|-13138|-13120|-13107|-13096|-13095|-13091|-13076|-13068|-13063|-13060|-12888" .
"|-12875|-12871|-12860|-12858|-12852|-12849|-12838|-12831|-12829|-12812|-12802|-12607|-12597|-12594|-12585" .
"|-12556|-12359|-12346|-12320|-12300|-12120|-12099|-12089|-12074|-12067|-12058|-12039|-11867|-11861|-11847" .
"|-11831|-11798|-11781|-11604|-11589|-11536|-11358|-11340|-11339|-11324|-11303|-11097|-11077|-11067|-11055" .
"|-11052|-11045|-11041|-11038|-11024|-11020|-11019|-11018|-11014|-10838|-10832|-10815|-10800|-10790|-10780" .
"|-10764|-10587|-10544|-10533|-10519|-10331|-10329|-10328|-10322|-10315|-10309|-10307|-10296|-10281|-10274" .
"|-10270|-10262|-10260|-10256|-10254";
$_TDataKey = explode('|', $_DataKey);
$_TDataValue = explode('|', $_DataValue);
$_Data = array_combine($_TDataKey, $_TDataValue);
arsort($_Data);
reset($_Data);
if ($_Code != 'gb2312')
$_String = self::_U2_Utf8_Gb($_String);
$_Res = '';
for ($i = 0; $i < strlen($_String); $i++) {
$_P = ord(substr($_String, $i, 1));
if ($_P > 160) {
$_Q = ord(substr($_String, ++$i, 1));
$_P = $_P * 256 + $_Q - 65536;
}
$_Res .= self::_Pinyin($_P, $_Data);
}
return preg_replace("/[^a-z0-9]*/", '', $_Res);
}
|
php
|
public static function Pinyin($_String, $_Code = 'UTF8')
{
// GBK页面可改为gb2312,其他随意填写为UTF8
$_DataKey = "a|ai|an|ang|ao|ba|bai|ban|bang|bao|bei|ben|beng|bi|bian|biao|bie|bin|bing|bo|bu|ca|cai|can|cang|cao|ce|ceng|cha" .
"|chai|chan|chang|chao|che|chen|cheng|chi|chong|chou|chu|chuai|chuan|chuang|chui|chun|chuo|ci|cong|cou|cu|" .
"cuan|cui|cun|cuo|da|dai|dan|dang|dao|de|deng|di|dian|diao|die|ding|diu|dong|dou|du|duan|dui|dun|duo|e|en|er" .
"|fa|fan|fang|fei|fen|feng|fo|fou|fu|ga|gai|gan|gang|gao|ge|gei|gen|geng|gong|gou|gu|gua|guai|guan|guang|gui" .
"|gun|guo|ha|hai|han|hang|hao|he|hei|hen|heng|hong|hou|hu|hua|huai|huan|huang|hui|hun|huo|ji|jia|jian|jiang" .
"|jiao|jie|jin|jing|jiong|jiu|ju|juan|jue|jun|ka|kai|kan|kang|kao|ke|ken|keng|kong|kou|ku|kua|kuai|kuan|kuang" .
"|kui|kun|kuo|la|lai|lan|lang|lao|le|lei|leng|li|lia|lian|liang|liao|lie|lin|ling|liu|long|lou|lu|lv|luan|lue" .
"|lun|luo|ma|mai|man|mang|mao|me|mei|men|meng|mi|mian|miao|mie|min|ming|miu|mo|mou|mu|na|nai|nan|nang|nao|ne" .
"|nei|nen|neng|ni|nian|niang|niao|nie|nin|ning|niu|nong|nu|nv|nuan|nue|nuo|o|ou|pa|pai|pan|pang|pao|pei|pen" .
"|peng|pi|pian|piao|pie|pin|ping|po|pu|qi|qia|qian|qiang|qiao|qie|qin|qing|qiong|qiu|qu|quan|que|qun|ran|rang" .
"|rao|re|ren|reng|ri|rong|rou|ru|ruan|rui|run|ruo|sa|sai|san|sang|sao|se|sen|seng|sha|shai|shan|shang|shao|" .
"she|shen|sheng|shi|shou|shu|shua|shuai|shuan|shuang|shui|shun|shuo|si|song|sou|su|suan|sui|sun|suo|ta|tai|" .
"tan|tang|tao|te|teng|ti|tian|tiao|tie|ting|tong|tou|tu|tuan|tui|tun|tuo|wa|wai|wan|wang|wei|wen|weng|wo|wu" .
"|xi|xia|xian|xiang|xiao|xie|xin|xing|xiong|xiu|xu|xuan|xue|xun|ya|yan|yang|yao|ye|yi|yin|ying|yo|yong|you" .
"|yu|yuan|yue|yun|za|zai|zan|zang|zao|ze|zei|zen|zeng|zha|zhai|zhan|zhang|zhao|zhe|zhen|zheng|zhi|zhong|" .
"zhou|zhu|zhua|zhuai|zhuan|zhuang|zhui|zhun|zhuo|zi|zong|zou|zu|zuan|zui|zun|zuo";
$_DataValue = "-20319|-20317|-20304|-20295|-20292|-20283|-20265|-20257|-20242|-20230|-20051|-20036|-20032|-20026|-20002|-19990" .
"|-19986|-19982|-19976|-19805|-19784|-19775|-19774|-19763|-19756|-19751|-19746|-19741|-19739|-19728|-19725" .
"|-19715|-19540|-19531|-19525|-19515|-19500|-19484|-19479|-19467|-19289|-19288|-19281|-19275|-19270|-19263" .
"|-19261|-19249|-19243|-19242|-19238|-19235|-19227|-19224|-19218|-19212|-19038|-19023|-19018|-19006|-19003" .
"|-18996|-18977|-18961|-18952|-18783|-18774|-18773|-18763|-18756|-18741|-18735|-18731|-18722|-18710|-18697" .
"|-18696|-18526|-18518|-18501|-18490|-18478|-18463|-18448|-18447|-18446|-18239|-18237|-18231|-18220|-18211" .
"|-18201|-18184|-18183|-18181|-18012|-17997|-17988|-17970|-17964|-17961|-17950|-17947|-17931|-17928|-17922" .
"|-17759|-17752|-17733|-17730|-17721|-17703|-17701|-17697|-17692|-17683|-17676|-17496|-17487|-17482|-17468" .
"|-17454|-17433|-17427|-17417|-17202|-17185|-16983|-16970|-16942|-16915|-16733|-16708|-16706|-16689|-16664" .
"|-16657|-16647|-16474|-16470|-16465|-16459|-16452|-16448|-16433|-16429|-16427|-16423|-16419|-16412|-16407" .
"|-16403|-16401|-16393|-16220|-16216|-16212|-16205|-16202|-16187|-16180|-16171|-16169|-16158|-16155|-15959" .
"|-15958|-15944|-15933|-15920|-15915|-15903|-15889|-15878|-15707|-15701|-15681|-15667|-15661|-15659|-15652" .
"|-15640|-15631|-15625|-15454|-15448|-15436|-15435|-15419|-15416|-15408|-15394|-15385|-15377|-15375|-15369" .
"|-15363|-15362|-15183|-15180|-15165|-15158|-15153|-15150|-15149|-15144|-15143|-15141|-15140|-15139|-15128" .
"|-15121|-15119|-15117|-15110|-15109|-14941|-14937|-14933|-14930|-14929|-14928|-14926|-14922|-14921|-14914" .
"|-14908|-14902|-14894|-14889|-14882|-14873|-14871|-14857|-14678|-14674|-14670|-14668|-14663|-14654|-14645" .
"|-14630|-14594|-14429|-14407|-14399|-14384|-14379|-14368|-14355|-14353|-14345|-14170|-14159|-14151|-14149" .
"|-14145|-14140|-14137|-14135|-14125|-14123|-14122|-14112|-14109|-14099|-14097|-14094|-14092|-14090|-14087" .
"|-14083|-13917|-13914|-13910|-13907|-13906|-13905|-13896|-13894|-13878|-13870|-13859|-13847|-13831|-13658" .
"|-13611|-13601|-13406|-13404|-13400|-13398|-13395|-13391|-13387|-13383|-13367|-13359|-13356|-13343|-13340" .
"|-13329|-13326|-13318|-13147|-13138|-13120|-13107|-13096|-13095|-13091|-13076|-13068|-13063|-13060|-12888" .
"|-12875|-12871|-12860|-12858|-12852|-12849|-12838|-12831|-12829|-12812|-12802|-12607|-12597|-12594|-12585" .
"|-12556|-12359|-12346|-12320|-12300|-12120|-12099|-12089|-12074|-12067|-12058|-12039|-11867|-11861|-11847" .
"|-11831|-11798|-11781|-11604|-11589|-11536|-11358|-11340|-11339|-11324|-11303|-11097|-11077|-11067|-11055" .
"|-11052|-11045|-11041|-11038|-11024|-11020|-11019|-11018|-11014|-10838|-10832|-10815|-10800|-10790|-10780" .
"|-10764|-10587|-10544|-10533|-10519|-10331|-10329|-10328|-10322|-10315|-10309|-10307|-10296|-10281|-10274" .
"|-10270|-10262|-10260|-10256|-10254";
$_TDataKey = explode('|', $_DataKey);
$_TDataValue = explode('|', $_DataValue);
$_Data = array_combine($_TDataKey, $_TDataValue);
arsort($_Data);
reset($_Data);
if ($_Code != 'gb2312')
$_String = self::_U2_Utf8_Gb($_String);
$_Res = '';
for ($i = 0; $i < strlen($_String); $i++) {
$_P = ord(substr($_String, $i, 1));
if ($_P > 160) {
$_Q = ord(substr($_String, ++$i, 1));
$_P = $_P * 256 + $_Q - 65536;
}
$_Res .= self::_Pinyin($_P, $_Data);
}
return preg_replace("/[^a-z0-9]*/", '', $_Res);
}
|
[
"public",
"static",
"function",
"Pinyin",
"(",
"$",
"_String",
",",
"$",
"_Code",
"=",
"'UTF8'",
")",
"{",
"// GBK页面可改为gb2312,其他随意填写为UTF8",
"$",
"_DataKey",
"=",
"\"a|ai|an|ang|ao|ba|bai|ban|bang|bao|bei|ben|beng|bi|bian|biao|bie|bin|bing|bo|bu|ca|cai|can|cang|cao|ce|ceng|cha\"",
".",
"\"|chai|chan|chang|chao|che|chen|cheng|chi|chong|chou|chu|chuai|chuan|chuang|chui|chun|chuo|ci|cong|cou|cu|\"",
".",
"\"cuan|cui|cun|cuo|da|dai|dan|dang|dao|de|deng|di|dian|diao|die|ding|diu|dong|dou|du|duan|dui|dun|duo|e|en|er\"",
".",
"\"|fa|fan|fang|fei|fen|feng|fo|fou|fu|ga|gai|gan|gang|gao|ge|gei|gen|geng|gong|gou|gu|gua|guai|guan|guang|gui\"",
".",
"\"|gun|guo|ha|hai|han|hang|hao|he|hei|hen|heng|hong|hou|hu|hua|huai|huan|huang|hui|hun|huo|ji|jia|jian|jiang\"",
".",
"\"|jiao|jie|jin|jing|jiong|jiu|ju|juan|jue|jun|ka|kai|kan|kang|kao|ke|ken|keng|kong|kou|ku|kua|kuai|kuan|kuang\"",
".",
"\"|kui|kun|kuo|la|lai|lan|lang|lao|le|lei|leng|li|lia|lian|liang|liao|lie|lin|ling|liu|long|lou|lu|lv|luan|lue\"",
".",
"\"|lun|luo|ma|mai|man|mang|mao|me|mei|men|meng|mi|mian|miao|mie|min|ming|miu|mo|mou|mu|na|nai|nan|nang|nao|ne\"",
".",
"\"|nei|nen|neng|ni|nian|niang|niao|nie|nin|ning|niu|nong|nu|nv|nuan|nue|nuo|o|ou|pa|pai|pan|pang|pao|pei|pen\"",
".",
"\"|peng|pi|pian|piao|pie|pin|ping|po|pu|qi|qia|qian|qiang|qiao|qie|qin|qing|qiong|qiu|qu|quan|que|qun|ran|rang\"",
".",
"\"|rao|re|ren|reng|ri|rong|rou|ru|ruan|rui|run|ruo|sa|sai|san|sang|sao|se|sen|seng|sha|shai|shan|shang|shao|\"",
".",
"\"she|shen|sheng|shi|shou|shu|shua|shuai|shuan|shuang|shui|shun|shuo|si|song|sou|su|suan|sui|sun|suo|ta|tai|\"",
".",
"\"tan|tang|tao|te|teng|ti|tian|tiao|tie|ting|tong|tou|tu|tuan|tui|tun|tuo|wa|wai|wan|wang|wei|wen|weng|wo|wu\"",
".",
"\"|xi|xia|xian|xiang|xiao|xie|xin|xing|xiong|xiu|xu|xuan|xue|xun|ya|yan|yang|yao|ye|yi|yin|ying|yo|yong|you\"",
".",
"\"|yu|yuan|yue|yun|za|zai|zan|zang|zao|ze|zei|zen|zeng|zha|zhai|zhan|zhang|zhao|zhe|zhen|zheng|zhi|zhong|\"",
".",
"\"zhou|zhu|zhua|zhuai|zhuan|zhuang|zhui|zhun|zhuo|zi|zong|zou|zu|zuan|zui|zun|zuo\"",
";",
"$",
"_DataValue",
"=",
"\"-20319|-20317|-20304|-20295|-20292|-20283|-20265|-20257|-20242|-20230|-20051|-20036|-20032|-20026|-20002|-19990\"",
".",
"\"|-19986|-19982|-19976|-19805|-19784|-19775|-19774|-19763|-19756|-19751|-19746|-19741|-19739|-19728|-19725\"",
".",
"\"|-19715|-19540|-19531|-19525|-19515|-19500|-19484|-19479|-19467|-19289|-19288|-19281|-19275|-19270|-19263\"",
".",
"\"|-19261|-19249|-19243|-19242|-19238|-19235|-19227|-19224|-19218|-19212|-19038|-19023|-19018|-19006|-19003\"",
".",
"\"|-18996|-18977|-18961|-18952|-18783|-18774|-18773|-18763|-18756|-18741|-18735|-18731|-18722|-18710|-18697\"",
".",
"\"|-18696|-18526|-18518|-18501|-18490|-18478|-18463|-18448|-18447|-18446|-18239|-18237|-18231|-18220|-18211\"",
".",
"\"|-18201|-18184|-18183|-18181|-18012|-17997|-17988|-17970|-17964|-17961|-17950|-17947|-17931|-17928|-17922\"",
".",
"\"|-17759|-17752|-17733|-17730|-17721|-17703|-17701|-17697|-17692|-17683|-17676|-17496|-17487|-17482|-17468\"",
".",
"\"|-17454|-17433|-17427|-17417|-17202|-17185|-16983|-16970|-16942|-16915|-16733|-16708|-16706|-16689|-16664\"",
".",
"\"|-16657|-16647|-16474|-16470|-16465|-16459|-16452|-16448|-16433|-16429|-16427|-16423|-16419|-16412|-16407\"",
".",
"\"|-16403|-16401|-16393|-16220|-16216|-16212|-16205|-16202|-16187|-16180|-16171|-16169|-16158|-16155|-15959\"",
".",
"\"|-15958|-15944|-15933|-15920|-15915|-15903|-15889|-15878|-15707|-15701|-15681|-15667|-15661|-15659|-15652\"",
".",
"\"|-15640|-15631|-15625|-15454|-15448|-15436|-15435|-15419|-15416|-15408|-15394|-15385|-15377|-15375|-15369\"",
".",
"\"|-15363|-15362|-15183|-15180|-15165|-15158|-15153|-15150|-15149|-15144|-15143|-15141|-15140|-15139|-15128\"",
".",
"\"|-15121|-15119|-15117|-15110|-15109|-14941|-14937|-14933|-14930|-14929|-14928|-14926|-14922|-14921|-14914\"",
".",
"\"|-14908|-14902|-14894|-14889|-14882|-14873|-14871|-14857|-14678|-14674|-14670|-14668|-14663|-14654|-14645\"",
".",
"\"|-14630|-14594|-14429|-14407|-14399|-14384|-14379|-14368|-14355|-14353|-14345|-14170|-14159|-14151|-14149\"",
".",
"\"|-14145|-14140|-14137|-14135|-14125|-14123|-14122|-14112|-14109|-14099|-14097|-14094|-14092|-14090|-14087\"",
".",
"\"|-14083|-13917|-13914|-13910|-13907|-13906|-13905|-13896|-13894|-13878|-13870|-13859|-13847|-13831|-13658\"",
".",
"\"|-13611|-13601|-13406|-13404|-13400|-13398|-13395|-13391|-13387|-13383|-13367|-13359|-13356|-13343|-13340\"",
".",
"\"|-13329|-13326|-13318|-13147|-13138|-13120|-13107|-13096|-13095|-13091|-13076|-13068|-13063|-13060|-12888\"",
".",
"\"|-12875|-12871|-12860|-12858|-12852|-12849|-12838|-12831|-12829|-12812|-12802|-12607|-12597|-12594|-12585\"",
".",
"\"|-12556|-12359|-12346|-12320|-12300|-12120|-12099|-12089|-12074|-12067|-12058|-12039|-11867|-11861|-11847\"",
".",
"\"|-11831|-11798|-11781|-11604|-11589|-11536|-11358|-11340|-11339|-11324|-11303|-11097|-11077|-11067|-11055\"",
".",
"\"|-11052|-11045|-11041|-11038|-11024|-11020|-11019|-11018|-11014|-10838|-10832|-10815|-10800|-10790|-10780\"",
".",
"\"|-10764|-10587|-10544|-10533|-10519|-10331|-10329|-10328|-10322|-10315|-10309|-10307|-10296|-10281|-10274\"",
".",
"\"|-10270|-10262|-10260|-10256|-10254\"",
";",
"$",
"_TDataKey",
"=",
"explode",
"(",
"'|'",
",",
"$",
"_DataKey",
")",
";",
"$",
"_TDataValue",
"=",
"explode",
"(",
"'|'",
",",
"$",
"_DataValue",
")",
";",
"$",
"_Data",
"=",
"array_combine",
"(",
"$",
"_TDataKey",
",",
"$",
"_TDataValue",
")",
";",
"arsort",
"(",
"$",
"_Data",
")",
";",
"reset",
"(",
"$",
"_Data",
")",
";",
"if",
"(",
"$",
"_Code",
"!=",
"'gb2312'",
")",
"$",
"_String",
"=",
"self",
"::",
"_U2_Utf8_Gb",
"(",
"$",
"_String",
")",
";",
"$",
"_Res",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"strlen",
"(",
"$",
"_String",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"_P",
"=",
"ord",
"(",
"substr",
"(",
"$",
"_String",
",",
"$",
"i",
",",
"1",
")",
")",
";",
"if",
"(",
"$",
"_P",
">",
"160",
")",
"{",
"$",
"_Q",
"=",
"ord",
"(",
"substr",
"(",
"$",
"_String",
",",
"++",
"$",
"i",
",",
"1",
")",
")",
";",
"$",
"_P",
"=",
"$",
"_P",
"*",
"256",
"+",
"$",
"_Q",
"-",
"65536",
";",
"}",
"$",
"_Res",
".=",
"self",
"::",
"_Pinyin",
"(",
"$",
"_P",
",",
"$",
"_Data",
")",
";",
"}",
"return",
"preg_replace",
"(",
"\"/[^a-z0-9]*/\"",
",",
"''",
",",
"$",
"_Res",
")",
";",
"}"
] |
返回中文拼音
|
[
"返回中文拼音"
] |
train
|
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/libs/PinYin.php#L15-L80
|
wpottier/WizadSettingsBundle
|
DependencyInjection/ContainerInjectionManager.php
|
ContainerInjectionManager.inject
|
public function inject(ContainerBuilder $container)
{
foreach ($this->schema as $parameter) {
$value = $parameter['default'];
if ($this->parametersStorage->has($parameter['key'])) {
$value = $this->parametersStorage->get($parameter['key']);
}
$container->setParameter($this->getParametersName($parameter['key']), $this->protectParameterValue($value));
}
}
|
php
|
public function inject(ContainerBuilder $container)
{
foreach ($this->schema as $parameter) {
$value = $parameter['default'];
if ($this->parametersStorage->has($parameter['key'])) {
$value = $this->parametersStorage->get($parameter['key']);
}
$container->setParameter($this->getParametersName($parameter['key']), $this->protectParameterValue($value));
}
}
|
[
"public",
"function",
"inject",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"schema",
"as",
"$",
"parameter",
")",
"{",
"$",
"value",
"=",
"$",
"parameter",
"[",
"'default'",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"parametersStorage",
"->",
"has",
"(",
"$",
"parameter",
"[",
"'key'",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"parametersStorage",
"->",
"get",
"(",
"$",
"parameter",
"[",
"'key'",
"]",
")",
";",
"}",
"$",
"container",
"->",
"setParameter",
"(",
"$",
"this",
"->",
"getParametersName",
"(",
"$",
"parameter",
"[",
"'key'",
"]",
")",
",",
"$",
"this",
"->",
"protectParameterValue",
"(",
"$",
"value",
")",
")",
";",
"}",
"}"
] |
Inject dynamic parameters in the container builder
@param ContainerBuilder $container
|
[
"Inject",
"dynamic",
"parameters",
"in",
"the",
"container",
"builder"
] |
train
|
https://github.com/wpottier/WizadSettingsBundle/blob/92738c59d4da28d3a7376de854ce8505898159cb/DependencyInjection/ContainerInjectionManager.php#L39-L51
|
wpottier/WizadSettingsBundle
|
DependencyInjection/ContainerInjectionManager.php
|
ContainerInjectionManager.rebuild
|
public function rebuild(Kernel $kernel)
{
$kernelReflectionClass = new \ReflectionClass($kernel);
$buildContainerReflectionMethod = $kernelReflectionClass->getMethod('buildContainer');
$buildContainerReflectionMethod->setAccessible(true);
$dumpContainerReflectionMethod = $kernelReflectionClass->getMethod('dumpContainer');
$dumpContainerReflectionMethod->setAccessible(true);
$getContainerClassReflectionMethod = $kernelReflectionClass->getMethod('getContainerClass');
$getContainerClassReflectionMethod->setAccessible(true);
$getContainerBaseClassReflectionMethod = $kernelReflectionClass->getMethod('getContainerBaseClass');
$getContainerBaseClassReflectionMethod->setAccessible(true);
/** @var ContainerBuilder $newContainer */
$newContainer = $buildContainerReflectionMethod->invoke($kernel);
$this->inject($newContainer);
$newContainer->compile();
$class = $getContainerClassReflectionMethod->invoke($kernel);
$cache = new ConfigCache($kernel->getCacheDir() . '/' . $class . '.php', $kernel->isDebug());
$dumpContainerReflectionMethod->invoke($kernel, $cache, $newContainer, $class, $getContainerBaseClassReflectionMethod->invoke($kernel));
}
|
php
|
public function rebuild(Kernel $kernel)
{
$kernelReflectionClass = new \ReflectionClass($kernel);
$buildContainerReflectionMethod = $kernelReflectionClass->getMethod('buildContainer');
$buildContainerReflectionMethod->setAccessible(true);
$dumpContainerReflectionMethod = $kernelReflectionClass->getMethod('dumpContainer');
$dumpContainerReflectionMethod->setAccessible(true);
$getContainerClassReflectionMethod = $kernelReflectionClass->getMethod('getContainerClass');
$getContainerClassReflectionMethod->setAccessible(true);
$getContainerBaseClassReflectionMethod = $kernelReflectionClass->getMethod('getContainerBaseClass');
$getContainerBaseClassReflectionMethod->setAccessible(true);
/** @var ContainerBuilder $newContainer */
$newContainer = $buildContainerReflectionMethod->invoke($kernel);
$this->inject($newContainer);
$newContainer->compile();
$class = $getContainerClassReflectionMethod->invoke($kernel);
$cache = new ConfigCache($kernel->getCacheDir() . '/' . $class . '.php', $kernel->isDebug());
$dumpContainerReflectionMethod->invoke($kernel, $cache, $newContainer, $class, $getContainerBaseClassReflectionMethod->invoke($kernel));
}
|
[
"public",
"function",
"rebuild",
"(",
"Kernel",
"$",
"kernel",
")",
"{",
"$",
"kernelReflectionClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"kernel",
")",
";",
"$",
"buildContainerReflectionMethod",
"=",
"$",
"kernelReflectionClass",
"->",
"getMethod",
"(",
"'buildContainer'",
")",
";",
"$",
"buildContainerReflectionMethod",
"->",
"setAccessible",
"(",
"true",
")",
";",
"$",
"dumpContainerReflectionMethod",
"=",
"$",
"kernelReflectionClass",
"->",
"getMethod",
"(",
"'dumpContainer'",
")",
";",
"$",
"dumpContainerReflectionMethod",
"->",
"setAccessible",
"(",
"true",
")",
";",
"$",
"getContainerClassReflectionMethod",
"=",
"$",
"kernelReflectionClass",
"->",
"getMethod",
"(",
"'getContainerClass'",
")",
";",
"$",
"getContainerClassReflectionMethod",
"->",
"setAccessible",
"(",
"true",
")",
";",
"$",
"getContainerBaseClassReflectionMethod",
"=",
"$",
"kernelReflectionClass",
"->",
"getMethod",
"(",
"'getContainerBaseClass'",
")",
";",
"$",
"getContainerBaseClassReflectionMethod",
"->",
"setAccessible",
"(",
"true",
")",
";",
"/** @var ContainerBuilder $newContainer */",
"$",
"newContainer",
"=",
"$",
"buildContainerReflectionMethod",
"->",
"invoke",
"(",
"$",
"kernel",
")",
";",
"$",
"this",
"->",
"inject",
"(",
"$",
"newContainer",
")",
";",
"$",
"newContainer",
"->",
"compile",
"(",
")",
";",
"$",
"class",
"=",
"$",
"getContainerClassReflectionMethod",
"->",
"invoke",
"(",
"$",
"kernel",
")",
";",
"$",
"cache",
"=",
"new",
"ConfigCache",
"(",
"$",
"kernel",
"->",
"getCacheDir",
"(",
")",
".",
"'/'",
".",
"$",
"class",
".",
"'.php'",
",",
"$",
"kernel",
"->",
"isDebug",
"(",
")",
")",
";",
"$",
"dumpContainerReflectionMethod",
"->",
"invoke",
"(",
"$",
"kernel",
",",
"$",
"cache",
",",
"$",
"newContainer",
",",
"$",
"class",
",",
"$",
"getContainerBaseClassReflectionMethod",
"->",
"invoke",
"(",
"$",
"kernel",
")",
")",
";",
"}"
] |
Rebuild the container and dump it to the cache to apply change on redis stored parameters
|
[
"Rebuild",
"the",
"container",
"and",
"dump",
"it",
"to",
"the",
"cache",
"to",
"apply",
"change",
"on",
"redis",
"stored",
"parameters"
] |
train
|
https://github.com/wpottier/WizadSettingsBundle/blob/92738c59d4da28d3a7376de854ce8505898159cb/DependencyInjection/ContainerInjectionManager.php#L56-L82
|
Wonail/wocenter
|
helpers/StringHelper.php
|
StringHelper.parseIds
|
public static function parseIds($ids)
{
if (empty($ids)) {
return [];
}
// 转换数字ID和字符串形式ID串为数组
if (is_numeric($ids)) {
$ids = [$ids];
} else if (is_string($ids)) {
$ids = self::stringToArray($ids);
}
$id_array = array_unique(array_filter(array_map('intval', $ids)));
return 0 == count($id_array) ? [] : $id_array;
}
|
php
|
public static function parseIds($ids)
{
if (empty($ids)) {
return [];
}
// 转换数字ID和字符串形式ID串为数组
if (is_numeric($ids)) {
$ids = [$ids];
} else if (is_string($ids)) {
$ids = self::stringToArray($ids);
}
$id_array = array_unique(array_filter(array_map('intval', $ids)));
return 0 == count($id_array) ? [] : $id_array;
}
|
[
"public",
"static",
"function",
"parseIds",
"(",
"$",
"ids",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"ids",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"// 转换数字ID和字符串形式ID串为数组",
"if",
"(",
"is_numeric",
"(",
"$",
"ids",
")",
")",
"{",
"$",
"ids",
"=",
"[",
"$",
"ids",
"]",
";",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"ids",
")",
")",
"{",
"$",
"ids",
"=",
"self",
"::",
"stringToArray",
"(",
"$",
"ids",
")",
";",
"}",
"$",
"id_array",
"=",
"array_unique",
"(",
"array_filter",
"(",
"array_map",
"(",
"'intval'",
",",
"$",
"ids",
")",
")",
")",
";",
"return",
"0",
"==",
"count",
"(",
"$",
"id_array",
")",
"?",
"[",
"]",
":",
"$",
"id_array",
";",
"}"
] |
转换数字ID和字符串形式ID串为数组,并过滤重复和空的数据
@param mixed $ids 要格式化的字符串
@return array
|
[
"转换数字ID和字符串形式ID串为数组,并过滤重复和空的数据"
] |
train
|
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/helpers/StringHelper.php#L37-L53
|
Wonail/wocenter
|
helpers/StringHelper.php
|
StringHelper.parseString
|
public static function parseString($string)
{
$array = preg_split('/[,;\r\n]+/', trim($string, ",;\r\n"));
if (strpos($string, ':')) {
$value = [];
foreach ($array as $val) {
list($k, $v) = explode(':', $val);
$value[$k] = $v;
}
} else {
$value = $array;
}
return $value;
}
|
php
|
public static function parseString($string)
{
$array = preg_split('/[,;\r\n]+/', trim($string, ",;\r\n"));
if (strpos($string, ':')) {
$value = [];
foreach ($array as $val) {
list($k, $v) = explode(':', $val);
$value[$k] = $v;
}
} else {
$value = $array;
}
return $value;
}
|
[
"public",
"static",
"function",
"parseString",
"(",
"$",
"string",
")",
"{",
"$",
"array",
"=",
"preg_split",
"(",
"'/[,;\\r\\n]+/'",
",",
"trim",
"(",
"$",
"string",
",",
"\",;\\r\\n\"",
")",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"string",
",",
"':'",
")",
")",
"{",
"$",
"value",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"val",
")",
"{",
"list",
"(",
"$",
"k",
",",
"$",
"v",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"val",
")",
";",
"$",
"value",
"[",
"$",
"k",
"]",
"=",
"$",
"v",
";",
"}",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"array",
";",
"}",
"return",
"$",
"value",
";",
"}"
] |
解析[下拉框,单选框,多选框]类型额外配置值
格式:
1. 以英文逗号分隔。a:名称1,b:名称2
2. 以英文分号分隔。a:名称1;b:名称2;
3. 以回车换行分隔。
a:名称1
b:名称2
@param string $string 要解析的字符串
@return array
|
[
"解析",
"[",
"下拉框",
"单选框",
"多选框",
"]",
"类型额外配置值",
"格式",
":",
"1",
".",
"以英文逗号分隔。a",
":",
"名称1",
"b",
":",
"名称2",
"2",
".",
"以英文分号分隔。a",
":",
"名称1",
";",
"b",
":",
"名称2",
";",
"3",
".",
"以回车换行分隔。",
"a",
":",
"名称1",
"b",
":",
"名称2"
] |
train
|
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/helpers/StringHelper.php#L68-L82
|
Wonail/wocenter
|
helpers/StringHelper.php
|
StringHelper.getFirstLetter
|
public static function getFirstLetter($str)
{
$firstCharOrd = ord(strtoupper($str{0}));
if ($firstCharOrd >= 65 and $firstCharOrd <= 91) {
return strtoupper($str{0});
}
if ($firstCharOrd >= 48 and $firstCharOrd <= 57) {
return '#';
}
$s = iconv("UTF-8", "gb2312", $str);
$asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
if ($asc >= -20319 and $asc <= -20284)
return "A";
if ($asc >= -20283 and $asc <= -19776)
return "B";
if ($asc >= -19775 and $asc <= -19219)
return "C";
if ($asc >= -19218 and $asc <= -18711)
return "D";
if ($asc >= -18710 and $asc <= -18527)
return "E";
if ($asc >= -18526 and $asc <= -18240)
return "F";
if ($asc >= -18239 and $asc <= -17923)
return "G";
if ($asc >= -17922 and $asc <= -17418)
return "H";
if ($asc >= -17417 and $asc <= -16475)
return "J";
if ($asc >= -16474 and $asc <= -16213)
return "K";
if ($asc >= -16212 and $asc <= -15641)
return "L";
if ($asc >= -15640 and $asc <= -15166)
return "M";
if ($asc >= -15165 and $asc <= -14923)
return "N";
if ($asc >= -14922 and $asc <= -14915)
return "O";
if ($asc >= -14914 and $asc <= -14631)
return "P";
if ($asc >= -14630 and $asc <= -14150)
return "Q";
if ($asc >= -14149 and $asc <= -14091)
return "R";
if ($asc >= -14090 and $asc <= -13319)
return "S";
if ($asc >= -13318 and $asc <= -12839)
return "T";
if ($asc >= -12838 and $asc <= -12557)
return "W";
if ($asc >= -12556 and $asc <= -11848)
return "X";
if ($asc >= -11847 and $asc <= -11056)
return "Y";
if ($asc >= -11055 and $asc <= -10247)
return "Z";
return '#';
}
|
php
|
public static function getFirstLetter($str)
{
$firstCharOrd = ord(strtoupper($str{0}));
if ($firstCharOrd >= 65 and $firstCharOrd <= 91) {
return strtoupper($str{0});
}
if ($firstCharOrd >= 48 and $firstCharOrd <= 57) {
return '#';
}
$s = iconv("UTF-8", "gb2312", $str);
$asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
if ($asc >= -20319 and $asc <= -20284)
return "A";
if ($asc >= -20283 and $asc <= -19776)
return "B";
if ($asc >= -19775 and $asc <= -19219)
return "C";
if ($asc >= -19218 and $asc <= -18711)
return "D";
if ($asc >= -18710 and $asc <= -18527)
return "E";
if ($asc >= -18526 and $asc <= -18240)
return "F";
if ($asc >= -18239 and $asc <= -17923)
return "G";
if ($asc >= -17922 and $asc <= -17418)
return "H";
if ($asc >= -17417 and $asc <= -16475)
return "J";
if ($asc >= -16474 and $asc <= -16213)
return "K";
if ($asc >= -16212 and $asc <= -15641)
return "L";
if ($asc >= -15640 and $asc <= -15166)
return "M";
if ($asc >= -15165 and $asc <= -14923)
return "N";
if ($asc >= -14922 and $asc <= -14915)
return "O";
if ($asc >= -14914 and $asc <= -14631)
return "P";
if ($asc >= -14630 and $asc <= -14150)
return "Q";
if ($asc >= -14149 and $asc <= -14091)
return "R";
if ($asc >= -14090 and $asc <= -13319)
return "S";
if ($asc >= -13318 and $asc <= -12839)
return "T";
if ($asc >= -12838 and $asc <= -12557)
return "W";
if ($asc >= -12556 and $asc <= -11848)
return "X";
if ($asc >= -11847 and $asc <= -11056)
return "Y";
if ($asc >= -11055 and $asc <= -10247)
return "Z";
return '#';
}
|
[
"public",
"static",
"function",
"getFirstLetter",
"(",
"$",
"str",
")",
"{",
"$",
"firstCharOrd",
"=",
"ord",
"(",
"strtoupper",
"(",
"$",
"str",
"{",
"0",
"}",
")",
")",
";",
"if",
"(",
"$",
"firstCharOrd",
">=",
"65",
"and",
"$",
"firstCharOrd",
"<=",
"91",
")",
"{",
"return",
"strtoupper",
"(",
"$",
"str",
"{",
"0",
"}",
")",
";",
"}",
"if",
"(",
"$",
"firstCharOrd",
">=",
"48",
"and",
"$",
"firstCharOrd",
"<=",
"57",
")",
"{",
"return",
"'#'",
";",
"}",
"$",
"s",
"=",
"iconv",
"(",
"\"UTF-8\"",
",",
"\"gb2312\"",
",",
"$",
"str",
")",
";",
"$",
"asc",
"=",
"ord",
"(",
"$",
"s",
"{",
"0",
"}",
")",
"*",
"256",
"+",
"ord",
"(",
"$",
"s",
"{",
"1",
"}",
")",
"-",
"65536",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"20319",
"and",
"$",
"asc",
"<=",
"-",
"20284",
")",
"return",
"\"A\"",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"20283",
"and",
"$",
"asc",
"<=",
"-",
"19776",
")",
"return",
"\"B\"",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"19775",
"and",
"$",
"asc",
"<=",
"-",
"19219",
")",
"return",
"\"C\"",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"19218",
"and",
"$",
"asc",
"<=",
"-",
"18711",
")",
"return",
"\"D\"",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"18710",
"and",
"$",
"asc",
"<=",
"-",
"18527",
")",
"return",
"\"E\"",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"18526",
"and",
"$",
"asc",
"<=",
"-",
"18240",
")",
"return",
"\"F\"",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"18239",
"and",
"$",
"asc",
"<=",
"-",
"17923",
")",
"return",
"\"G\"",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"17922",
"and",
"$",
"asc",
"<=",
"-",
"17418",
")",
"return",
"\"H\"",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"17417",
"and",
"$",
"asc",
"<=",
"-",
"16475",
")",
"return",
"\"J\"",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"16474",
"and",
"$",
"asc",
"<=",
"-",
"16213",
")",
"return",
"\"K\"",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"16212",
"and",
"$",
"asc",
"<=",
"-",
"15641",
")",
"return",
"\"L\"",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"15640",
"and",
"$",
"asc",
"<=",
"-",
"15166",
")",
"return",
"\"M\"",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"15165",
"and",
"$",
"asc",
"<=",
"-",
"14923",
")",
"return",
"\"N\"",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"14922",
"and",
"$",
"asc",
"<=",
"-",
"14915",
")",
"return",
"\"O\"",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"14914",
"and",
"$",
"asc",
"<=",
"-",
"14631",
")",
"return",
"\"P\"",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"14630",
"and",
"$",
"asc",
"<=",
"-",
"14150",
")",
"return",
"\"Q\"",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"14149",
"and",
"$",
"asc",
"<=",
"-",
"14091",
")",
"return",
"\"R\"",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"14090",
"and",
"$",
"asc",
"<=",
"-",
"13319",
")",
"return",
"\"S\"",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"13318",
"and",
"$",
"asc",
"<=",
"-",
"12839",
")",
"return",
"\"T\"",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"12838",
"and",
"$",
"asc",
"<=",
"-",
"12557",
")",
"return",
"\"W\"",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"12556",
"and",
"$",
"asc",
"<=",
"-",
"11848",
")",
"return",
"\"X\"",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"11847",
"and",
"$",
"asc",
"<=",
"-",
"11056",
")",
"return",
"\"Y\"",
";",
"if",
"(",
"$",
"asc",
">=",
"-",
"11055",
"and",
"$",
"asc",
"<=",
"-",
"10247",
")",
"return",
"\"Z\"",
";",
"return",
"'#'",
";",
"}"
] |
获取字符串首字母
@param $str
@return string
|
[
"获取字符串首字母"
] |
train
|
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/helpers/StringHelper.php#L91-L150
|
Wonail/wocenter
|
helpers/StringHelper.php
|
StringHelper.mbSubstr
|
public static function mbSubstr($str, $start = 0, $length = 5, $charset = "utf-8", $suffix = true)
{
if (function_exists("mb_substr")) {
$slice = mb_substr($str, $start, $length, $charset);
} elseif (function_exists('iconv_substr')) {
$slice = iconv_substr($str, $start, $length, $charset);
} else {
$re['utf-8'] = "/[x01-x7f]|[xc2-xdf][x80-xbf]|[xe0-xef][x80-xbf]{2}|[xf0-xff][x80-xbf]{3}/";
$re['gb2312'] = "/[x01-x7f]|[xb0-xf7][xa0-xfe]/";
$re['gbk'] = "/[x01-x7f]|[x81-xfe][x40-xfe]/";
$re['big5'] = "/[x01-x7f]|[x81-xfe]([x40-x7e]|xa1-xfe])/";
preg_match_all($re[$charset], $str, $match);
$slice = join("", array_slice($match[0], $start, $length));
}
$fix = '';
if (strlen($slice) < strlen($str)) {
$fix = '...';
}
return $suffix ? $slice . $fix : $slice;
}
|
php
|
public static function mbSubstr($str, $start = 0, $length = 5, $charset = "utf-8", $suffix = true)
{
if (function_exists("mb_substr")) {
$slice = mb_substr($str, $start, $length, $charset);
} elseif (function_exists('iconv_substr')) {
$slice = iconv_substr($str, $start, $length, $charset);
} else {
$re['utf-8'] = "/[x01-x7f]|[xc2-xdf][x80-xbf]|[xe0-xef][x80-xbf]{2}|[xf0-xff][x80-xbf]{3}/";
$re['gb2312'] = "/[x01-x7f]|[xb0-xf7][xa0-xfe]/";
$re['gbk'] = "/[x01-x7f]|[x81-xfe][x40-xfe]/";
$re['big5'] = "/[x01-x7f]|[x81-xfe]([x40-x7e]|xa1-xfe])/";
preg_match_all($re[$charset], $str, $match);
$slice = join("", array_slice($match[0], $start, $length));
}
$fix = '';
if (strlen($slice) < strlen($str)) {
$fix = '...';
}
return $suffix ? $slice . $fix : $slice;
}
|
[
"public",
"static",
"function",
"mbSubstr",
"(",
"$",
"str",
",",
"$",
"start",
"=",
"0",
",",
"$",
"length",
"=",
"5",
",",
"$",
"charset",
"=",
"\"utf-8\"",
",",
"$",
"suffix",
"=",
"true",
")",
"{",
"if",
"(",
"function_exists",
"(",
"\"mb_substr\"",
")",
")",
"{",
"$",
"slice",
"=",
"mb_substr",
"(",
"$",
"str",
",",
"$",
"start",
",",
"$",
"length",
",",
"$",
"charset",
")",
";",
"}",
"elseif",
"(",
"function_exists",
"(",
"'iconv_substr'",
")",
")",
"{",
"$",
"slice",
"=",
"iconv_substr",
"(",
"$",
"str",
",",
"$",
"start",
",",
"$",
"length",
",",
"$",
"charset",
")",
";",
"}",
"else",
"{",
"$",
"re",
"[",
"'utf-8'",
"]",
"=",
"\"/[x01-x7f]|[xc2-xdf][x80-xbf]|[xe0-xef][x80-xbf]{2}|[xf0-xff][x80-xbf]{3}/\"",
";",
"$",
"re",
"[",
"'gb2312'",
"]",
"=",
"\"/[x01-x7f]|[xb0-xf7][xa0-xfe]/\"",
";",
"$",
"re",
"[",
"'gbk'",
"]",
"=",
"\"/[x01-x7f]|[x81-xfe][x40-xfe]/\"",
";",
"$",
"re",
"[",
"'big5'",
"]",
"=",
"\"/[x01-x7f]|[x81-xfe]([x40-x7e]|xa1-xfe])/\"",
";",
"preg_match_all",
"(",
"$",
"re",
"[",
"$",
"charset",
"]",
",",
"$",
"str",
",",
"$",
"match",
")",
";",
"$",
"slice",
"=",
"join",
"(",
"\"\"",
",",
"array_slice",
"(",
"$",
"match",
"[",
"0",
"]",
",",
"$",
"start",
",",
"$",
"length",
")",
")",
";",
"}",
"$",
"fix",
"=",
"''",
";",
"if",
"(",
"strlen",
"(",
"$",
"slice",
")",
"<",
"strlen",
"(",
"$",
"str",
")",
")",
"{",
"$",
"fix",
"=",
"'...'",
";",
"}",
"return",
"$",
"suffix",
"?",
"$",
"slice",
".",
"$",
"fix",
":",
"$",
"slice",
";",
"}"
] |
截取中文字符串
@param string $str 需要截取的字符串
@param integer $start 开始查询的下标
@param integer $length 截取长度
@param string $charset 字符串编码
@param boolean $suffix 超出部分是否显示省略号
@return string
|
[
"截取中文字符串"
] |
train
|
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/helpers/StringHelper.php#L163-L183
|
Wonail/wocenter
|
helpers/StringHelper.php
|
StringHelper.randString
|
public static function randString($len = 6, $type = Constants::UNLIMITED, $addChars = '')
{
$str = '';
switch ($type) {
case 0:
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' . $addChars;
break;
case 1:
$chars = str_repeat('0123456789', 3);
break;
case 2:
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . $addChars;
break;
case 3:
$chars = 'abcdefghijklmnopqrstuvwxyz' . $addChars;
break;
case 4:
$chars = "们以我到他会作时要动国产的一是工就年阶义发成部民可出能方进在了不和有大这主中人上为来分生对于学下级地个用同行面说种过命度革而多子后自社加小机也经力线本电高量长党得实家定深法表着水理化争现所二起政三好十战无农使性前等反体合斗路图把结第里正新开论之物从当两些还天资事队批点育重其思与间内去因件日利相由压员气业代全组数果期导平各基或月毛然如应形想制心样干都向变关问比展那它最及外没看治提五解系林者米群头意只明四道马认次文通但条较克又公孔领军流入接席位情运器并飞原油放立题质指建区验活众很教决特此常石强极土少已根共直团统式转别造切九你取西持总料连任志观调七么山程百报更见必真保热委手改管处己将修支识病象几先老光专什六型具示复安带每东增则完风回南广劳轮科北打积车计给节做务被整联步类集号列温装即毫知轴研单色坚据速防史拉世设达尔场织历花受求传口断况采精金界品判参层止边清至万确究书术状厂须离再目海交权且儿青才证低越际八试规斯近注办布门铁需走议县兵固除般引齿千胜细影济白格效置推空配刀叶率述今选养德话查差半敌始片施响收华觉备名红续均药标记难存测士身紧液派准斤角降维板许破述技消底床田势端感往神便贺村构照容非搞亚磨族火段算适讲按值美态黄易彪服早班麦削信排台声该击素张密害侯草何树肥继右属市严径螺检左页抗苏显苦英快称坏移约巴材省黑武培著河帝仅针怎植京助升王眼她抓含苗副杂普谈围食射源例致酸旧却充足短划剂宣环落首尺波承粉践府鱼随考刻靠够满夫失包住促枝局菌杆周护岩师举曲春元超负砂封换太模贫减阳扬江析亩木言球朝医校古呢稻宋听唯输滑站另卫字鼓刚写刘微略范供阿块某功套友限项余倒卷创律雨让骨远帮初皮播优占死毒圈伟季训控激找叫云互跟裂粮粒母练塞钢顶策双留误础吸阻故寸盾晚丝女散焊功株亲院冷彻弹错散商视艺灭版烈零室轻血倍缺厘泵察绝富城冲喷壤简否柱李望盘磁雄似困巩益洲脱投送奴侧润盖挥距触星松送获兴独官混纪依未突架宽冬章湿偏纹吃执阀矿寨责熟稳夺硬价努翻奇甲预职评读背协损棉侵灰虽矛厚罗泥辟告卵箱掌氧恩爱停曾溶营终纲孟钱待尽俄缩沙退陈讨奋械载胞幼哪剥迫旋征槽倒握担仍呀鲜吧卡粗介钻逐弱脚怕盐末阴丰雾冠丙街莱贝辐肠付吉渗瑞惊顿挤秒悬姆烂森糖圣凹陶词迟蚕亿矩康遵牧遭幅园腔订香肉弟屋敏恢忘编印蜂急拿扩伤飞露核缘游振操央伍域甚迅辉异序免纸夜乡久隶缸夹念兰映沟乙吗儒杀汽磷艰晶插埃燃欢铁补咱芽永瓦倾阵碳演威附牙芽永瓦斜灌欧献顺猪洋腐请透司危括脉宜笑若尾束壮暴企菜穗楚汉愈绿拖牛份染既秋遍锻玉夏疗尖殖井费州访吹荣铜沿替滚客召旱悟刺脑措贯藏敢令隙炉壳硫煤迎铸粘探临薄旬善福纵择礼愿伏残雷延烟句纯渐耕跑泽慢栽鲁赤繁境潮横掉锥希池败船假亮谓托伙哲怀割摆贡呈劲财仪沉炼麻罪祖息车穿货销齐鼠抽画饲龙库守筑房歌寒喜哥洗蚀废纳腹乎录镜妇恶脂庄擦险赞钟摇典柄辩竹谷卖乱虚桥奥伯赶垂途额壁网截野遗静谋弄挂课镇妄盛耐援扎虑键归符庆聚绕摩忙舞遇索顾胶羊湖钉仁音迹碎伸灯避泛亡答勇频皇柳哈揭甘诺概宪浓岛袭谁洪谢炮浇斑讯懂灵蛋闭孩释乳巨徒私银伊景坦累匀霉杜乐勒隔弯绩招绍胡呼痛峰零柴簧午跳居尚丁秦稍追梁折耗碱殊岗挖氏刃剧堆赫荷胸衡勤膜篇登驻案刊秧缓凸役剪川雪链渔啦脸户洛孢勃盟买杨宗焦赛旗滤硅炭股坐蒸凝竟陷枪黎救冒暗洞犯筒您宋弧爆谬涂味津臂障褐陆啊健尊豆拔莫抵桑坡缝警挑污冰柬嘴啥饭塑寄赵喊垫丹渡耳刨虎笔稀昆浪萨茶滴浅拥穴覆伦娘吨浸袖珠雌妈紫戏塔锤震岁貌洁剖牢锋疑霸闪埔猛诉刷狠忽灾闹乔唐漏闻沈熔氯荒茎男凡抢像浆旁玻亦忠唱蒙予纷捕锁尤乘乌智淡允叛畜俘摸锈扫毕璃宝芯爷鉴秘净蒋钙肩腾枯抛轨堂拌爸循诱祝励肯酒绳穷塘燥泡袋朗喂铝软渠颗惯贸粪综墙趋彼届墨碍启逆卸航衣孙龄岭骗休借" . $addChars;
break;
default :
// 默认去掉了容易混淆的字符oOLl和数字01,要添加请使用addChars参数
$chars = 'ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789' . $addChars;
break;
}
if ($len > 10) {//位数过长重复字符串一定次数
$chars = $type == 1 ? str_repeat($chars, $len) : str_repeat($chars, 5);
}
if ($type != 4) {
$chars = str_shuffle($chars);
$str = substr($chars, 0, $len);
} else {
// 中文随机字
for ($i = 0; $i < $len; $i++) {
$str .= self::mbSubstr($chars, floor(mt_rand(0, mb_strlen($chars, 'utf-8') - 1)), 1, 'utf-8', false);
}
}
return $str;
}
|
php
|
public static function randString($len = 6, $type = Constants::UNLIMITED, $addChars = '')
{
$str = '';
switch ($type) {
case 0:
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' . $addChars;
break;
case 1:
$chars = str_repeat('0123456789', 3);
break;
case 2:
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . $addChars;
break;
case 3:
$chars = 'abcdefghijklmnopqrstuvwxyz' . $addChars;
break;
case 4:
$chars = "们以我到他会作时要动国产的一是工就年阶义发成部民可出能方进在了不和有大这主中人上为来分生对于学下级地个用同行面说种过命度革而多子后自社加小机也经力线本电高量长党得实家定深法表着水理化争现所二起政三好十战无农使性前等反体合斗路图把结第里正新开论之物从当两些还天资事队批点育重其思与间内去因件日利相由压员气业代全组数果期导平各基或月毛然如应形想制心样干都向变关问比展那它最及外没看治提五解系林者米群头意只明四道马认次文通但条较克又公孔领军流入接席位情运器并飞原油放立题质指建区验活众很教决特此常石强极土少已根共直团统式转别造切九你取西持总料连任志观调七么山程百报更见必真保热委手改管处己将修支识病象几先老光专什六型具示复安带每东增则完风回南广劳轮科北打积车计给节做务被整联步类集号列温装即毫知轴研单色坚据速防史拉世设达尔场织历花受求传口断况采精金界品判参层止边清至万确究书术状厂须离再目海交权且儿青才证低越际八试规斯近注办布门铁需走议县兵固除般引齿千胜细影济白格效置推空配刀叶率述今选养德话查差半敌始片施响收华觉备名红续均药标记难存测士身紧液派准斤角降维板许破述技消底床田势端感往神便贺村构照容非搞亚磨族火段算适讲按值美态黄易彪服早班麦削信排台声该击素张密害侯草何树肥继右属市严径螺检左页抗苏显苦英快称坏移约巴材省黑武培著河帝仅针怎植京助升王眼她抓含苗副杂普谈围食射源例致酸旧却充足短划剂宣环落首尺波承粉践府鱼随考刻靠够满夫失包住促枝局菌杆周护岩师举曲春元超负砂封换太模贫减阳扬江析亩木言球朝医校古呢稻宋听唯输滑站另卫字鼓刚写刘微略范供阿块某功套友限项余倒卷创律雨让骨远帮初皮播优占死毒圈伟季训控激找叫云互跟裂粮粒母练塞钢顶策双留误础吸阻故寸盾晚丝女散焊功株亲院冷彻弹错散商视艺灭版烈零室轻血倍缺厘泵察绝富城冲喷壤简否柱李望盘磁雄似困巩益洲脱投送奴侧润盖挥距触星松送获兴独官混纪依未突架宽冬章湿偏纹吃执阀矿寨责熟稳夺硬价努翻奇甲预职评读背协损棉侵灰虽矛厚罗泥辟告卵箱掌氧恩爱停曾溶营终纲孟钱待尽俄缩沙退陈讨奋械载胞幼哪剥迫旋征槽倒握担仍呀鲜吧卡粗介钻逐弱脚怕盐末阴丰雾冠丙街莱贝辐肠付吉渗瑞惊顿挤秒悬姆烂森糖圣凹陶词迟蚕亿矩康遵牧遭幅园腔订香肉弟屋敏恢忘编印蜂急拿扩伤飞露核缘游振操央伍域甚迅辉异序免纸夜乡久隶缸夹念兰映沟乙吗儒杀汽磷艰晶插埃燃欢铁补咱芽永瓦倾阵碳演威附牙芽永瓦斜灌欧献顺猪洋腐请透司危括脉宜笑若尾束壮暴企菜穗楚汉愈绿拖牛份染既秋遍锻玉夏疗尖殖井费州访吹荣铜沿替滚客召旱悟刺脑措贯藏敢令隙炉壳硫煤迎铸粘探临薄旬善福纵择礼愿伏残雷延烟句纯渐耕跑泽慢栽鲁赤繁境潮横掉锥希池败船假亮谓托伙哲怀割摆贡呈劲财仪沉炼麻罪祖息车穿货销齐鼠抽画饲龙库守筑房歌寒喜哥洗蚀废纳腹乎录镜妇恶脂庄擦险赞钟摇典柄辩竹谷卖乱虚桥奥伯赶垂途额壁网截野遗静谋弄挂课镇妄盛耐援扎虑键归符庆聚绕摩忙舞遇索顾胶羊湖钉仁音迹碎伸灯避泛亡答勇频皇柳哈揭甘诺概宪浓岛袭谁洪谢炮浇斑讯懂灵蛋闭孩释乳巨徒私银伊景坦累匀霉杜乐勒隔弯绩招绍胡呼痛峰零柴簧午跳居尚丁秦稍追梁折耗碱殊岗挖氏刃剧堆赫荷胸衡勤膜篇登驻案刊秧缓凸役剪川雪链渔啦脸户洛孢勃盟买杨宗焦赛旗滤硅炭股坐蒸凝竟陷枪黎救冒暗洞犯筒您宋弧爆谬涂味津臂障褐陆啊健尊豆拔莫抵桑坡缝警挑污冰柬嘴啥饭塑寄赵喊垫丹渡耳刨虎笔稀昆浪萨茶滴浅拥穴覆伦娘吨浸袖珠雌妈紫戏塔锤震岁貌洁剖牢锋疑霸闪埔猛诉刷狠忽灾闹乔唐漏闻沈熔氯荒茎男凡抢像浆旁玻亦忠唱蒙予纷捕锁尤乘乌智淡允叛畜俘摸锈扫毕璃宝芯爷鉴秘净蒋钙肩腾枯抛轨堂拌爸循诱祝励肯酒绳穷塘燥泡袋朗喂铝软渠颗惯贸粪综墙趋彼届墨碍启逆卸航衣孙龄岭骗休借" . $addChars;
break;
default :
// 默认去掉了容易混淆的字符oOLl和数字01,要添加请使用addChars参数
$chars = 'ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789' . $addChars;
break;
}
if ($len > 10) {//位数过长重复字符串一定次数
$chars = $type == 1 ? str_repeat($chars, $len) : str_repeat($chars, 5);
}
if ($type != 4) {
$chars = str_shuffle($chars);
$str = substr($chars, 0, $len);
} else {
// 中文随机字
for ($i = 0; $i < $len; $i++) {
$str .= self::mbSubstr($chars, floor(mt_rand(0, mb_strlen($chars, 'utf-8') - 1)), 1, 'utf-8', false);
}
}
return $str;
}
|
[
"public",
"static",
"function",
"randString",
"(",
"$",
"len",
"=",
"6",
",",
"$",
"type",
"=",
"Constants",
"::",
"UNLIMITED",
",",
"$",
"addChars",
"=",
"''",
")",
"{",
"$",
"str",
"=",
"''",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"0",
":",
"$",
"chars",
"=",
"'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'",
".",
"$",
"addChars",
";",
"break",
";",
"case",
"1",
":",
"$",
"chars",
"=",
"str_repeat",
"(",
"'0123456789'",
",",
"3",
")",
";",
"break",
";",
"case",
"2",
":",
"$",
"chars",
"=",
"'ABCDEFGHIJKLMNOPQRSTUVWXYZ'",
".",
"$",
"addChars",
";",
"break",
";",
"case",
"3",
":",
"$",
"chars",
"=",
"'abcdefghijklmnopqrstuvwxyz'",
".",
"$",
"addChars",
";",
"break",
";",
"case",
"4",
":",
"$",
"chars",
"=",
"\"们以我到他会作时要动国产的一是工就年阶义发成部民可出能方进在了不和有大这主中人上为来分生对于学下级地个用同行面说种过命度革而多子后自社加小机也经力线本电高量长党得实家定深法表着水理化争现所二起政三好十战无农使性前等反体合斗路图把结第里正新开论之物从当两些还天资事队批点育重其思与间内去因件日利相由压员气业代全组数果期导平各基或月毛然如应形想制心样干都向变关问比展那它最及外没看治提五解系林者米群头意只明四道马认次文通但条较克又公孔领军流入接席位情运器并飞原油放立题质指建区验活众很教决特此常石强极土少已根共直团统式转别造切九你取西持总料连任志观调七么山程百报更见必真保热委手改管处己将修支识病象几先老光专什六型具示复安带每东增则完风回南广劳轮科北打积车计给节做务被整联步类集号列温装即毫知轴研单色坚据速防史拉世设达尔场织历花受求传口断况采精金界品判参层止边清至万确究书术状厂须离再目海交权且儿青才证低越际八试规斯近注办布门铁需走议县兵固除般引齿千胜细影济白格效置推空配刀叶率述今选养德话查差半敌始片施响收华觉备名红续均药标记难存测士身紧液派准斤角降维板许破述技消底床田势端感往神便贺村构照容非搞亚磨族火段算适讲按值美态黄易彪服早班麦削信排台声该击素张密害侯草何树肥继右属市严径螺检左页抗苏显苦英快称坏移约巴材省黑武培著河帝仅针怎植京助升王眼她抓含苗副杂普谈围食射源例致酸旧却充足短划剂宣环落首尺波承粉践府鱼随考刻靠够满夫失包住促枝局菌杆周护岩师举曲春元超负砂封换太模贫减阳扬江析亩木言球朝医校古呢稻宋听唯输滑站另卫字鼓刚写刘微略范供阿块某功套友限项余倒卷创律雨让骨远帮初皮播优占死毒圈伟季训控激找叫云互跟裂粮粒母练塞钢顶策双留误础吸阻故寸盾晚丝女散焊功株亲院冷彻弹错散商视艺灭版烈零室轻血倍缺厘泵察绝富城冲喷壤简否柱李望盘磁雄似困巩益洲脱投送奴侧润盖挥距触星松送获兴独官混纪依未突架宽冬章湿偏纹吃执阀矿寨责熟稳夺硬价努翻奇甲预职评读背协损棉侵灰虽矛厚罗泥辟告卵箱掌氧恩爱停曾溶营终纲孟钱待尽俄缩沙退陈讨奋械载胞幼哪剥迫旋征槽倒握担仍呀鲜吧卡粗介钻逐弱脚怕盐末阴丰雾冠丙街莱贝辐肠付吉渗瑞惊顿挤秒悬姆烂森糖圣凹陶词迟蚕亿矩康遵牧遭幅园腔订香肉弟屋敏恢忘编印蜂急拿扩伤飞露核缘游振操央伍域甚迅辉异序免纸夜乡久隶缸夹念兰映沟乙吗儒杀汽磷艰晶插埃燃欢铁补咱芽永瓦倾阵碳演威附牙芽永瓦斜灌欧献顺猪洋腐请透司危括脉宜笑若尾束壮暴企菜穗楚汉愈绿拖牛份染既秋遍锻玉夏疗尖殖井费州访吹荣铜沿替滚客召旱悟刺脑措贯藏敢令隙炉壳硫煤迎铸粘探临薄旬善福纵择礼愿伏残雷延烟句纯渐耕跑泽慢栽鲁赤繁境潮横掉锥希池败船假亮谓托伙哲怀割摆贡呈劲财仪沉炼麻罪祖息车穿货销齐鼠抽画饲龙库守筑房歌寒喜哥洗蚀废纳腹乎录镜妇恶脂庄擦险赞钟摇典柄辩竹谷卖乱虚桥奥伯赶垂途额壁网截野遗静谋弄挂课镇妄盛耐援扎虑键归符庆聚绕摩忙舞遇索顾胶羊湖钉仁音迹碎伸灯避泛亡答勇频皇柳哈揭甘诺概宪浓岛袭谁洪谢炮浇斑讯懂灵蛋闭孩释乳巨徒私银伊景坦累匀霉杜乐勒隔弯绩招绍胡呼痛峰零柴簧午跳居尚丁秦稍追梁折耗碱殊岗挖氏刃剧堆赫荷胸衡勤膜篇登驻案刊秧缓凸役剪川雪链渔啦脸户洛孢勃盟买杨宗焦赛旗滤硅炭股坐蒸凝竟陷枪黎救冒暗洞犯筒您宋弧爆谬涂味津臂障褐陆啊健尊豆拔莫抵桑坡缝警挑污冰柬嘴啥饭塑寄赵喊垫丹渡耳刨虎笔稀昆浪萨茶滴浅拥穴覆伦娘吨浸袖珠雌妈紫戏塔锤震岁貌洁剖牢锋疑霸闪埔猛诉刷狠忽灾闹乔唐漏闻沈熔氯荒茎男凡抢像浆旁玻亦忠唱蒙予纷捕锁尤乘乌智淡允叛畜俘摸锈扫毕璃宝芯爷鉴秘净蒋钙肩腾枯抛轨堂拌爸循诱祝励肯酒绳穷塘燥泡袋朗喂铝软渠颗惯贸粪综墙趋彼届墨碍启逆卸航衣孙龄岭骗休借\" . $addChars;",
"",
"",
"",
"",
"break",
";",
"default",
":",
"// 默认去掉了容易混淆的字符oOLl和数字01,要添加请使用addChars参数",
"$",
"chars",
"=",
"'ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789'",
".",
"$",
"addChars",
";",
"break",
";",
"}",
"if",
"(",
"$",
"len",
">",
"10",
")",
"{",
"//位数过长重复字符串一定次数",
"$",
"chars",
"=",
"$",
"type",
"==",
"1",
"?",
"str_repeat",
"(",
"$",
"chars",
",",
"$",
"len",
")",
":",
"str_repeat",
"(",
"$",
"chars",
",",
"5",
")",
";",
"}",
"if",
"(",
"$",
"type",
"!=",
"4",
")",
"{",
"$",
"chars",
"=",
"str_shuffle",
"(",
"$",
"chars",
")",
";",
"$",
"str",
"=",
"substr",
"(",
"$",
"chars",
",",
"0",
",",
"$",
"len",
")",
";",
"}",
"else",
"{",
"// 中文随机字",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"len",
";",
"$",
"i",
"++",
")",
"{",
"$",
"str",
".=",
"self",
"::",
"mbSubstr",
"(",
"$",
"chars",
",",
"floor",
"(",
"mt_rand",
"(",
"0",
",",
"mb_strlen",
"(",
"$",
"chars",
",",
"'utf-8'",
")",
"-",
"1",
")",
")",
",",
"1",
",",
"'utf-8'",
",",
"false",
")",
";",
"}",
"}",
"return",
"$",
"str",
";",
"}"
] |
产生随机字串,可用来自动生成密码
默认长度6位 字母和数字混合 支持中文
@param integer $len 长度
@param integer $type 字串类型,默认去掉了容易混淆的字符oOLl和数字01,要添加请使用addChars参数
0 - 所有字母,包括大小写
1 - 数字
2 - 大写字母
3 - 小写字母
4 - 中文
默认 - 混合,默认去掉了容易混淆的字符oOLl和数字01,要添加请使用addChars参数
@param string $addChars 额外字符
@return string
|
[
"产生随机字串,可用来自动生成密码",
"默认长度6位",
"字母和数字混合",
"支持中文"
] |
train
|
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/helpers/StringHelper.php#L243-L281
|
Wonail/wocenter
|
helpers/StringHelper.php
|
StringHelper.buildCountRand
|
public static function buildCountRand($number, $length = 4, $type = Constants::UNLIMITED)
{
if ($type == 1 && $length < strlen($number)) {
//不足以生成一定数量的不重复数字
return false;
}
$rand = [];
for ($i = 0; $i < $number; $i++) {
$rand[] = self::randString($length, $type);
}
$unique = array_unique($rand);
if (count($unique) == count($rand)) {
return $rand;
}
$count = count($rand) - count($unique);
for ($i = 0; $i < $count * 3; $i++) {
$rand[] = self::randString($length, $type);
}
$rand = array_slice(array_unique($rand), 0, $number);
return $rand;
}
|
php
|
public static function buildCountRand($number, $length = 4, $type = Constants::UNLIMITED)
{
if ($type == 1 && $length < strlen($number)) {
//不足以生成一定数量的不重复数字
return false;
}
$rand = [];
for ($i = 0; $i < $number; $i++) {
$rand[] = self::randString($length, $type);
}
$unique = array_unique($rand);
if (count($unique) == count($rand)) {
return $rand;
}
$count = count($rand) - count($unique);
for ($i = 0; $i < $count * 3; $i++) {
$rand[] = self::randString($length, $type);
}
$rand = array_slice(array_unique($rand), 0, $number);
return $rand;
}
|
[
"public",
"static",
"function",
"buildCountRand",
"(",
"$",
"number",
",",
"$",
"length",
"=",
"4",
",",
"$",
"type",
"=",
"Constants",
"::",
"UNLIMITED",
")",
"{",
"if",
"(",
"$",
"type",
"==",
"1",
"&&",
"$",
"length",
"<",
"strlen",
"(",
"$",
"number",
")",
")",
"{",
"//不足以生成一定数量的不重复数字",
"return",
"false",
";",
"}",
"$",
"rand",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"number",
";",
"$",
"i",
"++",
")",
"{",
"$",
"rand",
"[",
"]",
"=",
"self",
"::",
"randString",
"(",
"$",
"length",
",",
"$",
"type",
")",
";",
"}",
"$",
"unique",
"=",
"array_unique",
"(",
"$",
"rand",
")",
";",
"if",
"(",
"count",
"(",
"$",
"unique",
")",
"==",
"count",
"(",
"$",
"rand",
")",
")",
"{",
"return",
"$",
"rand",
";",
"}",
"$",
"count",
"=",
"count",
"(",
"$",
"rand",
")",
"-",
"count",
"(",
"$",
"unique",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"count",
"*",
"3",
";",
"$",
"i",
"++",
")",
"{",
"$",
"rand",
"[",
"]",
"=",
"self",
"::",
"randString",
"(",
"$",
"length",
",",
"$",
"type",
")",
";",
"}",
"$",
"rand",
"=",
"array_slice",
"(",
"array_unique",
"(",
"$",
"rand",
")",
",",
"0",
",",
"$",
"number",
")",
";",
"return",
"$",
"rand",
";",
"}"
] |
生成一定数量的随机数,并且不重复
@param integer $number 数量
@param integer $length 长度
@param integer $type 字串类型,默认去掉了容易混淆的字符oOLl和数字01,要添加请使用addChars参数
0 - 所有字母,包括大小写
1 - 数字
2 - 大写字母
3 - 小写字母
4 - 中文
默认 - 混合,默认去掉了容易混淆的字符oOLl和数字01,要添加请使用addChars参数
@return bool|array
|
[
"生成一定数量的随机数,并且不重复"
] |
train
|
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/helpers/StringHelper.php#L298-L319
|
Wonail/wocenter
|
helpers/StringHelper.php
|
StringHelper.autoCharset
|
public static function autoCharset($string, $from = 'gbk', $to = 'utf-8')
{
$from = strtoupper($from) == 'UTF8' ? 'utf-8' : $from;
$to = strtoupper($to) == 'UTF8' ? 'utf-8' : $to;
if (strtoupper($from) === strtoupper($to) || empty($string) || (is_scalar($string) && !is_string($string))) {
//如果编码相同或者非字符串标量则不转换
return $string;
}
if (is_string($string)) {
if (function_exists('mb_convert_encoding')) {
return mb_convert_encoding($string, $to, $from);
} elseif (function_exists('iconv')) {
return iconv($from, $to, $string);
} else {
return $string;
}
} elseif (is_array($string)) {
foreach ($string as $key => $val) {
$_key = self::autoCharset($key, $from, $to);
$string[$_key] = self::autoCharset($val, $from, $to);
if ($key != $_key)
unset($string[$key]);
}
return $string;
} else {
return $string;
}
}
|
php
|
public static function autoCharset($string, $from = 'gbk', $to = 'utf-8')
{
$from = strtoupper($from) == 'UTF8' ? 'utf-8' : $from;
$to = strtoupper($to) == 'UTF8' ? 'utf-8' : $to;
if (strtoupper($from) === strtoupper($to) || empty($string) || (is_scalar($string) && !is_string($string))) {
//如果编码相同或者非字符串标量则不转换
return $string;
}
if (is_string($string)) {
if (function_exists('mb_convert_encoding')) {
return mb_convert_encoding($string, $to, $from);
} elseif (function_exists('iconv')) {
return iconv($from, $to, $string);
} else {
return $string;
}
} elseif (is_array($string)) {
foreach ($string as $key => $val) {
$_key = self::autoCharset($key, $from, $to);
$string[$_key] = self::autoCharset($val, $from, $to);
if ($key != $_key)
unset($string[$key]);
}
return $string;
} else {
return $string;
}
}
|
[
"public",
"static",
"function",
"autoCharset",
"(",
"$",
"string",
",",
"$",
"from",
"=",
"'gbk'",
",",
"$",
"to",
"=",
"'utf-8'",
")",
"{",
"$",
"from",
"=",
"strtoupper",
"(",
"$",
"from",
")",
"==",
"'UTF8'",
"?",
"'utf-8'",
":",
"$",
"from",
";",
"$",
"to",
"=",
"strtoupper",
"(",
"$",
"to",
")",
"==",
"'UTF8'",
"?",
"'utf-8'",
":",
"$",
"to",
";",
"if",
"(",
"strtoupper",
"(",
"$",
"from",
")",
"===",
"strtoupper",
"(",
"$",
"to",
")",
"||",
"empty",
"(",
"$",
"string",
")",
"||",
"(",
"is_scalar",
"(",
"$",
"string",
")",
"&&",
"!",
"is_string",
"(",
"$",
"string",
")",
")",
")",
"{",
"//如果编码相同或者非字符串标量则不转换",
"return",
"$",
"string",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"string",
")",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'mb_convert_encoding'",
")",
")",
"{",
"return",
"mb_convert_encoding",
"(",
"$",
"string",
",",
"$",
"to",
",",
"$",
"from",
")",
";",
"}",
"elseif",
"(",
"function_exists",
"(",
"'iconv'",
")",
")",
"{",
"return",
"iconv",
"(",
"$",
"from",
",",
"$",
"to",
",",
"$",
"string",
")",
";",
"}",
"else",
"{",
"return",
"$",
"string",
";",
"}",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"string",
")",
")",
"{",
"foreach",
"(",
"$",
"string",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"_key",
"=",
"self",
"::",
"autoCharset",
"(",
"$",
"key",
",",
"$",
"from",
",",
"$",
"to",
")",
";",
"$",
"string",
"[",
"$",
"_key",
"]",
"=",
"self",
"::",
"autoCharset",
"(",
"$",
"val",
",",
"$",
"from",
",",
"$",
"to",
")",
";",
"if",
"(",
"$",
"key",
"!=",
"$",
"_key",
")",
"unset",
"(",
"$",
"string",
"[",
"$",
"key",
"]",
")",
";",
"}",
"return",
"$",
"string",
";",
"}",
"else",
"{",
"return",
"$",
"string",
";",
"}",
"}"
] |
自动转换字符集 支持数组转换
@param $string
@param string $from
@param string $to
@return array|string
|
[
"自动转换字符集",
"支持数组转换"
] |
train
|
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/helpers/StringHelper.php#L385-L413
|
Wonail/wocenter
|
helpers/StringHelper.php
|
StringHelper.htmlSubString
|
public static function htmlSubString($str, $length, $url = null, $anchor = '<!-- break -->')
{
$_length = mb_strlen(strip_tags($str), "utf-8"); // 统计字符串长度(中、英文都算一个字符)
if ($_length <= $length) {
return $str; // 传入的字符串长度小于截取长度,原样返回
}
$strlen_var = strlen($str); // 统计字符串长度(UTF8编码下-中文算3个字符,英文算一个字符)
if (strpos($str, '<') === false) {
return mb_substr($str, 0, $length); // 不包含 html 标签 ,直接截取
}
if ($e = strpos($str, $anchor)) {
return mb_substr($str, 0, $e); // 包含截断标志,优先
}
$html_tag = 0; // html 代码标记
$result = ''; // 摘要字符串
$html_array = ['left' => [], 'right' => []]; //记录截取后字符串内出现的 html 标签,开始=>left,结束=>right
/*
* 如字符串为:<h3><p><b>a</b></h3>,假设p未闭合,数组则为:array('left'=>array('h3','p','b'), 'right'=>'b','h3');
* 仅补全 html 标签,<? <% 等其它语言标记,会产生不可预知结果
*/
for ($i = 0; $i < $strlen_var; ++$i) {
if (!$length)
break; // 遍历完之后跳出
$current_var = substr($str, $i, 1); // 当前字符
$html_array_str = '';
if ($current_var == '<') { // html 代码开始
$html_tag = 1;
} else if ($html_tag == 1) { // 一段 html 代码结束
if ($current_var == '>') {
$html_array_str = trim($html_array_str); //去除首尾空格,如 <br / > < img src="" / > 等可能出现首尾空格
if (substr($html_array_str, -1) != '/') { //判断最后一个字符是否为 /,若是,则标签已闭合,不记录
// 判断第一个字符是否 /,若是,则放在 right 单元
$f = substr($html_array_str, 0, 1);
if ($f == '/') {
$html_array['right'][] = str_replace('/', '', $html_array_str); // 去掉 '/'
} else if ($f != '?') { // 若是?,则为 PHP 代码,跳过
// 若有半角空格,以空格分割,第一个单元为 html 标签。如:<h2 class="a"> <p class="a">
if (strpos($html_array_str, ' ') !== false) {
// 分割成2个单元,可能有多个空格,如:<h2 class="" id="">
$html_array['left'][] = strtolower(current(explode(' ', $html_array_str, 2)));
} else {
//若没有空格,整个字符串为 html 标签,如:<b> <p> 等,统一转换为小写
$html_array['left'][] = strtolower($html_array_str);
}
}
}
$html_array_str = ''; // 字符串重置
$html_tag = 0;
} else {
$html_array_str .= $current_var; //将< >之间的字符组成一个字符串,用于提取 html 标签
}
} else {
--$length; // 非 html 代码才记数
}
$ord_var_c = ord($str{$i});
switch (true) {
case (($ord_var_c & 0xE0) == 0xC0): // 2 字节
$result .= substr($str, $i, 2);
$i += 1;
break;
case (($ord_var_c & 0xF0) == 0xE0): // 3 字节
$result .= substr($str, $i, 3);
$i += 2;
break;
case (($ord_var_c & 0xF8) == 0xF0): // 4 字节
$result .= substr($str, $i, 4);
$i += 3;
break;
case (($ord_var_c & 0xFC) == 0xF8): // 5 字节
$result .= substr($str, $i, 5);
$i += 4;
break;
case (($ord_var_c & 0xFE) == 0xFC): // 6 字节
$result .= substr($str, $i, 6);
$i += 5;
break;
default: // 1 字节
$result .= $current_var;
}
}
if ($html_array['left']) { //比对左右 html 标签,不足则补全
$html_array['left'] = array_reverse($html_array['left']); //翻转left数组,补充的顺序应与 html 出现的顺序相反
foreach ($html_array['left'] as $index => $tag) {
$key = array_search($tag, $html_array['right']); // 判断该标签是否出现在 right 中
if ($key !== false) { // 出现,从 right 中删除该单元
unset($html_array['right'][$key]);
} else { // 没有出现,需要补全
$result .= '</' . $tag . '>';
}
}
}
if ($url == null) {
return $result . '...';
} else {
$replace = '<br />' . Html::a('<i class="glyphicon glyphicon-hand-right"></i>' . Yii::t('app', 'Unfinished,continue reading') . '>>', $url);
return $result . '...' . $replace;
}
}
|
php
|
public static function htmlSubString($str, $length, $url = null, $anchor = '<!-- break -->')
{
$_length = mb_strlen(strip_tags($str), "utf-8"); // 统计字符串长度(中、英文都算一个字符)
if ($_length <= $length) {
return $str; // 传入的字符串长度小于截取长度,原样返回
}
$strlen_var = strlen($str); // 统计字符串长度(UTF8编码下-中文算3个字符,英文算一个字符)
if (strpos($str, '<') === false) {
return mb_substr($str, 0, $length); // 不包含 html 标签 ,直接截取
}
if ($e = strpos($str, $anchor)) {
return mb_substr($str, 0, $e); // 包含截断标志,优先
}
$html_tag = 0; // html 代码标记
$result = ''; // 摘要字符串
$html_array = ['left' => [], 'right' => []]; //记录截取后字符串内出现的 html 标签,开始=>left,结束=>right
/*
* 如字符串为:<h3><p><b>a</b></h3>,假设p未闭合,数组则为:array('left'=>array('h3','p','b'), 'right'=>'b','h3');
* 仅补全 html 标签,<? <% 等其它语言标记,会产生不可预知结果
*/
for ($i = 0; $i < $strlen_var; ++$i) {
if (!$length)
break; // 遍历完之后跳出
$current_var = substr($str, $i, 1); // 当前字符
$html_array_str = '';
if ($current_var == '<') { // html 代码开始
$html_tag = 1;
} else if ($html_tag == 1) { // 一段 html 代码结束
if ($current_var == '>') {
$html_array_str = trim($html_array_str); //去除首尾空格,如 <br / > < img src="" / > 等可能出现首尾空格
if (substr($html_array_str, -1) != '/') { //判断最后一个字符是否为 /,若是,则标签已闭合,不记录
// 判断第一个字符是否 /,若是,则放在 right 单元
$f = substr($html_array_str, 0, 1);
if ($f == '/') {
$html_array['right'][] = str_replace('/', '', $html_array_str); // 去掉 '/'
} else if ($f != '?') { // 若是?,则为 PHP 代码,跳过
// 若有半角空格,以空格分割,第一个单元为 html 标签。如:<h2 class="a"> <p class="a">
if (strpos($html_array_str, ' ') !== false) {
// 分割成2个单元,可能有多个空格,如:<h2 class="" id="">
$html_array['left'][] = strtolower(current(explode(' ', $html_array_str, 2)));
} else {
//若没有空格,整个字符串为 html 标签,如:<b> <p> 等,统一转换为小写
$html_array['left'][] = strtolower($html_array_str);
}
}
}
$html_array_str = ''; // 字符串重置
$html_tag = 0;
} else {
$html_array_str .= $current_var; //将< >之间的字符组成一个字符串,用于提取 html 标签
}
} else {
--$length; // 非 html 代码才记数
}
$ord_var_c = ord($str{$i});
switch (true) {
case (($ord_var_c & 0xE0) == 0xC0): // 2 字节
$result .= substr($str, $i, 2);
$i += 1;
break;
case (($ord_var_c & 0xF0) == 0xE0): // 3 字节
$result .= substr($str, $i, 3);
$i += 2;
break;
case (($ord_var_c & 0xF8) == 0xF0): // 4 字节
$result .= substr($str, $i, 4);
$i += 3;
break;
case (($ord_var_c & 0xFC) == 0xF8): // 5 字节
$result .= substr($str, $i, 5);
$i += 4;
break;
case (($ord_var_c & 0xFE) == 0xFC): // 6 字节
$result .= substr($str, $i, 6);
$i += 5;
break;
default: // 1 字节
$result .= $current_var;
}
}
if ($html_array['left']) { //比对左右 html 标签,不足则补全
$html_array['left'] = array_reverse($html_array['left']); //翻转left数组,补充的顺序应与 html 出现的顺序相反
foreach ($html_array['left'] as $index => $tag) {
$key = array_search($tag, $html_array['right']); // 判断该标签是否出现在 right 中
if ($key !== false) { // 出现,从 right 中删除该单元
unset($html_array['right'][$key]);
} else { // 没有出现,需要补全
$result .= '</' . $tag . '>';
}
}
}
if ($url == null) {
return $result . '...';
} else {
$replace = '<br />' . Html::a('<i class="glyphicon glyphicon-hand-right"></i>' . Yii::t('app', 'Unfinished,continue reading') . '>>', $url);
return $result . '...' . $replace;
}
}
|
[
"public",
"static",
"function",
"htmlSubString",
"(",
"$",
"str",
",",
"$",
"length",
",",
"$",
"url",
"=",
"null",
",",
"$",
"anchor",
"=",
"'<!-- break -->'",
")",
"{",
"$",
"_length",
"=",
"mb_strlen",
"(",
"strip_tags",
"(",
"$",
"str",
")",
",",
"\"utf-8\"",
")",
";",
"// 统计字符串长度(中、英文都算一个字符)",
"if",
"(",
"$",
"_length",
"<=",
"$",
"length",
")",
"{",
"return",
"$",
"str",
";",
"// 传入的字符串长度小于截取长度,原样返回",
"}",
"$",
"strlen_var",
"=",
"strlen",
"(",
"$",
"str",
")",
";",
"// 统计字符串长度(UTF8编码下-中文算3个字符,英文算一个字符)",
"if",
"(",
"strpos",
"(",
"$",
"str",
",",
"'<'",
")",
"===",
"false",
")",
"{",
"return",
"mb_substr",
"(",
"$",
"str",
",",
"0",
",",
"$",
"length",
")",
";",
"// 不包含 html 标签 ,直接截取",
"}",
"if",
"(",
"$",
"e",
"=",
"strpos",
"(",
"$",
"str",
",",
"$",
"anchor",
")",
")",
"{",
"return",
"mb_substr",
"(",
"$",
"str",
",",
"0",
",",
"$",
"e",
")",
";",
"// 包含截断标志,优先",
"}",
"$",
"html_tag",
"=",
"0",
";",
"// html 代码标记 ",
"$",
"result",
"=",
"''",
";",
"// 摘要字符串",
"$",
"html_array",
"=",
"[",
"'left'",
"=>",
"[",
"]",
",",
"'right'",
"=>",
"[",
"]",
"]",
";",
"//记录截取后字符串内出现的 html 标签,开始=>left,结束=>right",
"/*\n * 如字符串为:<h3><p><b>a</b></h3>,假设p未闭合,数组则为:array('left'=>array('h3','p','b'), 'right'=>'b','h3');\n * 仅补全 html 标签,<? <% 等其它语言标记,会产生不可预知结果\n */",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"strlen_var",
";",
"++",
"$",
"i",
")",
"{",
"if",
"(",
"!",
"$",
"length",
")",
"break",
";",
"// 遍历完之后跳出",
"$",
"current_var",
"=",
"substr",
"(",
"$",
"str",
",",
"$",
"i",
",",
"1",
")",
";",
"// 当前字符",
"$",
"html_array_str",
"=",
"''",
";",
"if",
"(",
"$",
"current_var",
"==",
"'<'",
")",
"{",
"// html 代码开始 ",
"$",
"html_tag",
"=",
"1",
";",
"}",
"else",
"if",
"(",
"$",
"html_tag",
"==",
"1",
")",
"{",
"// 一段 html 代码结束",
"if",
"(",
"$",
"current_var",
"==",
"'>'",
")",
"{",
"$",
"html_array_str",
"=",
"trim",
"(",
"$",
"html_array_str",
")",
";",
"//去除首尾空格,如 <br / > < img src=\"\" / > 等可能出现首尾空格",
"if",
"(",
"substr",
"(",
"$",
"html_array_str",
",",
"-",
"1",
")",
"!=",
"'/'",
")",
"{",
"//判断最后一个字符是否为 /,若是,则标签已闭合,不记录",
"// 判断第一个字符是否 /,若是,则放在 right 单元 ",
"$",
"f",
"=",
"substr",
"(",
"$",
"html_array_str",
",",
"0",
",",
"1",
")",
";",
"if",
"(",
"$",
"f",
"==",
"'/'",
")",
"{",
"$",
"html_array",
"[",
"'right'",
"]",
"[",
"]",
"=",
"str_replace",
"(",
"'/'",
",",
"''",
",",
"$",
"html_array_str",
")",
";",
"// 去掉 '/' ",
"}",
"else",
"if",
"(",
"$",
"f",
"!=",
"'?'",
")",
"{",
"// 若是?,则为 PHP 代码,跳过",
"// 若有半角空格,以空格分割,第一个单元为 html 标签。如:<h2 class=\"a\"> <p class=\"a\"> ",
"if",
"(",
"strpos",
"(",
"$",
"html_array_str",
",",
"' '",
")",
"!==",
"false",
")",
"{",
"// 分割成2个单元,可能有多个空格,如:<h2 class=\"\" id=\"\"> ",
"$",
"html_array",
"[",
"'left'",
"]",
"[",
"]",
"=",
"strtolower",
"(",
"current",
"(",
"explode",
"(",
"' '",
",",
"$",
"html_array_str",
",",
"2",
")",
")",
")",
";",
"}",
"else",
"{",
"//若没有空格,整个字符串为 html 标签,如:<b> <p> 等,统一转换为小写",
"$",
"html_array",
"[",
"'left'",
"]",
"[",
"]",
"=",
"strtolower",
"(",
"$",
"html_array_str",
")",
";",
"}",
"}",
"}",
"$",
"html_array_str",
"=",
"''",
";",
"// 字符串重置",
"$",
"html_tag",
"=",
"0",
";",
"}",
"else",
"{",
"$",
"html_array_str",
".=",
"$",
"current_var",
";",
"//将< >之间的字符组成一个字符串,用于提取 html 标签",
"}",
"}",
"else",
"{",
"--",
"$",
"length",
";",
"// 非 html 代码才记数",
"}",
"$",
"ord_var_c",
"=",
"ord",
"(",
"$",
"str",
"{",
"$",
"i",
"}",
")",
";",
"switch",
"(",
"true",
")",
"{",
"case",
"(",
"(",
"$",
"ord_var_c",
"&",
"0xE0",
")",
"==",
"0xC0",
")",
":",
"// 2 字节 ",
"$",
"result",
".=",
"substr",
"(",
"$",
"str",
",",
"$",
"i",
",",
"2",
")",
";",
"$",
"i",
"+=",
"1",
";",
"break",
";",
"case",
"(",
"(",
"$",
"ord_var_c",
"&",
"0xF0",
")",
"==",
"0xE0",
")",
":",
"// 3 字节",
"$",
"result",
".=",
"substr",
"(",
"$",
"str",
",",
"$",
"i",
",",
"3",
")",
";",
"$",
"i",
"+=",
"2",
";",
"break",
";",
"case",
"(",
"(",
"$",
"ord_var_c",
"&",
"0xF8",
")",
"==",
"0xF0",
")",
":",
"// 4 字节",
"$",
"result",
".=",
"substr",
"(",
"$",
"str",
",",
"$",
"i",
",",
"4",
")",
";",
"$",
"i",
"+=",
"3",
";",
"break",
";",
"case",
"(",
"(",
"$",
"ord_var_c",
"&",
"0xFC",
")",
"==",
"0xF8",
")",
":",
"// 5 字节 ",
"$",
"result",
".=",
"substr",
"(",
"$",
"str",
",",
"$",
"i",
",",
"5",
")",
";",
"$",
"i",
"+=",
"4",
";",
"break",
";",
"case",
"(",
"(",
"$",
"ord_var_c",
"&",
"0xFE",
")",
"==",
"0xFC",
")",
":",
"// 6 字节",
"$",
"result",
".=",
"substr",
"(",
"$",
"str",
",",
"$",
"i",
",",
"6",
")",
";",
"$",
"i",
"+=",
"5",
";",
"break",
";",
"default",
":",
"// 1 字节 ",
"$",
"result",
".=",
"$",
"current_var",
";",
"}",
"}",
"if",
"(",
"$",
"html_array",
"[",
"'left'",
"]",
")",
"{",
"//比对左右 html 标签,不足则补全",
"$",
"html_array",
"[",
"'left'",
"]",
"=",
"array_reverse",
"(",
"$",
"html_array",
"[",
"'left'",
"]",
")",
";",
"//翻转left数组,补充的顺序应与 html 出现的顺序相反",
"foreach",
"(",
"$",
"html_array",
"[",
"'left'",
"]",
"as",
"$",
"index",
"=>",
"$",
"tag",
")",
"{",
"$",
"key",
"=",
"array_search",
"(",
"$",
"tag",
",",
"$",
"html_array",
"[",
"'right'",
"]",
")",
";",
"// 判断该标签是否出现在 right 中",
"if",
"(",
"$",
"key",
"!==",
"false",
")",
"{",
"// 出现,从 right 中删除该单元",
"unset",
"(",
"$",
"html_array",
"[",
"'right'",
"]",
"[",
"$",
"key",
"]",
")",
";",
"}",
"else",
"{",
"// 没有出现,需要补全 ",
"$",
"result",
".=",
"'</'",
".",
"$",
"tag",
".",
"'>'",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"url",
"==",
"null",
")",
"{",
"return",
"$",
"result",
".",
"'...'",
";",
"}",
"else",
"{",
"$",
"replace",
"=",
"'<br />'",
".",
"Html",
"::",
"a",
"(",
"'<i class=\"glyphicon glyphicon-hand-right\"></i>'",
".",
"Yii",
"::",
"t",
"(",
"'app'",
",",
"'Unfinished,continue reading'",
")",
".",
"'>>'",
",",
"$",
"url",
")",
";",
"return",
"$",
"result",
".",
"'...'",
".",
"$",
"replace",
";",
"}",
"}"
] |
截取含有 html标签的字符串
@param string $str 待截取字符串
@param int $length 截取长度
@param string $url 链接
@param string $anchor 截取锚点,如果截取过程中遇到这个标记锚点就截至该锚点处
@return string $result 返回值
@demo $res = cut_html_str($str, 256, '...'); //截取256个长度,其余部分用'...'替换
@author Wang Jian. <[email protected]> Date: 2014/03/16
|
[
"截取含有",
"html标签的字符串"
] |
train
|
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/helpers/StringHelper.php#L428-L526
|
Wonail/wocenter
|
helpers/StringHelper.php
|
StringHelper.replace
|
public static function replace(string $str, string $find, $replace = ''): string
{
return ($position = strpos($str, $find)) !== false ? substr_replace($str, $replace, $position, strlen($find)) : $str;
}
|
php
|
public static function replace(string $str, string $find, $replace = ''): string
{
return ($position = strpos($str, $find)) !== false ? substr_replace($str, $replace, $position, strlen($find)) : $str;
}
|
[
"public",
"static",
"function",
"replace",
"(",
"string",
"$",
"str",
",",
"string",
"$",
"find",
",",
"$",
"replace",
"=",
"''",
")",
":",
"string",
"{",
"return",
"(",
"$",
"position",
"=",
"strpos",
"(",
"$",
"str",
",",
"$",
"find",
")",
")",
"!==",
"false",
"?",
"substr_replace",
"(",
"$",
"str",
",",
"$",
"replace",
",",
"$",
"position",
",",
"strlen",
"(",
"$",
"find",
")",
")",
":",
"$",
"str",
";",
"}"
] |
替换第一个被找到的字符串
@param string $str
@param string $find
@param string $replace
@return string
|
[
"替换第一个被找到的字符串"
] |
train
|
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/helpers/StringHelper.php#L549-L552
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Base/RoleQuery.php
|
RoleQuery.filterByCreateDate
|
public function filterByCreateDate($createDate = null, $comparison = null)
{
if (is_array($createDate)) {
$useMinMax = false;
if (isset($createDate['min'])) {
$this->addUsingAlias(RoleTableMap::COL_CREATE_DATE, $createDate['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($createDate['max'])) {
$this->addUsingAlias(RoleTableMap::COL_CREATE_DATE, $createDate['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(RoleTableMap::COL_CREATE_DATE, $createDate, $comparison);
}
|
php
|
public function filterByCreateDate($createDate = null, $comparison = null)
{
if (is_array($createDate)) {
$useMinMax = false;
if (isset($createDate['min'])) {
$this->addUsingAlias(RoleTableMap::COL_CREATE_DATE, $createDate['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($createDate['max'])) {
$this->addUsingAlias(RoleTableMap::COL_CREATE_DATE, $createDate['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(RoleTableMap::COL_CREATE_DATE, $createDate, $comparison);
}
|
[
"public",
"function",
"filterByCreateDate",
"(",
"$",
"createDate",
"=",
"null",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"createDate",
")",
")",
"{",
"$",
"useMinMax",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"createDate",
"[",
"'min'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addUsingAlias",
"(",
"RoleTableMap",
"::",
"COL_CREATE_DATE",
",",
"$",
"createDate",
"[",
"'min'",
"]",
",",
"Criteria",
"::",
"GREATER_EQUAL",
")",
";",
"$",
"useMinMax",
"=",
"true",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"createDate",
"[",
"'max'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addUsingAlias",
"(",
"RoleTableMap",
"::",
"COL_CREATE_DATE",
",",
"$",
"createDate",
"[",
"'max'",
"]",
",",
"Criteria",
"::",
"LESS_EQUAL",
")",
";",
"$",
"useMinMax",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"useMinMax",
")",
"{",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"comparison",
")",
"{",
"$",
"comparison",
"=",
"Criteria",
"::",
"IN",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"addUsingAlias",
"(",
"RoleTableMap",
"::",
"COL_CREATE_DATE",
",",
"$",
"createDate",
",",
"$",
"comparison",
")",
";",
"}"
] |
Filter the query on the create_date column
Example usage:
<code>
$query->filterByCreateDate('2011-03-14'); // WHERE create_date = '2011-03-14'
$query->filterByCreateDate('now'); // WHERE create_date = '2011-03-14'
$query->filterByCreateDate(array('max' => 'yesterday')); // WHERE create_date > '2011-03-13'
</code>
@param mixed $createDate The value to use as filter.
Values can be integers (unix timestamps), DateTime objects, or strings.
Empty strings are treated as NULL.
Use scalar values for equality.
Use array values for in_array() equivalent.
Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return $this|ChildRoleQuery The current query, for fluid interface
|
[
"Filter",
"the",
"query",
"on",
"the",
"create_date",
"column"
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/RoleQuery.php#L366-L387
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Base/RoleQuery.php
|
RoleQuery.filterByUpdateDate
|
public function filterByUpdateDate($updateDate = null, $comparison = null)
{
if (is_array($updateDate)) {
$useMinMax = false;
if (isset($updateDate['min'])) {
$this->addUsingAlias(RoleTableMap::COL_UPDATE_DATE, $updateDate['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($updateDate['max'])) {
$this->addUsingAlias(RoleTableMap::COL_UPDATE_DATE, $updateDate['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(RoleTableMap::COL_UPDATE_DATE, $updateDate, $comparison);
}
|
php
|
public function filterByUpdateDate($updateDate = null, $comparison = null)
{
if (is_array($updateDate)) {
$useMinMax = false;
if (isset($updateDate['min'])) {
$this->addUsingAlias(RoleTableMap::COL_UPDATE_DATE, $updateDate['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($updateDate['max'])) {
$this->addUsingAlias(RoleTableMap::COL_UPDATE_DATE, $updateDate['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(RoleTableMap::COL_UPDATE_DATE, $updateDate, $comparison);
}
|
[
"public",
"function",
"filterByUpdateDate",
"(",
"$",
"updateDate",
"=",
"null",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"updateDate",
")",
")",
"{",
"$",
"useMinMax",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"updateDate",
"[",
"'min'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addUsingAlias",
"(",
"RoleTableMap",
"::",
"COL_UPDATE_DATE",
",",
"$",
"updateDate",
"[",
"'min'",
"]",
",",
"Criteria",
"::",
"GREATER_EQUAL",
")",
";",
"$",
"useMinMax",
"=",
"true",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"updateDate",
"[",
"'max'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addUsingAlias",
"(",
"RoleTableMap",
"::",
"COL_UPDATE_DATE",
",",
"$",
"updateDate",
"[",
"'max'",
"]",
",",
"Criteria",
"::",
"LESS_EQUAL",
")",
";",
"$",
"useMinMax",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"useMinMax",
")",
"{",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"comparison",
")",
"{",
"$",
"comparison",
"=",
"Criteria",
"::",
"IN",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"addUsingAlias",
"(",
"RoleTableMap",
"::",
"COL_UPDATE_DATE",
",",
"$",
"updateDate",
",",
"$",
"comparison",
")",
";",
"}"
] |
Filter the query on the update_date column
Example usage:
<code>
$query->filterByUpdateDate('2011-03-14'); // WHERE update_date = '2011-03-14'
$query->filterByUpdateDate('now'); // WHERE update_date = '2011-03-14'
$query->filterByUpdateDate(array('max' => 'yesterday')); // WHERE update_date > '2011-03-13'
</code>
@param mixed $updateDate The value to use as filter.
Values can be integers (unix timestamps), DateTime objects, or strings.
Empty strings are treated as NULL.
Use scalar values for equality.
Use array values for in_array() equivalent.
Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return $this|ChildRoleQuery The current query, for fluid interface
|
[
"Filter",
"the",
"query",
"on",
"the",
"update_date",
"column"
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/RoleQuery.php#L409-L430
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Base/RoleQuery.php
|
RoleQuery.filterByUserRole
|
public function filterByUserRole($userRole, $comparison = null)
{
if ($userRole instanceof \Alchemy\Component\Cerberus\Model\UserRole) {
return $this
->addUsingAlias(RoleTableMap::COL_ID, $userRole->getRoleId(), $comparison);
} elseif ($userRole instanceof ObjectCollection) {
return $this
->useUserRoleQuery()
->filterByPrimaryKeys($userRole->getPrimaryKeys())
->endUse();
} else {
throw new PropelException('filterByUserRole() only accepts arguments of type \Alchemy\Component\Cerberus\Model\UserRole or Collection');
}
}
|
php
|
public function filterByUserRole($userRole, $comparison = null)
{
if ($userRole instanceof \Alchemy\Component\Cerberus\Model\UserRole) {
return $this
->addUsingAlias(RoleTableMap::COL_ID, $userRole->getRoleId(), $comparison);
} elseif ($userRole instanceof ObjectCollection) {
return $this
->useUserRoleQuery()
->filterByPrimaryKeys($userRole->getPrimaryKeys())
->endUse();
} else {
throw new PropelException('filterByUserRole() only accepts arguments of type \Alchemy\Component\Cerberus\Model\UserRole or Collection');
}
}
|
[
"public",
"function",
"filterByUserRole",
"(",
"$",
"userRole",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"userRole",
"instanceof",
"\\",
"Alchemy",
"\\",
"Component",
"\\",
"Cerberus",
"\\",
"Model",
"\\",
"UserRole",
")",
"{",
"return",
"$",
"this",
"->",
"addUsingAlias",
"(",
"RoleTableMap",
"::",
"COL_ID",
",",
"$",
"userRole",
"->",
"getRoleId",
"(",
")",
",",
"$",
"comparison",
")",
";",
"}",
"elseif",
"(",
"$",
"userRole",
"instanceof",
"ObjectCollection",
")",
"{",
"return",
"$",
"this",
"->",
"useUserRoleQuery",
"(",
")",
"->",
"filterByPrimaryKeys",
"(",
"$",
"userRole",
"->",
"getPrimaryKeys",
"(",
")",
")",
"->",
"endUse",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"PropelException",
"(",
"'filterByUserRole() only accepts arguments of type \\Alchemy\\Component\\Cerberus\\Model\\UserRole or Collection'",
")",
";",
"}",
"}"
] |
Filter the query by a related \Alchemy\Component\Cerberus\Model\UserRole object
@param \Alchemy\Component\Cerberus\Model\UserRole|ObjectCollection $userRole the related object to use as filter
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return ChildRoleQuery The current query, for fluid interface
|
[
"Filter",
"the",
"query",
"by",
"a",
"related",
"\\",
"Alchemy",
"\\",
"Component",
"\\",
"Cerberus",
"\\",
"Model",
"\\",
"UserRole",
"object"
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/RoleQuery.php#L469-L482
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Base/RoleQuery.php
|
RoleQuery.useUserRoleQuery
|
public function useUserRoleQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
return $this
->joinUserRole($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'UserRole', '\Alchemy\Component\Cerberus\Model\UserRoleQuery');
}
|
php
|
public function useUserRoleQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
return $this
->joinUserRole($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'UserRole', '\Alchemy\Component\Cerberus\Model\UserRoleQuery');
}
|
[
"public",
"function",
"useUserRoleQuery",
"(",
"$",
"relationAlias",
"=",
"null",
",",
"$",
"joinType",
"=",
"Criteria",
"::",
"INNER_JOIN",
")",
"{",
"return",
"$",
"this",
"->",
"joinUserRole",
"(",
"$",
"relationAlias",
",",
"$",
"joinType",
")",
"->",
"useQuery",
"(",
"$",
"relationAlias",
"?",
"$",
"relationAlias",
":",
"'UserRole'",
",",
"'\\Alchemy\\Component\\Cerberus\\Model\\UserRoleQuery'",
")",
";",
"}"
] |
Use the UserRole relation UserRole object
@see useQuery()
@param string $relationAlias optional alias for the relation,
to be used as main alias in the secondary query
@param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
@return \Alchemy\Component\Cerberus\Model\UserRoleQuery A secondary query class using the current class as primary query
|
[
"Use",
"the",
"UserRole",
"relation",
"UserRole",
"object"
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/RoleQuery.php#L527-L532
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Base/RoleQuery.php
|
RoleQuery.useRolePermissionQuery
|
public function useRolePermissionQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
return $this
->joinRolePermission($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'RolePermission', '\Alchemy\Component\Cerberus\Model\RolePermissionQuery');
}
|
php
|
public function useRolePermissionQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
return $this
->joinRolePermission($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'RolePermission', '\Alchemy\Component\Cerberus\Model\RolePermissionQuery');
}
|
[
"public",
"function",
"useRolePermissionQuery",
"(",
"$",
"relationAlias",
"=",
"null",
",",
"$",
"joinType",
"=",
"Criteria",
"::",
"INNER_JOIN",
")",
"{",
"return",
"$",
"this",
"->",
"joinRolePermission",
"(",
"$",
"relationAlias",
",",
"$",
"joinType",
")",
"->",
"useQuery",
"(",
"$",
"relationAlias",
"?",
"$",
"relationAlias",
":",
"'RolePermission'",
",",
"'\\Alchemy\\Component\\Cerberus\\Model\\RolePermissionQuery'",
")",
";",
"}"
] |
Use the RolePermission relation RolePermission object
@see useQuery()
@param string $relationAlias optional alias for the relation,
to be used as main alias in the secondary query
@param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
@return \Alchemy\Component\Cerberus\Model\RolePermissionQuery A secondary query class using the current class as primary query
|
[
"Use",
"the",
"RolePermission",
"relation",
"RolePermission",
"object"
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/RoleQuery.php#L600-L605
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Base/RoleQuery.php
|
RoleQuery.filterByUser
|
public function filterByUser($user, $comparison = Criteria::EQUAL)
{
return $this
->useUserRoleQuery()
->filterByUser($user, $comparison)
->endUse();
}
|
php
|
public function filterByUser($user, $comparison = Criteria::EQUAL)
{
return $this
->useUserRoleQuery()
->filterByUser($user, $comparison)
->endUse();
}
|
[
"public",
"function",
"filterByUser",
"(",
"$",
"user",
",",
"$",
"comparison",
"=",
"Criteria",
"::",
"EQUAL",
")",
"{",
"return",
"$",
"this",
"->",
"useUserRoleQuery",
"(",
")",
"->",
"filterByUser",
"(",
"$",
"user",
",",
"$",
"comparison",
")",
"->",
"endUse",
"(",
")",
";",
"}"
] |
Filter the query by a related User object
using the user_role table as cross reference
@param User $user the related object to use as filter
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return ChildRoleQuery The current query, for fluid interface
|
[
"Filter",
"the",
"query",
"by",
"a",
"related",
"User",
"object",
"using",
"the",
"user_role",
"table",
"as",
"cross",
"reference"
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/RoleQuery.php#L616-L622
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Base/RoleQuery.php
|
RoleQuery.filterByPermission
|
public function filterByPermission($permission, $comparison = Criteria::EQUAL)
{
return $this
->useRolePermissionQuery()
->filterByPermission($permission, $comparison)
->endUse();
}
|
php
|
public function filterByPermission($permission, $comparison = Criteria::EQUAL)
{
return $this
->useRolePermissionQuery()
->filterByPermission($permission, $comparison)
->endUse();
}
|
[
"public",
"function",
"filterByPermission",
"(",
"$",
"permission",
",",
"$",
"comparison",
"=",
"Criteria",
"::",
"EQUAL",
")",
"{",
"return",
"$",
"this",
"->",
"useRolePermissionQuery",
"(",
")",
"->",
"filterByPermission",
"(",
"$",
"permission",
",",
"$",
"comparison",
")",
"->",
"endUse",
"(",
")",
";",
"}"
] |
Filter the query by a related Permission object
using the role_permission table as cross reference
@param Permission $permission the related object to use as filter
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return ChildRoleQuery The current query, for fluid interface
|
[
"Filter",
"the",
"query",
"by",
"a",
"related",
"Permission",
"object",
"using",
"the",
"role_permission",
"table",
"as",
"cross",
"reference"
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/RoleQuery.php#L633-L639
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Base/RoleQuery.php
|
RoleQuery.prune
|
public function prune($role = null)
{
if ($role) {
$this->addUsingAlias(RoleTableMap::COL_ID, $role->getId(), Criteria::NOT_EQUAL);
}
return $this;
}
|
php
|
public function prune($role = null)
{
if ($role) {
$this->addUsingAlias(RoleTableMap::COL_ID, $role->getId(), Criteria::NOT_EQUAL);
}
return $this;
}
|
[
"public",
"function",
"prune",
"(",
"$",
"role",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"role",
")",
"{",
"$",
"this",
"->",
"addUsingAlias",
"(",
"RoleTableMap",
"::",
"COL_ID",
",",
"$",
"role",
"->",
"getId",
"(",
")",
",",
"Criteria",
"::",
"NOT_EQUAL",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Exclude object from result
@param ChildRole $role Object to remove from the list of results
@return $this|ChildRoleQuery The current query, for fluid interface
|
[
"Exclude",
"object",
"from",
"result"
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/RoleQuery.php#L648-L655
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Base/RoleQuery.php
|
RoleQuery.doDeleteAll
|
public function doDeleteAll(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(RoleTableMap::DATABASE_NAME);
}
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
return $con->transaction(function () use ($con) {
$affectedRows = 0; // initialize var to track total num of affected rows
$affectedRows += parent::doDeleteAll($con);
// Because this db requires some delete cascade/set null emulation, we have to
// clear the cached instance *after* the emulation has happened (since
// instances get re-added by the select statement contained therein).
RoleTableMap::clearInstancePool();
RoleTableMap::clearRelatedInstancePool();
return $affectedRows;
});
}
|
php
|
public function doDeleteAll(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(RoleTableMap::DATABASE_NAME);
}
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
return $con->transaction(function () use ($con) {
$affectedRows = 0; // initialize var to track total num of affected rows
$affectedRows += parent::doDeleteAll($con);
// Because this db requires some delete cascade/set null emulation, we have to
// clear the cached instance *after* the emulation has happened (since
// instances get re-added by the select statement contained therein).
RoleTableMap::clearInstancePool();
RoleTableMap::clearRelatedInstancePool();
return $affectedRows;
});
}
|
[
"public",
"function",
"doDeleteAll",
"(",
"ConnectionInterface",
"$",
"con",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"con",
")",
"{",
"$",
"con",
"=",
"Propel",
"::",
"getServiceContainer",
"(",
")",
"->",
"getWriteConnection",
"(",
"RoleTableMap",
"::",
"DATABASE_NAME",
")",
";",
"}",
"// use transaction because $criteria could contain info",
"// for more than one table or we could emulating ON DELETE CASCADE, etc.",
"return",
"$",
"con",
"->",
"transaction",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"con",
")",
"{",
"$",
"affectedRows",
"=",
"0",
";",
"// initialize var to track total num of affected rows",
"$",
"affectedRows",
"+=",
"parent",
"::",
"doDeleteAll",
"(",
"$",
"con",
")",
";",
"// Because this db requires some delete cascade/set null emulation, we have to",
"// clear the cached instance *after* the emulation has happened (since",
"// instances get re-added by the select statement contained therein).",
"RoleTableMap",
"::",
"clearInstancePool",
"(",
")",
";",
"RoleTableMap",
"::",
"clearRelatedInstancePool",
"(",
")",
";",
"return",
"$",
"affectedRows",
";",
"}",
")",
";",
"}"
] |
Deletes all rows from the role table.
@param ConnectionInterface $con the connection to use
@return int The number of affected rows (if supported by underlying database driver).
|
[
"Deletes",
"all",
"rows",
"from",
"the",
"role",
"table",
"."
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/RoleQuery.php#L663-L682
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Base/RoleQuery.php
|
RoleQuery.delete
|
public function delete(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(RoleTableMap::DATABASE_NAME);
}
$criteria = $this;
// Set the correct dbName
$criteria->setDbName(RoleTableMap::DATABASE_NAME);
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
return $con->transaction(function () use ($con, $criteria) {
$affectedRows = 0; // initialize var to track total num of affected rows
RoleTableMap::removeInstanceFromPool($criteria);
$affectedRows += ModelCriteria::delete($con);
RoleTableMap::clearRelatedInstancePool();
return $affectedRows;
});
}
|
php
|
public function delete(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(RoleTableMap::DATABASE_NAME);
}
$criteria = $this;
// Set the correct dbName
$criteria->setDbName(RoleTableMap::DATABASE_NAME);
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
return $con->transaction(function () use ($con, $criteria) {
$affectedRows = 0; // initialize var to track total num of affected rows
RoleTableMap::removeInstanceFromPool($criteria);
$affectedRows += ModelCriteria::delete($con);
RoleTableMap::clearRelatedInstancePool();
return $affectedRows;
});
}
|
[
"public",
"function",
"delete",
"(",
"ConnectionInterface",
"$",
"con",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"con",
")",
"{",
"$",
"con",
"=",
"Propel",
"::",
"getServiceContainer",
"(",
")",
"->",
"getWriteConnection",
"(",
"RoleTableMap",
"::",
"DATABASE_NAME",
")",
";",
"}",
"$",
"criteria",
"=",
"$",
"this",
";",
"// Set the correct dbName",
"$",
"criteria",
"->",
"setDbName",
"(",
"RoleTableMap",
"::",
"DATABASE_NAME",
")",
";",
"// use transaction because $criteria could contain info",
"// for more than one table or we could emulating ON DELETE CASCADE, etc.",
"return",
"$",
"con",
"->",
"transaction",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"con",
",",
"$",
"criteria",
")",
"{",
"$",
"affectedRows",
"=",
"0",
";",
"// initialize var to track total num of affected rows",
"RoleTableMap",
"::",
"removeInstanceFromPool",
"(",
"$",
"criteria",
")",
";",
"$",
"affectedRows",
"+=",
"ModelCriteria",
"::",
"delete",
"(",
"$",
"con",
")",
";",
"RoleTableMap",
"::",
"clearRelatedInstancePool",
"(",
")",
";",
"return",
"$",
"affectedRows",
";",
"}",
")",
";",
"}"
] |
Performs a DELETE on the database based on the current ModelCriteria
@param ConnectionInterface $con the connection to use
@return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
if supported by native driver or if emulated using Propel.
@throws PropelException Any exceptions caught during processing will be
rethrown wrapped into a PropelException.
|
[
"Performs",
"a",
"DELETE",
"on",
"the",
"database",
"based",
"on",
"the",
"current",
"ModelCriteria"
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/RoleQuery.php#L693-L716
|
crossjoin/Css
|
src/Crossjoin/Css/Format/Rule/AtPage/PageSelector.php
|
PageSelector.checkValue
|
public function checkValue(&$value)
{
if (parent::checkValue($value) === true) {
$value = trim($value);
if (in_array($value,
[
self::SELECTOR_ALL, self::SELECTOR_FIRST, self::SELECTOR_LEFT,
self::SELECTOR_RIGHT, self::SELECTOR_BLANK
])) {
return true;
} else {
throw new \InvalidArgumentException("Invalid value '" . $value . "' for argument 'value'.");
}
}
return false;
}
|
php
|
public function checkValue(&$value)
{
if (parent::checkValue($value) === true) {
$value = trim($value);
if (in_array($value,
[
self::SELECTOR_ALL, self::SELECTOR_FIRST, self::SELECTOR_LEFT,
self::SELECTOR_RIGHT, self::SELECTOR_BLANK
])) {
return true;
} else {
throw new \InvalidArgumentException("Invalid value '" . $value . "' for argument 'value'.");
}
}
return false;
}
|
[
"public",
"function",
"checkValue",
"(",
"&",
"$",
"value",
")",
"{",
"if",
"(",
"parent",
"::",
"checkValue",
"(",
"$",
"value",
")",
"===",
"true",
")",
"{",
"$",
"value",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"value",
",",
"[",
"self",
"::",
"SELECTOR_ALL",
",",
"self",
"::",
"SELECTOR_FIRST",
",",
"self",
"::",
"SELECTOR_LEFT",
",",
"self",
"::",
"SELECTOR_RIGHT",
",",
"self",
"::",
"SELECTOR_BLANK",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid value '\"",
".",
"$",
"value",
".",
"\"' for argument 'value'.\"",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Checks the selector value.
@param string $value
@return bool
|
[
"Checks",
"the",
"selector",
"value",
"."
] |
train
|
https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Format/Rule/AtPage/PageSelector.php#L31-L47
|
awethemes/wp-session
|
src/Store.php
|
Store.start
|
public function start() {
$data = $this->handler->read( $this->get_id() );
if ( false !== $data && ! is_null( $data ) && is_array( $data ) ) {
$this->attributes = $data;
}
$this->started = true;
}
|
php
|
public function start() {
$data = $this->handler->read( $this->get_id() );
if ( false !== $data && ! is_null( $data ) && is_array( $data ) ) {
$this->attributes = $data;
}
$this->started = true;
}
|
[
"public",
"function",
"start",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"handler",
"->",
"read",
"(",
"$",
"this",
"->",
"get_id",
"(",
")",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"data",
"&&",
"!",
"is_null",
"(",
"$",
"data",
")",
"&&",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"this",
"->",
"attributes",
"=",
"$",
"data",
";",
"}",
"$",
"this",
"->",
"started",
"=",
"true",
";",
"}"
] |
Start the session, reading the data from a handler.
@return void
|
[
"Start",
"the",
"session",
"reading",
"the",
"data",
"from",
"a",
"handler",
"."
] |
train
|
https://github.com/awethemes/wp-session/blob/4819c6392a0dbcbbf547027b70d5af88e7a89d61/src/Store.php#L63-L71
|
awethemes/wp-session
|
src/Store.php
|
Store.save
|
public function save() {
if ( ! $this->started ) {
return;
}
$this->age_flash_data();
/* @noinspection PhpParamsInspection */
$this->handler->write( $this->get_id(), $this->attributes );
$this->started = false;
}
|
php
|
public function save() {
if ( ! $this->started ) {
return;
}
$this->age_flash_data();
/* @noinspection PhpParamsInspection */
$this->handler->write( $this->get_id(), $this->attributes );
$this->started = false;
}
|
[
"public",
"function",
"save",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"started",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"age_flash_data",
"(",
")",
";",
"/* @noinspection PhpParamsInspection */",
"$",
"this",
"->",
"handler",
"->",
"write",
"(",
"$",
"this",
"->",
"get_id",
"(",
")",
",",
"$",
"this",
"->",
"attributes",
")",
";",
"$",
"this",
"->",
"started",
"=",
"false",
";",
"}"
] |
Save the session data to storage.
@return void
|
[
"Save",
"the",
"session",
"data",
"to",
"storage",
"."
] |
train
|
https://github.com/awethemes/wp-session/blob/4819c6392a0dbcbbf547027b70d5af88e7a89d61/src/Store.php#L78-L89
|
awethemes/wp-session
|
src/Store.php
|
Store.exists
|
public function exists( $key ) {
return ! collect( is_array( $key ) ? $key : func_get_args() )->contains(
function ( $key ) {
return ! Arr::exists( $this->attributes, $key );
}
);
}
|
php
|
public function exists( $key ) {
return ! collect( is_array( $key ) ? $key : func_get_args() )->contains(
function ( $key ) {
return ! Arr::exists( $this->attributes, $key );
}
);
}
|
[
"public",
"function",
"exists",
"(",
"$",
"key",
")",
"{",
"return",
"!",
"collect",
"(",
"is_array",
"(",
"$",
"key",
")",
"?",
"$",
"key",
":",
"func_get_args",
"(",
")",
")",
"->",
"contains",
"(",
"function",
"(",
"$",
"key",
")",
"{",
"return",
"!",
"Arr",
"::",
"exists",
"(",
"$",
"this",
"->",
"attributes",
",",
"$",
"key",
")",
";",
"}",
")",
";",
"}"
] |
Checks if a key exists.
@param string|array $key Key name or an array keys.
@return bool
|
[
"Checks",
"if",
"a",
"key",
"exists",
"."
] |
train
|
https://github.com/awethemes/wp-session/blob/4819c6392a0dbcbbf547027b70d5af88e7a89d61/src/Store.php#L106-L112
|
awethemes/wp-session
|
src/Store.php
|
Store.put
|
public function put( $key, $value = null ) {
if ( ! is_array( $key ) ) {
$key = [ $key => $value ];
}
foreach ( $key as $array_key => $array_value ) {
Arr::set( $this->attributes, $array_key, $array_value );
}
}
|
php
|
public function put( $key, $value = null ) {
if ( ! is_array( $key ) ) {
$key = [ $key => $value ];
}
foreach ( $key as $array_key => $array_value ) {
Arr::set( $this->attributes, $array_key, $array_value );
}
}
|
[
"public",
"function",
"put",
"(",
"$",
"key",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"$",
"key",
"=",
"[",
"$",
"key",
"=>",
"$",
"value",
"]",
";",
"}",
"foreach",
"(",
"$",
"key",
"as",
"$",
"array_key",
"=>",
"$",
"array_value",
")",
"{",
"Arr",
"::",
"set",
"(",
"$",
"this",
"->",
"attributes",
",",
"$",
"array_key",
",",
"$",
"array_value",
")",
";",
"}",
"}"
] |
Put a key/value pair or array of key/value pairs in the session.
@param string|array $key An array of key/value pairs or string key name.
@param mixed $value If $key is string, use this as value.
@return void
|
[
"Put",
"a",
"key",
"/",
"value",
"pair",
"or",
"array",
"of",
"key",
"/",
"value",
"pairs",
"in",
"the",
"session",
"."
] |
train
|
https://github.com/awethemes/wp-session/blob/4819c6392a0dbcbbf547027b70d5af88e7a89d61/src/Store.php#L146-L154
|
awethemes/wp-session
|
src/Store.php
|
Store.flash
|
public function flash( $key, $value = true ) {
$this->put( $key, $value );
$this->push( '_flash.new', $key );
$this->remove_old_flash_data( [ $key ] );
}
|
php
|
public function flash( $key, $value = true ) {
$this->put( $key, $value );
$this->push( '_flash.new', $key );
$this->remove_old_flash_data( [ $key ] );
}
|
[
"public",
"function",
"flash",
"(",
"$",
"key",
",",
"$",
"value",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"put",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"$",
"this",
"->",
"push",
"(",
"'_flash.new'",
",",
"$",
"key",
")",
";",
"$",
"this",
"->",
"remove_old_flash_data",
"(",
"[",
"$",
"key",
"]",
")",
";",
"}"
] |
Flash a key / value pair to the session.
@param string $key The flash key.
@param mixed $value The flash value.
@return void
|
[
"Flash",
"a",
"key",
"/",
"value",
"pair",
"to",
"the",
"session",
"."
] |
train
|
https://github.com/awethemes/wp-session/blob/4819c6392a0dbcbbf547027b70d5af88e7a89d61/src/Store.php#L254-L260
|
awethemes/wp-session
|
src/Store.php
|
Store.keep
|
public function keep( $keys = null ) {
$keys = is_array( $keys ) ? $keys : func_get_args();
$this->merge_new_flashes( $keys );
$this->remove_old_flash_data( $keys );
}
|
php
|
public function keep( $keys = null ) {
$keys = is_array( $keys ) ? $keys : func_get_args();
$this->merge_new_flashes( $keys );
$this->remove_old_flash_data( $keys );
}
|
[
"public",
"function",
"keep",
"(",
"$",
"keys",
"=",
"null",
")",
"{",
"$",
"keys",
"=",
"is_array",
"(",
"$",
"keys",
")",
"?",
"$",
"keys",
":",
"func_get_args",
"(",
")",
";",
"$",
"this",
"->",
"merge_new_flashes",
"(",
"$",
"keys",
")",
";",
"$",
"this",
"->",
"remove_old_flash_data",
"(",
"$",
"keys",
")",
";",
"}"
] |
Reflash a subset of the current flash data.
@param array|mixed $keys Keep flash keys.
@return void
|
[
"Reflash",
"a",
"subset",
"of",
"the",
"current",
"flash",
"data",
"."
] |
train
|
https://github.com/awethemes/wp-session/blob/4819c6392a0dbcbbf547027b70d5af88e7a89d61/src/Store.php#L292-L298
|
awethemes/wp-session
|
src/Store.php
|
Store.merge_new_flashes
|
protected function merge_new_flashes( array $keys ) {
$values = array_unique( array_merge( $this->get( '_flash.new', [] ), $keys ) );
$this->put( '_flash.new', $values );
}
|
php
|
protected function merge_new_flashes( array $keys ) {
$values = array_unique( array_merge( $this->get( '_flash.new', [] ), $keys ) );
$this->put( '_flash.new', $values );
}
|
[
"protected",
"function",
"merge_new_flashes",
"(",
"array",
"$",
"keys",
")",
"{",
"$",
"values",
"=",
"array_unique",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"get",
"(",
"'_flash.new'",
",",
"[",
"]",
")",
",",
"$",
"keys",
")",
")",
";",
"$",
"this",
"->",
"put",
"(",
"'_flash.new'",
",",
"$",
"values",
")",
";",
"}"
] |
Merge new flash keys into the new flash array.
@param array $keys Merge flash keys.
@return void
|
[
"Merge",
"new",
"flash",
"keys",
"into",
"the",
"new",
"flash",
"array",
"."
] |
train
|
https://github.com/awethemes/wp-session/blob/4819c6392a0dbcbbf547027b70d5af88e7a89d61/src/Store.php#L306-L310
|
awethemes/wp-session
|
src/Store.php
|
Store.has_old_input
|
public function has_old_input( $key = null ) {
$old = $this->get_old_input( $key );
return is_null( $key ) ? count( $old ) > 0 : ! is_null( $old );
}
|
php
|
public function has_old_input( $key = null ) {
$old = $this->get_old_input( $key );
return is_null( $key ) ? count( $old ) > 0 : ! is_null( $old );
}
|
[
"public",
"function",
"has_old_input",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"$",
"old",
"=",
"$",
"this",
"->",
"get_old_input",
"(",
"$",
"key",
")",
";",
"return",
"is_null",
"(",
"$",
"key",
")",
"?",
"count",
"(",
"$",
"old",
")",
">",
"0",
":",
"!",
"is_null",
"(",
"$",
"old",
")",
";",
"}"
] |
Determine if the session contains old input.
@param string $key Old input key name.
@return bool
|
[
"Determine",
"if",
"the",
"session",
"contains",
"old",
"input",
"."
] |
train
|
https://github.com/awethemes/wp-session/blob/4819c6392a0dbcbbf547027b70d5af88e7a89d61/src/Store.php#L338-L342
|
awethemes/wp-session
|
src/Store.php
|
Store.age_flash_data
|
public function age_flash_data() {
$this->forget( $this->get( '_flash.old', [] ) );
$this->put( '_flash.old', $this->get( '_flash.new', [] ) );
$this->put( '_flash.new', [] );
}
|
php
|
public function age_flash_data() {
$this->forget( $this->get( '_flash.old', [] ) );
$this->put( '_flash.old', $this->get( '_flash.new', [] ) );
$this->put( '_flash.new', [] );
}
|
[
"public",
"function",
"age_flash_data",
"(",
")",
"{",
"$",
"this",
"->",
"forget",
"(",
"$",
"this",
"->",
"get",
"(",
"'_flash.old'",
",",
"[",
"]",
")",
")",
";",
"$",
"this",
"->",
"put",
"(",
"'_flash.old'",
",",
"$",
"this",
"->",
"get",
"(",
"'_flash.new'",
",",
"[",
"]",
")",
")",
";",
"$",
"this",
"->",
"put",
"(",
"'_flash.new'",
",",
"[",
"]",
")",
";",
"}"
] |
Age the flash data for the session.
@access private
@return void
|
[
"Age",
"the",
"flash",
"data",
"for",
"the",
"session",
"."
] |
train
|
https://github.com/awethemes/wp-session/blob/4819c6392a0dbcbbf547027b70d5af88e7a89d61/src/Store.php#L362-L368
|
awethemes/wp-session
|
src/Store.php
|
Store.regenerate
|
public function regenerate( $destroy = false ) {
if ( $destroy ) {
$this->handler->destroy( $this->get_id() );
}
$this->set_id( $this->generate_session_id() );
return true;
}
|
php
|
public function regenerate( $destroy = false ) {
if ( $destroy ) {
$this->handler->destroy( $this->get_id() );
}
$this->set_id( $this->generate_session_id() );
return true;
}
|
[
"public",
"function",
"regenerate",
"(",
"$",
"destroy",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"destroy",
")",
"{",
"$",
"this",
"->",
"handler",
"->",
"destroy",
"(",
"$",
"this",
"->",
"get_id",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"set_id",
"(",
"$",
"this",
"->",
"generate_session_id",
"(",
")",
")",
";",
"return",
"true",
";",
"}"
] |
Generate a new session identifier.
@param bool $destroy Destroy current session.
@return bool
|
[
"Generate",
"a",
"new",
"session",
"identifier",
"."
] |
train
|
https://github.com/awethemes/wp-session/blob/4819c6392a0dbcbbf547027b70d5af88e7a89d61/src/Store.php#L387-L395
|
awethemes/wp-session
|
src/Store.php
|
Store.set_id
|
public function set_id( $id ) {
$this->id = $this->is_valid_id( $id ) ? $id : $this->generate_session_id();
}
|
php
|
public function set_id( $id ) {
$this->id = $this->is_valid_id( $id ) ? $id : $this->generate_session_id();
}
|
[
"public",
"function",
"set_id",
"(",
"$",
"id",
")",
"{",
"$",
"this",
"->",
"id",
"=",
"$",
"this",
"->",
"is_valid_id",
"(",
"$",
"id",
")",
"?",
"$",
"id",
":",
"$",
"this",
"->",
"generate_session_id",
"(",
")",
";",
"}"
] |
Set the session ID.
@param string $id A valid session ID.
@return void
|
[
"Set",
"the",
"session",
"ID",
"."
] |
train
|
https://github.com/awethemes/wp-session/blob/4819c6392a0dbcbbf547027b70d5af88e7a89d61/src/Store.php#L449-L451
|
awethemes/wp-session
|
src/Store.php
|
Store.generate_session_id
|
protected function generate_session_id() {
$length = 40;
require_once ABSPATH . 'wp-includes/class-phpass.php';
$bytes = ( new \PasswordHash( 8, false ) )->get_random_bytes( $length * 2 );
return substr( str_replace( [ '/', '+', '=' ], '', base64_encode( $bytes ) ), 0, $length );
}
|
php
|
protected function generate_session_id() {
$length = 40;
require_once ABSPATH . 'wp-includes/class-phpass.php';
$bytes = ( new \PasswordHash( 8, false ) )->get_random_bytes( $length * 2 );
return substr( str_replace( [ '/', '+', '=' ], '', base64_encode( $bytes ) ), 0, $length );
}
|
[
"protected",
"function",
"generate_session_id",
"(",
")",
"{",
"$",
"length",
"=",
"40",
";",
"require_once",
"ABSPATH",
".",
"'wp-includes/class-phpass.php'",
";",
"$",
"bytes",
"=",
"(",
"new",
"\\",
"PasswordHash",
"(",
"8",
",",
"false",
")",
")",
"->",
"get_random_bytes",
"(",
"$",
"length",
"*",
"2",
")",
";",
"return",
"substr",
"(",
"str_replace",
"(",
"[",
"'/'",
",",
"'+'",
",",
"'='",
"]",
",",
"''",
",",
"base64_encode",
"(",
"$",
"bytes",
")",
")",
",",
"0",
",",
"$",
"length",
")",
";",
"}"
] |
Get a new, random session ID.
@return string
|
[
"Get",
"a",
"new",
"random",
"session",
"ID",
"."
] |
train
|
https://github.com/awethemes/wp-session/blob/4819c6392a0dbcbbf547027b70d5af88e7a89d61/src/Store.php#L468-L475
|
drunomics/service-utils
|
src/Core/Routing/CurrentRouteMatchTrait.php
|
CurrentRouteMatchTrait.getCurrentRouteMatch
|
public function getCurrentRouteMatch() {
if (empty($this->currentRouteMatch)) {
$this->currentRouteMatch = \Drupal::service('current_route_match');
}
return $this->currentRouteMatch;
}
|
php
|
public function getCurrentRouteMatch() {
if (empty($this->currentRouteMatch)) {
$this->currentRouteMatch = \Drupal::service('current_route_match');
}
return $this->currentRouteMatch;
}
|
[
"public",
"function",
"getCurrentRouteMatch",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"currentRouteMatch",
")",
")",
"{",
"$",
"this",
"->",
"currentRouteMatch",
"=",
"\\",
"Drupal",
"::",
"service",
"(",
"'current_route_match'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"currentRouteMatch",
";",
"}"
] |
Gets the current route match.
@return \Drupal\Core\Routing\ResettableStackedRouteMatchInterface
The alias manager.
|
[
"Gets",
"the",
"current",
"route",
"match",
"."
] |
train
|
https://github.com/drunomics/service-utils/blob/56761750043132365ef4ae5d9e0cf4263459328f/src/Core/Routing/CurrentRouteMatchTrait.php#L38-L43
|
GokulSrinivas/Sangria
|
src/Sangria/HelperFunctions.php
|
HelperFunctions.ddp
|
public static function ddp($obj = NULL)
{
try
{
$json_str = json_encode($obj, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
echo $json_str;
die();
}
catch(SangriaException $e)
{
/**
* Default to dd if there is an exception while encoding to JSON
*/
var_dump($obj);
die();
}
}
|
php
|
public static function ddp($obj = NULL)
{
try
{
$json_str = json_encode($obj, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
echo $json_str;
die();
}
catch(SangriaException $e)
{
/**
* Default to dd if there is an exception while encoding to JSON
*/
var_dump($obj);
die();
}
}
|
[
"public",
"static",
"function",
"ddp",
"(",
"$",
"obj",
"=",
"NULL",
")",
"{",
"try",
"{",
"$",
"json_str",
"=",
"json_encode",
"(",
"$",
"obj",
",",
"JSON_UNESCAPED_SLASHES",
"|",
"JSON_PRETTY_PRINT",
")",
";",
"echo",
"$",
"json_str",
";",
"die",
"(",
")",
";",
"}",
"catch",
"(",
"SangriaException",
"$",
"e",
")",
"{",
"/**\n\t\t\t * Default to dd if there is an exception while encoding to JSON\n\t\t\t */",
"var_dump",
"(",
"$",
"obj",
")",
";",
"die",
"(",
")",
";",
"}",
"}"
] |
[ddp prints the json_encoded form of the variable and stops execution]
@param mixed $obj [the variable to be dumped]
@return void [returns nothing]
|
[
"[",
"ddp",
"prints",
"the",
"json_encoded",
"form",
"of",
"the",
"variable",
"and",
"stops",
"execution",
"]"
] |
train
|
https://github.com/GokulSrinivas/Sangria/blob/e69076655da30ef74b9b6f4a7b7317b3d37d5710/src/Sangria/HelperFunctions.php#L28-L44
|
crossjoin/Css
|
src/Crossjoin/Css/Reader/CssString.php
|
CssString.setCssContent
|
protected function setCssContent($cssContent)
{
if (is_string($cssContent)) {
$this->content = $cssContent;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($cssContent). "' for argument 'cssContent' given."
);
}
return $this;
}
|
php
|
protected function setCssContent($cssContent)
{
if (is_string($cssContent)) {
$this->content = $cssContent;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($cssContent). "' for argument 'cssContent' given."
);
}
return $this;
}
|
[
"protected",
"function",
"setCssContent",
"(",
"$",
"cssContent",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"cssContent",
")",
")",
"{",
"$",
"this",
"->",
"content",
"=",
"$",
"cssContent",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid type '\"",
".",
"gettype",
"(",
"$",
"cssContent",
")",
".",
"\"' for argument 'cssContent' given.\"",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Sets the CSS source content.
@param string $cssContent
@return $this
|
[
"Sets",
"the",
"CSS",
"source",
"content",
"."
] |
train
|
https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Reader/CssString.php#L26-L37
|
huasituo/hstcms
|
src/Libraries/Fields/Text.php
|
Text.input
|
public function input($cname, $name, $cfg, $value = NULL, $id = 0)
{
$cfg['validate']['tips'] = isset($cfg['validate']['tips']) ? $cfg['validate']['tips'] : "";
$text = (isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1 ? '<font color="red">*</font>' : '').$cname;
// 表单附加参数
$attr = isset($cfg['validate']['formattr']) && $cfg['validate']['formattr'] ? $cfg['validate']['formattr'] : '';
// 表单宽度设置
$width = isset($cfg['option']['width']) && $cfg['option']['width'] ? $cfg['option']['width'] : '200';
$ispass = isset($cfg['option']['ispass']) && $cfg['option']['ispass'] ? $cfg['option']['ispass'] : 0;
$width = 'style="width:'.$width.(is_numeric($width) ? 'px' : '').';"';
// 字段提示信息
$tips = ($name == 'title') || (isset($cfg['validate']['tips']) && $cfg['validate']['tips']) ? ''.$cfg['validate']['tips'].'' : '';
// 字段默认值
if(!$value) {
$value = isset($cfg['option']['value']) && $cfg['option']['value'] ? htmlspecialchars_decode($cfg['option']['value']) : "";
} else {
$value = isset($value) && $value ? htmlspecialchars_decode($value) : "";
}
//修改
$disabled = !$this->isadmin && $id && $value && isset($cfg['validate']['isedit']) && !$cfg['validate']['isedit'] ? ' disabled' : ' ';
$_type = $ispass ? 'password' : 'text';
// 当字段必填时,加入html5验证标签
$required = isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1 ? ' required="required"' : '';
return $this->input_format($name, $text, '<input class="hstui-input" type="'.$_type.'" name="'.$name.'" id="hstcms_'.$name.'" value="'.$value.'" '.$width . $disabled . $required . $attr .' >', $tips);
}
|
php
|
public function input($cname, $name, $cfg, $value = NULL, $id = 0)
{
$cfg['validate']['tips'] = isset($cfg['validate']['tips']) ? $cfg['validate']['tips'] : "";
$text = (isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1 ? '<font color="red">*</font>' : '').$cname;
// 表单附加参数
$attr = isset($cfg['validate']['formattr']) && $cfg['validate']['formattr'] ? $cfg['validate']['formattr'] : '';
// 表单宽度设置
$width = isset($cfg['option']['width']) && $cfg['option']['width'] ? $cfg['option']['width'] : '200';
$ispass = isset($cfg['option']['ispass']) && $cfg['option']['ispass'] ? $cfg['option']['ispass'] : 0;
$width = 'style="width:'.$width.(is_numeric($width) ? 'px' : '').';"';
// 字段提示信息
$tips = ($name == 'title') || (isset($cfg['validate']['tips']) && $cfg['validate']['tips']) ? ''.$cfg['validate']['tips'].'' : '';
// 字段默认值
if(!$value) {
$value = isset($cfg['option']['value']) && $cfg['option']['value'] ? htmlspecialchars_decode($cfg['option']['value']) : "";
} else {
$value = isset($value) && $value ? htmlspecialchars_decode($value) : "";
}
//修改
$disabled = !$this->isadmin && $id && $value && isset($cfg['validate']['isedit']) && !$cfg['validate']['isedit'] ? ' disabled' : ' ';
$_type = $ispass ? 'password' : 'text';
// 当字段必填时,加入html5验证标签
$required = isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1 ? ' required="required"' : '';
return $this->input_format($name, $text, '<input class="hstui-input" type="'.$_type.'" name="'.$name.'" id="hstcms_'.$name.'" value="'.$value.'" '.$width . $disabled . $required . $attr .' >', $tips);
}
|
[
"public",
"function",
"input",
"(",
"$",
"cname",
",",
"$",
"name",
",",
"$",
"cfg",
",",
"$",
"value",
"=",
"NULL",
",",
"$",
"id",
"=",
"0",
")",
"{",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'tips'",
"]",
"=",
"isset",
"(",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'tips'",
"]",
")",
"?",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'tips'",
"]",
":",
"\"\"",
";",
"$",
"text",
"=",
"(",
"isset",
"(",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'required'",
"]",
")",
"&&",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'required'",
"]",
"==",
"1",
"?",
"'<font color=\"red\">*</font>'",
":",
"''",
")",
".",
"$",
"cname",
";",
"// 表单附加参数",
"$",
"attr",
"=",
"isset",
"(",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'formattr'",
"]",
")",
"&&",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'formattr'",
"]",
"?",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'formattr'",
"]",
":",
"''",
";",
"// 表单宽度设置",
"$",
"width",
"=",
"isset",
"(",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'width'",
"]",
")",
"&&",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'width'",
"]",
"?",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'width'",
"]",
":",
"'200'",
";",
"$",
"ispass",
"=",
"isset",
"(",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'ispass'",
"]",
")",
"&&",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'ispass'",
"]",
"?",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'ispass'",
"]",
":",
"0",
";",
"$",
"width",
"=",
"'style=\"width:'",
".",
"$",
"width",
".",
"(",
"is_numeric",
"(",
"$",
"width",
")",
"?",
"'px'",
":",
"''",
")",
".",
"';\"'",
";",
"// 字段提示信息",
"$",
"tips",
"=",
"(",
"$",
"name",
"==",
"'title'",
")",
"||",
"(",
"isset",
"(",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'tips'",
"]",
")",
"&&",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'tips'",
"]",
")",
"?",
"''",
".",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'tips'",
"]",
".",
"''",
":",
"''",
";",
"// 字段默认值",
"if",
"(",
"!",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"isset",
"(",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'value'",
"]",
")",
"&&",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'value'",
"]",
"?",
"htmlspecialchars_decode",
"(",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'value'",
"]",
")",
":",
"\"\"",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"isset",
"(",
"$",
"value",
")",
"&&",
"$",
"value",
"?",
"htmlspecialchars_decode",
"(",
"$",
"value",
")",
":",
"\"\"",
";",
"}",
"//修改",
"$",
"disabled",
"=",
"!",
"$",
"this",
"->",
"isadmin",
"&&",
"$",
"id",
"&&",
"$",
"value",
"&&",
"isset",
"(",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'isedit'",
"]",
")",
"&&",
"!",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'isedit'",
"]",
"?",
"' disabled'",
":",
"' '",
";",
"$",
"_type",
"=",
"$",
"ispass",
"?",
"'password'",
":",
"'text'",
";",
"// 当字段必填时,加入html5验证标签",
"$",
"required",
"=",
"isset",
"(",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'required'",
"]",
")",
"&&",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'required'",
"]",
"==",
"1",
"?",
"' required=\"required\"'",
":",
"''",
";",
"return",
"$",
"this",
"->",
"input_format",
"(",
"$",
"name",
",",
"$",
"text",
",",
"'<input class=\"hstui-input\" type=\"'",
".",
"$",
"_type",
".",
"'\" name=\"'",
".",
"$",
"name",
".",
"'\" id=\"hstcms_'",
".",
"$",
"name",
".",
"'\" value=\"'",
".",
"$",
"value",
".",
"'\" '",
".",
"$",
"width",
".",
"$",
"disabled",
".",
"$",
"required",
".",
"$",
"attr",
".",
"' >'",
",",
"$",
"tips",
")",
";",
"}"
] |
字段表单输入
@param string $cname 字段别名
@param string $name 字段名称
@param array $cfg 字段配置
@param array $value 值
@param array $id 当前内容表的id(表示非发布操作)
@return string
|
[
"字段表单输入"
] |
train
|
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Fields/Text.php#L67-L91
|
huasituo/hstcms
|
src/Libraries/Fields/Text.php
|
Text.insert_value
|
public function insert_value(Request $request, $filed, $postData = [])
{
$value = $request->get($field['fieldname']);
$postData[$field['relatedtable']] = [
$fieldname=>htmlspecialchars($value)
];
return $postData;
}
|
php
|
public function insert_value(Request $request, $filed, $postData = [])
{
$value = $request->get($field['fieldname']);
$postData[$field['relatedtable']] = [
$fieldname=>htmlspecialchars($value)
];
return $postData;
}
|
[
"public",
"function",
"insert_value",
"(",
"Request",
"$",
"request",
",",
"$",
"filed",
",",
"$",
"postData",
"=",
"[",
"]",
")",
"{",
"$",
"value",
"=",
"$",
"request",
"->",
"get",
"(",
"$",
"field",
"[",
"'fieldname'",
"]",
")",
";",
"$",
"postData",
"[",
"$",
"field",
"[",
"'relatedtable'",
"]",
"]",
"=",
"[",
"$",
"fieldname",
"=>",
"htmlspecialchars",
"(",
"$",
"value",
")",
"]",
";",
"return",
"$",
"postData",
";",
"}"
] |
处理输入数据,提供给入库
|
[
"处理输入数据,提供给入库"
] |
train
|
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Fields/Text.php#L96-L103
|
FrenchFrogs/framework
|
src/Table/Renderer/Csv.php
|
Csv.table
|
public function table(Table\Table $table)
{
// INitilisation du CSV
$csv = Writer::createFromFileObject(new \SplTempFileObject());
// gestion des colonne
$header = $columns = [];
foreach ($table->getColumns() as $index => $column) {
// Seule les colonnes Exportable peuvent être exporté
if ($column instanceof Exportable) {
$columns[$index] = $column;
$header[$index] = $column->getLabel();
}
}
// insertion du header
$csv->insertOne(array_values($header));
//@todo mettre en place un streaming pour économiser la memoire
// insertion des lignes
foreach ($table->getRows() as $row) {
$line = [];
foreach (array_keys($header) as $index) {
$line[] = $columns[$index]->getValue($row);
}
$csv->insertOne($line);
}
$csv->output($table->getFilename());
exit;
}
|
php
|
public function table(Table\Table $table)
{
// INitilisation du CSV
$csv = Writer::createFromFileObject(new \SplTempFileObject());
// gestion des colonne
$header = $columns = [];
foreach ($table->getColumns() as $index => $column) {
// Seule les colonnes Exportable peuvent être exporté
if ($column instanceof Exportable) {
$columns[$index] = $column;
$header[$index] = $column->getLabel();
}
}
// insertion du header
$csv->insertOne(array_values($header));
//@todo mettre en place un streaming pour économiser la memoire
// insertion des lignes
foreach ($table->getRows() as $row) {
$line = [];
foreach (array_keys($header) as $index) {
$line[] = $columns[$index]->getValue($row);
}
$csv->insertOne($line);
}
$csv->output($table->getFilename());
exit;
}
|
[
"public",
"function",
"table",
"(",
"Table",
"\\",
"Table",
"$",
"table",
")",
"{",
"// INitilisation du CSV",
"$",
"csv",
"=",
"Writer",
"::",
"createFromFileObject",
"(",
"new",
"\\",
"SplTempFileObject",
"(",
")",
")",
";",
"// gestion des colonne",
"$",
"header",
"=",
"$",
"columns",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"table",
"->",
"getColumns",
"(",
")",
"as",
"$",
"index",
"=>",
"$",
"column",
")",
"{",
"// Seule les colonnes Exportable peuvent être exporté",
"if",
"(",
"$",
"column",
"instanceof",
"Exportable",
")",
"{",
"$",
"columns",
"[",
"$",
"index",
"]",
"=",
"$",
"column",
";",
"$",
"header",
"[",
"$",
"index",
"]",
"=",
"$",
"column",
"->",
"getLabel",
"(",
")",
";",
"}",
"}",
"// insertion du header",
"$",
"csv",
"->",
"insertOne",
"(",
"array_values",
"(",
"$",
"header",
")",
")",
";",
"//@todo mettre en place un streaming pour économiser la memoire",
"// insertion des lignes",
"foreach",
"(",
"$",
"table",
"->",
"getRows",
"(",
")",
"as",
"$",
"row",
")",
"{",
"$",
"line",
"=",
"[",
"]",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"header",
")",
"as",
"$",
"index",
")",
"{",
"$",
"line",
"[",
"]",
"=",
"$",
"columns",
"[",
"$",
"index",
"]",
"->",
"getValue",
"(",
"$",
"row",
")",
";",
"}",
"$",
"csv",
"->",
"insertOne",
"(",
"$",
"line",
")",
";",
"}",
"$",
"csv",
"->",
"output",
"(",
"$",
"table",
"->",
"getFilename",
"(",
")",
")",
";",
"exit",
";",
"}"
] |
Overload render for array data output
@param \FrenchFrogs\Table\Table\Table $table
@return array
|
[
"Overload",
"render",
"for",
"array",
"data",
"output"
] |
train
|
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Renderer/Csv.php#L23-L55
|
rinvex/obsolete-module
|
src/Module.php
|
Module.migrate
|
protected function migrate()
{
if (! $this->container['migrator']->repositoryExists()) {
throw new Exception('Migration table not found.');
}
$this->container['migrator']->run($this->getAttribute('path').'/database/migrations');
}
|
php
|
protected function migrate()
{
if (! $this->container['migrator']->repositoryExists()) {
throw new Exception('Migration table not found.');
}
$this->container['migrator']->run($this->getAttribute('path').'/database/migrations');
}
|
[
"protected",
"function",
"migrate",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"container",
"[",
"'migrator'",
"]",
"->",
"repositoryExists",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Migration table not found.'",
")",
";",
"}",
"$",
"this",
"->",
"container",
"[",
"'migrator'",
"]",
"->",
"run",
"(",
"$",
"this",
"->",
"getAttribute",
"(",
"'path'",
")",
".",
"'/database/migrations'",
")",
";",
"}"
] |
Execute module migrations.
@throws \Exception
@return void
|
[
"Execute",
"module",
"migrations",
"."
] |
train
|
https://github.com/rinvex/obsolete-module/blob/95e372ae97ecbe7071c3da397b0afd57f327361f/src/Module.php#L160-L167
|
rinvex/obsolete-module
|
src/Module.php
|
Module.rollback
|
protected function rollback()
{
if (! $this->container['migrator']->repositoryExists()) {
throw new Exception('Migration table not found.');
}
$this->container['migrator']->rollback($this->getAttribute('path').'/database/migrations');
}
|
php
|
protected function rollback()
{
if (! $this->container['migrator']->repositoryExists()) {
throw new Exception('Migration table not found.');
}
$this->container['migrator']->rollback($this->getAttribute('path').'/database/migrations');
}
|
[
"protected",
"function",
"rollback",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"container",
"[",
"'migrator'",
"]",
"->",
"repositoryExists",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Migration table not found.'",
")",
";",
"}",
"$",
"this",
"->",
"container",
"[",
"'migrator'",
"]",
"->",
"rollback",
"(",
"$",
"this",
"->",
"getAttribute",
"(",
"'path'",
")",
".",
"'/database/migrations'",
")",
";",
"}"
] |
Rollback module migrations.
@throws \Exception
@return void
|
[
"Rollback",
"module",
"migrations",
"."
] |
train
|
https://github.com/rinvex/obsolete-module/blob/95e372ae97ecbe7071c3da397b0afd57f327361f/src/Module.php#L176-L183
|
rinvex/obsolete-module
|
src/Module.php
|
Module.seed
|
protected function seed()
{
$seederFilePath = $this->getAttribute('path').'/database/seeds/DatabaseSeeder.php';
if ($this->container['files']->exists($seederFilePath)) {
require_once $seederFilePath;
$namespace = $this->getAttribute('namespace').'Database\\Seeds\\DatabaseSeeder';
$class = '\\'.ltrim($namespace, '\\');
$seeder = new $class();
$seeder->run();
}
}
|
php
|
protected function seed()
{
$seederFilePath = $this->getAttribute('path').'/database/seeds/DatabaseSeeder.php';
if ($this->container['files']->exists($seederFilePath)) {
require_once $seederFilePath;
$namespace = $this->getAttribute('namespace').'Database\\Seeds\\DatabaseSeeder';
$class = '\\'.ltrim($namespace, '\\');
$seeder = new $class();
$seeder->run();
}
}
|
[
"protected",
"function",
"seed",
"(",
")",
"{",
"$",
"seederFilePath",
"=",
"$",
"this",
"->",
"getAttribute",
"(",
"'path'",
")",
".",
"'/database/seeds/DatabaseSeeder.php'",
";",
"if",
"(",
"$",
"this",
"->",
"container",
"[",
"'files'",
"]",
"->",
"exists",
"(",
"$",
"seederFilePath",
")",
")",
"{",
"require_once",
"$",
"seederFilePath",
";",
"$",
"namespace",
"=",
"$",
"this",
"->",
"getAttribute",
"(",
"'namespace'",
")",
".",
"'Database\\\\Seeds\\\\DatabaseSeeder'",
";",
"$",
"class",
"=",
"'\\\\'",
".",
"ltrim",
"(",
"$",
"namespace",
",",
"'\\\\'",
")",
";",
"$",
"seeder",
"=",
"new",
"$",
"class",
"(",
")",
";",
"$",
"seeder",
"->",
"run",
"(",
")",
";",
"}",
"}"
] |
Seed the database with module seeders.
@return void
|
[
"Seed",
"the",
"database",
"with",
"module",
"seeders",
"."
] |
train
|
https://github.com/rinvex/obsolete-module/blob/95e372ae97ecbe7071c3da397b0afd57f327361f/src/Module.php#L190-L203
|
acasademont/wurfl
|
WURFL/Request/GenericRequest.php
|
WURFL_Request_GenericRequest.getOriginalHeader
|
public function getOriginalHeader($name)
{
return array_key_exists($name, $this->_request)? $this->_request[$name]: null;
}
|
php
|
public function getOriginalHeader($name)
{
return array_key_exists($name, $this->_request)? $this->_request[$name]: null;
}
|
[
"public",
"function",
"getOriginalHeader",
"(",
"$",
"name",
")",
"{",
"return",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"_request",
")",
"?",
"$",
"this",
"->",
"_request",
"[",
"$",
"name",
"]",
":",
"null",
";",
"}"
] |
Get the original HTTP header value from the request
@param string $name
@return string
|
[
"Get",
"the",
"original",
"HTTP",
"header",
"value",
"from",
"the",
"request"
] |
train
|
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/Request/GenericRequest.php#L97-L100
|
chris-schmitz/L5SimpleFM
|
src/L5SimpleFMBase.php
|
L5SimpleFMBase.primeCommandArray
|
protected function primeCommandArray()
{
if (empty($this->layoutName)) {
throw new LayoutNameIsMissingException('You must specify a layout name.');
}
$this->commandArray['-db'] = $this->adapter->getHostConnection()->getDbName();
$this->commandArray['-lay'] = $this->layoutName;
}
|
php
|
protected function primeCommandArray()
{
if (empty($this->layoutName)) {
throw new LayoutNameIsMissingException('You must specify a layout name.');
}
$this->commandArray['-db'] = $this->adapter->getHostConnection()->getDbName();
$this->commandArray['-lay'] = $this->layoutName;
}
|
[
"protected",
"function",
"primeCommandArray",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"layoutName",
")",
")",
"{",
"throw",
"new",
"LayoutNameIsMissingException",
"(",
"'You must specify a layout name.'",
")",
";",
"}",
"$",
"this",
"->",
"commandArray",
"[",
"'-db'",
"]",
"=",
"$",
"this",
"->",
"adapter",
"->",
"getHostConnection",
"(",
")",
"->",
"getDbName",
"(",
")",
";",
"$",
"this",
"->",
"commandArray",
"[",
"'-lay'",
"]",
"=",
"$",
"this",
"->",
"layoutName",
";",
"}"
] |
Adds the default url parameters needed for any request.
@return none
|
[
"Adds",
"the",
"default",
"url",
"parameters",
"needed",
"for",
"any",
"request",
"."
] |
train
|
https://github.com/chris-schmitz/L5SimpleFM/blob/9c3250e0918184d537a46c15140f15527e833a4c/src/L5SimpleFMBase.php#L39-L46
|
chris-schmitz/L5SimpleFM
|
src/L5SimpleFMBase.php
|
L5SimpleFMBase.addToCommandArray
|
protected function addToCommandArray($values)
{
foreach ($values as $key => $value) {
$this->commandArray[$key] = $value;
}
}
|
php
|
protected function addToCommandArray($values)
{
foreach ($values as $key => $value) {
$this->commandArray[$key] = $value;
}
}
|
[
"protected",
"function",
"addToCommandArray",
"(",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"commandArray",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}"
] |
Adds additional Url parameters to the request.
@param array An associative array of url keys and values.
These are normally fields => values or additional FM XML flags => null
|
[
"Adds",
"additional",
"Url",
"parameters",
"to",
"the",
"request",
"."
] |
train
|
https://github.com/chris-schmitz/L5SimpleFM/blob/9c3250e0918184d537a46c15140f15527e833a4c/src/L5SimpleFMBase.php#L54-L59
|
chris-schmitz/L5SimpleFM
|
src/L5SimpleFMBase.php
|
L5SimpleFMBase.executeCommand
|
public function executeCommand()
{
$this->adapter->setCommandArray($this->commandArray);
$result = $this->adapter->execute();
$commandArrayUsed = $this->adapter->getCommandArray();
$this->clearCommandArray();
$this->checkResultForError($result, $commandArrayUsed);
return $result;
}
|
php
|
public function executeCommand()
{
$this->adapter->setCommandArray($this->commandArray);
$result = $this->adapter->execute();
$commandArrayUsed = $this->adapter->getCommandArray();
$this->clearCommandArray();
$this->checkResultForError($result, $commandArrayUsed);
return $result;
}
|
[
"public",
"function",
"executeCommand",
"(",
")",
"{",
"$",
"this",
"->",
"adapter",
"->",
"setCommandArray",
"(",
"$",
"this",
"->",
"commandArray",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"adapter",
"->",
"execute",
"(",
")",
";",
"$",
"commandArrayUsed",
"=",
"$",
"this",
"->",
"adapter",
"->",
"getCommandArray",
"(",
")",
";",
"$",
"this",
"->",
"clearCommandArray",
"(",
")",
";",
"$",
"this",
"->",
"checkResultForError",
"(",
"$",
"result",
",",
"$",
"commandArrayUsed",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Performs the steps necessary to execute a SimpleFM query.
@return object The SimpleFM result Object
|
[
"Performs",
"the",
"steps",
"necessary",
"to",
"execute",
"a",
"SimpleFM",
"query",
"."
] |
train
|
https://github.com/chris-schmitz/L5SimpleFM/blob/9c3250e0918184d537a46c15140f15527e833a4c/src/L5SimpleFMBase.php#L77-L85
|
chris-schmitz/L5SimpleFM
|
src/L5SimpleFMBase.php
|
L5SimpleFMBase.checkResultForError
|
protected function checkResultForError($result, $commandArrayUsed)
{
if (empty($result)) {
throw new NoResultReturnedException('The SimpleFM request did not return a result.');
}
if ($result->getErrorCode() == 401) {
throw new RecordsNotFoundException($result->getErrorMessage(), $result->getErrorCode(), $result);
}
if ($result->getErrorCode() !== 0) {
$message = $result->getErrorMessage() . ". Command used: " . json_encode($commandArrayUsed);
throw new GeneralException($message, $result->getErrorCode(), $result);
}
}
|
php
|
protected function checkResultForError($result, $commandArrayUsed)
{
if (empty($result)) {
throw new NoResultReturnedException('The SimpleFM request did not return a result.');
}
if ($result->getErrorCode() == 401) {
throw new RecordsNotFoundException($result->getErrorMessage(), $result->getErrorCode(), $result);
}
if ($result->getErrorCode() !== 0) {
$message = $result->getErrorMessage() . ". Command used: " . json_encode($commandArrayUsed);
throw new GeneralException($message, $result->getErrorCode(), $result);
}
}
|
[
"protected",
"function",
"checkResultForError",
"(",
"$",
"result",
",",
"$",
"commandArrayUsed",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"throw",
"new",
"NoResultReturnedException",
"(",
"'The SimpleFM request did not return a result.'",
")",
";",
"}",
"if",
"(",
"$",
"result",
"->",
"getErrorCode",
"(",
")",
"==",
"401",
")",
"{",
"throw",
"new",
"RecordsNotFoundException",
"(",
"$",
"result",
"->",
"getErrorMessage",
"(",
")",
",",
"$",
"result",
"->",
"getErrorCode",
"(",
")",
",",
"$",
"result",
")",
";",
"}",
"if",
"(",
"$",
"result",
"->",
"getErrorCode",
"(",
")",
"!==",
"0",
")",
"{",
"$",
"message",
"=",
"$",
"result",
"->",
"getErrorMessage",
"(",
")",
".",
"\". Command used: \"",
".",
"json_encode",
"(",
"$",
"commandArrayUsed",
")",
";",
"throw",
"new",
"GeneralException",
"(",
"$",
"message",
",",
"$",
"result",
"->",
"getErrorCode",
"(",
")",
",",
"$",
"result",
")",
";",
"}",
"}"
] |
Parses the SimpleFM result and determines if a FileMaker error was thrown.
@param object A SimpleFM result object
@return none
|
[
"Parses",
"the",
"SimpleFM",
"result",
"and",
"determines",
"if",
"a",
"FileMaker",
"error",
"was",
"thrown",
"."
] |
train
|
https://github.com/chris-schmitz/L5SimpleFM/blob/9c3250e0918184d537a46c15140f15527e833a4c/src/L5SimpleFMBase.php#L93-L105
|
link0/profiler
|
src/Link0/Profiler/PersistenceService.php
|
PersistenceService.persist
|
public function persist(ProfileInterface $profile)
{
foreach ($this->persistenceHandlers as $persistenceHandler) {
$persistenceHandler->persist($profile);
}
return $this;
}
|
php
|
public function persist(ProfileInterface $profile)
{
foreach ($this->persistenceHandlers as $persistenceHandler) {
$persistenceHandler->persist($profile);
}
return $this;
}
|
[
"public",
"function",
"persist",
"(",
"ProfileInterface",
"$",
"profile",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"persistenceHandlers",
"as",
"$",
"persistenceHandler",
")",
"{",
"$",
"persistenceHandler",
"->",
"persist",
"(",
"$",
"profile",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Persists data to the persistence handlers
@param ProfileInterface $profile
@return PersistenceService $this
|
[
"Persists",
"data",
"to",
"the",
"persistence",
"handlers"
] |
train
|
https://github.com/link0/profiler/blob/0573073ff029743734de747619ab65ab2476052d/src/Link0/Profiler/PersistenceService.php#L77-L84
|
Teamsisu/contao-mm-frontendInput
|
src/Teamsisu/MetaModelsFrontendInput/DataContainer/Field/BaseField.php
|
BaseField.removeEval
|
public function removeEval($key)
{
if (array_key_exists($key, $this->eval)) {
unset($this->eval[$key]);
return true;
}
return false;
}
|
php
|
public function removeEval($key)
{
if (array_key_exists($key, $this->eval)) {
unset($this->eval[$key]);
return true;
}
return false;
}
|
[
"public",
"function",
"removeEval",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"eval",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"eval",
"[",
"$",
"key",
"]",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Remove an entry vom the eval array
Returns true if entry was removed and false if key was not found
@param string $key
@return bool
|
[
"Remove",
"an",
"entry",
"vom",
"the",
"eval",
"array",
"Returns",
"true",
"if",
"entry",
"was",
"removed",
"and",
"false",
"if",
"key",
"was",
"not",
"found"
] |
train
|
https://github.com/Teamsisu/contao-mm-frontendInput/blob/ab92e61c24644f1e61265304b6a35e505007d021/src/Teamsisu/MetaModelsFrontendInput/DataContainer/Field/BaseField.php#L85-L95
|
Teamsisu/contao-mm-frontendInput
|
src/Teamsisu/MetaModelsFrontendInput/DataContainer/Field/BaseField.php
|
BaseField.modifyEval
|
public function modifyEval($key, $value)
{
if (array_key_exists($key, $this->eval)) {
$this->eval[$key] = $value;
}
}
|
php
|
public function modifyEval($key, $value)
{
if (array_key_exists($key, $this->eval)) {
$this->eval[$key] = $value;
}
}
|
[
"public",
"function",
"modifyEval",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"eval",
")",
")",
"{",
"$",
"this",
"->",
"eval",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}"
] |
Set a new value to an existing eval entry
@param string $key
@param mixed $value
|
[
"Set",
"a",
"new",
"value",
"to",
"an",
"existing",
"eval",
"entry"
] |
train
|
https://github.com/Teamsisu/contao-mm-frontendInput/blob/ab92e61c24644f1e61265304b6a35e505007d021/src/Teamsisu/MetaModelsFrontendInput/DataContainer/Field/BaseField.php#L103-L110
|
Teamsisu/contao-mm-frontendInput
|
src/Teamsisu/MetaModelsFrontendInput/DataContainer/Field/BaseField.php
|
BaseField.getEval
|
public function getEval($key)
{
if (array_key_exists($key, $this->eval)) {
return $this->eval[$key];
}
return false;
}
|
php
|
public function getEval($key)
{
if (array_key_exists($key, $this->eval)) {
return $this->eval[$key];
}
return false;
}
|
[
"public",
"function",
"getEval",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"eval",
")",
")",
"{",
"return",
"$",
"this",
"->",
"eval",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"false",
";",
"}"
] |
Get an entry from the eval array
Returns the entry or false if key not found
@param string $key
@return mixed|bool
|
[
"Get",
"an",
"entry",
"from",
"the",
"eval",
"array",
"Returns",
"the",
"entry",
"or",
"false",
"if",
"key",
"not",
"found"
] |
train
|
https://github.com/Teamsisu/contao-mm-frontendInput/blob/ab92e61c24644f1e61265304b6a35e505007d021/src/Teamsisu/MetaModelsFrontendInput/DataContainer/Field/BaseField.php#L119-L126
|
yosmanyga/resource
|
src/Yosmanyga/Resource/Cacher/Checker/TtlChecker.php
|
TtlChecker.add
|
public function add(Resource $resource)
{
$this->storer->add(
time() + $this->ttl,
$resource
);
}
|
php
|
public function add(Resource $resource)
{
$this->storer->add(
time() + $this->ttl,
$resource
);
}
|
[
"public",
"function",
"add",
"(",
"Resource",
"$",
"resource",
")",
"{",
"$",
"this",
"->",
"storer",
"->",
"add",
"(",
"time",
"(",
")",
"+",
"$",
"this",
"->",
"ttl",
",",
"$",
"resource",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/yosmanyga/resource/blob/a8b505c355920a908917a0484f764ddfa63205fa/src/Yosmanyga/Resource/Cacher/Checker/TtlChecker.php#L38-L44
|
yosmanyga/resource
|
src/Yosmanyga/Resource/Cacher/Checker/TtlChecker.php
|
TtlChecker.check
|
public function check(Resource $resource)
{
if (!$this->storer->has($resource)) {
return false;
}
return $this->storer->get($resource) >= time();
}
|
php
|
public function check(Resource $resource)
{
if (!$this->storer->has($resource)) {
return false;
}
return $this->storer->get($resource) >= time();
}
|
[
"public",
"function",
"check",
"(",
"Resource",
"$",
"resource",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"storer",
"->",
"has",
"(",
"$",
"resource",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"storer",
"->",
"get",
"(",
"$",
"resource",
")",
">=",
"time",
"(",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/yosmanyga/resource/blob/a8b505c355920a908917a0484f764ddfa63205fa/src/Yosmanyga/Resource/Cacher/Checker/TtlChecker.php#L49-L56
|
pageon/SlackWebhookMonolog
|
src/Slack/Attachment/ParametersAttachment.php
|
ParametersAttachment.parseParameter
|
private function parseParameter($parameter)
{
if (!is_array($parameter)) {
return print_r($parameter, true);
}
return $this->parseArrayParameter($parameter);
}
|
php
|
private function parseParameter($parameter)
{
if (!is_array($parameter)) {
return print_r($parameter, true);
}
return $this->parseArrayParameter($parameter);
}
|
[
"private",
"function",
"parseParameter",
"(",
"$",
"parameter",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"parameter",
")",
")",
"{",
"return",
"print_r",
"(",
"$",
"parameter",
",",
"true",
")",
";",
"}",
"return",
"$",
"this",
"->",
"parseArrayParameter",
"(",
"$",
"parameter",
")",
";",
"}"
] |
Parse all the data into the markup of slack.
@param mixed $parameter
@return string
|
[
"Parse",
"all",
"the",
"data",
"into",
"the",
"markup",
"of",
"slack",
"."
] |
train
|
https://github.com/pageon/SlackWebhookMonolog/blob/6755060ddd6429620fd4c7decbb95f05463fc36b/src/Slack/Attachment/ParametersAttachment.php#L53-L60
|
pageon/SlackWebhookMonolog
|
src/Slack/Attachment/ParametersAttachment.php
|
ParametersAttachment.parseArrayParameter
|
private function parseArrayParameter(array $parameter)
{
return "\n" . $this->formatter->arrayToKeyValueList(
array_map(
function ($item) {
return print_r($item, true);
},
$parameter
)
);
}
|
php
|
private function parseArrayParameter(array $parameter)
{
return "\n" . $this->formatter->arrayToKeyValueList(
array_map(
function ($item) {
return print_r($item, true);
},
$parameter
)
);
}
|
[
"private",
"function",
"parseArrayParameter",
"(",
"array",
"$",
"parameter",
")",
"{",
"return",
"\"\\n\"",
".",
"$",
"this",
"->",
"formatter",
"->",
"arrayToKeyValueList",
"(",
"array_map",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"return",
"print_r",
"(",
"$",
"item",
",",
"true",
")",
";",
"}",
",",
"$",
"parameter",
")",
")",
";",
"}"
] |
@param array $parameter
@return string
|
[
"@param",
"array",
"$parameter"
] |
train
|
https://github.com/pageon/SlackWebhookMonolog/blob/6755060ddd6429620fd4c7decbb95f05463fc36b/src/Slack/Attachment/ParametersAttachment.php#L67-L77
|
crossjoin/Css
|
src/Crossjoin/Css/Helper/Placeholder.php
|
Placeholder.replaceStringsAndComments
|
public static function replaceStringsAndComments($text)
{
if (is_string($text)) {
// Fast pre-check, to optimize performance
if (strpos($text, "'") !== false || strpos($text, '"') !== false) {
// Replace all strings in quotes (also in comments, but that's okay - removed in next step)
$replaceStringCallback = function ($matches) {
return self::addStringReplacement($matches[1] . $matches[2] . $matches[1]);
};
$text = preg_replace('/\r/', '', $text);
$text = preg_replace('/\\\\\n/', '_STRING_CSSLINEBREAK_', $text);
$text = preg_replace('/\\\\"/', '_STRING_ESCAPEDDOUBLEQUOTE_', $text);
$text = preg_replace('/\\\\\'/', '_STRING_ESCAPEDSINGLEQUOTE_', $text);
$text = preg_replace_callback('/("|\')(.*?)\g{1}/', $replaceStringCallback, $text);
}
if (strpos($text, "data:") !== false) {
// Replace all data URIs
// (that are not in quotes and therefor were not replaced by the previous check)
$replaceDataUriCallback = function ($matches) {
return self::addStringReplacement($matches[1]);
};
$text = preg_replace_callback(
'/(data:(?:[^;,]+)?(?:;charset=[^;,]+)?' .
'(?:;base64,(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?|,[-.a-zA-Z0-9_%]+))/',
$replaceDataUriCallback,
$text
);
}
// Fast pre-check, to optimize performance
if (strpos($text, "*") !== false) {
// Strip multi-line comments (after string replace to keep comments in strings)
$replaceCommentCallback = function ($matches) {
return self::addCommentReplacement($matches[1]);
};
$text = preg_replace_callback('/(\/\*.*?\*\/)/', $replaceCommentCallback, $text);
}
return $text;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($text). "' for argument 'text' given."
);
}
}
|
php
|
public static function replaceStringsAndComments($text)
{
if (is_string($text)) {
// Fast pre-check, to optimize performance
if (strpos($text, "'") !== false || strpos($text, '"') !== false) {
// Replace all strings in quotes (also in comments, but that's okay - removed in next step)
$replaceStringCallback = function ($matches) {
return self::addStringReplacement($matches[1] . $matches[2] . $matches[1]);
};
$text = preg_replace('/\r/', '', $text);
$text = preg_replace('/\\\\\n/', '_STRING_CSSLINEBREAK_', $text);
$text = preg_replace('/\\\\"/', '_STRING_ESCAPEDDOUBLEQUOTE_', $text);
$text = preg_replace('/\\\\\'/', '_STRING_ESCAPEDSINGLEQUOTE_', $text);
$text = preg_replace_callback('/("|\')(.*?)\g{1}/', $replaceStringCallback, $text);
}
if (strpos($text, "data:") !== false) {
// Replace all data URIs
// (that are not in quotes and therefor were not replaced by the previous check)
$replaceDataUriCallback = function ($matches) {
return self::addStringReplacement($matches[1]);
};
$text = preg_replace_callback(
'/(data:(?:[^;,]+)?(?:;charset=[^;,]+)?' .
'(?:;base64,(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?|,[-.a-zA-Z0-9_%]+))/',
$replaceDataUriCallback,
$text
);
}
// Fast pre-check, to optimize performance
if (strpos($text, "*") !== false) {
// Strip multi-line comments (after string replace to keep comments in strings)
$replaceCommentCallback = function ($matches) {
return self::addCommentReplacement($matches[1]);
};
$text = preg_replace_callback('/(\/\*.*?\*\/)/', $replaceCommentCallback, $text);
}
return $text;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($text). "' for argument 'text' given."
);
}
}
|
[
"public",
"static",
"function",
"replaceStringsAndComments",
"(",
"$",
"text",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"text",
")",
")",
"{",
"// Fast pre-check, to optimize performance",
"if",
"(",
"strpos",
"(",
"$",
"text",
",",
"\"'\"",
")",
"!==",
"false",
"||",
"strpos",
"(",
"$",
"text",
",",
"'\"'",
")",
"!==",
"false",
")",
"{",
"// Replace all strings in quotes (also in comments, but that's okay - removed in next step)",
"$",
"replaceStringCallback",
"=",
"function",
"(",
"$",
"matches",
")",
"{",
"return",
"self",
"::",
"addStringReplacement",
"(",
"$",
"matches",
"[",
"1",
"]",
".",
"$",
"matches",
"[",
"2",
"]",
".",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"}",
";",
"$",
"text",
"=",
"preg_replace",
"(",
"'/\\r/'",
",",
"''",
",",
"$",
"text",
")",
";",
"$",
"text",
"=",
"preg_replace",
"(",
"'/\\\\\\\\\\n/'",
",",
"'_STRING_CSSLINEBREAK_'",
",",
"$",
"text",
")",
";",
"$",
"text",
"=",
"preg_replace",
"(",
"'/\\\\\\\\\"/'",
",",
"'_STRING_ESCAPEDDOUBLEQUOTE_'",
",",
"$",
"text",
")",
";",
"$",
"text",
"=",
"preg_replace",
"(",
"'/\\\\\\\\\\'/'",
",",
"'_STRING_ESCAPEDSINGLEQUOTE_'",
",",
"$",
"text",
")",
";",
"$",
"text",
"=",
"preg_replace_callback",
"(",
"'/(\"|\\')(.*?)\\g{1}/'",
",",
"$",
"replaceStringCallback",
",",
"$",
"text",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"text",
",",
"\"data:\"",
")",
"!==",
"false",
")",
"{",
"// Replace all data URIs",
"// (that are not in quotes and therefor were not replaced by the previous check)",
"$",
"replaceDataUriCallback",
"=",
"function",
"(",
"$",
"matches",
")",
"{",
"return",
"self",
"::",
"addStringReplacement",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"}",
";",
"$",
"text",
"=",
"preg_replace_callback",
"(",
"'/(data:(?:[^;,]+)?(?:;charset=[^;,]+)?'",
".",
"'(?:;base64,(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=)?|,[-.a-zA-Z0-9_%]+))/'",
",",
"$",
"replaceDataUriCallback",
",",
"$",
"text",
")",
";",
"}",
"// Fast pre-check, to optimize performance",
"if",
"(",
"strpos",
"(",
"$",
"text",
",",
"\"*\"",
")",
"!==",
"false",
")",
"{",
"// Strip multi-line comments (after string replace to keep comments in strings)",
"$",
"replaceCommentCallback",
"=",
"function",
"(",
"$",
"matches",
")",
"{",
"return",
"self",
"::",
"addCommentReplacement",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"}",
";",
"$",
"text",
"=",
"preg_replace_callback",
"(",
"'/(\\/\\*.*?\\*\\/)/'",
",",
"$",
"replaceCommentCallback",
",",
"$",
"text",
")",
";",
"}",
"return",
"$",
"text",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid type '\"",
".",
"gettype",
"(",
"$",
"text",
")",
".",
"\"' for argument 'text' given.\"",
")",
";",
"}",
"}"
] |
Replaces all CSS strings and comments in the given text.
@param string $text
@return string
|
[
"Replaces",
"all",
"CSS",
"strings",
"and",
"comments",
"in",
"the",
"given",
"text",
"."
] |
train
|
https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Helper/Placeholder.php#L22-L67
|
crossjoin/Css
|
src/Crossjoin/Css/Helper/Placeholder.php
|
Placeholder.replaceStringPlaceholders
|
public static function replaceStringPlaceholders($text, $deletePlaceholders = false)
{
if (is_string($text)) {
// Fast pre-check, to optimize performance
if (strpos($text, "_") !== false) {
$replaceStringPlaceholders = function ($matches) use ($deletePlaceholders) {
$result = "";
if (isset(self::$replacements[$matches[1]])) {
$result = self::$replacements[$matches[1]];
$result = str_replace(
['_STRING_CSSLINEBREAK_', '_STRING_ESCAPEDDOUBLEQUOTE_', '_STRING_ESCAPEDSINGLEQUOTE_'],
["\\\n", '\\"', "\\'"],
$result
);
if ($deletePlaceholders === true) {
unset(self::$replacements[$matches[1]]);
}
}
return $result;
};
$text = preg_replace_callback('/(?:_STRING_([a-f0-9]{32})_)/', $replaceStringPlaceholders, $text);
}
return $text;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($text). "' for argument 'text' given."
);
}
}
|
php
|
public static function replaceStringPlaceholders($text, $deletePlaceholders = false)
{
if (is_string($text)) {
// Fast pre-check, to optimize performance
if (strpos($text, "_") !== false) {
$replaceStringPlaceholders = function ($matches) use ($deletePlaceholders) {
$result = "";
if (isset(self::$replacements[$matches[1]])) {
$result = self::$replacements[$matches[1]];
$result = str_replace(
['_STRING_CSSLINEBREAK_', '_STRING_ESCAPEDDOUBLEQUOTE_', '_STRING_ESCAPEDSINGLEQUOTE_'],
["\\\n", '\\"', "\\'"],
$result
);
if ($deletePlaceholders === true) {
unset(self::$replacements[$matches[1]]);
}
}
return $result;
};
$text = preg_replace_callback('/(?:_STRING_([a-f0-9]{32})_)/', $replaceStringPlaceholders, $text);
}
return $text;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($text). "' for argument 'text' given."
);
}
}
|
[
"public",
"static",
"function",
"replaceStringPlaceholders",
"(",
"$",
"text",
",",
"$",
"deletePlaceholders",
"=",
"false",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"text",
")",
")",
"{",
"// Fast pre-check, to optimize performance",
"if",
"(",
"strpos",
"(",
"$",
"text",
",",
"\"_\"",
")",
"!==",
"false",
")",
"{",
"$",
"replaceStringPlaceholders",
"=",
"function",
"(",
"$",
"matches",
")",
"use",
"(",
"$",
"deletePlaceholders",
")",
"{",
"$",
"result",
"=",
"\"\"",
";",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"replacements",
"[",
"$",
"matches",
"[",
"1",
"]",
"]",
")",
")",
"{",
"$",
"result",
"=",
"self",
"::",
"$",
"replacements",
"[",
"$",
"matches",
"[",
"1",
"]",
"]",
";",
"$",
"result",
"=",
"str_replace",
"(",
"[",
"'_STRING_CSSLINEBREAK_'",
",",
"'_STRING_ESCAPEDDOUBLEQUOTE_'",
",",
"'_STRING_ESCAPEDSINGLEQUOTE_'",
"]",
",",
"[",
"\"\\\\\\n\"",
",",
"'\\\\\"'",
",",
"\"\\\\'\"",
"]",
",",
"$",
"result",
")",
";",
"if",
"(",
"$",
"deletePlaceholders",
"===",
"true",
")",
"{",
"unset",
"(",
"self",
"::",
"$",
"replacements",
"[",
"$",
"matches",
"[",
"1",
"]",
"]",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}",
";",
"$",
"text",
"=",
"preg_replace_callback",
"(",
"'/(?:_STRING_([a-f0-9]{32})_)/'",
",",
"$",
"replaceStringPlaceholders",
",",
"$",
"text",
")",
";",
"}",
"return",
"$",
"text",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid type '\"",
".",
"gettype",
"(",
"$",
"text",
")",
".",
"\"' for argument 'text' given.\"",
")",
";",
"}",
"}"
] |
Replaces the string place holders wih the saved strings in a given text.
@param string $text
@param bool $deletePlaceholders
@return string
|
[
"Replaces",
"the",
"string",
"place",
"holders",
"wih",
"the",
"saved",
"strings",
"in",
"a",
"given",
"text",
"."
] |
train
|
https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Helper/Placeholder.php#L76-L104
|
crossjoin/Css
|
src/Crossjoin/Css/Helper/Placeholder.php
|
Placeholder.removeCommentPlaceholders
|
public static function removeCommentPlaceholders($text, $deletePlaceholders = false)
{
if (is_string($text)) {
// Fast pre-check, to optimize performance
if (strpos($text, "_") !== false) {
$removeStringPlaceholders = function ($matches) use ($deletePlaceholders) {
if ($deletePlaceholders === true) {
if (isset(self::$replacements[$matches[1]])) {
unset(self::$replacements[$matches[1]]);
}
}
return "";
};
$text = preg_replace_callback('/(?:_COMMENT_([a-f0-9]{32})_)/', $removeStringPlaceholders, $text);
}
return $text;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($text). "' for argument 'text' given."
);
}
}
|
php
|
public static function removeCommentPlaceholders($text, $deletePlaceholders = false)
{
if (is_string($text)) {
// Fast pre-check, to optimize performance
if (strpos($text, "_") !== false) {
$removeStringPlaceholders = function ($matches) use ($deletePlaceholders) {
if ($deletePlaceholders === true) {
if (isset(self::$replacements[$matches[1]])) {
unset(self::$replacements[$matches[1]]);
}
}
return "";
};
$text = preg_replace_callback('/(?:_COMMENT_([a-f0-9]{32})_)/', $removeStringPlaceholders, $text);
}
return $text;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($text). "' for argument 'text' given."
);
}
}
|
[
"public",
"static",
"function",
"removeCommentPlaceholders",
"(",
"$",
"text",
",",
"$",
"deletePlaceholders",
"=",
"false",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"text",
")",
")",
"{",
"// Fast pre-check, to optimize performance",
"if",
"(",
"strpos",
"(",
"$",
"text",
",",
"\"_\"",
")",
"!==",
"false",
")",
"{",
"$",
"removeStringPlaceholders",
"=",
"function",
"(",
"$",
"matches",
")",
"use",
"(",
"$",
"deletePlaceholders",
")",
"{",
"if",
"(",
"$",
"deletePlaceholders",
"===",
"true",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"replacements",
"[",
"$",
"matches",
"[",
"1",
"]",
"]",
")",
")",
"{",
"unset",
"(",
"self",
"::",
"$",
"replacements",
"[",
"$",
"matches",
"[",
"1",
"]",
"]",
")",
";",
"}",
"}",
"return",
"\"\"",
";",
"}",
";",
"$",
"text",
"=",
"preg_replace_callback",
"(",
"'/(?:_COMMENT_([a-f0-9]{32})_)/'",
",",
"$",
"removeStringPlaceholders",
",",
"$",
"text",
")",
";",
"}",
"return",
"$",
"text",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid type '\"",
".",
"gettype",
"(",
"$",
"text",
")",
".",
"\"' for argument 'text' given.\"",
")",
";",
"}",
"}"
] |
Removes the comment place holders from a given text.
@param string $text
@param bool $deletePlaceholders
@return string
|
[
"Removes",
"the",
"comment",
"place",
"holders",
"from",
"a",
"given",
"text",
"."
] |
train
|
https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Helper/Placeholder.php#L146-L167
|
crossjoin/Css
|
src/Crossjoin/Css/Helper/Placeholder.php
|
Placeholder.addReplacement
|
protected static function addReplacement($string, $prefix)
{
if (is_string($string)) {
if (is_string($prefix)) {
$hash = md5(self::$counter);
$placeholder = "_" . $prefix . "_" . $hash . "_";
self::$replacements[$hash] = $string;
self::$counter++;
return $placeholder;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($prefix). "' for argument 'prefix' given."
);
}
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($string). "' for argument 'string' given."
);
}
}
|
php
|
protected static function addReplacement($string, $prefix)
{
if (is_string($string)) {
if (is_string($prefix)) {
$hash = md5(self::$counter);
$placeholder = "_" . $prefix . "_" . $hash . "_";
self::$replacements[$hash] = $string;
self::$counter++;
return $placeholder;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($prefix). "' for argument 'prefix' given."
);
}
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($string). "' for argument 'string' given."
);
}
}
|
[
"protected",
"static",
"function",
"addReplacement",
"(",
"$",
"string",
",",
"$",
"prefix",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"string",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"prefix",
")",
")",
"{",
"$",
"hash",
"=",
"md5",
"(",
"self",
"::",
"$",
"counter",
")",
";",
"$",
"placeholder",
"=",
"\"_\"",
".",
"$",
"prefix",
".",
"\"_\"",
".",
"$",
"hash",
".",
"\"_\"",
";",
"self",
"::",
"$",
"replacements",
"[",
"$",
"hash",
"]",
"=",
"$",
"string",
";",
"self",
"::",
"$",
"counter",
"++",
";",
"return",
"$",
"placeholder",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid type '\"",
".",
"gettype",
"(",
"$",
"prefix",
")",
".",
"\"' for argument 'prefix' given.\"",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid type '\"",
".",
"gettype",
"(",
"$",
"string",
")",
".",
"\"' for argument 'string' given.\"",
")",
";",
"}",
"}"
] |
Adds a replacement to the internal list.
@param string $string
@param string $prefix
@return string
|
[
"Adds",
"a",
"replacement",
"to",
"the",
"internal",
"list",
"."
] |
train
|
https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Helper/Placeholder.php#L198-L218
|
axelitus/php-base
|
src/PropertyAccessible.php
|
PropertyAccessible.getRefClass
|
final private function getRefClass()
{
if ($this->refClass === null) {
$this->refClass = new \ReflectionClass($this);
}
return $this->refClass;
}
|
php
|
final private function getRefClass()
{
if ($this->refClass === null) {
$this->refClass = new \ReflectionClass($this);
}
return $this->refClass;
}
|
[
"final",
"private",
"function",
"getRefClass",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"refClass",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"refClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"this",
"->",
"refClass",
";",
"}"
] |
Gets the ReflectionClass object for the current object.
The ReflectionClass object is created only once, then that value is returned for subsequent calls.
@return null|\ReflectionClass The ReflectionClass of the object.
|
[
"Gets",
"the",
"ReflectionClass",
"object",
"for",
"the",
"current",
"object",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/PropertyAccessible.php#L54-L61
|
axelitus/php-base
|
src/PropertyAccessible.php
|
PropertyAccessible.hasProperty
|
final public function hasProperty($property)
{
if (!Str::is($property)
|| !Str::match($property, "/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/")
|| $property == 'this'
) {
throw new \InvalidArgumentException(
"The \$property parameter must be a string and follow the PHP rules of variable naming."
);
}
return property_exists($this, $property);
}
|
php
|
final public function hasProperty($property)
{
if (!Str::is($property)
|| !Str::match($property, "/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/")
|| $property == 'this'
) {
throw new \InvalidArgumentException(
"The \$property parameter must be a string and follow the PHP rules of variable naming."
);
}
return property_exists($this, $property);
}
|
[
"final",
"public",
"function",
"hasProperty",
"(",
"$",
"property",
")",
"{",
"if",
"(",
"!",
"Str",
"::",
"is",
"(",
"$",
"property",
")",
"||",
"!",
"Str",
"::",
"match",
"(",
"$",
"property",
",",
"\"/[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*/\"",
")",
"||",
"$",
"property",
"==",
"'this'",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"The \\$property parameter must be a string and follow the PHP rules of variable naming.\"",
")",
";",
"}",
"return",
"property_exists",
"(",
"$",
"this",
",",
"$",
"property",
")",
";",
"}"
] |
Checks if the object has the given property.
@param string $property The property to check.
@return bool Returns true if the property exists, false otherwise.
@see http://docs.php.net/manual/en/language.variables.basics.php
@throws \InvalidArgumentException
|
[
"Checks",
"if",
"the",
"object",
"has",
"the",
"given",
"property",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/PropertyAccessible.php#L143-L155
|
axelitus/php-base
|
src/PropertyAccessible.php
|
PropertyAccessible.hasMethod
|
final public function hasMethod($method)
{
if (!Str::is($method)
|| !Str::match($method, "/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/")
) {
throw new \InvalidArgumentException(
"The \$method parameter must be a string and follow the PHP rules of method naming."
);
}
return method_exists($this, $method);
}
|
php
|
final public function hasMethod($method)
{
if (!Str::is($method)
|| !Str::match($method, "/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/")
) {
throw new \InvalidArgumentException(
"The \$method parameter must be a string and follow the PHP rules of method naming."
);
}
return method_exists($this, $method);
}
|
[
"final",
"public",
"function",
"hasMethod",
"(",
"$",
"method",
")",
"{",
"if",
"(",
"!",
"Str",
"::",
"is",
"(",
"$",
"method",
")",
"||",
"!",
"Str",
"::",
"match",
"(",
"$",
"method",
",",
"\"/[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*/\"",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"The \\$method parameter must be a string and follow the PHP rules of method naming.\"",
")",
";",
"}",
"return",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
";",
"}"
] |
Checks if the object has the given method.
@param string $method The method to check.
@return bool Returns true if the property exists, false otherwise.
@see http://docs.php.net/manual/en/function.user-defined.php
@throws \InvalidArgumentException
|
[
"Checks",
"if",
"the",
"object",
"has",
"the",
"given",
"method",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/PropertyAccessible.php#L167-L178
|
shakahl/hups-util-filedownloader
|
src/Hups/Util/FileDownloader.php
|
FileDownloader.download
|
public static function download($location, $filename = null, $mime = 'application/octet-stream', $speed = 1024, $disposition = 'attachment')
{
if (connection_status() != 0) return(false);
if(!is_file($location))
{
http_response_code(404);
exit();
}
if (empty($mime))
{
$mime = static::getFileMime($location);
}
set_time_limit(0);
while (ob_get_level() > 0)
{
ob_end_clean();
}
if (!$filename)
{
$filename = pathinfo($location, PATHINFO_BASENAME);
}
$time = date('r', filemtime($location));
$size = filesize($location);
$speed = ($speed === null) ? 1024 : intval($speed) * 1024;
$begin = 0;
$end = $size;
$status = 200;
if(isset($_SERVER['HTTP_RANGE']))
{
if(preg_match('/bytes=\h*(\d+)-(\d*)[\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches))
{
$begin = intval($matches[0]);
if(!empty($matches[1]))
{
$end = intval($matches[1]);
}
$status = 206;
}
}
http_response_code($status);
header('Expires: 0');
header("Content-Type: $mime");
header('Pragma: public');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Accept-Ranges: bytes');
header('Content-Length: '.($end - $begin));
header("Content-Range: bytes $begin-" . ($end - 1) . "/$size");
header("Content-Disposition: " . $disposition . "; filename=$filename");
header("Content-Transfer-Encoding: binary");
header("Last-Modified: $time");
header('Connection: close');
for ($offset = $begin; $offset <= $end; $offset += $speed)
{
if (connection_status() || connection_aborted())
{
exit(1);
}
echo file_get_contents($location, false, null, $offset, $speed);
while (ob_get_level() > 0)
{
ob_end_flush();
}
flush();
//ob_flush();
//ob_implicit_flush();
usleep(intval(floatval($time) * 1000000));
}
return ((connection_status()==0) and !connection_aborted());
}
|
php
|
public static function download($location, $filename = null, $mime = 'application/octet-stream', $speed = 1024, $disposition = 'attachment')
{
if (connection_status() != 0) return(false);
if(!is_file($location))
{
http_response_code(404);
exit();
}
if (empty($mime))
{
$mime = static::getFileMime($location);
}
set_time_limit(0);
while (ob_get_level() > 0)
{
ob_end_clean();
}
if (!$filename)
{
$filename = pathinfo($location, PATHINFO_BASENAME);
}
$time = date('r', filemtime($location));
$size = filesize($location);
$speed = ($speed === null) ? 1024 : intval($speed) * 1024;
$begin = 0;
$end = $size;
$status = 200;
if(isset($_SERVER['HTTP_RANGE']))
{
if(preg_match('/bytes=\h*(\d+)-(\d*)[\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches))
{
$begin = intval($matches[0]);
if(!empty($matches[1]))
{
$end = intval($matches[1]);
}
$status = 206;
}
}
http_response_code($status);
header('Expires: 0');
header("Content-Type: $mime");
header('Pragma: public');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Accept-Ranges: bytes');
header('Content-Length: '.($end - $begin));
header("Content-Range: bytes $begin-" . ($end - 1) . "/$size");
header("Content-Disposition: " . $disposition . "; filename=$filename");
header("Content-Transfer-Encoding: binary");
header("Last-Modified: $time");
header('Connection: close');
for ($offset = $begin; $offset <= $end; $offset += $speed)
{
if (connection_status() || connection_aborted())
{
exit(1);
}
echo file_get_contents($location, false, null, $offset, $speed);
while (ob_get_level() > 0)
{
ob_end_flush();
}
flush();
//ob_flush();
//ob_implicit_flush();
usleep(intval(floatval($time) * 1000000));
}
return ((connection_status()==0) and !connection_aborted());
}
|
[
"public",
"static",
"function",
"download",
"(",
"$",
"location",
",",
"$",
"filename",
"=",
"null",
",",
"$",
"mime",
"=",
"'application/octet-stream'",
",",
"$",
"speed",
"=",
"1024",
",",
"$",
"disposition",
"=",
"'attachment'",
")",
"{",
"if",
"(",
"connection_status",
"(",
")",
"!=",
"0",
")",
"return",
"(",
"false",
")",
";",
"if",
"(",
"!",
"is_file",
"(",
"$",
"location",
")",
")",
"{",
"http_response_code",
"(",
"404",
")",
";",
"exit",
"(",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"mime",
")",
")",
"{",
"$",
"mime",
"=",
"static",
"::",
"getFileMime",
"(",
"$",
"location",
")",
";",
"}",
"set_time_limit",
"(",
"0",
")",
";",
"while",
"(",
"ob_get_level",
"(",
")",
">",
"0",
")",
"{",
"ob_end_clean",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"filename",
")",
"{",
"$",
"filename",
"=",
"pathinfo",
"(",
"$",
"location",
",",
"PATHINFO_BASENAME",
")",
";",
"}",
"$",
"time",
"=",
"date",
"(",
"'r'",
",",
"filemtime",
"(",
"$",
"location",
")",
")",
";",
"$",
"size",
"=",
"filesize",
"(",
"$",
"location",
")",
";",
"$",
"speed",
"=",
"(",
"$",
"speed",
"===",
"null",
")",
"?",
"1024",
":",
"intval",
"(",
"$",
"speed",
")",
"*",
"1024",
";",
"$",
"begin",
"=",
"0",
";",
"$",
"end",
"=",
"$",
"size",
";",
"$",
"status",
"=",
"200",
";",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_RANGE'",
"]",
")",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/bytes=\\h*(\\d+)-(\\d*)[\\D.*]?/i'",
",",
"$",
"_SERVER",
"[",
"'HTTP_RANGE'",
"]",
",",
"$",
"matches",
")",
")",
"{",
"$",
"begin",
"=",
"intval",
"(",
"$",
"matches",
"[",
"0",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
")",
"{",
"$",
"end",
"=",
"intval",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"}",
"$",
"status",
"=",
"206",
";",
"}",
"}",
"http_response_code",
"(",
"$",
"status",
")",
";",
"header",
"(",
"'Expires: 0'",
")",
";",
"header",
"(",
"\"Content-Type: $mime\"",
")",
";",
"header",
"(",
"'Pragma: public'",
")",
";",
"header",
"(",
"'Cache-Control: must-revalidate, post-check=0, pre-check=0'",
")",
";",
"header",
"(",
"'Accept-Ranges: bytes'",
")",
";",
"header",
"(",
"'Content-Length: '",
".",
"(",
"$",
"end",
"-",
"$",
"begin",
")",
")",
";",
"header",
"(",
"\"Content-Range: bytes $begin-\"",
".",
"(",
"$",
"end",
"-",
"1",
")",
".",
"\"/$size\"",
")",
";",
"header",
"(",
"\"Content-Disposition: \"",
".",
"$",
"disposition",
".",
"\"; filename=$filename\"",
")",
";",
"header",
"(",
"\"Content-Transfer-Encoding: binary\"",
")",
";",
"header",
"(",
"\"Last-Modified: $time\"",
")",
";",
"header",
"(",
"'Connection: close'",
")",
";",
"for",
"(",
"$",
"offset",
"=",
"$",
"begin",
";",
"$",
"offset",
"<=",
"$",
"end",
";",
"$",
"offset",
"+=",
"$",
"speed",
")",
"{",
"if",
"(",
"connection_status",
"(",
")",
"||",
"connection_aborted",
"(",
")",
")",
"{",
"exit",
"(",
"1",
")",
";",
"}",
"echo",
"file_get_contents",
"(",
"$",
"location",
",",
"false",
",",
"null",
",",
"$",
"offset",
",",
"$",
"speed",
")",
";",
"while",
"(",
"ob_get_level",
"(",
")",
">",
"0",
")",
"{",
"ob_end_flush",
"(",
")",
";",
"}",
"flush",
"(",
")",
";",
"//ob_flush();",
"//ob_implicit_flush();",
"usleep",
"(",
"intval",
"(",
"floatval",
"(",
"$",
"time",
")",
"*",
"1000000",
")",
")",
";",
"}",
"return",
"(",
"(",
"connection_status",
"(",
")",
"==",
"0",
")",
"and",
"!",
"connection_aborted",
"(",
")",
")",
";",
"}"
] |
Sends the file to the browser for download
@param string $location Path to the file
@param string|null $filename Filename to download as
@param string|null $mime Mime type. Set to null for autodetect.
@param int $speed Download speed
@param string $disposition Content disposition. attachment or inline.
@return bool Return status.
|
[
"Sends",
"the",
"file",
"to",
"the",
"browser",
"for",
"download"
] |
train
|
https://github.com/shakahl/hups-util-filedownloader/blob/e9fa3a02f5ff3e31b4ead8f535362efd27c6cfac/src/Hups/Util/FileDownloader.php#L27-L112
|
shakahl/hups-util-filedownloader
|
src/Hups/Util/FileDownloader.php
|
FileDownloader.getFileMime
|
public static function getFileMime($filename, $default = 'application/octet-stream')
{
if(function_exists('mime_content_type'))
{
return mime_content_type($filename);
}
$mime_types = array(
'txt' => 'text/plain',
'htm' => 'text/html',
'html' => 'text/html',
'php' => 'text/html',
'css' => 'text/css',
'js' => 'application/javascript',
'json' => 'application/json',
'xml' => 'application/xml',
'swf' => 'application/x-shockwave-flash',
'flv' => 'video/x-flv',
// images
'png' => 'image/png',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'gif' => 'image/gif',
'bmp' => 'image/bmp',
'ico' => 'image/vnd.microsoft.icon',
'tiff' => 'image/tiff',
'tif' => 'image/tiff',
'svg' => 'image/svg+xml',
'svgz' => 'image/svg+xml',
// archives
'zip' => 'application/zip',
'rar' => 'application/x-rar-compressed',
'exe' => 'application/x-msdownload',
'msi' => 'application/x-msdownload',
'cab' => 'application/vnd.ms-cab-compressed',
// audio/video
'mp3' => 'audio/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
// adobe
'pdf' => 'application/pdf',
'psd' => 'image/vnd.adobe.photoshop',
'ai' => 'application/postscript',
'eps' => 'application/postscript',
'ps' => 'application/postscript',
// ms office
'doc' => 'application/msword',
'rtf' => 'application/rtf',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',
// open office
'odt' => 'application/vnd.oasis.opendocument.text',
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
);
$ext = substr(strrchr($filename, "."), 1);
if (array_key_exists($ext, $mime_types))
{
return $mime_types[$ext];
}
elseif (function_exists('finfo_open'))
{
$finfo = finfo_open(FILEINFO_MIME);
$mimetype = finfo_file($finfo, $filename);
finfo_close($finfo);
return $mimetype;
}
return $default;
}
|
php
|
public static function getFileMime($filename, $default = 'application/octet-stream')
{
if(function_exists('mime_content_type'))
{
return mime_content_type($filename);
}
$mime_types = array(
'txt' => 'text/plain',
'htm' => 'text/html',
'html' => 'text/html',
'php' => 'text/html',
'css' => 'text/css',
'js' => 'application/javascript',
'json' => 'application/json',
'xml' => 'application/xml',
'swf' => 'application/x-shockwave-flash',
'flv' => 'video/x-flv',
// images
'png' => 'image/png',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'gif' => 'image/gif',
'bmp' => 'image/bmp',
'ico' => 'image/vnd.microsoft.icon',
'tiff' => 'image/tiff',
'tif' => 'image/tiff',
'svg' => 'image/svg+xml',
'svgz' => 'image/svg+xml',
// archives
'zip' => 'application/zip',
'rar' => 'application/x-rar-compressed',
'exe' => 'application/x-msdownload',
'msi' => 'application/x-msdownload',
'cab' => 'application/vnd.ms-cab-compressed',
// audio/video
'mp3' => 'audio/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
// adobe
'pdf' => 'application/pdf',
'psd' => 'image/vnd.adobe.photoshop',
'ai' => 'application/postscript',
'eps' => 'application/postscript',
'ps' => 'application/postscript',
// ms office
'doc' => 'application/msword',
'rtf' => 'application/rtf',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',
// open office
'odt' => 'application/vnd.oasis.opendocument.text',
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
);
$ext = substr(strrchr($filename, "."), 1);
if (array_key_exists($ext, $mime_types))
{
return $mime_types[$ext];
}
elseif (function_exists('finfo_open'))
{
$finfo = finfo_open(FILEINFO_MIME);
$mimetype = finfo_file($finfo, $filename);
finfo_close($finfo);
return $mimetype;
}
return $default;
}
|
[
"public",
"static",
"function",
"getFileMime",
"(",
"$",
"filename",
",",
"$",
"default",
"=",
"'application/octet-stream'",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'mime_content_type'",
")",
")",
"{",
"return",
"mime_content_type",
"(",
"$",
"filename",
")",
";",
"}",
"$",
"mime_types",
"=",
"array",
"(",
"'txt'",
"=>",
"'text/plain'",
",",
"'htm'",
"=>",
"'text/html'",
",",
"'html'",
"=>",
"'text/html'",
",",
"'php'",
"=>",
"'text/html'",
",",
"'css'",
"=>",
"'text/css'",
",",
"'js'",
"=>",
"'application/javascript'",
",",
"'json'",
"=>",
"'application/json'",
",",
"'xml'",
"=>",
"'application/xml'",
",",
"'swf'",
"=>",
"'application/x-shockwave-flash'",
",",
"'flv'",
"=>",
"'video/x-flv'",
",",
"// images",
"'png'",
"=>",
"'image/png'",
",",
"'jpe'",
"=>",
"'image/jpeg'",
",",
"'jpeg'",
"=>",
"'image/jpeg'",
",",
"'jpg'",
"=>",
"'image/jpeg'",
",",
"'gif'",
"=>",
"'image/gif'",
",",
"'bmp'",
"=>",
"'image/bmp'",
",",
"'ico'",
"=>",
"'image/vnd.microsoft.icon'",
",",
"'tiff'",
"=>",
"'image/tiff'",
",",
"'tif'",
"=>",
"'image/tiff'",
",",
"'svg'",
"=>",
"'image/svg+xml'",
",",
"'svgz'",
"=>",
"'image/svg+xml'",
",",
"// archives",
"'zip'",
"=>",
"'application/zip'",
",",
"'rar'",
"=>",
"'application/x-rar-compressed'",
",",
"'exe'",
"=>",
"'application/x-msdownload'",
",",
"'msi'",
"=>",
"'application/x-msdownload'",
",",
"'cab'",
"=>",
"'application/vnd.ms-cab-compressed'",
",",
"// audio/video",
"'mp3'",
"=>",
"'audio/mpeg'",
",",
"'qt'",
"=>",
"'video/quicktime'",
",",
"'mov'",
"=>",
"'video/quicktime'",
",",
"// adobe",
"'pdf'",
"=>",
"'application/pdf'",
",",
"'psd'",
"=>",
"'image/vnd.adobe.photoshop'",
",",
"'ai'",
"=>",
"'application/postscript'",
",",
"'eps'",
"=>",
"'application/postscript'",
",",
"'ps'",
"=>",
"'application/postscript'",
",",
"// ms office",
"'doc'",
"=>",
"'application/msword'",
",",
"'rtf'",
"=>",
"'application/rtf'",
",",
"'xls'",
"=>",
"'application/vnd.ms-excel'",
",",
"'ppt'",
"=>",
"'application/vnd.ms-powerpoint'",
",",
"// open office",
"'odt'",
"=>",
"'application/vnd.oasis.opendocument.text'",
",",
"'ods'",
"=>",
"'application/vnd.oasis.opendocument.spreadsheet'",
",",
")",
";",
"$",
"ext",
"=",
"substr",
"(",
"strrchr",
"(",
"$",
"filename",
",",
"\".\"",
")",
",",
"1",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"ext",
",",
"$",
"mime_types",
")",
")",
"{",
"return",
"$",
"mime_types",
"[",
"$",
"ext",
"]",
";",
"}",
"elseif",
"(",
"function_exists",
"(",
"'finfo_open'",
")",
")",
"{",
"$",
"finfo",
"=",
"finfo_open",
"(",
"FILEINFO_MIME",
")",
";",
"$",
"mimetype",
"=",
"finfo_file",
"(",
"$",
"finfo",
",",
"$",
"filename",
")",
";",
"finfo_close",
"(",
"$",
"finfo",
")",
";",
"return",
"$",
"mimetype",
";",
"}",
"return",
"$",
"default",
";",
"}"
] |
Get file's mime type
@param string $filename
@param string $default Default value
@return string
|
[
"Get",
"file",
"s",
"mime",
"type"
] |
train
|
https://github.com/shakahl/hups-util-filedownloader/blob/e9fa3a02f5ff3e31b4ead8f535362efd27c6cfac/src/Hups/Util/FileDownloader.php#L120-L198
|
slogsdon/staticwp
|
includes/staticwp-view.class.php
|
View.notice
|
public static function notice($slug, $type = null)
{
ob_start();
self::template($slug, 'notice');
$result = null;
if ($type == null) {
$result = ob_get_flush();
} else {
$result = array(
'message' => ob_get_flush(),
'type' => $type,
);
}
return $result;
}
|
php
|
public static function notice($slug, $type = null)
{
ob_start();
self::template($slug, 'notice');
$result = null;
if ($type == null) {
$result = ob_get_flush();
} else {
$result = array(
'message' => ob_get_flush(),
'type' => $type,
);
}
return $result;
}
|
[
"public",
"static",
"function",
"notice",
"(",
"$",
"slug",
",",
"$",
"type",
"=",
"null",
")",
"{",
"ob_start",
"(",
")",
";",
"self",
"::",
"template",
"(",
"$",
"slug",
",",
"'notice'",
")",
";",
"$",
"result",
"=",
"null",
";",
"if",
"(",
"$",
"type",
"==",
"null",
")",
"{",
"$",
"result",
"=",
"ob_get_flush",
"(",
")",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"array",
"(",
"'message'",
"=>",
"ob_get_flush",
"(",
")",
",",
"'type'",
"=>",
"$",
"type",
",",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Loads notice templates.
@since 1.3.0
@param string $slug
@return string|array
|
[
"Loads",
"notice",
"templates",
"."
] |
train
|
https://github.com/slogsdon/staticwp/blob/e96811e57c521b0dc28fc600647b89828cdba8c0/includes/staticwp-view.class.php#L28-L44
|
fuelphp/display
|
src/Parser/Markdown.php
|
Markdown.parse
|
public function parse($file, array $data = [])
{
$contents = $file;
if (file_exists($file))
{
$contents = file_get_contents($file);
}
return $this->markdown->transformMarkdown($contents);
}
|
php
|
public function parse($file, array $data = [])
{
$contents = $file;
if (file_exists($file))
{
$contents = file_get_contents($file);
}
return $this->markdown->transformMarkdown($contents);
}
|
[
"public",
"function",
"parse",
"(",
"$",
"file",
",",
"array",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"contents",
"=",
"$",
"file",
";",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"$",
"contents",
"=",
"file_get_contents",
"(",
"$",
"file",
")",
";",
"}",
"return",
"$",
"this",
"->",
"markdown",
"->",
"transformMarkdown",
"(",
"$",
"contents",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/fuelphp/display/blob/d9a3eddbf80f0fd81beb40d9f4507600ac6611a4/src/Parser/Markdown.php#L59-L69
|
yoanm/php-jsonrpc-http-server-openapi-doc-sdk
|
src/App/Normalizer/Component/TypeDocNormalizer.php
|
TypeDocNormalizer.normalize
|
public function normalize(TypeDoc $doc) : array
{
$siblingsDoc = $paramDocRequired = [];
$siblingsDoc = $this->appendArrayDoc($doc, $siblingsDoc);
list (
$siblingsDoc,
$paramDocRequired
) = $this->appendObjectDoc($doc, $siblingsDoc, $paramDocRequired);
$format = ($doc instanceof StringDoc ? $doc->getFormat() : null);
return $this->appendIfValueNotNull('description', $doc->getDescription())
+ ['type' => $this->schemaTypeNormalizer->normalize($doc)]
+ $this->appendIfValueNotNull('format', $format)
+ ['nullable' => $doc->isNullable()]
+ $paramDocRequired
+ $this->appendIfValueNotNull('default', $doc->getDefault())
+ $this->appendIfValueNotNull('example', $doc->getExample())
+ $this->appendIfValueHaveSiblings('enum', array_values($doc->getAllowedValueList()))
+ $this->getMinMaxDoc($doc)
+ $siblingsDoc
;
}
|
php
|
public function normalize(TypeDoc $doc) : array
{
$siblingsDoc = $paramDocRequired = [];
$siblingsDoc = $this->appendArrayDoc($doc, $siblingsDoc);
list (
$siblingsDoc,
$paramDocRequired
) = $this->appendObjectDoc($doc, $siblingsDoc, $paramDocRequired);
$format = ($doc instanceof StringDoc ? $doc->getFormat() : null);
return $this->appendIfValueNotNull('description', $doc->getDescription())
+ ['type' => $this->schemaTypeNormalizer->normalize($doc)]
+ $this->appendIfValueNotNull('format', $format)
+ ['nullable' => $doc->isNullable()]
+ $paramDocRequired
+ $this->appendIfValueNotNull('default', $doc->getDefault())
+ $this->appendIfValueNotNull('example', $doc->getExample())
+ $this->appendIfValueHaveSiblings('enum', array_values($doc->getAllowedValueList()))
+ $this->getMinMaxDoc($doc)
+ $siblingsDoc
;
}
|
[
"public",
"function",
"normalize",
"(",
"TypeDoc",
"$",
"doc",
")",
":",
"array",
"{",
"$",
"siblingsDoc",
"=",
"$",
"paramDocRequired",
"=",
"[",
"]",
";",
"$",
"siblingsDoc",
"=",
"$",
"this",
"->",
"appendArrayDoc",
"(",
"$",
"doc",
",",
"$",
"siblingsDoc",
")",
";",
"list",
"(",
"$",
"siblingsDoc",
",",
"$",
"paramDocRequired",
")",
"=",
"$",
"this",
"->",
"appendObjectDoc",
"(",
"$",
"doc",
",",
"$",
"siblingsDoc",
",",
"$",
"paramDocRequired",
")",
";",
"$",
"format",
"=",
"(",
"$",
"doc",
"instanceof",
"StringDoc",
"?",
"$",
"doc",
"->",
"getFormat",
"(",
")",
":",
"null",
")",
";",
"return",
"$",
"this",
"->",
"appendIfValueNotNull",
"(",
"'description'",
",",
"$",
"doc",
"->",
"getDescription",
"(",
")",
")",
"+",
"[",
"'type'",
"=>",
"$",
"this",
"->",
"schemaTypeNormalizer",
"->",
"normalize",
"(",
"$",
"doc",
")",
"]",
"+",
"$",
"this",
"->",
"appendIfValueNotNull",
"(",
"'format'",
",",
"$",
"format",
")",
"+",
"[",
"'nullable'",
"=>",
"$",
"doc",
"->",
"isNullable",
"(",
")",
"]",
"+",
"$",
"paramDocRequired",
"+",
"$",
"this",
"->",
"appendIfValueNotNull",
"(",
"'default'",
",",
"$",
"doc",
"->",
"getDefault",
"(",
")",
")",
"+",
"$",
"this",
"->",
"appendIfValueNotNull",
"(",
"'example'",
",",
"$",
"doc",
"->",
"getExample",
"(",
")",
")",
"+",
"$",
"this",
"->",
"appendIfValueHaveSiblings",
"(",
"'enum'",
",",
"array_values",
"(",
"$",
"doc",
"->",
"getAllowedValueList",
"(",
")",
")",
")",
"+",
"$",
"this",
"->",
"getMinMaxDoc",
"(",
"$",
"doc",
")",
"+",
"$",
"siblingsDoc",
";",
"}"
] |
@param TypeDoc $doc
@return array|mixed
@throws \ReflectionException
|
[
"@param",
"TypeDoc",
"$doc"
] |
train
|
https://github.com/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/blob/52d6bb5d0671e0363bbf482c3c75fef97d7d1d5e/src/App/Normalizer/Component/TypeDocNormalizer.php#L37-L60
|
yoanm/php-jsonrpc-http-server-openapi-doc-sdk
|
src/App/Normalizer/Component/TypeDocNormalizer.php
|
TypeDocNormalizer.getMinMaxDoc
|
protected function getMinMaxDoc(TypeDoc $doc) : array
{
$paramDocMinMax = [];
if ($doc instanceof StringDoc) {
$paramDocMinMax = $this->appendIfValueNotNull('minLength', $doc->getMinLength(), $paramDocMinMax);
$paramDocMinMax = $this->appendIfValueNotNull('maxLength', $doc->getMaxLength(), $paramDocMinMax);
} elseif ($doc instanceof NumberDoc) {
$paramDocMinMax = $this->appendNumberMinMax($doc, $paramDocMinMax);
} elseif ($doc instanceof CollectionDoc) {
if ($doc instanceof ObjectDoc) {
$paramDocMinMax = $this->appendIfValueNotNull('minProperties', $doc->getMinItem(), $paramDocMinMax);
$paramDocMinMax = $this->appendIfValueNotNull('maxProperties', $doc->getMaxItem(), $paramDocMinMax);
} else {
$paramDocMinMax = $this->appendIfValueNotNull('minItems', $doc->getMinItem(), $paramDocMinMax);
$paramDocMinMax = $this->appendIfValueNotNull('maxItems', $doc->getMaxItem(), $paramDocMinMax);
}
}
return $paramDocMinMax;
}
|
php
|
protected function getMinMaxDoc(TypeDoc $doc) : array
{
$paramDocMinMax = [];
if ($doc instanceof StringDoc) {
$paramDocMinMax = $this->appendIfValueNotNull('minLength', $doc->getMinLength(), $paramDocMinMax);
$paramDocMinMax = $this->appendIfValueNotNull('maxLength', $doc->getMaxLength(), $paramDocMinMax);
} elseif ($doc instanceof NumberDoc) {
$paramDocMinMax = $this->appendNumberMinMax($doc, $paramDocMinMax);
} elseif ($doc instanceof CollectionDoc) {
if ($doc instanceof ObjectDoc) {
$paramDocMinMax = $this->appendIfValueNotNull('minProperties', $doc->getMinItem(), $paramDocMinMax);
$paramDocMinMax = $this->appendIfValueNotNull('maxProperties', $doc->getMaxItem(), $paramDocMinMax);
} else {
$paramDocMinMax = $this->appendIfValueNotNull('minItems', $doc->getMinItem(), $paramDocMinMax);
$paramDocMinMax = $this->appendIfValueNotNull('maxItems', $doc->getMaxItem(), $paramDocMinMax);
}
}
return $paramDocMinMax;
}
|
[
"protected",
"function",
"getMinMaxDoc",
"(",
"TypeDoc",
"$",
"doc",
")",
":",
"array",
"{",
"$",
"paramDocMinMax",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"doc",
"instanceof",
"StringDoc",
")",
"{",
"$",
"paramDocMinMax",
"=",
"$",
"this",
"->",
"appendIfValueNotNull",
"(",
"'minLength'",
",",
"$",
"doc",
"->",
"getMinLength",
"(",
")",
",",
"$",
"paramDocMinMax",
")",
";",
"$",
"paramDocMinMax",
"=",
"$",
"this",
"->",
"appendIfValueNotNull",
"(",
"'maxLength'",
",",
"$",
"doc",
"->",
"getMaxLength",
"(",
")",
",",
"$",
"paramDocMinMax",
")",
";",
"}",
"elseif",
"(",
"$",
"doc",
"instanceof",
"NumberDoc",
")",
"{",
"$",
"paramDocMinMax",
"=",
"$",
"this",
"->",
"appendNumberMinMax",
"(",
"$",
"doc",
",",
"$",
"paramDocMinMax",
")",
";",
"}",
"elseif",
"(",
"$",
"doc",
"instanceof",
"CollectionDoc",
")",
"{",
"if",
"(",
"$",
"doc",
"instanceof",
"ObjectDoc",
")",
"{",
"$",
"paramDocMinMax",
"=",
"$",
"this",
"->",
"appendIfValueNotNull",
"(",
"'minProperties'",
",",
"$",
"doc",
"->",
"getMinItem",
"(",
")",
",",
"$",
"paramDocMinMax",
")",
";",
"$",
"paramDocMinMax",
"=",
"$",
"this",
"->",
"appendIfValueNotNull",
"(",
"'maxProperties'",
",",
"$",
"doc",
"->",
"getMaxItem",
"(",
")",
",",
"$",
"paramDocMinMax",
")",
";",
"}",
"else",
"{",
"$",
"paramDocMinMax",
"=",
"$",
"this",
"->",
"appendIfValueNotNull",
"(",
"'minItems'",
",",
"$",
"doc",
"->",
"getMinItem",
"(",
")",
",",
"$",
"paramDocMinMax",
")",
";",
"$",
"paramDocMinMax",
"=",
"$",
"this",
"->",
"appendIfValueNotNull",
"(",
"'maxItems'",
",",
"$",
"doc",
"->",
"getMaxItem",
"(",
")",
",",
"$",
"paramDocMinMax",
")",
";",
"}",
"}",
"return",
"$",
"paramDocMinMax",
";",
"}"
] |
@param TypeDoc $doc
@return array
|
[
"@param",
"TypeDoc",
"$doc"
] |
train
|
https://github.com/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/blob/52d6bb5d0671e0363bbf482c3c75fef97d7d1d5e/src/App/Normalizer/Component/TypeDocNormalizer.php#L67-L86
|
yoanm/php-jsonrpc-http-server-openapi-doc-sdk
|
src/App/Normalizer/Component/TypeDocNormalizer.php
|
TypeDocNormalizer.appendArrayDoc
|
protected function appendArrayDoc(TypeDoc $doc, array $siblingsDoc) : array
{
// CollectionDoc should be managed as ArrayDoc
if (!$doc instanceof ArrayDoc && get_class($doc) !== CollectionDoc::class) {
return $siblingsDoc;
}
/** @var $doc ArrayDoc|CollectionDoc */
// add mandatory "items" field
if ($doc instanceof ArrayDoc && null !== $doc->getItemValidation()) {
$siblingsDoc['items'] = $this->normalize($doc->getItemValidation());
} else {
$siblingsDoc['items']['type'] = $this->guessItemsType($doc->getSiblingList());
}
return $siblingsDoc;
}
|
php
|
protected function appendArrayDoc(TypeDoc $doc, array $siblingsDoc) : array
{
// CollectionDoc should be managed as ArrayDoc
if (!$doc instanceof ArrayDoc && get_class($doc) !== CollectionDoc::class) {
return $siblingsDoc;
}
/** @var $doc ArrayDoc|CollectionDoc */
// add mandatory "items" field
if ($doc instanceof ArrayDoc && null !== $doc->getItemValidation()) {
$siblingsDoc['items'] = $this->normalize($doc->getItemValidation());
} else {
$siblingsDoc['items']['type'] = $this->guessItemsType($doc->getSiblingList());
}
return $siblingsDoc;
}
|
[
"protected",
"function",
"appendArrayDoc",
"(",
"TypeDoc",
"$",
"doc",
",",
"array",
"$",
"siblingsDoc",
")",
":",
"array",
"{",
"// CollectionDoc should be managed as ArrayDoc",
"if",
"(",
"!",
"$",
"doc",
"instanceof",
"ArrayDoc",
"&&",
"get_class",
"(",
"$",
"doc",
")",
"!==",
"CollectionDoc",
"::",
"class",
")",
"{",
"return",
"$",
"siblingsDoc",
";",
"}",
"/** @var $doc ArrayDoc|CollectionDoc */",
"// add mandatory \"items\" field",
"if",
"(",
"$",
"doc",
"instanceof",
"ArrayDoc",
"&&",
"null",
"!==",
"$",
"doc",
"->",
"getItemValidation",
"(",
")",
")",
"{",
"$",
"siblingsDoc",
"[",
"'items'",
"]",
"=",
"$",
"this",
"->",
"normalize",
"(",
"$",
"doc",
"->",
"getItemValidation",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"siblingsDoc",
"[",
"'items'",
"]",
"[",
"'type'",
"]",
"=",
"$",
"this",
"->",
"guessItemsType",
"(",
"$",
"doc",
"->",
"getSiblingList",
"(",
")",
")",
";",
"}",
"return",
"$",
"siblingsDoc",
";",
"}"
] |
@param TypeDoc $doc
@param array $siblingsDoc
@return array
@throws \ReflectionException
|
[
"@param",
"TypeDoc",
"$doc",
"@param",
"array",
"$siblingsDoc"
] |
train
|
https://github.com/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/blob/52d6bb5d0671e0363bbf482c3c75fef97d7d1d5e/src/App/Normalizer/Component/TypeDocNormalizer.php#L96-L111
|
yoanm/php-jsonrpc-http-server-openapi-doc-sdk
|
src/App/Normalizer/Component/TypeDocNormalizer.php
|
TypeDocNormalizer.appendObjectDoc
|
protected function appendObjectDoc(TypeDoc $doc, array $siblingsDoc, array $paramDocRequired) : array
{
if (!$doc instanceof ObjectDoc) {
return [$siblingsDoc, $paramDocRequired];
}
if (true === $doc->isAllowExtraSibling()) {
$siblingsDoc['additionalProperties']['description'] = "Extra property";
}
$self = $this;
$siblingDocList = array_reduce(
$doc->getSiblingList(),
function (array $carry, TypeDoc $sibling) use ($self) {
$carry[$sibling->getName()] = $self->normalize($sibling);
return $carry;
},
[]
);
$requiredSiblings = array_keys(// Keeps only keys
array_filter(// Remove not required
array_reduce(// Convert to $carray[PROPERTY_NAME] = IS_REQUIRED
$doc->getSiblingList(),
function (array $carry, TypeDoc $sibling) {
$carry[$sibling->getName()] = $sibling->isRequired();
return $carry;
},
[]
)
)
);
$siblingsDoc = $this->appendIfValueHaveSiblings('properties', $siblingDocList, $siblingsDoc);
$paramDocRequired = $this->appendIfValueHaveSiblings('required', $requiredSiblings, $paramDocRequired);
return [$siblingsDoc, $paramDocRequired];
}
|
php
|
protected function appendObjectDoc(TypeDoc $doc, array $siblingsDoc, array $paramDocRequired) : array
{
if (!$doc instanceof ObjectDoc) {
return [$siblingsDoc, $paramDocRequired];
}
if (true === $doc->isAllowExtraSibling()) {
$siblingsDoc['additionalProperties']['description'] = "Extra property";
}
$self = $this;
$siblingDocList = array_reduce(
$doc->getSiblingList(),
function (array $carry, TypeDoc $sibling) use ($self) {
$carry[$sibling->getName()] = $self->normalize($sibling);
return $carry;
},
[]
);
$requiredSiblings = array_keys(// Keeps only keys
array_filter(// Remove not required
array_reduce(// Convert to $carray[PROPERTY_NAME] = IS_REQUIRED
$doc->getSiblingList(),
function (array $carry, TypeDoc $sibling) {
$carry[$sibling->getName()] = $sibling->isRequired();
return $carry;
},
[]
)
)
);
$siblingsDoc = $this->appendIfValueHaveSiblings('properties', $siblingDocList, $siblingsDoc);
$paramDocRequired = $this->appendIfValueHaveSiblings('required', $requiredSiblings, $paramDocRequired);
return [$siblingsDoc, $paramDocRequired];
}
|
[
"protected",
"function",
"appendObjectDoc",
"(",
"TypeDoc",
"$",
"doc",
",",
"array",
"$",
"siblingsDoc",
",",
"array",
"$",
"paramDocRequired",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"doc",
"instanceof",
"ObjectDoc",
")",
"{",
"return",
"[",
"$",
"siblingsDoc",
",",
"$",
"paramDocRequired",
"]",
";",
"}",
"if",
"(",
"true",
"===",
"$",
"doc",
"->",
"isAllowExtraSibling",
"(",
")",
")",
"{",
"$",
"siblingsDoc",
"[",
"'additionalProperties'",
"]",
"[",
"'description'",
"]",
"=",
"\"Extra property\"",
";",
"}",
"$",
"self",
"=",
"$",
"this",
";",
"$",
"siblingDocList",
"=",
"array_reduce",
"(",
"$",
"doc",
"->",
"getSiblingList",
"(",
")",
",",
"function",
"(",
"array",
"$",
"carry",
",",
"TypeDoc",
"$",
"sibling",
")",
"use",
"(",
"$",
"self",
")",
"{",
"$",
"carry",
"[",
"$",
"sibling",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"self",
"->",
"normalize",
"(",
"$",
"sibling",
")",
";",
"return",
"$",
"carry",
";",
"}",
",",
"[",
"]",
")",
";",
"$",
"requiredSiblings",
"=",
"array_keys",
"(",
"// Keeps only keys",
"array_filter",
"(",
"// Remove not required",
"array_reduce",
"(",
"// Convert to $carray[PROPERTY_NAME] = IS_REQUIRED",
"$",
"doc",
"->",
"getSiblingList",
"(",
")",
",",
"function",
"(",
"array",
"$",
"carry",
",",
"TypeDoc",
"$",
"sibling",
")",
"{",
"$",
"carry",
"[",
"$",
"sibling",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"sibling",
"->",
"isRequired",
"(",
")",
";",
"return",
"$",
"carry",
";",
"}",
",",
"[",
"]",
")",
")",
")",
";",
"$",
"siblingsDoc",
"=",
"$",
"this",
"->",
"appendIfValueHaveSiblings",
"(",
"'properties'",
",",
"$",
"siblingDocList",
",",
"$",
"siblingsDoc",
")",
";",
"$",
"paramDocRequired",
"=",
"$",
"this",
"->",
"appendIfValueHaveSiblings",
"(",
"'required'",
",",
"$",
"requiredSiblings",
",",
"$",
"paramDocRequired",
")",
";",
"return",
"[",
"$",
"siblingsDoc",
",",
"$",
"paramDocRequired",
"]",
";",
"}"
] |
@param TypeDoc $doc
@param array $siblingsDoc
@param array $paramDocRequired
@return array
|
[
"@param",
"TypeDoc",
"$doc",
"@param",
"array",
"$siblingsDoc",
"@param",
"array",
"$paramDocRequired"
] |
train
|
https://github.com/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/blob/52d6bb5d0671e0363bbf482c3c75fef97d7d1d5e/src/App/Normalizer/Component/TypeDocNormalizer.php#L120-L158
|
yoanm/php-jsonrpc-http-server-openapi-doc-sdk
|
src/App/Normalizer/Component/TypeDocNormalizer.php
|
TypeDocNormalizer.guessItemsType
|
protected function guessItemsType(array $siblingList) : string
{
$self = $this;
$uniqueTypeList = array_unique(
array_map(
function (TypeDoc $sibling) use ($self) {
return $self->schemaTypeNormalizer->normalize($sibling);
},
$siblingList
)
);
if (count($uniqueTypeList) !== 1) {
// default string if sub item type not guessable
return 'string';
}
return array_shift($uniqueTypeList);
}
|
php
|
protected function guessItemsType(array $siblingList) : string
{
$self = $this;
$uniqueTypeList = array_unique(
array_map(
function (TypeDoc $sibling) use ($self) {
return $self->schemaTypeNormalizer->normalize($sibling);
},
$siblingList
)
);
if (count($uniqueTypeList) !== 1) {
// default string if sub item type not guessable
return 'string';
}
return array_shift($uniqueTypeList);
}
|
[
"protected",
"function",
"guessItemsType",
"(",
"array",
"$",
"siblingList",
")",
":",
"string",
"{",
"$",
"self",
"=",
"$",
"this",
";",
"$",
"uniqueTypeList",
"=",
"array_unique",
"(",
"array_map",
"(",
"function",
"(",
"TypeDoc",
"$",
"sibling",
")",
"use",
"(",
"$",
"self",
")",
"{",
"return",
"$",
"self",
"->",
"schemaTypeNormalizer",
"->",
"normalize",
"(",
"$",
"sibling",
")",
";",
"}",
",",
"$",
"siblingList",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"uniqueTypeList",
")",
"!==",
"1",
")",
"{",
"// default string if sub item type not guessable",
"return",
"'string'",
";",
"}",
"return",
"array_shift",
"(",
"$",
"uniqueTypeList",
")",
";",
"}"
] |
@param TypeDoc[] $siblingList
@return string
|
[
"@param",
"TypeDoc",
"[]",
"$siblingList"
] |
train
|
https://github.com/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/blob/52d6bb5d0671e0363bbf482c3c75fef97d7d1d5e/src/App/Normalizer/Component/TypeDocNormalizer.php#L165-L183
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.