id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
230,000
Webiny/Framework
src/Webiny/Component/Security/Authorization/AccessControl.php
AccessControl.getVoters
private function getVoters() { // we have 2 built in voters $voters = $this->servicesByTag('Security.Voter', VoterInterface::class); $voters[] = new AuthenticationVoter(); $voters[] = new RoleVoter(); return $voters; }
php
private function getVoters() { // we have 2 built in voters $voters = $this->servicesByTag('Security.Voter', VoterInterface::class); $voters[] = new AuthenticationVoter(); $voters[] = new RoleVoter(); return $voters; }
[ "private", "function", "getVoters", "(", ")", "{", "// we have 2 built in voters", "$", "voters", "=", "$", "this", "->", "servicesByTag", "(", "'Security.Voter'", ",", "VoterInterface", "::", "class", ")", ";", "$", "voters", "[", "]", "=", "new", "AuthenticationVoter", "(", ")", ";", "$", "voters", "[", "]", "=", "new", "RoleVoter", "(", ")", ";", "return", "$", "voters", ";", "}" ]
Creates an array of registered Voters. @return array Array of registered voters.
[ "Creates", "an", "array", "of", "registered", "Voters", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Security/Authorization/AccessControl.php#L93-L101
230,001
Webiny/Framework
src/Webiny/Component/Security/Authorization/AccessControl.php
AccessControl.getRequestedRoles
private function getRequestedRoles() { $rules = $this->config->get('Rules', false); if (!$rules) { return []; } // see which of the rules matches the path and extract the requested roles for access $returnRoles = []; foreach ($rules as $r) { $path = $r->get('Path', false); if ($path && $this->testPath($path)) { $roles = $r->get('Roles', []); if ($this->isString($roles)) { $roles = (array)$roles; } else { $roles = $roles->toArray(); } // covert the role names to Role instances foreach ($roles as $role) { $returnRoles[] = new Role($role); } return $returnRoles; } } return []; }
php
private function getRequestedRoles() { $rules = $this->config->get('Rules', false); if (!$rules) { return []; } // see which of the rules matches the path and extract the requested roles for access $returnRoles = []; foreach ($rules as $r) { $path = $r->get('Path', false); if ($path && $this->testPath($path)) { $roles = $r->get('Roles', []); if ($this->isString($roles)) { $roles = (array)$roles; } else { $roles = $roles->toArray(); } // covert the role names to Role instances foreach ($roles as $role) { $returnRoles[] = new Role($role); } return $returnRoles; } } return []; }
[ "private", "function", "getRequestedRoles", "(", ")", "{", "$", "rules", "=", "$", "this", "->", "config", "->", "get", "(", "'Rules'", ",", "false", ")", ";", "if", "(", "!", "$", "rules", ")", "{", "return", "[", "]", ";", "}", "// see which of the rules matches the path and extract the requested roles for access", "$", "returnRoles", "=", "[", "]", ";", "foreach", "(", "$", "rules", "as", "$", "r", ")", "{", "$", "path", "=", "$", "r", "->", "get", "(", "'Path'", ",", "false", ")", ";", "if", "(", "$", "path", "&&", "$", "this", "->", "testPath", "(", "$", "path", ")", ")", "{", "$", "roles", "=", "$", "r", "->", "get", "(", "'Roles'", ",", "[", "]", ")", ";", "if", "(", "$", "this", "->", "isString", "(", "$", "roles", ")", ")", "{", "$", "roles", "=", "(", "array", ")", "$", "roles", ";", "}", "else", "{", "$", "roles", "=", "$", "roles", "->", "toArray", "(", ")", ";", "}", "// covert the role names to Role instances", "foreach", "(", "$", "roles", "as", "$", "role", ")", "{", "$", "returnRoles", "[", "]", "=", "new", "Role", "(", "$", "role", ")", ";", "}", "return", "$", "returnRoles", ";", "}", "}", "return", "[", "]", ";", "}" ]
Returns an array of roles required by the access rule. @return array
[ "Returns", "an", "array", "of", "roles", "required", "by", "the", "access", "rule", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Security/Authorization/AccessControl.php#L108-L137
230,002
Webiny/Framework
src/Webiny/Component/Security/Authorization/AccessControl.php
AccessControl.setDecisionStrategy
private function setDecisionStrategy() { $strategy = $this->config->get('DecisionStrategy', 'unanimous'); if ($strategy != self::VOTER_STR_AFFIRMATIVE && $strategy != self::VOTER_STR_CONSENSUS && $strategy != self::VOTER_STR_UNANIMOUS ) { throw new AccessControlException('Invalid access control decision strategy "' . $strategy . '"'); } $this->strategy = $strategy; }
php
private function setDecisionStrategy() { $strategy = $this->config->get('DecisionStrategy', 'unanimous'); if ($strategy != self::VOTER_STR_AFFIRMATIVE && $strategy != self::VOTER_STR_CONSENSUS && $strategy != self::VOTER_STR_UNANIMOUS ) { throw new AccessControlException('Invalid access control decision strategy "' . $strategy . '"'); } $this->strategy = $strategy; }
[ "private", "function", "setDecisionStrategy", "(", ")", "{", "$", "strategy", "=", "$", "this", "->", "config", "->", "get", "(", "'DecisionStrategy'", ",", "'unanimous'", ")", ";", "if", "(", "$", "strategy", "!=", "self", "::", "VOTER_STR_AFFIRMATIVE", "&&", "$", "strategy", "!=", "self", "::", "VOTER_STR_CONSENSUS", "&&", "$", "strategy", "!=", "self", "::", "VOTER_STR_UNANIMOUS", ")", "{", "throw", "new", "AccessControlException", "(", "'Invalid access control decision strategy \"'", ".", "$", "strategy", ".", "'\"'", ")", ";", "}", "$", "this", "->", "strategy", "=", "$", "strategy", ";", "}" ]
Sets the decision strategy based on the application configuration. @throws AccessControlException
[ "Sets", "the", "decision", "strategy", "based", "on", "the", "application", "configuration", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Security/Authorization/AccessControl.php#L156-L166
230,003
Webiny/Framework
src/Webiny/Component/Security/Authorization/AccessControl.php
AccessControl.getAccessDecision
private function getAccessDecision(array $requestedRoles) { $voters = $this->getVoters(); $userClassName = get_class($this->user); $voteScore = 0; $maxScore = 0; foreach ($voters as $v) { /** * @var $v VoterInterface */ if ($v->supportsUserClass($userClassName)) { $vote = $v->vote($this->user, $requestedRoles); if ($this->strategy == self::VOTER_STR_AFFIRMATIVE) { if ($vote > 0) { $maxScore++; $voteScore += $vote; } } else { if ($this->strategy == self::VOTER_STR_CONSENSUS) { if ($vote > 0) { $voteScore += $vote; } $maxScore++; } else { if ($vote <> 0) { $maxScore++; $voteScore += $vote; } } } } } return $this->whatsTheRuling($voteScore, $maxScore); }
php
private function getAccessDecision(array $requestedRoles) { $voters = $this->getVoters(); $userClassName = get_class($this->user); $voteScore = 0; $maxScore = 0; foreach ($voters as $v) { /** * @var $v VoterInterface */ if ($v->supportsUserClass($userClassName)) { $vote = $v->vote($this->user, $requestedRoles); if ($this->strategy == self::VOTER_STR_AFFIRMATIVE) { if ($vote > 0) { $maxScore++; $voteScore += $vote; } } else { if ($this->strategy == self::VOTER_STR_CONSENSUS) { if ($vote > 0) { $voteScore += $vote; } $maxScore++; } else { if ($vote <> 0) { $maxScore++; $voteScore += $vote; } } } } } return $this->whatsTheRuling($voteScore, $maxScore); }
[ "private", "function", "getAccessDecision", "(", "array", "$", "requestedRoles", ")", "{", "$", "voters", "=", "$", "this", "->", "getVoters", "(", ")", ";", "$", "userClassName", "=", "get_class", "(", "$", "this", "->", "user", ")", ";", "$", "voteScore", "=", "0", ";", "$", "maxScore", "=", "0", ";", "foreach", "(", "$", "voters", "as", "$", "v", ")", "{", "/**\n * @var $v VoterInterface\n */", "if", "(", "$", "v", "->", "supportsUserClass", "(", "$", "userClassName", ")", ")", "{", "$", "vote", "=", "$", "v", "->", "vote", "(", "$", "this", "->", "user", ",", "$", "requestedRoles", ")", ";", "if", "(", "$", "this", "->", "strategy", "==", "self", "::", "VOTER_STR_AFFIRMATIVE", ")", "{", "if", "(", "$", "vote", ">", "0", ")", "{", "$", "maxScore", "++", ";", "$", "voteScore", "+=", "$", "vote", ";", "}", "}", "else", "{", "if", "(", "$", "this", "->", "strategy", "==", "self", "::", "VOTER_STR_CONSENSUS", ")", "{", "if", "(", "$", "vote", ">", "0", ")", "{", "$", "voteScore", "+=", "$", "vote", ";", "}", "$", "maxScore", "++", ";", "}", "else", "{", "if", "(", "$", "vote", "<>", "0", ")", "{", "$", "maxScore", "++", ";", "$", "voteScore", "+=", "$", "vote", ";", "}", "}", "}", "}", "}", "return", "$", "this", "->", "whatsTheRuling", "(", "$", "voteScore", ",", "$", "maxScore", ")", ";", "}" ]
This method get the votes from all the voters and sends them to the ruling. The result of ruling is then returned. @param array $requestedRoles An array of requested roles for the current access map. @return bool True if access is allowed to the current user, otherwise false.
[ "This", "method", "get", "the", "votes", "from", "all", "the", "voters", "and", "sends", "them", "to", "the", "ruling", ".", "The", "result", "of", "ruling", "is", "then", "returned", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Security/Authorization/AccessControl.php#L176-L211
230,004
Webiny/Framework
src/Webiny/Component/Security/Authorization/AccessControl.php
AccessControl.whatsTheRuling
private function whatsTheRuling($votes, $maxVotes) { switch ($this->strategy) { case self::VOTER_STR_UNANIMOUS: return ($votes == $maxVotes); break; case self::VOTER_STR_CONSENSUS: return ($votes > ($maxVotes - $votes)); break; case self::VOTER_STR_AFFIRMATIVE: return ($votes > 0); break; } return false; }
php
private function whatsTheRuling($votes, $maxVotes) { switch ($this->strategy) { case self::VOTER_STR_UNANIMOUS: return ($votes == $maxVotes); break; case self::VOTER_STR_CONSENSUS: return ($votes > ($maxVotes - $votes)); break; case self::VOTER_STR_AFFIRMATIVE: return ($votes > 0); break; } return false; }
[ "private", "function", "whatsTheRuling", "(", "$", "votes", ",", "$", "maxVotes", ")", "{", "switch", "(", "$", "this", "->", "strategy", ")", "{", "case", "self", "::", "VOTER_STR_UNANIMOUS", ":", "return", "(", "$", "votes", "==", "$", "maxVotes", ")", ";", "break", ";", "case", "self", "::", "VOTER_STR_CONSENSUS", ":", "return", "(", "$", "votes", ">", "(", "$", "maxVotes", "-", "$", "votes", ")", ")", ";", "break", ";", "case", "self", "::", "VOTER_STR_AFFIRMATIVE", ":", "return", "(", "$", "votes", ">", "0", ")", ";", "break", ";", "}", "return", "false", ";", "}" ]
Method that decides if access is allowed or not based on the results of votes and the defined decision strategy. @param int $votes The voting score. @param int $maxVotes Max possible number of votes. @return bool True if access is allowed, otherwise false.
[ "Method", "that", "decides", "if", "access", "is", "allowed", "or", "not", "based", "on", "the", "results", "of", "votes", "and", "the", "defined", "decision", "strategy", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Security/Authorization/AccessControl.php#L221-L238
230,005
Webiny/Framework
src/Webiny/Component/TwitterOAuth/TwitterOAuthLoader.php
TwitterOAuthLoader.getInstance
public static function getInstance($key) { if (isset(self::$instances[$key])) { return self::$instances; } $config = TwitterOAuth::getConfig()->get($key, false); if (!$config) { throw new TwitterOAuthException('Unable to read "TwitterOAuth.' . $key . '" configuration.'); } if (strpos($config->RedirectUri, 'http://') !== false || strpos($config->RedirectUri, 'https://' ) !== false ) { $redirectUri = $config->RedirectUri; } else { $redirectUri = self::httpRequest()->getCurrentUrl(true)->setPath($config->RedirectUri)->setQuery('')->val(); } $instance = \Webiny\Component\TwitterOAuth\Bridge\TwitterOAuth::getInstance($config->ClientId, $config->ClientSecret, $redirectUri ); return new TwitterOAuth($instance); }
php
public static function getInstance($key) { if (isset(self::$instances[$key])) { return self::$instances; } $config = TwitterOAuth::getConfig()->get($key, false); if (!$config) { throw new TwitterOAuthException('Unable to read "TwitterOAuth.' . $key . '" configuration.'); } if (strpos($config->RedirectUri, 'http://') !== false || strpos($config->RedirectUri, 'https://' ) !== false ) { $redirectUri = $config->RedirectUri; } else { $redirectUri = self::httpRequest()->getCurrentUrl(true)->setPath($config->RedirectUri)->setQuery('')->val(); } $instance = \Webiny\Component\TwitterOAuth\Bridge\TwitterOAuth::getInstance($config->ClientId, $config->ClientSecret, $redirectUri ); return new TwitterOAuth($instance); }
[ "public", "static", "function", "getInstance", "(", "$", "key", ")", "{", "if", "(", "isset", "(", "self", "::", "$", "instances", "[", "$", "key", "]", ")", ")", "{", "return", "self", "::", "$", "instances", ";", "}", "$", "config", "=", "TwitterOAuth", "::", "getConfig", "(", ")", "->", "get", "(", "$", "key", ",", "false", ")", ";", "if", "(", "!", "$", "config", ")", "{", "throw", "new", "TwitterOAuthException", "(", "'Unable to read \"TwitterOAuth.'", ".", "$", "key", ".", "'\" configuration.'", ")", ";", "}", "if", "(", "strpos", "(", "$", "config", "->", "RedirectUri", ",", "'http://'", ")", "!==", "false", "||", "strpos", "(", "$", "config", "->", "RedirectUri", ",", "'https://'", ")", "!==", "false", ")", "{", "$", "redirectUri", "=", "$", "config", "->", "RedirectUri", ";", "}", "else", "{", "$", "redirectUri", "=", "self", "::", "httpRequest", "(", ")", "->", "getCurrentUrl", "(", "true", ")", "->", "setPath", "(", "$", "config", "->", "RedirectUri", ")", "->", "setQuery", "(", "''", ")", "->", "val", "(", ")", ";", "}", "$", "instance", "=", "\\", "Webiny", "\\", "Component", "\\", "TwitterOAuth", "\\", "Bridge", "\\", "TwitterOAuth", "::", "getInstance", "(", "$", "config", "->", "ClientId", ",", "$", "config", "->", "ClientSecret", ",", "$", "redirectUri", ")", ";", "return", "new", "TwitterOAuth", "(", "$", "instance", ")", ";", "}" ]
Returns an instance to TwitterOAuth server based on the current configuration. @param string $key Unique identifier for the TwitterOAuth server that you wish to get. @return array|TwitterOAuth @throws TwitterOAuthException
[ "Returns", "an", "instance", "to", "TwitterOAuth", "server", "based", "on", "the", "current", "configuration", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/TwitterOAuth/TwitterOAuthLoader.php#L34-L59
230,006
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/StringObject/ValidatorTrait.php
ValidatorTrait.longerThan
public function longerThan($num, $inclusive = false) { if (!$this->isNumber($num)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$num', 'integer' ] ); } if (!$this->isBoolean($inclusive)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$inclusive', 'boolean' ] ); } $length = strlen($this->val()); if ($length > $num) { return true; } else { if ($inclusive && $length >= $num) { return true; } } return false; }
php
public function longerThan($num, $inclusive = false) { if (!$this->isNumber($num)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$num', 'integer' ] ); } if (!$this->isBoolean($inclusive)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$inclusive', 'boolean' ] ); } $length = strlen($this->val()); if ($length > $num) { return true; } else { if ($inclusive && $length >= $num) { return true; } } return false; }
[ "public", "function", "longerThan", "(", "$", "num", ",", "$", "inclusive", "=", "false", ")", "{", "if", "(", "!", "$", "this", "->", "isNumber", "(", "$", "num", ")", ")", "{", "throw", "new", "StringObjectException", "(", "StringObjectException", "::", "MSG_INVALID_ARG", ",", "[", "'$num'", ",", "'integer'", "]", ")", ";", "}", "if", "(", "!", "$", "this", "->", "isBoolean", "(", "$", "inclusive", ")", ")", "{", "throw", "new", "StringObjectException", "(", "StringObjectException", "::", "MSG_INVALID_ARG", ",", "[", "'$inclusive'", ",", "'boolean'", "]", ")", ";", "}", "$", "length", "=", "strlen", "(", "$", "this", "->", "val", "(", ")", ")", ";", "if", "(", "$", "length", ">", "$", "num", ")", "{", "return", "true", ";", "}", "else", "{", "if", "(", "$", "inclusive", "&&", "$", "length", ">=", "$", "num", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks if the string length is great than the given length. @param int $num Length against which you wish to check. @param bool $inclusive Do you want the check to be inclusive or not. Default is false (not inclusive). @throws StringObjectException @return bool If current string size is longer than the given $num, true is returned, otherwise false.
[ "Checks", "if", "the", "string", "length", "is", "great", "than", "the", "given", "length", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/StringObject/ValidatorTrait.php#L169-L197
230,007
milesj/admin
Model/ActionLog.php
ActionLog.logAction
public function logAction($query) { $interval = Configure::read('Admin.logActions.interval') ?: '-6 hours'; $conditions = $query; $conditions['created >='] = date('Y-m-d H:i:s', strtotime($interval)); $count = $this->find('count', array( 'conditions' => $conditions )); if ($count) { return true; } $this->create(); return $this->save($query, false); }
php
public function logAction($query) { $interval = Configure::read('Admin.logActions.interval') ?: '-6 hours'; $conditions = $query; $conditions['created >='] = date('Y-m-d H:i:s', strtotime($interval)); $count = $this->find('count', array( 'conditions' => $conditions )); if ($count) { return true; } $this->create(); return $this->save($query, false); }
[ "public", "function", "logAction", "(", "$", "query", ")", "{", "$", "interval", "=", "Configure", "::", "read", "(", "'Admin.logActions.interval'", ")", "?", ":", "'-6 hours'", ";", "$", "conditions", "=", "$", "query", ";", "$", "conditions", "[", "'created >='", "]", "=", "date", "(", "'Y-m-d H:i:s'", ",", "strtotime", "(", "$", "interval", ")", ")", ";", "$", "count", "=", "$", "this", "->", "find", "(", "'count'", ",", "array", "(", "'conditions'", "=>", "$", "conditions", ")", ")", ";", "if", "(", "$", "count", ")", "{", "return", "true", ";", "}", "$", "this", "->", "create", "(", ")", ";", "return", "$", "this", "->", "save", "(", "$", "query", ",", "false", ")", ";", "}" ]
Log an action only once every 6 hours. @param array $query @return bool
[ "Log", "an", "action", "only", "once", "every", "6", "hours", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Model/ActionLog.php#L81-L98
230,008
Webiny/Framework
src/Webiny/Component/Http/Cookie/Storage/NativeStorage.php
NativeStorage.delete
public function delete($name) { return setcookie($name, '', (time() - 86400), '/', $this->domain, $this->https, true); }
php
public function delete($name) { return setcookie($name, '', (time() - 86400), '/', $this->domain, $this->https, true); }
[ "public", "function", "delete", "(", "$", "name", ")", "{", "return", "setcookie", "(", "$", "name", ",", "''", ",", "(", "time", "(", ")", "-", "86400", ")", ",", "'/'", ",", "$", "this", "->", "domain", ",", "$", "this", "->", "https", ",", "true", ")", ";", "}" ]
Delete the given cookie. @param string $name Name of the cookie. @return bool True if cookie was deleted, otherwise false.
[ "Delete", "the", "given", "cookie", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Http/Cookie/Storage/NativeStorage.php#L77-L80
230,009
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/DateTimeObject/DateTimeObject.php
DateTimeObject.format
public function format($format) { try { return $this->getDateObject()->format($format); } catch (\Exception $e) { throw new DateTimeObjectException(DateTimeObjectException::MSG_INVALID_DATE_FORMAT, [$format]); } }
php
public function format($format) { try { return $this->getDateObject()->format($format); } catch (\Exception $e) { throw new DateTimeObjectException(DateTimeObjectException::MSG_INVALID_DATE_FORMAT, [$format]); } }
[ "public", "function", "format", "(", "$", "format", ")", "{", "try", "{", "return", "$", "this", "->", "getDateObject", "(", ")", "->", "format", "(", "$", "format", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "DateTimeObjectException", "(", "DateTimeObjectException", "::", "MSG_INVALID_DATE_FORMAT", ",", "[", "$", "format", "]", ")", ";", "}", "}" ]
Return date in the given format. @param string $format A valid date format. @return string A string containing the date in the given $format. @throws DateTimeObjectException
[ "Return", "date", "in", "the", "given", "format", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/DateTimeObject/DateTimeObject.php#L261-L268
230,010
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/DateTimeObject/DateTimeObject.php
DateTimeObject.parseDateTimeFormat
private function parseDateTimeFormat() { try { if ($this->isNull($this->format)) { $this->format = self::$defaultFormat; } $str = new StringObject($this->format); $chunks = $str->split(); $this->buildFormatterList(); foreach ($chunks as $c) { foreach (self::$formatters as $fk => $f) { if ($f->inArray($c)) { $this->dateTimeFormat[$fk] = $c; } } } $this->dateTimeFormat = new ArrayObject($this->dateTimeFormat); } catch (\Exception $e) { throw new DateTimeObjectException(DateTimeObjectException::MSG_INVALID_DATE_FORMAT, [$this->format]); } }
php
private function parseDateTimeFormat() { try { if ($this->isNull($this->format)) { $this->format = self::$defaultFormat; } $str = new StringObject($this->format); $chunks = $str->split(); $this->buildFormatterList(); foreach ($chunks as $c) { foreach (self::$formatters as $fk => $f) { if ($f->inArray($c)) { $this->dateTimeFormat[$fk] = $c; } } } $this->dateTimeFormat = new ArrayObject($this->dateTimeFormat); } catch (\Exception $e) { throw new DateTimeObjectException(DateTimeObjectException::MSG_INVALID_DATE_FORMAT, [$this->format]); } }
[ "private", "function", "parseDateTimeFormat", "(", ")", "{", "try", "{", "if", "(", "$", "this", "->", "isNull", "(", "$", "this", "->", "format", ")", ")", "{", "$", "this", "->", "format", "=", "self", "::", "$", "defaultFormat", ";", "}", "$", "str", "=", "new", "StringObject", "(", "$", "this", "->", "format", ")", ";", "$", "chunks", "=", "$", "str", "->", "split", "(", ")", ";", "$", "this", "->", "buildFormatterList", "(", ")", ";", "foreach", "(", "$", "chunks", "as", "$", "c", ")", "{", "foreach", "(", "self", "::", "$", "formatters", "as", "$", "fk", "=>", "$", "f", ")", "{", "if", "(", "$", "f", "->", "inArray", "(", "$", "c", ")", ")", "{", "$", "this", "->", "dateTimeFormat", "[", "$", "fk", "]", "=", "$", "c", ";", "}", "}", "}", "$", "this", "->", "dateTimeFormat", "=", "new", "ArrayObject", "(", "$", "this", "->", "dateTimeFormat", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "DateTimeObjectException", "(", "DateTimeObjectException", "::", "MSG_INVALID_DATE_FORMAT", ",", "[", "$", "this", "->", "format", "]", ")", ";", "}", "}" ]
This function parses the format provided by Config and sets the default formatting for getting date information like day, month, year, etc.. @throws DateTimeObjectException
[ "This", "function", "parses", "the", "format", "provided", "by", "Config", "and", "sets", "the", "default", "formatting", "for", "getting", "date", "information", "like", "day", "month", "year", "etc", ".." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/DateTimeObject/DateTimeObject.php#L560-L583
230,011
deanblackborough/zf3-view-helpers
src/Bootstrap4NavbarLite.php
Bootstrap4NavbarLite.addNavigation
public function addNavigation(array $navigation) : Bootstrap4NavbarLite { $html = '<ul class="navbar-nav mr-auto">'; foreach ($navigation as $nav) { if (array_key_exists('uri', $nav) === true && array_key_exists('active', $nav) === true && array_key_exists('label', $nav) === true) { $html .= '<li class="nav-item' . (($nav['active'] === true) ? ' active' : null) . '"><a class="nav-link" href="' . $nav['uri'] . '">' . $nav['label'] . '</a></li>'; } else { $html .= '<!-- Failed to add navigation item, index(es) missing -->'; } } $html .= '</ul>'; $this->content[] = $html; return $this; }
php
public function addNavigation(array $navigation) : Bootstrap4NavbarLite { $html = '<ul class="navbar-nav mr-auto">'; foreach ($navigation as $nav) { if (array_key_exists('uri', $nav) === true && array_key_exists('active', $nav) === true && array_key_exists('label', $nav) === true) { $html .= '<li class="nav-item' . (($nav['active'] === true) ? ' active' : null) . '"><a class="nav-link" href="' . $nav['uri'] . '">' . $nav['label'] . '</a></li>'; } else { $html .= '<!-- Failed to add navigation item, index(es) missing -->'; } } $html .= '</ul>'; $this->content[] = $html; return $this; }
[ "public", "function", "addNavigation", "(", "array", "$", "navigation", ")", ":", "Bootstrap4NavbarLite", "{", "$", "html", "=", "'<ul class=\"navbar-nav mr-auto\">'", ";", "foreach", "(", "$", "navigation", "as", "$", "nav", ")", "{", "if", "(", "array_key_exists", "(", "'uri'", ",", "$", "nav", ")", "===", "true", "&&", "array_key_exists", "(", "'active'", ",", "$", "nav", ")", "===", "true", "&&", "array_key_exists", "(", "'label'", ",", "$", "nav", ")", "===", "true", ")", "{", "$", "html", ".=", "'<li class=\"nav-item'", ".", "(", "(", "$", "nav", "[", "'active'", "]", "===", "true", ")", "?", "' active'", ":", "null", ")", ".", "'\"><a class=\"nav-link\" href=\"'", ".", "$", "nav", "[", "'uri'", "]", ".", "'\">'", ".", "$", "nav", "[", "'label'", "]", ".", "'</a></li>'", ";", "}", "else", "{", "$", "html", ".=", "'<!-- Failed to add navigation item, index(es) missing -->'", ";", "}", "}", "$", "html", ".=", "'</ul>'", ";", "$", "this", "->", "content", "[", "]", "=", "$", "html", ";", "return", "$", "this", ";", "}" ]
Add a navigation item to the content array for the navbar @param array $navigation Navigation data array, array of menu items each with active, uri and label indexes. If any of the indexes are missing the item is ignored and a HTML comment is added to state an index is missing @return Bootstrap4NavbarLite
[ "Add", "a", "navigation", "item", "to", "the", "content", "array", "for", "the", "navbar" ]
db8bea4ca62709b2ac8c732aedbb2a5235223f23
https://github.com/deanblackborough/zf3-view-helpers/blob/db8bea4ca62709b2ac8c732aedbb2a5235223f23/src/Bootstrap4NavbarLite.php#L72-L93
230,012
deanblackborough/zf3-view-helpers
src/Bootstrap4NavbarLite.php
Bootstrap4NavbarLite.addBrand
public function addBrand(string $label, string $uri = null) : Bootstrap4NavbarLite { $this->brand_label = $label; $this->brand_uri = $uri; return $this; }
php
public function addBrand(string $label, string $uri = null) : Bootstrap4NavbarLite { $this->brand_label = $label; $this->brand_uri = $uri; return $this; }
[ "public", "function", "addBrand", "(", "string", "$", "label", ",", "string", "$", "uri", "=", "null", ")", ":", "Bootstrap4NavbarLite", "{", "$", "this", "->", "brand_label", "=", "$", "label", ";", "$", "this", "->", "brand_uri", "=", "$", "uri", ";", "return", "$", "this", ";", "}" ]
Set the brand label and an optional uri @param string $label @param string $uri @return Bootstrap4NavbarLite
[ "Set", "the", "brand", "label", "and", "an", "optional", "uri" ]
db8bea4ca62709b2ac8c732aedbb2a5235223f23
https://github.com/deanblackborough/zf3-view-helpers/blob/db8bea4ca62709b2ac8c732aedbb2a5235223f23/src/Bootstrap4NavbarLite.php#L157-L163
230,013
deanblackborough/zf3-view-helpers
src/Bootstrap4NavbarLite.php
Bootstrap4NavbarLite.brand
private function brand() : string { if ($this->brand_label !== null) { if ($this->brand_uri === null) { return '<span class="h1 navbar-brand">' . $this->brand_label . '</span>'; } else { return '<a class="navbar-brand" href="' . $this->brand_uri . '">' . $this->brand_label . '</a>'; } } return ''; }
php
private function brand() : string { if ($this->brand_label !== null) { if ($this->brand_uri === null) { return '<span class="h1 navbar-brand">' . $this->brand_label . '</span>'; } else { return '<a class="navbar-brand" href="' . $this->brand_uri . '">' . $this->brand_label . '</a>'; } } return ''; }
[ "private", "function", "brand", "(", ")", ":", "string", "{", "if", "(", "$", "this", "->", "brand_label", "!==", "null", ")", "{", "if", "(", "$", "this", "->", "brand_uri", "===", "null", ")", "{", "return", "'<span class=\"h1 navbar-brand\">'", ".", "$", "this", "->", "brand_label", ".", "'</span>'", ";", "}", "else", "{", "return", "'<a class=\"navbar-brand\" href=\"'", ".", "$", "this", "->", "brand_uri", ".", "'\">'", ".", "$", "this", "->", "brand_label", ".", "'</a>'", ";", "}", "}", "return", "''", ";", "}" ]
Create the HTML for the brand @return string
[ "Create", "the", "HTML", "for", "the", "brand" ]
db8bea4ca62709b2ac8c732aedbb2a5235223f23
https://github.com/deanblackborough/zf3-view-helpers/blob/db8bea4ca62709b2ac8c732aedbb2a5235223f23/src/Bootstrap4NavbarLite.php#L170-L180
230,014
Webiny/Framework
src/Webiny/Component/Entity/Attribute/Validation/ValidationException.php
ValidationException.addError
public function addError($key, $message, $params = null) { if (!is_string($message)) { $message = vsprintf(static::$messages[$message], is_array($params) ? $params : []); } $this->errors[$key] = $message; return $this; }
php
public function addError($key, $message, $params = null) { if (!is_string($message)) { $message = vsprintf(static::$messages[$message], is_array($params) ? $params : []); } $this->errors[$key] = $message; return $this; }
[ "public", "function", "addError", "(", "$", "key", ",", "$", "message", ",", "$", "params", "=", "null", ")", "{", "if", "(", "!", "is_string", "(", "$", "message", ")", ")", "{", "$", "message", "=", "vsprintf", "(", "static", "::", "$", "messages", "[", "$", "message", "]", ",", "is_array", "(", "$", "params", ")", "?", "$", "params", ":", "[", "]", ")", ";", "}", "$", "this", "->", "errors", "[", "$", "key", "]", "=", "$", "message", ";", "return", "$", "this", ";", "}" ]
Add error for given key This is useful when you are validating an array attribute which can have validators on every nested key. When validating a simple attribute with no nested values, use this method to set error message for the attribute itself. @param string $key Attribute name or nested attribute key @param string|int $message @param null|array $params @return $this
[ "Add", "error", "for", "given", "key" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Entity/Attribute/Validation/ValidationException.php#L45-L53
230,015
Webiny/Framework
src/Webiny/Component/Mailer/Bridge/Mandrill/Message.php
Message.setTo
public function setTo($to) { if ($to instanceof Email) { $to = [$to]; } foreach ($to as $email) { if (!$email instanceof Email) { throw new MailerException('Email must be an instance of \Webiny\Component\Mailer\Email.'); } $this->addTo($email); } return $this; }
php
public function setTo($to) { if ($to instanceof Email) { $to = [$to]; } foreach ($to as $email) { if (!$email instanceof Email) { throw new MailerException('Email must be an instance of \Webiny\Component\Mailer\Email.'); } $this->addTo($email); } return $this; }
[ "public", "function", "setTo", "(", "$", "to", ")", "{", "if", "(", "$", "to", "instanceof", "Email", ")", "{", "$", "to", "=", "[", "$", "to", "]", ";", "}", "foreach", "(", "$", "to", "as", "$", "email", ")", "{", "if", "(", "!", "$", "email", "instanceof", "Email", ")", "{", "throw", "new", "MailerException", "(", "'Email must be an instance of \\Webiny\\Component\\Mailer\\Email.'", ")", ";", "}", "$", "this", "->", "addTo", "(", "$", "email", ")", ";", "}", "return", "$", "this", ";", "}" ]
Specifies the addresses of the intended recipients. @param array|Email $to A list of recipients. @return $this @throws MailerException
[ "Specifies", "the", "addresses", "of", "the", "intended", "recipients", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Mailer/Bridge/Mandrill/Message.php#L164-L178
230,016
Webiny/Framework
src/Webiny/Component/Mailer/Bridge/Mandrill/Message.php
Message.setCc
public function setCc($cc) { if ($cc instanceof Email) { $cc = [$cc]; } foreach ($cc as $email) { if (!$email instanceof Email) { throw new MailerException('Email must be an instance of \Webiny\Component\Mailer\Email.'); } $this->addCc($email); } return $this; }
php
public function setCc($cc) { if ($cc instanceof Email) { $cc = [$cc]; } foreach ($cc as $email) { if (!$email instanceof Email) { throw new MailerException('Email must be an instance of \Webiny\Component\Mailer\Email.'); } $this->addCc($email); } return $this; }
[ "public", "function", "setCc", "(", "$", "cc", ")", "{", "if", "(", "$", "cc", "instanceof", "Email", ")", "{", "$", "cc", "=", "[", "$", "cc", "]", ";", "}", "foreach", "(", "$", "cc", "as", "$", "email", ")", "{", "if", "(", "!", "$", "email", "instanceof", "Email", ")", "{", "throw", "new", "MailerException", "(", "'Email must be an instance of \\Webiny\\Component\\Mailer\\Email.'", ")", ";", "}", "$", "this", "->", "addCc", "(", "$", "email", ")", ";", "}", "return", "$", "this", ";", "}" ]
Specifies the addresses of recipients who will be copied in on the message. @param array|Email $cc @return $this @throws MailerException
[ "Specifies", "the", "addresses", "of", "recipients", "who", "will", "be", "copied", "in", "on", "the", "message", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Mailer/Bridge/Mandrill/Message.php#L216-L230
230,017
Webiny/Framework
src/Webiny/Component/Mailer/Bridge/Mandrill/Message.php
Message.setBcc
public function setBcc($bcc) { if ($bcc instanceof Email) { $bcc = [$bcc]; } foreach ($bcc as $email) { if (!$email instanceof Email) { throw new MailerException('Email must be an instance of \Webiny\Component\Mailer\Email.'); } $this->addBcc($email); } return $this; }
php
public function setBcc($bcc) { if ($bcc instanceof Email) { $bcc = [$bcc]; } foreach ($bcc as $email) { if (!$email instanceof Email) { throw new MailerException('Email must be an instance of \Webiny\Component\Mailer\Email.'); } $this->addBcc($email); } return $this; }
[ "public", "function", "setBcc", "(", "$", "bcc", ")", "{", "if", "(", "$", "bcc", "instanceof", "Email", ")", "{", "$", "bcc", "=", "[", "$", "bcc", "]", ";", "}", "foreach", "(", "$", "bcc", "as", "$", "email", ")", "{", "if", "(", "!", "$", "email", "instanceof", "Email", ")", "{", "throw", "new", "MailerException", "(", "'Email must be an instance of \\Webiny\\Component\\Mailer\\Email.'", ")", ";", "}", "$", "this", "->", "addBcc", "(", "$", "email", ")", ";", "}", "return", "$", "this", ";", "}" ]
Specifies the addresses of recipients who the message will be blind-copied to. Other recipients will not be aware of these copies. @param array|Email $bcc @return $this @throws MailerException
[ "Specifies", "the", "addresses", "of", "recipients", "who", "the", "message", "will", "be", "blind", "-", "copied", "to", ".", "Other", "recipients", "will", "not", "be", "aware", "of", "these", "copies", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Mailer/Bridge/Mandrill/Message.php#L269-L283
230,018
naneau/semver
src/Naneau/SemVer/Regex.php
Regex.matchSemVer
public static function matchSemVer($string) { // Array of matches for PCRE $matches = array(); // Match the possible parts of a SemVer $matched = preg_match( self::$version, $string, $matches ); // No match, invalid if (!$matched) { throw new InvalidArgumentException( '"' . $string . '" is not a valid SemVer' ); } // Return matched array return $matches; }
php
public static function matchSemVer($string) { // Array of matches for PCRE $matches = array(); // Match the possible parts of a SemVer $matched = preg_match( self::$version, $string, $matches ); // No match, invalid if (!$matched) { throw new InvalidArgumentException( '"' . $string . '" is not a valid SemVer' ); } // Return matched array return $matches; }
[ "public", "static", "function", "matchSemVer", "(", "$", "string", ")", "{", "// Array of matches for PCRE", "$", "matches", "=", "array", "(", ")", ";", "// Match the possible parts of a SemVer", "$", "matched", "=", "preg_match", "(", "self", "::", "$", "version", ",", "$", "string", ",", "$", "matches", ")", ";", "// No match, invalid", "if", "(", "!", "$", "matched", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'\"'", ".", "$", "string", ".", "'\" is not a valid SemVer'", ")", ";", "}", "// Return matched array", "return", "$", "matches", ";", "}" ]
Match a SemVer using a regex Array wil at least have a key `version` But might also contain: - prerelease - build @throws InvalidArgumentException @param string $string @return array[string]string
[ "Match", "a", "SemVer", "using", "a", "regex" ]
c771ad1e6c89064c0a4fa714979639dc3649d6c8
https://github.com/naneau/semver/blob/c771ad1e6c89064c0a4fa714979639dc3649d6c8/src/Naneau/SemVer/Regex.php#L45-L66
230,019
ameliaikeda/rememberable
src/Eloquent/Builder.php
Builder.tagModels
protected function tagModels(Collection $models, $key) { $tags = $this->query->getCacheTags(); $class = get_class($this->model); foreach ($models as $model) { $tags[] = $class.':'.$model->getKey(); } $this->query->setTagsForKey($tags, $key); }
php
protected function tagModels(Collection $models, $key) { $tags = $this->query->getCacheTags(); $class = get_class($this->model); foreach ($models as $model) { $tags[] = $class.':'.$model->getKey(); } $this->query->setTagsForKey($tags, $key); }
[ "protected", "function", "tagModels", "(", "Collection", "$", "models", ",", "$", "key", ")", "{", "$", "tags", "=", "$", "this", "->", "query", "->", "getCacheTags", "(", ")", ";", "$", "class", "=", "get_class", "(", "$", "this", "->", "model", ")", ";", "foreach", "(", "$", "models", "as", "$", "model", ")", "{", "$", "tags", "[", "]", "=", "$", "class", ".", "':'", ".", "$", "model", "->", "getKey", "(", ")", ";", "}", "$", "this", "->", "query", "->", "setTagsForKey", "(", "$", "tags", ",", "$", "key", ")", ";", "}" ]
Tag this cache key with the ID of every model in the collection. @param \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model[] $models @param string $key
[ "Tag", "this", "cache", "key", "with", "the", "ID", "of", "every", "model", "in", "the", "collection", "." ]
a60826a33698e6a27129760d809325b143cf5f88
https://github.com/ameliaikeda/rememberable/blob/a60826a33698e6a27129760d809325b143cf5f88/src/Eloquent/Builder.php#L46-L57
230,020
Webiny/Framework
src/Webiny/Component/Entity/Entity.php
Entity.getDatabase
public function getDatabase() { if (self::$database === null) { self::$database = self::mongo(self::getConfig()->Database); } return self::$database; }
php
public function getDatabase() { if (self::$database === null) { self::$database = self::mongo(self::getConfig()->Database); } return self::$database; }
[ "public", "function", "getDatabase", "(", ")", "{", "if", "(", "self", "::", "$", "database", "===", "null", ")", "{", "self", "::", "$", "database", "=", "self", "::", "mongo", "(", "self", "::", "getConfig", "(", ")", "->", "Database", ")", ";", "}", "return", "self", "::", "$", "database", ";", "}" ]
Get entity database @return Mongo
[ "Get", "entity", "database" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Entity/Entity.php#L69-L76
230,021
Webiny/Framework
src/Webiny/Component/Entity/Entity.php
Entity.add
public function add($instance) { $class = get_class($instance); $entityPool = $this->pool[$class] ?? []; $entityPool[$instance->id] = $instance; $this->pool[$class] = $entityPool; return $instance; }
php
public function add($instance) { $class = get_class($instance); $entityPool = $this->pool[$class] ?? []; $entityPool[$instance->id] = $instance; $this->pool[$class] = $entityPool; return $instance; }
[ "public", "function", "add", "(", "$", "instance", ")", "{", "$", "class", "=", "get_class", "(", "$", "instance", ")", ";", "$", "entityPool", "=", "$", "this", "->", "pool", "[", "$", "class", "]", "??", "[", "]", ";", "$", "entityPool", "[", "$", "instance", "->", "id", "]", "=", "$", "instance", ";", "$", "this", "->", "pool", "[", "$", "class", "]", "=", "$", "entityPool", ";", "return", "$", "instance", ";", "}" ]
Add instance to the pool @param $instance @return mixed
[ "Add", "instance", "to", "the", "pool" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Entity/Entity.php#L108-L116
230,022
Webiny/Framework
src/Webiny/Component/Entity/Entity.php
Entity.remove
public function remove(AbstractEntity $instance) { $class = get_class($instance); $entityPool = $this->pool[$class] ?? []; $id = '' . $instance->id; if (isset($entityPool[$id])) { unset($entityPool[$id]); $this->pool[$class] = $entityPool; } unset($instance); return true; }
php
public function remove(AbstractEntity $instance) { $class = get_class($instance); $entityPool = $this->pool[$class] ?? []; $id = '' . $instance->id; if (isset($entityPool[$id])) { unset($entityPool[$id]); $this->pool[$class] = $entityPool; } unset($instance); return true; }
[ "public", "function", "remove", "(", "AbstractEntity", "$", "instance", ")", "{", "$", "class", "=", "get_class", "(", "$", "instance", ")", ";", "$", "entityPool", "=", "$", "this", "->", "pool", "[", "$", "class", "]", "??", "[", "]", ";", "$", "id", "=", "''", ".", "$", "instance", "->", "id", ";", "if", "(", "isset", "(", "$", "entityPool", "[", "$", "id", "]", ")", ")", "{", "unset", "(", "$", "entityPool", "[", "$", "id", "]", ")", ";", "$", "this", "->", "pool", "[", "$", "class", "]", "=", "$", "entityPool", ";", "}", "unset", "(", "$", "instance", ")", ";", "return", "true", ";", "}" ]
Remove instance from pool @param $instance @return bool
[ "Remove", "instance", "from", "pool" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Entity/Entity.php#L144-L156
230,023
ZenMagick/ZenCart
includes/modules/payment/paypal/paypal_curl.php
paypal_curl.paypal_curl
function paypal_curl($params = array()) { foreach ($params as $name => $value) { $this->setParam($name, $value); } }
php
function paypal_curl($params = array()) { foreach ($params as $name => $value) { $this->setParam($name, $value); } }
[ "function", "paypal_curl", "(", "$", "params", "=", "array", "(", ")", ")", "{", "foreach", "(", "$", "params", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "this", "->", "setParam", "(", "$", "name", ",", "$", "value", ")", ";", "}", "}" ]
Constructor. Sets up communication infrastructure.
[ "Constructor", ".", "Sets", "up", "communication", "infrastructure", "." ]
00438ebc0faee786489aab4a6d70fc0d0c1461c7
https://github.com/ZenMagick/ZenCart/blob/00438ebc0faee786489aab4a6d70fc0d0c1461c7/includes/modules/payment/paypal/paypal_curl.php#L105-L109
230,024
ZenMagick/ZenCart
includes/modules/payment/paypal/paypal_curl.php
paypal_curl.DoDirectPayment
function DoDirectPayment($cc, $cvv2 = '', $exp, $fname = null, $lname = null, $cc_type, $options = array(), $nvp = array() ) { $values = $options; $values['ACCT'] = $cc; if ($cvv2 != '') $values['CVV2'] = $cvv2; $values['FIRSTNAME'] = $fname; $values['LASTNAME'] = $lname; if (isset($values['NAME'])) unset ($values['NAME']); if ($this->_mode == 'payflow') { $values['EXPDATE'] = $exp; $values['TENDER'] = 'C'; $values['TRXTYPE'] = $this->_trxtype; $values['VERBOSITY'] = 'MEDIUM'; $values['NOTIFYURL'] = zen_href_link('ipn_main_handler.php', '', 'SSL',false,false,true); } elseif ($this->_mode == 'nvp') { $values = array_merge($values, $nvp); if (isset($values['ECI'])) { $values['ECI3DS'] = $values['ECI']; unset($values['ECI']); } $values['CREDITCARDTYPE'] = ($cc_type == 'American Express') ? 'Amex' : $cc_type; $values['NOTIFYURL'] = urlencode(zen_href_link('ipn_main_handler.php', '', 'SSL',false,false,true)); if (!isset($values['PAYMENTACTION'])) $values['PAYMENTACTION'] = ($this->_trxtype == 'S' ? 'Sale' : 'Authorization'); if (isset($values['COUNTRY'])) unset ($values['COUNTRY']); if (isset($values['COMMENT1'])) unset ($values['COMMENT1']); if (isset($values['COMMENT2'])) unset ($values['COMMENT2']); if (isset($values['CUSTREF'])) unset ($values['CUSTREF']); } $this->values = $values; $this->notify('NOTIFY_PAYPAL_DODIRECTPAYMENT'); ksort($this->values); return $this->_request($this->values, 'DoDirectPayment'); }
php
function DoDirectPayment($cc, $cvv2 = '', $exp, $fname = null, $lname = null, $cc_type, $options = array(), $nvp = array() ) { $values = $options; $values['ACCT'] = $cc; if ($cvv2 != '') $values['CVV2'] = $cvv2; $values['FIRSTNAME'] = $fname; $values['LASTNAME'] = $lname; if (isset($values['NAME'])) unset ($values['NAME']); if ($this->_mode == 'payflow') { $values['EXPDATE'] = $exp; $values['TENDER'] = 'C'; $values['TRXTYPE'] = $this->_trxtype; $values['VERBOSITY'] = 'MEDIUM'; $values['NOTIFYURL'] = zen_href_link('ipn_main_handler.php', '', 'SSL',false,false,true); } elseif ($this->_mode == 'nvp') { $values = array_merge($values, $nvp); if (isset($values['ECI'])) { $values['ECI3DS'] = $values['ECI']; unset($values['ECI']); } $values['CREDITCARDTYPE'] = ($cc_type == 'American Express') ? 'Amex' : $cc_type; $values['NOTIFYURL'] = urlencode(zen_href_link('ipn_main_handler.php', '', 'SSL',false,false,true)); if (!isset($values['PAYMENTACTION'])) $values['PAYMENTACTION'] = ($this->_trxtype == 'S' ? 'Sale' : 'Authorization'); if (isset($values['COUNTRY'])) unset ($values['COUNTRY']); if (isset($values['COMMENT1'])) unset ($values['COMMENT1']); if (isset($values['COMMENT2'])) unset ($values['COMMENT2']); if (isset($values['CUSTREF'])) unset ($values['CUSTREF']); } $this->values = $values; $this->notify('NOTIFY_PAYPAL_DODIRECTPAYMENT'); ksort($this->values); return $this->_request($this->values, 'DoDirectPayment'); }
[ "function", "DoDirectPayment", "(", "$", "cc", ",", "$", "cvv2", "=", "''", ",", "$", "exp", ",", "$", "fname", "=", "null", ",", "$", "lname", "=", "null", ",", "$", "cc_type", ",", "$", "options", "=", "array", "(", ")", ",", "$", "nvp", "=", "array", "(", ")", ")", "{", "$", "values", "=", "$", "options", ";", "$", "values", "[", "'ACCT'", "]", "=", "$", "cc", ";", "if", "(", "$", "cvv2", "!=", "''", ")", "$", "values", "[", "'CVV2'", "]", "=", "$", "cvv2", ";", "$", "values", "[", "'FIRSTNAME'", "]", "=", "$", "fname", ";", "$", "values", "[", "'LASTNAME'", "]", "=", "$", "lname", ";", "if", "(", "isset", "(", "$", "values", "[", "'NAME'", "]", ")", ")", "unset", "(", "$", "values", "[", "'NAME'", "]", ")", ";", "if", "(", "$", "this", "->", "_mode", "==", "'payflow'", ")", "{", "$", "values", "[", "'EXPDATE'", "]", "=", "$", "exp", ";", "$", "values", "[", "'TENDER'", "]", "=", "'C'", ";", "$", "values", "[", "'TRXTYPE'", "]", "=", "$", "this", "->", "_trxtype", ";", "$", "values", "[", "'VERBOSITY'", "]", "=", "'MEDIUM'", ";", "$", "values", "[", "'NOTIFYURL'", "]", "=", "zen_href_link", "(", "'ipn_main_handler.php'", ",", "''", ",", "'SSL'", ",", "false", ",", "false", ",", "true", ")", ";", "}", "elseif", "(", "$", "this", "->", "_mode", "==", "'nvp'", ")", "{", "$", "values", "=", "array_merge", "(", "$", "values", ",", "$", "nvp", ")", ";", "if", "(", "isset", "(", "$", "values", "[", "'ECI'", "]", ")", ")", "{", "$", "values", "[", "'ECI3DS'", "]", "=", "$", "values", "[", "'ECI'", "]", ";", "unset", "(", "$", "values", "[", "'ECI'", "]", ")", ";", "}", "$", "values", "[", "'CREDITCARDTYPE'", "]", "=", "(", "$", "cc_type", "==", "'American Express'", ")", "?", "'Amex'", ":", "$", "cc_type", ";", "$", "values", "[", "'NOTIFYURL'", "]", "=", "urlencode", "(", "zen_href_link", "(", "'ipn_main_handler.php'", ",", "''", ",", "'SSL'", ",", "false", ",", "false", ",", "true", ")", ")", ";", "if", "(", "!", "isset", "(", "$", "values", "[", "'PAYMENTACTION'", "]", ")", ")", "$", "values", "[", "'PAYMENTACTION'", "]", "=", "(", "$", "this", "->", "_trxtype", "==", "'S'", "?", "'Sale'", ":", "'Authorization'", ")", ";", "if", "(", "isset", "(", "$", "values", "[", "'COUNTRY'", "]", ")", ")", "unset", "(", "$", "values", "[", "'COUNTRY'", "]", ")", ";", "if", "(", "isset", "(", "$", "values", "[", "'COMMENT1'", "]", ")", ")", "unset", "(", "$", "values", "[", "'COMMENT1'", "]", ")", ";", "if", "(", "isset", "(", "$", "values", "[", "'COMMENT2'", "]", ")", ")", "unset", "(", "$", "values", "[", "'COMMENT2'", "]", ")", ";", "if", "(", "isset", "(", "$", "values", "[", "'CUSTREF'", "]", ")", ")", "unset", "(", "$", "values", "[", "'CUSTREF'", "]", ")", ";", "}", "$", "this", "->", "values", "=", "$", "values", ";", "$", "this", "->", "notify", "(", "'NOTIFY_PAYPAL_DODIRECTPAYMENT'", ")", ";", "ksort", "(", "$", "this", "->", "values", ")", ";", "return", "$", "this", "->", "_request", "(", "$", "this", "->", "values", ",", "'DoDirectPayment'", ")", ";", "}" ]
DoDirectPayment Sends CC information to gateway for processing. Requires Website Payments Pro or Payflow Pro as merchant gateway. PAYMENTACTION = Authorization (auth/capt) or Sale (final)
[ "DoDirectPayment", "Sends", "CC", "information", "to", "gateway", "for", "processing", "." ]
00438ebc0faee786489aab4a6d70fc0d0c1461c7
https://github.com/ZenMagick/ZenCart/blob/00438ebc0faee786489aab4a6d70fc0d0c1461c7/includes/modules/payment/paypal/paypal_curl.php#L206-L239
230,025
ZenMagick/ZenCart
includes/modules/payment/paypal/paypal_curl.php
paypal_curl._logTransaction
function _logTransaction($operation, $elapsed, $response, $errors) { $values = $this->_parseNameValueList($response); $token = isset($values['TOKEN']) ? $values['TOKEN'] : ''; $token = preg_replace('/[^0-9.A-Z\-]/', '', urldecode($token)); $success = false; if ($response) { if ((isset($values['RESULT']) && $values['RESULT'] == 0) || (isset($values['ACK']) && (strstr($values['ACK'],'Success') || strstr($values['ACK'],'SuccessWithWarning')) && !strstr($values['ACK'],'Failure'))) { $success = true; } } $message = date('Y-m-d h:i:s') . "\n-------------------\n"; $message .= '(' . $this->_server . ' transaction) --> ' . $this->_endpoints[$this->_server] . "\n"; $message .= 'Request Headers: ' . "\n" . $this->_sanitizeLog($this->lastHeaders) . "\n\n"; $message .= 'Request Parameters: {' . $operation . '} ' . "\n" . urldecode($this->_sanitizeLog($this->_parseNameValueList($this->lastParamList))) . "\n\n"; $message .= 'Response: ' . "\n" . urldecode($this->_sanitizeLog($values)) . $errors; if ($this->_logLevel > 0 || $success == FALSE) { $this->log($message, $token); // extra debug email: // if (MODULE_PAYMENT_PAYPALWPP_DEBUGGING == 'Log and Email') { zen_mail(STORE_NAME, STORE_OWNER_EMAIL_ADDRESS, 'PayPal Debug log - ' . $operation, $message, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, array('EMAIL_MESSAGE_HTML'=>nl2br($message)), 'debug'); } $this->log($operation . ', Elapsed: ' . $elapsed . 'ms -- ' . (isset($values['ACK']) ? $values['ACK'] : ($success ? 'Succeeded' : 'Failed')) . $errors, $token); if (!$response) { $this->log('No response from server' . $errors, $token); } else { if ((isset($values['RESULT']) && $values['RESULT'] != 0) || strstr($values['ACK'],'Failure')) { $this->log($response . $errors, $token); } } } }
php
function _logTransaction($operation, $elapsed, $response, $errors) { $values = $this->_parseNameValueList($response); $token = isset($values['TOKEN']) ? $values['TOKEN'] : ''; $token = preg_replace('/[^0-9.A-Z\-]/', '', urldecode($token)); $success = false; if ($response) { if ((isset($values['RESULT']) && $values['RESULT'] == 0) || (isset($values['ACK']) && (strstr($values['ACK'],'Success') || strstr($values['ACK'],'SuccessWithWarning')) && !strstr($values['ACK'],'Failure'))) { $success = true; } } $message = date('Y-m-d h:i:s') . "\n-------------------\n"; $message .= '(' . $this->_server . ' transaction) --> ' . $this->_endpoints[$this->_server] . "\n"; $message .= 'Request Headers: ' . "\n" . $this->_sanitizeLog($this->lastHeaders) . "\n\n"; $message .= 'Request Parameters: {' . $operation . '} ' . "\n" . urldecode($this->_sanitizeLog($this->_parseNameValueList($this->lastParamList))) . "\n\n"; $message .= 'Response: ' . "\n" . urldecode($this->_sanitizeLog($values)) . $errors; if ($this->_logLevel > 0 || $success == FALSE) { $this->log($message, $token); // extra debug email: // if (MODULE_PAYMENT_PAYPALWPP_DEBUGGING == 'Log and Email') { zen_mail(STORE_NAME, STORE_OWNER_EMAIL_ADDRESS, 'PayPal Debug log - ' . $operation, $message, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, array('EMAIL_MESSAGE_HTML'=>nl2br($message)), 'debug'); } $this->log($operation . ', Elapsed: ' . $elapsed . 'ms -- ' . (isset($values['ACK']) ? $values['ACK'] : ($success ? 'Succeeded' : 'Failed')) . $errors, $token); if (!$response) { $this->log('No response from server' . $errors, $token); } else { if ((isset($values['RESULT']) && $values['RESULT'] != 0) || strstr($values['ACK'],'Failure')) { $this->log($response . $errors, $token); } } } }
[ "function", "_logTransaction", "(", "$", "operation", ",", "$", "elapsed", ",", "$", "response", ",", "$", "errors", ")", "{", "$", "values", "=", "$", "this", "->", "_parseNameValueList", "(", "$", "response", ")", ";", "$", "token", "=", "isset", "(", "$", "values", "[", "'TOKEN'", "]", ")", "?", "$", "values", "[", "'TOKEN'", "]", ":", "''", ";", "$", "token", "=", "preg_replace", "(", "'/[^0-9.A-Z\\-]/'", ",", "''", ",", "urldecode", "(", "$", "token", ")", ")", ";", "$", "success", "=", "false", ";", "if", "(", "$", "response", ")", "{", "if", "(", "(", "isset", "(", "$", "values", "[", "'RESULT'", "]", ")", "&&", "$", "values", "[", "'RESULT'", "]", "==", "0", ")", "||", "(", "isset", "(", "$", "values", "[", "'ACK'", "]", ")", "&&", "(", "strstr", "(", "$", "values", "[", "'ACK'", "]", ",", "'Success'", ")", "||", "strstr", "(", "$", "values", "[", "'ACK'", "]", ",", "'SuccessWithWarning'", ")", ")", "&&", "!", "strstr", "(", "$", "values", "[", "'ACK'", "]", ",", "'Failure'", ")", ")", ")", "{", "$", "success", "=", "true", ";", "}", "}", "$", "message", "=", "date", "(", "'Y-m-d h:i:s'", ")", ".", "\"\\n-------------------\\n\"", ";", "$", "message", ".=", "'('", ".", "$", "this", "->", "_server", ".", "' transaction) --> '", ".", "$", "this", "->", "_endpoints", "[", "$", "this", "->", "_server", "]", ".", "\"\\n\"", ";", "$", "message", ".=", "'Request Headers: '", ".", "\"\\n\"", ".", "$", "this", "->", "_sanitizeLog", "(", "$", "this", "->", "lastHeaders", ")", ".", "\"\\n\\n\"", ";", "$", "message", ".=", "'Request Parameters: {'", ".", "$", "operation", ".", "'} '", ".", "\"\\n\"", ".", "urldecode", "(", "$", "this", "->", "_sanitizeLog", "(", "$", "this", "->", "_parseNameValueList", "(", "$", "this", "->", "lastParamList", ")", ")", ")", ".", "\"\\n\\n\"", ";", "$", "message", ".=", "'Response: '", ".", "\"\\n\"", ".", "urldecode", "(", "$", "this", "->", "_sanitizeLog", "(", "$", "values", ")", ")", ".", "$", "errors", ";", "if", "(", "$", "this", "->", "_logLevel", ">", "0", "||", "$", "success", "==", "FALSE", ")", "{", "$", "this", "->", "log", "(", "$", "message", ",", "$", "token", ")", ";", "// extra debug email: //", "if", "(", "MODULE_PAYMENT_PAYPALWPP_DEBUGGING", "==", "'Log and Email'", ")", "{", "zen_mail", "(", "STORE_NAME", ",", "STORE_OWNER_EMAIL_ADDRESS", ",", "'PayPal Debug log - '", ".", "$", "operation", ",", "$", "message", ",", "STORE_OWNER", ",", "STORE_OWNER_EMAIL_ADDRESS", ",", "array", "(", "'EMAIL_MESSAGE_HTML'", "=>", "nl2br", "(", "$", "message", ")", ")", ",", "'debug'", ")", ";", "}", "$", "this", "->", "log", "(", "$", "operation", ".", "', Elapsed: '", ".", "$", "elapsed", ".", "'ms -- '", ".", "(", "isset", "(", "$", "values", "[", "'ACK'", "]", ")", "?", "$", "values", "[", "'ACK'", "]", ":", "(", "$", "success", "?", "'Succeeded'", ":", "'Failed'", ")", ")", ".", "$", "errors", ",", "$", "token", ")", ";", "if", "(", "!", "$", "response", ")", "{", "$", "this", "->", "log", "(", "'No response from server'", ".", "$", "errors", ",", "$", "token", ")", ";", "}", "else", "{", "if", "(", "(", "isset", "(", "$", "values", "[", "'RESULT'", "]", ")", "&&", "$", "values", "[", "'RESULT'", "]", "!=", "0", ")", "||", "strstr", "(", "$", "values", "[", "'ACK'", "]", ",", "'Failure'", ")", ")", "{", "$", "this", "->", "log", "(", "$", "response", ".", "$", "errors", ",", "$", "token", ")", ";", "}", "}", "}", "}" ]
Log the current transaction depending on the current log level. @access protected @param string $operation The operation called. @param integer $elapsed Microseconds taken. @param object $response The response.
[ "Log", "the", "current", "transaction", "depending", "on", "the", "current", "log", "level", "." ]
00438ebc0faee786489aab4a6d70fc0d0c1461c7
https://github.com/ZenMagick/ZenCart/blob/00438ebc0faee786489aab4a6d70fc0d0c1461c7/includes/modules/payment/paypal/paypal_curl.php#L574-L606
230,026
addiks/phpsql
src/Addiks/PHPSQL/Value/Enum.php
Enum.factory
public static function factory($name) { $classname = get_called_class(); if (!isset(self::$instances[$classname])) { self::$instances[$classname] = array(); } if ($name instanceof Value) { $name = $name->getValue(); } if (!isset(self::$instances[$classname][$name])) { $instance = new static($name); $name = $instance->getName(); if (!isset(self::$instances[$classname][$name])) { self::$instances[$classname][$name] = $instance; } } return self::$instances[$classname][$name]; }
php
public static function factory($name) { $classname = get_called_class(); if (!isset(self::$instances[$classname])) { self::$instances[$classname] = array(); } if ($name instanceof Value) { $name = $name->getValue(); } if (!isset(self::$instances[$classname][$name])) { $instance = new static($name); $name = $instance->getName(); if (!isset(self::$instances[$classname][$name])) { self::$instances[$classname][$name] = $instance; } } return self::$instances[$classname][$name]; }
[ "public", "static", "function", "factory", "(", "$", "name", ")", "{", "$", "classname", "=", "get_called_class", "(", ")", ";", "if", "(", "!", "isset", "(", "self", "::", "$", "instances", "[", "$", "classname", "]", ")", ")", "{", "self", "::", "$", "instances", "[", "$", "classname", "]", "=", "array", "(", ")", ";", "}", "if", "(", "$", "name", "instanceof", "Value", ")", "{", "$", "name", "=", "$", "name", "->", "getValue", "(", ")", ";", "}", "if", "(", "!", "isset", "(", "self", "::", "$", "instances", "[", "$", "classname", "]", "[", "$", "name", "]", ")", ")", "{", "$", "instance", "=", "new", "static", "(", "$", "name", ")", ";", "$", "name", "=", "$", "instance", "->", "getName", "(", ")", ";", "if", "(", "!", "isset", "(", "self", "::", "$", "instances", "[", "$", "classname", "]", "[", "$", "name", "]", ")", ")", "{", "self", "::", "$", "instances", "[", "$", "classname", "]", "[", "$", "name", "]", "=", "$", "instance", ";", "}", "}", "return", "self", "::", "$", "instances", "[", "$", "classname", "]", "[", "$", "name", "]", ";", "}" ]
Creates new enum-objects. @param string $name
[ "Creates", "new", "enum", "-", "objects", "." ]
28dae64ffc2123f39f801a50ab53bfe29890cbd9
https://github.com/addiks/phpsql/blob/28dae64ffc2123f39f801a50ab53bfe29890cbd9/src/Addiks/PHPSQL/Value/Enum.php#L116-L138
230,027
addiks/phpsql
src/Addiks/PHPSQL/Value/Enum.php
Enum.getKeyByValue
public static function getKeyByValue($needle) { $classname = get_called_class(); $reflection = new ReflectionClass($classname); foreach ($reflection->getConstants() as $name => $value) { if (strtolower($value) === strtolower($needle) || strtolower($name) === strtolower($needle)) { return $name; } } throw new ErrorException("Value '{$needle}' does not match enumeration '{$classname}'"); }
php
public static function getKeyByValue($needle) { $classname = get_called_class(); $reflection = new ReflectionClass($classname); foreach ($reflection->getConstants() as $name => $value) { if (strtolower($value) === strtolower($needle) || strtolower($name) === strtolower($needle)) { return $name; } } throw new ErrorException("Value '{$needle}' does not match enumeration '{$classname}'"); }
[ "public", "static", "function", "getKeyByValue", "(", "$", "needle", ")", "{", "$", "classname", "=", "get_called_class", "(", ")", ";", "$", "reflection", "=", "new", "ReflectionClass", "(", "$", "classname", ")", ";", "foreach", "(", "$", "reflection", "->", "getConstants", "(", ")", "as", "$", "name", "=>", "$", "value", ")", "{", "if", "(", "strtolower", "(", "$", "value", ")", "===", "strtolower", "(", "$", "needle", ")", "||", "strtolower", "(", "$", "name", ")", "===", "strtolower", "(", "$", "needle", ")", ")", "{", "return", "$", "name", ";", "}", "}", "throw", "new", "ErrorException", "(", "\"Value '{$needle}' does not match enumeration '{$classname}'\"", ")", ";", "}" ]
Gets name of enum-entry by searching for specific value. @param mixed $value @return string
[ "Gets", "name", "of", "enum", "-", "entry", "by", "searching", "for", "specific", "value", "." ]
28dae64ffc2123f39f801a50ab53bfe29890cbd9
https://github.com/addiks/phpsql/blob/28dae64ffc2123f39f801a50ab53bfe29890cbd9/src/Addiks/PHPSQL/Value/Enum.php#L187-L200
230,028
EdgedesignCZ/ares
Provider/HttpProvider.php
HttpProvider.fetchSubjectXml
public function fetchSubjectXml($ic) { $url = $this->generateUrl($ic); $session = curl_init($url); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); if ($this->decorator) { $this->decorator->decorate($session); } $xml = curl_exec($session); if($xml === false) { throw new HttpException('cURL error: ' . curl_errno($session)); } curl_close($session); return $xml; }
php
public function fetchSubjectXml($ic) { $url = $this->generateUrl($ic); $session = curl_init($url); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); if ($this->decorator) { $this->decorator->decorate($session); } $xml = curl_exec($session); if($xml === false) { throw new HttpException('cURL error: ' . curl_errno($session)); } curl_close($session); return $xml; }
[ "public", "function", "fetchSubjectXml", "(", "$", "ic", ")", "{", "$", "url", "=", "$", "this", "->", "generateUrl", "(", "$", "ic", ")", ";", "$", "session", "=", "curl_init", "(", "$", "url", ")", ";", "curl_setopt", "(", "$", "session", ",", "CURLOPT_HEADER", ",", "false", ")", ";", "curl_setopt", "(", "$", "session", ",", "CURLOPT_RETURNTRANSFER", ",", "true", ")", ";", "if", "(", "$", "this", "->", "decorator", ")", "{", "$", "this", "->", "decorator", "->", "decorate", "(", "$", "session", ")", ";", "}", "$", "xml", "=", "curl_exec", "(", "$", "session", ")", ";", "if", "(", "$", "xml", "===", "false", ")", "{", "throw", "new", "HttpException", "(", "'cURL error: '", ".", "curl_errno", "(", "$", "session", ")", ")", ";", "}", "curl_close", "(", "$", "session", ")", ";", "return", "$", "xml", ";", "}" ]
Fetch XML describing subject with given ID. @param integer $ic @throws \Edge\Ares\Exception\HttpException @return string
[ "Fetch", "XML", "describing", "subject", "with", "given", "ID", "." ]
ae0f50155571875d09ba969e7b062854c823b57d
https://github.com/EdgedesignCZ/ares/blob/ae0f50155571875d09ba969e7b062854c823b57d/Provider/HttpProvider.php#L33-L54
230,029
ZenMagick/ZenCart
includes/classes/class.phpmailer.php
PHPMailer.SetLanguage
function SetLanguage($lang_type, $lang_path = "support/") { if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) include($lang_path.'phpmailer.lang-'.$lang_type.'.php'); else if(file_exists($lang_path.'phpmailer.lang-en.php')) include($lang_path.'phpmailer.lang-en.php'); else { $this->SetError("Could not load language file"); return false; } $this->language = $PHPMAILER_LANG; return true; }
php
function SetLanguage($lang_type, $lang_path = "support/") { if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) include($lang_path.'phpmailer.lang-'.$lang_type.'.php'); else if(file_exists($lang_path.'phpmailer.lang-en.php')) include($lang_path.'phpmailer.lang-en.php'); else { $this->SetError("Could not load language file"); return false; } $this->language = $PHPMAILER_LANG; return true; }
[ "function", "SetLanguage", "(", "$", "lang_type", ",", "$", "lang_path", "=", "\"support/\"", ")", "{", "if", "(", "file_exists", "(", "$", "lang_path", ".", "'phpmailer.lang-'", ".", "$", "lang_type", ".", "'.php'", ")", ")", "include", "(", "$", "lang_path", ".", "'phpmailer.lang-'", ".", "$", "lang_type", ".", "'.php'", ")", ";", "else", "if", "(", "file_exists", "(", "$", "lang_path", ".", "'phpmailer.lang-en.php'", ")", ")", "include", "(", "$", "lang_path", ".", "'phpmailer.lang-en.php'", ")", ";", "else", "{", "$", "this", "->", "SetError", "(", "\"Could not load language file\"", ")", ";", "return", "false", ";", "}", "$", "this", "->", "language", "=", "$", "PHPMAILER_LANG", ";", "return", "true", ";", "}" ]
Sets the language for all class error messages. Returns false if it cannot load the language file. The default language type is English. @param string $lang_type Type of language (e.g. Portuguese: "br") @param string $lang_path Path to the language file directory @access public @return bool
[ "Sets", "the", "language", "for", "all", "class", "error", "messages", ".", "Returns", "false", "if", "it", "cannot", "load", "the", "language", "file", ".", "The", "default", "language", "type", "is", "English", "." ]
00438ebc0faee786489aab4a6d70fc0d0c1461c7
https://github.com/ZenMagick/ZenCart/blob/00438ebc0faee786489aab4a6d70fc0d0c1461c7/includes/classes/class.phpmailer.php#L614-L627
230,030
Webiny/Framework
src/Webiny/Component/Router/Router.php
Router.match
public function match($url) { if ($this->isString($url)) { $url = $this->url($url); } else { $url = StdObjectWrapper::isUrlObject($url) ? $url : $this->url(''); } // get it from cache if (($result = $this->loadFromCache('match.' . $url->val())) !== false) { return $this->unserialize($result); } // try to match the url $result = $this->urlMatcher->match($url); // cache it $cacheResult = $this->isArray($result) ? $this->serialize($result) : $result; $this->saveToCache('match.' . $url->val(), $cacheResult); return $result; }
php
public function match($url) { if ($this->isString($url)) { $url = $this->url($url); } else { $url = StdObjectWrapper::isUrlObject($url) ? $url : $this->url(''); } // get it from cache if (($result = $this->loadFromCache('match.' . $url->val())) !== false) { return $this->unserialize($result); } // try to match the url $result = $this->urlMatcher->match($url); // cache it $cacheResult = $this->isArray($result) ? $this->serialize($result) : $result; $this->saveToCache('match.' . $url->val(), $cacheResult); return $result; }
[ "public", "function", "match", "(", "$", "url", ")", "{", "if", "(", "$", "this", "->", "isString", "(", "$", "url", ")", ")", "{", "$", "url", "=", "$", "this", "->", "url", "(", "$", "url", ")", ";", "}", "else", "{", "$", "url", "=", "StdObjectWrapper", "::", "isUrlObject", "(", "$", "url", ")", "?", "$", "url", ":", "$", "this", "->", "url", "(", "''", ")", ";", "}", "// get it from cache", "if", "(", "(", "$", "result", "=", "$", "this", "->", "loadFromCache", "(", "'match.'", ".", "$", "url", "->", "val", "(", ")", ")", ")", "!==", "false", ")", "{", "return", "$", "this", "->", "unserialize", "(", "$", "result", ")", ";", "}", "// try to match the url", "$", "result", "=", "$", "this", "->", "urlMatcher", "->", "match", "(", "$", "url", ")", ";", "// cache it", "$", "cacheResult", "=", "$", "this", "->", "isArray", "(", "$", "result", ")", "?", "$", "this", "->", "serialize", "(", "$", "result", ")", ":", "$", "result", ";", "$", "this", "->", "saveToCache", "(", "'match.'", ".", "$", "url", "->", "val", "(", ")", ",", "$", "cacheResult", ")", ";", "return", "$", "result", ";", "}" ]
Tries to match the given url against current RouteCollection. @param string|UrlObject $url Url to match. @return MatchedRoute|bool MatchedRoute instance is returned if url was matched. Otherwise false is returned.
[ "Tries", "to", "match", "the", "given", "url", "against", "current", "RouteCollection", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Router/Router.php#L76-L97
230,031
Webiny/Framework
src/Webiny/Component/Router/Router.php
Router.setCache
public function setCache($cache) { $this->cache = $cache; if ($this->isBool($cache) && $cache === false) { $this->cache = $cache; } else { if (is_object($cache)) { if ($this->isInstanceOf($cache, CacheStorage::class)) { $this->cache = $cache; } else { throw new RouterException('$cache must either be a boolean or instance of ' . CacheStorage::class . '.'); } } else { $this->cache = $this->cache($cache); } } }
php
public function setCache($cache) { $this->cache = $cache; if ($this->isBool($cache) && $cache === false) { $this->cache = $cache; } else { if (is_object($cache)) { if ($this->isInstanceOf($cache, CacheStorage::class)) { $this->cache = $cache; } else { throw new RouterException('$cache must either be a boolean or instance of ' . CacheStorage::class . '.'); } } else { $this->cache = $this->cache($cache); } } }
[ "public", "function", "setCache", "(", "$", "cache", ")", "{", "$", "this", "->", "cache", "=", "$", "cache", ";", "if", "(", "$", "this", "->", "isBool", "(", "$", "cache", ")", "&&", "$", "cache", "===", "false", ")", "{", "$", "this", "->", "cache", "=", "$", "cache", ";", "}", "else", "{", "if", "(", "is_object", "(", "$", "cache", ")", ")", "{", "if", "(", "$", "this", "->", "isInstanceOf", "(", "$", "cache", ",", "CacheStorage", "::", "class", ")", ")", "{", "$", "this", "->", "cache", "=", "$", "cache", ";", "}", "else", "{", "throw", "new", "RouterException", "(", "'$cache must either be a boolean or instance of '", ".", "CacheStorage", "::", "class", ".", "'.'", ")", ";", "}", "}", "else", "{", "$", "this", "->", "cache", "=", "$", "this", "->", "cache", "(", "$", "cache", ")", ";", "}", "}", "}" ]
Sets the cache parameter. If you don't want the Router to cache stuff, pass boolean false. @param bool|CacheStorage|string $cache Cache object, boolean false or name of a registered Cache service. @throws RouterException
[ "Sets", "the", "cache", "parameter", ".", "If", "you", "don", "t", "want", "the", "Router", "to", "cache", "stuff", "pass", "boolean", "false", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Router/Router.php#L182-L198
230,032
Webiny/Framework
src/Webiny/Component/Router/Router.php
Router.appendRoutes
public function appendRoutes(ConfigObject $routes) { /* @var $routeConfig ConfigObject */ foreach ($routes as $name => $routeConfig) { self::$routeCollection->add($name, $this->loader->processRoute($routeConfig)); } return $this; }
php
public function appendRoutes(ConfigObject $routes) { /* @var $routeConfig ConfigObject */ foreach ($routes as $name => $routeConfig) { self::$routeCollection->add($name, $this->loader->processRoute($routeConfig)); } return $this; }
[ "public", "function", "appendRoutes", "(", "ConfigObject", "$", "routes", ")", "{", "/* @var $routeConfig ConfigObject */", "foreach", "(", "$", "routes", "as", "$", "name", "=>", "$", "routeConfig", ")", "{", "self", "::", "$", "routeCollection", "->", "add", "(", "$", "name", ",", "$", "this", "->", "loader", "->", "processRoute", "(", "$", "routeConfig", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Adds a route to the end of the current route collection. @param ConfigObject $routes An instance of ConfigObject holding the routes. @return $this
[ "Adds", "a", "route", "to", "the", "end", "of", "the", "current", "route", "collection", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Router/Router.php#L227-L235
230,033
Webiny/Framework
src/Webiny/Component/Router/Router.php
Router.prependRoutes
public function prependRoutes(ConfigObject $routes) { /* @var $routeConfig ConfigObject */ foreach ($routes as $name => $routeConfig) { self::$routeCollection->prepend($name, $this->loader->processRoute($routeConfig)); } return $this; }
php
public function prependRoutes(ConfigObject $routes) { /* @var $routeConfig ConfigObject */ foreach ($routes as $name => $routeConfig) { self::$routeCollection->prepend($name, $this->loader->processRoute($routeConfig)); } return $this; }
[ "public", "function", "prependRoutes", "(", "ConfigObject", "$", "routes", ")", "{", "/* @var $routeConfig ConfigObject */", "foreach", "(", "$", "routes", "as", "$", "name", "=>", "$", "routeConfig", ")", "{", "self", "::", "$", "routeCollection", "->", "prepend", "(", "$", "name", ",", "$", "this", "->", "loader", "->", "processRoute", "(", "$", "routeConfig", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Adds a route to the beginning of the current route collection. @param ConfigObject $routes An instance of ConfigObject holding the routes. @return $this
[ "Adds", "a", "route", "to", "the", "beginning", "of", "the", "current", "route", "collection", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Router/Router.php#L244-L252
230,034
Webiny/Framework
src/Webiny/Component/Router/Router.php
Router.saveToCache
private function saveToCache($path, $value) { if ($this->getCache()) { $this->getCache()->save(self::CACHE_KEY . md5($path), $value, null, [ '_wf', '_component', '_router' ]); } }
php
private function saveToCache($path, $value) { if ($this->getCache()) { $this->getCache()->save(self::CACHE_KEY . md5($path), $value, null, [ '_wf', '_component', '_router' ]); } }
[ "private", "function", "saveToCache", "(", "$", "path", ",", "$", "value", ")", "{", "if", "(", "$", "this", "->", "getCache", "(", ")", ")", "{", "$", "this", "->", "getCache", "(", ")", "->", "save", "(", "self", "::", "CACHE_KEY", ".", "md5", "(", "$", "path", ")", ",", "$", "value", ",", "null", ",", "[", "'_wf'", ",", "'_component'", ",", "'_router'", "]", ")", ";", "}", "}" ]
Save the given value into cache. @param string $path This is the cache key. @param string $value This is the value that is going to be stored.
[ "Save", "the", "given", "value", "into", "cache", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Router/Router.php#L290-L299
230,035
Webiny/Framework
src/Webiny/Component/Logger/Driver/Webiny/Formatter/AbstractFormatter.php
AbstractFormatter.normalizeValues
public function normalizeValues(Record $record) { foreach ($record as $key => $value) { $setter = 'set' . ucfirst($key); $record->$setter($this->normalizeValue($value)); } }
php
public function normalizeValues(Record $record) { foreach ($record as $key => $value) { $setter = 'set' . ucfirst($key); $record->$setter($this->normalizeValue($value)); } }
[ "public", "function", "normalizeValues", "(", "Record", "$", "record", ")", "{", "foreach", "(", "$", "record", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "setter", "=", "'set'", ".", "ucfirst", "(", "$", "key", ")", ";", "$", "record", "->", "$", "setter", "(", "$", "this", "->", "normalizeValue", "(", "$", "value", ")", ")", ";", "}", "}" ]
Normalize record values, convert objects and resources to string representation, encode arrays to json, etc.
[ "Normalize", "record", "values", "convert", "objects", "and", "resources", "to", "string", "representation", "encode", "arrays", "to", "json", "etc", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Logger/Driver/Webiny/Formatter/AbstractFormatter.php#L27-L34
230,036
alexandresalome/php-webdriver
src/WebDriver/Element.php
Element.moveTo
public function moveTo($x = 0, $y = 0) { $this->browser->moveTo($x, $y, $this); return $this; }
php
public function moveTo($x = 0, $y = 0) { $this->browser->moveTo($x, $y, $this); return $this; }
[ "public", "function", "moveTo", "(", "$", "x", "=", "0", ",", "$", "y", "=", "0", ")", "{", "$", "this", "->", "browser", "->", "moveTo", "(", "$", "x", ",", "$", "y", ",", "$", "this", ")", ";", "return", "$", "this", ";", "}" ]
Moves mouse to the element. @param int $x X offset @param int $y Y offset @return Element
[ "Moves", "mouse", "to", "the", "element", "." ]
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/Element.php#L129-L134
230,037
alexandresalome/php-webdriver
src/WebDriver/Element.php
Element.upload
public function upload($file) { $zip = new Zip(); $zip->addFile($file); $response = $this->browser->request('POST', 'file', json_encode(array('file' => base64_encode($zip->getContent())))); $content = json_decode($response->getContent(), true); if (!isset($content['value'])) { throw new LibraryException('Malformed expression, no key "value" in response: '.$response->getContent()); } $file = $content['value']; $this->type($file); return $file; }
php
public function upload($file) { $zip = new Zip(); $zip->addFile($file); $response = $this->browser->request('POST', 'file', json_encode(array('file' => base64_encode($zip->getContent())))); $content = json_decode($response->getContent(), true); if (!isset($content['value'])) { throw new LibraryException('Malformed expression, no key "value" in response: '.$response->getContent()); } $file = $content['value']; $this->type($file); return $file; }
[ "public", "function", "upload", "(", "$", "file", ")", "{", "$", "zip", "=", "new", "Zip", "(", ")", ";", "$", "zip", "->", "addFile", "(", "$", "file", ")", ";", "$", "response", "=", "$", "this", "->", "browser", "->", "request", "(", "'POST'", ",", "'file'", ",", "json_encode", "(", "array", "(", "'file'", "=>", "base64_encode", "(", "$", "zip", "->", "getContent", "(", ")", ")", ")", ")", ")", ";", "$", "content", "=", "json_decode", "(", "$", "response", "->", "getContent", "(", ")", ",", "true", ")", ";", "if", "(", "!", "isset", "(", "$", "content", "[", "'value'", "]", ")", ")", "{", "throw", "new", "LibraryException", "(", "'Malformed expression, no key \"value\" in response: '", ".", "$", "response", "->", "getContent", "(", ")", ")", ";", "}", "$", "file", "=", "$", "content", "[", "'value'", "]", ";", "$", "this", "->", "type", "(", "$", "file", ")", ";", "return", "$", "file", ";", "}" ]
Uploads a file to the selected field. @param string $file Absolute path to the file @return string Path on server.
[ "Uploads", "a", "file", "to", "the", "selected", "field", "." ]
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/Element.php#L194-L211
230,038
Webiny/Framework
src/Webiny/Component/Image/Bridge/Loader.php
Loader.getImageLoader
public static function getImageLoader(ConfigObject $config) { $lib = self::getLibrary(); /** @var ImageLoaderInterface $libInstance */ $instance = self::factory($lib, ImageLoaderInterface::class, [$config]); if (!self::isInstanceOf($instance, ImageLoaderInterface::class)) { throw new ImageException('The message library must implement "' . ImageLoaderInterface::class . '".'); } return $instance; }
php
public static function getImageLoader(ConfigObject $config) { $lib = self::getLibrary(); /** @var ImageLoaderInterface $libInstance */ $instance = self::factory($lib, ImageLoaderInterface::class, [$config]); if (!self::isInstanceOf($instance, ImageLoaderInterface::class)) { throw new ImageException('The message library must implement "' . ImageLoaderInterface::class . '".'); } return $instance; }
[ "public", "static", "function", "getImageLoader", "(", "ConfigObject", "$", "config", ")", "{", "$", "lib", "=", "self", "::", "getLibrary", "(", ")", ";", "/** @var ImageLoaderInterface $libInstance */", "$", "instance", "=", "self", "::", "factory", "(", "$", "lib", ",", "ImageLoaderInterface", "::", "class", ",", "[", "$", "config", "]", ")", ";", "if", "(", "!", "self", "::", "isInstanceOf", "(", "$", "instance", ",", "ImageLoaderInterface", "::", "class", ")", ")", "{", "throw", "new", "ImageException", "(", "'The message library must implement \"'", ".", "ImageLoaderInterface", "::", "class", ".", "'\".'", ")", ";", "}", "return", "$", "instance", ";", "}" ]
Returns an instance of ImageLoaderInterface based on current bridge. @param ConfigObject $config @throws ImageException @return \Webiny\Component\Image\Bridge\ImageLoaderInterface
[ "Returns", "an", "instance", "of", "ImageLoaderInterface", "based", "on", "current", "bridge", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Image/Bridge/Loader.php#L40-L52
230,039
takatost/wechat_open_platform
src/Foundation/WechatOpenApplication.php
WechatOpenApplication.app
public function app($appConfig) { $appConfig = array_merge( $this['config']->only(['debug', 'log', 'guzzle']), $appConfig ); $appConfig['cache'] = $this['config']['cache']; return new Application($this['open_platform'], $this['config'], $appConfig); }
php
public function app($appConfig) { $appConfig = array_merge( $this['config']->only(['debug', 'log', 'guzzle']), $appConfig ); $appConfig['cache'] = $this['config']['cache']; return new Application($this['open_platform'], $this['config'], $appConfig); }
[ "public", "function", "app", "(", "$", "appConfig", ")", "{", "$", "appConfig", "=", "array_merge", "(", "$", "this", "[", "'config'", "]", "->", "only", "(", "[", "'debug'", ",", "'log'", ",", "'guzzle'", "]", ")", ",", "$", "appConfig", ")", ";", "$", "appConfig", "[", "'cache'", "]", "=", "$", "this", "[", "'config'", "]", "[", "'cache'", "]", ";", "return", "new", "Application", "(", "$", "this", "[", "'open_platform'", "]", ",", "$", "this", "[", "'config'", "]", ",", "$", "appConfig", ")", ";", "}" ]
Get Wechat App @param $appConfig @return Application
[ "Get", "Wechat", "App" ]
e3173f529236f6203a0d8f85ee20f4486183a85e
https://github.com/takatost/wechat_open_platform/blob/e3173f529236f6203a0d8f85ee20f4486183a85e/src/Foundation/WechatOpenApplication.php#L103-L113
230,040
takatost/wechat_open_platform
src/Foundation/WechatOpenApplication.php
WechatOpenApplication.registerCache
protected function registerCache($cacheConfig) { switch ($cacheConfig['driver']) { case 'filesystem': $cacheDriver = new FilesystemCache($cacheConfig['dir']); break; default: $cacheDriver = new FilesystemCache(sys_get_temp_dir()); } return $cacheDriver; }
php
protected function registerCache($cacheConfig) { switch ($cacheConfig['driver']) { case 'filesystem': $cacheDriver = new FilesystemCache($cacheConfig['dir']); break; default: $cacheDriver = new FilesystemCache(sys_get_temp_dir()); } return $cacheDriver; }
[ "protected", "function", "registerCache", "(", "$", "cacheConfig", ")", "{", "switch", "(", "$", "cacheConfig", "[", "'driver'", "]", ")", "{", "case", "'filesystem'", ":", "$", "cacheDriver", "=", "new", "FilesystemCache", "(", "$", "cacheConfig", "[", "'dir'", "]", ")", ";", "break", ";", "default", ":", "$", "cacheDriver", "=", "new", "FilesystemCache", "(", "sys_get_temp_dir", "(", ")", ")", ";", "}", "return", "$", "cacheDriver", ";", "}" ]
Register Cache Driver @param $cacheConfig @return CacheInterface
[ "Register", "Cache", "Driver" ]
e3173f529236f6203a0d8f85ee20f4486183a85e
https://github.com/takatost/wechat_open_platform/blob/e3173f529236f6203a0d8f85ee20f4486183a85e/src/Foundation/WechatOpenApplication.php#L255-L266
230,041
milesj/admin
Controller/Component/AdminToolbarComponent.php
AdminToolbarComponent.startup
public function startup(Controller $controller) { $this->Controller = $controller; // Thrown an exception if accessing an override action without requestAction() if (substr($controller->action, 0, 6) === 'admin_' && empty($controller->request->params['override'])) { throw new ForbiddenException(); } // Set ACL session $user_id = $this->Auth->user('id'); if (!$user_id || $this->Auth->user(Configure::read('User.fieldMap.status')) == Configure::read('User.statusMap.banned')) { return; } if (!$this->Session->check('Acl')) { $roles = ClassRegistry::init('Admin.RequestObject')->getRoles($user_id); $isAdmin = false; $isSuper = false; $roleMap = array(); foreach ($roles as $role) { if (!$isAdmin && $role['RequestObject']['alias'] == Configure::read('Admin.aliases.administrator')) { $isAdmin = true; } if (!$isSuper && $role['RequestObject']['alias'] == Configure::read('Admin.aliases.superModerator')) { $isSuper = true; } $roleMap[$role['RequestObject']['id']] = $role['RequestObject']['alias']; } $this->Session->write('Acl.isAdmin', $isAdmin); $this->Session->write('Acl.isSuper', $isSuper); $this->Session->write('Acl.roles', $roleMap); } // Set reported count if (Configure::read('Admin.menu.reports')) { Configure::write('Admin.menu.reports.count', Admin::introspectModel('Admin.ItemReport')->getCountByStatus()); } }
php
public function startup(Controller $controller) { $this->Controller = $controller; // Thrown an exception if accessing an override action without requestAction() if (substr($controller->action, 0, 6) === 'admin_' && empty($controller->request->params['override'])) { throw new ForbiddenException(); } // Set ACL session $user_id = $this->Auth->user('id'); if (!$user_id || $this->Auth->user(Configure::read('User.fieldMap.status')) == Configure::read('User.statusMap.banned')) { return; } if (!$this->Session->check('Acl')) { $roles = ClassRegistry::init('Admin.RequestObject')->getRoles($user_id); $isAdmin = false; $isSuper = false; $roleMap = array(); foreach ($roles as $role) { if (!$isAdmin && $role['RequestObject']['alias'] == Configure::read('Admin.aliases.administrator')) { $isAdmin = true; } if (!$isSuper && $role['RequestObject']['alias'] == Configure::read('Admin.aliases.superModerator')) { $isSuper = true; } $roleMap[$role['RequestObject']['id']] = $role['RequestObject']['alias']; } $this->Session->write('Acl.isAdmin', $isAdmin); $this->Session->write('Acl.isSuper', $isSuper); $this->Session->write('Acl.roles', $roleMap); } // Set reported count if (Configure::read('Admin.menu.reports')) { Configure::write('Admin.menu.reports.count', Admin::introspectModel('Admin.ItemReport')->getCountByStatus()); } }
[ "public", "function", "startup", "(", "Controller", "$", "controller", ")", "{", "$", "this", "->", "Controller", "=", "$", "controller", ";", "// Thrown an exception if accessing an override action without requestAction()", "if", "(", "substr", "(", "$", "controller", "->", "action", ",", "0", ",", "6", ")", "===", "'admin_'", "&&", "empty", "(", "$", "controller", "->", "request", "->", "params", "[", "'override'", "]", ")", ")", "{", "throw", "new", "ForbiddenException", "(", ")", ";", "}", "// Set ACL session", "$", "user_id", "=", "$", "this", "->", "Auth", "->", "user", "(", "'id'", ")", ";", "if", "(", "!", "$", "user_id", "||", "$", "this", "->", "Auth", "->", "user", "(", "Configure", "::", "read", "(", "'User.fieldMap.status'", ")", ")", "==", "Configure", "::", "read", "(", "'User.statusMap.banned'", ")", ")", "{", "return", ";", "}", "if", "(", "!", "$", "this", "->", "Session", "->", "check", "(", "'Acl'", ")", ")", "{", "$", "roles", "=", "ClassRegistry", "::", "init", "(", "'Admin.RequestObject'", ")", "->", "getRoles", "(", "$", "user_id", ")", ";", "$", "isAdmin", "=", "false", ";", "$", "isSuper", "=", "false", ";", "$", "roleMap", "=", "array", "(", ")", ";", "foreach", "(", "$", "roles", "as", "$", "role", ")", "{", "if", "(", "!", "$", "isAdmin", "&&", "$", "role", "[", "'RequestObject'", "]", "[", "'alias'", "]", "==", "Configure", "::", "read", "(", "'Admin.aliases.administrator'", ")", ")", "{", "$", "isAdmin", "=", "true", ";", "}", "if", "(", "!", "$", "isSuper", "&&", "$", "role", "[", "'RequestObject'", "]", "[", "'alias'", "]", "==", "Configure", "::", "read", "(", "'Admin.aliases.superModerator'", ")", ")", "{", "$", "isSuper", "=", "true", ";", "}", "$", "roleMap", "[", "$", "role", "[", "'RequestObject'", "]", "[", "'id'", "]", "]", "=", "$", "role", "[", "'RequestObject'", "]", "[", "'alias'", "]", ";", "}", "$", "this", "->", "Session", "->", "write", "(", "'Acl.isAdmin'", ",", "$", "isAdmin", ")", ";", "$", "this", "->", "Session", "->", "write", "(", "'Acl.isSuper'", ",", "$", "isSuper", ")", ";", "$", "this", "->", "Session", "->", "write", "(", "'Acl.roles'", ",", "$", "roleMap", ")", ";", "}", "// Set reported count", "if", "(", "Configure", "::", "read", "(", "'Admin.menu.reports'", ")", ")", "{", "Configure", "::", "write", "(", "'Admin.menu.reports.count'", ",", "Admin", "::", "introspectModel", "(", "'Admin.ItemReport'", ")", "->", "getCountByStatus", "(", ")", ")", ";", "}", "}" ]
Store the controller. @param Controller $controller @throws ForbiddenException
[ "Store", "the", "controller", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/Component/AdminToolbarComponent.php#L30-L72
230,042
milesj/admin
Controller/Component/AdminToolbarComponent.php
AdminToolbarComponent.beforeRender
public function beforeRender(Controller $controller) { $badges = array(); foreach (Configure::read('Admin.menu') as $section => $menu) { $badges[$section] = $menu['count']; } $controller->set('badgeCounts', $badges); if (isset($controller->Model)) { $controller->set('model', $controller->Model); } if (isset($controller->request->params['override'])) { $controller->layout = 'Admin.admin'; $controller->request->params['action'] = str_replace('admin_', '', $controller->action); } }
php
public function beforeRender(Controller $controller) { $badges = array(); foreach (Configure::read('Admin.menu') as $section => $menu) { $badges[$section] = $menu['count']; } $controller->set('badgeCounts', $badges); if (isset($controller->Model)) { $controller->set('model', $controller->Model); } if (isset($controller->request->params['override'])) { $controller->layout = 'Admin.admin'; $controller->request->params['action'] = str_replace('admin_', '', $controller->action); } }
[ "public", "function", "beforeRender", "(", "Controller", "$", "controller", ")", "{", "$", "badges", "=", "array", "(", ")", ";", "foreach", "(", "Configure", "::", "read", "(", "'Admin.menu'", ")", "as", "$", "section", "=>", "$", "menu", ")", "{", "$", "badges", "[", "$", "section", "]", "=", "$", "menu", "[", "'count'", "]", ";", "}", "$", "controller", "->", "set", "(", "'badgeCounts'", ",", "$", "badges", ")", ";", "if", "(", "isset", "(", "$", "controller", "->", "Model", ")", ")", "{", "$", "controller", "->", "set", "(", "'model'", ",", "$", "controller", "->", "Model", ")", ";", "}", "if", "(", "isset", "(", "$", "controller", "->", "request", "->", "params", "[", "'override'", "]", ")", ")", "{", "$", "controller", "->", "layout", "=", "'Admin.admin'", ";", "$", "controller", "->", "request", "->", "params", "[", "'action'", "]", "=", "str_replace", "(", "'admin_'", ",", "''", ",", "$", "controller", "->", "action", ")", ";", "}", "}" ]
An action or view is being overridden, so prepare the layout and environment. Bind any other data that should be present. @param Controller $controller
[ "An", "action", "or", "view", "is", "being", "overridden", "so", "prepare", "the", "layout", "and", "environment", ".", "Bind", "any", "other", "data", "that", "should", "be", "present", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/Component/AdminToolbarComponent.php#L80-L97
230,043
milesj/admin
Controller/Component/AdminToolbarComponent.php
AdminToolbarComponent.getDeepRelations
public function getDeepRelations(Model $model, $extended = true) { $contain = array_keys($model->belongsTo); $contain = array_merge($contain, array_keys($model->hasAndBelongsToMany)); if ($extended) { foreach (array($model->hasOne, $model->hasMany) as $assocs) { foreach ($assocs as $alias => $assoc) { $contain[$alias] = array_keys($model->{$alias}->belongsTo); } } } return $contain; }
php
public function getDeepRelations(Model $model, $extended = true) { $contain = array_keys($model->belongsTo); $contain = array_merge($contain, array_keys($model->hasAndBelongsToMany)); if ($extended) { foreach (array($model->hasOne, $model->hasMany) as $assocs) { foreach ($assocs as $alias => $assoc) { $contain[$alias] = array_keys($model->{$alias}->belongsTo); } } } return $contain; }
[ "public", "function", "getDeepRelations", "(", "Model", "$", "model", ",", "$", "extended", "=", "true", ")", "{", "$", "contain", "=", "array_keys", "(", "$", "model", "->", "belongsTo", ")", ";", "$", "contain", "=", "array_merge", "(", "$", "contain", ",", "array_keys", "(", "$", "model", "->", "hasAndBelongsToMany", ")", ")", ";", "if", "(", "$", "extended", ")", "{", "foreach", "(", "array", "(", "$", "model", "->", "hasOne", ",", "$", "model", "->", "hasMany", ")", "as", "$", "assocs", ")", "{", "foreach", "(", "$", "assocs", "as", "$", "alias", "=>", "$", "assoc", ")", "{", "$", "contain", "[", "$", "alias", "]", "=", "array_keys", "(", "$", "model", "->", "{", "$", "alias", "}", "->", "belongsTo", ")", ";", "}", "}", "}", "return", "$", "contain", ";", "}" ]
Get a list of valid containable model relations. Should also get belongsTo data for hasOne and hasMany. @param Model $model @param bool $extended @return array
[ "Get", "a", "list", "of", "valid", "containable", "model", "relations", ".", "Should", "also", "get", "belongsTo", "data", "for", "hasOne", "and", "hasMany", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/Component/AdminToolbarComponent.php#L107-L120
230,044
milesj/admin
Controller/Component/AdminToolbarComponent.php
AdminToolbarComponent.getRecordById
public function getRecordById(Model $model, $id, $deepRelation = true) { $model->id = $id; $data = $model->find('first', array( 'conditions' => array($model->alias . '.' . $model->primaryKey => $id), 'contain' => $this->getDeepRelations($model, $deepRelation) )); if ($data) { $model->set($data); } return $data; }
php
public function getRecordById(Model $model, $id, $deepRelation = true) { $model->id = $id; $data = $model->find('first', array( 'conditions' => array($model->alias . '.' . $model->primaryKey => $id), 'contain' => $this->getDeepRelations($model, $deepRelation) )); if ($data) { $model->set($data); } return $data; }
[ "public", "function", "getRecordById", "(", "Model", "$", "model", ",", "$", "id", ",", "$", "deepRelation", "=", "true", ")", "{", "$", "model", "->", "id", "=", "$", "id", ";", "$", "data", "=", "$", "model", "->", "find", "(", "'first'", ",", "array", "(", "'conditions'", "=>", "array", "(", "$", "model", "->", "alias", ".", "'.'", ".", "$", "model", "->", "primaryKey", "=>", "$", "id", ")", ",", "'contain'", "=>", "$", "this", "->", "getDeepRelations", "(", "$", "model", ",", "$", "deepRelation", ")", ")", ")", ";", "if", "(", "$", "data", ")", "{", "$", "model", "->", "set", "(", "$", "data", ")", ";", "}", "return", "$", "data", ";", "}" ]
Return a record based on ID. @param Model $model @param int $id @param bool $deepRelation @return array
[ "Return", "a", "record", "based", "on", "ID", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/Component/AdminToolbarComponent.php#L130-L143
230,045
milesj/admin
Controller/Component/AdminToolbarComponent.php
AdminToolbarComponent.getRecordList
public function getRecordList(Model $model) { if ($model->hasMethod('generateTreeList')) { return $model->generateTreeList(null, null, null, ' -- '); } else if ($model->hasMethod('getList')) { return $model->getList(); } return $model->find('list', array( 'order' => array($model->alias . '.' . $model->displayField => 'ASC') )); }
php
public function getRecordList(Model $model) { if ($model->hasMethod('generateTreeList')) { return $model->generateTreeList(null, null, null, ' -- '); } else if ($model->hasMethod('getList')) { return $model->getList(); } return $model->find('list', array( 'order' => array($model->alias . '.' . $model->displayField => 'ASC') )); }
[ "public", "function", "getRecordList", "(", "Model", "$", "model", ")", "{", "if", "(", "$", "model", "->", "hasMethod", "(", "'generateTreeList'", ")", ")", "{", "return", "$", "model", "->", "generateTreeList", "(", "null", ",", "null", ",", "null", ",", "' -- '", ")", ";", "}", "else", "if", "(", "$", "model", "->", "hasMethod", "(", "'getList'", ")", ")", "{", "return", "$", "model", "->", "getList", "(", ")", ";", "}", "return", "$", "model", "->", "find", "(", "'list'", ",", "array", "(", "'order'", "=>", "array", "(", "$", "model", "->", "alias", ".", "'.'", ".", "$", "model", "->", "displayField", "=>", "'ASC'", ")", ")", ")", ";", "}" ]
Return a list of records. If a certain method exists, use it. @param Model $model @return array
[ "Return", "a", "list", "of", "records", ".", "If", "a", "certain", "method", "exists", "use", "it", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/Component/AdminToolbarComponent.php#L151-L162
230,046
milesj/admin
Controller/Component/AdminToolbarComponent.php
AdminToolbarComponent.getRequestData
public function getRequestData() { $data = $this->Controller->request->data; if ($data) { foreach ($data as $model => $fields) { foreach ($fields as $key => $value) { if ( (mb_substr($key, -5) === '_null') || (mb_substr($key, -11) === '_type_ahead') || in_array($key, array('redirect_to', 'log_comment', 'report_action')) ) { unset($data[$model][$key]); } } } } return $data; }
php
public function getRequestData() { $data = $this->Controller->request->data; if ($data) { foreach ($data as $model => $fields) { foreach ($fields as $key => $value) { if ( (mb_substr($key, -5) === '_null') || (mb_substr($key, -11) === '_type_ahead') || in_array($key, array('redirect_to', 'log_comment', 'report_action')) ) { unset($data[$model][$key]); } } } } return $data; }
[ "public", "function", "getRequestData", "(", ")", "{", "$", "data", "=", "$", "this", "->", "Controller", "->", "request", "->", "data", ";", "if", "(", "$", "data", ")", "{", "foreach", "(", "$", "data", "as", "$", "model", "=>", "$", "fields", ")", "{", "foreach", "(", "$", "fields", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "(", "mb_substr", "(", "$", "key", ",", "-", "5", ")", "===", "'_null'", ")", "||", "(", "mb_substr", "(", "$", "key", ",", "-", "11", ")", "===", "'_type_ahead'", ")", "||", "in_array", "(", "$", "key", ",", "array", "(", "'redirect_to'", ",", "'log_comment'", ",", "'report_action'", ")", ")", ")", "{", "unset", "(", "$", "data", "[", "$", "model", "]", "[", "$", "key", "]", ")", ";", "}", "}", "}", "}", "return", "$", "data", ";", "}" ]
Return the request data after processing the fields. @return array
[ "Return", "the", "request", "data", "after", "processing", "the", "fields", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/Component/AdminToolbarComponent.php#L183-L201
230,047
milesj/admin
Controller/Component/AdminToolbarComponent.php
AdminToolbarComponent.logAction
public function logAction($action, Model $model = null, $id = null, $comment = null, $item = null) { if (!Configure::read('Admin.logActions')) { return false; } $log = ClassRegistry::init('Admin.ActionLog'); $query = array( 'user_id' => $this->Auth->user('id'), 'action' => $action ); // Validate action if (!$log->enum('action', $action)) { throw new InvalidArgumentException(__d('admin', 'Invalid log action type')); } if ($model) { $query['model'] = ($model->plugin ? $model->plugin . '.' : '') . $model->name; // Get comment from request if (!$comment && isset($this->Controller->request->data[$model->alias]['log_comment'])) { $comment = $this->Controller->request->data[$model->alias]['log_comment']; } // Get display field from data if (!$item) { if (isset($model->data[$model->alias][$model->displayField])) { $item = $model->data[$model->alias][$model->displayField]; } } } $query['foreign_key'] = (string) $id; $query['comment'] = $comment; $query['item'] = $item; return $log->logAction($query); }
php
public function logAction($action, Model $model = null, $id = null, $comment = null, $item = null) { if (!Configure::read('Admin.logActions')) { return false; } $log = ClassRegistry::init('Admin.ActionLog'); $query = array( 'user_id' => $this->Auth->user('id'), 'action' => $action ); // Validate action if (!$log->enum('action', $action)) { throw new InvalidArgumentException(__d('admin', 'Invalid log action type')); } if ($model) { $query['model'] = ($model->plugin ? $model->plugin . '.' : '') . $model->name; // Get comment from request if (!$comment && isset($this->Controller->request->data[$model->alias]['log_comment'])) { $comment = $this->Controller->request->data[$model->alias]['log_comment']; } // Get display field from data if (!$item) { if (isset($model->data[$model->alias][$model->displayField])) { $item = $model->data[$model->alias][$model->displayField]; } } } $query['foreign_key'] = (string) $id; $query['comment'] = $comment; $query['item'] = $item; return $log->logAction($query); }
[ "public", "function", "logAction", "(", "$", "action", ",", "Model", "$", "model", "=", "null", ",", "$", "id", "=", "null", ",", "$", "comment", "=", "null", ",", "$", "item", "=", "null", ")", "{", "if", "(", "!", "Configure", "::", "read", "(", "'Admin.logActions'", ")", ")", "{", "return", "false", ";", "}", "$", "log", "=", "ClassRegistry", "::", "init", "(", "'Admin.ActionLog'", ")", ";", "$", "query", "=", "array", "(", "'user_id'", "=>", "$", "this", "->", "Auth", "->", "user", "(", "'id'", ")", ",", "'action'", "=>", "$", "action", ")", ";", "// Validate action", "if", "(", "!", "$", "log", "->", "enum", "(", "'action'", ",", "$", "action", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "__d", "(", "'admin'", ",", "'Invalid log action type'", ")", ")", ";", "}", "if", "(", "$", "model", ")", "{", "$", "query", "[", "'model'", "]", "=", "(", "$", "model", "->", "plugin", "?", "$", "model", "->", "plugin", ".", "'.'", ":", "''", ")", ".", "$", "model", "->", "name", ";", "// Get comment from request", "if", "(", "!", "$", "comment", "&&", "isset", "(", "$", "this", "->", "Controller", "->", "request", "->", "data", "[", "$", "model", "->", "alias", "]", "[", "'log_comment'", "]", ")", ")", "{", "$", "comment", "=", "$", "this", "->", "Controller", "->", "request", "->", "data", "[", "$", "model", "->", "alias", "]", "[", "'log_comment'", "]", ";", "}", "// Get display field from data", "if", "(", "!", "$", "item", ")", "{", "if", "(", "isset", "(", "$", "model", "->", "data", "[", "$", "model", "->", "alias", "]", "[", "$", "model", "->", "displayField", "]", ")", ")", "{", "$", "item", "=", "$", "model", "->", "data", "[", "$", "model", "->", "alias", "]", "[", "$", "model", "->", "displayField", "]", ";", "}", "}", "}", "$", "query", "[", "'foreign_key'", "]", "=", "(", "string", ")", "$", "id", ";", "$", "query", "[", "'comment'", "]", "=", "$", "comment", ";", "$", "query", "[", "'item'", "]", "=", "$", "item", ";", "return", "$", "log", "->", "logAction", "(", "$", "query", ")", ";", "}" ]
Log a users action. @param int $action @param Model $model @param int $id @param string $comment @param string $item @return bool @throws InvalidArgumentException
[ "Log", "a", "users", "action", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/Component/AdminToolbarComponent.php#L227-L264
230,048
milesj/admin
Controller/Component/AdminToolbarComponent.php
AdminToolbarComponent.parseFilterConditions
public function parseFilterConditions(Model $model, $data) { $conditions = array(); $fields = $model->fields; $alias = $model->alias; $enum = $model->enum; foreach ($data as $key => $value) { if (mb_substr($key, -7) === '_filter' || mb_substr($key, -11) === '_type_ahead') { $data[$key] = urldecode($value); continue; } else if (!isset($fields[$key])) { continue; } $field = $fields[$key]; $value = urldecode($value); // Dates, times, numbers if (isset($data[$key . '_filter'])) { $operator = $data[$key . '_filter']; $operator = ($operator === '=') ? '' : ' ' . $operator; if ($field['type'] === 'datetime') { $value = date('Y-m-d H:i:s', strtotime($value)); } else if ($field['type'] === 'date') { $value = date('Y-m-d', strtotime($value)); } else if ($field['type'] === 'time') { $value = date('H:i:s', strtotime($value)); } $conditions[$alias . '.' . $key . $operator] = $value; // Enums, booleans, relations } else if (isset($enum[$key]) || $field['type'] === 'boolean' || !empty($field['belongsTo'])) { $conditions[$alias . '.' . $key] = $value; // Strings } else { $conditions[$alias . '.' . $key . ' LIKE'] = '%' . $value . '%'; } } // Set data to use in form if (isset($this->Controller->request->data[$model->alias])) { $data = array_merge($this->Controller->request->data[$model->alias], $data); } $this->Controller->request->data[$model->alias] = $data; return $conditions; }
php
public function parseFilterConditions(Model $model, $data) { $conditions = array(); $fields = $model->fields; $alias = $model->alias; $enum = $model->enum; foreach ($data as $key => $value) { if (mb_substr($key, -7) === '_filter' || mb_substr($key, -11) === '_type_ahead') { $data[$key] = urldecode($value); continue; } else if (!isset($fields[$key])) { continue; } $field = $fields[$key]; $value = urldecode($value); // Dates, times, numbers if (isset($data[$key . '_filter'])) { $operator = $data[$key . '_filter']; $operator = ($operator === '=') ? '' : ' ' . $operator; if ($field['type'] === 'datetime') { $value = date('Y-m-d H:i:s', strtotime($value)); } else if ($field['type'] === 'date') { $value = date('Y-m-d', strtotime($value)); } else if ($field['type'] === 'time') { $value = date('H:i:s', strtotime($value)); } $conditions[$alias . '.' . $key . $operator] = $value; // Enums, booleans, relations } else if (isset($enum[$key]) || $field['type'] === 'boolean' || !empty($field['belongsTo'])) { $conditions[$alias . '.' . $key] = $value; // Strings } else { $conditions[$alias . '.' . $key . ' LIKE'] = '%' . $value . '%'; } } // Set data to use in form if (isset($this->Controller->request->data[$model->alias])) { $data = array_merge($this->Controller->request->data[$model->alias], $data); } $this->Controller->request->data[$model->alias] = $data; return $conditions; }
[ "public", "function", "parseFilterConditions", "(", "Model", "$", "model", ",", "$", "data", ")", "{", "$", "conditions", "=", "array", "(", ")", ";", "$", "fields", "=", "$", "model", "->", "fields", ";", "$", "alias", "=", "$", "model", "->", "alias", ";", "$", "enum", "=", "$", "model", "->", "enum", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "mb_substr", "(", "$", "key", ",", "-", "7", ")", "===", "'_filter'", "||", "mb_substr", "(", "$", "key", ",", "-", "11", ")", "===", "'_type_ahead'", ")", "{", "$", "data", "[", "$", "key", "]", "=", "urldecode", "(", "$", "value", ")", ";", "continue", ";", "}", "else", "if", "(", "!", "isset", "(", "$", "fields", "[", "$", "key", "]", ")", ")", "{", "continue", ";", "}", "$", "field", "=", "$", "fields", "[", "$", "key", "]", ";", "$", "value", "=", "urldecode", "(", "$", "value", ")", ";", "// Dates, times, numbers", "if", "(", "isset", "(", "$", "data", "[", "$", "key", ".", "'_filter'", "]", ")", ")", "{", "$", "operator", "=", "$", "data", "[", "$", "key", ".", "'_filter'", "]", ";", "$", "operator", "=", "(", "$", "operator", "===", "'='", ")", "?", "''", ":", "' '", ".", "$", "operator", ";", "if", "(", "$", "field", "[", "'type'", "]", "===", "'datetime'", ")", "{", "$", "value", "=", "date", "(", "'Y-m-d H:i:s'", ",", "strtotime", "(", "$", "value", ")", ")", ";", "}", "else", "if", "(", "$", "field", "[", "'type'", "]", "===", "'date'", ")", "{", "$", "value", "=", "date", "(", "'Y-m-d'", ",", "strtotime", "(", "$", "value", ")", ")", ";", "}", "else", "if", "(", "$", "field", "[", "'type'", "]", "===", "'time'", ")", "{", "$", "value", "=", "date", "(", "'H:i:s'", ",", "strtotime", "(", "$", "value", ")", ")", ";", "}", "$", "conditions", "[", "$", "alias", ".", "'.'", ".", "$", "key", ".", "$", "operator", "]", "=", "$", "value", ";", "// Enums, booleans, relations", "}", "else", "if", "(", "isset", "(", "$", "enum", "[", "$", "key", "]", ")", "||", "$", "field", "[", "'type'", "]", "===", "'boolean'", "||", "!", "empty", "(", "$", "field", "[", "'belongsTo'", "]", ")", ")", "{", "$", "conditions", "[", "$", "alias", ".", "'.'", ".", "$", "key", "]", "=", "$", "value", ";", "// Strings", "}", "else", "{", "$", "conditions", "[", "$", "alias", ".", "'.'", ".", "$", "key", ".", "' LIKE'", "]", "=", "'%'", ".", "$", "value", ".", "'%'", ";", "}", "}", "// Set data to use in form", "if", "(", "isset", "(", "$", "this", "->", "Controller", "->", "request", "->", "data", "[", "$", "model", "->", "alias", "]", ")", ")", "{", "$", "data", "=", "array_merge", "(", "$", "this", "->", "Controller", "->", "request", "->", "data", "[", "$", "model", "->", "alias", "]", ",", "$", "data", ")", ";", "}", "$", "this", "->", "Controller", "->", "request", "->", "data", "[", "$", "model", "->", "alias", "]", "=", "$", "data", ";", "return", "$", "conditions", ";", "}" ]
Parse the request into an array of filtering SQL conditions. @param Model $model @param array $data @return array
[ "Parse", "the", "request", "into", "an", "array", "of", "filtering", "SQL", "conditions", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/Component/AdminToolbarComponent.php#L273-L326
230,049
milesj/admin
Controller/Component/AdminToolbarComponent.php
AdminToolbarComponent.redirectAfter
public function redirectAfter(Model $model, $action = null) { if (!$action) { $action = $this->Controller->request->data[$model->alias]['redirect_to']; } if ($action === 'parent') { $parentName = $this->Controller->request->data[$model->alias]['redirect_to_model']; $className = $model->belongsTo[$parentName]['className']; $foreignKey = $model->belongsTo[$parentName]['foreignKey']; $id = !empty($this->Controller->request->data[$model->alias][$foreignKey]) ? $this->Controller->request->data[$model->alias][$foreignKey] : null; $foreignModel = Admin::introspectModel($className); $url = array('plugin' => 'admin', 'controller' => 'crud', 'action' => $id ? 'read' : 'index', $id, 'model' => $foreignModel->urlSlug); } else { $url = array('plugin' => 'admin', 'controller' => 'crud', 'action' => $action, 'model' => $model->urlSlug); switch ($action) { case 'read': case 'update': case 'delete': $url[] = $model->id; break; } } $this->Controller->redirect($url); }
php
public function redirectAfter(Model $model, $action = null) { if (!$action) { $action = $this->Controller->request->data[$model->alias]['redirect_to']; } if ($action === 'parent') { $parentName = $this->Controller->request->data[$model->alias]['redirect_to_model']; $className = $model->belongsTo[$parentName]['className']; $foreignKey = $model->belongsTo[$parentName]['foreignKey']; $id = !empty($this->Controller->request->data[$model->alias][$foreignKey]) ? $this->Controller->request->data[$model->alias][$foreignKey] : null; $foreignModel = Admin::introspectModel($className); $url = array('plugin' => 'admin', 'controller' => 'crud', 'action' => $id ? 'read' : 'index', $id, 'model' => $foreignModel->urlSlug); } else { $url = array('plugin' => 'admin', 'controller' => 'crud', 'action' => $action, 'model' => $model->urlSlug); switch ($action) { case 'read': case 'update': case 'delete': $url[] = $model->id; break; } } $this->Controller->redirect($url); }
[ "public", "function", "redirectAfter", "(", "Model", "$", "model", ",", "$", "action", "=", "null", ")", "{", "if", "(", "!", "$", "action", ")", "{", "$", "action", "=", "$", "this", "->", "Controller", "->", "request", "->", "data", "[", "$", "model", "->", "alias", "]", "[", "'redirect_to'", "]", ";", "}", "if", "(", "$", "action", "===", "'parent'", ")", "{", "$", "parentName", "=", "$", "this", "->", "Controller", "->", "request", "->", "data", "[", "$", "model", "->", "alias", "]", "[", "'redirect_to_model'", "]", ";", "$", "className", "=", "$", "model", "->", "belongsTo", "[", "$", "parentName", "]", "[", "'className'", "]", ";", "$", "foreignKey", "=", "$", "model", "->", "belongsTo", "[", "$", "parentName", "]", "[", "'foreignKey'", "]", ";", "$", "id", "=", "!", "empty", "(", "$", "this", "->", "Controller", "->", "request", "->", "data", "[", "$", "model", "->", "alias", "]", "[", "$", "foreignKey", "]", ")", "?", "$", "this", "->", "Controller", "->", "request", "->", "data", "[", "$", "model", "->", "alias", "]", "[", "$", "foreignKey", "]", ":", "null", ";", "$", "foreignModel", "=", "Admin", "::", "introspectModel", "(", "$", "className", ")", ";", "$", "url", "=", "array", "(", "'plugin'", "=>", "'admin'", ",", "'controller'", "=>", "'crud'", ",", "'action'", "=>", "$", "id", "?", "'read'", ":", "'index'", ",", "$", "id", ",", "'model'", "=>", "$", "foreignModel", "->", "urlSlug", ")", ";", "}", "else", "{", "$", "url", "=", "array", "(", "'plugin'", "=>", "'admin'", ",", "'controller'", "=>", "'crud'", ",", "'action'", "=>", "$", "action", ",", "'model'", "=>", "$", "model", "->", "urlSlug", ")", ";", "switch", "(", "$", "action", ")", "{", "case", "'read'", ":", "case", "'update'", ":", "case", "'delete'", ":", "$", "url", "[", "]", "=", "$", "model", "->", "id", ";", "break", ";", "}", "}", "$", "this", "->", "Controller", "->", "redirect", "(", "$", "url", ")", ";", "}" ]
Redirect after a create or update. @param Model $model @param string $action
[ "Redirect", "after", "a", "create", "or", "update", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/Component/AdminToolbarComponent.php#L334-L361
230,050
milesj/admin
Controller/Component/AdminToolbarComponent.php
AdminToolbarComponent.searchTypeAhead
public function searchTypeAhead(Model $model, array $query) { if ($model->hasMethod('searchTypeAhead')) { return $model->searchTypeAhead($query); } $keyword = $query['term']; unset($query['term']); $results = $model->find('all', array( 'conditions' => array($model->alias . '.' . $model->displayField . ' LIKE' => '%' . $keyword . '%') + $query, 'order' => array($model->alias . '.' . $model->displayField => 'ASC'), 'contain' => false )); $data = array(); foreach ($results as $result) { $data[] = array( 'id' => $result[$model->alias][$model->primaryKey], 'title' => $result[$model->alias][$model->displayField] ); } return $data; }
php
public function searchTypeAhead(Model $model, array $query) { if ($model->hasMethod('searchTypeAhead')) { return $model->searchTypeAhead($query); } $keyword = $query['term']; unset($query['term']); $results = $model->find('all', array( 'conditions' => array($model->alias . '.' . $model->displayField . ' LIKE' => '%' . $keyword . '%') + $query, 'order' => array($model->alias . '.' . $model->displayField => 'ASC'), 'contain' => false )); $data = array(); foreach ($results as $result) { $data[] = array( 'id' => $result[$model->alias][$model->primaryKey], 'title' => $result[$model->alias][$model->displayField] ); } return $data; }
[ "public", "function", "searchTypeAhead", "(", "Model", "$", "model", ",", "array", "$", "query", ")", "{", "if", "(", "$", "model", "->", "hasMethod", "(", "'searchTypeAhead'", ")", ")", "{", "return", "$", "model", "->", "searchTypeAhead", "(", "$", "query", ")", ";", "}", "$", "keyword", "=", "$", "query", "[", "'term'", "]", ";", "unset", "(", "$", "query", "[", "'term'", "]", ")", ";", "$", "results", "=", "$", "model", "->", "find", "(", "'all'", ",", "array", "(", "'conditions'", "=>", "array", "(", "$", "model", "->", "alias", ".", "'.'", ".", "$", "model", "->", "displayField", ".", "' LIKE'", "=>", "'%'", ".", "$", "keyword", ".", "'%'", ")", "+", "$", "query", ",", "'order'", "=>", "array", "(", "$", "model", "->", "alias", ".", "'.'", ".", "$", "model", "->", "displayField", "=>", "'ASC'", ")", ",", "'contain'", "=>", "false", ")", ")", ";", "$", "data", "=", "array", "(", ")", ";", "foreach", "(", "$", "results", "as", "$", "result", ")", "{", "$", "data", "[", "]", "=", "array", "(", "'id'", "=>", "$", "result", "[", "$", "model", "->", "alias", "]", "[", "$", "model", "->", "primaryKey", "]", ",", "'title'", "=>", "$", "result", "[", "$", "model", "->", "alias", "]", "[", "$", "model", "->", "displayField", "]", ")", ";", "}", "return", "$", "data", ";", "}" ]
Search for a list of records that match the query. @param Model $model @param array $query @return array
[ "Search", "for", "a", "list", "of", "records", "that", "match", "the", "query", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/Component/AdminToolbarComponent.php#L417-L440
230,051
milesj/admin
Controller/Component/AdminToolbarComponent.php
AdminToolbarComponent.setAssociationCounts
public function setAssociationCounts(Model $model) { $counts = array(); foreach (array($model->hasMany, $model->hasAndBelongsToMany) as $property) { foreach ($property as $alias => $assoc) { $class = isset($assoc['with']) ? $assoc['with'] : $assoc['className']; $counts[$alias] = Admin::introspectModel($class)->find('count', array( 'conditions' => array($assoc['foreignKey'] => $model->id), 'contain' => false )); } } $this->Controller->set('counts', $counts); }
php
public function setAssociationCounts(Model $model) { $counts = array(); foreach (array($model->hasMany, $model->hasAndBelongsToMany) as $property) { foreach ($property as $alias => $assoc) { $class = isset($assoc['with']) ? $assoc['with'] : $assoc['className']; $counts[$alias] = Admin::introspectModel($class)->find('count', array( 'conditions' => array($assoc['foreignKey'] => $model->id), 'contain' => false )); } } $this->Controller->set('counts', $counts); }
[ "public", "function", "setAssociationCounts", "(", "Model", "$", "model", ")", "{", "$", "counts", "=", "array", "(", ")", ";", "foreach", "(", "array", "(", "$", "model", "->", "hasMany", ",", "$", "model", "->", "hasAndBelongsToMany", ")", "as", "$", "property", ")", "{", "foreach", "(", "$", "property", "as", "$", "alias", "=>", "$", "assoc", ")", "{", "$", "class", "=", "isset", "(", "$", "assoc", "[", "'with'", "]", ")", "?", "$", "assoc", "[", "'with'", "]", ":", "$", "assoc", "[", "'className'", "]", ";", "$", "counts", "[", "$", "alias", "]", "=", "Admin", "::", "introspectModel", "(", "$", "class", ")", "->", "find", "(", "'count'", ",", "array", "(", "'conditions'", "=>", "array", "(", "$", "assoc", "[", "'foreignKey'", "]", "=>", "$", "model", "->", "id", ")", ",", "'contain'", "=>", "false", ")", ")", ";", "}", "}", "$", "this", "->", "Controller", "->", "set", "(", "'counts'", ",", "$", "counts", ")", ";", "}" ]
Set a count for every model association. @param Model $model
[ "Set", "a", "count", "for", "every", "model", "association", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/Component/AdminToolbarComponent.php#L447-L462
230,052
milesj/admin
Controller/Component/AdminToolbarComponent.php
AdminToolbarComponent.setBelongsToData
public function setBelongsToData(Model $model) { $typeAhead = array(); foreach ($model->belongsTo as $alias => $assoc) { $object = Admin::introspectModel($assoc['className']); $count = $this->getRecordCount($object); // Add to type ahead if too many records if (!$count || $count > $object->admin['associationLimit']) { $class = $assoc['className']; if (mb_strpos($class, '.') === false) { $class = Configure::read('Admin.coreName') . '.' . $class; } // Get the foreign key from the child -> parent $foreignKey = null; foreach ($object->belongsTo as $childAssoc) { if ($childAssoc['className'] === $model->name) { $foreignKey = $childAssoc['foreignKey']; break; } } $typeAhead[$assoc['foreignKey']] = array( 'alias' => $alias, 'model' => $class, 'foreignKey' => $foreignKey ); } else { $variable = Inflector::variable(Inflector::pluralize(preg_replace('/(?:_id)$/', '', $assoc['foreignKey']))); $this->Controller->set($variable, $this->getRecordList($object)); } } $this->Controller->set('typeAhead', $typeAhead); }
php
public function setBelongsToData(Model $model) { $typeAhead = array(); foreach ($model->belongsTo as $alias => $assoc) { $object = Admin::introspectModel($assoc['className']); $count = $this->getRecordCount($object); // Add to type ahead if too many records if (!$count || $count > $object->admin['associationLimit']) { $class = $assoc['className']; if (mb_strpos($class, '.') === false) { $class = Configure::read('Admin.coreName') . '.' . $class; } // Get the foreign key from the child -> parent $foreignKey = null; foreach ($object->belongsTo as $childAssoc) { if ($childAssoc['className'] === $model->name) { $foreignKey = $childAssoc['foreignKey']; break; } } $typeAhead[$assoc['foreignKey']] = array( 'alias' => $alias, 'model' => $class, 'foreignKey' => $foreignKey ); } else { $variable = Inflector::variable(Inflector::pluralize(preg_replace('/(?:_id)$/', '', $assoc['foreignKey']))); $this->Controller->set($variable, $this->getRecordList($object)); } } $this->Controller->set('typeAhead', $typeAhead); }
[ "public", "function", "setBelongsToData", "(", "Model", "$", "model", ")", "{", "$", "typeAhead", "=", "array", "(", ")", ";", "foreach", "(", "$", "model", "->", "belongsTo", "as", "$", "alias", "=>", "$", "assoc", ")", "{", "$", "object", "=", "Admin", "::", "introspectModel", "(", "$", "assoc", "[", "'className'", "]", ")", ";", "$", "count", "=", "$", "this", "->", "getRecordCount", "(", "$", "object", ")", ";", "// Add to type ahead if too many records", "if", "(", "!", "$", "count", "||", "$", "count", ">", "$", "object", "->", "admin", "[", "'associationLimit'", "]", ")", "{", "$", "class", "=", "$", "assoc", "[", "'className'", "]", ";", "if", "(", "mb_strpos", "(", "$", "class", ",", "'.'", ")", "===", "false", ")", "{", "$", "class", "=", "Configure", "::", "read", "(", "'Admin.coreName'", ")", ".", "'.'", ".", "$", "class", ";", "}", "// Get the foreign key from the child -> parent", "$", "foreignKey", "=", "null", ";", "foreach", "(", "$", "object", "->", "belongsTo", "as", "$", "childAssoc", ")", "{", "if", "(", "$", "childAssoc", "[", "'className'", "]", "===", "$", "model", "->", "name", ")", "{", "$", "foreignKey", "=", "$", "childAssoc", "[", "'foreignKey'", "]", ";", "break", ";", "}", "}", "$", "typeAhead", "[", "$", "assoc", "[", "'foreignKey'", "]", "]", "=", "array", "(", "'alias'", "=>", "$", "alias", ",", "'model'", "=>", "$", "class", ",", "'foreignKey'", "=>", "$", "foreignKey", ")", ";", "}", "else", "{", "$", "variable", "=", "Inflector", "::", "variable", "(", "Inflector", "::", "pluralize", "(", "preg_replace", "(", "'/(?:_id)$/'", ",", "''", ",", "$", "assoc", "[", "'foreignKey'", "]", ")", ")", ")", ";", "$", "this", "->", "Controller", "->", "set", "(", "$", "variable", ",", "$", "this", "->", "getRecordList", "(", "$", "object", ")", ")", ";", "}", "}", "$", "this", "->", "Controller", "->", "set", "(", "'typeAhead'", ",", "$", "typeAhead", ")", ";", "}" ]
Set belongsTo data for select inputs. If there are too many records, switch to type ahead. @param Model $model
[ "Set", "belongsTo", "data", "for", "select", "inputs", ".", "If", "there", "are", "too", "many", "records", "switch", "to", "type", "ahead", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/Component/AdminToolbarComponent.php#L469-L508
230,053
milesj/admin
Controller/Component/AdminToolbarComponent.php
AdminToolbarComponent.setHabtmData
public function setHabtmData(Model $model) { foreach ($model->hasAndBelongsToMany as $assoc) { if (!$assoc['showInForm']) { continue; } $object = Admin::introspectModel($assoc['className']); $variable = Inflector::variable(Inflector::pluralize(preg_replace('/(?:_id)$/', '', $assoc['associationForeignKey']))); $this->Controller->set($variable, $this->getRecordList($object)); } }
php
public function setHabtmData(Model $model) { foreach ($model->hasAndBelongsToMany as $assoc) { if (!$assoc['showInForm']) { continue; } $object = Admin::introspectModel($assoc['className']); $variable = Inflector::variable(Inflector::pluralize(preg_replace('/(?:_id)$/', '', $assoc['associationForeignKey']))); $this->Controller->set($variable, $this->getRecordList($object)); } }
[ "public", "function", "setHabtmData", "(", "Model", "$", "model", ")", "{", "foreach", "(", "$", "model", "->", "hasAndBelongsToMany", "as", "$", "assoc", ")", "{", "if", "(", "!", "$", "assoc", "[", "'showInForm'", "]", ")", "{", "continue", ";", "}", "$", "object", "=", "Admin", "::", "introspectModel", "(", "$", "assoc", "[", "'className'", "]", ")", ";", "$", "variable", "=", "Inflector", "::", "variable", "(", "Inflector", "::", "pluralize", "(", "preg_replace", "(", "'/(?:_id)$/'", ",", "''", ",", "$", "assoc", "[", "'associationForeignKey'", "]", ")", ")", ")", ";", "$", "this", "->", "Controller", "->", "set", "(", "$", "variable", ",", "$", "this", "->", "getRecordList", "(", "$", "object", ")", ")", ";", "}", "}" ]
Set hasAndBelongsToMany data for forms. This allows for saving of associated data. @param Model $model
[ "Set", "hasAndBelongsToMany", "data", "for", "forms", ".", "This", "allows", "for", "saving", "of", "associated", "data", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/Component/AdminToolbarComponent.php#L515-L526
230,054
Webiny/Framework
src/Webiny/Component/Http/Request/Headers.php
Headers.getAllHeaders
private function getAllHeaders() { $headers = []; foreach ($_SERVER as $name => $value) { if (substr($name, 0, 5) == 'HTTP_') { $name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5))))); $headers[$name] = $value; } else { if ($name == "CONTENT_TYPE") { $headers["Content-Type"] = $value; } else { if ($name == "CONTENT_LENGTH") { $headers["Content-Length"] = $value; } } } } return $headers; }
php
private function getAllHeaders() { $headers = []; foreach ($_SERVER as $name => $value) { if (substr($name, 0, 5) == 'HTTP_') { $name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5))))); $headers[$name] = $value; } else { if ($name == "CONTENT_TYPE") { $headers["Content-Type"] = $value; } else { if ($name == "CONTENT_LENGTH") { $headers["Content-Length"] = $value; } } } } return $headers; }
[ "private", "function", "getAllHeaders", "(", ")", "{", "$", "headers", "=", "[", "]", ";", "foreach", "(", "$", "_SERVER", "as", "$", "name", "=>", "$", "value", ")", "{", "if", "(", "substr", "(", "$", "name", ",", "0", ",", "5", ")", "==", "'HTTP_'", ")", "{", "$", "name", "=", "str_replace", "(", "' '", ",", "'-'", ",", "ucwords", "(", "strtolower", "(", "str_replace", "(", "'_'", ",", "' '", ",", "substr", "(", "$", "name", ",", "5", ")", ")", ")", ")", ")", ";", "$", "headers", "[", "$", "name", "]", "=", "$", "value", ";", "}", "else", "{", "if", "(", "$", "name", "==", "\"CONTENT_TYPE\"", ")", "{", "$", "headers", "[", "\"Content-Type\"", "]", "=", "$", "value", ";", "}", "else", "{", "if", "(", "$", "name", "==", "\"CONTENT_LENGTH\"", ")", "{", "$", "headers", "[", "\"Content-Length\"", "]", "=", "$", "value", ";", "}", "}", "}", "}", "return", "$", "headers", ";", "}" ]
Returns a list of header information. @return array
[ "Returns", "a", "list", "of", "header", "information", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Http/Request/Headers.php#L65-L84
230,055
wikimedia/mediawiki-extensions-Auth_remoteuser
src/AuthRemoteuserSessionProvider.php
AuthRemoteuserSessionProvider.setUserNameReplaceFilter
public function setUserNameReplaceFilter( $replacepatterns ) { if ( !is_array( $replacepatterns ) ) { throw new UnexpectedValueException( __METHOD__ . ' expects an array as parameter.' ); } Hooks::register( static::HOOKNAME, function ( &$username ) use ( $replacepatterns ) { foreach ( $replacepatterns as $pattern => $replacement ) { # If $pattern is no regex, create one from it. if ( @preg_match( $pattern, null ) === false ) { $pattern = str_replace( '\\', '\\\\', $pattern ); $pattern = str_replace( '/', '\\/', $pattern ); $pattern = "/$pattern/"; } $replaced = preg_replace( $pattern, $replacement, $username ); if ( null === $replaced ) { return false; } $username = $replaced; } return true; } ); }
php
public function setUserNameReplaceFilter( $replacepatterns ) { if ( !is_array( $replacepatterns ) ) { throw new UnexpectedValueException( __METHOD__ . ' expects an array as parameter.' ); } Hooks::register( static::HOOKNAME, function ( &$username ) use ( $replacepatterns ) { foreach ( $replacepatterns as $pattern => $replacement ) { # If $pattern is no regex, create one from it. if ( @preg_match( $pattern, null ) === false ) { $pattern = str_replace( '\\', '\\\\', $pattern ); $pattern = str_replace( '/', '\\/', $pattern ); $pattern = "/$pattern/"; } $replaced = preg_replace( $pattern, $replacement, $username ); if ( null === $replaced ) { return false; } $username = $replaced; } return true; } ); }
[ "public", "function", "setUserNameReplaceFilter", "(", "$", "replacepatterns", ")", "{", "if", "(", "!", "is_array", "(", "$", "replacepatterns", ")", ")", "{", "throw", "new", "UnexpectedValueException", "(", "__METHOD__", ".", "' expects an array as parameter.'", ")", ";", "}", "Hooks", "::", "register", "(", "static", "::", "HOOKNAME", ",", "function", "(", "&", "$", "username", ")", "use", "(", "$", "replacepatterns", ")", "{", "foreach", "(", "$", "replacepatterns", "as", "$", "pattern", "=>", "$", "replacement", ")", "{", "# If $pattern is no regex, create one from it.", "if", "(", "@", "preg_match", "(", "$", "pattern", ",", "null", ")", "===", "false", ")", "{", "$", "pattern", "=", "str_replace", "(", "'\\\\'", ",", "'\\\\\\\\'", ",", "$", "pattern", ")", ";", "$", "pattern", "=", "str_replace", "(", "'/'", ",", "'\\\\/'", ",", "$", "pattern", ")", ";", "$", "pattern", "=", "\"/$pattern/\"", ";", "}", "$", "replaced", "=", "preg_replace", "(", "$", "pattern", ",", "$", "replacement", ",", "$", "username", ")", ";", "if", "(", "null", "===", "$", "replaced", ")", "{", "return", "false", ";", "}", "$", "username", "=", "$", "replaced", ";", "}", "return", "true", ";", "}", ")", ";", "}" ]
Helper method to apply replacement patterns to a remote user name before using it as an identifier into the local wiki user database. Method uses the provided hook and accepts regular expressions as search patterns. @param array $replacepatterns Array of search and replace patterns. @throws UnexpectedValueException Wrong parameter type given. @see preg_replace() @since 2.0.0
[ "Helper", "method", "to", "apply", "replacement", "patterns", "to", "a", "remote", "user", "name", "before", "using", "it", "as", "an", "identifier", "into", "the", "local", "wiki", "user", "database", "." ]
1436b981d6ff721cb7e0072cf32779d56ce03f45
https://github.com/wikimedia/mediawiki-extensions-Auth_remoteuser/blob/1436b981d6ff721cb7e0072cf32779d56ce03f45/src/AuthRemoteuserSessionProvider.php#L226-L252
230,056
wikimedia/mediawiki-extensions-Auth_remoteuser
src/AuthRemoteuserSessionProvider.php
AuthRemoteuserSessionProvider.setUserNameMatchFilter
public function setUserNameMatchFilter( $names, $allow ) { if ( !is_array( $names ) ) { throw new UnexpectedValueException( __METHOD__ . ' expects an array as parameter.' ); } $allow = (bool)$allow; Hooks::register( static::HOOKNAME, function ( &$username ) use ( $names, $allow ) { if ( isset( $names[ $username ] ) ) { return $allow; } foreach ( $names as $pattern ) { # If $pattern is no regex, create one from it. if ( @preg_match( $pattern, null ) === false ) { $pattern = str_replace( '\\', '\\\\', $pattern ); $pattern = str_replace( '/', '\\/', $pattern ); $pattern = "/$pattern/"; } if ( preg_match( $pattern, $username ) ) { return $allow; } } return !$allow; } ); }
php
public function setUserNameMatchFilter( $names, $allow ) { if ( !is_array( $names ) ) { throw new UnexpectedValueException( __METHOD__ . ' expects an array as parameter.' ); } $allow = (bool)$allow; Hooks::register( static::HOOKNAME, function ( &$username ) use ( $names, $allow ) { if ( isset( $names[ $username ] ) ) { return $allow; } foreach ( $names as $pattern ) { # If $pattern is no regex, create one from it. if ( @preg_match( $pattern, null ) === false ) { $pattern = str_replace( '\\', '\\\\', $pattern ); $pattern = str_replace( '/', '\\/', $pattern ); $pattern = "/$pattern/"; } if ( preg_match( $pattern, $username ) ) { return $allow; } } return !$allow; } ); }
[ "public", "function", "setUserNameMatchFilter", "(", "$", "names", ",", "$", "allow", ")", "{", "if", "(", "!", "is_array", "(", "$", "names", ")", ")", "{", "throw", "new", "UnexpectedValueException", "(", "__METHOD__", ".", "' expects an array as parameter.'", ")", ";", "}", "$", "allow", "=", "(", "bool", ")", "$", "allow", ";", "Hooks", "::", "register", "(", "static", "::", "HOOKNAME", ",", "function", "(", "&", "$", "username", ")", "use", "(", "$", "names", ",", "$", "allow", ")", "{", "if", "(", "isset", "(", "$", "names", "[", "$", "username", "]", ")", ")", "{", "return", "$", "allow", ";", "}", "foreach", "(", "$", "names", "as", "$", "pattern", ")", "{", "# If $pattern is no regex, create one from it.", "if", "(", "@", "preg_match", "(", "$", "pattern", ",", "null", ")", "===", "false", ")", "{", "$", "pattern", "=", "str_replace", "(", "'\\\\'", ",", "'\\\\\\\\'", ",", "$", "pattern", ")", ";", "$", "pattern", "=", "str_replace", "(", "'/'", ",", "'\\\\/'", ",", "$", "pattern", ")", ";", "$", "pattern", "=", "\"/$pattern/\"", ";", "}", "if", "(", "preg_match", "(", "$", "pattern", ",", "$", "username", ")", ")", "{", "return", "$", "allow", ";", "}", "}", "return", "!", "$", "allow", ";", "}", ")", ";", "}" ]
Helper method to create a filter which matches the user name against a given list. Uses the provided hook. Each of the provided names can be a regular expression too. @param string[] $names List of names to match remote user name against. @param boolean $allow Either allow or disallow if name matches. @throws UnexpectedValueException Wrong parameter type given. @see preg_match() @since 2.0.0
[ "Helper", "method", "to", "create", "a", "filter", "which", "matches", "the", "user", "name", "against", "a", "given", "list", "." ]
1436b981d6ff721cb7e0072cf32779d56ce03f45
https://github.com/wikimedia/mediawiki-extensions-Auth_remoteuser/blob/1436b981d6ff721cb7e0072cf32779d56ce03f45/src/AuthRemoteuserSessionProvider.php#L267-L296
230,057
Webiny/Framework
src/Webiny/Component/Router/Route/RouteOption.php
RouteOption.addAttribute
public function addAttribute($name, $value) { if ($name == 'Pattern') { $value = $this->sanitizePattern($name, $value); } $this->attributes[$name] = $value; return $this; }
php
public function addAttribute($name, $value) { if ($name == 'Pattern') { $value = $this->sanitizePattern($name, $value); } $this->attributes[$name] = $value; return $this; }
[ "public", "function", "addAttribute", "(", "$", "name", ",", "$", "value", ")", "{", "if", "(", "$", "name", "==", "'Pattern'", ")", "{", "$", "value", "=", "$", "this", "->", "sanitizePattern", "(", "$", "name", ",", "$", "value", ")", ";", "}", "$", "this", "->", "attributes", "[", "$", "name", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
Adds an attribute to the parameter. @param string $name Name of the attribute. @param string $value Value of the attribute. @return $this
[ "Adds", "an", "attribute", "to", "the", "parameter", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Router/Route/RouteOption.php#L57-L65
230,058
Webiny/Framework
src/Webiny/Component/Router/Route/RouteOption.php
RouteOption.sanitizePattern
private function sanitizePattern($name, $pattern) { // make sure value is a string if (!$this->isString($pattern)) { throw new RouterException('The value of %s.%s option must be a string.', [ $this->name, $name ] ); } // filter out some characters from the start and end of the pattern $pattern = $this->str($pattern)->trimLeft('^')->trimRight('$'); // make sure pattern is not empty if ($pattern->length() < 1) { throw new RouterException('The route for %s.%s cannot be empty.', [ $this->name, $name ] ); } return $pattern->val(); }
php
private function sanitizePattern($name, $pattern) { // make sure value is a string if (!$this->isString($pattern)) { throw new RouterException('The value of %s.%s option must be a string.', [ $this->name, $name ] ); } // filter out some characters from the start and end of the pattern $pattern = $this->str($pattern)->trimLeft('^')->trimRight('$'); // make sure pattern is not empty if ($pattern->length() < 1) { throw new RouterException('The route for %s.%s cannot be empty.', [ $this->name, $name ] ); } return $pattern->val(); }
[ "private", "function", "sanitizePattern", "(", "$", "name", ",", "$", "pattern", ")", "{", "// make sure value is a string", "if", "(", "!", "$", "this", "->", "isString", "(", "$", "pattern", ")", ")", "{", "throw", "new", "RouterException", "(", "'The value of %s.%s option must be a string.'", ",", "[", "$", "this", "->", "name", ",", "$", "name", "]", ")", ";", "}", "// filter out some characters from the start and end of the pattern", "$", "pattern", "=", "$", "this", "->", "str", "(", "$", "pattern", ")", "->", "trimLeft", "(", "'^'", ")", "->", "trimRight", "(", "'$'", ")", ";", "// make sure pattern is not empty", "if", "(", "$", "pattern", "->", "length", "(", ")", "<", "1", ")", "{", "throw", "new", "RouterException", "(", "'The route for %s.%s cannot be empty.'", ",", "[", "$", "this", "->", "name", ",", "$", "name", "]", ")", ";", "}", "return", "$", "pattern", "->", "val", "(", ")", ";", "}" ]
Sanitizes the given pattern. @param string $name Name of the attribute. @param string $pattern Pattern to sanitize. @return string @throws \Webiny\Component\Router\RouterException
[ "Sanitizes", "the", "given", "pattern", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Router/Route/RouteOption.php#L111-L135
230,059
jkphl/squeezr
squeezr/lib/Tollwerk/Squeezr.php
Squeezr._sendFile
protected function _sendFile($src, $mime, $cache = true) { // Custom headers foreach ($this->_headers as $header => $value) { header($header.': '.$value); } // Send basic headers header('Content-Type: '.$mime); header('Content-Length: '.filesize(@is_link($src) ? @readlink($src) : $src)); // If the client browser should cache the image if ($cache) { header('Cache-Control: private, max-age='.SQUEEZR_CACHE_LIFETIME); header('Expires: '.gmdate('D, d M Y H:i:s', time() + SQUEEZR_CACHE_LIFETIME).' GMT'); header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($src)).' GMT'); header('ETag: '.$this->_calculateFileETag($src)); // Else } else { header('Cache-Control: no-cache, must-revalidate'); header('Expires: '.gmdate('D, d M Y H:i:s', time() - SQUEEZR_CACHE_LIFETIME).' GMT'); } readfile($src); exit; }
php
protected function _sendFile($src, $mime, $cache = true) { // Custom headers foreach ($this->_headers as $header => $value) { header($header.': '.$value); } // Send basic headers header('Content-Type: '.$mime); header('Content-Length: '.filesize(@is_link($src) ? @readlink($src) : $src)); // If the client browser should cache the image if ($cache) { header('Cache-Control: private, max-age='.SQUEEZR_CACHE_LIFETIME); header('Expires: '.gmdate('D, d M Y H:i:s', time() + SQUEEZR_CACHE_LIFETIME).' GMT'); header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($src)).' GMT'); header('ETag: '.$this->_calculateFileETag($src)); // Else } else { header('Cache-Control: no-cache, must-revalidate'); header('Expires: '.gmdate('D, d M Y H:i:s', time() - SQUEEZR_CACHE_LIFETIME).' GMT'); } readfile($src); exit; }
[ "protected", "function", "_sendFile", "(", "$", "src", ",", "$", "mime", ",", "$", "cache", "=", "true", ")", "{", "// Custom headers", "foreach", "(", "$", "this", "->", "_headers", "as", "$", "header", "=>", "$", "value", ")", "{", "header", "(", "$", "header", ".", "': '", ".", "$", "value", ")", ";", "}", "// Send basic headers", "header", "(", "'Content-Type: '", ".", "$", "mime", ")", ";", "header", "(", "'Content-Length: '", ".", "filesize", "(", "@", "is_link", "(", "$", "src", ")", "?", "@", "readlink", "(", "$", "src", ")", ":", "$", "src", ")", ")", ";", "// If the client browser should cache the image", "if", "(", "$", "cache", ")", "{", "header", "(", "'Cache-Control: private, max-age='", ".", "SQUEEZR_CACHE_LIFETIME", ")", ";", "header", "(", "'Expires: '", ".", "gmdate", "(", "'D, d M Y H:i:s'", ",", "time", "(", ")", "+", "SQUEEZR_CACHE_LIFETIME", ")", ".", "' GMT'", ")", ";", "header", "(", "'Last-Modified: '", ".", "gmdate", "(", "'D, d M Y H:i:s'", ",", "filemtime", "(", "$", "src", ")", ")", ".", "' GMT'", ")", ";", "header", "(", "'ETag: '", ".", "$", "this", "->", "_calculateFileETag", "(", "$", "src", ")", ")", ";", "// Else", "}", "else", "{", "header", "(", "'Cache-Control: no-cache, must-revalidate'", ")", ";", "header", "(", "'Expires: '", ".", "gmdate", "(", "'D, d M Y H:i:s'", ",", "time", "(", ")", "-", "SQUEEZR_CACHE_LIFETIME", ")", ".", "' GMT'", ")", ";", "}", "readfile", "(", "$", "src", ")", ";", "exit", ";", "}" ]
Send a file along with it's appropriate headers @param string $src File path @param string $mime MIME type @param boolean $cache Optional: The client browser should cache the file @return void
[ "Send", "a", "file", "along", "with", "it", "s", "appropriate", "headers" ]
9aed77dcdca889a532a81630498fa51ad63138b7
https://github.com/jkphl/squeezr/blob/9aed77dcdca889a532a81630498fa51ad63138b7/squeezr/lib/Tollwerk/Squeezr.php#L63-L90
230,060
jkphl/squeezr
squeezr/lib/Tollwerk/Squeezr.php
Squeezr._calculateFileETag
private function _calculateFileETag($src) { $src = @is_link($src) ? @readlink($src) : $src; $fileStats = stat($src); $fileFulltime = @exec('ls --full-time '.escapeshellarg($src)); $fileMtime = str_pad(preg_match("%\d+\:\d+\:\d+\.(\d+)%", $fileFulltime, $fileMtime) ? substr($fileStats['mtime'].$fileMtime[1], 0, 16) : $fileStats['mtime'], 16, '0'); return sprintf('"%x-%x-%s"', $fileStats['ino'], $fileStats['size'], base_convert($fileMtime, 10, 16)); }
php
private function _calculateFileETag($src) { $src = @is_link($src) ? @readlink($src) : $src; $fileStats = stat($src); $fileFulltime = @exec('ls --full-time '.escapeshellarg($src)); $fileMtime = str_pad(preg_match("%\d+\:\d+\:\d+\.(\d+)%", $fileFulltime, $fileMtime) ? substr($fileStats['mtime'].$fileMtime[1], 0, 16) : $fileStats['mtime'], 16, '0'); return sprintf('"%x-%x-%s"', $fileStats['ino'], $fileStats['size'], base_convert($fileMtime, 10, 16)); }
[ "private", "function", "_calculateFileETag", "(", "$", "src", ")", "{", "$", "src", "=", "@", "is_link", "(", "$", "src", ")", "?", "@", "readlink", "(", "$", "src", ")", ":", "$", "src", ";", "$", "fileStats", "=", "stat", "(", "$", "src", ")", ";", "$", "fileFulltime", "=", "@", "exec", "(", "'ls --full-time '", ".", "escapeshellarg", "(", "$", "src", ")", ")", ";", "$", "fileMtime", "=", "str_pad", "(", "preg_match", "(", "\"%\\d+\\:\\d+\\:\\d+\\.(\\d+)%\"", ",", "$", "fileFulltime", ",", "$", "fileMtime", ")", "?", "substr", "(", "$", "fileStats", "[", "'mtime'", "]", ".", "$", "fileMtime", "[", "1", "]", ",", "0", ",", "16", ")", ":", "$", "fileStats", "[", "'mtime'", "]", ",", "16", ",", "'0'", ")", ";", "return", "sprintf", "(", "'\"%x-%x-%s\"'", ",", "$", "fileStats", "[", "'ino'", "]", ",", "$", "fileStats", "[", "'size'", "]", ",", "base_convert", "(", "$", "fileMtime", ",", "10", ",", "16", ")", ")", ";", "}" ]
Calculate the ETag of a file @param string $src File path @return string File ETag
[ "Calculate", "the", "ETag", "of", "a", "file" ]
9aed77dcdca889a532a81630498fa51ad63138b7
https://github.com/jkphl/squeezr/blob/9aed77dcdca889a532a81630498fa51ad63138b7/squeezr/lib/Tollwerk/Squeezr.php#L98-L106
230,061
naneau/semver
src/Naneau/SemVer/Parser.php
Parser.parse
public static function parse($string) { $matches = Regex::matchSemVer($string); // Parse the SemVer root $version = VersionableParser::parse( $matches[1], 'Naneau\SemVer\Version' ); // There is a pre-release part if (!empty($matches['prerelease'])) { $version->setPreRelease( PreReleaseParser::parse( ltrim($matches['prerelease'], '-') ) ); } // There is a build number if (!empty($matches['build'])) { $version->setBuild( BuildParser::parse( ltrim($matches['build'], '+') ) ); } // Return $version->setOriginalVersion($string); return $version; }
php
public static function parse($string) { $matches = Regex::matchSemVer($string); // Parse the SemVer root $version = VersionableParser::parse( $matches[1], 'Naneau\SemVer\Version' ); // There is a pre-release part if (!empty($matches['prerelease'])) { $version->setPreRelease( PreReleaseParser::parse( ltrim($matches['prerelease'], '-') ) ); } // There is a build number if (!empty($matches['build'])) { $version->setBuild( BuildParser::parse( ltrim($matches['build'], '+') ) ); } // Return $version->setOriginalVersion($string); return $version; }
[ "public", "static", "function", "parse", "(", "$", "string", ")", "{", "$", "matches", "=", "Regex", "::", "matchSemVer", "(", "$", "string", ")", ";", "// Parse the SemVer root", "$", "version", "=", "VersionableParser", "::", "parse", "(", "$", "matches", "[", "1", "]", ",", "'Naneau\\SemVer\\Version'", ")", ";", "// There is a pre-release part", "if", "(", "!", "empty", "(", "$", "matches", "[", "'prerelease'", "]", ")", ")", "{", "$", "version", "->", "setPreRelease", "(", "PreReleaseParser", "::", "parse", "(", "ltrim", "(", "$", "matches", "[", "'prerelease'", "]", ",", "'-'", ")", ")", ")", ";", "}", "// There is a build number", "if", "(", "!", "empty", "(", "$", "matches", "[", "'build'", "]", ")", ")", "{", "$", "version", "->", "setBuild", "(", "BuildParser", "::", "parse", "(", "ltrim", "(", "$", "matches", "[", "'build'", "]", ",", "'+'", ")", ")", ")", ";", "}", "// Return", "$", "version", "->", "setOriginalVersion", "(", "$", "string", ")", ";", "return", "$", "version", ";", "}" ]
Parse a string into a SemVer Version @throws InvalidArgumentException @param string $string @return SemVerVersion
[ "Parse", "a", "string", "into", "a", "SemVer", "Version" ]
c771ad1e6c89064c0a4fa714979639dc3649d6c8
https://github.com/naneau/semver/blob/c771ad1e6c89064c0a4fa714979639dc3649d6c8/src/Naneau/SemVer/Parser.php#L41-L72
230,062
ameliaikeda/rememberable
src/Query/Builder.php
Builder.forget
public function forget($key = null) { $key = $key ?: $this->getCacheKey(); $cache = $this->getCache(); return $cache->forget($key); }
php
public function forget($key = null) { $key = $key ?: $this->getCacheKey(); $cache = $this->getCache(); return $cache->forget($key); }
[ "public", "function", "forget", "(", "$", "key", "=", "null", ")", "{", "$", "key", "=", "$", "key", "?", ":", "$", "this", "->", "getCacheKey", "(", ")", ";", "$", "cache", "=", "$", "this", "->", "getCache", "(", ")", ";", "return", "$", "cache", "->", "forget", "(", "$", "key", ")", ";", "}" ]
Forget the executed query. Allows a key to be passed in, for `User::forget('my-key')`. @param string $key @return bool
[ "Forget", "the", "executed", "query", "." ]
a60826a33698e6a27129760d809325b143cf5f88
https://github.com/ameliaikeda/rememberable/blob/a60826a33698e6a27129760d809325b143cf5f88/src/Query/Builder.php#L103-L110
230,063
ameliaikeda/rememberable
src/Query/Builder.php
Builder.flush
public function flush($tags = null) { $tags = $this->getCacheTags($tags); $this->flushKeysForTags($tags); }
php
public function flush($tags = null) { $tags = $this->getCacheTags($tags); $this->flushKeysForTags($tags); }
[ "public", "function", "flush", "(", "$", "tags", "=", "null", ")", "{", "$", "tags", "=", "$", "this", "->", "getCacheTags", "(", "$", "tags", ")", ";", "$", "this", "->", "flushKeysForTags", "(", "$", "tags", ")", ";", "}" ]
Flush the cache for the current model or a given tag name. Can be called using Model::flush() @param array|string $tags @return bool
[ "Flush", "the", "cache", "for", "the", "current", "model", "or", "a", "given", "tag", "name", "." ]
a60826a33698e6a27129760d809325b143cf5f88
https://github.com/ameliaikeda/rememberable/blob/a60826a33698e6a27129760d809325b143cf5f88/src/Query/Builder.php#L131-L136
230,064
ameliaikeda/rememberable
src/Query/Builder.php
Builder.getCacheKey
public function getCacheKey($columns = null) { if ($columns !== null) { $this->columns = $columns; } return $this->prefix.':'.($this->key ?: $this->generateCacheKey()); }
php
public function getCacheKey($columns = null) { if ($columns !== null) { $this->columns = $columns; } return $this->prefix.':'.($this->key ?: $this->generateCacheKey()); }
[ "public", "function", "getCacheKey", "(", "$", "columns", "=", "null", ")", "{", "if", "(", "$", "columns", "!==", "null", ")", "{", "$", "this", "->", "columns", "=", "$", "columns", ";", "}", "return", "$", "this", "->", "prefix", ".", "':'", ".", "(", "$", "this", "->", "key", "?", ":", "$", "this", "->", "generateCacheKey", "(", ")", ")", ";", "}" ]
Get a unique cache key for the complete query. @param array|null $columns @return string
[ "Get", "a", "unique", "cache", "key", "for", "the", "complete", "query", "." ]
a60826a33698e6a27129760d809325b143cf5f88
https://github.com/ameliaikeda/rememberable/blob/a60826a33698e6a27129760d809325b143cf5f88/src/Query/Builder.php#L183-L190
230,065
ameliaikeda/rememberable
src/Query/Builder.php
Builder.getCacheTags
public function getCacheTags($tags = null) { if ($tags !== null) { return (array) $tags; } $tags = (array) $this->tags; $tags[] = static::VERSION_TAG; $tags[] = static::BASE_TAG; $tags[] = $this->from; if ($this->model) { $tags[] = get_class($this->model); } return $tags; }
php
public function getCacheTags($tags = null) { if ($tags !== null) { return (array) $tags; } $tags = (array) $this->tags; $tags[] = static::VERSION_TAG; $tags[] = static::BASE_TAG; $tags[] = $this->from; if ($this->model) { $tags[] = get_class($this->model); } return $tags; }
[ "public", "function", "getCacheTags", "(", "$", "tags", "=", "null", ")", "{", "if", "(", "$", "tags", "!==", "null", ")", "{", "return", "(", "array", ")", "$", "tags", ";", "}", "$", "tags", "=", "(", "array", ")", "$", "this", "->", "tags", ";", "$", "tags", "[", "]", "=", "static", "::", "VERSION_TAG", ";", "$", "tags", "[", "]", "=", "static", "::", "BASE_TAG", ";", "$", "tags", "[", "]", "=", "$", "this", "->", "from", ";", "if", "(", "$", "this", "->", "model", ")", "{", "$", "tags", "[", "]", "=", "get_class", "(", "$", "this", "->", "model", ")", ";", "}", "return", "$", "tags", ";", "}" ]
Get the cache tags to use for this. @param string|array|null $tags @return array
[ "Get", "the", "cache", "tags", "to", "use", "for", "this", "." ]
a60826a33698e6a27129760d809325b143cf5f88
https://github.com/ameliaikeda/rememberable/blob/a60826a33698e6a27129760d809325b143cf5f88/src/Query/Builder.php#L198-L214
230,066
ameliaikeda/rememberable
src/Query/Builder.php
Builder.flushKeysForTags
public function flushKeysForTags($tags) { $tags = is_array($tags) ? $tags : func_get_args(); $cache = $this->getCache(); $store = $cache->getStore(); if (! $store instanceof RedisStore) { // we can't cache forever in this case. we need sets. return; } $connection = $store->connection(); foreach ($tags as $tag) { $segment = $this->getCacheSegmentKey($tag); $this->deleteCacheValues($store->getPrefix().$segment, $connection, $cache); $cache->forget($segment); } }
php
public function flushKeysForTags($tags) { $tags = is_array($tags) ? $tags : func_get_args(); $cache = $this->getCache(); $store = $cache->getStore(); if (! $store instanceof RedisStore) { // we can't cache forever in this case. we need sets. return; } $connection = $store->connection(); foreach ($tags as $tag) { $segment = $this->getCacheSegmentKey($tag); $this->deleteCacheValues($store->getPrefix().$segment, $connection, $cache); $cache->forget($segment); } }
[ "public", "function", "flushKeysForTags", "(", "$", "tags", ")", "{", "$", "tags", "=", "is_array", "(", "$", "tags", ")", "?", "$", "tags", ":", "func_get_args", "(", ")", ";", "$", "cache", "=", "$", "this", "->", "getCache", "(", ")", ";", "$", "store", "=", "$", "cache", "->", "getStore", "(", ")", ";", "if", "(", "!", "$", "store", "instanceof", "RedisStore", ")", "{", "// we can't cache forever in this case. we need sets.", "return", ";", "}", "$", "connection", "=", "$", "store", "->", "connection", "(", ")", ";", "foreach", "(", "$", "tags", "as", "$", "tag", ")", "{", "$", "segment", "=", "$", "this", "->", "getCacheSegmentKey", "(", "$", "tag", ")", ";", "$", "this", "->", "deleteCacheValues", "(", "$", "store", "->", "getPrefix", "(", ")", ".", "$", "segment", ",", "$", "connection", ",", "$", "cache", ")", ";", "$", "cache", "->", "forget", "(", "$", "segment", ")", ";", "}", "}" ]
Flush keys for a set of given tags. @param string|array $tags
[ "Flush", "keys", "for", "a", "set", "of", "given", "tags", "." ]
a60826a33698e6a27129760d809325b143cf5f88
https://github.com/ameliaikeda/rememberable/blob/a60826a33698e6a27129760d809325b143cf5f88/src/Query/Builder.php#L297-L319
230,067
ameliaikeda/rememberable
src/Query/Builder.php
Builder.deleteCacheValues
protected function deleteCacheValues($key, RedisClient $connection, Repository $store) { $members = $connection->smembers($key); foreach ($members as $member) { $store->forget($member); } }
php
protected function deleteCacheValues($key, RedisClient $connection, Repository $store) { $members = $connection->smembers($key); foreach ($members as $member) { $store->forget($member); } }
[ "protected", "function", "deleteCacheValues", "(", "$", "key", ",", "RedisClient", "$", "connection", ",", "Repository", "$", "store", ")", "{", "$", "members", "=", "$", "connection", "->", "smembers", "(", "$", "key", ")", ";", "foreach", "(", "$", "members", "as", "$", "member", ")", "{", "$", "store", "->", "forget", "(", "$", "member", ")", ";", "}", "}" ]
Forget cache values that are tagged. @param string $key @param \Predis\ClientInterface $connection @param \Illuminate\Contracts\Cache\Repository $store
[ "Forget", "cache", "values", "that", "are", "tagged", "." ]
a60826a33698e6a27129760d809325b143cf5f88
https://github.com/ameliaikeda/rememberable/blob/a60826a33698e6a27129760d809325b143cf5f88/src/Query/Builder.php#L328-L335
230,068
beyondit/opencart-extension-installer
src/BeyondIT/Composer/OpenCartExtensionInstaller.php
OpenCartExtensionInstaller.getSrcDir
public function getSrcDir($installPath, array $extra) { if (isset($extra['src-dir']) && is_string($extra['src-dir'])) { $installPath .= "/" . $extra['src-dir']; } else { // default $installPath .= "/src/upload"; } return $installPath; }
php
public function getSrcDir($installPath, array $extra) { if (isset($extra['src-dir']) && is_string($extra['src-dir'])) { $installPath .= "/" . $extra['src-dir']; } else { // default $installPath .= "/src/upload"; } return $installPath; }
[ "public", "function", "getSrcDir", "(", "$", "installPath", ",", "array", "$", "extra", ")", "{", "if", "(", "isset", "(", "$", "extra", "[", "'src-dir'", "]", ")", "&&", "is_string", "(", "$", "extra", "[", "'src-dir'", "]", ")", ")", "{", "$", "installPath", ".=", "\"/\"", ".", "$", "extra", "[", "'src-dir'", "]", ";", "}", "else", "{", "// default", "$", "installPath", ".=", "\"/src/upload\"", ";", "}", "return", "$", "installPath", ";", "}" ]
Get src path of module
[ "Get", "src", "path", "of", "module" ]
87bed19d1b603b7ac32997ca0bf2ffc3e01d4afe
https://github.com/beyondit/opencart-extension-installer/blob/87bed19d1b603b7ac32997ca0bf2ffc3e01d4afe/src/BeyondIT/Composer/OpenCartExtensionInstaller.php#L28-L37
230,069
alexandresalome/php-webdriver
src/WebDriver/CookieBag.php
CookieBag.getValue
public function getValue($name) { $cookie = $this->get($name); return null === $cookie ? null : $cookie->getValue(); }
php
public function getValue($name) { $cookie = $this->get($name); return null === $cookie ? null : $cookie->getValue(); }
[ "public", "function", "getValue", "(", "$", "name", ")", "{", "$", "cookie", "=", "$", "this", "->", "get", "(", "$", "name", ")", ";", "return", "null", "===", "$", "cookie", "?", "null", ":", "$", "cookie", "->", "getValue", "(", ")", ";", "}" ]
Fetches value of a given cookie. @return string|null the cookie or null if cookie is not found.
[ "Fetches", "value", "of", "a", "given", "cookie", "." ]
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/CookieBag.php#L36-L41
230,070
alexandresalome/php-webdriver
src/WebDriver/CookieBag.php
CookieBag.get
public function get($name) { $cookies = $this->getAll(); foreach ($cookies as $cookie) { if ($cookie->getName() == $name) { return $cookie; } } return null; }
php
public function get($name) { $cookies = $this->getAll(); foreach ($cookies as $cookie) { if ($cookie->getName() == $name) { return $cookie; } } return null; }
[ "public", "function", "get", "(", "$", "name", ")", "{", "$", "cookies", "=", "$", "this", "->", "getAll", "(", ")", ";", "foreach", "(", "$", "cookies", "as", "$", "cookie", ")", "{", "if", "(", "$", "cookie", "->", "getName", "(", ")", "==", "$", "name", ")", "{", "return", "$", "cookie", ";", "}", "}", "return", "null", ";", "}" ]
Returns a Cookie. @return Cookie|null returns cookie or null if cookie was not found
[ "Returns", "a", "Cookie", "." ]
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/CookieBag.php#L48-L59
230,071
alexandresalome/php-webdriver
src/WebDriver/CookieBag.php
CookieBag.set
public function set($name, $value, $path = null, $domain = null, $isSecure = null, \DateTime $expiry = null) { $cookie = new Cookie($name, $value, $path, $domain, $isSecure, $expiry); $this->setCookie($cookie); }
php
public function set($name, $value, $path = null, $domain = null, $isSecure = null, \DateTime $expiry = null) { $cookie = new Cookie($name, $value, $path, $domain, $isSecure, $expiry); $this->setCookie($cookie); }
[ "public", "function", "set", "(", "$", "name", ",", "$", "value", ",", "$", "path", "=", "null", ",", "$", "domain", "=", "null", ",", "$", "isSecure", "=", "null", ",", "\\", "DateTime", "$", "expiry", "=", "null", ")", "{", "$", "cookie", "=", "new", "Cookie", "(", "$", "name", ",", "$", "value", ",", "$", "path", ",", "$", "domain", ",", "$", "isSecure", ",", "$", "expiry", ")", ";", "$", "this", "->", "setCookie", "(", "$", "cookie", ")", ";", "}" ]
Returns a cookie value. @return string|null returns the cookie value or null if cookie does not exist
[ "Returns", "a", "cookie", "value", "." ]
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/CookieBag.php#L89-L94
230,072
madeyourday/contao-rocksolid-icon-picker
src/Widget/IconPicker.php
IconPicker.getCacheDirPaths
public static function getCacheDirPaths() { $cacheDir = \System::getContainer()->getParameter('kernel.cache_dir') . '/contao'; $dirFullPath = $cacheDir . '/rocksolid_icon_picker'; $dirPath = $dirFullPath; if ( substr($dirPath, 0, strlen(TL_ROOT) + 1) === TL_ROOT . '/' || substr($dirPath, 0, strlen(TL_ROOT) + 1) === TL_ROOT . '\\' ) { $dirPath = substr($dirPath, strlen(TL_ROOT) + 1); } return array( 'path' => $dirPath, 'fullPath' => $dirFullPath, ); }
php
public static function getCacheDirPaths() { $cacheDir = \System::getContainer()->getParameter('kernel.cache_dir') . '/contao'; $dirFullPath = $cacheDir . '/rocksolid_icon_picker'; $dirPath = $dirFullPath; if ( substr($dirPath, 0, strlen(TL_ROOT) + 1) === TL_ROOT . '/' || substr($dirPath, 0, strlen(TL_ROOT) + 1) === TL_ROOT . '\\' ) { $dirPath = substr($dirPath, strlen(TL_ROOT) + 1); } return array( 'path' => $dirPath, 'fullPath' => $dirFullPath, ); }
[ "public", "static", "function", "getCacheDirPaths", "(", ")", "{", "$", "cacheDir", "=", "\\", "System", "::", "getContainer", "(", ")", "->", "getParameter", "(", "'kernel.cache_dir'", ")", ".", "'/contao'", ";", "$", "dirFullPath", "=", "$", "cacheDir", ".", "'/rocksolid_icon_picker'", ";", "$", "dirPath", "=", "$", "dirFullPath", ";", "if", "(", "substr", "(", "$", "dirPath", ",", "0", ",", "strlen", "(", "TL_ROOT", ")", "+", "1", ")", "===", "TL_ROOT", ".", "'/'", "||", "substr", "(", "$", "dirPath", ",", "0", ",", "strlen", "(", "TL_ROOT", ")", "+", "1", ")", "===", "TL_ROOT", ".", "'\\\\'", ")", "{", "$", "dirPath", "=", "substr", "(", "$", "dirPath", ",", "strlen", "(", "TL_ROOT", ")", "+", "1", ")", ";", "}", "return", "array", "(", "'path'", "=>", "$", "dirPath", ",", "'fullPath'", "=>", "$", "dirFullPath", ",", ")", ";", "}" ]
Get path and fullPath to the cache directory @return string
[ "Get", "path", "and", "fullPath", "to", "the", "cache", "directory" ]
80be69c3787ba68ca8d27aca5fb00faa23e04108
https://github.com/madeyourday/contao-rocksolid-icon-picker/blob/80be69c3787ba68ca8d27aca5fb00faa23e04108/src/Widget/IconPicker.php#L159-L176
230,073
Webiny/Framework
src/Webiny/Component/Entity/AbstractEntity.php
AbstractEntity.findOne
public static function findOne(array $conditions = []) { $data = static::entity()->getDatabase()->findOne(static::$collection, $conditions); if (!$data) { return null; } $instance = new static; $data['__webiny_db__'] = true; $instance->populate($data); return static::entity()->add($instance); }
php
public static function findOne(array $conditions = []) { $data = static::entity()->getDatabase()->findOne(static::$collection, $conditions); if (!$data) { return null; } $instance = new static; $data['__webiny_db__'] = true; $instance->populate($data); return static::entity()->add($instance); }
[ "public", "static", "function", "findOne", "(", "array", "$", "conditions", "=", "[", "]", ")", "{", "$", "data", "=", "static", "::", "entity", "(", ")", "->", "getDatabase", "(", ")", "->", "findOne", "(", "static", "::", "$", "collection", ",", "$", "conditions", ")", ";", "if", "(", "!", "$", "data", ")", "{", "return", "null", ";", "}", "$", "instance", "=", "new", "static", ";", "$", "data", "[", "'__webiny_db__'", "]", "=", "true", ";", "$", "instance", "->", "populate", "(", "$", "data", ")", ";", "return", "static", "::", "entity", "(", ")", "->", "add", "(", "$", "instance", ")", ";", "}" ]
Find entity by array of conditions @param array $conditions @return null|AbstractEntity @throws EntityException
[ "Find", "entity", "by", "array", "of", "conditions" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Entity/AbstractEntity.php#L108-L121
230,074
Webiny/Framework
src/Webiny/Component/Entity/AbstractEntity.php
AbstractEntity.random
public static function random(array $conditions = []) { $count = static::entity()->getDatabase()->count(static::$collection, $conditions); if ($count === 0) { return null; } $data = static::find($conditions, [], 1, rand(0, $count)); return $data[0]; }
php
public static function random(array $conditions = []) { $count = static::entity()->getDatabase()->count(static::$collection, $conditions); if ($count === 0) { return null; } $data = static::find($conditions, [], 1, rand(0, $count)); return $data[0]; }
[ "public", "static", "function", "random", "(", "array", "$", "conditions", "=", "[", "]", ")", "{", "$", "count", "=", "static", "::", "entity", "(", ")", "->", "getDatabase", "(", ")", "->", "count", "(", "static", "::", "$", "collection", ",", "$", "conditions", ")", ";", "if", "(", "$", "count", "===", "0", ")", "{", "return", "null", ";", "}", "$", "data", "=", "static", "::", "find", "(", "$", "conditions", ",", "[", "]", ",", "1", ",", "rand", "(", "0", ",", "$", "count", ")", ")", ";", "return", "$", "data", "[", "0", "]", ";", "}" ]
Find a random entity @param array $conditions @return null|AbstractEntity @throws EntityException
[ "Find", "a", "random", "entity" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Entity/AbstractEntity.php#L131-L141
230,075
Webiny/Framework
src/Webiny/Component/Entity/AbstractEntity.php
AbstractEntity.getAttribute
public function getAttribute($attribute) { if (!isset($this->attributes[$attribute])) { throw new EntityException(EntityException::ATTRIBUTE_NOT_FOUND, [ $attribute, get_class($this) ]); } return $this->attributes[$attribute]; }
php
public function getAttribute($attribute) { if (!isset($this->attributes[$attribute])) { throw new EntityException(EntityException::ATTRIBUTE_NOT_FOUND, [ $attribute, get_class($this) ]); } return $this->attributes[$attribute]; }
[ "public", "function", "getAttribute", "(", "$", "attribute", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "attributes", "[", "$", "attribute", "]", ")", ")", "{", "throw", "new", "EntityException", "(", "EntityException", "::", "ATTRIBUTE_NOT_FOUND", ",", "[", "$", "attribute", ",", "get_class", "(", "$", "this", ")", "]", ")", ";", "}", "return", "$", "this", "->", "attributes", "[", "$", "attribute", "]", ";", "}" ]
Get entity attribute @param string $attribute @throws EntityException @return AbstractAttribute
[ "Get", "entity", "attribute" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Entity/AbstractEntity.php#L255-L265
230,076
Webiny/Framework
src/Webiny/Component/Entity/AbstractEntity.php
AbstractEntity.populate
public function populate($data) { if (is_null($data)) { return $this; } $data = $this->normalizeData($data); $fromDb = false; if ($this->isDbData($data)) { $fromDb = true; } else { unset($data['id']); unset($data['_id']); } $validation = $this->arr(); /* @var $entityAttribute AbstractAttribute */ foreach ($this->attributes as $attributeName => $entityAttribute) { if (!$entityAttribute->getAfterPopulate()) { $this->populateAttribute($attributeName, $entityAttribute, $validation, $data, $fromDb); } } foreach ($this->attributes as $attributeName => $entityAttribute) { if ($entityAttribute->getAfterPopulate()) { $this->populateAttribute($attributeName, $entityAttribute, $validation, $data, $fromDb); } } if ($validation->count() > 0) { $attributes = []; foreach ($validation as $attr => $error) { foreach ($error as $key => $value) { $attributes[$key] = $value; } } $ex = new EntityException(EntityException::VALIDATION_FAILED, [get_class($this), $validation->count()]); $ex->setInvalidAttributes($attributes); throw $ex; } return $this; }
php
public function populate($data) { if (is_null($data)) { return $this; } $data = $this->normalizeData($data); $fromDb = false; if ($this->isDbData($data)) { $fromDb = true; } else { unset($data['id']); unset($data['_id']); } $validation = $this->arr(); /* @var $entityAttribute AbstractAttribute */ foreach ($this->attributes as $attributeName => $entityAttribute) { if (!$entityAttribute->getAfterPopulate()) { $this->populateAttribute($attributeName, $entityAttribute, $validation, $data, $fromDb); } } foreach ($this->attributes as $attributeName => $entityAttribute) { if ($entityAttribute->getAfterPopulate()) { $this->populateAttribute($attributeName, $entityAttribute, $validation, $data, $fromDb); } } if ($validation->count() > 0) { $attributes = []; foreach ($validation as $attr => $error) { foreach ($error as $key => $value) { $attributes[$key] = $value; } } $ex = new EntityException(EntityException::VALIDATION_FAILED, [get_class($this), $validation->count()]); $ex->setInvalidAttributes($attributes); throw $ex; } return $this; }
[ "public", "function", "populate", "(", "$", "data", ")", "{", "if", "(", "is_null", "(", "$", "data", ")", ")", "{", "return", "$", "this", ";", "}", "$", "data", "=", "$", "this", "->", "normalizeData", "(", "$", "data", ")", ";", "$", "fromDb", "=", "false", ";", "if", "(", "$", "this", "->", "isDbData", "(", "$", "data", ")", ")", "{", "$", "fromDb", "=", "true", ";", "}", "else", "{", "unset", "(", "$", "data", "[", "'id'", "]", ")", ";", "unset", "(", "$", "data", "[", "'_id'", "]", ")", ";", "}", "$", "validation", "=", "$", "this", "->", "arr", "(", ")", ";", "/* @var $entityAttribute AbstractAttribute */", "foreach", "(", "$", "this", "->", "attributes", "as", "$", "attributeName", "=>", "$", "entityAttribute", ")", "{", "if", "(", "!", "$", "entityAttribute", "->", "getAfterPopulate", "(", ")", ")", "{", "$", "this", "->", "populateAttribute", "(", "$", "attributeName", ",", "$", "entityAttribute", ",", "$", "validation", ",", "$", "data", ",", "$", "fromDb", ")", ";", "}", "}", "foreach", "(", "$", "this", "->", "attributes", "as", "$", "attributeName", "=>", "$", "entityAttribute", ")", "{", "if", "(", "$", "entityAttribute", "->", "getAfterPopulate", "(", ")", ")", "{", "$", "this", "->", "populateAttribute", "(", "$", "attributeName", ",", "$", "entityAttribute", ",", "$", "validation", ",", "$", "data", ",", "$", "fromDb", ")", ";", "}", "}", "if", "(", "$", "validation", "->", "count", "(", ")", ">", "0", ")", "{", "$", "attributes", "=", "[", "]", ";", "foreach", "(", "$", "validation", "as", "$", "attr", "=>", "$", "error", ")", "{", "foreach", "(", "$", "error", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "attributes", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "$", "ex", "=", "new", "EntityException", "(", "EntityException", "::", "VALIDATION_FAILED", ",", "[", "get_class", "(", "$", "this", ")", ",", "$", "validation", "->", "count", "(", ")", "]", ")", ";", "$", "ex", "->", "setInvalidAttributes", "(", "$", "attributes", ")", ";", "throw", "$", "ex", ";", "}", "return", "$", "this", ";", "}" ]
Populate entity with given data @param array $data @throws EntityException @return $this
[ "Populate", "entity", "with", "given", "data" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Entity/AbstractEntity.php#L496-L540
230,077
Webiny/Framework
src/Webiny/Component/Entity/AbstractEntity.php
AbstractEntity.parseOrderParameters
protected static function parseOrderParameters($order) { $parsedOrder = []; if (count($order) > 0) { foreach ($order as $key => $o) { // Check if $order array is already formatted properly if (!is_numeric($key) && is_numeric($o)) { $parsedOrder[$key] = $o; continue; } $o = self::str($o); if ($o->startsWith('-')) { $parsedOrder[$o->subString(1, 0)->val()] = -1; } elseif ($o->startsWith('+')) { $parsedOrder[$o->subString(1, 0)->val()] = 1; } else { $parsedOrder[$o->val()] = 1; } } } return $parsedOrder; }
php
protected static function parseOrderParameters($order) { $parsedOrder = []; if (count($order) > 0) { foreach ($order as $key => $o) { // Check if $order array is already formatted properly if (!is_numeric($key) && is_numeric($o)) { $parsedOrder[$key] = $o; continue; } $o = self::str($o); if ($o->startsWith('-')) { $parsedOrder[$o->subString(1, 0)->val()] = -1; } elseif ($o->startsWith('+')) { $parsedOrder[$o->subString(1, 0)->val()] = 1; } else { $parsedOrder[$o->val()] = 1; } } } return $parsedOrder; }
[ "protected", "static", "function", "parseOrderParameters", "(", "$", "order", ")", "{", "$", "parsedOrder", "=", "[", "]", ";", "if", "(", "count", "(", "$", "order", ")", ">", "0", ")", "{", "foreach", "(", "$", "order", "as", "$", "key", "=>", "$", "o", ")", "{", "// Check if $order array is already formatted properly", "if", "(", "!", "is_numeric", "(", "$", "key", ")", "&&", "is_numeric", "(", "$", "o", ")", ")", "{", "$", "parsedOrder", "[", "$", "key", "]", "=", "$", "o", ";", "continue", ";", "}", "$", "o", "=", "self", "::", "str", "(", "$", "o", ")", ";", "if", "(", "$", "o", "->", "startsWith", "(", "'-'", ")", ")", "{", "$", "parsedOrder", "[", "$", "o", "->", "subString", "(", "1", ",", "0", ")", "->", "val", "(", ")", "]", "=", "-", "1", ";", "}", "elseif", "(", "$", "o", "->", "startsWith", "(", "'+'", ")", ")", "{", "$", "parsedOrder", "[", "$", "o", "->", "subString", "(", "1", ",", "0", ")", "->", "val", "(", ")", "]", "=", "1", ";", "}", "else", "{", "$", "parsedOrder", "[", "$", "o", "->", "val", "(", ")", "]", "=", "1", ";", "}", "}", "}", "return", "$", "parsedOrder", ";", "}" ]
Parse order parameters and construct parameters suitable for MongoDB @param $order @return array
[ "Parse", "order", "parameters", "and", "construct", "parameters", "suitable", "for", "MongoDB" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Entity/AbstractEntity.php#L637-L659
230,078
Webiny/Framework
src/Webiny/Component/Router/Route/RouteCollection.php
RouteCollection.addOption
public function addOption($name, array $attributes) { /** * @var Route $route */ foreach ($this->routes as $route) { $route->addOption($name, $attributes); } }
php
public function addOption($name, array $attributes) { /** * @var Route $route */ foreach ($this->routes as $route) { $route->addOption($name, $attributes); } }
[ "public", "function", "addOption", "(", "$", "name", ",", "array", "$", "attributes", ")", "{", "/**\n * @var Route $route\n */", "foreach", "(", "$", "this", "->", "routes", "as", "$", "route", ")", "{", "$", "route", "->", "addOption", "(", "$", "name", ",", "$", "attributes", ")", ";", "}", "}" ]
Adds an option for all the routes within the collection. @param string $name Name of the route parameter. @param array $attributes Parameter attributes.
[ "Adds", "an", "option", "for", "all", "the", "routes", "within", "the", "collection", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Router/Route/RouteCollection.php#L153-L161
230,079
Webiny/Framework
src/Webiny/Component/Storage/Driver/Local/LocalHelper.php
LocalHelper.ensureDirectoryExists
public function ensureDirectoryExists($directory, $create = false) { if (!is_dir($directory)) { if (!$create) { throw new StorageException(StorageException::DIRECTORY_DOES_NOT_EXIST, [$directory]); } $this->createDirectory($directory); } }
php
public function ensureDirectoryExists($directory, $create = false) { if (!is_dir($directory)) { if (!$create) { throw new StorageException(StorageException::DIRECTORY_DOES_NOT_EXIST, [$directory]); } $this->createDirectory($directory); } }
[ "public", "function", "ensureDirectoryExists", "(", "$", "directory", ",", "$", "create", "=", "false", ")", "{", "if", "(", "!", "is_dir", "(", "$", "directory", ")", ")", "{", "if", "(", "!", "$", "create", ")", "{", "throw", "new", "StorageException", "(", "StorageException", "::", "DIRECTORY_DOES_NOT_EXIST", ",", "[", "$", "directory", "]", ")", ";", "}", "$", "this", "->", "createDirectory", "(", "$", "directory", ")", ";", "}", "}" ]
Make sure the target directory exists @param string $directory Path to check @param bool $create (Optional) Create path if doesn't exist @throws \Webiny\Component\Storage\StorageException
[ "Make", "sure", "the", "target", "directory", "exists" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Storage/Driver/Local/LocalHelper.php#L65-L73
230,080
Webiny/Framework
src/Webiny/Component/Rest/Response/Router.php
Router.getUrl
public function getUrl() { if (empty($this->url)) { $url = $this->httpRequest()->getCurrentUrl(true)->getPath(); // we need to have the trailing slash because of the match inside matchRequest // and also when matching the default method, we can do an incorrect match if we don't have the start and end slash $this->url = $this->str($url)->trimRight('/')->val() . '/'; } return $this->url; }
php
public function getUrl() { if (empty($this->url)) { $url = $this->httpRequest()->getCurrentUrl(true)->getPath(); // we need to have the trailing slash because of the match inside matchRequest // and also when matching the default method, we can do an incorrect match if we don't have the start and end slash $this->url = $this->str($url)->trimRight('/')->val() . '/'; } return $this->url; }
[ "public", "function", "getUrl", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "url", ")", ")", "{", "$", "url", "=", "$", "this", "->", "httpRequest", "(", ")", "->", "getCurrentUrl", "(", "true", ")", "->", "getPath", "(", ")", ";", "// we need to have the trailing slash because of the match inside matchRequest", "// and also when matching the default method, we can do an incorrect match if we don't have the start and end slash", "$", "this", "->", "url", "=", "$", "this", "->", "str", "(", "$", "url", ")", "->", "trimRight", "(", "'/'", ")", "->", "val", "(", ")", ".", "'/'", ";", "}", "return", "$", "this", "->", "url", ";", "}" ]
Returns the current url path. @return string
[ "Returns", "the", "current", "url", "path", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Response/Router.php#L108-L118
230,081
Webiny/Framework
src/Webiny/Component/Rest/Response/Router.php
Router.setHttpMethod
public function setHttpMethod($method) { $method = strtolower($method); if (!in_array($method, self::$supportedRequestTypes)) { throw new RestException('The provided HTTP is no supported: "' . $method . '".'); } $this->method = $method; }
php
public function setHttpMethod($method) { $method = strtolower($method); if (!in_array($method, self::$supportedRequestTypes)) { throw new RestException('The provided HTTP is no supported: "' . $method . '".'); } $this->method = $method; }
[ "public", "function", "setHttpMethod", "(", "$", "method", ")", "{", "$", "method", "=", "strtolower", "(", "$", "method", ")", ";", "if", "(", "!", "in_array", "(", "$", "method", ",", "self", "::", "$", "supportedRequestTypes", ")", ")", "{", "throw", "new", "RestException", "(", "'The provided HTTP is no supported: \"'", ".", "$", "method", ".", "'\".'", ")", ";", "}", "$", "this", "->", "method", "=", "$", "method", ";", "}" ]
Force sets the http method. @param string $method Method name. @throws \Webiny\Component\Rest\RestException
[ "Force", "sets", "the", "http", "method", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Response/Router.php#L127-L135
230,082
Webiny/Framework
src/Webiny/Component/Rest/Response/Router.php
Router.getMethod
public function getMethod() { if (empty($this->method)) { $this->method = strtolower($this->httpRequest()->getRequestMethod()); } return $this->method; }
php
public function getMethod() { if (empty($this->method)) { $this->method = strtolower($this->httpRequest()->getRequestMethod()); } return $this->method; }
[ "public", "function", "getMethod", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "method", ")", ")", "{", "$", "this", "->", "method", "=", "strtolower", "(", "$", "this", "->", "httpRequest", "(", ")", "->", "getRequestMethod", "(", ")", ")", ";", "}", "return", "$", "this", "->", "method", ";", "}" ]
Get the http method. @return string
[ "Get", "the", "http", "method", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Response/Router.php#L142-L149
230,083
Webiny/Framework
src/Webiny/Component/Rest/Response/Router.php
Router.processRequest
public function processRequest() { // get version cache file $version = $this->getVersion(); // get class data from the compiled cache files $classData = $this->compilerCache->getCacheContent($this->api, $this->class, $version); // match request return $this->matchRequest($classData); }
php
public function processRequest() { // get version cache file $version = $this->getVersion(); // get class data from the compiled cache files $classData = $this->compilerCache->getCacheContent($this->api, $this->class, $version); // match request return $this->matchRequest($classData); }
[ "public", "function", "processRequest", "(", ")", "{", "// get version cache file", "$", "version", "=", "$", "this", "->", "getVersion", "(", ")", ";", "// get class data from the compiled cache files", "$", "classData", "=", "$", "this", "->", "compilerCache", "->", "getCacheContent", "(", "$", "this", "->", "api", ",", "$", "this", "->", "class", ",", "$", "version", ")", ";", "// match request", "return", "$", "this", "->", "matchRequest", "(", "$", "classData", ")", ";", "}" ]
Process the api rest request and return the CallbackResult object. @return CallbackResult
[ "Process", "the", "api", "rest", "request", "and", "return", "the", "CallbackResult", "object", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Response/Router.php#L156-L166
230,084
Webiny/Framework
src/Webiny/Component/Rest/Response/Router.php
Router.matchRequest
private function matchRequest(&$classData) { if (!is_array($classData)) { throw new RestException("Invalid class cache data."); } // build the request url upon which we will do the matching try { $url = $this->getUrl(); } catch (\Exception $e) { throw $e; } // get request method $method = $this->getMethod(); if (!in_array($method, self::$supportedRequestTypes)) { throw new RestException('Unsupported request method: "' . $method . '"'); } $callbacks = (empty($classData[$method])) ? [] : $classData[$method]; // match array $matchedMethod = [ 'methodData' => false, 'matchedParameters' => false ]; // validate that we have the ending class name in the url $classUrl = PathTransformations::classNameToUrl($this->class, $this->normalize); if (strpos($url, '/' . $classUrl . '/') !== false) { $matchedMethod = $this->matchMethod($callbacks, $url); // if method was not matched if (!$matchedMethod['methodData']) { // if no method was matched, let's try to match a default method $matchedMethod = $this->matchDefaultMethod($callbacks, $url, $classUrl); } } $methodData = (isset($matchedMethod['methodData'])) ? $matchedMethod['methodData'] : false; $matchedParameters = ($matchedMethod['matchedParameters']) ? $matchedMethod['matchedParameters'] : []; $requestBag = new RequestBag(); $requestBag->setClassData($classData) ->setMethodData($methodData) ->setMethodParameters($matchedParameters) ->setApi($this->api); $callback = new Callback($requestBag); return $callback->getCallbackResult(); }
php
private function matchRequest(&$classData) { if (!is_array($classData)) { throw new RestException("Invalid class cache data."); } // build the request url upon which we will do the matching try { $url = $this->getUrl(); } catch (\Exception $e) { throw $e; } // get request method $method = $this->getMethod(); if (!in_array($method, self::$supportedRequestTypes)) { throw new RestException('Unsupported request method: "' . $method . '"'); } $callbacks = (empty($classData[$method])) ? [] : $classData[$method]; // match array $matchedMethod = [ 'methodData' => false, 'matchedParameters' => false ]; // validate that we have the ending class name in the url $classUrl = PathTransformations::classNameToUrl($this->class, $this->normalize); if (strpos($url, '/' . $classUrl . '/') !== false) { $matchedMethod = $this->matchMethod($callbacks, $url); // if method was not matched if (!$matchedMethod['methodData']) { // if no method was matched, let's try to match a default method $matchedMethod = $this->matchDefaultMethod($callbacks, $url, $classUrl); } } $methodData = (isset($matchedMethod['methodData'])) ? $matchedMethod['methodData'] : false; $matchedParameters = ($matchedMethod['matchedParameters']) ? $matchedMethod['matchedParameters'] : []; $requestBag = new RequestBag(); $requestBag->setClassData($classData) ->setMethodData($methodData) ->setMethodParameters($matchedParameters) ->setApi($this->api); $callback = new Callback($requestBag); return $callback->getCallbackResult(); }
[ "private", "function", "matchRequest", "(", "&", "$", "classData", ")", "{", "if", "(", "!", "is_array", "(", "$", "classData", ")", ")", "{", "throw", "new", "RestException", "(", "\"Invalid class cache data.\"", ")", ";", "}", "// build the request url upon which we will do the matching", "try", "{", "$", "url", "=", "$", "this", "->", "getUrl", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "$", "e", ";", "}", "// get request method", "$", "method", "=", "$", "this", "->", "getMethod", "(", ")", ";", "if", "(", "!", "in_array", "(", "$", "method", ",", "self", "::", "$", "supportedRequestTypes", ")", ")", "{", "throw", "new", "RestException", "(", "'Unsupported request method: \"'", ".", "$", "method", ".", "'\"'", ")", ";", "}", "$", "callbacks", "=", "(", "empty", "(", "$", "classData", "[", "$", "method", "]", ")", ")", "?", "[", "]", ":", "$", "classData", "[", "$", "method", "]", ";", "// match array", "$", "matchedMethod", "=", "[", "'methodData'", "=>", "false", ",", "'matchedParameters'", "=>", "false", "]", ";", "// validate that we have the ending class name in the url", "$", "classUrl", "=", "PathTransformations", "::", "classNameToUrl", "(", "$", "this", "->", "class", ",", "$", "this", "->", "normalize", ")", ";", "if", "(", "strpos", "(", "$", "url", ",", "'/'", ".", "$", "classUrl", ".", "'/'", ")", "!==", "false", ")", "{", "$", "matchedMethod", "=", "$", "this", "->", "matchMethod", "(", "$", "callbacks", ",", "$", "url", ")", ";", "// if method was not matched", "if", "(", "!", "$", "matchedMethod", "[", "'methodData'", "]", ")", "{", "// if no method was matched, let's try to match a default method", "$", "matchedMethod", "=", "$", "this", "->", "matchDefaultMethod", "(", "$", "callbacks", ",", "$", "url", ",", "$", "classUrl", ")", ";", "}", "}", "$", "methodData", "=", "(", "isset", "(", "$", "matchedMethod", "[", "'methodData'", "]", ")", ")", "?", "$", "matchedMethod", "[", "'methodData'", "]", ":", "false", ";", "$", "matchedParameters", "=", "(", "$", "matchedMethod", "[", "'matchedParameters'", "]", ")", "?", "$", "matchedMethod", "[", "'matchedParameters'", "]", ":", "[", "]", ";", "$", "requestBag", "=", "new", "RequestBag", "(", ")", ";", "$", "requestBag", "->", "setClassData", "(", "$", "classData", ")", "->", "setMethodData", "(", "$", "methodData", ")", "->", "setMethodParameters", "(", "$", "matchedParameters", ")", "->", "setApi", "(", "$", "this", "->", "api", ")", ";", "$", "callback", "=", "new", "Callback", "(", "$", "requestBag", ")", ";", "return", "$", "callback", "->", "getCallbackResult", "(", ")", ";", "}" ]
Analyzes the request and tries to match an api method. @param array $classData Class array form compiled cache file. @return CallbackResult @throws RestException @throws \Exception
[ "Analyzes", "the", "request", "and", "tries", "to", "match", "an", "api", "method", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Response/Router.php#L187-L239
230,085
Webiny/Framework
src/Webiny/Component/Rest/Response/Router.php
Router.matchMethod
private function matchMethod($callbacks, $url) { // match a callback based on url pattern $methodData = false; $matchedParameters = false; // match method foreach ($callbacks as $pattern => $data) { if (($matchedParameters = $this->doesPatternMatch($pattern, $data, $url)) !== false) { $methodData = $data; break; } else if ($data['resourceNaming'] === false) { $matchedParameters = $this->tryMatchingOptionalParams($pattern, $data, $url); if ($matchedParameters) { $methodData = $data; break; } } } return [ 'methodData' => $methodData, 'matchedParameters' => $matchedParameters ]; }
php
private function matchMethod($callbacks, $url) { // match a callback based on url pattern $methodData = false; $matchedParameters = false; // match method foreach ($callbacks as $pattern => $data) { if (($matchedParameters = $this->doesPatternMatch($pattern, $data, $url)) !== false) { $methodData = $data; break; } else if ($data['resourceNaming'] === false) { $matchedParameters = $this->tryMatchingOptionalParams($pattern, $data, $url); if ($matchedParameters) { $methodData = $data; break; } } } return [ 'methodData' => $methodData, 'matchedParameters' => $matchedParameters ]; }
[ "private", "function", "matchMethod", "(", "$", "callbacks", ",", "$", "url", ")", "{", "// match a callback based on url pattern", "$", "methodData", "=", "false", ";", "$", "matchedParameters", "=", "false", ";", "// match method", "foreach", "(", "$", "callbacks", "as", "$", "pattern", "=>", "$", "data", ")", "{", "if", "(", "(", "$", "matchedParameters", "=", "$", "this", "->", "doesPatternMatch", "(", "$", "pattern", ",", "$", "data", ",", "$", "url", ")", ")", "!==", "false", ")", "{", "$", "methodData", "=", "$", "data", ";", "break", ";", "}", "else", "if", "(", "$", "data", "[", "'resourceNaming'", "]", "===", "false", ")", "{", "$", "matchedParameters", "=", "$", "this", "->", "tryMatchingOptionalParams", "(", "$", "pattern", ",", "$", "data", ",", "$", "url", ")", ";", "if", "(", "$", "matchedParameters", ")", "{", "$", "methodData", "=", "$", "data", ";", "break", ";", "}", "}", "}", "return", "[", "'methodData'", "=>", "$", "methodData", ",", "'matchedParameters'", "=>", "$", "matchedParameters", "]", ";", "}" ]
Does the matching of method if method name is present in the url. @param array $callbacks Available callbacks in the current class. @param string $url Url upon we will do the match @return array
[ "Does", "the", "matching", "of", "method", "if", "method", "name", "is", "present", "in", "the", "url", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Response/Router.php#L249-L273
230,086
Webiny/Framework
src/Webiny/Component/Rest/Response/Router.php
Router.matchDefaultMethod
private function matchDefaultMethod($callbacks, $url, $classUrl) { // match a callback based on url pattern $methodData = false; $matchedParameters = false; // match method foreach ($callbacks as $pattern => $data) { if ($data['default'] !== false && $data['resourceNaming'] === false) { // for default method we need to remove the method name from the pattern $methodUrl = $data['method']; if ($this->normalize) { $methodUrl = PathTransformations::methodNameToUrl($methodUrl); } $pattern = $classUrl . '/' . str_replace($methodUrl . '/', '', $pattern); if (($matchedParameters = $this->doesPatternMatch($pattern, $data, $url)) !== false) { $methodData = $data; break; } else { $methodName = $data['method']; $data['method'] = $classUrl; $matchedParameters = $this->tryMatchingOptionalParams($pattern, $data, $url); $data['method'] = $methodName; if ($matchedParameters) { $methodData = $data; break; } } } } return [ 'methodData' => $methodData, 'matchedParameters' => $matchedParameters ]; }
php
private function matchDefaultMethod($callbacks, $url, $classUrl) { // match a callback based on url pattern $methodData = false; $matchedParameters = false; // match method foreach ($callbacks as $pattern => $data) { if ($data['default'] !== false && $data['resourceNaming'] === false) { // for default method we need to remove the method name from the pattern $methodUrl = $data['method']; if ($this->normalize) { $methodUrl = PathTransformations::methodNameToUrl($methodUrl); } $pattern = $classUrl . '/' . str_replace($methodUrl . '/', '', $pattern); if (($matchedParameters = $this->doesPatternMatch($pattern, $data, $url)) !== false) { $methodData = $data; break; } else { $methodName = $data['method']; $data['method'] = $classUrl; $matchedParameters = $this->tryMatchingOptionalParams($pattern, $data, $url); $data['method'] = $methodName; if ($matchedParameters) { $methodData = $data; break; } } } } return [ 'methodData' => $methodData, 'matchedParameters' => $matchedParameters ]; }
[ "private", "function", "matchDefaultMethod", "(", "$", "callbacks", ",", "$", "url", ",", "$", "classUrl", ")", "{", "// match a callback based on url pattern", "$", "methodData", "=", "false", ";", "$", "matchedParameters", "=", "false", ";", "// match method", "foreach", "(", "$", "callbacks", "as", "$", "pattern", "=>", "$", "data", ")", "{", "if", "(", "$", "data", "[", "'default'", "]", "!==", "false", "&&", "$", "data", "[", "'resourceNaming'", "]", "===", "false", ")", "{", "// for default method we need to remove the method name from the pattern", "$", "methodUrl", "=", "$", "data", "[", "'method'", "]", ";", "if", "(", "$", "this", "->", "normalize", ")", "{", "$", "methodUrl", "=", "PathTransformations", "::", "methodNameToUrl", "(", "$", "methodUrl", ")", ";", "}", "$", "pattern", "=", "$", "classUrl", ".", "'/'", ".", "str_replace", "(", "$", "methodUrl", ".", "'/'", ",", "''", ",", "$", "pattern", ")", ";", "if", "(", "(", "$", "matchedParameters", "=", "$", "this", "->", "doesPatternMatch", "(", "$", "pattern", ",", "$", "data", ",", "$", "url", ")", ")", "!==", "false", ")", "{", "$", "methodData", "=", "$", "data", ";", "break", ";", "}", "else", "{", "$", "methodName", "=", "$", "data", "[", "'method'", "]", ";", "$", "data", "[", "'method'", "]", "=", "$", "classUrl", ";", "$", "matchedParameters", "=", "$", "this", "->", "tryMatchingOptionalParams", "(", "$", "pattern", ",", "$", "data", ",", "$", "url", ")", ";", "$", "data", "[", "'method'", "]", "=", "$", "methodName", ";", "if", "(", "$", "matchedParameters", ")", "{", "$", "methodData", "=", "$", "data", ";", "break", ";", "}", "}", "}", "}", "return", "[", "'methodData'", "=>", "$", "methodData", ",", "'matchedParameters'", "=>", "$", "matchedParameters", "]", ";", "}" ]
This is the fallback method that tries to match a default method. @param array $callbacks Available callbacks in the current class. @param string $url Url upon we will do the match @return array
[ "This", "is", "the", "fallback", "method", "that", "tries", "to", "match", "a", "default", "method", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Response/Router.php#L283-L319
230,087
themsaid/katana-core
src/FileHandlers/BaseHandler.php
BaseHandler.handle
public function handle(SplFileInfo $file) { $this->file = $file; $this->viewPath = $this->getViewPath(); $this->directory = $this->getDirectoryPrettyName(); $this->appendViewInformationToData(); if (@$this->viewsData['enableBlog'] && @$this->viewsData['postsListView'] == $this->viewPath) { $this->prepareBlogIndexViewData(); } $content = $this->getFileContent(); $this->filesystem->put( sprintf( '%s/%s', $this->prepareAndGetDirectory(), ends_with($file->getFilename(), ['.blade.php', 'md']) ? 'index.html' : $file->getFilename() ), $content ); }
php
public function handle(SplFileInfo $file) { $this->file = $file; $this->viewPath = $this->getViewPath(); $this->directory = $this->getDirectoryPrettyName(); $this->appendViewInformationToData(); if (@$this->viewsData['enableBlog'] && @$this->viewsData['postsListView'] == $this->viewPath) { $this->prepareBlogIndexViewData(); } $content = $this->getFileContent(); $this->filesystem->put( sprintf( '%s/%s', $this->prepareAndGetDirectory(), ends_with($file->getFilename(), ['.blade.php', 'md']) ? 'index.html' : $file->getFilename() ), $content ); }
[ "public", "function", "handle", "(", "SplFileInfo", "$", "file", ")", "{", "$", "this", "->", "file", "=", "$", "file", ";", "$", "this", "->", "viewPath", "=", "$", "this", "->", "getViewPath", "(", ")", ";", "$", "this", "->", "directory", "=", "$", "this", "->", "getDirectoryPrettyName", "(", ")", ";", "$", "this", "->", "appendViewInformationToData", "(", ")", ";", "if", "(", "@", "$", "this", "->", "viewsData", "[", "'enableBlog'", "]", "&&", "@", "$", "this", "->", "viewsData", "[", "'postsListView'", "]", "==", "$", "this", "->", "viewPath", ")", "{", "$", "this", "->", "prepareBlogIndexViewData", "(", ")", ";", "}", "$", "content", "=", "$", "this", "->", "getFileContent", "(", ")", ";", "$", "this", "->", "filesystem", "->", "put", "(", "sprintf", "(", "'%s/%s'", ",", "$", "this", "->", "prepareAndGetDirectory", "(", ")", ",", "ends_with", "(", "$", "file", "->", "getFilename", "(", ")", ",", "[", "'.blade.php'", ",", "'md'", "]", ")", "?", "'index.html'", ":", "$", "file", "->", "getFilename", "(", ")", ")", ",", "$", "content", ")", ";", "}" ]
Convert a blade view into a site page. @param SplFileInfo $file @return void
[ "Convert", "a", "blade", "view", "into", "a", "site", "page", "." ]
897c1adb6863d5145f1f104cbc8c9200cd98c3fb
https://github.com/themsaid/katana-core/blob/897c1adb6863d5145f1f104cbc8c9200cd98c3fb/src/FileHandlers/BaseHandler.php#L61-L85
230,088
themsaid/katana-core
src/FileHandlers/BaseHandler.php
BaseHandler.getFileContent
protected function getFileContent() { if (ends_with($this->file->getFilename(), '.blade.php')) { return $this->renderBlade(); } elseif (ends_with($this->file->getFilename(), '.md')) { return $this->renderMarkdown(); } return $this->file->getContents(); }
php
protected function getFileContent() { if (ends_with($this->file->getFilename(), '.blade.php')) { return $this->renderBlade(); } elseif (ends_with($this->file->getFilename(), '.md')) { return $this->renderMarkdown(); } return $this->file->getContents(); }
[ "protected", "function", "getFileContent", "(", ")", "{", "if", "(", "ends_with", "(", "$", "this", "->", "file", "->", "getFilename", "(", ")", ",", "'.blade.php'", ")", ")", "{", "return", "$", "this", "->", "renderBlade", "(", ")", ";", "}", "elseif", "(", "ends_with", "(", "$", "this", "->", "file", "->", "getFilename", "(", ")", ",", "'.md'", ")", ")", "{", "return", "$", "this", "->", "renderMarkdown", "(", ")", ";", "}", "return", "$", "this", "->", "file", "->", "getContents", "(", ")", ";", "}" ]
Get the content of the file after rendering. @param SplFileInfo $file @return string
[ "Get", "the", "content", "of", "the", "file", "after", "rendering", "." ]
897c1adb6863d5145f1f104cbc8c9200cd98c3fb
https://github.com/themsaid/katana-core/blob/897c1adb6863d5145f1f104cbc8c9200cd98c3fb/src/FileHandlers/BaseHandler.php#L94-L103
230,089
themsaid/katana-core
src/FileHandlers/BaseHandler.php
BaseHandler.renderMarkdown
protected function renderMarkdown() { $markdownFileBuilder = new MarkdownFileBuilder($this->filesystem, $this->viewFactory, $this->file, $this->viewsData); return $markdownFileBuilder->render(); }
php
protected function renderMarkdown() { $markdownFileBuilder = new MarkdownFileBuilder($this->filesystem, $this->viewFactory, $this->file, $this->viewsData); return $markdownFileBuilder->render(); }
[ "protected", "function", "renderMarkdown", "(", ")", "{", "$", "markdownFileBuilder", "=", "new", "MarkdownFileBuilder", "(", "$", "this", "->", "filesystem", ",", "$", "this", "->", "viewFactory", ",", "$", "this", "->", "file", ",", "$", "this", "->", "viewsData", ")", ";", "return", "$", "markdownFileBuilder", "->", "render", "(", ")", ";", "}" ]
Render the markdown file. @return string
[ "Render", "the", "markdown", "file", "." ]
897c1adb6863d5145f1f104cbc8c9200cd98c3fb
https://github.com/themsaid/katana-core/blob/897c1adb6863d5145f1f104cbc8c9200cd98c3fb/src/FileHandlers/BaseHandler.php#L120-L125
230,090
themsaid/katana-core
src/FileHandlers/BaseHandler.php
BaseHandler.prepareAndGetDirectory
protected function prepareAndGetDirectory() { if (! $this->filesystem->isDirectory($this->directory)) { $this->filesystem->makeDirectory($this->directory, 0755, true); } return $this->directory; }
php
protected function prepareAndGetDirectory() { if (! $this->filesystem->isDirectory($this->directory)) { $this->filesystem->makeDirectory($this->directory, 0755, true); } return $this->directory; }
[ "protected", "function", "prepareAndGetDirectory", "(", ")", "{", "if", "(", "!", "$", "this", "->", "filesystem", "->", "isDirectory", "(", "$", "this", "->", "directory", ")", ")", "{", "$", "this", "->", "filesystem", "->", "makeDirectory", "(", "$", "this", "->", "directory", ",", "0755", ",", "true", ")", ";", "}", "return", "$", "this", "->", "directory", ";", "}" ]
Prepare and get the directory name for pretty URLs. @return string
[ "Prepare", "and", "get", "the", "directory", "name", "for", "pretty", "URLs", "." ]
897c1adb6863d5145f1f104cbc8c9200cd98c3fb
https://github.com/themsaid/katana-core/blob/897c1adb6863d5145f1f104cbc8c9200cd98c3fb/src/FileHandlers/BaseHandler.php#L132-L139
230,091
themsaid/katana-core
src/FileHandlers/BaseHandler.php
BaseHandler.getDirectoryPrettyName
protected function getDirectoryPrettyName() { $fileBaseName = $this->getFileName(); $fileRelativePath = $this->normalizePath($this->file->getRelativePath()); if (in_array($this->file->getExtension(), ['php', 'md']) && $fileBaseName != 'index') { $fileRelativePath .= $fileRelativePath ? "/$fileBaseName" : $fileBaseName; } return KATANA_PUBLIC_DIR.($fileRelativePath ? "/$fileRelativePath" : ''); }
php
protected function getDirectoryPrettyName() { $fileBaseName = $this->getFileName(); $fileRelativePath = $this->normalizePath($this->file->getRelativePath()); if (in_array($this->file->getExtension(), ['php', 'md']) && $fileBaseName != 'index') { $fileRelativePath .= $fileRelativePath ? "/$fileBaseName" : $fileBaseName; } return KATANA_PUBLIC_DIR.($fileRelativePath ? "/$fileRelativePath" : ''); }
[ "protected", "function", "getDirectoryPrettyName", "(", ")", "{", "$", "fileBaseName", "=", "$", "this", "->", "getFileName", "(", ")", ";", "$", "fileRelativePath", "=", "$", "this", "->", "normalizePath", "(", "$", "this", "->", "file", "->", "getRelativePath", "(", ")", ")", ";", "if", "(", "in_array", "(", "$", "this", "->", "file", "->", "getExtension", "(", ")", ",", "[", "'php'", ",", "'md'", "]", ")", "&&", "$", "fileBaseName", "!=", "'index'", ")", "{", "$", "fileRelativePath", ".=", "$", "fileRelativePath", "?", "\"/$fileBaseName\"", ":", "$", "fileBaseName", ";", "}", "return", "KATANA_PUBLIC_DIR", ".", "(", "$", "fileRelativePath", "?", "\"/$fileRelativePath\"", ":", "''", ")", ";", "}" ]
Generate directory path to be used for the file pretty name. @return string
[ "Generate", "directory", "path", "to", "be", "used", "for", "the", "file", "pretty", "name", "." ]
897c1adb6863d5145f1f104cbc8c9200cd98c3fb
https://github.com/themsaid/katana-core/blob/897c1adb6863d5145f1f104cbc8c9200cd98c3fb/src/FileHandlers/BaseHandler.php#L146-L157
230,092
themsaid/katana-core
src/FileHandlers/BaseHandler.php
BaseHandler.prepareBlogIndexViewData
protected function prepareBlogIndexViewData() { $postsPerPage = @$this->viewsData['postsPerPage'] ?: 5; $this->viewsData['nextPage'] = count($this->viewsData['blogPosts']) > $postsPerPage ? '/blog-page/2' : null; $this->viewsData['previousPage'] = null; $this->viewsData['paginatedBlogPosts'] = array_slice($this->viewsData['blogPosts'], 0, $postsPerPage, true); }
php
protected function prepareBlogIndexViewData() { $postsPerPage = @$this->viewsData['postsPerPage'] ?: 5; $this->viewsData['nextPage'] = count($this->viewsData['blogPosts']) > $postsPerPage ? '/blog-page/2' : null; $this->viewsData['previousPage'] = null; $this->viewsData['paginatedBlogPosts'] = array_slice($this->viewsData['blogPosts'], 0, $postsPerPage, true); }
[ "protected", "function", "prepareBlogIndexViewData", "(", ")", "{", "$", "postsPerPage", "=", "@", "$", "this", "->", "viewsData", "[", "'postsPerPage'", "]", "?", ":", "5", ";", "$", "this", "->", "viewsData", "[", "'nextPage'", "]", "=", "count", "(", "$", "this", "->", "viewsData", "[", "'blogPosts'", "]", ")", ">", "$", "postsPerPage", "?", "'/blog-page/2'", ":", "null", ";", "$", "this", "->", "viewsData", "[", "'previousPage'", "]", "=", "null", ";", "$", "this", "->", "viewsData", "[", "'paginatedBlogPosts'", "]", "=", "array_slice", "(", "$", "this", "->", "viewsData", "[", "'blogPosts'", "]", ",", "0", ",", "$", "postsPerPage", ",", "true", ")", ";", "}" ]
Prepare the data for the blog landing page. We will pass only the first n posts and a next page path. @return void
[ "Prepare", "the", "data", "for", "the", "blog", "landing", "page", "." ]
897c1adb6863d5145f1f104cbc8c9200cd98c3fb
https://github.com/themsaid/katana-core/blob/897c1adb6863d5145f1f104cbc8c9200cd98c3fb/src/FileHandlers/BaseHandler.php#L176-L185
230,093
themsaid/katana-core
src/FileHandlers/BaseHandler.php
BaseHandler.getFileName
protected function getFileName(SplFileInfo $file = null) { $file = $file ?: $this->file; return str_replace(['.blade.php', '.php', '.md'], '', $file->getBasename()); }
php
protected function getFileName(SplFileInfo $file = null) { $file = $file ?: $this->file; return str_replace(['.blade.php', '.php', '.md'], '', $file->getBasename()); }
[ "protected", "function", "getFileName", "(", "SplFileInfo", "$", "file", "=", "null", ")", "{", "$", "file", "=", "$", "file", "?", ":", "$", "this", "->", "file", ";", "return", "str_replace", "(", "[", "'.blade.php'", ",", "'.php'", ",", "'.md'", "]", ",", "''", ",", "$", "file", "->", "getBasename", "(", ")", ")", ";", "}" ]
Get the file name without the extension. @return string
[ "Get", "the", "file", "name", "without", "the", "extension", "." ]
897c1adb6863d5145f1f104cbc8c9200cd98c3fb
https://github.com/themsaid/katana-core/blob/897c1adb6863d5145f1f104cbc8c9200cd98c3fb/src/FileHandlers/BaseHandler.php#L192-L197
230,094
themsaid/katana-core
src/FileHandlers/BaseHandler.php
BaseHandler.appendViewInformationToData
protected function appendViewInformationToData() { $this->viewsData['currentViewPath'] = $this->viewPath; $this->viewsData['currentUrlPath'] = ($path = str_replace(KATANA_PUBLIC_DIR, '', $this->directory)) ? $path : '/'; }
php
protected function appendViewInformationToData() { $this->viewsData['currentViewPath'] = $this->viewPath; $this->viewsData['currentUrlPath'] = ($path = str_replace(KATANA_PUBLIC_DIR, '', $this->directory)) ? $path : '/'; }
[ "protected", "function", "appendViewInformationToData", "(", ")", "{", "$", "this", "->", "viewsData", "[", "'currentViewPath'", "]", "=", "$", "this", "->", "viewPath", ";", "$", "this", "->", "viewsData", "[", "'currentUrlPath'", "]", "=", "(", "$", "path", "=", "str_replace", "(", "KATANA_PUBLIC_DIR", ",", "''", ",", "$", "this", "->", "directory", ")", ")", "?", "$", "path", ":", "'/'", ";", "}" ]
Append the view file information to the view data. @return void
[ "Append", "the", "view", "file", "information", "to", "the", "view", "data", "." ]
897c1adb6863d5145f1f104cbc8c9200cd98c3fb
https://github.com/themsaid/katana-core/blob/897c1adb6863d5145f1f104cbc8c9200cd98c3fb/src/FileHandlers/BaseHandler.php#L204-L209
230,095
Webiny/Framework
src/Webiny/Component/Storage/Directory/Directory.php
Directory.getSize
public function getSize() { $size = 0; $this->loadItems(); foreach ($this->items as $item) { $size += $item->getSize(); } return $size; }
php
public function getSize() { $size = 0; $this->loadItems(); foreach ($this->items as $item) { $size += $item->getSize(); } return $size; }
[ "public", "function", "getSize", "(", ")", "{", "$", "size", "=", "0", ";", "$", "this", "->", "loadItems", "(", ")", ";", "foreach", "(", "$", "this", "->", "items", "as", "$", "item", ")", "{", "$", "size", "+=", "$", "item", "->", "getSize", "(", ")", ";", "}", "return", "$", "size", ";", "}" ]
Get directory size WARNING! This is a very intensive operation especially on deep directory structures! It is performed by recursively walking through directory structure and getting each file's size.
[ "Get", "directory", "size" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Storage/Directory/Directory.php#L214-L223
230,096
Webiny/Framework
src/Webiny/Component/Security/Role/RoleHierarchy.php
RoleHierarchy.buildRoleMap
private function buildRoleMap($hierarchy) { $this->map = $this->arr(); foreach ($hierarchy as $main => $roles) { $hierarchy[$main] = $this->arr((array)$roles); } $hierarchy = $this->arr($hierarchy); foreach ($hierarchy as $main => $roles) { $this->map->append($main, $roles->val()); $additionalRoles = clone $roles; $parsed = $this->arr(); $role = ''; while ($additionalRoles->count() > 0 && $additionalRoles->removeFirst($role)) { if (!$hierarchy->keyExists($role)) { continue; } $parsed->append($role); $innerRole = $this->arr($this->map->key($main)); $innerRole->merge($hierarchy[$role]->val()); $this->map->append($main, $innerRole->val()); $additionalRoles->merge($hierarchy->key($role)->diff($parsed->val())->val()); } } }
php
private function buildRoleMap($hierarchy) { $this->map = $this->arr(); foreach ($hierarchy as $main => $roles) { $hierarchy[$main] = $this->arr((array)$roles); } $hierarchy = $this->arr($hierarchy); foreach ($hierarchy as $main => $roles) { $this->map->append($main, $roles->val()); $additionalRoles = clone $roles; $parsed = $this->arr(); $role = ''; while ($additionalRoles->count() > 0 && $additionalRoles->removeFirst($role)) { if (!$hierarchy->keyExists($role)) { continue; } $parsed->append($role); $innerRole = $this->arr($this->map->key($main)); $innerRole->merge($hierarchy[$role]->val()); $this->map->append($main, $innerRole->val()); $additionalRoles->merge($hierarchy->key($role)->diff($parsed->val())->val()); } } }
[ "private", "function", "buildRoleMap", "(", "$", "hierarchy", ")", "{", "$", "this", "->", "map", "=", "$", "this", "->", "arr", "(", ")", ";", "foreach", "(", "$", "hierarchy", "as", "$", "main", "=>", "$", "roles", ")", "{", "$", "hierarchy", "[", "$", "main", "]", "=", "$", "this", "->", "arr", "(", "(", "array", ")", "$", "roles", ")", ";", "}", "$", "hierarchy", "=", "$", "this", "->", "arr", "(", "$", "hierarchy", ")", ";", "foreach", "(", "$", "hierarchy", "as", "$", "main", "=>", "$", "roles", ")", "{", "$", "this", "->", "map", "->", "append", "(", "$", "main", ",", "$", "roles", "->", "val", "(", ")", ")", ";", "$", "additionalRoles", "=", "clone", "$", "roles", ";", "$", "parsed", "=", "$", "this", "->", "arr", "(", ")", ";", "$", "role", "=", "''", ";", "while", "(", "$", "additionalRoles", "->", "count", "(", ")", ">", "0", "&&", "$", "additionalRoles", "->", "removeFirst", "(", "$", "role", ")", ")", "{", "if", "(", "!", "$", "hierarchy", "->", "keyExists", "(", "$", "role", ")", ")", "{", "continue", ";", "}", "$", "parsed", "->", "append", "(", "$", "role", ")", ";", "$", "innerRole", "=", "$", "this", "->", "arr", "(", "$", "this", "->", "map", "->", "key", "(", "$", "main", ")", ")", ";", "$", "innerRole", "->", "merge", "(", "$", "hierarchy", "[", "$", "role", "]", "->", "val", "(", ")", ")", ";", "$", "this", "->", "map", "->", "append", "(", "$", "main", ",", "$", "innerRole", "->", "val", "(", ")", ")", ";", "$", "additionalRoles", "->", "merge", "(", "$", "hierarchy", "->", "key", "(", "$", "role", ")", "->", "diff", "(", "$", "parsed", "->", "val", "(", ")", ")", "->", "val", "(", ")", ")", ";", "}", "}", "}" ]
Private function that parses the hierarchy array and builds up a hierarchy map @param array $hierarchy Role hierarchy array from system configuration.
[ "Private", "function", "that", "parses", "the", "hierarchy", "array", "and", "builds", "up", "a", "hierarchy", "map" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Security/Role/RoleHierarchy.php#L67-L94
230,097
Webiny/Framework
src/Webiny/Component/Config/Config.php
Config.ini
public function ini($resource, $useSections = true, $nestDelimiter = '.') { $driver = new IniDriver($resource); $driver->setDelimiter($nestDelimiter)->useSections($useSections); return new ConfigObject($driver); }
php
public function ini($resource, $useSections = true, $nestDelimiter = '.') { $driver = new IniDriver($resource); $driver->setDelimiter($nestDelimiter)->useSections($useSections); return new ConfigObject($driver); }
[ "public", "function", "ini", "(", "$", "resource", ",", "$", "useSections", "=", "true", ",", "$", "nestDelimiter", "=", "'.'", ")", "{", "$", "driver", "=", "new", "IniDriver", "(", "$", "resource", ")", ";", "$", "driver", "->", "setDelimiter", "(", "$", "nestDelimiter", ")", "->", "useSections", "(", "$", "useSections", ")", ";", "return", "new", "ConfigObject", "(", "$", "driver", ")", ";", "}" ]
Get Config object from INI file or string @param string $resource Config resource in form of a file path or config string @param bool $useSections Default: true @param string $nestDelimiter Delimiter for nested properties, ex: a.b.c or a-b-c @return ConfigObject
[ "Get", "Config", "object", "from", "INI", "file", "or", "string" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Config/Config.php#L40-L46
230,098
Webiny/Framework
src/Webiny/Component/Security/SecurityTrait.php
SecurityTrait.security
protected static function security($firewall = null) { if($firewall) { return Security::getInstance()->firewall($firewall); } return Security::getInstance(); }
php
protected static function security($firewall = null) { if($firewall) { return Security::getInstance()->firewall($firewall); } return Security::getInstance(); }
[ "protected", "static", "function", "security", "(", "$", "firewall", "=", "null", ")", "{", "if", "(", "$", "firewall", ")", "{", "return", "Security", "::", "getInstance", "(", ")", "->", "firewall", "(", "$", "firewall", ")", ";", "}", "return", "Security", "::", "getInstance", "(", ")", ";", "}" ]
Returns the current security instance or firewall if firewall key is given @param null|string $firewall Firewall key @throws SecurityException @return Security|Firewall
[ "Returns", "the", "current", "security", "instance", "or", "firewall", "if", "firewall", "key", "is", "given" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Security/SecurityTrait.php#L29-L36
230,099
milesj/admin
Controller/AclController.php
AclController.grant
public function grant() { $aro_id = isset($this->request->params['named']['aro_id']) ? $this->request->params['named']['aro_id'] : null; $aco_id = isset($this->request->params['named']['aco_id']) ? $this->request->params['named']['aco_id'] : null; if (!$aro_id || !$aco_id) { throw new BadRequestException(__d('admin', 'Invalid ARO/ACO IDs')); } $aro = $this->Aro->getById($aro_id); $aco = $this->Aco->getById($aco_id); if (!$aro || !$aco) { throw new NotFoundException(__d('admin', 'Invalid ARO/ACO Records')); } $aroAlias = $aro['RequestObject']['alias']; $acoAlias = $aco['ControlObject']['alias']; if (!empty($aro['Parent']['alias'])) { $aroAlias = $aro['Parent']['alias'] . '/' . $aroAlias; } if ($this->Acl->allow($aroAlias, $acoAlias)) { $this->AdminToolbar->logAction(ActionLog::CREATE, $this->Permission, $this->Acl->adapter()->Permission->id, sprintf('Granted %s access to %s', $aroAlias, $acoAlias)); $this->AdminToolbar->setFlashMessage(__d('admin', 'Successfully granted %s permission to %s', array($aroAlias, $acoAlias))); } else { $this->AdminToolbar->setFlashMessage(__d('admin', 'Failed to grant %s permission to %s', array($aroAlias, $acoAlias)), 'is-error'); } $this->redirect(array('action' => 'index')); }
php
public function grant() { $aro_id = isset($this->request->params['named']['aro_id']) ? $this->request->params['named']['aro_id'] : null; $aco_id = isset($this->request->params['named']['aco_id']) ? $this->request->params['named']['aco_id'] : null; if (!$aro_id || !$aco_id) { throw new BadRequestException(__d('admin', 'Invalid ARO/ACO IDs')); } $aro = $this->Aro->getById($aro_id); $aco = $this->Aco->getById($aco_id); if (!$aro || !$aco) { throw new NotFoundException(__d('admin', 'Invalid ARO/ACO Records')); } $aroAlias = $aro['RequestObject']['alias']; $acoAlias = $aco['ControlObject']['alias']; if (!empty($aro['Parent']['alias'])) { $aroAlias = $aro['Parent']['alias'] . '/' . $aroAlias; } if ($this->Acl->allow($aroAlias, $acoAlias)) { $this->AdminToolbar->logAction(ActionLog::CREATE, $this->Permission, $this->Acl->adapter()->Permission->id, sprintf('Granted %s access to %s', $aroAlias, $acoAlias)); $this->AdminToolbar->setFlashMessage(__d('admin', 'Successfully granted %s permission to %s', array($aroAlias, $acoAlias))); } else { $this->AdminToolbar->setFlashMessage(__d('admin', 'Failed to grant %s permission to %s', array($aroAlias, $acoAlias)), 'is-error'); } $this->redirect(array('action' => 'index')); }
[ "public", "function", "grant", "(", ")", "{", "$", "aro_id", "=", "isset", "(", "$", "this", "->", "request", "->", "params", "[", "'named'", "]", "[", "'aro_id'", "]", ")", "?", "$", "this", "->", "request", "->", "params", "[", "'named'", "]", "[", "'aro_id'", "]", ":", "null", ";", "$", "aco_id", "=", "isset", "(", "$", "this", "->", "request", "->", "params", "[", "'named'", "]", "[", "'aco_id'", "]", ")", "?", "$", "this", "->", "request", "->", "params", "[", "'named'", "]", "[", "'aco_id'", "]", ":", "null", ";", "if", "(", "!", "$", "aro_id", "||", "!", "$", "aco_id", ")", "{", "throw", "new", "BadRequestException", "(", "__d", "(", "'admin'", ",", "'Invalid ARO/ACO IDs'", ")", ")", ";", "}", "$", "aro", "=", "$", "this", "->", "Aro", "->", "getById", "(", "$", "aro_id", ")", ";", "$", "aco", "=", "$", "this", "->", "Aco", "->", "getById", "(", "$", "aco_id", ")", ";", "if", "(", "!", "$", "aro", "||", "!", "$", "aco", ")", "{", "throw", "new", "NotFoundException", "(", "__d", "(", "'admin'", ",", "'Invalid ARO/ACO Records'", ")", ")", ";", "}", "$", "aroAlias", "=", "$", "aro", "[", "'RequestObject'", "]", "[", "'alias'", "]", ";", "$", "acoAlias", "=", "$", "aco", "[", "'ControlObject'", "]", "[", "'alias'", "]", ";", "if", "(", "!", "empty", "(", "$", "aro", "[", "'Parent'", "]", "[", "'alias'", "]", ")", ")", "{", "$", "aroAlias", "=", "$", "aro", "[", "'Parent'", "]", "[", "'alias'", "]", ".", "'/'", ".", "$", "aroAlias", ";", "}", "if", "(", "$", "this", "->", "Acl", "->", "allow", "(", "$", "aroAlias", ",", "$", "acoAlias", ")", ")", "{", "$", "this", "->", "AdminToolbar", "->", "logAction", "(", "ActionLog", "::", "CREATE", ",", "$", "this", "->", "Permission", ",", "$", "this", "->", "Acl", "->", "adapter", "(", ")", "->", "Permission", "->", "id", ",", "sprintf", "(", "'Granted %s access to %s'", ",", "$", "aroAlias", ",", "$", "acoAlias", ")", ")", ";", "$", "this", "->", "AdminToolbar", "->", "setFlashMessage", "(", "__d", "(", "'admin'", ",", "'Successfully granted %s permission to %s'", ",", "array", "(", "$", "aroAlias", ",", "$", "acoAlias", ")", ")", ")", ";", "}", "else", "{", "$", "this", "->", "AdminToolbar", "->", "setFlashMessage", "(", "__d", "(", "'admin'", ",", "'Failed to grant %s permission to %s'", ",", "array", "(", "$", "aroAlias", ",", "$", "acoAlias", ")", ")", ",", "'is-error'", ")", ";", "}", "$", "this", "->", "redirect", "(", "array", "(", "'action'", "=>", "'index'", ")", ")", ";", "}" ]
Grant an ARO access to an ACO. @throws NotFoundException @throws BadRequestException
[ "Grant", "an", "ARO", "access", "to", "an", "ACO", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/AclController.php#L31-L61