id int32 0 241k | repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 |
|---|---|---|---|---|---|---|---|---|---|---|---|
31,200 | thejacer87/php-canadapost-api | src/Shipment.php | Shipment.getShipments | public function getShipments(
$from = '',
$to = '',
$tracking_pin = '',
array $options = []
) {
if (!isset($from) && !isset($tracking_pin)) {
$message = 'You must include either a $from date or a $tracking_pin.';
throw new \InvalidArgumentException($message);
}
if (empty($to)) {
$to = date('YmdHs');
}
$this->verifyDates($from, $to);
$query_params = "from={$from}&to{$to}";
if (!empty($tracking_pin)) {
$query_params = "trackingPIN={$tracking_pin}";
}
$response = $this->get(
"rs/{$this->config['customer_number']}/{$this->config['customer_number']}/shipment?" . $query_params,
['Accept' => 'application/vnd.cpc.shipment-v8+xml'],
$options
);
return $response;
} | php | public function getShipments(
$from = '',
$to = '',
$tracking_pin = '',
array $options = []
) {
if (!isset($from) && !isset($tracking_pin)) {
$message = 'You must include either a $from date or a $tracking_pin.';
throw new \InvalidArgumentException($message);
}
if (empty($to)) {
$to = date('YmdHs');
}
$this->verifyDates($from, $to);
$query_params = "from={$from}&to{$to}";
if (!empty($tracking_pin)) {
$query_params = "trackingPIN={$tracking_pin}";
}
$response = $this->get(
"rs/{$this->config['customer_number']}/{$this->config['customer_number']}/shipment?" . $query_params,
['Accept' => 'application/vnd.cpc.shipment-v8+xml'],
$options
);
return $response;
} | [
"public",
"function",
"getShipments",
"(",
"$",
"from",
"=",
"''",
",",
"$",
"to",
"=",
"''",
",",
"$",
"tracking_pin",
"=",
"''",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"from",
")",
"&&",
"!",
"isset",
"(",
"$",
"tracking_pin",
")",
")",
"{",
"$",
"message",
"=",
"'You must include either a $from date or a $tracking_pin.'",
";",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"$",
"message",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"to",
")",
")",
"{",
"$",
"to",
"=",
"date",
"(",
"'YmdHs'",
")",
";",
"}",
"$",
"this",
"->",
"verifyDates",
"(",
"$",
"from",
",",
"$",
"to",
")",
";",
"$",
"query_params",
"=",
"\"from={$from}&to{$to}\"",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"tracking_pin",
")",
")",
"{",
"$",
"query_params",
"=",
"\"trackingPIN={$tracking_pin}\"",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"get",
"(",
"\"rs/{$this->config['customer_number']}/{$this->config['customer_number']}/shipment?\"",
".",
"$",
"query_params",
",",
"[",
"'Accept'",
"=>",
"'application/vnd.cpc.shipment-v8+xml'",
"]",
",",
"$",
"options",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Get Shipments from Canada Post within the specified range.
@param string $from
The beginning range. YmdHs format, eg. 201808282359.
@param string $to
The end range, defaults to current time. YmdHs format, eg. 201808282359.
@param string $tracking_pin
The Tracking PIN of the shipment to retrieve.
@param array $options
The options array.
@see https://www.canadapost.ca/cpo/mc/business/productsservices/developers/services/shippingmanifest/shipments.jsf
@return \DOMDocument|\Psr\Http\Message\StreamInterface
@throws \GuzzleHttp\Exception\GuzzleException | [
"Get",
"Shipments",
"from",
"Canada",
"Post",
"within",
"the",
"specified",
"range",
"."
] | 1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a | https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/Shipment.php#L158-L184 |
31,201 | thejacer87/php-canadapost-api | src/Shipment.php | Shipment.requestShipmentRefund | public function requestShipmentRefund($shipment_id, $email, $options)
{
$content = [
'email' => $email,
];
$xml = Array2XML::createXML(
'non-contract-shipment-refund-request',
$content
);
$envelope = $xml->documentElement;
$envelope->setAttribute(
'xmlns',
'http://www.canadapost.ca/ws/shipment-v8'
);
$payload = $xml->saveXML();
$endpoint = sprintf(
'rs/%s/%s/shipment/%s/refund',
$this->config['customer_number'],
$this->config['customer_number'],
$shipment_id
);
$response = $this->post(
$endpoint,
[
'Content-Type' => 'application/vnd.cpc.shipment-v8+xml',
'Accept' => 'application/vnd.cpc.shipment-v8+xml',
],
$payload,
$options
);
return $response;
} | php | public function requestShipmentRefund($shipment_id, $email, $options)
{
$content = [
'email' => $email,
];
$xml = Array2XML::createXML(
'non-contract-shipment-refund-request',
$content
);
$envelope = $xml->documentElement;
$envelope->setAttribute(
'xmlns',
'http://www.canadapost.ca/ws/shipment-v8'
);
$payload = $xml->saveXML();
$endpoint = sprintf(
'rs/%s/%s/shipment/%s/refund',
$this->config['customer_number'],
$this->config['customer_number'],
$shipment_id
);
$response = $this->post(
$endpoint,
[
'Content-Type' => 'application/vnd.cpc.shipment-v8+xml',
'Accept' => 'application/vnd.cpc.shipment-v8+xml',
],
$payload,
$options
);
return $response;
} | [
"public",
"function",
"requestShipmentRefund",
"(",
"$",
"shipment_id",
",",
"$",
"email",
",",
"$",
"options",
")",
"{",
"$",
"content",
"=",
"[",
"'email'",
"=>",
"$",
"email",
",",
"]",
";",
"$",
"xml",
"=",
"Array2XML",
"::",
"createXML",
"(",
"'non-contract-shipment-refund-request'",
",",
"$",
"content",
")",
";",
"$",
"envelope",
"=",
"$",
"xml",
"->",
"documentElement",
";",
"$",
"envelope",
"->",
"setAttribute",
"(",
"'xmlns'",
",",
"'http://www.canadapost.ca/ws/shipment-v8'",
")",
";",
"$",
"payload",
"=",
"$",
"xml",
"->",
"saveXML",
"(",
")",
";",
"$",
"endpoint",
"=",
"sprintf",
"(",
"'rs/%s/%s/shipment/%s/refund'",
",",
"$",
"this",
"->",
"config",
"[",
"'customer_number'",
"]",
",",
"$",
"this",
"->",
"config",
"[",
"'customer_number'",
"]",
",",
"$",
"shipment_id",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"post",
"(",
"$",
"endpoint",
",",
"[",
"'Content-Type'",
"=>",
"'application/vnd.cpc.shipment-v8+xml'",
",",
"'Accept'",
"=>",
"'application/vnd.cpc.shipment-v8+xml'",
",",
"]",
",",
"$",
"payload",
",",
"$",
"options",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Request a refund for a shipment that has been transmitted.
@param string $shipment_id
The shipment id.
@param string $email
The email that will receive updates from Canada Post.
@param array $options
The options to pass along to the Guzzle Client.
@return \DOMDocument
@throws \GuzzleHttp\Exception\GuzzleException
@see https://www.canadapost.ca/cpo/mc/business/productsservices/developers/services/shippingmanifest/shipmentrefund.jsf
for all available options for the sender,destination and parcel params. | [
"Request",
"a",
"refund",
"for",
"a",
"shipment",
"that",
"has",
"been",
"transmitted",
"."
] | 1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a | https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/Shipment.php#L201-L234 |
31,202 | thejacer87/php-canadapost-api | src/Shipment.php | Shipment.transmitShipments | public function transmitShipments(
array $manifest_address,
array $group_ids,
array $options = []
) {
$this->formatPostalCode($manifest_address['address-details']['postal-zip-code']);
$content = [
'group-ids' => [
'group-id' => $group_ids,
],
'requested-shipping-point' => $manifest_address['address-details']['postal-zip-code'],
'cpc-pickup-indicator' => true,
'detailed-manifests' => true,
'manifest-address' => $manifest_address,
];
if (!empty($options['option_codes'])) {
$content['options']['option'] = $this->parseOptionCodes($options);
}
$xml = Array2XML::createXML('transmit-set', $content);
$envelope = $xml->documentElement;
$envelope->setAttribute(
'xmlns',
'http://www.canadapost.ca/ws/manifest-v8'
);
$payload = $xml->saveXML();
$response = $this->post(
"rs/{$this->customerNumber}/{$this->customerNumber}/shipment",
[
'Accept' => 'application/vnd.cpc.manifest-v8+xml',
'Content-Type' => 'application/vnd.cpc.manifest-v8+xml',
],
$payload,
$options
);
return $response;
} | php | public function transmitShipments(
array $manifest_address,
array $group_ids,
array $options = []
) {
$this->formatPostalCode($manifest_address['address-details']['postal-zip-code']);
$content = [
'group-ids' => [
'group-id' => $group_ids,
],
'requested-shipping-point' => $manifest_address['address-details']['postal-zip-code'],
'cpc-pickup-indicator' => true,
'detailed-manifests' => true,
'manifest-address' => $manifest_address,
];
if (!empty($options['option_codes'])) {
$content['options']['option'] = $this->parseOptionCodes($options);
}
$xml = Array2XML::createXML('transmit-set', $content);
$envelope = $xml->documentElement;
$envelope->setAttribute(
'xmlns',
'http://www.canadapost.ca/ws/manifest-v8'
);
$payload = $xml->saveXML();
$response = $this->post(
"rs/{$this->customerNumber}/{$this->customerNumber}/shipment",
[
'Accept' => 'application/vnd.cpc.manifest-v8+xml',
'Content-Type' => 'application/vnd.cpc.manifest-v8+xml',
],
$payload,
$options
);
return $response;
} | [
"public",
"function",
"transmitShipments",
"(",
"array",
"$",
"manifest_address",
",",
"array",
"$",
"group_ids",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"formatPostalCode",
"(",
"$",
"manifest_address",
"[",
"'address-details'",
"]",
"[",
"'postal-zip-code'",
"]",
")",
";",
"$",
"content",
"=",
"[",
"'group-ids'",
"=>",
"[",
"'group-id'",
"=>",
"$",
"group_ids",
",",
"]",
",",
"'requested-shipping-point'",
"=>",
"$",
"manifest_address",
"[",
"'address-details'",
"]",
"[",
"'postal-zip-code'",
"]",
",",
"'cpc-pickup-indicator'",
"=>",
"true",
",",
"'detailed-manifests'",
"=>",
"true",
",",
"'manifest-address'",
"=>",
"$",
"manifest_address",
",",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'option_codes'",
"]",
")",
")",
"{",
"$",
"content",
"[",
"'options'",
"]",
"[",
"'option'",
"]",
"=",
"$",
"this",
"->",
"parseOptionCodes",
"(",
"$",
"options",
")",
";",
"}",
"$",
"xml",
"=",
"Array2XML",
"::",
"createXML",
"(",
"'transmit-set'",
",",
"$",
"content",
")",
";",
"$",
"envelope",
"=",
"$",
"xml",
"->",
"documentElement",
";",
"$",
"envelope",
"->",
"setAttribute",
"(",
"'xmlns'",
",",
"'http://www.canadapost.ca/ws/manifest-v8'",
")",
";",
"$",
"payload",
"=",
"$",
"xml",
"->",
"saveXML",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"post",
"(",
"\"rs/{$this->customerNumber}/{$this->customerNumber}/shipment\"",
",",
"[",
"'Accept'",
"=>",
"'application/vnd.cpc.manifest-v8+xml'",
",",
"'Content-Type'",
"=>",
"'application/vnd.cpc.manifest-v8+xml'",
",",
"]",
",",
"$",
"payload",
",",
"$",
"options",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Transmit shipments for pickup by Canada Post.
@param array $manifest_address
The destination info.
<code>
$manifest_address = [
'manifest-company' => 'ACME Inc.',
'phone-number' => '778 867 5309',
'address-details' => [
'address-line-1' => '123 Main St',
'city' => 'Kelowna',
'prov-state' => 'BC',
'country-code' => 'CA',
'postal-zip-code' => 'V1X 1M2',
],
]
</code>
@param array $group_ids
The group IDs. The Transmit Shipments service will create a manifest
for each group. The manifest will list the shipments included in the
group.
@param array $options
The options to pass along to the Guzzle Client.
@see https://www.canadapost.ca/cpo/mc/business/productsservices/developers/services/shippingmanifest/transmitshipments.jsf
for all available options for the sender,destination and parcel params.
@return \DOMDocument
@throws \GuzzleHttp\Exception\GuzzleException | [
"Transmit",
"shipments",
"for",
"pickup",
"by",
"Canada",
"Post",
"."
] | 1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a | https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/Shipment.php#L266-L304 |
31,203 | thejacer87/php-canadapost-api | src/Shipment.php | Shipment.getManifest | public function getManifest($manifest_id, $rel = '', array $options = [])
{
if (!empty($rel) && ($rel !== 'details')) {
$message = sprintf(
'Unsupported "rel" value: "%s". Supported "rel" value are "details" or null.',
$rel
);
throw new \InvalidArgumentException($message);
}
$endpoint = sprintf(
'rs/%s/%s/manifest/%s/%s',
$this->config['customer_number'],
$this->config['customer_number'],
$manifest_id,
$rel
);
$response = $this->get(
$endpoint,
['Accept' => 'application/vnd.cpc.manifest-v8+xml'],
$options
);
return $response;
} | php | public function getManifest($manifest_id, $rel = '', array $options = [])
{
if (!empty($rel) && ($rel !== 'details')) {
$message = sprintf(
'Unsupported "rel" value: "%s". Supported "rel" value are "details" or null.',
$rel
);
throw new \InvalidArgumentException($message);
}
$endpoint = sprintf(
'rs/%s/%s/manifest/%s/%s',
$this->config['customer_number'],
$this->config['customer_number'],
$manifest_id,
$rel
);
$response = $this->get(
$endpoint,
['Accept' => 'application/vnd.cpc.manifest-v8+xml'],
$options
);
return $response;
} | [
"public",
"function",
"getManifest",
"(",
"$",
"manifest_id",
",",
"$",
"rel",
"=",
"''",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"rel",
")",
"&&",
"(",
"$",
"rel",
"!==",
"'details'",
")",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'Unsupported \"rel\" value: \"%s\". Supported \"rel\" value are \"details\" or null.'",
",",
"$",
"rel",
")",
";",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"$",
"message",
")",
";",
"}",
"$",
"endpoint",
"=",
"sprintf",
"(",
"'rs/%s/%s/manifest/%s/%s'",
",",
"$",
"this",
"->",
"config",
"[",
"'customer_number'",
"]",
",",
"$",
"this",
"->",
"config",
"[",
"'customer_number'",
"]",
",",
"$",
"manifest_id",
",",
"$",
"rel",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"endpoint",
",",
"[",
"'Accept'",
"=>",
"'application/vnd.cpc.manifest-v8+xml'",
"]",
",",
"$",
"options",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Get the manifest from Canada Post server.
@param string $manifest_id
The manifest id.
@param string $rel
The 'rel' value from the links for a manifest. 'details' is the only valid argument.
@param array $options
The options array.
@return \DOMDocument|\Psr\Http\Message\StreamInterface
@throws \GuzzleHttp\Exception\GuzzleException | [
"Get",
"the",
"manifest",
"from",
"Canada",
"Post",
"server",
"."
] | 1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a | https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/Shipment.php#L319-L342 |
31,204 | pulsarvp/vps-tools | src/controllers/SettingsController.php | SettingsController.actionList | public function actionList ()
{
$class = $this->_modelClass;
$list = $class::find()->select('name,value,description')->orderBy([ 'name' => SORT_ASC ])->asArray()->all();
Console::printTable($list, [ 'Name', 'Value', 'Description' ]);
} | php | public function actionList ()
{
$class = $this->_modelClass;
$list = $class::find()->select('name,value,description')->orderBy([ 'name' => SORT_ASC ])->asArray()->all();
Console::printTable($list, [ 'Name', 'Value', 'Description' ]);
} | [
"public",
"function",
"actionList",
"(",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"_modelClass",
";",
"$",
"list",
"=",
"$",
"class",
"::",
"find",
"(",
")",
"->",
"select",
"(",
"'name,value,description'",
")",
"->",
"orderBy",
"(",
"[",
"'name'",
"=>",
"SORT_ASC",
"]",
")",
"->",
"asArray",
"(",
")",
"->",
"all",
"(",
")",
";",
"Console",
"::",
"printTable",
"(",
"$",
"list",
",",
"[",
"'Name'",
",",
"'Value'",
",",
"'Description'",
"]",
")",
";",
"}"
] | List all settings in database. | [
"List",
"all",
"settings",
"in",
"database",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/controllers/SettingsController.php#L33-L38 |
31,205 | pulsarvp/vps-tools | src/controllers/SettingsController.php | SettingsController.actionGet | public function actionGet ($name)
{
$class = $this->_modelClass;
$object = $class::find()->select('name,value,description')->where([ 'name' => $name ])->asArray()->one();
if ($object == null)
{
Console::printColor('Setting not found.', 'red');
Yii::$app->end();
}
Console::printTable([ $object ], [ 'Name', 'Value', 'Description' ]);
} | php | public function actionGet ($name)
{
$class = $this->_modelClass;
$object = $class::find()->select('name,value,description')->where([ 'name' => $name ])->asArray()->one();
if ($object == null)
{
Console::printColor('Setting not found.', 'red');
Yii::$app->end();
}
Console::printTable([ $object ], [ 'Name', 'Value', 'Description' ]);
} | [
"public",
"function",
"actionGet",
"(",
"$",
"name",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"_modelClass",
";",
"$",
"object",
"=",
"$",
"class",
"::",
"find",
"(",
")",
"->",
"select",
"(",
"'name,value,description'",
")",
"->",
"where",
"(",
"[",
"'name'",
"=>",
"$",
"name",
"]",
")",
"->",
"asArray",
"(",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"$",
"object",
"==",
"null",
")",
"{",
"Console",
"::",
"printColor",
"(",
"'Setting not found.'",
",",
"'red'",
")",
";",
"Yii",
"::",
"$",
"app",
"->",
"end",
"(",
")",
";",
"}",
"Console",
"::",
"printTable",
"(",
"[",
"$",
"object",
"]",
",",
"[",
"'Name'",
",",
"'Value'",
",",
"'Description'",
"]",
")",
";",
"}"
] | Gets setting with given name.
@param $name | [
"Gets",
"setting",
"with",
"given",
"name",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/controllers/SettingsController.php#L45-L55 |
31,206 | pulsarvp/vps-tools | src/controllers/SettingsController.php | SettingsController.actionSet | public function actionSet ($name, $value, $description = null)
{
$class = $this->_modelClass;
$object = $class::find()->where([ 'name' => $name ])->one();
if ($object == null)
{
Console::printColor('Setting not found.', 'red');
Yii::$app->end();
}
else
{
$object->value = $value;
if (!is_null($description))
$object->description = $description;
}
$object->save();
$this->actionList();
} | php | public function actionSet ($name, $value, $description = null)
{
$class = $this->_modelClass;
$object = $class::find()->where([ 'name' => $name ])->one();
if ($object == null)
{
Console::printColor('Setting not found.', 'red');
Yii::$app->end();
}
else
{
$object->value = $value;
if (!is_null($description))
$object->description = $description;
}
$object->save();
$this->actionList();
} | [
"public",
"function",
"actionSet",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"description",
"=",
"null",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"_modelClass",
";",
"$",
"object",
"=",
"$",
"class",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'name'",
"=>",
"$",
"name",
"]",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"$",
"object",
"==",
"null",
")",
"{",
"Console",
"::",
"printColor",
"(",
"'Setting not found.'",
",",
"'red'",
")",
";",
"Yii",
"::",
"$",
"app",
"->",
"end",
"(",
")",
";",
"}",
"else",
"{",
"$",
"object",
"->",
"value",
"=",
"$",
"value",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"description",
")",
")",
"$",
"object",
"->",
"description",
"=",
"$",
"description",
";",
"}",
"$",
"object",
"->",
"save",
"(",
")",
";",
"$",
"this",
"->",
"actionList",
"(",
")",
";",
"}"
] | Updates or creates setting with given name and value.
@param $name
@param $value
@param $description | [
"Updates",
"or",
"creates",
"setting",
"with",
"given",
"name",
"and",
"value",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/controllers/SettingsController.php#L64-L81 |
31,207 | pulsarvp/vps-tools | src/controllers/SettingsController.php | SettingsController.actionDelete | public function actionDelete ($name)
{
$class = $this->_modelClass;
$object = $class::find()->where([ 'name' => $name ])->one();
if ($object == null)
{
Console::printColor('Setting not found.', 'red');
Yii::$app->end();
}
if ($this->confirm("Remove setting '" . $name . "'?"))
{
if ($object->delete())
Console::printColor('Setting deleted.', 'green');
else
Console::printColor(current($object->getFirstErrors()), 'red');
}
} | php | public function actionDelete ($name)
{
$class = $this->_modelClass;
$object = $class::find()->where([ 'name' => $name ])->one();
if ($object == null)
{
Console::printColor('Setting not found.', 'red');
Yii::$app->end();
}
if ($this->confirm("Remove setting '" . $name . "'?"))
{
if ($object->delete())
Console::printColor('Setting deleted.', 'green');
else
Console::printColor(current($object->getFirstErrors()), 'red');
}
} | [
"public",
"function",
"actionDelete",
"(",
"$",
"name",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"_modelClass",
";",
"$",
"object",
"=",
"$",
"class",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'name'",
"=>",
"$",
"name",
"]",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"$",
"object",
"==",
"null",
")",
"{",
"Console",
"::",
"printColor",
"(",
"'Setting not found.'",
",",
"'red'",
")",
";",
"Yii",
"::",
"$",
"app",
"->",
"end",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"confirm",
"(",
"\"Remove setting '\"",
".",
"$",
"name",
".",
"\"'?\"",
")",
")",
"{",
"if",
"(",
"$",
"object",
"->",
"delete",
"(",
")",
")",
"Console",
"::",
"printColor",
"(",
"'Setting deleted.'",
",",
"'green'",
")",
";",
"else",
"Console",
"::",
"printColor",
"(",
"current",
"(",
"$",
"object",
"->",
"getFirstErrors",
"(",
")",
")",
",",
"'red'",
")",
";",
"}",
"}"
] | Deletes setting with given name.
@param $name | [
"Deletes",
"setting",
"with",
"given",
"name",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/controllers/SettingsController.php#L88-L105 |
31,208 | pulsarvp/vps-tools | src/components/redis/Connection.php | Connection.setPasswordDb | public function setPasswordDb ($name)
{
$value = Yii::$app->settings->get($name);
if (empty($value))
{
return;
}
$this->password = $value;
} | php | public function setPasswordDb ($name)
{
$value = Yii::$app->settings->get($name);
if (empty($value))
{
return;
}
$this->password = $value;
} | [
"public",
"function",
"setPasswordDb",
"(",
"$",
"name",
")",
"{",
"$",
"value",
"=",
"Yii",
"::",
"$",
"app",
"->",
"settings",
"->",
"get",
"(",
"$",
"name",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"password",
"=",
"$",
"value",
";",
"}"
] | Set password DB settings.
@param string $name | [
"Set",
"password",
"DB",
"settings",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/redis/Connection.php#L32-L42 |
31,209 | oradwell/covers-validator | src/Command/ValidateCommand.php | ValidateCommand.writeValidity | protected function writeValidity($output, $message, $isValid = null) {
if ($this->firstValidityWrite) {
$output->writeln('');
$this->firstValidityWrite = false;
}
if (is_bool($isValid)) {
$message = sprintf(
'%s - %s',
$isValid ? '<fg=green>Valid</>' : '<fg=red>Invalid</>',
$message
);
}
$output->writeln($message);
} | php | protected function writeValidity($output, $message, $isValid = null) {
if ($this->firstValidityWrite) {
$output->writeln('');
$this->firstValidityWrite = false;
}
if (is_bool($isValid)) {
$message = sprintf(
'%s - %s',
$isValid ? '<fg=green>Valid</>' : '<fg=red>Invalid</>',
$message
);
}
$output->writeln($message);
} | [
"protected",
"function",
"writeValidity",
"(",
"$",
"output",
",",
"$",
"message",
",",
"$",
"isValid",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"firstValidityWrite",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"''",
")",
";",
"$",
"this",
"->",
"firstValidityWrite",
"=",
"false",
";",
"}",
"if",
"(",
"is_bool",
"(",
"$",
"isValid",
")",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'%s - %s'",
",",
"$",
"isValid",
"?",
"'<fg=green>Valid</>'",
":",
"'<fg=red>Invalid</>'",
",",
"$",
"message",
")",
";",
"}",
"$",
"output",
"->",
"writeln",
"(",
"$",
"message",
")",
";",
"}"
] | Write validity message for tests
The purpose of this method is to write a new line for the first
validity related message
@param OutputInterface $output
@param string $message
@param bool|null $isValid | [
"Write",
"validity",
"message",
"for",
"tests",
"The",
"purpose",
"of",
"this",
"method",
"is",
"to",
"write",
"a",
"new",
"line",
"for",
"the",
"first",
"validity",
"related",
"message"
] | 1bc9db0e4846d80ad38b14662b6e48edaa7d289f | https://github.com/oradwell/covers-validator/blob/1bc9db0e4846d80ad38b14662b6e48edaa7d289f/src/Command/ValidateCommand.php#L119-L134 |
31,210 | bearcms/bearframework-addon | classes/BearCMS/Internal/Data2/Themes.php | Themes.getValues | public function getValues(string $id): array
{
$data = Internal\Data::getValue('bearcms/themes/theme/' . md5($id) . '.json');
if ($data !== null) {
$data = json_decode($data, true);
if (isset($data['options'])) {
return $data['options'];
}
}
return [];
} | php | public function getValues(string $id): array
{
$data = Internal\Data::getValue('bearcms/themes/theme/' . md5($id) . '.json');
if ($data !== null) {
$data = json_decode($data, true);
if (isset($data['options'])) {
return $data['options'];
}
}
return [];
} | [
"public",
"function",
"getValues",
"(",
"string",
"$",
"id",
")",
":",
"array",
"{",
"$",
"data",
"=",
"Internal",
"\\",
"Data",
"::",
"getValue",
"(",
"'bearcms/themes/theme/'",
".",
"md5",
"(",
"$",
"id",
")",
".",
"'.json'",
")",
";",
"if",
"(",
"$",
"data",
"!==",
"null",
")",
"{",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'options'",
"]",
")",
")",
"{",
"return",
"$",
"data",
"[",
"'options'",
"]",
";",
"}",
"}",
"return",
"[",
"]",
";",
"}"
] | Returns a list containing the options for the theme specified
@param string $id The id of the theme
@return array A list containing the theme options
@throws \InvalidArgumentException | [
"Returns",
"a",
"list",
"containing",
"the",
"options",
"for",
"the",
"theme",
"specified"
] | 7ef131b81aac26070a2b937dd67f530a6caa02f0 | https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/Internal/Data2/Themes.php#L29-L39 |
31,211 | bearcms/bearframework-addon | classes/BearCMS/Internal/Data2/Themes.php | Themes.getUserOptions | public function getUserOptions(string $id, string $userID): ?array
{
$data = Internal\Data::getValue('.temp/bearcms/userthemeoptions/' . md5($userID) . '/' . md5($id) . '.json');
if ($data !== null) {
$data = json_decode($data, true);
if (isset($data['options'])) {
return $data['options'];
}
}
return null;
} | php | public function getUserOptions(string $id, string $userID): ?array
{
$data = Internal\Data::getValue('.temp/bearcms/userthemeoptions/' . md5($userID) . '/' . md5($id) . '.json');
if ($data !== null) {
$data = json_decode($data, true);
if (isset($data['options'])) {
return $data['options'];
}
}
return null;
} | [
"public",
"function",
"getUserOptions",
"(",
"string",
"$",
"id",
",",
"string",
"$",
"userID",
")",
":",
"?",
"array",
"{",
"$",
"data",
"=",
"Internal",
"\\",
"Data",
"::",
"getValue",
"(",
"'.temp/bearcms/userthemeoptions/'",
".",
"md5",
"(",
"$",
"userID",
")",
".",
"'/'",
".",
"md5",
"(",
"$",
"id",
")",
".",
"'.json'",
")",
";",
"if",
"(",
"$",
"data",
"!==",
"null",
")",
"{",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'options'",
"]",
")",
")",
"{",
"return",
"$",
"data",
"[",
"'options'",
"]",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Returns a list containing the theme options a specific user has made
@param string $id The id of the theme
@param string $userID The id of the user
@return array A list containing the theme options
@throws \InvalidArgumentException | [
"Returns",
"a",
"list",
"containing",
"the",
"theme",
"options",
"a",
"specific",
"user",
"has",
"made"
] | 7ef131b81aac26070a2b937dd67f530a6caa02f0 | https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/Internal/Data2/Themes.php#L49-L59 |
31,212 | traderinteractive/filter-php | src/Filterer.php | Filterer.setFilterAliases | public static function setFilterAliases(array $aliases)
{
$originalAliases = self::$registeredFilterAliases;
self::$registeredFilterAliases = [];
try {
foreach ($aliases as $alias => $callback) {
self::registerAlias($alias, $callback);
}
} catch (Throwable $throwable) {
self::$registeredFilterAliases = $originalAliases;
throw $throwable;
}
} | php | public static function setFilterAliases(array $aliases)
{
$originalAliases = self::$registeredFilterAliases;
self::$registeredFilterAliases = [];
try {
foreach ($aliases as $alias => $callback) {
self::registerAlias($alias, $callback);
}
} catch (Throwable $throwable) {
self::$registeredFilterAliases = $originalAliases;
throw $throwable;
}
} | [
"public",
"static",
"function",
"setFilterAliases",
"(",
"array",
"$",
"aliases",
")",
"{",
"$",
"originalAliases",
"=",
"self",
"::",
"$",
"registeredFilterAliases",
";",
"self",
"::",
"$",
"registeredFilterAliases",
"=",
"[",
"]",
";",
"try",
"{",
"foreach",
"(",
"$",
"aliases",
"as",
"$",
"alias",
"=>",
"$",
"callback",
")",
"{",
"self",
"::",
"registerAlias",
"(",
"$",
"alias",
",",
"$",
"callback",
")",
";",
"}",
"}",
"catch",
"(",
"Throwable",
"$",
"throwable",
")",
"{",
"self",
"::",
"$",
"registeredFilterAliases",
"=",
"$",
"originalAliases",
";",
"throw",
"$",
"throwable",
";",
"}",
"}"
] | Set the filter aliases.
@param array $aliases array where keys are aliases and values pass is_callable().
@return void
@throws Exception Thrown if any of the given $aliases is not valid. @see registerAlias() | [
"Set",
"the",
"filter",
"aliases",
"."
] | a8dec173063ee2444ec297f065f64496b7d21590 | https://github.com/traderinteractive/filter-php/blob/a8dec173063ee2444ec297f065f64496b7d21590/src/Filterer.php#L325-L337 |
31,213 | traderinteractive/filter-php | src/Filterer.php | Filterer.registerAlias | public static function registerAlias($alias, callable $filter, bool $overwrite = false)
{
self::assertIfStringOrInt($alias);
self::assertIfAliasExists($alias, $overwrite);
self::$registeredFilterAliases[$alias] = $filter;
} | php | public static function registerAlias($alias, callable $filter, bool $overwrite = false)
{
self::assertIfStringOrInt($alias);
self::assertIfAliasExists($alias, $overwrite);
self::$registeredFilterAliases[$alias] = $filter;
} | [
"public",
"static",
"function",
"registerAlias",
"(",
"$",
"alias",
",",
"callable",
"$",
"filter",
",",
"bool",
"$",
"overwrite",
"=",
"false",
")",
"{",
"self",
"::",
"assertIfStringOrInt",
"(",
"$",
"alias",
")",
";",
"self",
"::",
"assertIfAliasExists",
"(",
"$",
"alias",
",",
"$",
"overwrite",
")",
";",
"self",
"::",
"$",
"registeredFilterAliases",
"[",
"$",
"alias",
"]",
"=",
"$",
"filter",
";",
"}"
] | Register a new alias with the Filterer
@param string|int $alias the alias to register
@param callable $filter the aliased callable filter
@param bool $overwrite Flag to overwrite existing alias if it exists
@return void
@throws \InvalidArgumentException if $alias was not a string or int
@throws Exception if $overwrite is false and $alias exists | [
"Register",
"a",
"new",
"alias",
"with",
"the",
"Filterer"
] | a8dec173063ee2444ec297f065f64496b7d21590 | https://github.com/traderinteractive/filter-php/blob/a8dec173063ee2444ec297f065f64496b7d21590/src/Filterer.php#L351-L356 |
31,214 | thejacer87/php-canadapost-api | src/Rating.php | Rating.parseServiceCodes | protected function parseServiceCodes(array $options)
{
$services = [];
foreach ($options['service_codes'] as $serviceCode) {
if (!array_key_exists(strtoupper($serviceCode), self::getServiceCodes())) {
$message = sprintf(
'Unsupported service code: "%s". Supported services are %s',
$serviceCode,
implode(', ', array_keys(self::getServiceCodes()))
);
throw new \InvalidArgumentException($message);
}
$services[] = $serviceCode;
}
return $services;
} | php | protected function parseServiceCodes(array $options)
{
$services = [];
foreach ($options['service_codes'] as $serviceCode) {
if (!array_key_exists(strtoupper($serviceCode), self::getServiceCodes())) {
$message = sprintf(
'Unsupported service code: "%s". Supported services are %s',
$serviceCode,
implode(', ', array_keys(self::getServiceCodes()))
);
throw new \InvalidArgumentException($message);
}
$services[] = $serviceCode;
}
return $services;
} | [
"protected",
"function",
"parseServiceCodes",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"services",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"options",
"[",
"'service_codes'",
"]",
"as",
"$",
"serviceCode",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"strtoupper",
"(",
"$",
"serviceCode",
")",
",",
"self",
"::",
"getServiceCodes",
"(",
")",
")",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'Unsupported service code: \"%s\". Supported services are %s'",
",",
"$",
"serviceCode",
",",
"implode",
"(",
"', '",
",",
"array_keys",
"(",
"self",
"::",
"getServiceCodes",
"(",
")",
")",
")",
")",
";",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"$",
"message",
")",
";",
"}",
"$",
"services",
"[",
"]",
"=",
"$",
"serviceCode",
";",
"}",
"return",
"$",
"services",
";",
"}"
] | Helper function to extract the service codes.
@param array $options
The options array.
@return array
The list of services to look up. | [
"Helper",
"function",
"to",
"extract",
"the",
"service",
"codes",
"."
] | 1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a | https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/Rating.php#L144-L160 |
31,215 | EmchBerger/cube-custom-fields-bundle | src/EntityHelper/CustomFieldsGetSet.php | CustomFieldsGetSet.getField | public static function getField($owningEntity, $key)
{
$entity = $owningEntity->getNonemptyCustomFields()->get($key);
if (!$entity) {
self::checkCustomFieldExists($owningEntity, $key);
}
return $entity;
} | php | public static function getField($owningEntity, $key)
{
$entity = $owningEntity->getNonemptyCustomFields()->get($key);
if (!$entity) {
self::checkCustomFieldExists($owningEntity, $key);
}
return $entity;
} | [
"public",
"static",
"function",
"getField",
"(",
"$",
"owningEntity",
",",
"$",
"key",
")",
"{",
"$",
"entity",
"=",
"$",
"owningEntity",
"->",
"getNonemptyCustomFields",
"(",
")",
"->",
"get",
"(",
"$",
"key",
")",
";",
"if",
"(",
"!",
"$",
"entity",
")",
"{",
"self",
"::",
"checkCustomFieldExists",
"(",
"$",
"owningEntity",
",",
"$",
"key",
")",
";",
"}",
"return",
"$",
"entity",
";",
"}"
] | Gets the customField, null if the key does not exist.
@param object $owningEntity
@param string $key
@return CustomFieldBase|null | [
"Gets",
"the",
"customField",
"null",
"if",
"the",
"key",
"does",
"not",
"exist",
"."
] | 7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414 | https://github.com/EmchBerger/cube-custom-fields-bundle/blob/7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414/src/EntityHelper/CustomFieldsGetSet.php#L26-L35 |
31,216 | EmchBerger/cube-custom-fields-bundle | src/EntityHelper/CustomFieldsGetSet.php | CustomFieldsGetSet.getValue | public static function getValue($owningEntity, $key)
{
$entity = $owningEntity->getNonemptyCustomFields()->get($key);
if ($entity) {
$value = $entity->getValue();
} else {
self::checkCustomFieldExists($owningEntity, $key);
$value = null;
}
return $value;
} | php | public static function getValue($owningEntity, $key)
{
$entity = $owningEntity->getNonemptyCustomFields()->get($key);
if ($entity) {
$value = $entity->getValue();
} else {
self::checkCustomFieldExists($owningEntity, $key);
$value = null;
}
return $value;
} | [
"public",
"static",
"function",
"getValue",
"(",
"$",
"owningEntity",
",",
"$",
"key",
")",
"{",
"$",
"entity",
"=",
"$",
"owningEntity",
"->",
"getNonemptyCustomFields",
"(",
")",
"->",
"get",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"entity",
")",
"{",
"$",
"value",
"=",
"$",
"entity",
"->",
"getValue",
"(",
")",
";",
"}",
"else",
"{",
"self",
"::",
"checkCustomFieldExists",
"(",
"$",
"owningEntity",
",",
"$",
"key",
")",
";",
"$",
"value",
"=",
"null",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Gets the value of a custom field, null if not set.
@param object $owningEntity
@param string $key
@return mixed | [
"Gets",
"the",
"value",
"of",
"a",
"custom",
"field",
"null",
"if",
"not",
"set",
"."
] | 7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414 | https://github.com/EmchBerger/cube-custom-fields-bundle/blob/7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414/src/EntityHelper/CustomFieldsGetSet.php#L45-L57 |
31,217 | EmchBerger/cube-custom-fields-bundle | src/EntityHelper/CustomFieldsGetSet.php | CustomFieldsGetSet.getEntityType | private static function getEntityType($owningEntity, $key)
{
$config = self::getConfig();
$owningClass = ClassUtils::getClass($owningEntity);
if (isset($config[$owningClass][$key])) {
return $config[$owningClass][$key]['type'];
}
return null;
} | php | private static function getEntityType($owningEntity, $key)
{
$config = self::getConfig();
$owningClass = ClassUtils::getClass($owningEntity);
if (isset($config[$owningClass][$key])) {
return $config[$owningClass][$key]['type'];
}
return null;
} | [
"private",
"static",
"function",
"getEntityType",
"(",
"$",
"owningEntity",
",",
"$",
"key",
")",
"{",
"$",
"config",
"=",
"self",
"::",
"getConfig",
"(",
")",
";",
"$",
"owningClass",
"=",
"ClassUtils",
"::",
"getClass",
"(",
"$",
"owningEntity",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"$",
"owningClass",
"]",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"config",
"[",
"$",
"owningClass",
"]",
"[",
"$",
"key",
"]",
"[",
"'type'",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the type according to the configuration.
@param object $owningEntity
@param string $key
@return string|null | [
"Returns",
"the",
"type",
"according",
"to",
"the",
"configuration",
"."
] | 7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414 | https://github.com/EmchBerger/cube-custom-fields-bundle/blob/7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414/src/EntityHelper/CustomFieldsGetSet.php#L137-L146 |
31,218 | EmchBerger/cube-custom-fields-bundle | src/EntityHelper/CustomFieldsGetSet.php | CustomFieldsGetSet.checkCustomFieldExists | private static function checkCustomFieldExists($owningEntity, $key)
{
if (is_null(self::getEntityType($owningEntity, $key))) {
$msg = sprintf('CustomField "%s" does not exist for entity class "%s"', $key, ClassUtils::getClass($owningEntity));
throw new \LogicException($msg);
}
} | php | private static function checkCustomFieldExists($owningEntity, $key)
{
if (is_null(self::getEntityType($owningEntity, $key))) {
$msg = sprintf('CustomField "%s" does not exist for entity class "%s"', $key, ClassUtils::getClass($owningEntity));
throw new \LogicException($msg);
}
} | [
"private",
"static",
"function",
"checkCustomFieldExists",
"(",
"$",
"owningEntity",
",",
"$",
"key",
")",
"{",
"if",
"(",
"is_null",
"(",
"self",
"::",
"getEntityType",
"(",
"$",
"owningEntity",
",",
"$",
"key",
")",
")",
")",
"{",
"$",
"msg",
"=",
"sprintf",
"(",
"'CustomField \"%s\" does not exist for entity class \"%s\"'",
",",
"$",
"key",
",",
"ClassUtils",
"::",
"getClass",
"(",
"$",
"owningEntity",
")",
")",
";",
"throw",
"new",
"\\",
"LogicException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Throws an error if the entity does not contain the custom field.
@param object $owningEntity
@param string $key
@throws \LogicException | [
"Throws",
"an",
"error",
"if",
"the",
"entity",
"does",
"not",
"contain",
"the",
"custom",
"field",
"."
] | 7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414 | https://github.com/EmchBerger/cube-custom-fields-bundle/blob/7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414/src/EntityHelper/CustomFieldsGetSet.php#L156-L162 |
31,219 | wikimedia/slimapp | src/CsrfMiddleware.php | CsrfMiddleware.call | public function call() {
if ( !isset( $_SESSION[self::PARAM] ) ) {
$_SESSION[self::PARAM] = sha1( session_id() . microtime() );
}
$token = $_SESSION[self::PARAM];
$method = $this->app->request()->getMethod();
if ( in_array( $method, [ 'POST', 'PUT', 'DELETE' ] ) ) {
$requestToken = $this->app->request()->post( self::PARAM );
if ( $token !== $requestToken ) {
$this->app->log->error( 'Missing or invalid CSRF token', [
'got' => $requestToken,
'expected' => $token,
] );
$this->app->render( 'csrf.html', [], 400 );
return;
}
}
$this->app->view()->replace( [
'csrf_param' => self::PARAM,
'csrf_token' => $token,
] );
$this->next->call();
} | php | public function call() {
if ( !isset( $_SESSION[self::PARAM] ) ) {
$_SESSION[self::PARAM] = sha1( session_id() . microtime() );
}
$token = $_SESSION[self::PARAM];
$method = $this->app->request()->getMethod();
if ( in_array( $method, [ 'POST', 'PUT', 'DELETE' ] ) ) {
$requestToken = $this->app->request()->post( self::PARAM );
if ( $token !== $requestToken ) {
$this->app->log->error( 'Missing or invalid CSRF token', [
'got' => $requestToken,
'expected' => $token,
] );
$this->app->render( 'csrf.html', [], 400 );
return;
}
}
$this->app->view()->replace( [
'csrf_param' => self::PARAM,
'csrf_token' => $token,
] );
$this->next->call();
} | [
"public",
"function",
"call",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SESSION",
"[",
"self",
"::",
"PARAM",
"]",
")",
")",
"{",
"$",
"_SESSION",
"[",
"self",
"::",
"PARAM",
"]",
"=",
"sha1",
"(",
"session_id",
"(",
")",
".",
"microtime",
"(",
")",
")",
";",
"}",
"$",
"token",
"=",
"$",
"_SESSION",
"[",
"self",
"::",
"PARAM",
"]",
";",
"$",
"method",
"=",
"$",
"this",
"->",
"app",
"->",
"request",
"(",
")",
"->",
"getMethod",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"method",
",",
"[",
"'POST'",
",",
"'PUT'",
",",
"'DELETE'",
"]",
")",
")",
"{",
"$",
"requestToken",
"=",
"$",
"this",
"->",
"app",
"->",
"request",
"(",
")",
"->",
"post",
"(",
"self",
"::",
"PARAM",
")",
";",
"if",
"(",
"$",
"token",
"!==",
"$",
"requestToken",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"log",
"->",
"error",
"(",
"'Missing or invalid CSRF token'",
",",
"[",
"'got'",
"=>",
"$",
"requestToken",
",",
"'expected'",
"=>",
"$",
"token",
",",
"]",
")",
";",
"$",
"this",
"->",
"app",
"->",
"render",
"(",
"'csrf.html'",
",",
"[",
"]",
",",
"400",
")",
";",
"return",
";",
"}",
"}",
"$",
"this",
"->",
"app",
"->",
"view",
"(",
")",
"->",
"replace",
"(",
"[",
"'csrf_param'",
"=>",
"self",
"::",
"PARAM",
",",
"'csrf_token'",
"=>",
"$",
"token",
",",
"]",
")",
";",
"$",
"this",
"->",
"next",
"->",
"call",
"(",
")",
";",
"}"
] | Handle CSRF validation and view injection. | [
"Handle",
"CSRF",
"validation",
"and",
"view",
"injection",
"."
] | 9fd0deba96f635c96d28d59d1f761283f62842d4 | https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/CsrfMiddleware.php#L44-L70 |
31,220 | thejacer87/php-canadapost-api | src/NCShipment.php | NCShipment.createNCShipment | public function createNCShipment(
array $sender,
array $destination,
array $parcel,
array $options = []
) {
$content = $this->buildShipmentArray($sender, $destination, $parcel, $options);
$xml = Array2XML::createXML('non-contract-shipment', $content);
$envelope = $xml->documentElement;
$envelope->setAttribute(
'xmlns',
'http://www.canadapost.ca/ws/ncshipment-v4'
);
$payload = $xml->saveXML();
$response = $this->post(
"rs/{$this->customerNumber}/ncshipment",
[
'Accept' => 'application/vnd.cpc.ncshipment-v4+xml',
'Content-Type' => 'application/vnd.cpc.ncshipment-v4+xml',
],
$payload,
$options
);
return $response;
} | php | public function createNCShipment(
array $sender,
array $destination,
array $parcel,
array $options = []
) {
$content = $this->buildShipmentArray($sender, $destination, $parcel, $options);
$xml = Array2XML::createXML('non-contract-shipment', $content);
$envelope = $xml->documentElement;
$envelope->setAttribute(
'xmlns',
'http://www.canadapost.ca/ws/ncshipment-v4'
);
$payload = $xml->saveXML();
$response = $this->post(
"rs/{$this->customerNumber}/ncshipment",
[
'Accept' => 'application/vnd.cpc.ncshipment-v4+xml',
'Content-Type' => 'application/vnd.cpc.ncshipment-v4+xml',
],
$payload,
$options
);
return $response;
} | [
"public",
"function",
"createNCShipment",
"(",
"array",
"$",
"sender",
",",
"array",
"$",
"destination",
",",
"array",
"$",
"parcel",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"buildShipmentArray",
"(",
"$",
"sender",
",",
"$",
"destination",
",",
"$",
"parcel",
",",
"$",
"options",
")",
";",
"$",
"xml",
"=",
"Array2XML",
"::",
"createXML",
"(",
"'non-contract-shipment'",
",",
"$",
"content",
")",
";",
"$",
"envelope",
"=",
"$",
"xml",
"->",
"documentElement",
";",
"$",
"envelope",
"->",
"setAttribute",
"(",
"'xmlns'",
",",
"'http://www.canadapost.ca/ws/ncshipment-v4'",
")",
";",
"$",
"payload",
"=",
"$",
"xml",
"->",
"saveXML",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"post",
"(",
"\"rs/{$this->customerNumber}/ncshipment\"",
",",
"[",
"'Accept'",
"=>",
"'application/vnd.cpc.ncshipment-v4+xml'",
",",
"'Content-Type'",
"=>",
"'application/vnd.cpc.ncshipment-v4+xml'",
",",
"]",
",",
"$",
"payload",
",",
"$",
"options",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Create the shipment.
@param array $sender
The sender info.
<code>
$sender = [
'company' => 'Acro Media',
'contact-phone' => '(250) 763-8884',
'address-details' => [
'address-line-1' => '103-2303 Leckie Rd',
'city' => 'Kelowna',
'prov-state' => 'BC',
'postal-zip-code' => 'V1X 6Y5',
],
]
</code>
@param array $destination
The destination info.
<code>
$destination = [
'name' => 'John Smith',
'address-details' => [
'address-line-1' => '123 Main St',
'city' => 'Kelowna',
'prov-state' => 'BC',
'country-code' => 'CA',
'postal-zip-code' => 'V1X 1M2',
],
]
</code>
@param array $parcel
The parcel characteristics.
<code>
$parcel = [
'weight' => 0.500, // in kg.
'dimensions' => [ // in cm.
'length' => 30,
'width' => 10,
'height' => 20,
],
],
]
</code>
@param array $options
The options to pass along to the Guzzle Client.
@see https://www.canadapost.ca/cpo/mc/business/productsservices/developers/services/onestepshipping/createshipment.jsf
for all available options for the sender,destination and parcel params.
@return \DOMDocument
@throws \GuzzleHttp\Exception\GuzzleException | [
"Create",
"the",
"shipment",
"."
] | 1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a | https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/NCShipment.php#L68-L94 |
31,221 | thejacer87/php-canadapost-api | src/NCShipment.php | NCShipment.getNCShipments | public function getNCShipments(
$from = '',
$to = '',
$tracking_pin = '',
array $options = []
) {
if (!isset($from) && !isset($tracking_pin)) {
$message = 'You must include either a $from date or a $tracking_pin.';
throw new \InvalidArgumentException($message);
}
if (empty($to)) {
$to = date('YmdHs');
}
$this->verifyDates($from, $to);
$query_params = "from={$from}&to{$to}";
if (!empty($tracking_pin)) {
$query_params = "trackingPIN={$tracking_pin}";
}
$endpoint = sprintf(
'rs/%s/ncshipment?%s',
$this->config['customer_number'],
$query_params
);
$response = $this->get(
$endpoint,
['Accept' => 'application/vnd.cpc.ncshipment-v4+xml'],
$options
);
return $response;
} | php | public function getNCShipments(
$from = '',
$to = '',
$tracking_pin = '',
array $options = []
) {
if (!isset($from) && !isset($tracking_pin)) {
$message = 'You must include either a $from date or a $tracking_pin.';
throw new \InvalidArgumentException($message);
}
if (empty($to)) {
$to = date('YmdHs');
}
$this->verifyDates($from, $to);
$query_params = "from={$from}&to{$to}";
if (!empty($tracking_pin)) {
$query_params = "trackingPIN={$tracking_pin}";
}
$endpoint = sprintf(
'rs/%s/ncshipment?%s',
$this->config['customer_number'],
$query_params
);
$response = $this->get(
$endpoint,
['Accept' => 'application/vnd.cpc.ncshipment-v4+xml'],
$options
);
return $response;
} | [
"public",
"function",
"getNCShipments",
"(",
"$",
"from",
"=",
"''",
",",
"$",
"to",
"=",
"''",
",",
"$",
"tracking_pin",
"=",
"''",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"from",
")",
"&&",
"!",
"isset",
"(",
"$",
"tracking_pin",
")",
")",
"{",
"$",
"message",
"=",
"'You must include either a $from date or a $tracking_pin.'",
";",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"$",
"message",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"to",
")",
")",
"{",
"$",
"to",
"=",
"date",
"(",
"'YmdHs'",
")",
";",
"}",
"$",
"this",
"->",
"verifyDates",
"(",
"$",
"from",
",",
"$",
"to",
")",
";",
"$",
"query_params",
"=",
"\"from={$from}&to{$to}\"",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"tracking_pin",
")",
")",
"{",
"$",
"query_params",
"=",
"\"trackingPIN={$tracking_pin}\"",
";",
"}",
"$",
"endpoint",
"=",
"sprintf",
"(",
"'rs/%s/ncshipment?%s'",
",",
"$",
"this",
"->",
"config",
"[",
"'customer_number'",
"]",
",",
"$",
"query_params",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"endpoint",
",",
"[",
"'Accept'",
"=>",
"'application/vnd.cpc.ncshipment-v4+xml'",
"]",
",",
"$",
"options",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Get NCShipments from Canada Post within the specified range.
If you supply a tracking PIN, the from/to dates will be ignored.
@param string $from
The beginning range. YmdHs format, eg. 201808282359.
@param string $to
The end range, defaults to current time. YmdHs format, eg. 201808282359.
@param string $tracking_pin
The Tracking PIN of the shipment to retrieve.
@param array $options
The options array.
@see https://www.canadapost.ca/cpo/mc/business/productsservices/developers/services/onestepshipping/onestepshipments.jsf
@return \DOMDocument|\Psr\Http\Message\StreamInterface
@throws \GuzzleHttp\Exception\GuzzleException | [
"Get",
"NCShipments",
"from",
"Canada",
"Post",
"within",
"the",
"specified",
"range",
"."
] | 1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a | https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/NCShipment.php#L153-L184 |
31,222 | thejacer87/php-canadapost-api | src/NCShipment.php | NCShipment.requestNCShipmentRefund | public function requestNCShipmentRefund($shipment_id, $email, $options)
{
$content = [
'email' => $email,
];
$xml = Array2XML::createXML(
'non-contract-shipment-refund-request',
$content
);
$envelope = $xml->documentElement;
$envelope->setAttribute(
'xmlns',
'http://www.canadapost.ca/ws/ncshipment-v4'
);
$payload = $xml->saveXML();
$response = $this->post(
"rs/{$this->config['customer_number']}/ncshipment/{$shipment_id}/refund",
[
'Content-Type' => 'application/vnd.cpc.ncshipment-v4+xml',
'Accept' => 'application/vnd.cpc.ncshipment-v4+xml',
],
$payload,
$options
);
return $response;
} | php | public function requestNCShipmentRefund($shipment_id, $email, $options)
{
$content = [
'email' => $email,
];
$xml = Array2XML::createXML(
'non-contract-shipment-refund-request',
$content
);
$envelope = $xml->documentElement;
$envelope->setAttribute(
'xmlns',
'http://www.canadapost.ca/ws/ncshipment-v4'
);
$payload = $xml->saveXML();
$response = $this->post(
"rs/{$this->config['customer_number']}/ncshipment/{$shipment_id}/refund",
[
'Content-Type' => 'application/vnd.cpc.ncshipment-v4+xml',
'Accept' => 'application/vnd.cpc.ncshipment-v4+xml',
],
$payload,
$options
);
return $response;
} | [
"public",
"function",
"requestNCShipmentRefund",
"(",
"$",
"shipment_id",
",",
"$",
"email",
",",
"$",
"options",
")",
"{",
"$",
"content",
"=",
"[",
"'email'",
"=>",
"$",
"email",
",",
"]",
";",
"$",
"xml",
"=",
"Array2XML",
"::",
"createXML",
"(",
"'non-contract-shipment-refund-request'",
",",
"$",
"content",
")",
";",
"$",
"envelope",
"=",
"$",
"xml",
"->",
"documentElement",
";",
"$",
"envelope",
"->",
"setAttribute",
"(",
"'xmlns'",
",",
"'http://www.canadapost.ca/ws/ncshipment-v4'",
")",
";",
"$",
"payload",
"=",
"$",
"xml",
"->",
"saveXML",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"post",
"(",
"\"rs/{$this->config['customer_number']}/ncshipment/{$shipment_id}/refund\"",
",",
"[",
"'Content-Type'",
"=>",
"'application/vnd.cpc.ncshipment-v4+xml'",
",",
"'Accept'",
"=>",
"'application/vnd.cpc.ncshipment-v4+xml'",
",",
"]",
",",
"$",
"payload",
",",
"$",
"options",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Request a refund for a non-contract shipment that has been transmitted.
@param string $shipment_id
The shipment id.
@param string $email
The email that will receive updates from Canada Post.
@param array $options
The options to pass along to the Guzzle Client.
@return \DOMDocument
@throws \GuzzleHttp\Exception\GuzzleException
@see https://www.canadapost.ca/cpo/mc/business/productsservices/developers/services/onestepshipping/shipmentrefund.jsf
for all available options for the sender,destination and parcel params. | [
"Request",
"a",
"refund",
"for",
"a",
"non",
"-",
"contract",
"shipment",
"that",
"has",
"been",
"transmitted",
"."
] | 1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a | https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/NCShipment.php#L201-L227 |
31,223 | EmchBerger/cube-custom-fields-bundle | src/Entity/AbstractCustomFieldRepository.php | AbstractCustomFieldRepository.findByObject | public function findByObject($object, $fieldId = null)
{
$qb = $this->createQueryBuilder('cf');
$this->addFindByObject($qb, 'cf', $object, $fieldId);
return $qb->getQuery()->getResult();
} | php | public function findByObject($object, $fieldId = null)
{
$qb = $this->createQueryBuilder('cf');
$this->addFindByObject($qb, 'cf', $object, $fieldId);
return $qb->getQuery()->getResult();
} | [
"public",
"function",
"findByObject",
"(",
"$",
"object",
",",
"$",
"fieldId",
"=",
"null",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'cf'",
")",
";",
"$",
"this",
"->",
"addFindByObject",
"(",
"$",
"qb",
",",
"'cf'",
",",
"$",
"object",
",",
"$",
"fieldId",
")",
";",
"return",
"$",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"getResult",
"(",
")",
";",
"}"
] | Finds EntityCustomFields which point to a specific object.
@param object $object value to filter for
@param string $fieldId optional
@return \Doctrine\ORM\QueryBuilder $qb | [
"Finds",
"EntityCustomFields",
"which",
"point",
"to",
"a",
"specific",
"object",
"."
] | 7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414 | https://github.com/EmchBerger/cube-custom-fields-bundle/blob/7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414/src/Entity/AbstractCustomFieldRepository.php#L20-L26 |
31,224 | oradwell/covers-validator | src/Locator/ConfigLocator.php | ConfigLocator.locate | public static function locate($configOption)
{
$configurationFile = static::CONFIG_FILENAME;
if (is_dir($configOption)) {
$configurationFile = $configOption . DIRECTORY_SEPARATOR . $configurationFile;
}
if (file_exists($configOption) && is_file($configOption)) {
return realpath($configOption);
}
if (file_exists($configurationFile)) {
return realpath($configurationFile);
}
if (file_exists($configurationFile . '.dist')) {
return realpath($configurationFile . '.dist');
}
return null;
} | php | public static function locate($configOption)
{
$configurationFile = static::CONFIG_FILENAME;
if (is_dir($configOption)) {
$configurationFile = $configOption . DIRECTORY_SEPARATOR . $configurationFile;
}
if (file_exists($configOption) && is_file($configOption)) {
return realpath($configOption);
}
if (file_exists($configurationFile)) {
return realpath($configurationFile);
}
if (file_exists($configurationFile . '.dist')) {
return realpath($configurationFile . '.dist');
}
return null;
} | [
"public",
"static",
"function",
"locate",
"(",
"$",
"configOption",
")",
"{",
"$",
"configurationFile",
"=",
"static",
"::",
"CONFIG_FILENAME",
";",
"if",
"(",
"is_dir",
"(",
"$",
"configOption",
")",
")",
"{",
"$",
"configurationFile",
"=",
"$",
"configOption",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"configurationFile",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"configOption",
")",
"&&",
"is_file",
"(",
"$",
"configOption",
")",
")",
"{",
"return",
"realpath",
"(",
"$",
"configOption",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"configurationFile",
")",
")",
"{",
"return",
"realpath",
"(",
"$",
"configurationFile",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"configurationFile",
".",
"'.dist'",
")",
")",
"{",
"return",
"realpath",
"(",
"$",
"configurationFile",
".",
"'.dist'",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Locates config file to use in the way PHPUnit does it
@param string $configOption
@return string|null | [
"Locates",
"config",
"file",
"to",
"use",
"in",
"the",
"way",
"PHPUnit",
"does",
"it"
] | 1bc9db0e4846d80ad38b14662b6e48edaa7d289f | https://github.com/oradwell/covers-validator/blob/1bc9db0e4846d80ad38b14662b6e48edaa7d289f/src/Locator/ConfigLocator.php#L15-L32 |
31,225 | oradwell/covers-validator | src/Loader/FileLoader.php | FileLoader.loadFile | public static function loadFile($filename)
{
if (class_exists(\PHPUnit\Util\Fileloader::class)) {
// PHPUnit 6.x
\PHPUnit\Util\Fileloader::checkAndLoad($filename);
} else {
// PHPUnit 7.x+
\PHPUnit\Util\FileLoader::checkAndLoad($filename);
}
} | php | public static function loadFile($filename)
{
if (class_exists(\PHPUnit\Util\Fileloader::class)) {
// PHPUnit 6.x
\PHPUnit\Util\Fileloader::checkAndLoad($filename);
} else {
// PHPUnit 7.x+
\PHPUnit\Util\FileLoader::checkAndLoad($filename);
}
} | [
"public",
"static",
"function",
"loadFile",
"(",
"$",
"filename",
")",
"{",
"if",
"(",
"class_exists",
"(",
"\\",
"PHPUnit",
"\\",
"Util",
"\\",
"Fileloader",
"::",
"class",
")",
")",
"{",
"// PHPUnit 6.x",
"\\",
"PHPUnit",
"\\",
"Util",
"\\",
"Fileloader",
"::",
"checkAndLoad",
"(",
"$",
"filename",
")",
";",
"}",
"else",
"{",
"// PHPUnit 7.x+",
"\\",
"PHPUnit",
"\\",
"Util",
"\\",
"FileLoader",
"::",
"checkAndLoad",
"(",
"$",
"filename",
")",
";",
"}",
"}"
] | Include a file
@param string $filename | [
"Include",
"a",
"file"
] | 1bc9db0e4846d80ad38b14662b6e48edaa7d289f | https://github.com/oradwell/covers-validator/blob/1bc9db0e4846d80ad38b14662b6e48edaa7d289f/src/Loader/FileLoader.php#L12-L21 |
31,226 | bearcms/bearframework-addon | classes/BearCMS/Internal/CurrentTheme.php | CurrentTheme.getID | static public function getID(): string
{
if (!isset(self::$cache['id'])) {
$cookies = Internal\Cookies::getList(Internal\Cookies::TYPE_SERVER);
self::$cache['id'] = isset($cookies['tmpr']) ? $cookies['tmpr'] : Internal\Themes::getActiveThemeID();
}
return self::$cache['id'];
} | php | static public function getID(): string
{
if (!isset(self::$cache['id'])) {
$cookies = Internal\Cookies::getList(Internal\Cookies::TYPE_SERVER);
self::$cache['id'] = isset($cookies['tmpr']) ? $cookies['tmpr'] : Internal\Themes::getActiveThemeID();
}
return self::$cache['id'];
} | [
"static",
"public",
"function",
"getID",
"(",
")",
":",
"string",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"cache",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"cookies",
"=",
"Internal",
"\\",
"Cookies",
"::",
"getList",
"(",
"Internal",
"\\",
"Cookies",
"::",
"TYPE_SERVER",
")",
";",
"self",
"::",
"$",
"cache",
"[",
"'id'",
"]",
"=",
"isset",
"(",
"$",
"cookies",
"[",
"'tmpr'",
"]",
")",
"?",
"$",
"cookies",
"[",
"'tmpr'",
"]",
":",
"Internal",
"\\",
"Themes",
"::",
"getActiveThemeID",
"(",
")",
";",
"}",
"return",
"self",
"::",
"$",
"cache",
"[",
"'id'",
"]",
";",
"}"
] | Returns the id of the current active theme or theme in preview
@return string The id of the current active theme or theme in preview | [
"Returns",
"the",
"id",
"of",
"the",
"current",
"active",
"theme",
"or",
"theme",
"in",
"preview"
] | 7ef131b81aac26070a2b937dd67f530a6caa02f0 | https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/Internal/CurrentTheme.php#L33-L40 |
31,227 | pulsarvp/vps-tools | src/db/Migration.php | Migration.addEnumValue | public function addEnumValue ($table, $column, $value, $default = false)
{
echo " > add enum value $value to column $column in $table ...\n";
$time = microtime(true);
$columnSchema = $this->db->getTableSchema($table)->columns[ $column ];
$values = $columnSchema->enumValues;
$values[] = $value;
$defaultValue = $default ? $value : $columnSchema->defaultValue;
$this->alterColumn($table, $column, $this->enum($values)->defaultValue($defaultValue));
echo ' > done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
} | php | public function addEnumValue ($table, $column, $value, $default = false)
{
echo " > add enum value $value to column $column in $table ...\n";
$time = microtime(true);
$columnSchema = $this->db->getTableSchema($table)->columns[ $column ];
$values = $columnSchema->enumValues;
$values[] = $value;
$defaultValue = $default ? $value : $columnSchema->defaultValue;
$this->alterColumn($table, $column, $this->enum($values)->defaultValue($defaultValue));
echo ' > done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
} | [
"public",
"function",
"addEnumValue",
"(",
"$",
"table",
",",
"$",
"column",
",",
"$",
"value",
",",
"$",
"default",
"=",
"false",
")",
"{",
"echo",
"\" > add enum value $value to column $column in $table ...\\n\"",
";",
"$",
"time",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"columnSchema",
"=",
"$",
"this",
"->",
"db",
"->",
"getTableSchema",
"(",
"$",
"table",
")",
"->",
"columns",
"[",
"$",
"column",
"]",
";",
"$",
"values",
"=",
"$",
"columnSchema",
"->",
"enumValues",
";",
"$",
"values",
"[",
"]",
"=",
"$",
"value",
";",
"$",
"defaultValue",
"=",
"$",
"default",
"?",
"$",
"value",
":",
"$",
"columnSchema",
"->",
"defaultValue",
";",
"$",
"this",
"->",
"alterColumn",
"(",
"$",
"table",
",",
"$",
"column",
",",
"$",
"this",
"->",
"enum",
"(",
"$",
"values",
")",
"->",
"defaultValue",
"(",
"$",
"defaultValue",
")",
")",
";",
"echo",
"' > done (time: '",
".",
"sprintf",
"(",
"'%.3f'",
",",
"microtime",
"(",
"true",
")",
"-",
"$",
"time",
")",
".",
"\"s)\\n\"",
";",
"}"
] | Adds value to enum column.
@param string $table Table name.
@param string $column Column name.
@param string $value New value in enum.
@param bool $default Whether to set new value as default. | [
"Adds",
"value",
"to",
"enum",
"column",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/db/Migration.php#L25-L37 |
31,228 | pulsarvp/vps-tools | src/db/Migration.php | Migration.createView | public function createView ($name, Query $query, $replace = true)
{
echo " > create table $name ...";
$time = microtime(true);
$sql = 'CREATE' . ( $replace ? ' OR REPLACE' : '' ) . ' VIEW ' . $this->db->quoteTableName($name) . ' AS ' . $query->createCommand()->getRawSql();
$this->db->createCommand($sql)->execute();
echo ' > done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
} | php | public function createView ($name, Query $query, $replace = true)
{
echo " > create table $name ...";
$time = microtime(true);
$sql = 'CREATE' . ( $replace ? ' OR REPLACE' : '' ) . ' VIEW ' . $this->db->quoteTableName($name) . ' AS ' . $query->createCommand()->getRawSql();
$this->db->createCommand($sql)->execute();
echo ' > done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
} | [
"public",
"function",
"createView",
"(",
"$",
"name",
",",
"Query",
"$",
"query",
",",
"$",
"replace",
"=",
"true",
")",
"{",
"echo",
"\" > create table $name ...\"",
";",
"$",
"time",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"sql",
"=",
"'CREATE'",
".",
"(",
"$",
"replace",
"?",
"' OR REPLACE'",
":",
"''",
")",
".",
"' VIEW '",
".",
"$",
"this",
"->",
"db",
"->",
"quoteTableName",
"(",
"$",
"name",
")",
".",
"' AS '",
".",
"$",
"query",
"->",
"createCommand",
"(",
")",
"->",
"getRawSql",
"(",
")",
";",
"$",
"this",
"->",
"db",
"->",
"createCommand",
"(",
"$",
"sql",
")",
"->",
"execute",
"(",
")",
";",
"echo",
"' > done (time: '",
".",
"sprintf",
"(",
"'%.3f'",
",",
"microtime",
"(",
"true",
")",
"-",
"$",
"time",
")",
".",
"\"s)\\n\"",
";",
"}"
] | Creates database view.
@param string $name View name.
@param Query $query Query that is used to create view.
@param bool $replace Whether to replace existing view with the same name.
@throws \yii\db\Exception
@see dropView | [
"Creates",
"database",
"view",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/db/Migration.php#L49-L58 |
31,229 | pulsarvp/vps-tools | src/db/Migration.php | Migration.checkCollation | public function checkCollation ($encoding = 'utf8', $exception = true)
{
$variables = [
'character_set_client',
'character_set_connection',
'character_set_database',
'character_set_results',
'character_set_server',
'character_set_system',
'collation_connection',
'collation_database',
'collation_server'
];
foreach ($variables as $variable)
{
$sql = "show variables like '" . $variable . "'";
$value = $this->db->createCommand($sql)->queryOne();
$pos = StringHelper::pos($value[ 'Value' ], $encoding);
if ($pos !== 0)
{
if (!$exception)
return false;
else
throw new InvalidConfigException ("Parameter $variable does not match $encoding.");
}
}
return true;
} | php | public function checkCollation ($encoding = 'utf8', $exception = true)
{
$variables = [
'character_set_client',
'character_set_connection',
'character_set_database',
'character_set_results',
'character_set_server',
'character_set_system',
'collation_connection',
'collation_database',
'collation_server'
];
foreach ($variables as $variable)
{
$sql = "show variables like '" . $variable . "'";
$value = $this->db->createCommand($sql)->queryOne();
$pos = StringHelper::pos($value[ 'Value' ], $encoding);
if ($pos !== 0)
{
if (!$exception)
return false;
else
throw new InvalidConfigException ("Parameter $variable does not match $encoding.");
}
}
return true;
} | [
"public",
"function",
"checkCollation",
"(",
"$",
"encoding",
"=",
"'utf8'",
",",
"$",
"exception",
"=",
"true",
")",
"{",
"$",
"variables",
"=",
"[",
"'character_set_client'",
",",
"'character_set_connection'",
",",
"'character_set_database'",
",",
"'character_set_results'",
",",
"'character_set_server'",
",",
"'character_set_system'",
",",
"'collation_connection'",
",",
"'collation_database'",
",",
"'collation_server'",
"]",
";",
"foreach",
"(",
"$",
"variables",
"as",
"$",
"variable",
")",
"{",
"$",
"sql",
"=",
"\"show variables like '\"",
".",
"$",
"variable",
".",
"\"'\"",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"db",
"->",
"createCommand",
"(",
"$",
"sql",
")",
"->",
"queryOne",
"(",
")",
";",
"$",
"pos",
"=",
"StringHelper",
"::",
"pos",
"(",
"$",
"value",
"[",
"'Value'",
"]",
",",
"$",
"encoding",
")",
";",
"if",
"(",
"$",
"pos",
"!==",
"0",
")",
"{",
"if",
"(",
"!",
"$",
"exception",
")",
"return",
"false",
";",
"else",
"throw",
"new",
"InvalidConfigException",
"(",
"\"Parameter $variable does not match $encoding.\"",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Server encoding checking
@param string $encoding
@param bool $exception
@return bool
@throws InvalidConfigException | [
"Server",
"encoding",
"checking"
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/db/Migration.php#L69-L97 |
31,230 | pulsarvp/vps-tools | src/db/Migration.php | Migration.checkEngine | public function checkEngine (string $name = 'InnoDB', bool $default = true, bool $exception = true)
{
$engines = $this->db->createCommand("SHOW ENGINES")->queryAll();
foreach ($engines as $engine)
{
if (strcasecmp($engine[ 'Engine' ], $name) == 0)
{
switch ($engine[ 'Support' ])
{
case 'DEFAULT':
return true;
case 'YES':
if ($default)
{
if ($exception)
throw new Exception("Engine $name is enabled but not default.");
else
return false;
}
else
return true;
case 'DISABLED':
if ($exception)
throw new Exception("Engine $name is supported but disabled.");
else
return false;
default:
if ($exception)
throw new Exception("Engine $name is not supported.");
else
return false;
}
}
}
if ($exception)
throw new Exception("Engine $name not found in the list of database engines.");
else
return false;
} | php | public function checkEngine (string $name = 'InnoDB', bool $default = true, bool $exception = true)
{
$engines = $this->db->createCommand("SHOW ENGINES")->queryAll();
foreach ($engines as $engine)
{
if (strcasecmp($engine[ 'Engine' ], $name) == 0)
{
switch ($engine[ 'Support' ])
{
case 'DEFAULT':
return true;
case 'YES':
if ($default)
{
if ($exception)
throw new Exception("Engine $name is enabled but not default.");
else
return false;
}
else
return true;
case 'DISABLED':
if ($exception)
throw new Exception("Engine $name is supported but disabled.");
else
return false;
default:
if ($exception)
throw new Exception("Engine $name is not supported.");
else
return false;
}
}
}
if ($exception)
throw new Exception("Engine $name not found in the list of database engines.");
else
return false;
} | [
"public",
"function",
"checkEngine",
"(",
"string",
"$",
"name",
"=",
"'InnoDB'",
",",
"bool",
"$",
"default",
"=",
"true",
",",
"bool",
"$",
"exception",
"=",
"true",
")",
"{",
"$",
"engines",
"=",
"$",
"this",
"->",
"db",
"->",
"createCommand",
"(",
"\"SHOW ENGINES\"",
")",
"->",
"queryAll",
"(",
")",
";",
"foreach",
"(",
"$",
"engines",
"as",
"$",
"engine",
")",
"{",
"if",
"(",
"strcasecmp",
"(",
"$",
"engine",
"[",
"'Engine'",
"]",
",",
"$",
"name",
")",
"==",
"0",
")",
"{",
"switch",
"(",
"$",
"engine",
"[",
"'Support'",
"]",
")",
"{",
"case",
"'DEFAULT'",
":",
"return",
"true",
";",
"case",
"'YES'",
":",
"if",
"(",
"$",
"default",
")",
"{",
"if",
"(",
"$",
"exception",
")",
"throw",
"new",
"Exception",
"(",
"\"Engine $name is enabled but not default.\"",
")",
";",
"else",
"return",
"false",
";",
"}",
"else",
"return",
"true",
";",
"case",
"'DISABLED'",
":",
"if",
"(",
"$",
"exception",
")",
"throw",
"new",
"Exception",
"(",
"\"Engine $name is supported but disabled.\"",
")",
";",
"else",
"return",
"false",
";",
"default",
":",
"if",
"(",
"$",
"exception",
")",
"throw",
"new",
"Exception",
"(",
"\"Engine $name is not supported.\"",
")",
";",
"else",
"return",
"false",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"exception",
")",
"throw",
"new",
"Exception",
"(",
"\"Engine $name not found in the list of database engines.\"",
")",
";",
"else",
"return",
"false",
";",
"}"
] | Check if provided engine is supported and enabled.
@param string $name Engine name.
@param bool $default Whether to check if engine is default.
@param bool $exception Whether to throw exception on error.
@return bool True in case of engine is enabled and (in case of default is true) default. Otherwise exception is thrown (id exception is true) or false returned.
@throws \yii\db\Exception | [
"Check",
"if",
"provided",
"engine",
"is",
"supported",
"and",
"enabled",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/db/Migration.php#L109-L151 |
31,231 | pulsarvp/vps-tools | src/db/Migration.php | Migration.deleteEnumValue | public function deleteEnumValue ($table, $column, $value, $default = null)
{
echo " > delete enum value $value from column $column in $table ...\n";
$time = microtime(true);
$columnSchema = $this->db->getTableSchema($table)->columns[ $column ];
$values = $columnSchema->enumValues;
$key = array_search($value, $values);
if ($key === false)
throw new Exception("Cannot find value $value in enum values " . implode(", ", $values) . ".");
unset($values[ $key ]);
$defaultValue = $default ? $default : $columnSchema->defaultValue;
$this->alterColumn($table, $column, $this->enum($values)->defaultValue($defaultValue));
echo ' > done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
} | php | public function deleteEnumValue ($table, $column, $value, $default = null)
{
echo " > delete enum value $value from column $column in $table ...\n";
$time = microtime(true);
$columnSchema = $this->db->getTableSchema($table)->columns[ $column ];
$values = $columnSchema->enumValues;
$key = array_search($value, $values);
if ($key === false)
throw new Exception("Cannot find value $value in enum values " . implode(", ", $values) . ".");
unset($values[ $key ]);
$defaultValue = $default ? $default : $columnSchema->defaultValue;
$this->alterColumn($table, $column, $this->enum($values)->defaultValue($defaultValue));
echo ' > done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
} | [
"public",
"function",
"deleteEnumValue",
"(",
"$",
"table",
",",
"$",
"column",
",",
"$",
"value",
",",
"$",
"default",
"=",
"null",
")",
"{",
"echo",
"\" > delete enum value $value from column $column in $table ...\\n\"",
";",
"$",
"time",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"columnSchema",
"=",
"$",
"this",
"->",
"db",
"->",
"getTableSchema",
"(",
"$",
"table",
")",
"->",
"columns",
"[",
"$",
"column",
"]",
";",
"$",
"values",
"=",
"$",
"columnSchema",
"->",
"enumValues",
";",
"$",
"key",
"=",
"array_search",
"(",
"$",
"value",
",",
"$",
"values",
")",
";",
"if",
"(",
"$",
"key",
"===",
"false",
")",
"throw",
"new",
"Exception",
"(",
"\"Cannot find value $value in enum values \"",
".",
"implode",
"(",
"\", \"",
",",
"$",
"values",
")",
".",
"\".\"",
")",
";",
"unset",
"(",
"$",
"values",
"[",
"$",
"key",
"]",
")",
";",
"$",
"defaultValue",
"=",
"$",
"default",
"?",
"$",
"default",
":",
"$",
"columnSchema",
"->",
"defaultValue",
";",
"$",
"this",
"->",
"alterColumn",
"(",
"$",
"table",
",",
"$",
"column",
",",
"$",
"this",
"->",
"enum",
"(",
"$",
"values",
")",
"->",
"defaultValue",
"(",
"$",
"defaultValue",
")",
")",
";",
"echo",
"' > done (time: '",
".",
"sprintf",
"(",
"'%.3f'",
",",
"microtime",
"(",
"true",
")",
"-",
"$",
"time",
")",
".",
"\"s)\\n\"",
";",
"}"
] | Deletes value from enum column.
@param string $table Table name.
@param string $column Column name.
@param string $value Value to be removed from column.
@param null $default New default value. If null the old one will be used.
@throws \yii\db\Exception | [
"Deletes",
"value",
"from",
"enum",
"column",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/db/Migration.php#L163-L178 |
31,232 | pulsarvp/vps-tools | src/db/Migration.php | Migration.dropView | public function dropView ($name)
{
echo " > drop view $name ...";
$time = microtime(true);
$this->db->createCommand('DROP VIEW IF EXISTS ' . $this->db->quoteTableName($name))->execute();
echo ' > done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
} | php | public function dropView ($name)
{
echo " > drop view $name ...";
$time = microtime(true);
$this->db->createCommand('DROP VIEW IF EXISTS ' . $this->db->quoteTableName($name))->execute();
echo ' > done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
} | [
"public",
"function",
"dropView",
"(",
"$",
"name",
")",
"{",
"echo",
"\" > drop view $name ...\"",
";",
"$",
"time",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"this",
"->",
"db",
"->",
"createCommand",
"(",
"'DROP VIEW IF EXISTS '",
".",
"$",
"this",
"->",
"db",
"->",
"quoteTableName",
"(",
"$",
"name",
")",
")",
"->",
"execute",
"(",
")",
";",
"echo",
"' > done (time: '",
".",
"sprintf",
"(",
"'%.3f'",
",",
"microtime",
"(",
"true",
")",
"-",
"$",
"time",
")",
".",
"\"s)\\n\"",
";",
"}"
] | Drops view by name.
@param string $name
@see createView | [
"Drops",
"view",
"by",
"name",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/db/Migration.php#L187-L193 |
31,233 | pulsarvp/vps-tools | src/db/Migration.php | Migration.findForeignKeys | public function findForeignKeys ($table, $column = null)
{
$query = ( new Query )
->select('CONSTRAINT_NAME')
->from('INFORMATION_SCHEMA.KEY_COLUMN_USAGE')
->where([
'TABLE_SCHEMA' => $this->getDbName(),
'TABLE_NAME' => $table
]);
if (!is_null($column))
$query->andWhere([ 'COLUMN_NAME' => $column ]);
return $query->column();
} | php | public function findForeignKeys ($table, $column = null)
{
$query = ( new Query )
->select('CONSTRAINT_NAME')
->from('INFORMATION_SCHEMA.KEY_COLUMN_USAGE')
->where([
'TABLE_SCHEMA' => $this->getDbName(),
'TABLE_NAME' => $table
]);
if (!is_null($column))
$query->andWhere([ 'COLUMN_NAME' => $column ]);
return $query->column();
} | [
"public",
"function",
"findForeignKeys",
"(",
"$",
"table",
",",
"$",
"column",
"=",
"null",
")",
"{",
"$",
"query",
"=",
"(",
"new",
"Query",
")",
"->",
"select",
"(",
"'CONSTRAINT_NAME'",
")",
"->",
"from",
"(",
"'INFORMATION_SCHEMA.KEY_COLUMN_USAGE'",
")",
"->",
"where",
"(",
"[",
"'TABLE_SCHEMA'",
"=>",
"$",
"this",
"->",
"getDbName",
"(",
")",
",",
"'TABLE_NAME'",
"=>",
"$",
"table",
"]",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"column",
")",
")",
"$",
"query",
"->",
"andWhere",
"(",
"[",
"'COLUMN_NAME'",
"=>",
"$",
"column",
"]",
")",
";",
"return",
"$",
"query",
"->",
"column",
"(",
")",
";",
"}"
] | Find all foreign keys names for specific table and column.
@param string $table
@param string|null $column
@return string[] | [
"Find",
"all",
"foreign",
"keys",
"names",
"for",
"specific",
"table",
"and",
"column",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/db/Migration.php#L215-L228 |
31,234 | pulsarvp/vps-tools | src/db/Migration.php | Migration.fromFile | public function fromFile ($path)
{
if (file_exists($path) and is_readable($path))
{
echo " > loading queries from file $path ...";
$time = microtime(true);
$rows = file($path, FILE_SKIP_EMPTY_LINES);
foreach ($rows as $row)
$this->db->createCommand($row)->execute();
echo ' > done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
}
else
throw new \Exception ('Cannot open file ' . $path . ' for reading.');
} | php | public function fromFile ($path)
{
if (file_exists($path) and is_readable($path))
{
echo " > loading queries from file $path ...";
$time = microtime(true);
$rows = file($path, FILE_SKIP_EMPTY_LINES);
foreach ($rows as $row)
$this->db->createCommand($row)->execute();
echo ' > done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
}
else
throw new \Exception ('Cannot open file ' . $path . ' for reading.');
} | [
"public",
"function",
"fromFile",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
"and",
"is_readable",
"(",
"$",
"path",
")",
")",
"{",
"echo",
"\" > loading queries from file $path ...\"",
";",
"$",
"time",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"rows",
"=",
"file",
"(",
"$",
"path",
",",
"FILE_SKIP_EMPTY_LINES",
")",
";",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"row",
")",
"$",
"this",
"->",
"db",
"->",
"createCommand",
"(",
"$",
"row",
")",
"->",
"execute",
"(",
")",
";",
"echo",
"' > done (time: '",
".",
"sprintf",
"(",
"'%.3f'",
",",
"microtime",
"(",
"true",
")",
"-",
"$",
"time",
")",
".",
"\"s)\\n\"",
";",
"}",
"else",
"throw",
"new",
"\\",
"Exception",
"(",
"'Cannot open file '",
".",
"$",
"path",
".",
"' for reading.'",
")",
";",
"}"
] | Loads queries from file and executes them. Each query should be on
new line just in case.
@param string $path Path to the file.
@throws \Exception
@throws \yii\db\Exception | [
"Loads",
"queries",
"from",
"file",
"and",
"executes",
"them",
".",
"Each",
"query",
"should",
"be",
"on",
"new",
"line",
"just",
"in",
"case",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/db/Migration.php#L239-L254 |
31,235 | pulsarvp/vps-tools | src/db/Migration.php | Migration.foreignKeyCheck | public function foreignKeyCheck ($check = true)
{
$check = intval(boolval($check));
$this->db->createCommand("SET FOREIGN_KEY_CHECKS=$check")->execute();
} | php | public function foreignKeyCheck ($check = true)
{
$check = intval(boolval($check));
$this->db->createCommand("SET FOREIGN_KEY_CHECKS=$check")->execute();
} | [
"public",
"function",
"foreignKeyCheck",
"(",
"$",
"check",
"=",
"true",
")",
"{",
"$",
"check",
"=",
"intval",
"(",
"boolval",
"(",
"$",
"check",
")",
")",
";",
"$",
"this",
"->",
"db",
"->",
"createCommand",
"(",
"\"SET FOREIGN_KEY_CHECKS=$check\"",
")",
"->",
"execute",
"(",
")",
";",
"}"
] | Sets foreign key check to 1 or 0.
@param bool $check | [
"Sets",
"foreign",
"key",
"check",
"to",
"1",
"or",
"0",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/db/Migration.php#L261-L265 |
31,236 | pulsarvp/vps-tools | src/db/Migration.php | Migration.getDbName | public function getDbName ()
{
if ($this->db->getDriverName() == 'mysql')
{
preg_match("/dbname=([^;]*)/", $this->db->dsn, $match);
if (isset($match[ 1 ]))
return $match[ 1 ];
}
return null;
} | php | public function getDbName ()
{
if ($this->db->getDriverName() == 'mysql')
{
preg_match("/dbname=([^;]*)/", $this->db->dsn, $match);
if (isset($match[ 1 ]))
return $match[ 1 ];
}
return null;
} | [
"public",
"function",
"getDbName",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"db",
"->",
"getDriverName",
"(",
")",
"==",
"'mysql'",
")",
"{",
"preg_match",
"(",
"\"/dbname=([^;]*)/\"",
",",
"$",
"this",
"->",
"db",
"->",
"dsn",
",",
"$",
"match",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"match",
"[",
"1",
"]",
")",
")",
"return",
"$",
"match",
"[",
"1",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Gets database name via dbname parameter from dsn.
@return string|null | [
"Gets",
"database",
"name",
"via",
"dbname",
"parameter",
"from",
"dsn",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/db/Migration.php#L272-L282 |
31,237 | pulsarvp/vps-tools | src/db/Migration.php | Migration.hasColumn | public function hasColumn ($table, $column)
{
$schema = $this->db->getTableSchema($table);
return isset($schema->columns[ $column ]);
} | php | public function hasColumn ($table, $column)
{
$schema = $this->db->getTableSchema($table);
return isset($schema->columns[ $column ]);
} | [
"public",
"function",
"hasColumn",
"(",
"$",
"table",
",",
"$",
"column",
")",
"{",
"$",
"schema",
"=",
"$",
"this",
"->",
"db",
"->",
"getTableSchema",
"(",
"$",
"table",
")",
";",
"return",
"isset",
"(",
"$",
"schema",
"->",
"columns",
"[",
"$",
"column",
"]",
")",
";",
"}"
] | Checks whether column for a table exist.
@param string $table
@param string $column
@return bool | [
"Checks",
"whether",
"column",
"for",
"a",
"table",
"exist",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/db/Migration.php#L292-L297 |
31,238 | FernleafSystems/ApiWrappers-FreeAgent | src/Entities/BankTransactions/Finder.php | Finder.byAmount | public function byAmount( $nAmount ) {
$oTheOne = null;
foreach ( $this as $oBankTxn ) {
if ( (string)$oBankTxn->amount == (string)$nAmount ) {
$oTheOne = $oBankTxn;
break;
}
}
return $oTheOne;
} | php | public function byAmount( $nAmount ) {
$oTheOne = null;
foreach ( $this as $oBankTxn ) {
if ( (string)$oBankTxn->amount == (string)$nAmount ) {
$oTheOne = $oBankTxn;
break;
}
}
return $oTheOne;
} | [
"public",
"function",
"byAmount",
"(",
"$",
"nAmount",
")",
"{",
"$",
"oTheOne",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"as",
"$",
"oBankTxn",
")",
"{",
"if",
"(",
"(",
"string",
")",
"$",
"oBankTxn",
"->",
"amount",
"==",
"(",
"string",
")",
"$",
"nAmount",
")",
"{",
"$",
"oTheOne",
"=",
"$",
"oBankTxn",
";",
"break",
";",
"}",
"}",
"return",
"$",
"oTheOne",
";",
"}"
] | Ideally you would set other filter params on this if you're looking for a specific
transaction - i.e. unexplained, within a date range
@param string $nAmount
@return BankTransactionVO|null | [
"Ideally",
"you",
"would",
"set",
"other",
"filter",
"params",
"on",
"this",
"if",
"you",
"re",
"looking",
"for",
"a",
"specific",
"transaction",
"-",
"i",
".",
"e",
".",
"unexplained",
"within",
"a",
"date",
"range"
] | bfa283d27b81eccc34d214839b68cee7bf75f17a | https://github.com/FernleafSystems/ApiWrappers-FreeAgent/blob/bfa283d27b81eccc34d214839b68cee7bf75f17a/src/Entities/BankTransactions/Finder.php#L17-L26 |
31,239 | pulsarvp/vps-tools | src/html/Field.php | Field.hidden | public function hidden ($options = [])
{
$this->options[ 'class' ] = ( isset($this->options[ 'class' ]) ? $this->options[ 'class' ] . ' ' : '' ) . 'hide';
$this->parts[ '{input}' ] = Html::activeHiddenInput($this->model, $this->attribute, $options);
return $this;
} | php | public function hidden ($options = [])
{
$this->options[ 'class' ] = ( isset($this->options[ 'class' ]) ? $this->options[ 'class' ] . ' ' : '' ) . 'hide';
$this->parts[ '{input}' ] = Html::activeHiddenInput($this->model, $this->attribute, $options);
return $this;
} | [
"public",
"function",
"hidden",
"(",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"options",
"[",
"'class'",
"]",
"=",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'class'",
"]",
")",
"?",
"$",
"this",
"->",
"options",
"[",
"'class'",
"]",
".",
"' '",
":",
"''",
")",
".",
"'hide'",
";",
"$",
"this",
"->",
"parts",
"[",
"'{input}'",
"]",
"=",
"Html",
"::",
"activeHiddenInput",
"(",
"$",
"this",
"->",
"model",
",",
"$",
"this",
"->",
"attribute",
",",
"$",
"options",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Generates hidden input inside hidden form-group.
@param array $options
@return $this | [
"Generates",
"hidden",
"input",
"inside",
"hidden",
"form",
"-",
"group",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/html/Field.php#L45-L51 |
31,240 | pulsarvp/vps-tools | src/html/Field.php | Field.render | public function render ($content = null)
{
// Custom error output.
$errors = $this->model->getErrors($this->attribute);
if (count($errors) == 0)
$this->parts[ '{error}' ] = '';
else
{
$class = isset($this->errorOptions[ 'class' ]) ? ' class="' . $this->errorOptions[ 'class' ] . '"' : '';
$this->parts[ '{error}' ] = '<div' . $class . '><ul class="list-unstyled">';
foreach ($errors as $e)
{
$this->parts[ '{error}' ] .= '<li>' . $e . '</li>';
}
$this->parts[ '{error}' ] .= '</ul></div>';
}
return parent::render($content);
} | php | public function render ($content = null)
{
// Custom error output.
$errors = $this->model->getErrors($this->attribute);
if (count($errors) == 0)
$this->parts[ '{error}' ] = '';
else
{
$class = isset($this->errorOptions[ 'class' ]) ? ' class="' . $this->errorOptions[ 'class' ] . '"' : '';
$this->parts[ '{error}' ] = '<div' . $class . '><ul class="list-unstyled">';
foreach ($errors as $e)
{
$this->parts[ '{error}' ] .= '<li>' . $e . '</li>';
}
$this->parts[ '{error}' ] .= '</ul></div>';
}
return parent::render($content);
} | [
"public",
"function",
"render",
"(",
"$",
"content",
"=",
"null",
")",
"{",
"// Custom error output.",
"$",
"errors",
"=",
"$",
"this",
"->",
"model",
"->",
"getErrors",
"(",
"$",
"this",
"->",
"attribute",
")",
";",
"if",
"(",
"count",
"(",
"$",
"errors",
")",
"==",
"0",
")",
"$",
"this",
"->",
"parts",
"[",
"'{error}'",
"]",
"=",
"''",
";",
"else",
"{",
"$",
"class",
"=",
"isset",
"(",
"$",
"this",
"->",
"errorOptions",
"[",
"'class'",
"]",
")",
"?",
"' class=\"'",
".",
"$",
"this",
"->",
"errorOptions",
"[",
"'class'",
"]",
".",
"'\"'",
":",
"''",
";",
"$",
"this",
"->",
"parts",
"[",
"'{error}'",
"]",
"=",
"'<div'",
".",
"$",
"class",
".",
"'><ul class=\"list-unstyled\">'",
";",
"foreach",
"(",
"$",
"errors",
"as",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"parts",
"[",
"'{error}'",
"]",
".=",
"'<li>'",
".",
"$",
"e",
".",
"'</li>'",
";",
"}",
"$",
"this",
"->",
"parts",
"[",
"'{error}'",
"]",
".=",
"'</ul></div>'",
";",
"}",
"return",
"parent",
"::",
"render",
"(",
"$",
"content",
")",
";",
"}"
] | This function overrides error output. All errors are displayed.
@inheritdoc | [
"This",
"function",
"overrides",
"error",
"output",
".",
"All",
"errors",
"are",
"displayed",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/html/Field.php#L111-L130 |
31,241 | pulsarvp/vps-tools | src/html/Field.php | Field.submit | public function submit ($text, $options = [])
{
$this->label(false);
$this->parts[ '{input}' ] = Html::submitButton($text, [ 'class' => 'btn btn-lg btn-primary', 'name' => 's-' . $this->attribute ]);
return $this;
} | php | public function submit ($text, $options = [])
{
$this->label(false);
$this->parts[ '{input}' ] = Html::submitButton($text, [ 'class' => 'btn btn-lg btn-primary', 'name' => 's-' . $this->attribute ]);
return $this;
} | [
"public",
"function",
"submit",
"(",
"$",
"text",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"label",
"(",
"false",
")",
";",
"$",
"this",
"->",
"parts",
"[",
"'{input}'",
"]",
"=",
"Html",
"::",
"submitButton",
"(",
"$",
"text",
",",
"[",
"'class'",
"=>",
"'btn btn-lg btn-primary'",
",",
"'name'",
"=>",
"'s-'",
".",
"$",
"this",
"->",
"attribute",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Renders submit button.
@param string $text
@param array $options
@return $this | [
"Renders",
"submit",
"button",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/html/Field.php#L240-L246 |
31,242 | pulsarvp/vps-tools | src/html/Field.php | Field.renderLabelParts | protected function renderLabelParts ($label = null, $options = [])
{
parent::renderLabelParts($label, $options);
if (!empty($this->parts[ '{labelTitle}' ]))
$this->parts[ '{labelTitle}' ] = Yii::tr($this->parts[ '{labelTitle}' ]);
} | php | protected function renderLabelParts ($label = null, $options = [])
{
parent::renderLabelParts($label, $options);
if (!empty($this->parts[ '{labelTitle}' ]))
$this->parts[ '{labelTitle}' ] = Yii::tr($this->parts[ '{labelTitle}' ]);
} | [
"protected",
"function",
"renderLabelParts",
"(",
"$",
"label",
"=",
"null",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"parent",
"::",
"renderLabelParts",
"(",
"$",
"label",
",",
"$",
"options",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"parts",
"[",
"'{labelTitle}'",
"]",
")",
")",
"$",
"this",
"->",
"parts",
"[",
"'{labelTitle}'",
"]",
"=",
"Yii",
"::",
"tr",
"(",
"$",
"this",
"->",
"parts",
"[",
"'{labelTitle}'",
"]",
")",
";",
"}"
] | Added translation for label title.
@inheritdoc | [
"Added",
"translation",
"for",
"label",
"title",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/html/Field.php#L289-L294 |
31,243 | cedx/yii2-mustache | lib/helpers/Url.php | Url.getBase | function getBase(): \Closure {
return function($value, \Mustache_LambdaHelper $helper) {
return UrlHelper::base($helper->render($value) ?: false);
};
} | php | function getBase(): \Closure {
return function($value, \Mustache_LambdaHelper $helper) {
return UrlHelper::base($helper->render($value) ?: false);
};
} | [
"function",
"getBase",
"(",
")",
":",
"\\",
"Closure",
"{",
"return",
"function",
"(",
"$",
"value",
",",
"\\",
"Mustache_LambdaHelper",
"$",
"helper",
")",
"{",
"return",
"UrlHelper",
"::",
"base",
"(",
"$",
"helper",
"->",
"render",
"(",
"$",
"value",
")",
"?",
":",
"false",
")",
";",
"}",
";",
"}"
] | Returns a function returning the base URL of the current request.
@return \Closure A function returning the base URL of the current request. | [
"Returns",
"a",
"function",
"returning",
"the",
"base",
"URL",
"of",
"the",
"current",
"request",
"."
] | 20c961e65e74a0bacbe992dd7fdb28319f58a919 | https://github.com/cedx/yii2-mustache/blob/20c961e65e74a0bacbe992dd7fdb28319f58a919/lib/helpers/Url.php#L23-L27 |
31,244 | cedx/yii2-mustache | lib/helpers/Url.php | Url.getCurrent | function getCurrent(): \Closure {
return function($value, \Mustache_LambdaHelper $helper) {
$args = $this->parseArguments($helper->render($value), 'params', ['scheme' => false]);
return UrlHelper::current($args['params'], $args['scheme']);
};
} | php | function getCurrent(): \Closure {
return function($value, \Mustache_LambdaHelper $helper) {
$args = $this->parseArguments($helper->render($value), 'params', ['scheme' => false]);
return UrlHelper::current($args['params'], $args['scheme']);
};
} | [
"function",
"getCurrent",
"(",
")",
":",
"\\",
"Closure",
"{",
"return",
"function",
"(",
"$",
"value",
",",
"\\",
"Mustache_LambdaHelper",
"$",
"helper",
")",
"{",
"$",
"args",
"=",
"$",
"this",
"->",
"parseArguments",
"(",
"$",
"helper",
"->",
"render",
"(",
"$",
"value",
")",
",",
"'params'",
",",
"[",
"'scheme'",
"=>",
"false",
"]",
")",
";",
"return",
"UrlHelper",
"::",
"current",
"(",
"$",
"args",
"[",
"'params'",
"]",
",",
"$",
"args",
"[",
"'scheme'",
"]",
")",
";",
"}",
";",
"}"
] | Returns a function creating a URL by using the current route and the GET parameters.
@return \Closure A function creating a URL by using the current route and the GET parameters. | [
"Returns",
"a",
"function",
"creating",
"a",
"URL",
"by",
"using",
"the",
"current",
"route",
"and",
"the",
"GET",
"parameters",
"."
] | 20c961e65e74a0bacbe992dd7fdb28319f58a919 | https://github.com/cedx/yii2-mustache/blob/20c961e65e74a0bacbe992dd7fdb28319f58a919/lib/helpers/Url.php#L41-L46 |
31,245 | cedx/yii2-mustache | lib/helpers/Url.php | Url.getHome | function getHome(): \Closure {
return function($value, \Mustache_LambdaHelper $helper) {
return UrlHelper::home($helper->render($value) ?: false);
};
} | php | function getHome(): \Closure {
return function($value, \Mustache_LambdaHelper $helper) {
return UrlHelper::home($helper->render($value) ?: false);
};
} | [
"function",
"getHome",
"(",
")",
":",
"\\",
"Closure",
"{",
"return",
"function",
"(",
"$",
"value",
",",
"\\",
"Mustache_LambdaHelper",
"$",
"helper",
")",
"{",
"return",
"UrlHelper",
"::",
"home",
"(",
"$",
"helper",
"->",
"render",
"(",
"$",
"value",
")",
"?",
":",
"false",
")",
";",
"}",
";",
"}"
] | Returns a function returning the home URL.
@return \Closure A function returning the home URL. | [
"Returns",
"a",
"function",
"returning",
"the",
"home",
"URL",
"."
] | 20c961e65e74a0bacbe992dd7fdb28319f58a919 | https://github.com/cedx/yii2-mustache/blob/20c961e65e74a0bacbe992dd7fdb28319f58a919/lib/helpers/Url.php#L52-L56 |
31,246 | cedx/yii2-mustache | lib/helpers/Url.php | Url.getPrevious | function getPrevious(): \Closure {
return function($value, \Mustache_LambdaHelper $helper) {
return UrlHelper::previous($helper->render($value) ?: null);
};
} | php | function getPrevious(): \Closure {
return function($value, \Mustache_LambdaHelper $helper) {
return UrlHelper::previous($helper->render($value) ?: null);
};
} | [
"function",
"getPrevious",
"(",
")",
":",
"\\",
"Closure",
"{",
"return",
"function",
"(",
"$",
"value",
",",
"\\",
"Mustache_LambdaHelper",
"$",
"helper",
")",
"{",
"return",
"UrlHelper",
"::",
"previous",
"(",
"$",
"helper",
"->",
"render",
"(",
"$",
"value",
")",
"?",
":",
"null",
")",
";",
"}",
";",
"}"
] | Returns a function returning the URL previously remembered.
@return \Closure A function returning the URL previously remembered. | [
"Returns",
"a",
"function",
"returning",
"the",
"URL",
"previously",
"remembered",
"."
] | 20c961e65e74a0bacbe992dd7fdb28319f58a919 | https://github.com/cedx/yii2-mustache/blob/20c961e65e74a0bacbe992dd7fdb28319f58a919/lib/helpers/Url.php#L62-L66 |
31,247 | cedx/yii2-mustache | lib/helpers/Url.php | Url.getTo | function getTo(): \Closure {
return function($value, \Mustache_LambdaHelper $helper) {
$args = $this->parseArguments($helper->render($value), 'url', ['scheme' => false]);
return UrlHelper::to($args['url'], $args['scheme']);
};
} | php | function getTo(): \Closure {
return function($value, \Mustache_LambdaHelper $helper) {
$args = $this->parseArguments($helper->render($value), 'url', ['scheme' => false]);
return UrlHelper::to($args['url'], $args['scheme']);
};
} | [
"function",
"getTo",
"(",
")",
":",
"\\",
"Closure",
"{",
"return",
"function",
"(",
"$",
"value",
",",
"\\",
"Mustache_LambdaHelper",
"$",
"helper",
")",
"{",
"$",
"args",
"=",
"$",
"this",
"->",
"parseArguments",
"(",
"$",
"helper",
"->",
"render",
"(",
"$",
"value",
")",
",",
"'url'",
",",
"[",
"'scheme'",
"=>",
"false",
"]",
")",
";",
"return",
"UrlHelper",
"::",
"to",
"(",
"$",
"args",
"[",
"'url'",
"]",
",",
"$",
"args",
"[",
"'scheme'",
"]",
")",
";",
"}",
";",
"}"
] | Returns a function creating a URL based on the given parameters.
@return \Closure A function creating a URL based on the given parameters. | [
"Returns",
"a",
"function",
"creating",
"a",
"URL",
"based",
"on",
"the",
"given",
"parameters",
"."
] | 20c961e65e74a0bacbe992dd7fdb28319f58a919 | https://github.com/cedx/yii2-mustache/blob/20c961e65e74a0bacbe992dd7fdb28319f58a919/lib/helpers/Url.php#L72-L77 |
31,248 | cedx/yii2-mustache | lib/helpers/Url.php | Url.getToRoute | function getToRoute(): \Closure {
return function($value, \Mustache_LambdaHelper $helper) {
$args = $this->parseArguments($helper->render($value), 'route', ['scheme' => false]);
return UrlHelper::toRoute($args['route'], $args['scheme']);
};
} | php | function getToRoute(): \Closure {
return function($value, \Mustache_LambdaHelper $helper) {
$args = $this->parseArguments($helper->render($value), 'route', ['scheme' => false]);
return UrlHelper::toRoute($args['route'], $args['scheme']);
};
} | [
"function",
"getToRoute",
"(",
")",
":",
"\\",
"Closure",
"{",
"return",
"function",
"(",
"$",
"value",
",",
"\\",
"Mustache_LambdaHelper",
"$",
"helper",
")",
"{",
"$",
"args",
"=",
"$",
"this",
"->",
"parseArguments",
"(",
"$",
"helper",
"->",
"render",
"(",
"$",
"value",
")",
",",
"'route'",
",",
"[",
"'scheme'",
"=>",
"false",
"]",
")",
";",
"return",
"UrlHelper",
"::",
"toRoute",
"(",
"$",
"args",
"[",
"'route'",
"]",
",",
"$",
"args",
"[",
"'scheme'",
"]",
")",
";",
"}",
";",
"}"
] | Returns a function creating a URL for the given route.
@return \Closure A function creating a URL for the given route. | [
"Returns",
"a",
"function",
"creating",
"a",
"URL",
"for",
"the",
"given",
"route",
"."
] | 20c961e65e74a0bacbe992dd7fdb28319f58a919 | https://github.com/cedx/yii2-mustache/blob/20c961e65e74a0bacbe992dd7fdb28319f58a919/lib/helpers/Url.php#L83-L88 |
31,249 | cedx/yii2-mustache | lib/helpers/Html.php | Html.getBeginBody | function getBeginBody(): string {
/** @var \yii\web\View|null $view */
$view = \Yii::$app->view;
if (!$view || !$view->hasMethod('beginBody')) return '';
return $this->captureOutput([$view, 'beginBody']);
} | php | function getBeginBody(): string {
/** @var \yii\web\View|null $view */
$view = \Yii::$app->view;
if (!$view || !$view->hasMethod('beginBody')) return '';
return $this->captureOutput([$view, 'beginBody']);
} | [
"function",
"getBeginBody",
"(",
")",
":",
"string",
"{",
"/** @var \\yii\\web\\View|null $view */",
"$",
"view",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"view",
";",
"if",
"(",
"!",
"$",
"view",
"||",
"!",
"$",
"view",
"->",
"hasMethod",
"(",
"'beginBody'",
")",
")",
"return",
"''",
";",
"return",
"$",
"this",
"->",
"captureOutput",
"(",
"[",
"$",
"view",
",",
"'beginBody'",
"]",
")",
";",
"}"
] | Returns the tag marking the beginning of an HTML body section.
@return string The tag marking the beginning of an HTML body section. | [
"Returns",
"the",
"tag",
"marking",
"the",
"beginning",
"of",
"an",
"HTML",
"body",
"section",
"."
] | 20c961e65e74a0bacbe992dd7fdb28319f58a919 | https://github.com/cedx/yii2-mustache/blob/20c961e65e74a0bacbe992dd7fdb28319f58a919/lib/helpers/Html.php#L24-L29 |
31,250 | cedx/yii2-mustache | lib/helpers/Html.php | Html.getEndBody | function getEndBody(): string {
/** @var \yii\web\View|null $view */
$view = \Yii::$app->view;
if (!$view || !$view->hasMethod('endBody')) return '';
return $this->captureOutput([$view, 'endBody']);
} | php | function getEndBody(): string {
/** @var \yii\web\View|null $view */
$view = \Yii::$app->view;
if (!$view || !$view->hasMethod('endBody')) return '';
return $this->captureOutput([$view, 'endBody']);
} | [
"function",
"getEndBody",
"(",
")",
":",
"string",
"{",
"/** @var \\yii\\web\\View|null $view */",
"$",
"view",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"view",
";",
"if",
"(",
"!",
"$",
"view",
"||",
"!",
"$",
"view",
"->",
"hasMethod",
"(",
"'endBody'",
")",
")",
"return",
"''",
";",
"return",
"$",
"this",
"->",
"captureOutput",
"(",
"[",
"$",
"view",
",",
"'endBody'",
"]",
")",
";",
"}"
] | Returns the tag marking the ending of an HTML body section.
@return string The tag marking the ending of an HTML body section. | [
"Returns",
"the",
"tag",
"marking",
"the",
"ending",
"of",
"an",
"HTML",
"body",
"section",
"."
] | 20c961e65e74a0bacbe992dd7fdb28319f58a919 | https://github.com/cedx/yii2-mustache/blob/20c961e65e74a0bacbe992dd7fdb28319f58a919/lib/helpers/Html.php#L35-L40 |
31,251 | cedx/yii2-mustache | lib/helpers/Html.php | Html.getHead | function getHead(): string {
/** @var \yii\web\View|null $view */
$view = \Yii::$app->view;
if (!$view || !$view->hasMethod('head')) return '';
return $this->captureOutput([$view, 'head']);
} | php | function getHead(): string {
/** @var \yii\web\View|null $view */
$view = \Yii::$app->view;
if (!$view || !$view->hasMethod('head')) return '';
return $this->captureOutput([$view, 'head']);
} | [
"function",
"getHead",
"(",
")",
":",
"string",
"{",
"/** @var \\yii\\web\\View|null $view */",
"$",
"view",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"view",
";",
"if",
"(",
"!",
"$",
"view",
"||",
"!",
"$",
"view",
"->",
"hasMethod",
"(",
"'head'",
")",
")",
"return",
"''",
";",
"return",
"$",
"this",
"->",
"captureOutput",
"(",
"[",
"$",
"view",
",",
"'head'",
"]",
")",
";",
"}"
] | Returns the tag marking the position of an HTML head section.
@return string The tag marking the position of an HTML head section. | [
"Returns",
"the",
"tag",
"marking",
"the",
"position",
"of",
"an",
"HTML",
"head",
"section",
"."
] | 20c961e65e74a0bacbe992dd7fdb28319f58a919 | https://github.com/cedx/yii2-mustache/blob/20c961e65e74a0bacbe992dd7fdb28319f58a919/lib/helpers/Html.php#L46-L51 |
31,252 | cedx/yii2-mustache | lib/helpers/Html.php | Html.getMarkdown | function getMarkdown(): \Closure {
return function($value, \Mustache_LambdaHelper $helper) {
$args = $this->parseArguments($helper->render($value), 'markdown', ['flavor' => Markdown::$defaultFlavor]);
return Markdown::process($args['markdown'], $args['flavor']);
};
} | php | function getMarkdown(): \Closure {
return function($value, \Mustache_LambdaHelper $helper) {
$args = $this->parseArguments($helper->render($value), 'markdown', ['flavor' => Markdown::$defaultFlavor]);
return Markdown::process($args['markdown'], $args['flavor']);
};
} | [
"function",
"getMarkdown",
"(",
")",
":",
"\\",
"Closure",
"{",
"return",
"function",
"(",
"$",
"value",
",",
"\\",
"Mustache_LambdaHelper",
"$",
"helper",
")",
"{",
"$",
"args",
"=",
"$",
"this",
"->",
"parseArguments",
"(",
"$",
"helper",
"->",
"render",
"(",
"$",
"value",
")",
",",
"'markdown'",
",",
"[",
"'flavor'",
"=>",
"Markdown",
"::",
"$",
"defaultFlavor",
"]",
")",
";",
"return",
"Markdown",
"::",
"process",
"(",
"$",
"args",
"[",
"'markdown'",
"]",
",",
"$",
"args",
"[",
"'flavor'",
"]",
")",
";",
"}",
";",
"}"
] | Returns a function converting Markdown into HTML.
@return \Closure A function converting Markdown into HTML. | [
"Returns",
"a",
"function",
"converting",
"Markdown",
"into",
"HTML",
"."
] | 20c961e65e74a0bacbe992dd7fdb28319f58a919 | https://github.com/cedx/yii2-mustache/blob/20c961e65e74a0bacbe992dd7fdb28319f58a919/lib/helpers/Html.php#L57-L62 |
31,253 | cedx/yii2-mustache | lib/helpers/Html.php | Html.getMarkdownParagraph | function getMarkdownParagraph(): \Closure {
return function($value, \Mustache_LambdaHelper $helper) {
$args = $this->parseArguments($helper->render($value), 'markdown', ['flavor' => Markdown::$defaultFlavor]);
return Markdown::processParagraph($args['markdown'], $args['flavor']);
};
} | php | function getMarkdownParagraph(): \Closure {
return function($value, \Mustache_LambdaHelper $helper) {
$args = $this->parseArguments($helper->render($value), 'markdown', ['flavor' => Markdown::$defaultFlavor]);
return Markdown::processParagraph($args['markdown'], $args['flavor']);
};
} | [
"function",
"getMarkdownParagraph",
"(",
")",
":",
"\\",
"Closure",
"{",
"return",
"function",
"(",
"$",
"value",
",",
"\\",
"Mustache_LambdaHelper",
"$",
"helper",
")",
"{",
"$",
"args",
"=",
"$",
"this",
"->",
"parseArguments",
"(",
"$",
"helper",
"->",
"render",
"(",
"$",
"value",
")",
",",
"'markdown'",
",",
"[",
"'flavor'",
"=>",
"Markdown",
"::",
"$",
"defaultFlavor",
"]",
")",
";",
"return",
"Markdown",
"::",
"processParagraph",
"(",
"$",
"args",
"[",
"'markdown'",
"]",
",",
"$",
"args",
"[",
"'flavor'",
"]",
")",
";",
"}",
";",
"}"
] | Returns a function converting Markdown into HTML but only parsing inline elements.
@return \Closure A function converting Markdown into HTML but only parsing inline elements. | [
"Returns",
"a",
"function",
"converting",
"Markdown",
"into",
"HTML",
"but",
"only",
"parsing",
"inline",
"elements",
"."
] | 20c961e65e74a0bacbe992dd7fdb28319f58a919 | https://github.com/cedx/yii2-mustache/blob/20c961e65e74a0bacbe992dd7fdb28319f58a919/lib/helpers/Html.php#L68-L73 |
31,254 | cedx/yii2-mustache | lib/helpers/Html.php | Html.getSpaceless | function getSpaceless(): \Closure {
return function($value, \Mustache_LambdaHelper $helper) {
return $this->captureOutput(function() use ($helper, $value) {
Spaceless::begin();
echo $helper->render($value);
Spaceless::end();
});
};
} | php | function getSpaceless(): \Closure {
return function($value, \Mustache_LambdaHelper $helper) {
return $this->captureOutput(function() use ($helper, $value) {
Spaceless::begin();
echo $helper->render($value);
Spaceless::end();
});
};
} | [
"function",
"getSpaceless",
"(",
")",
":",
"\\",
"Closure",
"{",
"return",
"function",
"(",
"$",
"value",
",",
"\\",
"Mustache_LambdaHelper",
"$",
"helper",
")",
"{",
"return",
"$",
"this",
"->",
"captureOutput",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"helper",
",",
"$",
"value",
")",
"{",
"Spaceless",
"::",
"begin",
"(",
")",
";",
"echo",
"$",
"helper",
"->",
"render",
"(",
"$",
"value",
")",
";",
"Spaceless",
"::",
"end",
"(",
")",
";",
"}",
")",
";",
"}",
";",
"}"
] | Returns a function removing whitespace characters between HTML tags.
@return \Closure A function removing whitespaces between HTML tags. | [
"Returns",
"a",
"function",
"removing",
"whitespace",
"characters",
"between",
"HTML",
"tags",
"."
] | 20c961e65e74a0bacbe992dd7fdb28319f58a919 | https://github.com/cedx/yii2-mustache/blob/20c961e65e74a0bacbe992dd7fdb28319f58a919/lib/helpers/Html.php#L79-L87 |
31,255 | cedx/yii2-mustache | lib/helpers/Html.php | Html.getViewTitle | function getViewTitle(): \Closure {
return function($value, \Mustache_LambdaHelper $helper) {
$view = \Yii::$app->view;
if ($view && $view->canSetProperty('title')) $view->title = trim($helper->render($value));
};
} | php | function getViewTitle(): \Closure {
return function($value, \Mustache_LambdaHelper $helper) {
$view = \Yii::$app->view;
if ($view && $view->canSetProperty('title')) $view->title = trim($helper->render($value));
};
} | [
"function",
"getViewTitle",
"(",
")",
":",
"\\",
"Closure",
"{",
"return",
"function",
"(",
"$",
"value",
",",
"\\",
"Mustache_LambdaHelper",
"$",
"helper",
")",
"{",
"$",
"view",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"view",
";",
"if",
"(",
"$",
"view",
"&&",
"$",
"view",
"->",
"canSetProperty",
"(",
"'title'",
")",
")",
"$",
"view",
"->",
"title",
"=",
"trim",
"(",
"$",
"helper",
"->",
"render",
"(",
"$",
"value",
")",
")",
";",
"}",
";",
"}"
] | Returns a function setting the view title.
@return \Closure A function setting the view title. | [
"Returns",
"a",
"function",
"setting",
"the",
"view",
"title",
"."
] | 20c961e65e74a0bacbe992dd7fdb28319f58a919 | https://github.com/cedx/yii2-mustache/blob/20c961e65e74a0bacbe992dd7fdb28319f58a919/lib/helpers/Html.php#L93-L98 |
31,256 | bearcms/bearframework-addon | classes/BearCMS/Internal/Data2/Addons.php | Addons.get | public function get(string $id)
{
$app = App::get();
$data = $app->data->getValue('bearcms/addons/addon/' . md5($id) . '.json');
if ($data !== null) {
return $this->makeAddonFromRawData($data);
}
return null;
} | php | public function get(string $id)
{
$app = App::get();
$data = $app->data->getValue('bearcms/addons/addon/' . md5($id) . '.json');
if ($data !== null) {
return $this->makeAddonFromRawData($data);
}
return null;
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"id",
")",
"{",
"$",
"app",
"=",
"App",
"::",
"get",
"(",
")",
";",
"$",
"data",
"=",
"$",
"app",
"->",
"data",
"->",
"getValue",
"(",
"'bearcms/addons/addon/'",
".",
"md5",
"(",
"$",
"id",
")",
".",
"'.json'",
")",
";",
"if",
"(",
"$",
"data",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"makeAddonFromRawData",
"(",
"$",
"data",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Retrieves information about the addon specified
@param string $id The addon ID
@return \IvoPetkov\DataObject|null The addon data or null if addon not found
@throws \InvalidArgumentException | [
"Retrieves",
"information",
"about",
"the",
"addon",
"specified"
] | 7ef131b81aac26070a2b937dd67f530a6caa02f0 | https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/Internal/Data2/Addons.php#L34-L42 |
31,257 | bearcms/bearframework-addon | classes/BearCMS/Internal/Data2/Addons.php | Addons.getList | public function getList()
{
$app = App::get();
$list = $app->data->getList()
->filterBy('key', 'bearcms/addons/addon/', 'startWith');
$result = [];
foreach ($list as $item) {
$result[] = $this->makeAddonFromRawData($item->value);
}
return new \IvoPetkov\DataList($result);
} | php | public function getList()
{
$app = App::get();
$list = $app->data->getList()
->filterBy('key', 'bearcms/addons/addon/', 'startWith');
$result = [];
foreach ($list as $item) {
$result[] = $this->makeAddonFromRawData($item->value);
}
return new \IvoPetkov\DataList($result);
} | [
"public",
"function",
"getList",
"(",
")",
"{",
"$",
"app",
"=",
"App",
"::",
"get",
"(",
")",
";",
"$",
"list",
"=",
"$",
"app",
"->",
"data",
"->",
"getList",
"(",
")",
"->",
"filterBy",
"(",
"'key'",
",",
"'bearcms/addons/addon/'",
",",
"'startWith'",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"item",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"this",
"->",
"makeAddonFromRawData",
"(",
"$",
"item",
"->",
"value",
")",
";",
"}",
"return",
"new",
"\\",
"IvoPetkov",
"\\",
"DataList",
"(",
"$",
"result",
")",
";",
"}"
] | Retrieves a list of all addons
@return \IvoPetkov\DataList List containing all addons data | [
"Retrieves",
"a",
"list",
"of",
"all",
"addons"
] | 7ef131b81aac26070a2b937dd67f530a6caa02f0 | https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/Internal/Data2/Addons.php#L49-L59 |
31,258 | wikimedia/slimapp | src/AbstractApp.php | AbstractApp.run | public function run() {
session_name( '_s' );
session_cache_limiter( false );
ini_set( 'session.cookie_httponly', true );
session_start();
register_shutdown_function( 'session_write_close' );
$this->slim->run();
} | php | public function run() {
session_name( '_s' );
session_cache_limiter( false );
ini_set( 'session.cookie_httponly', true );
session_start();
register_shutdown_function( 'session_write_close' );
$this->slim->run();
} | [
"public",
"function",
"run",
"(",
")",
"{",
"session_name",
"(",
"'_s'",
")",
";",
"session_cache_limiter",
"(",
"false",
")",
";",
"ini_set",
"(",
"'session.cookie_httponly'",
",",
"true",
")",
";",
"session_start",
"(",
")",
";",
"register_shutdown_function",
"(",
"'session_write_close'",
")",
";",
"$",
"this",
"->",
"slim",
"->",
"run",
"(",
")",
";",
"}"
] | Main entry point for all requests. | [
"Main",
"entry",
"point",
"for",
"all",
"requests",
"."
] | 9fd0deba96f635c96d28d59d1f761283f62842d4 | https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/AbstractApp.php#L165-L172 |
31,259 | wikimedia/slimapp | src/AbstractApp.php | AbstractApp.redirect | public static function redirect(
\Slim\Slim $slim, $name, $to, $routeName = null
) {
$routeName = $routeName ?: $name;
$slim->get( $name, function () use ( $slim, $name, $to ) {
$slim->flashKeep();
$slim->redirect( $slim->urlFor( $to ) );
} )->name( $routeName );
} | php | public static function redirect(
\Slim\Slim $slim, $name, $to, $routeName = null
) {
$routeName = $routeName ?: $name;
$slim->get( $name, function () use ( $slim, $name, $to ) {
$slim->flashKeep();
$slim->redirect( $slim->urlFor( $to ) );
} )->name( $routeName );
} | [
"public",
"static",
"function",
"redirect",
"(",
"\\",
"Slim",
"\\",
"Slim",
"$",
"slim",
",",
"$",
"name",
",",
"$",
"to",
",",
"$",
"routeName",
"=",
"null",
")",
"{",
"$",
"routeName",
"=",
"$",
"routeName",
"?",
":",
"$",
"name",
";",
"$",
"slim",
"->",
"get",
"(",
"$",
"name",
",",
"function",
"(",
")",
"use",
"(",
"$",
"slim",
",",
"$",
"name",
",",
"$",
"to",
")",
"{",
"$",
"slim",
"->",
"flashKeep",
"(",
")",
";",
"$",
"slim",
"->",
"redirect",
"(",
"$",
"slim",
"->",
"urlFor",
"(",
"$",
"to",
")",
")",
";",
"}",
")",
"->",
"name",
"(",
"$",
"routeName",
")",
";",
"}"
] | Add a redirect route to the app.
@param \Slim\Slim $slim App
@param string $name Page name
@param string $to Redirect target route name
@param string $routeName Name for the route | [
"Add",
"a",
"redirect",
"route",
"to",
"the",
"app",
"."
] | 9fd0deba96f635c96d28d59d1f761283f62842d4 | https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/AbstractApp.php#L181-L190 |
31,260 | wikimedia/slimapp | src/AbstractApp.php | AbstractApp.template | public static function template(
\Slim\Slim $slim, $name, $routeName = null
) {
$routeName = $routeName ?: $name;
$slim->get( $name, function () use ( $slim, $name ) {
$slim->render( "{$name}.html" );
} )->name( $routeName );
} | php | public static function template(
\Slim\Slim $slim, $name, $routeName = null
) {
$routeName = $routeName ?: $name;
$slim->get( $name, function () use ( $slim, $name ) {
$slim->render( "{$name}.html" );
} )->name( $routeName );
} | [
"public",
"static",
"function",
"template",
"(",
"\\",
"Slim",
"\\",
"Slim",
"$",
"slim",
",",
"$",
"name",
",",
"$",
"routeName",
"=",
"null",
")",
"{",
"$",
"routeName",
"=",
"$",
"routeName",
"?",
":",
"$",
"name",
";",
"$",
"slim",
"->",
"get",
"(",
"$",
"name",
",",
"function",
"(",
")",
"use",
"(",
"$",
"slim",
",",
"$",
"name",
")",
"{",
"$",
"slim",
"->",
"render",
"(",
"\"{$name}.html\"",
")",
";",
"}",
")",
"->",
"name",
"(",
"$",
"routeName",
")",
";",
"}"
] | Add a static template route to the app.
@param \Slim\Slim $slim App
@param string $name Page name
@param string $routeName Name for the route | [
"Add",
"a",
"static",
"template",
"route",
"to",
"the",
"app",
"."
] | 9fd0deba96f635c96d28d59d1f761283f62842d4 | https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/AbstractApp.php#L198-L206 |
31,261 | Jalle19/php-yui-compressor | lib/YUI/Compressor.php | Compressor.setType | public function setType($type)
{
if ($type === self::TYPE_CSS || $type === self::TYPE_JS)
$this->_options['type'] = $type;
else
throw new Exception('Invalid type: '.$type);
} | php | public function setType($type)
{
if ($type === self::TYPE_CSS || $type === self::TYPE_JS)
$this->_options['type'] = $type;
else
throw new Exception('Invalid type: '.$type);
} | [
"public",
"function",
"setType",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"type",
"===",
"self",
"::",
"TYPE_CSS",
"||",
"$",
"type",
"===",
"self",
"::",
"TYPE_JS",
")",
"$",
"this",
"->",
"_options",
"[",
"'type'",
"]",
"=",
"$",
"type",
";",
"else",
"throw",
"new",
"Exception",
"(",
"'Invalid type: '",
".",
"$",
"type",
")",
";",
"}"
] | Sets the compressor type. Valid values are TYPE_JS and TYPE_CSS. This
method can be used to change the compressor type after the class has
been instantiated.
@param string $type the type
@throws Exception if the type is invalid | [
"Sets",
"the",
"compressor",
"type",
".",
"Valid",
"values",
"are",
"TYPE_JS",
"and",
"TYPE_CSS",
".",
"This",
"method",
"can",
"be",
"used",
"to",
"change",
"the",
"compressor",
"type",
"after",
"the",
"class",
"has",
"been",
"instantiated",
"."
] | eb88c4f7fd8d7c8bd15a1970611d67cca11f71a0 | https://github.com/Jalle19/php-yui-compressor/blob/eb88c4f7fd8d7c8bd15a1970611d67cca11f71a0/lib/YUI/Compressor.php#L85-L91 |
31,262 | Jalle19/php-yui-compressor | lib/YUI/Compressor.php | Compressor.compress | public function compress($data)
{
// Construct the command
$cmd = $this->_options['javaPath'].' -jar '.escapeshellarg($this->_jarPath);
$cmd .= ' --charset '.$this->_options['charset'];
$cmd .= ' --type '.$this->_options['type'];
if ($this->_options['line-break'] !== false)
$cmd .= ' --line-break '.(int) $this->_options['line-break'];
if ($this->_options['verbose'])
$cmd .= " -v";
// Javascript-specific options
if ($this->_options['type'] === self::TYPE_JS)
foreach (self::$_javaScriptOptions as $option)
if ($this->_options[$option])
$cmd .= ' --'.$option;
// Run the command
$pipes = array();
$descriptors = array(
0=>array('pipe', 'r'),
1=>array('pipe', 'w'),
2=>array('pipe', 'w'),
);
$process = proc_open($cmd, $descriptors, $pipes);
if (is_resource($process))
{
// Write the data we want to compress to STDIN
fwrite($pipes[0], $data);
fclose($pipes[0]);
// Get the compressed data and eventual error from STDOUT and STDERR
$compressedData = stream_get_contents($pipes[1]);
$error = stream_get_contents($pipes[2]);
fclose($pipes[1]);
fclose($pipes[2]);
$return = proc_close($process);
// Throw an exception if compression fails
if ($return === 0)
return $compressedData;
else
throw new Exception('Failed to compress data: '.$error, $return);
}
throw new Exception('Failed to open a process');
} | php | public function compress($data)
{
// Construct the command
$cmd = $this->_options['javaPath'].' -jar '.escapeshellarg($this->_jarPath);
$cmd .= ' --charset '.$this->_options['charset'];
$cmd .= ' --type '.$this->_options['type'];
if ($this->_options['line-break'] !== false)
$cmd .= ' --line-break '.(int) $this->_options['line-break'];
if ($this->_options['verbose'])
$cmd .= " -v";
// Javascript-specific options
if ($this->_options['type'] === self::TYPE_JS)
foreach (self::$_javaScriptOptions as $option)
if ($this->_options[$option])
$cmd .= ' --'.$option;
// Run the command
$pipes = array();
$descriptors = array(
0=>array('pipe', 'r'),
1=>array('pipe', 'w'),
2=>array('pipe', 'w'),
);
$process = proc_open($cmd, $descriptors, $pipes);
if (is_resource($process))
{
// Write the data we want to compress to STDIN
fwrite($pipes[0], $data);
fclose($pipes[0]);
// Get the compressed data and eventual error from STDOUT and STDERR
$compressedData = stream_get_contents($pipes[1]);
$error = stream_get_contents($pipes[2]);
fclose($pipes[1]);
fclose($pipes[2]);
$return = proc_close($process);
// Throw an exception if compression fails
if ($return === 0)
return $compressedData;
else
throw new Exception('Failed to compress data: '.$error, $return);
}
throw new Exception('Failed to open a process');
} | [
"public",
"function",
"compress",
"(",
"$",
"data",
")",
"{",
"// Construct the command",
"$",
"cmd",
"=",
"$",
"this",
"->",
"_options",
"[",
"'javaPath'",
"]",
".",
"' -jar '",
".",
"escapeshellarg",
"(",
"$",
"this",
"->",
"_jarPath",
")",
";",
"$",
"cmd",
".=",
"' --charset '",
".",
"$",
"this",
"->",
"_options",
"[",
"'charset'",
"]",
";",
"$",
"cmd",
".=",
"' --type '",
".",
"$",
"this",
"->",
"_options",
"[",
"'type'",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"_options",
"[",
"'line-break'",
"]",
"!==",
"false",
")",
"$",
"cmd",
".=",
"' --line-break '",
".",
"(",
"int",
")",
"$",
"this",
"->",
"_options",
"[",
"'line-break'",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"_options",
"[",
"'verbose'",
"]",
")",
"$",
"cmd",
".=",
"\" -v\"",
";",
"// Javascript-specific options",
"if",
"(",
"$",
"this",
"->",
"_options",
"[",
"'type'",
"]",
"===",
"self",
"::",
"TYPE_JS",
")",
"foreach",
"(",
"self",
"::",
"$",
"_javaScriptOptions",
"as",
"$",
"option",
")",
"if",
"(",
"$",
"this",
"->",
"_options",
"[",
"$",
"option",
"]",
")",
"$",
"cmd",
".=",
"' --'",
".",
"$",
"option",
";",
"// Run the command",
"$",
"pipes",
"=",
"array",
"(",
")",
";",
"$",
"descriptors",
"=",
"array",
"(",
"0",
"=>",
"array",
"(",
"'pipe'",
",",
"'r'",
")",
",",
"1",
"=>",
"array",
"(",
"'pipe'",
",",
"'w'",
")",
",",
"2",
"=>",
"array",
"(",
"'pipe'",
",",
"'w'",
")",
",",
")",
";",
"$",
"process",
"=",
"proc_open",
"(",
"$",
"cmd",
",",
"$",
"descriptors",
",",
"$",
"pipes",
")",
";",
"if",
"(",
"is_resource",
"(",
"$",
"process",
")",
")",
"{",
"// Write the data we want to compress to STDIN",
"fwrite",
"(",
"$",
"pipes",
"[",
"0",
"]",
",",
"$",
"data",
")",
";",
"fclose",
"(",
"$",
"pipes",
"[",
"0",
"]",
")",
";",
"// Get the compressed data and eventual error from STDOUT and STDERR",
"$",
"compressedData",
"=",
"stream_get_contents",
"(",
"$",
"pipes",
"[",
"1",
"]",
")",
";",
"$",
"error",
"=",
"stream_get_contents",
"(",
"$",
"pipes",
"[",
"2",
"]",
")",
";",
"fclose",
"(",
"$",
"pipes",
"[",
"1",
"]",
")",
";",
"fclose",
"(",
"$",
"pipes",
"[",
"2",
"]",
")",
";",
"$",
"return",
"=",
"proc_close",
"(",
"$",
"process",
")",
";",
"// Throw an exception if compression fails",
"if",
"(",
"$",
"return",
"===",
"0",
")",
"return",
"$",
"compressedData",
";",
"else",
"throw",
"new",
"Exception",
"(",
"'Failed to compress data: '",
".",
"$",
"error",
",",
"$",
"return",
")",
";",
"}",
"throw",
"new",
"Exception",
"(",
"'Failed to open a process'",
")",
";",
"}"
] | Compresses the specified data and returns it
@param string $data the data
@return string the compressed data
@throws Exception if the compression fails | [
"Compresses",
"the",
"specified",
"data",
"and",
"returns",
"it"
] | eb88c4f7fd8d7c8bd15a1970611d67cca11f71a0 | https://github.com/Jalle19/php-yui-compressor/blob/eb88c4f7fd8d7c8bd15a1970611d67cca11f71a0/lib/YUI/Compressor.php#L99-L150 |
31,263 | shimabox/SMBArrayto | src/SMB/Arrayto/Traits/Ltsv/Creatable.php | Creatable.createOutputContents | protected function createOutputContents()
{
$formattedItems = $this->formatterInstance()->format($this->rows);
$ret = array();
foreach ($formattedItems as $label => $value) {
$ret[] = $label . ':' . $value;
}
return join("\t", $ret) . $this->EOL;
} | php | protected function createOutputContents()
{
$formattedItems = $this->formatterInstance()->format($this->rows);
$ret = array();
foreach ($formattedItems as $label => $value) {
$ret[] = $label . ':' . $value;
}
return join("\t", $ret) . $this->EOL;
} | [
"protected",
"function",
"createOutputContents",
"(",
")",
"{",
"$",
"formattedItems",
"=",
"$",
"this",
"->",
"formatterInstance",
"(",
")",
"->",
"format",
"(",
"$",
"this",
"->",
"rows",
")",
";",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"formattedItems",
"as",
"$",
"label",
"=>",
"$",
"value",
")",
"{",
"$",
"ret",
"[",
"]",
"=",
"$",
"label",
".",
"':'",
".",
"$",
"value",
";",
"}",
"return",
"join",
"(",
"\"\\t\"",
",",
"$",
"ret",
")",
".",
"$",
"this",
"->",
"EOL",
";",
"}"
] | Create an output content for Ltsv
@return string | [
"Create",
"an",
"output",
"content",
"for",
"Ltsv"
] | 7ecacc0c15994c02224bbd3efe055d3bce243971 | https://github.com/shimabox/SMBArrayto/blob/7ecacc0c15994c02224bbd3efe055d3bce243971/src/SMB/Arrayto/Traits/Ltsv/Creatable.php#L33-L43 |
31,264 | pulsarvp/vps-tools | src/helpers/Html.php | Html.buttonFa | public static function buttonFa ($text, $fa, $options = [])
{
$class = 'fa fa-' . $fa;
if (!empty(trim($text)))
$class .= ' margin';
$icon = self::tag('i', '', [ 'class' => $class ]);
if (!isset($options[ 'title' ]))
$options[ 'title' ] = $text;
if (isset($options[ 'raw' ]) and $options[ 'raw' ] == true)
{
unset($options[ 'raw' ]);
return parent::button($icon . $text, $options);
}
else
{
unset($options[ 'raw' ]);
return parent::button($icon . Yii::t('app', $text), $options);
}
} | php | public static function buttonFa ($text, $fa, $options = [])
{
$class = 'fa fa-' . $fa;
if (!empty(trim($text)))
$class .= ' margin';
$icon = self::tag('i', '', [ 'class' => $class ]);
if (!isset($options[ 'title' ]))
$options[ 'title' ] = $text;
if (isset($options[ 'raw' ]) and $options[ 'raw' ] == true)
{
unset($options[ 'raw' ]);
return parent::button($icon . $text, $options);
}
else
{
unset($options[ 'raw' ]);
return parent::button($icon . Yii::t('app', $text), $options);
}
} | [
"public",
"static",
"function",
"buttonFa",
"(",
"$",
"text",
",",
"$",
"fa",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"class",
"=",
"'fa fa-'",
".",
"$",
"fa",
";",
"if",
"(",
"!",
"empty",
"(",
"trim",
"(",
"$",
"text",
")",
")",
")",
"$",
"class",
".=",
"' margin'",
";",
"$",
"icon",
"=",
"self",
"::",
"tag",
"(",
"'i'",
",",
"''",
",",
"[",
"'class'",
"=>",
"$",
"class",
"]",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'title'",
"]",
")",
")",
"$",
"options",
"[",
"'title'",
"]",
"=",
"$",
"text",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'raw'",
"]",
")",
"and",
"$",
"options",
"[",
"'raw'",
"]",
"==",
"true",
")",
"{",
"unset",
"(",
"$",
"options",
"[",
"'raw'",
"]",
")",
";",
"return",
"parent",
"::",
"button",
"(",
"$",
"icon",
".",
"$",
"text",
",",
"$",
"options",
")",
";",
"}",
"else",
"{",
"unset",
"(",
"$",
"options",
"[",
"'raw'",
"]",
")",
";",
"return",
"parent",
"::",
"button",
"(",
"$",
"icon",
".",
"Yii",
"::",
"t",
"(",
"'app'",
",",
"$",
"text",
")",
",",
"$",
"options",
")",
";",
"}",
"}"
] | Creates button with FontAwesome icon.
```php
Html::buttonFa('Save', 'save', [ 'raw' => true ]);
// <button type="button"><i class="fa fa-save margin"></i>Save</button>
```
@param string $text Button text.
@param string $fa Icon name.
@param array $options Additional options.
@return string | [
"Creates",
"button",
"with",
"FontAwesome",
"icon",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/helpers/Html.php#L99-L120 |
31,265 | wikimedia/slimapp | src/Controller.php | Controller.flashGet | protected function flashGet( $key ) {
if ( isset( $this->slim->environment['slim.flash'] ) ) {
return $this->slim->environment['slim.flash'][$key];
} else {
return null;
}
} | php | protected function flashGet( $key ) {
if ( isset( $this->slim->environment['slim.flash'] ) ) {
return $this->slim->environment['slim.flash'][$key];
} else {
return null;
}
} | [
"protected",
"function",
"flashGet",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"slim",
"->",
"environment",
"[",
"'slim.flash'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"slim",
"->",
"environment",
"[",
"'slim.flash'",
"]",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] | Get a flash message.
@param string $key Message key
@return mixed|null | [
"Get",
"a",
"flash",
"message",
"."
] | 9fd0deba96f635c96d28d59d1f761283f62842d4 | https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/Controller.php#L163-L169 |
31,266 | wikimedia/slimapp | src/Controller.php | Controller.pagination | protected function pagination( $total, $current, $pageSize, $around = 4 ) {
$pageCount = ceil( $total / $pageSize );
$first = max( 0, $current - $around );
$last = min( max( 0, $pageCount - 1 ), $current + 4 );
return [ $pageCount, $first, $last ];
} | php | protected function pagination( $total, $current, $pageSize, $around = 4 ) {
$pageCount = ceil( $total / $pageSize );
$first = max( 0, $current - $around );
$last = min( max( 0, $pageCount - 1 ), $current + 4 );
return [ $pageCount, $first, $last ];
} | [
"protected",
"function",
"pagination",
"(",
"$",
"total",
",",
"$",
"current",
",",
"$",
"pageSize",
",",
"$",
"around",
"=",
"4",
")",
"{",
"$",
"pageCount",
"=",
"ceil",
"(",
"$",
"total",
"/",
"$",
"pageSize",
")",
";",
"$",
"first",
"=",
"max",
"(",
"0",
",",
"$",
"current",
"-",
"$",
"around",
")",
";",
"$",
"last",
"=",
"min",
"(",
"max",
"(",
"0",
",",
"$",
"pageCount",
"-",
"1",
")",
",",
"$",
"current",
"+",
"4",
")",
";",
"return",
"[",
"$",
"pageCount",
",",
"$",
"first",
",",
"$",
"last",
"]",
";",
"}"
] | Compute pagination data.
@param int $total Total records
@param int $current Current page number (0-indexed)
@param int $pageSize Number of items per page
@param int $around Numer of pages to show on each side of current
@return array Page count, first page index, last page index | [
"Compute",
"pagination",
"data",
"."
] | 9fd0deba96f635c96d28d59d1f761283f62842d4 | https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/Controller.php#L191-L196 |
31,267 | pulsarvp/vps-tools | src/controllers/DbController.php | DbController.actionRecreateViews | public function actionRecreateViews ()
{
$db = Yii::$app->db;
$views = $this->getViews();
foreach ($views as $view)
{
$info = $db->createCommand("SHOW CREATE VIEW `$view`")->queryAll();
$sql = $info[ 0 ][ 'Create View' ];
preg_match("/.*VIEW `$view` as (.*)/i", $sql, $match);
if (isset($match[ 1 ]))
{
$db->createCommand("CREATE OR REPLACE VIEW `$view` AS " . $match[ 1 ])->execute();
Console::printColor("View `$view` was recreated.", "green");
}
else
{
Console::printColor("Cannot find create string for view `$view`.", "red");
}
}
} | php | public function actionRecreateViews ()
{
$db = Yii::$app->db;
$views = $this->getViews();
foreach ($views as $view)
{
$info = $db->createCommand("SHOW CREATE VIEW `$view`")->queryAll();
$sql = $info[ 0 ][ 'Create View' ];
preg_match("/.*VIEW `$view` as (.*)/i", $sql, $match);
if (isset($match[ 1 ]))
{
$db->createCommand("CREATE OR REPLACE VIEW `$view` AS " . $match[ 1 ])->execute();
Console::printColor("View `$view` was recreated.", "green");
}
else
{
Console::printColor("Cannot find create string for view `$view`.", "red");
}
}
} | [
"public",
"function",
"actionRecreateViews",
"(",
")",
"{",
"$",
"db",
"=",
"Yii",
"::",
"$",
"app",
"->",
"db",
";",
"$",
"views",
"=",
"$",
"this",
"->",
"getViews",
"(",
")",
";",
"foreach",
"(",
"$",
"views",
"as",
"$",
"view",
")",
"{",
"$",
"info",
"=",
"$",
"db",
"->",
"createCommand",
"(",
"\"SHOW CREATE VIEW `$view`\"",
")",
"->",
"queryAll",
"(",
")",
";",
"$",
"sql",
"=",
"$",
"info",
"[",
"0",
"]",
"[",
"'Create View'",
"]",
";",
"preg_match",
"(",
"\"/.*VIEW `$view` as (.*)/i\"",
",",
"$",
"sql",
",",
"$",
"match",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"match",
"[",
"1",
"]",
")",
")",
"{",
"$",
"db",
"->",
"createCommand",
"(",
"\"CREATE OR REPLACE VIEW `$view` AS \"",
".",
"$",
"match",
"[",
"1",
"]",
")",
"->",
"execute",
"(",
")",
";",
"Console",
"::",
"printColor",
"(",
"\"View `$view` was recreated.\"",
",",
"\"green\"",
")",
";",
"}",
"else",
"{",
"Console",
"::",
"printColor",
"(",
"\"Cannot find create string for view `$view`.\"",
",",
"\"red\"",
")",
";",
"}",
"}",
"}"
] | List all views. This method is needed in order to match the database collection if it was changed. | [
"List",
"all",
"views",
".",
"This",
"method",
"is",
"needed",
"in",
"order",
"to",
"match",
"the",
"database",
"collection",
"if",
"it",
"was",
"changed",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/controllers/DbController.php#L17-L37 |
31,268 | cedx/yii2-mustache | lib/ViewRenderer.php | ViewRenderer.setHelpers | function setHelpers(array $value): self {
if ($this->engine) $this->engine->setHelpers($value);
else $this->helpers = $value;
return $this;
} | php | function setHelpers(array $value): self {
if ($this->engine) $this->engine->setHelpers($value);
else $this->helpers = $value;
return $this;
} | [
"function",
"setHelpers",
"(",
"array",
"$",
"value",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"engine",
")",
"$",
"this",
"->",
"engine",
"->",
"setHelpers",
"(",
"$",
"value",
")",
";",
"else",
"$",
"this",
"->",
"helpers",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the values to prepend to the context stack, so they will be available in any view loaded by this instance.
@param array $value The list of the values to prepend to the context stack.
@return $this This instance. | [
"Sets",
"the",
"values",
"to",
"prepend",
"to",
"the",
"context",
"stack",
"so",
"they",
"will",
"be",
"available",
"in",
"any",
"view",
"loaded",
"by",
"this",
"instance",
"."
] | 20c961e65e74a0bacbe992dd7fdb28319f58a919 | https://github.com/cedx/yii2-mustache/blob/20c961e65e74a0bacbe992dd7fdb28319f58a919/lib/ViewRenderer.php#L107-L111 |
31,269 | pulsarvp/vps-tools | src/components/ImageManager.php | ImageManager.saveImage | public function saveImage ($path, $file, $resize = false)
{
$filename = UuidHelper::generate() . '.' . $file->extension;
$name = $filename[ 0 ] . DIRECTORY_SEPARATOR . $filename[ 1 ] . DIRECTORY_SEPARATOR . $filename;
$filepath = $path . DIRECTORY_SEPARATOR . $name;
if ($resize)
{
$data = [];
foreach ($this->_formats() as $format)
{
$method = '_save' . ucfirst($format);
$this->$method($path, $name, $file->tempName);
$data[ $format ] = $path . DIRECTORY_SEPARATOR . $name;
}
if (file_exists($filepath))
return $data;
else
return false;
}
else
{
$this->_saveOriginal($path, $name, $file->tempName);
if (file_exists($filepath))
return [ self::F_ORIGINAL => $path . DIRECTORY_SEPARATOR . $name ];
else
return false;
}
} | php | public function saveImage ($path, $file, $resize = false)
{
$filename = UuidHelper::generate() . '.' . $file->extension;
$name = $filename[ 0 ] . DIRECTORY_SEPARATOR . $filename[ 1 ] . DIRECTORY_SEPARATOR . $filename;
$filepath = $path . DIRECTORY_SEPARATOR . $name;
if ($resize)
{
$data = [];
foreach ($this->_formats() as $format)
{
$method = '_save' . ucfirst($format);
$this->$method($path, $name, $file->tempName);
$data[ $format ] = $path . DIRECTORY_SEPARATOR . $name;
}
if (file_exists($filepath))
return $data;
else
return false;
}
else
{
$this->_saveOriginal($path, $name, $file->tempName);
if (file_exists($filepath))
return [ self::F_ORIGINAL => $path . DIRECTORY_SEPARATOR . $name ];
else
return false;
}
} | [
"public",
"function",
"saveImage",
"(",
"$",
"path",
",",
"$",
"file",
",",
"$",
"resize",
"=",
"false",
")",
"{",
"$",
"filename",
"=",
"UuidHelper",
"::",
"generate",
"(",
")",
".",
"'.'",
".",
"$",
"file",
"->",
"extension",
";",
"$",
"name",
"=",
"$",
"filename",
"[",
"0",
"]",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"filename",
"[",
"1",
"]",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"filename",
";",
"$",
"filepath",
"=",
"$",
"path",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"name",
";",
"if",
"(",
"$",
"resize",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_formats",
"(",
")",
"as",
"$",
"format",
")",
"{",
"$",
"method",
"=",
"'_save'",
".",
"ucfirst",
"(",
"$",
"format",
")",
";",
"$",
"this",
"->",
"$",
"method",
"(",
"$",
"path",
",",
"$",
"name",
",",
"$",
"file",
"->",
"tempName",
")",
";",
"$",
"data",
"[",
"$",
"format",
"]",
"=",
"$",
"path",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"name",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"filepath",
")",
")",
"return",
"$",
"data",
";",
"else",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_saveOriginal",
"(",
"$",
"path",
",",
"$",
"name",
",",
"$",
"file",
"->",
"tempName",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"filepath",
")",
")",
"return",
"[",
"self",
"::",
"F_ORIGINAL",
"=>",
"$",
"path",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"name",
"]",
";",
"else",
"return",
"false",
";",
"}",
"}"
] | Save all formats image.
@param string $path The path to the file.
@param UploadedFile $file The path to the source file.
```php
return Yii::$app->image->saveImage('var/www/site/data/img/author', $image);
```
@return bool|string | [
"Save",
"all",
"formats",
"image",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/ImageManager.php#L44-L72 |
31,270 | pulsarvp/vps-tools | src/components/ImageManager.php | ImageManager._resize | private function _resize (ImageInterface $image, BoxInterface $newSize)
{
$size = $image->getSize();
$ratio = min($newSize->getHeight() / $size->getHeight(), $newSize->getWidth() / $size->getWidth());
if ($ratio < 1)
$image->resize($size->scale($ratio));
} | php | private function _resize (ImageInterface $image, BoxInterface $newSize)
{
$size = $image->getSize();
$ratio = min($newSize->getHeight() / $size->getHeight(), $newSize->getWidth() / $size->getWidth());
if ($ratio < 1)
$image->resize($size->scale($ratio));
} | [
"private",
"function",
"_resize",
"(",
"ImageInterface",
"$",
"image",
",",
"BoxInterface",
"$",
"newSize",
")",
"{",
"$",
"size",
"=",
"$",
"image",
"->",
"getSize",
"(",
")",
";",
"$",
"ratio",
"=",
"min",
"(",
"$",
"newSize",
"->",
"getHeight",
"(",
")",
"/",
"$",
"size",
"->",
"getHeight",
"(",
")",
",",
"$",
"newSize",
"->",
"getWidth",
"(",
")",
"/",
"$",
"size",
"->",
"getWidth",
"(",
")",
")",
";",
"if",
"(",
"$",
"ratio",
"<",
"1",
")",
"$",
"image",
"->",
"resize",
"(",
"$",
"size",
"->",
"scale",
"(",
"$",
"ratio",
")",
")",
";",
"}"
] | Resize the image proportionally with max sizes constraints
@param ImageInterface $image
@param BoxInterface $newSize | [
"Resize",
"the",
"image",
"proportionally",
"with",
"max",
"sizes",
"constraints"
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/ImageManager.php#L92-L98 |
31,271 | pulsarvp/vps-tools | src/components/ImageManager.php | ImageManager._save | private function _save ($path, $file, $format)
{
$image = ( new Imagine() )->open($file);
$class = $this->config;
$params = $class::get($format);
$newSize = $this->_size($format);
if ($class::$fit == ImageSizeFit::WIDTH)
$this->resizeToWidth($image, $newSize->getWidth());
elseif ($class::$fit == ImageSizeFit::HEIGHT)
$this->resizeToHeight($image, $newSize->getHeight());
else
$this->_resize($image, $newSize);
FileHelper::createDirectory(dirname($path));
$image->save($path, [ 'jpeg_quality' => $params[ 'quality' ] ]);
} | php | private function _save ($path, $file, $format)
{
$image = ( new Imagine() )->open($file);
$class = $this->config;
$params = $class::get($format);
$newSize = $this->_size($format);
if ($class::$fit == ImageSizeFit::WIDTH)
$this->resizeToWidth($image, $newSize->getWidth());
elseif ($class::$fit == ImageSizeFit::HEIGHT)
$this->resizeToHeight($image, $newSize->getHeight());
else
$this->_resize($image, $newSize);
FileHelper::createDirectory(dirname($path));
$image->save($path, [ 'jpeg_quality' => $params[ 'quality' ] ]);
} | [
"private",
"function",
"_save",
"(",
"$",
"path",
",",
"$",
"file",
",",
"$",
"format",
")",
"{",
"$",
"image",
"=",
"(",
"new",
"Imagine",
"(",
")",
")",
"->",
"open",
"(",
"$",
"file",
")",
";",
"$",
"class",
"=",
"$",
"this",
"->",
"config",
";",
"$",
"params",
"=",
"$",
"class",
"::",
"get",
"(",
"$",
"format",
")",
";",
"$",
"newSize",
"=",
"$",
"this",
"->",
"_size",
"(",
"$",
"format",
")",
";",
"if",
"(",
"$",
"class",
"::",
"$",
"fit",
"==",
"ImageSizeFit",
"::",
"WIDTH",
")",
"$",
"this",
"->",
"resizeToWidth",
"(",
"$",
"image",
",",
"$",
"newSize",
"->",
"getWidth",
"(",
")",
")",
";",
"elseif",
"(",
"$",
"class",
"::",
"$",
"fit",
"==",
"ImageSizeFit",
"::",
"HEIGHT",
")",
"$",
"this",
"->",
"resizeToHeight",
"(",
"$",
"image",
",",
"$",
"newSize",
"->",
"getHeight",
"(",
")",
")",
";",
"else",
"$",
"this",
"->",
"_resize",
"(",
"$",
"image",
",",
"$",
"newSize",
")",
";",
"FileHelper",
"::",
"createDirectory",
"(",
"dirname",
"(",
"$",
"path",
")",
")",
";",
"$",
"image",
"->",
"save",
"(",
"$",
"path",
",",
"[",
"'jpeg_quality'",
"=>",
"$",
"params",
"[",
"'quality'",
"]",
"]",
")",
";",
"}"
] | Saves image to the format using sizes from settings.
@param string $path
@param string $dest
@param string $type
@param string $format | [
"Saves",
"image",
"to",
"the",
"format",
"using",
"sizes",
"from",
"settings",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/ImageManager.php#L108-L122 |
31,272 | pulsarvp/vps-tools | src/components/ImageManager.php | ImageManager._saveHd | private function _saveHd ($path, $name, $file)
{
$this->_save($path . DIRECTORY_SEPARATOR . self::F_HD . DIRECTORY_SEPARATOR . $name, $file, self::F_HD);
} | php | private function _saveHd ($path, $name, $file)
{
$this->_save($path . DIRECTORY_SEPARATOR . self::F_HD . DIRECTORY_SEPARATOR . $name, $file, self::F_HD);
} | [
"private",
"function",
"_saveHd",
"(",
"$",
"path",
",",
"$",
"name",
",",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"_save",
"(",
"$",
"path",
".",
"DIRECTORY_SEPARATOR",
".",
"self",
"::",
"F_HD",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"name",
",",
"$",
"file",
",",
"self",
"::",
"F_HD",
")",
";",
"}"
] | Saves a image to the HD format.
@param string $path
@param string $dest
@param string $type | [
"Saves",
"a",
"image",
"to",
"the",
"HD",
"format",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/ImageManager.php#L163-L166 |
31,273 | pulsarvp/vps-tools | src/components/ImageManager.php | ImageManager._saveOriginal | private function _saveOriginal ($path, $name, $file)
{
$filepath = $path . DIRECTORY_SEPARATOR . $name;
if (Yii::$app->settings->get('image_original_save', true))
{
FileHelper::createDirectory(dirname($filepath));
copy($file, $filepath);
}
} | php | private function _saveOriginal ($path, $name, $file)
{
$filepath = $path . DIRECTORY_SEPARATOR . $name;
if (Yii::$app->settings->get('image_original_save', true))
{
FileHelper::createDirectory(dirname($filepath));
copy($file, $filepath);
}
} | [
"private",
"function",
"_saveOriginal",
"(",
"$",
"path",
",",
"$",
"name",
",",
"$",
"file",
")",
"{",
"$",
"filepath",
"=",
"$",
"path",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"name",
";",
"if",
"(",
"Yii",
"::",
"$",
"app",
"->",
"settings",
"->",
"get",
"(",
"'image_original_save'",
",",
"true",
")",
")",
"{",
"FileHelper",
"::",
"createDirectory",
"(",
"dirname",
"(",
"$",
"filepath",
")",
")",
";",
"copy",
"(",
"$",
"file",
",",
"$",
"filepath",
")",
";",
"}",
"}"
] | Saves a image to the original format.
@param string $path
@param string $dest
@param string $type | [
"Saves",
"a",
"image",
"to",
"the",
"original",
"format",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/ImageManager.php#L175-L183 |
31,274 | pulsarvp/vps-tools | src/components/ImageManager.php | ImageManager._saveSd | private function _saveSd ($path, $name, $file)
{
$this->_save($path . DIRECTORY_SEPARATOR . self::F_SD . DIRECTORY_SEPARATOR . $name, $file, self::F_SD);
} | php | private function _saveSd ($path, $name, $file)
{
$this->_save($path . DIRECTORY_SEPARATOR . self::F_SD . DIRECTORY_SEPARATOR . $name, $file, self::F_SD);
} | [
"private",
"function",
"_saveSd",
"(",
"$",
"path",
",",
"$",
"name",
",",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"_save",
"(",
"$",
"path",
".",
"DIRECTORY_SEPARATOR",
".",
"self",
"::",
"F_SD",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"name",
",",
"$",
"file",
",",
"self",
"::",
"F_SD",
")",
";",
"}"
] | Saves a image to the SD format.
@param string $path
@param string $dest
@param string $type | [
"Saves",
"a",
"image",
"to",
"the",
"SD",
"format",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/ImageManager.php#L192-L195 |
31,275 | pulsarvp/vps-tools | src/modules/user/models/User.php | User.getRoleName | public function getRoleName ()
{
$auth = Yii::$app->getAuthManager();
$roles = $auth->getRolesByUser($this->id);
$role = current($roles);
return $role ? $role->name : null;
} | php | public function getRoleName ()
{
$auth = Yii::$app->getAuthManager();
$roles = $auth->getRolesByUser($this->id);
$role = current($roles);
return $role ? $role->name : null;
} | [
"public",
"function",
"getRoleName",
"(",
")",
"{",
"$",
"auth",
"=",
"Yii",
"::",
"$",
"app",
"->",
"getAuthManager",
"(",
")",
";",
"$",
"roles",
"=",
"$",
"auth",
"->",
"getRolesByUser",
"(",
"$",
"this",
"->",
"id",
")",
";",
"$",
"role",
"=",
"current",
"(",
"$",
"roles",
")",
";",
"return",
"$",
"role",
"?",
"$",
"role",
"->",
"name",
":",
"null",
";",
"}"
] | Gets user role.
@return string|null | [
"Gets",
"user",
"role",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/user/models/User.php#L57-L64 |
31,276 | pulsarvp/vps-tools | src/modules/user/models/User.php | User.getRolesNames | public function getRolesNames ()
{
$auth = Yii::$app->getAuthManager();
$rolesByUser = $auth->getRolesByUser($this->id);
$roles = ArrayHelper::objectsAttribute($rolesByUser, 'name');
return $roles;
} | php | public function getRolesNames ()
{
$auth = Yii::$app->getAuthManager();
$rolesByUser = $auth->getRolesByUser($this->id);
$roles = ArrayHelper::objectsAttribute($rolesByUser, 'name');
return $roles;
} | [
"public",
"function",
"getRolesNames",
"(",
")",
"{",
"$",
"auth",
"=",
"Yii",
"::",
"$",
"app",
"->",
"getAuthManager",
"(",
")",
";",
"$",
"rolesByUser",
"=",
"$",
"auth",
"->",
"getRolesByUser",
"(",
"$",
"this",
"->",
"id",
")",
";",
"$",
"roles",
"=",
"ArrayHelper",
"::",
"objectsAttribute",
"(",
"$",
"rolesByUser",
",",
"'name'",
")",
";",
"return",
"$",
"roles",
";",
"}"
] | Gets user all roles.
@return array | [
"Gets",
"user",
"all",
"roles",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/user/models/User.php#L71-L78 |
31,277 | pulsarvp/vps-tools | src/modules/user/models/User.php | User.register | public function register ($name, $email, $profile, $active)
{
$this->active = $active;
$this->name = $name;
$this->email = $email;
$this->profile = $profile;
$this->loginDT = TimeHelper::now();
return $this->save();
} | php | public function register ($name, $email, $profile, $active)
{
$this->active = $active;
$this->name = $name;
$this->email = $email;
$this->profile = $profile;
$this->loginDT = TimeHelper::now();
return $this->save();
} | [
"public",
"function",
"register",
"(",
"$",
"name",
",",
"$",
"email",
",",
"$",
"profile",
",",
"$",
"active",
")",
"{",
"$",
"this",
"->",
"active",
"=",
"$",
"active",
";",
"$",
"this",
"->",
"name",
"=",
"$",
"name",
";",
"$",
"this",
"->",
"email",
"=",
"$",
"email",
";",
"$",
"this",
"->",
"profile",
"=",
"$",
"profile",
";",
"$",
"this",
"->",
"loginDT",
"=",
"TimeHelper",
"::",
"now",
"(",
")",
";",
"return",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}"
] | Saves user with given parameters.
@param string $name
@param string $email
@param string $profile
@return bool Whether user save was successful. | [
"Saves",
"user",
"with",
"given",
"parameters",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/user/models/User.php#L154-L163 |
31,278 | bearcms/bearframework-addon | classes/BearCMS.php | BearCMS.disabledCheck | public function disabledCheck(): ?\BearFramework\App\Response
{
$currentUserExists = Config::hasServer() && (Config::hasFeature('USERS') || Config::hasFeature('USERS_LOGIN_*')) ? $this->currentUser->exists() : false;
$settings = $this->app->bearCMS->data->settings->get();
$isDisabled = !$currentUserExists && $settings->disabled;
if ($isDisabled) {
return new App\Response\TemporaryUnavailable(htmlspecialchars($settings->disabledText));
}
return null;
} | php | public function disabledCheck(): ?\BearFramework\App\Response
{
$currentUserExists = Config::hasServer() && (Config::hasFeature('USERS') || Config::hasFeature('USERS_LOGIN_*')) ? $this->currentUser->exists() : false;
$settings = $this->app->bearCMS->data->settings->get();
$isDisabled = !$currentUserExists && $settings->disabled;
if ($isDisabled) {
return new App\Response\TemporaryUnavailable(htmlspecialchars($settings->disabledText));
}
return null;
} | [
"public",
"function",
"disabledCheck",
"(",
")",
":",
"?",
"\\",
"BearFramework",
"\\",
"App",
"\\",
"Response",
"{",
"$",
"currentUserExists",
"=",
"Config",
"::",
"hasServer",
"(",
")",
"&&",
"(",
"Config",
"::",
"hasFeature",
"(",
"'USERS'",
")",
"||",
"Config",
"::",
"hasFeature",
"(",
"'USERS_LOGIN_*'",
")",
")",
"?",
"$",
"this",
"->",
"currentUser",
"->",
"exists",
"(",
")",
":",
"false",
";",
"$",
"settings",
"=",
"$",
"this",
"->",
"app",
"->",
"bearCMS",
"->",
"data",
"->",
"settings",
"->",
"get",
"(",
")",
";",
"$",
"isDisabled",
"=",
"!",
"$",
"currentUserExists",
"&&",
"$",
"settings",
"->",
"disabled",
";",
"if",
"(",
"$",
"isDisabled",
")",
"{",
"return",
"new",
"App",
"\\",
"Response",
"\\",
"TemporaryUnavailable",
"(",
"htmlspecialchars",
"(",
"$",
"settings",
"->",
"disabledText",
")",
")",
";",
"}",
"return",
"null",
";",
"}"
] | A middleware to be used in routes that returns a temporary unavailable response if an administrator has disabled the app.
@return \BearFramework\App\Response|null | [
"A",
"middleware",
"to",
"be",
"used",
"in",
"routes",
"that",
"returns",
"a",
"temporary",
"unavailable",
"response",
"if",
"an",
"administrator",
"has",
"disabled",
"the",
"app",
"."
] | 7ef131b81aac26070a2b937dd67f530a6caa02f0 | https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS.php#L1629-L1638 |
31,279 | czim/laravel-listify | src/Listify.php | Listify.setListifyConfig | public function setListifyConfig($key, $value)
{
switch ($key) {
case 'add_new_at':
if ( ! method_exists($this, "addToList{$value}")) {
throw new \UnexpectedValueException("No method exists for applying the add_new_at value '{$value}'.");
}
break;
case 'scope':
$normalizedScope = $this->normalizeListifyScope($value);
if (null !== $normalizedScope && ! is_string($normalizedScope)) {
throw new \InvalidArgumentException("Given list scope does not resolve to a usable where clause");
}
break;
// default omitted on purpose
}
$this->listifyConfig[ $key ] = $value;
if ($key === 'scope') {
$this->rememberCurrentlyUsedScope();
}
return $this;
} | php | public function setListifyConfig($key, $value)
{
switch ($key) {
case 'add_new_at':
if ( ! method_exists($this, "addToList{$value}")) {
throw new \UnexpectedValueException("No method exists for applying the add_new_at value '{$value}'.");
}
break;
case 'scope':
$normalizedScope = $this->normalizeListifyScope($value);
if (null !== $normalizedScope && ! is_string($normalizedScope)) {
throw new \InvalidArgumentException("Given list scope does not resolve to a usable where clause");
}
break;
// default omitted on purpose
}
$this->listifyConfig[ $key ] = $value;
if ($key === 'scope') {
$this->rememberCurrentlyUsedScope();
}
return $this;
} | [
"public",
"function",
"setListifyConfig",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"key",
")",
"{",
"case",
"'add_new_at'",
":",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"this",
",",
"\"addToList{$value}\"",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"\"No method exists for applying the add_new_at value '{$value}'.\"",
")",
";",
"}",
"break",
";",
"case",
"'scope'",
":",
"$",
"normalizedScope",
"=",
"$",
"this",
"->",
"normalizeListifyScope",
"(",
"$",
"value",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"normalizedScope",
"&&",
"!",
"is_string",
"(",
"$",
"normalizedScope",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Given list scope does not resolve to a usable where clause\"",
")",
";",
"}",
"break",
";",
"// default omitted on purpose",
"}",
"$",
"this",
"->",
"listifyConfig",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"if",
"(",
"$",
"key",
"===",
"'scope'",
")",
"{",
"$",
"this",
"->",
"rememberCurrentlyUsedScope",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets a listify config value.
@param string
@param mixed
@return $this | [
"Sets",
"a",
"listify",
"config",
"value",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L117-L146 |
31,280 | czim/laravel-listify | src/Listify.php | Listify.getListifyConfigValue | protected function getListifyConfigValue($key)
{
return array_key_exists($key, $this->listifyConfig) ? $this->listifyConfig[ $key ] : null;
} | php | protected function getListifyConfigValue($key)
{
return array_key_exists($key, $this->listifyConfig) ? $this->listifyConfig[ $key ] : null;
} | [
"protected",
"function",
"getListifyConfigValue",
"(",
"$",
"key",
")",
"{",
"return",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"listifyConfig",
")",
"?",
"$",
"this",
"->",
"listifyConfig",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}"
] | Returns a config value by key, or null if it does not exist.
@param string $key
@return null|mixed | [
"Returns",
"a",
"config",
"value",
"by",
"key",
"or",
"null",
"if",
"it",
"does",
"not",
"exist",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L194-L197 |
31,281 | czim/laravel-listify | src/Listify.php | Listify.scopeListifyScope | public function scopeListifyScope(Builder $query)
{
if (method_exists($this, 'cleanListifyScopedQuery')) {
$this->cleanListifyScopedQuery($query);
}
return $query->whereRaw($this->listifyScopeCondition());
} | php | public function scopeListifyScope(Builder $query)
{
if (method_exists($this, 'cleanListifyScopedQuery')) {
$this->cleanListifyScopedQuery($query);
}
return $query->whereRaw($this->listifyScopeCondition());
} | [
"public",
"function",
"scopeListifyScope",
"(",
"Builder",
"$",
"query",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'cleanListifyScopedQuery'",
")",
")",
"{",
"$",
"this",
"->",
"cleanListifyScopedQuery",
"(",
"$",
"query",
")",
";",
"}",
"return",
"$",
"query",
"->",
"whereRaw",
"(",
"$",
"this",
"->",
"listifyScopeCondition",
"(",
")",
")",
";",
"}"
] | Applies the listify scope to a query builder instance.
Eloquent scope method.
@param Builder|QueryBuilder $query
@return Builder|QueryBuilder | [
"Applies",
"the",
"listify",
"scope",
"to",
"a",
"query",
"builder",
"instance",
".",
"Eloquent",
"scope",
"method",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L211-L218 |
31,282 | czim/laravel-listify | src/Listify.php | Listify.scopeInList | public function scopeInList(Builder $query)
{
return $query->listifyScope()->whereNotNull($this->getTable() . "." . $this->positionColumn());
} | php | public function scopeInList(Builder $query)
{
return $query->listifyScope()->whereNotNull($this->getTable() . "." . $this->positionColumn());
} | [
"public",
"function",
"scopeInList",
"(",
"Builder",
"$",
"query",
")",
"{",
"return",
"$",
"query",
"->",
"listifyScope",
"(",
")",
"->",
"whereNotNull",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
".",
"\".\"",
".",
"$",
"this",
"->",
"positionColumn",
"(",
")",
")",
";",
"}"
] | Applies conditions to a query in order to retrieve only the records that are in a list.
Eloquent scope method.
@param Builder|QueryBuilder|Listify $query
@return Builder|QueryBuilder|Listify | [
"Applies",
"conditions",
"to",
"a",
"query",
"in",
"order",
"to",
"retrieve",
"only",
"the",
"records",
"that",
"are",
"in",
"a",
"list",
".",
"Eloquent",
"scope",
"method",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L227-L230 |
31,283 | czim/laravel-listify | src/Listify.php | Listify.addToListBottom | protected function addToListBottom()
{
if ($this->isInList()) return;
$newPosition = $this->getBottomPositionValue();
if (null === $newPosition) {
$newPosition = $this->listifyTop();
} else {
$newPosition += 1;
}
$this->setListifyPosition($newPosition);
} | php | protected function addToListBottom()
{
if ($this->isInList()) return;
$newPosition = $this->getBottomPositionValue();
if (null === $newPosition) {
$newPosition = $this->listifyTop();
} else {
$newPosition += 1;
}
$this->setListifyPosition($newPosition);
} | [
"protected",
"function",
"addToListBottom",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isInList",
"(",
")",
")",
"return",
";",
"$",
"newPosition",
"=",
"$",
"this",
"->",
"getBottomPositionValue",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"newPosition",
")",
"{",
"$",
"newPosition",
"=",
"$",
"this",
"->",
"listifyTop",
"(",
")",
";",
"}",
"else",
"{",
"$",
"newPosition",
"+=",
"1",
";",
"}",
"$",
"this",
"->",
"setListifyPosition",
"(",
"$",
"newPosition",
")",
";",
"}"
] | Adds record to the bottom of the list.
Note that this does not save the model. | [
"Adds",
"record",
"to",
"the",
"bottom",
"of",
"the",
"list",
".",
"Note",
"that",
"this",
"does",
"not",
"save",
"the",
"model",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L299-L312 |
31,284 | czim/laravel-listify | src/Listify.php | Listify.insertAt | public function insertAt($position = null)
{
if (null === $position) {
$position = $this->listifyTop();
}
$this->insertAtPositionAndReorder($position);
return $this;
} | php | public function insertAt($position = null)
{
if (null === $position) {
$position = $this->listifyTop();
}
$this->insertAtPositionAndReorder($position);
return $this;
} | [
"public",
"function",
"insertAt",
"(",
"$",
"position",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"position",
")",
"{",
"$",
"position",
"=",
"$",
"this",
"->",
"listifyTop",
"(",
")",
";",
"}",
"$",
"this",
"->",
"insertAtPositionAndReorder",
"(",
"$",
"position",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Inserts record at the given position.
This re-arranges the affected surrounding records.
@param integer $position default is listifyTop()
@return $this | [
"Inserts",
"record",
"at",
"the",
"given",
"position",
".",
"This",
"re",
"-",
"arranges",
"the",
"affected",
"surrounding",
"records",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L321-L330 |
31,285 | czim/laravel-listify | src/Listify.php | Listify.moveToBottom | public function moveToBottom()
{
if ($this->isNotInList()) return $this;
$this->getConnection()->transaction(function() {
$this->decrementPositionsOfItemsBelow();
$bottomPosition = $this->getBottomPositionValue($this);
$newPosition = (null === $bottomPosition) ? $this->listifyTop() : $bottomPosition + 1;
$this->setListPosition($newPosition);
});
return $this;
} | php | public function moveToBottom()
{
if ($this->isNotInList()) return $this;
$this->getConnection()->transaction(function() {
$this->decrementPositionsOfItemsBelow();
$bottomPosition = $this->getBottomPositionValue($this);
$newPosition = (null === $bottomPosition) ? $this->listifyTop() : $bottomPosition + 1;
$this->setListPosition($newPosition);
});
return $this;
} | [
"public",
"function",
"moveToBottom",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isNotInList",
"(",
")",
")",
"return",
"$",
"this",
";",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"transaction",
"(",
"function",
"(",
")",
"{",
"$",
"this",
"->",
"decrementPositionsOfItemsBelow",
"(",
")",
";",
"$",
"bottomPosition",
"=",
"$",
"this",
"->",
"getBottomPositionValue",
"(",
"$",
"this",
")",
";",
"$",
"newPosition",
"=",
"(",
"null",
"===",
"$",
"bottomPosition",
")",
"?",
"$",
"this",
"->",
"listifyTop",
"(",
")",
":",
"$",
"bottomPosition",
"+",
"1",
";",
"$",
"this",
"->",
"setListPosition",
"(",
"$",
"newPosition",
")",
";",
"}",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Moves the record to the bottom of the list.
This re-arranges the affected surrounding records.
@return $this | [
"Moves",
"the",
"record",
"to",
"the",
"bottom",
"of",
"the",
"list",
".",
"This",
"re",
"-",
"arranges",
"the",
"affected",
"surrounding",
"records",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L386-L401 |
31,286 | czim/laravel-listify | src/Listify.php | Listify.moveToTop | public function moveToTop()
{
if ($this->isNotInList()) return $this;
$this->getConnection()->transaction(function() {
$this->incrementPositionsOfItemsAbove();
$this->setListPosition($this->listifyTop());
});
return $this;
} | php | public function moveToTop()
{
if ($this->isNotInList()) return $this;
$this->getConnection()->transaction(function() {
$this->incrementPositionsOfItemsAbove();
$this->setListPosition($this->listifyTop());
});
return $this;
} | [
"public",
"function",
"moveToTop",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isNotInList",
"(",
")",
")",
"return",
"$",
"this",
";",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"transaction",
"(",
"function",
"(",
")",
"{",
"$",
"this",
"->",
"incrementPositionsOfItemsAbove",
"(",
")",
";",
"$",
"this",
"->",
"setListPosition",
"(",
"$",
"this",
"->",
"listifyTop",
"(",
")",
")",
";",
"}",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Moves the record to the top of the list.
This re-arranges the affected surrounding records.
@return $this | [
"Moves",
"the",
"record",
"to",
"the",
"top",
"of",
"the",
"list",
".",
"This",
"re",
"-",
"arranges",
"the",
"affected",
"surrounding",
"records",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L409-L421 |
31,287 | czim/laravel-listify | src/Listify.php | Listify.removeFromList | public function removeFromList()
{
if ( ! $this->isInList()) return $this;
$this->decrementPositionsOfItemsBelow();
$this->setListPosition(null);
return $this;
} | php | public function removeFromList()
{
if ( ! $this->isInList()) return $this;
$this->decrementPositionsOfItemsBelow();
$this->setListPosition(null);
return $this;
} | [
"public",
"function",
"removeFromList",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isInList",
"(",
")",
")",
"return",
"$",
"this",
";",
"$",
"this",
"->",
"decrementPositionsOfItemsBelow",
"(",
")",
";",
"$",
"this",
"->",
"setListPosition",
"(",
"null",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Removes the record from the list.
This re-arranges the affected surrounding records.
@return $this | [
"Removes",
"the",
"record",
"from",
"the",
"list",
".",
"This",
"re",
"-",
"arranges",
"the",
"affected",
"surrounding",
"records",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L429-L437 |
31,288 | czim/laravel-listify | src/Listify.php | Listify.decrementPosition | public function decrementPosition($count = 1)
{
if ($this->isNotInList()) return $this;
$newPosition = $this->getListifyPosition() - $count;
if ($newPosition < $this->listifyTop()) {
$newPosition = $this->listifyTop();
}
$this->setListifyPosition($newPosition);
return $this;
} | php | public function decrementPosition($count = 1)
{
if ($this->isNotInList()) return $this;
$newPosition = $this->getListifyPosition() - $count;
if ($newPosition < $this->listifyTop()) {
$newPosition = $this->listifyTop();
}
$this->setListifyPosition($newPosition);
return $this;
} | [
"public",
"function",
"decrementPosition",
"(",
"$",
"count",
"=",
"1",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isNotInList",
"(",
")",
")",
"return",
"$",
"this",
";",
"$",
"newPosition",
"=",
"$",
"this",
"->",
"getListifyPosition",
"(",
")",
"-",
"$",
"count",
";",
"if",
"(",
"$",
"newPosition",
"<",
"$",
"this",
"->",
"listifyTop",
"(",
")",
")",
"{",
"$",
"newPosition",
"=",
"$",
"this",
"->",
"listifyTop",
"(",
")",
";",
"}",
"$",
"this",
"->",
"setListifyPosition",
"(",
"$",
"newPosition",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Decrease the position of the record without affecting other record positions.
@param integer $count default 1
@return $this | [
"Decrease",
"the",
"position",
"of",
"the",
"record",
"without",
"affecting",
"other",
"record",
"positions",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L461-L474 |
31,289 | czim/laravel-listify | src/Listify.php | Listify.higherItems | public function higherItems($limit = null)
{
if ($this->isNotInList()) return null;
$query = $this->listifyScopedQuery()
->where($this->positionColumn(), '<', $this->getListifyPosition())
->orderBy($this->getTable() . '.' . $this->positionColumn(), 'DESC');
if (null !== $limit) {
$query->take($limit);
}
return $query->get();
} | php | public function higherItems($limit = null)
{
if ($this->isNotInList()) return null;
$query = $this->listifyScopedQuery()
->where($this->positionColumn(), '<', $this->getListifyPosition())
->orderBy($this->getTable() . '.' . $this->positionColumn(), 'DESC');
if (null !== $limit) {
$query->take($limit);
}
return $query->get();
} | [
"public",
"function",
"higherItems",
"(",
"$",
"limit",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isNotInList",
"(",
")",
")",
"return",
"null",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"listifyScopedQuery",
"(",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"positionColumn",
"(",
")",
",",
"'<'",
",",
"$",
"this",
"->",
"getListifyPosition",
"(",
")",
")",
"->",
"orderBy",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
".",
"'.'",
".",
"$",
"this",
"->",
"positionColumn",
"(",
")",
",",
"'DESC'",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"limit",
")",
"{",
"$",
"query",
"->",
"take",
"(",
"$",
"limit",
")",
";",
"}",
"return",
"$",
"query",
"->",
"get",
"(",
")",
";",
"}"
] | Returns a number of previous records on the list, above the current record.
@param null|integer $limit the maximum number of records to retrieve
@return \Illuminate\Database\Eloquent\Collection|static[] | [
"Returns",
"a",
"number",
"of",
"previous",
"records",
"on",
"the",
"list",
"above",
"the",
"current",
"record",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L523-L536 |
31,290 | czim/laravel-listify | src/Listify.php | Listify.lowerItem | public function lowerItem()
{
if ($this->isNotInList()) return null;
return $this->listifyScopedQuery()
->where($this->positionColumn(), '>', $this->getListifyPosition())
->orderBy($this->getTable() . '.' . $this->positionColumn())
->first();
} | php | public function lowerItem()
{
if ($this->isNotInList()) return null;
return $this->listifyScopedQuery()
->where($this->positionColumn(), '>', $this->getListifyPosition())
->orderBy($this->getTable() . '.' . $this->positionColumn())
->first();
} | [
"public",
"function",
"lowerItem",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isNotInList",
"(",
")",
")",
"return",
"null",
";",
"return",
"$",
"this",
"->",
"listifyScopedQuery",
"(",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"positionColumn",
"(",
")",
",",
"'>'",
",",
"$",
"this",
"->",
"getListifyPosition",
"(",
")",
")",
"->",
"orderBy",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
".",
"'.'",
".",
"$",
"this",
"->",
"positionColumn",
"(",
")",
")",
"->",
"first",
"(",
")",
";",
"}"
] | Returns the next record on the list, the one below the current record.
@return null|static | [
"Returns",
"the",
"next",
"record",
"on",
"the",
"list",
"the",
"one",
"below",
"the",
"current",
"record",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L544-L552 |
31,291 | czim/laravel-listify | src/Listify.php | Listify.hasListifyScopeChanged | protected function hasListifyScopeChanged()
{
$scope = $this->normalizeListifyScope($this->getScopeName(), true);
if ($scope instanceof BelongsTo) {
// for BelongsTo scopes, use a cleaner way to check for differences
$foreignKey = $scope->getForeignKeyName();
return (Arr::get($this->getOriginal(), $foreignKey) != $this->getAttribute($foreignKey));
}
if (null === $this->stringScopeValue && ! $this->stringScopeNullExplicitlySet) {
// if the known previous scope is null, make sure this isn't the result of a
// variable scope that returned null - if that is the case, the scope has changed
if (null !== $scope && $this->hasVariableListifyScope()) {
$this->swapChangedAttributes();
$previousScope = $this->normalizeListifyScope($this->getScopeName());
$this->swapChangedAttributes();
if (null === $previousScope) return true;
}
$this->stringScopeValue = $scope;
$this->stringScopeNullExplicitlySet = (null === $scope);
return false;
}
return ($scope != $this->stringScopeValue);
} | php | protected function hasListifyScopeChanged()
{
$scope = $this->normalizeListifyScope($this->getScopeName(), true);
if ($scope instanceof BelongsTo) {
// for BelongsTo scopes, use a cleaner way to check for differences
$foreignKey = $scope->getForeignKeyName();
return (Arr::get($this->getOriginal(), $foreignKey) != $this->getAttribute($foreignKey));
}
if (null === $this->stringScopeValue && ! $this->stringScopeNullExplicitlySet) {
// if the known previous scope is null, make sure this isn't the result of a
// variable scope that returned null - if that is the case, the scope has changed
if (null !== $scope && $this->hasVariableListifyScope()) {
$this->swapChangedAttributes();
$previousScope = $this->normalizeListifyScope($this->getScopeName());
$this->swapChangedAttributes();
if (null === $previousScope) return true;
}
$this->stringScopeValue = $scope;
$this->stringScopeNullExplicitlySet = (null === $scope);
return false;
}
return ($scope != $this->stringScopeValue);
} | [
"protected",
"function",
"hasListifyScopeChanged",
"(",
")",
"{",
"$",
"scope",
"=",
"$",
"this",
"->",
"normalizeListifyScope",
"(",
"$",
"this",
"->",
"getScopeName",
"(",
")",
",",
"true",
")",
";",
"if",
"(",
"$",
"scope",
"instanceof",
"BelongsTo",
")",
"{",
"// for BelongsTo scopes, use a cleaner way to check for differences",
"$",
"foreignKey",
"=",
"$",
"scope",
"->",
"getForeignKeyName",
"(",
")",
";",
"return",
"(",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"getOriginal",
"(",
")",
",",
"$",
"foreignKey",
")",
"!=",
"$",
"this",
"->",
"getAttribute",
"(",
"$",
"foreignKey",
")",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"stringScopeValue",
"&&",
"!",
"$",
"this",
"->",
"stringScopeNullExplicitlySet",
")",
"{",
"// if the known previous scope is null, make sure this isn't the result of a",
"// variable scope that returned null - if that is the case, the scope has changed",
"if",
"(",
"null",
"!==",
"$",
"scope",
"&&",
"$",
"this",
"->",
"hasVariableListifyScope",
"(",
")",
")",
"{",
"$",
"this",
"->",
"swapChangedAttributes",
"(",
")",
";",
"$",
"previousScope",
"=",
"$",
"this",
"->",
"normalizeListifyScope",
"(",
"$",
"this",
"->",
"getScopeName",
"(",
")",
")",
";",
"$",
"this",
"->",
"swapChangedAttributes",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"previousScope",
")",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"stringScopeValue",
"=",
"$",
"scope",
";",
"$",
"this",
"->",
"stringScopeNullExplicitlySet",
"=",
"(",
"null",
"===",
"$",
"scope",
")",
";",
"return",
"false",
";",
"}",
"return",
"(",
"$",
"scope",
"!=",
"$",
"this",
"->",
"stringScopeValue",
")",
";",
"}"
] | Returns whether the scope has changed since it was last applied.
Note that this also updates the last known scope, resetting the changed state back to false
@return boolean | [
"Returns",
"whether",
"the",
"scope",
"has",
"changed",
"since",
"it",
"was",
"last",
"applied",
".",
"Note",
"that",
"this",
"also",
"updates",
"the",
"last",
"known",
"scope",
"resetting",
"the",
"changed",
"state",
"back",
"to",
"false"
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L648-L677 |
31,292 | czim/laravel-listify | src/Listify.php | Listify.normalizeListifyScope | protected function normalizeListifyScope($scope, $doNotResolveBelongsTo = false)
{
if ($scope instanceof BelongsTo) {
if ($doNotResolveBelongsTo) return $scope;
return $this->getConditionStringFromBelongsTo($scope);
}
if ($scope instanceof QueryBuilder) {
return $this->getConditionStringFromQueryBuilder($scope);
}
if (is_callable($scope)) {
return $this->normalizeListifyScope( $scope($this) );
}
// scope can only be a string in this case
return $scope;
} | php | protected function normalizeListifyScope($scope, $doNotResolveBelongsTo = false)
{
if ($scope instanceof BelongsTo) {
if ($doNotResolveBelongsTo) return $scope;
return $this->getConditionStringFromBelongsTo($scope);
}
if ($scope instanceof QueryBuilder) {
return $this->getConditionStringFromQueryBuilder($scope);
}
if (is_callable($scope)) {
return $this->normalizeListifyScope( $scope($this) );
}
// scope can only be a string in this case
return $scope;
} | [
"protected",
"function",
"normalizeListifyScope",
"(",
"$",
"scope",
",",
"$",
"doNotResolveBelongsTo",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"scope",
"instanceof",
"BelongsTo",
")",
"{",
"if",
"(",
"$",
"doNotResolveBelongsTo",
")",
"return",
"$",
"scope",
";",
"return",
"$",
"this",
"->",
"getConditionStringFromBelongsTo",
"(",
"$",
"scope",
")",
";",
"}",
"if",
"(",
"$",
"scope",
"instanceof",
"QueryBuilder",
")",
"{",
"return",
"$",
"this",
"->",
"getConditionStringFromQueryBuilder",
"(",
"$",
"scope",
")",
";",
"}",
"if",
"(",
"is_callable",
"(",
"$",
"scope",
")",
")",
"{",
"return",
"$",
"this",
"->",
"normalizeListifyScope",
"(",
"$",
"scope",
"(",
"$",
"this",
")",
")",
";",
"}",
"// scope can only be a string in this case",
"return",
"$",
"scope",
";",
"}"
] | Normalizes the currently applicable list scope to a string
or BelongsTo relation instance.
@param mixed $scope
@param boolean $doNotResolveBelongsTo if true, does not stringify a BelongsTo instance
@return string|BelongsTo | [
"Normalizes",
"the",
"currently",
"applicable",
"list",
"scope",
"to",
"a",
"string",
"or",
"BelongsTo",
"relation",
"instance",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L712-L730 |
31,293 | czim/laravel-listify | src/Listify.php | Listify.listifyScopeCondition | protected function listifyScopeCondition()
{
$this->stringScopeValue = $this->normalizeListifyScope($this->getScopeName());
$this->stringScopeNullExplicitlySet = (null === $this->stringScopeValue);
return $this->stringScopeValue;
} | php | protected function listifyScopeCondition()
{
$this->stringScopeValue = $this->normalizeListifyScope($this->getScopeName());
$this->stringScopeNullExplicitlySet = (null === $this->stringScopeValue);
return $this->stringScopeValue;
} | [
"protected",
"function",
"listifyScopeCondition",
"(",
")",
"{",
"$",
"this",
"->",
"stringScopeValue",
"=",
"$",
"this",
"->",
"normalizeListifyScope",
"(",
"$",
"this",
"->",
"getScopeName",
"(",
")",
")",
";",
"$",
"this",
"->",
"stringScopeNullExplicitlySet",
"=",
"(",
"null",
"===",
"$",
"this",
"->",
"stringScopeValue",
")",
";",
"return",
"$",
"this",
"->",
"stringScopeValue",
";",
"}"
] | Returns string version of current listify scope.
@return string | [
"Returns",
"string",
"version",
"of",
"current",
"listify",
"scope",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L737-L744 |
31,294 | czim/laravel-listify | src/Listify.php | Listify.listifyScopedQuery | protected function listifyScopedQuery()
{
$model = new static;
$model->setListifyConfig('scope', $this->listifyScopeCondition());
// if set, call a method that may be used to remove global scopes
// and other automatically active listify-scope breaking clauses
if (method_exists($this, 'cleanListifyScopedQuery')) {
$model = $this->cleanListifyScopedQuery($model);
}
return $model->whereRaw($this->listifyScopeCondition());
} | php | protected function listifyScopedQuery()
{
$model = new static;
$model->setListifyConfig('scope', $this->listifyScopeCondition());
// if set, call a method that may be used to remove global scopes
// and other automatically active listify-scope breaking clauses
if (method_exists($this, 'cleanListifyScopedQuery')) {
$model = $this->cleanListifyScopedQuery($model);
}
return $model->whereRaw($this->listifyScopeCondition());
} | [
"protected",
"function",
"listifyScopedQuery",
"(",
")",
"{",
"$",
"model",
"=",
"new",
"static",
";",
"$",
"model",
"->",
"setListifyConfig",
"(",
"'scope'",
",",
"$",
"this",
"->",
"listifyScopeCondition",
"(",
")",
")",
";",
"// if set, call a method that may be used to remove global scopes",
"// and other automatically active listify-scope breaking clauses",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'cleanListifyScopedQuery'",
")",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"cleanListifyScopedQuery",
"(",
"$",
"model",
")",
";",
"}",
"return",
"$",
"model",
"->",
"whereRaw",
"(",
"$",
"this",
"->",
"listifyScopeCondition",
"(",
")",
")",
";",
"}"
] | Returns a fresh query builder after re-applying the listify scope condition.
@return Builder | [
"Returns",
"a",
"fresh",
"query",
"builder",
"after",
"re",
"-",
"applying",
"the",
"listify",
"scope",
"condition",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L752-L765 |
31,295 | czim/laravel-listify | src/Listify.php | Listify.handleListifyScopeChange | protected function handleListifyScopeChange()
{
if ( ! $this->hasListifyScopeChanged()) return;
$this->rememberCurrentlyUsedScope();
// swap the attributes so the record is scoped in its old scope
$this->swapChangedAttributes();
if ( ! $this->excludeFromList() && $this->lowerItem()) {
$this->decrementPositionsOfItemsBelow();
}
// swap the attributes back, so the item can be positioned in its new scope
$this->swapChangedAttributes();
// unset its position, so it will get the correct new position in its new scope
$this->setListifyPosition(null);
$this->performConfiguredAddMethod($this);
} | php | protected function handleListifyScopeChange()
{
if ( ! $this->hasListifyScopeChanged()) return;
$this->rememberCurrentlyUsedScope();
// swap the attributes so the record is scoped in its old scope
$this->swapChangedAttributes();
if ( ! $this->excludeFromList() && $this->lowerItem()) {
$this->decrementPositionsOfItemsBelow();
}
// swap the attributes back, so the item can be positioned in its new scope
$this->swapChangedAttributes();
// unset its position, so it will get the correct new position in its new scope
$this->setListifyPosition(null);
$this->performConfiguredAddMethod($this);
} | [
"protected",
"function",
"handleListifyScopeChange",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasListifyScopeChanged",
"(",
")",
")",
"return",
";",
"$",
"this",
"->",
"rememberCurrentlyUsedScope",
"(",
")",
";",
"// swap the attributes so the record is scoped in its old scope",
"$",
"this",
"->",
"swapChangedAttributes",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"excludeFromList",
"(",
")",
"&&",
"$",
"this",
"->",
"lowerItem",
"(",
")",
")",
"{",
"$",
"this",
"->",
"decrementPositionsOfItemsBelow",
"(",
")",
";",
"}",
"// swap the attributes back, so the item can be positioned in its new scope",
"$",
"this",
"->",
"swapChangedAttributes",
"(",
")",
";",
"// unset its position, so it will get the correct new position in its new scope",
"$",
"this",
"->",
"setListifyPosition",
"(",
"null",
")",
";",
"$",
"this",
"->",
"performConfiguredAddMethod",
"(",
"$",
"this",
")",
";",
"}"
] | Checks and handles when the model's list scope has changed.
Makes sure that the old list positions are adjusted and the model
is correctly placed in the new list. | [
"Checks",
"and",
"handles",
"when",
"the",
"model",
"s",
"list",
"scope",
"has",
"changed",
".",
"Makes",
"sure",
"that",
"the",
"old",
"list",
"positions",
"are",
"adjusted",
"and",
"the",
"model",
"is",
"correctly",
"placed",
"in",
"the",
"new",
"list",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L772-L792 |
31,296 | czim/laravel-listify | src/Listify.php | Listify.reorderPositionsOnItemsBetween | protected function reorderPositionsOnItemsBetween($positionBefore, $positionAfter, $ignoreId = null)
{
if ($positionBefore == $positionAfter) {
return;
}
$query = $this->listifyScopedQuery();
if ($ignoreId) {
$query->where($this->getPrimaryKey(), '!=', $ignoreId);
}
if ($positionBefore < $positionAfter) {
// increment the in-between positions
$query
->where($this->positionColumn(), '>', $positionBefore)
->where($this->positionColumn(), '<=', $positionAfter)
->decrement($this->positionColumn());
} else {
// decrement the in-between positions
$query
->where($this->positionColumn(), '>=', $positionAfter)
->where($this->positionColumn(), '<', $positionBefore)
->increment($this->positionColumn());
}
} | php | protected function reorderPositionsOnItemsBetween($positionBefore, $positionAfter, $ignoreId = null)
{
if ($positionBefore == $positionAfter) {
return;
}
$query = $this->listifyScopedQuery();
if ($ignoreId) {
$query->where($this->getPrimaryKey(), '!=', $ignoreId);
}
if ($positionBefore < $positionAfter) {
// increment the in-between positions
$query
->where($this->positionColumn(), '>', $positionBefore)
->where($this->positionColumn(), '<=', $positionAfter)
->decrement($this->positionColumn());
} else {
// decrement the in-between positions
$query
->where($this->positionColumn(), '>=', $positionAfter)
->where($this->positionColumn(), '<', $positionBefore)
->increment($this->positionColumn());
}
} | [
"protected",
"function",
"reorderPositionsOnItemsBetween",
"(",
"$",
"positionBefore",
",",
"$",
"positionAfter",
",",
"$",
"ignoreId",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"positionBefore",
"==",
"$",
"positionAfter",
")",
"{",
"return",
";",
"}",
"$",
"query",
"=",
"$",
"this",
"->",
"listifyScopedQuery",
"(",
")",
";",
"if",
"(",
"$",
"ignoreId",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
",",
"'!='",
",",
"$",
"ignoreId",
")",
";",
"}",
"if",
"(",
"$",
"positionBefore",
"<",
"$",
"positionAfter",
")",
"{",
"// increment the in-between positions",
"$",
"query",
"->",
"where",
"(",
"$",
"this",
"->",
"positionColumn",
"(",
")",
",",
"'>'",
",",
"$",
"positionBefore",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"positionColumn",
"(",
")",
",",
"'<='",
",",
"$",
"positionAfter",
")",
"->",
"decrement",
"(",
"$",
"this",
"->",
"positionColumn",
"(",
")",
")",
";",
"}",
"else",
"{",
"// decrement the in-between positions",
"$",
"query",
"->",
"where",
"(",
"$",
"this",
"->",
"positionColumn",
"(",
")",
",",
"'>='",
",",
"$",
"positionAfter",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"positionColumn",
"(",
")",
",",
"'<'",
",",
"$",
"positionBefore",
")",
"->",
"increment",
"(",
"$",
"this",
"->",
"positionColumn",
"(",
")",
")",
";",
"}",
"}"
] | Reorders the positions of all items between two affected positions.
@param integer $positionBefore
@param integer $positionAfter
@param null|integer $ignoreId | [
"Reorders",
"the",
"positions",
"of",
"all",
"items",
"between",
"two",
"affected",
"positions",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L828-L856 |
31,297 | czim/laravel-listify | src/Listify.php | Listify.decrementPositionsOfItemsBelow | protected function decrementPositionsOfItemsBelow($position = null)
{
if ($this->isNotInList()) return;
if (null === $position) {
$position = $this->getListifyPosition();
}
$this->listifyScopedQuery()
->where($this->positionColumn(), '>', $position)
->decrement($this->positionColumn());
} | php | protected function decrementPositionsOfItemsBelow($position = null)
{
if ($this->isNotInList()) return;
if (null === $position) {
$position = $this->getListifyPosition();
}
$this->listifyScopedQuery()
->where($this->positionColumn(), '>', $position)
->decrement($this->positionColumn());
} | [
"protected",
"function",
"decrementPositionsOfItemsBelow",
"(",
"$",
"position",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isNotInList",
"(",
")",
")",
"return",
";",
"if",
"(",
"null",
"===",
"$",
"position",
")",
"{",
"$",
"position",
"=",
"$",
"this",
"->",
"getListifyPosition",
"(",
")",
";",
"}",
"$",
"this",
"->",
"listifyScopedQuery",
"(",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"positionColumn",
"(",
")",
",",
"'>'",
",",
"$",
"position",
")",
"->",
"decrement",
"(",
"$",
"this",
"->",
"positionColumn",
"(",
")",
")",
";",
"}"
] | Increments the position values of records with a higher position value than the given.
Note that 'below' means a higher position value.
@param null|integer $position if null, uses this record's current position | [
"Increments",
"the",
"position",
"values",
"of",
"records",
"with",
"a",
"higher",
"position",
"value",
"than",
"the",
"given",
".",
"Note",
"that",
"below",
"means",
"a",
"higher",
"position",
"value",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L864-L875 |
31,298 | czim/laravel-listify | src/Listify.php | Listify.incrementPositionsOfItemsAbove | protected function incrementPositionsOfItemsAbove($position = null)
{
if ($this->isNotInList()) return;
if (null === $position) {
$position = $this->getListifyPosition();
}
$this->listifyScopedQuery()
->where($this->positionColumn(), '<', $position)
->increment($this->positionColumn());
} | php | protected function incrementPositionsOfItemsAbove($position = null)
{
if ($this->isNotInList()) return;
if (null === $position) {
$position = $this->getListifyPosition();
}
$this->listifyScopedQuery()
->where($this->positionColumn(), '<', $position)
->increment($this->positionColumn());
} | [
"protected",
"function",
"incrementPositionsOfItemsAbove",
"(",
"$",
"position",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isNotInList",
"(",
")",
")",
"return",
";",
"if",
"(",
"null",
"===",
"$",
"position",
")",
"{",
"$",
"position",
"=",
"$",
"this",
"->",
"getListifyPosition",
"(",
")",
";",
"}",
"$",
"this",
"->",
"listifyScopedQuery",
"(",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"positionColumn",
"(",
")",
",",
"'<'",
",",
"$",
"position",
")",
"->",
"increment",
"(",
"$",
"this",
"->",
"positionColumn",
"(",
")",
")",
";",
"}"
] | Increments the position values of records with a lower position value than the given.
Note that 'above' means a lower position value.
@param null|integer $position if null, uses this record's current position | [
"Increments",
"the",
"position",
"values",
"of",
"records",
"with",
"a",
"lower",
"position",
"value",
"than",
"the",
"given",
".",
"Note",
"that",
"above",
"means",
"a",
"lower",
"position",
"value",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L883-L894 |
31,299 | czim/laravel-listify | src/Listify.php | Listify.incrementPositionsOfItemsBelow | protected function incrementPositionsOfItemsBelow($position)
{
$this->listifyScopedQuery()
->where($this->positionColumn(), '>=', $position)
->increment($this->positionColumn());
} | php | protected function incrementPositionsOfItemsBelow($position)
{
$this->listifyScopedQuery()
->where($this->positionColumn(), '>=', $position)
->increment($this->positionColumn());
} | [
"protected",
"function",
"incrementPositionsOfItemsBelow",
"(",
"$",
"position",
")",
"{",
"$",
"this",
"->",
"listifyScopedQuery",
"(",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"positionColumn",
"(",
")",
",",
"'>='",
",",
"$",
"position",
")",
"->",
"increment",
"(",
"$",
"this",
"->",
"positionColumn",
"(",
")",
")",
";",
"}"
] | Increments the position values of records with a lower position value than the given.
Note that 'below' means a smaller position value.
@param integer $position if null, uses this record's current position | [
"Increments",
"the",
"position",
"values",
"of",
"records",
"with",
"a",
"lower",
"position",
"value",
"than",
"the",
"given",
".",
"Note",
"that",
"below",
"means",
"a",
"smaller",
"position",
"value",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L902-L907 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.