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
|
---|---|---|---|---|---|---|---|---|---|---|
harp-orm/query
|
src/Arr.php
|
Arr.flatten
|
public static function flatten(array $array)
{
$result = array();
array_walk_recursive($array, function ($value, $key) use (& $result) {
if (is_numeric($key) or is_object($value)) {
$result[] = $value;
} else {
$result[$key] = $value;
}
});
return $result;
}
|
php
|
public static function flatten(array $array)
{
$result = array();
array_walk_recursive($array, function ($value, $key) use (& $result) {
if (is_numeric($key) or is_object($value)) {
$result[] = $value;
} else {
$result[$key] = $value;
}
});
return $result;
}
|
[
"public",
"static",
"function",
"flatten",
"(",
"array",
"$",
"array",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"array_walk_recursive",
"(",
"$",
"array",
",",
"function",
"(",
"$",
"value",
",",
"$",
"key",
")",
"use",
"(",
"&",
"$",
"result",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"key",
")",
"or",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Flatten an array
@param array $array
@return array
|
[
"Flatten",
"an",
"array"
] |
train
|
https://github.com/harp-orm/query/blob/98ce2468a0a31fe15ed3692bad32547bf6dbe41a/src/Arr.php#L40-L53
|
harp-orm/query
|
src/Arr.php
|
Arr.flipNested
|
public static function flipNested(array $arr)
{
$result = array();
foreach ($arr as $key => $values) {
foreach ($values as $innerKey => $value) {
$result[$innerKey][$key] = $value;
}
}
return $result;
}
|
php
|
public static function flipNested(array $arr)
{
$result = array();
foreach ($arr as $key => $values) {
foreach ($values as $innerKey => $value) {
$result[$innerKey][$key] = $value;
}
}
return $result;
}
|
[
"public",
"static",
"function",
"flipNested",
"(",
"array",
"$",
"arr",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"arr",
"as",
"$",
"key",
"=>",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"innerKey",
"=>",
"$",
"value",
")",
"{",
"$",
"result",
"[",
"$",
"innerKey",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
Transpose 2 dimensional array:
array ( | | array (
1 => array( | | 'name' => array(
'name' => 'val1', | | 1 => 'val1',
'email' => 'val2', | | 2 => 'val3',
), | to | ),
2 => array( | | 'email' => array(
'name' => 'val3', | | 1 => 'val2',
'email' => 'val4', | | 2 => 'val4',
), | | )
) | | )
|
[
"Transpose",
"2",
"dimensional",
"array",
":"
] |
train
|
https://github.com/harp-orm/query/blob/98ce2468a0a31fe15ed3692bad32547bf6dbe41a/src/Arr.php#L81-L92
|
hamjoint/mustard-auctions
|
src/database/migrations/2015_09_01_300000_mustard_auctions_tables.php
|
MustardAuctionsTables.up
|
public function up()
{
Schema::create('bids', function (Blueprint $table) {
$table->integer('bid_id', true)->unsigned();
$table->integer('item_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->decimal('amount', 8, 2)->unsigned();
$table->integer('placed')->unsigned();
$table->foreign('item_id')->references('item_id')->on('items');
$table->foreign('user_id')->references('user_id')->on('users');
$table->unique(['item_id', 'user_id', 'amount']);
});
Schema::create('bid_increments', function (Blueprint $table) {
$table->mediumInteger('bid_increment_id', true)->unsigned();
$table->decimal('minimum', 8, 2)->unsigned();
$table->decimal('increment', 8, 2)->unsigned();
});
$increments = [
0 => 0.01,
1 => 0.1,
10 => 1,
50 => 5,
100 => 10,
500 => 50,
1000 => 100,
];
foreach ($increments as $minimum => $increment) {
$bid_increment = new BidIncrement();
$bid_increment->minimum = $minimum;
$bid_increment->increment = $increment;
$bid_increment->save();
}
}
|
php
|
public function up()
{
Schema::create('bids', function (Blueprint $table) {
$table->integer('bid_id', true)->unsigned();
$table->integer('item_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->decimal('amount', 8, 2)->unsigned();
$table->integer('placed')->unsigned();
$table->foreign('item_id')->references('item_id')->on('items');
$table->foreign('user_id')->references('user_id')->on('users');
$table->unique(['item_id', 'user_id', 'amount']);
});
Schema::create('bid_increments', function (Blueprint $table) {
$table->mediumInteger('bid_increment_id', true)->unsigned();
$table->decimal('minimum', 8, 2)->unsigned();
$table->decimal('increment', 8, 2)->unsigned();
});
$increments = [
0 => 0.01,
1 => 0.1,
10 => 1,
50 => 5,
100 => 10,
500 => 50,
1000 => 100,
];
foreach ($increments as $minimum => $increment) {
$bid_increment = new BidIncrement();
$bid_increment->minimum = $minimum;
$bid_increment->increment = $increment;
$bid_increment->save();
}
}
|
[
"public",
"function",
"up",
"(",
")",
"{",
"Schema",
"::",
"create",
"(",
"'bids'",
",",
"function",
"(",
"Blueprint",
"$",
"table",
")",
"{",
"$",
"table",
"->",
"integer",
"(",
"'bid_id'",
",",
"true",
")",
"->",
"unsigned",
"(",
")",
";",
"$",
"table",
"->",
"integer",
"(",
"'item_id'",
")",
"->",
"unsigned",
"(",
")",
";",
"$",
"table",
"->",
"integer",
"(",
"'user_id'",
")",
"->",
"unsigned",
"(",
")",
";",
"$",
"table",
"->",
"decimal",
"(",
"'amount'",
",",
"8",
",",
"2",
")",
"->",
"unsigned",
"(",
")",
";",
"$",
"table",
"->",
"integer",
"(",
"'placed'",
")",
"->",
"unsigned",
"(",
")",
";",
"$",
"table",
"->",
"foreign",
"(",
"'item_id'",
")",
"->",
"references",
"(",
"'item_id'",
")",
"->",
"on",
"(",
"'items'",
")",
";",
"$",
"table",
"->",
"foreign",
"(",
"'user_id'",
")",
"->",
"references",
"(",
"'user_id'",
")",
"->",
"on",
"(",
"'users'",
")",
";",
"$",
"table",
"->",
"unique",
"(",
"[",
"'item_id'",
",",
"'user_id'",
",",
"'amount'",
"]",
")",
";",
"}",
")",
";",
"Schema",
"::",
"create",
"(",
"'bid_increments'",
",",
"function",
"(",
"Blueprint",
"$",
"table",
")",
"{",
"$",
"table",
"->",
"mediumInteger",
"(",
"'bid_increment_id'",
",",
"true",
")",
"->",
"unsigned",
"(",
")",
";",
"$",
"table",
"->",
"decimal",
"(",
"'minimum'",
",",
"8",
",",
"2",
")",
"->",
"unsigned",
"(",
")",
";",
"$",
"table",
"->",
"decimal",
"(",
"'increment'",
",",
"8",
",",
"2",
")",
"->",
"unsigned",
"(",
")",
";",
"}",
")",
";",
"$",
"increments",
"=",
"[",
"0",
"=>",
"0.01",
",",
"1",
"=>",
"0.1",
",",
"10",
"=>",
"1",
",",
"50",
"=>",
"5",
",",
"100",
"=>",
"10",
",",
"500",
"=>",
"50",
",",
"1000",
"=>",
"100",
",",
"]",
";",
"foreach",
"(",
"$",
"increments",
"as",
"$",
"minimum",
"=>",
"$",
"increment",
")",
"{",
"$",
"bid_increment",
"=",
"new",
"BidIncrement",
"(",
")",
";",
"$",
"bid_increment",
"->",
"minimum",
"=",
"$",
"minimum",
";",
"$",
"bid_increment",
"->",
"increment",
"=",
"$",
"increment",
";",
"$",
"bid_increment",
"->",
"save",
"(",
")",
";",
"}",
"}"
] |
Run the migrations.
@return void
|
[
"Run",
"the",
"migrations",
"."
] |
train
|
https://github.com/hamjoint/mustard-auctions/blob/66c8723d8681466e280263ad100f3fdc5895480d/src/database/migrations/2015_09_01_300000_mustard_auctions_tables.php#L33-L71
|
datasift/datasift-php
|
lib/DataSift/StreamConsumer.php
|
DataSift_StreamConsumer.factory
|
public static function factory($user, $type, $definition, $eventHandler)
{
$classname = 'DataSift_StreamConsumer_' . $type;
if (! class_exists($classname)) {
throw new DataSift_Exception_InvalidData('Consumer type "' . $type . '" is unknown');
}
return new $classname($user, $definition, $eventHandler);
}
|
php
|
public static function factory($user, $type, $definition, $eventHandler)
{
$classname = 'DataSift_StreamConsumer_' . $type;
if (! class_exists($classname)) {
throw new DataSift_Exception_InvalidData('Consumer type "' . $type . '" is unknown');
}
return new $classname($user, $definition, $eventHandler);
}
|
[
"public",
"static",
"function",
"factory",
"(",
"$",
"user",
",",
"$",
"type",
",",
"$",
"definition",
",",
"$",
"eventHandler",
")",
"{",
"$",
"classname",
"=",
"'DataSift_StreamConsumer_'",
".",
"$",
"type",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"classname",
")",
")",
"{",
"throw",
"new",
"DataSift_Exception_InvalidData",
"(",
"'Consumer type \"'",
".",
"$",
"type",
".",
"'\" is unknown'",
")",
";",
"}",
"return",
"new",
"$",
"classname",
"(",
"$",
"user",
",",
"$",
"definition",
",",
"$",
"eventHandler",
")",
";",
"}"
] |
Factory function. Creates a StreamConsumer-derived object for the given
type.
@param string $user Use DataSift_User object.
@param string $type Use the TYPE_ constants
@param mixed $definition CSDL string or a Definition object.
@param string $eventHandler The object that will receive events.
@return DataSift_StreamConsumer The consumer object
@throws DataSift_Exception_InvalidData
|
[
"Factory",
"function",
".",
"Creates",
"a",
"StreamConsumer",
"-",
"derived",
"object",
"for",
"the",
"given",
"type",
"."
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/StreamConsumer.php#L82-L90
|
datasift/datasift-php
|
lib/DataSift/StreamConsumer.php
|
DataSift_StreamConsumer.onData
|
protected function onData($json)
{
// Decode the JSON
$interaction = json_decode(trim($json), true);
// If the interaction is valid, pass it to the event handler
if ($interaction) {
if (isset($interaction['status'])) {
switch ($interaction['status']) {
case 'error':
case 'failure':
$this->onError($interaction['message']);
// Stop the consumer when an error is received
$this->stop();
break;
case 'warning':
$this->onWarning($interaction['message']);
break;
default:
$type = $interaction['status'];
unset($interaction['status']);
$this->onStatus($type, $interaction);
break;
}
} else {
// Extract the hash and the data if present
$hash = false;
if (isset($interaction['hash'])) {
$hash = $interaction['hash'];
$interaction = $interaction['data'];
}
// Ignore ticks and handle delete requests
if (! empty($interaction['deleted'])) {
$this->onDeleted($interaction, $hash);
} elseif (! empty($interaction['interaction'])) {
$this->onInteraction($interaction, $hash);
}
}
}
}
|
php
|
protected function onData($json)
{
// Decode the JSON
$interaction = json_decode(trim($json), true);
// If the interaction is valid, pass it to the event handler
if ($interaction) {
if (isset($interaction['status'])) {
switch ($interaction['status']) {
case 'error':
case 'failure':
$this->onError($interaction['message']);
// Stop the consumer when an error is received
$this->stop();
break;
case 'warning':
$this->onWarning($interaction['message']);
break;
default:
$type = $interaction['status'];
unset($interaction['status']);
$this->onStatus($type, $interaction);
break;
}
} else {
// Extract the hash and the data if present
$hash = false;
if (isset($interaction['hash'])) {
$hash = $interaction['hash'];
$interaction = $interaction['data'];
}
// Ignore ticks and handle delete requests
if (! empty($interaction['deleted'])) {
$this->onDeleted($interaction, $hash);
} elseif (! empty($interaction['interaction'])) {
$this->onInteraction($interaction, $hash);
}
}
}
}
|
[
"protected",
"function",
"onData",
"(",
"$",
"json",
")",
"{",
"// Decode the JSON",
"$",
"interaction",
"=",
"json_decode",
"(",
"trim",
"(",
"$",
"json",
")",
",",
"true",
")",
";",
"// If the interaction is valid, pass it to the event handler",
"if",
"(",
"$",
"interaction",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"interaction",
"[",
"'status'",
"]",
")",
")",
"{",
"switch",
"(",
"$",
"interaction",
"[",
"'status'",
"]",
")",
"{",
"case",
"'error'",
":",
"case",
"'failure'",
":",
"$",
"this",
"->",
"onError",
"(",
"$",
"interaction",
"[",
"'message'",
"]",
")",
";",
"// Stop the consumer when an error is received",
"$",
"this",
"->",
"stop",
"(",
")",
";",
"break",
";",
"case",
"'warning'",
":",
"$",
"this",
"->",
"onWarning",
"(",
"$",
"interaction",
"[",
"'message'",
"]",
")",
";",
"break",
";",
"default",
":",
"$",
"type",
"=",
"$",
"interaction",
"[",
"'status'",
"]",
";",
"unset",
"(",
"$",
"interaction",
"[",
"'status'",
"]",
")",
";",
"$",
"this",
"->",
"onStatus",
"(",
"$",
"type",
",",
"$",
"interaction",
")",
";",
"break",
";",
"}",
"}",
"else",
"{",
"// Extract the hash and the data if present",
"$",
"hash",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"interaction",
"[",
"'hash'",
"]",
")",
")",
"{",
"$",
"hash",
"=",
"$",
"interaction",
"[",
"'hash'",
"]",
";",
"$",
"interaction",
"=",
"$",
"interaction",
"[",
"'data'",
"]",
";",
"}",
"// Ignore ticks and handle delete requests",
"if",
"(",
"!",
"empty",
"(",
"$",
"interaction",
"[",
"'deleted'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"onDeleted",
"(",
"$",
"interaction",
",",
"$",
"hash",
")",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"interaction",
"[",
"'interaction'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"onInteraction",
"(",
"$",
"interaction",
",",
"$",
"hash",
")",
";",
"}",
"}",
"}",
"}"
] |
This is called when a complete JSON item is received.
@param $json The JSON data.
@return void
|
[
"This",
"is",
"called",
"when",
"a",
"complete",
"JSON",
"item",
"is",
"received",
"."
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/StreamConsumer.php#L159-L198
|
datasift/datasift-php
|
lib/DataSift/StreamConsumer.php
|
DataSift_StreamConsumer.onInteraction
|
protected function onInteraction($interaction, $hash = false)
{
$this->_eventHandler->onInteraction($this, $interaction, $hash);
}
|
php
|
protected function onInteraction($interaction, $hash = false)
{
$this->_eventHandler->onInteraction($this, $interaction, $hash);
}
|
[
"protected",
"function",
"onInteraction",
"(",
"$",
"interaction",
",",
"$",
"hash",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"_eventHandler",
"->",
"onInteraction",
"(",
"$",
"this",
",",
"$",
"interaction",
",",
"$",
"hash",
")",
";",
"}"
] |
This is called for each interaction received from the stream and must
be implemented in extending classes.
@param array $interaction The interaction data structure
@param bool $hash
@return void
|
[
"This",
"is",
"called",
"for",
"each",
"interaction",
"received",
"from",
"the",
"stream",
"and",
"must",
"be",
"implemented",
"in",
"extending",
"classes",
"."
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/StreamConsumer.php#L219-L222
|
datasift/datasift-php
|
lib/DataSift/StreamConsumer.php
|
DataSift_StreamConsumer.onDeleted
|
protected function onDeleted($interaction, $hash = false)
{
$this->_eventHandler->onDeleted($this, $interaction, $hash);
}
|
php
|
protected function onDeleted($interaction, $hash = false)
{
$this->_eventHandler->onDeleted($this, $interaction, $hash);
}
|
[
"protected",
"function",
"onDeleted",
"(",
"$",
"interaction",
",",
"$",
"hash",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"_eventHandler",
"->",
"onDeleted",
"(",
"$",
"this",
",",
"$",
"interaction",
",",
"$",
"hash",
")",
";",
"}"
] |
This is called for each DELETE request received from the stream and must
be implemented in extending classes.
@param array $interaction The interaction data structure
@param string $hash The stream hash.
@return void
|
[
"This",
"is",
"called",
"for",
"each",
"DELETE",
"request",
"received",
"from",
"the",
"stream",
"and",
"must",
"be",
"implemented",
"in",
"extending",
"classes",
"."
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/StreamConsumer.php#L233-L236
|
datasift/datasift-php
|
lib/DataSift/StreamConsumer.php
|
DataSift_StreamConsumer.consume
|
public function consume($auto_reconnect = true)
{
$this->_auto_reconnect = $auto_reconnect;
// Start consuming
$this->_state = self::STATE_STARTING;
$this->onStart();
}
|
php
|
public function consume($auto_reconnect = true)
{
$this->_auto_reconnect = $auto_reconnect;
// Start consuming
$this->_state = self::STATE_STARTING;
$this->onStart();
}
|
[
"public",
"function",
"consume",
"(",
"$",
"auto_reconnect",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"_auto_reconnect",
"=",
"$",
"auto_reconnect",
";",
"// Start consuming",
"$",
"this",
"->",
"_state",
"=",
"self",
"::",
"STATE_STARTING",
";",
"$",
"this",
"->",
"onStart",
"(",
")",
";",
"}"
] |
Once an instance of a StreamConsumer is ready for use, call this to
start consuming. Extending classes should implement onStart to handle
actually starting.
@param boolean $auto_reconnect Whether to reconnect automatically
@return void
|
[
"Once",
"an",
"instance",
"of",
"a",
"StreamConsumer",
"is",
"ready",
"for",
"use",
"call",
"this",
"to",
"start",
"consuming",
".",
"Extending",
"classes",
"should",
"implement",
"onStart",
"to",
"handle",
"actually",
"starting",
"."
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/StreamConsumer.php#L308-L315
|
datasift/datasift-php
|
lib/DataSift/StreamConsumer.php
|
DataSift_StreamConsumer.stop
|
public function stop()
{
if ($this->_state != self::STATE_RUNNING) {
throw new DataSift_Exception_InvalidData('Consumer state must be RUNNING before it can be stopped');
}
$this->_state = self::STATE_STOPPING;
}
|
php
|
public function stop()
{
if ($this->_state != self::STATE_RUNNING) {
throw new DataSift_Exception_InvalidData('Consumer state must be RUNNING before it can be stopped');
}
$this->_state = self::STATE_STOPPING;
}
|
[
"public",
"function",
"stop",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_state",
"!=",
"self",
"::",
"STATE_RUNNING",
")",
"{",
"throw",
"new",
"DataSift_Exception_InvalidData",
"(",
"'Consumer state must be RUNNING before it can be stopped'",
")",
";",
"}",
"$",
"this",
"->",
"_state",
"=",
"self",
"::",
"STATE_STOPPING",
";",
"}"
] |
This method can be called at any time to *request* that the consumer
stop consuming. This method sets the state to STATE_STOPPING and it's
up to the consumer implementation to notice that this has changed, stop
consuming and call the onStopped method.
@return void
@throws DataSift_Exception_InalidData
|
[
"This",
"method",
"can",
"be",
"called",
"at",
"any",
"time",
"to",
"*",
"request",
"*",
"that",
"the",
"consumer",
"stop",
"consuming",
".",
"This",
"method",
"sets",
"the",
"state",
"to",
"STATE_STOPPING",
"and",
"it",
"s",
"up",
"to",
"the",
"consumer",
"implementation",
"to",
"notice",
"that",
"this",
"has",
"changed",
"stop",
"consuming",
"and",
"call",
"the",
"onStopped",
"method",
"."
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/StreamConsumer.php#L334-L340
|
datasift/datasift-php
|
lib/DataSift/StreamConsumer.php
|
DataSift_StreamConsumer.onStop
|
protected function onStop($reason = '')
{
//var_dump(debug_backtrace());
if ($this->_state != self::STATE_STOPPING and $reason == '') {
$reason = 'Unexpected';
}
$this->_state = self::STATE_STOPPED;
$this->onStopped($reason);
}
|
php
|
protected function onStop($reason = '')
{
//var_dump(debug_backtrace());
if ($this->_state != self::STATE_STOPPING and $reason == '') {
$reason = 'Unexpected';
}
$this->_state = self::STATE_STOPPED;
$this->onStopped($reason);
}
|
[
"protected",
"function",
"onStop",
"(",
"$",
"reason",
"=",
"''",
")",
"{",
"//var_dump(debug_backtrace());",
"if",
"(",
"$",
"this",
"->",
"_state",
"!=",
"self",
"::",
"STATE_STOPPING",
"and",
"$",
"reason",
"==",
"''",
")",
"{",
"$",
"reason",
"=",
"'Unexpected'",
";",
"}",
"$",
"this",
"->",
"_state",
"=",
"self",
"::",
"STATE_STOPPED",
";",
"$",
"this",
"->",
"onStopped",
"(",
"$",
"reason",
")",
";",
"}"
] |
Default implementation of onStop. It's unlikely that this method will
ever be used in isolation, but rather it should be called as the final
step in the extending class's implementation.
@param string $reason Reason why the stream was stopped
@return void
@throws DataSift_Exception_InvalidData
|
[
"Default",
"implementation",
"of",
"onStop",
".",
"It",
"s",
"unlikely",
"that",
"this",
"method",
"will",
"ever",
"be",
"used",
"in",
"isolation",
"but",
"rather",
"it",
"should",
"be",
"called",
"as",
"the",
"final",
"step",
"in",
"the",
"extending",
"class",
"s",
"implementation",
"."
] |
train
|
https://github.com/datasift/datasift-php/blob/35282461ad3e54880e5940bb5afce26c75dc4bb9/lib/DataSift/StreamConsumer.php#L352-L361
|
huasituo/hstcms
|
src/Providers/HelperServiceProvider.php
|
HelperServiceProvider.register
|
public function register()
{
$file = $this->app->make(Filesystem::class);
$path = realpath(__DIR__.'/../Helpers');
$helpers = $file->glob($path.'/*.php');
foreach ($helpers as $helper)
{
require_once($helper);
}
$helpers = $file->glob($path.'/*/*.php');
foreach ($helpers as $helper)
{
require_once($helper);
}
}
|
php
|
public function register()
{
$file = $this->app->make(Filesystem::class);
$path = realpath(__DIR__.'/../Helpers');
$helpers = $file->glob($path.'/*.php');
foreach ($helpers as $helper)
{
require_once($helper);
}
$helpers = $file->glob($path.'/*/*.php');
foreach ($helpers as $helper)
{
require_once($helper);
}
}
|
[
"public",
"function",
"register",
"(",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"Filesystem",
"::",
"class",
")",
";",
"$",
"path",
"=",
"realpath",
"(",
"__DIR__",
".",
"'/../Helpers'",
")",
";",
"$",
"helpers",
"=",
"$",
"file",
"->",
"glob",
"(",
"$",
"path",
".",
"'/*.php'",
")",
";",
"foreach",
"(",
"$",
"helpers",
"as",
"$",
"helper",
")",
"{",
"require_once",
"(",
"$",
"helper",
")",
";",
"}",
"$",
"helpers",
"=",
"$",
"file",
"->",
"glob",
"(",
"$",
"path",
".",
"'/*/*.php'",
")",
";",
"foreach",
"(",
"$",
"helpers",
"as",
"$",
"helper",
")",
"{",
"require_once",
"(",
"$",
"helper",
")",
";",
"}",
"}"
] |
Register the application services.
@return void
|
[
"Register",
"the",
"application",
"services",
"."
] |
train
|
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Providers/HelperServiceProvider.php#L29-L43
|
kiwiz/ecl
|
src/ArrayUnion.php
|
ArrayUnion.getKeys
|
public function getKeys() {
$keys = [];
foreach($this->arrays as $array) {
$keys = array_merge($keys, $array instanceof \ArrayAccess ? $array->getKeys():array_keys($array));
}
return array_unique($keys);
}
|
php
|
public function getKeys() {
$keys = [];
foreach($this->arrays as $array) {
$keys = array_merge($keys, $array instanceof \ArrayAccess ? $array->getKeys():array_keys($array));
}
return array_unique($keys);
}
|
[
"public",
"function",
"getKeys",
"(",
")",
"{",
"$",
"keys",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"arrays",
"as",
"$",
"array",
")",
"{",
"$",
"keys",
"=",
"array_merge",
"(",
"$",
"keys",
",",
"$",
"array",
"instanceof",
"\\",
"ArrayAccess",
"?",
"$",
"array",
"->",
"getKeys",
"(",
")",
":",
"array_keys",
"(",
"$",
"array",
")",
")",
";",
"}",
"return",
"array_unique",
"(",
"$",
"keys",
")",
";",
"}"
] |
Get a list of all defined keys.
@return string[] Keys.
|
[
"Get",
"a",
"list",
"of",
"all",
"defined",
"keys",
"."
] |
train
|
https://github.com/kiwiz/ecl/blob/6536dd2a4c1905a08cf718bdbef56a22f0e9b488/src/ArrayUnion.php#L25-L31
|
kiwiz/ecl
|
src/ArrayUnion.php
|
ArrayUnion.&
|
public function &offsetGet($key) {
for($i = 0; $i < count($this->arrays); ++$i) {
if(Util::exists($this->arrays[$i], $key)) {
return $this->arrays[$i][$key];
}
}
throw new KeyNotFoundException($key);
}
|
php
|
public function &offsetGet($key) {
for($i = 0; $i < count($this->arrays); ++$i) {
if(Util::exists($this->arrays[$i], $key)) {
return $this->arrays[$i][$key];
}
}
throw new KeyNotFoundException($key);
}
|
[
"public",
"function",
"&",
"offsetGet",
"(",
"$",
"key",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"this",
"->",
"arrays",
")",
";",
"++",
"$",
"i",
")",
"{",
"if",
"(",
"Util",
"::",
"exists",
"(",
"$",
"this",
"->",
"arrays",
"[",
"$",
"i",
"]",
",",
"$",
"key",
")",
")",
"{",
"return",
"$",
"this",
"->",
"arrays",
"[",
"$",
"i",
"]",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"throw",
"new",
"KeyNotFoundException",
"(",
"$",
"key",
")",
";",
"}"
] |
Get the value for a symbol.
@param string $key Symbol name.
@return Value Symbol value.
|
[
"Get",
"the",
"value",
"for",
"a",
"symbol",
"."
] |
train
|
https://github.com/kiwiz/ecl/blob/6536dd2a4c1905a08cf718bdbef56a22f0e9b488/src/ArrayUnion.php#L38-L45
|
phramework/validate
|
src/NumberValidator.php
|
NumberValidator.validate
|
public function validate($value)
{
$return = $this->validateCommon($value, new ValidateResult($value, true));
if ($return->status === false) {
return $return;
}
return $this->validateNumber($return->value);
}
|
php
|
public function validate($value)
{
$return = $this->validateCommon($value, new ValidateResult($value, true));
if ($return->status === false) {
return $return;
}
return $this->validateNumber($return->value);
}
|
[
"public",
"function",
"validate",
"(",
"$",
"value",
")",
"{",
"$",
"return",
"=",
"$",
"this",
"->",
"validateCommon",
"(",
"$",
"value",
",",
"new",
"ValidateResult",
"(",
"$",
"value",
",",
"true",
")",
")",
";",
"if",
"(",
"$",
"return",
"->",
"status",
"===",
"false",
")",
"{",
"return",
"$",
"return",
";",
"}",
"return",
"$",
"this",
"->",
"validateNumber",
"(",
"$",
"return",
"->",
"value",
")",
";",
"}"
] |
Validate value
@see \Phramework\Validate\ValidateResult for ValidateResult object
@param mixed $value Value to validate
@return ValidateResult
|
[
"Validate",
"value"
] |
train
|
https://github.com/phramework/validate/blob/22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc/src/NumberValidator.php#L109-L118
|
phramework/validate
|
src/NumberValidator.php
|
NumberValidator.validateNumber
|
protected function validateNumber($value)
{
$return = new ValidateResult($value, false);
if (is_string($value)) {
//Replace comma with dot
$value = str_replace(',', '.', $value);
}
//Apply all rules
if (!is_numeric($value) || filter_var($value, FILTER_VALIDATE_FLOAT) === false) {
//error
$return->errorObject = new IncorrectParametersException([
[
'type' => static::getType(),
'failure' => 'type'
]
]);
} elseif ($this->maximum !== null
&& ($value > $this->maximum
|| ($this->exclusiveMaximum === true && $value >= $this->maximum)
)
) {
//error
$return->errorObject = new IncorrectParametersException([
[
'type' => static::getType(),
'failure' => 'maximum'
]
]);
} elseif ($this->minimum !== null
&& ($value < $this->minimum
|| ($this->exclusiveMinimum === true && $value <= $this->minimum)
)
) {
//error
$return->errorObject = new IncorrectParametersException([
[
'type' => static::getType(),
'failure' => 'minimum'
]
]);
} elseif ($this->multipleOf !== null
&& fmod((float)$value, (float)$this->multipleOf) != 0
) {
//error
$return->errorObject = new IncorrectParametersException([
[
'type' => static::getType(),
'failure' => 'multipleOf'
]
]);
} else {
$return->errorObject = null;
//Set status to success
$return->status = true;
//Type cast
$return->value = $this->cast($value);
}
return $return;
}
|
php
|
protected function validateNumber($value)
{
$return = new ValidateResult($value, false);
if (is_string($value)) {
//Replace comma with dot
$value = str_replace(',', '.', $value);
}
//Apply all rules
if (!is_numeric($value) || filter_var($value, FILTER_VALIDATE_FLOAT) === false) {
//error
$return->errorObject = new IncorrectParametersException([
[
'type' => static::getType(),
'failure' => 'type'
]
]);
} elseif ($this->maximum !== null
&& ($value > $this->maximum
|| ($this->exclusiveMaximum === true && $value >= $this->maximum)
)
) {
//error
$return->errorObject = new IncorrectParametersException([
[
'type' => static::getType(),
'failure' => 'maximum'
]
]);
} elseif ($this->minimum !== null
&& ($value < $this->minimum
|| ($this->exclusiveMinimum === true && $value <= $this->minimum)
)
) {
//error
$return->errorObject = new IncorrectParametersException([
[
'type' => static::getType(),
'failure' => 'minimum'
]
]);
} elseif ($this->multipleOf !== null
&& fmod((float)$value, (float)$this->multipleOf) != 0
) {
//error
$return->errorObject = new IncorrectParametersException([
[
'type' => static::getType(),
'failure' => 'multipleOf'
]
]);
} else {
$return->errorObject = null;
//Set status to success
$return->status = true;
//Type cast
$return->value = $this->cast($value);
}
return $return;
}
|
[
"protected",
"function",
"validateNumber",
"(",
"$",
"value",
")",
"{",
"$",
"return",
"=",
"new",
"ValidateResult",
"(",
"$",
"value",
",",
"false",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"//Replace comma with dot",
"$",
"value",
"=",
"str_replace",
"(",
"','",
",",
"'.'",
",",
"$",
"value",
")",
";",
"}",
"//Apply all rules",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"value",
")",
"||",
"filter_var",
"(",
"$",
"value",
",",
"FILTER_VALIDATE_FLOAT",
")",
"===",
"false",
")",
"{",
"//error",
"$",
"return",
"->",
"errorObject",
"=",
"new",
"IncorrectParametersException",
"(",
"[",
"[",
"'type'",
"=>",
"static",
"::",
"getType",
"(",
")",
",",
"'failure'",
"=>",
"'type'",
"]",
"]",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"maximum",
"!==",
"null",
"&&",
"(",
"$",
"value",
">",
"$",
"this",
"->",
"maximum",
"||",
"(",
"$",
"this",
"->",
"exclusiveMaximum",
"===",
"true",
"&&",
"$",
"value",
">=",
"$",
"this",
"->",
"maximum",
")",
")",
")",
"{",
"//error",
"$",
"return",
"->",
"errorObject",
"=",
"new",
"IncorrectParametersException",
"(",
"[",
"[",
"'type'",
"=>",
"static",
"::",
"getType",
"(",
")",
",",
"'failure'",
"=>",
"'maximum'",
"]",
"]",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"minimum",
"!==",
"null",
"&&",
"(",
"$",
"value",
"<",
"$",
"this",
"->",
"minimum",
"||",
"(",
"$",
"this",
"->",
"exclusiveMinimum",
"===",
"true",
"&&",
"$",
"value",
"<=",
"$",
"this",
"->",
"minimum",
")",
")",
")",
"{",
"//error",
"$",
"return",
"->",
"errorObject",
"=",
"new",
"IncorrectParametersException",
"(",
"[",
"[",
"'type'",
"=>",
"static",
"::",
"getType",
"(",
")",
",",
"'failure'",
"=>",
"'minimum'",
"]",
"]",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"multipleOf",
"!==",
"null",
"&&",
"fmod",
"(",
"(",
"float",
")",
"$",
"value",
",",
"(",
"float",
")",
"$",
"this",
"->",
"multipleOf",
")",
"!=",
"0",
")",
"{",
"//error",
"$",
"return",
"->",
"errorObject",
"=",
"new",
"IncorrectParametersException",
"(",
"[",
"[",
"'type'",
"=>",
"static",
"::",
"getType",
"(",
")",
",",
"'failure'",
"=>",
"'multipleOf'",
"]",
"]",
")",
";",
"}",
"else",
"{",
"$",
"return",
"->",
"errorObject",
"=",
"null",
";",
"//Set status to success",
"$",
"return",
"->",
"status",
"=",
"true",
";",
"//Type cast",
"$",
"return",
"->",
"value",
"=",
"$",
"this",
"->",
"cast",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"return",
";",
"}"
] |
Validate value, without calling validateCommon
@see \Phramework\Validate\ValidateResult for ValidateResult object
@param mixed $value Value to validate
@return ValidateResult
|
[
"Validate",
"value",
"without",
"calling",
"validateCommon"
] |
train
|
https://github.com/phramework/validate/blob/22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc/src/NumberValidator.php#L126-L187
|
contao-bootstrap/buttons
|
src/Netzmacht/Bootstrap/Buttons/Factory.php
|
Factory.createFromFieldset
|
public static function createFromFieldset($definition)
{
$definition = self::parseDefinition($definition);
$root = new Group();
$group = $root;
/** @var bool|Dropdown $dropdown */
$dropdown = false;
$first = true;
foreach ($definition as $button) {
// dont add empty items
if (self::isInvalidDefinition($button)) {
continue;
}
// encode value
$button = self::encodeValue($button);
// finish dropdown
if (self::hasToCloseDropdown($dropdown, $button)) {
$dropdown = false;
}
if (in_array($button['type'], array('group', 'vgroup'))) {
// create new group
$group = self::createNewGroup($root, $button, $dropdown, !$first);
} elseif ($button['type'] == 'dropdown') {
// create dropdown
$dropdown = static::createDropdown($button['label'], $button['attributes'], true);
$dropdownGroup = static::createGroup();
$dropdownGroup->addChild($dropdown);
$group->addChild($dropdownGroup);
} elseif ($button['type'] == 'child' || $button['type'] == 'header') {
// add dropdown child
static::parseDropdownChild($dropdown, $button);
} elseif ($dropdown !== false) {
$child = static::createDropdownItem($button['label'], $button['url'], $button['attributes'], true);
$dropdown->addChild($child);
} else {
$child = static::createButton($button['label'], $button['url'], $button['attributes'], true);
$group->addChild($child);
}
$first = false;
}
return $root;
}
|
php
|
public static function createFromFieldset($definition)
{
$definition = self::parseDefinition($definition);
$root = new Group();
$group = $root;
/** @var bool|Dropdown $dropdown */
$dropdown = false;
$first = true;
foreach ($definition as $button) {
// dont add empty items
if (self::isInvalidDefinition($button)) {
continue;
}
// encode value
$button = self::encodeValue($button);
// finish dropdown
if (self::hasToCloseDropdown($dropdown, $button)) {
$dropdown = false;
}
if (in_array($button['type'], array('group', 'vgroup'))) {
// create new group
$group = self::createNewGroup($root, $button, $dropdown, !$first);
} elseif ($button['type'] == 'dropdown') {
// create dropdown
$dropdown = static::createDropdown($button['label'], $button['attributes'], true);
$dropdownGroup = static::createGroup();
$dropdownGroup->addChild($dropdown);
$group->addChild($dropdownGroup);
} elseif ($button['type'] == 'child' || $button['type'] == 'header') {
// add dropdown child
static::parseDropdownChild($dropdown, $button);
} elseif ($dropdown !== false) {
$child = static::createDropdownItem($button['label'], $button['url'], $button['attributes'], true);
$dropdown->addChild($child);
} else {
$child = static::createButton($button['label'], $button['url'], $button['attributes'], true);
$group->addChild($child);
}
$first = false;
}
return $root;
}
|
[
"public",
"static",
"function",
"createFromFieldset",
"(",
"$",
"definition",
")",
"{",
"$",
"definition",
"=",
"self",
"::",
"parseDefinition",
"(",
"$",
"definition",
")",
";",
"$",
"root",
"=",
"new",
"Group",
"(",
")",
";",
"$",
"group",
"=",
"$",
"root",
";",
"/** @var bool|Dropdown $dropdown */",
"$",
"dropdown",
"=",
"false",
";",
"$",
"first",
"=",
"true",
";",
"foreach",
"(",
"$",
"definition",
"as",
"$",
"button",
")",
"{",
"// dont add empty items",
"if",
"(",
"self",
"::",
"isInvalidDefinition",
"(",
"$",
"button",
")",
")",
"{",
"continue",
";",
"}",
"// encode value",
"$",
"button",
"=",
"self",
"::",
"encodeValue",
"(",
"$",
"button",
")",
";",
"// finish dropdown",
"if",
"(",
"self",
"::",
"hasToCloseDropdown",
"(",
"$",
"dropdown",
",",
"$",
"button",
")",
")",
"{",
"$",
"dropdown",
"=",
"false",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"button",
"[",
"'type'",
"]",
",",
"array",
"(",
"'group'",
",",
"'vgroup'",
")",
")",
")",
"{",
"// create new group",
"$",
"group",
"=",
"self",
"::",
"createNewGroup",
"(",
"$",
"root",
",",
"$",
"button",
",",
"$",
"dropdown",
",",
"!",
"$",
"first",
")",
";",
"}",
"elseif",
"(",
"$",
"button",
"[",
"'type'",
"]",
"==",
"'dropdown'",
")",
"{",
"// create dropdown",
"$",
"dropdown",
"=",
"static",
"::",
"createDropdown",
"(",
"$",
"button",
"[",
"'label'",
"]",
",",
"$",
"button",
"[",
"'attributes'",
"]",
",",
"true",
")",
";",
"$",
"dropdownGroup",
"=",
"static",
"::",
"createGroup",
"(",
")",
";",
"$",
"dropdownGroup",
"->",
"addChild",
"(",
"$",
"dropdown",
")",
";",
"$",
"group",
"->",
"addChild",
"(",
"$",
"dropdownGroup",
")",
";",
"}",
"elseif",
"(",
"$",
"button",
"[",
"'type'",
"]",
"==",
"'child'",
"||",
"$",
"button",
"[",
"'type'",
"]",
"==",
"'header'",
")",
"{",
"// add dropdown child",
"static",
"::",
"parseDropdownChild",
"(",
"$",
"dropdown",
",",
"$",
"button",
")",
";",
"}",
"elseif",
"(",
"$",
"dropdown",
"!==",
"false",
")",
"{",
"$",
"child",
"=",
"static",
"::",
"createDropdownItem",
"(",
"$",
"button",
"[",
"'label'",
"]",
",",
"$",
"button",
"[",
"'url'",
"]",
",",
"$",
"button",
"[",
"'attributes'",
"]",
",",
"true",
")",
";",
"$",
"dropdown",
"->",
"addChild",
"(",
"$",
"child",
")",
";",
"}",
"else",
"{",
"$",
"child",
"=",
"static",
"::",
"createButton",
"(",
"$",
"button",
"[",
"'label'",
"]",
",",
"$",
"button",
"[",
"'url'",
"]",
",",
"$",
"button",
"[",
"'attributes'",
"]",
",",
"true",
")",
";",
"$",
"group",
"->",
"addChild",
"(",
"$",
"child",
")",
";",
"}",
"$",
"first",
"=",
"false",
";",
"}",
"return",
"$",
"root",
";",
"}"
] |
Create button from fieldset defintiion.
@param string|array $definition Button definition.
@return Group|Toolbar
|
[
"Create",
"button",
"from",
"fieldset",
"defintiion",
"."
] |
train
|
https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L28-L79
|
contao-bootstrap/buttons
|
src/Netzmacht/Bootstrap/Buttons/Factory.php
|
Factory.createButton
|
public static function createButton($label, $url, array $attributes = array(), $fromFieldset = false)
{
$button = new Button();
$button->setLabel($label);
static::applyAttributes($button, $attributes, $fromFieldset);
$button->setAttribute('href', $url);
return $button;
}
|
php
|
public static function createButton($label, $url, array $attributes = array(), $fromFieldset = false)
{
$button = new Button();
$button->setLabel($label);
static::applyAttributes($button, $attributes, $fromFieldset);
$button->setAttribute('href', $url);
return $button;
}
|
[
"public",
"static",
"function",
"createButton",
"(",
"$",
"label",
",",
"$",
"url",
",",
"array",
"$",
"attributes",
"=",
"array",
"(",
")",
",",
"$",
"fromFieldset",
"=",
"false",
")",
"{",
"$",
"button",
"=",
"new",
"Button",
"(",
")",
";",
"$",
"button",
"->",
"setLabel",
"(",
"$",
"label",
")",
";",
"static",
"::",
"applyAttributes",
"(",
"$",
"button",
",",
"$",
"attributes",
",",
"$",
"fromFieldset",
")",
";",
"$",
"button",
"->",
"setAttribute",
"(",
"'href'",
",",
"$",
"url",
")",
";",
"return",
"$",
"button",
";",
"}"
] |
Create a button.
@param string $label Button label.
@param string $url Button href url.
@param array $attributes Additional html attributes.
@param bool $fromFieldset Set true if attributes comes from fieldset definitions have to be transformed.
@return Button
|
[
"Create",
"a",
"button",
"."
] |
train
|
https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L91-L99
|
contao-bootstrap/buttons
|
src/Netzmacht/Bootstrap/Buttons/Factory.php
|
Factory.createGroup
|
public static function createGroup(array $attributes = array(), $fromFieldset = false, $vertical = false)
{
$group = new Group(array(), $vertical);
static::applyAttributes($group, $attributes, $fromFieldset);
return $group;
}
|
php
|
public static function createGroup(array $attributes = array(), $fromFieldset = false, $vertical = false)
{
$group = new Group(array(), $vertical);
static::applyAttributes($group, $attributes, $fromFieldset);
return $group;
}
|
[
"public",
"static",
"function",
"createGroup",
"(",
"array",
"$",
"attributes",
"=",
"array",
"(",
")",
",",
"$",
"fromFieldset",
"=",
"false",
",",
"$",
"vertical",
"=",
"false",
")",
"{",
"$",
"group",
"=",
"new",
"Group",
"(",
"array",
"(",
")",
",",
"$",
"vertical",
")",
";",
"static",
"::",
"applyAttributes",
"(",
"$",
"group",
",",
"$",
"attributes",
",",
"$",
"fromFieldset",
")",
";",
"return",
"$",
"group",
";",
"}"
] |
Create button group.
@param array $attributes Additional html attributes.
@param bool $fromFieldset Set true if attributes comes from fieldset definitions have to be transformed.
@param bool $vertical If true a vertical group is created.
@return Group
|
[
"Create",
"button",
"group",
"."
] |
train
|
https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L110-L116
|
contao-bootstrap/buttons
|
src/Netzmacht/Bootstrap/Buttons/Factory.php
|
Factory.createToolbar
|
public static function createToolbar(array $attributes = array(), $fromFieldset = false)
{
$toolbar = new Toolbar();
static::applyAttributes($toolbar, $attributes, $fromFieldset);
return $toolbar;
}
|
php
|
public static function createToolbar(array $attributes = array(), $fromFieldset = false)
{
$toolbar = new Toolbar();
static::applyAttributes($toolbar, $attributes, $fromFieldset);
return $toolbar;
}
|
[
"public",
"static",
"function",
"createToolbar",
"(",
"array",
"$",
"attributes",
"=",
"array",
"(",
")",
",",
"$",
"fromFieldset",
"=",
"false",
")",
"{",
"$",
"toolbar",
"=",
"new",
"Toolbar",
"(",
")",
";",
"static",
"::",
"applyAttributes",
"(",
"$",
"toolbar",
",",
"$",
"attributes",
",",
"$",
"fromFieldset",
")",
";",
"return",
"$",
"toolbar",
";",
"}"
] |
Create button toolbar.
@param array $attributes Additional html attributes.
@param bool $fromFieldset Set true if attributes comes from fieldset definitions have to be transformed.
@return Toolbar
|
[
"Create",
"button",
"toolbar",
"."
] |
train
|
https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L126-L132
|
contao-bootstrap/buttons
|
src/Netzmacht/Bootstrap/Buttons/Factory.php
|
Factory.createDropdown
|
public static function createDropdown($label, array $attributes = array(), $fromFieldset = false)
{
$dropdown = new Dropdown();
$dropdown->setLabel($label);
static::applyAttributes($dropdown, $attributes, $fromFieldset);
return $dropdown;
}
|
php
|
public static function createDropdown($label, array $attributes = array(), $fromFieldset = false)
{
$dropdown = new Dropdown();
$dropdown->setLabel($label);
static::applyAttributes($dropdown, $attributes, $fromFieldset);
return $dropdown;
}
|
[
"public",
"static",
"function",
"createDropdown",
"(",
"$",
"label",
",",
"array",
"$",
"attributes",
"=",
"array",
"(",
")",
",",
"$",
"fromFieldset",
"=",
"false",
")",
"{",
"$",
"dropdown",
"=",
"new",
"Dropdown",
"(",
")",
";",
"$",
"dropdown",
"->",
"setLabel",
"(",
"$",
"label",
")",
";",
"static",
"::",
"applyAttributes",
"(",
"$",
"dropdown",
",",
"$",
"attributes",
",",
"$",
"fromFieldset",
")",
";",
"return",
"$",
"dropdown",
";",
"}"
] |
Create dropdown button.
@param string $label Dropdown button.
@param array $attributes Additional html attributes.
@param bool $fromFieldset Set true if attributes comes from fieldset definitions have to be transformed.
@return Dropdown
|
[
"Create",
"dropdown",
"button",
"."
] |
train
|
https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L143-L151
|
contao-bootstrap/buttons
|
src/Netzmacht/Bootstrap/Buttons/Factory.php
|
Factory.createDropdownHeader
|
public static function createDropdownHeader($label, array $attributes = array(), $fromFieldset = false)
{
$dropdown = new Dropdown\Header();
$dropdown->setLabel($label);
static::applyAttributes($dropdown, $attributes, $fromFieldset);
return $dropdown;
}
|
php
|
public static function createDropdownHeader($label, array $attributes = array(), $fromFieldset = false)
{
$dropdown = new Dropdown\Header();
$dropdown->setLabel($label);
static::applyAttributes($dropdown, $attributes, $fromFieldset);
return $dropdown;
}
|
[
"public",
"static",
"function",
"createDropdownHeader",
"(",
"$",
"label",
",",
"array",
"$",
"attributes",
"=",
"array",
"(",
")",
",",
"$",
"fromFieldset",
"=",
"false",
")",
"{",
"$",
"dropdown",
"=",
"new",
"Dropdown",
"\\",
"Header",
"(",
")",
";",
"$",
"dropdown",
"->",
"setLabel",
"(",
"$",
"label",
")",
";",
"static",
"::",
"applyAttributes",
"(",
"$",
"dropdown",
",",
"$",
"attributes",
",",
"$",
"fromFieldset",
")",
";",
"return",
"$",
"dropdown",
";",
"}"
] |
Create dropdown header.
@param string $label Dropdown button.
@param array $attributes Additional html attributes.
@param bool $fromFieldset Set true if attributes comes from fieldset definitions have to be transformed.
@return Dropdown\Header
|
[
"Create",
"dropdown",
"header",
"."
] |
train
|
https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L162-L170
|
contao-bootstrap/buttons
|
src/Netzmacht/Bootstrap/Buttons/Factory.php
|
Factory.createDropdownDivider
|
public static function createDropdownDivider(array $attributes = array(), $fromFieldset = false)
{
$dropdown = new Dropdown\Divider();
static::applyAttributes($dropdown, $attributes, $fromFieldset);
return $dropdown;
}
|
php
|
public static function createDropdownDivider(array $attributes = array(), $fromFieldset = false)
{
$dropdown = new Dropdown\Divider();
static::applyAttributes($dropdown, $attributes, $fromFieldset);
return $dropdown;
}
|
[
"public",
"static",
"function",
"createDropdownDivider",
"(",
"array",
"$",
"attributes",
"=",
"array",
"(",
")",
",",
"$",
"fromFieldset",
"=",
"false",
")",
"{",
"$",
"dropdown",
"=",
"new",
"Dropdown",
"\\",
"Divider",
"(",
")",
";",
"static",
"::",
"applyAttributes",
"(",
"$",
"dropdown",
",",
"$",
"attributes",
",",
"$",
"fromFieldset",
")",
";",
"return",
"$",
"dropdown",
";",
"}"
] |
Create dropdown divider.
@param array $attributes Additional html attributes.
@param bool $fromFieldset Set true if attributes comes from fieldset definitions have to be transformed.
@return Dropdown\Divider
|
[
"Create",
"dropdown",
"divider",
"."
] |
train
|
https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L180-L186
|
contao-bootstrap/buttons
|
src/Netzmacht/Bootstrap/Buttons/Factory.php
|
Factory.createDropdownItem
|
public static function createDropdownItem($label, $url, array $attributes = array(), $fromFieldset = false)
{
$button = static::createButton($label, $url, $attributes, $fromFieldset);
$button->setAttribute('role', 'menuitem');
$dropdown = new Dropdown\Item($button);
return $dropdown;
}
|
php
|
public static function createDropdownItem($label, $url, array $attributes = array(), $fromFieldset = false)
{
$button = static::createButton($label, $url, $attributes, $fromFieldset);
$button->setAttribute('role', 'menuitem');
$dropdown = new Dropdown\Item($button);
return $dropdown;
}
|
[
"public",
"static",
"function",
"createDropdownItem",
"(",
"$",
"label",
",",
"$",
"url",
",",
"array",
"$",
"attributes",
"=",
"array",
"(",
")",
",",
"$",
"fromFieldset",
"=",
"false",
")",
"{",
"$",
"button",
"=",
"static",
"::",
"createButton",
"(",
"$",
"label",
",",
"$",
"url",
",",
"$",
"attributes",
",",
"$",
"fromFieldset",
")",
";",
"$",
"button",
"->",
"setAttribute",
"(",
"'role'",
",",
"'menuitem'",
")",
";",
"$",
"dropdown",
"=",
"new",
"Dropdown",
"\\",
"Item",
"(",
"$",
"button",
")",
";",
"return",
"$",
"dropdown",
";",
"}"
] |
Create dropdown item.
@param string $label Dropdown label.
@param string $url Dropdown url.
@param array $attributes Additional html attributes.
@param bool $fromFieldset Set true if attributes comes from fieldset definitions have to be transformed.
@return Dropdown\Item
|
[
"Create",
"dropdown",
"item",
"."
] |
train
|
https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L198-L205
|
contao-bootstrap/buttons
|
src/Netzmacht/Bootstrap/Buttons/Factory.php
|
Factory.applyAttributes
|
protected static function applyAttributes(Attributes $node, array $attributes, $fromFieldset = false)
{
if (empty($attributes)) {
return;
}
if ($fromFieldset) {
foreach ($attributes as $attribute) {
if ($attribute['name']) {
if ($attribute['name'] == 'class') {
if (!$attribute['value']) {
return;
}
$attribute['value'] = explode(' ', $attribute['value']);
}
$node->setAttribute($attribute['name'], $attribute['value']);
}
}
} else {
foreach ($attributes as $name => $value) {
if ($name) {
$node->setAttribute($name, $value);
}
}
}
}
|
php
|
protected static function applyAttributes(Attributes $node, array $attributes, $fromFieldset = false)
{
if (empty($attributes)) {
return;
}
if ($fromFieldset) {
foreach ($attributes as $attribute) {
if ($attribute['name']) {
if ($attribute['name'] == 'class') {
if (!$attribute['value']) {
return;
}
$attribute['value'] = explode(' ', $attribute['value']);
}
$node->setAttribute($attribute['name'], $attribute['value']);
}
}
} else {
foreach ($attributes as $name => $value) {
if ($name) {
$node->setAttribute($name, $value);
}
}
}
}
|
[
"protected",
"static",
"function",
"applyAttributes",
"(",
"Attributes",
"$",
"node",
",",
"array",
"$",
"attributes",
",",
"$",
"fromFieldset",
"=",
"false",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"attributes",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"fromFieldset",
")",
"{",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
")",
"{",
"if",
"(",
"$",
"attribute",
"[",
"'name'",
"]",
")",
"{",
"if",
"(",
"$",
"attribute",
"[",
"'name'",
"]",
"==",
"'class'",
")",
"{",
"if",
"(",
"!",
"$",
"attribute",
"[",
"'value'",
"]",
")",
"{",
"return",
";",
"}",
"$",
"attribute",
"[",
"'value'",
"]",
"=",
"explode",
"(",
"' '",
",",
"$",
"attribute",
"[",
"'value'",
"]",
")",
";",
"}",
"$",
"node",
"->",
"setAttribute",
"(",
"$",
"attribute",
"[",
"'name'",
"]",
",",
"$",
"attribute",
"[",
"'value'",
"]",
")",
";",
"}",
"}",
"}",
"else",
"{",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"name",
")",
"{",
"$",
"node",
"->",
"setAttribute",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}",
"}",
"}"
] |
Apply attributes.
@param Attributes $node Attrbiutes alement.
@param array $attributes Html attributes which being applied.
@param bool $fromFieldset Set true if attributes comes from fieldset definitions have to be transformed.
@return void
|
[
"Apply",
"attributes",
"."
] |
train
|
https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L216-L242
|
contao-bootstrap/buttons
|
src/Netzmacht/Bootstrap/Buttons/Factory.php
|
Factory.enableToolbar
|
protected static function enableToolbar($root)
{
if (!$root instanceof Toolbar) {
$group = $root;
$root = static::createToolbar(array(), true);
if ($group instanceof Group && $group->getChildren()) {
$root->addChild($group);
}
}
return $root;
}
|
php
|
protected static function enableToolbar($root)
{
if (!$root instanceof Toolbar) {
$group = $root;
$root = static::createToolbar(array(), true);
if ($group instanceof Group && $group->getChildren()) {
$root->addChild($group);
}
}
return $root;
}
|
[
"protected",
"static",
"function",
"enableToolbar",
"(",
"$",
"root",
")",
"{",
"if",
"(",
"!",
"$",
"root",
"instanceof",
"Toolbar",
")",
"{",
"$",
"group",
"=",
"$",
"root",
";",
"$",
"root",
"=",
"static",
"::",
"createToolbar",
"(",
"array",
"(",
")",
",",
"true",
")",
";",
"if",
"(",
"$",
"group",
"instanceof",
"Group",
"&&",
"$",
"group",
"->",
"getChildren",
"(",
")",
")",
"{",
"$",
"root",
"->",
"addChild",
"(",
"$",
"group",
")",
";",
"}",
"}",
"return",
"$",
"root",
";",
"}"
] |
Enable the toolbar.
@param mixed $root Current root element.
@return Toolbar
|
[
"Enable",
"the",
"toolbar",
"."
] |
train
|
https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L251-L263
|
contao-bootstrap/buttons
|
src/Netzmacht/Bootstrap/Buttons/Factory.php
|
Factory.parseDropdownChild
|
private static function parseDropdownChild($dropdown, $button)
{
if ($dropdown === false || !$dropdown instanceof Dropdown) {
// @codingStandardsIgnoreStart
// TODO throw exception?
// @codingStandardsIgnoreEnd
return;
}
if ($button['type'] == 'child') {
$child = static::createDropdownItem($button['label'], $button['url'], $button['attributes'], true);
} else {
if ($dropdown->getChildren()) {
$child = static::createDropdownDivider();
$dropdown->addChild($child);
}
$child = static::createDropdownHeader($button['label'], $button['attributes'], true);
}
$dropdown->addChild($child);
}
|
php
|
private static function parseDropdownChild($dropdown, $button)
{
if ($dropdown === false || !$dropdown instanceof Dropdown) {
// @codingStandardsIgnoreStart
// TODO throw exception?
// @codingStandardsIgnoreEnd
return;
}
if ($button['type'] == 'child') {
$child = static::createDropdownItem($button['label'], $button['url'], $button['attributes'], true);
} else {
if ($dropdown->getChildren()) {
$child = static::createDropdownDivider();
$dropdown->addChild($child);
}
$child = static::createDropdownHeader($button['label'], $button['attributes'], true);
}
$dropdown->addChild($child);
}
|
[
"private",
"static",
"function",
"parseDropdownChild",
"(",
"$",
"dropdown",
",",
"$",
"button",
")",
"{",
"if",
"(",
"$",
"dropdown",
"===",
"false",
"||",
"!",
"$",
"dropdown",
"instanceof",
"Dropdown",
")",
"{",
"// @codingStandardsIgnoreStart",
"// TODO throw exception?",
"// @codingStandardsIgnoreEnd",
"return",
";",
"}",
"if",
"(",
"$",
"button",
"[",
"'type'",
"]",
"==",
"'child'",
")",
"{",
"$",
"child",
"=",
"static",
"::",
"createDropdownItem",
"(",
"$",
"button",
"[",
"'label'",
"]",
",",
"$",
"button",
"[",
"'url'",
"]",
",",
"$",
"button",
"[",
"'attributes'",
"]",
",",
"true",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"dropdown",
"->",
"getChildren",
"(",
")",
")",
"{",
"$",
"child",
"=",
"static",
"::",
"createDropdownDivider",
"(",
")",
";",
"$",
"dropdown",
"->",
"addChild",
"(",
"$",
"child",
")",
";",
"}",
"$",
"child",
"=",
"static",
"::",
"createDropdownHeader",
"(",
"$",
"button",
"[",
"'label'",
"]",
",",
"$",
"button",
"[",
"'attributes'",
"]",
",",
"true",
")",
";",
"}",
"$",
"dropdown",
"->",
"addChild",
"(",
"$",
"child",
")",
";",
"}"
] |
Parse dropdown child.
@param Dropdown|bool $dropdown Current dropdown element.
@param array $button Button definition.
@return void
|
[
"Parse",
"dropdown",
"child",
"."
] |
train
|
https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L273-L294
|
contao-bootstrap/buttons
|
src/Netzmacht/Bootstrap/Buttons/Factory.php
|
Factory.parseDefinition
|
protected static function parseDefinition($definition)
{
if (!is_array($definition)) {
$definition = deserialize($definition, true);
return $definition;
}
return $definition;
}
|
php
|
protected static function parseDefinition($definition)
{
if (!is_array($definition)) {
$definition = deserialize($definition, true);
return $definition;
}
return $definition;
}
|
[
"protected",
"static",
"function",
"parseDefinition",
"(",
"$",
"definition",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"definition",
")",
")",
"{",
"$",
"definition",
"=",
"deserialize",
"(",
"$",
"definition",
",",
"true",
")",
";",
"return",
"$",
"definition",
";",
"}",
"return",
"$",
"definition",
";",
"}"
] |
Parse button definition.
@param string|array $definition Button definition.
@return array
|
[
"Parse",
"button",
"definition",
"."
] |
train
|
https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L303-L312
|
contao-bootstrap/buttons
|
src/Netzmacht/Bootstrap/Buttons/Factory.php
|
Factory.encodeValue
|
protected static function encodeValue($button)
{
if (isset($button['button']) && $button['button'] == 'link') {
if (substr($button['value'], 0, 7) == 'mailto:') {
if (version_compare(VERSION . '.' . BUILD, '3.5.5', '>=')) {
$button['value'] = \StringUtil::encodeEmail($button['value']);
} else {
$button['value'] = \String::encodeEmail($button['value']);
}
} else {
$button['value'] = ampersand($button['value']);
}
}
return $button;
}
|
php
|
protected static function encodeValue($button)
{
if (isset($button['button']) && $button['button'] == 'link') {
if (substr($button['value'], 0, 7) == 'mailto:') {
if (version_compare(VERSION . '.' . BUILD, '3.5.5', '>=')) {
$button['value'] = \StringUtil::encodeEmail($button['value']);
} else {
$button['value'] = \String::encodeEmail($button['value']);
}
} else {
$button['value'] = ampersand($button['value']);
}
}
return $button;
}
|
[
"protected",
"static",
"function",
"encodeValue",
"(",
"$",
"button",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"button",
"[",
"'button'",
"]",
")",
"&&",
"$",
"button",
"[",
"'button'",
"]",
"==",
"'link'",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"button",
"[",
"'value'",
"]",
",",
"0",
",",
"7",
")",
"==",
"'mailto:'",
")",
"{",
"if",
"(",
"version_compare",
"(",
"VERSION",
".",
"'.'",
".",
"BUILD",
",",
"'3.5.5'",
",",
"'>='",
")",
")",
"{",
"$",
"button",
"[",
"'value'",
"]",
"=",
"\\",
"StringUtil",
"::",
"encodeEmail",
"(",
"$",
"button",
"[",
"'value'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"button",
"[",
"'value'",
"]",
"=",
"\\",
"String",
"::",
"encodeEmail",
"(",
"$",
"button",
"[",
"'value'",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"button",
"[",
"'value'",
"]",
"=",
"ampersand",
"(",
"$",
"button",
"[",
"'value'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"button",
";",
"}"
] |
Encode button value.
@param array $button Button definition.
@return array
|
[
"Encode",
"button",
"value",
"."
] |
train
|
https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L333-L348
|
contao-bootstrap/buttons
|
src/Netzmacht/Bootstrap/Buttons/Factory.php
|
Factory.createNewGroup
|
protected static function createNewGroup(&$root, $button, &$dropdown, $addToRoot = true)
{
if ($addToRoot) {
$root = self::enableToolbar($root);
}
if ($dropdown !== false) {
$dropdown = false;
}
$group = static::createGroup($button['attributes'], true, ($button['type'] === 'vgroup'));
if ($addToRoot) {
$root->addChild($group);
} else {
$root = $group;
}
return $group;
}
|
php
|
protected static function createNewGroup(&$root, $button, &$dropdown, $addToRoot = true)
{
if ($addToRoot) {
$root = self::enableToolbar($root);
}
if ($dropdown !== false) {
$dropdown = false;
}
$group = static::createGroup($button['attributes'], true, ($button['type'] === 'vgroup'));
if ($addToRoot) {
$root->addChild($group);
} else {
$root = $group;
}
return $group;
}
|
[
"protected",
"static",
"function",
"createNewGroup",
"(",
"&",
"$",
"root",
",",
"$",
"button",
",",
"&",
"$",
"dropdown",
",",
"$",
"addToRoot",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"addToRoot",
")",
"{",
"$",
"root",
"=",
"self",
"::",
"enableToolbar",
"(",
"$",
"root",
")",
";",
"}",
"if",
"(",
"$",
"dropdown",
"!==",
"false",
")",
"{",
"$",
"dropdown",
"=",
"false",
";",
"}",
"$",
"group",
"=",
"static",
"::",
"createGroup",
"(",
"$",
"button",
"[",
"'attributes'",
"]",
",",
"true",
",",
"(",
"$",
"button",
"[",
"'type'",
"]",
"===",
"'vgroup'",
")",
")",
";",
"if",
"(",
"$",
"addToRoot",
")",
"{",
"$",
"root",
"->",
"addChild",
"(",
"$",
"group",
")",
";",
"}",
"else",
"{",
"$",
"root",
"=",
"$",
"group",
";",
"}",
"return",
"$",
"group",
";",
"}"
] |
Create a new group element.
@param mixed $root Current root.
@param array $button Button definition.
@param Dropdown|bool $dropdown Dropdown element.
@param bool $addToRoot If rue the created group is added to the root.
@return Group
|
[
"Create",
"a",
"new",
"group",
"element",
"."
] |
train
|
https://github.com/contao-bootstrap/buttons/blob/f573a24c19ec059aae528a12ba46dfc993844201/src/Netzmacht/Bootstrap/Buttons/Factory.php#L360-L379
|
jan-dolata/crude-crud
|
src/Engine/CrudeInstance.php
|
CrudeInstance.get
|
public static function get($name)
{
$namespaces = config('crude.namespace');
if (! is_array($namespaces)) {
$fullName = $namespaces . $name;
return class_exists($fullName)
? new $fullName()
: null;
}
foreach ($namespaces as $namespace) {
$fullName = $namespace . $name;
if (class_exists($fullName))
return new $fullName();
}
return null;
}
|
php
|
public static function get($name)
{
$namespaces = config('crude.namespace');
if (! is_array($namespaces)) {
$fullName = $namespaces . $name;
return class_exists($fullName)
? new $fullName()
: null;
}
foreach ($namespaces as $namespace) {
$fullName = $namespace . $name;
if (class_exists($fullName))
return new $fullName();
}
return null;
}
|
[
"public",
"static",
"function",
"get",
"(",
"$",
"name",
")",
"{",
"$",
"namespaces",
"=",
"config",
"(",
"'crude.namespace'",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"namespaces",
")",
")",
"{",
"$",
"fullName",
"=",
"$",
"namespaces",
".",
"$",
"name",
";",
"return",
"class_exists",
"(",
"$",
"fullName",
")",
"?",
"new",
"$",
"fullName",
"(",
")",
":",
"null",
";",
"}",
"foreach",
"(",
"$",
"namespaces",
"as",
"$",
"namespace",
")",
"{",
"$",
"fullName",
"=",
"$",
"namespace",
".",
"$",
"name",
";",
"if",
"(",
"class_exists",
"(",
"$",
"fullName",
")",
")",
"return",
"new",
"$",
"fullName",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Create crude instance
@param string $name
@return Model|null
|
[
"Create",
"crude",
"instance"
] |
train
|
https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/CrudeInstance.php#L13-L32
|
blast-project/CoreBundle
|
src/Admin/Traits/PreEvents.php
|
PreEvents.prePersistOrUpdate
|
protected function prePersistOrUpdate($object, $method)
{
$analyzer = new ClassAnalyzer();
foreach ($analyzer->getTraits($this) as $traitname) {
$rc = new \ReflectionClass($traitname);
if (method_exists($this, $exec = $method . $rc->getShortName())) {
$this->$exec($object);
} // executes $this->prePersistMyTrait() or $this->preUpdateMyTrait() method
}
return $this;
}
|
php
|
protected function prePersistOrUpdate($object, $method)
{
$analyzer = new ClassAnalyzer();
foreach ($analyzer->getTraits($this) as $traitname) {
$rc = new \ReflectionClass($traitname);
if (method_exists($this, $exec = $method . $rc->getShortName())) {
$this->$exec($object);
} // executes $this->prePersistMyTrait() or $this->preUpdateMyTrait() method
}
return $this;
}
|
[
"protected",
"function",
"prePersistOrUpdate",
"(",
"$",
"object",
",",
"$",
"method",
")",
"{",
"$",
"analyzer",
"=",
"new",
"ClassAnalyzer",
"(",
")",
";",
"foreach",
"(",
"$",
"analyzer",
"->",
"getTraits",
"(",
"$",
"this",
")",
"as",
"$",
"traitname",
")",
"{",
"$",
"rc",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"traitname",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"exec",
"=",
"$",
"method",
".",
"$",
"rc",
"->",
"getShortName",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"$",
"exec",
"(",
"$",
"object",
")",
";",
"}",
"// executes $this->prePersistMyTrait() or $this->preUpdateMyTrait() method",
"}",
"return",
"$",
"this",
";",
"}"
] |
function prePersistOrUpdate.
Searches in every trait (as if they were kind of Doctrine Behaviors) some logical to be
executed during the self::prePersist() or self::preUpdate() calls
The logical is stored in the self::prePersist{TraitName}() method
@param object $object (Entity)
@param string $method (the current called method, eg. 'preUpdate' or 'prePersist')
@return CoreAdmin $this
|
[
"function",
"prePersistOrUpdate",
"."
] |
train
|
https://github.com/blast-project/CoreBundle/blob/7a0832758ca14e5bc5d65515532c1220df3930ae/src/Admin/Traits/PreEvents.php#L51-L62
|
comelyio/comely
|
src/Comely/IO/Yaml/Compiler.php
|
Compiler.setIndent
|
public function setIndent(int $indent = 2): self
{
if (!Number::Range($indent, 2, 8)) {
throw new CompilerException(sprintf('"%d" is an invalid indent value', $indent));
}
return $this;
}
|
php
|
public function setIndent(int $indent = 2): self
{
if (!Number::Range($indent, 2, 8)) {
throw new CompilerException(sprintf('"%d" is an invalid indent value', $indent));
}
return $this;
}
|
[
"public",
"function",
"setIndent",
"(",
"int",
"$",
"indent",
"=",
"2",
")",
":",
"self",
"{",
"if",
"(",
"!",
"Number",
"::",
"Range",
"(",
"$",
"indent",
",",
"2",
",",
"8",
")",
")",
"{",
"throw",
"new",
"CompilerException",
"(",
"sprintf",
"(",
"'\"%d\" is an invalid indent value'",
",",
"$",
"indent",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set indent spacer
@param int $indent
@return Compiler
@throws CompilerException
|
[
"Set",
"indent",
"spacer"
] |
train
|
https://github.com/comelyio/comely/blob/561ea7aef36fea347a1a79d3ee5597d4057ddf82/src/Comely/IO/Yaml/Compiler.php#L66-L73
|
axelitus/php-base
|
src/Comparison/IntComparer.php
|
IntComparer.setCallback
|
public function setCallback(Closure $callback = null)
{
if ($this->callback !== null || $callback === null) {
throw new \RuntimeException("Cannot redeclare this comparer callback.");
}
$this->callback = Closure::bind($callback, $this, get_called_class());
}
|
php
|
public function setCallback(Closure $callback = null)
{
if ($this->callback !== null || $callback === null) {
throw new \RuntimeException("Cannot redeclare this comparer callback.");
}
$this->callback = Closure::bind($callback, $this, get_called_class());
}
|
[
"public",
"function",
"setCallback",
"(",
"Closure",
"$",
"callback",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"callback",
"!==",
"null",
"||",
"$",
"callback",
"===",
"null",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Cannot redeclare this comparer callback.\"",
")",
";",
"}",
"$",
"this",
"->",
"callback",
"=",
"Closure",
"::",
"bind",
"(",
"$",
"callback",
",",
"$",
"this",
",",
"get_called_class",
"(",
")",
")",
";",
"}"
] |
This comparer does not allow to set the callback outside this class.
@param Closure $callback The new callback.
@throws \RuntimeException
|
[
"This",
"comparer",
"does",
"not",
"allow",
"to",
"set",
"the",
"callback",
"outside",
"this",
"class",
"."
] |
train
|
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Comparison/IntComparer.php#L52-L59
|
faganchalabizada/millikart-epos-laravel
|
src/Controller/EPOSController.php
|
EPOSController.createTransaction
|
public function createTransaction(Request $request)
{
$this->validate($request, [
'amount' => 'required|numeric',
'card_type' => 'required|numeric|max:3',
'phone_number' => 'phone_number',
]);
$amount = $request->input("amount");
$card_type = $request->input("card_type");
$phone_number = $request->input("phone_number") ?: "994044444444";
$EPOS = new EPOS();
$amount = round($amount, 2);
$card_type = ($card_type == 0) ? $EPOS::VISA : $EPOS::MASTERCARD;
//here you have to save transaction and get id. After send id in URL for result page.
$Wallet = new WalletApi();
$local_transaction_id = $Wallet->createTransaction(
2,
1,
$amount,
null,
\Auth::user()->id,
0
);
if ($local_transaction_id === false) {
$errors[] = "Something went wrong. Please try again.";
return Redirect::back()->withErrors($errors);
}
$response = $EPOS->getPaymentData(
$amount,
$phone_number,
$card_type,
url(str_replace("{id?}", $local_transaction_id, config("EPOS.result_url"))),
url(config("EPOS.failed_url")),
config("EPOS.form_type"),
config("EPOS.currency"),
""
);
$result = $EPOS->getResult($response);
if ($result == "success") {
$payment_id = $EPOS->getPaymentID($response);
$Wallet->editTransactionCode($local_transaction_id, $payment_id);
return Redirect::to($EPOS->getPaymentUrl($response));
}
$errors[] = $EPOS->getErrorInfo($response);
return Redirect::back()->withErrors($errors);
}
|
php
|
public function createTransaction(Request $request)
{
$this->validate($request, [
'amount' => 'required|numeric',
'card_type' => 'required|numeric|max:3',
'phone_number' => 'phone_number',
]);
$amount = $request->input("amount");
$card_type = $request->input("card_type");
$phone_number = $request->input("phone_number") ?: "994044444444";
$EPOS = new EPOS();
$amount = round($amount, 2);
$card_type = ($card_type == 0) ? $EPOS::VISA : $EPOS::MASTERCARD;
//here you have to save transaction and get id. After send id in URL for result page.
$Wallet = new WalletApi();
$local_transaction_id = $Wallet->createTransaction(
2,
1,
$amount,
null,
\Auth::user()->id,
0
);
if ($local_transaction_id === false) {
$errors[] = "Something went wrong. Please try again.";
return Redirect::back()->withErrors($errors);
}
$response = $EPOS->getPaymentData(
$amount,
$phone_number,
$card_type,
url(str_replace("{id?}", $local_transaction_id, config("EPOS.result_url"))),
url(config("EPOS.failed_url")),
config("EPOS.form_type"),
config("EPOS.currency"),
""
);
$result = $EPOS->getResult($response);
if ($result == "success") {
$payment_id = $EPOS->getPaymentID($response);
$Wallet->editTransactionCode($local_transaction_id, $payment_id);
return Redirect::to($EPOS->getPaymentUrl($response));
}
$errors[] = $EPOS->getErrorInfo($response);
return Redirect::back()->withErrors($errors);
}
|
[
"public",
"function",
"createTransaction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"validate",
"(",
"$",
"request",
",",
"[",
"'amount'",
"=>",
"'required|numeric'",
",",
"'card_type'",
"=>",
"'required|numeric|max:3'",
",",
"'phone_number'",
"=>",
"'phone_number'",
",",
"]",
")",
";",
"$",
"amount",
"=",
"$",
"request",
"->",
"input",
"(",
"\"amount\"",
")",
";",
"$",
"card_type",
"=",
"$",
"request",
"->",
"input",
"(",
"\"card_type\"",
")",
";",
"$",
"phone_number",
"=",
"$",
"request",
"->",
"input",
"(",
"\"phone_number\"",
")",
"?",
":",
"\"994044444444\"",
";",
"$",
"EPOS",
"=",
"new",
"EPOS",
"(",
")",
";",
"$",
"amount",
"=",
"round",
"(",
"$",
"amount",
",",
"2",
")",
";",
"$",
"card_type",
"=",
"(",
"$",
"card_type",
"==",
"0",
")",
"?",
"$",
"EPOS",
"::",
"VISA",
":",
"$",
"EPOS",
"::",
"MASTERCARD",
";",
"//here you have to save transaction and get id. After send id in URL for result page.",
"$",
"Wallet",
"=",
"new",
"WalletApi",
"(",
")",
";",
"$",
"local_transaction_id",
"=",
"$",
"Wallet",
"->",
"createTransaction",
"(",
"2",
",",
"1",
",",
"$",
"amount",
",",
"null",
",",
"\\",
"Auth",
"::",
"user",
"(",
")",
"->",
"id",
",",
"0",
")",
";",
"if",
"(",
"$",
"local_transaction_id",
"===",
"false",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"\"Something went wrong. Please try again.\"",
";",
"return",
"Redirect",
"::",
"back",
"(",
")",
"->",
"withErrors",
"(",
"$",
"errors",
")",
";",
"}",
"$",
"response",
"=",
"$",
"EPOS",
"->",
"getPaymentData",
"(",
"$",
"amount",
",",
"$",
"phone_number",
",",
"$",
"card_type",
",",
"url",
"(",
"str_replace",
"(",
"\"{id?}\"",
",",
"$",
"local_transaction_id",
",",
"config",
"(",
"\"EPOS.result_url\"",
")",
")",
")",
",",
"url",
"(",
"config",
"(",
"\"EPOS.failed_url\"",
")",
")",
",",
"config",
"(",
"\"EPOS.form_type\"",
")",
",",
"config",
"(",
"\"EPOS.currency\"",
")",
",",
"\"\"",
")",
";",
"$",
"result",
"=",
"$",
"EPOS",
"->",
"getResult",
"(",
"$",
"response",
")",
";",
"if",
"(",
"$",
"result",
"==",
"\"success\"",
")",
"{",
"$",
"payment_id",
"=",
"$",
"EPOS",
"->",
"getPaymentID",
"(",
"$",
"response",
")",
";",
"$",
"Wallet",
"->",
"editTransactionCode",
"(",
"$",
"local_transaction_id",
",",
"$",
"payment_id",
")",
";",
"return",
"Redirect",
"::",
"to",
"(",
"$",
"EPOS",
"->",
"getPaymentUrl",
"(",
"$",
"response",
")",
")",
";",
"}",
"$",
"errors",
"[",
"]",
"=",
"$",
"EPOS",
"->",
"getErrorInfo",
"(",
"$",
"response",
")",
";",
"return",
"Redirect",
"::",
"back",
"(",
")",
"->",
"withErrors",
"(",
"$",
"errors",
")",
";",
"}"
] |
Create transaction
@param $request
@return
|
[
"Create",
"transaction"
] |
train
|
https://github.com/faganchalabizada/millikart-epos-laravel/blob/0a535c59ba30acb1d0cbee933e788b35404eb7be/src/Controller/EPOSController.php#L53-L112
|
ekyna/GlsUniBox
|
Api/AbstractData.php
|
AbstractData.get
|
protected function get($tag)
{
if (isset($this->data[$tag])) {
return $this->data[$tag];
}
return null;
}
|
php
|
protected function get($tag)
{
if (isset($this->data[$tag])) {
return $this->data[$tag];
}
return null;
}
|
[
"protected",
"function",
"get",
"(",
"$",
"tag",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"tag",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"data",
"[",
"$",
"tag",
"]",
";",
"}",
"return",
"null",
";",
"}"
] |
Returns the value for the given tag.
@param string $tag
@return string|null
|
[
"Returns",
"the",
"value",
"for",
"the",
"given",
"tag",
"."
] |
train
|
https://github.com/ekyna/GlsUniBox/blob/b474271ba355c3917074422306dc64abf09584d0/Api/AbstractData.php#L54-L61
|
ekyna/GlsUniBox
|
Api/AbstractData.php
|
AbstractData.clean
|
public function clean()
{
foreach ($this->data as $key => $data) {
if (empty($data)) {
unset($this->data[$key]);
}
}
return $this;
}
|
php
|
public function clean()
{
foreach ($this->data as $key => $data) {
if (empty($data)) {
unset($this->data[$key]);
}
}
return $this;
}
|
[
"public",
"function",
"clean",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"key",
"=>",
"$",
"data",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Removes keys with empty value.
@return $this
|
[
"Removes",
"keys",
"with",
"empty",
"value",
"."
] |
train
|
https://github.com/ekyna/GlsUniBox/blob/b474271ba355c3917074422306dc64abf09584d0/Api/AbstractData.php#L68-L77
|
vincentchalamon/VinceCmsSonataAdminBundle
|
Form/Type/AreaType.php
|
AreaType.buildForm
|
public function buildForm(FormBuilderInterface $builder, array $options)
{
foreach ($options['areas'] as $area) {
/** @var Area $area */
$fieldOptions = array_merge(array(
'label' => $area->getTitle(),
'required' => $area->isRequired(),
), $area->getOptions());
if ($area->getType() == 'document') {
$fieldOptions['string'] = true;
}
$builder->add($area->getName(), $area->getType(), $fieldOptions);
}
}
|
php
|
public function buildForm(FormBuilderInterface $builder, array $options)
{
foreach ($options['areas'] as $area) {
/** @var Area $area */
$fieldOptions = array_merge(array(
'label' => $area->getTitle(),
'required' => $area->isRequired(),
), $area->getOptions());
if ($area->getType() == 'document') {
$fieldOptions['string'] = true;
}
$builder->add($area->getName(), $area->getType(), $fieldOptions);
}
}
|
[
"public",
"function",
"buildForm",
"(",
"FormBuilderInterface",
"$",
"builder",
",",
"array",
"$",
"options",
")",
"{",
"foreach",
"(",
"$",
"options",
"[",
"'areas'",
"]",
"as",
"$",
"area",
")",
"{",
"/** @var Area $area */",
"$",
"fieldOptions",
"=",
"array_merge",
"(",
"array",
"(",
"'label'",
"=>",
"$",
"area",
"->",
"getTitle",
"(",
")",
",",
"'required'",
"=>",
"$",
"area",
"->",
"isRequired",
"(",
")",
",",
")",
",",
"$",
"area",
"->",
"getOptions",
"(",
")",
")",
";",
"if",
"(",
"$",
"area",
"->",
"getType",
"(",
")",
"==",
"'document'",
")",
"{",
"$",
"fieldOptions",
"[",
"'string'",
"]",
"=",
"true",
";",
"}",
"$",
"builder",
"->",
"add",
"(",
"$",
"area",
"->",
"getName",
"(",
")",
",",
"$",
"area",
"->",
"getType",
"(",
")",
",",
"$",
"fieldOptions",
")",
";",
"}",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/vincentchalamon/VinceCmsSonataAdminBundle/blob/edc768061734a92ba116488dd7b61ad40af21ceb/Form/Type/AreaType.php#L28-L41
|
huasituo/hstcms
|
src/Console/Commands/HstcmsSeedCommand.php
|
HstcmsSeedCommand.handle
|
public function handle()
{
$seeder = ['ManageUser', 'CommonConfig', 'CommonRole', 'CommonRoleUri', 'ManageMenu'];
if($seeder) {
if($this->option('table')) {
if(in_array($this->option('table'), $seeder)) {
$fullPath = 'Huasituo\Hstcms\Database\Seeds\\'.$this->option('table').'TableSeeder';
$this->seed($fullPath, $this->option('table'));
}
} else {
foreach ($seeder as $key => $value) {
$fullPath = 'Huasituo\Hstcms\Database\Seeds\\'.$value.'TableSeeder';
$this->seed($fullPath, $value);
}
}
}
}
|
php
|
public function handle()
{
$seeder = ['ManageUser', 'CommonConfig', 'CommonRole', 'CommonRoleUri', 'ManageMenu'];
if($seeder) {
if($this->option('table')) {
if(in_array($this->option('table'), $seeder)) {
$fullPath = 'Huasituo\Hstcms\Database\Seeds\\'.$this->option('table').'TableSeeder';
$this->seed($fullPath, $this->option('table'));
}
} else {
foreach ($seeder as $key => $value) {
$fullPath = 'Huasituo\Hstcms\Database\Seeds\\'.$value.'TableSeeder';
$this->seed($fullPath, $value);
}
}
}
}
|
[
"public",
"function",
"handle",
"(",
")",
"{",
"$",
"seeder",
"=",
"[",
"'ManageUser'",
",",
"'CommonConfig'",
",",
"'CommonRole'",
",",
"'CommonRoleUri'",
",",
"'ManageMenu'",
"]",
";",
"if",
"(",
"$",
"seeder",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"option",
"(",
"'table'",
")",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"option",
"(",
"'table'",
")",
",",
"$",
"seeder",
")",
")",
"{",
"$",
"fullPath",
"=",
"'Huasituo\\Hstcms\\Database\\Seeds\\\\'",
".",
"$",
"this",
"->",
"option",
"(",
"'table'",
")",
".",
"'TableSeeder'",
";",
"$",
"this",
"->",
"seed",
"(",
"$",
"fullPath",
",",
"$",
"this",
"->",
"option",
"(",
"'table'",
")",
")",
";",
"}",
"}",
"else",
"{",
"foreach",
"(",
"$",
"seeder",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"fullPath",
"=",
"'Huasituo\\Hstcms\\Database\\Seeds\\\\'",
".",
"$",
"value",
".",
"'TableSeeder'",
";",
"$",
"this",
"->",
"seed",
"(",
"$",
"fullPath",
",",
"$",
"value",
")",
";",
"}",
"}",
"}",
"}"
] |
Execute the console command.
@return mixed
|
[
"Execute",
"the",
"console",
"command",
"."
] |
train
|
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Console/Commands/HstcmsSeedCommand.php#L52-L68
|
huasituo/hstcms
|
src/Console/Commands/HstcmsSeedCommand.php
|
HstcmsSeedCommand.seed
|
protected function seed($fullPath, $table)
{
if (class_exists($fullPath)) {
if ($this->option('class')) {
$params['--class'] = $this->option('class');
} else {
$params['--class'] = $fullPath;
}
if ($option = $this->option('database')) {
$params['--database'] = $option;
}
if ($option = $this->option('force')) {
$params['--force'] = $option;
}
$this->call('db:seed', $params);
$this->info('Seed: '. $table);
}
}
|
php
|
protected function seed($fullPath, $table)
{
if (class_exists($fullPath)) {
if ($this->option('class')) {
$params['--class'] = $this->option('class');
} else {
$params['--class'] = $fullPath;
}
if ($option = $this->option('database')) {
$params['--database'] = $option;
}
if ($option = $this->option('force')) {
$params['--force'] = $option;
}
$this->call('db:seed', $params);
$this->info('Seed: '. $table);
}
}
|
[
"protected",
"function",
"seed",
"(",
"$",
"fullPath",
",",
"$",
"table",
")",
"{",
"if",
"(",
"class_exists",
"(",
"$",
"fullPath",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"option",
"(",
"'class'",
")",
")",
"{",
"$",
"params",
"[",
"'--class'",
"]",
"=",
"$",
"this",
"->",
"option",
"(",
"'class'",
")",
";",
"}",
"else",
"{",
"$",
"params",
"[",
"'--class'",
"]",
"=",
"$",
"fullPath",
";",
"}",
"if",
"(",
"$",
"option",
"=",
"$",
"this",
"->",
"option",
"(",
"'database'",
")",
")",
"{",
"$",
"params",
"[",
"'--database'",
"]",
"=",
"$",
"option",
";",
"}",
"if",
"(",
"$",
"option",
"=",
"$",
"this",
"->",
"option",
"(",
"'force'",
")",
")",
"{",
"$",
"params",
"[",
"'--force'",
"]",
"=",
"$",
"option",
";",
"}",
"$",
"this",
"->",
"call",
"(",
"'db:seed'",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"info",
"(",
"'Seed: '",
".",
"$",
"table",
")",
";",
"}",
"}"
] |
Seed the specific module.
@param string $module
@return array
|
[
"Seed",
"the",
"specific",
"module",
"."
] |
train
|
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Console/Commands/HstcmsSeedCommand.php#L77-L94
|
refinery29/piston
|
src/RequestFactory.php
|
RequestFactory.fromGlobals
|
public static function fromGlobals(
array $server = null,
array $query = null,
array $body = null,
array $cookies = null,
array $files = null
) {
$cookies = new CookieJar($cookies ?: $_COOKIE);
$server = static::normalizeServer($server ?: $_SERVER);
$files = static::normalizeFiles($files ?: $_FILES);
$headers = static::marshalHeaders($server);
$request = new Request(
$cookies,
$server,
$files,
static::marshalUriFromServer($server, $headers),
static::get('REQUEST_METHOD', $server, 'GET'),
'php://input',
$headers
);
return $request
->withQueryParams($query ?: $_GET)
->withParsedBody($body ?: $_POST);
}
|
php
|
public static function fromGlobals(
array $server = null,
array $query = null,
array $body = null,
array $cookies = null,
array $files = null
) {
$cookies = new CookieJar($cookies ?: $_COOKIE);
$server = static::normalizeServer($server ?: $_SERVER);
$files = static::normalizeFiles($files ?: $_FILES);
$headers = static::marshalHeaders($server);
$request = new Request(
$cookies,
$server,
$files,
static::marshalUriFromServer($server, $headers),
static::get('REQUEST_METHOD', $server, 'GET'),
'php://input',
$headers
);
return $request
->withQueryParams($query ?: $_GET)
->withParsedBody($body ?: $_POST);
}
|
[
"public",
"static",
"function",
"fromGlobals",
"(",
"array",
"$",
"server",
"=",
"null",
",",
"array",
"$",
"query",
"=",
"null",
",",
"array",
"$",
"body",
"=",
"null",
",",
"array",
"$",
"cookies",
"=",
"null",
",",
"array",
"$",
"files",
"=",
"null",
")",
"{",
"$",
"cookies",
"=",
"new",
"CookieJar",
"(",
"$",
"cookies",
"?",
":",
"$",
"_COOKIE",
")",
";",
"$",
"server",
"=",
"static",
"::",
"normalizeServer",
"(",
"$",
"server",
"?",
":",
"$",
"_SERVER",
")",
";",
"$",
"files",
"=",
"static",
"::",
"normalizeFiles",
"(",
"$",
"files",
"?",
":",
"$",
"_FILES",
")",
";",
"$",
"headers",
"=",
"static",
"::",
"marshalHeaders",
"(",
"$",
"server",
")",
";",
"$",
"request",
"=",
"new",
"Request",
"(",
"$",
"cookies",
",",
"$",
"server",
",",
"$",
"files",
",",
"static",
"::",
"marshalUriFromServer",
"(",
"$",
"server",
",",
"$",
"headers",
")",
",",
"static",
"::",
"get",
"(",
"'REQUEST_METHOD'",
",",
"$",
"server",
",",
"'GET'",
")",
",",
"'php://input'",
",",
"$",
"headers",
")",
";",
"return",
"$",
"request",
"->",
"withQueryParams",
"(",
"$",
"query",
"?",
":",
"$",
"_GET",
")",
"->",
"withParsedBody",
"(",
"$",
"body",
"?",
":",
"$",
"_POST",
")",
";",
"}"
] |
@param array $server
@param array $query
@param array $body
@param array $cookies
@param array $files
@return ServerRequest
|
[
"@param",
"array",
"$server",
"@param",
"array",
"$query",
"@param",
"array",
"$body",
"@param",
"array",
"$cookies",
"@param",
"array",
"$files"
] |
train
|
https://github.com/refinery29/piston/blob/75c402e814136577fa9a02479e8803aca664c865/src/RequestFactory.php#L27-L51
|
ray-di/Ray.WebFormModule
|
src/AbstractForm.php
|
AbstractForm.setBaseDependencies
|
public function setBaseDependencies(
BuilderInterface $builder,
FilterFactory $filterFactory,
HelperLocatorFactory $helperFactory
) {
$this->builder = $builder;
$this->filter = $filterFactory->newSubjectFilter();
$this->helper = $helperFactory->newInstance();
}
|
php
|
public function setBaseDependencies(
BuilderInterface $builder,
FilterFactory $filterFactory,
HelperLocatorFactory $helperFactory
) {
$this->builder = $builder;
$this->filter = $filterFactory->newSubjectFilter();
$this->helper = $helperFactory->newInstance();
}
|
[
"public",
"function",
"setBaseDependencies",
"(",
"BuilderInterface",
"$",
"builder",
",",
"FilterFactory",
"$",
"filterFactory",
",",
"HelperLocatorFactory",
"$",
"helperFactory",
")",
"{",
"$",
"this",
"->",
"builder",
"=",
"$",
"builder",
";",
"$",
"this",
"->",
"filter",
"=",
"$",
"filterFactory",
"->",
"newSubjectFilter",
"(",
")",
";",
"$",
"this",
"->",
"helper",
"=",
"$",
"helperFactory",
"->",
"newInstance",
"(",
")",
";",
"}"
] |
@param BuilderInterface $builder
@param FilterFactory $filterFactory
@param HelperLocatorFactory $helperFactory
@\Ray\Di\Di\Inject
|
[
"@param",
"BuilderInterface",
"$builder",
"@param",
"FilterFactory",
"$filterFactory",
"@param",
"HelperLocatorFactory",
"$helperFactory"
] |
train
|
https://github.com/ray-di/Ray.WebFormModule/blob/4b6d33adb4a5c285278a068f3e7a5afdc4e680d9/src/AbstractForm.php#L78-L86
|
ray-di/Ray.WebFormModule
|
src/AbstractForm.php
|
AbstractForm.error
|
public function error($input)
{
if (! $this->errorMessages) {
$failure = $this->filter->getFailures();
if ($failure) {
$this->errorMessages = $failure->getMessages();
}
}
if (isset($this->errorMessages[$input])) {
return $this->errorMessages[$input][0];
}
return '';
}
|
php
|
public function error($input)
{
if (! $this->errorMessages) {
$failure = $this->filter->getFailures();
if ($failure) {
$this->errorMessages = $failure->getMessages();
}
}
if (isset($this->errorMessages[$input])) {
return $this->errorMessages[$input][0];
}
return '';
}
|
[
"public",
"function",
"error",
"(",
"$",
"input",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"errorMessages",
")",
"{",
"$",
"failure",
"=",
"$",
"this",
"->",
"filter",
"->",
"getFailures",
"(",
")",
";",
"if",
"(",
"$",
"failure",
")",
"{",
"$",
"this",
"->",
"errorMessages",
"=",
"$",
"failure",
"->",
"getMessages",
"(",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"errorMessages",
"[",
"$",
"input",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"errorMessages",
"[",
"$",
"input",
"]",
"[",
"0",
"]",
";",
"}",
"return",
"''",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/ray-di/Ray.WebFormModule/blob/4b6d33adb4a5c285278a068f3e7a5afdc4e680d9/src/AbstractForm.php#L115-L129
|
ray-di/Ray.WebFormModule
|
src/AbstractForm.php
|
AbstractForm.form
|
public function form($attr = [])
{
$form = $this->helper->form($attr);
if (isset($this->inputs['__csrf_token'])) {
$form .= $this->helper->input($this->get('__csrf_token'));
}
return $form;
}
|
php
|
public function form($attr = [])
{
$form = $this->helper->form($attr);
if (isset($this->inputs['__csrf_token'])) {
$form .= $this->helper->input($this->get('__csrf_token'));
}
return $form;
}
|
[
"public",
"function",
"form",
"(",
"$",
"attr",
"=",
"[",
"]",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"helper",
"->",
"form",
"(",
"$",
"attr",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"inputs",
"[",
"'__csrf_token'",
"]",
")",
")",
"{",
"$",
"form",
".=",
"$",
"this",
"->",
"helper",
"->",
"input",
"(",
"$",
"this",
"->",
"get",
"(",
"'__csrf_token'",
")",
")",
";",
"}",
"return",
"$",
"form",
";",
"}"
] |
@param array $attr attributes for the form tag
@throws \Aura\Html\Exception\HelperNotFound
@throws \Aura\Input\Exception\NoSuchInput
@return string
|
[
"@param",
"array",
"$attr",
"attributes",
"for",
"the",
"form",
"tag"
] |
train
|
https://github.com/ray-di/Ray.WebFormModule/blob/4b6d33adb4a5c285278a068f3e7a5afdc4e680d9/src/AbstractForm.php#L139-L147
|
ray-di/Ray.WebFormModule
|
src/AbstractForm.php
|
AbstractForm.apply
|
public function apply(array $data)
{
if ($this->antiCsrf && ! $this->antiCsrf->isValid($data)) {
throw new CsrfViolationException;
}
$this->fill($data);
return $this->filter->apply($data);
}
|
php
|
public function apply(array $data)
{
if ($this->antiCsrf && ! $this->antiCsrf->isValid($data)) {
throw new CsrfViolationException;
}
$this->fill($data);
return $this->filter->apply($data);
}
|
[
"public",
"function",
"apply",
"(",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"antiCsrf",
"&&",
"!",
"$",
"this",
"->",
"antiCsrf",
"->",
"isValid",
"(",
"$",
"data",
")",
")",
"{",
"throw",
"new",
"CsrfViolationException",
";",
"}",
"$",
"this",
"->",
"fill",
"(",
"$",
"data",
")",
";",
"return",
"$",
"this",
"->",
"filter",
"->",
"apply",
"(",
"$",
"data",
")",
";",
"}"
] |
Applies the filter to a subject.
@param array $data
@throws CsrfViolationException
@return bool
|
[
"Applies",
"the",
"filter",
"to",
"a",
"subject",
"."
] |
train
|
https://github.com/ray-di/Ray.WebFormModule/blob/4b6d33adb4a5c285278a068f3e7a5afdc4e680d9/src/AbstractForm.php#L158-L166
|
andyvenus/form
|
src/EntityProcessor/GetterSetterEntityProcessor.php
|
GetterSetterEntityProcessor.getFromEntity
|
public function getFromEntity($entity, array $formParameters, $limitFields = null)
{
$extracted_data = array();
foreach($formParameters as $field) {
$getter_name = "get".$this->dashesToCamelCase($field);
if (($limitFields === null || in_array($field, $limitFields)) && method_exists($entity, $getter_name) && ($value = $entity->$getter_name()) !== null) {
$extracted_data[$field] = $value;
}
}
return $extracted_data;
}
|
php
|
public function getFromEntity($entity, array $formParameters, $limitFields = null)
{
$extracted_data = array();
foreach($formParameters as $field) {
$getter_name = "get".$this->dashesToCamelCase($field);
if (($limitFields === null || in_array($field, $limitFields)) && method_exists($entity, $getter_name) && ($value = $entity->$getter_name()) !== null) {
$extracted_data[$field] = $value;
}
}
return $extracted_data;
}
|
[
"public",
"function",
"getFromEntity",
"(",
"$",
"entity",
",",
"array",
"$",
"formParameters",
",",
"$",
"limitFields",
"=",
"null",
")",
"{",
"$",
"extracted_data",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"formParameters",
"as",
"$",
"field",
")",
"{",
"$",
"getter_name",
"=",
"\"get\"",
".",
"$",
"this",
"->",
"dashesToCamelCase",
"(",
"$",
"field",
")",
";",
"if",
"(",
"(",
"$",
"limitFields",
"===",
"null",
"||",
"in_array",
"(",
"$",
"field",
",",
"$",
"limitFields",
")",
")",
"&&",
"method_exists",
"(",
"$",
"entity",
",",
"$",
"getter_name",
")",
"&&",
"(",
"$",
"value",
"=",
"$",
"entity",
"->",
"$",
"getter_name",
"(",
")",
")",
"!==",
"null",
")",
"{",
"$",
"extracted_data",
"[",
"$",
"field",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"extracted_data",
";",
"}"
] |
Get data from an entity using getter methods
@param $entity
@param array $formParameters
@param null $limitFields
@return array
|
[
"Get",
"data",
"from",
"an",
"entity",
"using",
"getter",
"methods"
] |
train
|
https://github.com/andyvenus/form/blob/fde9d7e1741a707028aec4fd55c3568802df3708/src/EntityProcessor/GetterSetterEntityProcessor.php#L25-L38
|
andyvenus/form
|
src/EntityProcessor/GetterSetterEntityProcessor.php
|
GetterSetterEntityProcessor.saveToEntity
|
public function saveToEntity($entity, $formData, $limitFields = null)
{
foreach($formData as $field => $value) {
$setter_name = "set".$this->dashesToCamelCase($field);
if (($limitFields === null || in_array($field, $limitFields)) && method_exists($entity, $setter_name)) {
$entity->$setter_name($value);
}
}
}
|
php
|
public function saveToEntity($entity, $formData, $limitFields = null)
{
foreach($formData as $field => $value) {
$setter_name = "set".$this->dashesToCamelCase($field);
if (($limitFields === null || in_array($field, $limitFields)) && method_exists($entity, $setter_name)) {
$entity->$setter_name($value);
}
}
}
|
[
"public",
"function",
"saveToEntity",
"(",
"$",
"entity",
",",
"$",
"formData",
",",
"$",
"limitFields",
"=",
"null",
")",
"{",
"foreach",
"(",
"$",
"formData",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"setter_name",
"=",
"\"set\"",
".",
"$",
"this",
"->",
"dashesToCamelCase",
"(",
"$",
"field",
")",
";",
"if",
"(",
"(",
"$",
"limitFields",
"===",
"null",
"||",
"in_array",
"(",
"$",
"field",
",",
"$",
"limitFields",
")",
")",
"&&",
"method_exists",
"(",
"$",
"entity",
",",
"$",
"setter_name",
")",
")",
"{",
"$",
"entity",
"->",
"$",
"setter_name",
"(",
"$",
"value",
")",
";",
"}",
"}",
"}"
] |
Save data to an entity using setter methods
@param $entity
@param $formData
@param null $limitFields
@return void
|
[
"Save",
"data",
"to",
"an",
"entity",
"using",
"setter",
"methods"
] |
train
|
https://github.com/andyvenus/form/blob/fde9d7e1741a707028aec4fd55c3568802df3708/src/EntityProcessor/GetterSetterEntityProcessor.php#L48-L57
|
foothing/laravel-repository
|
src/Foothing/Repository/Eloquent/EloquentRepository.php
|
EloquentRepository.setModel
|
public function setModel(\Illuminate\Database\Eloquent\Model $model) {
$this->model = $model;
if ($this->model instanceof ResourceInterface) {
$this->enableAutoEagerLoading = true;
}
}
|
php
|
public function setModel(\Illuminate\Database\Eloquent\Model $model) {
$this->model = $model;
if ($this->model instanceof ResourceInterface) {
$this->enableAutoEagerLoading = true;
}
}
|
[
"public",
"function",
"setModel",
"(",
"\\",
"Illuminate",
"\\",
"Database",
"\\",
"Eloquent",
"\\",
"Model",
"$",
"model",
")",
"{",
"$",
"this",
"->",
"model",
"=",
"$",
"model",
";",
"if",
"(",
"$",
"this",
"->",
"model",
"instanceof",
"ResourceInterface",
")",
"{",
"$",
"this",
"->",
"enableAutoEagerLoading",
"=",
"true",
";",
"}",
"}"
] |
Set the repository model.
@param \Illuminate\Database\Eloquent\Model $model
|
[
"Set",
"the",
"repository",
"model",
"."
] |
train
|
https://github.com/foothing/laravel-repository/blob/a2e329acb26a08d9f260c66534b0d4f42e2adff5/src/Foothing/Repository/Eloquent/EloquentRepository.php#L60-L65
|
foothing/laravel-repository
|
src/Foothing/Repository/Eloquent/EloquentRepository.php
|
EloquentRepository.finalize
|
protected function finalize($result) {
$this->eagerLoad = [];
$this->criteria->reset();
$this->scope = null;
return $result;
}
|
php
|
protected function finalize($result) {
$this->eagerLoad = [];
$this->criteria->reset();
$this->scope = null;
return $result;
}
|
[
"protected",
"function",
"finalize",
"(",
"$",
"result",
")",
"{",
"$",
"this",
"->",
"eagerLoad",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"criteria",
"->",
"reset",
"(",
")",
";",
"$",
"this",
"->",
"scope",
"=",
"null",
";",
"return",
"$",
"result",
";",
"}"
] |
Utility method for flags reset. Always use this to return results.
@param $result
The result we want to return
@return mixed
|
[
"Utility",
"method",
"for",
"flags",
"reset",
".",
"Always",
"use",
"this",
"to",
"return",
"results",
"."
] |
train
|
https://github.com/foothing/laravel-repository/blob/a2e329acb26a08d9f260c66534b0d4f42e2adff5/src/Foothing/Repository/Eloquent/EloquentRepository.php#L75-L80
|
foothing/laravel-repository
|
src/Foothing/Repository/Eloquent/EloquentRepository.php
|
EloquentRepository.applyAutoEagerLoading
|
protected function applyAutoEagerLoading($fetch = 'unit') {
if (! empty($this->eagerLoad)) {
return;
}
if ($this->enableAutoEagerLoading && $fetch == 'unit') {
$this->eagerLoad = $this->model->unitRelations();
}
elseif ($this->enableAutoEagerLoading && $fetch == 'list') {
$this->eagerLoad = $this->model->listRelations();
}
}
|
php
|
protected function applyAutoEagerLoading($fetch = 'unit') {
if (! empty($this->eagerLoad)) {
return;
}
if ($this->enableAutoEagerLoading && $fetch == 'unit') {
$this->eagerLoad = $this->model->unitRelations();
}
elseif ($this->enableAutoEagerLoading && $fetch == 'list') {
$this->eagerLoad = $this->model->listRelations();
}
}
|
[
"protected",
"function",
"applyAutoEagerLoading",
"(",
"$",
"fetch",
"=",
"'unit'",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"eagerLoad",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"enableAutoEagerLoading",
"&&",
"$",
"fetch",
"==",
"'unit'",
")",
"{",
"$",
"this",
"->",
"eagerLoad",
"=",
"$",
"this",
"->",
"model",
"->",
"unitRelations",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"enableAutoEagerLoading",
"&&",
"$",
"fetch",
"==",
"'list'",
")",
"{",
"$",
"this",
"->",
"eagerLoad",
"=",
"$",
"this",
"->",
"model",
"->",
"listRelations",
"(",
")",
";",
"}",
"}"
] |
Check whether the autoEagerLoading feature has to be applied.
@param string $fetch
|
[
"Check",
"whether",
"the",
"autoEagerLoading",
"feature",
"has",
"to",
"be",
"applied",
"."
] |
train
|
https://github.com/foothing/laravel-repository/blob/a2e329acb26a08d9f260c66534b0d4f42e2adff5/src/Foothing/Repository/Eloquent/EloquentRepository.php#L87-L99
|
heyday/heystack
|
src/DependencyInjection/SilverStripe/SilverStripeServiceTrait.php
|
SilverStripeServiceTrait.getInjector
|
protected function getInjector()
{
if ($this->injector === null) {
$this->injector = \Injector::inst();
}
return $this->injector;
}
|
php
|
protected function getInjector()
{
if ($this->injector === null) {
$this->injector = \Injector::inst();
}
return $this->injector;
}
|
[
"protected",
"function",
"getInjector",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"injector",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"injector",
"=",
"\\",
"Injector",
"::",
"inst",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"injector",
";",
"}"
] |
Retrieves the Injector instance
@return \Injector
|
[
"Retrieves",
"the",
"Injector",
"instance"
] |
train
|
https://github.com/heyday/heystack/blob/2c051933f8c532d0a9a23be6ee1ff5c619e47dfe/src/DependencyInjection/SilverStripe/SilverStripeServiceTrait.php#L34-L41
|
activecollab/databasestructure
|
src/Builder/TriggersBuilder.php
|
TriggersBuilder.prepareCreateTriggerStatement
|
public function prepareCreateTriggerStatement(TypeInterface $type, TriggerInterface $trigger)
{
if (strpos($trigger->getBody(), "\n") === false) {
return rtrim('CREATE TRIGGER ' . $this->getConnection()->escapeFieldName($trigger->getName()) . ' ' . strtoupper($trigger->getTime()) . ' ' . strtoupper($trigger->getEvent()) . ' ON ' . $this->getConnection()->escapeTableName($type->getName()) . ' FOR EACH ROW ' . $trigger->getBody(), ';') . ';';
} else {
$result = [];
$result[] = 'CREATE TRIGGER ' . $this->getConnection()->escapeFieldName($trigger->getName()) . ' ' . strtoupper($trigger->getTime()) . ' ' . strtoupper($trigger->getEvent()) . ' ON ' . $this->getConnection()->escapeTableName($type->getName());
$result[] = 'FOR EACH ROW BEGIN';
$result[] = $trigger->getBody();
$result[] = 'END;';
return $this->wrapDelimiter(implode("\n", $result));
}
}
|
php
|
public function prepareCreateTriggerStatement(TypeInterface $type, TriggerInterface $trigger)
{
if (strpos($trigger->getBody(), "\n") === false) {
return rtrim('CREATE TRIGGER ' . $this->getConnection()->escapeFieldName($trigger->getName()) . ' ' . strtoupper($trigger->getTime()) . ' ' . strtoupper($trigger->getEvent()) . ' ON ' . $this->getConnection()->escapeTableName($type->getName()) . ' FOR EACH ROW ' . $trigger->getBody(), ';') . ';';
} else {
$result = [];
$result[] = 'CREATE TRIGGER ' . $this->getConnection()->escapeFieldName($trigger->getName()) . ' ' . strtoupper($trigger->getTime()) . ' ' . strtoupper($trigger->getEvent()) . ' ON ' . $this->getConnection()->escapeTableName($type->getName());
$result[] = 'FOR EACH ROW BEGIN';
$result[] = $trigger->getBody();
$result[] = 'END;';
return $this->wrapDelimiter(implode("\n", $result));
}
}
|
[
"public",
"function",
"prepareCreateTriggerStatement",
"(",
"TypeInterface",
"$",
"type",
",",
"TriggerInterface",
"$",
"trigger",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"trigger",
"->",
"getBody",
"(",
")",
",",
"\"\\n\"",
")",
"===",
"false",
")",
"{",
"return",
"rtrim",
"(",
"'CREATE TRIGGER '",
".",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"escapeFieldName",
"(",
"$",
"trigger",
"->",
"getName",
"(",
")",
")",
".",
"' '",
".",
"strtoupper",
"(",
"$",
"trigger",
"->",
"getTime",
"(",
")",
")",
".",
"' '",
".",
"strtoupper",
"(",
"$",
"trigger",
"->",
"getEvent",
"(",
")",
")",
".",
"' ON '",
".",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"escapeTableName",
"(",
"$",
"type",
"->",
"getName",
"(",
")",
")",
".",
"' FOR EACH ROW '",
".",
"$",
"trigger",
"->",
"getBody",
"(",
")",
",",
"';'",
")",
".",
"';'",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"result",
"[",
"]",
"=",
"'CREATE TRIGGER '",
".",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"escapeFieldName",
"(",
"$",
"trigger",
"->",
"getName",
"(",
")",
")",
".",
"' '",
".",
"strtoupper",
"(",
"$",
"trigger",
"->",
"getTime",
"(",
")",
")",
".",
"' '",
".",
"strtoupper",
"(",
"$",
"trigger",
"->",
"getEvent",
"(",
")",
")",
".",
"' ON '",
".",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"escapeTableName",
"(",
"$",
"type",
"->",
"getName",
"(",
")",
")",
";",
"$",
"result",
"[",
"]",
"=",
"'FOR EACH ROW BEGIN'",
";",
"$",
"result",
"[",
"]",
"=",
"$",
"trigger",
"->",
"getBody",
"(",
")",
";",
"$",
"result",
"[",
"]",
"=",
"'END;'",
";",
"return",
"$",
"this",
"->",
"wrapDelimiter",
"(",
"implode",
"(",
"\"\\n\"",
",",
"$",
"result",
")",
")",
";",
"}",
"}"
] |
Prepare belongs to constraint statement.
@param TypeInterface $type
@param TriggerInterface $trigger
@return string
|
[
"Prepare",
"belongs",
"to",
"constraint",
"statement",
"."
] |
train
|
https://github.com/activecollab/databasestructure/blob/4b2353c4422186bcfce63b3212da3e70e63eb5df/src/Builder/TriggersBuilder.php#L83-L97
|
activecollab/databasestructure
|
src/Builder/TriggersBuilder.php
|
TriggersBuilder.triggerExists
|
private function triggerExists($trigger_name)
{
if ($triggers = $this->getConnection()->execute('SHOW TRIGGERS', $trigger_name)) {
foreach ($triggers as $trigger) {
if ($trigger['Trigger'] == $trigger_name) {
return true;
}
}
}
return false;
}
|
php
|
private function triggerExists($trigger_name)
{
if ($triggers = $this->getConnection()->execute('SHOW TRIGGERS', $trigger_name)) {
foreach ($triggers as $trigger) {
if ($trigger['Trigger'] == $trigger_name) {
return true;
}
}
}
return false;
}
|
[
"private",
"function",
"triggerExists",
"(",
"$",
"trigger_name",
")",
"{",
"if",
"(",
"$",
"triggers",
"=",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"execute",
"(",
"'SHOW TRIGGERS'",
",",
"$",
"trigger_name",
")",
")",
"{",
"foreach",
"(",
"$",
"triggers",
"as",
"$",
"trigger",
")",
"{",
"if",
"(",
"$",
"trigger",
"[",
"'Trigger'",
"]",
"==",
"$",
"trigger_name",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] |
Check if trigger exists.
@param string $trigger_name
@return bool
|
[
"Check",
"if",
"trigger",
"exists",
"."
] |
train
|
https://github.com/activecollab/databasestructure/blob/4b2353c4422186bcfce63b3212da3e70e63eb5df/src/Builder/TriggersBuilder.php#L134-L145
|
jan-dolata/crude-crud
|
src/Engine/Traits/FromModelTraitPart/StoreUpdateDeleteTrait.php
|
StoreUpdateDeleteTrait.store
|
public function store($attributes)
{
$attributes = $this->formatStoreAttributes($attributes);
$model = $this->model->create($this->mapAttributesWithScope($attributes));
if ($this->canOrder()) {
if ($this->storeInLastPlace) {
$attr = $this->crudeSetup->getOrderAttribute();
$model->$attr = $model->id;
$model->save();
}
$this->resetOrder();
}
$apiModel = $this->getById($model->id);
$this->afterStore($apiModel, $attributes);
return $apiModel;
}
|
php
|
public function store($attributes)
{
$attributes = $this->formatStoreAttributes($attributes);
$model = $this->model->create($this->mapAttributesWithScope($attributes));
if ($this->canOrder()) {
if ($this->storeInLastPlace) {
$attr = $this->crudeSetup->getOrderAttribute();
$model->$attr = $model->id;
$model->save();
}
$this->resetOrder();
}
$apiModel = $this->getById($model->id);
$this->afterStore($apiModel, $attributes);
return $apiModel;
}
|
[
"public",
"function",
"store",
"(",
"$",
"attributes",
")",
"{",
"$",
"attributes",
"=",
"$",
"this",
"->",
"formatStoreAttributes",
"(",
"$",
"attributes",
")",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"model",
"->",
"create",
"(",
"$",
"this",
"->",
"mapAttributesWithScope",
"(",
"$",
"attributes",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"canOrder",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"storeInLastPlace",
")",
"{",
"$",
"attr",
"=",
"$",
"this",
"->",
"crudeSetup",
"->",
"getOrderAttribute",
"(",
")",
";",
"$",
"model",
"->",
"$",
"attr",
"=",
"$",
"model",
"->",
"id",
";",
"$",
"model",
"->",
"save",
"(",
")",
";",
"}",
"$",
"this",
"->",
"resetOrder",
"(",
")",
";",
"}",
"$",
"apiModel",
"=",
"$",
"this",
"->",
"getById",
"(",
"$",
"model",
"->",
"id",
")",
";",
"$",
"this",
"->",
"afterStore",
"(",
"$",
"apiModel",
",",
"$",
"attributes",
")",
";",
"return",
"$",
"apiModel",
";",
"}"
] |
Store new model
@param array $attributes
@return Model
|
[
"Store",
"new",
"model"
] |
train
|
https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/Traits/FromModelTraitPart/StoreUpdateDeleteTrait.php#L47-L67
|
jan-dolata/crude-crud
|
src/Engine/Traits/FromModelTraitPart/StoreUpdateDeleteTrait.php
|
StoreUpdateDeleteTrait.updateById
|
public function updateById($id, $attributes)
{
$attributes = $this->formatUpdateAttributes($attributes);
$model = $this->model->find($id);
if (empty($model))
return $this;
$model->update($this->mapAttributesWithScope($attributes));
$apiModel = $this->getById($model->id);
$this->afterUpdate($apiModel, $attributes);
return $apiModel;
}
|
php
|
public function updateById($id, $attributes)
{
$attributes = $this->formatUpdateAttributes($attributes);
$model = $this->model->find($id);
if (empty($model))
return $this;
$model->update($this->mapAttributesWithScope($attributes));
$apiModel = $this->getById($model->id);
$this->afterUpdate($apiModel, $attributes);
return $apiModel;
}
|
[
"public",
"function",
"updateById",
"(",
"$",
"id",
",",
"$",
"attributes",
")",
"{",
"$",
"attributes",
"=",
"$",
"this",
"->",
"formatUpdateAttributes",
"(",
"$",
"attributes",
")",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"model",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"model",
")",
")",
"return",
"$",
"this",
";",
"$",
"model",
"->",
"update",
"(",
"$",
"this",
"->",
"mapAttributesWithScope",
"(",
"$",
"attributes",
")",
")",
";",
"$",
"apiModel",
"=",
"$",
"this",
"->",
"getById",
"(",
"$",
"model",
"->",
"id",
")",
";",
"$",
"this",
"->",
"afterUpdate",
"(",
"$",
"apiModel",
",",
"$",
"attributes",
")",
";",
"return",
"$",
"apiModel",
";",
"}"
] |
Update by id
@param integer $id
@param array $attributes
@return Model
|
[
"Update",
"by",
"id"
] |
train
|
https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/Traits/FromModelTraitPart/StoreUpdateDeleteTrait.php#L75-L89
|
jan-dolata/crude-crud
|
src/Engine/Traits/FromModelTraitPart/StoreUpdateDeleteTrait.php
|
StoreUpdateDeleteTrait.deleteById
|
public function deleteById($id)
{
$model = $this->getById($id);
if (empty($model))
return $this;
if ($this instanceof \JanDolata\CrudeCRUD\Engine\Interfaces\WithFileInterface) {
$fileAttrName = $this->fileAttrName;
$modelFiles = $model->$fileAttrName;
foreach ($modelFiles as $file)
$this->deleteFileByData($model->id, $file['file_log_id']);
}
$model->delete();
if ($this->canOrder())
$this->resetOrder();
return $this;
}
|
php
|
public function deleteById($id)
{
$model = $this->getById($id);
if (empty($model))
return $this;
if ($this instanceof \JanDolata\CrudeCRUD\Engine\Interfaces\WithFileInterface) {
$fileAttrName = $this->fileAttrName;
$modelFiles = $model->$fileAttrName;
foreach ($modelFiles as $file)
$this->deleteFileByData($model->id, $file['file_log_id']);
}
$model->delete();
if ($this->canOrder())
$this->resetOrder();
return $this;
}
|
[
"public",
"function",
"deleteById",
"(",
"$",
"id",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"getById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"model",
")",
")",
"return",
"$",
"this",
";",
"if",
"(",
"$",
"this",
"instanceof",
"\\",
"JanDolata",
"\\",
"CrudeCRUD",
"\\",
"Engine",
"\\",
"Interfaces",
"\\",
"WithFileInterface",
")",
"{",
"$",
"fileAttrName",
"=",
"$",
"this",
"->",
"fileAttrName",
";",
"$",
"modelFiles",
"=",
"$",
"model",
"->",
"$",
"fileAttrName",
";",
"foreach",
"(",
"$",
"modelFiles",
"as",
"$",
"file",
")",
"$",
"this",
"->",
"deleteFileByData",
"(",
"$",
"model",
"->",
"id",
",",
"$",
"file",
"[",
"'file_log_id'",
"]",
")",
";",
"}",
"$",
"model",
"->",
"delete",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"canOrder",
"(",
")",
")",
"$",
"this",
"->",
"resetOrder",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Delete by id
@param integer $id
@return self
|
[
"Delete",
"by",
"id"
] |
train
|
https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/Traits/FromModelTraitPart/StoreUpdateDeleteTrait.php#L124-L145
|
JoffreyPoreeCoding/MongoDB-ODM
|
src/Hydrator.php
|
Hydrator.hydrate
|
public function hydrate(&$object, $data, $soft = false, $maxReferenceDepth = 10)
{
$strategy = $this->documentManager->getOptions()['hydratorStrategy'] ?? self::STRAT_SETTERS;
$reflectionClass = new \ReflectionClass($this->classMetadata->getName());
if ($data instanceof \MongoDB\Model\BSONArray || $data instanceof \MongoDB\Model\BSONDocument) {
$data = (array) $data;
}
if (!is_array($data)) {
throw new \Exception('$data must be an array');
}
$properties = $this->classMetadata->getPropertiesInfos();
foreach ($properties as $name => $infos) {
$setter = 'set' . ucfirst($name);
if (!$reflectionClass->hasMethod($setter) || $strategy === self::STRAT_ATTRIBUTES) {
$prop = new \ReflectionProperty($this->classMetadata->getName(), $name);
$prop->setAccessible(true);
} else {
$prop = null;
}
if (null !== ($field = $infos->getField())) {
if (!$soft && !array_key_exists($field, $data)) {
$this->setValue($object, null, $setter, $prop);
} elseif (array_key_exists($field, $data)) {
if (!$soft && $data[$field] === null) {
continue;
}
if ((($data[$field] instanceof \MongoDB\Model\BSONDocument) || is_array($data[$field])) && $infos->getEmbedded() && null !== ($class = $infos->getEmbeddedClass())) {
if ($infos->isDiscriminable()) {
if (null !== ($discrimatorField = $infos->getDiscriminatorField())
&& null !== ($discrimatorMap = $infos->getDiscriminatorMap())) {
$discriminatorValue = isset($data[$field][$discrimatorField]) ? $data[$field][$discrimatorField] : null;
if (isset($discriminatorValue)) {
$class = isset($discrimatorMap[$discriminatorValue]) ? $discrimatorMap[$discriminatorValue] : $class;
}
} else {
$discriminatorValue = isset($data[$field]) ? $data[$field] : null;
$method = $infos->getDiscriminatorMethod();
$class = $object->$method($discriminatorValue);
}
}
if (!class_exists($class)) {
$class = $this->classMetadata->getNamespace() . "\\" . $class;
}
if ($data[$field] instanceof $class) {
$embedded = $data[$field];
} else {
$embedded = new $class();
$this->getHydrator($class)->hydrate($embedded, $data[$field]);
}
$data[$field] = $embedded;
} elseif ((($data[$field] instanceof \MongoDB\Model\BSONArray) || ($data[$field] instanceof \MongoDB\Model\BSONDocument) || is_array($data[$field])) && $infos->getMultiEmbedded() && null !== ($class = $infos->getEmbeddedClass())) {
$array = [];
$originalClass = $class;
foreach ($data[$field] as $key => $value) {
if ($infos->isDiscriminable()) {
if (null !== ($discrimatorField = $infos->getDiscriminatorField())
&& null !== ($discrimatorMap = $infos->getDiscriminatorMap())) {
$discriminatorValue = isset($data[$field][$key][$discrimatorField]) ? $data[$field][$key][$discrimatorField] : null;
if (isset($discriminatorValue)) {
$class = isset($discrimatorMap[$discriminatorValue]) ? $discrimatorMap[$discriminatorValue] : $originalClass;
}
if (!class_exists($class)) {
$class = $this->classMetadata->getNamespace() . "\\" . $class;
}
} else {
//call_s
}
}
if (!class_exists($class)) {
$class = $this->classMetadata->getNamespace() . "\\" . $originalClass;
}
if ($value === null) {
continue;
}
if ($value instanceof $class) {
$embedded = $value;
} else {
$embedded = new $class();
$this->getHydrator($class)->hydrate($embedded, $value);
}
$array[$key] = $embedded;
}
$data[$field] = $array;
} elseif (null !== ($refInfos = $infos->getReferenceInfo()) && !$refInfos->getIsMultiple() && $maxReferenceDepth > 0) {
$repository = $this->repositoryFactory->getRepository($this->documentManager, $refInfos->getDocument(), $refInfos->getCollection());
$objectDatas = $repository->getCollection()->findOne(["_id" => $data[$field]]);
$referedObject = null;
if (isset($objectDatas)) {
$class = $refInfos->getDocument();
if (!class_exists($class)) {
$class = $this->classMetadata->getNamespace() . "\\" . $class;
}
$referedObject = new $class();
$hydrator = $repository->getHydrator();
$hydrator->hydrate($referedObject, $objectDatas, $soft, $maxReferenceDepth - 1);
}
$data[$field] = $referedObject;
} elseif (null !== ($refInfos = $infos->getReferenceInfo()) && $refInfos->getIsMultiple()) {
$repository = $this->repositoryFactory->getRepository($this->documentManager, $refInfos->getDocument(), $refInfos->getCollection());
if (!$data[$field] instanceof \MongoDB\Model\BSONArray && !is_array($data[$field])) {
throw new \Exception("RefersMany value must be an array for document with '_id' : " . $data["_id"]);
} else {
$objectsDatas = $repository->getCollection()->find(["_id" => ['$in' => $data[$field]]]);
}
$objectArray = null;
if (!empty($objectsDatas)) {
$objectArray = [];
foreach ($objectsDatas as $objectDatas) {
$class = $refInfos->getDocument();
if (!class_exists($class)) {
$class = $this->classMetadata->getNamespace() . "\\" . $class;
}
$referedObject = new $class();
$hydrator = $repository->getHydrator();
$hydrator->hydrate($referedObject, $objectDatas, $soft, $maxReferenceDepth - 1);
$objectArray[] = $referedObject;
}
}
$data[$field] = $objectArray;
}
$this->setValue($object, $data[$field], $setter, $prop);
}
}
}
}
|
php
|
public function hydrate(&$object, $data, $soft = false, $maxReferenceDepth = 10)
{
$strategy = $this->documentManager->getOptions()['hydratorStrategy'] ?? self::STRAT_SETTERS;
$reflectionClass = new \ReflectionClass($this->classMetadata->getName());
if ($data instanceof \MongoDB\Model\BSONArray || $data instanceof \MongoDB\Model\BSONDocument) {
$data = (array) $data;
}
if (!is_array($data)) {
throw new \Exception('$data must be an array');
}
$properties = $this->classMetadata->getPropertiesInfos();
foreach ($properties as $name => $infos) {
$setter = 'set' . ucfirst($name);
if (!$reflectionClass->hasMethod($setter) || $strategy === self::STRAT_ATTRIBUTES) {
$prop = new \ReflectionProperty($this->classMetadata->getName(), $name);
$prop->setAccessible(true);
} else {
$prop = null;
}
if (null !== ($field = $infos->getField())) {
if (!$soft && !array_key_exists($field, $data)) {
$this->setValue($object, null, $setter, $prop);
} elseif (array_key_exists($field, $data)) {
if (!$soft && $data[$field] === null) {
continue;
}
if ((($data[$field] instanceof \MongoDB\Model\BSONDocument) || is_array($data[$field])) && $infos->getEmbedded() && null !== ($class = $infos->getEmbeddedClass())) {
if ($infos->isDiscriminable()) {
if (null !== ($discrimatorField = $infos->getDiscriminatorField())
&& null !== ($discrimatorMap = $infos->getDiscriminatorMap())) {
$discriminatorValue = isset($data[$field][$discrimatorField]) ? $data[$field][$discrimatorField] : null;
if (isset($discriminatorValue)) {
$class = isset($discrimatorMap[$discriminatorValue]) ? $discrimatorMap[$discriminatorValue] : $class;
}
} else {
$discriminatorValue = isset($data[$field]) ? $data[$field] : null;
$method = $infos->getDiscriminatorMethod();
$class = $object->$method($discriminatorValue);
}
}
if (!class_exists($class)) {
$class = $this->classMetadata->getNamespace() . "\\" . $class;
}
if ($data[$field] instanceof $class) {
$embedded = $data[$field];
} else {
$embedded = new $class();
$this->getHydrator($class)->hydrate($embedded, $data[$field]);
}
$data[$field] = $embedded;
} elseif ((($data[$field] instanceof \MongoDB\Model\BSONArray) || ($data[$field] instanceof \MongoDB\Model\BSONDocument) || is_array($data[$field])) && $infos->getMultiEmbedded() && null !== ($class = $infos->getEmbeddedClass())) {
$array = [];
$originalClass = $class;
foreach ($data[$field] as $key => $value) {
if ($infos->isDiscriminable()) {
if (null !== ($discrimatorField = $infos->getDiscriminatorField())
&& null !== ($discrimatorMap = $infos->getDiscriminatorMap())) {
$discriminatorValue = isset($data[$field][$key][$discrimatorField]) ? $data[$field][$key][$discrimatorField] : null;
if (isset($discriminatorValue)) {
$class = isset($discrimatorMap[$discriminatorValue]) ? $discrimatorMap[$discriminatorValue] : $originalClass;
}
if (!class_exists($class)) {
$class = $this->classMetadata->getNamespace() . "\\" . $class;
}
} else {
//call_s
}
}
if (!class_exists($class)) {
$class = $this->classMetadata->getNamespace() . "\\" . $originalClass;
}
if ($value === null) {
continue;
}
if ($value instanceof $class) {
$embedded = $value;
} else {
$embedded = new $class();
$this->getHydrator($class)->hydrate($embedded, $value);
}
$array[$key] = $embedded;
}
$data[$field] = $array;
} elseif (null !== ($refInfos = $infos->getReferenceInfo()) && !$refInfos->getIsMultiple() && $maxReferenceDepth > 0) {
$repository = $this->repositoryFactory->getRepository($this->documentManager, $refInfos->getDocument(), $refInfos->getCollection());
$objectDatas = $repository->getCollection()->findOne(["_id" => $data[$field]]);
$referedObject = null;
if (isset($objectDatas)) {
$class = $refInfos->getDocument();
if (!class_exists($class)) {
$class = $this->classMetadata->getNamespace() . "\\" . $class;
}
$referedObject = new $class();
$hydrator = $repository->getHydrator();
$hydrator->hydrate($referedObject, $objectDatas, $soft, $maxReferenceDepth - 1);
}
$data[$field] = $referedObject;
} elseif (null !== ($refInfos = $infos->getReferenceInfo()) && $refInfos->getIsMultiple()) {
$repository = $this->repositoryFactory->getRepository($this->documentManager, $refInfos->getDocument(), $refInfos->getCollection());
if (!$data[$field] instanceof \MongoDB\Model\BSONArray && !is_array($data[$field])) {
throw new \Exception("RefersMany value must be an array for document with '_id' : " . $data["_id"]);
} else {
$objectsDatas = $repository->getCollection()->find(["_id" => ['$in' => $data[$field]]]);
}
$objectArray = null;
if (!empty($objectsDatas)) {
$objectArray = [];
foreach ($objectsDatas as $objectDatas) {
$class = $refInfos->getDocument();
if (!class_exists($class)) {
$class = $this->classMetadata->getNamespace() . "\\" . $class;
}
$referedObject = new $class();
$hydrator = $repository->getHydrator();
$hydrator->hydrate($referedObject, $objectDatas, $soft, $maxReferenceDepth - 1);
$objectArray[] = $referedObject;
}
}
$data[$field] = $objectArray;
}
$this->setValue($object, $data[$field], $setter, $prop);
}
}
}
}
|
[
"public",
"function",
"hydrate",
"(",
"&",
"$",
"object",
",",
"$",
"data",
",",
"$",
"soft",
"=",
"false",
",",
"$",
"maxReferenceDepth",
"=",
"10",
")",
"{",
"$",
"strategy",
"=",
"$",
"this",
"->",
"documentManager",
"->",
"getOptions",
"(",
")",
"[",
"'hydratorStrategy'",
"]",
"??",
"self",
"::",
"STRAT_SETTERS",
";",
"$",
"reflectionClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"this",
"->",
"classMetadata",
"->",
"getName",
"(",
")",
")",
";",
"if",
"(",
"$",
"data",
"instanceof",
"\\",
"MongoDB",
"\\",
"Model",
"\\",
"BSONArray",
"||",
"$",
"data",
"instanceof",
"\\",
"MongoDB",
"\\",
"Model",
"\\",
"BSONDocument",
")",
"{",
"$",
"data",
"=",
"(",
"array",
")",
"$",
"data",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'$data must be an array'",
")",
";",
"}",
"$",
"properties",
"=",
"$",
"this",
"->",
"classMetadata",
"->",
"getPropertiesInfos",
"(",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"name",
"=>",
"$",
"infos",
")",
"{",
"$",
"setter",
"=",
"'set'",
".",
"ucfirst",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"$",
"reflectionClass",
"->",
"hasMethod",
"(",
"$",
"setter",
")",
"||",
"$",
"strategy",
"===",
"self",
"::",
"STRAT_ATTRIBUTES",
")",
"{",
"$",
"prop",
"=",
"new",
"\\",
"ReflectionProperty",
"(",
"$",
"this",
"->",
"classMetadata",
"->",
"getName",
"(",
")",
",",
"$",
"name",
")",
";",
"$",
"prop",
"->",
"setAccessible",
"(",
"true",
")",
";",
"}",
"else",
"{",
"$",
"prop",
"=",
"null",
";",
"}",
"if",
"(",
"null",
"!==",
"(",
"$",
"field",
"=",
"$",
"infos",
"->",
"getField",
"(",
")",
")",
")",
"{",
"if",
"(",
"!",
"$",
"soft",
"&&",
"!",
"array_key_exists",
"(",
"$",
"field",
",",
"$",
"data",
")",
")",
"{",
"$",
"this",
"->",
"setValue",
"(",
"$",
"object",
",",
"null",
",",
"$",
"setter",
",",
"$",
"prop",
")",
";",
"}",
"elseif",
"(",
"array_key_exists",
"(",
"$",
"field",
",",
"$",
"data",
")",
")",
"{",
"if",
"(",
"!",
"$",
"soft",
"&&",
"$",
"data",
"[",
"$",
"field",
"]",
"===",
"null",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"(",
"(",
"$",
"data",
"[",
"$",
"field",
"]",
"instanceof",
"\\",
"MongoDB",
"\\",
"Model",
"\\",
"BSONDocument",
")",
"||",
"is_array",
"(",
"$",
"data",
"[",
"$",
"field",
"]",
")",
")",
"&&",
"$",
"infos",
"->",
"getEmbedded",
"(",
")",
"&&",
"null",
"!==",
"(",
"$",
"class",
"=",
"$",
"infos",
"->",
"getEmbeddedClass",
"(",
")",
")",
")",
"{",
"if",
"(",
"$",
"infos",
"->",
"isDiscriminable",
"(",
")",
")",
"{",
"if",
"(",
"null",
"!==",
"(",
"$",
"discrimatorField",
"=",
"$",
"infos",
"->",
"getDiscriminatorField",
"(",
")",
")",
"&&",
"null",
"!==",
"(",
"$",
"discrimatorMap",
"=",
"$",
"infos",
"->",
"getDiscriminatorMap",
"(",
")",
")",
")",
"{",
"$",
"discriminatorValue",
"=",
"isset",
"(",
"$",
"data",
"[",
"$",
"field",
"]",
"[",
"$",
"discrimatorField",
"]",
")",
"?",
"$",
"data",
"[",
"$",
"field",
"]",
"[",
"$",
"discrimatorField",
"]",
":",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"discriminatorValue",
")",
")",
"{",
"$",
"class",
"=",
"isset",
"(",
"$",
"discrimatorMap",
"[",
"$",
"discriminatorValue",
"]",
")",
"?",
"$",
"discrimatorMap",
"[",
"$",
"discriminatorValue",
"]",
":",
"$",
"class",
";",
"}",
"}",
"else",
"{",
"$",
"discriminatorValue",
"=",
"isset",
"(",
"$",
"data",
"[",
"$",
"field",
"]",
")",
"?",
"$",
"data",
"[",
"$",
"field",
"]",
":",
"null",
";",
"$",
"method",
"=",
"$",
"infos",
"->",
"getDiscriminatorMethod",
"(",
")",
";",
"$",
"class",
"=",
"$",
"object",
"->",
"$",
"method",
"(",
"$",
"discriminatorValue",
")",
";",
"}",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"classMetadata",
"->",
"getNamespace",
"(",
")",
".",
"\"\\\\\"",
".",
"$",
"class",
";",
"}",
"if",
"(",
"$",
"data",
"[",
"$",
"field",
"]",
"instanceof",
"$",
"class",
")",
"{",
"$",
"embedded",
"=",
"$",
"data",
"[",
"$",
"field",
"]",
";",
"}",
"else",
"{",
"$",
"embedded",
"=",
"new",
"$",
"class",
"(",
")",
";",
"$",
"this",
"->",
"getHydrator",
"(",
"$",
"class",
")",
"->",
"hydrate",
"(",
"$",
"embedded",
",",
"$",
"data",
"[",
"$",
"field",
"]",
")",
";",
"}",
"$",
"data",
"[",
"$",
"field",
"]",
"=",
"$",
"embedded",
";",
"}",
"elseif",
"(",
"(",
"(",
"$",
"data",
"[",
"$",
"field",
"]",
"instanceof",
"\\",
"MongoDB",
"\\",
"Model",
"\\",
"BSONArray",
")",
"||",
"(",
"$",
"data",
"[",
"$",
"field",
"]",
"instanceof",
"\\",
"MongoDB",
"\\",
"Model",
"\\",
"BSONDocument",
")",
"||",
"is_array",
"(",
"$",
"data",
"[",
"$",
"field",
"]",
")",
")",
"&&",
"$",
"infos",
"->",
"getMultiEmbedded",
"(",
")",
"&&",
"null",
"!==",
"(",
"$",
"class",
"=",
"$",
"infos",
"->",
"getEmbeddedClass",
"(",
")",
")",
")",
"{",
"$",
"array",
"=",
"[",
"]",
";",
"$",
"originalClass",
"=",
"$",
"class",
";",
"foreach",
"(",
"$",
"data",
"[",
"$",
"field",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"infos",
"->",
"isDiscriminable",
"(",
")",
")",
"{",
"if",
"(",
"null",
"!==",
"(",
"$",
"discrimatorField",
"=",
"$",
"infos",
"->",
"getDiscriminatorField",
"(",
")",
")",
"&&",
"null",
"!==",
"(",
"$",
"discrimatorMap",
"=",
"$",
"infos",
"->",
"getDiscriminatorMap",
"(",
")",
")",
")",
"{",
"$",
"discriminatorValue",
"=",
"isset",
"(",
"$",
"data",
"[",
"$",
"field",
"]",
"[",
"$",
"key",
"]",
"[",
"$",
"discrimatorField",
"]",
")",
"?",
"$",
"data",
"[",
"$",
"field",
"]",
"[",
"$",
"key",
"]",
"[",
"$",
"discrimatorField",
"]",
":",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"discriminatorValue",
")",
")",
"{",
"$",
"class",
"=",
"isset",
"(",
"$",
"discrimatorMap",
"[",
"$",
"discriminatorValue",
"]",
")",
"?",
"$",
"discrimatorMap",
"[",
"$",
"discriminatorValue",
"]",
":",
"$",
"originalClass",
";",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"classMetadata",
"->",
"getNamespace",
"(",
")",
".",
"\"\\\\\"",
".",
"$",
"class",
";",
"}",
"}",
"else",
"{",
"//call_s",
"}",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"classMetadata",
"->",
"getNamespace",
"(",
")",
".",
"\"\\\\\"",
".",
"$",
"originalClass",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"$",
"class",
")",
"{",
"$",
"embedded",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"embedded",
"=",
"new",
"$",
"class",
"(",
")",
";",
"$",
"this",
"->",
"getHydrator",
"(",
"$",
"class",
")",
"->",
"hydrate",
"(",
"$",
"embedded",
",",
"$",
"value",
")",
";",
"}",
"$",
"array",
"[",
"$",
"key",
"]",
"=",
"$",
"embedded",
";",
"}",
"$",
"data",
"[",
"$",
"field",
"]",
"=",
"$",
"array",
";",
"}",
"elseif",
"(",
"null",
"!==",
"(",
"$",
"refInfos",
"=",
"$",
"infos",
"->",
"getReferenceInfo",
"(",
")",
")",
"&&",
"!",
"$",
"refInfos",
"->",
"getIsMultiple",
"(",
")",
"&&",
"$",
"maxReferenceDepth",
">",
"0",
")",
"{",
"$",
"repository",
"=",
"$",
"this",
"->",
"repositoryFactory",
"->",
"getRepository",
"(",
"$",
"this",
"->",
"documentManager",
",",
"$",
"refInfos",
"->",
"getDocument",
"(",
")",
",",
"$",
"refInfos",
"->",
"getCollection",
"(",
")",
")",
";",
"$",
"objectDatas",
"=",
"$",
"repository",
"->",
"getCollection",
"(",
")",
"->",
"findOne",
"(",
"[",
"\"_id\"",
"=>",
"$",
"data",
"[",
"$",
"field",
"]",
"]",
")",
";",
"$",
"referedObject",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"objectDatas",
")",
")",
"{",
"$",
"class",
"=",
"$",
"refInfos",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"classMetadata",
"->",
"getNamespace",
"(",
")",
".",
"\"\\\\\"",
".",
"$",
"class",
";",
"}",
"$",
"referedObject",
"=",
"new",
"$",
"class",
"(",
")",
";",
"$",
"hydrator",
"=",
"$",
"repository",
"->",
"getHydrator",
"(",
")",
";",
"$",
"hydrator",
"->",
"hydrate",
"(",
"$",
"referedObject",
",",
"$",
"objectDatas",
",",
"$",
"soft",
",",
"$",
"maxReferenceDepth",
"-",
"1",
")",
";",
"}",
"$",
"data",
"[",
"$",
"field",
"]",
"=",
"$",
"referedObject",
";",
"}",
"elseif",
"(",
"null",
"!==",
"(",
"$",
"refInfos",
"=",
"$",
"infos",
"->",
"getReferenceInfo",
"(",
")",
")",
"&&",
"$",
"refInfos",
"->",
"getIsMultiple",
"(",
")",
")",
"{",
"$",
"repository",
"=",
"$",
"this",
"->",
"repositoryFactory",
"->",
"getRepository",
"(",
"$",
"this",
"->",
"documentManager",
",",
"$",
"refInfos",
"->",
"getDocument",
"(",
")",
",",
"$",
"refInfos",
"->",
"getCollection",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"data",
"[",
"$",
"field",
"]",
"instanceof",
"\\",
"MongoDB",
"\\",
"Model",
"\\",
"BSONArray",
"&&",
"!",
"is_array",
"(",
"$",
"data",
"[",
"$",
"field",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"RefersMany value must be an array for document with '_id' : \"",
".",
"$",
"data",
"[",
"\"_id\"",
"]",
")",
";",
"}",
"else",
"{",
"$",
"objectsDatas",
"=",
"$",
"repository",
"->",
"getCollection",
"(",
")",
"->",
"find",
"(",
"[",
"\"_id\"",
"=>",
"[",
"'$in'",
"=>",
"$",
"data",
"[",
"$",
"field",
"]",
"]",
"]",
")",
";",
"}",
"$",
"objectArray",
"=",
"null",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"objectsDatas",
")",
")",
"{",
"$",
"objectArray",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"objectsDatas",
"as",
"$",
"objectDatas",
")",
"{",
"$",
"class",
"=",
"$",
"refInfos",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"classMetadata",
"->",
"getNamespace",
"(",
")",
".",
"\"\\\\\"",
".",
"$",
"class",
";",
"}",
"$",
"referedObject",
"=",
"new",
"$",
"class",
"(",
")",
";",
"$",
"hydrator",
"=",
"$",
"repository",
"->",
"getHydrator",
"(",
")",
";",
"$",
"hydrator",
"->",
"hydrate",
"(",
"$",
"referedObject",
",",
"$",
"objectDatas",
",",
"$",
"soft",
",",
"$",
"maxReferenceDepth",
"-",
"1",
")",
";",
"$",
"objectArray",
"[",
"]",
"=",
"$",
"referedObject",
";",
"}",
"}",
"$",
"data",
"[",
"$",
"field",
"]",
"=",
"$",
"objectArray",
";",
"}",
"$",
"this",
"->",
"setValue",
"(",
"$",
"object",
",",
"$",
"data",
"[",
"$",
"field",
"]",
",",
"$",
"setter",
",",
"$",
"prop",
")",
";",
"}",
"}",
"}",
"}"
] |
Hydrate an object
@param mixed $object Object to hydrate
@param array $data Data wich will hydrate object
@param integer $maxReferenceDepth Max reference depth
@return void
|
[
"Hydrate",
"an",
"object"
] |
train
|
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Hydrator.php#L67-L208
|
JoffreyPoreeCoding/MongoDB-ODM
|
src/Hydrator.php
|
Hydrator.unhydrate
|
public function unhydrate($object)
{
$properties = $this->classMetadata->getPropertiesInfos();
$datas = [];
if (!is_object($object)) {
return $object;
}
foreach ($properties as $name => $infos) {
$prop = new \ReflectionProperty($this->classMetadata->getName(), $name);
$prop->setAccessible(true);
$value = $prop->getValue($object);
if (null === $value) {
continue;
}
if (($value instanceof \MongoDB\Model\BSONDocument) || ($value instanceof \MongoDB\Model\BSONArray)) {
$value = $this->recursiveConvertInArray((array) $value);
}
if (is_object($value) && $infos->getEmbedded()) {
$class = get_class($value);
if (!class_exists($class)) {
$class = $this->classMetadata->getNamespace() . "\\" . $class;
}
$value = $this->getHydrator($class)->unhydrate($value);
}
if (is_array($value) && $infos->getMultiEmbedded()) {
$array = [];
foreach ($value as $key => $embeddedValue) {
$class = $infos->getEmbeddedClass();
if (is_object($embeddedValue) && false !== ($realClass = get_class($embeddedValue))) {
$class = $realClass;
}
if (!class_exists($class)) {
$class = $this->classMetadata->getNamespace() . "\\" . $class;
}
$array[$key] = $this->getHydrator($class)->unhydrate($embeddedValue);
}
$value = $array;
}
if (is_object($value) && null != ($refInfos = $infos->getReferenceInfo()) && !$refInfos->getIsMultiple() && !$value instanceof \MongoDB\BSON\ObjectId) {
$class = $refInfos->getDocument();
if (!class_exists($class)) {
$class = $this->classMetadata->getNamespace() . "\\" . $class;
}
$value = $this->getHydrator($class)->unhydrate($value)["_id"];
}
if (is_array($value) && null != ($refInfos = $infos->getReferenceInfo()) && $refInfos->getIsMultiple()) {
$array = [];
foreach ($value as $referedValue) {
$class = $refInfos->getDocument();
if (!class_exists($class)) {
$class = $this->classMetadata->getNamespace() . "\\" . $class;
}
if (!$value instanceof \MongoDB\BSON\ObjectId) {
$array[] = $this->getHydrator($class)->unhydrate($referedValue)["_id"];
} else {
$array[] = $value;
}
}
$value = $array;
}
if ($value instanceof \DateTime) {
$value = new \MongoDB\BSON\UTCDateTime($value->getTimestamp() * 1000);
}
$datas[$infos->getField()] = $value;
}
return $datas;
}
|
php
|
public function unhydrate($object)
{
$properties = $this->classMetadata->getPropertiesInfos();
$datas = [];
if (!is_object($object)) {
return $object;
}
foreach ($properties as $name => $infos) {
$prop = new \ReflectionProperty($this->classMetadata->getName(), $name);
$prop->setAccessible(true);
$value = $prop->getValue($object);
if (null === $value) {
continue;
}
if (($value instanceof \MongoDB\Model\BSONDocument) || ($value instanceof \MongoDB\Model\BSONArray)) {
$value = $this->recursiveConvertInArray((array) $value);
}
if (is_object($value) && $infos->getEmbedded()) {
$class = get_class($value);
if (!class_exists($class)) {
$class = $this->classMetadata->getNamespace() . "\\" . $class;
}
$value = $this->getHydrator($class)->unhydrate($value);
}
if (is_array($value) && $infos->getMultiEmbedded()) {
$array = [];
foreach ($value as $key => $embeddedValue) {
$class = $infos->getEmbeddedClass();
if (is_object($embeddedValue) && false !== ($realClass = get_class($embeddedValue))) {
$class = $realClass;
}
if (!class_exists($class)) {
$class = $this->classMetadata->getNamespace() . "\\" . $class;
}
$array[$key] = $this->getHydrator($class)->unhydrate($embeddedValue);
}
$value = $array;
}
if (is_object($value) && null != ($refInfos = $infos->getReferenceInfo()) && !$refInfos->getIsMultiple() && !$value instanceof \MongoDB\BSON\ObjectId) {
$class = $refInfos->getDocument();
if (!class_exists($class)) {
$class = $this->classMetadata->getNamespace() . "\\" . $class;
}
$value = $this->getHydrator($class)->unhydrate($value)["_id"];
}
if (is_array($value) && null != ($refInfos = $infos->getReferenceInfo()) && $refInfos->getIsMultiple()) {
$array = [];
foreach ($value as $referedValue) {
$class = $refInfos->getDocument();
if (!class_exists($class)) {
$class = $this->classMetadata->getNamespace() . "\\" . $class;
}
if (!$value instanceof \MongoDB\BSON\ObjectId) {
$array[] = $this->getHydrator($class)->unhydrate($referedValue)["_id"];
} else {
$array[] = $value;
}
}
$value = $array;
}
if ($value instanceof \DateTime) {
$value = new \MongoDB\BSON\UTCDateTime($value->getTimestamp() * 1000);
}
$datas[$infos->getField()] = $value;
}
return $datas;
}
|
[
"public",
"function",
"unhydrate",
"(",
"$",
"object",
")",
"{",
"$",
"properties",
"=",
"$",
"this",
"->",
"classMetadata",
"->",
"getPropertiesInfos",
"(",
")",
";",
"$",
"datas",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"object",
")",
")",
"{",
"return",
"$",
"object",
";",
"}",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"name",
"=>",
"$",
"infos",
")",
"{",
"$",
"prop",
"=",
"new",
"\\",
"ReflectionProperty",
"(",
"$",
"this",
"->",
"classMetadata",
"->",
"getName",
"(",
")",
",",
"$",
"name",
")",
";",
"$",
"prop",
"->",
"setAccessible",
"(",
"true",
")",
";",
"$",
"value",
"=",
"$",
"prop",
"->",
"getValue",
"(",
"$",
"object",
")",
";",
"if",
"(",
"null",
"===",
"$",
"value",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"(",
"$",
"value",
"instanceof",
"\\",
"MongoDB",
"\\",
"Model",
"\\",
"BSONDocument",
")",
"||",
"(",
"$",
"value",
"instanceof",
"\\",
"MongoDB",
"\\",
"Model",
"\\",
"BSONArray",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"recursiveConvertInArray",
"(",
"(",
"array",
")",
"$",
"value",
")",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"$",
"infos",
"->",
"getEmbedded",
"(",
")",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"value",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"classMetadata",
"->",
"getNamespace",
"(",
")",
".",
"\"\\\\\"",
".",
"$",
"class",
";",
"}",
"$",
"value",
"=",
"$",
"this",
"->",
"getHydrator",
"(",
"$",
"class",
")",
"->",
"unhydrate",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"$",
"infos",
"->",
"getMultiEmbedded",
"(",
")",
")",
"{",
"$",
"array",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"key",
"=>",
"$",
"embeddedValue",
")",
"{",
"$",
"class",
"=",
"$",
"infos",
"->",
"getEmbeddedClass",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"embeddedValue",
")",
"&&",
"false",
"!==",
"(",
"$",
"realClass",
"=",
"get_class",
"(",
"$",
"embeddedValue",
")",
")",
")",
"{",
"$",
"class",
"=",
"$",
"realClass",
";",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"classMetadata",
"->",
"getNamespace",
"(",
")",
".",
"\"\\\\\"",
".",
"$",
"class",
";",
"}",
"$",
"array",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"getHydrator",
"(",
"$",
"class",
")",
"->",
"unhydrate",
"(",
"$",
"embeddedValue",
")",
";",
"}",
"$",
"value",
"=",
"$",
"array",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"null",
"!=",
"(",
"$",
"refInfos",
"=",
"$",
"infos",
"->",
"getReferenceInfo",
"(",
")",
")",
"&&",
"!",
"$",
"refInfos",
"->",
"getIsMultiple",
"(",
")",
"&&",
"!",
"$",
"value",
"instanceof",
"\\",
"MongoDB",
"\\",
"BSON",
"\\",
"ObjectId",
")",
"{",
"$",
"class",
"=",
"$",
"refInfos",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"classMetadata",
"->",
"getNamespace",
"(",
")",
".",
"\"\\\\\"",
".",
"$",
"class",
";",
"}",
"$",
"value",
"=",
"$",
"this",
"->",
"getHydrator",
"(",
"$",
"class",
")",
"->",
"unhydrate",
"(",
"$",
"value",
")",
"[",
"\"_id\"",
"]",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"null",
"!=",
"(",
"$",
"refInfos",
"=",
"$",
"infos",
"->",
"getReferenceInfo",
"(",
")",
")",
"&&",
"$",
"refInfos",
"->",
"getIsMultiple",
"(",
")",
")",
"{",
"$",
"array",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"referedValue",
")",
"{",
"$",
"class",
"=",
"$",
"refInfos",
"->",
"getDocument",
"(",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"classMetadata",
"->",
"getNamespace",
"(",
")",
".",
"\"\\\\\"",
".",
"$",
"class",
";",
"}",
"if",
"(",
"!",
"$",
"value",
"instanceof",
"\\",
"MongoDB",
"\\",
"BSON",
"\\",
"ObjectId",
")",
"{",
"$",
"array",
"[",
"]",
"=",
"$",
"this",
"->",
"getHydrator",
"(",
"$",
"class",
")",
"->",
"unhydrate",
"(",
"$",
"referedValue",
")",
"[",
"\"_id\"",
"]",
";",
"}",
"else",
"{",
"$",
"array",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"$",
"value",
"=",
"$",
"array",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"DateTime",
")",
"{",
"$",
"value",
"=",
"new",
"\\",
"MongoDB",
"\\",
"BSON",
"\\",
"UTCDateTime",
"(",
"$",
"value",
"->",
"getTimestamp",
"(",
")",
"*",
"1000",
")",
";",
"}",
"$",
"datas",
"[",
"$",
"infos",
"->",
"getField",
"(",
")",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"datas",
";",
"}"
] |
Unhydrate an object
@param object $object Object to unhydrate
@return array Unhydrated Object
|
[
"Unhydrate",
"an",
"object"
] |
train
|
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Hydrator.php#L216-L294
|
JoffreyPoreeCoding/MongoDB-ODM
|
src/Hydrator.php
|
Hydrator.recursiveConvertInArray
|
public function recursiveConvertInArray($array)
{
$newArray = [];
foreach ($array as $key => $value) {
if ($value instanceof \MongoDB\Model\BSONDocument || $value instanceof \MongoDB\Model\BSONArray) {
$value = (array) $value;
}
if (is_array($value)) {
$value = $this->recursiveConvertInArray($value);
}
$newArray[$key] = $value;
}
return $newArray;
}
|
php
|
public function recursiveConvertInArray($array)
{
$newArray = [];
foreach ($array as $key => $value) {
if ($value instanceof \MongoDB\Model\BSONDocument || $value instanceof \MongoDB\Model\BSONArray) {
$value = (array) $value;
}
if (is_array($value)) {
$value = $this->recursiveConvertInArray($value);
}
$newArray[$key] = $value;
}
return $newArray;
}
|
[
"public",
"function",
"recursiveConvertInArray",
"(",
"$",
"array",
")",
"{",
"$",
"newArray",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"MongoDB",
"\\",
"Model",
"\\",
"BSONDocument",
"||",
"$",
"value",
"instanceof",
"\\",
"MongoDB",
"\\",
"Model",
"\\",
"BSONArray",
")",
"{",
"$",
"value",
"=",
"(",
"array",
")",
"$",
"value",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"recursiveConvertInArray",
"(",
"$",
"value",
")",
";",
"}",
"$",
"newArray",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"newArray",
";",
"}"
] |
Convert BSONDocument and BSONArray to array recursively
@param array $array Array to convert
@return array
|
[
"Convert",
"BSONDocument",
"and",
"BSONArray",
"to",
"array",
"recursively"
] |
train
|
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Hydrator.php#L302-L318
|
JoffreyPoreeCoding/MongoDB-ODM
|
src/Hydrator.php
|
Hydrator.getHydrator
|
public function getHydrator($class)
{
$metadata = $this->classMetadataFactory->getMetadataForClass($class);
return new Hydrator($this->classMetadataFactory, $metadata, $this->documentManager, $this->repositoryFactory);
}
|
php
|
public function getHydrator($class)
{
$metadata = $this->classMetadataFactory->getMetadataForClass($class);
return new Hydrator($this->classMetadataFactory, $metadata, $this->documentManager, $this->repositoryFactory);
}
|
[
"public",
"function",
"getHydrator",
"(",
"$",
"class",
")",
"{",
"$",
"metadata",
"=",
"$",
"this",
"->",
"classMetadataFactory",
"->",
"getMetadataForClass",
"(",
"$",
"class",
")",
";",
"return",
"new",
"Hydrator",
"(",
"$",
"this",
"->",
"classMetadataFactory",
",",
"$",
"metadata",
",",
"$",
"this",
"->",
"documentManager",
",",
"$",
"this",
"->",
"repositoryFactory",
")",
";",
"}"
] |
Get hydrator for specified class
@param string $class Class which you will get hydrator
@return Hydrator Hydrator corresponding to specified class
|
[
"Get",
"hydrator",
"for",
"specified",
"class"
] |
train
|
https://github.com/JoffreyPoreeCoding/MongoDB-ODM/blob/56fd7ab28c22f276573a89d56bb93c8d74ad7f74/src/Hydrator.php#L326-L330
|
movoin/one-swoole
|
src/Protocol/Message/Uri.php
|
Uri.withScheme
|
public function withScheme($scheme): UriInterface
{
$scheme = $this->filterScheme($scheme);
$clone = clone $this;
$clone->scheme = $scheme;
return $clone;
}
|
php
|
public function withScheme($scheme): UriInterface
{
$scheme = $this->filterScheme($scheme);
$clone = clone $this;
$clone->scheme = $scheme;
return $clone;
}
|
[
"public",
"function",
"withScheme",
"(",
"$",
"scheme",
")",
":",
"UriInterface",
"{",
"$",
"scheme",
"=",
"$",
"this",
"->",
"filterScheme",
"(",
"$",
"scheme",
")",
";",
"$",
"clone",
"=",
"clone",
"$",
"this",
";",
"$",
"clone",
"->",
"scheme",
"=",
"$",
"scheme",
";",
"return",
"$",
"clone",
";",
"}"
] |
获得指定 Uri 协议的 Uri 对象
@param string $scheme
@return self
@throws \InvalidArgumentException
|
[
"获得指定",
"Uri",
"协议的",
"Uri",
"对象"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Message/Uri.php#L121-L129
|
movoin/one-swoole
|
src/Protocol/Message/Uri.php
|
Uri.withUserInfo
|
public function withUserInfo($user, $password = null): UriInterface
{
if (! is_string($user)) {
throw new InvalidArgumentException('Uri user must be a string');
}
$clone = clone $this;
$clone->user = $this->filterUserInfo($user);
if ($clone->user) {
$clone->password = $password ? $this->filterUserInfo($password) : '';
} else {
$clone->password = '';
}
return $clone;
}
|
php
|
public function withUserInfo($user, $password = null): UriInterface
{
if (! is_string($user)) {
throw new InvalidArgumentException('Uri user must be a string');
}
$clone = clone $this;
$clone->user = $this->filterUserInfo($user);
if ($clone->user) {
$clone->password = $password ? $this->filterUserInfo($password) : '';
} else {
$clone->password = '';
}
return $clone;
}
|
[
"public",
"function",
"withUserInfo",
"(",
"$",
"user",
",",
"$",
"password",
"=",
"null",
")",
":",
"UriInterface",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"user",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Uri user must be a string'",
")",
";",
"}",
"$",
"clone",
"=",
"clone",
"$",
"this",
";",
"$",
"clone",
"->",
"user",
"=",
"$",
"this",
"->",
"filterUserInfo",
"(",
"$",
"user",
")",
";",
"if",
"(",
"$",
"clone",
"->",
"user",
")",
"{",
"$",
"clone",
"->",
"password",
"=",
"$",
"password",
"?",
"$",
"this",
"->",
"filterUserInfo",
"(",
"$",
"password",
")",
":",
"''",
";",
"}",
"else",
"{",
"$",
"clone",
"->",
"password",
"=",
"''",
";",
"}",
"return",
"$",
"clone",
";",
"}"
] |
获得指定用户信息的 Uri 对象
@param string $user
@param null|string $password
@return self
@throws \InvalidArgumentException
|
[
"获得指定用户信息的",
"Uri",
"对象"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Message/Uri.php#L164-L180
|
movoin/one-swoole
|
src/Protocol/Message/Uri.php
|
Uri.withPort
|
public function withPort($port): UriInterface
{
$port = $this->filterPort($port);
$clone = clone $this;
$clone->port = $port;
return $clone;
}
|
php
|
public function withPort($port): UriInterface
{
$port = $this->filterPort($port);
$clone = clone $this;
$clone->port = $port;
return $clone;
}
|
[
"public",
"function",
"withPort",
"(",
"$",
"port",
")",
":",
"UriInterface",
"{",
"$",
"port",
"=",
"$",
"this",
"->",
"filterPort",
"(",
"$",
"port",
")",
";",
"$",
"clone",
"=",
"clone",
"$",
"this",
";",
"$",
"clone",
"->",
"port",
"=",
"$",
"port",
";",
"return",
"$",
"clone",
";",
"}"
] |
获得指定端口的 Uri 对象
@param null|int $port
@return self
@throws \InvalidArgumentException
|
[
"获得指定端口的",
"Uri",
"对象"
] |
train
|
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Protocol/Message/Uri.php#L230-L238
|
stubbles/stubbles-webapp-core
|
src/main/php/response/mimetypes/TextPlain.php
|
TextPlain.serialize
|
public function serialize($resource, OutputStream $out): OutputStream
{
if (is_object($resource) && method_exists($resource, '__toString')) {
$out->write((string) $resource);
} elseif (is_object($resource) || is_array($resource)) {
$out->write(var_export($resource, true));
} elseif (is_bool($resource) && $resource) {
$out->write('true');
} elseif (is_bool($resource) && !$resource) {
$out->write('false');
} else {
$out->write((string) $resource);
}
return $out;
}
|
php
|
public function serialize($resource, OutputStream $out): OutputStream
{
if (is_object($resource) && method_exists($resource, '__toString')) {
$out->write((string) $resource);
} elseif (is_object($resource) || is_array($resource)) {
$out->write(var_export($resource, true));
} elseif (is_bool($resource) && $resource) {
$out->write('true');
} elseif (is_bool($resource) && !$resource) {
$out->write('false');
} else {
$out->write((string) $resource);
}
return $out;
}
|
[
"public",
"function",
"serialize",
"(",
"$",
"resource",
",",
"OutputStream",
"$",
"out",
")",
":",
"OutputStream",
"{",
"if",
"(",
"is_object",
"(",
"$",
"resource",
")",
"&&",
"method_exists",
"(",
"$",
"resource",
",",
"'__toString'",
")",
")",
"{",
"$",
"out",
"->",
"write",
"(",
"(",
"string",
")",
"$",
"resource",
")",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"resource",
")",
"||",
"is_array",
"(",
"$",
"resource",
")",
")",
"{",
"$",
"out",
"->",
"write",
"(",
"var_export",
"(",
"$",
"resource",
",",
"true",
")",
")",
";",
"}",
"elseif",
"(",
"is_bool",
"(",
"$",
"resource",
")",
"&&",
"$",
"resource",
")",
"{",
"$",
"out",
"->",
"write",
"(",
"'true'",
")",
";",
"}",
"elseif",
"(",
"is_bool",
"(",
"$",
"resource",
")",
"&&",
"!",
"$",
"resource",
")",
"{",
"$",
"out",
"->",
"write",
"(",
"'false'",
")",
";",
"}",
"else",
"{",
"$",
"out",
"->",
"write",
"(",
"(",
"string",
")",
"$",
"resource",
")",
";",
"}",
"return",
"$",
"out",
";",
"}"
] |
serializes resource to output stream
@param mixed $resource
@param \stubbles\streams\OutputStream $out
@return \stubbles\streams\OutputStream
|
[
"serializes",
"resource",
"to",
"output",
"stream"
] |
train
|
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/response/mimetypes/TextPlain.php#L37-L52
|
WebDevTmas/date-repetition
|
src/DateRepetition/DateRepetitionCalculator.php
|
DateRepetitionCalculator.getNextOccurence
|
public function getNextOccurence(DateRepetition $dateRepetition, DateTime $datetime = null)
{
if(null === $datetime) {
$datetime = $this->timeProvider->now();
}
switch(true) {
case $dateRepetition instanceof WeeklyDateRepetition:
return $this->getNextOccurenceForWeeklyDateRepetition($dateRepetition, $datetime);
case $dateRepetition instanceof DailyDateRepetition:
return $this->getNextOccurenceForDailyDateRepetition($dateRepetition, $datetime);
case $dateRepetition instanceof HourlyDateRepetition:
return $this->getNextOccurenceForHourlyDateRepetition($dateRepetition, $datetime);
}
return new \Exception('Not yet implemented');
}
|
php
|
public function getNextOccurence(DateRepetition $dateRepetition, DateTime $datetime = null)
{
if(null === $datetime) {
$datetime = $this->timeProvider->now();
}
switch(true) {
case $dateRepetition instanceof WeeklyDateRepetition:
return $this->getNextOccurenceForWeeklyDateRepetition($dateRepetition, $datetime);
case $dateRepetition instanceof DailyDateRepetition:
return $this->getNextOccurenceForDailyDateRepetition($dateRepetition, $datetime);
case $dateRepetition instanceof HourlyDateRepetition:
return $this->getNextOccurenceForHourlyDateRepetition($dateRepetition, $datetime);
}
return new \Exception('Not yet implemented');
}
|
[
"public",
"function",
"getNextOccurence",
"(",
"DateRepetition",
"$",
"dateRepetition",
",",
"DateTime",
"$",
"datetime",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"datetime",
")",
"{",
"$",
"datetime",
"=",
"$",
"this",
"->",
"timeProvider",
"->",
"now",
"(",
")",
";",
"}",
"switch",
"(",
"true",
")",
"{",
"case",
"$",
"dateRepetition",
"instanceof",
"WeeklyDateRepetition",
":",
"return",
"$",
"this",
"->",
"getNextOccurenceForWeeklyDateRepetition",
"(",
"$",
"dateRepetition",
",",
"$",
"datetime",
")",
";",
"case",
"$",
"dateRepetition",
"instanceof",
"DailyDateRepetition",
":",
"return",
"$",
"this",
"->",
"getNextOccurenceForDailyDateRepetition",
"(",
"$",
"dateRepetition",
",",
"$",
"datetime",
")",
";",
"case",
"$",
"dateRepetition",
"instanceof",
"HourlyDateRepetition",
":",
"return",
"$",
"this",
"->",
"getNextOccurenceForHourlyDateRepetition",
"(",
"$",
"dateRepetition",
",",
"$",
"datetime",
")",
";",
"}",
"return",
"new",
"\\",
"Exception",
"(",
"'Not yet implemented'",
")",
";",
"}"
] |
Find next occurence of date repetition
@param DateRepetition
@param DateTime next occurence from this date (null == now)
@return DateTime date/time of next occurence
|
[
"Find",
"next",
"occurence",
"of",
"date",
"repetition"
] |
train
|
https://github.com/WebDevTmas/date-repetition/blob/3ebd59f4ab3aab4b7497ebd767a57fad08277c6d/src/DateRepetition/DateRepetitionCalculator.php#L33-L49
|
miquido/data-structure
|
src/Map/MapCollection.php
|
MapCollection.find
|
public function find(callable $callback): MapInterface
{
foreach ($this->data as $item) {
$result = $callback($item);
Assert::boolean($result, \sprintf('Callback should return a boolean, but %s was returned', \gettype($result)));
if ($result) {
return $item;
}
}
throw new ItemNotFoundException('No item found.');
}
|
php
|
public function find(callable $callback): MapInterface
{
foreach ($this->data as $item) {
$result = $callback($item);
Assert::boolean($result, \sprintf('Callback should return a boolean, but %s was returned', \gettype($result)));
if ($result) {
return $item;
}
}
throw new ItemNotFoundException('No item found.');
}
|
[
"public",
"function",
"find",
"(",
"callable",
"$",
"callback",
")",
":",
"MapInterface",
"{",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"item",
")",
"{",
"$",
"result",
"=",
"$",
"callback",
"(",
"$",
"item",
")",
";",
"Assert",
"::",
"boolean",
"(",
"$",
"result",
",",
"\\",
"sprintf",
"(",
"'Callback should return a boolean, but %s was returned'",
",",
"\\",
"gettype",
"(",
"$",
"result",
")",
")",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"return",
"$",
"item",
";",
"}",
"}",
"throw",
"new",
"ItemNotFoundException",
"(",
"'No item found.'",
")",
";",
"}"
] |
@param callable $callback
@throws ItemNotFoundException
@return MapInterface
|
[
"@param",
"callable",
"$callback"
] |
train
|
https://github.com/miquido/data-structure/blob/54352ff1927dc5f09aad4dd0b3365c43358cb60d/src/Map/MapCollection.php#L60-L72
|
miquido/data-structure
|
src/Map/MapCollection.php
|
MapCollection.findByKeyAndValue
|
public function findByKeyAndValue(string $key, $value): MapInterface
{
return $this->find(function (MapInterface $item) use ($key, $value): bool {
return $item->get($key) === $value;
});
}
|
php
|
public function findByKeyAndValue(string $key, $value): MapInterface
{
return $this->find(function (MapInterface $item) use ($key, $value): bool {
return $item->get($key) === $value;
});
}
|
[
"public",
"function",
"findByKeyAndValue",
"(",
"string",
"$",
"key",
",",
"$",
"value",
")",
":",
"MapInterface",
"{",
"return",
"$",
"this",
"->",
"find",
"(",
"function",
"(",
"MapInterface",
"$",
"item",
")",
"use",
"(",
"$",
"key",
",",
"$",
"value",
")",
":",
"bool",
"{",
"return",
"$",
"item",
"->",
"get",
"(",
"$",
"key",
")",
"===",
"$",
"value",
";",
"}",
")",
";",
"}"
] |
@param string $key
@param mixed $value
@throws ItemNotFoundException
@return MapInterface
|
[
"@param",
"string",
"$key",
"@param",
"mixed",
"$value"
] |
train
|
https://github.com/miquido/data-structure/blob/54352ff1927dc5f09aad4dd0b3365c43358cb60d/src/Map/MapCollection.php#L82-L87
|
tonicospinelli/class-generation
|
src/ClassGeneration/MethodCollection.php
|
MethodCollection.add
|
public function add($method)
{
if (!$method instanceof MethodInterface) {
throw new \InvalidArgumentException('This Method must be a instance of \ClassGeneration\MethodInterface');
}
if ($method->getName() === null) {
$method->setName('method' . ($this->count() + 1));
}
parent::set($method->getName(), $method);
return true;
}
|
php
|
public function add($method)
{
if (!$method instanceof MethodInterface) {
throw new \InvalidArgumentException('This Method must be a instance of \ClassGeneration\MethodInterface');
}
if ($method->getName() === null) {
$method->setName('method' . ($this->count() + 1));
}
parent::set($method->getName(), $method);
return true;
}
|
[
"public",
"function",
"add",
"(",
"$",
"method",
")",
"{",
"if",
"(",
"!",
"$",
"method",
"instanceof",
"MethodInterface",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'This Method must be a instance of \\ClassGeneration\\MethodInterface'",
")",
";",
"}",
"if",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
"===",
"null",
")",
"{",
"$",
"method",
"->",
"setName",
"(",
"'method'",
".",
"(",
"$",
"this",
"->",
"count",
"(",
")",
"+",
"1",
")",
")",
";",
"}",
"parent",
"::",
"set",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
",",
"$",
"method",
")",
";",
"return",
"true",
";",
"}"
] |
Adds a new Method on collection.
@param MethodInterface $method
@return bool
@throws \InvalidArgumentException
|
[
"Adds",
"a",
"new",
"Method",
"on",
"collection",
"."
] |
train
|
https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/MethodCollection.php#L32-L43
|
tonicospinelli/class-generation
|
src/ClassGeneration/MethodCollection.php
|
MethodCollection.toString
|
public function toString()
{
$string = '';
$methods = $this->getIterator();
foreach ($methods as $method) {
$string .= $method->toString();
}
return $string;
}
|
php
|
public function toString()
{
$string = '';
$methods = $this->getIterator();
foreach ($methods as $method) {
$string .= $method->toString();
}
return $string;
}
|
[
"public",
"function",
"toString",
"(",
")",
"{",
"$",
"string",
"=",
"''",
";",
"$",
"methods",
"=",
"$",
"this",
"->",
"getIterator",
"(",
")",
";",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"method",
")",
"{",
"$",
"string",
".=",
"$",
"method",
"->",
"toString",
"(",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] |
Parse the Method Collection to string.
@return string
|
[
"Parse",
"the",
"Method",
"Collection",
"to",
"string",
"."
] |
train
|
https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/MethodCollection.php#L58-L67
|
tonicospinelli/class-generation
|
src/ClassGeneration/MethodCollection.php
|
MethodCollection.removeByName
|
public function removeByName($methodName)
{
$removedList = new self();
$list = $this->getIterator();
foreach ($list as $index => $method) {
if ((is_array($methodName) && in_array($method->getName(), $methodName))
|| ($method->getName() === $methodName)
) {
$removedList->add($method);
$this->remove($index);
}
}
return $removedList;
}
|
php
|
public function removeByName($methodName)
{
$removedList = new self();
$list = $this->getIterator();
foreach ($list as $index => $method) {
if ((is_array($methodName) && in_array($method->getName(), $methodName))
|| ($method->getName() === $methodName)
) {
$removedList->add($method);
$this->remove($index);
}
}
return $removedList;
}
|
[
"public",
"function",
"removeByName",
"(",
"$",
"methodName",
")",
"{",
"$",
"removedList",
"=",
"new",
"self",
"(",
")",
";",
"$",
"list",
"=",
"$",
"this",
"->",
"getIterator",
"(",
")",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"index",
"=>",
"$",
"method",
")",
"{",
"if",
"(",
"(",
"is_array",
"(",
"$",
"methodName",
")",
"&&",
"in_array",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
",",
"$",
"methodName",
")",
")",
"||",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
"===",
"$",
"methodName",
")",
")",
"{",
"$",
"removedList",
"->",
"add",
"(",
"$",
"method",
")",
";",
"$",
"this",
"->",
"remove",
"(",
"$",
"index",
")",
";",
"}",
"}",
"return",
"$",
"removedList",
";",
"}"
] |
Removes tags by name.
@param string $methodName
@return MethodCollection Returns a collection with removed methods.
|
[
"Removes",
"tags",
"by",
"name",
"."
] |
train
|
https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/MethodCollection.php#L76-L90
|
withfatpanda/illuminate-wordpress
|
src/Support/Concerns/Retriable.php
|
Retriable.fail
|
function fail($callback)
{
if (is_null($this->state)) {
$this->onError[] = $callback;
} else if (!$this->state) {
$callback($this->result);
}
return $this;
}
|
php
|
function fail($callback)
{
if (is_null($this->state)) {
$this->onError[] = $callback;
} else if (!$this->state) {
$callback($this->result);
}
return $this;
}
|
[
"function",
"fail",
"(",
"$",
"callback",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"state",
")",
")",
"{",
"$",
"this",
"->",
"onError",
"[",
"]",
"=",
"$",
"callback",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"this",
"->",
"state",
")",
"{",
"$",
"callback",
"(",
"$",
"this",
"->",
"result",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
If the wrapped operation ultimately fails on all attempts,
invoke the given function. Many functions can be
added to the stack. If the attempted execution
of the wrapped operation has already failed, the the function
given here will be invoked instantly.
@param function
@return self
|
[
"If",
"the",
"wrapped",
"operation",
"ultimately",
"fails",
"on",
"all",
"attempts",
"invoke",
"the",
"given",
"function",
".",
"Many",
"functions",
"can",
"be",
"added",
"to",
"the",
"stack",
".",
"If",
"the",
"attempted",
"execution",
"of",
"the",
"wrapped",
"operation",
"has",
"already",
"failed",
"the",
"the",
"function",
"given",
"here",
"will",
"be",
"invoked",
"instantly",
"."
] |
train
|
https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/Support/Concerns/Retriable.php#L143-L151
|
withfatpanda/illuminate-wordpress
|
src/Support/Concerns/Retriable.php
|
Retriable.then
|
function then($callback)
{
if (is_null($this->state)) {
$this->onSuccess[] = $callback;
} else if ($this->state) {
$callback($this->result);
}
return $this;
}
|
php
|
function then($callback)
{
if (is_null($this->state)) {
$this->onSuccess[] = $callback;
} else if ($this->state) {
$callback($this->result);
}
return $this;
}
|
[
"function",
"then",
"(",
"$",
"callback",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"state",
")",
")",
"{",
"$",
"this",
"->",
"onSuccess",
"[",
"]",
"=",
"$",
"callback",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"state",
")",
"{",
"$",
"callback",
"(",
"$",
"this",
"->",
"result",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
If the wrapped operation ultimately succeeds,
invoke the given function. Many functions can be
added to the stack. If the attempted execution
of the wrapped operation has already succeeded,
the the function given here will be invoked instantly.
If the given function throws an Exception, the
wrapped operation will be retried again—this allows
for instances in which the wrapped operation might
fail, but does not do so by throwing an Exception,
and success/failure is determined by post-processing.
@param function
@return self
|
[
"If",
"the",
"wrapped",
"operation",
"ultimately",
"succeeds",
"invoke",
"the",
"given",
"function",
".",
"Many",
"functions",
"can",
"be",
"added",
"to",
"the",
"stack",
".",
"If",
"the",
"attempted",
"execution",
"of",
"the",
"wrapped",
"operation",
"has",
"already",
"succeeded",
"the",
"the",
"function",
"given",
"here",
"will",
"be",
"invoked",
"instantly",
".",
"If",
"the",
"given",
"function",
"throws",
"an",
"Exception",
"the",
"wrapped",
"operation",
"will",
"be",
"retried",
"again—this",
"allows",
"for",
"instances",
"in",
"which",
"the",
"wrapped",
"operation",
"might",
"fail",
"but",
"does",
"not",
"do",
"so",
"by",
"throwing",
"an",
"Exception",
"and",
"success",
"/",
"failure",
"is",
"determined",
"by",
"post",
"-",
"processing",
"."
] |
train
|
https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/Support/Concerns/Retriable.php#L167-L175
|
withfatpanda/illuminate-wordpress
|
src/Support/Concerns/Retriable.php
|
Retriable.until
|
function until($limit)
{
$until = function() use ($limit) {
if (is_int($limit)) {
if ($this->attempts < $limit) {
return true;
} else {
return false;
}
} else {
if ($limit($this->lastException, $this->attempts)) {
return true;
} else {
return false;
}
}
};
$defaultResult = function() {
if (is_callable($this->defaultResult)) {
return call_user_func_array($this->defaultResult, [ $this->lastException, $this->attempts ]);
} else {
return $this->defaultResult;
}
};
do {
$this->attempts++;
if ($this->attempts > 1) {
if ($timeout = $this->handleWait($this->lastException)) {
// DEBUG: echo "sleep($timeout)\n";
sleep($timeout);
}
}
try {
// try to execute the wrapped process
$result = call_user_func_array($this->operation, [ $this->attempts ]);
// this might throw an Exception too:
$this->handleSuccess($result);
// it didn't throw an exception, so we're done!
return $result;
} catch (\Exception $e) {
$this->lastException = $e;
// let's filter the exception:
if (!$this->handleException($e)) {
// filtering the exception resulted in false, so we're done:
$this->handleError($e);
// just return the default result
return $defaultResult();
}
}
} while ($until());
// we fell through to here, so we invoke handleError
// DEBUG: echo "Fell through at: ".time()."\n";
$this->handleError($this->lastException, $this->attempts);
// and we just return whatever the default value of result was
return $defaultResult();
}
|
php
|
function until($limit)
{
$until = function() use ($limit) {
if (is_int($limit)) {
if ($this->attempts < $limit) {
return true;
} else {
return false;
}
} else {
if ($limit($this->lastException, $this->attempts)) {
return true;
} else {
return false;
}
}
};
$defaultResult = function() {
if (is_callable($this->defaultResult)) {
return call_user_func_array($this->defaultResult, [ $this->lastException, $this->attempts ]);
} else {
return $this->defaultResult;
}
};
do {
$this->attempts++;
if ($this->attempts > 1) {
if ($timeout = $this->handleWait($this->lastException)) {
// DEBUG: echo "sleep($timeout)\n";
sleep($timeout);
}
}
try {
// try to execute the wrapped process
$result = call_user_func_array($this->operation, [ $this->attempts ]);
// this might throw an Exception too:
$this->handleSuccess($result);
// it didn't throw an exception, so we're done!
return $result;
} catch (\Exception $e) {
$this->lastException = $e;
// let's filter the exception:
if (!$this->handleException($e)) {
// filtering the exception resulted in false, so we're done:
$this->handleError($e);
// just return the default result
return $defaultResult();
}
}
} while ($until());
// we fell through to here, so we invoke handleError
// DEBUG: echo "Fell through at: ".time()."\n";
$this->handleError($this->lastException, $this->attempts);
// and we just return whatever the default value of result was
return $defaultResult();
}
|
[
"function",
"until",
"(",
"$",
"limit",
")",
"{",
"$",
"until",
"=",
"function",
"(",
")",
"use",
"(",
"$",
"limit",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"limit",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"attempts",
"<",
"$",
"limit",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"limit",
"(",
"$",
"this",
"->",
"lastException",
",",
"$",
"this",
"->",
"attempts",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"}",
";",
"$",
"defaultResult",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"defaultResult",
")",
")",
"{",
"return",
"call_user_func_array",
"(",
"$",
"this",
"->",
"defaultResult",
",",
"[",
"$",
"this",
"->",
"lastException",
",",
"$",
"this",
"->",
"attempts",
"]",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"defaultResult",
";",
"}",
"}",
";",
"do",
"{",
"$",
"this",
"->",
"attempts",
"++",
";",
"if",
"(",
"$",
"this",
"->",
"attempts",
">",
"1",
")",
"{",
"if",
"(",
"$",
"timeout",
"=",
"$",
"this",
"->",
"handleWait",
"(",
"$",
"this",
"->",
"lastException",
")",
")",
"{",
"// DEBUG: echo \"sleep($timeout)\\n\";",
"sleep",
"(",
"$",
"timeout",
")",
";",
"}",
"}",
"try",
"{",
"// try to execute the wrapped process",
"$",
"result",
"=",
"call_user_func_array",
"(",
"$",
"this",
"->",
"operation",
",",
"[",
"$",
"this",
"->",
"attempts",
"]",
")",
";",
"// this might throw an Exception too:",
"$",
"this",
"->",
"handleSuccess",
"(",
"$",
"result",
")",
";",
"// it didn't throw an exception, so we're done!",
"return",
"$",
"result",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"lastException",
"=",
"$",
"e",
";",
"// let's filter the exception:",
"if",
"(",
"!",
"$",
"this",
"->",
"handleException",
"(",
"$",
"e",
")",
")",
"{",
"// filtering the exception resulted in false, so we're done:",
"$",
"this",
"->",
"handleError",
"(",
"$",
"e",
")",
";",
"// just return the default result",
"return",
"$",
"defaultResult",
"(",
")",
";",
"}",
"}",
"}",
"while",
"(",
"$",
"until",
"(",
")",
")",
";",
"// we fell through to here, so we invoke handleError",
"// DEBUG: echo \"Fell through at: \".time().\"\\n\";",
"$",
"this",
"->",
"handleError",
"(",
"$",
"this",
"->",
"lastException",
",",
"$",
"this",
"->",
"attempts",
")",
";",
"// and we just return whatever the default value of result was",
"return",
"$",
"defaultResult",
"(",
")",
";",
"}"
] |
Start the loop with the given limit
@param mixed Can be an integer or a function of
the signature function(\Exception $e, $attempt),
where $e is the last Exception thrown and $attempt
is the count of attempts made to execute the wrapped
operation
@return The return result of the wrapped operation,
if and when it completes successfully.
@throws Exception If there are no functions in the
fail stack, the final exception thrown by the
wrapped operation will be rethrown by this function
|
[
"Start",
"the",
"loop",
"with",
"the",
"given",
"limit"
] |
train
|
https://github.com/withfatpanda/illuminate-wordpress/blob/b426ca81a55367459430c974932ee5a941d759d8/src/Support/Concerns/Retriable.php#L237-L302
|
huasituo/hstcms
|
src/Libraries/Fields/Files.php
|
Files.option
|
public function option($option)
{
$option['fieldtype'] = isset($option['fieldtype']) ? $option['fieldtype'] : '';
$option['fieldlength'] = isset($option['fieldlength']) ? $option['fieldlength'] : '';
$option['uptips'] = isset($option['uptips']) ? $option['uptips'] : '';
$option['fvalue'] = isset($option['fvalue']) ? $option['fvalue'] : '';
$option['value'] = isset($option['value']) ? $option['value'] : '';
$option['size'] = isset($option['size']) ? $option['size'] : '2048';
$option['ext'] = isset($option['ext']) ? $option['ext'] : 'jpg,png,gif,jpeg';
$option['upauto'] = isset($option['upauto']) ? $option['upauto'] : 1;
$option['upbuttontext'] = isset($option['upbuttontext']) ? $option['upbuttontext'] : '选择图片';
$option['upapp'] = isset($option['upapp']) ? $option['upapp'] : '';
$option['multiNum'] = isset($option['multiNum']) ? $option['multiNum'] : 5;
return '
<div class="hstui-form-group hstui-form-group-sm">
<label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::fields.file.size').'</label>
<div class="hstui-u-sm-10 hstui-form-input">
<input type="text" name="setting[option][size]" value="'.$option['size'].'" class="hstui-input hstui-length-5">
<div class="hstui-form-input-tips" id="J_form_tips_size" data-tips="'.hst_lang('hstcms::fields.file.size.tips').'">'.hst_lang('hstcms::fields.file.size.tips').'</div>
</div>
</div>
<div class="hstui-form-group hstui-form-group-sm">
<label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::fields.file.ext').'</label>
<div class="hstui-u-sm-10 hstui-form-input">
<input type="text" name="setting[option][ext]" value="'.$option['ext'].'" class="hstui-input hstui-length-5">
<div class="hstui-form-input-tips" id="J_form_tips_ext" data-tips="'.hst_lang('hstcms::fields.file.ext.tips').'">'.hst_lang('hstcms::fields.file.ext.tips').'</div>
</div>
</div>
<div class="hstui-form-group hstui-form-group-sm">
<label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::fields.file.multi.num').'</label>
<div class="hstui-u-sm-10 hstui-form-input">
<input type="text" name="setting[option][multiNum]" value="'.$option['multiNum'].'" class="hstui-input hstui-length-5">
<div class="hstui-form-input-tips" id="J_form_tips_multiNum" data-tips="'.hst_lang('hstcms::fields.file.multi.num.tips').'">'.hst_lang('hstcms::fields.file.multi.num.tips').'</div>
</div>
</div>
<div class="hstui-form-group hstui-form-group-sm">
<label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::fields.file.upbuttontext').'</label>
<div class="hstui-u-sm-10 hstui-form-input">
<input type="text" name="setting[option][upbuttontext]" value="'.$option['upbuttontext'].'" class="hstui-input hstui-length-5">
<div class="hstui-form-input-tips" id="J_form_tips_upbuttontext" data-tips="'.hst_lang('hstcms::fields.file.upbuttontext.tips').'">'.hst_lang('hstcms::fields.file.upbuttontext.tips').'</div>
</div>
</div>
<div class="hstui-form-group hstui-form-group-sm">
<label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::fields.file.upapp').'</label>
<div class="hstui-u-sm-10 hstui-form-input">
<input type="text" name="setting[option][upapp]" value="'.$option['upapp'].'" class="hstui-input hstui-length-5">
<div class="hstui-form-input-tips" id="J_form_tips_upapp" data-tips="'.hst_lang('hstcms::fields.file.upapp.tips').'">'.hst_lang('hstcms::fields.file.upapp.tips').'</div>
</div>
</div>
<div class="hstui-form-group hstui-form-group-sm">
<label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::fields.file.uptips').'</label>
<div class="hstui-u-sm-10 hstui-form-input">
<input type="text" name="setting[option][uptips]" value="'.$option['uptips'].'" class="hstui-input hstui-length-5">
<div class="hstui-form-input-tips" id="J_form_tips_uptips" data-tips="'.hst_lang('hstcms::fields.file.uptips.tips').'">'.hst_lang('hstcms::fields.file.uptips.tips').'</div>
</div>
</div>
<div class="hstui-form-group hstui-form-group-sm">
<label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::fields.file.auto.upload').'</label>
<div class="hstui-u-sm-10 hstui-form-input">
<div class="hstui-mr-sm"><input type="radio" name="setting[option][upauto]" '.hst_ifCheck(!$option['upauto']).' value="0" />'.hst_lang('hstcms::public.no').'
<input type="radio" name="setting[option][upauto]" '.hst_ifCheck($option['upauto']).' value="1" />'.hst_lang('hstcms::public.yes').'</div>
<div class="hstui-form-input-tips" id="J_form_tips_upauto" data-tips="'.hst_lang('hstcms::fields.file.auto.upload.tips').'">'.hst_lang('hstcms::fields.file.auto.upload.tips').'</div>
</div>
</div>
'.$this->field_type($option['fieldtype'], $option['fieldlength'], $option['fvalue']);
}
|
php
|
public function option($option)
{
$option['fieldtype'] = isset($option['fieldtype']) ? $option['fieldtype'] : '';
$option['fieldlength'] = isset($option['fieldlength']) ? $option['fieldlength'] : '';
$option['uptips'] = isset($option['uptips']) ? $option['uptips'] : '';
$option['fvalue'] = isset($option['fvalue']) ? $option['fvalue'] : '';
$option['value'] = isset($option['value']) ? $option['value'] : '';
$option['size'] = isset($option['size']) ? $option['size'] : '2048';
$option['ext'] = isset($option['ext']) ? $option['ext'] : 'jpg,png,gif,jpeg';
$option['upauto'] = isset($option['upauto']) ? $option['upauto'] : 1;
$option['upbuttontext'] = isset($option['upbuttontext']) ? $option['upbuttontext'] : '选择图片';
$option['upapp'] = isset($option['upapp']) ? $option['upapp'] : '';
$option['multiNum'] = isset($option['multiNum']) ? $option['multiNum'] : 5;
return '
<div class="hstui-form-group hstui-form-group-sm">
<label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::fields.file.size').'</label>
<div class="hstui-u-sm-10 hstui-form-input">
<input type="text" name="setting[option][size]" value="'.$option['size'].'" class="hstui-input hstui-length-5">
<div class="hstui-form-input-tips" id="J_form_tips_size" data-tips="'.hst_lang('hstcms::fields.file.size.tips').'">'.hst_lang('hstcms::fields.file.size.tips').'</div>
</div>
</div>
<div class="hstui-form-group hstui-form-group-sm">
<label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::fields.file.ext').'</label>
<div class="hstui-u-sm-10 hstui-form-input">
<input type="text" name="setting[option][ext]" value="'.$option['ext'].'" class="hstui-input hstui-length-5">
<div class="hstui-form-input-tips" id="J_form_tips_ext" data-tips="'.hst_lang('hstcms::fields.file.ext.tips').'">'.hst_lang('hstcms::fields.file.ext.tips').'</div>
</div>
</div>
<div class="hstui-form-group hstui-form-group-sm">
<label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::fields.file.multi.num').'</label>
<div class="hstui-u-sm-10 hstui-form-input">
<input type="text" name="setting[option][multiNum]" value="'.$option['multiNum'].'" class="hstui-input hstui-length-5">
<div class="hstui-form-input-tips" id="J_form_tips_multiNum" data-tips="'.hst_lang('hstcms::fields.file.multi.num.tips').'">'.hst_lang('hstcms::fields.file.multi.num.tips').'</div>
</div>
</div>
<div class="hstui-form-group hstui-form-group-sm">
<label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::fields.file.upbuttontext').'</label>
<div class="hstui-u-sm-10 hstui-form-input">
<input type="text" name="setting[option][upbuttontext]" value="'.$option['upbuttontext'].'" class="hstui-input hstui-length-5">
<div class="hstui-form-input-tips" id="J_form_tips_upbuttontext" data-tips="'.hst_lang('hstcms::fields.file.upbuttontext.tips').'">'.hst_lang('hstcms::fields.file.upbuttontext.tips').'</div>
</div>
</div>
<div class="hstui-form-group hstui-form-group-sm">
<label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::fields.file.upapp').'</label>
<div class="hstui-u-sm-10 hstui-form-input">
<input type="text" name="setting[option][upapp]" value="'.$option['upapp'].'" class="hstui-input hstui-length-5">
<div class="hstui-form-input-tips" id="J_form_tips_upapp" data-tips="'.hst_lang('hstcms::fields.file.upapp.tips').'">'.hst_lang('hstcms::fields.file.upapp.tips').'</div>
</div>
</div>
<div class="hstui-form-group hstui-form-group-sm">
<label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::fields.file.uptips').'</label>
<div class="hstui-u-sm-10 hstui-form-input">
<input type="text" name="setting[option][uptips]" value="'.$option['uptips'].'" class="hstui-input hstui-length-5">
<div class="hstui-form-input-tips" id="J_form_tips_uptips" data-tips="'.hst_lang('hstcms::fields.file.uptips.tips').'">'.hst_lang('hstcms::fields.file.uptips.tips').'</div>
</div>
</div>
<div class="hstui-form-group hstui-form-group-sm">
<label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::fields.file.auto.upload').'</label>
<div class="hstui-u-sm-10 hstui-form-input">
<div class="hstui-mr-sm"><input type="radio" name="setting[option][upauto]" '.hst_ifCheck(!$option['upauto']).' value="0" />'.hst_lang('hstcms::public.no').'
<input type="radio" name="setting[option][upauto]" '.hst_ifCheck($option['upauto']).' value="1" />'.hst_lang('hstcms::public.yes').'</div>
<div class="hstui-form-input-tips" id="J_form_tips_upauto" data-tips="'.hst_lang('hstcms::fields.file.auto.upload.tips').'">'.hst_lang('hstcms::fields.file.auto.upload.tips').'</div>
</div>
</div>
'.$this->field_type($option['fieldtype'], $option['fieldlength'], $option['fvalue']);
}
|
[
"public",
"function",
"option",
"(",
"$",
"option",
")",
"{",
"$",
"option",
"[",
"'fieldtype'",
"]",
"=",
"isset",
"(",
"$",
"option",
"[",
"'fieldtype'",
"]",
")",
"?",
"$",
"option",
"[",
"'fieldtype'",
"]",
":",
"''",
";",
"$",
"option",
"[",
"'fieldlength'",
"]",
"=",
"isset",
"(",
"$",
"option",
"[",
"'fieldlength'",
"]",
")",
"?",
"$",
"option",
"[",
"'fieldlength'",
"]",
":",
"''",
";",
"$",
"option",
"[",
"'uptips'",
"]",
"=",
"isset",
"(",
"$",
"option",
"[",
"'uptips'",
"]",
")",
"?",
"$",
"option",
"[",
"'uptips'",
"]",
":",
"''",
";",
"$",
"option",
"[",
"'fvalue'",
"]",
"=",
"isset",
"(",
"$",
"option",
"[",
"'fvalue'",
"]",
")",
"?",
"$",
"option",
"[",
"'fvalue'",
"]",
":",
"''",
";",
"$",
"option",
"[",
"'value'",
"]",
"=",
"isset",
"(",
"$",
"option",
"[",
"'value'",
"]",
")",
"?",
"$",
"option",
"[",
"'value'",
"]",
":",
"''",
";",
"$",
"option",
"[",
"'size'",
"]",
"=",
"isset",
"(",
"$",
"option",
"[",
"'size'",
"]",
")",
"?",
"$",
"option",
"[",
"'size'",
"]",
":",
"'2048'",
";",
"$",
"option",
"[",
"'ext'",
"]",
"=",
"isset",
"(",
"$",
"option",
"[",
"'ext'",
"]",
")",
"?",
"$",
"option",
"[",
"'ext'",
"]",
":",
"'jpg,png,gif,jpeg'",
";",
"$",
"option",
"[",
"'upauto'",
"]",
"=",
"isset",
"(",
"$",
"option",
"[",
"'upauto'",
"]",
")",
"?",
"$",
"option",
"[",
"'upauto'",
"]",
":",
"1",
";",
"$",
"option",
"[",
"'upbuttontext'",
"]",
"=",
"isset",
"(",
"$",
"option",
"[",
"'upbuttontext'",
"]",
")",
"?",
"$",
"option",
"[",
"'upbuttontext'",
"]",
":",
"'选择图片';",
"",
"$",
"option",
"[",
"'upapp'",
"]",
"=",
"isset",
"(",
"$",
"option",
"[",
"'upapp'",
"]",
")",
"?",
"$",
"option",
"[",
"'upapp'",
"]",
":",
"''",
";",
"$",
"option",
"[",
"'multiNum'",
"]",
"=",
"isset",
"(",
"$",
"option",
"[",
"'multiNum'",
"]",
")",
"?",
"$",
"option",
"[",
"'multiNum'",
"]",
":",
"5",
";",
"return",
"'\n\t\t\t<div class=\"hstui-form-group hstui-form-group-sm\">\n\t <label class=\"hstui-u-sm-2 hstui-form-label\">'",
".",
"hst_lang",
"(",
"'hstcms::fields.file.size'",
")",
".",
"'</label>\n\t <div class=\"hstui-u-sm-10 hstui-form-input\">\n\t <input type=\"text\" name=\"setting[option][size]\" value=\"'",
".",
"$",
"option",
"[",
"'size'",
"]",
".",
"'\" class=\"hstui-input hstui-length-5\">\n\t <div class=\"hstui-form-input-tips\" id=\"J_form_tips_size\" data-tips=\"'",
".",
"hst_lang",
"(",
"'hstcms::fields.file.size.tips'",
")",
".",
"'\">'",
".",
"hst_lang",
"(",
"'hstcms::fields.file.size.tips'",
")",
".",
"'</div>\n\t </div>\n\t </div>\n\t\t\t<div class=\"hstui-form-group hstui-form-group-sm\">\n\t <label class=\"hstui-u-sm-2 hstui-form-label\">'",
".",
"hst_lang",
"(",
"'hstcms::fields.file.ext'",
")",
".",
"'</label>\n\t <div class=\"hstui-u-sm-10 hstui-form-input\">\n\t <input type=\"text\" name=\"setting[option][ext]\" value=\"'",
".",
"$",
"option",
"[",
"'ext'",
"]",
".",
"'\" class=\"hstui-input hstui-length-5\">\n\t <div class=\"hstui-form-input-tips\" id=\"J_form_tips_ext\" data-tips=\"'",
".",
"hst_lang",
"(",
"'hstcms::fields.file.ext.tips'",
")",
".",
"'\">'",
".",
"hst_lang",
"(",
"'hstcms::fields.file.ext.tips'",
")",
".",
"'</div>\n\t </div>\n\t </div> \n\t\t\t<div class=\"hstui-form-group hstui-form-group-sm\">\n\t <label class=\"hstui-u-sm-2 hstui-form-label\">'",
".",
"hst_lang",
"(",
"'hstcms::fields.file.multi.num'",
")",
".",
"'</label>\n\t <div class=\"hstui-u-sm-10 hstui-form-input\">\n\t <input type=\"text\" name=\"setting[option][multiNum]\" value=\"'",
".",
"$",
"option",
"[",
"'multiNum'",
"]",
".",
"'\" class=\"hstui-input hstui-length-5\">\n\t <div class=\"hstui-form-input-tips\" id=\"J_form_tips_multiNum\" data-tips=\"'",
".",
"hst_lang",
"(",
"'hstcms::fields.file.multi.num.tips'",
")",
".",
"'\">'",
".",
"hst_lang",
"(",
"'hstcms::fields.file.multi.num.tips'",
")",
".",
"'</div>\n\t </div>\n\t </div> \n\t\t\t<div class=\"hstui-form-group hstui-form-group-sm\">\n\t <label class=\"hstui-u-sm-2 hstui-form-label\">'",
".",
"hst_lang",
"(",
"'hstcms::fields.file.upbuttontext'",
")",
".",
"'</label>\n\t <div class=\"hstui-u-sm-10 hstui-form-input\">\n\t <input type=\"text\" name=\"setting[option][upbuttontext]\" value=\"'",
".",
"$",
"option",
"[",
"'upbuttontext'",
"]",
".",
"'\" class=\"hstui-input hstui-length-5\">\n\t <div class=\"hstui-form-input-tips\" id=\"J_form_tips_upbuttontext\" data-tips=\"'",
".",
"hst_lang",
"(",
"'hstcms::fields.file.upbuttontext.tips'",
")",
".",
"'\">'",
".",
"hst_lang",
"(",
"'hstcms::fields.file.upbuttontext.tips'",
")",
".",
"'</div>\n\t </div>\n\t </div> \n\t\t\t<div class=\"hstui-form-group hstui-form-group-sm\">\n\t <label class=\"hstui-u-sm-2 hstui-form-label\">'",
".",
"hst_lang",
"(",
"'hstcms::fields.file.upapp'",
")",
".",
"'</label>\n\t <div class=\"hstui-u-sm-10 hstui-form-input\">\n\t <input type=\"text\" name=\"setting[option][upapp]\" value=\"'",
".",
"$",
"option",
"[",
"'upapp'",
"]",
".",
"'\" class=\"hstui-input hstui-length-5\">\n\t <div class=\"hstui-form-input-tips\" id=\"J_form_tips_upapp\" data-tips=\"'",
".",
"hst_lang",
"(",
"'hstcms::fields.file.upapp.tips'",
")",
".",
"'\">'",
".",
"hst_lang",
"(",
"'hstcms::fields.file.upapp.tips'",
")",
".",
"'</div>\n\t </div>\n\t </div> \n\t\t\t<div class=\"hstui-form-group hstui-form-group-sm\">\n\t <label class=\"hstui-u-sm-2 hstui-form-label\">'",
".",
"hst_lang",
"(",
"'hstcms::fields.file.uptips'",
")",
".",
"'</label>\n\t <div class=\"hstui-u-sm-10 hstui-form-input\">\n\t <input type=\"text\" name=\"setting[option][uptips]\" value=\"'",
".",
"$",
"option",
"[",
"'uptips'",
"]",
".",
"'\" class=\"hstui-input hstui-length-5\">\n\t <div class=\"hstui-form-input-tips\" id=\"J_form_tips_uptips\" data-tips=\"'",
".",
"hst_lang",
"(",
"'hstcms::fields.file.uptips.tips'",
")",
".",
"'\">'",
".",
"hst_lang",
"(",
"'hstcms::fields.file.uptips.tips'",
")",
".",
"'</div>\n\t </div>\n\t </div> \n\t\t\t<div class=\"hstui-form-group hstui-form-group-sm\">\n\t <label class=\"hstui-u-sm-2 hstui-form-label\">'",
".",
"hst_lang",
"(",
"'hstcms::fields.file.auto.upload'",
")",
".",
"'</label>\n\t <div class=\"hstui-u-sm-10 hstui-form-input\">\n <div class=\"hstui-mr-sm\"><input type=\"radio\" name=\"setting[option][upauto]\" '",
".",
"hst_ifCheck",
"(",
"!",
"$",
"option",
"[",
"'upauto'",
"]",
")",
".",
"' value=\"0\" />'",
".",
"hst_lang",
"(",
"'hstcms::public.no'",
")",
".",
"'\n <input type=\"radio\" name=\"setting[option][upauto]\" '",
".",
"hst_ifCheck",
"(",
"$",
"option",
"[",
"'upauto'",
"]",
")",
".",
"' value=\"1\" />'",
".",
"hst_lang",
"(",
"'hstcms::public.yes'",
")",
".",
"'</div>\n\t <div class=\"hstui-form-input-tips\" id=\"J_form_tips_upauto\" data-tips=\"'",
".",
"hst_lang",
"(",
"'hstcms::fields.file.auto.upload.tips'",
")",
".",
"'\">'",
".",
"hst_lang",
"(",
"'hstcms::fields.file.auto.upload.tips'",
")",
".",
"'</div>\n\t </div>\n\t </div>\n '",
".",
"$",
"this",
"->",
"field_type",
"(",
"$",
"option",
"[",
"'fieldtype'",
"]",
",",
"$",
"option",
"[",
"'fieldlength'",
"]",
",",
"$",
"option",
"[",
"'fvalue'",
"]",
")",
";",
"}"
] |
字段相关属性参数
@param array $value 值
@return string
|
[
"字段相关属性参数"
] |
train
|
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Fields/Files.php#L33-L98
|
huasituo/hstcms
|
src/Libraries/Fields/Files.php
|
Files.input
|
public function input($cname, $name, $cfg, $value = NULL, $id = 0)
{
$upauto = isset($cfg['option']['upauto']) ? $cfg['option']['upauto'] ? 'true' : 'false' : 'true';
$upbuttontext = isset($cfg['option']['upbuttontext']) ? $cfg['option']['upbuttontext'] : hst_lang('hstcms::fields.file.select.pic');
$uptips = isset($cfg['option']['uptips']) ? $cfg['option']['uptips'] : '';
$multiNum = isset($cfg['option']['multiNum']) ? $cfg['option']['multiNum'] : 5;
$upapp = isset($cfg['option']['upapp']) ? $cfg['option']['upapp'] : '';
// 是否必须
$text = (isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1 ? '<font color="red">*</font> ' : '').$cname;
// 字段提示信息
$tips = isset($cfg['validate']['tips']) && $cfg['validate']['tips'] ? $cfg['validate']['tips'] : '';
// 禁止修改
$disabled = !$this->isadmin && $id && $value && isset($cfg['validate']['isedit']) && $cfg['validate']['isedit'] ? 'false' : 'true';
$postDatas ='';
$attachs = [];
if ($value) {
$attachs = $value;
}
$attachs = json_encode($attachs);
$uploadUrl = route('uploadSave');
$str = '<div class="hstui-upload J_upload_'.$name.'" style="line-height: 20px;"></div>';
$str .= "<script>
Hstui.use('jquery', 'common', 'upload', function() {
$(\".J_upload_$name\").hstuiUpload({
autoUpload: $upauto,
selectText: '$upbuttontext',
multi: true,
multiNum: $multiNum, //多文件上传时允许的有效文件数
fileName: 'filedata',
fName: '$name',
isedit: $disabled,
dataList: $attachs,
queue: {
},
showNote: '$uptips',
url: '$uploadUrl',
formParam: {
upapp:'$upapp'
}
})
})
</script>";
return $this->input_format($name, $text, $str, $tips);
}
|
php
|
public function input($cname, $name, $cfg, $value = NULL, $id = 0)
{
$upauto = isset($cfg['option']['upauto']) ? $cfg['option']['upauto'] ? 'true' : 'false' : 'true';
$upbuttontext = isset($cfg['option']['upbuttontext']) ? $cfg['option']['upbuttontext'] : hst_lang('hstcms::fields.file.select.pic');
$uptips = isset($cfg['option']['uptips']) ? $cfg['option']['uptips'] : '';
$multiNum = isset($cfg['option']['multiNum']) ? $cfg['option']['multiNum'] : 5;
$upapp = isset($cfg['option']['upapp']) ? $cfg['option']['upapp'] : '';
// 是否必须
$text = (isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1 ? '<font color="red">*</font> ' : '').$cname;
// 字段提示信息
$tips = isset($cfg['validate']['tips']) && $cfg['validate']['tips'] ? $cfg['validate']['tips'] : '';
// 禁止修改
$disabled = !$this->isadmin && $id && $value && isset($cfg['validate']['isedit']) && $cfg['validate']['isedit'] ? 'false' : 'true';
$postDatas ='';
$attachs = [];
if ($value) {
$attachs = $value;
}
$attachs = json_encode($attachs);
$uploadUrl = route('uploadSave');
$str = '<div class="hstui-upload J_upload_'.$name.'" style="line-height: 20px;"></div>';
$str .= "<script>
Hstui.use('jquery', 'common', 'upload', function() {
$(\".J_upload_$name\").hstuiUpload({
autoUpload: $upauto,
selectText: '$upbuttontext',
multi: true,
multiNum: $multiNum, //多文件上传时允许的有效文件数
fileName: 'filedata',
fName: '$name',
isedit: $disabled,
dataList: $attachs,
queue: {
},
showNote: '$uptips',
url: '$uploadUrl',
formParam: {
upapp:'$upapp'
}
})
})
</script>";
return $this->input_format($name, $text, $str, $tips);
}
|
[
"public",
"function",
"input",
"(",
"$",
"cname",
",",
"$",
"name",
",",
"$",
"cfg",
",",
"$",
"value",
"=",
"NULL",
",",
"$",
"id",
"=",
"0",
")",
"{",
"$",
"upauto",
"=",
"isset",
"(",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'upauto'",
"]",
")",
"?",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'upauto'",
"]",
"?",
"'true'",
":",
"'false'",
":",
"'true'",
";",
"$",
"upbuttontext",
"=",
"isset",
"(",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'upbuttontext'",
"]",
")",
"?",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'upbuttontext'",
"]",
":",
"hst_lang",
"(",
"'hstcms::fields.file.select.pic'",
")",
";",
"$",
"uptips",
"=",
"isset",
"(",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'uptips'",
"]",
")",
"?",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'uptips'",
"]",
":",
"''",
";",
"$",
"multiNum",
"=",
"isset",
"(",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'multiNum'",
"]",
")",
"?",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'multiNum'",
"]",
":",
"5",
";",
"$",
"upapp",
"=",
"isset",
"(",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'upapp'",
"]",
")",
"?",
"$",
"cfg",
"[",
"'option'",
"]",
"[",
"'upapp'",
"]",
":",
"''",
";",
"// 是否必须",
"$",
"text",
"=",
"(",
"isset",
"(",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'required'",
"]",
")",
"&&",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'required'",
"]",
"==",
"1",
"?",
"'<font color=\"red\">*</font> '",
":",
"''",
")",
".",
"$",
"cname",
";",
"// 字段提示信息",
"$",
"tips",
"=",
"isset",
"(",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'tips'",
"]",
")",
"&&",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'tips'",
"]",
"?",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'tips'",
"]",
":",
"''",
";",
"// 禁止修改",
"$",
"disabled",
"=",
"!",
"$",
"this",
"->",
"isadmin",
"&&",
"$",
"id",
"&&",
"$",
"value",
"&&",
"isset",
"(",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'isedit'",
"]",
")",
"&&",
"$",
"cfg",
"[",
"'validate'",
"]",
"[",
"'isedit'",
"]",
"?",
"'false'",
":",
"'true'",
";",
"$",
"postDatas",
"=",
"''",
";",
"$",
"attachs",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"value",
")",
"{",
"$",
"attachs",
"=",
"$",
"value",
";",
"}",
"$",
"attachs",
"=",
"json_encode",
"(",
"$",
"attachs",
")",
";",
"$",
"uploadUrl",
"=",
"route",
"(",
"'uploadSave'",
")",
";",
"$",
"str",
"=",
"'<div class=\"hstui-upload J_upload_'",
".",
"$",
"name",
".",
"'\" style=\"line-height: 20px;\"></div>'",
";",
"$",
"str",
".=",
"\"<script>\n\t\t\tHstui.use('jquery', 'common', 'upload', function() {\n\t\t\t\t$(\\\".J_upload_$name\\\").hstuiUpload({\n\t\t\t\t\tautoUpload: $upauto,\n\t\t\t\t\tselectText: '$upbuttontext',\n\t\t\t\t\tmulti: true,\n\t\t\t\t\tmultiNum: $multiNum, //多文件上传时允许的有效文件数\n\t\t\t\t\tfileName: 'filedata',\n\t\t\t\t\tfName: '$name',\n\t\t\t\t\tisedit: $disabled,\n\t\t\t\t\tdataList: $attachs,\n\t\t\t\t\tqueue: {\n\t\t\t\t\t},\n\t\t\t\t\tshowNote: '$uptips',\n\t\t\t\t\turl: '$uploadUrl',\n\t\t\t\t\tformParam: {\n\t\t\t\t\t\tupapp:'$upapp'\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t})\n\t\t</script>\"",
";",
"return",
"$",
"this",
"->",
"input_format",
"(",
"$",
"name",
",",
"$",
"text",
",",
"$",
"str",
",",
"$",
"tips",
")",
";",
"}"
] |
字段表单输入
@param string $cname 字段别名
@param string $name 字段名称
@param array $cfg 字段配置
@param array $data 值
@return string
|
[
"字段表单输入"
] |
train
|
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Fields/Files.php#L109-L152
|
huasituo/hstcms
|
src/Libraries/Fields/Files.php
|
Files.insert_value
|
public function insert_value(Request $request, $field, $postData = [])
{
$value = $request->get($field['fieldname']);
if($value) {
$aids = [];
foreach ($value['aid'] as $k => $v) {
$aids[] = $v;
}
$value = implode(',', $aids);
}
$postData[$field['relatedtable']][$field['fieldname']] = (string)$value;
return $postData;
}
|
php
|
public function insert_value(Request $request, $field, $postData = [])
{
$value = $request->get($field['fieldname']);
if($value) {
$aids = [];
foreach ($value['aid'] as $k => $v) {
$aids[] = $v;
}
$value = implode(',', $aids);
}
$postData[$field['relatedtable']][$field['fieldname']] = (string)$value;
return $postData;
}
|
[
"public",
"function",
"insert_value",
"(",
"Request",
"$",
"request",
",",
"$",
"field",
",",
"$",
"postData",
"=",
"[",
"]",
")",
"{",
"$",
"value",
"=",
"$",
"request",
"->",
"get",
"(",
"$",
"field",
"[",
"'fieldname'",
"]",
")",
";",
"if",
"(",
"$",
"value",
")",
"{",
"$",
"aids",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"value",
"[",
"'aid'",
"]",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"aids",
"[",
"]",
"=",
"$",
"v",
";",
"}",
"$",
"value",
"=",
"implode",
"(",
"','",
",",
"$",
"aids",
")",
";",
"}",
"$",
"postData",
"[",
"$",
"field",
"[",
"'relatedtable'",
"]",
"]",
"[",
"$",
"field",
"[",
"'fieldname'",
"]",
"]",
"=",
"(",
"string",
")",
"$",
"value",
";",
"return",
"$",
"postData",
";",
"}"
] |
处理输入数据,提供给入库
|
[
"处理输入数据,提供给入库"
] |
train
|
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Fields/Files.php#L158-L170
|
huasituo/hstcms
|
src/Libraries/Fields/Files.php
|
Files.output_data
|
public function output_data($data, $field = [])
{
if(!isset($data[$field['fieldname']])) {
return $data;
}
$value = $data[$field['fieldname']];
$data['_'.$field['fieldname']] = $value;
$data[$field['fieldname']] = AttachmentModel::getAttachs(explode(',', $value));
return $data;
}
|
php
|
public function output_data($data, $field = [])
{
if(!isset($data[$field['fieldname']])) {
return $data;
}
$value = $data[$field['fieldname']];
$data['_'.$field['fieldname']] = $value;
$data[$field['fieldname']] = AttachmentModel::getAttachs(explode(',', $value));
return $data;
}
|
[
"public",
"function",
"output_data",
"(",
"$",
"data",
",",
"$",
"field",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
"field",
"[",
"'fieldname'",
"]",
"]",
")",
")",
"{",
"return",
"$",
"data",
";",
"}",
"$",
"value",
"=",
"$",
"data",
"[",
"$",
"field",
"[",
"'fieldname'",
"]",
"]",
";",
"$",
"data",
"[",
"'_'",
".",
"$",
"field",
"[",
"'fieldname'",
"]",
"]",
"=",
"$",
"value",
";",
"$",
"data",
"[",
"$",
"field",
"[",
"'fieldname'",
"]",
"]",
"=",
"AttachmentModel",
"::",
"getAttachs",
"(",
"explode",
"(",
"','",
",",
"$",
"value",
")",
")",
";",
"return",
"$",
"data",
";",
"}"
] |
字段输出
|
[
"字段输出"
] |
train
|
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Fields/Files.php#L175-L184
|
activecollab/databasestructure
|
src/Field/Composite/CreatedAtField.php
|
CreatedAtField.onAddedToType
|
public function onAddedToType(TypeInterface &$type)
{
parent::onAddedToType($type);
if ($this->getAddIndex()) {
$type->addIndex(new Index($this->name));
}
$type->addTrait(CreatedAtInterface::class, CreatedAtInterfaceImplementation::class)->serialize($this->name);
}
|
php
|
public function onAddedToType(TypeInterface &$type)
{
parent::onAddedToType($type);
if ($this->getAddIndex()) {
$type->addIndex(new Index($this->name));
}
$type->addTrait(CreatedAtInterface::class, CreatedAtInterfaceImplementation::class)->serialize($this->name);
}
|
[
"public",
"function",
"onAddedToType",
"(",
"TypeInterface",
"&",
"$",
"type",
")",
"{",
"parent",
"::",
"onAddedToType",
"(",
"$",
"type",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getAddIndex",
"(",
")",
")",
"{",
"$",
"type",
"->",
"addIndex",
"(",
"new",
"Index",
"(",
"$",
"this",
"->",
"name",
")",
")",
";",
"}",
"$",
"type",
"->",
"addTrait",
"(",
"CreatedAtInterface",
"::",
"class",
",",
"CreatedAtInterfaceImplementation",
"::",
"class",
")",
"->",
"serialize",
"(",
"$",
"this",
"->",
"name",
")",
";",
"}"
] |
Method that is called when field is added to a type.
@param TypeInterface $type
|
[
"Method",
"that",
"is",
"called",
"when",
"field",
"is",
"added",
"to",
"a",
"type",
"."
] |
train
|
https://github.com/activecollab/databasestructure/blob/4b2353c4422186bcfce63b3212da3e70e63eb5df/src/Field/Composite/CreatedAtField.php#L67-L76
|
gbprod/elastica-provider-bundle
|
src/ElasticaProviderBundle/Provider/BulkProvider.php
|
BulkProvider.run
|
public function run(Client $client, $index, $type, EventDispatcherInterface $dispatcher)
{
$this->initialize($client, $index, $type, $dispatcher);
$this->populate();
$this->commit();
}
|
php
|
public function run(Client $client, $index, $type, EventDispatcherInterface $dispatcher)
{
$this->initialize($client, $index, $type, $dispatcher);
$this->populate();
$this->commit();
}
|
[
"public",
"function",
"run",
"(",
"Client",
"$",
"client",
",",
"$",
"index",
",",
"$",
"type",
",",
"EventDispatcherInterface",
"$",
"dispatcher",
")",
"{",
"$",
"this",
"->",
"initialize",
"(",
"$",
"client",
",",
"$",
"index",
",",
"$",
"type",
",",
"$",
"dispatcher",
")",
";",
"$",
"this",
"->",
"populate",
"(",
")",
";",
"$",
"this",
"->",
"commit",
"(",
")",
";",
"}"
] |
{@inheritdoc}
|
[
"{"
] |
train
|
https://github.com/gbprod/elastica-provider-bundle/blob/ee1e2ca78651d570b7400049bf81d8405fc744fc/src/ElasticaProviderBundle/Provider/BulkProvider.php#L56-L61
|
EcomDev/phpspec-magento-di-adapter
|
src/ParameterValidator.php
|
ParameterValidator.addGenerator
|
public function addGenerator($generatorClass, $suffix, \Closure $factory = null)
{
$this->generators[] = new GeneratorWrapper($this->createGeneratorFactory($generatorClass, $factory), $suffix);
return $this;
}
|
php
|
public function addGenerator($generatorClass, $suffix, \Closure $factory = null)
{
$this->generators[] = new GeneratorWrapper($this->createGeneratorFactory($generatorClass, $factory), $suffix);
return $this;
}
|
[
"public",
"function",
"addGenerator",
"(",
"$",
"generatorClass",
",",
"$",
"suffix",
",",
"\\",
"Closure",
"$",
"factory",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"generators",
"[",
"]",
"=",
"new",
"GeneratorWrapper",
"(",
"$",
"this",
"->",
"createGeneratorFactory",
"(",
"$",
"generatorClass",
",",
"$",
"factory",
")",
",",
"$",
"suffix",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
*
Adds a new generator
@param string $generatorClass
@param string $suffix
@param \Closure|null $factory
@return $this
|
[
"*",
"Adds",
"a",
"new",
"generator"
] |
train
|
https://github.com/EcomDev/phpspec-magento-di-adapter/blob/b39f6f0afbb837dbf0eb4c71e6cdb318b8c9de37/src/ParameterValidator.php#L65-L69
|
EcomDev/phpspec-magento-di-adapter
|
src/ParameterValidator.php
|
ParameterValidator.generator
|
public function generator($className)
{
foreach ($this->generators as $generator) {
if ($generator->supports($className)) {
return $generator->createGenerator($className);
}
}
return false;
}
|
php
|
public function generator($className)
{
foreach ($this->generators as $generator) {
if ($generator->supports($className)) {
return $generator->createGenerator($className);
}
}
return false;
}
|
[
"public",
"function",
"generator",
"(",
"$",
"className",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"generators",
"as",
"$",
"generator",
")",
"{",
"if",
"(",
"$",
"generator",
"->",
"supports",
"(",
"$",
"className",
")",
")",
"{",
"return",
"$",
"generator",
"->",
"createGenerator",
"(",
"$",
"className",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Generates a generator from class name rules
@param string $className
@return bool|\Magento\Framework\Code\Generator\EntityAbstract
|
[
"Generates",
"a",
"generator",
"from",
"class",
"name",
"rules"
] |
train
|
https://github.com/EcomDev/phpspec-magento-di-adapter/blob/b39f6f0afbb837dbf0eb4c71e6cdb318b8c9de37/src/ParameterValidator.php#L78-L87
|
EcomDev/phpspec-magento-di-adapter
|
src/ParameterValidator.php
|
ParameterValidator.createGeneratorFactory
|
private function createGeneratorFactory($generatorClass, \Closure $factory = null)
{
return function ($sourceClass, $prefixClass) use ($factory, $generatorClass) {
if ($factory) {
return $factory($sourceClass, $prefixClass, $this->generationIo, $this->definedClasses, $generatorClass);
}
return new $generatorClass($sourceClass, $prefixClass, $this->generationIo, null, $this->definedClasses);
};
}
|
php
|
private function createGeneratorFactory($generatorClass, \Closure $factory = null)
{
return function ($sourceClass, $prefixClass) use ($factory, $generatorClass) {
if ($factory) {
return $factory($sourceClass, $prefixClass, $this->generationIo, $this->definedClasses, $generatorClass);
}
return new $generatorClass($sourceClass, $prefixClass, $this->generationIo, null, $this->definedClasses);
};
}
|
[
"private",
"function",
"createGeneratorFactory",
"(",
"$",
"generatorClass",
",",
"\\",
"Closure",
"$",
"factory",
"=",
"null",
")",
"{",
"return",
"function",
"(",
"$",
"sourceClass",
",",
"$",
"prefixClass",
")",
"use",
"(",
"$",
"factory",
",",
"$",
"generatorClass",
")",
"{",
"if",
"(",
"$",
"factory",
")",
"{",
"return",
"$",
"factory",
"(",
"$",
"sourceClass",
",",
"$",
"prefixClass",
",",
"$",
"this",
"->",
"generationIo",
",",
"$",
"this",
"->",
"definedClasses",
",",
"$",
"generatorClass",
")",
";",
"}",
"return",
"new",
"$",
"generatorClass",
"(",
"$",
"sourceClass",
",",
"$",
"prefixClass",
",",
"$",
"this",
"->",
"generationIo",
",",
"null",
",",
"$",
"this",
"->",
"definedClasses",
")",
";",
"}",
";",
"}"
] |
Returns generator factory
@param string $generatorClass
@param \Closure|null $factory
@return \Closure
|
[
"Returns",
"generator",
"factory"
] |
train
|
https://github.com/EcomDev/phpspec-magento-di-adapter/blob/b39f6f0afbb837dbf0eb4c71e6cdb318b8c9de37/src/ParameterValidator.php#L97-L106
|
EcomDev/phpspec-magento-di-adapter
|
src/ParameterValidator.php
|
ParameterValidator.validate
|
public function validate(\ReflectionFunctionAbstract $reflectionFunction)
{
foreach ($reflectionFunction->getParameters() as $parameter) {
$this->validateParameter($parameter);
}
return $this;
}
|
php
|
public function validate(\ReflectionFunctionAbstract $reflectionFunction)
{
foreach ($reflectionFunction->getParameters() as $parameter) {
$this->validateParameter($parameter);
}
return $this;
}
|
[
"public",
"function",
"validate",
"(",
"\\",
"ReflectionFunctionAbstract",
"$",
"reflectionFunction",
")",
"{",
"foreach",
"(",
"$",
"reflectionFunction",
"->",
"getParameters",
"(",
")",
"as",
"$",
"parameter",
")",
"{",
"$",
"this",
"->",
"validateParameter",
"(",
"$",
"parameter",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Validates method signature and tries to generate missing classes
@param \ReflectionFunctionAbstract $reflectionFunction
@return $this
|
[
"Validates",
"method",
"signature",
"and",
"tries",
"to",
"generate",
"missing",
"classes"
] |
train
|
https://github.com/EcomDev/phpspec-magento-di-adapter/blob/b39f6f0afbb837dbf0eb4c71e6cdb318b8c9de37/src/ParameterValidator.php#L115-L122
|
EcomDev/phpspec-magento-di-adapter
|
src/ParameterValidator.php
|
ParameterValidator.validateParameter
|
private function validateParameter(\ReflectionParameter $parameter)
{
$catcher = function ($className) {
$generator = $this->generator($className);
if ($generator) {
include $generator->generate();
}
};
if (($reflectionClass = $parameter->getDeclaringClass())
&& ($reflectionMethod = $parameter->getDeclaringFunction())) {
$type = $this->typeHintIndex->lookup(
$reflectionClass->getName(),
$reflectionMethod->getName(),
'$' . $parameter->getName()
);
if ($type && !class_exists($type) && !interface_exists($type)) {
$catcher($type);
return $this;
}
}
spl_autoload_register($catcher);
try {
$parameter->getClass();
} catch (\ReflectionException $e) {
// Ignore reflection exception, as it is an intended behaviour for our catcher
}
spl_autoload_unregister($catcher);
return $this;
}
|
php
|
private function validateParameter(\ReflectionParameter $parameter)
{
$catcher = function ($className) {
$generator = $this->generator($className);
if ($generator) {
include $generator->generate();
}
};
if (($reflectionClass = $parameter->getDeclaringClass())
&& ($reflectionMethod = $parameter->getDeclaringFunction())) {
$type = $this->typeHintIndex->lookup(
$reflectionClass->getName(),
$reflectionMethod->getName(),
'$' . $parameter->getName()
);
if ($type && !class_exists($type) && !interface_exists($type)) {
$catcher($type);
return $this;
}
}
spl_autoload_register($catcher);
try {
$parameter->getClass();
} catch (\ReflectionException $e) {
// Ignore reflection exception, as it is an intended behaviour for our catcher
}
spl_autoload_unregister($catcher);
return $this;
}
|
[
"private",
"function",
"validateParameter",
"(",
"\\",
"ReflectionParameter",
"$",
"parameter",
")",
"{",
"$",
"catcher",
"=",
"function",
"(",
"$",
"className",
")",
"{",
"$",
"generator",
"=",
"$",
"this",
"->",
"generator",
"(",
"$",
"className",
")",
";",
"if",
"(",
"$",
"generator",
")",
"{",
"include",
"$",
"generator",
"->",
"generate",
"(",
")",
";",
"}",
"}",
";",
"if",
"(",
"(",
"$",
"reflectionClass",
"=",
"$",
"parameter",
"->",
"getDeclaringClass",
"(",
")",
")",
"&&",
"(",
"$",
"reflectionMethod",
"=",
"$",
"parameter",
"->",
"getDeclaringFunction",
"(",
")",
")",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"typeHintIndex",
"->",
"lookup",
"(",
"$",
"reflectionClass",
"->",
"getName",
"(",
")",
",",
"$",
"reflectionMethod",
"->",
"getName",
"(",
")",
",",
"'$'",
".",
"$",
"parameter",
"->",
"getName",
"(",
")",
")",
";",
"if",
"(",
"$",
"type",
"&&",
"!",
"class_exists",
"(",
"$",
"type",
")",
"&&",
"!",
"interface_exists",
"(",
"$",
"type",
")",
")",
"{",
"$",
"catcher",
"(",
"$",
"type",
")",
";",
"return",
"$",
"this",
";",
"}",
"}",
"spl_autoload_register",
"(",
"$",
"catcher",
")",
";",
"try",
"{",
"$",
"parameter",
"->",
"getClass",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"ReflectionException",
"$",
"e",
")",
"{",
"// Ignore reflection exception, as it is an intended behaviour for our catcher",
"}",
"spl_autoload_unregister",
"(",
"$",
"catcher",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Reflection parameter
@param \ReflectionParameter $parameter
@return $this
|
[
"Reflection",
"parameter"
] |
train
|
https://github.com/EcomDev/phpspec-magento-di-adapter/blob/b39f6f0afbb837dbf0eb4c71e6cdb318b8c9de37/src/ParameterValidator.php#L131-L162
|
phramework/jsonapi
|
src/Controller/GETById.php
|
GETById.handleGETById
|
protected static function handleGETById(
$parameters,
$id,
$modelClass,
$primaryDataParameters = [],
$relationshipParameters = []
) {
$filterValidationModel = $modelClass::getFilterValidationModel();
$idAttribute = $modelClass::getIdAttribute();
//Filter id attribute value
if (!empty($filterValidationModel) && isset($filterValidationModel->{$idAttribute})) {
$id = $filterValidationModel->{$idAttribute}->parse($id);
}
$fields = $modelClass::parseFields($parameters);
$requestInclude = static::getRequestInclude($parameters, $modelClass);
$data = $modelClass::getById(
$id,
$fields,
...$primaryDataParameters
);
//Check if resource exists
static::exists($data);
$includedData = $modelClass::getIncludedData(
$data,
$requestInclude,
$fields,
$relationshipParameters
);
return static::viewData(
$data,
(object) [
'self' => $modelClass::getSelfLink($id)
],
null,
(empty($requestInclude) ? null : $includedData)
);
}
|
php
|
protected static function handleGETById(
$parameters,
$id,
$modelClass,
$primaryDataParameters = [],
$relationshipParameters = []
) {
$filterValidationModel = $modelClass::getFilterValidationModel();
$idAttribute = $modelClass::getIdAttribute();
//Filter id attribute value
if (!empty($filterValidationModel) && isset($filterValidationModel->{$idAttribute})) {
$id = $filterValidationModel->{$idAttribute}->parse($id);
}
$fields = $modelClass::parseFields($parameters);
$requestInclude = static::getRequestInclude($parameters, $modelClass);
$data = $modelClass::getById(
$id,
$fields,
...$primaryDataParameters
);
//Check if resource exists
static::exists($data);
$includedData = $modelClass::getIncludedData(
$data,
$requestInclude,
$fields,
$relationshipParameters
);
return static::viewData(
$data,
(object) [
'self' => $modelClass::getSelfLink($id)
],
null,
(empty($requestInclude) ? null : $includedData)
);
}
|
[
"protected",
"static",
"function",
"handleGETById",
"(",
"$",
"parameters",
",",
"$",
"id",
",",
"$",
"modelClass",
",",
"$",
"primaryDataParameters",
"=",
"[",
"]",
",",
"$",
"relationshipParameters",
"=",
"[",
"]",
")",
"{",
"$",
"filterValidationModel",
"=",
"$",
"modelClass",
"::",
"getFilterValidationModel",
"(",
")",
";",
"$",
"idAttribute",
"=",
"$",
"modelClass",
"::",
"getIdAttribute",
"(",
")",
";",
"//Filter id attribute value",
"if",
"(",
"!",
"empty",
"(",
"$",
"filterValidationModel",
")",
"&&",
"isset",
"(",
"$",
"filterValidationModel",
"->",
"{",
"$",
"idAttribute",
"}",
")",
")",
"{",
"$",
"id",
"=",
"$",
"filterValidationModel",
"->",
"{",
"$",
"idAttribute",
"}",
"->",
"parse",
"(",
"$",
"id",
")",
";",
"}",
"$",
"fields",
"=",
"$",
"modelClass",
"::",
"parseFields",
"(",
"$",
"parameters",
")",
";",
"$",
"requestInclude",
"=",
"static",
"::",
"getRequestInclude",
"(",
"$",
"parameters",
",",
"$",
"modelClass",
")",
";",
"$",
"data",
"=",
"$",
"modelClass",
"::",
"getById",
"(",
"$",
"id",
",",
"$",
"fields",
",",
"...",
"$",
"primaryDataParameters",
")",
";",
"//Check if resource exists",
"static",
"::",
"exists",
"(",
"$",
"data",
")",
";",
"$",
"includedData",
"=",
"$",
"modelClass",
"::",
"getIncludedData",
"(",
"$",
"data",
",",
"$",
"requestInclude",
",",
"$",
"fields",
",",
"$",
"relationshipParameters",
")",
";",
"return",
"static",
"::",
"viewData",
"(",
"$",
"data",
",",
"(",
"object",
")",
"[",
"'self'",
"=>",
"$",
"modelClass",
"::",
"getSelfLink",
"(",
"$",
"id",
")",
"]",
",",
"null",
",",
"(",
"empty",
"(",
"$",
"requestInclude",
")",
"?",
"null",
":",
"$",
"includedData",
")",
")",
";",
"}"
] |
handles GETById requests
@param object $parameters Request parameters
@param integer|string $id Requested resource's id
@param string $modelClass Resource's primary model
to be used
@param array $primaryDataParameters [Optional] Array with any
additional arguments that the primary data is requiring
@param array $relationshipParameters [Optional] Array with any
additional argument primary data's relationships are requiring
@uses model's `getById` method to fetch resource
@return boolean
@todo Force parsing of relationship data when included
|
[
"handles",
"GETById",
"requests"
] |
train
|
https://github.com/phramework/jsonapi/blob/af20882a8b6f6e5be9c8e09e5b87f6c23a4b0726/src/Controller/GETById.php#L46-L90
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Map/RolePermissionTableMap.php
|
RolePermissionTableMap.addInstanceToPool
|
public static function addInstanceToPool($obj, $key = null)
{
if (Propel::isInstancePoolingEnabled()) {
if (null === $key) {
$key = serialize(array((string) $obj->getRoleId(), (string) $obj->getPermissionId()));
} // if key === null
self::$instances[$key] = $obj;
}
}
|
php
|
public static function addInstanceToPool($obj, $key = null)
{
if (Propel::isInstancePoolingEnabled()) {
if (null === $key) {
$key = serialize(array((string) $obj->getRoleId(), (string) $obj->getPermissionId()));
} // if key === null
self::$instances[$key] = $obj;
}
}
|
[
"public",
"static",
"function",
"addInstanceToPool",
"(",
"$",
"obj",
",",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"Propel",
"::",
"isInstancePoolingEnabled",
"(",
")",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"key",
")",
"{",
"$",
"key",
"=",
"serialize",
"(",
"array",
"(",
"(",
"string",
")",
"$",
"obj",
"->",
"getRoleId",
"(",
")",
",",
"(",
"string",
")",
"$",
"obj",
"->",
"getPermissionId",
"(",
")",
")",
")",
";",
"}",
"// if key === null",
"self",
"::",
"$",
"instances",
"[",
"$",
"key",
"]",
"=",
"$",
"obj",
";",
"}",
"}"
] |
Adds an object to the instance pool.
Propel keeps cached copies of objects in an instance pool when they are retrieved
from the database. In some cases you may need to explicitly add objects
to the cache in order to ensure that the same objects are always returned by find*()
and findPk*() calls.
@param \Alchemy\Component\Cerberus\Model\RolePermission $obj A \Alchemy\Component\Cerberus\Model\RolePermission object.
@param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
|
[
"Adds",
"an",
"object",
"to",
"the",
"instance",
"pool",
"."
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Map/RolePermissionTableMap.php#L160-L168
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Map/RolePermissionTableMap.php
|
RolePermissionTableMap.removeInstanceFromPool
|
public static function removeInstanceFromPool($value)
{
if (Propel::isInstancePoolingEnabled() && null !== $value) {
if (is_object($value) && $value instanceof \Alchemy\Component\Cerberus\Model\RolePermission) {
$key = serialize(array((string) $value->getRoleId(), (string) $value->getPermissionId()));
} elseif (is_array($value) && count($value) === 2) {
// assume we've been passed a primary key";
$key = serialize(array((string) $value[0], (string) $value[1]));
} elseif ($value instanceof Criteria) {
self::$instances = [];
return;
} else {
$e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or \Alchemy\Component\Cerberus\Model\RolePermission object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value, true)));
throw $e;
}
unset(self::$instances[$key]);
}
}
|
php
|
public static function removeInstanceFromPool($value)
{
if (Propel::isInstancePoolingEnabled() && null !== $value) {
if (is_object($value) && $value instanceof \Alchemy\Component\Cerberus\Model\RolePermission) {
$key = serialize(array((string) $value->getRoleId(), (string) $value->getPermissionId()));
} elseif (is_array($value) && count($value) === 2) {
// assume we've been passed a primary key";
$key = serialize(array((string) $value[0], (string) $value[1]));
} elseif ($value instanceof Criteria) {
self::$instances = [];
return;
} else {
$e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or \Alchemy\Component\Cerberus\Model\RolePermission object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value, true)));
throw $e;
}
unset(self::$instances[$key]);
}
}
|
[
"public",
"static",
"function",
"removeInstanceFromPool",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"Propel",
"::",
"isInstancePoolingEnabled",
"(",
")",
"&&",
"null",
"!==",
"$",
"value",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"$",
"value",
"instanceof",
"\\",
"Alchemy",
"\\",
"Component",
"\\",
"Cerberus",
"\\",
"Model",
"\\",
"RolePermission",
")",
"{",
"$",
"key",
"=",
"serialize",
"(",
"array",
"(",
"(",
"string",
")",
"$",
"value",
"->",
"getRoleId",
"(",
")",
",",
"(",
"string",
")",
"$",
"value",
"->",
"getPermissionId",
"(",
")",
")",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"count",
"(",
"$",
"value",
")",
"===",
"2",
")",
"{",
"// assume we've been passed a primary key\";",
"$",
"key",
"=",
"serialize",
"(",
"array",
"(",
"(",
"string",
")",
"$",
"value",
"[",
"0",
"]",
",",
"(",
"string",
")",
"$",
"value",
"[",
"1",
"]",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"Criteria",
")",
"{",
"self",
"::",
"$",
"instances",
"=",
"[",
"]",
";",
"return",
";",
"}",
"else",
"{",
"$",
"e",
"=",
"new",
"PropelException",
"(",
"\"Invalid value passed to removeInstanceFromPool(). Expected primary key or \\Alchemy\\Component\\Cerberus\\Model\\RolePermission object; got \"",
".",
"(",
"is_object",
"(",
"$",
"value",
")",
"?",
"get_class",
"(",
"$",
"value",
")",
".",
"' object.'",
":",
"var_export",
"(",
"$",
"value",
",",
"true",
")",
")",
")",
";",
"throw",
"$",
"e",
";",
"}",
"unset",
"(",
"self",
"::",
"$",
"instances",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}"
] |
Removes an object from the instance pool.
Propel keeps cached copies of objects in an instance pool when they are retrieved
from the database. In some cases -- especially when you override doDelete
methods in your stub classes -- you may need to explicitly remove objects
from the cache in order to prevent returning objects that no longer exist.
@param mixed $value A \Alchemy\Component\Cerberus\Model\RolePermission object or a primary key value.
|
[
"Removes",
"an",
"object",
"from",
"the",
"instance",
"pool",
"."
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Map/RolePermissionTableMap.php#L180-L200
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Map/RolePermissionTableMap.php
|
RolePermissionTableMap.addSelectColumns
|
public static function addSelectColumns(Criteria $criteria, $alias = null)
{
if (null === $alias) {
$criteria->addSelectColumn(RolePermissionTableMap::COL_ROLE_ID);
$criteria->addSelectColumn(RolePermissionTableMap::COL_PERMISSION_ID);
} else {
$criteria->addSelectColumn($alias . '.ROLE_ID');
$criteria->addSelectColumn($alias . '.PERMISSION_ID');
}
}
|
php
|
public static function addSelectColumns(Criteria $criteria, $alias = null)
{
if (null === $alias) {
$criteria->addSelectColumn(RolePermissionTableMap::COL_ROLE_ID);
$criteria->addSelectColumn(RolePermissionTableMap::COL_PERMISSION_ID);
} else {
$criteria->addSelectColumn($alias . '.ROLE_ID');
$criteria->addSelectColumn($alias . '.PERMISSION_ID');
}
}
|
[
"public",
"static",
"function",
"addSelectColumns",
"(",
"Criteria",
"$",
"criteria",
",",
"$",
"alias",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"alias",
")",
"{",
"$",
"criteria",
"->",
"addSelectColumn",
"(",
"RolePermissionTableMap",
"::",
"COL_ROLE_ID",
")",
";",
"$",
"criteria",
"->",
"addSelectColumn",
"(",
"RolePermissionTableMap",
"::",
"COL_PERMISSION_ID",
")",
";",
"}",
"else",
"{",
"$",
"criteria",
"->",
"addSelectColumn",
"(",
"$",
"alias",
".",
"'.ROLE_ID'",
")",
";",
"$",
"criteria",
"->",
"addSelectColumn",
"(",
"$",
"alias",
".",
"'.PERMISSION_ID'",
")",
";",
"}",
"}"
] |
Add all the columns needed to create a new object.
Note: any columns that were marked with lazyLoad="true" in the
XML schema will not be added to the select list and only loaded
on demand.
@param Criteria $criteria object containing the columns to add.
@param string $alias optional table alias
@throws PropelException Any exceptions caught during processing will be
rethrown wrapped into a PropelException.
|
[
"Add",
"all",
"the",
"columns",
"needed",
"to",
"create",
"a",
"new",
"object",
"."
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Map/RolePermissionTableMap.php#L349-L358
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Map/RolePermissionTableMap.php
|
RolePermissionTableMap.buildTableMap
|
public static function buildTableMap()
{
$dbMap = Propel::getServiceContainer()->getDatabaseMap(RolePermissionTableMap::DATABASE_NAME);
if (!$dbMap->hasTable(RolePermissionTableMap::TABLE_NAME)) {
$dbMap->addTableObject(new RolePermissionTableMap());
}
}
|
php
|
public static function buildTableMap()
{
$dbMap = Propel::getServiceContainer()->getDatabaseMap(RolePermissionTableMap::DATABASE_NAME);
if (!$dbMap->hasTable(RolePermissionTableMap::TABLE_NAME)) {
$dbMap->addTableObject(new RolePermissionTableMap());
}
}
|
[
"public",
"static",
"function",
"buildTableMap",
"(",
")",
"{",
"$",
"dbMap",
"=",
"Propel",
"::",
"getServiceContainer",
"(",
")",
"->",
"getDatabaseMap",
"(",
"RolePermissionTableMap",
"::",
"DATABASE_NAME",
")",
";",
"if",
"(",
"!",
"$",
"dbMap",
"->",
"hasTable",
"(",
"RolePermissionTableMap",
"::",
"TABLE_NAME",
")",
")",
"{",
"$",
"dbMap",
"->",
"addTableObject",
"(",
"new",
"RolePermissionTableMap",
"(",
")",
")",
";",
"}",
"}"
] |
Add a TableMap instance to the database for this tableMap class.
|
[
"Add",
"a",
"TableMap",
"instance",
"to",
"the",
"database",
"for",
"this",
"tableMap",
"class",
"."
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Map/RolePermissionTableMap.php#L375-L381
|
phpalchemy/cerberus
|
src/Alchemy/Component/Cerberus/Model/Map/RolePermissionTableMap.php
|
RolePermissionTableMap.doInsert
|
public static function doInsert($criteria, ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(RolePermissionTableMap::DATABASE_NAME);
}
if ($criteria instanceof Criteria) {
$criteria = clone $criteria; // rename for clarity
} else {
$criteria = $criteria->buildCriteria(); // build Criteria from RolePermission object
}
// Set the correct dbName
$query = RolePermissionQuery::create()->mergeWith($criteria);
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
return $con->transaction(function () use ($con, $query) {
return $query->doInsert($con);
});
}
|
php
|
public static function doInsert($criteria, ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(RolePermissionTableMap::DATABASE_NAME);
}
if ($criteria instanceof Criteria) {
$criteria = clone $criteria; // rename for clarity
} else {
$criteria = $criteria->buildCriteria(); // build Criteria from RolePermission object
}
// Set the correct dbName
$query = RolePermissionQuery::create()->mergeWith($criteria);
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
return $con->transaction(function () use ($con, $query) {
return $query->doInsert($con);
});
}
|
[
"public",
"static",
"function",
"doInsert",
"(",
"$",
"criteria",
",",
"ConnectionInterface",
"$",
"con",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"con",
")",
"{",
"$",
"con",
"=",
"Propel",
"::",
"getServiceContainer",
"(",
")",
"->",
"getWriteConnection",
"(",
"RolePermissionTableMap",
"::",
"DATABASE_NAME",
")",
";",
"}",
"if",
"(",
"$",
"criteria",
"instanceof",
"Criteria",
")",
"{",
"$",
"criteria",
"=",
"clone",
"$",
"criteria",
";",
"// rename for clarity",
"}",
"else",
"{",
"$",
"criteria",
"=",
"$",
"criteria",
"->",
"buildCriteria",
"(",
")",
";",
"// build Criteria from RolePermission object",
"}",
"// Set the correct dbName",
"$",
"query",
"=",
"RolePermissionQuery",
"::",
"create",
"(",
")",
"->",
"mergeWith",
"(",
"$",
"criteria",
")",
";",
"// use transaction because $criteria could contain info",
"// for more than one table (I guess, conceivably)",
"return",
"$",
"con",
"->",
"transaction",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"con",
",",
"$",
"query",
")",
"{",
"return",
"$",
"query",
"->",
"doInsert",
"(",
"$",
"con",
")",
";",
"}",
")",
";",
"}"
] |
Performs an INSERT on the database, given a RolePermission or Criteria object.
@param mixed $criteria Criteria or RolePermission object containing data that is used to create the INSERT statement.
@param ConnectionInterface $con the ConnectionInterface connection to use
@return mixed The new primary key.
@throws PropelException Any exceptions caught during processing will be
rethrown wrapped into a PropelException.
|
[
"Performs",
"an",
"INSERT",
"on",
"the",
"database",
"given",
"a",
"RolePermission",
"or",
"Criteria",
"object",
"."
] |
train
|
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Map/RolePermissionTableMap.php#L454-L475
|
gregorybesson/PlaygroundCore
|
src/Filter/Slugify.php
|
Slugify.filter
|
public function filter($value)
{
setlocale(LC_CTYPE, 'en_US.UTF-8');
//@HotFix : en attendant Bacon/BaconStringUtils
$unwanted_array = array('Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E',
'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U',
'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c',
'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o',
'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'Ğ'=>'G', 'İ'=>'I', 'Ş'=>'S', 'ğ'=>'g', 'ı'=>'i',
'ş'=>'s', 'ü'=>'u', 'ă'=>'a', 'Ă'=>'A', 'ș'=>'s', 'Ș'=>'S', 'ț'=>'t', 'Ț'=>'T', 'Α' => 'A', 'Β' => 'B', 'Γ' => 'G', 'Δ' => 'D', 'Ε' => 'E',
'Ζ' => 'Z', 'Η' => 'H', 'Θ' => '8','Ι' => 'I', 'Κ' => 'K', 'Λ' => 'L', 'Μ' => 'M', 'Ν' => 'N', 'Ξ' => '3', 'Ο' => 'O', 'Π' => 'P','Ρ' => 'R',
'Σ' => 'S', 'Τ' => 'T', 'Υ' => 'Y', 'Φ' => 'F', 'Χ' => 'X', 'Ψ' => 'PS', 'Ω' => 'W','Ά' => 'A', 'Έ' => 'E', 'Ί' => 'I', 'Ό' => 'O', 'Ύ' => 'Y',
'Ή' => 'H', 'Ώ' => 'W', 'Ϊ' => 'I','Ϋ' => 'Y','α' => 'a', 'β' => 'b', 'γ' => 'g', 'δ' => 'd', 'ε' => 'e', 'ζ' => 'z', 'η' => 'h', 'θ' => '8',
'ι' => 'i', 'κ' => 'k', 'λ' => 'l', 'μ' => 'm', 'ν' => 'n', 'ξ' => '3', 'ο' => 'o', 'π' => 'p','ρ' => 'r', 'σ' => 's', 'τ' => 't', 'υ' => 'y',
'φ' => 'f', 'χ' => 'x', 'ψ' => 'ps', 'ω' => 'w','ά' => 'a', 'έ' => 'e', 'ί' => 'i', 'ό' => 'o', 'ύ' => 'y', 'ή' => 'h', 'ώ' => 'w', 'ς' => 's',
'ϊ' => 'i', 'ΰ' => 'y', 'ϋ' => 'y', 'ΐ' => 'i', );
$value = strtr($value, $unwanted_array);
$value = iconv("UTF-8", "ASCII//TRANSLIT", $value);
$value = strtolower($value);
$value = str_replace("'", '', $value);
$value = preg_replace('([^a-zA-Z0-9_-]+)', '-', $value);
$value = preg_replace('(-{2,})', '-', $value);
$value = trim($value, '-');
return $value;
}
|
php
|
public function filter($value)
{
setlocale(LC_CTYPE, 'en_US.UTF-8');
//@HotFix : en attendant Bacon/BaconStringUtils
$unwanted_array = array('Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E',
'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U',
'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c',
'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o',
'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'Ğ'=>'G', 'İ'=>'I', 'Ş'=>'S', 'ğ'=>'g', 'ı'=>'i',
'ş'=>'s', 'ü'=>'u', 'ă'=>'a', 'Ă'=>'A', 'ș'=>'s', 'Ș'=>'S', 'ț'=>'t', 'Ț'=>'T', 'Α' => 'A', 'Β' => 'B', 'Γ' => 'G', 'Δ' => 'D', 'Ε' => 'E',
'Ζ' => 'Z', 'Η' => 'H', 'Θ' => '8','Ι' => 'I', 'Κ' => 'K', 'Λ' => 'L', 'Μ' => 'M', 'Ν' => 'N', 'Ξ' => '3', 'Ο' => 'O', 'Π' => 'P','Ρ' => 'R',
'Σ' => 'S', 'Τ' => 'T', 'Υ' => 'Y', 'Φ' => 'F', 'Χ' => 'X', 'Ψ' => 'PS', 'Ω' => 'W','Ά' => 'A', 'Έ' => 'E', 'Ί' => 'I', 'Ό' => 'O', 'Ύ' => 'Y',
'Ή' => 'H', 'Ώ' => 'W', 'Ϊ' => 'I','Ϋ' => 'Y','α' => 'a', 'β' => 'b', 'γ' => 'g', 'δ' => 'd', 'ε' => 'e', 'ζ' => 'z', 'η' => 'h', 'θ' => '8',
'ι' => 'i', 'κ' => 'k', 'λ' => 'l', 'μ' => 'm', 'ν' => 'n', 'ξ' => '3', 'ο' => 'o', 'π' => 'p','ρ' => 'r', 'σ' => 's', 'τ' => 't', 'υ' => 'y',
'φ' => 'f', 'χ' => 'x', 'ψ' => 'ps', 'ω' => 'w','ά' => 'a', 'έ' => 'e', 'ί' => 'i', 'ό' => 'o', 'ύ' => 'y', 'ή' => 'h', 'ώ' => 'w', 'ς' => 's',
'ϊ' => 'i', 'ΰ' => 'y', 'ϋ' => 'y', 'ΐ' => 'i', );
$value = strtr($value, $unwanted_array);
$value = iconv("UTF-8", "ASCII//TRANSLIT", $value);
$value = strtolower($value);
$value = str_replace("'", '', $value);
$value = preg_replace('([^a-zA-Z0-9_-]+)', '-', $value);
$value = preg_replace('(-{2,})', '-', $value);
$value = trim($value, '-');
return $value;
}
|
[
"public",
"function",
"filter",
"(",
"$",
"value",
")",
"{",
"setlocale",
"(",
"LC_CTYPE",
",",
"'en_US.UTF-8'",
")",
";",
"//@HotFix : en attendant Bacon/BaconStringUtils",
"$",
"unwanted_array",
"=",
"array",
"(",
"'Š'=",
">'",
"S',",
" ",
"š'=>",
"'s",
"', ",
"'",
"'=>'",
"Z'",
", '",
"ž",
"=>'z",
"',",
" 'À",
"'",
">'A'",
", ",
"'Á'",
"=",
"'A',",
" '",
"Â'=",
">",
"A', ",
"'Ã",
"'=>",
"'",
"', '",
"Ä'",
"=>'",
"A",
", 'Å",
"'=",
">'A",
"'",
" 'Æ'",
"=>",
"'A'",
",",
"'Ç'=",
">'",
"C',",
" ",
"È'=>",
"'E",
"', ",
"'",
"'=>'",
"E'",
",",
"",
"",
"",
"",
"",
"'Ê'=",
">'",
"E',",
" ",
"Ë'=>",
"'E",
"', ",
"'",
"'=>'",
"I'",
", '",
"Í",
"=>'I",
"',",
" 'Î",
"'",
">'I'",
", ",
"'Ï'",
"=",
"'I',",
" '",
"Ñ'=",
">",
"N', ",
"'Ò",
"'=>",
"'",
"', '",
"Ó'",
"=>'",
"O",
", 'Ô",
"'=",
">'O",
"'",
" 'Õ'",
"=>",
"'O'",
",",
"'Ö'=",
">'",
"O',",
" ",
"Ø'=>",
"'O",
"', ",
"'",
"'=>'",
"U'",
",",
"",
"",
"",
"",
"",
"'Ú'=",
">'",
"U',",
" ",
"Û'=>",
"'U",
"', ",
"'",
"'=>'",
"U'",
", '",
"Ý",
"=>'Y",
"',",
" 'Þ",
"'",
">'B'",
", ",
"'ß'",
"=",
"'Ss'",
", ",
"'à'=",
">",
"a', ",
"'á",
"'=>",
"'",
"', '",
"â'",
"=>'",
"a",
", 'ã",
"'=",
">'a",
"'",
" 'ä'",
"=>",
"'a'",
",",
"'å'=",
">'",
"a',",
" ",
"æ'=>",
"'a",
"', ",
"'",
"'=>'",
"c'",
",",
"",
"",
"",
"",
"",
"'è'=",
">'",
"e',",
" ",
"é'=>",
"'e",
"', ",
"'",
"'=>'",
"e'",
", '",
"ë",
"=>'e",
"',",
" 'ì",
"'",
">'i'",
", ",
"'í'",
"=",
"'i',",
" '",
"î'=",
">",
"i', ",
"'ï",
"'=>",
"'",
"', '",
"ð'",
"=>'",
"o",
", 'ñ",
"'=",
">'n",
"'",
" 'ò'",
"=>",
"'o'",
",",
"'ó'=",
">'",
"o',",
" ",
"ô'=>",
"'o",
"', ",
"'",
"'=>'",
"o'",
",",
"",
"",
"",
"",
"",
"'ö'=",
">'",
"o',",
" ",
"ø'=>",
"'o",
"', ",
"'",
"'=>'",
"u'",
", '",
"ú",
"=>'u",
"',",
" 'û",
"'",
">'u'",
", ",
"'ý'",
"=",
"'y',",
" '",
"ý'=",
">",
"y', ",
"'þ",
"'=>",
"'",
"', '",
"ÿ'",
"=>'",
"y",
", 'Ğ",
"'=",
">'G",
"'",
" 'İ'",
"=>",
"'I'",
",",
"'Ş'=",
">'",
"S',",
" ",
"ğ'=>",
"'g",
"', ",
"'",
"'=>'",
"i'",
",",
"",
"",
"",
"",
"",
"'ş'=",
">'",
"s',",
" ",
"ü'=>",
"'u",
"', ",
"'",
"'=>'",
"a'",
", '",
"Ă",
"=>'A",
"',",
" 'ș",
"'",
">'s'",
", ",
"'Ș'",
"=",
"'S',",
" '",
"ț'=",
">",
"t', ",
"'Ț",
"'=>",
"'",
"', '",
"Α'",
" =>",
" ",
"A', ",
"Β'",
"=> ",
"'",
"', '",
"' ",
"> '",
"G",
", 'Δ",
" =",
" 'D",
"'",
" 'Ε'",
"=>",
"'E'",
",",
"",
"",
"",
"",
"'Ζ' ",
"> ",
"Z',",
" ",
"Η' =",
" '",
"', ",
"'",
"' =>",
"'8",
",'Ι",
"'",
" => ",
"I'",
" 'Κ",
"'",
"=> '",
"',",
"'Λ'",
" ",
"> 'L",
", ",
"Μ' ",
"=",
" 'M'",
" '",
"' =",
">",
"'N',",
"'Ξ",
" =>",
" ",
"3', ",
"Ο'",
"=> ",
"'",
"', '",
"' ",
"> '",
"P",
",'Ρ'",
"=>",
"'R'",
",",
"",
"",
"",
"",
"'Σ' ",
"> ",
"S',",
" ",
"Τ' =",
" '",
"', ",
"'",
"' =>",
"'Y",
", '",
"Φ",
" => ",
"F'",
" 'Χ",
"'",
"=> '",
"',",
"'Ψ'",
" ",
"> 'P",
"',",
"'Ω' ",
"=",
" 'W'",
"'Ά",
" =>",
" ",
"'A',",
"'Έ",
" =>",
" ",
"E', ",
"Ί'",
"=> ",
"'",
"', '",
"' ",
"> '",
"O",
", 'Ύ",
" =",
" 'Y",
"'",
"",
"",
"",
"",
"'Ή' ",
"> ",
"H',",
" ",
"Ώ' =",
" '",
"', ",
"'",
"' =>",
"'I",
",'Ϋ",
"'",
" => ",
"Y'",
"'α'",
" ",
"=> '",
"',",
"'β'",
" ",
"> 'b",
", ",
"γ' ",
"=",
" 'g'",
" '",
"' =",
">",
"'d',",
"'ε",
" =>",
" ",
"e', ",
"ζ'",
"=> ",
"'",
"', '",
"' ",
"> '",
"h",
", 'θ",
" =",
" '8",
"'",
"",
"",
"",
"",
"'ι' ",
"> ",
"i',",
" ",
"κ' =",
" '",
"', ",
"'",
"' =>",
"'l",
", '",
"μ",
" => ",
"m'",
" 'ν",
"'",
"=> '",
"',",
"'ξ'",
" ",
"> '3",
", ",
"ο' ",
"=",
" 'o'",
" '",
"' =",
">",
"'p',",
"ρ'",
"=> ",
"'",
"r', ",
"σ'",
"=> ",
"'",
"', '",
"' ",
"> '",
"t",
", 'υ",
" =",
" 'y",
"'",
"",
"",
"",
"",
"'φ' ",
"> ",
"f',",
" ",
"χ' =",
" '",
"', ",
"'",
"' =>",
"'p",
"', '",
"ω",
" => ",
"w'",
"'ά'",
" ",
"=> '",
"',",
"'έ'",
" ",
"> 'e",
", ",
"ί' ",
"=",
" 'i'",
" '",
"' =",
">",
"'o',",
"'ύ",
" =>",
" ",
"y', ",
"ή'",
"=> ",
"'",
"', '",
"' ",
"> '",
"w",
", 'ς",
" =",
" 's",
"'",
"",
"",
"",
"",
"'ϊ' ",
"> ",
"i',",
" ",
"ΰ' =",
" '",
"', ",
"'",
"' =>",
"'y",
", '",
"ΐ",
" => ",
"i'",
" );",
"",
"",
"",
"$",
"value",
"=",
"strtr",
"(",
"$",
"value",
",",
"$",
"unwanted_array",
")",
";",
"$",
"value",
"=",
"iconv",
"(",
"\"UTF-8\"",
",",
"\"ASCII//TRANSLIT\"",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"strtolower",
"(",
"$",
"value",
")",
";",
"$",
"value",
"=",
"str_replace",
"(",
"\"'\"",
",",
"''",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"preg_replace",
"(",
"'([^a-zA-Z0-9_-]+)'",
",",
"'-'",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"preg_replace",
"(",
"'(-{2,})'",
",",
"'-'",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"trim",
"(",
"$",
"value",
",",
"'-'",
")",
";",
"return",
"$",
"value",
";",
"}"
] |
Defined by Zend\Filter\FilterInterface
Returns the string $value, converting characters to lowercase as necessary
@param string $value
@return string
|
[
"Defined",
"by",
"Zend",
"\\",
"Filter",
"\\",
"FilterInterface"
] |
train
|
https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/Filter/Slugify.php#L43-L70
|
huasituo/hstcms
|
src/Http/Controllers/Manage/AuthController.php
|
AuthController.login
|
public function login()
{
if (Session::get('manager')) {
return redirect()->route('manageIndex');
}
$this->addMessage(hst_lang('hstcms::manage.login.title'), 'seo_title');
return $this->loadTemplate('login');
}
|
php
|
public function login()
{
if (Session::get('manager')) {
return redirect()->route('manageIndex');
}
$this->addMessage(hst_lang('hstcms::manage.login.title'), 'seo_title');
return $this->loadTemplate('login');
}
|
[
"public",
"function",
"login",
"(",
")",
"{",
"if",
"(",
"Session",
"::",
"get",
"(",
"'manager'",
")",
")",
"{",
"return",
"redirect",
"(",
")",
"->",
"route",
"(",
"'manageIndex'",
")",
";",
"}",
"$",
"this",
"->",
"addMessage",
"(",
"hst_lang",
"(",
"'hstcms::manage.login.title'",
")",
",",
"'seo_title'",
")",
";",
"return",
"$",
"this",
"->",
"loadTemplate",
"(",
"'login'",
")",
";",
"}"
] |
后台登录页面
|
[
"后台登录页面"
] |
train
|
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Http/Controllers/Manage/AuthController.php#L29-L36
|
jan-dolata/crude-crud
|
src/Http/Requests/FileRequest.php
|
FileRequest.authorize
|
public function authorize()
{
$crude = CrudeInstance::get($this->input('crudeName'));
if ($crude == null)
return false;
if (! $crude instanceof \JanDolata\CrudeCRUD\Engine\Interfaces\ListInterface)
return false;
if (! $crude instanceof \JanDolata\CrudeCRUD\Engine\Interfaces\WithFileInterface)
return false;
return true;
}
|
php
|
public function authorize()
{
$crude = CrudeInstance::get($this->input('crudeName'));
if ($crude == null)
return false;
if (! $crude instanceof \JanDolata\CrudeCRUD\Engine\Interfaces\ListInterface)
return false;
if (! $crude instanceof \JanDolata\CrudeCRUD\Engine\Interfaces\WithFileInterface)
return false;
return true;
}
|
[
"public",
"function",
"authorize",
"(",
")",
"{",
"$",
"crude",
"=",
"CrudeInstance",
"::",
"get",
"(",
"$",
"this",
"->",
"input",
"(",
"'crudeName'",
")",
")",
";",
"if",
"(",
"$",
"crude",
"==",
"null",
")",
"return",
"false",
";",
"if",
"(",
"!",
"$",
"crude",
"instanceof",
"\\",
"JanDolata",
"\\",
"CrudeCRUD",
"\\",
"Engine",
"\\",
"Interfaces",
"\\",
"ListInterface",
")",
"return",
"false",
";",
"if",
"(",
"!",
"$",
"crude",
"instanceof",
"\\",
"JanDolata",
"\\",
"CrudeCRUD",
"\\",
"Engine",
"\\",
"Interfaces",
"\\",
"WithFileInterface",
")",
"return",
"false",
";",
"return",
"true",
";",
"}"
] |
Determine if the user is authorized to make this request.
@return bool
|
[
"Determine",
"if",
"the",
"user",
"is",
"authorized",
"to",
"make",
"this",
"request",
"."
] |
train
|
https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Http/Requests/FileRequest.php#L16-L30
|
VDMi/Guzzle-oAuth
|
src/GuzzleOauth/Plugin/Oauth2/Oauth2Plugin.php
|
Oauth2Plugin.onRequestBeforeSend
|
public function onRequestBeforeSend(Event $event)
{
if (!strlen($this->config['access_token'])) {
return;
}
switch ($this->config['authorize_location']) {
case 'query':
$event['request']->getQuery()->set(
$this->config['query_param_key'],
$this->config['access_token']
);
break;
default:
$authorizationParams = array(
'access_token' => $this->config['access_token'],
'token_type' => $this->config['token_type'],
);
$event['request']->setHeader(
'Authorization',
$this->buildAuthorizationHeader($authorizationParams)
);
break;
}
}
|
php
|
public function onRequestBeforeSend(Event $event)
{
if (!strlen($this->config['access_token'])) {
return;
}
switch ($this->config['authorize_location']) {
case 'query':
$event['request']->getQuery()->set(
$this->config['query_param_key'],
$this->config['access_token']
);
break;
default:
$authorizationParams = array(
'access_token' => $this->config['access_token'],
'token_type' => $this->config['token_type'],
);
$event['request']->setHeader(
'Authorization',
$this->buildAuthorizationHeader($authorizationParams)
);
break;
}
}
|
[
"public",
"function",
"onRequestBeforeSend",
"(",
"Event",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"strlen",
"(",
"$",
"this",
"->",
"config",
"[",
"'access_token'",
"]",
")",
")",
"{",
"return",
";",
"}",
"switch",
"(",
"$",
"this",
"->",
"config",
"[",
"'authorize_location'",
"]",
")",
"{",
"case",
"'query'",
":",
"$",
"event",
"[",
"'request'",
"]",
"->",
"getQuery",
"(",
")",
"->",
"set",
"(",
"$",
"this",
"->",
"config",
"[",
"'query_param_key'",
"]",
",",
"$",
"this",
"->",
"config",
"[",
"'access_token'",
"]",
")",
";",
"break",
";",
"default",
":",
"$",
"authorizationParams",
"=",
"array",
"(",
"'access_token'",
"=>",
"$",
"this",
"->",
"config",
"[",
"'access_token'",
"]",
",",
"'token_type'",
"=>",
"$",
"this",
"->",
"config",
"[",
"'token_type'",
"]",
",",
")",
";",
"$",
"event",
"[",
"'request'",
"]",
"->",
"setHeader",
"(",
"'Authorization'",
",",
"$",
"this",
"->",
"buildAuthorizationHeader",
"(",
"$",
"authorizationParams",
")",
")",
";",
"break",
";",
"}",
"}"
] |
Request before-send event handler
@param Event $event Event received
@return array
|
[
"Request",
"before",
"-",
"send",
"event",
"handler"
] |
train
|
https://github.com/VDMi/Guzzle-oAuth/blob/e2b2561e4e402e13ba605082bf768b29942f90cb/src/GuzzleOauth/Plugin/Oauth2/Oauth2Plugin.php#L47-L73
|
larakit/lk-staticfiles
|
src/StaticFiles/Manager.php
|
Manager.package
|
static function package($package) {
if(!isset(self::$packages[$package])) {
self::$packages[$package] = new Package($package);
}
return self::$packages[$package];
}
|
php
|
static function package($package) {
if(!isset(self::$packages[$package])) {
self::$packages[$package] = new Package($package);
}
return self::$packages[$package];
}
|
[
"static",
"function",
"package",
"(",
"$",
"package",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"packages",
"[",
"$",
"package",
"]",
")",
")",
"{",
"self",
"::",
"$",
"packages",
"[",
"$",
"package",
"]",
"=",
"new",
"Package",
"(",
"$",
"package",
")",
";",
"}",
"return",
"self",
"::",
"$",
"packages",
"[",
"$",
"package",
"]",
";",
"}"
] |
@param $package
@return Package
|
[
"@param",
"$package"
] |
train
|
https://github.com/larakit/lk-staticfiles/blob/1ee718b1f3a00c29c46b06c2f501413599b0335a/src/StaticFiles/Manager.php#L19-L25
|
braincrafted/arrayquery
|
src/Braincrafted/ArrayQuery/Evaluation.php
|
Evaluation.evaluateFilter
|
protected function evaluateFilter($value, $filter)
{
$filter = explode(' ', $filter, 2);
if (1 === count($filter)) {
$args = [];
$filter = $filter[0];
} else {
$args = array_map('trim', explode(',', $filter[1]));
$filter = $filter[0];
}
if (false === isset($this->filters[$filter])) {
throw new UnkownFilterException(sprintf('The filter "%s" does not exist.', $filter));
}
return $this->filters[$filter]->evaluate($value, $args);
}
|
php
|
protected function evaluateFilter($value, $filter)
{
$filter = explode(' ', $filter, 2);
if (1 === count($filter)) {
$args = [];
$filter = $filter[0];
} else {
$args = array_map('trim', explode(',', $filter[1]));
$filter = $filter[0];
}
if (false === isset($this->filters[$filter])) {
throw new UnkownFilterException(sprintf('The filter "%s" does not exist.', $filter));
}
return $this->filters[$filter]->evaluate($value, $args);
}
|
[
"protected",
"function",
"evaluateFilter",
"(",
"$",
"value",
",",
"$",
"filter",
")",
"{",
"$",
"filter",
"=",
"explode",
"(",
"' '",
",",
"$",
"filter",
",",
"2",
")",
";",
"if",
"(",
"1",
"===",
"count",
"(",
"$",
"filter",
")",
")",
"{",
"$",
"args",
"=",
"[",
"]",
";",
"$",
"filter",
"=",
"$",
"filter",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"$",
"args",
"=",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"','",
",",
"$",
"filter",
"[",
"1",
"]",
")",
")",
";",
"$",
"filter",
"=",
"$",
"filter",
"[",
"0",
"]",
";",
"}",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"this",
"->",
"filters",
"[",
"$",
"filter",
"]",
")",
")",
"{",
"throw",
"new",
"UnkownFilterException",
"(",
"sprintf",
"(",
"'The filter \"%s\" does not exist.'",
",",
"$",
"filter",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"filters",
"[",
"$",
"filter",
"]",
"->",
"evaluate",
"(",
"$",
"value",
",",
"$",
"args",
")",
";",
"}"
] |
Evaluates the given value with the given filter.
@param mixed $value
@param string|array $filter
@return mixed
@throws Braincrafted\ArrayQuery\Exception\UnkownFilterException if a filter does not exist.
|
[
"Evaluates",
"the",
"given",
"value",
"with",
"the",
"given",
"filter",
"."
] |
train
|
https://github.com/braincrafted/arrayquery/blob/8b0c44ee76cea796589422f52e2f7130676b9bd1/src/Braincrafted/ArrayQuery/Evaluation.php#L36-L52
|
heyday/heystack
|
src/Processor/HandlerTrait.php
|
HandlerTrait.getProcessor
|
public function getProcessor($name)
{
return isset($this->processors[$name]) ? $this->processors[$name] : false;
}
|
php
|
public function getProcessor($name)
{
return isset($this->processors[$name]) ? $this->processors[$name] : false;
}
|
[
"public",
"function",
"getProcessor",
"(",
"$",
"name",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"processors",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"processors",
"[",
"$",
"name",
"]",
":",
"false",
";",
"}"
] |
Return a processor by an identifier if it exists
@param string $name The processor identifier
@return mixed The processor if it exists
|
[
"Return",
"a",
"processor",
"by",
"an",
"identifier",
"if",
"it",
"exists"
] |
train
|
https://github.com/heyday/heystack/blob/2c051933f8c532d0a9a23be6ee1ff5c619e47dfe/src/Processor/HandlerTrait.php#L27-L30
|
crossjoin/Css
|
src/Crossjoin/Css/Format/Rule/AtDocument/DocumentRule.php
|
DocumentRule.setUrl
|
public function setUrl($url)
{
if (is_string($url)) {
$this->url = $url;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($url) . "' for argument 'url' given. String expected."
);
}
}
|
php
|
public function setUrl($url)
{
if (is_string($url)) {
$this->url = $url;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($url) . "' for argument 'url' given. String expected."
);
}
}
|
[
"public",
"function",
"setUrl",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"url",
")",
")",
"{",
"$",
"this",
"->",
"url",
"=",
"$",
"url",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid type '\"",
".",
"gettype",
"(",
"$",
"url",
")",
".",
"\"' for argument 'url' given. String expected.\"",
")",
";",
"}",
"}"
] |
Sets the document URL filter.
@param string $url
|
[
"Sets",
"the",
"document",
"URL",
"filter",
"."
] |
train
|
https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Format/Rule/AtDocument/DocumentRule.php#L52-L61
|
crossjoin/Css
|
src/Crossjoin/Css/Format/Rule/AtDocument/DocumentRule.php
|
DocumentRule.setUrlPrefix
|
public function setUrlPrefix($urlPrefix)
{
if (is_string($urlPrefix)) {
$this->urlPrefix = $urlPrefix;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($urlPrefix) . "' for argument 'urlPrefix' given. String expected."
);
}
}
|
php
|
public function setUrlPrefix($urlPrefix)
{
if (is_string($urlPrefix)) {
$this->urlPrefix = $urlPrefix;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($urlPrefix) . "' for argument 'urlPrefix' given. String expected."
);
}
}
|
[
"public",
"function",
"setUrlPrefix",
"(",
"$",
"urlPrefix",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"urlPrefix",
")",
")",
"{",
"$",
"this",
"->",
"urlPrefix",
"=",
"$",
"urlPrefix",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid type '\"",
".",
"gettype",
"(",
"$",
"urlPrefix",
")",
".",
"\"' for argument 'urlPrefix' given. String expected.\"",
")",
";",
"}",
"}"
] |
Sets the document URL prefix filter.
@param string $urlPrefix
|
[
"Sets",
"the",
"document",
"URL",
"prefix",
"filter",
"."
] |
train
|
https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Format/Rule/AtDocument/DocumentRule.php#L78-L87
|
crossjoin/Css
|
src/Crossjoin/Css/Format/Rule/AtDocument/DocumentRule.php
|
DocumentRule.setDomain
|
public function setDomain($domain)
{
if (is_string($domain)) {
$this->domain = $domain;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($domain) . "' for argument 'domain' given. String expected."
);
}
}
|
php
|
public function setDomain($domain)
{
if (is_string($domain)) {
$this->domain = $domain;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($domain) . "' for argument 'domain' given. String expected."
);
}
}
|
[
"public",
"function",
"setDomain",
"(",
"$",
"domain",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"domain",
")",
")",
"{",
"$",
"this",
"->",
"domain",
"=",
"$",
"domain",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid type '\"",
".",
"gettype",
"(",
"$",
"domain",
")",
".",
"\"' for argument 'domain' given. String expected.\"",
")",
";",
"}",
"}"
] |
Sets the document domain filter.
@param string $domain
|
[
"Sets",
"the",
"document",
"domain",
"filter",
"."
] |
train
|
https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Format/Rule/AtDocument/DocumentRule.php#L104-L113
|
crossjoin/Css
|
src/Crossjoin/Css/Format/Rule/AtDocument/DocumentRule.php
|
DocumentRule.setRegexp
|
public function setRegexp($regexp)
{
if (is_string($regexp)) {
$this->regexp = $regexp;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($regexp) . "' for argument 'regexp' given. String expected."
);
}
}
|
php
|
public function setRegexp($regexp)
{
if (is_string($regexp)) {
$this->regexp = $regexp;
} else {
throw new \InvalidArgumentException(
"Invalid type '" . gettype($regexp) . "' for argument 'regexp' given. String expected."
);
}
}
|
[
"public",
"function",
"setRegexp",
"(",
"$",
"regexp",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"regexp",
")",
")",
"{",
"$",
"this",
"->",
"regexp",
"=",
"$",
"regexp",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid type '\"",
".",
"gettype",
"(",
"$",
"regexp",
")",
".",
"\"' for argument 'regexp' given. String expected.\"",
")",
";",
"}",
"}"
] |
Sets the document regular expression filter.
@param string $regexp
|
[
"Sets",
"the",
"document",
"regular",
"expression",
"filter",
"."
] |
train
|
https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Format/Rule/AtDocument/DocumentRule.php#L130-L139
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.