id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
|---|---|---|---|---|---|---|---|---|---|---|---|
224,800
|
dereuromark/cakephp-data
|
src/Controller/Admin/CountriesController.php
|
CountriesController.icons
|
public function icons() {
$icons = $this->_icons();
$countries = $this->Countries->find('all', ['fields' => ['id', 'name', 'iso2', 'iso3']]);
$usedIcons = [];
# countries without icons
$contriesWithoutIcons = [];
foreach ($countries as $country) {
$icon = strtoupper($country['iso2']);
if (!in_array($icon, $icons)) {
$contriesWithoutIcons[] = $country;
} else {
$key = array_keys($icons, $icon);
$usedIcons[] = $icons[$key[0]];
}
}
# icons without countries
$iconsWithoutCountries = [];
$iconsWithoutCountries = array_diff($icons, $usedIcons);
//pr($iconsWithoutCountries);
$this->set(compact('icons', 'countries', 'contriesWithoutIcons', 'iconsWithoutCountries'));
}
|
php
|
public function icons() {
$icons = $this->_icons();
$countries = $this->Countries->find('all', ['fields' => ['id', 'name', 'iso2', 'iso3']]);
$usedIcons = [];
# countries without icons
$contriesWithoutIcons = [];
foreach ($countries as $country) {
$icon = strtoupper($country['iso2']);
if (!in_array($icon, $icons)) {
$contriesWithoutIcons[] = $country;
} else {
$key = array_keys($icons, $icon);
$usedIcons[] = $icons[$key[0]];
}
}
# icons without countries
$iconsWithoutCountries = [];
$iconsWithoutCountries = array_diff($icons, $usedIcons);
//pr($iconsWithoutCountries);
$this->set(compact('icons', 'countries', 'contriesWithoutIcons', 'iconsWithoutCountries'));
}
|
[
"public",
"function",
"icons",
"(",
")",
"{",
"$",
"icons",
"=",
"$",
"this",
"->",
"_icons",
"(",
")",
";",
"$",
"countries",
"=",
"$",
"this",
"->",
"Countries",
"->",
"find",
"(",
"'all'",
",",
"[",
"'fields'",
"=>",
"[",
"'id'",
",",
"'name'",
",",
"'iso2'",
",",
"'iso3'",
"]",
"]",
")",
";",
"$",
"usedIcons",
"=",
"[",
"]",
";",
"# countries without icons",
"$",
"contriesWithoutIcons",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"countries",
"as",
"$",
"country",
")",
"{",
"$",
"icon",
"=",
"strtoupper",
"(",
"$",
"country",
"[",
"'iso2'",
"]",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"icon",
",",
"$",
"icons",
")",
")",
"{",
"$",
"contriesWithoutIcons",
"[",
"]",
"=",
"$",
"country",
";",
"}",
"else",
"{",
"$",
"key",
"=",
"array_keys",
"(",
"$",
"icons",
",",
"$",
"icon",
")",
";",
"$",
"usedIcons",
"[",
"]",
"=",
"$",
"icons",
"[",
"$",
"key",
"[",
"0",
"]",
"]",
";",
"}",
"}",
"# icons without countries",
"$",
"iconsWithoutCountries",
"=",
"[",
"]",
";",
"$",
"iconsWithoutCountries",
"=",
"array_diff",
"(",
"$",
"icons",
",",
"$",
"usedIcons",
")",
";",
"//pr($iconsWithoutCountries);",
"$",
"this",
"->",
"set",
"(",
"compact",
"(",
"'icons'",
",",
"'countries'",
",",
"'contriesWithoutIcons'",
",",
"'iconsWithoutCountries'",
")",
")",
";",
"}"
] |
Check for missing or unused country flag icons
@return \Cake\Http\Response|null
|
[
"Check",
"for",
"missing",
"or",
"unused",
"country",
"flag",
"icons"
] |
362f8db270fc994ac3665c33682cefba7d73bb44
|
https://github.com/dereuromark/cakephp-data/blob/362f8db270fc994ac3665c33682cefba7d73bb44/src/Controller/Admin/CountriesController.php#L67-L92
|
224,801
|
mediumart/orange-sms
|
src/Http/SMSClient.php
|
SMSClient.configure
|
public function configure()
{
switch (count($options = func_get_args())) {
case 0:
break;
case 1:
$this->configureInstance($options[0]);
break;
case 2:
$this->configureInstanceAssoc(
static::authorize($options[0], $options[1])
);
break;
default:
throw new \InvalidArgumentException('invalid argument count');
break;
}
return $this;
}
|
php
|
public function configure()
{
switch (count($options = func_get_args())) {
case 0:
break;
case 1:
$this->configureInstance($options[0]);
break;
case 2:
$this->configureInstanceAssoc(
static::authorize($options[0], $options[1])
);
break;
default:
throw new \InvalidArgumentException('invalid argument count');
break;
}
return $this;
}
|
[
"public",
"function",
"configure",
"(",
")",
"{",
"switch",
"(",
"count",
"(",
"$",
"options",
"=",
"func_get_args",
"(",
")",
")",
")",
"{",
"case",
"0",
":",
"break",
";",
"case",
"1",
":",
"$",
"this",
"->",
"configureInstance",
"(",
"$",
"options",
"[",
"0",
"]",
")",
";",
"break",
";",
"case",
"2",
":",
"$",
"this",
"->",
"configureInstanceAssoc",
"(",
"static",
"::",
"authorize",
"(",
"$",
"options",
"[",
"0",
"]",
",",
"$",
"options",
"[",
"1",
"]",
")",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'invalid argument count'",
")",
";",
"break",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Configure the instance.
@param array $options
@return $this
|
[
"Configure",
"the",
"instance",
"."
] |
62aff9d24c326663fa8b9e742fa3f15c9df20945
|
https://github.com/mediumart/orange-sms/blob/62aff9d24c326663fa8b9e742fa3f15c9df20945/src/Http/SMSClient.php#L91-L113
|
224,802
|
mediumart/orange-sms
|
src/Http/SMSClient.php
|
SMSClient.configureInstance
|
protected function configureInstance($options)
{
if (is_string($options)) {
$this->setToken($options)->setTokenExpiresIn(null);
} elseif (is_array($options)) {
$this->configureInstanceAssoc($options);
}
}
|
php
|
protected function configureInstance($options)
{
if (is_string($options)) {
$this->setToken($options)->setTokenExpiresIn(null);
} elseif (is_array($options)) {
$this->configureInstanceAssoc($options);
}
}
|
[
"protected",
"function",
"configureInstance",
"(",
"$",
"options",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"options",
")",
")",
"{",
"$",
"this",
"->",
"setToken",
"(",
"$",
"options",
")",
"->",
"setTokenExpiresIn",
"(",
"null",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"options",
")",
")",
"{",
"$",
"this",
"->",
"configureInstanceAssoc",
"(",
"$",
"options",
")",
";",
"}",
"}"
] |
Configure instance using options.
@param mixed $options
@return $this
|
[
"Configure",
"instance",
"using",
"options",
"."
] |
62aff9d24c326663fa8b9e742fa3f15c9df20945
|
https://github.com/mediumart/orange-sms/blob/62aff9d24c326663fa8b9e742fa3f15c9df20945/src/Http/SMSClient.php#L121-L128
|
224,803
|
mediumart/orange-sms
|
src/Http/SMSClient.php
|
SMSClient.configureInstanceAssoc
|
protected function configureInstanceAssoc(array $options)
{
if (array_key_exists('access_token', $options)) {
$this->setToken($options['access_token']);
}
if (array_key_exists('expires_in', $options)) {
$this->setTokenExpiresIn($options['expires_in']);
}
return $this;
}
|
php
|
protected function configureInstanceAssoc(array $options)
{
if (array_key_exists('access_token', $options)) {
$this->setToken($options['access_token']);
}
if (array_key_exists('expires_in', $options)) {
$this->setTokenExpiresIn($options['expires_in']);
}
return $this;
}
|
[
"protected",
"function",
"configureInstanceAssoc",
"(",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"'access_token'",
",",
"$",
"options",
")",
")",
"{",
"$",
"this",
"->",
"setToken",
"(",
"$",
"options",
"[",
"'access_token'",
"]",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'expires_in'",
",",
"$",
"options",
")",
")",
"{",
"$",
"this",
"->",
"setTokenExpiresIn",
"(",
"$",
"options",
"[",
"'expires_in'",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Configure instance using assoc array options.
@param array $options
@return $this
|
[
"Configure",
"instance",
"using",
"assoc",
"array",
"options",
"."
] |
62aff9d24c326663fa8b9e742fa3f15c9df20945
|
https://github.com/mediumart/orange-sms/blob/62aff9d24c326663fa8b9e742fa3f15c9df20945/src/Http/SMSClient.php#L136-L147
|
224,804
|
mediumart/orange-sms
|
src/Http/SMSClient.php
|
SMSClient.executeRequest
|
public function executeRequest(SMSClientRequest $request, $decodeJson = true)
{
$options = $request->options();
if (! isset($options['headers']["Authorization"])) {
$options['headers']["Authorization"] = "Bearer ". $this->getToken();
}
$response = $request->execute($options)->getBody();
return $decodeJson ? json_decode($response, true) : $response;
}
|
php
|
public function executeRequest(SMSClientRequest $request, $decodeJson = true)
{
$options = $request->options();
if (! isset($options['headers']["Authorization"])) {
$options['headers']["Authorization"] = "Bearer ". $this->getToken();
}
$response = $request->execute($options)->getBody();
return $decodeJson ? json_decode($response, true) : $response;
}
|
[
"public",
"function",
"executeRequest",
"(",
"SMSClientRequest",
"$",
"request",
",",
"$",
"decodeJson",
"=",
"true",
")",
"{",
"$",
"options",
"=",
"$",
"request",
"->",
"options",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'headers'",
"]",
"[",
"\"Authorization\"",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'headers'",
"]",
"[",
"\"Authorization\"",
"]",
"=",
"\"Bearer \"",
".",
"$",
"this",
"->",
"getToken",
"(",
")",
";",
"}",
"$",
"response",
"=",
"$",
"request",
"->",
"execute",
"(",
"$",
"options",
")",
"->",
"getBody",
"(",
")",
";",
"return",
"$",
"decodeJson",
"?",
"json_decode",
"(",
"$",
"response",
",",
"true",
")",
":",
"$",
"response",
";",
"}"
] |
Execute a request against the Api server
@param SMSClientRequest $request
@param bool $decodeJson
@return array
|
[
"Execute",
"a",
"request",
"against",
"the",
"Api",
"server"
] |
62aff9d24c326663fa8b9e742fa3f15c9df20945
|
https://github.com/mediumart/orange-sms/blob/62aff9d24c326663fa8b9e742fa3f15c9df20945/src/Http/SMSClient.php#L156-L167
|
224,805
|
mediumart/orange-sms
|
src/Http/SMSClient.php
|
SMSClient.authorize
|
public static function authorize($clientID, $clientSecret)
{
return json_decode(
(new AuthorizationRequest($clientID, $clientSecret))->execute()->getBody(), true
);
}
|
php
|
public static function authorize($clientID, $clientSecret)
{
return json_decode(
(new AuthorizationRequest($clientID, $clientSecret))->execute()->getBody(), true
);
}
|
[
"public",
"static",
"function",
"authorize",
"(",
"$",
"clientID",
",",
"$",
"clientSecret",
")",
"{",
"return",
"json_decode",
"(",
"(",
"new",
"AuthorizationRequest",
"(",
"$",
"clientID",
",",
"$",
"clientSecret",
")",
")",
"->",
"execute",
"(",
")",
"->",
"getBody",
"(",
")",
",",
"true",
")",
";",
"}"
] |
Get the client access token
@param $clientID
@param $clientSecret
@return array
|
[
"Get",
"the",
"client",
"access",
"token"
] |
62aff9d24c326663fa8b9e742fa3f15c9df20945
|
https://github.com/mediumart/orange-sms/blob/62aff9d24c326663fa8b9e742fa3f15c9df20945/src/Http/SMSClient.php#L176-L181
|
224,806
|
dereuromark/cakephp-data
|
src/Controller/Component/CountryStateHelperComponent.php
|
CountryStateHelperComponent.provideData
|
public function provideData($ignoreStates = false, $model = null, $defaultValue = 0) {
if (!isset($this->Controller->Countries)) {
$this->Controller->Countries = TableRegistry::get('Data.Countries');
}
$countries = $this->Controller->Countries->findActive()->hydrate(false)->find('list')->toArray();
$states = [];
if ($model === null) {
$model = $this->Controller->modelClass;
}
if (!isset($this->Controller->States)) {
$this->Controller->States = TableRegistry::get('Data.States');
}
$selectedCountry = $this->Controller->request->getQuery('country_id');
if (!empty($this->Controller->request->data['country_id'])) {
$selectedCountry = $this->Controller->request->data['country_id'];
}
if ($selectedCountry) {
$states = $this->Controller->States->getListByCountry($selectedCountry);
} elseif ($ignoreStates === true) {
# do nothing
} else {
# use the id of the first country of the country-list
foreach ($countries as $key => $value) {
$states = $this->Controller->States->getListByCountry($key);
break;
}
}
$this->Controller->set(compact('countries', 'states', 'defaultValue'));
}
|
php
|
public function provideData($ignoreStates = false, $model = null, $defaultValue = 0) {
if (!isset($this->Controller->Countries)) {
$this->Controller->Countries = TableRegistry::get('Data.Countries');
}
$countries = $this->Controller->Countries->findActive()->hydrate(false)->find('list')->toArray();
$states = [];
if ($model === null) {
$model = $this->Controller->modelClass;
}
if (!isset($this->Controller->States)) {
$this->Controller->States = TableRegistry::get('Data.States');
}
$selectedCountry = $this->Controller->request->getQuery('country_id');
if (!empty($this->Controller->request->data['country_id'])) {
$selectedCountry = $this->Controller->request->data['country_id'];
}
if ($selectedCountry) {
$states = $this->Controller->States->getListByCountry($selectedCountry);
} elseif ($ignoreStates === true) {
# do nothing
} else {
# use the id of the first country of the country-list
foreach ($countries as $key => $value) {
$states = $this->Controller->States->getListByCountry($key);
break;
}
}
$this->Controller->set(compact('countries', 'states', 'defaultValue'));
}
|
[
"public",
"function",
"provideData",
"(",
"$",
"ignoreStates",
"=",
"false",
",",
"$",
"model",
"=",
"null",
",",
"$",
"defaultValue",
"=",
"0",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"Controller",
"->",
"Countries",
")",
")",
"{",
"$",
"this",
"->",
"Controller",
"->",
"Countries",
"=",
"TableRegistry",
"::",
"get",
"(",
"'Data.Countries'",
")",
";",
"}",
"$",
"countries",
"=",
"$",
"this",
"->",
"Controller",
"->",
"Countries",
"->",
"findActive",
"(",
")",
"->",
"hydrate",
"(",
"false",
")",
"->",
"find",
"(",
"'list'",
")",
"->",
"toArray",
"(",
")",
";",
"$",
"states",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"model",
"===",
"null",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"Controller",
"->",
"modelClass",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"Controller",
"->",
"States",
")",
")",
"{",
"$",
"this",
"->",
"Controller",
"->",
"States",
"=",
"TableRegistry",
"::",
"get",
"(",
"'Data.States'",
")",
";",
"}",
"$",
"selectedCountry",
"=",
"$",
"this",
"->",
"Controller",
"->",
"request",
"->",
"getQuery",
"(",
"'country_id'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"Controller",
"->",
"request",
"->",
"data",
"[",
"'country_id'",
"]",
")",
")",
"{",
"$",
"selectedCountry",
"=",
"$",
"this",
"->",
"Controller",
"->",
"request",
"->",
"data",
"[",
"'country_id'",
"]",
";",
"}",
"if",
"(",
"$",
"selectedCountry",
")",
"{",
"$",
"states",
"=",
"$",
"this",
"->",
"Controller",
"->",
"States",
"->",
"getListByCountry",
"(",
"$",
"selectedCountry",
")",
";",
"}",
"elseif",
"(",
"$",
"ignoreStates",
"===",
"true",
")",
"{",
"# do nothing",
"}",
"else",
"{",
"# use the id of the first country of the country-list",
"foreach",
"(",
"$",
"countries",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"states",
"=",
"$",
"this",
"->",
"Controller",
"->",
"States",
"->",
"getListByCountry",
"(",
"$",
"key",
")",
";",
"break",
";",
"}",
"}",
"$",
"this",
"->",
"Controller",
"->",
"set",
"(",
"compact",
"(",
"'countries'",
",",
"'states'",
",",
"'defaultValue'",
")",
")",
";",
"}"
] |
Call in methods where needed
@param bool $ignoreStates
@param string|null $model
@param int $defaultValue
@return void
|
[
"Call",
"in",
"methods",
"where",
"needed"
] |
362f8db270fc994ac3665c33682cefba7d73bb44
|
https://github.com/dereuromark/cakephp-data/blob/362f8db270fc994ac3665c33682cefba7d73bb44/src/Controller/Component/CountryStateHelperComponent.php#L34-L66
|
224,807
|
fillup/walmart-auth-signature-php
|
src/Signature.php
|
Signature.calculateSignature
|
public static function calculateSignature($consumerId, $privateKey, $requestUrl, $requestMethod, $timestamp=null)
{
if(is_null($timestamp) || !is_numeric($timestamp)){
$timestamp = self::getMilliseconds();
}
/**
* Append values into string for signing
*/
$message = $consumerId."\n".$requestUrl."\n".strtoupper($requestMethod)."\n".$timestamp."\n";
/**
* Get RSA object for signing
*/
$rsa = new RSA();
$decodedPrivateKey = base64_decode($privateKey);
$rsa->setPrivateKeyFormat(RSA::PRIVATE_FORMAT_PKCS8);
$rsa->setPublicKeyFormat(RSA::PRIVATE_FORMAT_PKCS8);
/**
* Load private key
*/
if($rsa->loadKey($decodedPrivateKey,RSA::PRIVATE_FORMAT_PKCS8)){
/**
* Make sure we use SHA256 for signing
*/
$rsa->setHash('sha256');
$rsa->setSignatureMode(RSA::SIGNATURE_PKCS1);
$signed = $rsa->sign($message);
/**
* Return Base64 Encode generated signature
*/
return base64_encode($signed);
} else {
throw new \Exception("Unable to load private key", 1446780146);
}
}
|
php
|
public static function calculateSignature($consumerId, $privateKey, $requestUrl, $requestMethod, $timestamp=null)
{
if(is_null($timestamp) || !is_numeric($timestamp)){
$timestamp = self::getMilliseconds();
}
/**
* Append values into string for signing
*/
$message = $consumerId."\n".$requestUrl."\n".strtoupper($requestMethod)."\n".$timestamp."\n";
/**
* Get RSA object for signing
*/
$rsa = new RSA();
$decodedPrivateKey = base64_decode($privateKey);
$rsa->setPrivateKeyFormat(RSA::PRIVATE_FORMAT_PKCS8);
$rsa->setPublicKeyFormat(RSA::PRIVATE_FORMAT_PKCS8);
/**
* Load private key
*/
if($rsa->loadKey($decodedPrivateKey,RSA::PRIVATE_FORMAT_PKCS8)){
/**
* Make sure we use SHA256 for signing
*/
$rsa->setHash('sha256');
$rsa->setSignatureMode(RSA::SIGNATURE_PKCS1);
$signed = $rsa->sign($message);
/**
* Return Base64 Encode generated signature
*/
return base64_encode($signed);
} else {
throw new \Exception("Unable to load private key", 1446780146);
}
}
|
[
"public",
"static",
"function",
"calculateSignature",
"(",
"$",
"consumerId",
",",
"$",
"privateKey",
",",
"$",
"requestUrl",
",",
"$",
"requestMethod",
",",
"$",
"timestamp",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"timestamp",
")",
"||",
"!",
"is_numeric",
"(",
"$",
"timestamp",
")",
")",
"{",
"$",
"timestamp",
"=",
"self",
"::",
"getMilliseconds",
"(",
")",
";",
"}",
"/**\n * Append values into string for signing\n */",
"$",
"message",
"=",
"$",
"consumerId",
".",
"\"\\n\"",
".",
"$",
"requestUrl",
".",
"\"\\n\"",
".",
"strtoupper",
"(",
"$",
"requestMethod",
")",
".",
"\"\\n\"",
".",
"$",
"timestamp",
".",
"\"\\n\"",
";",
"/**\n * Get RSA object for signing\n */",
"$",
"rsa",
"=",
"new",
"RSA",
"(",
")",
";",
"$",
"decodedPrivateKey",
"=",
"base64_decode",
"(",
"$",
"privateKey",
")",
";",
"$",
"rsa",
"->",
"setPrivateKeyFormat",
"(",
"RSA",
"::",
"PRIVATE_FORMAT_PKCS8",
")",
";",
"$",
"rsa",
"->",
"setPublicKeyFormat",
"(",
"RSA",
"::",
"PRIVATE_FORMAT_PKCS8",
")",
";",
"/**\n * Load private key\n */",
"if",
"(",
"$",
"rsa",
"->",
"loadKey",
"(",
"$",
"decodedPrivateKey",
",",
"RSA",
"::",
"PRIVATE_FORMAT_PKCS8",
")",
")",
"{",
"/**\n * Make sure we use SHA256 for signing\n */",
"$",
"rsa",
"->",
"setHash",
"(",
"'sha256'",
")",
";",
"$",
"rsa",
"->",
"setSignatureMode",
"(",
"RSA",
"::",
"SIGNATURE_PKCS1",
")",
";",
"$",
"signed",
"=",
"$",
"rsa",
"->",
"sign",
"(",
"$",
"message",
")",
";",
"/**\n * Return Base64 Encode generated signature\n */",
"return",
"base64_encode",
"(",
"$",
"signed",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Unable to load private key\"",
",",
"1446780146",
")",
";",
"}",
"}"
] |
Static method for quick calls to calculate a signature.
@link https://developer.walmartapis.com/#authentication
@param string $consumerId
@param string $privateKey
@param string $requestUrl
@param string $requestMethod
@param string|null $timestamp
@return string
@throws \Exception
|
[
"Static",
"method",
"for",
"quick",
"calls",
"to",
"calculate",
"a",
"signature",
"."
] |
7c1b94a0e00baa79bf51d5d0986fd9a667e6efce
|
https://github.com/fillup/walmart-auth-signature-php/blob/7c1b94a0e00baa79bf51d5d0986fd9a667e6efce/src/Signature.php#L76-L114
|
224,808
|
sulu/SuluRedirectBundle
|
Controller/RedirectRouteController.php
|
RedirectRouteController.cgetAction
|
public function cgetAction(Request $request)
{
$restHelper = $this->get('sulu_core.doctrine_rest_helper');
$factory = $this->get('sulu_core.doctrine_list_builder_factory');
$listBuilder = $factory->create(RedirectRoute::class);
$restHelper->initializeListBuilder($listBuilder, $this->getFieldDescriptors());
$results = $listBuilder->execute();
$list = new ListRepresentation(
$results,
self::RESULT_KEY,
$request->attributes->get('_route'),
$request->query->all(),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
return $this->handleView($this->view($list));
}
|
php
|
public function cgetAction(Request $request)
{
$restHelper = $this->get('sulu_core.doctrine_rest_helper');
$factory = $this->get('sulu_core.doctrine_list_builder_factory');
$listBuilder = $factory->create(RedirectRoute::class);
$restHelper->initializeListBuilder($listBuilder, $this->getFieldDescriptors());
$results = $listBuilder->execute();
$list = new ListRepresentation(
$results,
self::RESULT_KEY,
$request->attributes->get('_route'),
$request->query->all(),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
return $this->handleView($this->view($list));
}
|
[
"public",
"function",
"cgetAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"restHelper",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.doctrine_rest_helper'",
")",
";",
"$",
"factory",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.doctrine_list_builder_factory'",
")",
";",
"$",
"listBuilder",
"=",
"$",
"factory",
"->",
"create",
"(",
"RedirectRoute",
"::",
"class",
")",
";",
"$",
"restHelper",
"->",
"initializeListBuilder",
"(",
"$",
"listBuilder",
",",
"$",
"this",
"->",
"getFieldDescriptors",
"(",
")",
")",
";",
"$",
"results",
"=",
"$",
"listBuilder",
"->",
"execute",
"(",
")",
";",
"$",
"list",
"=",
"new",
"ListRepresentation",
"(",
"$",
"results",
",",
"self",
"::",
"RESULT_KEY",
",",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'_route'",
")",
",",
"$",
"request",
"->",
"query",
"->",
"all",
"(",
")",
",",
"$",
"listBuilder",
"->",
"getCurrentPage",
"(",
")",
",",
"$",
"listBuilder",
"->",
"getLimit",
"(",
")",
",",
"$",
"listBuilder",
"->",
"count",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"$",
"list",
")",
")",
";",
"}"
] |
Returns redirect-routes.
@param Request $request
@return Response
|
[
"Returns",
"redirect",
"-",
"routes",
"."
] |
913c501cced6c7db5fb96d4baf6cce4b884c65c6
|
https://github.com/sulu/SuluRedirectBundle/blob/913c501cced6c7db5fb96d4baf6cce4b884c65c6/Controller/RedirectRouteController.php#L52-L72
|
224,809
|
sulu/SuluRedirectBundle
|
Controller/RedirectRouteController.php
|
RedirectRouteController.postAction
|
public function postAction(Request $request)
{
$data = $request->request->all();
$serializer = $this->get('serializer');
$redirectRoute = $serializer->deserialize(
json_encode($data),
$this->getParameter('sulu.model.redirect_route.class'),
'json'
);
$this->getRedirectRouteManager()->save($redirectRoute);
$this->get('doctrine.orm.entity_manager')->flush();
return $this->handleView($this->view($redirectRoute));
}
|
php
|
public function postAction(Request $request)
{
$data = $request->request->all();
$serializer = $this->get('serializer');
$redirectRoute = $serializer->deserialize(
json_encode($data),
$this->getParameter('sulu.model.redirect_route.class'),
'json'
);
$this->getRedirectRouteManager()->save($redirectRoute);
$this->get('doctrine.orm.entity_manager')->flush();
return $this->handleView($this->view($redirectRoute));
}
|
[
"public",
"function",
"postAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"data",
"=",
"$",
"request",
"->",
"request",
"->",
"all",
"(",
")",
";",
"$",
"serializer",
"=",
"$",
"this",
"->",
"get",
"(",
"'serializer'",
")",
";",
"$",
"redirectRoute",
"=",
"$",
"serializer",
"->",
"deserialize",
"(",
"json_encode",
"(",
"$",
"data",
")",
",",
"$",
"this",
"->",
"getParameter",
"(",
"'sulu.model.redirect_route.class'",
")",
",",
"'json'",
")",
";",
"$",
"this",
"->",
"getRedirectRouteManager",
"(",
")",
"->",
"save",
"(",
"$",
"redirectRoute",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'doctrine.orm.entity_manager'",
")",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"$",
"redirectRoute",
")",
")",
";",
"}"
] |
Create a new redirect-route.
@param Request $request
@return Response
|
[
"Create",
"a",
"new",
"redirect",
"-",
"route",
"."
] |
913c501cced6c7db5fb96d4baf6cce4b884c65c6
|
https://github.com/sulu/SuluRedirectBundle/blob/913c501cced6c7db5fb96d4baf6cce4b884c65c6/Controller/RedirectRouteController.php#L81-L96
|
224,810
|
sulu/SuluRedirectBundle
|
Controller/RedirectRouteController.php
|
RedirectRouteController.getAction
|
public function getAction($id)
{
$entity = $this->getRedirectRouteRepository()->find($id);
if (!$entity) {
throw new EntityNotFoundException($this->getParameter('sulu.model.redirect_route.class'), $id);
}
return $this->handleView($this->view($entity));
}
|
php
|
public function getAction($id)
{
$entity = $this->getRedirectRouteRepository()->find($id);
if (!$entity) {
throw new EntityNotFoundException($this->getParameter('sulu.model.redirect_route.class'), $id);
}
return $this->handleView($this->view($entity));
}
|
[
"public",
"function",
"getAction",
"(",
"$",
"id",
")",
"{",
"$",
"entity",
"=",
"$",
"this",
"->",
"getRedirectRouteRepository",
"(",
")",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"entity",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'sulu.model.redirect_route.class'",
")",
",",
"$",
"id",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
"$",
"entity",
")",
")",
";",
"}"
] |
Returns single redirect-route.
@param string $id
@return Response
@throws EntityNotFoundException
|
[
"Returns",
"single",
"redirect",
"-",
"route",
"."
] |
913c501cced6c7db5fb96d4baf6cce4b884c65c6
|
https://github.com/sulu/SuluRedirectBundle/blob/913c501cced6c7db5fb96d4baf6cce4b884c65c6/Controller/RedirectRouteController.php#L107-L115
|
224,811
|
sulu/SuluRedirectBundle
|
Controller/RedirectRouteController.php
|
RedirectRouteController.deleteAction
|
public function deleteAction($id)
{
$redirectRoute = $this->getRedirectRouteRepository()->find($id);
if (!$redirectRoute) {
throw new EntityNotFoundException($this->getParameter('sulu.model.redirect_route.class'), $id);
}
$this->getRedirectRouteManager()->delete($redirectRoute);
$this->get('doctrine.orm.entity_manager')->flush();
return $this->handleView($this->view());
}
|
php
|
public function deleteAction($id)
{
$redirectRoute = $this->getRedirectRouteRepository()->find($id);
if (!$redirectRoute) {
throw new EntityNotFoundException($this->getParameter('sulu.model.redirect_route.class'), $id);
}
$this->getRedirectRouteManager()->delete($redirectRoute);
$this->get('doctrine.orm.entity_manager')->flush();
return $this->handleView($this->view());
}
|
[
"public",
"function",
"deleteAction",
"(",
"$",
"id",
")",
"{",
"$",
"redirectRoute",
"=",
"$",
"this",
"->",
"getRedirectRouteRepository",
"(",
")",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"redirectRoute",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'sulu.model.redirect_route.class'",
")",
",",
"$",
"id",
")",
";",
"}",
"$",
"this",
"->",
"getRedirectRouteManager",
"(",
")",
"->",
"delete",
"(",
"$",
"redirectRoute",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'doctrine.orm.entity_manager'",
")",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
")",
")",
";",
"}"
] |
Delete a redirect-route identified by id.
@param string $id
@return Response
@throws EntityNotFoundException
|
[
"Delete",
"a",
"redirect",
"-",
"route",
"identified",
"by",
"id",
"."
] |
913c501cced6c7db5fb96d4baf6cce4b884c65c6
|
https://github.com/sulu/SuluRedirectBundle/blob/913c501cced6c7db5fb96d4baf6cce4b884c65c6/Controller/RedirectRouteController.php#L152-L163
|
224,812
|
sulu/SuluRedirectBundle
|
Controller/RedirectRouteController.php
|
RedirectRouteController.cdeleteAction
|
public function cdeleteAction(Request $request)
{
$repository = $this->getRedirectRouteRepository();
$manager = $this->getRedirectRouteManager();
$ids = array_filter(explode(',', $request->query->get('ids', '')));
foreach ($ids as $id) {
$redirectRoute = $repository->find($id);
if (!$redirectRoute) {
continue;
}
$manager->delete($redirectRoute);
}
$this->get('doctrine.orm.entity_manager')->flush();
return $this->handleView($this->view());
}
|
php
|
public function cdeleteAction(Request $request)
{
$repository = $this->getRedirectRouteRepository();
$manager = $this->getRedirectRouteManager();
$ids = array_filter(explode(',', $request->query->get('ids', '')));
foreach ($ids as $id) {
$redirectRoute = $repository->find($id);
if (!$redirectRoute) {
continue;
}
$manager->delete($redirectRoute);
}
$this->get('doctrine.orm.entity_manager')->flush();
return $this->handleView($this->view());
}
|
[
"public",
"function",
"cdeleteAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"repository",
"=",
"$",
"this",
"->",
"getRedirectRouteRepository",
"(",
")",
";",
"$",
"manager",
"=",
"$",
"this",
"->",
"getRedirectRouteManager",
"(",
")",
";",
"$",
"ids",
"=",
"array_filter",
"(",
"explode",
"(",
"','",
",",
"$",
"request",
"->",
"query",
"->",
"get",
"(",
"'ids'",
",",
"''",
")",
")",
")",
";",
"foreach",
"(",
"$",
"ids",
"as",
"$",
"id",
")",
"{",
"$",
"redirectRoute",
"=",
"$",
"repository",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"redirectRoute",
")",
"{",
"continue",
";",
"}",
"$",
"manager",
"->",
"delete",
"(",
"$",
"redirectRoute",
")",
";",
"}",
"$",
"this",
"->",
"get",
"(",
"'doctrine.orm.entity_manager'",
")",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"this",
"->",
"view",
"(",
")",
")",
";",
"}"
] |
Delete a list of redirect-route identified by id.
@param Request $request
@return Response
|
[
"Delete",
"a",
"list",
"of",
"redirect",
"-",
"route",
"identified",
"by",
"id",
"."
] |
913c501cced6c7db5fb96d4baf6cce4b884c65c6
|
https://github.com/sulu/SuluRedirectBundle/blob/913c501cced6c7db5fb96d4baf6cce4b884c65c6/Controller/RedirectRouteController.php#L172-L190
|
224,813
|
sulu/SuluRedirectBundle
|
Import/FileImport.php
|
FileImport.importItem
|
private function importItem(array $item)
{
if (!$this->converter->supports($item)) {
throw new ConverterNotFoundException($item);
}
$entity = $this->converter->convert($item);
$this->writer->write($entity);
return $entity;
}
|
php
|
private function importItem(array $item)
{
if (!$this->converter->supports($item)) {
throw new ConverterNotFoundException($item);
}
$entity = $this->converter->convert($item);
$this->writer->write($entity);
return $entity;
}
|
[
"private",
"function",
"importItem",
"(",
"array",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"converter",
"->",
"supports",
"(",
"$",
"item",
")",
")",
"{",
"throw",
"new",
"ConverterNotFoundException",
"(",
"$",
"item",
")",
";",
"}",
"$",
"entity",
"=",
"$",
"this",
"->",
"converter",
"->",
"convert",
"(",
"$",
"item",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"write",
"(",
"$",
"entity",
")",
";",
"return",
"$",
"entity",
";",
"}"
] |
Import given item.
@param array $item
@return RedirectRouteInterface
@throws \Exception
|
[
"Import",
"given",
"item",
"."
] |
913c501cced6c7db5fb96d4baf6cce4b884c65c6
|
https://github.com/sulu/SuluRedirectBundle/blob/913c501cced6c7db5fb96d4baf6cce4b884c65c6/Import/FileImport.php#L88-L98
|
224,814
|
simplesamlphp/simplesamlphp-module-openid
|
lib/SessionStore.php
|
sspmod_openid_SessionStore.set
|
public function set($key, $value) {
assert('is_string($key)');
$session = SimpleSAML_Session::getSessionFromRequest();
$session->setData('openid.session', $key, $value);
}
|
php
|
public function set($key, $value) {
assert('is_string($key)');
$session = SimpleSAML_Session::getSessionFromRequest();
$session->setData('openid.session', $key, $value);
}
|
[
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"assert",
"(",
"'is_string($key)'",
")",
";",
"$",
"session",
"=",
"SimpleSAML_Session",
"::",
"getSessionFromRequest",
"(",
")",
";",
"$",
"session",
"->",
"setData",
"(",
"'openid.session'",
",",
"$",
"key",
",",
"$",
"value",
")",
";",
"}"
] |
Save a value to the session store under the given key.
@param string $key The key we should save.
@param mixed NULL $value The value we should save.
|
[
"Save",
"a",
"value",
"to",
"the",
"session",
"store",
"under",
"the",
"given",
"key",
"."
] |
f2256f9866fcd6561ff0ab41d1c810328a310f63
|
https://github.com/simplesamlphp/simplesamlphp-module-openid/blob/f2256f9866fcd6561ff0ab41d1c810328a310f63/lib/SessionStore.php#L33-L38
|
224,815
|
liip/LiipTranslationBundle
|
Repository/UnitRepository.php
|
UnitRepository.removeTranslation
|
public function removeTranslation($locale, $domain, $key)
{
$unit = $this->findByDomainAndKey($domain, $key);
$unit->deleteTranslation($locale);
$this->persist($unit);
}
|
php
|
public function removeTranslation($locale, $domain, $key)
{
$unit = $this->findByDomainAndKey($domain, $key);
$unit->deleteTranslation($locale);
$this->persist($unit);
}
|
[
"public",
"function",
"removeTranslation",
"(",
"$",
"locale",
",",
"$",
"domain",
",",
"$",
"key",
")",
"{",
"$",
"unit",
"=",
"$",
"this",
"->",
"findByDomainAndKey",
"(",
"$",
"domain",
",",
"$",
"key",
")",
";",
"$",
"unit",
"->",
"deleteTranslation",
"(",
"$",
"locale",
")",
";",
"$",
"this",
"->",
"persist",
"(",
"$",
"unit",
")",
";",
"}"
] |
Remove a specific translation.
@param string $locale
@param string $domain
@param string $key
|
[
"Remove",
"a",
"specific",
"translation",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Repository/UnitRepository.php#L320-L325
|
224,816
|
liip/LiipTranslationBundle
|
Repository/UnitRepository.php
|
UnitRepository.updateTranslation
|
public function updateTranslation($locale, $domain, $key, $value)
{
$unit = $this->findByDomainAndKey($domain, $key);
$unit->setTranslation($locale, $value);
$this->persist($unit);
}
|
php
|
public function updateTranslation($locale, $domain, $key, $value)
{
$unit = $this->findByDomainAndKey($domain, $key);
$unit->setTranslation($locale, $value);
$this->persist($unit);
}
|
[
"public",
"function",
"updateTranslation",
"(",
"$",
"locale",
",",
"$",
"domain",
",",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"unit",
"=",
"$",
"this",
"->",
"findByDomainAndKey",
"(",
"$",
"domain",
",",
"$",
"key",
")",
";",
"$",
"unit",
"->",
"setTranslation",
"(",
"$",
"locale",
",",
"$",
"value",
")",
";",
"$",
"this",
"->",
"persist",
"(",
"$",
"unit",
")",
";",
"}"
] |
Update a specific translation.
@param string $locale
@param string $domain
@param string $key
@param string $value
|
[
"Update",
"a",
"specific",
"translation",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Repository/UnitRepository.php#L335-L340
|
224,817
|
jasny/error-handler
|
src/ErrorHandler/HandleShutdownError.php
|
HandleShutdownError.initShutdownFunction
|
protected function initShutdownFunction()
{
if (!$this->registeredShutdown) {
$this->registerShutdownFunction([$this, 'shutdownFunction']) ?: false;
$this->registeredShutdown = true;
$this->reserveMemory();
}
}
|
php
|
protected function initShutdownFunction()
{
if (!$this->registeredShutdown) {
$this->registerShutdownFunction([$this, 'shutdownFunction']) ?: false;
$this->registeredShutdown = true;
$this->reserveMemory();
}
}
|
[
"protected",
"function",
"initShutdownFunction",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"registeredShutdown",
")",
"{",
"$",
"this",
"->",
"registerShutdownFunction",
"(",
"[",
"$",
"this",
",",
"'shutdownFunction'",
"]",
")",
"?",
":",
"false",
";",
"$",
"this",
"->",
"registeredShutdown",
"=",
"true",
";",
"$",
"this",
"->",
"reserveMemory",
"(",
")",
";",
"}",
"}"
] |
Register the shutdown function
|
[
"Register",
"the",
"shutdown",
"function"
] |
38e076fc36d86689010081bc2eab96f12d97b0d8
|
https://github.com/jasny/error-handler/blob/38e076fc36d86689010081bc2eab96f12d97b0d8/src/ErrorHandler/HandleShutdownError.php#L72-L80
|
224,818
|
jasny/error-handler
|
src/ErrorHandler/HandleShutdownError.php
|
HandleShutdownError.shutdownFunction
|
public function shutdownFunction()
{
$this->reservedMemory = null;
$err = $this->errorGetLast();
$unhandled = E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR;
if (empty($err) || !($err['type'] & $unhandled)) {
return;
}
$error = new \ErrorException($err['message'], 0, $err['type'], $err['file'], $err['line']);
if ($err['type'] & $this->getLoggedErrorTypes()) {
$this->log($error);
}
$this->callOnFatalError($error);
}
|
php
|
public function shutdownFunction()
{
$this->reservedMemory = null;
$err = $this->errorGetLast();
$unhandled = E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR;
if (empty($err) || !($err['type'] & $unhandled)) {
return;
}
$error = new \ErrorException($err['message'], 0, $err['type'], $err['file'], $err['line']);
if ($err['type'] & $this->getLoggedErrorTypes()) {
$this->log($error);
}
$this->callOnFatalError($error);
}
|
[
"public",
"function",
"shutdownFunction",
"(",
")",
"{",
"$",
"this",
"->",
"reservedMemory",
"=",
"null",
";",
"$",
"err",
"=",
"$",
"this",
"->",
"errorGetLast",
"(",
")",
";",
"$",
"unhandled",
"=",
"E_ERROR",
"|",
"E_PARSE",
"|",
"E_CORE_ERROR",
"|",
"E_COMPILE_ERROR",
";",
"if",
"(",
"empty",
"(",
"$",
"err",
")",
"||",
"!",
"(",
"$",
"err",
"[",
"'type'",
"]",
"&",
"$",
"unhandled",
")",
")",
"{",
"return",
";",
"}",
"$",
"error",
"=",
"new",
"\\",
"ErrorException",
"(",
"$",
"err",
"[",
"'message'",
"]",
",",
"0",
",",
"$",
"err",
"[",
"'type'",
"]",
",",
"$",
"err",
"[",
"'file'",
"]",
",",
"$",
"err",
"[",
"'line'",
"]",
")",
";",
"if",
"(",
"$",
"err",
"[",
"'type'",
"]",
"&",
"$",
"this",
"->",
"getLoggedErrorTypes",
"(",
")",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"$",
"error",
")",
";",
"}",
"$",
"this",
"->",
"callOnFatalError",
"(",
"$",
"error",
")",
";",
"}"
] |
Called when the script has ends
@ignore
|
[
"Called",
"when",
"the",
"script",
"has",
"ends"
] |
38e076fc36d86689010081bc2eab96f12d97b0d8
|
https://github.com/jasny/error-handler/blob/38e076fc36d86689010081bc2eab96f12d97b0d8/src/ErrorHandler/HandleShutdownError.php#L86-L104
|
224,819
|
liip/LiipTranslationBundle
|
Controller/BaseController.php
|
BaseController.securityCheck
|
public function securityCheck($domain = null, $locale = null)
{
if (isset($domain) && $this->getSecurity()->isSecuredByDomain()) {
if (!$this->getSecurityContext()->isGranted(Security::getRoleForDomain($domain))) {
throw new AccessDeniedHttpException("You don't have permissions to work on translations for domain [$domain]");
}
}
if (isset($locale) && $this->getSecurity()->isSecuredByLocale()) {
if (!$this->getSecurityContext()->isGranted(Security::getRoleForLocale($locale))) {
throw new AccessDeniedHttpException("You don't have permissions to work on translations for locale [$locale]");
}
}
}
|
php
|
public function securityCheck($domain = null, $locale = null)
{
if (isset($domain) && $this->getSecurity()->isSecuredByDomain()) {
if (!$this->getSecurityContext()->isGranted(Security::getRoleForDomain($domain))) {
throw new AccessDeniedHttpException("You don't have permissions to work on translations for domain [$domain]");
}
}
if (isset($locale) && $this->getSecurity()->isSecuredByLocale()) {
if (!$this->getSecurityContext()->isGranted(Security::getRoleForLocale($locale))) {
throw new AccessDeniedHttpException("You don't have permissions to work on translations for locale [$locale]");
}
}
}
|
[
"public",
"function",
"securityCheck",
"(",
"$",
"domain",
"=",
"null",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"domain",
")",
"&&",
"$",
"this",
"->",
"getSecurity",
"(",
")",
"->",
"isSecuredByDomain",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getSecurityContext",
"(",
")",
"->",
"isGranted",
"(",
"Security",
"::",
"getRoleForDomain",
"(",
"$",
"domain",
")",
")",
")",
"{",
"throw",
"new",
"AccessDeniedHttpException",
"(",
"\"You don't have permissions to work on translations for domain [$domain]\"",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"locale",
")",
"&&",
"$",
"this",
"->",
"getSecurity",
"(",
")",
"->",
"isSecuredByLocale",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getSecurityContext",
"(",
")",
"->",
"isGranted",
"(",
"Security",
"::",
"getRoleForLocale",
"(",
"$",
"locale",
")",
")",
")",
"{",
"throw",
"new",
"AccessDeniedHttpException",
"(",
"\"You don't have permissions to work on translations for locale [$locale]\"",
")",
";",
"}",
"}",
"}"
] |
Process security for the provided locale or domain. Either one of the both
parameters can be null if we don't need to check them.
@param string $domain domain to check for
@param string $locale locale to check for
@throws AccessDeniedHttpException
|
[
"Process",
"security",
"for",
"the",
"provided",
"locale",
"or",
"domain",
".",
"Either",
"one",
"of",
"the",
"both",
"parameters",
"can",
"be",
"null",
"if",
"we",
"don",
"t",
"need",
"to",
"check",
"them",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Controller/BaseController.php#L42-L55
|
224,820
|
jasny/error-handler
|
src/ErrorHandler/Middleware.php
|
Middleware.errorResponse
|
protected function errorResponse(ServerRequestInterface $request, ResponseInterface $response)
{
if (
interface_exists(GlobalEnvironmentInterface::class, false) &&
$response instanceof GlobalEnvironmentInterface &&
$response->isStale()
) {
$response = $response->revive();
}
$errorResponse = $response->withProtocolVersion($request->getProtocolVersion())->withStatus(500);
$errorResponse->getBody()->write('An unexpected error occured');
return $errorResponse;
}
|
php
|
protected function errorResponse(ServerRequestInterface $request, ResponseInterface $response)
{
if (
interface_exists(GlobalEnvironmentInterface::class, false) &&
$response instanceof GlobalEnvironmentInterface &&
$response->isStale()
) {
$response = $response->revive();
}
$errorResponse = $response->withProtocolVersion($request->getProtocolVersion())->withStatus(500);
$errorResponse->getBody()->write('An unexpected error occured');
return $errorResponse;
}
|
[
"protected",
"function",
"errorResponse",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"if",
"(",
"interface_exists",
"(",
"GlobalEnvironmentInterface",
"::",
"class",
",",
"false",
")",
"&&",
"$",
"response",
"instanceof",
"GlobalEnvironmentInterface",
"&&",
"$",
"response",
"->",
"isStale",
"(",
")",
")",
"{",
"$",
"response",
"=",
"$",
"response",
"->",
"revive",
"(",
")",
";",
"}",
"$",
"errorResponse",
"=",
"$",
"response",
"->",
"withProtocolVersion",
"(",
"$",
"request",
"->",
"getProtocolVersion",
"(",
")",
")",
"->",
"withStatus",
"(",
"500",
")",
";",
"$",
"errorResponse",
"->",
"getBody",
"(",
")",
"->",
"write",
"(",
"'An unexpected error occured'",
")",
";",
"return",
"$",
"errorResponse",
";",
"}"
] |
Handle caught error
@param ServerRequestInterface $request
@param ResponseInterface $response
@return ResponseInterface
|
[
"Handle",
"caught",
"error"
] |
38e076fc36d86689010081bc2eab96f12d97b0d8
|
https://github.com/jasny/error-handler/blob/38e076fc36d86689010081bc2eab96f12d97b0d8/src/ErrorHandler/Middleware.php#L70-L84
|
224,821
|
jasny/error-handler
|
src/ErrorHandler/ErrorCodes.php
|
ErrorCodes.getLogLevel
|
protected function getLogLevel($code = null)
{
switch ($code) {
case E_STRICT:
case E_DEPRECATED:
case E_USER_DEPRECATED:
return LogLevel::INFO;
case E_NOTICE:
case E_USER_NOTICE:
return LogLevel::NOTICE;
case E_WARNING:
case E_CORE_WARNING:
case E_COMPILE_WARNING:
case E_USER_WARNING:
return LogLevel::WARNING;
case E_PARSE:
case E_CORE_ERROR:
case E_COMPILE_ERROR:
return LogLevel::CRITICAL;
default:
return LogLevel::ERROR;
}
}
|
php
|
protected function getLogLevel($code = null)
{
switch ($code) {
case E_STRICT:
case E_DEPRECATED:
case E_USER_DEPRECATED:
return LogLevel::INFO;
case E_NOTICE:
case E_USER_NOTICE:
return LogLevel::NOTICE;
case E_WARNING:
case E_CORE_WARNING:
case E_COMPILE_WARNING:
case E_USER_WARNING:
return LogLevel::WARNING;
case E_PARSE:
case E_CORE_ERROR:
case E_COMPILE_ERROR:
return LogLevel::CRITICAL;
default:
return LogLevel::ERROR;
}
}
|
[
"protected",
"function",
"getLogLevel",
"(",
"$",
"code",
"=",
"null",
")",
"{",
"switch",
"(",
"$",
"code",
")",
"{",
"case",
"E_STRICT",
":",
"case",
"E_DEPRECATED",
":",
"case",
"E_USER_DEPRECATED",
":",
"return",
"LogLevel",
"::",
"INFO",
";",
"case",
"E_NOTICE",
":",
"case",
"E_USER_NOTICE",
":",
"return",
"LogLevel",
"::",
"NOTICE",
";",
"case",
"E_WARNING",
":",
"case",
"E_CORE_WARNING",
":",
"case",
"E_COMPILE_WARNING",
":",
"case",
"E_USER_WARNING",
":",
"return",
"LogLevel",
"::",
"WARNING",
";",
"case",
"E_PARSE",
":",
"case",
"E_CORE_ERROR",
":",
"case",
"E_COMPILE_ERROR",
":",
"return",
"LogLevel",
"::",
"CRITICAL",
";",
"default",
":",
"return",
"LogLevel",
"::",
"ERROR",
";",
"}",
"}"
] |
Get the log level for an error code
@param int $code E_* error code
@return string
|
[
"Get",
"the",
"log",
"level",
"for",
"an",
"error",
"code"
] |
38e076fc36d86689010081bc2eab96f12d97b0d8
|
https://github.com/jasny/error-handler/blob/38e076fc36d86689010081bc2eab96f12d97b0d8/src/ErrorHandler/ErrorCodes.php#L18-L44
|
224,822
|
Crinsane/LaravelNotify
|
src/Notifications/Notification.php
|
Notification.add
|
public function add($type, $message, $title = null)
{
$notifications = $this->getNotifications();
$notifications[] = [
'type' => $type,
'message' => $message,
'title' => $title
];
$this->session->flash(self::SESSION_KEY, $notifications);
}
|
php
|
public function add($type, $message, $title = null)
{
$notifications = $this->getNotifications();
$notifications[] = [
'type' => $type,
'message' => $message,
'title' => $title
];
$this->session->flash(self::SESSION_KEY, $notifications);
}
|
[
"public",
"function",
"add",
"(",
"$",
"type",
",",
"$",
"message",
",",
"$",
"title",
"=",
"null",
")",
"{",
"$",
"notifications",
"=",
"$",
"this",
"->",
"getNotifications",
"(",
")",
";",
"$",
"notifications",
"[",
"]",
"=",
"[",
"'type'",
"=>",
"$",
"type",
",",
"'message'",
"=>",
"$",
"message",
",",
"'title'",
"=>",
"$",
"title",
"]",
";",
"$",
"this",
"->",
"session",
"->",
"flash",
"(",
"self",
"::",
"SESSION_KEY",
",",
"$",
"notifications",
")",
";",
"}"
] |
Add a new notification to the session
@param string $type
@param string $message
@param null $title
@return void
|
[
"Add",
"a",
"new",
"notification",
"to",
"the",
"session"
] |
5064482018534abdb4483b9a08f86fa3ac735efd
|
https://github.com/Crinsane/LaravelNotify/blob/5064482018534abdb4483b9a08f86fa3ac735efd/src/Notifications/Notification.php#L60-L71
|
224,823
|
liip/LiipTranslationBundle
|
Model/Unit.php
|
Unit.setTranslation
|
public function setTranslation($locale, $translation, $isUpdate = true)
{
$this->offsetSet($locale, $translation);
if ($isUpdate) {
$this->setIsModified(true);
}
}
|
php
|
public function setTranslation($locale, $translation, $isUpdate = true)
{
$this->offsetSet($locale, $translation);
if ($isUpdate) {
$this->setIsModified(true);
}
}
|
[
"public",
"function",
"setTranslation",
"(",
"$",
"locale",
",",
"$",
"translation",
",",
"$",
"isUpdate",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"offsetSet",
"(",
"$",
"locale",
",",
"$",
"translation",
")",
";",
"if",
"(",
"$",
"isUpdate",
")",
"{",
"$",
"this",
"->",
"setIsModified",
"(",
"true",
")",
";",
"}",
"}"
] |
Set a translation for the given locale without caring if
the translation already exists or not.
@param string $locale the locale
@param string $translation the translation (value)
@param bool $isUpdate
|
[
"Set",
"a",
"translation",
"for",
"the",
"given",
"locale",
"without",
"caring",
"if",
"the",
"translation",
"already",
"exists",
"or",
"not",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Model/Unit.php#L75-L81
|
224,824
|
liip/LiipTranslationBundle
|
Model/Unit.php
|
Unit.addTranslation
|
public function addTranslation(Translation $translation, $isUpdate = true)
{
$this->translations[$translation->getLocale()] = $translation;
if ($isUpdate) {
$this->setIsModified(true);
}
}
|
php
|
public function addTranslation(Translation $translation, $isUpdate = true)
{
$this->translations[$translation->getLocale()] = $translation;
if ($isUpdate) {
$this->setIsModified(true);
}
}
|
[
"public",
"function",
"addTranslation",
"(",
"Translation",
"$",
"translation",
",",
"$",
"isUpdate",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"translations",
"[",
"$",
"translation",
"->",
"getLocale",
"(",
")",
"]",
"=",
"$",
"translation",
";",
"if",
"(",
"$",
"isUpdate",
")",
"{",
"$",
"this",
"->",
"setIsModified",
"(",
"true",
")",
";",
"}",
"}"
] |
Add or set the translation for the locale associated to the
given translation.
@param Translation $translation
|
[
"Add",
"or",
"set",
"the",
"translation",
"for",
"the",
"locale",
"associated",
"to",
"the",
"given",
"translation",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Model/Unit.php#L89-L95
|
224,825
|
liip/LiipTranslationBundle
|
Import/SessionImporter.php
|
SessionImporter.extractZip
|
protected function extractZip($file)
{
$tempFolder = sys_get_temp_dir().'/'.md5(rand(0, 99999));
if (@mkdir($tempFolder) === false) {
throw new ImportException('Impossible to create a temp folder for zip extraction');
}
$zip = new \ZipArchive();
$zip->open($file->getRealPath());
$zip->extractTo($tempFolder);
$zip->close();
return $tempFolder;
}
|
php
|
protected function extractZip($file)
{
$tempFolder = sys_get_temp_dir().'/'.md5(rand(0, 99999));
if (@mkdir($tempFolder) === false) {
throw new ImportException('Impossible to create a temp folder for zip extraction');
}
$zip = new \ZipArchive();
$zip->open($file->getRealPath());
$zip->extractTo($tempFolder);
$zip->close();
return $tempFolder;
}
|
[
"protected",
"function",
"extractZip",
"(",
"$",
"file",
")",
"{",
"$",
"tempFolder",
"=",
"sys_get_temp_dir",
"(",
")",
".",
"'/'",
".",
"md5",
"(",
"rand",
"(",
"0",
",",
"99999",
")",
")",
";",
"if",
"(",
"@",
"mkdir",
"(",
"$",
"tempFolder",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"ImportException",
"(",
"'Impossible to create a temp folder for zip extraction'",
")",
";",
"}",
"$",
"zip",
"=",
"new",
"\\",
"ZipArchive",
"(",
")",
";",
"$",
"zip",
"->",
"open",
"(",
"$",
"file",
"->",
"getRealPath",
"(",
")",
")",
";",
"$",
"zip",
"->",
"extractTo",
"(",
"$",
"tempFolder",
")",
";",
"$",
"zip",
"->",
"close",
"(",
")",
";",
"return",
"$",
"tempFolder",
";",
"}"
] |
Extract a zip file into a temp folder and return the folder path.
@param UploadedFile $file
@return string The path to the temp folder
@throws ImportException
|
[
"Extract",
"a",
"zip",
"file",
"into",
"a",
"temp",
"folder",
"and",
"return",
"the",
"folder",
"path",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Import/SessionImporter.php#L88-L100
|
224,826
|
liip/LiipTranslationBundle
|
Import/SessionImporter.php
|
SessionImporter.importFile
|
protected function importFile($filePath, $fileName = null)
{
// Filename parsing
if ($fileName == null) {
$fileName = basename($filePath);
}
if (!preg_match('/\w+\.\w+\.\w+/', $fileName)) {
throw new ImportException("Invalid filename [$fileName], all translation files must be named: domain.locale.format (ex: messages.en.yml)");
}
list($domain, $locale, $format) = explode('.', $fileName, 3);
$catalogue = $this->translator->loadResource(array(
'format' => $format,
'locale' => $locale,
'domain' => $domain,
'path' => $filePath,
));
// Merge with existing entries
$translations = $this->getTranslationsFromSession();
$counters = array('new' => 0, 'updated' => 0);
if (!array_key_exists($locale, $translations)) {
$translations[$locale] = array('new' => array(), 'updated' => array());
}
foreach ($catalogue->all() as $domain => $messages) {
foreach ($messages as $key => $value) {
if ($trans = $this->repository->findTranslation($domain, $key, $locale, true)) {
if ($trans->getValue() !== $value) {
$translations[$locale]['updated'][$domain][$key] = array('old' => $trans->getValue(), 'new' => $value);
$counters['updated'] += 1;
}
} else {
$translations[$locale]['new'][$domain][$key] = $value;
$counters['new'] += 1;
}
}
}
$this->updateSession($translations);
return $counters;
}
|
php
|
protected function importFile($filePath, $fileName = null)
{
// Filename parsing
if ($fileName == null) {
$fileName = basename($filePath);
}
if (!preg_match('/\w+\.\w+\.\w+/', $fileName)) {
throw new ImportException("Invalid filename [$fileName], all translation files must be named: domain.locale.format (ex: messages.en.yml)");
}
list($domain, $locale, $format) = explode('.', $fileName, 3);
$catalogue = $this->translator->loadResource(array(
'format' => $format,
'locale' => $locale,
'domain' => $domain,
'path' => $filePath,
));
// Merge with existing entries
$translations = $this->getTranslationsFromSession();
$counters = array('new' => 0, 'updated' => 0);
if (!array_key_exists($locale, $translations)) {
$translations[$locale] = array('new' => array(), 'updated' => array());
}
foreach ($catalogue->all() as $domain => $messages) {
foreach ($messages as $key => $value) {
if ($trans = $this->repository->findTranslation($domain, $key, $locale, true)) {
if ($trans->getValue() !== $value) {
$translations[$locale]['updated'][$domain][$key] = array('old' => $trans->getValue(), 'new' => $value);
$counters['updated'] += 1;
}
} else {
$translations[$locale]['new'][$domain][$key] = $value;
$counters['new'] += 1;
}
}
}
$this->updateSession($translations);
return $counters;
}
|
[
"protected",
"function",
"importFile",
"(",
"$",
"filePath",
",",
"$",
"fileName",
"=",
"null",
")",
"{",
"// Filename parsing",
"if",
"(",
"$",
"fileName",
"==",
"null",
")",
"{",
"$",
"fileName",
"=",
"basename",
"(",
"$",
"filePath",
")",
";",
"}",
"if",
"(",
"!",
"preg_match",
"(",
"'/\\w+\\.\\w+\\.\\w+/'",
",",
"$",
"fileName",
")",
")",
"{",
"throw",
"new",
"ImportException",
"(",
"\"Invalid filename [$fileName], all translation files must be named: domain.locale.format (ex: messages.en.yml)\"",
")",
";",
"}",
"list",
"(",
"$",
"domain",
",",
"$",
"locale",
",",
"$",
"format",
")",
"=",
"explode",
"(",
"'.'",
",",
"$",
"fileName",
",",
"3",
")",
";",
"$",
"catalogue",
"=",
"$",
"this",
"->",
"translator",
"->",
"loadResource",
"(",
"array",
"(",
"'format'",
"=>",
"$",
"format",
",",
"'locale'",
"=>",
"$",
"locale",
",",
"'domain'",
"=>",
"$",
"domain",
",",
"'path'",
"=>",
"$",
"filePath",
",",
")",
")",
";",
"// Merge with existing entries",
"$",
"translations",
"=",
"$",
"this",
"->",
"getTranslationsFromSession",
"(",
")",
";",
"$",
"counters",
"=",
"array",
"(",
"'new'",
"=>",
"0",
",",
"'updated'",
"=>",
"0",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"locale",
",",
"$",
"translations",
")",
")",
"{",
"$",
"translations",
"[",
"$",
"locale",
"]",
"=",
"array",
"(",
"'new'",
"=>",
"array",
"(",
")",
",",
"'updated'",
"=>",
"array",
"(",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"catalogue",
"->",
"all",
"(",
")",
"as",
"$",
"domain",
"=>",
"$",
"messages",
")",
"{",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"trans",
"=",
"$",
"this",
"->",
"repository",
"->",
"findTranslation",
"(",
"$",
"domain",
",",
"$",
"key",
",",
"$",
"locale",
",",
"true",
")",
")",
"{",
"if",
"(",
"$",
"trans",
"->",
"getValue",
"(",
")",
"!==",
"$",
"value",
")",
"{",
"$",
"translations",
"[",
"$",
"locale",
"]",
"[",
"'updated'",
"]",
"[",
"$",
"domain",
"]",
"[",
"$",
"key",
"]",
"=",
"array",
"(",
"'old'",
"=>",
"$",
"trans",
"->",
"getValue",
"(",
")",
",",
"'new'",
"=>",
"$",
"value",
")",
";",
"$",
"counters",
"[",
"'updated'",
"]",
"+=",
"1",
";",
"}",
"}",
"else",
"{",
"$",
"translations",
"[",
"$",
"locale",
"]",
"[",
"'new'",
"]",
"[",
"$",
"domain",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"$",
"counters",
"[",
"'new'",
"]",
"+=",
"1",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"updateSession",
"(",
"$",
"translations",
")",
";",
"return",
"$",
"counters",
";",
"}"
] |
Add a file to the current import buffer.
@param string $filePath The path to the file
@param string $fileName Optional, the filename to parse to extract resources data
@return array
@throws ImportException
|
[
"Add",
"a",
"file",
"to",
"the",
"current",
"import",
"buffer",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Import/SessionImporter.php#L112-L152
|
224,827
|
liip/LiipTranslationBundle
|
Command/GitPersistenceAwareCommand.php
|
GitPersistenceAwareCommand.getPersistence
|
public function getPersistence()
{
$persistence = $this->getContainer()->get('liip.translation.persistence');
if (false === $persistence instanceof GitPersistence) {
throw new \RuntimeException(sprintf(
'Cannot initialize git repository, configured persistence should be "%s", "%s" given',
'Liip\TranslationBundle\Persistence\GitPersistence',
get_class($persistence)
));
}
return $persistence;
}
|
php
|
public function getPersistence()
{
$persistence = $this->getContainer()->get('liip.translation.persistence');
if (false === $persistence instanceof GitPersistence) {
throw new \RuntimeException(sprintf(
'Cannot initialize git repository, configured persistence should be "%s", "%s" given',
'Liip\TranslationBundle\Persistence\GitPersistence',
get_class($persistence)
));
}
return $persistence;
}
|
[
"public",
"function",
"getPersistence",
"(",
")",
"{",
"$",
"persistence",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'liip.translation.persistence'",
")",
";",
"if",
"(",
"false",
"===",
"$",
"persistence",
"instanceof",
"GitPersistence",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Cannot initialize git repository, configured persistence should be \"%s\", \"%s\" given'",
",",
"'Liip\\TranslationBundle\\Persistence\\GitPersistence'",
",",
"get_class",
"(",
"$",
"persistence",
")",
")",
")",
";",
"}",
"return",
"$",
"persistence",
";",
"}"
] |
Returns the configured repository, which should be a GitPersistence.
@return GitPersistence
@throws \RuntimeException
|
[
"Returns",
"the",
"configured",
"repository",
"which",
"should",
"be",
"a",
"GitPersistence",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Command/GitPersistenceAwareCommand.php#L29-L42
|
224,828
|
liip/LiipTranslationBundle
|
Persistence/GitPersistence.php
|
GitPersistence.cloneRepository
|
public function cloneRepository($remote)
{
$fileSystem = new Filesystem();
$fileSystem->mkdir($this->directory);
if ($fileSystem->exists($this->directory.DIRECTORY_SEPARATOR.'.git')) {
throw new \RuntimeException(sprintf('"%s" already is a git repository.', $this->directory));
}
return $this->executeCmd(sprintf(
self::CMD_GITCLONE,
$remote,
$this->directory
));
}
|
php
|
public function cloneRepository($remote)
{
$fileSystem = new Filesystem();
$fileSystem->mkdir($this->directory);
if ($fileSystem->exists($this->directory.DIRECTORY_SEPARATOR.'.git')) {
throw new \RuntimeException(sprintf('"%s" already is a git repository.', $this->directory));
}
return $this->executeCmd(sprintf(
self::CMD_GITCLONE,
$remote,
$this->directory
));
}
|
[
"public",
"function",
"cloneRepository",
"(",
"$",
"remote",
")",
"{",
"$",
"fileSystem",
"=",
"new",
"Filesystem",
"(",
")",
";",
"$",
"fileSystem",
"->",
"mkdir",
"(",
"$",
"this",
"->",
"directory",
")",
";",
"if",
"(",
"$",
"fileSystem",
"->",
"exists",
"(",
"$",
"this",
"->",
"directory",
".",
"DIRECTORY_SEPARATOR",
".",
"'.git'",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'\"%s\" already is a git repository.'",
",",
"$",
"this",
"->",
"directory",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"executeCmd",
"(",
"sprintf",
"(",
"self",
"::",
"CMD_GITCLONE",
",",
"$",
"remote",
",",
"$",
"this",
"->",
"directory",
")",
")",
";",
"}"
] |
Clones a given remote.
@param string $remote
@return bool
@throws \RuntimeException
|
[
"Clones",
"a",
"given",
"remote",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Persistence/GitPersistence.php#L136-L150
|
224,829
|
liip/LiipTranslationBundle
|
Persistence/GitPersistence.php
|
GitPersistence.executeCmd
|
protected function executeCmd($command)
{
$process = new $this->processClass($command);
$process->run();
if (false === $process->isSuccessful() && strlen($process->getErrorOutput()) > 0) {
throw new \RuntimeException($process->getErrorOutput());
}
return $process->getOutput();
}
|
php
|
protected function executeCmd($command)
{
$process = new $this->processClass($command);
$process->run();
if (false === $process->isSuccessful() && strlen($process->getErrorOutput()) > 0) {
throw new \RuntimeException($process->getErrorOutput());
}
return $process->getOutput();
}
|
[
"protected",
"function",
"executeCmd",
"(",
"$",
"command",
")",
"{",
"$",
"process",
"=",
"new",
"$",
"this",
"->",
"processClass",
"(",
"$",
"command",
")",
";",
"$",
"process",
"->",
"run",
"(",
")",
";",
"if",
"(",
"false",
"===",
"$",
"process",
"->",
"isSuccessful",
"(",
")",
"&&",
"strlen",
"(",
"$",
"process",
"->",
"getErrorOutput",
"(",
")",
")",
">",
"0",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"$",
"process",
"->",
"getErrorOutput",
"(",
")",
")",
";",
"}",
"return",
"$",
"process",
"->",
"getOutput",
"(",
")",
";",
"}"
] |
Executes a given command on the shell.
@param string $command
@return bool
@throws \RuntimeException
|
[
"Executes",
"a",
"given",
"command",
"on",
"the",
"shell",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Persistence/GitPersistence.php#L193-L203
|
224,830
|
liip/LiipTranslationBundle
|
Persistence/GitPersistence.php
|
GitPersistence.getResolvedOptions
|
protected function getResolvedOptions(array $options)
{
$resolver = new OptionsResolver();
$resolver->setDefaults(array(
'processClass' => 'Symfony\\Component\\Process\\Process',
))
->setRequired(array('folder'))
->setAllowedTypes(array(
'processClass' => 'string',
'folder' => 'string',
))
;
return $resolver->resolve($options);
}
|
php
|
protected function getResolvedOptions(array $options)
{
$resolver = new OptionsResolver();
$resolver->setDefaults(array(
'processClass' => 'Symfony\\Component\\Process\\Process',
))
->setRequired(array('folder'))
->setAllowedTypes(array(
'processClass' => 'string',
'folder' => 'string',
))
;
return $resolver->resolve($options);
}
|
[
"protected",
"function",
"getResolvedOptions",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"resolver",
"=",
"new",
"OptionsResolver",
"(",
")",
";",
"$",
"resolver",
"->",
"setDefaults",
"(",
"array",
"(",
"'processClass'",
"=>",
"'Symfony\\\\Component\\\\Process\\\\Process'",
",",
")",
")",
"->",
"setRequired",
"(",
"array",
"(",
"'folder'",
")",
")",
"->",
"setAllowedTypes",
"(",
"array",
"(",
"'processClass'",
"=>",
"'string'",
",",
"'folder'",
"=>",
"'string'",
",",
")",
")",
";",
"return",
"$",
"resolver",
"->",
"resolve",
"(",
"$",
"options",
")",
";",
"}"
] |
Get a set of usable options.
@param array $options
@return array
|
[
"Get",
"a",
"set",
"of",
"usable",
"options",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Persistence/GitPersistence.php#L212-L226
|
224,831
|
adrotec/breeze.server.php
|
src/Adrotec/BreezeJs/CallbackExpressionProvider.php
|
CallbackExpressionProvider.onLogicalExpression
|
public function onLogicalExpression($expressionType, $left, $right) {
switch ($expressionType) {
case ExpressionType::AND_LOGICAL:
// return '$logicalAnd('.$left.', '.$right.')';
return $this->_prepareBinaryExpression(self::LOGICAL_AND, $left, $right);
break;
case ExpressionType::OR_LOGICAL:
// return '$logicalOr('.$left.', '.$right.')';
return $this->_prepareBinaryExpression(self::LOGICAL_OR, $left, $right);
break;
default:
throw new \InvalidArgumentException('onLogicalExpression');
}
}
|
php
|
public function onLogicalExpression($expressionType, $left, $right) {
switch ($expressionType) {
case ExpressionType::AND_LOGICAL:
// return '$logicalAnd('.$left.', '.$right.')';
return $this->_prepareBinaryExpression(self::LOGICAL_AND, $left, $right);
break;
case ExpressionType::OR_LOGICAL:
// return '$logicalOr('.$left.', '.$right.')';
return $this->_prepareBinaryExpression(self::LOGICAL_OR, $left, $right);
break;
default:
throw new \InvalidArgumentException('onLogicalExpression');
}
}
|
[
"public",
"function",
"onLogicalExpression",
"(",
"$",
"expressionType",
",",
"$",
"left",
",",
"$",
"right",
")",
"{",
"switch",
"(",
"$",
"expressionType",
")",
"{",
"case",
"ExpressionType",
"::",
"AND_LOGICAL",
":",
"//\t\t\t\treturn '$logicalAnd('.$left.', '.$right.')';",
"return",
"$",
"this",
"->",
"_prepareBinaryExpression",
"(",
"self",
"::",
"LOGICAL_AND",
",",
"$",
"left",
",",
"$",
"right",
")",
";",
"break",
";",
"case",
"ExpressionType",
"::",
"OR_LOGICAL",
":",
"//\t\t\t\treturn '$logicalOr('.$left.', '.$right.')';",
"return",
"$",
"this",
"->",
"_prepareBinaryExpression",
"(",
"self",
"::",
"LOGICAL_OR",
",",
"$",
"left",
",",
"$",
"right",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'onLogicalExpression'",
")",
";",
"}",
"}"
] |
Call-back for logical expression
@param ExpressionType $expressionType The type of logical expression.
@param string $left The left expression.
@param string $right The left expression.
@return string
|
[
"Call",
"-",
"back",
"for",
"logical",
"expression"
] |
0c29d7121b303e00e01588804821e760787dff0c
|
https://github.com/adrotec/breeze.server.php/blob/0c29d7121b303e00e01588804821e760787dff0c/src/Adrotec/BreezeJs/CallbackExpressionProvider.php#L110-L123
|
224,832
|
adrotec/breeze.server.php
|
src/Adrotec/BreezeJs/CallbackExpressionProvider.php
|
CallbackExpressionProvider.onArithmeticExpression
|
public function onArithmeticExpression($expressionType, $left, $right) {
switch ($expressionType) {
case ExpressionType::MULTIPLY:
return $this->_prepareBinaryExpression(self::MULTIPLY, $left, $right);
break;
case ExpressionType::DIVIDE:
return $this->_prepareBinaryExpression(self::DIVIDE, $left, $right);
break;
case ExpressionType::MODULO:
return $this->_prepareBinaryExpression(self::MODULO, $left, $right);
break;
case ExpressionType::ADD:
return $this->_prepareBinaryExpression(self::ADD, $left, $right);
break;
case ExpressionType::SUBTRACT:
return $this->_prepareBinaryExpression(self::SUBTRACT, $left, $right);
break;
default:
throw new \InvalidArgumentException('onArithmeticExpression');
}
}
|
php
|
public function onArithmeticExpression($expressionType, $left, $right) {
switch ($expressionType) {
case ExpressionType::MULTIPLY:
return $this->_prepareBinaryExpression(self::MULTIPLY, $left, $right);
break;
case ExpressionType::DIVIDE:
return $this->_prepareBinaryExpression(self::DIVIDE, $left, $right);
break;
case ExpressionType::MODULO:
return $this->_prepareBinaryExpression(self::MODULO, $left, $right);
break;
case ExpressionType::ADD:
return $this->_prepareBinaryExpression(self::ADD, $left, $right);
break;
case ExpressionType::SUBTRACT:
return $this->_prepareBinaryExpression(self::SUBTRACT, $left, $right);
break;
default:
throw new \InvalidArgumentException('onArithmeticExpression');
}
}
|
[
"public",
"function",
"onArithmeticExpression",
"(",
"$",
"expressionType",
",",
"$",
"left",
",",
"$",
"right",
")",
"{",
"switch",
"(",
"$",
"expressionType",
")",
"{",
"case",
"ExpressionType",
"::",
"MULTIPLY",
":",
"return",
"$",
"this",
"->",
"_prepareBinaryExpression",
"(",
"self",
"::",
"MULTIPLY",
",",
"$",
"left",
",",
"$",
"right",
")",
";",
"break",
";",
"case",
"ExpressionType",
"::",
"DIVIDE",
":",
"return",
"$",
"this",
"->",
"_prepareBinaryExpression",
"(",
"self",
"::",
"DIVIDE",
",",
"$",
"left",
",",
"$",
"right",
")",
";",
"break",
";",
"case",
"ExpressionType",
"::",
"MODULO",
":",
"return",
"$",
"this",
"->",
"_prepareBinaryExpression",
"(",
"self",
"::",
"MODULO",
",",
"$",
"left",
",",
"$",
"right",
")",
";",
"break",
";",
"case",
"ExpressionType",
"::",
"ADD",
":",
"return",
"$",
"this",
"->",
"_prepareBinaryExpression",
"(",
"self",
"::",
"ADD",
",",
"$",
"left",
",",
"$",
"right",
")",
";",
"break",
";",
"case",
"ExpressionType",
"::",
"SUBTRACT",
":",
"return",
"$",
"this",
"->",
"_prepareBinaryExpression",
"(",
"self",
"::",
"SUBTRACT",
",",
"$",
"left",
",",
"$",
"right",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'onArithmeticExpression'",
")",
";",
"}",
"}"
] |
Call-back for arithmetic expression
@param ExpressionType $expressionType The type of arithmetic expression.
@param string $left The left expression.
@param string $right The left expression.
@return string
|
[
"Call",
"-",
"back",
"for",
"arithmetic",
"expression"
] |
0c29d7121b303e00e01588804821e760787dff0c
|
https://github.com/adrotec/breeze.server.php/blob/0c29d7121b303e00e01588804821e760787dff0c/src/Adrotec/BreezeJs/CallbackExpressionProvider.php#L134-L154
|
224,833
|
adrotec/breeze.server.php
|
src/Adrotec/BreezeJs/CallbackExpressionProvider.php
|
CallbackExpressionProvider.onRelationalExpression
|
public function onRelationalExpression($expressionType, $left, $right) {
switch ($expressionType) {
case ExpressionType::GREATERTHAN:
return $this->_prepareBinaryExpression(self::GREATERTHAN, $left, $right);
break;
case ExpressionType::GREATERTHAN_OR_EQUAL:
return $this->_prepareBinaryExpression(
self::GREATERTHAN_OR_EQUAL, $left, $right
);
break;
case ExpressionType::LESSTHAN:
return $this->_prepareBinaryExpression(self::LESSTHAN, $left, $right);
break;
case ExpressionType::LESSTHAN_OR_EQUAL:
return $this->_prepareBinaryExpression(
self::LESSTHAN_OR_EQUAL, $left, $right
);
break;
case ExpressionType::EQUAL:
return $this->_prepareBinaryExpression(self::EQUAL, $left, $right);
break;
case ExpressionType::NOTEQUAL:
return $this->_prepareBinaryExpression(self::NOTEQUAL, $left, $right);
break;
default:
throw new \InvalidArgumentException('onArithmeticExpression');
}
}
|
php
|
public function onRelationalExpression($expressionType, $left, $right) {
switch ($expressionType) {
case ExpressionType::GREATERTHAN:
return $this->_prepareBinaryExpression(self::GREATERTHAN, $left, $right);
break;
case ExpressionType::GREATERTHAN_OR_EQUAL:
return $this->_prepareBinaryExpression(
self::GREATERTHAN_OR_EQUAL, $left, $right
);
break;
case ExpressionType::LESSTHAN:
return $this->_prepareBinaryExpression(self::LESSTHAN, $left, $right);
break;
case ExpressionType::LESSTHAN_OR_EQUAL:
return $this->_prepareBinaryExpression(
self::LESSTHAN_OR_EQUAL, $left, $right
);
break;
case ExpressionType::EQUAL:
return $this->_prepareBinaryExpression(self::EQUAL, $left, $right);
break;
case ExpressionType::NOTEQUAL:
return $this->_prepareBinaryExpression(self::NOTEQUAL, $left, $right);
break;
default:
throw new \InvalidArgumentException('onArithmeticExpression');
}
}
|
[
"public",
"function",
"onRelationalExpression",
"(",
"$",
"expressionType",
",",
"$",
"left",
",",
"$",
"right",
")",
"{",
"switch",
"(",
"$",
"expressionType",
")",
"{",
"case",
"ExpressionType",
"::",
"GREATERTHAN",
":",
"return",
"$",
"this",
"->",
"_prepareBinaryExpression",
"(",
"self",
"::",
"GREATERTHAN",
",",
"$",
"left",
",",
"$",
"right",
")",
";",
"break",
";",
"case",
"ExpressionType",
"::",
"GREATERTHAN_OR_EQUAL",
":",
"return",
"$",
"this",
"->",
"_prepareBinaryExpression",
"(",
"self",
"::",
"GREATERTHAN_OR_EQUAL",
",",
"$",
"left",
",",
"$",
"right",
")",
";",
"break",
";",
"case",
"ExpressionType",
"::",
"LESSTHAN",
":",
"return",
"$",
"this",
"->",
"_prepareBinaryExpression",
"(",
"self",
"::",
"LESSTHAN",
",",
"$",
"left",
",",
"$",
"right",
")",
";",
"break",
";",
"case",
"ExpressionType",
"::",
"LESSTHAN_OR_EQUAL",
":",
"return",
"$",
"this",
"->",
"_prepareBinaryExpression",
"(",
"self",
"::",
"LESSTHAN_OR_EQUAL",
",",
"$",
"left",
",",
"$",
"right",
")",
";",
"break",
";",
"case",
"ExpressionType",
"::",
"EQUAL",
":",
"return",
"$",
"this",
"->",
"_prepareBinaryExpression",
"(",
"self",
"::",
"EQUAL",
",",
"$",
"left",
",",
"$",
"right",
")",
";",
"break",
";",
"case",
"ExpressionType",
"::",
"NOTEQUAL",
":",
"return",
"$",
"this",
"->",
"_prepareBinaryExpression",
"(",
"self",
"::",
"NOTEQUAL",
",",
"$",
"left",
",",
"$",
"right",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'onArithmeticExpression'",
")",
";",
"}",
"}"
] |
Call-back for relational expression
@param ExpressionType $expressionType The type of relation expression
@param string $left The left expression
@param string $right The right expression
@return string
|
[
"Call",
"-",
"back",
"for",
"relational",
"expression"
] |
0c29d7121b303e00e01588804821e760787dff0c
|
https://github.com/adrotec/breeze.server.php/blob/0c29d7121b303e00e01588804821e760787dff0c/src/Adrotec/BreezeJs/CallbackExpressionProvider.php#L165-L192
|
224,834
|
adrotec/breeze.server.php
|
src/Adrotec/BreezeJs/CallbackExpressionProvider.php
|
CallbackExpressionProvider.onUnaryExpression
|
public function onUnaryExpression($expressionType, $child) {
switch ($expressionType) {
case ExpressionType::NEGATE:
return $this->_prepareUnaryExpression(self::NEGATE, $child);
break;
case ExpressionType::NOT_LOGICAL:
return $this->_prepareUnaryExpression(self::LOGICAL_NOT, $child);
break;
default:
throw new \InvalidArgumentException('onUnaryExpression');
}
}
|
php
|
public function onUnaryExpression($expressionType, $child) {
switch ($expressionType) {
case ExpressionType::NEGATE:
return $this->_prepareUnaryExpression(self::NEGATE, $child);
break;
case ExpressionType::NOT_LOGICAL:
return $this->_prepareUnaryExpression(self::LOGICAL_NOT, $child);
break;
default:
throw new \InvalidArgumentException('onUnaryExpression');
}
}
|
[
"public",
"function",
"onUnaryExpression",
"(",
"$",
"expressionType",
",",
"$",
"child",
")",
"{",
"switch",
"(",
"$",
"expressionType",
")",
"{",
"case",
"ExpressionType",
"::",
"NEGATE",
":",
"return",
"$",
"this",
"->",
"_prepareUnaryExpression",
"(",
"self",
"::",
"NEGATE",
",",
"$",
"child",
")",
";",
"break",
";",
"case",
"ExpressionType",
"::",
"NOT_LOGICAL",
":",
"return",
"$",
"this",
"->",
"_prepareUnaryExpression",
"(",
"self",
"::",
"LOGICAL_NOT",
",",
"$",
"child",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'onUnaryExpression'",
")",
";",
"}",
"}"
] |
Call-back for unary expression
@param ExpressionType $expressionType The type of unary expression
@param string $child The child expression
@return string
|
[
"Call",
"-",
"back",
"for",
"unary",
"expression"
] |
0c29d7121b303e00e01588804821e760787dff0c
|
https://github.com/adrotec/breeze.server.php/blob/0c29d7121b303e00e01588804821e760787dff0c/src/Adrotec/BreezeJs/CallbackExpressionProvider.php#L202-L213
|
224,835
|
adrotec/breeze.server.php
|
src/Adrotec/BreezeJs/CallbackExpressionProvider.php
|
CallbackExpressionProvider._prepareUnaryExpression
|
private function _prepareUnaryExpression($operator, $child) {
return $this->_iterName.$operator.self::OPEN_BRAKET.$child.self::CLOSE_BRACKET;
}
|
php
|
private function _prepareUnaryExpression($operator, $child) {
return $this->_iterName.$operator.self::OPEN_BRAKET.$child.self::CLOSE_BRACKET;
}
|
[
"private",
"function",
"_prepareUnaryExpression",
"(",
"$",
"operator",
",",
"$",
"child",
")",
"{",
"return",
"$",
"this",
"->",
"_iterName",
".",
"$",
"operator",
".",
"self",
"::",
"OPEN_BRAKET",
".",
"$",
"child",
".",
"self",
"::",
"CLOSE_BRACKET",
";",
"}"
] |
To format unary expression
@param string $operator The unary operator.
@param string $child The operand.
@return string
|
[
"To",
"format",
"unary",
"expression"
] |
0c29d7121b303e00e01588804821e760787dff0c
|
https://github.com/adrotec/breeze.server.php/blob/0c29d7121b303e00e01588804821e760787dff0c/src/Adrotec/BreezeJs/CallbackExpressionProvider.php#L367-L369
|
224,836
|
liip/LiipTranslationBundle
|
Translation/Translator.php
|
Translator.addResource
|
public function addResource($format, $resource, $locale, $domain = null)
{
$this->standardResources[] = array(
'format' => $format,
'path' => $resource,
'locale' => $locale,
'domain' => $domain === null ? 'messages' : $domain,
);
}
|
php
|
public function addResource($format, $resource, $locale, $domain = null)
{
$this->standardResources[] = array(
'format' => $format,
'path' => $resource,
'locale' => $locale,
'domain' => $domain === null ? 'messages' : $domain,
);
}
|
[
"public",
"function",
"addResource",
"(",
"$",
"format",
",",
"$",
"resource",
",",
"$",
"locale",
",",
"$",
"domain",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"standardResources",
"[",
"]",
"=",
"array",
"(",
"'format'",
"=>",
"$",
"format",
",",
"'path'",
"=>",
"$",
"resource",
",",
"'locale'",
"=>",
"$",
"locale",
",",
"'domain'",
"=>",
"$",
"domain",
"===",
"null",
"?",
"'messages'",
":",
"$",
"domain",
",",
")",
";",
"}"
] |
Override the addResource, so that we can keep tracking standard resources
but we don't call the parent method as we don't want to use them anymore.
@param string $format
@param mixed $resource
@param string $locale
@param string|null $domain
|
[
"Override",
"the",
"addResource",
"so",
"that",
"we",
"can",
"keep",
"tracking",
"standard",
"resources",
"but",
"we",
"don",
"t",
"call",
"the",
"parent",
"method",
"as",
"we",
"don",
"t",
"want",
"to",
"use",
"them",
"anymore",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Translation/Translator.php#L43-L51
|
224,837
|
liip/LiipTranslationBundle
|
Translation/Translator.php
|
Translator.getStandardResources
|
public function getStandardResources()
{
if (!$this->initialized && isset($this->options['resource_files'])) {
foreach ($this->options['resource_files'] as $files) {
foreach ($files as $file) {
// filename is domain.locale.format
list($domain, $locale, $format) = explode('.', basename($file), 3);
$this->addResource($format, $file, $locale, $domain);
}
}
}
// Check validity
foreach ($this->standardResources as $resource) {
if (!file_exists($resource['path'])) {
throw new \RuntimeException('Ressources list is outdated, please run a cache:clear to update it');
}
}
return $this->standardResources;
}
|
php
|
public function getStandardResources()
{
if (!$this->initialized && isset($this->options['resource_files'])) {
foreach ($this->options['resource_files'] as $files) {
foreach ($files as $file) {
// filename is domain.locale.format
list($domain, $locale, $format) = explode('.', basename($file), 3);
$this->addResource($format, $file, $locale, $domain);
}
}
}
// Check validity
foreach ($this->standardResources as $resource) {
if (!file_exists($resource['path'])) {
throw new \RuntimeException('Ressources list is outdated, please run a cache:clear to update it');
}
}
return $this->standardResources;
}
|
[
"public",
"function",
"getStandardResources",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"initialized",
"&&",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'resource_files'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"options",
"[",
"'resource_files'",
"]",
"as",
"$",
"files",
")",
"{",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"// filename is domain.locale.format",
"list",
"(",
"$",
"domain",
",",
"$",
"locale",
",",
"$",
"format",
")",
"=",
"explode",
"(",
"'.'",
",",
"basename",
"(",
"$",
"file",
")",
",",
"3",
")",
";",
"$",
"this",
"->",
"addResource",
"(",
"$",
"format",
",",
"$",
"file",
",",
"$",
"locale",
",",
"$",
"domain",
")",
";",
"}",
"}",
"}",
"// Check validity",
"foreach",
"(",
"$",
"this",
"->",
"standardResources",
"as",
"$",
"resource",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"resource",
"[",
"'path'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Ressources list is outdated, please run a cache:clear to update it'",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"standardResources",
";",
"}"
] |
Return the list of 'standard' resources.
@return array
|
[
"Return",
"the",
"list",
"of",
"standard",
"resources",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Translation/Translator.php#L58-L78
|
224,838
|
liip/LiipTranslationBundle
|
Translation/Translator.php
|
Translator.loadResource
|
public function loadResource($resource)
{
// If possible use our custom xliff loader, so we get metadata
if (in_array($resource['format'], array('xliff', 'xlf'))) {
return $this->container->get('liip.translation.xliff.loader')->load($resource['path'], $resource['locale'], $resource['domain']);
}
// Search for an other services
foreach ($this->loaderIds as $serviceId => $formats) {
if (!is_array($formats)) {
$formats = array($formats);
}
foreach ($formats as $format) {
if ($resource['format'] === $format) {
return $this->container->get($serviceId)->load($resource['path'], $resource['locale'], $resource['domain']);
}
}
}
throw new \RuntimeException("Not service found to load {$resource['path']}");
}
|
php
|
public function loadResource($resource)
{
// If possible use our custom xliff loader, so we get metadata
if (in_array($resource['format'], array('xliff', 'xlf'))) {
return $this->container->get('liip.translation.xliff.loader')->load($resource['path'], $resource['locale'], $resource['domain']);
}
// Search for an other services
foreach ($this->loaderIds as $serviceId => $formats) {
if (!is_array($formats)) {
$formats = array($formats);
}
foreach ($formats as $format) {
if ($resource['format'] === $format) {
return $this->container->get($serviceId)->load($resource['path'], $resource['locale'], $resource['domain']);
}
}
}
throw new \RuntimeException("Not service found to load {$resource['path']}");
}
|
[
"public",
"function",
"loadResource",
"(",
"$",
"resource",
")",
"{",
"// If possible use our custom xliff loader, so we get metadata",
"if",
"(",
"in_array",
"(",
"$",
"resource",
"[",
"'format'",
"]",
",",
"array",
"(",
"'xliff'",
",",
"'xlf'",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'liip.translation.xliff.loader'",
")",
"->",
"load",
"(",
"$",
"resource",
"[",
"'path'",
"]",
",",
"$",
"resource",
"[",
"'locale'",
"]",
",",
"$",
"resource",
"[",
"'domain'",
"]",
")",
";",
"}",
"// Search for an other services",
"foreach",
"(",
"$",
"this",
"->",
"loaderIds",
"as",
"$",
"serviceId",
"=>",
"$",
"formats",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"formats",
")",
")",
"{",
"$",
"formats",
"=",
"array",
"(",
"$",
"formats",
")",
";",
"}",
"foreach",
"(",
"$",
"formats",
"as",
"$",
"format",
")",
"{",
"if",
"(",
"$",
"resource",
"[",
"'format'",
"]",
"===",
"$",
"format",
")",
"{",
"return",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"serviceId",
")",
"->",
"load",
"(",
"$",
"resource",
"[",
"'path'",
"]",
",",
"$",
"resource",
"[",
"'locale'",
"]",
",",
"$",
"resource",
"[",
"'domain'",
"]",
")",
";",
"}",
"}",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Not service found to load {$resource['path']}\"",
")",
";",
"}"
] |
Load a specific resource.
@param array $resource
@return MessageCatalogue
@throws \RuntimeException
|
[
"Load",
"a",
"specific",
"resource",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Translation/Translator.php#L111-L131
|
224,839
|
liip/LiipTranslationBundle
|
Translation/Translator.php
|
Translator.initialize
|
protected function initialize()
{
if ($this->initialized) {
return;
}
parent::initialize();
// Add resources files directly, so that we still have translations
// event if we don't run translation:import
$standardResources = $this->getStandardResources();
foreach ($standardResources as $resource) {
parent::addResource($resource['format'], $resource['path'], $resource['locale'], $resource['domain']);
}
// Register all catalogues we have in the storage
$repo = $this->container->get('liip.translation.repository');
$locales = $repo->getLocaleList();
foreach ($repo->getDomainList() as $domain) {
foreach ($locales as $locale) {
parent::addResource('liip', 'intermediate.storage', $locale, $domain);
}
}
$this->initialized = true;
}
|
php
|
protected function initialize()
{
if ($this->initialized) {
return;
}
parent::initialize();
// Add resources files directly, so that we still have translations
// event if we don't run translation:import
$standardResources = $this->getStandardResources();
foreach ($standardResources as $resource) {
parent::addResource($resource['format'], $resource['path'], $resource['locale'], $resource['domain']);
}
// Register all catalogues we have in the storage
$repo = $this->container->get('liip.translation.repository');
$locales = $repo->getLocaleList();
foreach ($repo->getDomainList() as $domain) {
foreach ($locales as $locale) {
parent::addResource('liip', 'intermediate.storage', $locale, $domain);
}
}
$this->initialized = true;
}
|
[
"protected",
"function",
"initialize",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"initialized",
")",
"{",
"return",
";",
"}",
"parent",
"::",
"initialize",
"(",
")",
";",
"// Add resources files directly, so that we still have translations",
"// event if we don't run translation:import",
"$",
"standardResources",
"=",
"$",
"this",
"->",
"getStandardResources",
"(",
")",
";",
"foreach",
"(",
"$",
"standardResources",
"as",
"$",
"resource",
")",
"{",
"parent",
"::",
"addResource",
"(",
"$",
"resource",
"[",
"'format'",
"]",
",",
"$",
"resource",
"[",
"'path'",
"]",
",",
"$",
"resource",
"[",
"'locale'",
"]",
",",
"$",
"resource",
"[",
"'domain'",
"]",
")",
";",
"}",
"// Register all catalogues we have in the storage",
"$",
"repo",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'liip.translation.repository'",
")",
";",
"$",
"locales",
"=",
"$",
"repo",
"->",
"getLocaleList",
"(",
")",
";",
"foreach",
"(",
"$",
"repo",
"->",
"getDomainList",
"(",
")",
"as",
"$",
"domain",
")",
"{",
"foreach",
"(",
"$",
"locales",
"as",
"$",
"locale",
")",
"{",
"parent",
"::",
"addResource",
"(",
"'liip'",
",",
"'intermediate.storage'",
",",
"$",
"locale",
",",
"$",
"domain",
")",
";",
"}",
"}",
"$",
"this",
"->",
"initialized",
"=",
"true",
";",
"}"
] |
Initialize the translation before loading catalogues from the storage.
|
[
"Initialize",
"the",
"translation",
"before",
"loading",
"catalogues",
"from",
"the",
"storage",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Translation/Translator.php#L136-L161
|
224,840
|
umulmrum/holiday
|
src/Helper/HolidayHelper.php
|
HolidayHelper.isDayAHoliday
|
public function isDayAHoliday(DateTime $dateTime, $region)
{
$holidayList = $this->holidayCalculator->calculateHolidaysForYear((int) $dateTime->format('Y'), $region, $dateTime->getTimezone());
$filteredHolidays = (new IncludeTimespanFilter())->filter($holidayList, [
IncludeTimespanFilter::PARAM_FIRST_DAY => $dateTime,
IncludeTimespanFilter::PARAM_LAST_DAY => $dateTime,
]);
return count($filteredHolidays) > 0;
}
|
php
|
public function isDayAHoliday(DateTime $dateTime, $region)
{
$holidayList = $this->holidayCalculator->calculateHolidaysForYear((int) $dateTime->format('Y'), $region, $dateTime->getTimezone());
$filteredHolidays = (new IncludeTimespanFilter())->filter($holidayList, [
IncludeTimespanFilter::PARAM_FIRST_DAY => $dateTime,
IncludeTimespanFilter::PARAM_LAST_DAY => $dateTime,
]);
return count($filteredHolidays) > 0;
}
|
[
"public",
"function",
"isDayAHoliday",
"(",
"DateTime",
"$",
"dateTime",
",",
"$",
"region",
")",
"{",
"$",
"holidayList",
"=",
"$",
"this",
"->",
"holidayCalculator",
"->",
"calculateHolidaysForYear",
"(",
"(",
"int",
")",
"$",
"dateTime",
"->",
"format",
"(",
"'Y'",
")",
",",
"$",
"region",
",",
"$",
"dateTime",
"->",
"getTimezone",
"(",
")",
")",
";",
"$",
"filteredHolidays",
"=",
"(",
"new",
"IncludeTimespanFilter",
"(",
")",
")",
"->",
"filter",
"(",
"$",
"holidayList",
",",
"[",
"IncludeTimespanFilter",
"::",
"PARAM_FIRST_DAY",
"=>",
"$",
"dateTime",
",",
"IncludeTimespanFilter",
"::",
"PARAM_LAST_DAY",
"=>",
"$",
"dateTime",
",",
"]",
")",
";",
"return",
"count",
"(",
"$",
"filteredHolidays",
")",
">",
"0",
";",
"}"
] |
Returns if the given date is a holiday in the given region.
@param DateTime $dateTime
@param string $region
@return bool true if the day is a holiday, else false
@throws HolidayException
|
[
"Returns",
"if",
"the",
"given",
"date",
"is",
"a",
"holiday",
"in",
"the",
"given",
"region",
"."
] |
19bd2f0259c0e01d4b984876b014d636c53a2be3
|
https://github.com/umulmrum/holiday/blob/19bd2f0259c0e01d4b984876b014d636c53a2be3/src/Helper/HolidayHelper.php#L61-L70
|
224,841
|
umulmrum/holiday
|
src/Helper/HolidayHelper.php
|
HolidayHelper.getHolidaysForMonth
|
public function getHolidaysForMonth($year, $month, $region, DateTimeZone $timezone = null)
{
$holidayList = $this->holidayCalculator->calculateHolidaysForYear($year, $region, $timezone);
$date = new DateTime(sprintf('%s-%s-01', $year, $month), $timezone);
$lastDayOfMonth = (int) $date->format('t');
$filteredHolidays = (new IncludeTimespanFilter())->filter($holidayList, [
IncludeTimespanFilter::PARAM_FIRST_DAY => $date,
IncludeTimespanFilter::PARAM_LAST_DAY => new DateTime(sprintf('%s-%s-%s', $year, $month, $lastDayOfMonth), $timezone),
]);
return $filteredHolidays;
}
|
php
|
public function getHolidaysForMonth($year, $month, $region, DateTimeZone $timezone = null)
{
$holidayList = $this->holidayCalculator->calculateHolidaysForYear($year, $region, $timezone);
$date = new DateTime(sprintf('%s-%s-01', $year, $month), $timezone);
$lastDayOfMonth = (int) $date->format('t');
$filteredHolidays = (new IncludeTimespanFilter())->filter($holidayList, [
IncludeTimespanFilter::PARAM_FIRST_DAY => $date,
IncludeTimespanFilter::PARAM_LAST_DAY => new DateTime(sprintf('%s-%s-%s', $year, $month, $lastDayOfMonth), $timezone),
]);
return $filteredHolidays;
}
|
[
"public",
"function",
"getHolidaysForMonth",
"(",
"$",
"year",
",",
"$",
"month",
",",
"$",
"region",
",",
"DateTimeZone",
"$",
"timezone",
"=",
"null",
")",
"{",
"$",
"holidayList",
"=",
"$",
"this",
"->",
"holidayCalculator",
"->",
"calculateHolidaysForYear",
"(",
"$",
"year",
",",
"$",
"region",
",",
"$",
"timezone",
")",
";",
"$",
"date",
"=",
"new",
"DateTime",
"(",
"sprintf",
"(",
"'%s-%s-01'",
",",
"$",
"year",
",",
"$",
"month",
")",
",",
"$",
"timezone",
")",
";",
"$",
"lastDayOfMonth",
"=",
"(",
"int",
")",
"$",
"date",
"->",
"format",
"(",
"'t'",
")",
";",
"$",
"filteredHolidays",
"=",
"(",
"new",
"IncludeTimespanFilter",
"(",
")",
")",
"->",
"filter",
"(",
"$",
"holidayList",
",",
"[",
"IncludeTimespanFilter",
"::",
"PARAM_FIRST_DAY",
"=>",
"$",
"date",
",",
"IncludeTimespanFilter",
"::",
"PARAM_LAST_DAY",
"=>",
"new",
"DateTime",
"(",
"sprintf",
"(",
"'%s-%s-%s'",
",",
"$",
"year",
",",
"$",
"month",
",",
"$",
"lastDayOfMonth",
")",
",",
"$",
"timezone",
")",
",",
"]",
")",
";",
"return",
"$",
"filteredHolidays",
";",
"}"
] |
Returns all holidays for the given month in the given region.
@param int $year
@param int $month
@param string $region
@param DateTimeZone $timezone
@return HolidayList
@throws HolidayException
|
[
"Returns",
"all",
"holidays",
"for",
"the",
"given",
"month",
"in",
"the",
"given",
"region",
"."
] |
19bd2f0259c0e01d4b984876b014d636c53a2be3
|
https://github.com/umulmrum/holiday/blob/19bd2f0259c0e01d4b984876b014d636c53a2be3/src/Helper/HolidayHelper.php#L84-L95
|
224,842
|
umulmrum/holiday
|
src/Helper/HolidayHelper.php
|
HolidayHelper.getHolidaysByName
|
public function getHolidaysByName($year, $holidayName, $region, DateTimeZone $timezone = null)
{
$holidayList = $this->holidayCalculator->calculateHolidaysForYear($year, $region, $timezone);
$filteredHolidays = (new IncludeHolidayNameFilter())->filter($holidayList, [
IncludeHolidayNameFilter::PARAM_HOLIDAY_NAME => $holidayName,
]);
return $filteredHolidays;
}
|
php
|
public function getHolidaysByName($year, $holidayName, $region, DateTimeZone $timezone = null)
{
$holidayList = $this->holidayCalculator->calculateHolidaysForYear($year, $region, $timezone);
$filteredHolidays = (new IncludeHolidayNameFilter())->filter($holidayList, [
IncludeHolidayNameFilter::PARAM_HOLIDAY_NAME => $holidayName,
]);
return $filteredHolidays;
}
|
[
"public",
"function",
"getHolidaysByName",
"(",
"$",
"year",
",",
"$",
"holidayName",
",",
"$",
"region",
",",
"DateTimeZone",
"$",
"timezone",
"=",
"null",
")",
"{",
"$",
"holidayList",
"=",
"$",
"this",
"->",
"holidayCalculator",
"->",
"calculateHolidaysForYear",
"(",
"$",
"year",
",",
"$",
"region",
",",
"$",
"timezone",
")",
";",
"$",
"filteredHolidays",
"=",
"(",
"new",
"IncludeHolidayNameFilter",
"(",
")",
")",
"->",
"filter",
"(",
"$",
"holidayList",
",",
"[",
"IncludeHolidayNameFilter",
"::",
"PARAM_HOLIDAY_NAME",
"=>",
"$",
"holidayName",
",",
"]",
")",
";",
"return",
"$",
"filteredHolidays",
";",
"}"
] |
Returns all holidays with the given name for the given year in the given region. Note that holiday names are
not necessarily unique, and therefore a HolidayList object is returned.
@param int $year
@param string $holidayName
@param string $region
@param DateTimeZone $timezone
@return HolidayList
@throws HolidayException
|
[
"Returns",
"all",
"holidays",
"with",
"the",
"given",
"name",
"for",
"the",
"given",
"year",
"in",
"the",
"given",
"region",
".",
"Note",
"that",
"holiday",
"names",
"are",
"not",
"necessarily",
"unique",
"and",
"therefore",
"a",
"HolidayList",
"object",
"is",
"returned",
"."
] |
19bd2f0259c0e01d4b984876b014d636c53a2be3
|
https://github.com/umulmrum/holiday/blob/19bd2f0259c0e01d4b984876b014d636c53a2be3/src/Helper/HolidayHelper.php#L110-L118
|
224,843
|
umulmrum/holiday
|
src/Helper/HolidayHelper.php
|
HolidayHelper.getNoWorkDaysForTimespan
|
public function getNoWorkDaysForTimespan(DateTime $firstDay, DateTime $lastDay, $region, array $noWorkWeekdayProviders = [])
{
if (count($noWorkWeekdayProviders) > 0) {
$noWork = $noWorkWeekdayProviders;
} else {
$noWork = [
new Sundays(),
];
}
$startYear = (int) $firstDay->format('Y');
$endYear = (int) $lastDay->format('Y');
if ($startYear === $endYear) {
$holidayList = $this->getNoWorkDaysWithinSingleYear($firstDay, $lastDay, $region, $startYear, $noWork);
} else {
$holidayList = $this->getNoWorkDaysOverMultipleYears($firstDay, $lastDay, $region, $startYear, $endYear, $noWork);
}
return (new SortByDateFilter())->filter($holidayList);
}
|
php
|
public function getNoWorkDaysForTimespan(DateTime $firstDay, DateTime $lastDay, $region, array $noWorkWeekdayProviders = [])
{
if (count($noWorkWeekdayProviders) > 0) {
$noWork = $noWorkWeekdayProviders;
} else {
$noWork = [
new Sundays(),
];
}
$startYear = (int) $firstDay->format('Y');
$endYear = (int) $lastDay->format('Y');
if ($startYear === $endYear) {
$holidayList = $this->getNoWorkDaysWithinSingleYear($firstDay, $lastDay, $region, $startYear, $noWork);
} else {
$holidayList = $this->getNoWorkDaysOverMultipleYears($firstDay, $lastDay, $region, $startYear, $endYear, $noWork);
}
return (new SortByDateFilter())->filter($holidayList);
}
|
[
"public",
"function",
"getNoWorkDaysForTimespan",
"(",
"DateTime",
"$",
"firstDay",
",",
"DateTime",
"$",
"lastDay",
",",
"$",
"region",
",",
"array",
"$",
"noWorkWeekdayProviders",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"noWorkWeekdayProviders",
")",
">",
"0",
")",
"{",
"$",
"noWork",
"=",
"$",
"noWorkWeekdayProviders",
";",
"}",
"else",
"{",
"$",
"noWork",
"=",
"[",
"new",
"Sundays",
"(",
")",
",",
"]",
";",
"}",
"$",
"startYear",
"=",
"(",
"int",
")",
"$",
"firstDay",
"->",
"format",
"(",
"'Y'",
")",
";",
"$",
"endYear",
"=",
"(",
"int",
")",
"$",
"lastDay",
"->",
"format",
"(",
"'Y'",
")",
";",
"if",
"(",
"$",
"startYear",
"===",
"$",
"endYear",
")",
"{",
"$",
"holidayList",
"=",
"$",
"this",
"->",
"getNoWorkDaysWithinSingleYear",
"(",
"$",
"firstDay",
",",
"$",
"lastDay",
",",
"$",
"region",
",",
"$",
"startYear",
",",
"$",
"noWork",
")",
";",
"}",
"else",
"{",
"$",
"holidayList",
"=",
"$",
"this",
"->",
"getNoWorkDaysOverMultipleYears",
"(",
"$",
"firstDay",
",",
"$",
"lastDay",
",",
"$",
"region",
",",
"$",
"startYear",
",",
"$",
"endYear",
",",
"$",
"noWork",
")",
";",
"}",
"return",
"(",
"new",
"SortByDateFilter",
"(",
")",
")",
"->",
"filter",
"(",
"$",
"holidayList",
")",
";",
"}"
] |
Returns all days in the given timespan and the region in which normally employees do not need to work.
Be aware that this method is quite heavy-weight if multiple no-work days for multiple years are requested.
@param DateTime $firstDay
@param DateTime $lastDay
@param string $region
@param HolidayProviderInterface[] $noWorkWeekdayProviders
@return HolidayList
@throws HolidayException
|
[
"Returns",
"all",
"days",
"in",
"the",
"given",
"timespan",
"and",
"the",
"region",
"in",
"which",
"normally",
"employees",
"do",
"not",
"need",
"to",
"work",
".",
"Be",
"aware",
"that",
"this",
"method",
"is",
"quite",
"heavy",
"-",
"weight",
"if",
"multiple",
"no",
"-",
"work",
"days",
"for",
"multiple",
"years",
"are",
"requested",
"."
] |
19bd2f0259c0e01d4b984876b014d636c53a2be3
|
https://github.com/umulmrum/holiday/blob/19bd2f0259c0e01d4b984876b014d636c53a2be3/src/Helper/HolidayHelper.php#L133-L153
|
224,844
|
umulmrum/holiday
|
src/Helper/HolidayHelper.php
|
HolidayHelper.mergeHolidayLists
|
public function mergeHolidayLists(array $holidayLists)
{
$newList = new HolidayList();
foreach ($holidayLists as $holidayList) {
foreach ($holidayList->getList() as $holiday) {
$newList->add($holiday);
}
}
return (new SortByDateFilter())->filter($newList);
}
|
php
|
public function mergeHolidayLists(array $holidayLists)
{
$newList = new HolidayList();
foreach ($holidayLists as $holidayList) {
foreach ($holidayList->getList() as $holiday) {
$newList->add($holiday);
}
}
return (new SortByDateFilter())->filter($newList);
}
|
[
"public",
"function",
"mergeHolidayLists",
"(",
"array",
"$",
"holidayLists",
")",
"{",
"$",
"newList",
"=",
"new",
"HolidayList",
"(",
")",
";",
"foreach",
"(",
"$",
"holidayLists",
"as",
"$",
"holidayList",
")",
"{",
"foreach",
"(",
"$",
"holidayList",
"->",
"getList",
"(",
")",
"as",
"$",
"holiday",
")",
"{",
"$",
"newList",
"->",
"add",
"(",
"$",
"holiday",
")",
";",
"}",
"}",
"return",
"(",
"new",
"SortByDateFilter",
"(",
")",
")",
"->",
"filter",
"(",
"$",
"newList",
")",
";",
"}"
] |
Returns a merged list of all the HolidayList objects given.
@param HolidayList[] $holidayLists
@return HolidayList
|
[
"Returns",
"a",
"merged",
"list",
"of",
"all",
"the",
"HolidayList",
"objects",
"given",
"."
] |
19bd2f0259c0e01d4b984876b014d636c53a2be3
|
https://github.com/umulmrum/holiday/blob/19bd2f0259c0e01d4b984876b014d636c53a2be3/src/Helper/HolidayHelper.php#L194-L204
|
224,845
|
jasny/error-handler
|
src/ErrorHandler/Logging.php
|
Logging.log
|
public function log($error)
{
if ($error instanceof \Error || $error instanceof \ErrorException) {
return $this->logError($error);
}
if ($error instanceof \Exception) {
return $this->logException($error);
}
$message = "Unable to log a " . (is_object($error) ? get_class($error) . ' ' : '') . gettype($error);
$this->getLogger()->log(LogLevel::WARNING, $message);
}
|
php
|
public function log($error)
{
if ($error instanceof \Error || $error instanceof \ErrorException) {
return $this->logError($error);
}
if ($error instanceof \Exception) {
return $this->logException($error);
}
$message = "Unable to log a " . (is_object($error) ? get_class($error) . ' ' : '') . gettype($error);
$this->getLogger()->log(LogLevel::WARNING, $message);
}
|
[
"public",
"function",
"log",
"(",
"$",
"error",
")",
"{",
"if",
"(",
"$",
"error",
"instanceof",
"\\",
"Error",
"||",
"$",
"error",
"instanceof",
"\\",
"ErrorException",
")",
"{",
"return",
"$",
"this",
"->",
"logError",
"(",
"$",
"error",
")",
";",
"}",
"if",
"(",
"$",
"error",
"instanceof",
"\\",
"Exception",
")",
"{",
"return",
"$",
"this",
"->",
"logException",
"(",
"$",
"error",
")",
";",
"}",
"$",
"message",
"=",
"\"Unable to log a \"",
".",
"(",
"is_object",
"(",
"$",
"error",
")",
"?",
"get_class",
"(",
"$",
"error",
")",
".",
"' '",
":",
"''",
")",
".",
"gettype",
"(",
"$",
"error",
")",
";",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"log",
"(",
"LogLevel",
"::",
"WARNING",
",",
"$",
"message",
")",
";",
"}"
] |
Log an error or exception
@param \Exception|\Error $error
|
[
"Log",
"an",
"error",
"or",
"exception"
] |
38e076fc36d86689010081bc2eab96f12d97b0d8
|
https://github.com/jasny/error-handler/blob/38e076fc36d86689010081bc2eab96f12d97b0d8/src/ErrorHandler/Logging.php#L67-L79
|
224,846
|
jasny/error-handler
|
src/ErrorHandler/Logging.php
|
Logging.logException
|
protected function logException(\Exception $exception)
{
$level = $this->getLogLevel();
$message = sprintf('Uncaught Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(),
$exception->getFile(), $exception->getLine());
$context = compact('exception');
$this->getLogger()->log($level, $message, $context);
}
|
php
|
protected function logException(\Exception $exception)
{
$level = $this->getLogLevel();
$message = sprintf('Uncaught Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(),
$exception->getFile(), $exception->getLine());
$context = compact('exception');
$this->getLogger()->log($level, $message, $context);
}
|
[
"protected",
"function",
"logException",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"$",
"level",
"=",
"$",
"this",
"->",
"getLogLevel",
"(",
")",
";",
"$",
"message",
"=",
"sprintf",
"(",
"'Uncaught Exception %s: \"%s\" at %s line %s'",
",",
"get_class",
"(",
"$",
"exception",
")",
",",
"$",
"exception",
"->",
"getMessage",
"(",
")",
",",
"$",
"exception",
"->",
"getFile",
"(",
")",
",",
"$",
"exception",
"->",
"getLine",
"(",
")",
")",
";",
"$",
"context",
"=",
"compact",
"(",
"'exception'",
")",
";",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"log",
"(",
"$",
"level",
",",
"$",
"message",
",",
"$",
"context",
")",
";",
"}"
] |
Log an exception
@param \Exception $exception
|
[
"Log",
"an",
"exception"
] |
38e076fc36d86689010081bc2eab96f12d97b0d8
|
https://github.com/jasny/error-handler/blob/38e076fc36d86689010081bc2eab96f12d97b0d8/src/ErrorHandler/Logging.php#L110-L120
|
224,847
|
paillechat/php-enum
|
src/Enum.php
|
Enum.createByName
|
final public static function createByName(string $name)
{
$canonicalName = strtoupper($name);
if ($canonicalName !== $name) {
$name = $canonicalName;
trigger_error('PSR-1 requires constant to be declared in upper case.', E_USER_NOTICE);
}
$const = static::getConstList();
if (!\in_array($name, $const, true)) {
throw EnumException::becauseUnknownMember(static::class, $name);
}
return static::createNamedInstance($name);
}
|
php
|
final public static function createByName(string $name)
{
$canonicalName = strtoupper($name);
if ($canonicalName !== $name) {
$name = $canonicalName;
trigger_error('PSR-1 requires constant to be declared in upper case.', E_USER_NOTICE);
}
$const = static::getConstList();
if (!\in_array($name, $const, true)) {
throw EnumException::becauseUnknownMember(static::class, $name);
}
return static::createNamedInstance($name);
}
|
[
"final",
"public",
"static",
"function",
"createByName",
"(",
"string",
"$",
"name",
")",
"{",
"$",
"canonicalName",
"=",
"strtoupper",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"canonicalName",
"!==",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"$",
"canonicalName",
";",
"trigger_error",
"(",
"'PSR-1 requires constant to be declared in upper case.'",
",",
"E_USER_NOTICE",
")",
";",
"}",
"$",
"const",
"=",
"static",
"::",
"getConstList",
"(",
")",
";",
"if",
"(",
"!",
"\\",
"in_array",
"(",
"$",
"name",
",",
"$",
"const",
",",
"true",
")",
")",
"{",
"throw",
"EnumException",
"::",
"becauseUnknownMember",
"(",
"static",
"::",
"class",
",",
"$",
"name",
")",
";",
"}",
"return",
"static",
"::",
"createNamedInstance",
"(",
"$",
"name",
")",
";",
"}"
] |
Creates enum instance by name
@param string $name
@return static
@throws EnumException
|
[
"Creates",
"enum",
"instance",
"by",
"name"
] |
1a4d98d45b9c736f2fd036ef314d72e3d09d15b5
|
https://github.com/paillechat/php-enum/blob/1a4d98d45b9c736f2fd036ef314d72e3d09d15b5/src/Enum.php#L35-L50
|
224,848
|
paillechat/php-enum
|
src/Enum.php
|
Enum.createNamedInstance
|
private static function createNamedInstance(string $name)
{
$class = self::findParentClassForConst($name);
$key = self::getConstKey($class, $name);
if (!array_key_exists($key, self::$instances)) {
self::$instances[$key] = new static($name);
}
return self::$instances[$key];
}
|
php
|
private static function createNamedInstance(string $name)
{
$class = self::findParentClassForConst($name);
$key = self::getConstKey($class, $name);
if (!array_key_exists($key, self::$instances)) {
self::$instances[$key] = new static($name);
}
return self::$instances[$key];
}
|
[
"private",
"static",
"function",
"createNamedInstance",
"(",
"string",
"$",
"name",
")",
"{",
"$",
"class",
"=",
"self",
"::",
"findParentClassForConst",
"(",
"$",
"name",
")",
";",
"$",
"key",
"=",
"self",
"::",
"getConstKey",
"(",
"$",
"class",
",",
"$",
"name",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"self",
"::",
"$",
"instances",
")",
")",
"{",
"self",
"::",
"$",
"instances",
"[",
"$",
"key",
"]",
"=",
"new",
"static",
"(",
"$",
"name",
")",
";",
"}",
"return",
"self",
"::",
"$",
"instances",
"[",
"$",
"key",
"]",
";",
"}"
] |
Create named enum instance
@param string $name
@return static
|
[
"Create",
"named",
"enum",
"instance"
] |
1a4d98d45b9c736f2fd036ef314d72e3d09d15b5
|
https://github.com/paillechat/php-enum/blob/1a4d98d45b9c736f2fd036ef314d72e3d09d15b5/src/Enum.php#L116-L127
|
224,849
|
mrteye/GDAX
|
src/Api.php
|
Api._call
|
private function _call($method, $path, $param, $header = false) {
// Clear connection; Set timeout, and json header.
$this->curl->resetConnection();
// Set additional headers.
if ($header) {
foreach ($header as $name => $value) {
$this->curl->setHeader($name, $value);
}
}
// Make an API request to the GDAX server.
if ($param) {
// If the method is not GET, pass JSON in the request body.
$payload = false;
if ($method != 'GET') {
$param = json_encode($param);
$payload = true;
}
$this->curl->{strtolower($method)}("$this->api/$path", $param, $payload);
} else {
$this->curl->{strtolower($method)}("$this->api/$path");
}
// TODO: Move error logs out of class. ~: Monolog
// Error Logging
if ($this->curl->error) {
$this->_error[] = "$path: {$this->curl->error_message}";
if ($this->_debug) {
$this->_error[] = $this->_dump($path, $param);
}
}
if (is_null($ret = json_decode($this->curl->response))) {
throw new \Exception(__METHOD__ ." - Invalid JSON or null returned.");
}
// Throw an exception on any returned messages from GDAX.
if ($ret && isset($ret->message)) {
throw new \Exception("API: $path-> ". $ret->message);
}
return $ret;
}
|
php
|
private function _call($method, $path, $param, $header = false) {
// Clear connection; Set timeout, and json header.
$this->curl->resetConnection();
// Set additional headers.
if ($header) {
foreach ($header as $name => $value) {
$this->curl->setHeader($name, $value);
}
}
// Make an API request to the GDAX server.
if ($param) {
// If the method is not GET, pass JSON in the request body.
$payload = false;
if ($method != 'GET') {
$param = json_encode($param);
$payload = true;
}
$this->curl->{strtolower($method)}("$this->api/$path", $param, $payload);
} else {
$this->curl->{strtolower($method)}("$this->api/$path");
}
// TODO: Move error logs out of class. ~: Monolog
// Error Logging
if ($this->curl->error) {
$this->_error[] = "$path: {$this->curl->error_message}";
if ($this->_debug) {
$this->_error[] = $this->_dump($path, $param);
}
}
if (is_null($ret = json_decode($this->curl->response))) {
throw new \Exception(__METHOD__ ." - Invalid JSON or null returned.");
}
// Throw an exception on any returned messages from GDAX.
if ($ret && isset($ret->message)) {
throw new \Exception("API: $path-> ". $ret->message);
}
return $ret;
}
|
[
"private",
"function",
"_call",
"(",
"$",
"method",
",",
"$",
"path",
",",
"$",
"param",
",",
"$",
"header",
"=",
"false",
")",
"{",
"// Clear connection; Set timeout, and json header.",
"$",
"this",
"->",
"curl",
"->",
"resetConnection",
"(",
")",
";",
"// Set additional headers.",
"if",
"(",
"$",
"header",
")",
"{",
"foreach",
"(",
"$",
"header",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"curl",
"->",
"setHeader",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}",
"// Make an API request to the GDAX server.",
"if",
"(",
"$",
"param",
")",
"{",
"// If the method is not GET, pass JSON in the request body.",
"$",
"payload",
"=",
"false",
";",
"if",
"(",
"$",
"method",
"!=",
"'GET'",
")",
"{",
"$",
"param",
"=",
"json_encode",
"(",
"$",
"param",
")",
";",
"$",
"payload",
"=",
"true",
";",
"}",
"$",
"this",
"->",
"curl",
"->",
"{",
"strtolower",
"(",
"$",
"method",
")",
"}",
"(",
"\"$this->api/$path\"",
",",
"$",
"param",
",",
"$",
"payload",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"curl",
"->",
"{",
"strtolower",
"(",
"$",
"method",
")",
"}",
"(",
"\"$this->api/$path\"",
")",
";",
"}",
"// TODO: Move error logs out of class. ~: Monolog",
"// Error Logging",
"if",
"(",
"$",
"this",
"->",
"curl",
"->",
"error",
")",
"{",
"$",
"this",
"->",
"_error",
"[",
"]",
"=",
"\"$path: {$this->curl->error_message}\"",
";",
"if",
"(",
"$",
"this",
"->",
"_debug",
")",
"{",
"$",
"this",
"->",
"_error",
"[",
"]",
"=",
"$",
"this",
"->",
"_dump",
"(",
"$",
"path",
",",
"$",
"param",
")",
";",
"}",
"}",
"if",
"(",
"is_null",
"(",
"$",
"ret",
"=",
"json_decode",
"(",
"$",
"this",
"->",
"curl",
"->",
"response",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"__METHOD__",
".",
"\" - Invalid JSON or null returned.\"",
")",
";",
"}",
"// Throw an exception on any returned messages from GDAX.",
"if",
"(",
"$",
"ret",
"&&",
"isset",
"(",
"$",
"ret",
"->",
"message",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"API: $path-> \"",
".",
"$",
"ret",
"->",
"message",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] |
Connection logic; send requests to the Gdax API.
|
[
"Connection",
"logic",
";",
"send",
"requests",
"to",
"the",
"Gdax",
"API",
"."
] |
891e5e95abb4a0fc8d4e5b937d8f143701460824
|
https://github.com/mrteye/GDAX/blob/891e5e95abb4a0fc8d4e5b937d8f143701460824/src/Api.php#L79-L122
|
224,850
|
hendrikmaus/drafter-installer
|
src/Installer.php
|
Installer.createComposerInMemoryPackage
|
public static function createComposerInMemoryPackage($targetDir, $tag)
{
$package = new Package('apiaryio/drafter', 'drafter', $tag);
$package->setTargetDir($targetDir);
$package->setInstallationSource('source');
$package->setSourceUrl('https://github.com/apiaryio/drafter');
$package->setSourceType('git');
$package->setSourceReference($tag);
return $package;
}
|
php
|
public static function createComposerInMemoryPackage($targetDir, $tag)
{
$package = new Package('apiaryio/drafter', 'drafter', $tag);
$package->setTargetDir($targetDir);
$package->setInstallationSource('source');
$package->setSourceUrl('https://github.com/apiaryio/drafter');
$package->setSourceType('git');
$package->setSourceReference($tag);
return $package;
}
|
[
"public",
"static",
"function",
"createComposerInMemoryPackage",
"(",
"$",
"targetDir",
",",
"$",
"tag",
")",
"{",
"$",
"package",
"=",
"new",
"Package",
"(",
"'apiaryio/drafter'",
",",
"'drafter'",
",",
"$",
"tag",
")",
";",
"$",
"package",
"->",
"setTargetDir",
"(",
"$",
"targetDir",
")",
";",
"$",
"package",
"->",
"setInstallationSource",
"(",
"'source'",
")",
";",
"$",
"package",
"->",
"setSourceUrl",
"(",
"'https://github.com/apiaryio/drafter'",
")",
";",
"$",
"package",
"->",
"setSourceType",
"(",
"'git'",
")",
";",
"$",
"package",
"->",
"setSourceReference",
"(",
"$",
"tag",
")",
";",
"return",
"$",
"package",
";",
"}"
] |
Create composer in memory package
@param string $targetDir Download target dir
@param string $tag Tag to install, e.g. v3.1.1
@return Package
|
[
"Create",
"composer",
"in",
"memory",
"package"
] |
1dcad857cf8df47aac74dd8641cc6bb71d700712
|
https://github.com/hendrikmaus/drafter-installer/blob/1dcad857cf8df47aac74dd8641cc6bb71d700712/src/Installer.php#L108-L118
|
224,851
|
Crinsane/LaravelNotify
|
src/Notifications/Renderers/NativeRenderer.php
|
NativeRenderer.generateMessage
|
private function generateMessage($notification)
{
$message = ucfirst($notification['type']) . '\n\n';
if ( ! is_null($notification['title'])) {
$message .= $this->escapeTitle($notification['title']) . '\n\n';
}
return $this->escapeMessage($message . $notification['message']);
}
|
php
|
private function generateMessage($notification)
{
$message = ucfirst($notification['type']) . '\n\n';
if ( ! is_null($notification['title'])) {
$message .= $this->escapeTitle($notification['title']) . '\n\n';
}
return $this->escapeMessage($message . $notification['message']);
}
|
[
"private",
"function",
"generateMessage",
"(",
"$",
"notification",
")",
"{",
"$",
"message",
"=",
"ucfirst",
"(",
"$",
"notification",
"[",
"'type'",
"]",
")",
".",
"'\\n\\n'",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"notification",
"[",
"'title'",
"]",
")",
")",
"{",
"$",
"message",
".=",
"$",
"this",
"->",
"escapeTitle",
"(",
"$",
"notification",
"[",
"'title'",
"]",
")",
".",
"'\\n\\n'",
";",
"}",
"return",
"$",
"this",
"->",
"escapeMessage",
"(",
"$",
"message",
".",
"$",
"notification",
"[",
"'message'",
"]",
")",
";",
"}"
] |
Generate the message for a native alert
@param array $notification
@return string
|
[
"Generate",
"the",
"message",
"for",
"a",
"native",
"alert"
] |
5064482018534abdb4483b9a08f86fa3ac735efd
|
https://github.com/Crinsane/LaravelNotify/blob/5064482018534abdb4483b9a08f86fa3ac735efd/src/Notifications/Renderers/NativeRenderer.php#L55-L64
|
224,852
|
yii2mod/yii2-bx-slider
|
BxSlider.php
|
BxSlider.run
|
public function run()
{
if (empty($this->items)) {
return;
}
if (!isset($this->containerOptions['id'])) {
$this->containerOptions['id'] = $this->getId();
}
echo $this->renderItems() . "\n";
$this->registerAssets();
}
|
php
|
public function run()
{
if (empty($this->items)) {
return;
}
if (!isset($this->containerOptions['id'])) {
$this->containerOptions['id'] = $this->getId();
}
echo $this->renderItems() . "\n";
$this->registerAssets();
}
|
[
"public",
"function",
"run",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"items",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"containerOptions",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"containerOptions",
"[",
"'id'",
"]",
"=",
"$",
"this",
"->",
"getId",
"(",
")",
";",
"}",
"echo",
"$",
"this",
"->",
"renderItems",
"(",
")",
".",
"\"\\n\"",
";",
"$",
"this",
"->",
"registerAssets",
"(",
")",
";",
"}"
] |
Render range slider
@return string|void
|
[
"Render",
"range",
"slider"
] |
027468995da085ee4baae75d073cdb991533be14
|
https://github.com/yii2mod/yii2-bx-slider/blob/027468995da085ee4baae75d073cdb991533be14/BxSlider.php#L47-L57
|
224,853
|
yii2mod/yii2-bx-slider
|
BxSlider.php
|
BxSlider.renderItems
|
public function renderItems()
{
$items = [];
for ($i = 0, $count = count($this->items); $i < $count; $i++) {
$items[] = Html::tag('li', $this->items[$i], $this->itemOptions);
}
return Html::tag('ul', implode("\n", $items), $this->containerOptions);
}
|
php
|
public function renderItems()
{
$items = [];
for ($i = 0, $count = count($this->items); $i < $count; $i++) {
$items[] = Html::tag('li', $this->items[$i], $this->itemOptions);
}
return Html::tag('ul', implode("\n", $items), $this->containerOptions);
}
|
[
"public",
"function",
"renderItems",
"(",
")",
"{",
"$",
"items",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"count",
"=",
"count",
"(",
"$",
"this",
"->",
"items",
")",
";",
"$",
"i",
"<",
"$",
"count",
";",
"$",
"i",
"++",
")",
"{",
"$",
"items",
"[",
"]",
"=",
"Html",
"::",
"tag",
"(",
"'li'",
",",
"$",
"this",
"->",
"items",
"[",
"$",
"i",
"]",
",",
"$",
"this",
"->",
"itemOptions",
")",
";",
"}",
"return",
"Html",
"::",
"tag",
"(",
"'ul'",
",",
"implode",
"(",
"\"\\n\"",
",",
"$",
"items",
")",
",",
"$",
"this",
"->",
"containerOptions",
")",
";",
"}"
] |
Renders slider items.
@return string the rendering result
|
[
"Renders",
"slider",
"items",
"."
] |
027468995da085ee4baae75d073cdb991533be14
|
https://github.com/yii2mod/yii2-bx-slider/blob/027468995da085ee4baae75d073cdb991533be14/BxSlider.php#L84-L92
|
224,854
|
liip/LiipTranslationBundle
|
Persistence/PropelPersistence.php
|
PropelPersistence.saveUnit
|
public function saveUnit(Unit $unit)
{
$propelUnit = UnitQuery::create()->findOneByDomainAndKey($unit->getDomain(), $unit->getKey());
if (!$propelUnit) {
$propelUnit = new PropelUnit();
}
$propelUnit->updateFromModel($unit);
$propelUnit->save();
}
|
php
|
public function saveUnit(Unit $unit)
{
$propelUnit = UnitQuery::create()->findOneByDomainAndKey($unit->getDomain(), $unit->getKey());
if (!$propelUnit) {
$propelUnit = new PropelUnit();
}
$propelUnit->updateFromModel($unit);
$propelUnit->save();
}
|
[
"public",
"function",
"saveUnit",
"(",
"Unit",
"$",
"unit",
")",
"{",
"$",
"propelUnit",
"=",
"UnitQuery",
"::",
"create",
"(",
")",
"->",
"findOneByDomainAndKey",
"(",
"$",
"unit",
"->",
"getDomain",
"(",
")",
",",
"$",
"unit",
"->",
"getKey",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"propelUnit",
")",
"{",
"$",
"propelUnit",
"=",
"new",
"PropelUnit",
"(",
")",
";",
"}",
"$",
"propelUnit",
"->",
"updateFromModel",
"(",
"$",
"unit",
")",
";",
"$",
"propelUnit",
"->",
"save",
"(",
")",
";",
"}"
] |
Save the given Unit to the persistence layer.
@param Unit $unit
@return bool
|
[
"Save",
"the",
"given",
"Unit",
"to",
"the",
"persistence",
"layer",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Persistence/PropelPersistence.php#L65-L73
|
224,855
|
liip/LiipTranslationBundle
|
Security/Security.php
|
Security.getAuthorizedLocaleList
|
public function getAuthorizedLocaleList($securityChecker)
{
$this->validateSecurityChecker($securityChecker);
if (!$securityChecker || !$this->isSecuredByLocale()) {
return $this->getLocaleList();
}
$authorizedLocaleList = array();
foreach ($this->getLocaleList() as $locale) {
if ($securityChecker->isGranted(self::getRoleForLocale($locale))) {
$authorizedLocaleList[] = $locale;
}
}
return $authorizedLocaleList;
}
|
php
|
public function getAuthorizedLocaleList($securityChecker)
{
$this->validateSecurityChecker($securityChecker);
if (!$securityChecker || !$this->isSecuredByLocale()) {
return $this->getLocaleList();
}
$authorizedLocaleList = array();
foreach ($this->getLocaleList() as $locale) {
if ($securityChecker->isGranted(self::getRoleForLocale($locale))) {
$authorizedLocaleList[] = $locale;
}
}
return $authorizedLocaleList;
}
|
[
"public",
"function",
"getAuthorizedLocaleList",
"(",
"$",
"securityChecker",
")",
"{",
"$",
"this",
"->",
"validateSecurityChecker",
"(",
"$",
"securityChecker",
")",
";",
"if",
"(",
"!",
"$",
"securityChecker",
"||",
"!",
"$",
"this",
"->",
"isSecuredByLocale",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getLocaleList",
"(",
")",
";",
"}",
"$",
"authorizedLocaleList",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getLocaleList",
"(",
")",
"as",
"$",
"locale",
")",
"{",
"if",
"(",
"$",
"securityChecker",
"->",
"isGranted",
"(",
"self",
"::",
"getRoleForLocale",
"(",
"$",
"locale",
")",
")",
")",
"{",
"$",
"authorizedLocaleList",
"[",
"]",
"=",
"$",
"locale",
";",
"}",
"}",
"return",
"$",
"authorizedLocaleList",
";",
"}"
] |
Return the list of locales authorized by the provided security context.
@param SecurityContextInterface|AuthorizationCheckerInterface|null $securityChecker
@return array
|
[
"Return",
"the",
"list",
"of",
"locales",
"authorized",
"by",
"the",
"provided",
"security",
"context",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Security/Security.php#L87-L103
|
224,856
|
liip/LiipTranslationBundle
|
Translation/Loader/XliffFileLoader.php
|
XliffFileLoader.load
|
public function load($resource, $locale, $domain = 'messages')
{
/* @var MessageCatalogue $catalogue */
$base_catalogue = parent::load($resource, $locale, $domain);
$catalogue = new MessageCatalogue($locale);
$catalogue->addCatalogue($base_catalogue);
// Process a second pass over the file to collect metadata
$xml = simplexml_load_file($resource);
$xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
// Read the attributes
$attributes = (array) $translation->attributes();
$attributes = $attributes['@attributes'];
if (!(isset($attributes['resname']) || isset($translation->source)) || !isset($translation->target)) {
continue;
}
$key = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source;
$metadata = (array) $attributes;
// read the notes
if (isset($translation->note)) {
$metadata['note'] = (string) $translation->note;
}
$catalogue->setMetadata((string) $key, $metadata, $domain);
}
return $catalogue;
}
|
php
|
public function load($resource, $locale, $domain = 'messages')
{
/* @var MessageCatalogue $catalogue */
$base_catalogue = parent::load($resource, $locale, $domain);
$catalogue = new MessageCatalogue($locale);
$catalogue->addCatalogue($base_catalogue);
// Process a second pass over the file to collect metadata
$xml = simplexml_load_file($resource);
$xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
// Read the attributes
$attributes = (array) $translation->attributes();
$attributes = $attributes['@attributes'];
if (!(isset($attributes['resname']) || isset($translation->source)) || !isset($translation->target)) {
continue;
}
$key = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source;
$metadata = (array) $attributes;
// read the notes
if (isset($translation->note)) {
$metadata['note'] = (string) $translation->note;
}
$catalogue->setMetadata((string) $key, $metadata, $domain);
}
return $catalogue;
}
|
[
"public",
"function",
"load",
"(",
"$",
"resource",
",",
"$",
"locale",
",",
"$",
"domain",
"=",
"'messages'",
")",
"{",
"/* @var MessageCatalogue $catalogue */",
"$",
"base_catalogue",
"=",
"parent",
"::",
"load",
"(",
"$",
"resource",
",",
"$",
"locale",
",",
"$",
"domain",
")",
";",
"$",
"catalogue",
"=",
"new",
"MessageCatalogue",
"(",
"$",
"locale",
")",
";",
"$",
"catalogue",
"->",
"addCatalogue",
"(",
"$",
"base_catalogue",
")",
";",
"// Process a second pass over the file to collect metadata",
"$",
"xml",
"=",
"simplexml_load_file",
"(",
"$",
"resource",
")",
";",
"$",
"xml",
"->",
"registerXPathNamespace",
"(",
"'xliff'",
",",
"'urn:oasis:names:tc:xliff:document:1.2'",
")",
";",
"foreach",
"(",
"$",
"xml",
"->",
"xpath",
"(",
"'//xliff:trans-unit'",
")",
"as",
"$",
"translation",
")",
"{",
"// Read the attributes",
"$",
"attributes",
"=",
"(",
"array",
")",
"$",
"translation",
"->",
"attributes",
"(",
")",
";",
"$",
"attributes",
"=",
"$",
"attributes",
"[",
"'@attributes'",
"]",
";",
"if",
"(",
"!",
"(",
"isset",
"(",
"$",
"attributes",
"[",
"'resname'",
"]",
")",
"||",
"isset",
"(",
"$",
"translation",
"->",
"source",
")",
")",
"||",
"!",
"isset",
"(",
"$",
"translation",
"->",
"target",
")",
")",
"{",
"continue",
";",
"}",
"$",
"key",
"=",
"isset",
"(",
"$",
"attributes",
"[",
"'resname'",
"]",
")",
"&&",
"$",
"attributes",
"[",
"'resname'",
"]",
"?",
"$",
"attributes",
"[",
"'resname'",
"]",
":",
"$",
"translation",
"->",
"source",
";",
"$",
"metadata",
"=",
"(",
"array",
")",
"$",
"attributes",
";",
"// read the notes",
"if",
"(",
"isset",
"(",
"$",
"translation",
"->",
"note",
")",
")",
"{",
"$",
"metadata",
"[",
"'note'",
"]",
"=",
"(",
"string",
")",
"$",
"translation",
"->",
"note",
";",
"}",
"$",
"catalogue",
"->",
"setMetadata",
"(",
"(",
"string",
")",
"$",
"key",
",",
"$",
"metadata",
",",
"$",
"domain",
")",
";",
"}",
"return",
"$",
"catalogue",
";",
"}"
] |
Load translations and metadata of the trans-unit.
{@inheritdoc}
@api
|
[
"Load",
"translations",
"and",
"metadata",
"of",
"the",
"trans",
"-",
"unit",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Translation/Loader/XliffFileLoader.php#L17-L46
|
224,857
|
liip/LiipTranslationBundle
|
Export/ZipExporter.php
|
ZipExporter.setUnits
|
public function setUnits($units)
{
$this->unitsByLocaleAndDomain = array();
foreach ($units as $unit) {
foreach ($unit->getTranslations() as $translation) {
$this->unitsByLocaleAndDomain[$translation->getLocale()][$translation->getDomain()][] = $translation;
}
}
}
|
php
|
public function setUnits($units)
{
$this->unitsByLocaleAndDomain = array();
foreach ($units as $unit) {
foreach ($unit->getTranslations() as $translation) {
$this->unitsByLocaleAndDomain[$translation->getLocale()][$translation->getDomain()][] = $translation;
}
}
}
|
[
"public",
"function",
"setUnits",
"(",
"$",
"units",
")",
"{",
"$",
"this",
"->",
"unitsByLocaleAndDomain",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"units",
"as",
"$",
"unit",
")",
"{",
"foreach",
"(",
"$",
"unit",
"->",
"getTranslations",
"(",
")",
"as",
"$",
"translation",
")",
"{",
"$",
"this",
"->",
"unitsByLocaleAndDomain",
"[",
"$",
"translation",
"->",
"getLocale",
"(",
")",
"]",
"[",
"$",
"translation",
"->",
"getDomain",
"(",
")",
"]",
"[",
"]",
"=",
"$",
"translation",
";",
"}",
"}",
"}"
] |
Set the units you want to export.
@param Unit[] $units
|
[
"Set",
"the",
"units",
"you",
"want",
"to",
"export",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Export/ZipExporter.php#L32-L40
|
224,858
|
liip/LiipTranslationBundle
|
Export/ZipExporter.php
|
ZipExporter.createZipContent
|
public function createZipContent()
{
$zipFile = $this->createZipFile();
$content = file_get_contents($zipFile);
unlink($zipFile);
return $content;
}
|
php
|
public function createZipContent()
{
$zipFile = $this->createZipFile();
$content = file_get_contents($zipFile);
unlink($zipFile);
return $content;
}
|
[
"public",
"function",
"createZipContent",
"(",
")",
"{",
"$",
"zipFile",
"=",
"$",
"this",
"->",
"createZipFile",
"(",
")",
";",
"$",
"content",
"=",
"file_get_contents",
"(",
"$",
"zipFile",
")",
";",
"unlink",
"(",
"$",
"zipFile",
")",
";",
"return",
"$",
"content",
";",
"}"
] |
Create the data of a zip file from the current units.
@return string The zip file content
|
[
"Create",
"the",
"data",
"of",
"a",
"zip",
"file",
"from",
"the",
"current",
"units",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Export/ZipExporter.php#L47-L54
|
224,859
|
liip/LiipTranslationBundle
|
Export/ZipExporter.php
|
ZipExporter.createZipFile
|
public function createZipFile($path = null)
{
if ($path === null) {
$path = tempnam(sys_get_temp_dir(), 'temp-zip-');
}
$zip = new \ZipArchive();
$zip->open($path, \ZipArchive::CREATE);
$this->addYmlFiles($zip);
$zip->close();
return $path;
}
|
php
|
public function createZipFile($path = null)
{
if ($path === null) {
$path = tempnam(sys_get_temp_dir(), 'temp-zip-');
}
$zip = new \ZipArchive();
$zip->open($path, \ZipArchive::CREATE);
$this->addYmlFiles($zip);
$zip->close();
return $path;
}
|
[
"public",
"function",
"createZipFile",
"(",
"$",
"path",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"path",
"===",
"null",
")",
"{",
"$",
"path",
"=",
"tempnam",
"(",
"sys_get_temp_dir",
"(",
")",
",",
"'temp-zip-'",
")",
";",
"}",
"$",
"zip",
"=",
"new",
"\\",
"ZipArchive",
"(",
")",
";",
"$",
"zip",
"->",
"open",
"(",
"$",
"path",
",",
"\\",
"ZipArchive",
"::",
"CREATE",
")",
";",
"$",
"this",
"->",
"addYmlFiles",
"(",
"$",
"zip",
")",
";",
"$",
"zip",
"->",
"close",
"(",
")",
";",
"return",
"$",
"path",
";",
"}"
] |
Create a zip file from the current units.
@param string|null $path The pathname of the file o create. If not provided, file create a temporary file
@return string The zip file content
|
[
"Create",
"a",
"zip",
"file",
"from",
"the",
"current",
"units",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Export/ZipExporter.php#L63-L74
|
224,860
|
liip/LiipTranslationBundle
|
Persistence/Propel/Model/Unit.php
|
Unit.convertToModel
|
public function convertToModel()
{
$unit = new \Liip\TranslationBundle\Model\Unit(
$this->getDomain(),
$this->getKey(),
$this->getMetadata()
);
foreach ($this->getTranslations() as $translation) {
$unit->setTranslation($translation->getLocale(), $translation->getValue());
}
return $unit;
}
|
php
|
public function convertToModel()
{
$unit = new \Liip\TranslationBundle\Model\Unit(
$this->getDomain(),
$this->getKey(),
$this->getMetadata()
);
foreach ($this->getTranslations() as $translation) {
$unit->setTranslation($translation->getLocale(), $translation->getValue());
}
return $unit;
}
|
[
"public",
"function",
"convertToModel",
"(",
")",
"{",
"$",
"unit",
"=",
"new",
"\\",
"Liip",
"\\",
"TranslationBundle",
"\\",
"Model",
"\\",
"Unit",
"(",
"$",
"this",
"->",
"getDomain",
"(",
")",
",",
"$",
"this",
"->",
"getKey",
"(",
")",
",",
"$",
"this",
"->",
"getMetadata",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getTranslations",
"(",
")",
"as",
"$",
"translation",
")",
"{",
"$",
"unit",
"->",
"setTranslation",
"(",
"$",
"translation",
"->",
"getLocale",
"(",
")",
",",
"$",
"translation",
"->",
"getValue",
"(",
")",
")",
";",
"}",
"return",
"$",
"unit",
";",
"}"
] |
Create a ModelUnit representation of a this object.
@return ModelUnit
|
[
"Create",
"a",
"ModelUnit",
"representation",
"of",
"a",
"this",
"object",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Persistence/Propel/Model/Unit.php#L30-L42
|
224,861
|
liip/LiipTranslationBundle
|
Persistence/Propel/Model/Unit.php
|
Unit.updateFromModel
|
public function updateFromModel(ModelUnit $unit)
{
$this->setDomain($unit->getDomain());
$this->setKey($unit->getKey());
$this->setMetadata($unit->getMetadata());
}
|
php
|
public function updateFromModel(ModelUnit $unit)
{
$this->setDomain($unit->getDomain());
$this->setKey($unit->getKey());
$this->setMetadata($unit->getMetadata());
}
|
[
"public",
"function",
"updateFromModel",
"(",
"ModelUnit",
"$",
"unit",
")",
"{",
"$",
"this",
"->",
"setDomain",
"(",
"$",
"unit",
"->",
"getDomain",
"(",
")",
")",
";",
"$",
"this",
"->",
"setKey",
"(",
"$",
"unit",
"->",
"getKey",
"(",
")",
")",
";",
"$",
"this",
"->",
"setMetadata",
"(",
"$",
"unit",
"->",
"getMetadata",
"(",
")",
")",
";",
"}"
] |
Update the current object from a ModelUnit.
@param ModelUnit $unit
|
[
"Update",
"the",
"current",
"object",
"from",
"a",
"ModelUnit",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Persistence/Propel/Model/Unit.php#L49-L54
|
224,862
|
liip/LiipTranslationBundle
|
Persistence/Propel/Model/Unit.php
|
Unit.getOrCreateTranslationForLocale
|
public function getOrCreateTranslationForLocale($locale)
{
foreach ($this->getTranslations() as $propelTranslation) {
if ($propelTranslation->getLocale() == $locale) {
return $propelTranslation;
}
}
$propelTranslation = new PropelTranslation();
$propelTranslation->setLocale($locale);
$this->addTranslation($propelTranslation);
return $propelTranslation;
}
|
php
|
public function getOrCreateTranslationForLocale($locale)
{
foreach ($this->getTranslations() as $propelTranslation) {
if ($propelTranslation->getLocale() == $locale) {
return $propelTranslation;
}
}
$propelTranslation = new PropelTranslation();
$propelTranslation->setLocale($locale);
$this->addTranslation($propelTranslation);
return $propelTranslation;
}
|
[
"public",
"function",
"getOrCreateTranslationForLocale",
"(",
"$",
"locale",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getTranslations",
"(",
")",
"as",
"$",
"propelTranslation",
")",
"{",
"if",
"(",
"$",
"propelTranslation",
"->",
"getLocale",
"(",
")",
"==",
"$",
"locale",
")",
"{",
"return",
"$",
"propelTranslation",
";",
"}",
"}",
"$",
"propelTranslation",
"=",
"new",
"PropelTranslation",
"(",
")",
";",
"$",
"propelTranslation",
"->",
"setLocale",
"(",
"$",
"locale",
")",
";",
"$",
"this",
"->",
"addTranslation",
"(",
"$",
"propelTranslation",
")",
";",
"return",
"$",
"propelTranslation",
";",
"}"
] |
Get or create a Propel Tranlation object for the given locale.
@param string $locale
@return Translation
|
[
"Get",
"or",
"create",
"a",
"Propel",
"Tranlation",
"object",
"for",
"the",
"given",
"locale",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Persistence/Propel/Model/Unit.php#L63-L76
|
224,863
|
RikudouSage/QrPaymentSK
|
src/QrPayment.php
|
QrPayment.getIBAN
|
public function getIBAN()
{
if (!is_null($this->iban)) {
return $this->iban;
}
$this->country = strtoupper($this->country);
$part1 = ord($this->country[0]) - ord('A') + 10;
$part2 = ord($this->country[1]) - ord('A') + 10;
$accountPrefix = 0;
$accountNumber = $this->account;
if (strpos($accountNumber, '-') !== false) {
$accountParts = explode('-', $accountNumber);
$accountPrefix = $accountParts[0];
$accountNumber = $accountParts[1];
}
$numeric = sprintf('%04d%06d%010d%d%d00', $this->bank, $accountPrefix, $accountNumber, $part1, $part2);
$mod = '';
foreach (str_split($numeric) as $n) {
$mod = ($mod . $n) % 97;
}
$mod = intval($mod);
$this->iban = sprintf('%.2s%02d%04d%06d%010d', $this->country, 98 - $mod, $this->bank, $accountPrefix, $accountNumber);
return $this->iban;
}
|
php
|
public function getIBAN()
{
if (!is_null($this->iban)) {
return $this->iban;
}
$this->country = strtoupper($this->country);
$part1 = ord($this->country[0]) - ord('A') + 10;
$part2 = ord($this->country[1]) - ord('A') + 10;
$accountPrefix = 0;
$accountNumber = $this->account;
if (strpos($accountNumber, '-') !== false) {
$accountParts = explode('-', $accountNumber);
$accountPrefix = $accountParts[0];
$accountNumber = $accountParts[1];
}
$numeric = sprintf('%04d%06d%010d%d%d00', $this->bank, $accountPrefix, $accountNumber, $part1, $part2);
$mod = '';
foreach (str_split($numeric) as $n) {
$mod = ($mod . $n) % 97;
}
$mod = intval($mod);
$this->iban = sprintf('%.2s%02d%04d%06d%010d', $this->country, 98 - $mod, $this->bank, $accountPrefix, $accountNumber);
return $this->iban;
}
|
[
"public",
"function",
"getIBAN",
"(",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"iban",
")",
")",
"{",
"return",
"$",
"this",
"->",
"iban",
";",
"}",
"$",
"this",
"->",
"country",
"=",
"strtoupper",
"(",
"$",
"this",
"->",
"country",
")",
";",
"$",
"part1",
"=",
"ord",
"(",
"$",
"this",
"->",
"country",
"[",
"0",
"]",
")",
"-",
"ord",
"(",
"'A'",
")",
"+",
"10",
";",
"$",
"part2",
"=",
"ord",
"(",
"$",
"this",
"->",
"country",
"[",
"1",
"]",
")",
"-",
"ord",
"(",
"'A'",
")",
"+",
"10",
";",
"$",
"accountPrefix",
"=",
"0",
";",
"$",
"accountNumber",
"=",
"$",
"this",
"->",
"account",
";",
"if",
"(",
"strpos",
"(",
"$",
"accountNumber",
",",
"'-'",
")",
"!==",
"false",
")",
"{",
"$",
"accountParts",
"=",
"explode",
"(",
"'-'",
",",
"$",
"accountNumber",
")",
";",
"$",
"accountPrefix",
"=",
"$",
"accountParts",
"[",
"0",
"]",
";",
"$",
"accountNumber",
"=",
"$",
"accountParts",
"[",
"1",
"]",
";",
"}",
"$",
"numeric",
"=",
"sprintf",
"(",
"'%04d%06d%010d%d%d00'",
",",
"$",
"this",
"->",
"bank",
",",
"$",
"accountPrefix",
",",
"$",
"accountNumber",
",",
"$",
"part1",
",",
"$",
"part2",
")",
";",
"$",
"mod",
"=",
"''",
";",
"foreach",
"(",
"str_split",
"(",
"$",
"numeric",
")",
"as",
"$",
"n",
")",
"{",
"$",
"mod",
"=",
"(",
"$",
"mod",
".",
"$",
"n",
")",
"%",
"97",
";",
"}",
"$",
"mod",
"=",
"intval",
"(",
"$",
"mod",
")",
";",
"$",
"this",
"->",
"iban",
"=",
"sprintf",
"(",
"'%.2s%02d%04d%06d%010d'",
",",
"$",
"this",
"->",
"country",
",",
"98",
"-",
"$",
"mod",
",",
"$",
"this",
"->",
"bank",
",",
"$",
"accountPrefix",
",",
"$",
"accountNumber",
")",
";",
"return",
"$",
"this",
"->",
"iban",
";",
"}"
] |
Converts account and bank numbers to IBAN
@return string
|
[
"Converts",
"account",
"and",
"bank",
"numbers",
"to",
"IBAN"
] |
88b04b88f4110481f500f67f27f19a1d8df1778e
|
https://github.com/RikudouSage/QrPaymentSK/blob/88b04b88f4110481f500f67f27f19a1d8df1778e/src/QrPayment.php#L164-L193
|
224,864
|
mrteye/GDAX
|
src/AppCurl.php
|
AppCurl.resetConnection
|
public function resetConnection() {
$this->reset();
// Get quicker feedback when the API is down. (sandbox or other)
$this->setOpt(CURLOPT_TIMEOUT_MS, $this->timeout);
$this->setHeader("Content-Type", "application/json");
}
|
php
|
public function resetConnection() {
$this->reset();
// Get quicker feedback when the API is down. (sandbox or other)
$this->setOpt(CURLOPT_TIMEOUT_MS, $this->timeout);
$this->setHeader("Content-Type", "application/json");
}
|
[
"public",
"function",
"resetConnection",
"(",
")",
"{",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"// Get quicker feedback when the API is down. (sandbox or other)",
"$",
"this",
"->",
"setOpt",
"(",
"CURLOPT_TIMEOUT_MS",
",",
"$",
"this",
"->",
"timeout",
")",
";",
"$",
"this",
"->",
"setHeader",
"(",
"\"Content-Type\"",
",",
"\"application/json\"",
")",
";",
"}"
] |
Reset the curl connection.
|
[
"Reset",
"the",
"curl",
"connection",
"."
] |
891e5e95abb4a0fc8d4e5b937d8f143701460824
|
https://github.com/mrteye/GDAX/blob/891e5e95abb4a0fc8d4e5b937d8f143701460824/src/AppCurl.php#L20-L27
|
224,865
|
jasny/error-handler
|
src/ErrorHandler.php
|
ErrorHandler.setError
|
public function setError($error)
{
if (isset($error) && !$error instanceof \Error && !$error instanceof \Exception) {
$type = (is_object($error) ? get_class($error) . ' ' : '') . gettype($error);
trigger_error("Excpeted an Error or Exception, got a $type", E_USER_WARNING);
return;
}
$this->error = $error;
}
|
php
|
public function setError($error)
{
if (isset($error) && !$error instanceof \Error && !$error instanceof \Exception) {
$type = (is_object($error) ? get_class($error) . ' ' : '') . gettype($error);
trigger_error("Excpeted an Error or Exception, got a $type", E_USER_WARNING);
return;
}
$this->error = $error;
}
|
[
"public",
"function",
"setError",
"(",
"$",
"error",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"error",
")",
"&&",
"!",
"$",
"error",
"instanceof",
"\\",
"Error",
"&&",
"!",
"$",
"error",
"instanceof",
"\\",
"Exception",
")",
"{",
"$",
"type",
"=",
"(",
"is_object",
"(",
"$",
"error",
")",
"?",
"get_class",
"(",
"$",
"error",
")",
".",
"' '",
":",
"''",
")",
".",
"gettype",
"(",
"$",
"error",
")",
";",
"trigger_error",
"(",
"\"Excpeted an Error or Exception, got a $type\"",
",",
"E_USER_WARNING",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"error",
"=",
"$",
"error",
";",
"}"
] |
Set the caught error
@param \Throwable|\Exception|\Error
|
[
"Set",
"the",
"caught",
"error"
] |
38e076fc36d86689010081bc2eab96f12d97b0d8
|
https://github.com/jasny/error-handler/blob/38e076fc36d86689010081bc2eab96f12d97b0d8/src/ErrorHandler.php#L38-L47
|
224,866
|
jasny/error-handler
|
src/ErrorHandler.php
|
ErrorHandler.onFatalError
|
public function onFatalError($callback, $clearOutput = false)
{
if (!$clearOutput) {
$this->onFatalError = $callback;
} else {
$this->onFatalError = function ($error) use ($callback) {
$this->clearOutputBuffer();
$callback($error);
};
}
}
|
php
|
public function onFatalError($callback, $clearOutput = false)
{
if (!$clearOutput) {
$this->onFatalError = $callback;
} else {
$this->onFatalError = function ($error) use ($callback) {
$this->clearOutputBuffer();
$callback($error);
};
}
}
|
[
"public",
"function",
"onFatalError",
"(",
"$",
"callback",
",",
"$",
"clearOutput",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"clearOutput",
")",
"{",
"$",
"this",
"->",
"onFatalError",
"=",
"$",
"callback",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"onFatalError",
"=",
"function",
"(",
"$",
"error",
")",
"use",
"(",
"$",
"callback",
")",
"{",
"$",
"this",
"->",
"clearOutputBuffer",
"(",
")",
";",
"$",
"callback",
"(",
"$",
"error",
")",
";",
"}",
";",
"}",
"}"
] |
Set a callback for when the script dies because of a fatal, non-catchable error.
The callback should have an `ErrorException` as only argument.
@param callable $callback
@param boolean $clearOutput Clear the output buffer before calling the callback
|
[
"Set",
"a",
"callback",
"for",
"when",
"the",
"script",
"dies",
"because",
"of",
"a",
"fatal",
"non",
"-",
"catchable",
"error",
".",
"The",
"callback",
"should",
"have",
"an",
"ErrorException",
"as",
"only",
"argument",
"."
] |
38e076fc36d86689010081bc2eab96f12d97b0d8
|
https://github.com/jasny/error-handler/blob/38e076fc36d86689010081bc2eab96f12d97b0d8/src/ErrorHandler.php#L93-L103
|
224,867
|
taniko/dijkstra
|
src/Graph.php
|
Graph.cost
|
public function cost(array $route) : float
{
$result = 0;
if (count($route) > 0) {
$num = count($route) -1;
for ($i = 0; $i < $num; $i++) {
if (!isset($this->nodes[$route[$i]][$route[$i+1]])) {
throw new \UnexpectedValueException("edge from {$route[$i]} to {$route[$i+1]} does not exist");
}
$result += $this->nodes[$route[$i]][$route[$i+1]];
}
}
return floatval($result);
}
|
php
|
public function cost(array $route) : float
{
$result = 0;
if (count($route) > 0) {
$num = count($route) -1;
for ($i = 0; $i < $num; $i++) {
if (!isset($this->nodes[$route[$i]][$route[$i+1]])) {
throw new \UnexpectedValueException("edge from {$route[$i]} to {$route[$i+1]} does not exist");
}
$result += $this->nodes[$route[$i]][$route[$i+1]];
}
}
return floatval($result);
}
|
[
"public",
"function",
"cost",
"(",
"array",
"$",
"route",
")",
":",
"float",
"{",
"$",
"result",
"=",
"0",
";",
"if",
"(",
"count",
"(",
"$",
"route",
")",
">",
"0",
")",
"{",
"$",
"num",
"=",
"count",
"(",
"$",
"route",
")",
"-",
"1",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"num",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"nodes",
"[",
"$",
"route",
"[",
"$",
"i",
"]",
"]",
"[",
"$",
"route",
"[",
"$",
"i",
"+",
"1",
"]",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"\"edge from {$route[$i]} to {$route[$i+1]} does not exist\"",
")",
";",
"}",
"$",
"result",
"+=",
"$",
"this",
"->",
"nodes",
"[",
"$",
"route",
"[",
"$",
"i",
"]",
"]",
"[",
"$",
"route",
"[",
"$",
"i",
"+",
"1",
"]",
"]",
";",
"}",
"}",
"return",
"floatval",
"(",
"$",
"result",
")",
";",
"}"
] |
calculate cost of route
@param array $route
@return float
|
[
"calculate",
"cost",
"of",
"route"
] |
7b012cb499f0dd57d03a2e3ab36534ba78c52b7f
|
https://github.com/taniko/dijkstra/blob/7b012cb499f0dd57d03a2e3ab36534ba78c52b7f/src/Graph.php#L114-L127
|
224,868
|
liip/LiipTranslationBundle
|
Persistence/Propel/Model/Translation.php
|
Translation.updateFromModel
|
public function updateFromModel(ModelTranslation $translation)
{
$this->setLocale($translation->getLocale());
$this->setValue($translation->getValue());
$this->setMetadata($translation->getMetadata());
}
|
php
|
public function updateFromModel(ModelTranslation $translation)
{
$this->setLocale($translation->getLocale());
$this->setValue($translation->getValue());
$this->setMetadata($translation->getMetadata());
}
|
[
"public",
"function",
"updateFromModel",
"(",
"ModelTranslation",
"$",
"translation",
")",
"{",
"$",
"this",
"->",
"setLocale",
"(",
"$",
"translation",
"->",
"getLocale",
"(",
")",
")",
";",
"$",
"this",
"->",
"setValue",
"(",
"$",
"translation",
"->",
"getValue",
"(",
")",
")",
";",
"$",
"this",
"->",
"setMetadata",
"(",
"$",
"translation",
"->",
"getMetadata",
"(",
")",
")",
";",
"}"
] |
Update this object from a ModelTranslation.
@param ModelTranslation $translation
|
[
"Update",
"this",
"object",
"from",
"a",
"ModelTranslation",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Persistence/Propel/Model/Translation.php#L29-L34
|
224,869
|
umulmrum/holiday
|
src/Model/HolidayList.php
|
HolidayList.add
|
public function add(Holiday $holiday)
{
if (-1 !== $index = $this->getIndexByNameAndDate($holiday->getName(), $holiday->getDate())) {
$this->holidayList[$index] = new Holiday($holiday->getName(), $holiday->getDate(), $holiday->getType() | $this->holidayList[$index]->getType());
} else {
$this->holidayList[] = $holiday;
}
}
|
php
|
public function add(Holiday $holiday)
{
if (-1 !== $index = $this->getIndexByNameAndDate($holiday->getName(), $holiday->getDate())) {
$this->holidayList[$index] = new Holiday($holiday->getName(), $holiday->getDate(), $holiday->getType() | $this->holidayList[$index]->getType());
} else {
$this->holidayList[] = $holiday;
}
}
|
[
"public",
"function",
"add",
"(",
"Holiday",
"$",
"holiday",
")",
"{",
"if",
"(",
"-",
"1",
"!==",
"$",
"index",
"=",
"$",
"this",
"->",
"getIndexByNameAndDate",
"(",
"$",
"holiday",
"->",
"getName",
"(",
")",
",",
"$",
"holiday",
"->",
"getDate",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"holidayList",
"[",
"$",
"index",
"]",
"=",
"new",
"Holiday",
"(",
"$",
"holiday",
"->",
"getName",
"(",
")",
",",
"$",
"holiday",
"->",
"getDate",
"(",
")",
",",
"$",
"holiday",
"->",
"getType",
"(",
")",
"|",
"$",
"this",
"->",
"holidayList",
"[",
"$",
"index",
"]",
"->",
"getType",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"holidayList",
"[",
"]",
"=",
"$",
"holiday",
";",
"}",
"}"
] |
Adds a holiday to the list. If there already is a holiday with the same name and date, then the holiday will
not be added a second time, but its types will be added to the existing one.
@param Holiday $holiday
|
[
"Adds",
"a",
"holiday",
"to",
"the",
"list",
".",
"If",
"there",
"already",
"is",
"a",
"holiday",
"with",
"the",
"same",
"name",
"and",
"date",
"then",
"the",
"holiday",
"will",
"not",
"be",
"added",
"a",
"second",
"time",
"but",
"its",
"types",
"will",
"be",
"added",
"to",
"the",
"existing",
"one",
"."
] |
19bd2f0259c0e01d4b984876b014d636c53a2be3
|
https://github.com/umulmrum/holiday/blob/19bd2f0259c0e01d4b984876b014d636c53a2be3/src/Model/HolidayList.php#L40-L47
|
224,870
|
itbdw/laravel-storage-qiniu
|
src/QiniuAdapter.php
|
QiniuAdapter.fetch
|
public function fetch($url, $key)
{
$bucketMgr = $this->getBucketManager();
list($ret, $err) = $bucketMgr->fetch($url, $this->bucket, $key);
if ($err !== null) {
$this->logQiniuError($err);
return false;
} else {
return $ret['key'];
}
}
|
php
|
public function fetch($url, $key)
{
$bucketMgr = $this->getBucketManager();
list($ret, $err) = $bucketMgr->fetch($url, $this->bucket, $key);
if ($err !== null) {
$this->logQiniuError($err);
return false;
} else {
return $ret['key'];
}
}
|
[
"public",
"function",
"fetch",
"(",
"$",
"url",
",",
"$",
"key",
")",
"{",
"$",
"bucketMgr",
"=",
"$",
"this",
"->",
"getBucketManager",
"(",
")",
";",
"list",
"(",
"$",
"ret",
",",
"$",
"err",
")",
"=",
"$",
"bucketMgr",
"->",
"fetch",
"(",
"$",
"url",
",",
"$",
"this",
"->",
"bucket",
",",
"$",
"key",
")",
";",
"if",
"(",
"$",
"err",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"logQiniuError",
"(",
"$",
"err",
")",
";",
"return",
"false",
";",
"}",
"else",
"{",
"return",
"$",
"ret",
"[",
"'key'",
"]",
";",
"}",
"}"
] |
Fetch a file from url.
@param string $url The specified url.
@param string $key The target filename.
@return string|false
|
[
"Fetch",
"a",
"file",
"from",
"url",
"."
] |
9c0b49b1423532fd095ca4886109ec641bf5b3c6
|
https://github.com/itbdw/laravel-storage-qiniu/blob/9c0b49b1423532fd095ca4886109ec641bf5b3c6/src/QiniuAdapter.php#L212-L222
|
224,871
|
notamedia/yii2-relation
|
RelationBehavior.php
|
RelationBehavior.getRelationData
|
public function getRelationData($attribute)
{
return isset($this->relationalData[$attribute]) ? $this->relationalData[$attribute]['data'] : null;
}
|
php
|
public function getRelationData($attribute)
{
return isset($this->relationalData[$attribute]) ? $this->relationalData[$attribute]['data'] : null;
}
|
[
"public",
"function",
"getRelationData",
"(",
"$",
"attribute",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"relationalData",
"[",
"$",
"attribute",
"]",
")",
"?",
"$",
"this",
"->",
"relationalData",
"[",
"$",
"attribute",
"]",
"[",
"'data'",
"]",
":",
"null",
";",
"}"
] |
Return relation data of attribute
@param $attribute string
@return mixed|null
|
[
"Return",
"relation",
"data",
"of",
"attribute"
] |
ed8050df0b63df5e76cbb088ab03de5c7ab61b7b
|
https://github.com/notamedia/yii2-relation/blob/ed8050df0b63df5e76cbb088ab03de5c7ab61b7b/RelationBehavior.php#L128-L131
|
224,872
|
notamedia/yii2-relation
|
RelationBehavior.php
|
RelationBehavior.canSetProperty
|
public function canSetProperty($name, $checkVars = true)
{
return array_key_exists($name, $this->relationalFields) || parent::canSetProperty($name, $checkVars);
}
|
php
|
public function canSetProperty($name, $checkVars = true)
{
return array_key_exists($name, $this->relationalFields) || parent::canSetProperty($name, $checkVars);
}
|
[
"public",
"function",
"canSetProperty",
"(",
"$",
"name",
",",
"$",
"checkVars",
"=",
"true",
")",
"{",
"return",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"relationalFields",
")",
"||",
"parent",
"::",
"canSetProperty",
"(",
"$",
"name",
",",
"$",
"checkVars",
")",
";",
"}"
] |
Permission for this behavior to set relational attributes.
{@inheritdoc}
|
[
"Permission",
"for",
"this",
"behavior",
"to",
"set",
"relational",
"attributes",
"."
] |
ed8050df0b63df5e76cbb088ab03de5c7ab61b7b
|
https://github.com/notamedia/yii2-relation/blob/ed8050df0b63df5e76cbb088ab03de5c7ab61b7b/RelationBehavior.php#L156-L159
|
224,873
|
notamedia/yii2-relation
|
RelationBehavior.php
|
RelationBehavior.loadData
|
protected function loadData()
{
/** @var ActiveQuery $activeQuery */
foreach ($this->relationalData as $attribute => &$data) {
$getter = 'get' . ucfirst($attribute);
$data['activeQuery'] = $activeQuery = $this->owner->$getter();
$data['newModels'] = [];
$data['oldModels'] = [];
$data['newRows'] = [];
$data['oldRows'] = [];
if (!$this->validateOnCondition($activeQuery)) {
Yii::$app->getDb()->getTransaction()->rollBack();
throw new RelationException('ON condition for attribute ' . $attribute . ' must be associative array');
}
if ($activeQuery->multiple) {
if (empty($activeQuery->via)) { // one-to-many
$this->loadModelsOneToMany($attribute);
} else { // many-to-many
if ($activeQuery->via instanceof ActiveQueryInterface) { // viaTable
$this->loadModelsManyToManyViaTable($attribute);
} else { // via
$this->loadModelsManyToManyVia($attribute);
}
}
} elseif (!empty($data['data'])) {
// one-to-one
$this->loadModelsOneToOne($attribute);
}
if (empty($activeQuery->via)) {
$data['oldModels'] = $activeQuery->all();
}
unset($data['data']);
foreach ($data['newModels'] as $i => $model) {
$data['newModels'][$i] = $this->replaceExistingModel($model, $attribute);
}
}
}
|
php
|
protected function loadData()
{
/** @var ActiveQuery $activeQuery */
foreach ($this->relationalData as $attribute => &$data) {
$getter = 'get' . ucfirst($attribute);
$data['activeQuery'] = $activeQuery = $this->owner->$getter();
$data['newModels'] = [];
$data['oldModels'] = [];
$data['newRows'] = [];
$data['oldRows'] = [];
if (!$this->validateOnCondition($activeQuery)) {
Yii::$app->getDb()->getTransaction()->rollBack();
throw new RelationException('ON condition for attribute ' . $attribute . ' must be associative array');
}
if ($activeQuery->multiple) {
if (empty($activeQuery->via)) { // one-to-many
$this->loadModelsOneToMany($attribute);
} else { // many-to-many
if ($activeQuery->via instanceof ActiveQueryInterface) { // viaTable
$this->loadModelsManyToManyViaTable($attribute);
} else { // via
$this->loadModelsManyToManyVia($attribute);
}
}
} elseif (!empty($data['data'])) {
// one-to-one
$this->loadModelsOneToOne($attribute);
}
if (empty($activeQuery->via)) {
$data['oldModels'] = $activeQuery->all();
}
unset($data['data']);
foreach ($data['newModels'] as $i => $model) {
$data['newModels'][$i] = $this->replaceExistingModel($model, $attribute);
}
}
}
|
[
"protected",
"function",
"loadData",
"(",
")",
"{",
"/** @var ActiveQuery $activeQuery */",
"foreach",
"(",
"$",
"this",
"->",
"relationalData",
"as",
"$",
"attribute",
"=>",
"&",
"$",
"data",
")",
"{",
"$",
"getter",
"=",
"'get'",
".",
"ucfirst",
"(",
"$",
"attribute",
")",
";",
"$",
"data",
"[",
"'activeQuery'",
"]",
"=",
"$",
"activeQuery",
"=",
"$",
"this",
"->",
"owner",
"->",
"$",
"getter",
"(",
")",
";",
"$",
"data",
"[",
"'newModels'",
"]",
"=",
"[",
"]",
";",
"$",
"data",
"[",
"'oldModels'",
"]",
"=",
"[",
"]",
";",
"$",
"data",
"[",
"'newRows'",
"]",
"=",
"[",
"]",
";",
"$",
"data",
"[",
"'oldRows'",
"]",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"validateOnCondition",
"(",
"$",
"activeQuery",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"getDb",
"(",
")",
"->",
"getTransaction",
"(",
")",
"->",
"rollBack",
"(",
")",
";",
"throw",
"new",
"RelationException",
"(",
"'ON condition for attribute '",
".",
"$",
"attribute",
".",
"' must be associative array'",
")",
";",
"}",
"if",
"(",
"$",
"activeQuery",
"->",
"multiple",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"activeQuery",
"->",
"via",
")",
")",
"{",
"// one-to-many",
"$",
"this",
"->",
"loadModelsOneToMany",
"(",
"$",
"attribute",
")",
";",
"}",
"else",
"{",
"// many-to-many",
"if",
"(",
"$",
"activeQuery",
"->",
"via",
"instanceof",
"ActiveQueryInterface",
")",
"{",
"// viaTable",
"$",
"this",
"->",
"loadModelsManyToManyViaTable",
"(",
"$",
"attribute",
")",
";",
"}",
"else",
"{",
"// via",
"$",
"this",
"->",
"loadModelsManyToManyVia",
"(",
"$",
"attribute",
")",
";",
"}",
"}",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'data'",
"]",
")",
")",
"{",
"// one-to-one",
"$",
"this",
"->",
"loadModelsOneToOne",
"(",
"$",
"attribute",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"activeQuery",
"->",
"via",
")",
")",
"{",
"$",
"data",
"[",
"'oldModels'",
"]",
"=",
"$",
"activeQuery",
"->",
"all",
"(",
")",
";",
"}",
"unset",
"(",
"$",
"data",
"[",
"'data'",
"]",
")",
";",
"foreach",
"(",
"$",
"data",
"[",
"'newModels'",
"]",
"as",
"$",
"i",
"=>",
"$",
"model",
")",
"{",
"$",
"data",
"[",
"'newModels'",
"]",
"[",
"$",
"i",
"]",
"=",
"$",
"this",
"->",
"replaceExistingModel",
"(",
"$",
"model",
",",
"$",
"attribute",
")",
";",
"}",
"}",
"}"
] |
Load relational data from owner-model getter.
- Create related ActiveRecord objects from POST array data.
- Load existing related ActiveRecord objects from database.
- Check ON condition format.
- Get ActiveQuery object from attribute getter method.
Fill $this->relationalData array for each relational attribute:
```php
$this->relationalData[$attribute] = [
'newModels' => ActiveRecord[],
'oldModels' => ActiveRecord[],
'activeQuery' => ActiveQuery,
];
```
@throws RelationException
|
[
"Load",
"relational",
"data",
"from",
"owner",
"-",
"model",
"getter",
"."
] |
ed8050df0b63df5e76cbb088ab03de5c7ab61b7b
|
https://github.com/notamedia/yii2-relation/blob/ed8050df0b63df5e76cbb088ab03de5c7ab61b7b/RelationBehavior.php#L206-L248
|
224,874
|
notamedia/yii2-relation
|
RelationBehavior.php
|
RelationBehavior.validateData
|
protected function validateData()
{
foreach ($this->relationalData as $attribute => &$data) {
/** @var ActiveRecord $model */
/** @var ActiveQuery $activeQuery */
$activeQuery = $data['activeQuery'];
foreach ($data['newModels'] as &$model) {
if (!$model->validate()) {
$_errors = $model->getErrors();
$errors = [];
foreach ($_errors as $relatedAttribute => $error) {
if (!$activeQuery->multiple || !isset($activeQuery->link[$relatedAttribute])) {
$errors[$relatedAttribute] = $error;
}
}
if (count($errors)) {
$this->owner->addError($attribute, $errors);
return false;
}
}
}
}
return true;
}
|
php
|
protected function validateData()
{
foreach ($this->relationalData as $attribute => &$data) {
/** @var ActiveRecord $model */
/** @var ActiveQuery $activeQuery */
$activeQuery = $data['activeQuery'];
foreach ($data['newModels'] as &$model) {
if (!$model->validate()) {
$_errors = $model->getErrors();
$errors = [];
foreach ($_errors as $relatedAttribute => $error) {
if (!$activeQuery->multiple || !isset($activeQuery->link[$relatedAttribute])) {
$errors[$relatedAttribute] = $error;
}
}
if (count($errors)) {
$this->owner->addError($attribute, $errors);
return false;
}
}
}
}
return true;
}
|
[
"protected",
"function",
"validateData",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"relationalData",
"as",
"$",
"attribute",
"=>",
"&",
"$",
"data",
")",
"{",
"/** @var ActiveRecord $model */",
"/** @var ActiveQuery $activeQuery */",
"$",
"activeQuery",
"=",
"$",
"data",
"[",
"'activeQuery'",
"]",
";",
"foreach",
"(",
"$",
"data",
"[",
"'newModels'",
"]",
"as",
"&",
"$",
"model",
")",
"{",
"if",
"(",
"!",
"$",
"model",
"->",
"validate",
"(",
")",
")",
"{",
"$",
"_errors",
"=",
"$",
"model",
"->",
"getErrors",
"(",
")",
";",
"$",
"errors",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"_errors",
"as",
"$",
"relatedAttribute",
"=>",
"$",
"error",
")",
"{",
"if",
"(",
"!",
"$",
"activeQuery",
"->",
"multiple",
"||",
"!",
"isset",
"(",
"$",
"activeQuery",
"->",
"link",
"[",
"$",
"relatedAttribute",
"]",
")",
")",
"{",
"$",
"errors",
"[",
"$",
"relatedAttribute",
"]",
"=",
"$",
"error",
";",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"errors",
")",
")",
"{",
"$",
"this",
"->",
"owner",
"->",
"addError",
"(",
"$",
"attribute",
",",
"$",
"errors",
")",
";",
"return",
"false",
";",
"}",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] |
Validate relational models, return true only if all models successfully validated. Skip errors for foreign
columns.
@return bool
|
[
"Validate",
"relational",
"models",
"return",
"true",
"only",
"if",
"all",
"models",
"successfully",
"validated",
".",
"Skip",
"errors",
"for",
"foreign",
"columns",
"."
] |
ed8050df0b63df5e76cbb088ab03de5c7ab61b7b
|
https://github.com/notamedia/yii2-relation/blob/ed8050df0b63df5e76cbb088ab03de5c7ab61b7b/RelationBehavior.php#L256-L283
|
224,875
|
notamedia/yii2-relation
|
RelationBehavior.php
|
RelationBehavior.saveData
|
public function saveData()
{
$needSaveOwner = false;
foreach ($this->relationalData as $attribute => $data) {
// delete models
$this->deleteModels($attribute);
// save models
$this->saveModels($attribute);
if (!$data['activeQuery']->multiple && (count($data['newModels']) == 0 || !$data['newModels'][0]->isNewRecord)) {
$needSaveOwner = true;
foreach ($data['activeQuery']->link as $childAttribute => $parentAttribute) {
$this->owner->$parentAttribute = count($data['newModels']) ? $data['newModels'][0]->$childAttribute : null;
}
}
}
$this->relationalFinished = true;
if ($needSaveOwner) {
$model = $this->owner;
$this->detach();
if (!$model->save()) {
Yii::$app->getDb()->getTransaction()->rollBack();
throw new RelationException('Owner-model ' . $model::className() . ' not saved due to unknown error');
}
}
}
|
php
|
public function saveData()
{
$needSaveOwner = false;
foreach ($this->relationalData as $attribute => $data) {
// delete models
$this->deleteModels($attribute);
// save models
$this->saveModels($attribute);
if (!$data['activeQuery']->multiple && (count($data['newModels']) == 0 || !$data['newModels'][0]->isNewRecord)) {
$needSaveOwner = true;
foreach ($data['activeQuery']->link as $childAttribute => $parentAttribute) {
$this->owner->$parentAttribute = count($data['newModels']) ? $data['newModels'][0]->$childAttribute : null;
}
}
}
$this->relationalFinished = true;
if ($needSaveOwner) {
$model = $this->owner;
$this->detach();
if (!$model->save()) {
Yii::$app->getDb()->getTransaction()->rollBack();
throw new RelationException('Owner-model ' . $model::className() . ' not saved due to unknown error');
}
}
}
|
[
"public",
"function",
"saveData",
"(",
")",
"{",
"$",
"needSaveOwner",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"relationalData",
"as",
"$",
"attribute",
"=>",
"$",
"data",
")",
"{",
"// delete models",
"$",
"this",
"->",
"deleteModels",
"(",
"$",
"attribute",
")",
";",
"// save models",
"$",
"this",
"->",
"saveModels",
"(",
"$",
"attribute",
")",
";",
"if",
"(",
"!",
"$",
"data",
"[",
"'activeQuery'",
"]",
"->",
"multiple",
"&&",
"(",
"count",
"(",
"$",
"data",
"[",
"'newModels'",
"]",
")",
"==",
"0",
"||",
"!",
"$",
"data",
"[",
"'newModels'",
"]",
"[",
"0",
"]",
"->",
"isNewRecord",
")",
")",
"{",
"$",
"needSaveOwner",
"=",
"true",
";",
"foreach",
"(",
"$",
"data",
"[",
"'activeQuery'",
"]",
"->",
"link",
"as",
"$",
"childAttribute",
"=>",
"$",
"parentAttribute",
")",
"{",
"$",
"this",
"->",
"owner",
"->",
"$",
"parentAttribute",
"=",
"count",
"(",
"$",
"data",
"[",
"'newModels'",
"]",
")",
"?",
"$",
"data",
"[",
"'newModels'",
"]",
"[",
"0",
"]",
"->",
"$",
"childAttribute",
":",
"null",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"relationalFinished",
"=",
"true",
";",
"if",
"(",
"$",
"needSaveOwner",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"owner",
";",
"$",
"this",
"->",
"detach",
"(",
")",
";",
"if",
"(",
"!",
"$",
"model",
"->",
"save",
"(",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"getDb",
"(",
")",
"->",
"getTransaction",
"(",
")",
"->",
"rollBack",
"(",
")",
";",
"throw",
"new",
"RelationException",
"(",
"'Owner-model '",
".",
"$",
"model",
"::",
"className",
"(",
")",
".",
"' not saved due to unknown error'",
")",
";",
"}",
"}",
"}"
] |
Save changed related models.
- Delete old related models, which not exist in POST array.
- Create new related models, which not exist in database.
- Update owner models for one-to-one relation.
|
[
"Save",
"changed",
"related",
"models",
"."
] |
ed8050df0b63df5e76cbb088ab03de5c7ab61b7b
|
https://github.com/notamedia/yii2-relation/blob/ed8050df0b63df5e76cbb088ab03de5c7ab61b7b/RelationBehavior.php#L292-L320
|
224,876
|
notamedia/yii2-relation
|
RelationBehavior.php
|
RelationBehavior.relationsMap
|
protected function relationsMap($relations, $callback)
{
try {
if (is_callable($callback)) {
array_map($callback, $relations);
}
} catch (\Exception $e) {
Yii::$app->getDb()->getTransaction()->rollBack();
throw new RelationException('Owner-model not saved due to unknown error');
}
}
|
php
|
protected function relationsMap($relations, $callback)
{
try {
if (is_callable($callback)) {
array_map($callback, $relations);
}
} catch (\Exception $e) {
Yii::$app->getDb()->getTransaction()->rollBack();
throw new RelationException('Owner-model not saved due to unknown error');
}
}
|
[
"protected",
"function",
"relationsMap",
"(",
"$",
"relations",
",",
"$",
"callback",
")",
"{",
"try",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"callback",
")",
")",
"{",
"array_map",
"(",
"$",
"callback",
",",
"$",
"relations",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"getDb",
"(",
")",
"->",
"getTransaction",
"(",
")",
"->",
"rollBack",
"(",
")",
";",
"throw",
"new",
"RelationException",
"(",
"'Owner-model not saved due to unknown error'",
")",
";",
"}",
"}"
] |
Execute callback for each relation
- if error occurred throws exception
@param array $relations
@param callable $callback
@throws RelationException
|
[
"Execute",
"callback",
"for",
"each",
"relation"
] |
ed8050df0b63df5e76cbb088ab03de5c7ab61b7b
|
https://github.com/notamedia/yii2-relation/blob/ed8050df0b63df5e76cbb088ab03de5c7ab61b7b/RelationBehavior.php#L331-L341
|
224,877
|
notamedia/yii2-relation
|
RelationBehavior.php
|
RelationBehavior.replaceExistingModel
|
protected function replaceExistingModel($model, $attribute)
{
$modelAttributes = $model->attributes;
unset($modelAttributes[$model->primaryKey()[0]]);
foreach ($this->relationalData[$attribute]['oldModels'] as $oldModel) {
/** @var ActiveRecord $oldModel */
$oldModelAttributes = $oldModel->attributes;
unset($oldModelAttributes[$oldModel->primaryKey()[0]]);
if ($oldModelAttributes == $modelAttributes) {
return $oldModel;
}
}
return $model;
}
|
php
|
protected function replaceExistingModel($model, $attribute)
{
$modelAttributes = $model->attributes;
unset($modelAttributes[$model->primaryKey()[0]]);
foreach ($this->relationalData[$attribute]['oldModels'] as $oldModel) {
/** @var ActiveRecord $oldModel */
$oldModelAttributes = $oldModel->attributes;
unset($oldModelAttributes[$oldModel->primaryKey()[0]]);
if ($oldModelAttributes == $modelAttributes) {
return $oldModel;
}
}
return $model;
}
|
[
"protected",
"function",
"replaceExistingModel",
"(",
"$",
"model",
",",
"$",
"attribute",
")",
"{",
"$",
"modelAttributes",
"=",
"$",
"model",
"->",
"attributes",
";",
"unset",
"(",
"$",
"modelAttributes",
"[",
"$",
"model",
"->",
"primaryKey",
"(",
")",
"[",
"0",
"]",
"]",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"relationalData",
"[",
"$",
"attribute",
"]",
"[",
"'oldModels'",
"]",
"as",
"$",
"oldModel",
")",
"{",
"/** @var ActiveRecord $oldModel */",
"$",
"oldModelAttributes",
"=",
"$",
"oldModel",
"->",
"attributes",
";",
"unset",
"(",
"$",
"oldModelAttributes",
"[",
"$",
"oldModel",
"->",
"primaryKey",
"(",
")",
"[",
"0",
"]",
"]",
")",
";",
"if",
"(",
"$",
"oldModelAttributes",
"==",
"$",
"modelAttributes",
")",
"{",
"return",
"$",
"oldModel",
";",
"}",
"}",
"return",
"$",
"model",
";",
"}"
] |
Return existing model if it found in old models
@param ActiveRecord $model
@param $attribute
@return ActiveRecord
|
[
"Return",
"existing",
"model",
"if",
"it",
"found",
"in",
"old",
"models"
] |
ed8050df0b63df5e76cbb088ab03de5c7ab61b7b
|
https://github.com/notamedia/yii2-relation/blob/ed8050df0b63df5e76cbb088ab03de5c7ab61b7b/RelationBehavior.php#L351-L367
|
224,878
|
notamedia/yii2-relation
|
RelationBehavior.php
|
RelationBehavior.isExistingRow
|
protected function isExistingRow($row, $attribute)
{
$rowAttributes = $row;
unset($rowAttributes[$this->relationalData[$attribute]['junctionColumn']]);
foreach ($this->relationalData[$attribute]['oldRows'] as $oldRow) {
$oldModelAttributes = $oldRow;
unset($oldModelAttributes[$this->relationalData[$attribute]['junctionColumn']]);
if ($oldModelAttributes == $rowAttributes) {
return true;
}
}
return false;
}
|
php
|
protected function isExistingRow($row, $attribute)
{
$rowAttributes = $row;
unset($rowAttributes[$this->relationalData[$attribute]['junctionColumn']]);
foreach ($this->relationalData[$attribute]['oldRows'] as $oldRow) {
$oldModelAttributes = $oldRow;
unset($oldModelAttributes[$this->relationalData[$attribute]['junctionColumn']]);
if ($oldModelAttributes == $rowAttributes) {
return true;
}
}
return false;
}
|
[
"protected",
"function",
"isExistingRow",
"(",
"$",
"row",
",",
"$",
"attribute",
")",
"{",
"$",
"rowAttributes",
"=",
"$",
"row",
";",
"unset",
"(",
"$",
"rowAttributes",
"[",
"$",
"this",
"->",
"relationalData",
"[",
"$",
"attribute",
"]",
"[",
"'junctionColumn'",
"]",
"]",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"relationalData",
"[",
"$",
"attribute",
"]",
"[",
"'oldRows'",
"]",
"as",
"$",
"oldRow",
")",
"{",
"$",
"oldModelAttributes",
"=",
"$",
"oldRow",
";",
"unset",
"(",
"$",
"oldModelAttributes",
"[",
"$",
"this",
"->",
"relationalData",
"[",
"$",
"attribute",
"]",
"[",
"'junctionColumn'",
"]",
"]",
")",
";",
"if",
"(",
"$",
"oldModelAttributes",
"==",
"$",
"rowAttributes",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Check existing row if it found in old rows
@param $row
@param $attribute
@return mixed
|
[
"Check",
"existing",
"row",
"if",
"it",
"found",
"in",
"old",
"rows"
] |
ed8050df0b63df5e76cbb088ab03de5c7ab61b7b
|
https://github.com/notamedia/yii2-relation/blob/ed8050df0b63df5e76cbb088ab03de5c7ab61b7b/RelationBehavior.php#L376-L390
|
224,879
|
notamedia/yii2-relation
|
RelationBehavior.php
|
RelationBehavior.afterDelete
|
public function afterDelete()
{
foreach ($this->relationalFields as $attribute => $value) {
$getter = 'get' . ucfirst($attribute);
/** @var ActiveQuery $activeQuery */
$activeQuery = $this->owner->$getter();
$models = [];
if (empty($activeQuery->via)) {
$models = $activeQuery->all();
} else {
if ($activeQuery->via instanceof ActiveQueryInterface) { // viaTable
$junctionTable = $activeQuery->via->from[0];
list($junctionColumn) = array_keys($activeQuery->via->link);
list($relatedColumn) = array_values($activeQuery->link);
$rows = (new Query())
->from($junctionTable)
->select([
$junctionColumn,
$relatedColumn
])
->where([
$junctionColumn => $this->owner->getPrimaryKey(),
])->all();
$this->relationsMap($rows, function($row) use ($junctionTable) {
Yii::$app->db->createCommand()
->delete($junctionTable, $row)
->execute();
});
} else { // via
$junctionGetter = 'get' . ucfirst($activeQuery->via[0]);
$models = $this->owner->$junctionGetter()->all();
}
}
foreach ($models as $model) {
if (!$model->delete()) {
Yii::$app->getDb()->getTransaction()->rollBack();
throw new RelationException('Model ' . $model::className() . ' not deleted due to unknown error');
}
}
}
}
|
php
|
public function afterDelete()
{
foreach ($this->relationalFields as $attribute => $value) {
$getter = 'get' . ucfirst($attribute);
/** @var ActiveQuery $activeQuery */
$activeQuery = $this->owner->$getter();
$models = [];
if (empty($activeQuery->via)) {
$models = $activeQuery->all();
} else {
if ($activeQuery->via instanceof ActiveQueryInterface) { // viaTable
$junctionTable = $activeQuery->via->from[0];
list($junctionColumn) = array_keys($activeQuery->via->link);
list($relatedColumn) = array_values($activeQuery->link);
$rows = (new Query())
->from($junctionTable)
->select([
$junctionColumn,
$relatedColumn
])
->where([
$junctionColumn => $this->owner->getPrimaryKey(),
])->all();
$this->relationsMap($rows, function($row) use ($junctionTable) {
Yii::$app->db->createCommand()
->delete($junctionTable, $row)
->execute();
});
} else { // via
$junctionGetter = 'get' . ucfirst($activeQuery->via[0]);
$models = $this->owner->$junctionGetter()->all();
}
}
foreach ($models as $model) {
if (!$model->delete()) {
Yii::$app->getDb()->getTransaction()->rollBack();
throw new RelationException('Model ' . $model::className() . ' not deleted due to unknown error');
}
}
}
}
|
[
"public",
"function",
"afterDelete",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"relationalFields",
"as",
"$",
"attribute",
"=>",
"$",
"value",
")",
"{",
"$",
"getter",
"=",
"'get'",
".",
"ucfirst",
"(",
"$",
"attribute",
")",
";",
"/** @var ActiveQuery $activeQuery */",
"$",
"activeQuery",
"=",
"$",
"this",
"->",
"owner",
"->",
"$",
"getter",
"(",
")",
";",
"$",
"models",
"=",
"[",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"activeQuery",
"->",
"via",
")",
")",
"{",
"$",
"models",
"=",
"$",
"activeQuery",
"->",
"all",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"activeQuery",
"->",
"via",
"instanceof",
"ActiveQueryInterface",
")",
"{",
"// viaTable",
"$",
"junctionTable",
"=",
"$",
"activeQuery",
"->",
"via",
"->",
"from",
"[",
"0",
"]",
";",
"list",
"(",
"$",
"junctionColumn",
")",
"=",
"array_keys",
"(",
"$",
"activeQuery",
"->",
"via",
"->",
"link",
")",
";",
"list",
"(",
"$",
"relatedColumn",
")",
"=",
"array_values",
"(",
"$",
"activeQuery",
"->",
"link",
")",
";",
"$",
"rows",
"=",
"(",
"new",
"Query",
"(",
")",
")",
"->",
"from",
"(",
"$",
"junctionTable",
")",
"->",
"select",
"(",
"[",
"$",
"junctionColumn",
",",
"$",
"relatedColumn",
"]",
")",
"->",
"where",
"(",
"[",
"$",
"junctionColumn",
"=>",
"$",
"this",
"->",
"owner",
"->",
"getPrimaryKey",
"(",
")",
",",
"]",
")",
"->",
"all",
"(",
")",
";",
"$",
"this",
"->",
"relationsMap",
"(",
"$",
"rows",
",",
"function",
"(",
"$",
"row",
")",
"use",
"(",
"$",
"junctionTable",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"db",
"->",
"createCommand",
"(",
")",
"->",
"delete",
"(",
"$",
"junctionTable",
",",
"$",
"row",
")",
"->",
"execute",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"// via",
"$",
"junctionGetter",
"=",
"'get'",
".",
"ucfirst",
"(",
"$",
"activeQuery",
"->",
"via",
"[",
"0",
"]",
")",
";",
"$",
"models",
"=",
"$",
"this",
"->",
"owner",
"->",
"$",
"junctionGetter",
"(",
")",
"->",
"all",
"(",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"models",
"as",
"$",
"model",
")",
"{",
"if",
"(",
"!",
"$",
"model",
"->",
"delete",
"(",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"getDb",
"(",
")",
"->",
"getTransaction",
"(",
")",
"->",
"rollBack",
"(",
")",
";",
"throw",
"new",
"RelationException",
"(",
"'Model '",
".",
"$",
"model",
"::",
"className",
"(",
")",
".",
"' not deleted due to unknown error'",
")",
";",
"}",
"}",
"}",
"}"
] |
Delete related models. Rollback transaction and throw RelationException, if error occurred while deleting.
|
[
"Delete",
"related",
"models",
".",
"Rollback",
"transaction",
"and",
"throw",
"RelationException",
"if",
"error",
"occurred",
"while",
"deleting",
"."
] |
ed8050df0b63df5e76cbb088ab03de5c7ab61b7b
|
https://github.com/notamedia/yii2-relation/blob/ed8050df0b63df5e76cbb088ab03de5c7ab61b7b/RelationBehavior.php#L444-L490
|
224,880
|
notamedia/yii2-relation
|
RelationBehavior.php
|
RelationBehavior.validateOnCondition
|
protected function validateOnCondition($activeQuery)
{
if (
!ArrayHelper::isAssociative($activeQuery->on) &&
!empty($activeQuery->on)
) {
return false;
}
if (
$activeQuery->multiple &&
!empty($activeQuery->via) &&
is_array($activeQuery->via) &&
is_object($activeQuery->via[1]) &&
!ArrayHelper::isAssociative($activeQuery->via[1]->on) &&
!empty($activeQuery->via[1]->on)
) {
return false;
}
return true;
}
|
php
|
protected function validateOnCondition($activeQuery)
{
if (
!ArrayHelper::isAssociative($activeQuery->on) &&
!empty($activeQuery->on)
) {
return false;
}
if (
$activeQuery->multiple &&
!empty($activeQuery->via) &&
is_array($activeQuery->via) &&
is_object($activeQuery->via[1]) &&
!ArrayHelper::isAssociative($activeQuery->via[1]->on) &&
!empty($activeQuery->via[1]->on)
) {
return false;
}
return true;
}
|
[
"protected",
"function",
"validateOnCondition",
"(",
"$",
"activeQuery",
")",
"{",
"if",
"(",
"!",
"ArrayHelper",
"::",
"isAssociative",
"(",
"$",
"activeQuery",
"->",
"on",
")",
"&&",
"!",
"empty",
"(",
"$",
"activeQuery",
"->",
"on",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"activeQuery",
"->",
"multiple",
"&&",
"!",
"empty",
"(",
"$",
"activeQuery",
"->",
"via",
")",
"&&",
"is_array",
"(",
"$",
"activeQuery",
"->",
"via",
")",
"&&",
"is_object",
"(",
"$",
"activeQuery",
"->",
"via",
"[",
"1",
"]",
")",
"&&",
"!",
"ArrayHelper",
"::",
"isAssociative",
"(",
"$",
"activeQuery",
"->",
"via",
"[",
"1",
"]",
"->",
"on",
")",
"&&",
"!",
"empty",
"(",
"$",
"activeQuery",
"->",
"via",
"[",
"1",
"]",
"->",
"on",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Validate ON condition in ActiveQuery
@param ActiveQuery $activeQuery
@return bool
|
[
"Validate",
"ON",
"condition",
"in",
"ActiveQuery"
] |
ed8050df0b63df5e76cbb088ab03de5c7ab61b7b
|
https://github.com/notamedia/yii2-relation/blob/ed8050df0b63df5e76cbb088ab03de5c7ab61b7b/RelationBehavior.php#L498-L519
|
224,881
|
notamedia/yii2-relation
|
RelationBehavior.php
|
RelationBehavior.loadModelsOneToOne
|
protected function loadModelsOneToOne($attribute)
{
$data = $this->relationalData[$attribute];
$activeQuery = $data['activeQuery'];
$class = $activeQuery->modelClass;
$model = new $class($data['data']);
if (isset($this->relations[$attribute]) && is_callable($this->relations[$attribute])) {
$model = call_user_func($this->relations[$attribute], $model, $data['data']);
}
$data['newModels'][] = $model;
$this->relationalData[$attribute] = $data;
}
|
php
|
protected function loadModelsOneToOne($attribute)
{
$data = $this->relationalData[$attribute];
$activeQuery = $data['activeQuery'];
$class = $activeQuery->modelClass;
$model = new $class($data['data']);
if (isset($this->relations[$attribute]) && is_callable($this->relations[$attribute])) {
$model = call_user_func($this->relations[$attribute], $model, $data['data']);
}
$data['newModels'][] = $model;
$this->relationalData[$attribute] = $data;
}
|
[
"protected",
"function",
"loadModelsOneToOne",
"(",
"$",
"attribute",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"relationalData",
"[",
"$",
"attribute",
"]",
";",
"$",
"activeQuery",
"=",
"$",
"data",
"[",
"'activeQuery'",
"]",
";",
"$",
"class",
"=",
"$",
"activeQuery",
"->",
"modelClass",
";",
"$",
"model",
"=",
"new",
"$",
"class",
"(",
"$",
"data",
"[",
"'data'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"relations",
"[",
"$",
"attribute",
"]",
")",
"&&",
"is_callable",
"(",
"$",
"this",
"->",
"relations",
"[",
"$",
"attribute",
"]",
")",
")",
"{",
"$",
"model",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"relations",
"[",
"$",
"attribute",
"]",
",",
"$",
"model",
",",
"$",
"data",
"[",
"'data'",
"]",
")",
";",
"}",
"$",
"data",
"[",
"'newModels'",
"]",
"[",
"]",
"=",
"$",
"model",
";",
"$",
"this",
"->",
"relationalData",
"[",
"$",
"attribute",
"]",
"=",
"$",
"data",
";",
"}"
] |
Load new model from POST for one-to-one relation
@param $attribute
|
[
"Load",
"new",
"model",
"from",
"POST",
"for",
"one",
"-",
"to",
"-",
"one",
"relation"
] |
ed8050df0b63df5e76cbb088ab03de5c7ab61b7b
|
https://github.com/notamedia/yii2-relation/blob/ed8050df0b63df5e76cbb088ab03de5c7ab61b7b/RelationBehavior.php#L526-L540
|
224,882
|
notamedia/yii2-relation
|
RelationBehavior.php
|
RelationBehavior.loadModelsOneToMany
|
protected function loadModelsOneToMany($attribute)
{
$data = $this->relationalData[$attribute];
$activeQuery = $data['activeQuery'];
$class = $activeQuery->modelClass;
// default query conditions
$params = !ArrayHelper::isAssociative($activeQuery->on) ? [] : $activeQuery->on;
// one-to-many
foreach ($activeQuery->link as $childAttribute => $parentAttribute) {
$params[$childAttribute] = $this->owner->$parentAttribute;
}
if (!empty($data['data'])) {
foreach ($data['data'] as $attributes) {
$model = new $class(
array_merge(
$params,
ArrayHelper::isAssociative($attributes) ? $attributes : []
)
);
if (isset($this->relations[$attribute]) && is_callable($this->relations[$attribute])) {
$model = call_user_func($this->relations[$attribute], $model, $attributes);
}
$data['newModels'][] = $model;
}
}
$this->relationalData[$attribute] = $data;
}
|
php
|
protected function loadModelsOneToMany($attribute)
{
$data = $this->relationalData[$attribute];
$activeQuery = $data['activeQuery'];
$class = $activeQuery->modelClass;
// default query conditions
$params = !ArrayHelper::isAssociative($activeQuery->on) ? [] : $activeQuery->on;
// one-to-many
foreach ($activeQuery->link as $childAttribute => $parentAttribute) {
$params[$childAttribute] = $this->owner->$parentAttribute;
}
if (!empty($data['data'])) {
foreach ($data['data'] as $attributes) {
$model = new $class(
array_merge(
$params,
ArrayHelper::isAssociative($attributes) ? $attributes : []
)
);
if (isset($this->relations[$attribute]) && is_callable($this->relations[$attribute])) {
$model = call_user_func($this->relations[$attribute], $model, $attributes);
}
$data['newModels'][] = $model;
}
}
$this->relationalData[$attribute] = $data;
}
|
[
"protected",
"function",
"loadModelsOneToMany",
"(",
"$",
"attribute",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"relationalData",
"[",
"$",
"attribute",
"]",
";",
"$",
"activeQuery",
"=",
"$",
"data",
"[",
"'activeQuery'",
"]",
";",
"$",
"class",
"=",
"$",
"activeQuery",
"->",
"modelClass",
";",
"// default query conditions",
"$",
"params",
"=",
"!",
"ArrayHelper",
"::",
"isAssociative",
"(",
"$",
"activeQuery",
"->",
"on",
")",
"?",
"[",
"]",
":",
"$",
"activeQuery",
"->",
"on",
";",
"// one-to-many",
"foreach",
"(",
"$",
"activeQuery",
"->",
"link",
"as",
"$",
"childAttribute",
"=>",
"$",
"parentAttribute",
")",
"{",
"$",
"params",
"[",
"$",
"childAttribute",
"]",
"=",
"$",
"this",
"->",
"owner",
"->",
"$",
"parentAttribute",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'data'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"data",
"[",
"'data'",
"]",
"as",
"$",
"attributes",
")",
"{",
"$",
"model",
"=",
"new",
"$",
"class",
"(",
"array_merge",
"(",
"$",
"params",
",",
"ArrayHelper",
"::",
"isAssociative",
"(",
"$",
"attributes",
")",
"?",
"$",
"attributes",
":",
"[",
"]",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"relations",
"[",
"$",
"attribute",
"]",
")",
"&&",
"is_callable",
"(",
"$",
"this",
"->",
"relations",
"[",
"$",
"attribute",
"]",
")",
")",
"{",
"$",
"model",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"relations",
"[",
"$",
"attribute",
"]",
",",
"$",
"model",
",",
"$",
"attributes",
")",
";",
"}",
"$",
"data",
"[",
"'newModels'",
"]",
"[",
"]",
"=",
"$",
"model",
";",
"}",
"}",
"$",
"this",
"->",
"relationalData",
"[",
"$",
"attribute",
"]",
"=",
"$",
"data",
";",
"}"
] |
Load new models from POST for one-to-many relation
@param $attribute
|
[
"Load",
"new",
"models",
"from",
"POST",
"for",
"one",
"-",
"to",
"-",
"many",
"relation"
] |
ed8050df0b63df5e76cbb088ab03de5c7ab61b7b
|
https://github.com/notamedia/yii2-relation/blob/ed8050df0b63df5e76cbb088ab03de5c7ab61b7b/RelationBehavior.php#L547-L577
|
224,883
|
notamedia/yii2-relation
|
RelationBehavior.php
|
RelationBehavior.loadModelsManyToManyViaTable
|
protected function loadModelsManyToManyViaTable($attribute)
{
$data = $this->relationalData[$attribute];
$activeQuery = $data['activeQuery'];
/** @var ActiveRecord $class */
$class = $activeQuery->modelClass;
$via = $activeQuery->via;
$data['junctionTable'] = $via->from[0];
list($data['junctionColumn']) = array_keys($via->link);
list($data['relatedColumn']) = array_values($activeQuery->link);
$junctionColumn = $data['junctionColumn'];
$relatedColumn = $data['relatedColumn'];
if (!empty($data['data'])) {
// make sure what all row's ids from POST exists in database
$countManyToManyModels = $class::find()->where([$class::primaryKey()[0] => $data['data']])->count();
if ($countManyToManyModels != count($data['data'])) {
throw new RelationException('Related records for attribute ' . $attribute . ' not found');
}
// create new junction rows
foreach ($data['data'] as $relatedModelId) {
$junctionModel = array_merge(
!ArrayHelper::isAssociative($via->on) ? [] : $via->on,
[$junctionColumn => $this->owner->getPrimaryKey()]
);
$junctionModel[$relatedColumn] = $relatedModelId;
if (isset($this->relations[$attribute]) && is_callable($this->relations[$attribute])) {
$junctionModel = call_user_func($this->relations[$attribute], $junctionModel, $relatedModelId);
}
$data['newRows'][] = $junctionModel;
}
}
if (!empty($this->owner->getPrimaryKey())) {
$data['oldRows'] = (new Query())
->from($data['junctionTable'])
->select(array_merge(
[$junctionColumn, $relatedColumn],
!ArrayHelper::isAssociative($via->on) ? [] : array_keys($via->on))
)->where(array_merge(
!ArrayHelper::isAssociative($via->on) ? [] : $via->on,
[$junctionColumn => $this->owner->getPrimaryKey()]
))->all();
}
$this->relationalData[$attribute] = $data;
}
|
php
|
protected function loadModelsManyToManyViaTable($attribute)
{
$data = $this->relationalData[$attribute];
$activeQuery = $data['activeQuery'];
/** @var ActiveRecord $class */
$class = $activeQuery->modelClass;
$via = $activeQuery->via;
$data['junctionTable'] = $via->from[0];
list($data['junctionColumn']) = array_keys($via->link);
list($data['relatedColumn']) = array_values($activeQuery->link);
$junctionColumn = $data['junctionColumn'];
$relatedColumn = $data['relatedColumn'];
if (!empty($data['data'])) {
// make sure what all row's ids from POST exists in database
$countManyToManyModels = $class::find()->where([$class::primaryKey()[0] => $data['data']])->count();
if ($countManyToManyModels != count($data['data'])) {
throw new RelationException('Related records for attribute ' . $attribute . ' not found');
}
// create new junction rows
foreach ($data['data'] as $relatedModelId) {
$junctionModel = array_merge(
!ArrayHelper::isAssociative($via->on) ? [] : $via->on,
[$junctionColumn => $this->owner->getPrimaryKey()]
);
$junctionModel[$relatedColumn] = $relatedModelId;
if (isset($this->relations[$attribute]) && is_callable($this->relations[$attribute])) {
$junctionModel = call_user_func($this->relations[$attribute], $junctionModel, $relatedModelId);
}
$data['newRows'][] = $junctionModel;
}
}
if (!empty($this->owner->getPrimaryKey())) {
$data['oldRows'] = (new Query())
->from($data['junctionTable'])
->select(array_merge(
[$junctionColumn, $relatedColumn],
!ArrayHelper::isAssociative($via->on) ? [] : array_keys($via->on))
)->where(array_merge(
!ArrayHelper::isAssociative($via->on) ? [] : $via->on,
[$junctionColumn => $this->owner->getPrimaryKey()]
))->all();
}
$this->relationalData[$attribute] = $data;
}
|
[
"protected",
"function",
"loadModelsManyToManyViaTable",
"(",
"$",
"attribute",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"relationalData",
"[",
"$",
"attribute",
"]",
";",
"$",
"activeQuery",
"=",
"$",
"data",
"[",
"'activeQuery'",
"]",
";",
"/** @var ActiveRecord $class */",
"$",
"class",
"=",
"$",
"activeQuery",
"->",
"modelClass",
";",
"$",
"via",
"=",
"$",
"activeQuery",
"->",
"via",
";",
"$",
"data",
"[",
"'junctionTable'",
"]",
"=",
"$",
"via",
"->",
"from",
"[",
"0",
"]",
";",
"list",
"(",
"$",
"data",
"[",
"'junctionColumn'",
"]",
")",
"=",
"array_keys",
"(",
"$",
"via",
"->",
"link",
")",
";",
"list",
"(",
"$",
"data",
"[",
"'relatedColumn'",
"]",
")",
"=",
"array_values",
"(",
"$",
"activeQuery",
"->",
"link",
")",
";",
"$",
"junctionColumn",
"=",
"$",
"data",
"[",
"'junctionColumn'",
"]",
";",
"$",
"relatedColumn",
"=",
"$",
"data",
"[",
"'relatedColumn'",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'data'",
"]",
")",
")",
"{",
"// make sure what all row's ids from POST exists in database",
"$",
"countManyToManyModels",
"=",
"$",
"class",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"$",
"class",
"::",
"primaryKey",
"(",
")",
"[",
"0",
"]",
"=>",
"$",
"data",
"[",
"'data'",
"]",
"]",
")",
"->",
"count",
"(",
")",
";",
"if",
"(",
"$",
"countManyToManyModels",
"!=",
"count",
"(",
"$",
"data",
"[",
"'data'",
"]",
")",
")",
"{",
"throw",
"new",
"RelationException",
"(",
"'Related records for attribute '",
".",
"$",
"attribute",
".",
"' not found'",
")",
";",
"}",
"// create new junction rows",
"foreach",
"(",
"$",
"data",
"[",
"'data'",
"]",
"as",
"$",
"relatedModelId",
")",
"{",
"$",
"junctionModel",
"=",
"array_merge",
"(",
"!",
"ArrayHelper",
"::",
"isAssociative",
"(",
"$",
"via",
"->",
"on",
")",
"?",
"[",
"]",
":",
"$",
"via",
"->",
"on",
",",
"[",
"$",
"junctionColumn",
"=>",
"$",
"this",
"->",
"owner",
"->",
"getPrimaryKey",
"(",
")",
"]",
")",
";",
"$",
"junctionModel",
"[",
"$",
"relatedColumn",
"]",
"=",
"$",
"relatedModelId",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"relations",
"[",
"$",
"attribute",
"]",
")",
"&&",
"is_callable",
"(",
"$",
"this",
"->",
"relations",
"[",
"$",
"attribute",
"]",
")",
")",
"{",
"$",
"junctionModel",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"relations",
"[",
"$",
"attribute",
"]",
",",
"$",
"junctionModel",
",",
"$",
"relatedModelId",
")",
";",
"}",
"$",
"data",
"[",
"'newRows'",
"]",
"[",
"]",
"=",
"$",
"junctionModel",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"owner",
"->",
"getPrimaryKey",
"(",
")",
")",
")",
"{",
"$",
"data",
"[",
"'oldRows'",
"]",
"=",
"(",
"new",
"Query",
"(",
")",
")",
"->",
"from",
"(",
"$",
"data",
"[",
"'junctionTable'",
"]",
")",
"->",
"select",
"(",
"array_merge",
"(",
"[",
"$",
"junctionColumn",
",",
"$",
"relatedColumn",
"]",
",",
"!",
"ArrayHelper",
"::",
"isAssociative",
"(",
"$",
"via",
"->",
"on",
")",
"?",
"[",
"]",
":",
"array_keys",
"(",
"$",
"via",
"->",
"on",
")",
")",
")",
"->",
"where",
"(",
"array_merge",
"(",
"!",
"ArrayHelper",
"::",
"isAssociative",
"(",
"$",
"via",
"->",
"on",
")",
"?",
"[",
"]",
":",
"$",
"via",
"->",
"on",
",",
"[",
"$",
"junctionColumn",
"=>",
"$",
"this",
"->",
"owner",
"->",
"getPrimaryKey",
"(",
")",
"]",
")",
")",
"->",
"all",
"(",
")",
";",
"}",
"$",
"this",
"->",
"relationalData",
"[",
"$",
"attribute",
"]",
"=",
"$",
"data",
";",
"}"
] |
Load new models from POST for many-to-many relation with viaTable
@param $attribute
@throws RelationException
|
[
"Load",
"new",
"models",
"from",
"POST",
"for",
"many",
"-",
"to",
"-",
"many",
"relation",
"with",
"viaTable"
] |
ed8050df0b63df5e76cbb088ab03de5c7ab61b7b
|
https://github.com/notamedia/yii2-relation/blob/ed8050df0b63df5e76cbb088ab03de5c7ab61b7b/RelationBehavior.php#L585-L634
|
224,884
|
notamedia/yii2-relation
|
RelationBehavior.php
|
RelationBehavior.loadModelsManyToManyVia
|
protected function loadModelsManyToManyVia($attribute)
{
$data = $this->relationalData[$attribute];
$activeQuery = $data['activeQuery'];
/** @var ActiveRecord $class */
$class = $activeQuery->modelClass;
if (!is_object($activeQuery->via[1])) {
throw new RelationException('via condition for attribute ' . $attribute . ' cannot must be object');
}
$via = $activeQuery->via[1];
$junctionGetter = 'get' . ucfirst($activeQuery->via[0]);
/** @var ActiveRecord $junctionModelClass */
$data['junctionModelClass'] = $junctionModelClass = $via->modelClass;
$data['junctionTable'] = $junctionModelClass::tableName();
list($data['junctionColumn']) = array_keys($via->link);
list($data['relatedColumn']) = array_values($activeQuery->link);
$junctionColumn = $data['junctionColumn'];
$relatedColumn = $data['relatedColumn'];
if (!empty($data['data'])) {
// make sure what all model's ids from POST exists in database
$countManyToManyModels = $class::find()->where([$class::primaryKey()[0] => $data['data']])->count();
if ($countManyToManyModels != count($data['data'])) {
throw new RelationException('Related records for attribute ' . $attribute . ' not found');
}
// create new junction models
foreach ($data['data'] as $relatedModelId) {
$junctionModel = new $junctionModelClass(
array_merge(
!ArrayHelper::isAssociative($via->on) ? [] : $via->on,
[$junctionColumn => $this->owner->getPrimaryKey()]
)
);
$junctionModel->$relatedColumn = $relatedModelId;
if (isset($this->relations[$attribute]) && is_callable($this->relations[$attribute])) {
$junctionModel = call_user_func($this->relations[$attribute], $junctionModel, $relatedModelId);
}
$data['newModels'][] = $junctionModel;
}
}
$data['oldModels'] = $this->owner->$junctionGetter()->all();
$this->relationalData[$attribute] = $data;
}
|
php
|
protected function loadModelsManyToManyVia($attribute)
{
$data = $this->relationalData[$attribute];
$activeQuery = $data['activeQuery'];
/** @var ActiveRecord $class */
$class = $activeQuery->modelClass;
if (!is_object($activeQuery->via[1])) {
throw new RelationException('via condition for attribute ' . $attribute . ' cannot must be object');
}
$via = $activeQuery->via[1];
$junctionGetter = 'get' . ucfirst($activeQuery->via[0]);
/** @var ActiveRecord $junctionModelClass */
$data['junctionModelClass'] = $junctionModelClass = $via->modelClass;
$data['junctionTable'] = $junctionModelClass::tableName();
list($data['junctionColumn']) = array_keys($via->link);
list($data['relatedColumn']) = array_values($activeQuery->link);
$junctionColumn = $data['junctionColumn'];
$relatedColumn = $data['relatedColumn'];
if (!empty($data['data'])) {
// make sure what all model's ids from POST exists in database
$countManyToManyModels = $class::find()->where([$class::primaryKey()[0] => $data['data']])->count();
if ($countManyToManyModels != count($data['data'])) {
throw new RelationException('Related records for attribute ' . $attribute . ' not found');
}
// create new junction models
foreach ($data['data'] as $relatedModelId) {
$junctionModel = new $junctionModelClass(
array_merge(
!ArrayHelper::isAssociative($via->on) ? [] : $via->on,
[$junctionColumn => $this->owner->getPrimaryKey()]
)
);
$junctionModel->$relatedColumn = $relatedModelId;
if (isset($this->relations[$attribute]) && is_callable($this->relations[$attribute])) {
$junctionModel = call_user_func($this->relations[$attribute], $junctionModel, $relatedModelId);
}
$data['newModels'][] = $junctionModel;
}
}
$data['oldModels'] = $this->owner->$junctionGetter()->all();
$this->relationalData[$attribute] = $data;
}
|
[
"protected",
"function",
"loadModelsManyToManyVia",
"(",
"$",
"attribute",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"relationalData",
"[",
"$",
"attribute",
"]",
";",
"$",
"activeQuery",
"=",
"$",
"data",
"[",
"'activeQuery'",
"]",
";",
"/** @var ActiveRecord $class */",
"$",
"class",
"=",
"$",
"activeQuery",
"->",
"modelClass",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"activeQuery",
"->",
"via",
"[",
"1",
"]",
")",
")",
"{",
"throw",
"new",
"RelationException",
"(",
"'via condition for attribute '",
".",
"$",
"attribute",
".",
"' cannot must be object'",
")",
";",
"}",
"$",
"via",
"=",
"$",
"activeQuery",
"->",
"via",
"[",
"1",
"]",
";",
"$",
"junctionGetter",
"=",
"'get'",
".",
"ucfirst",
"(",
"$",
"activeQuery",
"->",
"via",
"[",
"0",
"]",
")",
";",
"/** @var ActiveRecord $junctionModelClass */",
"$",
"data",
"[",
"'junctionModelClass'",
"]",
"=",
"$",
"junctionModelClass",
"=",
"$",
"via",
"->",
"modelClass",
";",
"$",
"data",
"[",
"'junctionTable'",
"]",
"=",
"$",
"junctionModelClass",
"::",
"tableName",
"(",
")",
";",
"list",
"(",
"$",
"data",
"[",
"'junctionColumn'",
"]",
")",
"=",
"array_keys",
"(",
"$",
"via",
"->",
"link",
")",
";",
"list",
"(",
"$",
"data",
"[",
"'relatedColumn'",
"]",
")",
"=",
"array_values",
"(",
"$",
"activeQuery",
"->",
"link",
")",
";",
"$",
"junctionColumn",
"=",
"$",
"data",
"[",
"'junctionColumn'",
"]",
";",
"$",
"relatedColumn",
"=",
"$",
"data",
"[",
"'relatedColumn'",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'data'",
"]",
")",
")",
"{",
"// make sure what all model's ids from POST exists in database",
"$",
"countManyToManyModels",
"=",
"$",
"class",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"$",
"class",
"::",
"primaryKey",
"(",
")",
"[",
"0",
"]",
"=>",
"$",
"data",
"[",
"'data'",
"]",
"]",
")",
"->",
"count",
"(",
")",
";",
"if",
"(",
"$",
"countManyToManyModels",
"!=",
"count",
"(",
"$",
"data",
"[",
"'data'",
"]",
")",
")",
"{",
"throw",
"new",
"RelationException",
"(",
"'Related records for attribute '",
".",
"$",
"attribute",
".",
"' not found'",
")",
";",
"}",
"// create new junction models",
"foreach",
"(",
"$",
"data",
"[",
"'data'",
"]",
"as",
"$",
"relatedModelId",
")",
"{",
"$",
"junctionModel",
"=",
"new",
"$",
"junctionModelClass",
"(",
"array_merge",
"(",
"!",
"ArrayHelper",
"::",
"isAssociative",
"(",
"$",
"via",
"->",
"on",
")",
"?",
"[",
"]",
":",
"$",
"via",
"->",
"on",
",",
"[",
"$",
"junctionColumn",
"=>",
"$",
"this",
"->",
"owner",
"->",
"getPrimaryKey",
"(",
")",
"]",
")",
")",
";",
"$",
"junctionModel",
"->",
"$",
"relatedColumn",
"=",
"$",
"relatedModelId",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"relations",
"[",
"$",
"attribute",
"]",
")",
"&&",
"is_callable",
"(",
"$",
"this",
"->",
"relations",
"[",
"$",
"attribute",
"]",
")",
")",
"{",
"$",
"junctionModel",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"relations",
"[",
"$",
"attribute",
"]",
",",
"$",
"junctionModel",
",",
"$",
"relatedModelId",
")",
";",
"}",
"$",
"data",
"[",
"'newModels'",
"]",
"[",
"]",
"=",
"$",
"junctionModel",
";",
"}",
"}",
"$",
"data",
"[",
"'oldModels'",
"]",
"=",
"$",
"this",
"->",
"owner",
"->",
"$",
"junctionGetter",
"(",
")",
"->",
"all",
"(",
")",
";",
"$",
"this",
"->",
"relationalData",
"[",
"$",
"attribute",
"]",
"=",
"$",
"data",
";",
"}"
] |
Load new models from POST for many-to-many relation with via
@param $attribute
@throws RelationException
|
[
"Load",
"new",
"models",
"from",
"POST",
"for",
"many",
"-",
"to",
"-",
"many",
"relation",
"with",
"via"
] |
ed8050df0b63df5e76cbb088ab03de5c7ab61b7b
|
https://github.com/notamedia/yii2-relation/blob/ed8050df0b63df5e76cbb088ab03de5c7ab61b7b/RelationBehavior.php#L642-L690
|
224,885
|
notamedia/yii2-relation
|
RelationBehavior.php
|
RelationBehavior.saveModels
|
protected function saveModels($attribute)
{
$data = $this->relationalData[$attribute];
/** @var ActiveRecord $model */
foreach ($data['newModels'] as $model) {
if ($model->isNewRecord) {
if (!empty($data['activeQuery']->via)) {
// only for many-to-many
$junctionColumn = $data['junctionColumn'];
$model->$junctionColumn = $this->owner->getPrimaryKey();
} elseif ($data['activeQuery']->multiple) {
// only one-to-many
foreach ($data['activeQuery']->link as $childAttribute => $parentAttribute) {
$model->$childAttribute = $this->owner->$parentAttribute;
}
}
if (!$model->save()) {
Yii::$app->getDb()->getTransaction()->rollBack();
throw new RelationException('Model ' . $model::className() . ' not saved due to unknown error');
}
}
}
// only for many-to-many
$this->relationsMap($data['newRows'], function($row) use ($attribute, $data) {
$junctionColumn = $data['junctionColumn'];
$row[$junctionColumn] = $this->owner->getPrimaryKey();
if (!$this->isExistingRow($row, $attribute)) {
Yii::$app->db->createCommand()
->insert($data['junctionTable'], $row)
->execute();
}
});
}
|
php
|
protected function saveModels($attribute)
{
$data = $this->relationalData[$attribute];
/** @var ActiveRecord $model */
foreach ($data['newModels'] as $model) {
if ($model->isNewRecord) {
if (!empty($data['activeQuery']->via)) {
// only for many-to-many
$junctionColumn = $data['junctionColumn'];
$model->$junctionColumn = $this->owner->getPrimaryKey();
} elseif ($data['activeQuery']->multiple) {
// only one-to-many
foreach ($data['activeQuery']->link as $childAttribute => $parentAttribute) {
$model->$childAttribute = $this->owner->$parentAttribute;
}
}
if (!$model->save()) {
Yii::$app->getDb()->getTransaction()->rollBack();
throw new RelationException('Model ' . $model::className() . ' not saved due to unknown error');
}
}
}
// only for many-to-many
$this->relationsMap($data['newRows'], function($row) use ($attribute, $data) {
$junctionColumn = $data['junctionColumn'];
$row[$junctionColumn] = $this->owner->getPrimaryKey();
if (!$this->isExistingRow($row, $attribute)) {
Yii::$app->db->createCommand()
->insert($data['junctionTable'], $row)
->execute();
}
});
}
|
[
"protected",
"function",
"saveModels",
"(",
"$",
"attribute",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"relationalData",
"[",
"$",
"attribute",
"]",
";",
"/** @var ActiveRecord $model */",
"foreach",
"(",
"$",
"data",
"[",
"'newModels'",
"]",
"as",
"$",
"model",
")",
"{",
"if",
"(",
"$",
"model",
"->",
"isNewRecord",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'activeQuery'",
"]",
"->",
"via",
")",
")",
"{",
"// only for many-to-many",
"$",
"junctionColumn",
"=",
"$",
"data",
"[",
"'junctionColumn'",
"]",
";",
"$",
"model",
"->",
"$",
"junctionColumn",
"=",
"$",
"this",
"->",
"owner",
"->",
"getPrimaryKey",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"data",
"[",
"'activeQuery'",
"]",
"->",
"multiple",
")",
"{",
"// only one-to-many",
"foreach",
"(",
"$",
"data",
"[",
"'activeQuery'",
"]",
"->",
"link",
"as",
"$",
"childAttribute",
"=>",
"$",
"parentAttribute",
")",
"{",
"$",
"model",
"->",
"$",
"childAttribute",
"=",
"$",
"this",
"->",
"owner",
"->",
"$",
"parentAttribute",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"model",
"->",
"save",
"(",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"getDb",
"(",
")",
"->",
"getTransaction",
"(",
")",
"->",
"rollBack",
"(",
")",
";",
"throw",
"new",
"RelationException",
"(",
"'Model '",
".",
"$",
"model",
"::",
"className",
"(",
")",
".",
"' not saved due to unknown error'",
")",
";",
"}",
"}",
"}",
"// only for many-to-many",
"$",
"this",
"->",
"relationsMap",
"(",
"$",
"data",
"[",
"'newRows'",
"]",
",",
"function",
"(",
"$",
"row",
")",
"use",
"(",
"$",
"attribute",
",",
"$",
"data",
")",
"{",
"$",
"junctionColumn",
"=",
"$",
"data",
"[",
"'junctionColumn'",
"]",
";",
"$",
"row",
"[",
"$",
"junctionColumn",
"]",
"=",
"$",
"this",
"->",
"owner",
"->",
"getPrimaryKey",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isExistingRow",
"(",
"$",
"row",
",",
"$",
"attribute",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"db",
"->",
"createCommand",
"(",
")",
"->",
"insert",
"(",
"$",
"data",
"[",
"'junctionTable'",
"]",
",",
"$",
"row",
")",
"->",
"execute",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Save all new models for attribute
@param $attribute
@throws RelationException
|
[
"Save",
"all",
"new",
"models",
"for",
"attribute"
] |
ed8050df0b63df5e76cbb088ab03de5c7ab61b7b
|
https://github.com/notamedia/yii2-relation/blob/ed8050df0b63df5e76cbb088ab03de5c7ab61b7b/RelationBehavior.php#L698-L732
|
224,886
|
notamedia/yii2-relation
|
RelationBehavior.php
|
RelationBehavior.deleteModels
|
protected function deleteModels($attribute)
{
$data = $this->relationalData[$attribute];
/** @var ActiveRecord $model */
foreach ($data['oldModels'] as $model) {
if ($this->isDeletedModel($model, $attribute)) {
if (!$model->delete()) {
Yii::$app->getDb()->getTransaction()->rollBack();
throw new RelationException('Model ' . $model::className() . ' not deleted due to unknown error');
}
}
}
$this->relationsMap($data['oldRows'], function($row) use ($attribute, $data) {
if ($this->isDeletedRow($row, $attribute)) {
Yii::$app->db->createCommand()
->delete($data['junctionTable'], $row)
->execute();
}
});
}
|
php
|
protected function deleteModels($attribute)
{
$data = $this->relationalData[$attribute];
/** @var ActiveRecord $model */
foreach ($data['oldModels'] as $model) {
if ($this->isDeletedModel($model, $attribute)) {
if (!$model->delete()) {
Yii::$app->getDb()->getTransaction()->rollBack();
throw new RelationException('Model ' . $model::className() . ' not deleted due to unknown error');
}
}
}
$this->relationsMap($data['oldRows'], function($row) use ($attribute, $data) {
if ($this->isDeletedRow($row, $attribute)) {
Yii::$app->db->createCommand()
->delete($data['junctionTable'], $row)
->execute();
}
});
}
|
[
"protected",
"function",
"deleteModels",
"(",
"$",
"attribute",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"relationalData",
"[",
"$",
"attribute",
"]",
";",
"/** @var ActiveRecord $model */",
"foreach",
"(",
"$",
"data",
"[",
"'oldModels'",
"]",
"as",
"$",
"model",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isDeletedModel",
"(",
"$",
"model",
",",
"$",
"attribute",
")",
")",
"{",
"if",
"(",
"!",
"$",
"model",
"->",
"delete",
"(",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"getDb",
"(",
")",
"->",
"getTransaction",
"(",
")",
"->",
"rollBack",
"(",
")",
";",
"throw",
"new",
"RelationException",
"(",
"'Model '",
".",
"$",
"model",
"::",
"className",
"(",
")",
".",
"' not deleted due to unknown error'",
")",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"relationsMap",
"(",
"$",
"data",
"[",
"'oldRows'",
"]",
",",
"function",
"(",
"$",
"row",
")",
"use",
"(",
"$",
"attribute",
",",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isDeletedRow",
"(",
"$",
"row",
",",
"$",
"attribute",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"db",
"->",
"createCommand",
"(",
")",
"->",
"delete",
"(",
"$",
"data",
"[",
"'junctionTable'",
"]",
",",
"$",
"row",
")",
"->",
"execute",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Delete all old models for attribute if it needed
@param $attribute
@throws RelationException
|
[
"Delete",
"all",
"old",
"models",
"for",
"attribute",
"if",
"it",
"needed"
] |
ed8050df0b63df5e76cbb088ab03de5c7ab61b7b
|
https://github.com/notamedia/yii2-relation/blob/ed8050df0b63df5e76cbb088ab03de5c7ab61b7b/RelationBehavior.php#L740-L761
|
224,887
|
liip/LiipTranslationBundle
|
Controller/ImportController.php
|
ImportController.indexAction
|
public function indexAction()
{
return $this->render('LiipTranslationBundle:Import:index.html.twig', array(
'upload_form' => $this->createForm(new FileImportType())->createView(),
'translations' => $this->getSessionImporter()->getCurrentTranslations(),
));
}
|
php
|
public function indexAction()
{
return $this->render('LiipTranslationBundle:Import:index.html.twig', array(
'upload_form' => $this->createForm(new FileImportType())->createView(),
'translations' => $this->getSessionImporter()->getCurrentTranslations(),
));
}
|
[
"public",
"function",
"indexAction",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"render",
"(",
"'LiipTranslationBundle:Import:index.html.twig'",
",",
"array",
"(",
"'upload_form'",
"=>",
"$",
"this",
"->",
"createForm",
"(",
"new",
"FileImportType",
"(",
")",
")",
"->",
"createView",
"(",
")",
",",
"'translations'",
"=>",
"$",
"this",
"->",
"getSessionImporter",
"(",
")",
"->",
"getCurrentTranslations",
"(",
")",
",",
")",
")",
";",
"}"
] |
Importating dashboard.
@return Response
|
[
"Importating",
"dashboard",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Controller/ImportController.php#L33-L39
|
224,888
|
liip/LiipTranslationBundle
|
Controller/ImportController.php
|
ImportController.uploadAction
|
public function uploadAction(Request $request)
{
$form = $this->createForm(new FileImportType());
$data = $form->handleRequest($request)->getData();
$session = $this->getSession();
try {
$counters = $this->getSessionImporter()->handleUploadedFile($data['file']);
if ($counters['new'] == 0 && $counters['updated'] == 0) {
$session->getFlashBag()->set('warning', 'File import success, but not more modification found');
} else {
$session->getFlashBag()->set('info', "File import success, {$counters['new']} new and {$counters['updated']} update");
}
} catch (ImportException $e) {
$session->getFlashBag()->set('error', 'Error while trying to import: '.$e->getMessage());
}
return $this->redirect($this->generateUrl('liip_translation_import'));
}
|
php
|
public function uploadAction(Request $request)
{
$form = $this->createForm(new FileImportType());
$data = $form->handleRequest($request)->getData();
$session = $this->getSession();
try {
$counters = $this->getSessionImporter()->handleUploadedFile($data['file']);
if ($counters['new'] == 0 && $counters['updated'] == 0) {
$session->getFlashBag()->set('warning', 'File import success, but not more modification found');
} else {
$session->getFlashBag()->set('info', "File import success, {$counters['new']} new and {$counters['updated']} update");
}
} catch (ImportException $e) {
$session->getFlashBag()->set('error', 'Error while trying to import: '.$e->getMessage());
}
return $this->redirect($this->generateUrl('liip_translation_import'));
}
|
[
"public",
"function",
"uploadAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"FileImportType",
"(",
")",
")",
";",
"$",
"data",
"=",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
"->",
"getData",
"(",
")",
";",
"$",
"session",
"=",
"$",
"this",
"->",
"getSession",
"(",
")",
";",
"try",
"{",
"$",
"counters",
"=",
"$",
"this",
"->",
"getSessionImporter",
"(",
")",
"->",
"handleUploadedFile",
"(",
"$",
"data",
"[",
"'file'",
"]",
")",
";",
"if",
"(",
"$",
"counters",
"[",
"'new'",
"]",
"==",
"0",
"&&",
"$",
"counters",
"[",
"'updated'",
"]",
"==",
"0",
")",
"{",
"$",
"session",
"->",
"getFlashBag",
"(",
")",
"->",
"set",
"(",
"'warning'",
",",
"'File import success, but not more modification found'",
")",
";",
"}",
"else",
"{",
"$",
"session",
"->",
"getFlashBag",
"(",
")",
"->",
"set",
"(",
"'info'",
",",
"\"File import success, {$counters['new']} new and {$counters['updated']} update\"",
")",
";",
"}",
"}",
"catch",
"(",
"ImportException",
"$",
"e",
")",
"{",
"$",
"session",
"->",
"getFlashBag",
"(",
")",
"->",
"set",
"(",
"'error'",
",",
"'Error while trying to import: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'liip_translation_import'",
")",
")",
";",
"}"
] |
File upload handling, redirect to the dashboard.
@param Request $request the request
@return \Symfony\Component\HttpFoundation\RedirectResponse
|
[
"File",
"upload",
"handling",
"redirect",
"to",
"the",
"dashboard",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Controller/ImportController.php#L60-L78
|
224,889
|
liip/LiipTranslationBundle
|
Controller/ImportController.php
|
ImportController.removeEntryAction
|
public function removeEntryAction($locale, $domain, $key)
{
$this->securityCheck($domain, $locale);
$this->getSessionImporter()->remove($domain, $key, $locale);
$session = $this->getSession();
$session->getFlashBag()->set('success', 'Entry removed');
return $this->redirect($this->generateUrl('liip_translation_import'));
}
|
php
|
public function removeEntryAction($locale, $domain, $key)
{
$this->securityCheck($domain, $locale);
$this->getSessionImporter()->remove($domain, $key, $locale);
$session = $this->getSession();
$session->getFlashBag()->set('success', 'Entry removed');
return $this->redirect($this->generateUrl('liip_translation_import'));
}
|
[
"public",
"function",
"removeEntryAction",
"(",
"$",
"locale",
",",
"$",
"domain",
",",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"securityCheck",
"(",
"$",
"domain",
",",
"$",
"locale",
")",
";",
"$",
"this",
"->",
"getSessionImporter",
"(",
")",
"->",
"remove",
"(",
"$",
"domain",
",",
"$",
"key",
",",
"$",
"locale",
")",
";",
"$",
"session",
"=",
"$",
"this",
"->",
"getSession",
"(",
")",
";",
"$",
"session",
"->",
"getFlashBag",
"(",
")",
"->",
"set",
"(",
"'success'",
",",
"'Entry removed'",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'liip_translation_import'",
")",
")",
";",
"}"
] |
Remove an entry from the session.
@param string $locale
@param string $domain
@param string $key
@return \Symfony\Component\HttpFoundation\RedirectResponse
|
[
"Remove",
"an",
"entry",
"from",
"the",
"session",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Controller/ImportController.php#L89-L98
|
224,890
|
liip/LiipTranslationBundle
|
Controller/ImportController.php
|
ImportController.processAction
|
public function processAction($locale)
{
$stats = $this->getSessionImporter()->comfirmImportation($locale);
$session = $this->getSession();
$session->getFlashBag()->set('success', "Import success ({$stats['translations']['text']})");
return $this->redirect($this->generateUrl('liip_translation_import'));
}
|
php
|
public function processAction($locale)
{
$stats = $this->getSessionImporter()->comfirmImportation($locale);
$session = $this->getSession();
$session->getFlashBag()->set('success', "Import success ({$stats['translations']['text']})");
return $this->redirect($this->generateUrl('liip_translation_import'));
}
|
[
"public",
"function",
"processAction",
"(",
"$",
"locale",
")",
"{",
"$",
"stats",
"=",
"$",
"this",
"->",
"getSessionImporter",
"(",
")",
"->",
"comfirmImportation",
"(",
"$",
"locale",
")",
";",
"$",
"session",
"=",
"$",
"this",
"->",
"getSession",
"(",
")",
";",
"$",
"session",
"->",
"getFlashBag",
"(",
")",
"->",
"set",
"(",
"'success'",
",",
"\"Import success ({$stats['translations']['text']})\"",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'liip_translation_import'",
")",
")",
";",
"}"
] |
Process the importation for the given locale, and redirect to the dashboard.
@param string $locale
@return \Symfony\Component\HttpFoundation\RedirectResponse
|
[
"Process",
"the",
"importation",
"for",
"the",
"given",
"locale",
"and",
"redirect",
"to",
"the",
"dashboard",
"."
] |
6e9896042d80c4e50f1e7ceacf434e772daaf149
|
https://github.com/liip/LiipTranslationBundle/blob/6e9896042d80c4e50f1e7ceacf434e772daaf149/Controller/ImportController.php#L107-L114
|
224,891
|
kzykhys/PHPCsvParser
|
src/KzykHys/CsvParser/CsvParser.php
|
CsvParser.fromFile
|
public static function fromFile($file, array $option = array())
{
if (!file_exists($file)) {
throw new \InvalidArgumentException('File not found: ' . $file);
}
return new self(new FileIterator($file), $option);
}
|
php
|
public static function fromFile($file, array $option = array())
{
if (!file_exists($file)) {
throw new \InvalidArgumentException('File not found: ' . $file);
}
return new self(new FileIterator($file), $option);
}
|
[
"public",
"static",
"function",
"fromFile",
"(",
"$",
"file",
",",
"array",
"$",
"option",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'File not found: '",
".",
"$",
"file",
")",
";",
"}",
"return",
"new",
"self",
"(",
"new",
"FileIterator",
"(",
"$",
"file",
")",
",",
"$",
"option",
")",
";",
"}"
] |
Returns new instance from CSV file
@param string $file The CSV string to parse
@param array $option Options
@throws \InvalidArgumentException
@return CsvParser
|
[
"Returns",
"new",
"instance",
"from",
"CSV",
"file"
] |
a7d20bbfe1ec6402d736975571d8f4dcece6b489
|
https://github.com/kzykhys/PHPCsvParser/blob/a7d20bbfe1ec6402d736975571d8f4dcece6b489/src/KzykHys/CsvParser/CsvParser.php#L31-L38
|
224,892
|
kzykhys/PHPCsvParser
|
src/KzykHys/CsvParser/CsvParser.php
|
CsvParser.fromString
|
public static function fromString($csv, array $option = array())
{
$lines = array();
if ($csv !== '') {
if (!preg_match('/(\r|\n|\r\n)\Z/m', $csv)) {
$csv .= "\n";
}
preg_match_all('/[^\r\n]*(?:\r|\n|\r\n)+/m', $csv, $matches);
$lines = $matches[0];
}
return self::fromArray($lines, $option);
}
|
php
|
public static function fromString($csv, array $option = array())
{
$lines = array();
if ($csv !== '') {
if (!preg_match('/(\r|\n|\r\n)\Z/m', $csv)) {
$csv .= "\n";
}
preg_match_all('/[^\r\n]*(?:\r|\n|\r\n)+/m', $csv, $matches);
$lines = $matches[0];
}
return self::fromArray($lines, $option);
}
|
[
"public",
"static",
"function",
"fromString",
"(",
"$",
"csv",
",",
"array",
"$",
"option",
"=",
"array",
"(",
")",
")",
"{",
"$",
"lines",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"csv",
"!==",
"''",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"'/(\\r|\\n|\\r\\n)\\Z/m'",
",",
"$",
"csv",
")",
")",
"{",
"$",
"csv",
".=",
"\"\\n\"",
";",
"}",
"preg_match_all",
"(",
"'/[^\\r\\n]*(?:\\r|\\n|\\r\\n)+/m'",
",",
"$",
"csv",
",",
"$",
"matches",
")",
";",
"$",
"lines",
"=",
"$",
"matches",
"[",
"0",
"]",
";",
"}",
"return",
"self",
"::",
"fromArray",
"(",
"$",
"lines",
",",
"$",
"option",
")",
";",
"}"
] |
Returns new instance from string
@param string $csv The CSV string to parse
@param array $option Options
@return CsvParser
|
[
"Returns",
"new",
"instance",
"from",
"string"
] |
a7d20bbfe1ec6402d736975571d8f4dcece6b489
|
https://github.com/kzykhys/PHPCsvParser/blob/a7d20bbfe1ec6402d736975571d8f4dcece6b489/src/KzykHys/CsvParser/CsvParser.php#L48-L63
|
224,893
|
valga/fbns-react
|
src/Json.php
|
Json.decode
|
public static function decode($json)
{
$flags = 0;
if (PHP_INT_SIZE === 4) {
$flags |= JSON_BIGINT_AS_STRING;
}
$data = json_decode($json, false, 512, $flags);
$error = json_last_error();
if ($error !== JSON_ERROR_NONE) {
throw new \InvalidArgumentException(sprintf('Failed to decode JSON (%d): %s.', $error, json_last_error_msg()));
}
return $data;
}
|
php
|
public static function decode($json)
{
$flags = 0;
if (PHP_INT_SIZE === 4) {
$flags |= JSON_BIGINT_AS_STRING;
}
$data = json_decode($json, false, 512, $flags);
$error = json_last_error();
if ($error !== JSON_ERROR_NONE) {
throw new \InvalidArgumentException(sprintf('Failed to decode JSON (%d): %s.', $error, json_last_error_msg()));
}
return $data;
}
|
[
"public",
"static",
"function",
"decode",
"(",
"$",
"json",
")",
"{",
"$",
"flags",
"=",
"0",
";",
"if",
"(",
"PHP_INT_SIZE",
"===",
"4",
")",
"{",
"$",
"flags",
"|=",
"JSON_BIGINT_AS_STRING",
";",
"}",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"json",
",",
"false",
",",
"512",
",",
"$",
"flags",
")",
";",
"$",
"error",
"=",
"json_last_error",
"(",
")",
";",
"if",
"(",
"$",
"error",
"!==",
"JSON_ERROR_NONE",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Failed to decode JSON (%d): %s.'",
",",
"$",
"error",
",",
"json_last_error_msg",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] |
Special decoder to keep big numbers on x86 PHP builds.
@param string $json
@return mixed
|
[
"Special",
"decoder",
"to",
"keep",
"big",
"numbers",
"on",
"x86",
"PHP",
"builds",
"."
] |
4bbf513a8ffed7e0c9ca10776033d34515bb8b37
|
https://github.com/valga/fbns-react/blob/4bbf513a8ffed7e0c9ca10776033d34515bb8b37/src/Json.php#L14-L27
|
224,894
|
moeen-basra/laravel-passport-mongodb
|
src/Guards/TokenGuard.php
|
TokenGuard.decodeJwtTokenCookie
|
protected function decodeJwtTokenCookie($request)
{
return (array) JWT::decode(
$this->encrypter->decrypt($request->cookie(Passport::cookie())),
$this->encrypter->getKey(), ['HS256']
);
}
|
php
|
protected function decodeJwtTokenCookie($request)
{
return (array) JWT::decode(
$this->encrypter->decrypt($request->cookie(Passport::cookie())),
$this->encrypter->getKey(), ['HS256']
);
}
|
[
"protected",
"function",
"decodeJwtTokenCookie",
"(",
"$",
"request",
")",
"{",
"return",
"(",
"array",
")",
"JWT",
"::",
"decode",
"(",
"$",
"this",
"->",
"encrypter",
"->",
"decrypt",
"(",
"$",
"request",
"->",
"cookie",
"(",
"Passport",
"::",
"cookie",
"(",
")",
")",
")",
",",
"$",
"this",
"->",
"encrypter",
"->",
"getKey",
"(",
")",
",",
"[",
"'HS256'",
"]",
")",
";",
"}"
] |
Decode and decrypt the JWT token cookie.
@param \Illuminate\Http\Request $request
@return array
|
[
"Decode",
"and",
"decrypt",
"the",
"JWT",
"token",
"cookie",
"."
] |
738261912672e39f9f4f4e5bf420b99dbe303ef8
|
https://github.com/moeen-basra/laravel-passport-mongodb/blob/738261912672e39f9f4f4e5bf420b99dbe303ef8/src/Guards/TokenGuard.php#L186-L192
|
224,895
|
Spomky-Labs/pbkdf2
|
src/PBKDF2.php
|
PBKDF2.customPBKDF2
|
private static function customPBKDF2($algorithm, $password, $salt, $count, $key_length)
{
$hash_length = strlen(hash($algorithm, '', true));
if (0 === $key_length) {
$key_length = $hash_length;
}
$block_count = ceil($key_length / $hash_length);
$output = '';
for ($i = 1; $i <= $block_count; ++$i) {
$last = $salt.pack('N', $i);
$last = $xorsum = hash_hmac($algorithm, $last, $password, true);
for ($j = 1; $j < $count; ++$j) {
$xorsum ^= ($last = hash_hmac($algorithm, $last, $password, true));
}
$output .= $xorsum;
}
return substr($output, 0, $key_length);
}
|
php
|
private static function customPBKDF2($algorithm, $password, $salt, $count, $key_length)
{
$hash_length = strlen(hash($algorithm, '', true));
if (0 === $key_length) {
$key_length = $hash_length;
}
$block_count = ceil($key_length / $hash_length);
$output = '';
for ($i = 1; $i <= $block_count; ++$i) {
$last = $salt.pack('N', $i);
$last = $xorsum = hash_hmac($algorithm, $last, $password, true);
for ($j = 1; $j < $count; ++$j) {
$xorsum ^= ($last = hash_hmac($algorithm, $last, $password, true));
}
$output .= $xorsum;
}
return substr($output, 0, $key_length);
}
|
[
"private",
"static",
"function",
"customPBKDF2",
"(",
"$",
"algorithm",
",",
"$",
"password",
",",
"$",
"salt",
",",
"$",
"count",
",",
"$",
"key_length",
")",
"{",
"$",
"hash_length",
"=",
"strlen",
"(",
"hash",
"(",
"$",
"algorithm",
",",
"''",
",",
"true",
")",
")",
";",
"if",
"(",
"0",
"===",
"$",
"key_length",
")",
"{",
"$",
"key_length",
"=",
"$",
"hash_length",
";",
"}",
"$",
"block_count",
"=",
"ceil",
"(",
"$",
"key_length",
"/",
"$",
"hash_length",
")",
";",
"$",
"output",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<=",
"$",
"block_count",
";",
"++",
"$",
"i",
")",
"{",
"$",
"last",
"=",
"$",
"salt",
".",
"pack",
"(",
"'N'",
",",
"$",
"i",
")",
";",
"$",
"last",
"=",
"$",
"xorsum",
"=",
"hash_hmac",
"(",
"$",
"algorithm",
",",
"$",
"last",
",",
"$",
"password",
",",
"true",
")",
";",
"for",
"(",
"$",
"j",
"=",
"1",
";",
"$",
"j",
"<",
"$",
"count",
";",
"++",
"$",
"j",
")",
"{",
"$",
"xorsum",
"^=",
"(",
"$",
"last",
"=",
"hash_hmac",
"(",
"$",
"algorithm",
",",
"$",
"last",
",",
"$",
"password",
",",
"true",
")",
")",
";",
"}",
"$",
"output",
".=",
"$",
"xorsum",
";",
"}",
"return",
"substr",
"(",
"$",
"output",
",",
"0",
",",
"$",
"key_length",
")",
";",
"}"
] |
Pure PHP PBKDF2 key derivation function.
@param string $algorithm The hash algorithm to use. For supported hash algorithms, see hash_algos().
@param string $password The password.
@param string $salt A salt that is unique to the password.
@param int $count Iteration count. Higher is better, but slower.
@param int $key_length The length of the derived key in bytes.
@return string A $key_length-byte key derived from the password and salt.
|
[
"Pure",
"PHP",
"PBKDF2",
"key",
"derivation",
"function",
"."
] |
e5928f517d526dfd65963f81df736b618a48ce27
|
https://github.com/Spomky-Labs/pbkdf2/blob/e5928f517d526dfd65963f81df736b618a48ce27/src/PBKDF2.php#L64-L83
|
224,896
|
pdeans/http
|
src/Factories/MessageFactory.php
|
MessageFactory.createRequest
|
public function createRequest($method, $uri, array $headers = [], $body = null, $protocol_version = '1.1')
{
return (
new Request($uri, $method, $this->stream->createStream($body), $headers)
)->withProtocolVersion($protocol_version);
}
|
php
|
public function createRequest($method, $uri, array $headers = [], $body = null, $protocol_version = '1.1')
{
return (
new Request($uri, $method, $this->stream->createStream($body), $headers)
)->withProtocolVersion($protocol_version);
}
|
[
"public",
"function",
"createRequest",
"(",
"$",
"method",
",",
"$",
"uri",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"$",
"body",
"=",
"null",
",",
"$",
"protocol_version",
"=",
"'1.1'",
")",
"{",
"return",
"(",
"new",
"Request",
"(",
"$",
"uri",
",",
"$",
"method",
",",
"$",
"this",
"->",
"stream",
"->",
"createStream",
"(",
"$",
"body",
")",
",",
"$",
"headers",
")",
")",
"->",
"withProtocolVersion",
"(",
"$",
"protocol_version",
")",
";",
"}"
] |
Create a PSR-7 request
@param string $method
@param \Psr\Http\Message\UriInterface|string $uri
@param array $headers
@param \Psr\Http\Message\StreamInterface|resource|string|null $body
@param string $protocol_version
@return \Psr\Http\Message\RequestInterface
|
[
"Create",
"a",
"PSR",
"-",
"7",
"request"
] |
6ebd9d9926ed815d85d47c8808ca87b236e49d88
|
https://github.com/pdeans/http/blob/6ebd9d9926ed815d85d47c8808ca87b236e49d88/src/Factories/MessageFactory.php#L43-L48
|
224,897
|
pdeans/http
|
src/Factories/MessageFactory.php
|
MessageFactory.createResponse
|
public function createResponse($status = 200, $reason = null, array $headers = [], $body = null, $protocol_version = '1.1')
{
return (
new Response($this->stream->createStream($body), $status, $headers)
)->withProtocolVersion($protocol_version);
}
|
php
|
public function createResponse($status = 200, $reason = null, array $headers = [], $body = null, $protocol_version = '1.1')
{
return (
new Response($this->stream->createStream($body), $status, $headers)
)->withProtocolVersion($protocol_version);
}
|
[
"public",
"function",
"createResponse",
"(",
"$",
"status",
"=",
"200",
",",
"$",
"reason",
"=",
"null",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"$",
"body",
"=",
"null",
",",
"$",
"protocol_version",
"=",
"'1.1'",
")",
"{",
"return",
"(",
"new",
"Response",
"(",
"$",
"this",
"->",
"stream",
"->",
"createStream",
"(",
"$",
"body",
")",
",",
"$",
"status",
",",
"$",
"headers",
")",
")",
"->",
"withProtocolVersion",
"(",
"$",
"protocol_version",
")",
";",
"}"
] |
Create a PSR-7 response
@param integer $status Response status code
@param string|null $reason Response reason phrase
@param array $headers Response headers
@param \Psr\Http\Message\StreamInterface|resource|string|null $body Response body
@param string $protocol Response http protocol version
@return \Psr\Http\Message\ResponseInterface
|
[
"Create",
"a",
"PSR",
"-",
"7",
"response"
] |
6ebd9d9926ed815d85d47c8808ca87b236e49d88
|
https://github.com/pdeans/http/blob/6ebd9d9926ed815d85d47c8808ca87b236e49d88/src/Factories/MessageFactory.php#L61-L66
|
224,898
|
pdeans/http
|
src/Exceptions/HttpException.php
|
HttpException.create
|
public static function create(
RequestInterface $request,
ResponseInterface $response,
Exception $last_exception = null
) {
$message = sprintf(
'[url] %s [http method] %s [status code] %s [reason phrase] %s',
$request->getRequestTarget(),
$request->getMethod(),
$response->getStatusCode(),
$response->getReasonPhrase()
);
return new self($message, $request, $response, $last_exception);
}
|
php
|
public static function create(
RequestInterface $request,
ResponseInterface $response,
Exception $last_exception = null
) {
$message = sprintf(
'[url] %s [http method] %s [status code] %s [reason phrase] %s',
$request->getRequestTarget(),
$request->getMethod(),
$response->getStatusCode(),
$response->getReasonPhrase()
);
return new self($message, $request, $response, $last_exception);
}
|
[
"public",
"static",
"function",
"create",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
",",
"Exception",
"$",
"last_exception",
"=",
"null",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'[url] %s [http method] %s [status code] %s [reason phrase] %s'",
",",
"$",
"request",
"->",
"getRequestTarget",
"(",
")",
",",
"$",
"request",
"->",
"getMethod",
"(",
")",
",",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
",",
"$",
"response",
"->",
"getReasonPhrase",
"(",
")",
")",
";",
"return",
"new",
"self",
"(",
"$",
"message",
",",
"$",
"request",
",",
"$",
"response",
",",
"$",
"last_exception",
")",
";",
"}"
] |
Create a new exception with standardized error message
@param \Psr\Http\Message\RequestInterface $request Request object
@param \Psr\Http\Message\ResponseInterface $response Response object
@param \Exception|null $last_exception Previous exception object
@return \pdeans\Http\Exceptions\HttpException
|
[
"Create",
"a",
"new",
"exception",
"with",
"standardized",
"error",
"message"
] |
6ebd9d9926ed815d85d47c8808ca87b236e49d88
|
https://github.com/pdeans/http/blob/6ebd9d9926ed815d85d47c8808ca87b236e49d88/src/Exceptions/HttpException.php#L60-L74
|
224,899
|
moeen-basra/laravel-passport-mongodb
|
src/TokenRepository.php
|
TokenRepository.getValidToken
|
public function getValidToken($user, $client)
{
return $client->tokens()
->whereUserId($user->getKey())
->whereRevoked(0)
->where('expires_at', '>', Carbon::now())
->first();
}
|
php
|
public function getValidToken($user, $client)
{
return $client->tokens()
->whereUserId($user->getKey())
->whereRevoked(0)
->where('expires_at', '>', Carbon::now())
->first();
}
|
[
"public",
"function",
"getValidToken",
"(",
"$",
"user",
",",
"$",
"client",
")",
"{",
"return",
"$",
"client",
"->",
"tokens",
"(",
")",
"->",
"whereUserId",
"(",
"$",
"user",
"->",
"getKey",
"(",
")",
")",
"->",
"whereRevoked",
"(",
"0",
")",
"->",
"where",
"(",
"'expires_at'",
",",
"'>'",
",",
"Carbon",
"::",
"now",
"(",
")",
")",
"->",
"first",
"(",
")",
";",
"}"
] |
Get a valid token instance for the given user and client.
@param \Jenssegers\Mongodb\Eloquent\Model $user
@param \MoeenBasra\LaravelPassportMongoDB\Client $client
@return \MoeenBasra\LaravelPassportMongoDB\Token|null
|
[
"Get",
"a",
"valid",
"token",
"instance",
"for",
"the",
"given",
"user",
"and",
"client",
"."
] |
738261912672e39f9f4f4e5bf420b99dbe303ef8
|
https://github.com/moeen-basra/laravel-passport-mongodb/blob/738261912672e39f9f4f4e5bf420b99dbe303ef8/src/TokenRepository.php#L62-L69
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.