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 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
thejacer87/php-canadapost-api | src/ClientBase.php | ClientBase.buildClient | protected function buildClient(array &$options)
{
if (!isset($options['debug']) && $this->config['env'] === self::ENV_DEVELOPMENT) {
$options['debug'] = true;
}
if (!isset($options['handler'])) {
return new GuzzleClient();
}
$client = new GuzzleClient(['handler' => $options['handler']]);
unset($options['handler']);
return $client;
} | php | protected function buildClient(array &$options)
{
if (!isset($options['debug']) && $this->config['env'] === self::ENV_DEVELOPMENT) {
$options['debug'] = true;
}
if (!isset($options['handler'])) {
return new GuzzleClient();
}
$client = new GuzzleClient(['handler' => $options['handler']]);
unset($options['handler']);
return $client;
} | [
"protected",
"function",
"buildClient",
"(",
"array",
"&",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'debug'",
"]",
")",
"&&",
"$",
"this",
"->",
"config",
"[",
"'env'",
"]",
"===",
"self",
"::",
"ENV_DEVELOPMENT",
... | Build the Guzzle client.
@param array $options
The options array.
@return \GuzzleHttp\Client | [
"Build",
"the",
"Guzzle",
"client",
"."
] | 1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a | https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/ClientBase.php#L380-L393 | train |
thejacer87/php-canadapost-api | src/ClientBase.php | ClientBase.verifyDates | protected function verifyDates($from, $to, $format = 'YmdHs')
{
if (!DateTime::createFromFormat($format, $from)) {
$message = 'The $from date is improperly formatted. Please use "YmdHs".';
throw new \InvalidArgumentException($message);
}
if (!DateTime::createFromFormat($format, $to)) {
$message = 'The $to date is improperly formatted. Please use "YmdHs".';
throw new \InvalidArgumentException($message);
}
if (new DateTime($from) > new DateTime($to)) {
$message = 'The $from date cannot be a later date than the $to date.';
throw new \InvalidArgumentException($message);
}
} | php | protected function verifyDates($from, $to, $format = 'YmdHs')
{
if (!DateTime::createFromFormat($format, $from)) {
$message = 'The $from date is improperly formatted. Please use "YmdHs".';
throw new \InvalidArgumentException($message);
}
if (!DateTime::createFromFormat($format, $to)) {
$message = 'The $to date is improperly formatted. Please use "YmdHs".';
throw new \InvalidArgumentException($message);
}
if (new DateTime($from) > new DateTime($to)) {
$message = 'The $from date cannot be a later date than the $to date.';
throw new \InvalidArgumentException($message);
}
} | [
"protected",
"function",
"verifyDates",
"(",
"$",
"from",
",",
"$",
"to",
",",
"$",
"format",
"=",
"'YmdHs'",
")",
"{",
"if",
"(",
"!",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"format",
",",
"$",
"from",
")",
")",
"{",
"$",
"message",
"=",
... | Helper function to verify the dates are valid.
@param string $from
The beginning date.
@param $to
The end date.
@param string $format
The date format to verify.
@throws \InvalidArgumentException | [
"Helper",
"function",
"to",
"verify",
"the",
"dates",
"are",
"valid",
"."
] | 1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a | https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/ClientBase.php#L420-L434 | train |
thejacer87/php-canadapost-api | src/ClientBase.php | ClientBase.parseOptionCodes | protected function parseOptionCodes(array $options)
{
$valid_options = [];
foreach ($options['option_codes'] as $optionCode) {
if (!array_key_exists(strtoupper($optionCode), self::getOptionCodes())) {
$message = sprintf(
'Unsupported option code: "%s". Supported options are %s',
$optionCode,
implode(', ', array_keys(self::getOptionCodes()))
);
throw new \InvalidArgumentException($message);
}
// @todo Perhaps we should check for conflicts here, might be overkill.
// From Canada Post docs:
// There are some options that can be applied to a shipment that
// conflict with the presence of another option. You can use the
// "Get Option" call in advance to check the contents of the
// <conflicting-options> group from a Get Option call for options
// selected by end users or options available for a given service.
$valid_options[] = [
'option-code' => $optionCode,
];
}
return $valid_options;
} | php | protected function parseOptionCodes(array $options)
{
$valid_options = [];
foreach ($options['option_codes'] as $optionCode) {
if (!array_key_exists(strtoupper($optionCode), self::getOptionCodes())) {
$message = sprintf(
'Unsupported option code: "%s". Supported options are %s',
$optionCode,
implode(', ', array_keys(self::getOptionCodes()))
);
throw new \InvalidArgumentException($message);
}
// @todo Perhaps we should check for conflicts here, might be overkill.
// From Canada Post docs:
// There are some options that can be applied to a shipment that
// conflict with the presence of another option. You can use the
// "Get Option" call in advance to check the contents of the
// <conflicting-options> group from a Get Option call for options
// selected by end users or options available for a given service.
$valid_options[] = [
'option-code' => $optionCode,
];
}
return $valid_options;
} | [
"protected",
"function",
"parseOptionCodes",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"valid_options",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"options",
"[",
"'option_codes'",
"]",
"as",
"$",
"optionCode",
")",
"{",
"if",
"(",
"!",
"array_key_exists"... | Helper function to extract the option codes.
@param array $options
The options array.
@return array
The list of options with the option-code. | [
"Helper",
"function",
"to",
"extract",
"the",
"option",
"codes",
"."
] | 1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a | https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/ClientBase.php#L445-L470 | train |
pulsarvp/vps-tools | src/controllers/WebController.php | WebController.error | public function error ($message, $isRaw = false)
{
Yii::$app->notification->error($message, $isRaw);
} | php | public function error ($message, $isRaw = false)
{
Yii::$app->notification->error($message, $isRaw);
} | [
"public",
"function",
"error",
"(",
"$",
"message",
",",
"$",
"isRaw",
"=",
"false",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"notification",
"->",
"error",
"(",
"$",
"message",
",",
"$",
"isRaw",
")",
";",
"}"
] | Add user error message.
@param string $message Message text.
@param boolean $isRaw Whether given text is raw. If not it will be processed with [[Yii::tr()]]. | [
"Add",
"user",
"error",
"message",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/controllers/WebController.php#L144-L147 | train |
pulsarvp/vps-tools | src/controllers/WebController.php | WebController.message | public function message ($message, $isRaw = false)
{
Yii::$app->notification->message($message, $isRaw);
} | php | public function message ($message, $isRaw = false)
{
Yii::$app->notification->message($message, $isRaw);
} | [
"public",
"function",
"message",
"(",
"$",
"message",
",",
"$",
"isRaw",
"=",
"false",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"notification",
"->",
"message",
"(",
"$",
"message",
",",
"$",
"isRaw",
")",
";",
"}"
] | Add user message.
@param string $message Message text.
@param boolean $isRaw Whether given text is raw. If not it will be processed with [[Yii::tr()]]. | [
"Add",
"user",
"message",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/controllers/WebController.php#L155-L158 | train |
pulsarvp/vps-tools | src/controllers/WebController.php | WebController.redirect | public function redirect ($url, $statusCode = 302)
{
parent::redirect($url, $statusCode);
Yii::$app->end();
} | php | public function redirect ($url, $statusCode = 302)
{
parent::redirect($url, $statusCode);
Yii::$app->end();
} | [
"public",
"function",
"redirect",
"(",
"$",
"url",
",",
"$",
"statusCode",
"=",
"302",
")",
"{",
"parent",
"::",
"redirect",
"(",
"$",
"url",
",",
"$",
"statusCode",
")",
";",
"Yii",
"::",
"$",
"app",
"->",
"end",
"(",
")",
";",
"}"
] | Redirects and ends app. That prevents from sending additional headers.
@inheritdoc | [
"Redirects",
"and",
"ends",
"app",
".",
"That",
"prevents",
"from",
"sending",
"additional",
"headers",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/controllers/WebController.php#L165-L169 | train |
pulsarvp/vps-tools | src/controllers/WebController.php | WebController.warning | public function warning ($message, $isRaw = false)
{
Yii::$app->notification->warning($message, $isRaw);
} | php | public function warning ($message, $isRaw = false)
{
Yii::$app->notification->warning($message, $isRaw);
} | [
"public",
"function",
"warning",
"(",
"$",
"message",
",",
"$",
"isRaw",
"=",
"false",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"notification",
"->",
"warning",
"(",
"$",
"message",
",",
"$",
"isRaw",
")",
";",
"}"
] | Add user warning.
@param string $message Message text.
@param boolean $isRaw Whether given text is raw. If not it will be processed with [[Yii::tr()]]. | [
"Add",
"user",
"warning",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/controllers/WebController.php#L177-L180 | train |
pulsarvp/vps-tools | src/controllers/WebController.php | WebController.forceSetTitle | private function forceSetTitle ()
{
if (isset($this->_data[ 'title' ]))
return;
$path = Yii::$app->controller->id . '/' . Yii::$app->controller->action->id;
if (Yii::$app->has('menu'))
{
foreach (Yii::$app->menu as $menu)
{
if ($menu->path === $path)
{
$this->setTitle($menu->name);
return;
}
}
}
$this->setTitle(ucfirst(strtolower(Yii::$app->controller->id . ' ' . Yii::$app->controller->action->id)));
} | php | private function forceSetTitle ()
{
if (isset($this->_data[ 'title' ]))
return;
$path = Yii::$app->controller->id . '/' . Yii::$app->controller->action->id;
if (Yii::$app->has('menu'))
{
foreach (Yii::$app->menu as $menu)
{
if ($menu->path === $path)
{
$this->setTitle($menu->name);
return;
}
}
}
$this->setTitle(ucfirst(strtolower(Yii::$app->controller->id . ' ' . Yii::$app->controller->action->id)));
} | [
"private",
"function",
"forceSetTitle",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_data",
"[",
"'title'",
"]",
")",
")",
"return",
";",
"$",
"path",
"=",
"Yii",
"::",
"$",
"app",
"->",
"controller",
"->",
"id",
".",
"'/'",
".",
... | Force generate title if not set previously. | [
"Force",
"generate",
"title",
"if",
"not",
"set",
"previously",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/controllers/WebController.php#L185-L205 | train |
wikimedia/slimapp | src/Config.php | Config.getBool | public static function getBool( $name, $default = false ) {
$var = getenv( $name );
$val = filter_var( $var, \FILTER_VALIDATE_BOOLEAN, \FILTER_NULL_ON_FAILURE );
return ( $val === null ) ? $default : $val;
} | php | public static function getBool( $name, $default = false ) {
$var = getenv( $name );
$val = filter_var( $var, \FILTER_VALIDATE_BOOLEAN, \FILTER_NULL_ON_FAILURE );
return ( $val === null ) ? $default : $val;
} | [
"public",
"static",
"function",
"getBool",
"(",
"$",
"name",
",",
"$",
"default",
"=",
"false",
")",
"{",
"$",
"var",
"=",
"getenv",
"(",
"$",
"name",
")",
";",
"$",
"val",
"=",
"filter_var",
"(",
"$",
"var",
",",
"\\",
"FILTER_VALIDATE_BOOLEAN",
","... | Get a boolean value
@param string $name Setting name
@param bool $default Default value if none found
@return bool Value | [
"Get",
"a",
"boolean",
"value"
] | 9fd0deba96f635c96d28d59d1f761283f62842d4 | https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/Config.php#L39-L43 | train |
wikimedia/slimapp | src/Config.php | Config.getStr | public static function getStr( $name, $default = '' ) {
$var = getenv( $name );
if ( $var !== false ) {
$var = filter_var( $var,
\FILTER_SANITIZE_STRING,
\FILTER_FLAG_STRIP_LOW | \FILTER_FLAG_STRIP_HIGH
);
}
return ( $var === false ) ? $default : $var;
} | php | public static function getStr( $name, $default = '' ) {
$var = getenv( $name );
if ( $var !== false ) {
$var = filter_var( $var,
\FILTER_SANITIZE_STRING,
\FILTER_FLAG_STRIP_LOW | \FILTER_FLAG_STRIP_HIGH
);
}
return ( $var === false ) ? $default : $var;
} | [
"public",
"static",
"function",
"getStr",
"(",
"$",
"name",
",",
"$",
"default",
"=",
"''",
")",
"{",
"$",
"var",
"=",
"getenv",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"var",
"!==",
"false",
")",
"{",
"$",
"var",
"=",
"filter_var",
"(",
"$... | Get a string value
@param string $name Setting name
@param string $default Default value if none found
@return string Value | [
"Get",
"a",
"string",
"value"
] | 9fd0deba96f635c96d28d59d1f761283f62842d4 | https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/Config.php#L51-L60 | train |
wikimedia/slimapp | src/Config.php | Config.load | public static function load( $file ) {
if ( !is_readable( $file ) ) {
throw new \InvalidArgumentException( "File '{$file}' is not readable." );
}
$settings = parse_ini_file( $file );
foreach ( $settings as $key => $value ) {
// Store in super globals
$_ENV[$key] = $value;
$_SERVER[$key] = $value;
// Also store in process env vars
putenv( "{$key}={$value}" );
} // end foreach settings
} | php | public static function load( $file ) {
if ( !is_readable( $file ) ) {
throw new \InvalidArgumentException( "File '{$file}' is not readable." );
}
$settings = parse_ini_file( $file );
foreach ( $settings as $key => $value ) {
// Store in super globals
$_ENV[$key] = $value;
$_SERVER[$key] = $value;
// Also store in process env vars
putenv( "{$key}={$value}" );
} // end foreach settings
} | [
"public",
"static",
"function",
"load",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"File '{$file}' is not readable.\"",
")",
";",
"}",
"$",
"settings",
... | Load configuration data from file
Reads ini file style configuration settings from the given file and
loads the values into the application's environment. This is useful in
deployments where the use of the container environment for configuration
is discouraged.
@param string $file Path to config file | [
"Load",
"configuration",
"data",
"from",
"file"
] | 9fd0deba96f635c96d28d59d1f761283f62842d4 | https://github.com/wikimedia/slimapp/blob/9fd0deba96f635c96d28d59d1f761283f62842d4/src/Config.php#L81-L96 | train |
bearcms/bearframework-addon | classes/BearCMS/Internal/Data2/CommentsThreads.php | CommentsThreads.get | public function get(string $id): ?\BearCMS\Internal\Data2\CommentsThread
{
$data = Internal\Data::getValue('bearcms/comments/thread/' . md5($id) . '.json');
if ($data !== null) {
return $this->makeCommentsThreadPostFromRawData($data);
}
return null;
} | php | public function get(string $id): ?\BearCMS\Internal\Data2\CommentsThread
{
$data = Internal\Data::getValue('bearcms/comments/thread/' . md5($id) . '.json');
if ($data !== null) {
return $this->makeCommentsThreadPostFromRawData($data);
}
return null;
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"id",
")",
":",
"?",
"\\",
"BearCMS",
"\\",
"Internal",
"\\",
"Data2",
"\\",
"CommentsThread",
"{",
"$",
"data",
"=",
"Internal",
"\\",
"Data",
"::",
"getValue",
"(",
"'bearcms/comments/thread/'",
".",
"md5"... | Retrieves information about the comments thread specified
@param string $id The comments thread ID
@return \IvoPetkov\DataObject|null The comments thread data or null if the thread not found
@throws \InvalidArgumentException | [
"Retrieves",
"information",
"about",
"the",
"comments",
"thread",
"specified"
] | 7ef131b81aac26070a2b937dd67f530a6caa02f0 | https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/Internal/Data2/CommentsThreads.php#L36-L43 | train |
bearcms/bearframework-addon | classes/BearCMS/Internal/Data2/CommentsThreads.php | CommentsThreads.getList | public function getList()
{
$list = Internal\Data::getList('bearcms/comments/thread/');
array_walk($list, function(&$value) {
$value = $this->makeCommentsThreadPostFromRawData($value);
});
return new \IvoPetkov\DataList($list);
} | php | public function getList()
{
$list = Internal\Data::getList('bearcms/comments/thread/');
array_walk($list, function(&$value) {
$value = $this->makeCommentsThreadPostFromRawData($value);
});
return new \IvoPetkov\DataList($list);
} | [
"public",
"function",
"getList",
"(",
")",
"{",
"$",
"list",
"=",
"Internal",
"\\",
"Data",
"::",
"getList",
"(",
"'bearcms/comments/thread/'",
")",
";",
"array_walk",
"(",
"$",
"list",
",",
"function",
"(",
"&",
"$",
"value",
")",
"{",
"$",
"value",
"... | Retrieves a list of all comments threads
@return \IvoPetkov\DataList List containing all comments threads data | [
"Retrieves",
"a",
"list",
"of",
"all",
"comments",
"threads"
] | 7ef131b81aac26070a2b937dd67f530a6caa02f0 | https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/Internal/Data2/CommentsThreads.php#L50-L57 | train |
bearcms/bearframework-addon | classes/BearCMS/Internal/Data2/UsersInvitations.php | UsersInvitations.get | public function get(string $key): ?\BearCMS\Internal\Data2\UserInvitation
{
$data = \BearCMS\Internal\Data::getValue('bearcms/users/invitation/' . md5($key) . '.json');
if ($data !== null) {
return $this->makeUserFromRawData($data);
}
return null;
} | php | public function get(string $key): ?\BearCMS\Internal\Data2\UserInvitation
{
$data = \BearCMS\Internal\Data::getValue('bearcms/users/invitation/' . md5($key) . '.json');
if ($data !== null) {
return $this->makeUserFromRawData($data);
}
return null;
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"key",
")",
":",
"?",
"\\",
"BearCMS",
"\\",
"Internal",
"\\",
"Data2",
"\\",
"UserInvitation",
"{",
"$",
"data",
"=",
"\\",
"BearCMS",
"\\",
"Internal",
"\\",
"Data",
"::",
"getValue",
"(",
"'bearcms/user... | Retrieves information about the user invitation specified
@param string $id The user invitation key
@return \BearCMS\Internal\Data2\UserInvitation|null The user invitation data or null if not found | [
"Retrieves",
"information",
"about",
"the",
"user",
"invitation",
"specified"
] | 7ef131b81aac26070a2b937dd67f530a6caa02f0 | https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/Internal/Data2/UsersInvitations.php#L38-L45 | train |
bearcms/bearframework-addon | classes/BearCMS/Internal/Data2/UsersInvitations.php | UsersInvitations.getList | public function getList()
{
$list = \BearCMS\Internal\Data::getList('bearcms/users/invitation/');
array_walk($list, function(&$value) {
$value = $this->makeUserFromRawData($value);
});
return new \IvoPetkov\DataList($list);
} | php | public function getList()
{
$list = \BearCMS\Internal\Data::getList('bearcms/users/invitation/');
array_walk($list, function(&$value) {
$value = $this->makeUserFromRawData($value);
});
return new \IvoPetkov\DataList($list);
} | [
"public",
"function",
"getList",
"(",
")",
"{",
"$",
"list",
"=",
"\\",
"BearCMS",
"\\",
"Internal",
"\\",
"Data",
"::",
"getList",
"(",
"'bearcms/users/invitation/'",
")",
";",
"array_walk",
"(",
"$",
"list",
",",
"function",
"(",
"&",
"$",
"value",
")"... | Retrieves a list of all users invitations
@return \IvoPetkov\DataList|\BearCMS\Internal\Data2\UserInvitation[] List containing all users invitations data | [
"Retrieves",
"a",
"list",
"of",
"all",
"users",
"invitations"
] | 7ef131b81aac26070a2b937dd67f530a6caa02f0 | https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/Internal/Data2/UsersInvitations.php#L52-L59 | train |
thejacer87/php-canadapost-api | src/Returns.php | Returns.createAuthorizedReturn | public function createAuthorizedReturn(
array $returner,
array $receiver,
array $parcel,
array $options = []
) {
$content = $this->buildReturnsArray(
$returner,
$receiver,
$parcel,
$options
);
$xml = Array2XML::createXML('authorized-return', $content);
$envelope = $xml->documentElement;
$envelope->setAttribute('xmlns',
'http://www.canadapost.ca/ws/authreturn-v2');
$payload = $xml->saveXML();
$response = $this->post(
"rs/{$this->customerNumber}/{$this->customerNumber}/authorizedreturn",
[
'Accept' => 'application/vnd.cpc.authreturn-v2+xml',
'Content-Type' => 'application/vnd.cpc.authreturn-v2+xml',
],
$payload,
$options
);
return $response;
} | php | public function createAuthorizedReturn(
array $returner,
array $receiver,
array $parcel,
array $options = []
) {
$content = $this->buildReturnsArray(
$returner,
$receiver,
$parcel,
$options
);
$xml = Array2XML::createXML('authorized-return', $content);
$envelope = $xml->documentElement;
$envelope->setAttribute('xmlns',
'http://www.canadapost.ca/ws/authreturn-v2');
$payload = $xml->saveXML();
$response = $this->post(
"rs/{$this->customerNumber}/{$this->customerNumber}/authorizedreturn",
[
'Accept' => 'application/vnd.cpc.authreturn-v2+xml',
'Content-Type' => 'application/vnd.cpc.authreturn-v2+xml',
],
$payload,
$options
);
return $response;
} | [
"public",
"function",
"createAuthorizedReturn",
"(",
"array",
"$",
"returner",
",",
"array",
"$",
"receiver",
",",
"array",
"$",
"parcel",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"buildReturnsArray",
... | Create an authorized return.
@param array $returner
The returner info.
<code>
$returner = [
'name' => 'Jane Doe',
'company' => 'Acro Media',
'domestic-address' => [
'address-line-1' => '103-2303 Leckie Rd',
'city' => 'Kelowna',
'province' => 'BC',
'postal-code' => 'V1X 6Y5',
],
]
</code>
@param array $receiver
The receiver info.
<code>
$receiver = [
'name' => 'John Smith',
'company' => 'Acro Media',
'domestic-address' => [
'address-line-1' => '123 Main St',
'city' => 'Kelowna',
'province' => 'BC',
'postal-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 array.
@return \DOMDocument
@throws \GuzzleHttp\Exception\GuzzleException | [
"Create",
"an",
"authorized",
"return",
"."
] | 1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a | https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/Returns.php#L66-L95 | train |
thejacer87/php-canadapost-api | src/Returns.php | Returns.createOpenReturn | public function createOpenReturn(
array $receiver,
array $parcel,
array $options = []
) {
$this->formatPostalCode($receiver['domestic-address']['postal-code']);
$content = [
'max-number-of-artifacts' => 10,
'service-code' => $parcel['service_code'],
'receiver' => $receiver,
'settlement-info' => [
'contract-id' => $this->contractId,
],
];
if (!empty($options['option_codes'])) {
$return_info['options']['option'] = $this->parseOptionCodes($options);
}
$xml = Array2XML::createXML('open-return', $content);
$envelope = $xml->documentElement;
$envelope->setAttribute('xmlns',
'http://www.canadapost.ca/ws/openreturn-v2');
$payload = $xml->saveXML();
$response = $this->post(
"rs/{$this->customerNumber}/{$this->customerNumber}/openreturn",
[
'Accept' => 'application/vnd.cpc.openreturn-v2+xml',
'Content-Type' => 'application/vnd.cpc.openreturn-v2+xml',
],
$payload,
$options
);
return $response;
} | php | public function createOpenReturn(
array $receiver,
array $parcel,
array $options = []
) {
$this->formatPostalCode($receiver['domestic-address']['postal-code']);
$content = [
'max-number-of-artifacts' => 10,
'service-code' => $parcel['service_code'],
'receiver' => $receiver,
'settlement-info' => [
'contract-id' => $this->contractId,
],
];
if (!empty($options['option_codes'])) {
$return_info['options']['option'] = $this->parseOptionCodes($options);
}
$xml = Array2XML::createXML('open-return', $content);
$envelope = $xml->documentElement;
$envelope->setAttribute('xmlns',
'http://www.canadapost.ca/ws/openreturn-v2');
$payload = $xml->saveXML();
$response = $this->post(
"rs/{$this->customerNumber}/{$this->customerNumber}/openreturn",
[
'Accept' => 'application/vnd.cpc.openreturn-v2+xml',
'Content-Type' => 'application/vnd.cpc.openreturn-v2+xml',
],
$payload,
$options
);
return $response;
} | [
"public",
"function",
"createOpenReturn",
"(",
"array",
"$",
"receiver",
",",
"array",
"$",
"parcel",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"formatPostalCode",
"(",
"$",
"receiver",
"[",
"'domestic-address'",
"]",
"[",
... | Create an open return.
@param array $receiver
The receiver info.
<code>
$receiver = [
'name' => 'John Smith',
'company' => 'Acro Media',
'domestic-address' => [
'address-line-1' => '123 Main St',
'city' => 'Kelowna',
'province' => 'BC',
'postal-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 array.
@return \DOMDocument
@throws \GuzzleHttp\Exception\GuzzleException | [
"Create",
"an",
"open",
"return",
"."
] | 1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a | https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/Returns.php#L133-L169 | train |
thejacer87/php-canadapost-api | src/Returns.php | Returns.getAllOpenReturns | public function getAllOpenReturns($from, $to = '', array $options = []) {
if (empty($to)) {
$to = date('YmdHs');
}
$query_params = "from={$from}&to{$to}";
$this->verifyDates($from, $to);
$response = $this->get(
"rs/{$this->config['customer_number']}/{$this->config['customer_number']}/openreturn?{$query_params}",
[
'Accept' => 'application/vnd.cpc.openreturn+xml',
'Content-Type' => 'application/vnd.cpc.openreturn+xml',
],
$options
);
return $response;
} | php | public function getAllOpenReturns($from, $to = '', array $options = []) {
if (empty($to)) {
$to = date('YmdHs');
}
$query_params = "from={$from}&to{$to}";
$this->verifyDates($from, $to);
$response = $this->get(
"rs/{$this->config['customer_number']}/{$this->config['customer_number']}/openreturn?{$query_params}",
[
'Accept' => 'application/vnd.cpc.openreturn+xml',
'Content-Type' => 'application/vnd.cpc.openreturn+xml',
],
$options
);
return $response;
} | [
"public",
"function",
"getAllOpenReturns",
"(",
"$",
"from",
",",
"$",
"to",
"=",
"''",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"to",
")",
")",
"{",
"$",
"to",
"=",
"date",
"(",
"'YmdHs'",
")",
";",
... | Get next open return artifact.
@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 array $options
The options array.
@return \DOMDocument|\Psr\Http\Message\StreamInterface
@throws \GuzzleHttp\Exception\GuzzleException | [
"Get",
"next",
"open",
"return",
"artifact",
"."
] | 1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a | https://github.com/thejacer87/php-canadapost-api/blob/1f0f6db5ac2a85aa1e4adf6ddd6b99d29310923a/src/Returns.php#L242-L260 | train |
pulsarvp/vps-tools | src/auth/PulsarSsoClient.php | PulsarSsoClient.getLogoutUrl | public function getLogoutUrl ($redirectTo = null)
{
if (empty($redirectTo))
return $this->_logoutUrl;
else
return $this->_logoutUrl . '?next=' . urlencode($redirectTo);
} | php | public function getLogoutUrl ($redirectTo = null)
{
if (empty($redirectTo))
return $this->_logoutUrl;
else
return $this->_logoutUrl . '?next=' . urlencode($redirectTo);
} | [
"public",
"function",
"getLogoutUrl",
"(",
"$",
"redirectTo",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"redirectTo",
")",
")",
"return",
"$",
"this",
"->",
"_logoutUrl",
";",
"else",
"return",
"$",
"this",
"->",
"_logoutUrl",
".",
"'?next='",... | Creates logout URL.
@param string $redirectTo
@return string | [
"Creates",
"logout",
"URL",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/auth/PulsarSsoClient.php#L36-L42 | train |
Bokbasen/php-api-client | src/ApiClient/Client.php | Client.patch | public function patch(string $path, $body, array $headers = [], bool $authenticate = true): ResponseInterface
{
return $this->call(
HttpRequestOptions::HTTP_METHOD_PATCH,
$path,
$headers,
$body,
$authenticate
);
} | php | public function patch(string $path, $body, array $headers = [], bool $authenticate = true): ResponseInterface
{
return $this->call(
HttpRequestOptions::HTTP_METHOD_PATCH,
$path,
$headers,
$body,
$authenticate
);
} | [
"public",
"function",
"patch",
"(",
"string",
"$",
"path",
",",
"$",
"body",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"bool",
"$",
"authenticate",
"=",
"true",
")",
":",
"ResponseInterface",
"{",
"return",
"$",
"this",
"->",
"call",
"(",
"Ht... | Execute PATCH request
@param string $path
@param resource|string|StreamInterface|null $body
@param array $headers
@param bool $authenticate
@return ResponseInterface
@throws BokbasenApiClientException | [
"Execute",
"PATCH",
"request"
] | eeb33aa48b90d5043545d1af993167e9a74995df | https://github.com/Bokbasen/php-api-client/blob/eeb33aa48b90d5043545d1af993167e9a74995df/src/ApiClient/Client.php#L172-L181 | train |
Bokbasen/php-api-client | src/ApiClient/Client.php | Client.postJson | public function postJson(string $path, array $body): ResponseInterface
{
$body = json_encode($body);
if ($body === false) {
throw new BokbasenApiClientException('Unable to convert data to json');
}
return $this->post(
$path,
$body,
[
'Content-Type' => HttpRequestOptions::CONTENT_TYPE_JSON,
]
);
} | php | public function postJson(string $path, array $body): ResponseInterface
{
$body = json_encode($body);
if ($body === false) {
throw new BokbasenApiClientException('Unable to convert data to json');
}
return $this->post(
$path,
$body,
[
'Content-Type' => HttpRequestOptions::CONTENT_TYPE_JSON,
]
);
} | [
"public",
"function",
"postJson",
"(",
"string",
"$",
"path",
",",
"array",
"$",
"body",
")",
":",
"ResponseInterface",
"{",
"$",
"body",
"=",
"json_encode",
"(",
"$",
"body",
")",
";",
"if",
"(",
"$",
"body",
"===",
"false",
")",
"{",
"throw",
"new"... | Special endpoint for posting json, sets correct content type header and encodes data as json
@param string $path
@param array $body
@return ResponseInterface
@throws BokbasenApiClientException | [
"Special",
"endpoint",
"for",
"posting",
"json",
"sets",
"correct",
"content",
"type",
"header",
"and",
"encodes",
"data",
"as",
"json"
] | eeb33aa48b90d5043545d1af993167e9a74995df | https://github.com/Bokbasen/php-api-client/blob/eeb33aa48b90d5043545d1af993167e9a74995df/src/ApiClient/Client.php#L193-L208 | train |
pulsarvp/vps-tools | src/components/CategoryManager.php | CategoryManager.init | public function init ()
{
$class = $this->_modelClass;
$this->_root = $class::find()->roots()->one();
if ($this->_root == null)
{
$root = new $class([ 'guid' => 'root', 'title' => 'ROOT' ]);
$root->makeRoot();
$this->_root = $class::find()->roots()->one();
$this->_data = [];
}
else
$this->_data = $this->_root->children()->all();
$this->buildPaths();
} | php | public function init ()
{
$class = $this->_modelClass;
$this->_root = $class::find()->roots()->one();
if ($this->_root == null)
{
$root = new $class([ 'guid' => 'root', 'title' => 'ROOT' ]);
$root->makeRoot();
$this->_root = $class::find()->roots()->one();
$this->_data = [];
}
else
$this->_data = $this->_root->children()->all();
$this->buildPaths();
} | [
"public",
"function",
"init",
"(",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"_modelClass",
";",
"$",
"this",
"->",
"_root",
"=",
"$",
"class",
"::",
"find",
"(",
")",
"->",
"roots",
"(",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"$",
... | Populates category tree with data loaded from database.
@inheritdoc | [
"Populates",
"category",
"tree",
"with",
"data",
"loaded",
"from",
"database",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/CategoryManager.php#L48-L65 | train |
pulsarvp/vps-tools | src/components/CategoryManager.php | CategoryManager.getChildren | public function getChildren ($category)
{
$children = [];
foreach ($this->_data as $item)
if ($item->lft > $category->lft and $item->rgt < $category->rgt)
$children[] = $item;
return $children;
} | php | public function getChildren ($category)
{
$children = [];
foreach ($this->_data as $item)
if ($item->lft > $category->lft and $item->rgt < $category->rgt)
$children[] = $item;
return $children;
} | [
"public",
"function",
"getChildren",
"(",
"$",
"category",
")",
"{",
"$",
"children",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_data",
"as",
"$",
"item",
")",
"if",
"(",
"$",
"item",
"->",
"lft",
">",
"$",
"category",
"->",
"lft",
... | Gets children of current category.
@param Category $category
@return array | [
"Gets",
"children",
"of",
"current",
"category",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/CategoryManager.php#L81-L89 | train |
pulsarvp/vps-tools | src/components/CategoryManager.php | CategoryManager.getParent | public function getParent ($category, $depth = 1)
{
if ($category instanceof $this->_modelClass and $depth > 0)
{
if ($category->depth == $depth)
return $category;
foreach ($this->_data as $item)
if ($category->lft > $item->lft and $category->rgt < $item->rgt and $item->depth == $depth)
return $item;
}
return null;
} | php | public function getParent ($category, $depth = 1)
{
if ($category instanceof $this->_modelClass and $depth > 0)
{
if ($category->depth == $depth)
return $category;
foreach ($this->_data as $item)
if ($category->lft > $item->lft and $category->rgt < $item->rgt and $item->depth == $depth)
return $item;
}
return null;
} | [
"public",
"function",
"getParent",
"(",
"$",
"category",
",",
"$",
"depth",
"=",
"1",
")",
"{",
"if",
"(",
"$",
"category",
"instanceof",
"$",
"this",
"->",
"_modelClass",
"and",
"$",
"depth",
">",
"0",
")",
"{",
"if",
"(",
"$",
"category",
"->",
"... | Finds category parent with given depth.
@param Category $category
@param int $depth
@return Category|null | [
"Finds",
"category",
"parent",
"with",
"given",
"depth",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/CategoryManager.php#L97-L109 | train |
pulsarvp/vps-tools | src/components/CategoryManager.php | CategoryManager.getParents | public function getParents ($category)
{
if ($category instanceof $this->_modelClass)
{
$parents = [];
foreach ($this->_data as $item)
if ($category->lft > $item->lft and $category->rgt < $item->rgt)
$parents[] = $item;
return $parents;
}
return null;
} | php | public function getParents ($category)
{
if ($category instanceof $this->_modelClass)
{
$parents = [];
foreach ($this->_data as $item)
if ($category->lft > $item->lft and $category->rgt < $item->rgt)
$parents[] = $item;
return $parents;
}
return null;
} | [
"public",
"function",
"getParents",
"(",
"$",
"category",
")",
"{",
"if",
"(",
"$",
"category",
"instanceof",
"$",
"this",
"->",
"_modelClass",
")",
"{",
"$",
"parents",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_data",
"as",
"$",
"item... | Finds all parents from top one to nearest.
@param Category $category
@return Category[]|null | [
"Finds",
"all",
"parents",
"from",
"top",
"one",
"to",
"nearest",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/CategoryManager.php#L116-L129 | train |
pulsarvp/vps-tools | src/components/CategoryManager.php | CategoryManager.get | public function get ($id)
{
foreach ($this->_data as $category)
if ($category->id == $id)
return $category;
return null;
} | php | public function get ($id)
{
foreach ($this->_data as $category)
if ($category->id == $id)
return $category;
return null;
} | [
"public",
"function",
"get",
"(",
"$",
"id",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_data",
"as",
"$",
"category",
")",
"if",
"(",
"$",
"category",
"->",
"id",
"==",
"$",
"id",
")",
"return",
"$",
"category",
";",
"return",
"null",
";",
"}... | Gets single category by its ID.
@param integer $id
@return Category|null | [
"Gets",
"single",
"category",
"by",
"its",
"ID",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/CategoryManager.php#L145-L152 | train |
pulsarvp/vps-tools | src/components/CategoryManager.php | CategoryManager.getByGuidPath | public function getByGuidPath ($guidPath)
{
foreach ($this->_data as $category)
if ($category->guidPath === $guidPath)
return $category;
return null;
} | php | public function getByGuidPath ($guidPath)
{
foreach ($this->_data as $category)
if ($category->guidPath === $guidPath)
return $category;
return null;
} | [
"public",
"function",
"getByGuidPath",
"(",
"$",
"guidPath",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_data",
"as",
"$",
"category",
")",
"if",
"(",
"$",
"category",
"->",
"guidPath",
"===",
"$",
"guidPath",
")",
"return",
"$",
"category",
";",
"r... | Gets single category by its GUID path.
@param string $guidPath
@return Category|null | [
"Gets",
"single",
"category",
"by",
"its",
"GUID",
"path",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/CategoryManager.php#L159-L166 | train |
pulsarvp/vps-tools | src/components/CategoryManager.php | CategoryManager.exists | public function exists ($id)
{
foreach ($this->_data as $category)
if ($category->id == $id)
return true;
return false;
} | php | public function exists ($id)
{
foreach ($this->_data as $category)
if ($category->id == $id)
return true;
return false;
} | [
"public",
"function",
"exists",
"(",
"$",
"id",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_data",
"as",
"$",
"category",
")",
"if",
"(",
"$",
"category",
"->",
"id",
"==",
"$",
"id",
")",
"return",
"true",
";",
"return",
"false",
";",
"}"
] | Checks if category exists.
@param integer $id Category ID.
@return bool | [
"Checks",
"if",
"category",
"exists",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/CategoryManager.php#L185-L192 | train |
pulsarvp/vps-tools | src/components/CategoryManager.php | CategoryManager.reload | public function reload ()
{
$class = $this->_modelClass;
$this->_root = $class::find()->roots()->one();
$this->_data = $this->_root->children()->all();
$this->buildPaths();
} | php | public function reload ()
{
$class = $this->_modelClass;
$this->_root = $class::find()->roots()->one();
$this->_data = $this->_root->children()->all();
$this->buildPaths();
} | [
"public",
"function",
"reload",
"(",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"_modelClass",
";",
"$",
"this",
"->",
"_root",
"=",
"$",
"class",
"::",
"find",
"(",
")",
"->",
"roots",
"(",
")",
"->",
"one",
"(",
")",
";",
"$",
"this",
"-... | Reloads data from database. | [
"Reloads",
"data",
"from",
"database",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/CategoryManager.php#L197-L204 | train |
pulsarvp/vps-tools | src/components/CategoryManager.php | CategoryManager.guidPath | public function guidPath ($id)
{
$category = $this->get($id);
if ($category == null)
return null;
elseif (empty($category->guidPath))
$this->buildPaths();
return $category->guidPath;
} | php | public function guidPath ($id)
{
$category = $this->get($id);
if ($category == null)
return null;
elseif (empty($category->guidPath))
$this->buildPaths();
return $category->guidPath;
} | [
"public",
"function",
"guidPath",
"(",
"$",
"id",
")",
"{",
"$",
"category",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"category",
"==",
"null",
")",
"return",
"null",
";",
"elseif",
"(",
"empty",
"(",
"$",
"categor... | Finds category GUID path by given ID.
@param integer $id
@return null|string | [
"Finds",
"category",
"GUID",
"path",
"by",
"given",
"ID",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/CategoryManager.php#L211-L221 | train |
pulsarvp/vps-tools | src/components/CategoryManager.php | CategoryManager.titlePath | public function titlePath ($id)
{
$category = $this->get($id);
if ($category == null)
return null;
elseif (empty($category->titlePath))
$this->buildPaths();
return $category->titlePath;
} | php | public function titlePath ($id)
{
$category = $this->get($id);
if ($category == null)
return null;
elseif (empty($category->titlePath))
$this->buildPaths();
return $category->titlePath;
} | [
"public",
"function",
"titlePath",
"(",
"$",
"id",
")",
"{",
"$",
"category",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"category",
"==",
"null",
")",
"return",
"null",
";",
"elseif",
"(",
"empty",
"(",
"$",
"catego... | Finds category title path by given ID.
@param integer $id
@return null|string | [
"Finds",
"category",
"title",
"path",
"by",
"given",
"ID",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/CategoryManager.php#L228-L238 | train |
pulsarvp/vps-tools | src/components/CategoryManager.php | CategoryManager.buildPaths | protected function buildPaths ()
{
$titles = [];
$guids = [];
$n = count($this->_data);
for ($i = 0; $i < $n; $i++)
{
$parent = $this->_data[ $i ];
for ($j = $i + 1; $j < $n; $j++)
{
$child = $this->_data[ $j ];
if ($child->lft > $parent->lft and $child->rgt < $parent->rgt)
{
$titles[ $child->id ][] = $parent->title;
$guids[ $child->id ][] = $parent->guid;
}
}
$titles[ $parent->id ][] = $parent->title;
$guids[ $parent->id ][] = $parent->guid;
$parent->titlePath = implode($this->_titlePathDelimiter, $titles[ $parent->id ]);
$parent->guidPath = implode($this->_guidPathDelimiter, $guids[ $parent->id ]);
}
} | php | protected function buildPaths ()
{
$titles = [];
$guids = [];
$n = count($this->_data);
for ($i = 0; $i < $n; $i++)
{
$parent = $this->_data[ $i ];
for ($j = $i + 1; $j < $n; $j++)
{
$child = $this->_data[ $j ];
if ($child->lft > $parent->lft and $child->rgt < $parent->rgt)
{
$titles[ $child->id ][] = $parent->title;
$guids[ $child->id ][] = $parent->guid;
}
}
$titles[ $parent->id ][] = $parent->title;
$guids[ $parent->id ][] = $parent->guid;
$parent->titlePath = implode($this->_titlePathDelimiter, $titles[ $parent->id ]);
$parent->guidPath = implode($this->_guidPathDelimiter, $guids[ $parent->id ]);
}
} | [
"protected",
"function",
"buildPaths",
"(",
")",
"{",
"$",
"titles",
"=",
"[",
"]",
";",
"$",
"guids",
"=",
"[",
"]",
";",
"$",
"n",
"=",
"count",
"(",
"$",
"this",
"->",
"_data",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<"... | Builds full title and GUID paths for all categories. | [
"Builds",
"full",
"title",
"and",
"GUID",
"paths",
"for",
"all",
"categories",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/components/CategoryManager.php#L243-L267 | train |
shimabox/SMBArrayto | src/SMB/Arrayto/Plugins/Csv/Downloader.php | Downloader.downloadExistsFile | public function downloadExistsFile($fileName, $aliasOfFileName = '')
{
$baseFileName = $aliasOfFileName === '' ? basename($fileName) : $aliasOfFileName;
header("Content-Type: text/csv; charset={$this->getHeaderCharset()}");
header("Content-Disposition: attachment; filename={$baseFileName}");
readfile($fileName);
} | php | public function downloadExistsFile($fileName, $aliasOfFileName = '')
{
$baseFileName = $aliasOfFileName === '' ? basename($fileName) : $aliasOfFileName;
header("Content-Type: text/csv; charset={$this->getHeaderCharset()}");
header("Content-Disposition: attachment; filename={$baseFileName}");
readfile($fileName);
} | [
"public",
"function",
"downloadExistsFile",
"(",
"$",
"fileName",
",",
"$",
"aliasOfFileName",
"=",
"''",
")",
"{",
"$",
"baseFileName",
"=",
"$",
"aliasOfFileName",
"===",
"''",
"?",
"basename",
"(",
"$",
"fileName",
")",
":",
"$",
"aliasOfFileName",
";",
... | download an existing file
@param string $fileName e.g.) sample.xxx | ../sample.xxx | /path/to/sample.xxx
@param string $aliasOfFileName | [
"download",
"an",
"existing",
"file"
] | 7ecacc0c15994c02224bbd3efe055d3bce243971 | https://github.com/shimabox/SMBArrayto/blob/7ecacc0c15994c02224bbd3efe055d3bce243971/src/SMB/Arrayto/Plugins/Csv/Downloader.php#L40-L48 | train |
shimabox/SMBArrayto | src/SMB/Arrayto/Plugins/Csv/Downloader.php | Downloader.downloadExistsFileUsingWriter | public function downloadExistsFileUsingWriter($fileName, Writable $writer)
{
header("Content-Type: text/csv; charset={$this->getHeaderCharset()}");
header("Content-Disposition: attachment; filename={$fileName}");
$writer->write();
readfile($writer->getFileName());
} | php | public function downloadExistsFileUsingWriter($fileName, Writable $writer)
{
header("Content-Type: text/csv; charset={$this->getHeaderCharset()}");
header("Content-Disposition: attachment; filename={$fileName}");
$writer->write();
readfile($writer->getFileName());
} | [
"public",
"function",
"downloadExistsFileUsingWriter",
"(",
"$",
"fileName",
",",
"Writable",
"$",
"writer",
")",
"{",
"header",
"(",
"\"Content-Type: text/csv; charset={$this->getHeaderCharset()}\"",
")",
";",
"header",
"(",
"\"Content-Disposition: attachment; filename={$fileN... | download an existing file using Writer
@param string $fileName
@param \SMB\Arrayto\Interfaces\Writable $writer | [
"download",
"an",
"existing",
"file",
"using",
"Writer"
] | 7ecacc0c15994c02224bbd3efe055d3bce243971 | https://github.com/shimabox/SMBArrayto/blob/7ecacc0c15994c02224bbd3efe055d3bce243971/src/SMB/Arrayto/Plugins/Csv/Downloader.php#L55-L62 | train |
pulsarvp/vps-tools | src/modules/setting/models/Setting.php | Setting.validateCommand | public function validateCommand ($attribute)
{
if (!$this->hasErrors())
{
$return_var1 = $return_var2 = $return_var3 = 0;
exec('command -v ' . $this->$attribute . '', $output, $return_var);
if ($return_var == 127)
$this->addError($attribute, Yii::tr('Command not found.', [], 'setting'));
}
} | php | public function validateCommand ($attribute)
{
if (!$this->hasErrors())
{
$return_var1 = $return_var2 = $return_var3 = 0;
exec('command -v ' . $this->$attribute . '', $output, $return_var);
if ($return_var == 127)
$this->addError($attribute, Yii::tr('Command not found.', [], 'setting'));
}
} | [
"public",
"function",
"validateCommand",
"(",
"$",
"attribute",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasErrors",
"(",
")",
")",
"{",
"$",
"return_var1",
"=",
"$",
"return_var2",
"=",
"$",
"return_var3",
"=",
"0",
";",
"exec",
"(",
"'command -v... | Command validates.
@param string $attribute the attribute currently being validated | [
"Command",
"validates",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/setting/models/Setting.php#L139-L148 | train |
pulsarvp/vps-tools | src/modules/setting/models/Setting.php | Setting.validateJson | public function validateJson ($attribute)
{
if (!$this->hasErrors())
{
if (!( is_string($this->$attribute) && is_array(json_decode($this->$attribute, true)) && ( json_last_error() == JSON_ERROR_NONE ) ))
$this->addError($attribute, Yii::tr('This field must be well-formed JSON.', [], 'setting'));
}
} | php | public function validateJson ($attribute)
{
if (!$this->hasErrors())
{
if (!( is_string($this->$attribute) && is_array(json_decode($this->$attribute, true)) && ( json_last_error() == JSON_ERROR_NONE ) ))
$this->addError($attribute, Yii::tr('This field must be well-formed JSON.', [], 'setting'));
}
} | [
"public",
"function",
"validateJson",
"(",
"$",
"attribute",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasErrors",
"(",
")",
")",
"{",
"if",
"(",
"!",
"(",
"is_string",
"(",
"$",
"this",
"->",
"$",
"attribute",
")",
"&&",
"is_array",
"(",
"json... | Json validates.
@param string $attribute the attribute currently being validated | [
"Json",
"validates",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/setting/models/Setting.php#L155-L162 | train |
pulsarvp/vps-tools | src/modules/setting/models/Setting.php | Setting.validateUrl | public function validateUrl ($attribute)
{
if (!$this->hasErrors())
{
if (filter_var($this->$attribute, FILTER_VALIDATE_URL) === false)
$this->addError($attribute, Yii::tr('{attribute} is not a valid URL.', [ 'attribute' => $this->name ], 'setting'));
}
} | php | public function validateUrl ($attribute)
{
if (!$this->hasErrors())
{
if (filter_var($this->$attribute, FILTER_VALIDATE_URL) === false)
$this->addError($attribute, Yii::tr('{attribute} is not a valid URL.', [ 'attribute' => $this->name ], 'setting'));
}
} | [
"public",
"function",
"validateUrl",
"(",
"$",
"attribute",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasErrors",
"(",
")",
")",
"{",
"if",
"(",
"filter_var",
"(",
"$",
"this",
"->",
"$",
"attribute",
",",
"FILTER_VALIDATE_URL",
")",
"===",
"false"... | Url validates.
@param string $attribute the attribute currently being validated | [
"Url",
"validates",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/setting/models/Setting.php#L169-L176 | train |
pulsarvp/vps-tools | src/modules/setting/models/Setting.php | Setting.validatePath | public function validatePath ($attribute)
{
if (!$this->hasErrors())
{
if (!file_exists($this->$attribute))
$this->addError($attribute, Yii::tr('{attribute} does not exist.', [ 'attribute' => $attribute ], 'setting'));
if ($this->rule != '')
{
$rule = json_decode($this->rule, true);
if (isset($rule[ 'writable' ]) and $rule[ 'writable' ] == true)
{
if (!is_writable($this->$attribute))
$this->addError($attribute, Yii::tr('Path is not writable.', [], 'setting'));
}
}
}
} | php | public function validatePath ($attribute)
{
if (!$this->hasErrors())
{
if (!file_exists($this->$attribute))
$this->addError($attribute, Yii::tr('{attribute} does not exist.', [ 'attribute' => $attribute ], 'setting'));
if ($this->rule != '')
{
$rule = json_decode($this->rule, true);
if (isset($rule[ 'writable' ]) and $rule[ 'writable' ] == true)
{
if (!is_writable($this->$attribute))
$this->addError($attribute, Yii::tr('Path is not writable.', [], 'setting'));
}
}
}
} | [
"public",
"function",
"validatePath",
"(",
"$",
"attribute",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasErrors",
"(",
")",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"$",
"attribute",
")",
")",
"$",
"this",
"->",
"addErr... | Path validates.
@param string $attribute the attribute currently being validated | [
"Path",
"validates",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/setting/models/Setting.php#L183-L199 | train |
pulsarvp/vps-tools | src/base/BaseOrderModel.php | BaseOrderModel.beforeSave | public function beforeSave ($insert)
{
if ($parent = parent::beforeSave($insert))
{
if ($this->isNewRecord)
{
if ($this->hasAttribute('order') and empty($this->order))
{
$query = self::find()->select('order')->orderBy([ 'order' => SORT_DESC ]);
$condition = $this->orderCondition();
if ($condition !== null)
{
$query->where($condition);
}
$order = $query->scalar();
$this->order = !is_null($order) ? $order + 1 : 1;
}
}
}
return $parent;
} | php | public function beforeSave ($insert)
{
if ($parent = parent::beforeSave($insert))
{
if ($this->isNewRecord)
{
if ($this->hasAttribute('order') and empty($this->order))
{
$query = self::find()->select('order')->orderBy([ 'order' => SORT_DESC ]);
$condition = $this->orderCondition();
if ($condition !== null)
{
$query->where($condition);
}
$order = $query->scalar();
$this->order = !is_null($order) ? $order + 1 : 1;
}
}
}
return $parent;
} | [
"public",
"function",
"beforeSave",
"(",
"$",
"insert",
")",
"{",
"if",
"(",
"$",
"parent",
"=",
"parent",
"::",
"beforeSave",
"(",
"$",
"insert",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isNewRecord",
")",
"{",
"if",
"(",
"$",
"this",
"->",
... | Looking for the biggest order in the table, and the current model doing +1.
@param bool $insert
@return bool | [
"Looking",
"for",
"the",
"biggest",
"order",
"in",
"the",
"table",
"and",
"the",
"current",
"model",
"doing",
"+",
"1",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/base/BaseOrderModel.php#L24-L48 | train |
pulsarvp/vps-tools | src/base/BaseOrderModel.php | BaseOrderModel.afterDelete | public function afterDelete ()
{
$parent = parent::afterDelete();
if ($this->hasAttribute('order'))
{
$query = self::find()->where([ '>', 'order', $this->order ]);
$condition = $this->orderCondition();
if ($condition !== null)
{
$query->andWhere($condition);
}
$objects = $query->all();
foreach ($objects as $object)
{
$object->order -= 1;
$object->save();
}
}
return $parent;
} | php | public function afterDelete ()
{
$parent = parent::afterDelete();
if ($this->hasAttribute('order'))
{
$query = self::find()->where([ '>', 'order', $this->order ]);
$condition = $this->orderCondition();
if ($condition !== null)
{
$query->andWhere($condition);
}
$objects = $query->all();
foreach ($objects as $object)
{
$object->order -= 1;
$object->save();
}
}
return $parent;
} | [
"public",
"function",
"afterDelete",
"(",
")",
"{",
"$",
"parent",
"=",
"parent",
"::",
"afterDelete",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasAttribute",
"(",
"'order'",
")",
")",
"{",
"$",
"query",
"=",
"self",
"::",
"find",
"(",
")",
"-... | Which order more than the remote model, do for order -1. | [
"Which",
"order",
"more",
"than",
"the",
"remote",
"model",
"do",
"for",
"order",
"-",
"1",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/base/BaseOrderModel.php#L53-L76 | train |
pulsarvp/vps-tools | src/net/Curl.php | Curl.delete | public function delete ($data = null)
{
$this->_options[ CURLOPT_CUSTOMREQUEST ] = 'DELETE';
if ($data != null)
$this->_options[ CURLOPT_POSTFIELDS ] = is_array($data) ? http_build_query($data) : $data;
return $this->send();
} | php | public function delete ($data = null)
{
$this->_options[ CURLOPT_CUSTOMREQUEST ] = 'DELETE';
if ($data != null)
$this->_options[ CURLOPT_POSTFIELDS ] = is_array($data) ? http_build_query($data) : $data;
return $this->send();
} | [
"public",
"function",
"delete",
"(",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"_options",
"[",
"CURLOPT_CUSTOMREQUEST",
"]",
"=",
"'DELETE'",
";",
"if",
"(",
"$",
"data",
"!=",
"null",
")",
"$",
"this",
"->",
"_options",
"[",
"CURLOPT_POS... | Sends DELETE request.
@param null|array $data Additional data to append to request.
@return string|CurlResponse | [
"Sends",
"DELETE",
"request",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Curl.php#L103-L110 | train |
pulsarvp/vps-tools | src/net/Curl.php | Curl.post | public function post ($data)
{
$this->_options[ CURLOPT_POST ] = 1;
$this->_options[ CURLOPT_POSTFIELDS ] = is_array($data) ? http_build_query($data) : $data;
return $this->send();
} | php | public function post ($data)
{
$this->_options[ CURLOPT_POST ] = 1;
$this->_options[ CURLOPT_POSTFIELDS ] = is_array($data) ? http_build_query($data) : $data;
return $this->send();
} | [
"public",
"function",
"post",
"(",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"_options",
"[",
"CURLOPT_POST",
"]",
"=",
"1",
";",
"$",
"this",
"->",
"_options",
"[",
"CURLOPT_POSTFIELDS",
"]",
"=",
"is_array",
"(",
"$",
"data",
")",
"?",
"http_build_qu... | Sends POST request.
@param array|string $data Additional data to append to request.
@return string|CurlResponse | [
"Sends",
"POST",
"request",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Curl.php#L141-L147 | train |
pulsarvp/vps-tools | src/net/Curl.php | Curl.put | public function put ($data)
{
$this->_options[ CURLOPT_CUSTOMREQUEST ] = 'PUT';
$this->_options[ CURLOPT_POSTFIELDS ] = http_build_query($data);
return $this->send();
} | php | public function put ($data)
{
$this->_options[ CURLOPT_CUSTOMREQUEST ] = 'PUT';
$this->_options[ CURLOPT_POSTFIELDS ] = http_build_query($data);
return $this->send();
} | [
"public",
"function",
"put",
"(",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"_options",
"[",
"CURLOPT_CUSTOMREQUEST",
"]",
"=",
"'PUT'",
";",
"$",
"this",
"->",
"_options",
"[",
"CURLOPT_POSTFIELDS",
"]",
"=",
"http_build_query",
"(",
"$",
"data",
")",
"... | Sends PUT request.
@param null|array $data Additional data to append to request.
@return string|CurlResponse | [
"Sends",
"PUT",
"request",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Curl.php#L155-L161 | train |
pulsarvp/vps-tools | src/net/Curl.php | Curl.send | private function send ()
{
if (count($this->_params) > 0)
$this->_options[ CURLOPT_URL ] .= '?' . http_build_query($this->_params);
if (count($this->_headers) > 0)
$this->_options[ CURLOPT_HTTPHEADER ] = $this->_headers;
$curl = curl_init();
curl_setopt_array($curl, $this->_options);
$resp = curl_exec($curl);
if ($resp === false)
{
$this->_response = new CurlResponse([
'status' => CurlResponse::S_SERVERERROR,
'body' => 'Error #' . curl_errno($curl) . ': ' . curl_error($curl)
]);
}
else
{
$this->_response = new CurlResponse;
$this->_response->fromCurl($resp, $curl);
}
curl_close($curl);
return $this->_response;
} | php | private function send ()
{
if (count($this->_params) > 0)
$this->_options[ CURLOPT_URL ] .= '?' . http_build_query($this->_params);
if (count($this->_headers) > 0)
$this->_options[ CURLOPT_HTTPHEADER ] = $this->_headers;
$curl = curl_init();
curl_setopt_array($curl, $this->_options);
$resp = curl_exec($curl);
if ($resp === false)
{
$this->_response = new CurlResponse([
'status' => CurlResponse::S_SERVERERROR,
'body' => 'Error #' . curl_errno($curl) . ': ' . curl_error($curl)
]);
}
else
{
$this->_response = new CurlResponse;
$this->_response->fromCurl($resp, $curl);
}
curl_close($curl);
return $this->_response;
} | [
"private",
"function",
"send",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"_params",
")",
">",
"0",
")",
"$",
"this",
"->",
"_options",
"[",
"CURLOPT_URL",
"]",
".=",
"'?'",
".",
"http_build_query",
"(",
"$",
"this",
"->",
"_params",
... | This is general send method to use in particular request send method.
@return string|CurlResponse | [
"This",
"is",
"general",
"send",
"method",
"to",
"use",
"in",
"particular",
"request",
"send",
"method",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Curl.php#L168-L196 | train |
cedx/yii2-mustache | lib/Helper.php | Helper.parseArguments | protected function parseArguments(string $text, string $defaultArgument, array $defaultValues = []): array {
try {
if (is_array($json = Json::decode($text))) return ArrayHelper::merge($defaultValues, $json);
throw new InvalidArgumentException('The JSON string has an invalid format.');
}
catch (InvalidArgumentException $e) {
$defaultValues[$defaultArgument] = $text;
return $defaultValues;
}
} | php | protected function parseArguments(string $text, string $defaultArgument, array $defaultValues = []): array {
try {
if (is_array($json = Json::decode($text))) return ArrayHelper::merge($defaultValues, $json);
throw new InvalidArgumentException('The JSON string has an invalid format.');
}
catch (InvalidArgumentException $e) {
$defaultValues[$defaultArgument] = $text;
return $defaultValues;
}
} | [
"protected",
"function",
"parseArguments",
"(",
"string",
"$",
"text",
",",
"string",
"$",
"defaultArgument",
",",
"array",
"$",
"defaultValues",
"=",
"[",
"]",
")",
":",
"array",
"{",
"try",
"{",
"if",
"(",
"is_array",
"(",
"$",
"json",
"=",
"Json",
"... | Parses the arguments of a parameterized helper.
Arguments can be specified as a single value, or as a string in JSON format.
@param string $text The section content specifying the helper arguments.
@param string $defaultArgument The name of the default argument. This is used when the section content provides a plain string instead of a JSON object.
@param array $defaultValues The default values of arguments. These are used when the section content does not specify all arguments.
@return array The parsed arguments as an associative array. | [
"Parses",
"the",
"arguments",
"of",
"a",
"parameterized",
"helper",
".",
"Arguments",
"can",
"be",
"specified",
"as",
"a",
"single",
"value",
"or",
"as",
"a",
"string",
"in",
"JSON",
"format",
"."
] | 20c961e65e74a0bacbe992dd7fdb28319f58a919 | https://github.com/cedx/yii2-mustache/blob/20c961e65e74a0bacbe992dd7fdb28319f58a919/lib/Helper.php#L41-L51 | train |
EmchBerger/cube-custom-fields-bundle | src/Entity/EntityCustomField.php | EntityCustomField.createStrRepresentation | public function createStrRepresentation()
{
$entity = $this->getEntityData();
if (is_array($entity) || $entity instanceof \ArrayAccess) {
// for some reason, implode does not work directly on the entity traversable
$strArr = array();
foreach ($entity as $e) {
$strArr[] = $e->__toString();
}
return implode("\x1E", $strArr); // ASCII "record separator" character
} elseif ($entity) {
return $entity->__toString();
} else {
return '';
}
} | php | public function createStrRepresentation()
{
$entity = $this->getEntityData();
if (is_array($entity) || $entity instanceof \ArrayAccess) {
// for some reason, implode does not work directly on the entity traversable
$strArr = array();
foreach ($entity as $e) {
$strArr[] = $e->__toString();
}
return implode("\x1E", $strArr); // ASCII "record separator" character
} elseif ($entity) {
return $entity->__toString();
} else {
return '';
}
} | [
"public",
"function",
"createStrRepresentation",
"(",
")",
"{",
"$",
"entity",
"=",
"$",
"this",
"->",
"getEntityData",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"entity",
")",
"||",
"$",
"entity",
"instanceof",
"\\",
"ArrayAccess",
")",
"{",
"// f... | Override the default string representation creator method
@return string | [
"Override",
"the",
"default",
"string",
"representation",
"creator",
"method"
] | 7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414 | https://github.com/EmchBerger/cube-custom-fields-bundle/blob/7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414/src/Entity/EntityCustomField.php#L95-L110 | train |
EmchBerger/cube-custom-fields-bundle | src/Entity/EntityCustomField.php | EntityCustomField.createStrRepresentationOnFlush | public function createStrRepresentationOnFlush($flushEntity)
{
$entity = $this->getEntityData();
if (is_array($entity) || $entity instanceof \ArrayAccess) {
$entityArr = array();
foreach ($entity as $elem) {
$entityArr[] = $this->getEntityOnFlush($elem, $flushEntity);
}
return implode("\x1E", $entityArr); // ASCII "record separator" character
} elseif ($entity) {
return $this->getEntityOnFlush($entity, $flushEntity)->__toString();
} else {
return '';
}
} | php | public function createStrRepresentationOnFlush($flushEntity)
{
$entity = $this->getEntityData();
if (is_array($entity) || $entity instanceof \ArrayAccess) {
$entityArr = array();
foreach ($entity as $elem) {
$entityArr[] = $this->getEntityOnFlush($elem, $flushEntity);
}
return implode("\x1E", $entityArr); // ASCII "record separator" character
} elseif ($entity) {
return $this->getEntityOnFlush($entity, $flushEntity)->__toString();
} else {
return '';
}
} | [
"public",
"function",
"createStrRepresentationOnFlush",
"(",
"$",
"flushEntity",
")",
"{",
"$",
"entity",
"=",
"$",
"this",
"->",
"getEntityData",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"entity",
")",
"||",
"$",
"entity",
"instanceof",
"\\",
"Arra... | Override the default string representation creator method for the onFlush event
@return string | [
"Override",
"the",
"default",
"string",
"representation",
"creator",
"method",
"for",
"the",
"onFlush",
"event"
] | 7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414 | https://github.com/EmchBerger/cube-custom-fields-bundle/blob/7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414/src/Entity/EntityCustomField.php#L117-L131 | train |
EmchBerger/cube-custom-fields-bundle | src/Entity/EntityCustomField.php | EntityCustomField.getEntityOnFlush | private function getEntityOnFlush($entity, $flushEntity)
{
if (ClassUtils::getClass($entity) == ClassUtils::getClass($flushEntity) && $entity->getId() === $flushEntity->getId()) {
return $flushEntity;
} else {
return $entity;
}
} | php | private function getEntityOnFlush($entity, $flushEntity)
{
if (ClassUtils::getClass($entity) == ClassUtils::getClass($flushEntity) && $entity->getId() === $flushEntity->getId()) {
return $flushEntity;
} else {
return $entity;
}
} | [
"private",
"function",
"getEntityOnFlush",
"(",
"$",
"entity",
",",
"$",
"flushEntity",
")",
"{",
"if",
"(",
"ClassUtils",
"::",
"getClass",
"(",
"$",
"entity",
")",
"==",
"ClassUtils",
"::",
"getClass",
"(",
"$",
"flushEntity",
")",
"&&",
"$",
"entity",
... | Checks if the two passed objects are "the same" but possibly in different states. Returns the second argument if they are the same, else the first
@param type $entity
@param type $flushEntity
@return type | [
"Checks",
"if",
"the",
"two",
"passed",
"objects",
"are",
"the",
"same",
"but",
"possibly",
"in",
"different",
"states",
".",
"Returns",
"the",
"second",
"argument",
"if",
"they",
"are",
"the",
"same",
"else",
"the",
"first"
] | 7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414 | https://github.com/EmchBerger/cube-custom-fields-bundle/blob/7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414/src/Entity/EntityCustomField.php#L139-L146 | train |
EmchBerger/cube-custom-fields-bundle | src/Entity/EntityCustomField.php | EntityCustomField.loadEntitiesAtLoad | public function loadEntitiesAtLoad(LifecycleEventArgs $event)
{
if ($this->entityValue && $this->entityValue['entityClass']) {
$em = $event->getEntityManager();
if (is_array($this->entityValue) && is_array($this->entityValue['entityId'])) {
// multiple
$entityData = $em->getRepository($this->entityValue['entityClass'])->findById($this->entityValue['entityId']); // in this case, $this->entityValue['entityId'] contains an array of entity IDs
} else {
// single
$entityData = $em->getRepository($this->entityValue['entityClass'])->findOneById($this->entityValue['entityId']);
}
$this->entityData = $entityData;
} else {
$this->entityData = null;
}
} | php | public function loadEntitiesAtLoad(LifecycleEventArgs $event)
{
if ($this->entityValue && $this->entityValue['entityClass']) {
$em = $event->getEntityManager();
if (is_array($this->entityValue) && is_array($this->entityValue['entityId'])) {
// multiple
$entityData = $em->getRepository($this->entityValue['entityClass'])->findById($this->entityValue['entityId']); // in this case, $this->entityValue['entityId'] contains an array of entity IDs
} else {
// single
$entityData = $em->getRepository($this->entityValue['entityClass'])->findOneById($this->entityValue['entityId']);
}
$this->entityData = $entityData;
} else {
$this->entityData = null;
}
} | [
"public",
"function",
"loadEntitiesAtLoad",
"(",
"LifecycleEventArgs",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"entityValue",
"&&",
"$",
"this",
"->",
"entityValue",
"[",
"'entityClass'",
"]",
")",
"{",
"$",
"em",
"=",
"$",
"event",
"->",
"... | LifeCycleCallback PostLoad, loading entities from DataBase.
@ORM\PostLoad
@param LifecycleEventArgs $event | [
"LifeCycleCallback",
"PostLoad",
"loading",
"entities",
"from",
"DataBase",
"."
] | 7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414 | https://github.com/EmchBerger/cube-custom-fields-bundle/blob/7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414/src/Entity/EntityCustomField.php#L163-L179 | train |
pulsarvp/vps-tools | src/net/Flow.php | Flow.getChunkPath | public function getChunkPath ($n = null)
{
if ($n === null)
$n = $this->_params[ 'chunkNumber' ];
return $this->_tmpDir . '/' . $this->_params[ 'filename' ] . '.part' . $n;
} | php | public function getChunkPath ($n = null)
{
if ($n === null)
$n = $this->_params[ 'chunkNumber' ];
return $this->_tmpDir . '/' . $this->_params[ 'filename' ] . '.part' . $n;
} | [
"public",
"function",
"getChunkPath",
"(",
"$",
"n",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"n",
"===",
"null",
")",
"$",
"n",
"=",
"$",
"this",
"->",
"_params",
"[",
"'chunkNumber'",
"]",
";",
"return",
"$",
"this",
"->",
"_tmpDir",
".",
"'/'",
... | Gets full path to chunk file.
@param null|integer $n Chunk number.
@return string | [
"Gets",
"full",
"path",
"to",
"chunk",
"file",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Flow.php#L99-L105 | train |
pulsarvp/vps-tools | src/net/Flow.php | Flow.getIsComplete | public function getIsComplete ()
{
if ($this->_isComplete)
return true;
for ($i = 1; $i <= $this->_params[ 'totalChunks' ]; $i++)
{
if (!$this->chunkIsUploaded($i))
{
$this->_isComplete = false;
return false;
}
}
$this->_isComplete = true;
return true;
} | php | public function getIsComplete ()
{
if ($this->_isComplete)
return true;
for ($i = 1; $i <= $this->_params[ 'totalChunks' ]; $i++)
{
if (!$this->chunkIsUploaded($i))
{
$this->_isComplete = false;
return false;
}
}
$this->_isComplete = true;
return true;
} | [
"public",
"function",
"getIsComplete",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_isComplete",
")",
"return",
"true",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<=",
"$",
"this",
"->",
"_params",
"[",
"'totalChunks'",
"]",
";",
"$",
... | Check whether file uploading is complete.
@return bool | [
"Check",
"whether",
"file",
"uploading",
"is",
"complete",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Flow.php#L111-L129 | train |
pulsarvp/vps-tools | src/net/Flow.php | Flow.getIsNew | public function getIsNew ()
{
if ($this->_isNew == false)
return false;
for ($i = 1; $i <= $this->_params[ 'totalChunks' ]; $i++)
{
if ($this->chunkIsUploaded($i))
{
$this->_isNew = false;
return false;
}
}
$this->_isNew = true;
return true;
} | php | public function getIsNew ()
{
if ($this->_isNew == false)
return false;
for ($i = 1; $i <= $this->_params[ 'totalChunks' ]; $i++)
{
if ($this->chunkIsUploaded($i))
{
$this->_isNew = false;
return false;
}
}
$this->_isNew = true;
return true;
} | [
"public",
"function",
"getIsNew",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_isNew",
"==",
"false",
")",
"return",
"false",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<=",
"$",
"this",
"->",
"_params",
"[",
"'totalChunks'",
"]",
";"... | Check whether file uploading is new.
@return bool | [
"Check",
"whether",
"file",
"uploading",
"is",
"new",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Flow.php#L135-L153 | train |
pulsarvp/vps-tools | src/net/Flow.php | Flow.getParam | public function getParam ($name)
{
if (isset( $this->_params[ $name ] ))
return $this->_params[ $name ];
else
return null;
} | php | public function getParam ($name)
{
if (isset( $this->_params[ $name ] ))
return $this->_params[ $name ];
else
return null;
} | [
"public",
"function",
"getParam",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_params",
"[",
"$",
"name",
"]",
")",
")",
"return",
"$",
"this",
"->",
"_params",
"[",
"$",
"name",
"]",
";",
"else",
"return",
"null",
";... | Gets param by its name.
@param string $name Parameter name.
@return null|mixed Parameter if exists, null otherwise. | [
"Gets",
"param",
"by",
"its",
"name",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Flow.php#L169-L175 | train |
pulsarvp/vps-tools | src/net/Flow.php | Flow.setTmpDir | public function setTmpDir ($dir)
{
$this->_tmpDir = $dir . '/' . $this->_params[ 'identifier' ];
if (!is_dir($this->_tmpDir))
FileHelper::createDirectory($this->_tmpDir);
} | php | public function setTmpDir ($dir)
{
$this->_tmpDir = $dir . '/' . $this->_params[ 'identifier' ];
if (!is_dir($this->_tmpDir))
FileHelper::createDirectory($this->_tmpDir);
} | [
"public",
"function",
"setTmpDir",
"(",
"$",
"dir",
")",
"{",
"$",
"this",
"->",
"_tmpDir",
"=",
"$",
"dir",
".",
"'/'",
".",
"$",
"this",
"->",
"_params",
"[",
"'identifier'",
"]",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"this",
"->",
"_tmpDir",
... | Sets temporary directory.
@param string $dir
@throws \yii\base\Exception | [
"Sets",
"temporary",
"directory",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Flow.php#L191-L196 | train |
pulsarvp/vps-tools | src/net/Flow.php | Flow.setTargetDir | public function setTargetDir ($dir)
{
$this->_targetDir = $dir;
if (!is_dir($this->_targetDir))
FileHelper::createDirectory($this->_targetDir);
} | php | public function setTargetDir ($dir)
{
$this->_targetDir = $dir;
if (!is_dir($this->_targetDir))
FileHelper::createDirectory($this->_targetDir);
} | [
"public",
"function",
"setTargetDir",
"(",
"$",
"dir",
")",
"{",
"$",
"this",
"->",
"_targetDir",
"=",
"$",
"dir",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"this",
"->",
"_targetDir",
")",
")",
"FileHelper",
"::",
"createDirectory",
"(",
"$",
"this",
... | Sets path to target directory where to save video file.
@param string $dir
@throws \yii\base\Exception | [
"Sets",
"path",
"to",
"target",
"directory",
"where",
"to",
"save",
"video",
"file",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Flow.php#L203-L208 | train |
pulsarvp/vps-tools | src/net/Flow.php | Flow.process | public function process ()
{
if (!empty( $this->_params ))
{
if ($this->getIsUploading())
$this->uploadChunk();
else
$this->testChunk();
}
} | php | public function process ()
{
if (!empty( $this->_params ))
{
if ($this->getIsUploading())
$this->uploadChunk();
else
$this->testChunk();
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_params",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getIsUploading",
"(",
")",
")",
"$",
"this",
"->",
"uploadChunk",
"(",
")",
";",
"else",
"$"... | Uploads or tests current chunk. | [
"Uploads",
"or",
"tests",
"current",
"chunk",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Flow.php#L213-L222 | train |
pulsarvp/vps-tools | src/net/Flow.php | Flow.save | public function save ($name = null)
{
if ($name == null)
$name = StringHelper::random();
$ext = pathinfo($this->_params[ 'filename' ], PATHINFO_EXTENSION);
$this->_savedFilename = $name . '.' . $ext;
if (( $file = fopen($this->_targetDir . '/' . $this->_savedFilename, 'w') ) !== false)
{
if (Yii::$app->settings->get('upload_concat') == 'cat')
{
fclose($file);
setlocale(LC_ALL, 'ru_RU.UTF-8');
for ($i = 1; $i <= $this->_params[ 'totalChunks' ]; $i++)
shell_exec('cat ' . escapeshellarg($this->getChunkPath($i)) . ' >> ' . escapeshellarg($this->_targetDir . '/' . $this->_savedFilename));
setlocale(LC_ALL, null);
}
else
{
for ($i = 1; $i <= $this->_params[ 'totalChunks' ]; $i++)
fwrite($file, file_get_contents($this->getChunkPath($i)));
fclose($file);
}
}
FileHelper::removeDirectory($this->_tmpDir);
return $this->_savedFilename;
} | php | public function save ($name = null)
{
if ($name == null)
$name = StringHelper::random();
$ext = pathinfo($this->_params[ 'filename' ], PATHINFO_EXTENSION);
$this->_savedFilename = $name . '.' . $ext;
if (( $file = fopen($this->_targetDir . '/' . $this->_savedFilename, 'w') ) !== false)
{
if (Yii::$app->settings->get('upload_concat') == 'cat')
{
fclose($file);
setlocale(LC_ALL, 'ru_RU.UTF-8');
for ($i = 1; $i <= $this->_params[ 'totalChunks' ]; $i++)
shell_exec('cat ' . escapeshellarg($this->getChunkPath($i)) . ' >> ' . escapeshellarg($this->_targetDir . '/' . $this->_savedFilename));
setlocale(LC_ALL, null);
}
else
{
for ($i = 1; $i <= $this->_params[ 'totalChunks' ]; $i++)
fwrite($file, file_get_contents($this->getChunkPath($i)));
fclose($file);
}
}
FileHelper::removeDirectory($this->_tmpDir);
return $this->_savedFilename;
} | [
"public",
"function",
"save",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"name",
"==",
"null",
")",
"$",
"name",
"=",
"StringHelper",
"::",
"random",
"(",
")",
";",
"$",
"ext",
"=",
"pathinfo",
"(",
"$",
"this",
"->",
"_params",
"["... | Saves uploaded file.
@param null|string $name File name (without extension).
@return string Saved file name with extension.
@throws \yii\base\ErrorException | [
"Saves",
"uploaded",
"file",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Flow.php#L230-L257 | train |
pulsarvp/vps-tools | src/net/Flow.php | Flow.uploadChunk | public function uploadChunk ()
{
move_uploaded_file($this->_file[ 'tmp_name' ], $this->chunkPath);
Yii::$app->response->setStatusCode(200);
} | php | public function uploadChunk ()
{
move_uploaded_file($this->_file[ 'tmp_name' ], $this->chunkPath);
Yii::$app->response->setStatusCode(200);
} | [
"public",
"function",
"uploadChunk",
"(",
")",
"{",
"move_uploaded_file",
"(",
"$",
"this",
"->",
"_file",
"[",
"'tmp_name'",
"]",
",",
"$",
"this",
"->",
"chunkPath",
")",
";",
"Yii",
"::",
"$",
"app",
"->",
"response",
"->",
"setStatusCode",
"(",
"200"... | Uploads current chunk.
@throws \yii\base\ErrorException | [
"Uploads",
"current",
"chunk",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/net/Flow.php#L274-L279 | train |
EmchBerger/cube-custom-fields-bundle | src/Utils/ConfigReader.php | ConfigReader.getConfigForEntity | public function getConfigForEntity($entity)
{
if (is_object($entity)) {
$entityClass = self::getEntityClass($entity);
} else {
$entityClass = $entity;
}
if (array_key_exists($entityClass, $this->config)) {
return $this->config[$entityClass];
}
return array();
} | php | public function getConfigForEntity($entity)
{
if (is_object($entity)) {
$entityClass = self::getEntityClass($entity);
} else {
$entityClass = $entity;
}
if (array_key_exists($entityClass, $this->config)) {
return $this->config[$entityClass];
}
return array();
} | [
"public",
"function",
"getConfigForEntity",
"(",
"$",
"entity",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"entity",
")",
")",
"{",
"$",
"entityClass",
"=",
"self",
"::",
"getEntityClass",
"(",
"$",
"entity",
")",
";",
"}",
"else",
"{",
"$",
"entityCl... | Returns the custom field config for the given entity
@param object|string entity or class of entity
@return array config of entity | [
"Returns",
"the",
"custom",
"field",
"config",
"for",
"the",
"given",
"entity"
] | 7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414 | https://github.com/EmchBerger/cube-custom-fields-bundle/blob/7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414/src/Utils/ConfigReader.php#L41-L53 | train |
pulsarvp/vps-tools | src/modules/setting/migrations/m010101_100001_init_setting.php | m010101_100001_init_setting.up | public function up ()
{
$this->createTable('setting', [
'name' => $this->string(45)->notNull()->unique(),
'value' => $this->text()->null(),
'description' => $this->text()->null(),
]);
$this->addPrimaryKey('name', 'setting', 'name');
} | php | public function up ()
{
$this->createTable('setting', [
'name' => $this->string(45)->notNull()->unique(),
'value' => $this->text()->null(),
'description' => $this->text()->null(),
]);
$this->addPrimaryKey('name', 'setting', 'name');
} | [
"public",
"function",
"up",
"(",
")",
"{",
"$",
"this",
"->",
"createTable",
"(",
"'setting'",
",",
"[",
"'name'",
"=>",
"$",
"this",
"->",
"string",
"(",
"45",
")",
"->",
"notNull",
"(",
")",
"->",
"unique",
"(",
")",
",",
"'value'",
"=>",
"$",
... | Create table `Setting` | [
"Create",
"table",
"Setting"
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/setting/migrations/m010101_100001_init_setting.php#L10-L18 | train |
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",
")",
"&&",
"!",... | 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 | train |
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",
"(",
"'no... | 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 | train |
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... | 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 | train |
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'",
")",
")",
... | 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 | train |
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... | 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 | train |
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",
"(",... | 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 | train |
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... | 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 | train |
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",
"]",
")",
... | 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 | train |
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",
";",
"}",
... | 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 | train |
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",
"(",
"''",
")",
";",
"$",
"th... | 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 | train |
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",
"(",
"... | 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 | train |
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",
"(",
"$",
"user... | 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 | train |
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",... | 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 | train |
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",
... | 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 | train |
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",
... | 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 | train |
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",
... | 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 | train |
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",
")",
... | 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 | train |
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",
")",
"... | 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 | train |
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",
"=",
"s... | 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 | train |
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",
"(",
")",
".",
"microtim... | 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 | train |
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",
"("... | 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 | train |
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",
")",
"&&",
"!... | 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 | train |
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",
"(",
"'... | 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 | train |
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'",
"... | 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 | train |
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",
"=",
"$",
"configOpti... | 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 | train |
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"... | Include a file
@param string $filename | [
"Include",
"a",
"file"
] | 1bc9db0e4846d80ad38b14662b6e48edaa7d289f | https://github.com/oradwell/covers-validator/blob/1bc9db0e4846d80ad38b14662b6e48edaa7d289f/src/Loader/FileLoader.php#L12-L21 | train |
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",
"\... | 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 | train |
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",
"(",
"t... | 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 | train |
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... | 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 | train |
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_... | 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 | train |
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",
"(",
... | 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 | train |
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",
"(... | 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 | train |
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",... | 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 | train |
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'",
")"... | 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 | train |
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",... | 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 | train |
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\"",
")",... | 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 | train |
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",
... | 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 | train |
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",
"[",
"$",
... | 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 | train |
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",
")... | 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 | train |
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",
"[... | 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 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.