repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
Stillat/Common | src/Stillat/Common/Traits/Expectations.php | Expectations.expectNumberNotZeroForDivision | protected function expectNumberNotZeroForDivision($number, $message = '')
{
$this->expectValidNumber($number, $message);
if ($number == 0) {
throw new DivideByZeroException($message);
}
} | php | protected function expectNumberNotZeroForDivision($number, $message = '')
{
$this->expectValidNumber($number, $message);
if ($number == 0) {
throw new DivideByZeroException($message);
}
} | [
"protected",
"function",
"expectNumberNotZeroForDivision",
"(",
"$",
"number",
",",
"$",
"message",
"=",
"''",
")",
"{",
"$",
"this",
"->",
"expectValidNumber",
"(",
"$",
"number",
",",
"$",
"message",
")",
";",
"if",
"(",
"$",
"number",
"==",
"0",
")",
"{",
"throw",
"new",
"DivideByZeroException",
"(",
"$",
"message",
")",
";",
"}",
"}"
] | Expects a number not to be zero when using for division.
@param $number
@param string $message
@throws \Stillat\Common\Exceptions\Arithmetic\DivideByZeroException
@throws \Stillat\Common\Exceptions\Arithmetic\NotFiniteNumberException | [
"Expects",
"a",
"number",
"not",
"to",
"be",
"zero",
"when",
"using",
"for",
"division",
"."
] | 9f69105292740c307aece588cf58a85892bad350 | https://github.com/Stillat/Common/blob/9f69105292740c307aece588cf58a85892bad350/src/Stillat/Common/Traits/Expectations.php#L68-L74 | train |
joegreen88/zf1-component-validate | src/Zend/Validate/File/Hash.php | Zend_Validate_File_Hash.addHash | public function addHash($options)
{
if (is_string($options)) {
$options = array($options);
} else if (!is_array($options)) {
throw new Zend_Validate_Exception("False parameter given");
}
$known = hash_algos();
if (!isset($options['algorithm'])) {
$algorithm = 'crc32';
} else {
$algorithm = $options['algorithm'];
unset($options['algorithm']);
}
if (!in_array($algorithm, $known)) {
throw new Zend_Validate_Exception("Unknown algorithm '{$algorithm}'");
}
foreach ($options as $value) {
$this->_hash[$value] = $algorithm;
}
return $this;
} | php | public function addHash($options)
{
if (is_string($options)) {
$options = array($options);
} else if (!is_array($options)) {
throw new Zend_Validate_Exception("False parameter given");
}
$known = hash_algos();
if (!isset($options['algorithm'])) {
$algorithm = 'crc32';
} else {
$algorithm = $options['algorithm'];
unset($options['algorithm']);
}
if (!in_array($algorithm, $known)) {
throw new Zend_Validate_Exception("Unknown algorithm '{$algorithm}'");
}
foreach ($options as $value) {
$this->_hash[$value] = $algorithm;
}
return $this;
} | [
"public",
"function",
"addHash",
"(",
"$",
"options",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"$",
"options",
")",
";",
"}",
"else",
"if",
"(",
"!",
"is_array",
"(",
"$",
"options",
")",
")",
"{",
"throw",
"new",
"Zend_Validate_Exception",
"(",
"\"False parameter given\"",
")",
";",
"}",
"$",
"known",
"=",
"hash_algos",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'algorithm'",
"]",
")",
")",
"{",
"$",
"algorithm",
"=",
"'crc32'",
";",
"}",
"else",
"{",
"$",
"algorithm",
"=",
"$",
"options",
"[",
"'algorithm'",
"]",
";",
"unset",
"(",
"$",
"options",
"[",
"'algorithm'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"algorithm",
",",
"$",
"known",
")",
")",
"{",
"throw",
"new",
"Zend_Validate_Exception",
"(",
"\"Unknown algorithm '{$algorithm}'\"",
")",
";",
"}",
"foreach",
"(",
"$",
"options",
"as",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"_hash",
"[",
"$",
"value",
"]",
"=",
"$",
"algorithm",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Adds the hash for one or multiple files
@param string|array $options
@return Zend_Validate_File_Hash Provides a fluent interface | [
"Adds",
"the",
"hash",
"for",
"one",
"or",
"multiple",
"files"
] | 88d9ea016f73d48ff0ba7d06ecbbf28951fd279e | https://github.com/joegreen88/zf1-component-validate/blob/88d9ea016f73d48ff0ba7d06ecbbf28951fd279e/src/Zend/Validate/File/Hash.php#L114-L141 | train |
ARCANESOFT/Blog | src/Http/Controllers/Admin/DashboardController.php | DashboardController.index | public function index()
{
$this->authorize(DashboardPolicy::PERMISSION_STATS);
$this->setTitle(trans('blog::dashboard.titles.statistics'));
return $this->view('admin.dashboard');
} | php | public function index()
{
$this->authorize(DashboardPolicy::PERMISSION_STATS);
$this->setTitle(trans('blog::dashboard.titles.statistics'));
return $this->view('admin.dashboard');
} | [
"public",
"function",
"index",
"(",
")",
"{",
"$",
"this",
"->",
"authorize",
"(",
"DashboardPolicy",
"::",
"PERMISSION_STATS",
")",
";",
"$",
"this",
"->",
"setTitle",
"(",
"trans",
"(",
"'blog::dashboard.titles.statistics'",
")",
")",
";",
"return",
"$",
"this",
"->",
"view",
"(",
"'admin.dashboard'",
")",
";",
"}"
] | Get the dashboard page.
@return \Illuminate\View\View | [
"Get",
"the",
"dashboard",
"page",
"."
] | 2078fdfdcbccda161c02899b9e1f344f011b2859 | https://github.com/ARCANESOFT/Blog/blob/2078fdfdcbccda161c02899b9e1f344f011b2859/src/Http/Controllers/Admin/DashboardController.php#L39-L46 | train |
Marwelln/Notifier | src/Marwelln/Notifier/Notify.php | Notify.flash | public function flash($message = null, $type = null) {
if ($message !== null) $this->attributes['message'] = (array) $message;
if ($type !== null) $this->attributes['type'] = $type;
$this->session->flash('notifier', $this->attributes);
} | php | public function flash($message = null, $type = null) {
if ($message !== null) $this->attributes['message'] = (array) $message;
if ($type !== null) $this->attributes['type'] = $type;
$this->session->flash('notifier', $this->attributes);
} | [
"public",
"function",
"flash",
"(",
"$",
"message",
"=",
"null",
",",
"$",
"type",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"message",
"!==",
"null",
")",
"$",
"this",
"->",
"attributes",
"[",
"'message'",
"]",
"=",
"(",
"array",
")",
"$",
"message",
";",
"if",
"(",
"$",
"type",
"!==",
"null",
")",
"$",
"this",
"->",
"attributes",
"[",
"'type'",
"]",
"=",
"$",
"type",
";",
"$",
"this",
"->",
"session",
"->",
"flash",
"(",
"'notifier'",
",",
"$",
"this",
"->",
"attributes",
")",
";",
"}"
] | Save the setup to a session flash.
@return void | [
"Save",
"the",
"setup",
"to",
"a",
"session",
"flash",
"."
] | f3a17802f4bd0ce13f23ca54d32c254617cf2f17 | https://github.com/Marwelln/Notifier/blob/f3a17802f4bd0ce13f23ca54d32c254617cf2f17/src/Marwelln/Notifier/Notify.php#L91-L96 | train |
RocketPropelledTortoise/Core | src/Taxonomy/Utils/CommonTableExpressionQuery.php | CommonTableExpressionQuery.runQuery | protected function runQuery($raw_query, $id)
{
$query = str_replace(':id', $id, $raw_query);
$start = microtime(true);
// Does not work as a prepared statement; we have to execute it directly
$results = DB::getReadPdo()->query($query)->fetchAll(\PDO::FETCH_OBJ);
// Log the query manually
DB::logQuery($raw_query, [$id], round((microtime(true) - $start) * 1000, 2));
return $results;
} | php | protected function runQuery($raw_query, $id)
{
$query = str_replace(':id', $id, $raw_query);
$start = microtime(true);
// Does not work as a prepared statement; we have to execute it directly
$results = DB::getReadPdo()->query($query)->fetchAll(\PDO::FETCH_OBJ);
// Log the query manually
DB::logQuery($raw_query, [$id], round((microtime(true) - $start) * 1000, 2));
return $results;
} | [
"protected",
"function",
"runQuery",
"(",
"$",
"raw_query",
",",
"$",
"id",
")",
"{",
"$",
"query",
"=",
"str_replace",
"(",
"':id'",
",",
"$",
"id",
",",
"$",
"raw_query",
")",
";",
"$",
"start",
"=",
"microtime",
"(",
"true",
")",
";",
"// Does not work as a prepared statement; we have to execute it directly",
"$",
"results",
"=",
"DB",
"::",
"getReadPdo",
"(",
")",
"->",
"query",
"(",
"$",
"query",
")",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_OBJ",
")",
";",
"// Log the query manually",
"DB",
"::",
"logQuery",
"(",
"$",
"raw_query",
",",
"[",
"$",
"id",
"]",
",",
"round",
"(",
"(",
"microtime",
"(",
"true",
")",
"-",
"$",
"start",
")",
"*",
"1000",
",",
"2",
")",
")",
";",
"return",
"$",
"results",
";",
"}"
] | Execute the query with the current PDO connection.
Will log the time taken manually
@param string $raw_query
@param int $id
@return \Illuminate\Support\Collection | [
"Execute",
"the",
"query",
"with",
"the",
"current",
"PDO",
"connection",
".",
"Will",
"log",
"the",
"time",
"taken",
"manually"
] | 78b65663fc463e21e494257140ddbed0a9ccb3c3 | https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Taxonomy/Utils/CommonTableExpressionQuery.php#L27-L40 | train |
RocketPropelledTortoise/Core | src/Taxonomy/Utils/CommonTableExpressionQuery.php | CommonTableExpressionQuery.assembleQuery | protected function assembleQuery($initial, $recursive)
{
$tmp_tbl = 'name_tree';
$recursive = str_replace(':tmp_tbl', $tmp_tbl, $recursive);
$final = "select distinct * from $tmp_tbl";
if (DB::connection()->getDriverName() == 'mysql') {
return "Call WITH_EMULATOR('$tmp_tbl', '$initial', '$recursive', '$final', 0, 'ENGINE=MEMORY');";
}
return "WITH RECURSIVE $tmp_tbl AS ($initial UNION ALL $recursive) $final;";
} | php | protected function assembleQuery($initial, $recursive)
{
$tmp_tbl = 'name_tree';
$recursive = str_replace(':tmp_tbl', $tmp_tbl, $recursive);
$final = "select distinct * from $tmp_tbl";
if (DB::connection()->getDriverName() == 'mysql') {
return "Call WITH_EMULATOR('$tmp_tbl', '$initial', '$recursive', '$final', 0, 'ENGINE=MEMORY');";
}
return "WITH RECURSIVE $tmp_tbl AS ($initial UNION ALL $recursive) $final;";
} | [
"protected",
"function",
"assembleQuery",
"(",
"$",
"initial",
",",
"$",
"recursive",
")",
"{",
"$",
"tmp_tbl",
"=",
"'name_tree'",
";",
"$",
"recursive",
"=",
"str_replace",
"(",
"':tmp_tbl'",
",",
"$",
"tmp_tbl",
",",
"$",
"recursive",
")",
";",
"$",
"final",
"=",
"\"select distinct * from $tmp_tbl\"",
";",
"if",
"(",
"DB",
"::",
"connection",
"(",
")",
"->",
"getDriverName",
"(",
")",
"==",
"'mysql'",
")",
"{",
"return",
"\"Call WITH_EMULATOR('$tmp_tbl', '$initial', '$recursive', '$final', 0, 'ENGINE=MEMORY');\"",
";",
"}",
"return",
"\"WITH RECURSIVE $tmp_tbl AS ($initial UNION ALL $recursive) $final;\"",
";",
"}"
] | Prepare the complete query to run on the DB to get the data recursively.
@param string $initial The initial query bootstrapping the recursive query
@param string $recursive The query to dig deeper in the hierarchy
@return string | [
"Prepare",
"the",
"complete",
"query",
"to",
"run",
"on",
"the",
"DB",
"to",
"get",
"the",
"data",
"recursively",
"."
] | 78b65663fc463e21e494257140ddbed0a9ccb3c3 | https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Taxonomy/Utils/CommonTableExpressionQuery.php#L49-L61 | train |
patrickisgreat/da-php-fuel-sdk | src/ET_Client.php | ET_Client.getConfig | public function getConfig()
{
$config = false;
if (file_exists(realpath(__DIR__ . "/../ExactTargetLaravelConfig.php"))) {
$config = include __DIR__ . "/../ExactTargetLaravelConfig.php";
return $config;
}
return $config;
} | php | public function getConfig()
{
$config = false;
if (file_exists(realpath(__DIR__ . "/../ExactTargetLaravelConfig.php"))) {
$config = include __DIR__ . "/../ExactTargetLaravelConfig.php";
return $config;
}
return $config;
} | [
"public",
"function",
"getConfig",
"(",
")",
"{",
"$",
"config",
"=",
"false",
";",
"if",
"(",
"file_exists",
"(",
"realpath",
"(",
"__DIR__",
".",
"\"/../ExactTargetLaravelConfig.php\"",
")",
")",
")",
"{",
"$",
"config",
"=",
"include",
"__DIR__",
".",
"\"/../ExactTargetLaravelConfig.php\"",
";",
"return",
"$",
"config",
";",
"}",
"return",
"$",
"config",
";",
"}"
] | Gets the Configuration
@return array | [
"Gets",
"the",
"Configuration"
] | 6935f51b4d3dbd0923aed746620955fd63789549 | https://github.com/patrickisgreat/da-php-fuel-sdk/blob/6935f51b4d3dbd0923aed746620955fd63789549/src/ET_Client.php#L239-L247 | train |
patrickisgreat/da-php-fuel-sdk | src/ET_Client.php | ET_Client.refreshToken | public function refreshToken($forceRefresh = false)
{
if (property_exists($this, "sdl") && $this->sdl == 0) {
parent::__construct($this->xmlLoc, array('trace'=>1, 'exceptions'=>0));
}
try {
$currentTime = new DateTime();
if (is_null($this->getAuthTokenExpiration($this->tenantKey))) {
$timeDiff = 0;
} else {
$timeDiff = $currentTime->diff($this->getAuthTokenExpiration($this->tenantKey))->format('%i');
$timeDiff = $timeDiff + (60 * $currentTime->diff($this->getAuthTokenExpiration($this->tenantKey))->format('%H'));
}
if (is_null($this->getAuthToken($this->tenantKey)) || ($timeDiff < 5) || $forceRefresh) {
$url = $this->tenantKey == null
? $this->baseAuthUrl."/v1/requestToken?legacy=1"
: $this->baseUrl."/provisioning/v1/tenants/{$this->tenantKey}/requestToken?legacy=1";
$jsonRequest = new stdClass();
$jsonRequest->clientId = $this->clientId;
$jsonRequest->clientSecret = $this->clientSecret;
$jsonRequest->accessType = "offline";
if (!is_null($this->getRefreshToken($this->tenantKey))) {
$jsonRequest->refreshToken = $this->getRefreshToken($this->tenantKey);
}
$authResponse = ET_Util::restPost($url, json_encode($jsonRequest), $this);
$authObject = json_decode($authResponse->body);
//echo "auth: \n";
//print_r($authResponse);
if ($authResponse && property_exists($authObject, "accessToken")) {
$dv = new DateInterval('PT'.$authObject->expiresIn.'S');
$newexpTime = new DateTime();
$this->setAuthToken($this->tenantKey, $authObject->accessToken, $newexpTime->add($dv));
$this->setInternalAuthToken($this->tenantKey, $authObject->legacyToken);
if (property_exists($authObject, 'refreshToken')) {
$this->setRefreshToken($this->tenantKey, $authObject->refreshToken);
}
} else {
throw new Exception('Unable to validate App Keys(ClientID/ClientSecret) provided, requestToken response:'.$authResponse->body);
}
}
} catch (Exception $e) {
throw new Exception('Unable to validate App Keys(ClientID/ClientSecret) provided.: '.$e->getMessage());
}
} | php | public function refreshToken($forceRefresh = false)
{
if (property_exists($this, "sdl") && $this->sdl == 0) {
parent::__construct($this->xmlLoc, array('trace'=>1, 'exceptions'=>0));
}
try {
$currentTime = new DateTime();
if (is_null($this->getAuthTokenExpiration($this->tenantKey))) {
$timeDiff = 0;
} else {
$timeDiff = $currentTime->diff($this->getAuthTokenExpiration($this->tenantKey))->format('%i');
$timeDiff = $timeDiff + (60 * $currentTime->diff($this->getAuthTokenExpiration($this->tenantKey))->format('%H'));
}
if (is_null($this->getAuthToken($this->tenantKey)) || ($timeDiff < 5) || $forceRefresh) {
$url = $this->tenantKey == null
? $this->baseAuthUrl."/v1/requestToken?legacy=1"
: $this->baseUrl."/provisioning/v1/tenants/{$this->tenantKey}/requestToken?legacy=1";
$jsonRequest = new stdClass();
$jsonRequest->clientId = $this->clientId;
$jsonRequest->clientSecret = $this->clientSecret;
$jsonRequest->accessType = "offline";
if (!is_null($this->getRefreshToken($this->tenantKey))) {
$jsonRequest->refreshToken = $this->getRefreshToken($this->tenantKey);
}
$authResponse = ET_Util::restPost($url, json_encode($jsonRequest), $this);
$authObject = json_decode($authResponse->body);
//echo "auth: \n";
//print_r($authResponse);
if ($authResponse && property_exists($authObject, "accessToken")) {
$dv = new DateInterval('PT'.$authObject->expiresIn.'S');
$newexpTime = new DateTime();
$this->setAuthToken($this->tenantKey, $authObject->accessToken, $newexpTime->add($dv));
$this->setInternalAuthToken($this->tenantKey, $authObject->legacyToken);
if (property_exists($authObject, 'refreshToken')) {
$this->setRefreshToken($this->tenantKey, $authObject->refreshToken);
}
} else {
throw new Exception('Unable to validate App Keys(ClientID/ClientSecret) provided, requestToken response:'.$authResponse->body);
}
}
} catch (Exception $e) {
throw new Exception('Unable to validate App Keys(ClientID/ClientSecret) provided.: '.$e->getMessage());
}
} | [
"public",
"function",
"refreshToken",
"(",
"$",
"forceRefresh",
"=",
"false",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"this",
",",
"\"sdl\"",
")",
"&&",
"$",
"this",
"->",
"sdl",
"==",
"0",
")",
"{",
"parent",
"::",
"__construct",
"(",
"$",
"this",
"->",
"xmlLoc",
",",
"array",
"(",
"'trace'",
"=>",
"1",
",",
"'exceptions'",
"=>",
"0",
")",
")",
";",
"}",
"try",
"{",
"$",
"currentTime",
"=",
"new",
"DateTime",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"getAuthTokenExpiration",
"(",
"$",
"this",
"->",
"tenantKey",
")",
")",
")",
"{",
"$",
"timeDiff",
"=",
"0",
";",
"}",
"else",
"{",
"$",
"timeDiff",
"=",
"$",
"currentTime",
"->",
"diff",
"(",
"$",
"this",
"->",
"getAuthTokenExpiration",
"(",
"$",
"this",
"->",
"tenantKey",
")",
")",
"->",
"format",
"(",
"'%i'",
")",
";",
"$",
"timeDiff",
"=",
"$",
"timeDiff",
"+",
"(",
"60",
"*",
"$",
"currentTime",
"->",
"diff",
"(",
"$",
"this",
"->",
"getAuthTokenExpiration",
"(",
"$",
"this",
"->",
"tenantKey",
")",
")",
"->",
"format",
"(",
"'%H'",
")",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"getAuthToken",
"(",
"$",
"this",
"->",
"tenantKey",
")",
")",
"||",
"(",
"$",
"timeDiff",
"<",
"5",
")",
"||",
"$",
"forceRefresh",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"tenantKey",
"==",
"null",
"?",
"$",
"this",
"->",
"baseAuthUrl",
".",
"\"/v1/requestToken?legacy=1\"",
":",
"$",
"this",
"->",
"baseUrl",
".",
"\"/provisioning/v1/tenants/{$this->tenantKey}/requestToken?legacy=1\"",
";",
"$",
"jsonRequest",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"jsonRequest",
"->",
"clientId",
"=",
"$",
"this",
"->",
"clientId",
";",
"$",
"jsonRequest",
"->",
"clientSecret",
"=",
"$",
"this",
"->",
"clientSecret",
";",
"$",
"jsonRequest",
"->",
"accessType",
"=",
"\"offline\"",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"getRefreshToken",
"(",
"$",
"this",
"->",
"tenantKey",
")",
")",
")",
"{",
"$",
"jsonRequest",
"->",
"refreshToken",
"=",
"$",
"this",
"->",
"getRefreshToken",
"(",
"$",
"this",
"->",
"tenantKey",
")",
";",
"}",
"$",
"authResponse",
"=",
"ET_Util",
"::",
"restPost",
"(",
"$",
"url",
",",
"json_encode",
"(",
"$",
"jsonRequest",
")",
",",
"$",
"this",
")",
";",
"$",
"authObject",
"=",
"json_decode",
"(",
"$",
"authResponse",
"->",
"body",
")",
";",
"//echo \"auth: \\n\";",
"//print_r($authResponse);",
"if",
"(",
"$",
"authResponse",
"&&",
"property_exists",
"(",
"$",
"authObject",
",",
"\"accessToken\"",
")",
")",
"{",
"$",
"dv",
"=",
"new",
"DateInterval",
"(",
"'PT'",
".",
"$",
"authObject",
"->",
"expiresIn",
".",
"'S'",
")",
";",
"$",
"newexpTime",
"=",
"new",
"DateTime",
"(",
")",
";",
"$",
"this",
"->",
"setAuthToken",
"(",
"$",
"this",
"->",
"tenantKey",
",",
"$",
"authObject",
"->",
"accessToken",
",",
"$",
"newexpTime",
"->",
"add",
"(",
"$",
"dv",
")",
")",
";",
"$",
"this",
"->",
"setInternalAuthToken",
"(",
"$",
"this",
"->",
"tenantKey",
",",
"$",
"authObject",
"->",
"legacyToken",
")",
";",
"if",
"(",
"property_exists",
"(",
"$",
"authObject",
",",
"'refreshToken'",
")",
")",
"{",
"$",
"this",
"->",
"setRefreshToken",
"(",
"$",
"this",
"->",
"tenantKey",
",",
"$",
"authObject",
"->",
"refreshToken",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'Unable to validate App Keys(ClientID/ClientSecret) provided, requestToken response:'",
".",
"$",
"authResponse",
"->",
"body",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Unable to validate App Keys(ClientID/ClientSecret) provided.: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Gets the refresh token using the authentication URL.
@param boolean $forceRefresh Flag to indicate a force refresh of authentication toekn.
@return void | [
"Gets",
"the",
"refresh",
"token",
"using",
"the",
"authentication",
"URL",
"."
] | 6935f51b4d3dbd0923aed746620955fd63789549 | https://github.com/patrickisgreat/da-php-fuel-sdk/blob/6935f51b4d3dbd0923aed746620955fd63789549/src/ET_Client.php#L255-L300 | train |
patrickisgreat/da-php-fuel-sdk | src/ET_Client.php | ET_Client.setAuthToken | public function setAuthToken($tenantKey, $authToken, $authTokenExpiration)
{
if ($this->tenantTokens[$tenantKey] == null) {
$this->tenantTokens[$tenantKey] = array();
}
$this->tenantTokens[$tenantKey]['authToken'] = $authToken;
$this->tenantTokens[$tenantKey]['authTokenExpiration'] = $authTokenExpiration;
} | php | public function setAuthToken($tenantKey, $authToken, $authTokenExpiration)
{
if ($this->tenantTokens[$tenantKey] == null) {
$this->tenantTokens[$tenantKey] = array();
}
$this->tenantTokens[$tenantKey]['authToken'] = $authToken;
$this->tenantTokens[$tenantKey]['authTokenExpiration'] = $authTokenExpiration;
} | [
"public",
"function",
"setAuthToken",
"(",
"$",
"tenantKey",
",",
"$",
"authToken",
",",
"$",
"authTokenExpiration",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"tenantTokens",
"[",
"$",
"tenantKey",
"]",
"==",
"null",
")",
"{",
"$",
"this",
"->",
"tenantTokens",
"[",
"$",
"tenantKey",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"tenantTokens",
"[",
"$",
"tenantKey",
"]",
"[",
"'authToken'",
"]",
"=",
"$",
"authToken",
";",
"$",
"this",
"->",
"tenantTokens",
"[",
"$",
"tenantKey",
"]",
"[",
"'authTokenExpiration'",
"]",
"=",
"$",
"authTokenExpiration",
";",
"}"
] | Set the authentication token in the tenantTokens array.
@param string $tenantKey Tenant key for which auth toke to be set
@param string $authToken Authentication token to be set
@param string $authTokenExpiration Authentication token expiration value | [
"Set",
"the",
"authentication",
"token",
"in",
"the",
"tenantTokens",
"array",
"."
] | 6935f51b4d3dbd0923aed746620955fd63789549 | https://github.com/patrickisgreat/da-php-fuel-sdk/blob/6935f51b4d3dbd0923aed746620955fd63789549/src/ET_Client.php#L474-L481 | train |
patrickisgreat/da-php-fuel-sdk | src/ET_Client.php | ET_Client.getAuthTokenExpiration | public function getAuthTokenExpiration($tenantKey)
{
$tenantKey = $tenantKey == null ? $this->tenantKey : $tenantKey;
if ($this->tenantTokens[$tenantKey] == null) {
$this->tenantTokens[$tenantKey] = array();
}
return isset($this->tenantTokens[$tenantKey]['authTokenExpiration'])
? $this->tenantTokens[$tenantKey]['authTokenExpiration']
: null;
} | php | public function getAuthTokenExpiration($tenantKey)
{
$tenantKey = $tenantKey == null ? $this->tenantKey : $tenantKey;
if ($this->tenantTokens[$tenantKey] == null) {
$this->tenantTokens[$tenantKey] = array();
}
return isset($this->tenantTokens[$tenantKey]['authTokenExpiration'])
? $this->tenantTokens[$tenantKey]['authTokenExpiration']
: null;
} | [
"public",
"function",
"getAuthTokenExpiration",
"(",
"$",
"tenantKey",
")",
"{",
"$",
"tenantKey",
"=",
"$",
"tenantKey",
"==",
"null",
"?",
"$",
"this",
"->",
"tenantKey",
":",
"$",
"tenantKey",
";",
"if",
"(",
"$",
"this",
"->",
"tenantTokens",
"[",
"$",
"tenantKey",
"]",
"==",
"null",
")",
"{",
"$",
"this",
"->",
"tenantTokens",
"[",
"$",
"tenantKey",
"]",
"=",
"array",
"(",
")",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"tenantTokens",
"[",
"$",
"tenantKey",
"]",
"[",
"'authTokenExpiration'",
"]",
")",
"?",
"$",
"this",
"->",
"tenantTokens",
"[",
"$",
"tenantKey",
"]",
"[",
"'authTokenExpiration'",
"]",
":",
"null",
";",
"}"
] | Get the Auth Token Expiration.
@param string $tenantKey Tenant key for which authenication token is returned
@return string Authenticaiton token for the tenant key | [
"Get",
"the",
"Auth",
"Token",
"Expiration",
"."
] | 6935f51b4d3dbd0923aed746620955fd63789549 | https://github.com/patrickisgreat/da-php-fuel-sdk/blob/6935f51b4d3dbd0923aed746620955fd63789549/src/ET_Client.php#L488-L497 | train |
patrickisgreat/da-php-fuel-sdk | src/ET_Client.php | ET_Client.setInternalAuthToken | public function setInternalAuthToken($tenantKey, $internalAuthToken)
{
if ($this->tenantTokens[$tenantKey] == null) {
$this->tenantTokens[$tenantKey] = array();
}
$this->tenantTokens[$tenantKey]['internalAuthToken'] = $internalAuthToken;
} | php | public function setInternalAuthToken($tenantKey, $internalAuthToken)
{
if ($this->tenantTokens[$tenantKey] == null) {
$this->tenantTokens[$tenantKey] = array();
}
$this->tenantTokens[$tenantKey]['internalAuthToken'] = $internalAuthToken;
} | [
"public",
"function",
"setInternalAuthToken",
"(",
"$",
"tenantKey",
",",
"$",
"internalAuthToken",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"tenantTokens",
"[",
"$",
"tenantKey",
"]",
"==",
"null",
")",
"{",
"$",
"this",
"->",
"tenantTokens",
"[",
"$",
"tenantKey",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"tenantTokens",
"[",
"$",
"tenantKey",
"]",
"[",
"'internalAuthToken'",
"]",
"=",
"$",
"internalAuthToken",
";",
"}"
] | Set the internal auth tokan.
@param string $tenantKey
@param string $internalAuthToken | [
"Set",
"the",
"internal",
"auth",
"tokan",
"."
] | 6935f51b4d3dbd0923aed746620955fd63789549 | https://github.com/patrickisgreat/da-php-fuel-sdk/blob/6935f51b4d3dbd0923aed746620955fd63789549/src/ET_Client.php#L520-L526 | train |
patrickisgreat/da-php-fuel-sdk | src/ET_Client.php | ET_Client.setRefreshToken | public function setRefreshToken($tenantKey, $refreshToken)
{
if ($this->tenantTokens[$tenantKey] == null) {
$this->tenantTokens[$tenantKey] = array();
}
$this->tenantTokens[$tenantKey]['refreshToken'] = $refreshToken;
} | php | public function setRefreshToken($tenantKey, $refreshToken)
{
if ($this->tenantTokens[$tenantKey] == null) {
$this->tenantTokens[$tenantKey] = array();
}
$this->tenantTokens[$tenantKey]['refreshToken'] = $refreshToken;
} | [
"public",
"function",
"setRefreshToken",
"(",
"$",
"tenantKey",
",",
"$",
"refreshToken",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"tenantTokens",
"[",
"$",
"tenantKey",
"]",
"==",
"null",
")",
"{",
"$",
"this",
"->",
"tenantTokens",
"[",
"$",
"tenantKey",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"tenantTokens",
"[",
"$",
"tenantKey",
"]",
"[",
"'refreshToken'",
"]",
"=",
"$",
"refreshToken",
";",
"}"
] | Set the refresh authentication token.
@param string $tenantKey Tenant key to which refresh token is set
@param string $refreshToken Refresh authenication token | [
"Set",
"the",
"refresh",
"authentication",
"token",
"."
] | 6935f51b4d3dbd0923aed746620955fd63789549 | https://github.com/patrickisgreat/da-php-fuel-sdk/blob/6935f51b4d3dbd0923aed746620955fd63789549/src/ET_Client.php#L533-L539 | train |
patrickisgreat/da-php-fuel-sdk | src/ET_Client.php | ET_Client.getRefreshToken | public function getRefreshToken($tenantKey)
{
$tenantKey = $tenantKey == null ? $this->tenantKey : $tenantKey;
if ($this->tenantTokens[$tenantKey] == null) {
$this->tenantTokens[$tenantKey] = array();
}
return isset($this->tenantTokens[$tenantKey]['refreshToken'])
? $this->tenantTokens[$tenantKey]['refreshToken']
: null;
} | php | public function getRefreshToken($tenantKey)
{
$tenantKey = $tenantKey == null ? $this->tenantKey : $tenantKey;
if ($this->tenantTokens[$tenantKey] == null) {
$this->tenantTokens[$tenantKey] = array();
}
return isset($this->tenantTokens[$tenantKey]['refreshToken'])
? $this->tenantTokens[$tenantKey]['refreshToken']
: null;
} | [
"public",
"function",
"getRefreshToken",
"(",
"$",
"tenantKey",
")",
"{",
"$",
"tenantKey",
"=",
"$",
"tenantKey",
"==",
"null",
"?",
"$",
"this",
"->",
"tenantKey",
":",
"$",
"tenantKey",
";",
"if",
"(",
"$",
"this",
"->",
"tenantTokens",
"[",
"$",
"tenantKey",
"]",
"==",
"null",
")",
"{",
"$",
"this",
"->",
"tenantTokens",
"[",
"$",
"tenantKey",
"]",
"=",
"array",
"(",
")",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"tenantTokens",
"[",
"$",
"tenantKey",
"]",
"[",
"'refreshToken'",
"]",
")",
"?",
"$",
"this",
"->",
"tenantTokens",
"[",
"$",
"tenantKey",
"]",
"[",
"'refreshToken'",
"]",
":",
"null",
";",
"}"
] | Get the refresh token for the tenant.
@param string $tenantKey
@return string Refresh token for the tenant | [
"Get",
"the",
"refresh",
"token",
"for",
"the",
"tenant",
"."
] | 6935f51b4d3dbd0923aed746620955fd63789549 | https://github.com/patrickisgreat/da-php-fuel-sdk/blob/6935f51b4d3dbd0923aed746620955fd63789549/src/ET_Client.php#L547-L556 | train |
patrickisgreat/da-php-fuel-sdk | src/ET_Client.php | ET_Client.AddSubscriberToList | public function AddSubscriberToList($emailAddress, $listIDs, $subscriberKey = null)
{
$newSub = new ET_Subscriber;
$newSub->authStub = $this;
$lists = array();
foreach ($listIDs as $key => $value) {
$lists[] = array("ID" => $value);
}
//if (is_string($emailAddress)) {
$newSub->props = array("EmailAddress" => $emailAddress, "Lists" => $lists);
if ($subscriberKey != null) {
$newSub->props['SubscriberKey'] = $subscriberKey;
}
// Try to add the subscriber
$postResponse = $newSub->post();
if ($postResponse->status == false) {
// If the subscriber already exists in the account then we need to do an update.
// Update Subscriber On List
if ($postResponse->results[0]->ErrorCode == "12014") {
$patchResponse = $newSub->patch();
return $patchResponse;
}
}
return $postResponse;
} | php | public function AddSubscriberToList($emailAddress, $listIDs, $subscriberKey = null)
{
$newSub = new ET_Subscriber;
$newSub->authStub = $this;
$lists = array();
foreach ($listIDs as $key => $value) {
$lists[] = array("ID" => $value);
}
//if (is_string($emailAddress)) {
$newSub->props = array("EmailAddress" => $emailAddress, "Lists" => $lists);
if ($subscriberKey != null) {
$newSub->props['SubscriberKey'] = $subscriberKey;
}
// Try to add the subscriber
$postResponse = $newSub->post();
if ($postResponse->status == false) {
// If the subscriber already exists in the account then we need to do an update.
// Update Subscriber On List
if ($postResponse->results[0]->ErrorCode == "12014") {
$patchResponse = $newSub->patch();
return $patchResponse;
}
}
return $postResponse;
} | [
"public",
"function",
"AddSubscriberToList",
"(",
"$",
"emailAddress",
",",
"$",
"listIDs",
",",
"$",
"subscriberKey",
"=",
"null",
")",
"{",
"$",
"newSub",
"=",
"new",
"ET_Subscriber",
";",
"$",
"newSub",
"->",
"authStub",
"=",
"$",
"this",
";",
"$",
"lists",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"listIDs",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"lists",
"[",
"]",
"=",
"array",
"(",
"\"ID\"",
"=>",
"$",
"value",
")",
";",
"}",
"//if (is_string($emailAddress)) {",
"$",
"newSub",
"->",
"props",
"=",
"array",
"(",
"\"EmailAddress\"",
"=>",
"$",
"emailAddress",
",",
"\"Lists\"",
"=>",
"$",
"lists",
")",
";",
"if",
"(",
"$",
"subscriberKey",
"!=",
"null",
")",
"{",
"$",
"newSub",
"->",
"props",
"[",
"'SubscriberKey'",
"]",
"=",
"$",
"subscriberKey",
";",
"}",
"// Try to add the subscriber",
"$",
"postResponse",
"=",
"$",
"newSub",
"->",
"post",
"(",
")",
";",
"if",
"(",
"$",
"postResponse",
"->",
"status",
"==",
"false",
")",
"{",
"// If the subscriber already exists in the account then we need to do an update.",
"// Update Subscriber On List",
"if",
"(",
"$",
"postResponse",
"->",
"results",
"[",
"0",
"]",
"->",
"ErrorCode",
"==",
"\"12014\"",
")",
"{",
"$",
"patchResponse",
"=",
"$",
"newSub",
"->",
"patch",
"(",
")",
";",
"return",
"$",
"patchResponse",
";",
"}",
"}",
"return",
"$",
"postResponse",
";",
"}"
] | Add subscriber to list.
@param string $emailAddress Email address of the subscriber
@param array $listIDs Array of list id to which the subscriber is added
@param string $subscriberKey Newly added subscriber key
@return mixed post or patch response object. If the subscriber already existing patch response is returned otherwise post response returned. | [
"Add",
"subscriber",
"to",
"list",
"."
] | 6935f51b4d3dbd0923aed746620955fd63789549 | https://github.com/patrickisgreat/da-php-fuel-sdk/blob/6935f51b4d3dbd0923aed746620955fd63789549/src/ET_Client.php#L566-L593 | train |
patrickisgreat/da-php-fuel-sdk | src/ET_Client.php | ET_Client.CreateDataExtensions | public function CreateDataExtensions($dataExtensionDefinitions)
{
$newDEs = new ET_DataExtension();
$newDEs->authStub = $this;
$newDEs->props = $dataExtensionDefinitions;
$postResponse = $newDEs->post();
return $postResponse;
} | php | public function CreateDataExtensions($dataExtensionDefinitions)
{
$newDEs = new ET_DataExtension();
$newDEs->authStub = $this;
$newDEs->props = $dataExtensionDefinitions;
$postResponse = $newDEs->post();
return $postResponse;
} | [
"public",
"function",
"CreateDataExtensions",
"(",
"$",
"dataExtensionDefinitions",
")",
"{",
"$",
"newDEs",
"=",
"new",
"ET_DataExtension",
"(",
")",
";",
"$",
"newDEs",
"->",
"authStub",
"=",
"$",
"this",
";",
"$",
"newDEs",
"->",
"props",
"=",
"$",
"dataExtensionDefinitions",
";",
"$",
"postResponse",
"=",
"$",
"newDEs",
"->",
"post",
"(",
")",
";",
"return",
"$",
"postResponse",
";",
"}"
] | Create a new data extension based on the definition passed
@param array $dataExtensionDefinitions Data extension definition properties as an array
@return mixed post response object | [
"Create",
"a",
"new",
"data",
"extension",
"based",
"on",
"the",
"definition",
"passed"
] | 6935f51b4d3dbd0923aed746620955fd63789549 | https://github.com/patrickisgreat/da-php-fuel-sdk/blob/6935f51b4d3dbd0923aed746620955fd63789549/src/ET_Client.php#L623-L631 | train |
patrickisgreat/da-php-fuel-sdk | src/ET_Client.php | ET_Client.SendTriggeredSends | public function SendTriggeredSends($arrayOfTriggeredRecords)
{
$sendTS = new ET_TriggeredSend();
$sendTS->authStub = $this;
$sendTS->props = $arrayOfTriggeredRecords;
$sendResponse = $sendTS->send();
return $sendResponse;
} | php | public function SendTriggeredSends($arrayOfTriggeredRecords)
{
$sendTS = new ET_TriggeredSend();
$sendTS->authStub = $this;
$sendTS->props = $arrayOfTriggeredRecords;
$sendResponse = $sendTS->send();
return $sendResponse;
} | [
"public",
"function",
"SendTriggeredSends",
"(",
"$",
"arrayOfTriggeredRecords",
")",
"{",
"$",
"sendTS",
"=",
"new",
"ET_TriggeredSend",
"(",
")",
";",
"$",
"sendTS",
"->",
"authStub",
"=",
"$",
"this",
";",
"$",
"sendTS",
"->",
"props",
"=",
"$",
"arrayOfTriggeredRecords",
";",
"$",
"sendResponse",
"=",
"$",
"sendTS",
"->",
"send",
"(",
")",
";",
"return",
"$",
"sendResponse",
";",
"}"
] | Starts an send operation for the TriggerredSend records
@param array $arrayOfTriggeredRecords Array of TriggeredSend records
@return mixed Send reponse object | [
"Starts",
"an",
"send",
"operation",
"for",
"the",
"TriggerredSend",
"records"
] | 6935f51b4d3dbd0923aed746620955fd63789549 | https://github.com/patrickisgreat/da-php-fuel-sdk/blob/6935f51b4d3dbd0923aed746620955fd63789549/src/ET_Client.php#L638-L645 | train |
patrickisgreat/da-php-fuel-sdk | src/ET_Client.php | ET_Client.SendEmailToDataExtension | public function SendEmailToDataExtension($emailID, $sendableDataExtensionCustomerKey, $sendClassficationCustomerKey)
{
$email = new ET_Email_SendDefinition();
$email->props = array("Name"=>uniqid(), "CustomerKey"=>uniqid(), "Description"=>"Created with FuelSDK");
$email->props["SendClassification"] = array("CustomerKey"=> $sendClassficationCustomerKey);
$email->props["SendDefinitionList"] = array("CustomerKey"=> $sendableDataExtensionCustomerKey, "DataSourceTypeID"=>"CustomObject");
$email->props["Email"] = array("ID"=>$emailID);
$email->authStub = $this;
$result = $email->post();
if ($result->status) {
$sendresult = $email->send();
if ($sendresult->status) {
$deleteresult = $email->delete();
return $sendresult;
} else {
throw new Exception("Unable to send using send definition due to:".print_r($result, true));
}
} else {
throw new Exception("Unable to create send definition due to: ".print_r($result, true));
}
} | php | public function SendEmailToDataExtension($emailID, $sendableDataExtensionCustomerKey, $sendClassficationCustomerKey)
{
$email = new ET_Email_SendDefinition();
$email->props = array("Name"=>uniqid(), "CustomerKey"=>uniqid(), "Description"=>"Created with FuelSDK");
$email->props["SendClassification"] = array("CustomerKey"=> $sendClassficationCustomerKey);
$email->props["SendDefinitionList"] = array("CustomerKey"=> $sendableDataExtensionCustomerKey, "DataSourceTypeID"=>"CustomObject");
$email->props["Email"] = array("ID"=>$emailID);
$email->authStub = $this;
$result = $email->post();
if ($result->status) {
$sendresult = $email->send();
if ($sendresult->status) {
$deleteresult = $email->delete();
return $sendresult;
} else {
throw new Exception("Unable to send using send definition due to:".print_r($result, true));
}
} else {
throw new Exception("Unable to create send definition due to: ".print_r($result, true));
}
} | [
"public",
"function",
"SendEmailToDataExtension",
"(",
"$",
"emailID",
",",
"$",
"sendableDataExtensionCustomerKey",
",",
"$",
"sendClassficationCustomerKey",
")",
"{",
"$",
"email",
"=",
"new",
"ET_Email_SendDefinition",
"(",
")",
";",
"$",
"email",
"->",
"props",
"=",
"array",
"(",
"\"Name\"",
"=>",
"uniqid",
"(",
")",
",",
"\"CustomerKey\"",
"=>",
"uniqid",
"(",
")",
",",
"\"Description\"",
"=>",
"\"Created with FuelSDK\"",
")",
";",
"$",
"email",
"->",
"props",
"[",
"\"SendClassification\"",
"]",
"=",
"array",
"(",
"\"CustomerKey\"",
"=>",
"$",
"sendClassficationCustomerKey",
")",
";",
"$",
"email",
"->",
"props",
"[",
"\"SendDefinitionList\"",
"]",
"=",
"array",
"(",
"\"CustomerKey\"",
"=>",
"$",
"sendableDataExtensionCustomerKey",
",",
"\"DataSourceTypeID\"",
"=>",
"\"CustomObject\"",
")",
";",
"$",
"email",
"->",
"props",
"[",
"\"Email\"",
"]",
"=",
"array",
"(",
"\"ID\"",
"=>",
"$",
"emailID",
")",
";",
"$",
"email",
"->",
"authStub",
"=",
"$",
"this",
";",
"$",
"result",
"=",
"$",
"email",
"->",
"post",
"(",
")",
";",
"if",
"(",
"$",
"result",
"->",
"status",
")",
"{",
"$",
"sendresult",
"=",
"$",
"email",
"->",
"send",
"(",
")",
";",
"if",
"(",
"$",
"sendresult",
"->",
"status",
")",
"{",
"$",
"deleteresult",
"=",
"$",
"email",
"->",
"delete",
"(",
")",
";",
"return",
"$",
"sendresult",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"\"Unable to send using send definition due to:\"",
".",
"print_r",
"(",
"$",
"result",
",",
"true",
")",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"\"Unable to create send definition due to: \"",
".",
"print_r",
"(",
"$",
"result",
",",
"true",
")",
")",
";",
"}",
"}"
] | Create an email send definition, send the email based on the definition and delete the definition.
@param string $emailID Email identifier for which the email is sent
@param string $sendableDataExtensionCustomerKey Sendable data extension customer key
@param string $sendClassficationCustomerKey Send classification customer key
@return mixed Final delete action result | [
"Create",
"an",
"email",
"send",
"definition",
"send",
"the",
"email",
"based",
"on",
"the",
"definition",
"and",
"delete",
"the",
"definition",
"."
] | 6935f51b4d3dbd0923aed746620955fd63789549 | https://github.com/patrickisgreat/da-php-fuel-sdk/blob/6935f51b4d3dbd0923aed746620955fd63789549/src/ET_Client.php#L684-L704 | train |
patrickisgreat/da-php-fuel-sdk | src/ET_Client.php | ET_Client.CreateProfileAttributes | public function CreateProfileAttributes($allAttributes)
{
$attrs = new ET_ProfileAttribute();
$attrs->authStub = $this;
$attrs->props = $allAttributes;
return $attrs->post();
} | php | public function CreateProfileAttributes($allAttributes)
{
$attrs = new ET_ProfileAttribute();
$attrs->authStub = $this;
$attrs->props = $allAttributes;
return $attrs->post();
} | [
"public",
"function",
"CreateProfileAttributes",
"(",
"$",
"allAttributes",
")",
"{",
"$",
"attrs",
"=",
"new",
"ET_ProfileAttribute",
"(",
")",
";",
"$",
"attrs",
"->",
"authStub",
"=",
"$",
"this",
";",
"$",
"attrs",
"->",
"props",
"=",
"$",
"allAttributes",
";",
"return",
"$",
"attrs",
"->",
"post",
"(",
")",
";",
"}"
] | Create a profile attribute
@param array $allAttributes Profile attribute properties as an array.
@return mixed Post operation result | [
"Create",
"a",
"profile",
"attribute"
] | 6935f51b4d3dbd0923aed746620955fd63789549 | https://github.com/patrickisgreat/da-php-fuel-sdk/blob/6935f51b4d3dbd0923aed746620955fd63789549/src/ET_Client.php#L775-L781 | train |
patrickisgreat/da-php-fuel-sdk | src/ET_Client.php | ET_Client.CreateContentAreas | public function CreateContentAreas($arrayOfContentAreas)
{
$postC = new ET_ContentArea();
$postC->authStub = $this;
$postC->props = $arrayOfContentAreas;
$sendResponse = $postC->post();
return $sendResponse;
} | php | public function CreateContentAreas($arrayOfContentAreas)
{
$postC = new ET_ContentArea();
$postC->authStub = $this;
$postC->props = $arrayOfContentAreas;
$sendResponse = $postC->post();
return $sendResponse;
} | [
"public",
"function",
"CreateContentAreas",
"(",
"$",
"arrayOfContentAreas",
")",
"{",
"$",
"postC",
"=",
"new",
"ET_ContentArea",
"(",
")",
";",
"$",
"postC",
"->",
"authStub",
"=",
"$",
"this",
";",
"$",
"postC",
"->",
"props",
"=",
"$",
"arrayOfContentAreas",
";",
"$",
"sendResponse",
"=",
"$",
"postC",
"->",
"post",
"(",
")",
";",
"return",
"$",
"sendResponse",
";",
"}"
] | Create one or more content areas
@param array $arrayOfContentAreas Content areas properties as an array
@return void | [
"Create",
"one",
"or",
"more",
"content",
"areas"
] | 6935f51b4d3dbd0923aed746620955fd63789549 | https://github.com/patrickisgreat/da-php-fuel-sdk/blob/6935f51b4d3dbd0923aed746620955fd63789549/src/ET_Client.php#L788-L795 | train |
SagittariusX/Beluga.IO | src/Beluga/IO/Folder.php | Folder.Create | public static function Create( string $folder, int $mode = 0700 )
{
if ( \is_dir( $folder ) )
{
// No folder = do nothing
return;
}
if ( ! static::CanCreate( $folder ) )
{
// No rights to create the required folder
throw new FolderAccessError(
'IO',
$folder,
FolderAccessError::ACCESS_CREATE,
'Creation of folder fails cause base folder is not writable!'
);
}
try
{
if ( \DIRECTORY_SEPARATOR == '\\' )
{
// Windows = do not use the mode
$res = \mkdir( $folder, null, true );
}
else
{
// All other use the mode flag
$res = \mkdir( $folder, $mode, true );
}
}
catch ( \Throwable $ex )
{
// Folder creation fails
throw new FolderAccessError(
'IO',
$folder,
FolderAccessError::ACCESS_CREATE,
'Creation of folder fails cause base folder is not writable!',
\E_USER_ERROR,
$ex
);
}
if ( ! $res || ! \is_dir( $folder ) )
{
// Folder creation fails
throw new FolderAccessError(
'IO',
$folder,
FolderAccessError::ACCESS_CREATE,
'Unknown error while executing folder creation.'
);
}
\clearstatcache();
} | php | public static function Create( string $folder, int $mode = 0700 )
{
if ( \is_dir( $folder ) )
{
// No folder = do nothing
return;
}
if ( ! static::CanCreate( $folder ) )
{
// No rights to create the required folder
throw new FolderAccessError(
'IO',
$folder,
FolderAccessError::ACCESS_CREATE,
'Creation of folder fails cause base folder is not writable!'
);
}
try
{
if ( \DIRECTORY_SEPARATOR == '\\' )
{
// Windows = do not use the mode
$res = \mkdir( $folder, null, true );
}
else
{
// All other use the mode flag
$res = \mkdir( $folder, $mode, true );
}
}
catch ( \Throwable $ex )
{
// Folder creation fails
throw new FolderAccessError(
'IO',
$folder,
FolderAccessError::ACCESS_CREATE,
'Creation of folder fails cause base folder is not writable!',
\E_USER_ERROR,
$ex
);
}
if ( ! $res || ! \is_dir( $folder ) )
{
// Folder creation fails
throw new FolderAccessError(
'IO',
$folder,
FolderAccessError::ACCESS_CREATE,
'Unknown error while executing folder creation.'
);
}
\clearstatcache();
} | [
"public",
"static",
"function",
"Create",
"(",
"string",
"$",
"folder",
",",
"int",
"$",
"mode",
"=",
"0700",
")",
"{",
"if",
"(",
"\\",
"is_dir",
"(",
"$",
"folder",
")",
")",
"{",
"// No folder = do nothing",
"return",
";",
"}",
"if",
"(",
"!",
"static",
"::",
"CanCreate",
"(",
"$",
"folder",
")",
")",
"{",
"// No rights to create the required folder",
"throw",
"new",
"FolderAccessError",
"(",
"'IO'",
",",
"$",
"folder",
",",
"FolderAccessError",
"::",
"ACCESS_CREATE",
",",
"'Creation of folder fails cause base folder is not writable!'",
")",
";",
"}",
"try",
"{",
"if",
"(",
"\\",
"DIRECTORY_SEPARATOR",
"==",
"'\\\\'",
")",
"{",
"// Windows = do not use the mode",
"$",
"res",
"=",
"\\",
"mkdir",
"(",
"$",
"folder",
",",
"null",
",",
"true",
")",
";",
"}",
"else",
"{",
"// All other use the mode flag",
"$",
"res",
"=",
"\\",
"mkdir",
"(",
"$",
"folder",
",",
"$",
"mode",
",",
"true",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"ex",
")",
"{",
"// Folder creation fails",
"throw",
"new",
"FolderAccessError",
"(",
"'IO'",
",",
"$",
"folder",
",",
"FolderAccessError",
"::",
"ACCESS_CREATE",
",",
"'Creation of folder fails cause base folder is not writable!'",
",",
"\\",
"E_USER_ERROR",
",",
"$",
"ex",
")",
";",
"}",
"if",
"(",
"!",
"$",
"res",
"||",
"!",
"\\",
"is_dir",
"(",
"$",
"folder",
")",
")",
"{",
"// Folder creation fails",
"throw",
"new",
"FolderAccessError",
"(",
"'IO'",
",",
"$",
"folder",
",",
"FolderAccessError",
"::",
"ACCESS_CREATE",
",",
"'Unknown error while executing folder creation.'",
")",
";",
"}",
"\\",
"clearstatcache",
"(",
")",
";",
"}"
] | Creates a new folder with defined mode. The mode only works on unixoid systems.
@param string $folder The folder to create.
@param integer $mode Mode for new folder (0700) only used for unixoide systems
@throws \Beluga\IO\FolderAccessError If creation fails | [
"Creates",
"a",
"new",
"folder",
"with",
"defined",
"mode",
".",
"The",
"mode",
"only",
"works",
"on",
"unixoid",
"systems",
"."
] | c8af09a1b3cc8a955e43c89b70779d11b30ae29e | https://github.com/SagittariusX/Beluga.IO/blob/c8af09a1b3cc8a955e43c89b70779d11b30ae29e/src/Beluga/IO/Folder.php#L136-L195 | train |
SagittariusX/Beluga.IO | src/Beluga/IO/Folder.php | Folder.ListFilteredFiles | public static function ListFilteredFiles( string $folder, $filter, bool $recursive = false ) : array
{
// Init the array that should contain the resulting file paths
$files = array();
if ( ! \is_dir( $folder ) )
{
// No folder = we are done here
return $files;
}
if ( ! $recursive )
{
// List only files directly contained inside $folder (none from sub folders)
// Open the directory pointer
$d = \dir( $folder );
while ( false !== ( $entry = $d->read() ) )
{
if ( $entry == '.' || $entry == '..' )
{
// Ignore . and ..
continue;
}
$tmp = Path::Combine( $folder, $entry );
if ( ! \is_file( $tmp ) )
{
continue;
}
if ( \is_callable( $filter ) )
{
if ( \call_user_func( $filter, $entry, $tmp ) )
{
$files[] = $tmp;
}
continue;
}
try
{
if ( ! \preg_match( $filter, $entry ) )
{
continue;
}
$files[] = $tmp;
}
catch ( \Exception $ex ) { $ex = null; }
}
$d->close();
return $files;
}
static::_listRecursiveFiltered( $files, $filter, $folder );
return $files;
} | php | public static function ListFilteredFiles( string $folder, $filter, bool $recursive = false ) : array
{
// Init the array that should contain the resulting file paths
$files = array();
if ( ! \is_dir( $folder ) )
{
// No folder = we are done here
return $files;
}
if ( ! $recursive )
{
// List only files directly contained inside $folder (none from sub folders)
// Open the directory pointer
$d = \dir( $folder );
while ( false !== ( $entry = $d->read() ) )
{
if ( $entry == '.' || $entry == '..' )
{
// Ignore . and ..
continue;
}
$tmp = Path::Combine( $folder, $entry );
if ( ! \is_file( $tmp ) )
{
continue;
}
if ( \is_callable( $filter ) )
{
if ( \call_user_func( $filter, $entry, $tmp ) )
{
$files[] = $tmp;
}
continue;
}
try
{
if ( ! \preg_match( $filter, $entry ) )
{
continue;
}
$files[] = $tmp;
}
catch ( \Exception $ex ) { $ex = null; }
}
$d->close();
return $files;
}
static::_listRecursiveFiltered( $files, $filter, $folder );
return $files;
} | [
"public",
"static",
"function",
"ListFilteredFiles",
"(",
"string",
"$",
"folder",
",",
"$",
"filter",
",",
"bool",
"$",
"recursive",
"=",
"false",
")",
":",
"array",
"{",
"// Init the array that should contain the resulting file paths",
"$",
"files",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"\\",
"is_dir",
"(",
"$",
"folder",
")",
")",
"{",
"// No folder = we are done here",
"return",
"$",
"files",
";",
"}",
"if",
"(",
"!",
"$",
"recursive",
")",
"{",
"// List only files directly contained inside $folder (none from sub folders)",
"// Open the directory pointer",
"$",
"d",
"=",
"\\",
"dir",
"(",
"$",
"folder",
")",
";",
"while",
"(",
"false",
"!==",
"(",
"$",
"entry",
"=",
"$",
"d",
"->",
"read",
"(",
")",
")",
")",
"{",
"if",
"(",
"$",
"entry",
"==",
"'.'",
"||",
"$",
"entry",
"==",
"'..'",
")",
"{",
"// Ignore . and ..",
"continue",
";",
"}",
"$",
"tmp",
"=",
"Path",
"::",
"Combine",
"(",
"$",
"folder",
",",
"$",
"entry",
")",
";",
"if",
"(",
"!",
"\\",
"is_file",
"(",
"$",
"tmp",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"\\",
"is_callable",
"(",
"$",
"filter",
")",
")",
"{",
"if",
"(",
"\\",
"call_user_func",
"(",
"$",
"filter",
",",
"$",
"entry",
",",
"$",
"tmp",
")",
")",
"{",
"$",
"files",
"[",
"]",
"=",
"$",
"tmp",
";",
"}",
"continue",
";",
"}",
"try",
"{",
"if",
"(",
"!",
"\\",
"preg_match",
"(",
"$",
"filter",
",",
"$",
"entry",
")",
")",
"{",
"continue",
";",
"}",
"$",
"files",
"[",
"]",
"=",
"$",
"tmp",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"$",
"ex",
"=",
"null",
";",
"}",
"}",
"$",
"d",
"->",
"close",
"(",
")",
";",
"return",
"$",
"files",
";",
"}",
"static",
"::",
"_listRecursiveFiltered",
"(",
"$",
"files",
",",
"$",
"filter",
",",
"$",
"folder",
")",
";",
"return",
"$",
"files",
";",
"}"
] | Returns all files, matching the defined filter.
If $recursive is TRUE, it also includes al sub folders.
If the filter is a callback function/method, so it must accept 2 parameters.
- string $itemName The name of the current filter item
- string $itemPath THe absolute path of the item.
@param string $folder The folder
@param string|callback $filter Regex or callback|callable for filtering files
@param boolean $recursive Include sub folders? (Defaults to FALSE)
@return array | [
"Returns",
"all",
"files",
"matching",
"the",
"defined",
"filter",
"."
] | c8af09a1b3cc8a955e43c89b70779d11b30ae29e | https://github.com/SagittariusX/Beluga.IO/blob/c8af09a1b3cc8a955e43c89b70779d11b30ae29e/src/Beluga/IO/Folder.php#L323-L378 | train |
shgysk8zer0/core_api | traits/arraymethods.php | ArrayMethods.slice | final public function slice($offset, $length = null, $preserve_keys = false)
{
$arr = array_unshift($this->{self::MAGIC_PROPERTY}, $offset, $length, $preserve_keys);
return static::createFromArray($arr);
} | php | final public function slice($offset, $length = null, $preserve_keys = false)
{
$arr = array_unshift($this->{self::MAGIC_PROPERTY}, $offset, $length, $preserve_keys);
return static::createFromArray($arr);
} | [
"final",
"public",
"function",
"slice",
"(",
"$",
"offset",
",",
"$",
"length",
"=",
"null",
",",
"$",
"preserve_keys",
"=",
"false",
")",
"{",
"$",
"arr",
"=",
"array_unshift",
"(",
"$",
"this",
"->",
"{",
"self",
"::",
"MAGIC_PROPERTY",
"}",
",",
"$",
"offset",
",",
"$",
"length",
",",
"$",
"preserve_keys",
")",
";",
"return",
"static",
"::",
"createFromArray",
"(",
"$",
"arr",
")",
";",
"}"
] | Extract a slice of the array
@param int $offset Starting position in the array
@param int $length Number of items to include, starting from $offset
@param bool $preserve_keys Prevent override of indices
@return [type] Returns the slice.
@see https://secure.php.net/manual/en/function.array-slice.php | [
"Extract",
"a",
"slice",
"of",
"the",
"array"
] | 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/arraymethods.php#L110-L114 | train |
shgysk8zer0/core_api | traits/arraymethods.php | ArrayMethods.chunk | final public function chunk($size, $preserve_keys = false)
{
$arr = array_chunk($this->{self::MAGIC_PROPERTY}, $size, $preserve_keys);
return static::createFromArray($arr);
} | php | final public function chunk($size, $preserve_keys = false)
{
$arr = array_chunk($this->{self::MAGIC_PROPERTY}, $size, $preserve_keys);
return static::createFromArray($arr);
} | [
"final",
"public",
"function",
"chunk",
"(",
"$",
"size",
",",
"$",
"preserve_keys",
"=",
"false",
")",
"{",
"$",
"arr",
"=",
"array_chunk",
"(",
"$",
"this",
"->",
"{",
"self",
"::",
"MAGIC_PROPERTY",
"}",
",",
"$",
"size",
",",
"$",
"preserve_keys",
")",
";",
"return",
"static",
"::",
"createFromArray",
"(",
"$",
"arr",
")",
";",
"}"
] | Split an array into chunks
@param int $size The size of each chunk
@param bool $preserve_keys Whether or not to preserve array keys
@return [type] Multidimensional numerically indexed array of size $size
@see https://secure.php.net/manual/en/function.array-chunk.php | [
"Split",
"an",
"array",
"into",
"chunks"
] | 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/arraymethods.php#L137-L141 | train |
shgysk8zer0/core_api | traits/arraymethods.php | ArrayMethods.search | final public function search($needle, $strict = false)
{
return array_search($needle, $this->{self::MAGIC_PROPERTY}, $strict);
} | php | final public function search($needle, $strict = false)
{
return array_search($needle, $this->{self::MAGIC_PROPERTY}, $strict);
} | [
"final",
"public",
"function",
"search",
"(",
"$",
"needle",
",",
"$",
"strict",
"=",
"false",
")",
"{",
"return",
"array_search",
"(",
"$",
"needle",
",",
"$",
"this",
"->",
"{",
"self",
"::",
"MAGIC_PROPERTY",
"}",
",",
"$",
"strict",
")",
";",
"}"
] | Searches the array for a given value and returns the corresponding key if successful
@param mixed $needle [description]
@param bool $strict [description]
@return mixed Returns the key for needle if it is found in the array, FALSE otherwise.
@see https://secure.php.net/manual/en/function.array-search.php | [
"Searches",
"the",
"array",
"for",
"a",
"given",
"value",
"and",
"returns",
"the",
"corresponding",
"key",
"if",
"successful"
] | 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/arraymethods.php#L158-L161 | train |
shgysk8zer0/core_api | traits/arraymethods.php | ArrayMethods.keys | final public function keys($search_value = null, $strict = false)
{
if (isset($search_value)) {
return static::createFromArray(array_keys($this->{self::MAGIC_PROPERTY}, $search_value, $strict));
} else {
return static::createFromArray(array_keys($this->{self::MAGIC_PROPERTY}));
}
} | php | final public function keys($search_value = null, $strict = false)
{
if (isset($search_value)) {
return static::createFromArray(array_keys($this->{self::MAGIC_PROPERTY}, $search_value, $strict));
} else {
return static::createFromArray(array_keys($this->{self::MAGIC_PROPERTY}));
}
} | [
"final",
"public",
"function",
"keys",
"(",
"$",
"search_value",
"=",
"null",
",",
"$",
"strict",
"=",
"false",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"search_value",
")",
")",
"{",
"return",
"static",
"::",
"createFromArray",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"{",
"self",
"::",
"MAGIC_PROPERTY",
"}",
",",
"$",
"search_value",
",",
"$",
"strict",
")",
")",
";",
"}",
"else",
"{",
"return",
"static",
"::",
"createFromArray",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"{",
"self",
"::",
"MAGIC_PROPERTY",
"}",
")",
")",
";",
"}",
"}"
] | Return all the keys or a subset of the keys of an array
@param mixed $search_value If specified, then only keys containing these values are returned.
@param bool $strict Determines if strict comparison (===) should be used during the search.
@return array Returns an array of all the keys in array | [
"Return",
"all",
"the",
"keys",
"or",
"a",
"subset",
"of",
"the",
"keys",
"of",
"an",
"array"
] | 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/arraymethods.php#L179-L186 | train |
shgysk8zer0/core_api | traits/arraymethods.php | ArrayMethods.replace | final public function replace()
{
$args = func_get_args();
array_unshift($this->{self::MAGIC_PROPERTY}, $args);
$arr = call_user_func_array('array_replace', $args);
return static::createFromArray($arr);
} | php | final public function replace()
{
$args = func_get_args();
array_unshift($this->{self::MAGIC_PROPERTY}, $args);
$arr = call_user_func_array('array_replace', $args);
return static::createFromArray($arr);
} | [
"final",
"public",
"function",
"replace",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"array_unshift",
"(",
"$",
"this",
"->",
"{",
"self",
"::",
"MAGIC_PROPERTY",
"}",
",",
"$",
"args",
")",
";",
"$",
"arr",
"=",
"call_user_func_array",
"(",
"'array_replace'",
",",
"$",
"args",
")",
";",
"return",
"static",
"::",
"createFromArray",
"(",
"$",
"arr",
")",
";",
"}"
] | Replaces elements from passed arrays into the first array
@param array ... Arrays with values to be extracted
@return [type] Returns an array, or NULL if an error occurs.
@see https://secure.php.net/manual/en/function.array-replace.php | [
"Replaces",
"elements",
"from",
"passed",
"arrays",
"into",
"the",
"first",
"array"
] | 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/arraymethods.php#L217-L223 | train |
shgysk8zer0/core_api | traits/arraymethods.php | ArrayMethods.pad | final public function pad($size, $value)
{
return static::createFromArray(array_pad($this->{self::MAGIC_PROPERTY}, $size, $value));
} | php | final public function pad($size, $value)
{
return static::createFromArray(array_pad($this->{self::MAGIC_PROPERTY}, $size, $value));
} | [
"final",
"public",
"function",
"pad",
"(",
"$",
"size",
",",
"$",
"value",
")",
"{",
"return",
"static",
"::",
"createFromArray",
"(",
"array_pad",
"(",
"$",
"this",
"->",
"{",
"self",
"::",
"MAGIC_PROPERTY",
"}",
",",
"$",
"size",
",",
"$",
"value",
")",
")",
";",
"}"
] | Pad array to the specified length with a value
@param int $size New size of the array.
@param mixed $value Value to pad if array is less than size.
@return [type] Copy of the array padded to size specified by size with value value. | [
"Pad",
"array",
"to",
"the",
"specified",
"length",
"with",
"a",
"value"
] | 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/arraymethods.php#L231-L234 | train |
shgysk8zer0/core_api | traits/arraymethods.php | ArrayMethods.multisort | final public function multisort(
$array1_sort_order = SORT_ASC,
$array1_sort_flags = SORT_REGULAR
)
{
return array_multisort($this->{self::MAGIC_PROPERTY}, $array1_sort_order, $array1_sort_flags);
} | php | final public function multisort(
$array1_sort_order = SORT_ASC,
$array1_sort_flags = SORT_REGULAR
)
{
return array_multisort($this->{self::MAGIC_PROPERTY}, $array1_sort_order, $array1_sort_flags);
} | [
"final",
"public",
"function",
"multisort",
"(",
"$",
"array1_sort_order",
"=",
"SORT_ASC",
",",
"$",
"array1_sort_flags",
"=",
"SORT_REGULAR",
")",
"{",
"return",
"array_multisort",
"(",
"$",
"this",
"->",
"{",
"self",
"::",
"MAGIC_PROPERTY",
"}",
",",
"$",
"array1_sort_order",
",",
"$",
"array1_sort_flags",
")",
";",
"}"
] | Sort multiple or multi-dimensional arrays
@param mixed $array1_sort_order SORT_ASC or SORT_DESC
@param mixed $array1_sort_flags Sorting type flags
@return [type] Returns TRUE on success or FALSE on failure.
@see https://secure.php.net/manual/en/function.array-multisort.php | [
"Sort",
"multiple",
"or",
"multi",
"-",
"dimensional",
"arrays"
] | 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/arraymethods.php#L255-L261 | train |
shgysk8zer0/core_api | traits/arraymethods.php | ArrayMethods.unique | final public function unique($sort_flags = SORT_STRING)
{
$arr = array_unique($this->{self::MAGIC_PROPERTY}, $sort_flags);
return static::createFromArray($arr);
} | php | final public function unique($sort_flags = SORT_STRING)
{
$arr = array_unique($this->{self::MAGIC_PROPERTY}, $sort_flags);
return static::createFromArray($arr);
} | [
"final",
"public",
"function",
"unique",
"(",
"$",
"sort_flags",
"=",
"SORT_STRING",
")",
"{",
"$",
"arr",
"=",
"array_unique",
"(",
"$",
"this",
"->",
"{",
"self",
"::",
"MAGIC_PROPERTY",
"}",
",",
"$",
"sort_flags",
")",
";",
"return",
"static",
"::",
"createFromArray",
"(",
"$",
"arr",
")",
";",
"}"
] | Removes duplicate values from an array
@param int $sort_flags May be used to modify the sorting behavior
@return [type] Returns the filtered array.
@see https://secure.php.net/manual/en/function.array-unique.php | [
"Removes",
"duplicate",
"values",
"from",
"an",
"array"
] | 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/arraymethods.php#L269-L273 | train |
shgysk8zer0/core_api | traits/arraymethods.php | ArrayMethods.map | final public function map(Callable $callback)
{
$arr = array_map(
$callback,
array_values($this->{self::MAGIC_PROPERTY}),
array_keys($this->{self::MAGIC_PROPERTY})
);
return static::createFromArray($arr);
} | php | final public function map(Callable $callback)
{
$arr = array_map(
$callback,
array_values($this->{self::MAGIC_PROPERTY}),
array_keys($this->{self::MAGIC_PROPERTY})
);
return static::createFromArray($arr);
} | [
"final",
"public",
"function",
"map",
"(",
"Callable",
"$",
"callback",
")",
"{",
"$",
"arr",
"=",
"array_map",
"(",
"$",
"callback",
",",
"array_values",
"(",
"$",
"this",
"->",
"{",
"self",
"::",
"MAGIC_PROPERTY",
"}",
")",
",",
"array_keys",
"(",
"$",
"this",
"->",
"{",
"self",
"::",
"MAGIC_PROPERTY",
"}",
")",
")",
";",
"return",
"static",
"::",
"createFromArray",
"(",
"$",
"arr",
")",
";",
"}"
] | Applies the callback to the elements of the array
@param Callable $callback Callback function to run for each element in the array.
@return self An array containing elements from current array with callback applied | [
"Applies",
"the",
"callback",
"to",
"the",
"elements",
"of",
"the",
"array"
] | 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/arraymethods.php#L312-L320 | train |
shgysk8zer0/core_api | traits/arraymethods.php | ArrayMethods.walk | final public function walk(Callable $callback, $userdata = null)
{
array_walk($this->{self::MAGIC_PROPERTY}, $callback);
return $this;
} | php | final public function walk(Callable $callback, $userdata = null)
{
array_walk($this->{self::MAGIC_PROPERTY}, $callback);
return $this;
} | [
"final",
"public",
"function",
"walk",
"(",
"Callable",
"$",
"callback",
",",
"$",
"userdata",
"=",
"null",
")",
"{",
"array_walk",
"(",
"$",
"this",
"->",
"{",
"self",
"::",
"MAGIC_PROPERTY",
"}",
",",
"$",
"callback",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Apply a user supplied function to every member of an array
@param Callable $callback Typically, callback takes on two parameters. ($value, $index)
@param mixed $userdata Optional third paramater for third paramater of $callback
@return self | [
"Apply",
"a",
"user",
"supplied",
"function",
"to",
"every",
"member",
"of",
"an",
"array"
] | 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/arraymethods.php#L328-L332 | train |
shgysk8zer0/core_api | traits/arraymethods.php | ArrayMethods.filter | final public function filter(Callable $callback, $flags = 0)
{
$arr = array_filter($this->{self::MAGIC_PROPERTY}, $callback);
return static::createFromArray($arr);
} | php | final public function filter(Callable $callback, $flags = 0)
{
$arr = array_filter($this->{self::MAGIC_PROPERTY}, $callback);
return static::createFromArray($arr);
} | [
"final",
"public",
"function",
"filter",
"(",
"Callable",
"$",
"callback",
",",
"$",
"flags",
"=",
"0",
")",
"{",
"$",
"arr",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"{",
"self",
"::",
"MAGIC_PROPERTY",
"}",
",",
"$",
"callback",
")",
";",
"return",
"static",
"::",
"createFromArray",
"(",
"$",
"arr",
")",
";",
"}"
] | Filters elements of an array using a callback function
@param Callable $callback The callback function to use
@param int $flags Flag determining what arguments are sent to callback
@return array Returns the filtered array.
@see https://secure.php.net/manual/en/function.array-filter.php | [
"Filters",
"elements",
"of",
"an",
"array",
"using",
"a",
"callback",
"function"
] | 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/arraymethods.php#L341-L345 | train |
shgysk8zer0/core_api | traits/arraymethods.php | ArrayMethods.reduce | final public function reduce(Callable $callback, $initial = null)
{
$result = array_reduce($this->{self::MAGIC_PROPERTY}, $callback, $initial);
return static::from($result);
} | php | final public function reduce(Callable $callback, $initial = null)
{
$result = array_reduce($this->{self::MAGIC_PROPERTY}, $callback, $initial);
return static::from($result);
} | [
"final",
"public",
"function",
"reduce",
"(",
"Callable",
"$",
"callback",
",",
"$",
"initial",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"array_reduce",
"(",
"$",
"this",
"->",
"{",
"self",
"::",
"MAGIC_PROPERTY",
"}",
",",
"$",
"callback",
",",
"$",
"initial",
")",
";",
"return",
"static",
"::",
"from",
"(",
"$",
"result",
")",
";",
"}"
] | Iteratively reduce the array to a single value using a callback function
@param Callable $callback mixed callback ( mixed $carry , mixed $item )
@param mixed $initial Optional intitial value of $carry in $callback
@return mixed Returns the resulting value. | [
"Iteratively",
"reduce",
"the",
"array",
"to",
"a",
"single",
"value",
"using",
"a",
"callback",
"function"
] | 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/arraymethods.php#L353-L358 | train |
gplcart/cli | controllers/commands/Payment.php | Payment.cmdGetPayment | public function cmdGetPayment()
{
$result = $this->getListPayment();
$this->outputFormat($result);
$this->outputFormatTablePayment($result);
$this->output();
} | php | public function cmdGetPayment()
{
$result = $this->getListPayment();
$this->outputFormat($result);
$this->outputFormatTablePayment($result);
$this->output();
} | [
"public",
"function",
"cmdGetPayment",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getListPayment",
"(",
")",
";",
"$",
"this",
"->",
"outputFormat",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"outputFormatTablePayment",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "payment-get" command | [
"Callback",
"for",
"payment",
"-",
"get",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Payment.php#L40-L46 | train |
DreadLabs/VantomasWebsite | src/Disqus/Response/AbstractResponse.php | AbstractResponse.getErrorCode | protected function getErrorCode()
{
$content = $this->content;
return is_object($content) && property_exists($content, 'code') ? (integer) $content->code : 0;
} | php | protected function getErrorCode()
{
$content = $this->content;
return is_object($content) && property_exists($content, 'code') ? (integer) $content->code : 0;
} | [
"protected",
"function",
"getErrorCode",
"(",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"content",
";",
"return",
"is_object",
"(",
"$",
"content",
")",
"&&",
"property_exists",
"(",
"$",
"content",
",",
"'code'",
")",
"?",
"(",
"integer",
")",
"$",
"content",
"->",
"code",
":",
"0",
";",
"}"
] | returns the response error code
@return int | [
"returns",
"the",
"response",
"error",
"code"
] | 7f85f2b45bdf5ed9fa9d320c805c416bf99cd668 | https://github.com/DreadLabs/VantomasWebsite/blob/7f85f2b45bdf5ed9fa9d320c805c416bf99cd668/src/Disqus/Response/AbstractResponse.php#L81-L85 | train |
SlabPHP/cache-manager | src/Providers/Memcache.php | Memcache.flush | public function flush()
{
if (empty($this->memcache)) {
return false;
}
$flushStatus = $this->memcache->flush();
return $flushStatus;
} | php | public function flush()
{
if (empty($this->memcache)) {
return false;
}
$flushStatus = $this->memcache->flush();
return $flushStatus;
} | [
"public",
"function",
"flush",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"memcache",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"flushStatus",
"=",
"$",
"this",
"->",
"memcache",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"flushStatus",
";",
"}"
] | Flush the server
@return boolean | [
"Flush",
"the",
"server"
] | 7bbf9fe6519071fe14d382e98925cd3e10010a3a | https://github.com/SlabPHP/cache-manager/blob/7bbf9fe6519071fe14d382e98925cd3e10010a3a/src/Providers/Memcache.php#L113-L122 | train |
dms-org/common.structure | src/FileSystem/File.php | File.createTemporary | public static function createTemporary(string $data, string $clientFileName = null) : File
{
$tempFilePath = tempnam(sys_get_temp_dir(), 'dms');
file_put_contents($tempFilePath, $data);
return new self($tempFilePath, $clientFileName);
} | php | public static function createTemporary(string $data, string $clientFileName = null) : File
{
$tempFilePath = tempnam(sys_get_temp_dir(), 'dms');
file_put_contents($tempFilePath, $data);
return new self($tempFilePath, $clientFileName);
} | [
"public",
"static",
"function",
"createTemporary",
"(",
"string",
"$",
"data",
",",
"string",
"$",
"clientFileName",
"=",
"null",
")",
":",
"File",
"{",
"$",
"tempFilePath",
"=",
"tempnam",
"(",
"sys_get_temp_dir",
"(",
")",
",",
"'dms'",
")",
";",
"file_put_contents",
"(",
"$",
"tempFilePath",
",",
"$",
"data",
")",
";",
"return",
"new",
"self",
"(",
"$",
"tempFilePath",
",",
"$",
"clientFileName",
")",
";",
"}"
] | Create a temporary temporary file.
@param string $data
@param string|null $clientFileName
@return File | [
"Create",
"a",
"temporary",
"temporary",
"file",
"."
] | 23f122182f60df5ec847047a81a39c8aab019ff1 | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/FileSystem/File.php#L76-L82 | train |
koolkode/stream | src/ChunkDecodedOutputStream.php | ChunkDecodedOutputStream.readChunkHeader | protected function readChunkHeader()
{
static $m = NULL;
if(preg_match("'([a-fA-F0-9]+).*\r\n'", $this->buffer, $m))
{
$this->remainder = hexdec($m[1]);
$this->buffer = (string)substr($this->buffer, strlen($m[0]));
}
else
{
$this->remainder = 0;
}
} | php | protected function readChunkHeader()
{
static $m = NULL;
if(preg_match("'([a-fA-F0-9]+).*\r\n'", $this->buffer, $m))
{
$this->remainder = hexdec($m[1]);
$this->buffer = (string)substr($this->buffer, strlen($m[0]));
}
else
{
$this->remainder = 0;
}
} | [
"protected",
"function",
"readChunkHeader",
"(",
")",
"{",
"static",
"$",
"m",
"=",
"NULL",
";",
"if",
"(",
"preg_match",
"(",
"\"'([a-fA-F0-9]+).*\\r\\n'\"",
",",
"$",
"this",
"->",
"buffer",
",",
"$",
"m",
")",
")",
"{",
"$",
"this",
"->",
"remainder",
"=",
"hexdec",
"(",
"$",
"m",
"[",
"1",
"]",
")",
";",
"$",
"this",
"->",
"buffer",
"=",
"(",
"string",
")",
"substr",
"(",
"$",
"this",
"->",
"buffer",
",",
"strlen",
"(",
"$",
"m",
"[",
"0",
"]",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"remainder",
"=",
"0",
";",
"}",
"}"
] | Compute number of remaining bytes using chunk header | [
"Compute",
"number",
"of",
"remaining",
"bytes",
"using",
"chunk",
"header"
] | 05e83efd76e1cb9e40a972711986b4a7e38bc141 | https://github.com/koolkode/stream/blob/05e83efd76e1cb9e40a972711986b4a7e38bc141/src/ChunkDecodedOutputStream.php#L87-L100 | train |
agentmedia/phine-core | src/Core/Modules/Backend/JsonAreaList.php | JsonAreaList.BeforeDelete | protected function BeforeDelete()
{
foreach (self::$deleteHooks as $hook)
{
$hook->BeforeDelete($this->item);
}
$logger = new Logger(BackendModule::Guard()->GetUser());
$logger->ReportAreaAction($this->item, Action::Delete());
} | php | protected function BeforeDelete()
{
foreach (self::$deleteHooks as $hook)
{
$hook->BeforeDelete($this->item);
}
$logger = new Logger(BackendModule::Guard()->GetUser());
$logger->ReportAreaAction($this->item, Action::Delete());
} | [
"protected",
"function",
"BeforeDelete",
"(",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"deleteHooks",
"as",
"$",
"hook",
")",
"{",
"$",
"hook",
"->",
"BeforeDelete",
"(",
"$",
"this",
"->",
"item",
")",
";",
"}",
"$",
"logger",
"=",
"new",
"Logger",
"(",
"BackendModule",
"::",
"Guard",
"(",
")",
"->",
"GetUser",
"(",
")",
")",
";",
"$",
"logger",
"->",
"ReportAreaAction",
"(",
"$",
"this",
"->",
"item",
",",
"Action",
"::",
"Delete",
"(",
")",
")",
";",
"}"
] | Execute delete hooks | [
"Execute",
"delete",
"hooks"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/JsonAreaList.php#L45-L53 | train |
wobblecode/WobbleCodeUserBundle | OAuth/OAuthMapper.php | OAuthMapper.normalizeData | public function normalizeData(PathUserResponse $response)
{
$return = $response->getResponse();
$provider = $response->getResourceOwner()->getName();
$token = $response->getAccessToken();
switch ($provider) {
case 'google':
$data = $this->normalizeGoogle($return);
break;
case 'facebook':
$data = $this->normalizeFacebook($return);
break;
case 'github':
$data = $this->normalizeGithub($return, $token);
break;
}
$data['provider'] = $provider;
$data['token'] = $token;
return $data;
} | php | public function normalizeData(PathUserResponse $response)
{
$return = $response->getResponse();
$provider = $response->getResourceOwner()->getName();
$token = $response->getAccessToken();
switch ($provider) {
case 'google':
$data = $this->normalizeGoogle($return);
break;
case 'facebook':
$data = $this->normalizeFacebook($return);
break;
case 'github':
$data = $this->normalizeGithub($return, $token);
break;
}
$data['provider'] = $provider;
$data['token'] = $token;
return $data;
} | [
"public",
"function",
"normalizeData",
"(",
"PathUserResponse",
"$",
"response",
")",
"{",
"$",
"return",
"=",
"$",
"response",
"->",
"getResponse",
"(",
")",
";",
"$",
"provider",
"=",
"$",
"response",
"->",
"getResourceOwner",
"(",
")",
"->",
"getName",
"(",
")",
";",
"$",
"token",
"=",
"$",
"response",
"->",
"getAccessToken",
"(",
")",
";",
"switch",
"(",
"$",
"provider",
")",
"{",
"case",
"'google'",
":",
"$",
"data",
"=",
"$",
"this",
"->",
"normalizeGoogle",
"(",
"$",
"return",
")",
";",
"break",
";",
"case",
"'facebook'",
":",
"$",
"data",
"=",
"$",
"this",
"->",
"normalizeFacebook",
"(",
"$",
"return",
")",
";",
"break",
";",
"case",
"'github'",
":",
"$",
"data",
"=",
"$",
"this",
"->",
"normalizeGithub",
"(",
"$",
"return",
",",
"$",
"token",
")",
";",
"break",
";",
"}",
"$",
"data",
"[",
"'provider'",
"]",
"=",
"$",
"provider",
";",
"$",
"data",
"[",
"'token'",
"]",
"=",
"$",
"token",
";",
"return",
"$",
"data",
";",
"}"
] | Get oAuth data and normalize it to same var names
@param HttpMessageInterface $response oAuth response
@return array with normalized data | [
"Get",
"oAuth",
"data",
"and",
"normalize",
"it",
"to",
"same",
"var",
"names"
] | 7b8206f8b4a50fbc61f7bfe4f83eb466cad96440 | https://github.com/wobblecode/WobbleCodeUserBundle/blob/7b8206f8b4a50fbc61f7bfe4f83eb466cad96440/OAuth/OAuthMapper.php#L72-L96 | train |
wobblecode/WobbleCodeUserBundle | OAuth/OAuthMapper.php | OAuthMapper.normalizeGoogle | public function normalizeGoogle($return)
{
$genders = [
'male' => 'M',
'female' => 'F'
];
$data = [
'id' => $return['id'],
'name' => $this->ensureUtf8($return['name']),
'firstName' => $this->ensureUtf8($return['given_name']),
'lastName' => $this->ensureUtf8($return['family_name']),
'username' => $this->ensureUtf8($return['id']),
'email' => $return['email'],
'emailVerified' => $return['verified_email'],
'gender' => null,
'locale' => null,
'timezone' => null,
'avatar' => null,
'gravatar' => null,
'isSilhouette' => true,
];
if (isset($return['gender'])) {
$data['gender'] = $genders[$return['gender']];
}
if (isset($return['locale'])) {
$data['locale'] = str_replace('-', '_', $return['locale']);
}
if (isset($return['link'])) {
$data['googleProfileLink'] = $return['link'];
}
if (isset($return['picture'])) {
$data['avatar'] = $this->ensureUtf8($return['picture']);
$data['isSilhouette'] = false;
}
$data['avatar'] = strtok($data['avatar'], '?');
return $data;
} | php | public function normalizeGoogle($return)
{
$genders = [
'male' => 'M',
'female' => 'F'
];
$data = [
'id' => $return['id'],
'name' => $this->ensureUtf8($return['name']),
'firstName' => $this->ensureUtf8($return['given_name']),
'lastName' => $this->ensureUtf8($return['family_name']),
'username' => $this->ensureUtf8($return['id']),
'email' => $return['email'],
'emailVerified' => $return['verified_email'],
'gender' => null,
'locale' => null,
'timezone' => null,
'avatar' => null,
'gravatar' => null,
'isSilhouette' => true,
];
if (isset($return['gender'])) {
$data['gender'] = $genders[$return['gender']];
}
if (isset($return['locale'])) {
$data['locale'] = str_replace('-', '_', $return['locale']);
}
if (isset($return['link'])) {
$data['googleProfileLink'] = $return['link'];
}
if (isset($return['picture'])) {
$data['avatar'] = $this->ensureUtf8($return['picture']);
$data['isSilhouette'] = false;
}
$data['avatar'] = strtok($data['avatar'], '?');
return $data;
} | [
"public",
"function",
"normalizeGoogle",
"(",
"$",
"return",
")",
"{",
"$",
"genders",
"=",
"[",
"'male'",
"=>",
"'M'",
",",
"'female'",
"=>",
"'F'",
"]",
";",
"$",
"data",
"=",
"[",
"'id'",
"=>",
"$",
"return",
"[",
"'id'",
"]",
",",
"'name'",
"=>",
"$",
"this",
"->",
"ensureUtf8",
"(",
"$",
"return",
"[",
"'name'",
"]",
")",
",",
"'firstName'",
"=>",
"$",
"this",
"->",
"ensureUtf8",
"(",
"$",
"return",
"[",
"'given_name'",
"]",
")",
",",
"'lastName'",
"=>",
"$",
"this",
"->",
"ensureUtf8",
"(",
"$",
"return",
"[",
"'family_name'",
"]",
")",
",",
"'username'",
"=>",
"$",
"this",
"->",
"ensureUtf8",
"(",
"$",
"return",
"[",
"'id'",
"]",
")",
",",
"'email'",
"=>",
"$",
"return",
"[",
"'email'",
"]",
",",
"'emailVerified'",
"=>",
"$",
"return",
"[",
"'verified_email'",
"]",
",",
"'gender'",
"=>",
"null",
",",
"'locale'",
"=>",
"null",
",",
"'timezone'",
"=>",
"null",
",",
"'avatar'",
"=>",
"null",
",",
"'gravatar'",
"=>",
"null",
",",
"'isSilhouette'",
"=>",
"true",
",",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"return",
"[",
"'gender'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'gender'",
"]",
"=",
"$",
"genders",
"[",
"$",
"return",
"[",
"'gender'",
"]",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"return",
"[",
"'locale'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'locale'",
"]",
"=",
"str_replace",
"(",
"'-'",
",",
"'_'",
",",
"$",
"return",
"[",
"'locale'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"return",
"[",
"'link'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'googleProfileLink'",
"]",
"=",
"$",
"return",
"[",
"'link'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"return",
"[",
"'picture'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'avatar'",
"]",
"=",
"$",
"this",
"->",
"ensureUtf8",
"(",
"$",
"return",
"[",
"'picture'",
"]",
")",
";",
"$",
"data",
"[",
"'isSilhouette'",
"]",
"=",
"false",
";",
"}",
"$",
"data",
"[",
"'avatar'",
"]",
"=",
"strtok",
"(",
"$",
"data",
"[",
"'avatar'",
"]",
",",
"'?'",
")",
";",
"return",
"$",
"data",
";",
"}"
] | Mapping data from Google
@param Reponse $response
@return array contains normalized user data | [
"Mapping",
"data",
"from",
"Google"
] | 7b8206f8b4a50fbc61f7bfe4f83eb466cad96440 | https://github.com/wobblecode/WobbleCodeUserBundle/blob/7b8206f8b4a50fbc61f7bfe4f83eb466cad96440/OAuth/OAuthMapper.php#L105-L148 | train |
wobblecode/WobbleCodeUserBundle | OAuth/OAuthMapper.php | OAuthMapper.normalizeFacebook | public function normalizeFacebook($return)
{
$genders = [
'male' => 'M',
'female' => 'F'
];
$data = [
'id' => $return['id'],
'name' => $return['name'],
'firstName' => $return['first_name'],
'lastName' => $return['last_name'],
'facebookProfileLink' => $return['link'],
'username' => $return['username'],
'email' => $return['email'],
'timezone' => $return['timezone'],
'locale' => $return['locale'],
'verified' => $return['verified'],
'gender' => false,
'avatar' => false,
'gravatar' => false,
'emailVerified' => true,
'isSilhouette' => true
];
if (isset($return['gender'])) {
$data['gender'] = $genders[$return['gender']];
}
$response = $this->httpRequest(
'https://graph.facebook.com',
'/'.$return['id'].'/?fields=picture.type(large)'
);
if ($response->isOk()) {
$graph = json_decode($response->getContent());
$data['avatar'] = $graph->picture->data->url;
$data['issilhouette'] = $graph->picture->data->is_silhouette;
}
return $data;
} | php | public function normalizeFacebook($return)
{
$genders = [
'male' => 'M',
'female' => 'F'
];
$data = [
'id' => $return['id'],
'name' => $return['name'],
'firstName' => $return['first_name'],
'lastName' => $return['last_name'],
'facebookProfileLink' => $return['link'],
'username' => $return['username'],
'email' => $return['email'],
'timezone' => $return['timezone'],
'locale' => $return['locale'],
'verified' => $return['verified'],
'gender' => false,
'avatar' => false,
'gravatar' => false,
'emailVerified' => true,
'isSilhouette' => true
];
if (isset($return['gender'])) {
$data['gender'] = $genders[$return['gender']];
}
$response = $this->httpRequest(
'https://graph.facebook.com',
'/'.$return['id'].'/?fields=picture.type(large)'
);
if ($response->isOk()) {
$graph = json_decode($response->getContent());
$data['avatar'] = $graph->picture->data->url;
$data['issilhouette'] = $graph->picture->data->is_silhouette;
}
return $data;
} | [
"public",
"function",
"normalizeFacebook",
"(",
"$",
"return",
")",
"{",
"$",
"genders",
"=",
"[",
"'male'",
"=>",
"'M'",
",",
"'female'",
"=>",
"'F'",
"]",
";",
"$",
"data",
"=",
"[",
"'id'",
"=>",
"$",
"return",
"[",
"'id'",
"]",
",",
"'name'",
"=>",
"$",
"return",
"[",
"'name'",
"]",
",",
"'firstName'",
"=>",
"$",
"return",
"[",
"'first_name'",
"]",
",",
"'lastName'",
"=>",
"$",
"return",
"[",
"'last_name'",
"]",
",",
"'facebookProfileLink'",
"=>",
"$",
"return",
"[",
"'link'",
"]",
",",
"'username'",
"=>",
"$",
"return",
"[",
"'username'",
"]",
",",
"'email'",
"=>",
"$",
"return",
"[",
"'email'",
"]",
",",
"'timezone'",
"=>",
"$",
"return",
"[",
"'timezone'",
"]",
",",
"'locale'",
"=>",
"$",
"return",
"[",
"'locale'",
"]",
",",
"'verified'",
"=>",
"$",
"return",
"[",
"'verified'",
"]",
",",
"'gender'",
"=>",
"false",
",",
"'avatar'",
"=>",
"false",
",",
"'gravatar'",
"=>",
"false",
",",
"'emailVerified'",
"=>",
"true",
",",
"'isSilhouette'",
"=>",
"true",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"return",
"[",
"'gender'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'gender'",
"]",
"=",
"$",
"genders",
"[",
"$",
"return",
"[",
"'gender'",
"]",
"]",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"httpRequest",
"(",
"'https://graph.facebook.com'",
",",
"'/'",
".",
"$",
"return",
"[",
"'id'",
"]",
".",
"'/?fields=picture.type(large)'",
")",
";",
"if",
"(",
"$",
"response",
"->",
"isOk",
"(",
")",
")",
"{",
"$",
"graph",
"=",
"json_decode",
"(",
"$",
"response",
"->",
"getContent",
"(",
")",
")",
";",
"$",
"data",
"[",
"'avatar'",
"]",
"=",
"$",
"graph",
"->",
"picture",
"->",
"data",
"->",
"url",
";",
"$",
"data",
"[",
"'issilhouette'",
"]",
"=",
"$",
"graph",
"->",
"picture",
"->",
"data",
"->",
"is_silhouette",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Mapping data from facbook
@todo replace Buzz with Guzzle
@param Reponse $response
@return array contains normalized user data | [
"Mapping",
"data",
"from",
"facbook"
] | 7b8206f8b4a50fbc61f7bfe4f83eb466cad96440 | https://github.com/wobblecode/WobbleCodeUserBundle/blob/7b8206f8b4a50fbc61f7bfe4f83eb466cad96440/OAuth/OAuthMapper.php#L159-L200 | train |
wobblecode/WobbleCodeUserBundle | OAuth/OAuthMapper.php | OAuthMapper.normalizeGithub | public function normalizeGithub($return, $token)
{
$data = [
'id' => $return['id'],
'username' => $return['login'],
'name' => $return['name'],
'email' => $return['email'],
'gravatar' => $return['gravatar_id'],
'avatar' => $return['avatar_url'],
'gitHubProfileLink' => $return['html_url'],
'firstName' => false,
'lastName' => false,
'gender' => false,
'verified' => true,
'locale' => false,
'timezone' => false,
'isSilhouette' => true,
'emailVerified' => false
];
/**
* Setup http://developer.github.com/v3/media/
*
* @todo application/vnd.github.v3
*/
$data['email'] = $return['id'].'@github';
$headers = ['Authorization: bearer '.$token];
$response = $this->httpRequest('https://api.github.com', '/user/emails', null, $headers);
if ($response->isOk()) {
$emails = json_decode($response->getContent(), true);
$lastEmail = end($emails);
$data['email'] = $lastEmail['email'];
}
return $data;
} | php | public function normalizeGithub($return, $token)
{
$data = [
'id' => $return['id'],
'username' => $return['login'],
'name' => $return['name'],
'email' => $return['email'],
'gravatar' => $return['gravatar_id'],
'avatar' => $return['avatar_url'],
'gitHubProfileLink' => $return['html_url'],
'firstName' => false,
'lastName' => false,
'gender' => false,
'verified' => true,
'locale' => false,
'timezone' => false,
'isSilhouette' => true,
'emailVerified' => false
];
/**
* Setup http://developer.github.com/v3/media/
*
* @todo application/vnd.github.v3
*/
$data['email'] = $return['id'].'@github';
$headers = ['Authorization: bearer '.$token];
$response = $this->httpRequest('https://api.github.com', '/user/emails', null, $headers);
if ($response->isOk()) {
$emails = json_decode($response->getContent(), true);
$lastEmail = end($emails);
$data['email'] = $lastEmail['email'];
}
return $data;
} | [
"public",
"function",
"normalizeGithub",
"(",
"$",
"return",
",",
"$",
"token",
")",
"{",
"$",
"data",
"=",
"[",
"'id'",
"=>",
"$",
"return",
"[",
"'id'",
"]",
",",
"'username'",
"=>",
"$",
"return",
"[",
"'login'",
"]",
",",
"'name'",
"=>",
"$",
"return",
"[",
"'name'",
"]",
",",
"'email'",
"=>",
"$",
"return",
"[",
"'email'",
"]",
",",
"'gravatar'",
"=>",
"$",
"return",
"[",
"'gravatar_id'",
"]",
",",
"'avatar'",
"=>",
"$",
"return",
"[",
"'avatar_url'",
"]",
",",
"'gitHubProfileLink'",
"=>",
"$",
"return",
"[",
"'html_url'",
"]",
",",
"'firstName'",
"=>",
"false",
",",
"'lastName'",
"=>",
"false",
",",
"'gender'",
"=>",
"false",
",",
"'verified'",
"=>",
"true",
",",
"'locale'",
"=>",
"false",
",",
"'timezone'",
"=>",
"false",
",",
"'isSilhouette'",
"=>",
"true",
",",
"'emailVerified'",
"=>",
"false",
"]",
";",
"/**\n * Setup http://developer.github.com/v3/media/\n *\n * @todo application/vnd.github.v3\n */",
"$",
"data",
"[",
"'email'",
"]",
"=",
"$",
"return",
"[",
"'id'",
"]",
".",
"'@github'",
";",
"$",
"headers",
"=",
"[",
"'Authorization: bearer '",
".",
"$",
"token",
"]",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpRequest",
"(",
"'https://api.github.com'",
",",
"'/user/emails'",
",",
"null",
",",
"$",
"headers",
")",
";",
"if",
"(",
"$",
"response",
"->",
"isOk",
"(",
")",
")",
"{",
"$",
"emails",
"=",
"json_decode",
"(",
"$",
"response",
"->",
"getContent",
"(",
")",
",",
"true",
")",
";",
"$",
"lastEmail",
"=",
"end",
"(",
"$",
"emails",
")",
";",
"$",
"data",
"[",
"'email'",
"]",
"=",
"$",
"lastEmail",
"[",
"'email'",
"]",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Mapping data from github
@todo replace Buzz with Guzzle
@param Reponse $response
@return array contains normalized user data | [
"Mapping",
"data",
"from",
"github"
] | 7b8206f8b4a50fbc61f7bfe4f83eb466cad96440 | https://github.com/wobblecode/WobbleCodeUserBundle/blob/7b8206f8b4a50fbc61f7bfe4f83eb466cad96440/OAuth/OAuthMapper.php#L211-L249 | train |
wobblecode/WobbleCodeUserBundle | OAuth/OAuthMapper.php | OAuthMapper.httpRequest | protected function httpRequest($url, $resource = '/', $content = null, $headers = [], $method = 'GET')
{
$request = new HttpRequest($method, $resource, $url);
$response = new HttpResponse();
$headers = array_merge(['User-Agent: WobbleCodeUserBundle'], $headers);
$request->setHeaders($headers);
$request->setContent($content);
$client = new BuzzCUrl();
$browser = new BuzzBrowser($client);
$browser->send($request, $response);
return $response;
} | php | protected function httpRequest($url, $resource = '/', $content = null, $headers = [], $method = 'GET')
{
$request = new HttpRequest($method, $resource, $url);
$response = new HttpResponse();
$headers = array_merge(['User-Agent: WobbleCodeUserBundle'], $headers);
$request->setHeaders($headers);
$request->setContent($content);
$client = new BuzzCUrl();
$browser = new BuzzBrowser($client);
$browser->send($request, $response);
return $response;
} | [
"protected",
"function",
"httpRequest",
"(",
"$",
"url",
",",
"$",
"resource",
"=",
"'/'",
",",
"$",
"content",
"=",
"null",
",",
"$",
"headers",
"=",
"[",
"]",
",",
"$",
"method",
"=",
"'GET'",
")",
"{",
"$",
"request",
"=",
"new",
"HttpRequest",
"(",
"$",
"method",
",",
"$",
"resource",
",",
"$",
"url",
")",
";",
"$",
"response",
"=",
"new",
"HttpResponse",
"(",
")",
";",
"$",
"headers",
"=",
"array_merge",
"(",
"[",
"'User-Agent: WobbleCodeUserBundle'",
"]",
",",
"$",
"headers",
")",
";",
"$",
"request",
"->",
"setHeaders",
"(",
"$",
"headers",
")",
";",
"$",
"request",
"->",
"setContent",
"(",
"$",
"content",
")",
";",
"$",
"client",
"=",
"new",
"BuzzCUrl",
"(",
")",
";",
"$",
"browser",
"=",
"new",
"BuzzBrowser",
"(",
"$",
"client",
")",
";",
"$",
"browser",
"->",
"send",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Performs an HTTP request
@todo replace Buzz with Guzzle
@param string $url The url to fetch
@param string $content The content of the request
@param array $headers The headers of the request
@param string $method The HTTP method to use
@return HttpMessageInterface The response content | [
"Performs",
"an",
"HTTP",
"request"
] | 7b8206f8b4a50fbc61f7bfe4f83eb466cad96440 | https://github.com/wobblecode/WobbleCodeUserBundle/blob/7b8206f8b4a50fbc61f7bfe4f83eb466cad96440/OAuth/OAuthMapper.php#L263-L279 | train |
agentmedia/phine-builtin | src/BuiltIn/Logic/Logging/ContainerReferenceResolver.php | ContainerReferenceResolver.GetReferencedContainer | public function GetReferencedContainer(Content $content)
{
$contentContainer = ContentContainer::Schema()->ByContent($content);
return $contentContainer ? $contentContainer->GetContainer() : null;
} | php | public function GetReferencedContainer(Content $content)
{
$contentContainer = ContentContainer::Schema()->ByContent($content);
return $contentContainer ? $contentContainer->GetContainer() : null;
} | [
"public",
"function",
"GetReferencedContainer",
"(",
"Content",
"$",
"content",
")",
"{",
"$",
"contentContainer",
"=",
"ContentContainer",
"::",
"Schema",
"(",
")",
"->",
"ByContent",
"(",
"$",
"content",
")",
";",
"return",
"$",
"contentContainer",
"?",
"$",
"contentContainer",
"->",
"GetContainer",
"(",
")",
":",
"null",
";",
"}"
] | Gets a container referenced by a content
@param Content $content The content
@return Container Returns The referenced container, if exists | [
"Gets",
"a",
"container",
"referenced",
"by",
"a",
"content"
] | 4dd05bc406a71e997bd4eaa16b12e23dbe62a456 | https://github.com/agentmedia/phine-builtin/blob/4dd05bc406a71e997bd4eaa16b12e23dbe62a456/src/BuiltIn/Logic/Logging/ContainerReferenceResolver.php#L15-L19 | train |
erenmustafaozdal/laravel-modules-base | src/Controllers/BaseUserController.php | BaseUserController.activationComplete | protected function activationComplete()
{
try {
$activation = Activation::create($this->model);
if ( ! Activation::complete($this->model, $activation->code)) {
throw new ActivateException($this->model->id, $activation->code, 'fail');
}
if ($this->callerActivationMethod(debug_backtrace())) {
$this->model->is_active = true;
$this->model->save();
}
event(new $this->events['activationSuccess']($this->model));
return true;
} catch (ActivateException $e) {
$this->model->is_active = false;
$this->model->save();
event(new $this->events['activationFail']($e->getId(),$e->getActivationCode(), $e->getType()));
return false;
}
} | php | protected function activationComplete()
{
try {
$activation = Activation::create($this->model);
if ( ! Activation::complete($this->model, $activation->code)) {
throw new ActivateException($this->model->id, $activation->code, 'fail');
}
if ($this->callerActivationMethod(debug_backtrace())) {
$this->model->is_active = true;
$this->model->save();
}
event(new $this->events['activationSuccess']($this->model));
return true;
} catch (ActivateException $e) {
$this->model->is_active = false;
$this->model->save();
event(new $this->events['activationFail']($e->getId(),$e->getActivationCode(), $e->getType()));
return false;
}
} | [
"protected",
"function",
"activationComplete",
"(",
")",
"{",
"try",
"{",
"$",
"activation",
"=",
"Activation",
"::",
"create",
"(",
"$",
"this",
"->",
"model",
")",
";",
"if",
"(",
"!",
"Activation",
"::",
"complete",
"(",
"$",
"this",
"->",
"model",
",",
"$",
"activation",
"->",
"code",
")",
")",
"{",
"throw",
"new",
"ActivateException",
"(",
"$",
"this",
"->",
"model",
"->",
"id",
",",
"$",
"activation",
"->",
"code",
",",
"'fail'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"callerActivationMethod",
"(",
"debug_backtrace",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"model",
"->",
"is_active",
"=",
"true",
";",
"$",
"this",
"->",
"model",
"->",
"save",
"(",
")",
";",
"}",
"event",
"(",
"new",
"$",
"this",
"->",
"events",
"[",
"'activationSuccess'",
"]",
"(",
"$",
"this",
"->",
"model",
")",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"ActivateException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"model",
"->",
"is_active",
"=",
"false",
";",
"$",
"this",
"->",
"model",
"->",
"save",
"(",
")",
";",
"event",
"(",
"new",
"$",
"this",
"->",
"events",
"[",
"'activationFail'",
"]",
"(",
"$",
"e",
"->",
"getId",
"(",
")",
",",
"$",
"e",
"->",
"getActivationCode",
"(",
")",
",",
"$",
"e",
"->",
"getType",
"(",
")",
")",
")",
";",
"return",
"false",
";",
"}",
"}"
] | set activation complete
@return boolean | [
"set",
"activation",
"complete"
] | c26600543817642926bcf16ada84009e00d784e0 | https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Controllers/BaseUserController.php#L64-L85 | train |
erenmustafaozdal/laravel-modules-base | src/Controllers/BaseUserController.php | BaseUserController.activateGroupAction | protected function activateGroupAction($class)
{
$users = $class::whereIn('id', $this->request->id)->get();
foreach($users as $user) {
$this->setModel($user);
$this->activationComplete();
}
return true;
} | php | protected function activateGroupAction($class)
{
$users = $class::whereIn('id', $this->request->id)->get();
foreach($users as $user) {
$this->setModel($user);
$this->activationComplete();
}
return true;
} | [
"protected",
"function",
"activateGroupAction",
"(",
"$",
"class",
")",
"{",
"$",
"users",
"=",
"$",
"class",
"::",
"whereIn",
"(",
"'id'",
",",
"$",
"this",
"->",
"request",
"->",
"id",
")",
"->",
"get",
"(",
")",
";",
"foreach",
"(",
"$",
"users",
"as",
"$",
"user",
")",
"{",
"$",
"this",
"->",
"setModel",
"(",
"$",
"user",
")",
";",
"$",
"this",
"->",
"activationComplete",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] | activate group action
@param $class
@return boolean | [
"activate",
"group",
"action"
] | c26600543817642926bcf16ada84009e00d784e0 | https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Controllers/BaseUserController.php#L122-L130 | train |
erenmustafaozdal/laravel-modules-base | src/Controllers/BaseUserController.php | BaseUserController.notActivateGroupAction | protected function notActivateGroupAction($class)
{
$users = $class::whereIn('id', $this->request->id)->get();
foreach($users as $user) {
$this->setModel($user);
$this->activationRemove();
}
return true;
} | php | protected function notActivateGroupAction($class)
{
$users = $class::whereIn('id', $this->request->id)->get();
foreach($users as $user) {
$this->setModel($user);
$this->activationRemove();
}
return true;
} | [
"protected",
"function",
"notActivateGroupAction",
"(",
"$",
"class",
")",
"{",
"$",
"users",
"=",
"$",
"class",
"::",
"whereIn",
"(",
"'id'",
",",
"$",
"this",
"->",
"request",
"->",
"id",
")",
"->",
"get",
"(",
")",
";",
"foreach",
"(",
"$",
"users",
"as",
"$",
"user",
")",
"{",
"$",
"this",
"->",
"setModel",
"(",
"$",
"user",
")",
";",
"$",
"this",
"->",
"activationRemove",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] | not activate group action
@param $class
@return boolean | [
"not",
"activate",
"group",
"action"
] | c26600543817642926bcf16ada84009e00d784e0 | https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Controllers/BaseUserController.php#L138-L146 | train |
wb-crowdfusion/crowdfusion | system/context/ClassLoader.php | ClassLoader.addDirectory | public static function addDirectory($directory, $extensionToFind = '.php', $bypassDirectories = '')
{
self::register();
$dir = new SplFileInfo($directory);
if (!$dir->isDir()) {
throw new ApplicationContextException('Cannot add directory to ClassLoader, directory does not exist: ' . $directory);
}
if (!is_array($bypassDirectories)) {
$bypassDirectories = explode(',', $bypassDirectories);
}
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::SELF_FIRST);
foreach ($objects as $name => $object) {
if (self::isVcsFile($name)) {
continue;
}
$tmpPath = explode(DIRECTORY_SEPARATOR, ltrim(str_replace($directory, '', $name), DIRECTORY_SEPARATOR));
$rootNode = array_shift($tmpPath);
if (in_array($rootNode, $bypassDirectories)) {
continue;
}
if (!$object->isFile()) {
continue;
}
$extension = substr($object->getFilename(), strlen($extensionToFind)*-1);
if ($extension !== $extensionToFind) {
continue;
}
self::addFile($object, $extensionToFind);
}
} | php | public static function addDirectory($directory, $extensionToFind = '.php', $bypassDirectories = '')
{
self::register();
$dir = new SplFileInfo($directory);
if (!$dir->isDir()) {
throw new ApplicationContextException('Cannot add directory to ClassLoader, directory does not exist: ' . $directory);
}
if (!is_array($bypassDirectories)) {
$bypassDirectories = explode(',', $bypassDirectories);
}
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::SELF_FIRST);
foreach ($objects as $name => $object) {
if (self::isVcsFile($name)) {
continue;
}
$tmpPath = explode(DIRECTORY_SEPARATOR, ltrim(str_replace($directory, '', $name), DIRECTORY_SEPARATOR));
$rootNode = array_shift($tmpPath);
if (in_array($rootNode, $bypassDirectories)) {
continue;
}
if (!$object->isFile()) {
continue;
}
$extension = substr($object->getFilename(), strlen($extensionToFind)*-1);
if ($extension !== $extensionToFind) {
continue;
}
self::addFile($object, $extensionToFind);
}
} | [
"public",
"static",
"function",
"addDirectory",
"(",
"$",
"directory",
",",
"$",
"extensionToFind",
"=",
"'.php'",
",",
"$",
"bypassDirectories",
"=",
"''",
")",
"{",
"self",
"::",
"register",
"(",
")",
";",
"$",
"dir",
"=",
"new",
"SplFileInfo",
"(",
"$",
"directory",
")",
";",
"if",
"(",
"!",
"$",
"dir",
"->",
"isDir",
"(",
")",
")",
"{",
"throw",
"new",
"ApplicationContextException",
"(",
"'Cannot add directory to ClassLoader, directory does not exist: '",
".",
"$",
"directory",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"bypassDirectories",
")",
")",
"{",
"$",
"bypassDirectories",
"=",
"explode",
"(",
"','",
",",
"$",
"bypassDirectories",
")",
";",
"}",
"$",
"objects",
"=",
"new",
"RecursiveIteratorIterator",
"(",
"new",
"RecursiveDirectoryIterator",
"(",
"$",
"dir",
")",
",",
"RecursiveIteratorIterator",
"::",
"SELF_FIRST",
")",
";",
"foreach",
"(",
"$",
"objects",
"as",
"$",
"name",
"=>",
"$",
"object",
")",
"{",
"if",
"(",
"self",
"::",
"isVcsFile",
"(",
"$",
"name",
")",
")",
"{",
"continue",
";",
"}",
"$",
"tmpPath",
"=",
"explode",
"(",
"DIRECTORY_SEPARATOR",
",",
"ltrim",
"(",
"str_replace",
"(",
"$",
"directory",
",",
"''",
",",
"$",
"name",
")",
",",
"DIRECTORY_SEPARATOR",
")",
")",
";",
"$",
"rootNode",
"=",
"array_shift",
"(",
"$",
"tmpPath",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"rootNode",
",",
"$",
"bypassDirectories",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"object",
"->",
"isFile",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"extension",
"=",
"substr",
"(",
"$",
"object",
"->",
"getFilename",
"(",
")",
",",
"strlen",
"(",
"$",
"extensionToFind",
")",
"*",
"-",
"1",
")",
";",
"if",
"(",
"$",
"extension",
"!==",
"$",
"extensionToFind",
")",
"{",
"continue",
";",
"}",
"self",
"::",
"addFile",
"(",
"$",
"object",
",",
"$",
"extensionToFind",
")",
";",
"}",
"}"
] | Scans a directory recursively for all files with
a particular extension and will add any classes
it finds with the full path.
@param string $directory
@param string $extensionToFind
@param string $bypassDirectories
@throws ApplicationContextException
@return void | [
"Scans",
"a",
"directory",
"recursively",
"for",
"all",
"files",
"with",
"a",
"particular",
"extension",
"and",
"will",
"add",
"any",
"classes",
"it",
"finds",
"with",
"the",
"full",
"path",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/context/ClassLoader.php#L29-L65 | train |
wb-crowdfusion/crowdfusion | system/context/ClassLoader.php | ClassLoader.addFile | public static function addFile($filePath, $extensionToFind = '.php')
{
if (!$filePath instanceof SplFileInfo) {
$filePath = new SplFileInfo($filePath);
}
$firstChar = substr($filePath->getBasename(), 0, 1);
$extension = substr($filePath->getFilename(), strlen($extensionToFind)*-1);
$className = $filePath->getBasename($extension);
if ($extension == $extensionToFind && $firstChar === strtoupper($firstChar)) {
self::addClass($className, $filePath->getRealPath());
}
} | php | public static function addFile($filePath, $extensionToFind = '.php')
{
if (!$filePath instanceof SplFileInfo) {
$filePath = new SplFileInfo($filePath);
}
$firstChar = substr($filePath->getBasename(), 0, 1);
$extension = substr($filePath->getFilename(), strlen($extensionToFind)*-1);
$className = $filePath->getBasename($extension);
if ($extension == $extensionToFind && $firstChar === strtoupper($firstChar)) {
self::addClass($className, $filePath->getRealPath());
}
} | [
"public",
"static",
"function",
"addFile",
"(",
"$",
"filePath",
",",
"$",
"extensionToFind",
"=",
"'.php'",
")",
"{",
"if",
"(",
"!",
"$",
"filePath",
"instanceof",
"SplFileInfo",
")",
"{",
"$",
"filePath",
"=",
"new",
"SplFileInfo",
"(",
"$",
"filePath",
")",
";",
"}",
"$",
"firstChar",
"=",
"substr",
"(",
"$",
"filePath",
"->",
"getBasename",
"(",
")",
",",
"0",
",",
"1",
")",
";",
"$",
"extension",
"=",
"substr",
"(",
"$",
"filePath",
"->",
"getFilename",
"(",
")",
",",
"strlen",
"(",
"$",
"extensionToFind",
")",
"*",
"-",
"1",
")",
";",
"$",
"className",
"=",
"$",
"filePath",
"->",
"getBasename",
"(",
"$",
"extension",
")",
";",
"if",
"(",
"$",
"extension",
"==",
"$",
"extensionToFind",
"&&",
"$",
"firstChar",
"===",
"strtoupper",
"(",
"$",
"firstChar",
")",
")",
"{",
"self",
"::",
"addClass",
"(",
"$",
"className",
",",
"$",
"filePath",
"->",
"getRealPath",
"(",
")",
")",
";",
"}",
"}"
] | Evaluates a file and if it looks like a php
class it will add it. This prevents odd php files
that aren't classes from being auto loaded like
"bootstrap.php" or "autoload.php", etc.
@param string $filePath
@param string $extensionToFind
@return void | [
"Evaluates",
"a",
"file",
"and",
"if",
"it",
"looks",
"like",
"a",
"php",
"class",
"it",
"will",
"add",
"it",
".",
"This",
"prevents",
"odd",
"php",
"files",
"that",
"aren",
"t",
"classes",
"from",
"being",
"auto",
"loaded",
"like",
"bootstrap",
".",
"php",
"or",
"autoload",
".",
"php",
"etc",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/context/ClassLoader.php#L123-L135 | train |
wb-crowdfusion/crowdfusion | system/context/ClassLoader.php | ClassLoader.addClass | public static function addClass($className, $filePath)
{
if (self::classExists($className)) {
throw new ApplicationContextException('Cannot add class file [' . $filePath . '], class with same name already defined by [' . self::$classNames[$className] . ']');
}
self::$classNames[$className] = $filePath;
} | php | public static function addClass($className, $filePath)
{
if (self::classExists($className)) {
throw new ApplicationContextException('Cannot add class file [' . $filePath . '], class with same name already defined by [' . self::$classNames[$className] . ']');
}
self::$classNames[$className] = $filePath;
} | [
"public",
"static",
"function",
"addClass",
"(",
"$",
"className",
",",
"$",
"filePath",
")",
"{",
"if",
"(",
"self",
"::",
"classExists",
"(",
"$",
"className",
")",
")",
"{",
"throw",
"new",
"ApplicationContextException",
"(",
"'Cannot add class file ['",
".",
"$",
"filePath",
".",
"'], class with same name already defined by ['",
".",
"self",
"::",
"$",
"classNames",
"[",
"$",
"className",
"]",
".",
"']'",
")",
";",
"}",
"self",
"::",
"$",
"classNames",
"[",
"$",
"className",
"]",
"=",
"$",
"filePath",
";",
"}"
] | Adds a class name and file path.
@param string $className
@param string $filePath
@throws ApplicationContextException
@return void | [
"Adds",
"a",
"class",
"name",
"and",
"file",
"path",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/context/ClassLoader.php#L148-L155 | train |
wb-crowdfusion/crowdfusion | system/context/ClassLoader.php | ClassLoader.isVcsFile | public static function isVcsFile($fileName)
{
foreach (self::$vcsPatterns as $pattern) {
if (strpos($fileName, $pattern) !== false) {
return true;
}
}
return false;
} | php | public static function isVcsFile($fileName)
{
foreach (self::$vcsPatterns as $pattern) {
if (strpos($fileName, $pattern) !== false) {
return true;
}
}
return false;
} | [
"public",
"static",
"function",
"isVcsFile",
"(",
"$",
"fileName",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"vcsPatterns",
"as",
"$",
"pattern",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"fileName",
",",
"$",
"pattern",
")",
"!==",
"false",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Returns true if file path contains a vcs name.
@param string $fileName
@return bool | [
"Returns",
"true",
"if",
"file",
"path",
"contains",
"a",
"vcs",
"name",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/context/ClassLoader.php#L270-L278 | train |
apioo/psx-validate | src/Filter/Html.php | Html.apply | public function apply($value)
{
return htmlspecialchars((string) $value, $this->quoteStyle, $this->charset, $this->doubleEncode);
} | php | public function apply($value)
{
return htmlspecialchars((string) $value, $this->quoteStyle, $this->charset, $this->doubleEncode);
} | [
"public",
"function",
"apply",
"(",
"$",
"value",
")",
"{",
"return",
"htmlspecialchars",
"(",
"(",
"string",
")",
"$",
"value",
",",
"$",
"this",
"->",
"quoteStyle",
",",
"$",
"this",
"->",
"charset",
",",
"$",
"this",
"->",
"doubleEncode",
")",
";",
"}"
] | Converts special characters to HTML entities
@param mixed $value
@return boolean | [
"Converts",
"special",
"characters",
"to",
"HTML",
"entities"
] | 4860c6a2c7f7ca52d3bd6d7e6ec7d6a7ddcfd83d | https://github.com/apioo/psx-validate/blob/4860c6a2c7f7ca52d3bd6d7e6ec7d6a7ddcfd83d/src/Filter/Html.php#L51-L54 | train |
jabernardo/lollipop-php | Library/SQL/Connection/MySQL.php | MySQL.__connect | private function __connect() {
if (!is_null($db)) return true;
$config = Config::get('db');
if (is_null($config)) {
throw new \Lollipop\Exception\Configuration('Lollipop is initialized with wrong database configuration');
}
$host = isset($config->host) ? $config->host : 'localhost';
$uid = isset($config->username) ? $config->username : 'root';
$pwd = isset($config->password) ? $config->password : '';
$db = isset($config->database) ? $config->database : 'lollipop';
// Instantiate MySQLi
$this->db = new \mysqli($host, $uid, $pwd, $db);
if ($this->db->connect_errno > 0) {
throw new \Lollipop\Exception\Connection($this->db->connect_error);
}
return true;
} | php | private function __connect() {
if (!is_null($db)) return true;
$config = Config::get('db');
if (is_null($config)) {
throw new \Lollipop\Exception\Configuration('Lollipop is initialized with wrong database configuration');
}
$host = isset($config->host) ? $config->host : 'localhost';
$uid = isset($config->username) ? $config->username : 'root';
$pwd = isset($config->password) ? $config->password : '';
$db = isset($config->database) ? $config->database : 'lollipop';
// Instantiate MySQLi
$this->db = new \mysqli($host, $uid, $pwd, $db);
if ($this->db->connect_errno > 0) {
throw new \Lollipop\Exception\Connection($this->db->connect_error);
}
return true;
} | [
"private",
"function",
"__connect",
"(",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"db",
")",
")",
"return",
"true",
";",
"$",
"config",
"=",
"Config",
"::",
"get",
"(",
"'db'",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"config",
")",
")",
"{",
"throw",
"new",
"\\",
"Lollipop",
"\\",
"Exception",
"\\",
"Configuration",
"(",
"'Lollipop is initialized with wrong database configuration'",
")",
";",
"}",
"$",
"host",
"=",
"isset",
"(",
"$",
"config",
"->",
"host",
")",
"?",
"$",
"config",
"->",
"host",
":",
"'localhost'",
";",
"$",
"uid",
"=",
"isset",
"(",
"$",
"config",
"->",
"username",
")",
"?",
"$",
"config",
"->",
"username",
":",
"'root'",
";",
"$",
"pwd",
"=",
"isset",
"(",
"$",
"config",
"->",
"password",
")",
"?",
"$",
"config",
"->",
"password",
":",
"''",
";",
"$",
"db",
"=",
"isset",
"(",
"$",
"config",
"->",
"database",
")",
"?",
"$",
"config",
"->",
"database",
":",
"'lollipop'",
";",
"// Instantiate MySQLi",
"$",
"this",
"->",
"db",
"=",
"new",
"\\",
"mysqli",
"(",
"$",
"host",
",",
"$",
"uid",
",",
"$",
"pwd",
",",
"$",
"db",
")",
";",
"if",
"(",
"$",
"this",
"->",
"db",
"->",
"connect_errno",
">",
"0",
")",
"{",
"throw",
"new",
"\\",
"Lollipop",
"\\",
"Exception",
"\\",
"Connection",
"(",
"$",
"this",
"->",
"db",
"->",
"connect_error",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Connect to MySQL server
@throws \Lollipop\Exception\Configuration
@throws \Lollipop\Exception\Connection
@return boolean | [
"Connect",
"to",
"MySQL",
"server"
] | 004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5 | https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/SQL/Connection/MySQL.php#L37-L59 | train |
phpffcms/ffcms-core | src/Traits/ModelValidator.php | ModelValidator.initialize | public function initialize($csrf = false)
{
$this->_tokenRequired = $csrf;
if ($csrf) {
// get current token value from session
$currentToken = App::$Session->get('_csrf_token', false);
// set new token value to session
$newToken = Crypt::randomString(mt_rand(32, 64));
App::$Session->set('_csrf_token', $newToken);
// if request is submited for this model - try to validate input data
if ($this->send()) {
// token is wrong - update bool state
if ($currentToken !== $this->getRequest('_csrf_token')) {
$this->_tokenOk = false;
}
}
// set token data to display
$this->_csrf_token = $newToken;
}
} | php | public function initialize($csrf = false)
{
$this->_tokenRequired = $csrf;
if ($csrf) {
// get current token value from session
$currentToken = App::$Session->get('_csrf_token', false);
// set new token value to session
$newToken = Crypt::randomString(mt_rand(32, 64));
App::$Session->set('_csrf_token', $newToken);
// if request is submited for this model - try to validate input data
if ($this->send()) {
// token is wrong - update bool state
if ($currentToken !== $this->getRequest('_csrf_token')) {
$this->_tokenOk = false;
}
}
// set token data to display
$this->_csrf_token = $newToken;
}
} | [
"public",
"function",
"initialize",
"(",
"$",
"csrf",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"_tokenRequired",
"=",
"$",
"csrf",
";",
"if",
"(",
"$",
"csrf",
")",
"{",
"// get current token value from session",
"$",
"currentToken",
"=",
"App",
"::",
"$",
"Session",
"->",
"get",
"(",
"'_csrf_token'",
",",
"false",
")",
";",
"// set new token value to session",
"$",
"newToken",
"=",
"Crypt",
"::",
"randomString",
"(",
"mt_rand",
"(",
"32",
",",
"64",
")",
")",
";",
"App",
"::",
"$",
"Session",
"->",
"set",
"(",
"'_csrf_token'",
",",
"$",
"newToken",
")",
";",
"// if request is submited for this model - try to validate input data",
"if",
"(",
"$",
"this",
"->",
"send",
"(",
")",
")",
"{",
"// token is wrong - update bool state",
"if",
"(",
"$",
"currentToken",
"!==",
"$",
"this",
"->",
"getRequest",
"(",
"'_csrf_token'",
")",
")",
"{",
"$",
"this",
"->",
"_tokenOk",
"=",
"false",
";",
"}",
"}",
"// set token data to display",
"$",
"this",
"->",
"_csrf_token",
"=",
"$",
"newToken",
";",
"}",
"}"
] | Initialize validator. Set csrf protection token from request data if available.
@param bool $csrf | [
"Initialize",
"validator",
".",
"Set",
"csrf",
"protection",
"token",
"from",
"request",
"data",
"if",
"available",
"."
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Traits/ModelValidator.php#L32-L51 | train |
phpffcms/ffcms-core | src/Traits/ModelValidator.php | ModelValidator.send | final public function send()
{
if (!Str::equalIgnoreCase($this->_sendMethod, App::$Request->getMethod())) {
return false;
}
return $this->getRequest('submit', $this->_sendMethod) !== null;
} | php | final public function send()
{
if (!Str::equalIgnoreCase($this->_sendMethod, App::$Request->getMethod())) {
return false;
}
return $this->getRequest('submit', $this->_sendMethod) !== null;
} | [
"final",
"public",
"function",
"send",
"(",
")",
"{",
"if",
"(",
"!",
"Str",
"::",
"equalIgnoreCase",
"(",
"$",
"this",
"->",
"_sendMethod",
",",
"App",
"::",
"$",
"Request",
"->",
"getMethod",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"getRequest",
"(",
"'submit'",
",",
"$",
"this",
"->",
"_sendMethod",
")",
"!==",
"null",
";",
"}"
] | Check if model get POST-based request as submit of SEND data
@return bool
@throws \InvalidArgumentException | [
"Check",
"if",
"model",
"get",
"POST",
"-",
"based",
"request",
"as",
"submit",
"of",
"SEND",
"data"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Traits/ModelValidator.php#L270-L277 | train |
phpffcms/ffcms-core | src/Traits/ModelValidator.php | ModelValidator.getRequest | public function getRequest($param, $method = null)
{
if ($method === null) {
$method = $this->_sendMethod;
}
$method = Str::lowerCase($method);
// get root request as array or string
switch ($method) {
case 'get':
$request = App::$Request->query->get($this->getFormName(), null);
break;
case 'post':
$request = App::$Request->request->get($this->getFormName(), null);
break;
case 'file':
$request = App::$Request->files->get($this->getFormName(), null);
break;
default:
$request = App::$Request->get($this->getFormName(), null);
break;
}
$response = null;
// param is a dot-separated array type
if (Str::contains('.', $param)) {
$response = $request;
foreach (explode('.', $param) as $path) {
if ($response !== null && !array_key_exists($path, $response)) {
return null;
}
// find deep array nesting offset
$response = $response[$path];
}
} else {
$response = $request[$param];
}
return $response;
} | php | public function getRequest($param, $method = null)
{
if ($method === null) {
$method = $this->_sendMethod;
}
$method = Str::lowerCase($method);
// get root request as array or string
switch ($method) {
case 'get':
$request = App::$Request->query->get($this->getFormName(), null);
break;
case 'post':
$request = App::$Request->request->get($this->getFormName(), null);
break;
case 'file':
$request = App::$Request->files->get($this->getFormName(), null);
break;
default:
$request = App::$Request->get($this->getFormName(), null);
break;
}
$response = null;
// param is a dot-separated array type
if (Str::contains('.', $param)) {
$response = $request;
foreach (explode('.', $param) as $path) {
if ($response !== null && !array_key_exists($path, $response)) {
return null;
}
// find deep array nesting offset
$response = $response[$path];
}
} else {
$response = $request[$param];
}
return $response;
} | [
"public",
"function",
"getRequest",
"(",
"$",
"param",
",",
"$",
"method",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"method",
"===",
"null",
")",
"{",
"$",
"method",
"=",
"$",
"this",
"->",
"_sendMethod",
";",
"}",
"$",
"method",
"=",
"Str",
"::",
"lowerCase",
"(",
"$",
"method",
")",
";",
"// get root request as array or string",
"switch",
"(",
"$",
"method",
")",
"{",
"case",
"'get'",
":",
"$",
"request",
"=",
"App",
"::",
"$",
"Request",
"->",
"query",
"->",
"get",
"(",
"$",
"this",
"->",
"getFormName",
"(",
")",
",",
"null",
")",
";",
"break",
";",
"case",
"'post'",
":",
"$",
"request",
"=",
"App",
"::",
"$",
"Request",
"->",
"request",
"->",
"get",
"(",
"$",
"this",
"->",
"getFormName",
"(",
")",
",",
"null",
")",
";",
"break",
";",
"case",
"'file'",
":",
"$",
"request",
"=",
"App",
"::",
"$",
"Request",
"->",
"files",
"->",
"get",
"(",
"$",
"this",
"->",
"getFormName",
"(",
")",
",",
"null",
")",
";",
"break",
";",
"default",
":",
"$",
"request",
"=",
"App",
"::",
"$",
"Request",
"->",
"get",
"(",
"$",
"this",
"->",
"getFormName",
"(",
")",
",",
"null",
")",
";",
"break",
";",
"}",
"$",
"response",
"=",
"null",
";",
"// param is a dot-separated array type",
"if",
"(",
"Str",
"::",
"contains",
"(",
"'.'",
",",
"$",
"param",
")",
")",
"{",
"$",
"response",
"=",
"$",
"request",
";",
"foreach",
"(",
"explode",
"(",
"'.'",
",",
"$",
"param",
")",
"as",
"$",
"path",
")",
"{",
"if",
"(",
"$",
"response",
"!==",
"null",
"&&",
"!",
"array_key_exists",
"(",
"$",
"path",
",",
"$",
"response",
")",
")",
"{",
"return",
"null",
";",
"}",
"// find deep array nesting offset",
"$",
"response",
"=",
"$",
"response",
"[",
"$",
"path",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"response",
"=",
"$",
"request",
"[",
"$",
"param",
"]",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Get input value based on param path and request method
@param string $param
@param string|null $method
@return mixed | [
"Get",
"input",
"value",
"based",
"on",
"param",
"path",
"and",
"request",
"method"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Traits/ModelValidator.php#L307-L346 | train |
brightnucleus/options-store | src/Exception/InvalidOptionRepository.php | InvalidOptionRepository.fromRepository | public static function fromRepository($repository)
{
$message = sprintf(
'Could not add invalid OptionRepository of type "%1$s" to AggregateOptionRepository.',
is_object($repository)
? get_class($repository)
: gettype($repository)
);
return new static($message);
} | php | public static function fromRepository($repository)
{
$message = sprintf(
'Could not add invalid OptionRepository of type "%1$s" to AggregateOptionRepository.',
is_object($repository)
? get_class($repository)
: gettype($repository)
);
return new static($message);
} | [
"public",
"static",
"function",
"fromRepository",
"(",
"$",
"repository",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'Could not add invalid OptionRepository of type \"%1$s\" to AggregateOptionRepository.'",
",",
"is_object",
"(",
"$",
"repository",
")",
"?",
"get_class",
"(",
"$",
"repository",
")",
":",
"gettype",
"(",
"$",
"repository",
")",
")",
";",
"return",
"new",
"static",
"(",
"$",
"message",
")",
";",
"}"
] | Get a new exception based on the type of an invalid repository.
@since 0.1.0
@param mixed $repository Repository that was tried to be added.
@return static | [
"Get",
"a",
"new",
"exception",
"based",
"on",
"the",
"type",
"of",
"an",
"invalid",
"repository",
"."
] | 9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1 | https://github.com/brightnucleus/options-store/blob/9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1/src/Exception/InvalidOptionRepository.php#L42-L52 | train |
brightnucleus/options-store | src/Exception/InvalidOptionRepository.php | InvalidOptionRepository.fromInstantiationException | public static function fromInstantiationException($class, Exception $exception)
{
$message = sprintf(
'Could not instantiate OptionRepository of type "%1$s". Reason: %2$s',
is_object($class)
? get_class($class)
: gettype($class),
$exception->getMessage()
);
return new static($message, 0, $exception);
} | php | public static function fromInstantiationException($class, Exception $exception)
{
$message = sprintf(
'Could not instantiate OptionRepository of type "%1$s". Reason: %2$s',
is_object($class)
? get_class($class)
: gettype($class),
$exception->getMessage()
);
return new static($message, 0, $exception);
} | [
"public",
"static",
"function",
"fromInstantiationException",
"(",
"$",
"class",
",",
"Exception",
"$",
"exception",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'Could not instantiate OptionRepository of type \"%1$s\". Reason: %2$s'",
",",
"is_object",
"(",
"$",
"class",
")",
"?",
"get_class",
"(",
"$",
"class",
")",
":",
"gettype",
"(",
"$",
"class",
")",
",",
"$",
"exception",
"->",
"getMessage",
"(",
")",
")",
";",
"return",
"new",
"static",
"(",
"$",
"message",
",",
"0",
",",
"$",
"exception",
")",
";",
"}"
] | Get a new exception based on an exception that was thrown during instantiation of a class.
@since 0.1.4
@param mixed $class Class that was tried to be instantiated.
@param Exception $exception Exception that was thrown during instantiation.
@return static | [
"Get",
"a",
"new",
"exception",
"based",
"on",
"an",
"exception",
"that",
"was",
"thrown",
"during",
"instantiation",
"of",
"a",
"class",
"."
] | 9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1 | https://github.com/brightnucleus/options-store/blob/9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1/src/Exception/InvalidOptionRepository.php#L64-L75 | train |
brightnucleus/options-store | src/Exception/InvalidOptionRepository.php | InvalidOptionRepository.fromConfig | public static function fromConfig(Config $config)
{
$message = sprintf(
'Could not instantiate OptionRepository from Config with starting key "%1$s".',
empty($config->getKeys())
? '<none>'
: $config->getKeys()[0]
);
return new static($message);
} | php | public static function fromConfig(Config $config)
{
$message = sprintf(
'Could not instantiate OptionRepository from Config with starting key "%1$s".',
empty($config->getKeys())
? '<none>'
: $config->getKeys()[0]
);
return new static($message);
} | [
"public",
"static",
"function",
"fromConfig",
"(",
"Config",
"$",
"config",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'Could not instantiate OptionRepository from Config with starting key \"%1$s\".'",
",",
"empty",
"(",
"$",
"config",
"->",
"getKeys",
"(",
")",
")",
"?",
"'<none>'",
":",
"$",
"config",
"->",
"getKeys",
"(",
")",
"[",
"0",
"]",
")",
";",
"return",
"new",
"static",
"(",
"$",
"message",
")",
";",
"}"
] | Get a new exception based on a Config that did not produce a valid repository.
@since 0.1.0
@param Config $config Config instance that was used.
@return static | [
"Get",
"a",
"new",
"exception",
"based",
"on",
"a",
"Config",
"that",
"did",
"not",
"produce",
"a",
"valid",
"repository",
"."
] | 9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1 | https://github.com/brightnucleus/options-store/blob/9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1/src/Exception/InvalidOptionRepository.php#L86-L96 | train |
dkd/enumeration | src/Enumeration.php | Enumeration.setValue | protected function setValue($value)
{
$enumKey = array_search((string) $value, static::$enumConstants[get_class($this)]);
if ($enumKey === false) {
throw new Exception\InvalidEnumerationValueException(
sprintf('Invalid value %s for %s', $value, __CLASS__),
1381615295
);
}
$this->value = static::$enumConstants[get_class($this)][$enumKey];
} | php | protected function setValue($value)
{
$enumKey = array_search((string) $value, static::$enumConstants[get_class($this)]);
if ($enumKey === false) {
throw new Exception\InvalidEnumerationValueException(
sprintf('Invalid value %s for %s', $value, __CLASS__),
1381615295
);
}
$this->value = static::$enumConstants[get_class($this)][$enumKey];
} | [
"protected",
"function",
"setValue",
"(",
"$",
"value",
")",
"{",
"$",
"enumKey",
"=",
"array_search",
"(",
"(",
"string",
")",
"$",
"value",
",",
"static",
"::",
"$",
"enumConstants",
"[",
"get_class",
"(",
"$",
"this",
")",
"]",
")",
";",
"if",
"(",
"$",
"enumKey",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidEnumerationValueException",
"(",
"sprintf",
"(",
"'Invalid value %s for %s'",
",",
"$",
"value",
",",
"__CLASS__",
")",
",",
"1381615295",
")",
";",
"}",
"$",
"this",
"->",
"value",
"=",
"static",
"::",
"$",
"enumConstants",
"[",
"get_class",
"(",
"$",
"this",
")",
"]",
"[",
"$",
"enumKey",
"]",
";",
"}"
] | Set the Enumeration value to the associated enumeration value by a loose comparison.
The value, that is used as the enumeration value, will be of the same type like defined in the enumeration
@param mixed $value
@throws Exception\InvalidEnumerationValueException | [
"Set",
"the",
"Enumeration",
"value",
"to",
"the",
"associated",
"enumeration",
"value",
"by",
"a",
"loose",
"comparison",
".",
"The",
"value",
"that",
"is",
"used",
"as",
"the",
"enumeration",
"value",
"will",
"be",
"of",
"the",
"same",
"type",
"like",
"defined",
"in",
"the",
"enumeration"
] | 7e6d05ac383da5f7e968c7e011d602c5a4d7a1de | https://github.com/dkd/enumeration/blob/7e6d05ac383da5f7e968c7e011d602c5a4d7a1de/src/Enumeration.php#L127-L137 | train |
dkd/enumeration | src/Enumeration.php | Enumeration.isValid | protected function isValid($value)
{
$value = (string) $value;
foreach (static::$enumConstants[get_class($this)] as $constantValue) {
if ($value === (string) $constantValue) {
return true;
}
}
return false;
} | php | protected function isValid($value)
{
$value = (string) $value;
foreach (static::$enumConstants[get_class($this)] as $constantValue) {
if ($value === (string) $constantValue) {
return true;
}
}
return false;
} | [
"protected",
"function",
"isValid",
"(",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"value",
";",
"foreach",
"(",
"static",
"::",
"$",
"enumConstants",
"[",
"get_class",
"(",
"$",
"this",
")",
"]",
"as",
"$",
"constantValue",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"(",
"string",
")",
"$",
"constantValue",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check if the value on this enum is a valid value for the enum
@param mixed $value
@return boolean | [
"Check",
"if",
"the",
"value",
"on",
"this",
"enum",
"is",
"a",
"valid",
"value",
"for",
"the",
"enum"
] | 7e6d05ac383da5f7e968c7e011d602c5a4d7a1de | https://github.com/dkd/enumeration/blob/7e6d05ac383da5f7e968c7e011d602c5a4d7a1de/src/Enumeration.php#L145-L154 | train |
dkd/enumeration | src/Enumeration.php | Enumeration.getConstants | public static function getConstants($include_default = false)
{
static::loadValues();
$enumConstants = static::$enumConstants[get_called_class()];
if (!$include_default) {
unset($enumConstants['__DEFAULT']);
}
return $enumConstants;
} | php | public static function getConstants($include_default = false)
{
static::loadValues();
$enumConstants = static::$enumConstants[get_called_class()];
if (!$include_default) {
unset($enumConstants['__DEFAULT']);
}
return $enumConstants;
} | [
"public",
"static",
"function",
"getConstants",
"(",
"$",
"include_default",
"=",
"false",
")",
"{",
"static",
"::",
"loadValues",
"(",
")",
";",
"$",
"enumConstants",
"=",
"static",
"::",
"$",
"enumConstants",
"[",
"get_called_class",
"(",
")",
"]",
";",
"if",
"(",
"!",
"$",
"include_default",
")",
"{",
"unset",
"(",
"$",
"enumConstants",
"[",
"'__DEFAULT'",
"]",
")",
";",
"}",
"return",
"$",
"enumConstants",
";",
"}"
] | Get the valid values for this enum
Defaults to constants you define in your subclass
override to provide custom functionality
@param boolean $include_default
@return array | [
"Get",
"the",
"valid",
"values",
"for",
"this",
"enum",
"Defaults",
"to",
"constants",
"you",
"define",
"in",
"your",
"subclass",
"override",
"to",
"provide",
"custom",
"functionality"
] | 7e6d05ac383da5f7e968c7e011d602c5a4d7a1de | https://github.com/dkd/enumeration/blob/7e6d05ac383da5f7e968c7e011d602c5a4d7a1de/src/Enumeration.php#L164-L172 | train |
dkd/enumeration | src/Enumeration.php | Enumeration.cast | public static function cast($value)
{
$currentClass = get_called_class();
if (!is_object($value) || get_class($value) !== $currentClass) {
$value = new $currentClass($value);
}
return $value;
} | php | public static function cast($value)
{
$currentClass = get_called_class();
if (!is_object($value) || get_class($value) !== $currentClass) {
$value = new $currentClass($value);
}
return $value;
} | [
"public",
"static",
"function",
"cast",
"(",
"$",
"value",
")",
"{",
"$",
"currentClass",
"=",
"get_called_class",
"(",
")",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"value",
")",
"||",
"get_class",
"(",
"$",
"value",
")",
"!==",
"$",
"currentClass",
")",
"{",
"$",
"value",
"=",
"new",
"$",
"currentClass",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Cast value to enumeration type
@param mixed $value Value that has to be casted
@return static | [
"Cast",
"value",
"to",
"enumeration",
"type"
] | 7e6d05ac383da5f7e968c7e011d602c5a4d7a1de | https://github.com/dkd/enumeration/blob/7e6d05ac383da5f7e968c7e011d602c5a4d7a1de/src/Enumeration.php#L180-L187 | train |
urmaul/rss-pipes | src/Controller.php | Controller.readConfig | public function readConfig($pipe)
{
$filename = $this->pipesDir . '/' . $pipe;
if (file_exists($filename . '.yml')) {
return Yaml::parse(file_get_contents($filename . '.yml'));
} elseif ($this->allowPhp && file_exists($filename . '.php')) {
return include ($filename . '.php');
} else {
throw new Exception('Unknown pipe');
}
} | php | public function readConfig($pipe)
{
$filename = $this->pipesDir . '/' . $pipe;
if (file_exists($filename . '.yml')) {
return Yaml::parse(file_get_contents($filename . '.yml'));
} elseif ($this->allowPhp && file_exists($filename . '.php')) {
return include ($filename . '.php');
} else {
throw new Exception('Unknown pipe');
}
} | [
"public",
"function",
"readConfig",
"(",
"$",
"pipe",
")",
"{",
"$",
"filename",
"=",
"$",
"this",
"->",
"pipesDir",
".",
"'/'",
".",
"$",
"pipe",
";",
"if",
"(",
"file_exists",
"(",
"$",
"filename",
".",
"'.yml'",
")",
")",
"{",
"return",
"Yaml",
"::",
"parse",
"(",
"file_get_contents",
"(",
"$",
"filename",
".",
"'.yml'",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"allowPhp",
"&&",
"file_exists",
"(",
"$",
"filename",
".",
"'.php'",
")",
")",
"{",
"return",
"include",
"(",
"$",
"filename",
".",
"'.php'",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'Unknown pipe'",
")",
";",
"}",
"}"
] | Reads pipe config from file.
@param string $pipe pipe name
@return array
@throws Exception | [
"Reads",
"pipe",
"config",
"from",
"file",
"."
] | 9e11e9a5315e8d11764c2784c02ffa02dee5639f | https://github.com/urmaul/rss-pipes/blob/9e11e9a5315e8d11764c2784c02ffa02dee5639f/src/Controller.php#L41-L53 | train |
FusePump/cli.php | lib/FusePump/Cli/Utils.php | Utils.pregMatchArray | public static function pregMatchArray($patterns, $subject)
{
if (!is_array($patterns)) {
throw new \Exception('$patterns is not an array');
}
if (!is_string($subject)) {
throw new \Exception('$subject is not a string');
}
foreach ($patterns as $pattern) {
if (preg_match($pattern, $subject)) {
return true;
}
}
return false;
} | php | public static function pregMatchArray($patterns, $subject)
{
if (!is_array($patterns)) {
throw new \Exception('$patterns is not an array');
}
if (!is_string($subject)) {
throw new \Exception('$subject is not a string');
}
foreach ($patterns as $pattern) {
if (preg_match($pattern, $subject)) {
return true;
}
}
return false;
} | [
"public",
"static",
"function",
"pregMatchArray",
"(",
"$",
"patterns",
",",
"$",
"subject",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"patterns",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'$patterns is not an array'",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"subject",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'$subject is not a string'",
")",
";",
"}",
"foreach",
"(",
"$",
"patterns",
"as",
"$",
"pattern",
")",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"subject",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Preg match array
Match subject to an array of regex patterns
@param array $patterns - array of regex patterns
@param string $subject - string to test patterns on
@static
@return bool - true if found, false otherwise
@throws \Exception - if pattern is not an array or subject not a string | [
"Preg",
"match",
"array"
] | 2cc92f09ce7b2f73d5cbc09f5ae4f31f3f9ae3b4 | https://github.com/FusePump/cli.php/blob/2cc92f09ce7b2f73d5cbc09f5ae4f31f3f9ae3b4/lib/FusePump/Cli/Utils.php#L133-L150 | train |
shgysk8zer0/core_api | traits/auth/basic.php | Basic.requireBasicLogin | final public function requireBasicLogin($realm = 'Restricted')
{
if (! (
array_key_exists('PHP_AUTH_USER', $_SERVER)
and array_key_exists('PHP_AUTH_PW', $_SERVER)
)) {
$this->_basicAuthFailed($realm);
} else {
$this->loginWith([
'user' => $_SERVER['PHP_AUTH_USER'],
'password' => $_SERVER['PHP_AUTH_PW']
]);
if (! $this->logged_in) {
$this->_basicAuthFailed($realm);
}
}
} | php | final public function requireBasicLogin($realm = 'Restricted')
{
if (! (
array_key_exists('PHP_AUTH_USER', $_SERVER)
and array_key_exists('PHP_AUTH_PW', $_SERVER)
)) {
$this->_basicAuthFailed($realm);
} else {
$this->loginWith([
'user' => $_SERVER['PHP_AUTH_USER'],
'password' => $_SERVER['PHP_AUTH_PW']
]);
if (! $this->logged_in) {
$this->_basicAuthFailed($realm);
}
}
} | [
"final",
"public",
"function",
"requireBasicLogin",
"(",
"$",
"realm",
"=",
"'Restricted'",
")",
"{",
"if",
"(",
"!",
"(",
"array_key_exists",
"(",
"'PHP_AUTH_USER'",
",",
"$",
"_SERVER",
")",
"and",
"array_key_exists",
"(",
"'PHP_AUTH_PW'",
",",
"$",
"_SERVER",
")",
")",
")",
"{",
"$",
"this",
"->",
"_basicAuthFailed",
"(",
"$",
"realm",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"loginWith",
"(",
"[",
"'user'",
"=>",
"$",
"_SERVER",
"[",
"'PHP_AUTH_USER'",
"]",
",",
"'password'",
"=>",
"$",
"_SERVER",
"[",
"'PHP_AUTH_PW'",
"]",
"]",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"logged_in",
")",
"{",
"$",
"this",
"->",
"_basicAuthFailed",
"(",
"$",
"realm",
")",
";",
"}",
"}",
"}"
] | Check for Basic Auth credentials and attempt to login if present
@param string $realm The "realm" to pass along if asking for credentials
@return void | [
"Check",
"for",
"Basic",
"Auth",
"credentials",
"and",
"attempt",
"to",
"login",
"if",
"present"
] | 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/auth/basic.php#L36-L53 | train |
ZFury/framework | library/Mvc/Controller/AbstractCrudController.php | AbstractCrudController.loadEntity | protected function loadEntity()
{
$params = array_merge($this->params()->fromPost(), $this->params()->fromRoute());
if (empty($params['id'])) {
throw new EntityNotFoundException('Bad Request');
}
$objectManager = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
if (!$model = $objectManager->getRepository(get_class($this->getEntity()))->find($params['id'])) {
throw new EntityNotFoundException('Entity not found');
}
return $model;
} | php | protected function loadEntity()
{
$params = array_merge($this->params()->fromPost(), $this->params()->fromRoute());
if (empty($params['id'])) {
throw new EntityNotFoundException('Bad Request');
}
$objectManager = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
if (!$model = $objectManager->getRepository(get_class($this->getEntity()))->find($params['id'])) {
throw new EntityNotFoundException('Entity not found');
}
return $model;
} | [
"protected",
"function",
"loadEntity",
"(",
")",
"{",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"params",
"(",
")",
"->",
"fromPost",
"(",
")",
",",
"$",
"this",
"->",
"params",
"(",
")",
"->",
"fromRoute",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"'id'",
"]",
")",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"'Bad Request'",
")",
";",
"}",
"$",
"objectManager",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'Doctrine\\ORM\\EntityManager'",
")",
";",
"if",
"(",
"!",
"$",
"model",
"=",
"$",
"objectManager",
"->",
"getRepository",
"(",
"get_class",
"(",
"$",
"this",
"->",
"getEntity",
"(",
")",
")",
")",
"->",
"find",
"(",
"$",
"params",
"[",
"'id'",
"]",
")",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"'Entity not found'",
")",
";",
"}",
"return",
"$",
"model",
";",
"}"
] | Find entity by id
@return mixed
@throws \Doctrine\ORM\EntityNotFoundException | [
"Find",
"entity",
"by",
"id"
] | eee4ca2a64d2d65490777b08be56c4c9b67bc892 | https://github.com/ZFury/framework/blob/eee4ca2a64d2d65490777b08be56c4c9b67bc892/library/Mvc/Controller/AbstractCrudController.php#L148-L161 | train |
SagittariusX/Beluga.Translation | src/Beluga/Translation/Source/ArraySource.php | ArraySource.getTranslation | public function getTranslation( $identifier, $defaultTranslation = null ) : string
{
if ( $this->_useNumericId )
{
// Not integer identifier. End here with an exception
if ( ! \is_int( $identifier ) )
{
throw new \InvalidArgumentException( 'Current ' . __CLASS__ . ' instance requires numeric identifier!' );
}
// The identifier not exists, return the default translation
if ( ! isset( $this->_translations[ $identifier ] ) )
{
return $defaultTranslation;
}
// Return string translation as it
if ( \is_string( $this->_translations[ $identifier ] ) )
{
return $this->_translations[ $identifier ];
}
// Handle translation array values
if ( \is_array( $this->_translations[ $identifier ] ) )
{
if ( isset( $this->_translations[ $identifier ][ 'text' ] ) )
{
return $this->_translations[ $identifier ][ 'text' ];
}
if ( isset( $this->_translations[ $identifier ][ 'value' ] ) )
{
return $this->_translations[ $identifier ][ 'value' ];
}
if ( isset( $this->_translations[ $identifier ][ 'translation' ] ) )
{
return $this->_translations[ $identifier ][ 'translation' ];
}
}
// No translation found
return $defaultTranslation;
}
// Not integer identifier. End here with an exception
if ( ! \is_string( $identifier ) )
{
throw new \InvalidArgumentException( 'Current ' . __CLASS__ . ' instance requires string identifier!' );
}
// The identifier not exists, return the default translation
if ( ! isset( $this->_translations[ $identifier ] ) )
{
return empty( $defaultTranslation ) ? $identifier : $defaultTranslation;
}
// Return string translation as it
if ( \is_string( $this->_translations[ $identifier ] ) )
{
return $this->_translations[ $identifier ];
}
// Handle translation array values
if ( \is_array( $this->_translations[ $identifier ] ) )
{
if ( isset( $this->_translations[ $identifier ][ 'text' ] ) )
{
return $this->_translations[ $identifier ][ 'text' ];
}
if ( isset( $this->_translations[ $identifier ][ 'value' ] ) )
{
return $this->_translations[ $identifier ][ 'value' ];
}
if ( isset( $this->_translations[ $identifier ][ 'translation' ] ) )
{
return $this->_translations[ $identifier ][ 'translation' ];
}
}
return empty( $defaultTranslation ) ? $identifier : $defaultTranslation;
} | php | public function getTranslation( $identifier, $defaultTranslation = null ) : string
{
if ( $this->_useNumericId )
{
// Not integer identifier. End here with an exception
if ( ! \is_int( $identifier ) )
{
throw new \InvalidArgumentException( 'Current ' . __CLASS__ . ' instance requires numeric identifier!' );
}
// The identifier not exists, return the default translation
if ( ! isset( $this->_translations[ $identifier ] ) )
{
return $defaultTranslation;
}
// Return string translation as it
if ( \is_string( $this->_translations[ $identifier ] ) )
{
return $this->_translations[ $identifier ];
}
// Handle translation array values
if ( \is_array( $this->_translations[ $identifier ] ) )
{
if ( isset( $this->_translations[ $identifier ][ 'text' ] ) )
{
return $this->_translations[ $identifier ][ 'text' ];
}
if ( isset( $this->_translations[ $identifier ][ 'value' ] ) )
{
return $this->_translations[ $identifier ][ 'value' ];
}
if ( isset( $this->_translations[ $identifier ][ 'translation' ] ) )
{
return $this->_translations[ $identifier ][ 'translation' ];
}
}
// No translation found
return $defaultTranslation;
}
// Not integer identifier. End here with an exception
if ( ! \is_string( $identifier ) )
{
throw new \InvalidArgumentException( 'Current ' . __CLASS__ . ' instance requires string identifier!' );
}
// The identifier not exists, return the default translation
if ( ! isset( $this->_translations[ $identifier ] ) )
{
return empty( $defaultTranslation ) ? $identifier : $defaultTranslation;
}
// Return string translation as it
if ( \is_string( $this->_translations[ $identifier ] ) )
{
return $this->_translations[ $identifier ];
}
// Handle translation array values
if ( \is_array( $this->_translations[ $identifier ] ) )
{
if ( isset( $this->_translations[ $identifier ][ 'text' ] ) )
{
return $this->_translations[ $identifier ][ 'text' ];
}
if ( isset( $this->_translations[ $identifier ][ 'value' ] ) )
{
return $this->_translations[ $identifier ][ 'value' ];
}
if ( isset( $this->_translations[ $identifier ][ 'translation' ] ) )
{
return $this->_translations[ $identifier ][ 'translation' ];
}
}
return empty( $defaultTranslation ) ? $identifier : $defaultTranslation;
} | [
"public",
"function",
"getTranslation",
"(",
"$",
"identifier",
",",
"$",
"defaultTranslation",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"_useNumericId",
")",
"{",
"// Not integer identifier. End here with an exception",
"if",
"(",
"!",
"\\",
"is_int",
"(",
"$",
"identifier",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Current '",
".",
"__CLASS__",
".",
"' instance requires numeric identifier!'",
")",
";",
"}",
"// The identifier not exists, return the default translation",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_translations",
"[",
"$",
"identifier",
"]",
")",
")",
"{",
"return",
"$",
"defaultTranslation",
";",
"}",
"// Return string translation as it",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"this",
"->",
"_translations",
"[",
"$",
"identifier",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_translations",
"[",
"$",
"identifier",
"]",
";",
"}",
"// Handle translation array values",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"this",
"->",
"_translations",
"[",
"$",
"identifier",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_translations",
"[",
"$",
"identifier",
"]",
"[",
"'text'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_translations",
"[",
"$",
"identifier",
"]",
"[",
"'text'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_translations",
"[",
"$",
"identifier",
"]",
"[",
"'value'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_translations",
"[",
"$",
"identifier",
"]",
"[",
"'value'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_translations",
"[",
"$",
"identifier",
"]",
"[",
"'translation'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_translations",
"[",
"$",
"identifier",
"]",
"[",
"'translation'",
"]",
";",
"}",
"}",
"// No translation found",
"return",
"$",
"defaultTranslation",
";",
"}",
"// Not integer identifier. End here with an exception",
"if",
"(",
"!",
"\\",
"is_string",
"(",
"$",
"identifier",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Current '",
".",
"__CLASS__",
".",
"' instance requires string identifier!'",
")",
";",
"}",
"// The identifier not exists, return the default translation",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_translations",
"[",
"$",
"identifier",
"]",
")",
")",
"{",
"return",
"empty",
"(",
"$",
"defaultTranslation",
")",
"?",
"$",
"identifier",
":",
"$",
"defaultTranslation",
";",
"}",
"// Return string translation as it",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"this",
"->",
"_translations",
"[",
"$",
"identifier",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_translations",
"[",
"$",
"identifier",
"]",
";",
"}",
"// Handle translation array values",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"this",
"->",
"_translations",
"[",
"$",
"identifier",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_translations",
"[",
"$",
"identifier",
"]",
"[",
"'text'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_translations",
"[",
"$",
"identifier",
"]",
"[",
"'text'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_translations",
"[",
"$",
"identifier",
"]",
"[",
"'value'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_translations",
"[",
"$",
"identifier",
"]",
"[",
"'value'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_translations",
"[",
"$",
"identifier",
"]",
"[",
"'translation'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_translations",
"[",
"$",
"identifier",
"]",
"[",
"'translation'",
"]",
";",
"}",
"}",
"return",
"empty",
"(",
"$",
"defaultTranslation",
")",
"?",
"$",
"identifier",
":",
"$",
"defaultTranslation",
";",
"}"
] | Gets the translation with the defined identifier
@param string|int $identifier
@param string|null $defaultTranslation Is returned if the translation was not found
@return string
@throws \InvalidArgumentException If the $identifier is invalid | [
"Gets",
"the",
"translation",
"with",
"the",
"defined",
"identifier"
] | 8f66c4fef6fa4494413972ca56bd8e13f5a7e444 | https://github.com/SagittariusX/Beluga.Translation/blob/8f66c4fef6fa4494413972ca56bd8e13f5a7e444/src/Beluga/Translation/Source/ArraySource.php#L129-L220 | train |
SagittariusX/Beluga.Translation | src/Beluga/Translation/Source/ArraySource.php | ArraySource.getTranslations | public function getTranslations( $category = null ) : array
{
$translations = [];
// If no category is defined (must be NULL) return all translations without a
if ( \is_null( $category ) )
{
foreach ( $this->_translations as $identifier => $transData )
{
if ( is_string( $transData ) )
{
$translations[ $identifier ] = $transData;
continue;
}
if ( ! \is_array( $transData ) || ! isset( $transData[ 'text' ] ) )
{
continue;
}
$translations[ $identifier ] = $transData[ 'text' ];
}
return $translations;
}
$category = \trim( $category );
$withCategory = \strlen( $category ) > 0;
$this->getCategories();
if ( ! \in_array( $category, $this->_categories ) && $category !== '' )
{
return $translations;
}
foreach ( $this->_translations as $identifier => $transData )
{
if ( $withCategory )
{
if ( ! \is_array( $transData ) ||
! isset( $transData[ 'category' ] ) ||
! isset( $transData[ 'text' ] ) ||
$transData[ 'category' ] !== $category )
{
continue;
}
$translations[ $identifier ] = $transData[ 'text' ];
}
else
{
if ( \is_array( $transData ) && isset( $transData[ 'text' ] ) )
{
if ( ( isset( $transData[ 'category' ] ) && $transData[ 'category' ] === '' ) ||
! isset( $transData[ 'category' ] ) )
{
$translations[ $identifier ] = $transData[ 'text' ];
}
}
else if ( \is_string( $transData ) )
{
$translations[ $identifier ] = $transData;
}
}
}
return $translations;
} | php | public function getTranslations( $category = null ) : array
{
$translations = [];
// If no category is defined (must be NULL) return all translations without a
if ( \is_null( $category ) )
{
foreach ( $this->_translations as $identifier => $transData )
{
if ( is_string( $transData ) )
{
$translations[ $identifier ] = $transData;
continue;
}
if ( ! \is_array( $transData ) || ! isset( $transData[ 'text' ] ) )
{
continue;
}
$translations[ $identifier ] = $transData[ 'text' ];
}
return $translations;
}
$category = \trim( $category );
$withCategory = \strlen( $category ) > 0;
$this->getCategories();
if ( ! \in_array( $category, $this->_categories ) && $category !== '' )
{
return $translations;
}
foreach ( $this->_translations as $identifier => $transData )
{
if ( $withCategory )
{
if ( ! \is_array( $transData ) ||
! isset( $transData[ 'category' ] ) ||
! isset( $transData[ 'text' ] ) ||
$transData[ 'category' ] !== $category )
{
continue;
}
$translations[ $identifier ] = $transData[ 'text' ];
}
else
{
if ( \is_array( $transData ) && isset( $transData[ 'text' ] ) )
{
if ( ( isset( $transData[ 'category' ] ) && $transData[ 'category' ] === '' ) ||
! isset( $transData[ 'category' ] ) )
{
$translations[ $identifier ] = $transData[ 'text' ];
}
}
else if ( \is_string( $transData ) )
{
$translations[ $identifier ] = $transData;
}
}
}
return $translations;
} | [
"public",
"function",
"getTranslations",
"(",
"$",
"category",
"=",
"null",
")",
":",
"array",
"{",
"$",
"translations",
"=",
"[",
"]",
";",
"// If no category is defined (must be NULL) return all translations without a",
"if",
"(",
"\\",
"is_null",
"(",
"$",
"category",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_translations",
"as",
"$",
"identifier",
"=>",
"$",
"transData",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"transData",
")",
")",
"{",
"$",
"translations",
"[",
"$",
"identifier",
"]",
"=",
"$",
"transData",
";",
"continue",
";",
"}",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"transData",
")",
"||",
"!",
"isset",
"(",
"$",
"transData",
"[",
"'text'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"translations",
"[",
"$",
"identifier",
"]",
"=",
"$",
"transData",
"[",
"'text'",
"]",
";",
"}",
"return",
"$",
"translations",
";",
"}",
"$",
"category",
"=",
"\\",
"trim",
"(",
"$",
"category",
")",
";",
"$",
"withCategory",
"=",
"\\",
"strlen",
"(",
"$",
"category",
")",
">",
"0",
";",
"$",
"this",
"->",
"getCategories",
"(",
")",
";",
"if",
"(",
"!",
"\\",
"in_array",
"(",
"$",
"category",
",",
"$",
"this",
"->",
"_categories",
")",
"&&",
"$",
"category",
"!==",
"''",
")",
"{",
"return",
"$",
"translations",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"_translations",
"as",
"$",
"identifier",
"=>",
"$",
"transData",
")",
"{",
"if",
"(",
"$",
"withCategory",
")",
"{",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"transData",
")",
"||",
"!",
"isset",
"(",
"$",
"transData",
"[",
"'category'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"transData",
"[",
"'text'",
"]",
")",
"||",
"$",
"transData",
"[",
"'category'",
"]",
"!==",
"$",
"category",
")",
"{",
"continue",
";",
"}",
"$",
"translations",
"[",
"$",
"identifier",
"]",
"=",
"$",
"transData",
"[",
"'text'",
"]",
";",
"}",
"else",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"transData",
")",
"&&",
"isset",
"(",
"$",
"transData",
"[",
"'text'",
"]",
")",
")",
"{",
"if",
"(",
"(",
"isset",
"(",
"$",
"transData",
"[",
"'category'",
"]",
")",
"&&",
"$",
"transData",
"[",
"'category'",
"]",
"===",
"''",
")",
"||",
"!",
"isset",
"(",
"$",
"transData",
"[",
"'category'",
"]",
")",
")",
"{",
"$",
"translations",
"[",
"$",
"identifier",
"]",
"=",
"$",
"transData",
"[",
"'text'",
"]",
";",
"}",
"}",
"else",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"transData",
")",
")",
"{",
"$",
"translations",
"[",
"$",
"identifier",
"]",
"=",
"$",
"transData",
";",
"}",
"}",
"}",
"return",
"$",
"translations",
";",
"}"
] | Gets all translations of an specific category. If not category is defined all translations of all categories
are returned.
@param string $category
@return array | [
"Gets",
"all",
"translations",
"of",
"an",
"specific",
"category",
".",
"If",
"not",
"category",
"is",
"defined",
"all",
"translations",
"of",
"all",
"categories",
"are",
"returned",
"."
] | 8f66c4fef6fa4494413972ca56bd8e13f5a7e444 | https://github.com/SagittariusX/Beluga.Translation/blob/8f66c4fef6fa4494413972ca56bd8e13f5a7e444/src/Beluga/Translation/Source/ArraySource.php#L229-L300 | train |
SagittariusX/Beluga.Translation | src/Beluga/Translation/Source/ArraySource.php | ArraySource.LoadFromFolder | public static function LoadFromFolder( string $folder, Locale $locale, bool $useNumericId = false )
{
$languageFolderBase = rtrim( $folder, '\\/' );
if ( ! empty( $languageFolderBase ) ) { $languageFolderBase .= '/'; }
$languageFile = $languageFolderBase . $locale->getLID() . '_' . $locale->getCID();
if ( \strlen( $locale->getCharset() ) > 0 )
{
$languageFile .= '/' . $locale->getCharset() . '.php';
}
else
{
$languageFile .= '.php';
}
if ( ! \file_exists( $languageFile ) )
{
$languageFile = $languageFolderBase . $locale->getLID() . '_' . $locale->getCID() . '.php';
}
if ( ! \file_exists( $languageFile ) )
{
$languageFile = $languageFolderBase . $locale->getLID() . '.php';
}
if ( ! \file_exists( $languageFile ) )
{
return new ArraySource( $locale, $useNumericId, [ 'data' => [] ] );
}
return new ArraySource( $locale, $useNumericId, [ 'file' => $languageFile ] );
} | php | public static function LoadFromFolder( string $folder, Locale $locale, bool $useNumericId = false )
{
$languageFolderBase = rtrim( $folder, '\\/' );
if ( ! empty( $languageFolderBase ) ) { $languageFolderBase .= '/'; }
$languageFile = $languageFolderBase . $locale->getLID() . '_' . $locale->getCID();
if ( \strlen( $locale->getCharset() ) > 0 )
{
$languageFile .= '/' . $locale->getCharset() . '.php';
}
else
{
$languageFile .= '.php';
}
if ( ! \file_exists( $languageFile ) )
{
$languageFile = $languageFolderBase . $locale->getLID() . '_' . $locale->getCID() . '.php';
}
if ( ! \file_exists( $languageFile ) )
{
$languageFile = $languageFolderBase . $locale->getLID() . '.php';
}
if ( ! \file_exists( $languageFile ) )
{
return new ArraySource( $locale, $useNumericId, [ 'data' => [] ] );
}
return new ArraySource( $locale, $useNumericId, [ 'file' => $languageFile ] );
} | [
"public",
"static",
"function",
"LoadFromFolder",
"(",
"string",
"$",
"folder",
",",
"Locale",
"$",
"locale",
",",
"bool",
"$",
"useNumericId",
"=",
"false",
")",
"{",
"$",
"languageFolderBase",
"=",
"rtrim",
"(",
"$",
"folder",
",",
"'\\\\/'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"languageFolderBase",
")",
")",
"{",
"$",
"languageFolderBase",
".=",
"'/'",
";",
"}",
"$",
"languageFile",
"=",
"$",
"languageFolderBase",
".",
"$",
"locale",
"->",
"getLID",
"(",
")",
".",
"'_'",
".",
"$",
"locale",
"->",
"getCID",
"(",
")",
";",
"if",
"(",
"\\",
"strlen",
"(",
"$",
"locale",
"->",
"getCharset",
"(",
")",
")",
">",
"0",
")",
"{",
"$",
"languageFile",
".=",
"'/'",
".",
"$",
"locale",
"->",
"getCharset",
"(",
")",
".",
"'.php'",
";",
"}",
"else",
"{",
"$",
"languageFile",
".=",
"'.php'",
";",
"}",
"if",
"(",
"!",
"\\",
"file_exists",
"(",
"$",
"languageFile",
")",
")",
"{",
"$",
"languageFile",
"=",
"$",
"languageFolderBase",
".",
"$",
"locale",
"->",
"getLID",
"(",
")",
".",
"'_'",
".",
"$",
"locale",
"->",
"getCID",
"(",
")",
".",
"'.php'",
";",
"}",
"if",
"(",
"!",
"\\",
"file_exists",
"(",
"$",
"languageFile",
")",
")",
"{",
"$",
"languageFile",
"=",
"$",
"languageFolderBase",
".",
"$",
"locale",
"->",
"getLID",
"(",
")",
".",
"'.php'",
";",
"}",
"if",
"(",
"!",
"\\",
"file_exists",
"(",
"$",
"languageFile",
")",
")",
"{",
"return",
"new",
"ArraySource",
"(",
"$",
"locale",
",",
"$",
"useNumericId",
",",
"[",
"'data'",
"=>",
"[",
"]",
"]",
")",
";",
"}",
"return",
"new",
"ArraySource",
"(",
"$",
"locale",
",",
"$",
"useNumericId",
",",
"[",
"'file'",
"=>",
"$",
"languageFile",
"]",
")",
";",
"}"
] | Loads a translation array source from a specific folder that contains one or more locale depending PHP files.
E.G: if the defined $folder is '/var/www/example.com/translations' and the declared Locale is de_DE.UTF-8
it tries to use:
- /var/www/example.com/translations/de_DE.UTF-8.php
- /var/www/example.com/translations/de_DE.php
- /var/www/example.com/translations/de.php
The used file should be declared like for translations with numeric indicators
<code>
return [
// Simple translation as string (translation is not a part of a category)
1 => 'Übersetzter Text',
// Translation is an array (translation is not a part of a category because the category is empty)
2 => [ 'category' => '', 'text' => 'Anderer übersetzter Text' ],
// Translation is an array (translation is a part of the 'category name' category)
4 => [ 'category' => 'category name', 'text' => 'Anderer übersetzter Text' ],
// Translation is an array (translation is not a part of a category because no category is defined)
5 => [ 'text' => 'Anderer übersetzter Text' ],
// Translation will be ignored because the 'text' element not exists
6 => [ 'category' => 'category name', 'value' => 'Anderer übersetzter Text' ]
];
</code>
or for translations with string indicators:
<code>
return [
// Simple translation as string (translation is not a part of a category)
'Translated text' => 'Übersetzter Text',
// Translation is an array (translation is not a part of a category because the category is empty)
'Other translated text 1' => [ 'category' => '', 'text' => 'Anderer übersetzter Text 1' ],
// Translation is an array (translation is a part of the 'category name' category)
'Other translated text 2' => [ 'category' => 'category name', 'text' => 'Anderer übersetzter Text 2' ],
// Translation is an array (translation is not a part of a category because no category is defined)
'Other translated text 3' => [ 'text' => 'Anderer übersetzter Text 3' ],
// Translation will be ignored because the 'text' element not exists
'Other translated text 3' => [ 'category' => 'category name', 'value' => 'Anderer übersetzter Text 4' ]
];
</code>
@param string $folder
@param \Beluga\Translation\Locale $locale
@param bool $useNumericId
@return \Beluga\Translation\Source\ArraySource | [
"Loads",
"a",
"translation",
"array",
"source",
"from",
"a",
"specific",
"folder",
"that",
"contains",
"one",
"or",
"more",
"locale",
"depending",
"PHP",
"files",
"."
] | 8f66c4fef6fa4494413972ca56bd8e13f5a7e444 | https://github.com/SagittariusX/Beluga.Translation/blob/8f66c4fef6fa4494413972ca56bd8e13f5a7e444/src/Beluga/Translation/Source/ArraySource.php#L460-L493 | train |
black-lamp/blcms-cart | CartComponent.php | CartComponent.add | public function add($productId, $count, $attributesAndValues = null, $additionalProducts = [], $combinationId = null)
{
if (!empty($attributesAndValues)) {
$attributesAndValues = Json::decode($attributesAndValues);
}
if ($this->saveSelectedCombination) {
$combination = Combination::findOne($combinationId) ?? $this->getCombination($attributesAndValues, $productId);
$this->saveSelectedCombinationToSession($combination);
}
if ($this->saveToDataBase && !\Yii::$app->user->isGuest) {
$this->saveProductToDataBase($productId, $count, $attributesAndValues, $additionalProducts, $combinationId);
} else {
$this->saveProductToSession($productId, $count, $attributesAndValues, $additionalProducts, $combinationId);
}
$this->trigger(self::EVENT_AFTER_ADD_PRODUCT);
} | php | public function add($productId, $count, $attributesAndValues = null, $additionalProducts = [], $combinationId = null)
{
if (!empty($attributesAndValues)) {
$attributesAndValues = Json::decode($attributesAndValues);
}
if ($this->saveSelectedCombination) {
$combination = Combination::findOne($combinationId) ?? $this->getCombination($attributesAndValues, $productId);
$this->saveSelectedCombinationToSession($combination);
}
if ($this->saveToDataBase && !\Yii::$app->user->isGuest) {
$this->saveProductToDataBase($productId, $count, $attributesAndValues, $additionalProducts, $combinationId);
} else {
$this->saveProductToSession($productId, $count, $attributesAndValues, $additionalProducts, $combinationId);
}
$this->trigger(self::EVENT_AFTER_ADD_PRODUCT);
} | [
"public",
"function",
"add",
"(",
"$",
"productId",
",",
"$",
"count",
",",
"$",
"attributesAndValues",
"=",
"null",
",",
"$",
"additionalProducts",
"=",
"[",
"]",
",",
"$",
"combinationId",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"attributesAndValues",
")",
")",
"{",
"$",
"attributesAndValues",
"=",
"Json",
"::",
"decode",
"(",
"$",
"attributesAndValues",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"saveSelectedCombination",
")",
"{",
"$",
"combination",
"=",
"Combination",
"::",
"findOne",
"(",
"$",
"combinationId",
")",
"??",
"$",
"this",
"->",
"getCombination",
"(",
"$",
"attributesAndValues",
",",
"$",
"productId",
")",
";",
"$",
"this",
"->",
"saveSelectedCombinationToSession",
"(",
"$",
"combination",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"saveToDataBase",
"&&",
"!",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"isGuest",
")",
"{",
"$",
"this",
"->",
"saveProductToDataBase",
"(",
"$",
"productId",
",",
"$",
"count",
",",
"$",
"attributesAndValues",
",",
"$",
"additionalProducts",
",",
"$",
"combinationId",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"saveProductToSession",
"(",
"$",
"productId",
",",
"$",
"count",
",",
"$",
"attributesAndValues",
",",
"$",
"additionalProducts",
",",
"$",
"combinationId",
")",
";",
"}",
"$",
"this",
"->",
"trigger",
"(",
"self",
"::",
"EVENT_AFTER_ADD_PRODUCT",
")",
";",
"}"
] | Adds product to cart.
@param $productId
@param $count
@param null $attributesAndValues
@param array $additionalProducts
@param null $combinationId | [
"Adds",
"product",
"to",
"cart",
"."
] | 314796eecae3ca4ed5fecfdc0231a738af50eba7 | https://github.com/black-lamp/blcms-cart/blob/314796eecae3ca4ed5fecfdc0231a738af50eba7/CartComponent.php#L104-L121 | train |
black-lamp/blcms-cart | CartComponent.php | CartComponent.saveProductToDataBase | private function saveProductToDataBase($productId, $count, $attributesAndValues = null, $additionalProducts = null, $combinationId = null)
{
$order = $this->getIncompleteOrderFromDB();
if (\Yii::$app->getModule('shop')->enableCombinations) {
if (!empty($attributesAndValues)) {
$combination = $this->getCombination($attributesAndValues, $productId);
if (!empty($combination)) {
$orderProduct = $this->getOrderProduct($order->id, $productId, $combination->id);
}
else {
throw new Exception(\Yii::t('cart', 'Such attributes combination does not exist'));
}
}
else if(!empty($combinationId)) {
$orderProduct = $this->getOrderProduct($order->id, $productId, $combinationId);
}
else {
$orderProduct = $this->getOrderProduct($order->id, $productId, null);
}
} else {
$orderProduct = new OrderProduct();
$orderProduct->product_id = $productId;
$orderProduct->order_id = $order->id;
}
$orderProduct->count += $count;
if ($orderProduct->validate()) {
$orderProduct->save();
if (!empty($additionalProducts)) {
foreach ($additionalProducts as $additionalProduct) {
$orderProductAdditionalProduct = OrderProductAdditionalProduct::find()
->where(['order_product_id' => $orderProduct->id, 'additional_product_id' => $additionalProduct['productId']])
->one();
if (empty($orderProductAdditionalProduct)) {
$orderProductAdditionalProduct = new OrderProductAdditionalProduct();
$orderProductAdditionalProduct->order_product_id = $orderProduct->id;
$orderProductAdditionalProduct->additional_product_id = $additionalProduct['productId'];
$orderProductAdditionalProduct->number = $additionalProduct['number'];
if ($orderProductAdditionalProduct->validate()) $orderProductAdditionalProduct->save();
}
else {
$orderProductAdditionalProduct->number += $additionalProduct['number'];
if ($orderProductAdditionalProduct->validate()) $orderProductAdditionalProduct->save();
}
}
}
} else die(var_dump($orderProduct->errors));
} | php | private function saveProductToDataBase($productId, $count, $attributesAndValues = null, $additionalProducts = null, $combinationId = null)
{
$order = $this->getIncompleteOrderFromDB();
if (\Yii::$app->getModule('shop')->enableCombinations) {
if (!empty($attributesAndValues)) {
$combination = $this->getCombination($attributesAndValues, $productId);
if (!empty($combination)) {
$orderProduct = $this->getOrderProduct($order->id, $productId, $combination->id);
}
else {
throw new Exception(\Yii::t('cart', 'Such attributes combination does not exist'));
}
}
else if(!empty($combinationId)) {
$orderProduct = $this->getOrderProduct($order->id, $productId, $combinationId);
}
else {
$orderProduct = $this->getOrderProduct($order->id, $productId, null);
}
} else {
$orderProduct = new OrderProduct();
$orderProduct->product_id = $productId;
$orderProduct->order_id = $order->id;
}
$orderProduct->count += $count;
if ($orderProduct->validate()) {
$orderProduct->save();
if (!empty($additionalProducts)) {
foreach ($additionalProducts as $additionalProduct) {
$orderProductAdditionalProduct = OrderProductAdditionalProduct::find()
->where(['order_product_id' => $orderProduct->id, 'additional_product_id' => $additionalProduct['productId']])
->one();
if (empty($orderProductAdditionalProduct)) {
$orderProductAdditionalProduct = new OrderProductAdditionalProduct();
$orderProductAdditionalProduct->order_product_id = $orderProduct->id;
$orderProductAdditionalProduct->additional_product_id = $additionalProduct['productId'];
$orderProductAdditionalProduct->number = $additionalProduct['number'];
if ($orderProductAdditionalProduct->validate()) $orderProductAdditionalProduct->save();
}
else {
$orderProductAdditionalProduct->number += $additionalProduct['number'];
if ($orderProductAdditionalProduct->validate()) $orderProductAdditionalProduct->save();
}
}
}
} else die(var_dump($orderProduct->errors));
} | [
"private",
"function",
"saveProductToDataBase",
"(",
"$",
"productId",
",",
"$",
"count",
",",
"$",
"attributesAndValues",
"=",
"null",
",",
"$",
"additionalProducts",
"=",
"null",
",",
"$",
"combinationId",
"=",
"null",
")",
"{",
"$",
"order",
"=",
"$",
"this",
"->",
"getIncompleteOrderFromDB",
"(",
")",
";",
"if",
"(",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"getModule",
"(",
"'shop'",
")",
"->",
"enableCombinations",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"attributesAndValues",
")",
")",
"{",
"$",
"combination",
"=",
"$",
"this",
"->",
"getCombination",
"(",
"$",
"attributesAndValues",
",",
"$",
"productId",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"combination",
")",
")",
"{",
"$",
"orderProduct",
"=",
"$",
"this",
"->",
"getOrderProduct",
"(",
"$",
"order",
"->",
"id",
",",
"$",
"productId",
",",
"$",
"combination",
"->",
"id",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"\\",
"Yii",
"::",
"t",
"(",
"'cart'",
",",
"'Such attributes combination does not exist'",
")",
")",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"combinationId",
")",
")",
"{",
"$",
"orderProduct",
"=",
"$",
"this",
"->",
"getOrderProduct",
"(",
"$",
"order",
"->",
"id",
",",
"$",
"productId",
",",
"$",
"combinationId",
")",
";",
"}",
"else",
"{",
"$",
"orderProduct",
"=",
"$",
"this",
"->",
"getOrderProduct",
"(",
"$",
"order",
"->",
"id",
",",
"$",
"productId",
",",
"null",
")",
";",
"}",
"}",
"else",
"{",
"$",
"orderProduct",
"=",
"new",
"OrderProduct",
"(",
")",
";",
"$",
"orderProduct",
"->",
"product_id",
"=",
"$",
"productId",
";",
"$",
"orderProduct",
"->",
"order_id",
"=",
"$",
"order",
"->",
"id",
";",
"}",
"$",
"orderProduct",
"->",
"count",
"+=",
"$",
"count",
";",
"if",
"(",
"$",
"orderProduct",
"->",
"validate",
"(",
")",
")",
"{",
"$",
"orderProduct",
"->",
"save",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"additionalProducts",
")",
")",
"{",
"foreach",
"(",
"$",
"additionalProducts",
"as",
"$",
"additionalProduct",
")",
"{",
"$",
"orderProductAdditionalProduct",
"=",
"OrderProductAdditionalProduct",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'order_product_id'",
"=>",
"$",
"orderProduct",
"->",
"id",
",",
"'additional_product_id'",
"=>",
"$",
"additionalProduct",
"[",
"'productId'",
"]",
"]",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"orderProductAdditionalProduct",
")",
")",
"{",
"$",
"orderProductAdditionalProduct",
"=",
"new",
"OrderProductAdditionalProduct",
"(",
")",
";",
"$",
"orderProductAdditionalProduct",
"->",
"order_product_id",
"=",
"$",
"orderProduct",
"->",
"id",
";",
"$",
"orderProductAdditionalProduct",
"->",
"additional_product_id",
"=",
"$",
"additionalProduct",
"[",
"'productId'",
"]",
";",
"$",
"orderProductAdditionalProduct",
"->",
"number",
"=",
"$",
"additionalProduct",
"[",
"'number'",
"]",
";",
"if",
"(",
"$",
"orderProductAdditionalProduct",
"->",
"validate",
"(",
")",
")",
"$",
"orderProductAdditionalProduct",
"->",
"save",
"(",
")",
";",
"}",
"else",
"{",
"$",
"orderProductAdditionalProduct",
"->",
"number",
"+=",
"$",
"additionalProduct",
"[",
"'number'",
"]",
";",
"if",
"(",
"$",
"orderProductAdditionalProduct",
"->",
"validate",
"(",
")",
")",
"$",
"orderProductAdditionalProduct",
"->",
"save",
"(",
")",
";",
"}",
"}",
"}",
"}",
"else",
"die",
"(",
"var_dump",
"(",
"$",
"orderProduct",
"->",
"errors",
")",
")",
";",
"}"
] | Saves product to database if the corresponding property is true.
@param integer $productId
@param integer $count
@param array|null $attributesAndValues
@param array|null $additionalProducts
@param null $combinationId
@throws Exception | [
"Saves",
"product",
"to",
"database",
"if",
"the",
"corresponding",
"property",
"is",
"true",
"."
] | 314796eecae3ca4ed5fecfdc0231a738af50eba7 | https://github.com/black-lamp/blcms-cart/blob/314796eecae3ca4ed5fecfdc0231a738af50eba7/CartComponent.php#L133-L183 | train |
black-lamp/blcms-cart | CartComponent.php | CartComponent.getIncompleteOrderFromDB | private function getIncompleteOrderFromDB()
{
$order = Order::find()->where([
'user_id' => \Yii::$app->user->id,
'status' => OrderStatus::STATUS_INCOMPLETE])
->one();
if (empty($order)) {
$order = new Order();
$order->uid = $this->generateUniqueId($this->uidPrefix, $this->minOrderUid, $this->maxOrderUid);
$order->user_id = \Yii::$app->user->id;
$order->status = OrderStatus::STATUS_INCOMPLETE;
if ($order->validate()) {
$order->save();
}
}
return $order;
} | php | private function getIncompleteOrderFromDB()
{
$order = Order::find()->where([
'user_id' => \Yii::$app->user->id,
'status' => OrderStatus::STATUS_INCOMPLETE])
->one();
if (empty($order)) {
$order = new Order();
$order->uid = $this->generateUniqueId($this->uidPrefix, $this->minOrderUid, $this->maxOrderUid);
$order->user_id = \Yii::$app->user->id;
$order->status = OrderStatus::STATUS_INCOMPLETE;
if ($order->validate()) {
$order->save();
}
}
return $order;
} | [
"private",
"function",
"getIncompleteOrderFromDB",
"(",
")",
"{",
"$",
"order",
"=",
"Order",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'user_id'",
"=>",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"id",
",",
"'status'",
"=>",
"OrderStatus",
"::",
"STATUS_INCOMPLETE",
"]",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"order",
")",
")",
"{",
"$",
"order",
"=",
"new",
"Order",
"(",
")",
";",
"$",
"order",
"->",
"uid",
"=",
"$",
"this",
"->",
"generateUniqueId",
"(",
"$",
"this",
"->",
"uidPrefix",
",",
"$",
"this",
"->",
"minOrderUid",
",",
"$",
"this",
"->",
"maxOrderUid",
")",
";",
"$",
"order",
"->",
"user_id",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"id",
";",
"$",
"order",
"->",
"status",
"=",
"OrderStatus",
"::",
"STATUS_INCOMPLETE",
";",
"if",
"(",
"$",
"order",
"->",
"validate",
"(",
")",
")",
"{",
"$",
"order",
"->",
"save",
"(",
")",
";",
"}",
"}",
"return",
"$",
"order",
";",
"}"
] | Gets or creates incomplete order record from database.
@return array|Order|null|ActiveRecord | [
"Gets",
"or",
"creates",
"incomplete",
"order",
"record",
"from",
"database",
"."
] | 314796eecae3ca4ed5fecfdc0231a738af50eba7 | https://github.com/black-lamp/blcms-cart/blob/314796eecae3ca4ed5fecfdc0231a738af50eba7/CartComponent.php#L219-L236 | train |
black-lamp/blcms-cart | CartComponent.php | CartComponent.saveSelectedCombinationToSession | public function saveSelectedCombinationToSession($combination)
{
if (!empty($combination)) {
$items = Yii::$app->session[self::SESSION_KEY_SELECTED_COMBINATIONS];
$itemIsExist = false;
if(!empty($items)) {
foreach ($items as $key => $item) {
if ($item['productId'] == $combination->product_id) {
$items[$key]['combinationId'] = $combination->id;
$itemIsExist = true;
}
}
}
if (!$itemIsExist) {
$items[] = [
'productId' => $combination->product_id,
'combinationId' => $combination->id,
];
}
Yii::$app->session[self::SESSION_KEY_SELECTED_COMBINATIONS] = $items;
return true;
}
return false;
} | php | public function saveSelectedCombinationToSession($combination)
{
if (!empty($combination)) {
$items = Yii::$app->session[self::SESSION_KEY_SELECTED_COMBINATIONS];
$itemIsExist = false;
if(!empty($items)) {
foreach ($items as $key => $item) {
if ($item['productId'] == $combination->product_id) {
$items[$key]['combinationId'] = $combination->id;
$itemIsExist = true;
}
}
}
if (!$itemIsExist) {
$items[] = [
'productId' => $combination->product_id,
'combinationId' => $combination->id,
];
}
Yii::$app->session[self::SESSION_KEY_SELECTED_COMBINATIONS] = $items;
return true;
}
return false;
} | [
"public",
"function",
"saveSelectedCombinationToSession",
"(",
"$",
"combination",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"combination",
")",
")",
"{",
"$",
"items",
"=",
"Yii",
"::",
"$",
"app",
"->",
"session",
"[",
"self",
"::",
"SESSION_KEY_SELECTED_COMBINATIONS",
"]",
";",
"$",
"itemIsExist",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"items",
")",
")",
"{",
"foreach",
"(",
"$",
"items",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"[",
"'productId'",
"]",
"==",
"$",
"combination",
"->",
"product_id",
")",
"{",
"$",
"items",
"[",
"$",
"key",
"]",
"[",
"'combinationId'",
"]",
"=",
"$",
"combination",
"->",
"id",
";",
"$",
"itemIsExist",
"=",
"true",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"$",
"itemIsExist",
")",
"{",
"$",
"items",
"[",
"]",
"=",
"[",
"'productId'",
"=>",
"$",
"combination",
"->",
"product_id",
",",
"'combinationId'",
"=>",
"$",
"combination",
"->",
"id",
",",
"]",
";",
"}",
"Yii",
"::",
"$",
"app",
"->",
"session",
"[",
"self",
"::",
"SESSION_KEY_SELECTED_COMBINATIONS",
"]",
"=",
"$",
"items",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Saves last selected product combinations to session.
@param Combination $combination
@return bool | [
"Saves",
"last",
"selected",
"product",
"combinations",
"to",
"session",
"."
] | 314796eecae3ca4ed5fecfdc0231a738af50eba7 | https://github.com/black-lamp/blcms-cart/blob/314796eecae3ca4ed5fecfdc0231a738af50eba7/CartComponent.php#L328-L355 | train |
black-lamp/blcms-cart | CartComponent.php | CartComponent.getSelectedCombinationFromSession | public function getSelectedCombinationFromSession($productId)
{
$combination = null;
if (!empty($productId)) {
$items = Yii::$app->session[self::SESSION_KEY_SELECTED_COMBINATIONS];
if (!empty($items)) {
$combinationId = null;
foreach ($items as $item) {
if ($item['productId'] == $productId) {
$combinationId = $item['combinationId'];
}
}
$combination = Combination::findOne($combinationId);
}
}
return $combination;
} | php | public function getSelectedCombinationFromSession($productId)
{
$combination = null;
if (!empty($productId)) {
$items = Yii::$app->session[self::SESSION_KEY_SELECTED_COMBINATIONS];
if (!empty($items)) {
$combinationId = null;
foreach ($items as $item) {
if ($item['productId'] == $productId) {
$combinationId = $item['combinationId'];
}
}
$combination = Combination::findOne($combinationId);
}
}
return $combination;
} | [
"public",
"function",
"getSelectedCombinationFromSession",
"(",
"$",
"productId",
")",
"{",
"$",
"combination",
"=",
"null",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"productId",
")",
")",
"{",
"$",
"items",
"=",
"Yii",
"::",
"$",
"app",
"->",
"session",
"[",
"self",
"::",
"SESSION_KEY_SELECTED_COMBINATIONS",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"items",
")",
")",
"{",
"$",
"combinationId",
"=",
"null",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"[",
"'productId'",
"]",
"==",
"$",
"productId",
")",
"{",
"$",
"combinationId",
"=",
"$",
"item",
"[",
"'combinationId'",
"]",
";",
"}",
"}",
"$",
"combination",
"=",
"Combination",
"::",
"findOne",
"(",
"$",
"combinationId",
")",
";",
"}",
"}",
"return",
"$",
"combination",
";",
"}"
] | Gets last selected product combinations from session.
@param $productId [[Product]] id
@return null|Combination | [
"Gets",
"last",
"selected",
"product",
"combinations",
"from",
"session",
"."
] | 314796eecae3ca4ed5fecfdc0231a738af50eba7 | https://github.com/black-lamp/blcms-cart/blob/314796eecae3ca4ed5fecfdc0231a738af50eba7/CartComponent.php#L363-L384 | train |
black-lamp/blcms-cart | CartComponent.php | CartComponent.getOrderItems | public function getOrderItems()
{
if (\Yii::$app->user->isGuest) {
$session = \Yii::$app->session;
$products = $session[self::SESSION_KEY];
} else {
$order = Order::find()->where(['user_id' => \Yii::$app->user->id, 'status' => OrderStatus::STATUS_INCOMPLETE])->one();
if (!empty($order))
$products = OrderProduct::find()->asArray()->where(['order_id' => $order->id])->all();
}
return $products ?? false;
} | php | public function getOrderItems()
{
if (\Yii::$app->user->isGuest) {
$session = \Yii::$app->session;
$products = $session[self::SESSION_KEY];
} else {
$order = Order::find()->where(['user_id' => \Yii::$app->user->id, 'status' => OrderStatus::STATUS_INCOMPLETE])->one();
if (!empty($order))
$products = OrderProduct::find()->asArray()->where(['order_id' => $order->id])->all();
}
return $products ?? false;
} | [
"public",
"function",
"getOrderItems",
"(",
")",
"{",
"if",
"(",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"isGuest",
")",
"{",
"$",
"session",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"session",
";",
"$",
"products",
"=",
"$",
"session",
"[",
"self",
"::",
"SESSION_KEY",
"]",
";",
"}",
"else",
"{",
"$",
"order",
"=",
"Order",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'user_id'",
"=>",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"id",
",",
"'status'",
"=>",
"OrderStatus",
"::",
"STATUS_INCOMPLETE",
"]",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"order",
")",
")",
"$",
"products",
"=",
"OrderProduct",
"::",
"find",
"(",
")",
"->",
"asArray",
"(",
")",
"->",
"where",
"(",
"[",
"'order_id'",
"=>",
"$",
"order",
"->",
"id",
"]",
")",
"->",
"all",
"(",
")",
";",
"}",
"return",
"$",
"products",
"??",
"false",
";",
"}"
] | Gets order items.
@return array|bool|mixed|\yii\db\ActiveRecord[] | [
"Gets",
"order",
"items",
"."
] | 314796eecae3ca4ed5fecfdc0231a738af50eba7 | https://github.com/black-lamp/blcms-cart/blob/314796eecae3ca4ed5fecfdc0231a738af50eba7/CartComponent.php#L431-L442 | train |
black-lamp/blcms-cart | CartComponent.php | CartComponent.getOrderItemsCount | public function getOrderItemsCount()
{
if (\Yii::$app->user->isGuest) {
$session = \Yii::$app->session;
return count($session[self::SESSION_KEY]);
} else {
$order = Order::find()->where(['user_id' => \Yii::$app->user->id, 'status' => OrderStatus::STATUS_INCOMPLETE])->one();
if (!empty($order)) {
$count = OrderProduct::find()->asArray()->where(['order_id' => $order->id])->count();
} else $count = 0;
}
return $count;
} | php | public function getOrderItemsCount()
{
if (\Yii::$app->user->isGuest) {
$session = \Yii::$app->session;
return count($session[self::SESSION_KEY]);
} else {
$order = Order::find()->where(['user_id' => \Yii::$app->user->id, 'status' => OrderStatus::STATUS_INCOMPLETE])->one();
if (!empty($order)) {
$count = OrderProduct::find()->asArray()->where(['order_id' => $order->id])->count();
} else $count = 0;
}
return $count;
} | [
"public",
"function",
"getOrderItemsCount",
"(",
")",
"{",
"if",
"(",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"isGuest",
")",
"{",
"$",
"session",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"session",
";",
"return",
"count",
"(",
"$",
"session",
"[",
"self",
"::",
"SESSION_KEY",
"]",
")",
";",
"}",
"else",
"{",
"$",
"order",
"=",
"Order",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'user_id'",
"=>",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"id",
",",
"'status'",
"=>",
"OrderStatus",
"::",
"STATUS_INCOMPLETE",
"]",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"order",
")",
")",
"{",
"$",
"count",
"=",
"OrderProduct",
"::",
"find",
"(",
")",
"->",
"asArray",
"(",
")",
"->",
"where",
"(",
"[",
"'order_id'",
"=>",
"$",
"order",
"->",
"id",
"]",
")",
"->",
"count",
"(",
")",
";",
"}",
"else",
"$",
"count",
"=",
"0",
";",
"}",
"return",
"$",
"count",
";",
"}"
] | Gets order items count.
@return integer | [
"Gets",
"order",
"items",
"count",
"."
] | 314796eecae3ca4ed5fecfdc0231a738af50eba7 | https://github.com/black-lamp/blcms-cart/blob/314796eecae3ca4ed5fecfdc0231a738af50eba7/CartComponent.php#L449-L463 | train |
black-lamp/blcms-cart | CartComponent.php | CartComponent.getAllUserOrders | public function getAllUserOrders()
{
if (!\Yii::$app->user->isGuest && $this->saveToDataBase === true) {
$orders = Order::find()
->where(['user_id' => \Yii::$app->user->id])
->andWhere(['!=', 'status', OrderStatus::STATUS_INCOMPLETE])->all();
return $orders;
} else return false;
} | php | public function getAllUserOrders()
{
if (!\Yii::$app->user->isGuest && $this->saveToDataBase === true) {
$orders = Order::find()
->where(['user_id' => \Yii::$app->user->id])
->andWhere(['!=', 'status', OrderStatus::STATUS_INCOMPLETE])->all();
return $orders;
} else return false;
} | [
"public",
"function",
"getAllUserOrders",
"(",
")",
"{",
"if",
"(",
"!",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"isGuest",
"&&",
"$",
"this",
"->",
"saveToDataBase",
"===",
"true",
")",
"{",
"$",
"orders",
"=",
"Order",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'user_id'",
"=>",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"id",
"]",
")",
"->",
"andWhere",
"(",
"[",
"'!='",
",",
"'status'",
",",
"OrderStatus",
"::",
"STATUS_INCOMPLETE",
"]",
")",
"->",
"all",
"(",
")",
";",
"return",
"$",
"orders",
";",
"}",
"else",
"return",
"false",
";",
"}"
] | Gets all user orders from database.
@return bool|\yii\db\ActiveRecord[] | [
"Gets",
"all",
"user",
"orders",
"from",
"database",
"."
] | 314796eecae3ca4ed5fecfdc0231a738af50eba7 | https://github.com/black-lamp/blcms-cart/blob/314796eecae3ca4ed5fecfdc0231a738af50eba7/CartComponent.php#L470-L478 | train |
black-lamp/blcms-cart | CartComponent.php | CartComponent.removeItem | public function removeItem(int $productId, int $combinationId = null)
{
if (!\Yii::$app->user->isGuest) {
$order = Order::find()->where([
'user_id' => \Yii::$app->user->id,
'status' => OrderStatus::STATUS_INCOMPLETE
])->one();
if (!empty($order)) {
$orderProduct = OrderProduct::find()->where([
'product_id' => $productId,
'combination_id' => $combinationId,
'order_id' => $order->id
])->one();
if (!empty($orderProduct)) {
$orderProduct->delete();
}
}
} else {
$session = Yii::$app->session;
if ($session->has(self::SESSION_KEY)) {
$products = $session[self::SESSION_KEY];
foreach ($products as $key => $product) {
if ($product['id'] == $productId && $product['combinationId'] == $combinationId)
unset($_SESSION[self::SESSION_KEY][$key]);
}
}
}
$this->trigger(self::EVENT_AFTER_REMOVE_PRODUCT);
} | php | public function removeItem(int $productId, int $combinationId = null)
{
if (!\Yii::$app->user->isGuest) {
$order = Order::find()->where([
'user_id' => \Yii::$app->user->id,
'status' => OrderStatus::STATUS_INCOMPLETE
])->one();
if (!empty($order)) {
$orderProduct = OrderProduct::find()->where([
'product_id' => $productId,
'combination_id' => $combinationId,
'order_id' => $order->id
])->one();
if (!empty($orderProduct)) {
$orderProduct->delete();
}
}
} else {
$session = Yii::$app->session;
if ($session->has(self::SESSION_KEY)) {
$products = $session[self::SESSION_KEY];
foreach ($products as $key => $product) {
if ($product['id'] == $productId && $product['combinationId'] == $combinationId)
unset($_SESSION[self::SESSION_KEY][$key]);
}
}
}
$this->trigger(self::EVENT_AFTER_REMOVE_PRODUCT);
} | [
"public",
"function",
"removeItem",
"(",
"int",
"$",
"productId",
",",
"int",
"$",
"combinationId",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"isGuest",
")",
"{",
"$",
"order",
"=",
"Order",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'user_id'",
"=>",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"id",
",",
"'status'",
"=>",
"OrderStatus",
"::",
"STATUS_INCOMPLETE",
"]",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"order",
")",
")",
"{",
"$",
"orderProduct",
"=",
"OrderProduct",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'product_id'",
"=>",
"$",
"productId",
",",
"'combination_id'",
"=>",
"$",
"combinationId",
",",
"'order_id'",
"=>",
"$",
"order",
"->",
"id",
"]",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"orderProduct",
")",
")",
"{",
"$",
"orderProduct",
"->",
"delete",
"(",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"session",
"=",
"Yii",
"::",
"$",
"app",
"->",
"session",
";",
"if",
"(",
"$",
"session",
"->",
"has",
"(",
"self",
"::",
"SESSION_KEY",
")",
")",
"{",
"$",
"products",
"=",
"$",
"session",
"[",
"self",
"::",
"SESSION_KEY",
"]",
";",
"foreach",
"(",
"$",
"products",
"as",
"$",
"key",
"=>",
"$",
"product",
")",
"{",
"if",
"(",
"$",
"product",
"[",
"'id'",
"]",
"==",
"$",
"productId",
"&&",
"$",
"product",
"[",
"'combinationId'",
"]",
"==",
"$",
"combinationId",
")",
"unset",
"(",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_KEY",
"]",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"trigger",
"(",
"self",
"::",
"EVENT_AFTER_REMOVE_PRODUCT",
")",
";",
"}"
] | Removes item from order.
@param $productId integer
@param $combinationId integer | [
"Removes",
"item",
"from",
"order",
"."
] | 314796eecae3ca4ed5fecfdc0231a738af50eba7 | https://github.com/black-lamp/blcms-cart/blob/314796eecae3ca4ed5fecfdc0231a738af50eba7/CartComponent.php#L485-L513 | train |
black-lamp/blcms-cart | CartComponent.php | CartComponent.getIncompleteOrder | public function getIncompleteOrder()
{
if (!\Yii::$app->user->isGuest) {
$user = User::findOne(\Yii::$app->user->id);
$order = Order::find()
->where(['user_id' => $user->id, 'status' => OrderStatus::STATUS_INCOMPLETE])
->one();
if (!empty($order)) {
return $order;
}
}
return null;
} | php | public function getIncompleteOrder()
{
if (!\Yii::$app->user->isGuest) {
$user = User::findOne(\Yii::$app->user->id);
$order = Order::find()
->where(['user_id' => $user->id, 'status' => OrderStatus::STATUS_INCOMPLETE])
->one();
if (!empty($order)) {
return $order;
}
}
return null;
} | [
"public",
"function",
"getIncompleteOrder",
"(",
")",
"{",
"if",
"(",
"!",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"isGuest",
")",
"{",
"$",
"user",
"=",
"User",
"::",
"findOne",
"(",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"id",
")",
";",
"$",
"order",
"=",
"Order",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'user_id'",
"=>",
"$",
"user",
"->",
"id",
",",
"'status'",
"=>",
"OrderStatus",
"::",
"STATUS_INCOMPLETE",
"]",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"order",
")",
")",
"{",
"return",
"$",
"order",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Gets registered user's incomplete order
@return array|Order|null | [
"Gets",
"registered",
"user",
"s",
"incomplete",
"order"
] | 314796eecae3ca4ed5fecfdc0231a738af50eba7 | https://github.com/black-lamp/blcms-cart/blob/314796eecae3ca4ed5fecfdc0231a738af50eba7/CartComponent.php#L519-L531 | train |
black-lamp/blcms-cart | CartComponent.php | CartComponent.clearCart | public function clearCart()
{
if (!\Yii::$app->user->isGuest && $this->saveToDataBase === true) {
$order = Order::find()->where(['user_id' => \Yii::$app->user->id, 'status' => OrderStatus::STATUS_INCOMPLETE])->one();
if (!empty($order))
$order->delete();
} else {
$session = \Yii::$app->session;
$session->remove(self::SESSION_KEY);
}
$this->trigger(self::EVENT_AFTER_CLEAR);
} | php | public function clearCart()
{
if (!\Yii::$app->user->isGuest && $this->saveToDataBase === true) {
$order = Order::find()->where(['user_id' => \Yii::$app->user->id, 'status' => OrderStatus::STATUS_INCOMPLETE])->one();
if (!empty($order))
$order->delete();
} else {
$session = \Yii::$app->session;
$session->remove(self::SESSION_KEY);
}
$this->trigger(self::EVENT_AFTER_CLEAR);
} | [
"public",
"function",
"clearCart",
"(",
")",
"{",
"if",
"(",
"!",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"isGuest",
"&&",
"$",
"this",
"->",
"saveToDataBase",
"===",
"true",
")",
"{",
"$",
"order",
"=",
"Order",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'user_id'",
"=>",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"id",
",",
"'status'",
"=>",
"OrderStatus",
"::",
"STATUS_INCOMPLETE",
"]",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"order",
")",
")",
"$",
"order",
"->",
"delete",
"(",
")",
";",
"}",
"else",
"{",
"$",
"session",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"session",
";",
"$",
"session",
"->",
"remove",
"(",
"self",
"::",
"SESSION_KEY",
")",
";",
"}",
"$",
"this",
"->",
"trigger",
"(",
"self",
"::",
"EVENT_AFTER_CLEAR",
")",
";",
"}"
] | Clears cart. | [
"Clears",
"cart",
"."
] | 314796eecae3ca4ed5fecfdc0231a738af50eba7 | https://github.com/black-lamp/blcms-cart/blob/314796eecae3ca4ed5fecfdc0231a738af50eba7/CartComponent.php#L700-L711 | train |
black-lamp/blcms-cart | CartComponent.php | CartComponent.getCost | public function getCost() {
$totalCost = 0;
if (Yii::$app->user->isGuest) {
//Gets products from session
$session = Yii::$app->session;
$products = $session[self::SESSION_KEY];
if (!empty($products)) {
foreach ($products as $product) {
if (!empty($product['combinationId'])) {
$combination = Combination::findOne($product['combinationId']);
if (!empty($combination)) $totalCost += $combination->price->discountPriceFloor * $product['count'];
} else {
$productFromDb = Product::findOne($product['id']);
if (!empty($productFromDb))
$totalCost += $productFromDb->price->discountPriceFloor * $product['count'];
}
if (!empty($product['additionalProducts'])) {
foreach ($product['additionalProducts'] as $additionalProduct) {
if ((int)$additionalProduct['productId']) {
$product = Product::findOne($additionalProduct['productId']);
if (!empty($product)) {
$totalCost += $product->price->discountPriceFloor * $additionalProduct['number'];
}
}
}
}
}
}
} else {
//Gets products from incomplete order in DB
$order = Order::find()
->where(['user_id' => Yii::$app->user->id, 'status' => OrderStatus::STATUS_INCOMPLETE])
->one();
if (!empty($order)) {
$orderProducts = OrderProduct::find()->where(['order_id' => $order->id])->all();
if (!empty($orderProducts)) {
foreach ($orderProducts as $product) {
if (\Yii::$app->getModule('shop')->enableCombinations && !empty($product->combination)) {
$totalCost += $product->count * $product->combination->price->discountPriceFloor;
} else {
$totalCost += $product->count * $product->product->price->discountPriceFloor;
}
if (!empty($product->orderProductAdditionalProducts)) {
foreach ($product->orderProductAdditionalProducts as $orderProductAdditionalProduct) {
$totalCost += $orderProductAdditionalProduct->additionalProduct->price->discountPriceFloor *
$orderProductAdditionalProduct->number;
}
}
}
}
}
}
return $totalCost;
} | php | public function getCost() {
$totalCost = 0;
if (Yii::$app->user->isGuest) {
//Gets products from session
$session = Yii::$app->session;
$products = $session[self::SESSION_KEY];
if (!empty($products)) {
foreach ($products as $product) {
if (!empty($product['combinationId'])) {
$combination = Combination::findOne($product['combinationId']);
if (!empty($combination)) $totalCost += $combination->price->discountPriceFloor * $product['count'];
} else {
$productFromDb = Product::findOne($product['id']);
if (!empty($productFromDb))
$totalCost += $productFromDb->price->discountPriceFloor * $product['count'];
}
if (!empty($product['additionalProducts'])) {
foreach ($product['additionalProducts'] as $additionalProduct) {
if ((int)$additionalProduct['productId']) {
$product = Product::findOne($additionalProduct['productId']);
if (!empty($product)) {
$totalCost += $product->price->discountPriceFloor * $additionalProduct['number'];
}
}
}
}
}
}
} else {
//Gets products from incomplete order in DB
$order = Order::find()
->where(['user_id' => Yii::$app->user->id, 'status' => OrderStatus::STATUS_INCOMPLETE])
->one();
if (!empty($order)) {
$orderProducts = OrderProduct::find()->where(['order_id' => $order->id])->all();
if (!empty($orderProducts)) {
foreach ($orderProducts as $product) {
if (\Yii::$app->getModule('shop')->enableCombinations && !empty($product->combination)) {
$totalCost += $product->count * $product->combination->price->discountPriceFloor;
} else {
$totalCost += $product->count * $product->product->price->discountPriceFloor;
}
if (!empty($product->orderProductAdditionalProducts)) {
foreach ($product->orderProductAdditionalProducts as $orderProductAdditionalProduct) {
$totalCost += $orderProductAdditionalProduct->additionalProduct->price->discountPriceFloor *
$orderProductAdditionalProduct->number;
}
}
}
}
}
}
return $totalCost;
} | [
"public",
"function",
"getCost",
"(",
")",
"{",
"$",
"totalCost",
"=",
"0",
";",
"if",
"(",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"isGuest",
")",
"{",
"//Gets products from session",
"$",
"session",
"=",
"Yii",
"::",
"$",
"app",
"->",
"session",
";",
"$",
"products",
"=",
"$",
"session",
"[",
"self",
"::",
"SESSION_KEY",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"products",
")",
")",
"{",
"foreach",
"(",
"$",
"products",
"as",
"$",
"product",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"product",
"[",
"'combinationId'",
"]",
")",
")",
"{",
"$",
"combination",
"=",
"Combination",
"::",
"findOne",
"(",
"$",
"product",
"[",
"'combinationId'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"combination",
")",
")",
"$",
"totalCost",
"+=",
"$",
"combination",
"->",
"price",
"->",
"discountPriceFloor",
"*",
"$",
"product",
"[",
"'count'",
"]",
";",
"}",
"else",
"{",
"$",
"productFromDb",
"=",
"Product",
"::",
"findOne",
"(",
"$",
"product",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"productFromDb",
")",
")",
"$",
"totalCost",
"+=",
"$",
"productFromDb",
"->",
"price",
"->",
"discountPriceFloor",
"*",
"$",
"product",
"[",
"'count'",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"product",
"[",
"'additionalProducts'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"product",
"[",
"'additionalProducts'",
"]",
"as",
"$",
"additionalProduct",
")",
"{",
"if",
"(",
"(",
"int",
")",
"$",
"additionalProduct",
"[",
"'productId'",
"]",
")",
"{",
"$",
"product",
"=",
"Product",
"::",
"findOne",
"(",
"$",
"additionalProduct",
"[",
"'productId'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"product",
")",
")",
"{",
"$",
"totalCost",
"+=",
"$",
"product",
"->",
"price",
"->",
"discountPriceFloor",
"*",
"$",
"additionalProduct",
"[",
"'number'",
"]",
";",
"}",
"}",
"}",
"}",
"}",
"}",
"}",
"else",
"{",
"//Gets products from incomplete order in DB",
"$",
"order",
"=",
"Order",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'user_id'",
"=>",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"id",
",",
"'status'",
"=>",
"OrderStatus",
"::",
"STATUS_INCOMPLETE",
"]",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"order",
")",
")",
"{",
"$",
"orderProducts",
"=",
"OrderProduct",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'order_id'",
"=>",
"$",
"order",
"->",
"id",
"]",
")",
"->",
"all",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"orderProducts",
")",
")",
"{",
"foreach",
"(",
"$",
"orderProducts",
"as",
"$",
"product",
")",
"{",
"if",
"(",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"getModule",
"(",
"'shop'",
")",
"->",
"enableCombinations",
"&&",
"!",
"empty",
"(",
"$",
"product",
"->",
"combination",
")",
")",
"{",
"$",
"totalCost",
"+=",
"$",
"product",
"->",
"count",
"*",
"$",
"product",
"->",
"combination",
"->",
"price",
"->",
"discountPriceFloor",
";",
"}",
"else",
"{",
"$",
"totalCost",
"+=",
"$",
"product",
"->",
"count",
"*",
"$",
"product",
"->",
"product",
"->",
"price",
"->",
"discountPriceFloor",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"product",
"->",
"orderProductAdditionalProducts",
")",
")",
"{",
"foreach",
"(",
"$",
"product",
"->",
"orderProductAdditionalProducts",
"as",
"$",
"orderProductAdditionalProduct",
")",
"{",
"$",
"totalCost",
"+=",
"$",
"orderProductAdditionalProduct",
"->",
"additionalProduct",
"->",
"price",
"->",
"discountPriceFloor",
"*",
"$",
"orderProductAdditionalProduct",
"->",
"number",
";",
"}",
"}",
"}",
"}",
"}",
"}",
"return",
"$",
"totalCost",
";",
"}"
] | Gets cost of user's incomplete order without discounts
@return mixed | [
"Gets",
"cost",
"of",
"user",
"s",
"incomplete",
"order",
"without",
"discounts"
] | 314796eecae3ca4ed5fecfdc0231a738af50eba7 | https://github.com/black-lamp/blcms-cart/blob/314796eecae3ca4ed5fecfdc0231a738af50eba7/CartComponent.php#L763-L819 | train |
black-lamp/blcms-cart | CartComponent.php | CartComponent.getTotalCost | public function getTotalCost() {
$totalCost = $this->getCost();
$adjustmentTotal = 0;
foreach ($this->adjustments as $adjustment) {
$adjustmentObject = Yii::createObject($adjustment);
if($adjustmentObject instanceof CartSumAdjustment) {
$adjustmentTotal += $adjustmentObject->countAdjustment($totalCost);
}
}
return $totalCost + $adjustmentTotal;
} | php | public function getTotalCost() {
$totalCost = $this->getCost();
$adjustmentTotal = 0;
foreach ($this->adjustments as $adjustment) {
$adjustmentObject = Yii::createObject($adjustment);
if($adjustmentObject instanceof CartSumAdjustment) {
$adjustmentTotal += $adjustmentObject->countAdjustment($totalCost);
}
}
return $totalCost + $adjustmentTotal;
} | [
"public",
"function",
"getTotalCost",
"(",
")",
"{",
"$",
"totalCost",
"=",
"$",
"this",
"->",
"getCost",
"(",
")",
";",
"$",
"adjustmentTotal",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"adjustments",
"as",
"$",
"adjustment",
")",
"{",
"$",
"adjustmentObject",
"=",
"Yii",
"::",
"createObject",
"(",
"$",
"adjustment",
")",
";",
"if",
"(",
"$",
"adjustmentObject",
"instanceof",
"CartSumAdjustment",
")",
"{",
"$",
"adjustmentTotal",
"+=",
"$",
"adjustmentObject",
"->",
"countAdjustment",
"(",
"$",
"totalCost",
")",
";",
"}",
"}",
"return",
"$",
"totalCost",
"+",
"$",
"adjustmentTotal",
";",
"}"
] | Gets total cost of user's incomplete order from session if user is guest
or from DB if user is authenticated
@return mixed | [
"Gets",
"total",
"cost",
"of",
"user",
"s",
"incomplete",
"order",
"from",
"session",
"if",
"user",
"is",
"guest",
"or",
"from",
"DB",
"if",
"user",
"is",
"authenticated"
] | 314796eecae3ca4ed5fecfdc0231a738af50eba7 | https://github.com/black-lamp/blcms-cart/blob/314796eecae3ca4ed5fecfdc0231a738af50eba7/CartComponent.php#L826-L838 | train |
black-lamp/blcms-cart | CartComponent.php | CartComponent.isContainsProduct | public function isContainsProduct($productId, $combinationId = null)
{
if (Yii::$app->user->isGuest) {
if (!empty(Yii::$app->session[self::SESSION_KEY])) {
$sessionProducts = Yii::$app->session[self::SESSION_KEY];
foreach ($sessionProducts as $item) {
$condition = (empty($combinationId))
? (ArrayHelper::getValue($item, 'id') == $productId)
: (ArrayHelper::getValue($item, 'id') == $productId && ArrayHelper::getValue($item, 'combinationId') == $combinationId);
if($condition) {
return $condition;
}
}
}
} else {
/** @var Order $order */
$order = Order::find()
->where(['user_id' => Yii::$app->user->id, 'status' => OrderStatus::STATUS_INCOMPLETE])
->one();
if (!empty($order)) {
$condition = (empty($combinationId))
? ['order_id' => $order->id, 'product_id' => $productId]
: ['order_id' => $order->id, 'product_id' => $productId, 'combination_id' => $combinationId];
$product = OrderProduct::find()
->where($condition)
->one();
return (!empty($product));
}
}
return false;
} | php | public function isContainsProduct($productId, $combinationId = null)
{
if (Yii::$app->user->isGuest) {
if (!empty(Yii::$app->session[self::SESSION_KEY])) {
$sessionProducts = Yii::$app->session[self::SESSION_KEY];
foreach ($sessionProducts as $item) {
$condition = (empty($combinationId))
? (ArrayHelper::getValue($item, 'id') == $productId)
: (ArrayHelper::getValue($item, 'id') == $productId && ArrayHelper::getValue($item, 'combinationId') == $combinationId);
if($condition) {
return $condition;
}
}
}
} else {
/** @var Order $order */
$order = Order::find()
->where(['user_id' => Yii::$app->user->id, 'status' => OrderStatus::STATUS_INCOMPLETE])
->one();
if (!empty($order)) {
$condition = (empty($combinationId))
? ['order_id' => $order->id, 'product_id' => $productId]
: ['order_id' => $order->id, 'product_id' => $productId, 'combination_id' => $combinationId];
$product = OrderProduct::find()
->where($condition)
->one();
return (!empty($product));
}
}
return false;
} | [
"public",
"function",
"isContainsProduct",
"(",
"$",
"productId",
",",
"$",
"combinationId",
"=",
"null",
")",
"{",
"if",
"(",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"isGuest",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"Yii",
"::",
"$",
"app",
"->",
"session",
"[",
"self",
"::",
"SESSION_KEY",
"]",
")",
")",
"{",
"$",
"sessionProducts",
"=",
"Yii",
"::",
"$",
"app",
"->",
"session",
"[",
"self",
"::",
"SESSION_KEY",
"]",
";",
"foreach",
"(",
"$",
"sessionProducts",
"as",
"$",
"item",
")",
"{",
"$",
"condition",
"=",
"(",
"empty",
"(",
"$",
"combinationId",
")",
")",
"?",
"(",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"item",
",",
"'id'",
")",
"==",
"$",
"productId",
")",
":",
"(",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"item",
",",
"'id'",
")",
"==",
"$",
"productId",
"&&",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"item",
",",
"'combinationId'",
")",
"==",
"$",
"combinationId",
")",
";",
"if",
"(",
"$",
"condition",
")",
"{",
"return",
"$",
"condition",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"/** @var Order $order */",
"$",
"order",
"=",
"Order",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'user_id'",
"=>",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"id",
",",
"'status'",
"=>",
"OrderStatus",
"::",
"STATUS_INCOMPLETE",
"]",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"order",
")",
")",
"{",
"$",
"condition",
"=",
"(",
"empty",
"(",
"$",
"combinationId",
")",
")",
"?",
"[",
"'order_id'",
"=>",
"$",
"order",
"->",
"id",
",",
"'product_id'",
"=>",
"$",
"productId",
"]",
":",
"[",
"'order_id'",
"=>",
"$",
"order",
"->",
"id",
",",
"'product_id'",
"=>",
"$",
"productId",
",",
"'combination_id'",
"=>",
"$",
"combinationId",
"]",
";",
"$",
"product",
"=",
"OrderProduct",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"$",
"condition",
")",
"->",
"one",
"(",
")",
";",
"return",
"(",
"!",
"empty",
"(",
"$",
"product",
")",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks if the cart contains the product.
@param integer $productId [[Product]] id.
@param null|integer $combinationId [[Combination]] id.
@return bool whether the cart contains the product | [
"Checks",
"if",
"the",
"cart",
"contains",
"the",
"product",
"."
] | 314796eecae3ca4ed5fecfdc0231a738af50eba7 | https://github.com/black-lamp/blcms-cart/blob/314796eecae3ca4ed5fecfdc0231a738af50eba7/CartComponent.php#L1041-L1077 | train |
Vectrex/vxPHP | src/Session/Session.php | Session.init | public static function init() {
if(is_null(self::$storage)) {
self::$storage = new NativeSessionStorage();
}
self::$storage->start();
} | php | public static function init() {
if(is_null(self::$storage)) {
self::$storage = new NativeSessionStorage();
}
self::$storage->start();
} | [
"public",
"static",
"function",
"init",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"self",
"::",
"$",
"storage",
")",
")",
"{",
"self",
"::",
"$",
"storage",
"=",
"new",
"NativeSessionStorage",
"(",
")",
";",
"}",
"self",
"::",
"$",
"storage",
"->",
"start",
"(",
")",
";",
"}"
] | initialize session storage mechanism
currently only wraps PHP native session storage | [
"initialize",
"session",
"storage",
"mechanism",
"currently",
"only",
"wraps",
"PHP",
"native",
"session",
"storage"
] | 295c21b00e7ef6085efcdf5b64fabb28d499b5a6 | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Session/Session.php#L28-L36 | train |
SteeinRu/steein-sdk-php | src/Steein/SDK/Security/Cipher.php | Cipher.decrypt | public function decrypt($input)
{
// Decode the IV + data
$input = base64_decode($input);
// Remove the IV
$iv = substr($input, 0, Cipher::IV_SIZE);
// Return Decrypted Data
return openssl_decrypt(substr($input, Cipher::IV_SIZE), "AES-256-CBC", $this->secretKey, 0, $iv);
} | php | public function decrypt($input)
{
// Decode the IV + data
$input = base64_decode($input);
// Remove the IV
$iv = substr($input, 0, Cipher::IV_SIZE);
// Return Decrypted Data
return openssl_decrypt(substr($input, Cipher::IV_SIZE), "AES-256-CBC", $this->secretKey, 0, $iv);
} | [
"public",
"function",
"decrypt",
"(",
"$",
"input",
")",
"{",
"// Decode the IV + data",
"$",
"input",
"=",
"base64_decode",
"(",
"$",
"input",
")",
";",
"// Remove the IV",
"$",
"iv",
"=",
"substr",
"(",
"$",
"input",
",",
"0",
",",
"Cipher",
"::",
"IV_SIZE",
")",
";",
"// Return Decrypted Data",
"return",
"openssl_decrypt",
"(",
"substr",
"(",
"$",
"input",
",",
"Cipher",
"::",
"IV_SIZE",
")",
",",
"\"AES-256-CBC\"",
",",
"$",
"this",
"->",
"secretKey",
",",
"0",
",",
"$",
"iv",
")",
";",
"}"
] | Decrypts the input text from the cipher key
@param $input
@return string | [
"Decrypts",
"the",
"input",
"text",
"from",
"the",
"cipher",
"key"
] | 27113624a6582d27bb55d7c9724e8306739ef167 | https://github.com/SteeinRu/steein-sdk-php/blob/27113624a6582d27bb55d7c9724e8306739ef167/src/Steein/SDK/Security/Cipher.php#L75-L83 | train |
BartoszBartniczak/ArrayOfObjects | src/ArrayObject/ArrayObject.php | ArrayObject.filter | public function filter(callable $callback): ArrayObject
{
$arrayCopy = $this->getArrayCopy();
$filteredData = array_filter($arrayCopy, $callback);
return new ArrayObject($filteredData);
} | php | public function filter(callable $callback): ArrayObject
{
$arrayCopy = $this->getArrayCopy();
$filteredData = array_filter($arrayCopy, $callback);
return new ArrayObject($filteredData);
} | [
"public",
"function",
"filter",
"(",
"callable",
"$",
"callback",
")",
":",
"ArrayObject",
"{",
"$",
"arrayCopy",
"=",
"$",
"this",
"->",
"getArrayCopy",
"(",
")",
";",
"$",
"filteredData",
"=",
"array_filter",
"(",
"$",
"arrayCopy",
",",
"$",
"callback",
")",
";",
"return",
"new",
"ArrayObject",
"(",
"$",
"filteredData",
")",
";",
"}"
] | Iterates over each value in the array passing them to the callback function.
If the callback function returns true, the current value from array is returned into the result ArrayObject. Array keys are preserved.
@param callable $callback
@return ArrayObject | [
"Iterates",
"over",
"each",
"value",
"in",
"the",
"array",
"passing",
"them",
"to",
"the",
"callback",
"function",
".",
"If",
"the",
"callback",
"function",
"returns",
"true",
"the",
"current",
"value",
"from",
"array",
"is",
"returned",
"into",
"the",
"result",
"ArrayObject",
".",
"Array",
"keys",
"are",
"preserved",
"."
] | 8758d3230d876c7d18d6753fd28ac8ef6de301c4 | https://github.com/BartoszBartniczak/ArrayOfObjects/blob/8758d3230d876c7d18d6753fd28ac8ef6de301c4/src/ArrayObject/ArrayObject.php#L65-L70 | train |
BartoszBartniczak/ArrayOfObjects | src/ArrayObject/ArrayObject.php | ArrayObject.first | public function first()
{
$this->throwExceptionIfEmpty();
$keys = $this->keys();
$keyOfTheFirstElement = $keys->shift();
return $this->offsetGet($keyOfTheFirstElement);
} | php | public function first()
{
$this->throwExceptionIfEmpty();
$keys = $this->keys();
$keyOfTheFirstElement = $keys->shift();
return $this->offsetGet($keyOfTheFirstElement);
} | [
"public",
"function",
"first",
"(",
")",
"{",
"$",
"this",
"->",
"throwExceptionIfEmpty",
"(",
")",
";",
"$",
"keys",
"=",
"$",
"this",
"->",
"keys",
"(",
")",
";",
"$",
"keyOfTheFirstElement",
"=",
"$",
"keys",
"->",
"shift",
"(",
")",
";",
"return",
"$",
"this",
"->",
"offsetGet",
"(",
"$",
"keyOfTheFirstElement",
")",
";",
"}"
] | Returns the first element, ignoring the type of the keys.
@return mixed | [
"Returns",
"the",
"first",
"element",
"ignoring",
"the",
"type",
"of",
"the",
"keys",
"."
] | 8758d3230d876c7d18d6753fd28ac8ef6de301c4 | https://github.com/BartoszBartniczak/ArrayOfObjects/blob/8758d3230d876c7d18d6753fd28ac8ef6de301c4/src/ArrayObject/ArrayObject.php#L87-L94 | train |
BartoszBartniczak/ArrayOfObjects | src/ArrayObject/ArrayObject.php | ArrayObject.shift | public function shift()
{
$this->throwExceptionIfEmpty();
$arrayCopy = $this->getArrayCopy();
$firstElement = array_shift($arrayCopy);
$this->exchangeArray($arrayCopy);
return $firstElement;
} | php | public function shift()
{
$this->throwExceptionIfEmpty();
$arrayCopy = $this->getArrayCopy();
$firstElement = array_shift($arrayCopy);
$this->exchangeArray($arrayCopy);
return $firstElement;
} | [
"public",
"function",
"shift",
"(",
")",
"{",
"$",
"this",
"->",
"throwExceptionIfEmpty",
"(",
")",
";",
"$",
"arrayCopy",
"=",
"$",
"this",
"->",
"getArrayCopy",
"(",
")",
";",
"$",
"firstElement",
"=",
"array_shift",
"(",
"$",
"arrayCopy",
")",
";",
"$",
"this",
"->",
"exchangeArray",
"(",
"$",
"arrayCopy",
")",
";",
"return",
"$",
"firstElement",
";",
"}"
] | Shift an element off the beginning of array
@return mixed | [
"Shift",
"an",
"element",
"off",
"the",
"beginning",
"of",
"array"
] | 8758d3230d876c7d18d6753fd28ac8ef6de301c4 | https://github.com/BartoszBartniczak/ArrayOfObjects/blob/8758d3230d876c7d18d6753fd28ac8ef6de301c4/src/ArrayObject/ArrayObject.php#L137-L145 | train |
BartoszBartniczak/ArrayOfObjects | src/ArrayObject/ArrayObject.php | ArrayObject.last | public function last()
{
$this->throwExceptionIfEmpty();
$keys = $this->keys();
$keyOfTheLastElement = $keys->pop();
return $this->offsetGet($keyOfTheLastElement);
} | php | public function last()
{
$this->throwExceptionIfEmpty();
$keys = $this->keys();
$keyOfTheLastElement = $keys->pop();
return $this->offsetGet($keyOfTheLastElement);
} | [
"public",
"function",
"last",
"(",
")",
"{",
"$",
"this",
"->",
"throwExceptionIfEmpty",
"(",
")",
";",
"$",
"keys",
"=",
"$",
"this",
"->",
"keys",
"(",
")",
";",
"$",
"keyOfTheLastElement",
"=",
"$",
"keys",
"->",
"pop",
"(",
")",
";",
"return",
"$",
"this",
"->",
"offsetGet",
"(",
"$",
"keyOfTheLastElement",
")",
";",
"}"
] | Returns the last element, ignoring the type of the keys.
@return mixed | [
"Returns",
"the",
"last",
"element",
"ignoring",
"the",
"type",
"of",
"the",
"keys",
"."
] | 8758d3230d876c7d18d6753fd28ac8ef6de301c4 | https://github.com/BartoszBartniczak/ArrayOfObjects/blob/8758d3230d876c7d18d6753fd28ac8ef6de301c4/src/ArrayObject/ArrayObject.php#L151-L158 | train |
BartoszBartniczak/ArrayOfObjects | src/ArrayObject/ArrayObject.php | ArrayObject.pop | public function pop()
{
$this->throwExceptionIfEmpty();
$arrayCopy = $this->getArrayCopy();
$lastElement = array_pop($arrayCopy);
$this->exchangeArray($arrayCopy);
return $lastElement;
} | php | public function pop()
{
$this->throwExceptionIfEmpty();
$arrayCopy = $this->getArrayCopy();
$lastElement = array_pop($arrayCopy);
$this->exchangeArray($arrayCopy);
return $lastElement;
} | [
"public",
"function",
"pop",
"(",
")",
"{",
"$",
"this",
"->",
"throwExceptionIfEmpty",
"(",
")",
";",
"$",
"arrayCopy",
"=",
"$",
"this",
"->",
"getArrayCopy",
"(",
")",
";",
"$",
"lastElement",
"=",
"array_pop",
"(",
"$",
"arrayCopy",
")",
";",
"$",
"this",
"->",
"exchangeArray",
"(",
"$",
"arrayCopy",
")",
";",
"return",
"$",
"lastElement",
";",
"}"
] | Pop the element off the end of array
@return mixed
@throws EmptyArrayException | [
"Pop",
"the",
"element",
"off",
"the",
"end",
"of",
"array"
] | 8758d3230d876c7d18d6753fd28ac8ef6de301c4 | https://github.com/BartoszBartniczak/ArrayOfObjects/blob/8758d3230d876c7d18d6753fd28ac8ef6de301c4/src/ArrayObject/ArrayObject.php#L165-L173 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/Source.php | Source.initCategories | public function initCategories($overrideExisting = true)
{
if (null !== $this->collCategories && !$overrideExisting) {
return;
}
$collectionClassName = CategoryTableMap::getTableMap()->getCollectionClassName();
$this->collCategories = new $collectionClassName;
$this->collCategories->setModel('\Attogram\SharedMedia\Orm\Category');
} | php | public function initCategories($overrideExisting = true)
{
if (null !== $this->collCategories && !$overrideExisting) {
return;
}
$collectionClassName = CategoryTableMap::getTableMap()->getCollectionClassName();
$this->collCategories = new $collectionClassName;
$this->collCategories->setModel('\Attogram\SharedMedia\Orm\Category');
} | [
"public",
"function",
"initCategories",
"(",
"$",
"overrideExisting",
"=",
"true",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"collCategories",
"&&",
"!",
"$",
"overrideExisting",
")",
"{",
"return",
";",
"}",
"$",
"collectionClassName",
"=",
"CategoryTableMap",
"::",
"getTableMap",
"(",
")",
"->",
"getCollectionClassName",
"(",
")",
";",
"$",
"this",
"->",
"collCategories",
"=",
"new",
"$",
"collectionClassName",
";",
"$",
"this",
"->",
"collCategories",
"->",
"setModel",
"(",
"'\\Attogram\\SharedMedia\\Orm\\Category'",
")",
";",
"}"
] | Initializes the collCategories collection.
By default this just sets the collCategories collection to an empty array (like clearcollCategories());
however, you may wish to override this method in your stub class to provide setting appropriate
to your application -- for example, setting the initial array to the values stored in database.
@param boolean $overrideExisting If set to true, the method call initializes
the collection even if it is not empty
@return void | [
"Initializes",
"the",
"collCategories",
"collection",
"."
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/Source.php#L1502-L1512 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/Source.php | Source.getCategories | public function getCategories(Criteria $criteria = null, ConnectionInterface $con = null)
{
$partial = $this->collCategoriesPartial && !$this->isNew();
if (null === $this->collCategories || null !== $criteria || $partial) {
if ($this->isNew() && null === $this->collCategories) {
// return empty collection
$this->initCategories();
} else {
$collCategories = ChildCategoryQuery::create(null, $criteria)
->filterBySource($this)
->find($con);
if (null !== $criteria) {
if (false !== $this->collCategoriesPartial && count($collCategories)) {
$this->initCategories(false);
foreach ($collCategories as $obj) {
if (false == $this->collCategories->contains($obj)) {
$this->collCategories->append($obj);
}
}
$this->collCategoriesPartial = true;
}
return $collCategories;
}
if ($partial && $this->collCategories) {
foreach ($this->collCategories as $obj) {
if ($obj->isNew()) {
$collCategories[] = $obj;
}
}
}
$this->collCategories = $collCategories;
$this->collCategoriesPartial = false;
}
}
return $this->collCategories;
} | php | public function getCategories(Criteria $criteria = null, ConnectionInterface $con = null)
{
$partial = $this->collCategoriesPartial && !$this->isNew();
if (null === $this->collCategories || null !== $criteria || $partial) {
if ($this->isNew() && null === $this->collCategories) {
// return empty collection
$this->initCategories();
} else {
$collCategories = ChildCategoryQuery::create(null, $criteria)
->filterBySource($this)
->find($con);
if (null !== $criteria) {
if (false !== $this->collCategoriesPartial && count($collCategories)) {
$this->initCategories(false);
foreach ($collCategories as $obj) {
if (false == $this->collCategories->contains($obj)) {
$this->collCategories->append($obj);
}
}
$this->collCategoriesPartial = true;
}
return $collCategories;
}
if ($partial && $this->collCategories) {
foreach ($this->collCategories as $obj) {
if ($obj->isNew()) {
$collCategories[] = $obj;
}
}
}
$this->collCategories = $collCategories;
$this->collCategoriesPartial = false;
}
}
return $this->collCategories;
} | [
"public",
"function",
"getCategories",
"(",
"Criteria",
"$",
"criteria",
"=",
"null",
",",
"ConnectionInterface",
"$",
"con",
"=",
"null",
")",
"{",
"$",
"partial",
"=",
"$",
"this",
"->",
"collCategoriesPartial",
"&&",
"!",
"$",
"this",
"->",
"isNew",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"collCategories",
"||",
"null",
"!==",
"$",
"criteria",
"||",
"$",
"partial",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isNew",
"(",
")",
"&&",
"null",
"===",
"$",
"this",
"->",
"collCategories",
")",
"{",
"// return empty collection",
"$",
"this",
"->",
"initCategories",
"(",
")",
";",
"}",
"else",
"{",
"$",
"collCategories",
"=",
"ChildCategoryQuery",
"::",
"create",
"(",
"null",
",",
"$",
"criteria",
")",
"->",
"filterBySource",
"(",
"$",
"this",
")",
"->",
"find",
"(",
"$",
"con",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"criteria",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"collCategoriesPartial",
"&&",
"count",
"(",
"$",
"collCategories",
")",
")",
"{",
"$",
"this",
"->",
"initCategories",
"(",
"false",
")",
";",
"foreach",
"(",
"$",
"collCategories",
"as",
"$",
"obj",
")",
"{",
"if",
"(",
"false",
"==",
"$",
"this",
"->",
"collCategories",
"->",
"contains",
"(",
"$",
"obj",
")",
")",
"{",
"$",
"this",
"->",
"collCategories",
"->",
"append",
"(",
"$",
"obj",
")",
";",
"}",
"}",
"$",
"this",
"->",
"collCategoriesPartial",
"=",
"true",
";",
"}",
"return",
"$",
"collCategories",
";",
"}",
"if",
"(",
"$",
"partial",
"&&",
"$",
"this",
"->",
"collCategories",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"collCategories",
"as",
"$",
"obj",
")",
"{",
"if",
"(",
"$",
"obj",
"->",
"isNew",
"(",
")",
")",
"{",
"$",
"collCategories",
"[",
"]",
"=",
"$",
"obj",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"collCategories",
"=",
"$",
"collCategories",
";",
"$",
"this",
"->",
"collCategoriesPartial",
"=",
"false",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"collCategories",
";",
"}"
] | Gets an array of ChildCategory objects which contain a foreign key that references this object.
If the $criteria is not null, it is used to always fetch the results from the database.
Otherwise the results are fetched from the database the first time, then cached.
Next time the same method is called without $criteria, the cached collection is returned.
If this ChildSource is new, it will return
an empty collection or the current collection; the criteria is ignored on a new object.
@param Criteria $criteria optional Criteria object to narrow the query
@param ConnectionInterface $con optional connection object
@return ObjectCollection|ChildCategory[] List of ChildCategory objects
@throws PropelException | [
"Gets",
"an",
"array",
"of",
"ChildCategory",
"objects",
"which",
"contain",
"a",
"foreign",
"key",
"that",
"references",
"this",
"object",
"."
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/Source.php#L1528-L1570 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/Source.php | Source.countCategories | public function countCategories(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
{
$partial = $this->collCategoriesPartial && !$this->isNew();
if (null === $this->collCategories || null !== $criteria || $partial) {
if ($this->isNew() && null === $this->collCategories) {
return 0;
}
if ($partial && !$criteria) {
return count($this->getCategories());
}
$query = ChildCategoryQuery::create(null, $criteria);
if ($distinct) {
$query->distinct();
}
return $query
->filterBySource($this)
->count($con);
}
return count($this->collCategories);
} | php | public function countCategories(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
{
$partial = $this->collCategoriesPartial && !$this->isNew();
if (null === $this->collCategories || null !== $criteria || $partial) {
if ($this->isNew() && null === $this->collCategories) {
return 0;
}
if ($partial && !$criteria) {
return count($this->getCategories());
}
$query = ChildCategoryQuery::create(null, $criteria);
if ($distinct) {
$query->distinct();
}
return $query
->filterBySource($this)
->count($con);
}
return count($this->collCategories);
} | [
"public",
"function",
"countCategories",
"(",
"Criteria",
"$",
"criteria",
"=",
"null",
",",
"$",
"distinct",
"=",
"false",
",",
"ConnectionInterface",
"$",
"con",
"=",
"null",
")",
"{",
"$",
"partial",
"=",
"$",
"this",
"->",
"collCategoriesPartial",
"&&",
"!",
"$",
"this",
"->",
"isNew",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"collCategories",
"||",
"null",
"!==",
"$",
"criteria",
"||",
"$",
"partial",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isNew",
"(",
")",
"&&",
"null",
"===",
"$",
"this",
"->",
"collCategories",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"$",
"partial",
"&&",
"!",
"$",
"criteria",
")",
"{",
"return",
"count",
"(",
"$",
"this",
"->",
"getCategories",
"(",
")",
")",
";",
"}",
"$",
"query",
"=",
"ChildCategoryQuery",
"::",
"create",
"(",
"null",
",",
"$",
"criteria",
")",
";",
"if",
"(",
"$",
"distinct",
")",
"{",
"$",
"query",
"->",
"distinct",
"(",
")",
";",
"}",
"return",
"$",
"query",
"->",
"filterBySource",
"(",
"$",
"this",
")",
"->",
"count",
"(",
"$",
"con",
")",
";",
"}",
"return",
"count",
"(",
"$",
"this",
"->",
"collCategories",
")",
";",
"}"
] | Returns the number of related Category objects.
@param Criteria $criteria
@param boolean $distinct
@param ConnectionInterface $con
@return int Count of related Category objects.
@throws PropelException | [
"Returns",
"the",
"number",
"of",
"related",
"Category",
"objects",
"."
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/Source.php#L1614-L1637 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/Source.php | Source.addCategory | public function addCategory(ChildCategory $l)
{
if ($this->collCategories === null) {
$this->initCategories();
$this->collCategoriesPartial = true;
}
if (!$this->collCategories->contains($l)) {
$this->doAddCategory($l);
if ($this->categoriesScheduledForDeletion and $this->categoriesScheduledForDeletion->contains($l)) {
$this->categoriesScheduledForDeletion->remove($this->categoriesScheduledForDeletion->search($l));
}
}
return $this;
} | php | public function addCategory(ChildCategory $l)
{
if ($this->collCategories === null) {
$this->initCategories();
$this->collCategoriesPartial = true;
}
if (!$this->collCategories->contains($l)) {
$this->doAddCategory($l);
if ($this->categoriesScheduledForDeletion and $this->categoriesScheduledForDeletion->contains($l)) {
$this->categoriesScheduledForDeletion->remove($this->categoriesScheduledForDeletion->search($l));
}
}
return $this;
} | [
"public",
"function",
"addCategory",
"(",
"ChildCategory",
"$",
"l",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"collCategories",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"initCategories",
"(",
")",
";",
"$",
"this",
"->",
"collCategoriesPartial",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"collCategories",
"->",
"contains",
"(",
"$",
"l",
")",
")",
"{",
"$",
"this",
"->",
"doAddCategory",
"(",
"$",
"l",
")",
";",
"if",
"(",
"$",
"this",
"->",
"categoriesScheduledForDeletion",
"and",
"$",
"this",
"->",
"categoriesScheduledForDeletion",
"->",
"contains",
"(",
"$",
"l",
")",
")",
"{",
"$",
"this",
"->",
"categoriesScheduledForDeletion",
"->",
"remove",
"(",
"$",
"this",
"->",
"categoriesScheduledForDeletion",
"->",
"search",
"(",
"$",
"l",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Method called to associate a ChildCategory object to this object
through the ChildCategory foreign key attribute.
@param ChildCategory $l ChildCategory
@return $this|\Attogram\SharedMedia\Orm\Source The current object (for fluent API support) | [
"Method",
"called",
"to",
"associate",
"a",
"ChildCategory",
"object",
"to",
"this",
"object",
"through",
"the",
"ChildCategory",
"foreign",
"key",
"attribute",
"."
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/Source.php#L1646-L1662 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/Source.php | Source.initMedias | public function initMedias($overrideExisting = true)
{
if (null !== $this->collMedias && !$overrideExisting) {
return;
}
$collectionClassName = MediaTableMap::getTableMap()->getCollectionClassName();
$this->collMedias = new $collectionClassName;
$this->collMedias->setModel('\Attogram\SharedMedia\Orm\Media');
} | php | public function initMedias($overrideExisting = true)
{
if (null !== $this->collMedias && !$overrideExisting) {
return;
}
$collectionClassName = MediaTableMap::getTableMap()->getCollectionClassName();
$this->collMedias = new $collectionClassName;
$this->collMedias->setModel('\Attogram\SharedMedia\Orm\Media');
} | [
"public",
"function",
"initMedias",
"(",
"$",
"overrideExisting",
"=",
"true",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"collMedias",
"&&",
"!",
"$",
"overrideExisting",
")",
"{",
"return",
";",
"}",
"$",
"collectionClassName",
"=",
"MediaTableMap",
"::",
"getTableMap",
"(",
")",
"->",
"getCollectionClassName",
"(",
")",
";",
"$",
"this",
"->",
"collMedias",
"=",
"new",
"$",
"collectionClassName",
";",
"$",
"this",
"->",
"collMedias",
"->",
"setModel",
"(",
"'\\Attogram\\SharedMedia\\Orm\\Media'",
")",
";",
"}"
] | Initializes the collMedias collection.
By default this just sets the collMedias collection to an empty array (like clearcollMedias());
however, you may wish to override this method in your stub class to provide setting appropriate
to your application -- for example, setting the initial array to the values stored in database.
@param boolean $overrideExisting If set to true, the method call initializes
the collection even if it is not empty
@return void | [
"Initializes",
"the",
"collMedias",
"collection",
"."
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/Source.php#L1727-L1737 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/Source.php | Source.getMedias | public function getMedias(Criteria $criteria = null, ConnectionInterface $con = null)
{
$partial = $this->collMediasPartial && !$this->isNew();
if (null === $this->collMedias || null !== $criteria || $partial) {
if ($this->isNew() && null === $this->collMedias) {
// return empty collection
$this->initMedias();
} else {
$collMedias = ChildMediaQuery::create(null, $criteria)
->filterBySource($this)
->find($con);
if (null !== $criteria) {
if (false !== $this->collMediasPartial && count($collMedias)) {
$this->initMedias(false);
foreach ($collMedias as $obj) {
if (false == $this->collMedias->contains($obj)) {
$this->collMedias->append($obj);
}
}
$this->collMediasPartial = true;
}
return $collMedias;
}
if ($partial && $this->collMedias) {
foreach ($this->collMedias as $obj) {
if ($obj->isNew()) {
$collMedias[] = $obj;
}
}
}
$this->collMedias = $collMedias;
$this->collMediasPartial = false;
}
}
return $this->collMedias;
} | php | public function getMedias(Criteria $criteria = null, ConnectionInterface $con = null)
{
$partial = $this->collMediasPartial && !$this->isNew();
if (null === $this->collMedias || null !== $criteria || $partial) {
if ($this->isNew() && null === $this->collMedias) {
// return empty collection
$this->initMedias();
} else {
$collMedias = ChildMediaQuery::create(null, $criteria)
->filterBySource($this)
->find($con);
if (null !== $criteria) {
if (false !== $this->collMediasPartial && count($collMedias)) {
$this->initMedias(false);
foreach ($collMedias as $obj) {
if (false == $this->collMedias->contains($obj)) {
$this->collMedias->append($obj);
}
}
$this->collMediasPartial = true;
}
return $collMedias;
}
if ($partial && $this->collMedias) {
foreach ($this->collMedias as $obj) {
if ($obj->isNew()) {
$collMedias[] = $obj;
}
}
}
$this->collMedias = $collMedias;
$this->collMediasPartial = false;
}
}
return $this->collMedias;
} | [
"public",
"function",
"getMedias",
"(",
"Criteria",
"$",
"criteria",
"=",
"null",
",",
"ConnectionInterface",
"$",
"con",
"=",
"null",
")",
"{",
"$",
"partial",
"=",
"$",
"this",
"->",
"collMediasPartial",
"&&",
"!",
"$",
"this",
"->",
"isNew",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"collMedias",
"||",
"null",
"!==",
"$",
"criteria",
"||",
"$",
"partial",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isNew",
"(",
")",
"&&",
"null",
"===",
"$",
"this",
"->",
"collMedias",
")",
"{",
"// return empty collection",
"$",
"this",
"->",
"initMedias",
"(",
")",
";",
"}",
"else",
"{",
"$",
"collMedias",
"=",
"ChildMediaQuery",
"::",
"create",
"(",
"null",
",",
"$",
"criteria",
")",
"->",
"filterBySource",
"(",
"$",
"this",
")",
"->",
"find",
"(",
"$",
"con",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"criteria",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"collMediasPartial",
"&&",
"count",
"(",
"$",
"collMedias",
")",
")",
"{",
"$",
"this",
"->",
"initMedias",
"(",
"false",
")",
";",
"foreach",
"(",
"$",
"collMedias",
"as",
"$",
"obj",
")",
"{",
"if",
"(",
"false",
"==",
"$",
"this",
"->",
"collMedias",
"->",
"contains",
"(",
"$",
"obj",
")",
")",
"{",
"$",
"this",
"->",
"collMedias",
"->",
"append",
"(",
"$",
"obj",
")",
";",
"}",
"}",
"$",
"this",
"->",
"collMediasPartial",
"=",
"true",
";",
"}",
"return",
"$",
"collMedias",
";",
"}",
"if",
"(",
"$",
"partial",
"&&",
"$",
"this",
"->",
"collMedias",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"collMedias",
"as",
"$",
"obj",
")",
"{",
"if",
"(",
"$",
"obj",
"->",
"isNew",
"(",
")",
")",
"{",
"$",
"collMedias",
"[",
"]",
"=",
"$",
"obj",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"collMedias",
"=",
"$",
"collMedias",
";",
"$",
"this",
"->",
"collMediasPartial",
"=",
"false",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"collMedias",
";",
"}"
] | Gets an array of ChildMedia objects which contain a foreign key that references this object.
If the $criteria is not null, it is used to always fetch the results from the database.
Otherwise the results are fetched from the database the first time, then cached.
Next time the same method is called without $criteria, the cached collection is returned.
If this ChildSource is new, it will return
an empty collection or the current collection; the criteria is ignored on a new object.
@param Criteria $criteria optional Criteria object to narrow the query
@param ConnectionInterface $con optional connection object
@return ObjectCollection|ChildMedia[] List of ChildMedia objects
@throws PropelException | [
"Gets",
"an",
"array",
"of",
"ChildMedia",
"objects",
"which",
"contain",
"a",
"foreign",
"key",
"that",
"references",
"this",
"object",
"."
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/Source.php#L1753-L1795 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/Source.php | Source.countMedias | public function countMedias(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
{
$partial = $this->collMediasPartial && !$this->isNew();
if (null === $this->collMedias || null !== $criteria || $partial) {
if ($this->isNew() && null === $this->collMedias) {
return 0;
}
if ($partial && !$criteria) {
return count($this->getMedias());
}
$query = ChildMediaQuery::create(null, $criteria);
if ($distinct) {
$query->distinct();
}
return $query
->filterBySource($this)
->count($con);
}
return count($this->collMedias);
} | php | public function countMedias(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
{
$partial = $this->collMediasPartial && !$this->isNew();
if (null === $this->collMedias || null !== $criteria || $partial) {
if ($this->isNew() && null === $this->collMedias) {
return 0;
}
if ($partial && !$criteria) {
return count($this->getMedias());
}
$query = ChildMediaQuery::create(null, $criteria);
if ($distinct) {
$query->distinct();
}
return $query
->filterBySource($this)
->count($con);
}
return count($this->collMedias);
} | [
"public",
"function",
"countMedias",
"(",
"Criteria",
"$",
"criteria",
"=",
"null",
",",
"$",
"distinct",
"=",
"false",
",",
"ConnectionInterface",
"$",
"con",
"=",
"null",
")",
"{",
"$",
"partial",
"=",
"$",
"this",
"->",
"collMediasPartial",
"&&",
"!",
"$",
"this",
"->",
"isNew",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"collMedias",
"||",
"null",
"!==",
"$",
"criteria",
"||",
"$",
"partial",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isNew",
"(",
")",
"&&",
"null",
"===",
"$",
"this",
"->",
"collMedias",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"$",
"partial",
"&&",
"!",
"$",
"criteria",
")",
"{",
"return",
"count",
"(",
"$",
"this",
"->",
"getMedias",
"(",
")",
")",
";",
"}",
"$",
"query",
"=",
"ChildMediaQuery",
"::",
"create",
"(",
"null",
",",
"$",
"criteria",
")",
";",
"if",
"(",
"$",
"distinct",
")",
"{",
"$",
"query",
"->",
"distinct",
"(",
")",
";",
"}",
"return",
"$",
"query",
"->",
"filterBySource",
"(",
"$",
"this",
")",
"->",
"count",
"(",
"$",
"con",
")",
";",
"}",
"return",
"count",
"(",
"$",
"this",
"->",
"collMedias",
")",
";",
"}"
] | Returns the number of related Media objects.
@param Criteria $criteria
@param boolean $distinct
@param ConnectionInterface $con
@return int Count of related Media objects.
@throws PropelException | [
"Returns",
"the",
"number",
"of",
"related",
"Media",
"objects",
"."
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/Source.php#L1839-L1862 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/Source.php | Source.addMedia | public function addMedia(ChildMedia $l)
{
if ($this->collMedias === null) {
$this->initMedias();
$this->collMediasPartial = true;
}
if (!$this->collMedias->contains($l)) {
$this->doAddMedia($l);
if ($this->mediasScheduledForDeletion and $this->mediasScheduledForDeletion->contains($l)) {
$this->mediasScheduledForDeletion->remove($this->mediasScheduledForDeletion->search($l));
}
}
return $this;
} | php | public function addMedia(ChildMedia $l)
{
if ($this->collMedias === null) {
$this->initMedias();
$this->collMediasPartial = true;
}
if (!$this->collMedias->contains($l)) {
$this->doAddMedia($l);
if ($this->mediasScheduledForDeletion and $this->mediasScheduledForDeletion->contains($l)) {
$this->mediasScheduledForDeletion->remove($this->mediasScheduledForDeletion->search($l));
}
}
return $this;
} | [
"public",
"function",
"addMedia",
"(",
"ChildMedia",
"$",
"l",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"collMedias",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"initMedias",
"(",
")",
";",
"$",
"this",
"->",
"collMediasPartial",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"collMedias",
"->",
"contains",
"(",
"$",
"l",
")",
")",
"{",
"$",
"this",
"->",
"doAddMedia",
"(",
"$",
"l",
")",
";",
"if",
"(",
"$",
"this",
"->",
"mediasScheduledForDeletion",
"and",
"$",
"this",
"->",
"mediasScheduledForDeletion",
"->",
"contains",
"(",
"$",
"l",
")",
")",
"{",
"$",
"this",
"->",
"mediasScheduledForDeletion",
"->",
"remove",
"(",
"$",
"this",
"->",
"mediasScheduledForDeletion",
"->",
"search",
"(",
"$",
"l",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Method called to associate a ChildMedia object to this object
through the ChildMedia foreign key attribute.
@param ChildMedia $l ChildMedia
@return $this|\Attogram\SharedMedia\Orm\Source The current object (for fluent API support) | [
"Method",
"called",
"to",
"associate",
"a",
"ChildMedia",
"object",
"to",
"this",
"object",
"through",
"the",
"ChildMedia",
"foreign",
"key",
"attribute",
"."
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/Source.php#L1871-L1887 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.